Menu Windows.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2015-07-12 18:56:34 +03:00
parent 01e1958aa5
commit 4a96b92d93
3 changed files with 102 additions and 3 deletions

View File

@ -28,6 +28,7 @@
#include "tmainwindow.h" #include "tmainwindow.h"
#include "ui_tmainwindow.h" #include "ui_tmainwindow.h"
#include "mapplication.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
TMainWindow::TMainWindow(QWidget *parent) 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<TMainWindow*> 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<QAction*>(sender()))
{
const QVariant v = action->data();
if (v.canConvert<int>())
{
const int offset = qvariant_cast<int>(v);
QList<TMainWindow*> 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);
}

View File

@ -47,6 +47,14 @@ public:
public slots: public slots:
void LoadFile(const QString &path); void LoadFile(const QString &path);
private slots:
void FileOpen();
void FileSave();
void FileSaveAs();
void AboutToShowWindowMenu();
void ShowWindow();
void AboutApplication();
private: private:
Q_DISABLE_COPY(TMainWindow) Q_DISABLE_COPY(TMainWindow)
Ui::TMainWindow *ui; Ui::TMainWindow *ui;

View File

@ -392,7 +392,7 @@
<height>25</height> <height>25</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menu_File"> <widget class="QMenu" name="menuFile">
<property name="title"> <property name="title">
<string>File</string> <string>File</string>
</property> </property>
@ -416,7 +416,13 @@
<addaction name="actionAboutQt"/> <addaction name="actionAboutQt"/>
<addaction name="actionAboutTape"/> <addaction name="actionAboutTape"/>
</widget> </widget>
<addaction name="menu_File"/> <widget class="QMenu" name="menuEdit">
<property name="title">
<string>Edit</string>
</property>
</widget>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
<addaction name="menuWindow"/> <addaction name="menuWindow"/>
<addaction name="menuHelp"/> <addaction name="menuHelp"/>
</widget> </widget>