diff --git a/include/SignalSender.h b/include/SignalSender.h new file mode 100644 index 00000000000..e0a93e69474 --- /dev/null +++ b/include/SignalSender.h @@ -0,0 +1,23 @@ +#ifndef SIGNALSENDER_H +#define SIGNALSENDER_H + +#include +#include "SubWindow.h" + +class SignalSender : public QObject +{ + Q_OBJECT + +public: + static SignalSender* getInstance(); + +signals: + void closeAllSignal(); + void closeOthersSignal(SubWindow * source); + +public slots: + void closeAll(); + void closeOthers(SubWindow* source); +}; + +#endif diff --git a/include/SubWindow.h b/include/SubWindow.h index fdda6de4280..30675c75b19 100644 --- a/include/SubWindow.h +++ b/include/SubWindow.h @@ -78,6 +78,7 @@ class LMMS_EXPORT SubWindow : public QMdiSubWindow signals: void focusLost(); + void closeSignal(); private: const QSize m_buttonSize; @@ -93,12 +94,17 @@ class LMMS_EXPORT SubWindow : public QMdiSubWindow QLabel * m_windowTitle; QGraphicsDropShadowEffect * m_shadow; bool m_hasFocus; + QMenu* m_systemMenu; + QAction* m_closeAllAction; + QAction* m_closeOthersAction; static void elideText( QLabel *label, QString text ); void adjustTitleBar(); private slots: void focusChanged( QMdiSubWindow * subWindow ); + void closeOthersEmit(); + void closeOthersRecive( SubWindow * source); }; diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 1e809e9d710..5477e2dd2f4 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -33,6 +33,8 @@ SET(LMMS_SRCS gui/PluginBrowser.cpp gui/ProjectNotes.cpp gui/RowTableView.cpp + gui/SetupDialog.cpp + gui/SignalSender.cpp gui/SampleTrackWindow.cpp gui/SendButtonIndicator.cpp gui/SideBar.cpp diff --git a/src/gui/SignalSender.cpp b/src/gui/SignalSender.cpp new file mode 100644 index 00000000000..792e60f5a50 --- /dev/null +++ b/src/gui/SignalSender.cpp @@ -0,0 +1,17 @@ +#include "SignalSender.h" + +SignalSender* SignalSender::getInstance() +{ + static SignalSender* instance = new SignalSender(); + return instance; +} + +void SignalSender::closeAll() +{ + emit closeAllSignal(); +} + +void SignalSender::closeOthers(SubWindow* source) +{ + emit closeOthersSignal(source); +} diff --git a/src/gui/SubWindow.cpp b/src/gui/SubWindow.cpp index 78e4f586c67..e1633f5e390 100644 --- a/src/gui/SubWindow.cpp +++ b/src/gui/SubWindow.cpp @@ -33,13 +33,28 @@ #include #include #include +#include +#include #include #include "embed.h" +#include "SignalSender.h" namespace lmms::gui { +void SubWindow::closeOthersEmit() +{ + // trigger signal sender to send a close event to all elements + emit SignalSender::getInstance()->closeOthers(this); +} +void SubWindow::closeOthersRecive(SubWindow* source) +{ + // make sure source of signal is not the current window + if (source != this) { + emit closeSignal(); + } +} SubWindow::SubWindow( QWidget *parent, Qt::WindowFlags windowFlags ) : QMdiSubWindow( parent, windowFlags ), @@ -96,7 +111,38 @@ SubWindow::SubWindow( QWidget *parent, Qt::WindowFlags windowFlags ) : setWindowFlags( Qt::SubWindow | Qt::WindowMaximizeButtonHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint | Qt::CustomizeWindowHint ); - connect( mdiArea(), SIGNAL(subWindowActivated(QMdiSubWindow*)), this, SLOT(focusChanged(QMdiSubWindow*))); + connect( mdiArea(), SIGNAL(subWindowActivated(QMdiSubWindow*)), this, SLOT(focusChanged(QMdiSubWindow*))); + // get the default systemMenu + m_systemMenu = systemMenu(); + + // create 'close all' action + m_closeAllAction = new QAction("Close all", this); + m_closeAllAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_W)); + // connect action to SignalSender + connect(m_closeAllAction, SIGNAL(triggered()), SignalSender::getInstance(), SLOT(closeAll())); + // connect SignalSender to close action + connect(SignalSender::getInstance(), SIGNAL(closeAllSignal()), this, SLOT(close())); + // add action to subwindow to capture keypress + addAction(m_closeAllAction); + // add action to systemMenu + m_systemMenu->addAction(m_closeAllAction); + + // create 'close others' action + m_closeOthersAction = new QAction("Close others", this); + m_closeOthersAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Q)); + // connect action to signal emit + connect(m_closeOthersAction, SIGNAL(triggered()), this, SLOT(closeOthersEmit())); + // connect SignalSender to signal recive + connect(SignalSender::getInstance(), SIGNAL(closeOthersSignal(SubWindow*)), this, SLOT(closeOthersRecive(SubWindow*))); + // connect signal to close action + connect(this, SIGNAL(closeSignal()), this, SLOT(close())); + // add action to subwindow to capture keypress + addAction(m_closeOthersAction); + // add action to systemMenu + m_systemMenu->addAction(m_closeOthersAction); + + // update systemMenu + setSystemMenu(m_systemMenu); }