Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/close-all-but-this' into close-a…
Browse files Browse the repository at this point in the history
…ll-but-this-update
  • Loading branch information
dan-giddins committed Nov 6, 2023
2 parents d40b05c + fdfd15a commit 3b9f235
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 1 deletion.
23 changes: 23 additions & 0 deletions include/SignalSender.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef SIGNALSENDER_H
#define SIGNALSENDER_H

#include <QObject>
#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
6 changes: 6 additions & 0 deletions include/SubWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class LMMS_EXPORT SubWindow : public QMdiSubWindow

signals:
void focusLost();
void closeSignal();

private:
const QSize m_buttonSize;
Expand All @@ -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);
};


Expand Down
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions src/gui/SignalSender.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
48 changes: 47 additions & 1 deletion src/gui/SubWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,28 @@
#include <QMdiArea>
#include <QMoveEvent>
#include <QPainter>
#include <QScrollBar>
#include <QMenu>
#include <QPushButton>

#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 ),
Expand Down Expand Up @@ -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);
}


Expand Down

0 comments on commit 3b9f235

Please sign in to comment.