From 195880807e99eb08a84dd1e1e3817d57d562a217 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Mon, 15 Jun 2009 00:48:16 +0300 Subject: [PATCH] GUI: Refactor menu and toolbar creation to own methods. --- gui/mainwindow.cpp | 111 +++++++++++++++++++++++++-------------------- gui/mainwindow.h | 10 ++++ 2 files changed, 72 insertions(+), 49 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 07f59206c..1034f1b41 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -54,43 +54,8 @@ MainWindow::MainWindow() : mActionSave(tr("Save results to a file"), this), mResults(mSettings, mApplications) { - QMenu *menu = menuBar()->addMenu(tr("&File")); - menu->addAction(&mActionCheckFiles); - menu->addAction(&mActionCheckDirectory); - menu->addAction(&mActionReCheck); - menu->addAction(&mActionStop); - menu->addAction(&mActionClearResults); - menu->addAction(&mActionSave); - menu->addSeparator(); - menu->addAction(&mActionExit); - - QMenu *menuview = menuBar()->addMenu(tr("&View")); - mActionShowAll.setCheckable(true); - mActionShowSecurity.setCheckable(true); - mActionShowStyle.setCheckable(true); - mActionShowUnused.setCheckable(true); - mActionShowErrors.setCheckable(true); - - menuview->addAction(&mActionShowAll); - menuview->addAction(&mActionShowSecurity); - menuview->addAction(&mActionShowStyle); - menuview->addAction(&mActionShowUnused); - menuview->addAction(&mActionShowErrors); - menuview->addSeparator(); - menuview->addAction(&mActionShowCheckAll); - menuview->addAction(&mActionShowUncheckAll); - menuview->addSeparator(); - menuview->addAction(&mActionShowCollapseAll); - menuview->addAction(&mActionShowExpandAll); - - QMenu *menuprogram = menuBar()->addMenu(tr("&Program")); - menuprogram->addAction(&mActionSettings); - - QMenu *menuHelp = menuBar()->addMenu(tr("&Help")); - menuHelp->addAction(&mActionShowLicense); - menuHelp->addAction(&mActionShowAuthors); - menuHelp->addSeparator(); - menuHelp->addAction(&mActionAbout); + CreateMenus(); + CreateToolbar(); setCentralWidget(&mResults); @@ -118,13 +83,10 @@ MainWindow::MainWindow() : connect(&mActionAbout, SIGNAL(triggered()), this, SLOT(About())); connect(&mActionShowLicense, SIGNAL(triggered()), this, SLOT(ShowLicense())); connect(&mActionShowAuthors, SIGNAL(triggered()), this, SLOT(ShowAuthors())); + connect(&mThread, SIGNAL(Done()), this, SLOT(CheckDone())); connect(&mResults, SIGNAL(GotResults()), this, SLOT(ResultsAdded())); - //Toolbar - QToolBar *toolbar = addToolBar("Toolbar"); - toolbar->setIconSize(QSize(22, 22)); - mActionCheckDirectory.setIcon(QIcon(":icon.png")); mActionReCheck.setIcon(QIcon(":images/view-refresh.png")); mActionSettings.setIcon(QIcon(":images/preferences-system.png")); @@ -133,14 +95,6 @@ MainWindow::MainWindow() : mActionSave.setIcon(QIcon(":images/media-floppy.png")); mActionClearResults.setIcon(QIcon(":images/edit-clear.png")); - toolbar->addAction(&mActionCheckDirectory); - toolbar->addAction(&mActionSave); - toolbar->addAction(&mActionReCheck); - toolbar->addAction(&mActionStop); - toolbar->addAction(&mActionClearResults); - toolbar->addAction(&mActionSettings); - toolbar->addAction(&mActionAbout); - mActionReCheck.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R)); mActionCheckDirectory.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D)); mActionSave.setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S)); @@ -161,6 +115,65 @@ MainWindow::~MainWindow() SaveSettings(); } +void MainWindow::CreateMenus() +{ + // File-menu + QMenu *menu = menuBar()->addMenu(tr("&File")); + menu->addAction(&mActionCheckFiles); + menu->addAction(&mActionCheckDirectory); + menu->addAction(&mActionReCheck); + menu->addAction(&mActionStop); + menu->addAction(&mActionClearResults); + menu->addAction(&mActionSave); + menu->addSeparator(); + menu->addAction(&mActionExit); + + // View-menu + QMenu *menuview = menuBar()->addMenu(tr("&View")); + menuview->addAction(&mActionShowAll); + menuview->addAction(&mActionShowSecurity); + menuview->addAction(&mActionShowStyle); + menuview->addAction(&mActionShowUnused); + menuview->addAction(&mActionShowErrors); + menuview->addSeparator(); + menuview->addAction(&mActionShowCheckAll); + menuview->addAction(&mActionShowUncheckAll); + menuview->addSeparator(); + menuview->addAction(&mActionShowCollapseAll); + menuview->addAction(&mActionShowExpandAll); + + mActionShowAll.setCheckable(true); + mActionShowSecurity.setCheckable(true); + mActionShowStyle.setCheckable(true); + mActionShowUnused.setCheckable(true); + mActionShowErrors.setCheckable(true); + + // Program-menu + QMenu *menuprogram = menuBar()->addMenu(tr("&Program")); + menuprogram->addAction(&mActionSettings); + + // Help-menu + QMenu *menuHelp = menuBar()->addMenu(tr("&Help")); + menuHelp->addAction(&mActionShowLicense); + menuHelp->addAction(&mActionShowAuthors); + menuHelp->addSeparator(); + menuHelp->addAction(&mActionAbout); +} + +void MainWindow::CreateToolbar() +{ + QToolBar *toolbar = addToolBar("Toolbar"); + toolbar->setIconSize(QSize(22, 22)); + + toolbar->addAction(&mActionCheckDirectory); + toolbar->addAction(&mActionSave); + toolbar->addAction(&mActionReCheck); + toolbar->addAction(&mActionStop); + toolbar->addAction(&mActionClearResults); + toolbar->addAction(&mActionSettings); + toolbar->addAction(&mActionAbout); +} + void MainWindow::LoadSettings() { if (mSettings.value(tr("Window maximized"), false).toBool()) diff --git a/gui/mainwindow.h b/gui/mainwindow.h index d5fdc82e2..3c7d78133 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -152,6 +152,16 @@ protected slots: void ResultsAdded(); protected: + /** + * @brief Create main window menus. + */ + void CreateMenus(); + + /** + * @brief Create main window toolbar. + */ + void CreateToolbar(); + /** * @brief Event coming when application is about to close. */