diff options
author | Lukáš Lalinský <lalinsky@gmail.com> | 2009-09-03 10:56:29 +0200 |
---|---|---|
committer | Lukáš Lalinský <lalinsky@gmail.com> | 2009-09-03 10:56:29 +0200 |
commit | 7f1255f2cb90c347ecf90c53d1b8064c7bba652d (patch) | |
tree | 00b589c2bff0ddf6d0a4093a8b8e70bb2acf45fe /src | |
parent | 72200c7507e71799d8a79a341e3d91c35c0dbc82 (diff) | |
download | dbmodel-7f1255f2cb90c347ecf90c53d1b8064c7bba652d.tar.xz |
Make the "Close" menu item not quit the application
Diffstat (limited to 'src')
-rw-r--r-- | src/mainwindow.cpp | 38 | ||||
-rw-r--r-- | src/mainwindow.h | 4 |
2 files changed, 36 insertions, 6 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4b7b500..bc912b5 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -314,7 +314,7 @@ MainWindow::setupActions() m_actionClose->setText(tr("&Close")); m_actionClose->setIcon(loadIcon("window-close")); m_actionClose->setShortcut(QKeySequence(tr("Ctrl+W"))); - connect(m_actionClose, SIGNAL(triggered(bool)), SLOT(close())); + connect(m_actionClose, SIGNAL(triggered(bool)), SLOT(closeDocument())); m_actionQuit = new QAction(this); m_actionQuit->setText(tr("&Quit")); @@ -720,14 +720,40 @@ MainWindow::addRecentFile(const QString &fileName) } } +QList<MainWindow *> +MainWindow::mainWindows() +{ + QList<MainWindow *> result; + QWidgetList widgets = QApplication::topLevelWidgets(); + int listSize = widgets.size(); + for (int i = 0; i < listSize; i++) { + MainWindow *mainWin = qobject_cast<MainWindow *>(widgets.at(i)); + if (mainWin) { + result.append(mainWin); + } + } + return result; +} + +void +MainWindow::closeDocument() +{ + if (mainWindows().size() > 1) { + // There are still some windows open, close this one + close(); + } + else { + // This is the last window, close the document, but keep the window open + newModel(); + } +} + void MainWindow::closeAll() { - foreach (QWidget *widget, QApplication::topLevelWidgets()) { - MainWindow *mainWin = qobject_cast<MainWindow *>(widget); - if (mainWin) - mainWin->close(); - } + foreach (MainWindow *window, mainWindows()) { + window->close(); + } } void diff --git a/src/mainwindow.h b/src/mainwindow.h index 923f6cd..815d29e 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -75,6 +75,8 @@ public slots: void copy(); void paste(); void updateClipboard(QClipboard::Mode mode); + + void closeDocument(); void closeAll(); void showGrid(bool); @@ -93,6 +95,8 @@ protected: void saveWindowState(); void restoreWindowState(); + static QList<MainWindow *> mainWindows(); + private: class MainWindowPrivate; MainWindowPrivate *const d; |