diff --git a/src/lib/navigation/navigationbar.cpp b/src/lib/navigation/navigationbar.cpp index 6c3edd8da..1f05458da 100644 --- a/src/lib/navigation/navigationbar.cpp +++ b/src/lib/navigation/navigationbar.cpp @@ -37,14 +37,6 @@ #include #include -static void setToolBarButtonIconSize(ToolButton* button) -{ - QStyleOption opt; - opt.initFrom(button); - int size = button->style()->pixelMetric(QStyle::PM_ToolBarIconSize, &opt, button); - button->setIconSize(QSize(size, size)); -} - NavigationBar::NavigationBar(BrowserWindow* window) : QWidget(window) , m_window(window) @@ -60,19 +52,19 @@ NavigationBar::NavigationBar(BrowserWindow* window) m_buttonBack->setObjectName("navigation-button-back"); m_buttonBack->setToolTip(tr("Back")); m_buttonBack->setToolButtonStyle(Qt::ToolButtonIconOnly); + m_buttonBack->setToolbarButtonLook(true); m_buttonBack->setAutoRaise(true); m_buttonBack->setEnabled(false); m_buttonBack->setFocusPolicy(Qt::NoFocus); - setToolBarButtonIconSize(m_buttonBack); m_buttonForward = new ToolButton(this); m_buttonForward->setObjectName("navigation-button-next"); m_buttonForward->setToolTip(tr("Forward")); m_buttonForward->setToolButtonStyle(Qt::ToolButtonIconOnly); + m_buttonForward->setToolbarButtonLook(true); m_buttonForward->setAutoRaise(true); m_buttonForward->setEnabled(false); m_buttonForward->setFocusPolicy(Qt::NoFocus); - setToolBarButtonIconSize(m_buttonForward); QHBoxLayout* backNextLayout = new QHBoxLayout(); backNextLayout->setContentsMargins(0, 0, 0, 0); @@ -81,24 +73,22 @@ NavigationBar::NavigationBar(BrowserWindow* window) backNextLayout->addWidget(m_buttonForward); m_reloadStop = new ReloadStopButton(this); - setToolBarButtonIconSize(m_reloadStop->buttonReload()); - setToolBarButtonIconSize(m_reloadStop->buttonStop()); m_buttonHome = new ToolButton(this); m_buttonHome->setObjectName("navigation-button-home"); m_buttonHome->setToolTip(tr("Home")); m_buttonHome->setToolButtonStyle(Qt::ToolButtonIconOnly); + m_buttonHome->setToolbarButtonLook(true); m_buttonHome->setAutoRaise(true); m_buttonHome->setFocusPolicy(Qt::NoFocus); - setToolBarButtonIconSize(m_buttonHome); m_buttonAddTab = new ToolButton(this); m_buttonAddTab->setObjectName("navigation-button-addtab"); m_buttonAddTab->setToolTip(tr("New Tab")); m_buttonAddTab->setToolButtonStyle(Qt::ToolButtonIconOnly); + m_buttonAddTab->setToolbarButtonLook(true); m_buttonAddTab->setAutoRaise(true); m_buttonAddTab->setFocusPolicy(Qt::NoFocus); - setToolBarButtonIconSize(m_buttonAddTab); m_menuBack = new Menu(this); m_menuBack->setCloseOnMiddleClick(true); @@ -114,12 +104,12 @@ NavigationBar::NavigationBar(BrowserWindow* window) m_supMenu = new ToolButton(this); m_supMenu->setObjectName("navigation-button-supermenu"); m_supMenu->setPopupMode(QToolButton::InstantPopup); + m_supMenu->setToolbarButtonLook(true); m_supMenu->setToolTip(tr("Main Menu")); m_supMenu->setAutoRaise(true); m_supMenu->setFocusPolicy(Qt::NoFocus); m_supMenu->setMenu(m_window->superMenu()); m_supMenu->setShowMenuInside(true); - setToolBarButtonIconSize(m_supMenu); #endif m_searchLine = new WebSearchBar(m_window); @@ -135,10 +125,10 @@ NavigationBar::NavigationBar(BrowserWindow* window) m_exitFullscreen->setObjectName("navigation-button-exitfullscreen"); m_exitFullscreen->setToolTip(tr("Exit Fullscreen")); m_exitFullscreen->setToolButtonStyle(Qt::ToolButtonIconOnly); + m_exitFullscreen->setToolbarButtonLook(true); m_exitFullscreen->setFocusPolicy(Qt::NoFocus); m_exitFullscreen->setAutoRaise(true); m_exitFullscreen->setVisible(false); - setToolBarButtonIconSize(m_exitFullscreen); m_layout->addLayout(backNextLayout); m_layout->addWidget(m_reloadStop); diff --git a/src/lib/navigation/reloadstopbutton.cpp b/src/lib/navigation/reloadstopbutton.cpp index f36b2a8d5..6c86b1c06 100644 --- a/src/lib/navigation/reloadstopbutton.cpp +++ b/src/lib/navigation/reloadstopbutton.cpp @@ -32,6 +32,7 @@ ReloadStopButton::ReloadStopButton(QWidget* parent) m_buttonStop->setObjectName("navigation-button-stop"); m_buttonStop->setToolTip(ToolButton::tr("Stop")); m_buttonStop->setToolButtonStyle(Qt::ToolButtonIconOnly); + m_buttonStop->setToolbarButtonLook(true); m_buttonStop->setVisible(false); m_buttonStop->setAutoRaise(true); m_buttonStop->setFocusPolicy(Qt::NoFocus); @@ -40,6 +41,7 @@ ReloadStopButton::ReloadStopButton(QWidget* parent) m_buttonReload->setObjectName("navigation-button-reload"); m_buttonReload->setToolTip(ToolButton::tr("Reload")); m_buttonReload->setToolButtonStyle(Qt::ToolButtonIconOnly); + m_buttonReload->setToolbarButtonLook(true); m_buttonReload->setAutoRaise(true); m_buttonReload->setFocusPolicy(Qt::NoFocus); @@ -52,6 +54,9 @@ ReloadStopButton::ReloadStopButton(QWidget* parent) m_updateTimer->setInterval(100); m_updateTimer->setSingleShot(true); connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updateButton())); + + connect(m_buttonStop, SIGNAL(clicked()), this, SIGNAL(stopClicked())); + connect(m_buttonReload, SIGNAL(clicked()), this, SIGNAL(reloadClicked())); } void ReloadStopButton::showStopButton() @@ -66,16 +71,6 @@ void ReloadStopButton::showReloadButton() m_updateTimer->start(); } -ToolButton* ReloadStopButton::buttonStop() const -{ - return m_buttonStop; -} - -ToolButton* ReloadStopButton::buttonReload() const -{ - return m_buttonReload; -} - void ReloadStopButton::updateButton() { setUpdatesEnabled(false); diff --git a/src/lib/navigation/reloadstopbutton.h b/src/lib/navigation/reloadstopbutton.h index 9a1750c4b..7738b1413 100644 --- a/src/lib/navigation/reloadstopbutton.h +++ b/src/lib/navigation/reloadstopbutton.h @@ -36,8 +36,9 @@ public: void showStopButton(); void showReloadButton(); - ToolButton* buttonStop() const; - ToolButton* buttonReload() const; +signals: + void stopClicked(); + void reloadClicked(); private slots: void updateButton(); diff --git a/src/lib/tools/toolbutton.cpp b/src/lib/tools/toolbutton.cpp index 317df629d..f0721b158 100644 --- a/src/lib/tools/toolbutton.cpp +++ b/src/lib/tools/toolbutton.cpp @@ -27,8 +27,6 @@ ToolButton::ToolButton(QWidget* parent) : QToolButton(parent) , m_menu(0) - , m_usingMultiIcon(false) - , m_showMenuInside(false) { setMinimumWidth(16); @@ -55,7 +53,7 @@ void ToolButton::setMultiIcon(const QPixmap &icon) m_activeIcon = icon.copy(0, h / 2, w, h / 4); m_disabledIcon = icon.copy(0, 3 * h / 4, w, h / 4); - m_usingMultiIcon = true; + m_options |= MultiIconOption; setFixedSize(m_normalIcon.size()); } @@ -72,15 +70,15 @@ void ToolButton::setThemeIcon(const QString &icon) QIcon ToolButton::icon() const { - return m_usingMultiIcon ? multiIcon() : QToolButton::icon(); + return m_options & MultiIconOption ? multiIcon() : QToolButton::icon(); } void ToolButton::setIcon(const QIcon &icon) { - if (m_usingMultiIcon) + if (m_options & MultiIconOption) setFixedSize(sizeHint()); - m_usingMultiIcon = false; + m_options &= ~MultiIconOption; QToolButton::setIcon(icon); } @@ -102,12 +100,35 @@ void ToolButton::setMenu(QMenu* menu) bool ToolButton::showMenuInside() const { - return m_showMenuInside; + return m_options & ShowMenuInsideOption; } -void ToolButton::setShowMenuInside(bool inside) +void ToolButton::setShowMenuInside(bool enable) { - m_showMenuInside = inside; + if (enable) + m_options |= ShowMenuInsideOption; + else + m_options &= ~ShowMenuInsideOption; +} + +bool ToolButton::toolbarButtonLook() const +{ + return m_options & ToolBarLookOption; +} + +void ToolButton::setToolbarButtonLook(bool enable) +{ + if (enable) { + m_options |= ToolBarLookOption; + + QStyleOption opt; + opt.initFrom(this); + int size = style()->pixelMetric(QStyle::PM_ToolBarIconSize, &opt, this); + setIconSize(QSize(size, size)); + } + else { + m_options &= ~ToolBarLookOption; + } } void ToolButton::menuAboutToHide() @@ -125,7 +146,7 @@ void ToolButton::showMenu() QPoint pos; - if (m_showMenuInside) { + if (m_options & ShowMenuInsideOption) { pos = mapToGlobal(rect().bottomRight()); if (QApplication::layoutDirection() == Qt::RightToLeft) pos.setX(pos.x() - rect().width()); @@ -185,7 +206,7 @@ void ToolButton::mouseDoubleClickEvent(QMouseEvent* e) void ToolButton::paintEvent(QPaintEvent* e) { - if (!m_usingMultiIcon) { + if (!(m_options & MultiIconOption)) { QToolButton::paintEvent(e); return; } diff --git a/src/lib/tools/toolbutton.h b/src/lib/tools/toolbutton.h index 06ca91e86..e07047c17 100644 --- a/src/lib/tools/toolbutton.h +++ b/src/lib/tools/toolbutton.h @@ -57,14 +57,19 @@ public: // Align the right corner of menu to the right corner of button bool showMenuInside() const; - void setShowMenuInside(bool inside); + void setShowMenuInside(bool enable); + + // Set the button to look as it was in toolbar + // (it now only sets the correct icon size) + bool toolbarButtonLook() const; + void setToolbarButtonLook(bool enable); signals: void middleMouseClicked(); void controlClicked(); void doubleClicked(); - // It is needed to use these signals with showMenuInsied + // It is needed to use these signals with ShowMenuInside void aboutToShowMenu(); void aboutToHideMenu(); @@ -87,8 +92,13 @@ private: QTimer m_pressTimer; QMenu* m_menu; - bool m_usingMultiIcon; - bool m_showMenuInside; + enum Options { + MultiIconOption = 1, + ShowMenuInsideOption = 2, + ToolBarLookOption = 4 + }; + Q_DECLARE_FLAGS(OptionsFlags, Options) + QFlags m_options; }; #endif // TOOLBUTTON_H