mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Fix vertical alignment of donate button on toolbar
This commit is contained in:
parent
cdddb7528b
commit
2a9d8e3e81
@ -13,7 +13,6 @@ from PyQt5.Qt import (
|
||||
QTimer, QPropertyAnimation, QEasingCurve, pyqtProperty, QPainter, QWidget)
|
||||
|
||||
from calibre.constants import isosx
|
||||
from calibre.gui2.throbber import create_donate_widget
|
||||
from calibre.gui2 import gprefs, native_menubar_defaults, config
|
||||
|
||||
class RevealBar(QWidget): # {{{
|
||||
@ -83,8 +82,7 @@ class ToolBar(QToolBar): # {{{
|
||||
QToolBar.resizeEvent(self, ev)
|
||||
style = self.get_text_style()
|
||||
self.setToolButtonStyle(style)
|
||||
if hasattr(self, 'd_widget') and hasattr(self.d_widget, 'filler'):
|
||||
self.d_widget.filler.setVisible(style != Qt.ToolButtonIconOnly)
|
||||
self.donate_button.setToolButtonStyle(style)
|
||||
|
||||
def get_text_style(self):
|
||||
style = Qt.ToolButtonTextUnderIcon
|
||||
@ -134,8 +132,7 @@ class ToolBar(QToolBar): # {{{
|
||||
bar.setup_tool_button(bar, ac, QToolButton.MenuButtonPopup)
|
||||
ac.setVisible(False)
|
||||
elif what == 'Donate':
|
||||
self.d_widget = create_donate_widget(self.donate_button)
|
||||
bar.addWidget(self.d_widget)
|
||||
bar.addWidget(self.donate_button)
|
||||
self.showing_donate = True
|
||||
elif what in self.gui.iactions:
|
||||
action = self.gui.iactions[what]
|
||||
@ -550,6 +547,7 @@ class BarsManager(QObject):
|
||||
for bar in self.bars:
|
||||
bar.setIconSize(QSize(sz, sz))
|
||||
bar.setToolButtonStyle(style)
|
||||
self.donate_button.set_normal_icon_size(sz, sz)
|
||||
self.donate_button.setIconSize(bar.iconSize())
|
||||
self.donate_button.setToolButtonStyle(style)
|
||||
|
||||
|
||||
|
@ -1,39 +1,43 @@
|
||||
#!/usr/bin/env python2
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||
from __future__ import (unicode_literals, division, absolute_import,
|
||||
print_function)
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
|
||||
from PyQt5.Qt import QToolButton, QSize, QPropertyAnimation, Qt, \
|
||||
QMetaObject, QLabel, QVBoxLayout, QWidget
|
||||
from PyQt5.Qt import (
|
||||
QToolButton, QSize, QPropertyAnimation, Qt, QMetaObject, pyqtProperty,
|
||||
QWidget, QIcon, QPainter, QStyleOptionToolButton)
|
||||
|
||||
from calibre.constants import isosx
|
||||
from calibre.gui2 import config
|
||||
|
||||
class ThrobbingButton(QToolButton):
|
||||
|
||||
@pyqtProperty(int)
|
||||
def icon_size(self):
|
||||
return self._icon_size
|
||||
|
||||
@icon_size.setter
|
||||
def icon_size(self, value):
|
||||
self._icon_size = value
|
||||
|
||||
def __init__(self, *args):
|
||||
QToolButton.__init__(self, *args)
|
||||
self.animation = QPropertyAnimation(self, b'iconSize', self)
|
||||
self._icon_size = -1
|
||||
QToolButton.setIcon(self, QIcon(I('donate.png')))
|
||||
self.setText('\xa0')
|
||||
self.animation = QPropertyAnimation(self, b'icon_size', 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)
|
||||
try:
|
||||
self.setMinimumSize(self.sizeHint())
|
||||
except:
|
||||
self.setMinimumSize(QSize(w+5, h+5))
|
||||
|
||||
def animation_finished(self):
|
||||
self.setIconSize(self.normal_icon_size)
|
||||
self.icon_size = self.iconSize().width()
|
||||
|
||||
def enterEvent(self, ev):
|
||||
self.start_animation()
|
||||
@ -49,30 +53,27 @@ class ThrobbingButton(QToolButton):
|
||||
return
|
||||
if self.animation.state() != self.animation.Stopped or not self.isVisible():
|
||||
return
|
||||
size = self.normal_icon_size.width()
|
||||
size = self.iconSize().width()
|
||||
smaller = int(0.7 * size)
|
||||
self.animation.setStartValue(QSize(smaller, smaller))
|
||||
self.animation.setEndValue(self.normal_icon_size)
|
||||
self.animation.setStartValue(smaller)
|
||||
self.animation.setEndValue(size)
|
||||
QMetaObject.invokeMethod(self.animation, 'start', Qt.QueuedConnection)
|
||||
|
||||
def stop_animation(self):
|
||||
self.animation.stop()
|
||||
self.animation_finished()
|
||||
|
||||
def create_donate_widget(button):
|
||||
w = QWidget()
|
||||
w.setLayout(QVBoxLayout())
|
||||
w.layout().addWidget(button)
|
||||
if isosx:
|
||||
w.setStyleSheet('QWidget, QToolButton {background-color: none; border: none; }')
|
||||
w.layout().setContentsMargins(0,0,0,0)
|
||||
w.setContentsMargins(0,0,0,0)
|
||||
w.filler = QLabel(u'\u00a0')
|
||||
w.layout().addWidget(w.filler)
|
||||
return w
|
||||
def paintEvent(self, ev):
|
||||
size = self._icon_size if self._icon_size > 10 else self.iconSize().width()
|
||||
p = QPainter(self)
|
||||
opt = QStyleOptionToolButton()
|
||||
self.initStyleOption(opt)
|
||||
s = self.style()
|
||||
opt.iconSize = QSize(size, size)
|
||||
s.drawComplexControl(s.CC_ToolButton, opt, p, self)
|
||||
|
||||
if __name__ == '__main__':
|
||||
from PyQt5.Qt import QApplication, QHBoxLayout, QIcon
|
||||
from PyQt5.Qt import QApplication, QHBoxLayout
|
||||
app = QApplication([])
|
||||
w = QWidget()
|
||||
w.setLayout(QHBoxLayout())
|
||||
|
@ -22,7 +22,7 @@ from calibre.gui2 import elided_text, open_url
|
||||
from calibre.gui2.dbus_export.widgets import factory
|
||||
from calibre.gui2.keyboard import Manager as KeyboardManager
|
||||
from calibre.gui2.main_window import MainWindow
|
||||
from calibre.gui2.throbber import ThrobbingButton, create_donate_widget
|
||||
from calibre.gui2.throbber import ThrobbingButton
|
||||
from calibre.gui2.tweak_book import (
|
||||
current_container, tprefs, actions, capitalize, toolbar_actions, editors, update_mark_text_action)
|
||||
from calibre.gui2.tweak_book.file_list import FileListWidget
|
||||
@ -619,15 +619,10 @@ class Main(MainWindow):
|
||||
self.donate_button = b = ThrobbingButton(self)
|
||||
b.clicked.connect(open_donate)
|
||||
b.setAutoRaise(True)
|
||||
self.donate_widget = w = create_donate_widget(b)
|
||||
if hasattr(w, 'filler'):
|
||||
w.filler.setVisible(False)
|
||||
b.set_normal_icon_size(self.global_bar.iconSize().width(), self.global_bar.iconSize().height())
|
||||
b.setIcon(QIcon(I('donate.png')))
|
||||
b.setToolTip(_('Donate to support calibre development'))
|
||||
if animate:
|
||||
QTimer.singleShot(10, b.start_animation)
|
||||
bar.addWidget(w)
|
||||
bar.addWidget(b)
|
||||
else:
|
||||
try:
|
||||
bar.addAction(actions[ac])
|
||||
|
@ -269,7 +269,9 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
|
||||
self.toggle_to_tray_action = self.system_tray_menu.addAction(QIcon(I('page.png')), '')
|
||||
self.toggle_to_tray_action.triggered.connect(self.system_tray_icon_activated)
|
||||
self.system_tray_menu.addAction(self.donate_action)
|
||||
self.donate_button.setDefaultAction(self.donate_action)
|
||||
self.donate_button.clicked.connect(self.donate_action.trigger)
|
||||
self.donate_button.setToolTip(self.donate_action.text().replace('&', ''))
|
||||
self.donate_button.setIcon(self.donate_action.icon())
|
||||
self.donate_button.setStatusTip(self.donate_button.toolTip())
|
||||
self.eject_action = self.system_tray_menu.addAction(
|
||||
QIcon(I('eject.png')), _('&Eject connected device'))
|
||||
|
Loading…
x
Reference in New Issue
Block a user