# # # add_file "src/view/MenuBar.cpp" # content [1ae093a261a7338c10562a077b35dc1d080b1654] # # add_file "src/view/MenuBar.h" # content [89b6a0583ccb10a54ec519c3a3567d2a8f751d18] # ============================================================ --- src/view/MenuBar.cpp 1ae093a261a7338c10562a077b35dc1d080b1654 +++ src/view/MenuBar.cpp 1ae093a261a7338c10562a077b35dc1d080b1654 @@ -0,0 +1,227 @@ +/*************************************************************************** + * Copyright (C) 2007 by Thomas Keller * + * address@hidden * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "MenuBar.h" + +#include "Settings.h" +#include "Guitone.h" + +MenuBar::MenuBar() : QMenuBar(0) +{ + // ensure that the shortcut keys are properly recognized by linguist + QShortcut::tr("Ctrl"); + QShortcut::tr("Alt"); + QShortcut::tr("Shift"); + QShortcut::tr("Meta"); + + // + // The File menu + // + actionOpen_Workspace = new QAction(tr("Open Workspace"), this); + actionOpen_Workspace->setShortcut(tr("Ctrl+O")); + actionOpen_Database = new QAction(tr("Open Database"), this); + actionOpen_Database->setShortcut(tr("Ctrl+Shift+O")); + actionPreferences = new QAction(tr("Preferences..."), this); + actionPreferences->setMenuRole(QAction::PreferencesRole); + actionPreferences->setShortcut(tr("Ctrl+P")); + actionCheck_for_updates = new QAction(tr("Check for updates"), this); + actionClose = new QAction(tr("Close"), this); + actionClose->setShortcut(tr("Ctrl+W")); + actionQuit = new QAction(tr("Quit"), this); + actionQuit->setShortcut(tr("Ctrl+Q")); + + menuFile = new QMenu(tr("File"), this); + menuRecent_Databases = new QMenu(tr("Recent Databases"), menuFile); + menuRecent_Workspaces = new QMenu(tr("Recent Workspaces"), menuFile); + + menuFile->addAction(actionOpen_Workspace); + menuFile->addAction(menuRecent_Workspaces->menuAction()); + menuFile->addSeparator(); + menuFile->addAction(actionOpen_Database); + menuFile->addAction(menuRecent_Databases->menuAction()); + menuFile->addSeparator(); + menuFile->addAction(actionPreferences); + menuFile->addAction(actionCheck_for_updates); + menuFile->addSeparator(); + menuFile->addAction(actionClose); + menuFile->addAction(actionQuit); + + // + // The Window menu + // + actionBring_all_to_front = new QAction(tr("Bring all to front"), this); + + menuWindow = new QMenu(tr("Window"), this); + + menuWindow->addAction(actionBring_all_to_front); + menuWindow->addSeparator(); + + // The Help menu + // + actionAbout_Qt = new QAction(tr("About Qt"), this); + actionAbout_Qt->setMenuRole(QAction::AboutQtRole); + actionAbout_guitone = new QAction(tr("About guitone"), this); + actionAbout_guitone->setMenuRole(QAction::AboutRole); + + menuHelp = new QMenu(tr("Help"), this); + + menuHelp->addAction(actionAbout_Qt); + menuHelp->addAction(actionAbout_guitone); + + // add the created menus to this menu bar + addAction(menuFile->menuAction()); + addAction(menuHelp->menuAction()); + + connect( + actionQuit, SIGNAL(triggered()), + APP, SIGNAL(quit()) + ); + + connect( + actionAbout_Qt, SIGNAL(triggered()), + APP, SLOT(aboutQt()) + ); + + connect( + actionPreferences, SIGNAL(triggered()), + this, SIGNAL(showPreferences()) + ); + + connect( + actionCheck_for_updates, SIGNAL(triggered()), + this, SIGNAL(doUpdateCheck()) + ); + + connect( + actionClose, SIGNAL(triggered()), + this, SIGNAL(closeWindow()) + ); + + connect( + actionBring_all_to_front, SIGNAL(triggered()), + this, SIGNAL(bringAllWindowsToFront()) + ); + + updateRecentLists(); + updateWindowList(); +} + +MenuBar::~MenuBar() {} + +void MainWindow::updateRecentLists() +{ + menuRecentWorkspaces->clear(); + menuRecentDatabases->clear(); + + QStringList previousWs = Settings::getItemList("RecentWorkspaceList"); + int elemCount = previousWs.size(); + if (elemCount == 0) + { + menuRecentWorkspaces->addAction(tr("No previous workspaces available.")); + } + else + { + QAction * act; + for (int i = 0; i < elemCount; ++i) + { + act = menuRecentWorkspaces->addAction( + tr("&%1 %2").arg(i + 1).arg(previousWs[i]), + this, + SLOT(openRecentWorkspace()) + ); + act->setData(previousWs[i]); + } + } + + QStringList previousDb = Settings::getItemList("RecentDatabaseList"); + elemCount = previousDb.size(); + if (elemCount == 0) + { + menuRecentDatabases->addAction(tr("No previous databases available.")); + } + else + { + QAction * act; + for (int i = 0; i < elemCount; ++i) + { + act = menuRecentDatabases->addAction( + tr("&%1 %2").arg(i + 1).arg(previousDb[i]), + this, + SLOT(openRecentDatabase()) + ); + act->setData(previousDb[i]); + } + } +} + +void MenuBar::openRecentWorkspace() +{ + QAction * action = qobject_cast(sender()); + emit loadWorkspace(action->data().toString()); +} + +void MenuBar::openRecentDatabase() +{ + QAction * action = qobject_cast(sender()); + emit loadDatabase(action->data().toString()); +} + +void MenuBar::updateWindowList() +{ + // remove old actions + QList actions = menuWindow->actions(); + for (int i=0, j=actions.size(); idata().isValid()) + { + menuWindow->removeAction(act); + } + } + + // TODO: we should integrate a small indicator which window is actually + // active here, but this needs central work in the App + QStringList list = APP->windowTitleList(); + for (int i=0, j=list.size(); iaddAction( + tr("&%1 %2").arg(i + 1).arg(list.at(i)), + this, + SLOT(activateOtherWindow()) + ); + act->setData(i); + } +} + +void MenuBar::activateOtherWindow() +{ + // FIXME: the list of windows is not constant, theoretically it might + // be possible that we've just been notified to raise a window which + // was just removed. Since we can't / won't transport pointers around + // we try to identify the window by its index in the windowList again, + // if this fails, we do nothing. It might occur that we raise the wrong + // window by this, of course, but all this is better than the alternatives. + QAction * action = qobject_cast(sender()); + if (action) + { + emit doActivateOtherWindow(action->data().toInt()); + } +} + ============================================================ --- src/view/MenuBar.h 89b6a0583ccb10a54ec519c3a3567d2a8f751d18 +++ src/view/MenuBar.h 89b6a0583ccb10a54ec519c3a3567d2a8f751d18 @@ -0,0 +1,76 @@ +/*************************************************************************** + * Copyright (C) 2007 by Thomas Keller * + * address@hidden * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef MENU_BAR_H +#define MENU_BAR_H + +#include + +class MenuBar : public QMenuBar +{ + Q_OBJECT +public: + MenuBar(); + ~MenuBar(); + +public slots: + void updateRecentLists(); + void updateWindowList(); + +signals: + void loadWorkspace(const QString &); + void loadDatabase(const QString &); + void showPreferences(); + void doUpdateCheck(); + void closeWindow(); + void doActivateOtherWindow(int); + void bringAllWindowsToFront(); + +public: + QAction * actionOpen_Database; + QAction * actionOpen_Workspace; + QAction * actionPreferences; + QAction * actionCheck_for_updates; + QAction * actionClose; + QAction * actionQuit; + QAction * actionBring_all_to_front; + QAction * actionAbout_Qt; + QAction * actionAbout_guitone; + + QMenu * menuFile; + QMenu * menuRecent_Databases; + QMenu * menuRecent_Workspaces; + QMenu * menuWindow; + QMenu * menuHelp; + +private slots: + void on_actionOpen_Workspace_triggered(); + void on_actionOpen_Database_triggered(); + void on_actionPreferences_triggered(); + void on_actionAbout_guitone_triggered(); + void on_actionCheck_for_updates_triggered(); + + void openRecentDatabase(); + void openRecentWorkspace(); + void activateOtherWindow(); +}; + +#endif +