From 4a96b92d9351834d953daca2175bebaaf870ae2f Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 12 Jul 2015 18:56:34 +0300 Subject: [PATCH] Menu Windows. --HG-- branch : feature --- src/app/tape/tmainwindow.cpp | 87 +++++++++++++++++++++++++++++++++++- src/app/tape/tmainwindow.h | 8 ++++ src/app/tape/tmainwindow.ui | 10 ++++- 3 files changed, 102 insertions(+), 3 deletions(-) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 7c378bab8..9fa498573 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -28,6 +28,7 @@ #include "tmainwindow.h" #include "ui_tmainwindow.h" +#include "mapplication.h" //--------------------------------------------------------------------------------------------------------------------- TMainWindow::TMainWindow(QWidget *parent) @@ -54,7 +55,91 @@ void TMainWindow::LoadFile(const QString &path) } //--------------------------------------------------------------------------------------------------------------------- -void TMainWindow::SetupMenu() +void TMainWindow::FileOpen() { } + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::FileSave() +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::FileSaveAs() +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::AboutToShowWindowMenu() +{ + ui->menuWindow->clear(); + QList windows = MApplication::instance()->MainWindows(); + for (int i = 0; i < windows.count(); ++i) + { + TMainWindow *window = windows.at(i); + QAction *action = ui->menuWindow->addAction(window->windowTitle(), this, SLOT(ShowWindow())); + action->setData(i); + action->setCheckable(true); + if (window == this) + { + action->setChecked(true); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::ShowWindow() +{ + if (QAction *action = qobject_cast(sender())) + { + const QVariant v = action->data(); + if (v.canConvert()) + { + const int offset = qvariant_cast(v); + QList windows = MApplication::instance()->MainWindows(); + windows.at(offset)->activateWindow(); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::AboutApplication() +{ + +} + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::SetupMenu() +{ + // File + connect(ui->actionOpen, &QAction::triggered, this, &TMainWindow::FileOpen); + ui->actionOpen->setShortcuts(QKeySequence::Open); + + connect(ui->actionSave, &QAction::triggered, this, &TMainWindow::FileSave); + ui->actionOpen->setShortcuts(QKeySequence::Save); + + connect(ui->actionSaveAs, &QAction::triggered, this, &TMainWindow::FileSaveAs); + ui->actionOpen->setShortcuts(QKeySequence::SaveAs); + + QAction *separatorAct = new QAction(this); + separatorAct->setSeparator(true); + ui->menuFile->insertAction(ui->actionQuit, separatorAct); + + connect(ui->actionQuit, &QAction::triggered, this, &TMainWindow::close); + ui->actionQuit->setShortcuts(QKeySequence::Quit); + + // Edit + //ui->actionUndo->setShortcuts(QKeySequence::Undo); + //ui->actionRedo->setShortcuts(QKeySequence::Redo); + + // Window + connect(ui->menuWindow, &QMenu::aboutToShow, this, &TMainWindow::AboutToShowWindowMenu); + AboutToShowWindowMenu(); + + // Help + connect(ui->actionAboutQt, &QAction::triggered, qApp, &QApplication::aboutQt); + connect(ui->actionAboutTape, &QAction::triggered, this, &TMainWindow::AboutApplication); +} diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index 3c6e82a28..323d876b7 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -47,6 +47,14 @@ public: public slots: void LoadFile(const QString &path); +private slots: + void FileOpen(); + void FileSave(); + void FileSaveAs(); + void AboutToShowWindowMenu(); + void ShowWindow(); + void AboutApplication(); + private: Q_DISABLE_COPY(TMainWindow) Ui::TMainWindow *ui; diff --git a/src/app/tape/tmainwindow.ui b/src/app/tape/tmainwindow.ui index 85444d5b9..473521efd 100644 --- a/src/app/tape/tmainwindow.ui +++ b/src/app/tape/tmainwindow.ui @@ -392,7 +392,7 @@ 25 - + File @@ -416,7 +416,13 @@ - + + + Edit + + + +