diff --git a/src/calibre/gui2/main.ui b/src/calibre/gui2/main.ui index da2722a0a5..d89a451cda 100644 --- a/src/calibre/gui2/main.ui +++ b/src/calibre/gui2/main.ui @@ -96,10 +96,7 @@ - - - PointingHandCursor - + ... @@ -107,12 +104,6 @@ :/images/donate.svg:/images/donate.svg - - - 64 - 64 - - true @@ -552,6 +543,11 @@ QComboBox
calibre.gui2.search_box
+ + ThrobbingButton + QToolButton +
calibre/gui2/throbber.h
+
diff --git a/src/calibre/gui2/throbber.py b/src/calibre/gui2/throbber.py new file mode 100644 index 0000000000..99c899c9f3 --- /dev/null +++ b/src/calibre/gui2/throbber.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python +# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai + +__license__ = 'GPL v3' +__copyright__ = '2010, Kovid Goyal ' +__docformat__ = 'restructuredtext en' + + +from PyQt4.Qt import QToolButton, QSize, QPropertyAnimation, Qt, \ + QMetaObject + +from calibre.gui2 import config + +class ThrobbingButton(QToolButton): + + def __init__(self, *args): + QToolButton.__init__(self, *args) + self.animation = QPropertyAnimation(self, 'iconSize', self) + self.animation.setDuration(60/72.*1000) + self.animation.setLoopCount(4) + self.normal_icon_size = QSize(64, 64) + self.animation.valueChanged.connect(self.value_changed) + self.setCursor(Qt.PointingHandCursor) + self.animation.finished.connect(self.animation_finished) + + def set_normal_icon_size(self, w, h): + self.normal_icon_size = QSize(w, h) + self.setIconSize(self.normal_icon_size) + self.setMinimumSize(self.sizeHint()) + + def animation_finished(self): + self.setIconSize(self.normal_icon_size) + + def enterEvent(self, ev): + self.start_animation() + + def leaveEvent(self, ev): + self.stop_animation() + + def value_changed(self, val): + self.update() + + def start_animation(self): + if config['disable_animations']: return + if self.animation.state() != self.animation.Stopped or not self.isVisible(): + return + size = self.normal_icon_size.width() + smaller = int(0.7 * size) + self.animation.setStartValue(QSize(smaller, smaller)) + self.animation.setEndValue(self.normal_icon_size) + QMetaObject.invokeMethod(self.animation, 'start', Qt.QueuedConnection) + + def stop_animation(self): + self.animation.stop() + self.animation_finished() + + +if __name__ == '__main__': + from PyQt4.Qt import QApplication, QWidget, QHBoxLayout, QIcon + app = QApplication([]) + w = QWidget() + w.setLayout(QHBoxLayout()) + b = ThrobbingButton() + b.setIcon(QIcon(I('donate.svg'))) + w.layout().addWidget(b) + w.show() + b.set_normal_icon_size(64, 64) + b.start_animation() + + app.exec_() diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index 10cef9b2cb..709f91da25 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -281,6 +281,8 @@ class Main(MainWindow, Ui_MainWindow, DeviceMixin, ToolbarMixin, # {{{ self.read_settings() self.finalize_layout() + self.donate_button.set_normal_icon_size(64, 64) + self.donate_button.start_animation() def resizeEvent(self, ev): MainWindow.resizeEvent(self, ev)