This commit is contained in:
Kovid Goyal 2011-04-09 10:33:08 -06:00
commit 6985db62be

View File

@ -308,22 +308,46 @@ class MenuBar(QMenuBar): # {{{
ac.setMenu(m) ac.setMenu(m)
return ac return ac
# }}} # }}}
class ToolBar(QToolBar): # {{{ class BaseToolBar(QToolBar): # {{{
def __init__(self, donate, location_manager, child_bar, parent): def __init__(self, parent):
QToolBar.__init__(self, parent) QToolBar.__init__(self, parent)
self.gui = parent
self.child_bar = child_bar
self.setContextMenuPolicy(Qt.PreventContextMenu) self.setContextMenuPolicy(Qt.PreventContextMenu)
self.setMovable(False) self.setMovable(False)
self.setFloatable(False) self.setFloatable(False)
self.setOrientation(Qt.Horizontal) self.setOrientation(Qt.Horizontal)
self.setAllowedAreas(Qt.TopToolBarArea|Qt.BottomToolBarArea) self.setAllowedAreas(Qt.TopToolBarArea|Qt.BottomToolBarArea)
self.setStyleSheet('QToolButton:checked { font-weight: bold }') self.setStyleSheet('QToolButton:checked { font-weight: bold }')
def resizeEvent(self, ev):
QToolBar.resizeEvent(self, ev)
style = self.get_text_style()
self.setToolButtonStyle(style)
def get_text_style(self):
style = Qt.ToolButtonTextUnderIcon
s = gprefs['toolbar_icon_size']
if s != 'off':
p = gprefs['toolbar_text']
if p == 'never':
style = Qt.ToolButtonIconOnly
elif p == 'auto' and self.sizeHint().width() > self.width()+35:
style = Qt.ToolButtonIconOnly
return style
def contextMenuEvent(self, *args):
pass
# }}}
class ToolBar(BaseToolBar): # {{{
def __init__(self, donate, location_manager, child_bar, parent):
BaseToolBar.__init__(self, parent)
self.gui = parent
self.child_bar = child_bar
self.donate_button = donate self.donate_button = donate
self.apply_settings() self.apply_settings()
@ -333,7 +357,6 @@ class ToolBar(QToolBar): # {{{
donate.setCursor(Qt.PointingHandCursor) donate.setCursor(Qt.PointingHandCursor)
self.added_actions = [] self.added_actions = []
self.build_bar() self.build_bar()
self.preferred_width = self.sizeHint().width()
self.setAcceptDrops(True) self.setAcceptDrops(True)
def apply_settings(self): def apply_settings(self):
@ -348,9 +371,6 @@ class ToolBar(QToolBar): # {{{
self.child_bar.setToolButtonStyle(style) self.child_bar.setToolButtonStyle(style)
self.donate_button.set_normal_icon_size(sz, sz) self.donate_button.set_normal_icon_size(sz, sz)
def contextMenuEvent(self, *args):
pass
def build_bar(self): def build_bar(self):
self.showing_donate = False self.showing_donate = False
showing_device = self.location_manager.has_device showing_device = self.location_manager.has_device
@ -405,21 +425,6 @@ class ToolBar(QToolBar): # {{{
ch.setPopupMode(menu_mode) ch.setPopupMode(menu_mode)
return ch return ch
def resizeEvent(self, ev):
QToolBar.resizeEvent(self, ev)
style = Qt.ToolButtonTextUnderIcon
s = gprefs['toolbar_icon_size']
if s != 'off':
p = gprefs['toolbar_text']
if p == 'never':
style = Qt.ToolButtonIconOnly
if p == 'auto' and self.preferred_width > self.width()+35 and \
not gprefs['action-layout-toolbar-child']:
style = Qt.ToolButtonIconOnly
self.setToolButtonStyle(style)
def database_changed(self, db): def database_changed(self, db):
pass pass
@ -497,7 +502,7 @@ class MainWindowMixin(object): # {{{
self.iactions['Fetch News'].init_scheduler(db) self.iactions['Fetch News'].init_scheduler(db)
self.search_bar = SearchBar(self) self.search_bar = SearchBar(self)
self.child_bar = QToolBar(self) self.child_bar = BaseToolBar(self)
self.tool_bar = ToolBar(self.donate_button, self.tool_bar = ToolBar(self.donate_button,
self.location_manager, self.child_bar, self) self.location_manager, self.child_bar, self)
self.addToolBar(Qt.TopToolBarArea, self.tool_bar) self.addToolBar(Qt.TopToolBarArea, self.tool_bar)