mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Make the heart throb
This commit is contained in:
parent
2954cd028d
commit
c14020f84d
@ -96,10 +96,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="donate_button">
|
||||
<property name="cursor">
|
||||
<cursorShape>PointingHandCursor</cursorShape>
|
||||
</property>
|
||||
<widget class="ThrobbingButton" name="donate_button">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
@ -107,12 +104,6 @@
|
||||
<iconset resource="../../../resources/images.qrc">
|
||||
<normaloff>:/images/donate.svg</normaloff>:/images/donate.svg</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>64</width>
|
||||
<height>64</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@ -552,6 +543,11 @@
|
||||
<extends>QComboBox</extends>
|
||||
<header>calibre.gui2.search_box</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>ThrobbingButton</class>
|
||||
<extends>QToolButton</extends>
|
||||
<header>calibre/gui2/throbber.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../../../resources/images.qrc"/>
|
||||
|
70
src/calibre/gui2/throbber.py
Normal file
70
src/calibre/gui2/throbber.py
Normal file
@ -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 <kovid@kovidgoyal.net>'
|
||||
__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_()
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user