fix CTRL in songeditor by losing focus (#3796)

* fix CTRL in songeditor by losing focus

* init m_ctrlAction
This commit is contained in:
Steffen Baranowsky
2017-09-12 21:57:40 +02:00
committed by GitHub
parent 30020ebc8c
commit b69b585612
4 changed files with 50 additions and 4 deletions

View File

@@ -165,6 +165,7 @@ protected slots:
void recordAccompany();
void stop();
void lostFocus();
void adjustUiAfterProjectLoad();
signals:

View File

@@ -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

View File

@@ -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();

View File

@@ -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<QMdiSubWindow *>( parentWidget() ) );
connect( qobject_cast<SubWindow *>( parentWidget() ), SIGNAL( focusLost() ), this, SLOT( lostFocus() ) );
m_editor->scrolled(0);
}