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)
|
QTimer, QPropertyAnimation, QEasingCurve, pyqtProperty, QPainter, QWidget)
|
||||||
|
|
||||||
from calibre.constants import isosx
|
from calibre.constants import isosx
|
||||||
from calibre.gui2.throbber import create_donate_widget
|
|
||||||
from calibre.gui2 import gprefs, native_menubar_defaults, config
|
from calibre.gui2 import gprefs, native_menubar_defaults, config
|
||||||
|
|
||||||
class RevealBar(QWidget): # {{{
|
class RevealBar(QWidget): # {{{
|
||||||
@ -83,8 +82,7 @@ class ToolBar(QToolBar): # {{{
|
|||||||
QToolBar.resizeEvent(self, ev)
|
QToolBar.resizeEvent(self, ev)
|
||||||
style = self.get_text_style()
|
style = self.get_text_style()
|
||||||
self.setToolButtonStyle(style)
|
self.setToolButtonStyle(style)
|
||||||
if hasattr(self, 'd_widget') and hasattr(self.d_widget, 'filler'):
|
self.donate_button.setToolButtonStyle(style)
|
||||||
self.d_widget.filler.setVisible(style != Qt.ToolButtonIconOnly)
|
|
||||||
|
|
||||||
def get_text_style(self):
|
def get_text_style(self):
|
||||||
style = Qt.ToolButtonTextUnderIcon
|
style = Qt.ToolButtonTextUnderIcon
|
||||||
@ -134,8 +132,7 @@ class ToolBar(QToolBar): # {{{
|
|||||||
bar.setup_tool_button(bar, ac, QToolButton.MenuButtonPopup)
|
bar.setup_tool_button(bar, ac, QToolButton.MenuButtonPopup)
|
||||||
ac.setVisible(False)
|
ac.setVisible(False)
|
||||||
elif what == 'Donate':
|
elif what == 'Donate':
|
||||||
self.d_widget = create_donate_widget(self.donate_button)
|
bar.addWidget(self.donate_button)
|
||||||
bar.addWidget(self.d_widget)
|
|
||||||
self.showing_donate = True
|
self.showing_donate = True
|
||||||
elif what in self.gui.iactions:
|
elif what in self.gui.iactions:
|
||||||
action = self.gui.iactions[what]
|
action = self.gui.iactions[what]
|
||||||
@ -550,6 +547,7 @@ class BarsManager(QObject):
|
|||||||
for bar in self.bars:
|
for bar in self.bars:
|
||||||
bar.setIconSize(QSize(sz, sz))
|
bar.setIconSize(QSize(sz, sz))
|
||||||
bar.setToolButtonStyle(style)
|
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
|
#!/usr/bin/env python2
|
||||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
# 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'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
|
|
||||||
from PyQt5.Qt import QToolButton, QSize, QPropertyAnimation, Qt, \
|
from PyQt5.Qt import (
|
||||||
QMetaObject, QLabel, QVBoxLayout, QWidget
|
QToolButton, QSize, QPropertyAnimation, Qt, QMetaObject, pyqtProperty,
|
||||||
|
QWidget, QIcon, QPainter, QStyleOptionToolButton)
|
||||||
|
|
||||||
from calibre.constants import isosx
|
|
||||||
from calibre.gui2 import config
|
from calibre.gui2 import config
|
||||||
|
|
||||||
class ThrobbingButton(QToolButton):
|
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):
|
def __init__(self, *args):
|
||||||
QToolButton.__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.setDuration(60/72.*1000)
|
||||||
self.animation.setLoopCount(4)
|
self.animation.setLoopCount(4)
|
||||||
self.normal_icon_size = QSize(64, 64)
|
|
||||||
self.animation.valueChanged.connect(self.value_changed)
|
self.animation.valueChanged.connect(self.value_changed)
|
||||||
self.setCursor(Qt.PointingHandCursor)
|
self.setCursor(Qt.PointingHandCursor)
|
||||||
self.animation.finished.connect(self.animation_finished)
|
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):
|
def animation_finished(self):
|
||||||
self.setIconSize(self.normal_icon_size)
|
self.icon_size = self.iconSize().width()
|
||||||
|
|
||||||
def enterEvent(self, ev):
|
def enterEvent(self, ev):
|
||||||
self.start_animation()
|
self.start_animation()
|
||||||
@ -49,30 +53,27 @@ class ThrobbingButton(QToolButton):
|
|||||||
return
|
return
|
||||||
if self.animation.state() != self.animation.Stopped or not self.isVisible():
|
if self.animation.state() != self.animation.Stopped or not self.isVisible():
|
||||||
return
|
return
|
||||||
size = self.normal_icon_size.width()
|
size = self.iconSize().width()
|
||||||
smaller = int(0.7 * size)
|
smaller = int(0.7 * size)
|
||||||
self.animation.setStartValue(QSize(smaller, smaller))
|
self.animation.setStartValue(smaller)
|
||||||
self.animation.setEndValue(self.normal_icon_size)
|
self.animation.setEndValue(size)
|
||||||
QMetaObject.invokeMethod(self.animation, 'start', Qt.QueuedConnection)
|
QMetaObject.invokeMethod(self.animation, 'start', Qt.QueuedConnection)
|
||||||
|
|
||||||
def stop_animation(self):
|
def stop_animation(self):
|
||||||
self.animation.stop()
|
self.animation.stop()
|
||||||
self.animation_finished()
|
self.animation_finished()
|
||||||
|
|
||||||
def create_donate_widget(button):
|
def paintEvent(self, ev):
|
||||||
w = QWidget()
|
size = self._icon_size if self._icon_size > 10 else self.iconSize().width()
|
||||||
w.setLayout(QVBoxLayout())
|
p = QPainter(self)
|
||||||
w.layout().addWidget(button)
|
opt = QStyleOptionToolButton()
|
||||||
if isosx:
|
self.initStyleOption(opt)
|
||||||
w.setStyleSheet('QWidget, QToolButton {background-color: none; border: none; }')
|
s = self.style()
|
||||||
w.layout().setContentsMargins(0,0,0,0)
|
opt.iconSize = QSize(size, size)
|
||||||
w.setContentsMargins(0,0,0,0)
|
s.drawComplexControl(s.CC_ToolButton, opt, p, self)
|
||||||
w.filler = QLabel(u'\u00a0')
|
|
||||||
w.layout().addWidget(w.filler)
|
|
||||||
return w
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from PyQt5.Qt import QApplication, QHBoxLayout, QIcon
|
from PyQt5.Qt import QApplication, QHBoxLayout
|
||||||
app = QApplication([])
|
app = QApplication([])
|
||||||
w = QWidget()
|
w = QWidget()
|
||||||
w.setLayout(QHBoxLayout())
|
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.dbus_export.widgets import factory
|
||||||
from calibre.gui2.keyboard import Manager as KeyboardManager
|
from calibre.gui2.keyboard import Manager as KeyboardManager
|
||||||
from calibre.gui2.main_window import MainWindow
|
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 (
|
from calibre.gui2.tweak_book import (
|
||||||
current_container, tprefs, actions, capitalize, toolbar_actions, editors, update_mark_text_action)
|
current_container, tprefs, actions, capitalize, toolbar_actions, editors, update_mark_text_action)
|
||||||
from calibre.gui2.tweak_book.file_list import FileListWidget
|
from calibre.gui2.tweak_book.file_list import FileListWidget
|
||||||
@ -619,15 +619,10 @@ class Main(MainWindow):
|
|||||||
self.donate_button = b = ThrobbingButton(self)
|
self.donate_button = b = ThrobbingButton(self)
|
||||||
b.clicked.connect(open_donate)
|
b.clicked.connect(open_donate)
|
||||||
b.setAutoRaise(True)
|
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'))
|
b.setToolTip(_('Donate to support calibre development'))
|
||||||
if animate:
|
if animate:
|
||||||
QTimer.singleShot(10, b.start_animation)
|
QTimer.singleShot(10, b.start_animation)
|
||||||
bar.addWidget(w)
|
bar.addWidget(b)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
bar.addAction(actions[ac])
|
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 = self.system_tray_menu.addAction(QIcon(I('page.png')), '')
|
||||||
self.toggle_to_tray_action.triggered.connect(self.system_tray_icon_activated)
|
self.toggle_to_tray_action.triggered.connect(self.system_tray_icon_activated)
|
||||||
self.system_tray_menu.addAction(self.donate_action)
|
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.donate_button.setStatusTip(self.donate_button.toolTip())
|
||||||
self.eject_action = self.system_tray_menu.addAction(
|
self.eject_action = self.system_tray_menu.addAction(
|
||||||
QIcon(I('eject.png')), _('&Eject connected device'))
|
QIcon(I('eject.png')), _('&Eject connected device'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user