diff options
author | Stijn Buys <ingar@osirion.org> | 2012-02-18 15:11:49 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2012-02-18 15:11:49 +0000 |
commit | 81466bb5001c6fc524806311c4a95d1a42da393c (patch) | |
tree | 7b95e4b69520aba8b15a6c47e06d0931bdeb6764 /src | |
parent | 2d486c096ec890425ef0b23dcb6486e87ccf9788 (diff) |
added simple MDI framework.
Diffstat (limited to 'src')
-rw-r--r-- | src/mainwindow.cc | 61 | ||||
-rw-r--r-- | src/mainwindow.h | 12 |
2 files changed, 72 insertions, 1 deletions
diff --git a/src/mainwindow.cc b/src/mainwindow.cc index 22347a5..e5f8000 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -7,6 +7,8 @@ #include <mainwindow.h> +#include <QTextEdit> + namespace editor { @@ -21,15 +23,72 @@ MainWindow::MainWindow() mainwindow_mdiarea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); setCentralWidget(mainwindow_mdiarea); + // initialize actions + init_actions(); + // initialize menu bar init_menu(); } +void MainWindow::init_actions() +{ + // File -> New + action_new = new QAction( tr("&New..."), this); + action_new->setShortcuts(QKeySequence::New); + action_new->setStatusTip(tr("Create a new zone")); + connect(action_new, SIGNAL(triggered()), this, SLOT(slot_new())); + + // File -> Open + action_open = new QAction( tr("&Open..."), this); + action_open->setShortcuts(QKeySequence::Open); + action_open->setStatusTip(tr("Open an existing zone")); + connect(action_open, SIGNAL(triggered()), this, SLOT(slot_open())); + + // File -> Quit + action_quit = new QAction(tr("&Quit"), this); + action_quit->setShortcuts(QKeySequence::Quit); + action_quit->setStatusTip(tr("Exit the application")); + connect(action_quit, SIGNAL(triggered()), qApp, SLOT(closeAllWindows())); +} + void MainWindow::init_menu() { mainwindow_filemenu = menuBar()->addMenu(tr("&File")); + mainwindow_filemenu->addAction(action_new); + mainwindow_filemenu->addAction(action_open); + mainwindow_filemenu->addSeparator(); + mainwindow_filemenu->addAction(action_quit); + mainwindow_editmenu = menuBar()->addMenu(tr("&Edit")); } -}
\ No newline at end of file +void MainWindow::add_child() +{ + // create a child widget + // TODO replace QTextEdit qith the actual editor widget + QTextEdit *child_widget = new QTextEdit(); + + // add the widget to the MDI area, + // this will wrap an QMdiSubWindow around it + mainwindow_mdiarea->addSubWindow(child_widget); + + child_widget->show(); +} + +void MainWindow::slot_new() +{ + add_child(); +} + +void MainWindow::slot_open() +{ + QString filename = QFileDialog::getOpenFileName(this); + + if (!filename.isEmpty()) { + add_child(); + } +} + + +} diff --git a/src/mainwindow.h b/src/mainwindow.h index 702cc18..d2b385a 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -12,6 +12,7 @@ #include <QMainWindow> +class QAction; class QMenu; class QMdiArea; @@ -25,12 +26,23 @@ class MainWindow : public QMainWindow public: MainWindow(); +private slots: + void slot_new(); + void slot_open(); + private: + void init_actions(); void init_menu(); + + void add_child(); QMdiArea *mainwindow_mdiarea; QMenu *mainwindow_filemenu; QMenu *mainwindow_editmenu; + + QAction *action_new; + QAction *action_open; + QAction *action_quit; }; } |