From e8cefa133078a80607a7073c5be52688b72c1c56 Mon Sep 17 00:00:00 2001 From: Tvangeste Date: Sat, 29 Dec 2012 19:46:43 +0100 Subject: [PATCH] Added a new "Menu Button" when the main menubar is hidden. This button is very similar to Chrome browser's (wrench) button. --- icons/menu_button.png | Bin 0 -> 548 bytes mainwindow.cc | 57 ++++++++++++++++++++---------------------- mainwindow.hh | 5 ++-- mainwindow.ui | 12 +++++++++ qt-style.css | 4 +++ resources.qrc | 1 + 6 files changed, 47 insertions(+), 32 deletions(-) create mode 100644 icons/menu_button.png diff --git a/icons/menu_button.png b/icons/menu_button.png new file mode 100644 index 0000000000000000000000000000000000000000..142b3777f7970ecdc16680fac682088359f0a536 GIT binary patch literal 548 zcmV+<0^9wGP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02y>eSaefwW^{L9 za%BKeVQFr3E>1;MAa*k@H7+*LgRNQs00ERqL_t(&L+w|=PJ=)Y?Lkf^!husYrPPCo zG(b{~jRMiyKhV~A&@{wP;8Q%9_z|8w_KP@Z)1=pRheC>5x`(>-;%oAf$ui9Bdr;nN zqk$h3fC5ke3P1rU00q=4kR-{zX_{{by79&FO);&BU5Y$?na6ZPEwY-D{*|m5V_K_a zy&ttKc5>=upxCzUSAK1;xJk@&T#q@fuNdCO{u>_|-@@B1nx%TPm#d* z;qgNxAm-IcK&`4>HkmEi_ zkgxsv6PNNvJbvPMRt&01wb%Mfzq|B>A+_@j5*dm$@upJVA&;$^K(#CTt2GZ)Q>Xx( zSeYZkiI?L6ocND(5(x+=h7)h^)No>j7P+HRaAG*|>U@neaWP8ZOuXedfirPFLf}li mBMUaddAction( ui.print ); navToolbar->widgetForAction( ui.print )->setObjectName( "printButton" ); + beforeOptionsSeparator = navToolbar->addSeparator(); + navToolbar->widgetForAction( beforeOptionsSeparator )->setObjectName( "beforeOptionsSeparator" ); + beforeOptionsSeparator->setVisible( cfg.preferences.hideMenubar); + + QMenu * buttonMenu = new QMenu( this ); + buttonMenu->addAction( ui.dictionaries ); + buttonMenu->addAction( ui.preferences ); + buttonMenu->addSeparator(); + buttonMenu->addMenu( ui.menuHistory ); + buttonMenu->addSeparator(); + buttonMenu->addMenu( ui.menuFile ); + buttonMenu->addMenu( ui.menuView ); + buttonMenu->addMenu( ui.menu_Help ); + + QToolButton * menuButton = new QToolButton( navToolbar ); + menuButton->setPopupMode( QToolButton::InstantPopup ); + menuButton->setMenu( buttonMenu ); + menuButton->setIcon( QIcon (":/icons/menu_button.png") ); + menuButton->addAction( ui.menuOptions ); + menuButton->setToolTip( tr( "Menu Button" ) ); + menuButton->setObjectName( "menuButton" ); + + menuButtonAction = navToolbar->addWidget(menuButton); + menuButtonAction->setVisible( cfg.preferences.hideMenubar ); + // Make the search pane's titlebar groupLabel.setText( tr( "Look up in:" ) ); groupListInDock = new GroupComboBox( &searchPaneTitleBar ); @@ -2616,37 +2641,9 @@ void MainWindow::toggleMenuBarTriggered(bool announce) } } - // Obtain from the menubar all the actions with shortcuts - // and either add them to the main window or remove them, - // depending on the menubar state. - - QList allMenus = menuBar()->findChildren(); - QListIterator menuIter( allMenus ); - while( menuIter.hasNext() ) - { - QMenu * menu = menuIter.next(); - QList allMenuActions = menu->actions(); - QListIterator actionsIter( allMenuActions ); - while( actionsIter.hasNext() ) - { - QAction * action = actionsIter.next(); - if ( !action->shortcut().isEmpty() ) - { - if ( cfg.preferences.hideMenubar ) - { - // add all menubar actions to the main window, - // before we hide the menubar - addAction( action ); - } - else - { - // remove all menubar actions from the main window - removeAction( action ); - } - } - } - } menuBar()->setVisible( !cfg.preferences.hideMenubar ); + beforeOptionsSeparator->setVisible( cfg.preferences.hideMenubar); + menuButtonAction->setVisible( cfg.preferences.hideMenubar ); } void MainWindow::on_clearHistory_triggered() diff --git a/mainwindow.hh b/mainwindow.hh index 1e7491dd..0a657ea4 100644 --- a/mainwindow.hh +++ b/mainwindow.hh @@ -109,11 +109,12 @@ private: QToolBar * navToolbar; MainStatusBar * mainStatusBar; QAction * navBack, * navForward, * navPronounce, * enableScanPopup; - QAction * beforeScanPopupSeparator, * afterScanPopupSeparator; + QAction * beforeScanPopupSeparator, * afterScanPopupSeparator, * beforeOptionsSeparator; QAction * zoomIn, * zoomOut, * zoomBase; QAction * wordsZoomIn, * wordsZoomOut, * wordsZoomBase; QMenu trayIconMenu; - QMenu *tabMenu; + QMenu * tabMenu; + QAction * menuButtonAction; MRUQMenu *tabListMenu; //List that contains indexes of tabs arranged in a most-recently-used order QList mruList; diff --git a/mainwindow.ui b/mainwindow.ui index e56d780c..3146b704 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -446,6 +446,18 @@ Ctrl+O + + + + :/icons/menu_button.png:/icons/menu_button.png + + + Menu Button + + + Menu Button + + diff --git a/qt-style.css b/qt-style.css index 6607c373..aecba1da 100644 --- a/qt-style.css +++ b/qt-style.css @@ -9,6 +9,10 @@ MainWindow #translateLine[noResults="true"] background: #febb7d; } +#navToolbar #menuButton::menu-indicator { + image: none; +} + #navToolbar #translateLine { border: 1px solid gray; diff --git a/resources.qrc b/resources.qrc index 51067499..2ae829b3 100644 --- a/resources.qrc +++ b/resources.qrc @@ -55,5 +55,6 @@ qt-style-st-babylon.css icons/1downarrow.png icons/system-search.png + icons/menu_button.png