Added a new "Menu Button" when the main menubar is hidden.

This button is very similar to Chrome browser's (wrench) button.
This commit is contained in:
Tvangeste 2012-12-29 19:46:43 +01:00
parent cb8724ce1c
commit e8cefa1330
6 changed files with 47 additions and 32 deletions

BIN
icons/menu_button.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 548 B

View file

@ -157,6 +157,31 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
navToolbar->addAction( 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<QMenu *> allMenus = menuBar()->findChildren<QMenu *>();
QListIterator<QMenu *> menuIter( allMenus );
while( menuIter.hasNext() )
{
QMenu * menu = menuIter.next();
QList<QAction *> allMenuActions = menu->actions();
QListIterator<QAction *> 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()

View file

@ -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<QWidget*> mruList;

View file

@ -446,6 +446,18 @@
<string>Ctrl+O</string>
</property>
</action>
<action name="menuOptions">
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/icons/menu_button.png</normaloff>:/icons/menu_button.png</iconset>
</property>
<property name="text">
<string>Menu Button</string>
</property>
<property name="toolTip">
<string>Menu Button</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View file

@ -9,6 +9,10 @@ MainWindow #translateLine[noResults="true"]
background: #febb7d;
}
#navToolbar #menuButton::menu-indicator {
image: none;
}
#navToolbar #translateLine
{
border: 1px solid gray;

View file

@ -55,5 +55,6 @@
<file>qt-style-st-babylon.css</file>
<file>icons/1downarrow.png</file>
<file>icons/system-search.png</file>
<file>icons/menu_button.png</file>
</qresource>
</RCC>