From b69b5856121b53a33ecc75e3626ac4f3c87c2ba3 Mon Sep 17 00:00:00 2001 From: Steffen Baranowsky Date: Tue, 12 Sep 2017 21:57:40 +0200 Subject: [PATCH] fix CTRL in songeditor by losing focus (#3796) * fix CTRL in songeditor by losing focus * init m_ctrlAction --- include/SongEditor.h | 1 + include/SubWindow.h | 9 ++++++++- src/gui/SubWindow.cpp | 20 +++++++++++++++++++- src/gui/editors/SongEditor.cpp | 24 ++++++++++++++++++++++-- 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/include/SongEditor.h b/include/SongEditor.h index 0c17d43eb..d6e904ace 100644 --- a/include/SongEditor.h +++ b/include/SongEditor.h @@ -165,6 +165,7 @@ protected slots: void recordAccompany(); void stop(); + void lostFocus(); void adjustUiAfterProjectLoad(); signals: diff --git a/include/SubWindow.h b/include/SubWindow.h index 99bd49552..4bda072a6 100644 --- a/include/SubWindow.h +++ b/include/SubWindow.h @@ -65,7 +65,10 @@ protected: virtual void resizeEvent( QResizeEvent * event ); virtual void paintEvent( QPaintEvent * pe ); virtual void changeEvent( QEvent * event ); - + +signals: + void focusLost(); + private: const QSize m_buttonSize; const int m_titleBarHeight; @@ -79,10 +82,14 @@ private: QRect m_trackedNormalGeom; QLabel * m_windowTitle; QGraphicsDropShadowEffect * m_shadow; + bool m_hasFocus; static void elideText( QLabel *label, QString text ); bool isMaximized(); void adjustTitleBar(); + +private slots: + void focusChanged( QMdiSubWindow * subWindow ); }; #endif diff --git a/src/gui/SubWindow.cpp b/src/gui/SubWindow.cpp index e92c4cbcb..15d8a382e 100644 --- a/src/gui/SubWindow.cpp +++ b/src/gui/SubWindow.cpp @@ -37,7 +37,8 @@ SubWindow::SubWindow( QWidget *parent, Qt::WindowFlags windowFlags ) : QMdiSubWindow( parent, windowFlags ), m_buttonSize( 17, 17 ), - m_titleBarHeight( 24 ) + m_titleBarHeight( 24 ), + m_hasFocus( false ) { // initialize the tracked geometry to whatever Qt thinks the normal geometry currently is. // this should always work, since QMdiSubWindows will not start as maximized @@ -88,6 +89,7 @@ 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* ) ) ); } @@ -288,6 +290,22 @@ void SubWindow::adjustTitleBar() +void SubWindow::focusChanged( QMdiSubWindow *subWindow ) +{ + if( m_hasFocus && subWindow != this ) + { + m_hasFocus = false; + emit focusLost(); + } + else if( subWindow == this ) + { + m_hasFocus = true; + } +} + + + + void SubWindow::resizeEvent( QResizeEvent * event ) { adjustTitleBar(); diff --git a/src/gui/editors/SongEditor.cpp b/src/gui/editors/SongEditor.cpp index c54b60d22..a06854447 100644 --- a/src/gui/editors/SongEditor.cpp +++ b/src/gui/editors/SongEditor.cpp @@ -52,7 +52,6 @@ #include "PianoRoll.h" - positionLine::positionLine( QWidget * parent ) : QWidget( parent ) { @@ -653,7 +652,8 @@ ComboBoxModel *SongEditor::zoomingModel() const SongEditorWindow::SongEditorWindow(Song* song) : Editor(Engine::mixer()->audioDev()->supportsCapture()), - m_editor(new SongEditor(song)) + m_editor(new SongEditor(song)), + m_crtlAction( NULL ) { setWindowTitle( tr( "Song-Editor" ) ); setWindowIcon( embed::getIconPixmap( "songeditor" ) ); @@ -770,18 +770,37 @@ void SongEditorWindow::record() } + + void SongEditorWindow::recordAccompany() { m_editor->m_song->playAndRecord(); } + + void SongEditorWindow::stop() { m_editor->m_song->stop(); gui->pianoRoll()->stopRecording(); } + + + +void SongEditorWindow::lostFocus() +{ + if( m_crtlAction ) + { + m_crtlAction->setChecked( true ); + m_crtlAction->trigger(); + } +} + + + + void SongEditorWindow::adjustUiAfterProjectLoad() { // make sure to bring us to front as the song editor is the central @@ -789,6 +808,7 @@ void SongEditorWindow::adjustUiAfterProjectLoad() // it, it's very annyoing to manually bring up the song editor each time gui->mainWindow()->workspace()->setActiveSubWindow( qobject_cast( parentWidget() ) ); + connect( qobject_cast( parentWidget() ), SIGNAL( focusLost() ), this, SLOT( lostFocus() ) ); m_editor->scrolled(0); }