From 9aa997e5740fb6f5442ee2de5b2789530836a142 Mon Sep 17 00:00:00 2001 From: Johannes Lorenz Date: Sat, 16 Mar 2019 16:38:16 +0100 Subject: [PATCH 1/7] Allow TabWidget to be variable sized --- include/TabWidget.h | 8 +++++-- src/gui/widgets/TabWidget.cpp | 43 ++++++++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/include/TabWidget.h b/include/TabWidget.h index dacd2648b..11e4da40a 100644 --- a/include/TabWidget.h +++ b/include/TabWidget.h @@ -36,7 +36,10 @@ class TabWidget : public QWidget { Q_OBJECT public: - TabWidget( const QString & _caption, QWidget * _parent, bool usePixmap = false ); + //! @param resizable If true, the widget resizes to fit the size of all tabs + //! If false, all child widget will be cut down to the TabWidget's size + TabWidget( const QString & _caption, QWidget * _parent, + bool usePixmap = false, bool resizable = false ); virtual ~TabWidget() = default; void addTab( QWidget * w, const QString & name, const char *pixmap = NULL, int idx = -1 ); @@ -74,7 +77,7 @@ protected: virtual void paintEvent( QPaintEvent * _pe ); virtual void resizeEvent( QResizeEvent * _re ); virtual void wheelEvent( QWheelEvent * _we ); - + virtual QSize minimumSizeHint() const; private: struct widgetDesc @@ -88,6 +91,7 @@ private: widgetStack m_widgets; + bool m_resizable; int m_activeTab; QString m_caption; // Tab caption, used as the tooltip text on icon tabs quint8 m_tabbarHeight; // The height of the tab bar diff --git a/src/gui/widgets/TabWidget.cpp b/src/gui/widgets/TabWidget.cpp index f06710098..49898a3c7 100644 --- a/src/gui/widgets/TabWidget.cpp +++ b/src/gui/widgets/TabWidget.cpp @@ -34,8 +34,10 @@ #include "gui_templates.h" #include "embed.h" -TabWidget::TabWidget( const QString & caption, QWidget * parent, bool usePixmap ) : +TabWidget::TabWidget(const QString & caption, QWidget * parent, bool usePixmap, + bool resizable) : QWidget( parent ), + m_resizable( resizable ), m_activeTab( 0 ), m_caption( caption ), m_usePixmap( usePixmap ), @@ -81,7 +83,9 @@ void TabWidget::addTab( QWidget * w, const QString & name, const char *pixmap, i m_widgets[idx] = d; // Position tab's window - w->setFixedSize( width() - 4, height() - m_tabbarHeight ); + if(!m_resizable) { + w->setFixedSize( width() - 4, height() - m_tabbarHeight ); + } w->move( 2, m_tabbarHeight - 1 ); w->hide(); @@ -189,17 +193,19 @@ void TabWidget::mousePressEvent( QMouseEvent * me ) void TabWidget::resizeEvent( QResizeEvent * ) { - for( widgetStack::iterator it = m_widgets.begin(); - it != m_widgets.end(); ++it ) + if(!m_resizable) { - ( *it ).w->setFixedSize( width() - 4, height() - m_tabbarHeight ); + for( widgetStack::iterator it = m_widgets.begin(); + it != m_widgets.end(); ++it ) + { + ( *it ).w->setFixedSize( width() - 4, height() - m_tabbarHeight ); + } } } - void TabWidget::paintEvent( QPaintEvent * pe ) { QPainter p( this ); @@ -300,6 +306,31 @@ void TabWidget::wheelEvent( QWheelEvent * we ) setActiveTab( tab ); } + + + +// Let parent widgets know how much space this tab widget needs +QSize TabWidget::minimumSizeHint() const +{ + if(m_resizable) + { + int maxWidth = 0, maxHeight = 0; + for( widgetStack::const_iterator it = m_widgets.begin(); + it != m_widgets.end(); ++it ) + { + maxWidth = std::max(maxWidth, it->w->width()); + maxHeight = std::max(maxHeight, it->w->height()); + } + return QSize(maxWidth + 4, maxHeight + m_tabbarHeight); + } + else { + return QWidget::minimumSizeHint(); + } +} + + + + // Return the color to be used to draw a TabWidget's title text (if any) QColor TabWidget::tabTitleText() const { From dd43127514a423cc76ba0a5135c355f3af14220c Mon Sep 17 00:00:00 2001 From: Johannes Lorenz Date: Sat, 16 Mar 2019 19:46:21 +0100 Subject: [PATCH 2/7] Allow instrument views to grow with contents Make InstrumentTrackWindow as large as the InstrumentView requires --- src/gui/InstrumentView.cpp | 1 - src/tracks/InstrumentTrack.cpp | 16 +++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/gui/InstrumentView.cpp b/src/gui/InstrumentView.cpp index 9e8fc58c1..d2a7483e4 100644 --- a/src/gui/InstrumentView.cpp +++ b/src/gui/InstrumentView.cpp @@ -34,7 +34,6 @@ InstrumentView::InstrumentView( Instrument * _Instrument, QWidget * _parent ) : PluginView( _Instrument, _parent ) { setModel( _Instrument ); - setFixedSize( 250, 250 ); setAttribute( Qt::WA_DeleteOnClose, true ); } diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index 298430b03..6f4ad2b8e 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -1326,7 +1326,7 @@ InstrumentTrackWindow::InstrumentTrackWindow( InstrumentTrackView * _itv ) : this, SLOT( textChanged( const QString & ) ) ); m_nameLineEdit->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred)); - nameAndChangeTrackLayout->addWidget(m_nameLineEdit); + nameAndChangeTrackLayout->addWidget(m_nameLineEdit, 1); // set up left/right arrows for changing instrument @@ -1438,8 +1438,8 @@ InstrumentTrackWindow::InstrumentTrackWindow( InstrumentTrackView * _itv ) : generalSettingsLayout->addLayout( basicControlsLayout ); - m_tabWidget = new TabWidget( "", this, true ); - m_tabWidget->setFixedHeight( INSTRUMENT_HEIGHT + GRAPHIC_TAB_HEIGHT - 4 ); + m_tabWidget = new TabWidget( "", this, true, true ); + m_tabWidget->setMinimumHeight( INSTRUMENT_HEIGHT + GRAPHIC_TAB_HEIGHT - 4 ); // create tab-widgets @@ -1474,18 +1474,16 @@ InstrumentTrackWindow::InstrumentTrackWindow( InstrumentTrackView * _itv ) : // setup piano-widget m_pianoView = new PianoView( this ); - m_pianoView->setFixedSize( INSTRUMENT_WIDTH, PIANO_HEIGHT ); + m_pianoView->setMinimumHeight( PIANO_HEIGHT ); + m_pianoView->setMaximumHeight( PIANO_HEIGHT ); vlayout->addWidget( generalSettingsWidget ); - vlayout->addWidget( m_tabWidget ); + vlayout->addWidget( m_tabWidget, 1 ); vlayout->addWidget( m_pianoView ); - - setModel( _itv->model() ); updateInstrumentView(); - setFixedWidth( INSTRUMENT_WIDTH ); resize( sizeHint() ); QMdiSubWindow * subWin = gui->mainWindow()->addWindowedWidget( this ); @@ -1501,7 +1499,7 @@ InstrumentTrackWindow::InstrumentTrackWindow( InstrumentTrackView * _itv ) : systemMenu->actions().at( 4 )->setVisible( false ); // Maximize subWin->setWindowIcon( embed::getIconPixmap( "instrument_track" ) ); - subWin->setFixedSize( subWin->size() ); + subWin->setMinimumSize( subWin->size() ); subWin->hide(); } From 7e7141f38816a0b7b293585858c69866c972d2f1 Mon Sep 17 00:00:00 2001 From: Johannes Lorenz Date: Sun, 17 Mar 2019 10:43:38 +0100 Subject: [PATCH 3/7] Fix too small instrument tabs Previously, they had been resized by the fixed size parent tab widget. We need to do this manually now. --- src/tracks/InstrumentTrack.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index 6f4ad2b8e..fb9261ff7 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -1472,6 +1472,17 @@ InstrumentTrackWindow::InstrumentTrackWindow( InstrumentTrackView * _itv ) : m_tabWidget->addTab( m_midiView, tr( "MIDI" ), "midi_tab", 4 ); m_tabWidget->addTab( m_miscView, tr( "Miscellaneous" ), "misc_tab", 5 ); + //! adjust size of any child widget of the main tab + //! required to keep the old look when using a variable sized tab widget + auto adjustSize = [](QWidget *w) { + w->setMinimumSize(INSTRUMENT_WIDTH, INSTRUMENT_HEIGHT + GRAPHIC_TAB_HEIGHT); + }; + adjustSize(m_ssView); + adjustSize(instrumentFunctions); + adjustSize(m_effectView); + adjustSize(m_midiView); + adjustSize(m_miscView); + // setup piano-widget m_pianoView = new PianoView( this ); m_pianoView->setMinimumHeight( PIANO_HEIGHT ); From d52c220a5cd40af37a0c167c1425f89edca991cf Mon Sep 17 00:00:00 2001 From: Johannes Lorenz Date: Thu, 28 Mar 2019 18:57:19 +0100 Subject: [PATCH 4/7] Fix instrument window tab sizes - Fix the instrument window tabs minimum width and height formulae - Also set minimum height and width for instrument tab --- include/InstrumentTrack.h | 3 +++ src/tracks/InstrumentTrack.cpp | 26 ++++++++++++++------------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/include/InstrumentTrack.h b/include/InstrumentTrack.h index fb12e825a..0627e9f4e 100644 --- a/include/InstrumentTrack.h +++ b/include/InstrumentTrack.h @@ -427,6 +427,9 @@ protected slots: private: virtual void modelChanged(); void viewInstrumentInDirection(int d); + //! adjust size of any child widget of the main tab + //! required to keep the old look when using a variable sized tab widget + void adjustTabSize(QWidget *w); InstrumentTrack * m_track; InstrumentTrackView * m_itv; diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index fb9261ff7..69924c8be 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -1471,17 +1471,11 @@ InstrumentTrackWindow::InstrumentTrackWindow( InstrumentTrackView * _itv ) : m_tabWidget->addTab( m_effectView, tr( "Effects" ), "fx_tab", 3 ); m_tabWidget->addTab( m_midiView, tr( "MIDI" ), "midi_tab", 4 ); m_tabWidget->addTab( m_miscView, tr( "Miscellaneous" ), "misc_tab", 5 ); - - //! adjust size of any child widget of the main tab - //! required to keep the old look when using a variable sized tab widget - auto adjustSize = [](QWidget *w) { - w->setMinimumSize(INSTRUMENT_WIDTH, INSTRUMENT_HEIGHT + GRAPHIC_TAB_HEIGHT); - }; - adjustSize(m_ssView); - adjustSize(instrumentFunctions); - adjustSize(m_effectView); - adjustSize(m_midiView); - adjustSize(m_miscView); + adjustTabSize(m_ssView); + adjustTabSize(instrumentFunctions); + adjustTabSize(m_effectView); + adjustTabSize(m_midiView); + adjustTabSize(m_miscView); // setup piano-widget m_pianoView = new PianoView( this ); @@ -1497,7 +1491,7 @@ InstrumentTrackWindow::InstrumentTrackWindow( InstrumentTrackView * _itv ) : resize( sizeHint() ); - QMdiSubWindow * subWin = gui->mainWindow()->addWindowedWidget( this ); + QMdiSubWindow* subWin = gui->mainWindow()->addWindowedWidget( this ); Qt::WindowFlags flags = subWin->windowFlags(); flags |= Qt::MSWindowsFixedSizeDialogHint; flags &= ~Qt::WindowMaximizeButtonHint; @@ -1659,6 +1653,8 @@ void InstrumentTrackWindow::updateInstrumentView() modelChanged(); // Get the instrument window to refresh m_track->dataChanged(); // Get the text on the trackButton to change + + adjustTabSize(m_instrumentView); } } @@ -1846,6 +1842,7 @@ void InstrumentTrackWindow::viewInstrumentInDirection(int d) // scroll the SongEditor/BB-editor to make sure the new trackview label is visible bringToFront->trackContainerView()->scrollToTrackView(bringToFront); } + Q_ASSERT(bringToFront); bringToFront->getInstrumentTrackWindow()->setFocus(); } @@ -1858,4 +1855,9 @@ void InstrumentTrackWindow::viewPrevInstrument() viewInstrumentInDirection(-1); } +void InstrumentTrackWindow::adjustTabSize(QWidget *w) +{ + w->setMinimumSize(INSTRUMENT_WIDTH - 4, INSTRUMENT_HEIGHT - 4); +} + #include "InstrumentTrack.moc" From 91099e28d56bdb0ddf4c37da6a23582f92b52db1 Mon Sep 17 00:00:00 2001 From: Johannes Lorenz Date: Sat, 20 Apr 2019 13:23:42 +0200 Subject: [PATCH 5/7] Fix -1 offset in plugin tab In the instrument plugin tab, there was an orange stripe for TripleOscillator. This was because internally, TabWidget moves up the widget by 1 (TabWidget.cpp, line 89). The size of the whole window is: ``` widget->height() + m_tabbarHeight - 1 ``` So this code adds an offset of "-1" to the necessary computations. --- src/gui/widgets/TabWidget.cpp | 5 ++++- src/tracks/InstrumentTrack.cpp | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/gui/widgets/TabWidget.cpp b/src/gui/widgets/TabWidget.cpp index 49898a3c7..6049ce6cb 100644 --- a/src/gui/widgets/TabWidget.cpp +++ b/src/gui/widgets/TabWidget.cpp @@ -321,7 +321,10 @@ QSize TabWidget::minimumSizeHint() const maxWidth = std::max(maxWidth, it->w->width()); maxHeight = std::max(maxHeight, it->w->height()); } - return QSize(maxWidth + 4, maxHeight + m_tabbarHeight); + // "-1" : + // in "addTab", under "Position tab's window", the widget is + // moved up by 1 pixel + return QSize(maxWidth + 4, maxHeight + m_tabbarHeight - 1); } else { return QWidget::minimumSizeHint(); diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index 69924c8be..5466dd806 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -1439,7 +1439,10 @@ InstrumentTrackWindow::InstrumentTrackWindow( InstrumentTrackView * _itv ) : m_tabWidget = new TabWidget( "", this, true, true ); - m_tabWidget->setMinimumHeight( INSTRUMENT_HEIGHT + GRAPHIC_TAB_HEIGHT - 4 ); + // "-1" : + // in "TabWidget::addTab", under "Position tab's window", the widget is + // moved up by 1 pixel + m_tabWidget->setMinimumHeight( INSTRUMENT_HEIGHT + GRAPHIC_TAB_HEIGHT - 4 - 1 ); // create tab-widgets @@ -1857,7 +1860,10 @@ void InstrumentTrackWindow::viewPrevInstrument() void InstrumentTrackWindow::adjustTabSize(QWidget *w) { - w->setMinimumSize(INSTRUMENT_WIDTH - 4, INSTRUMENT_HEIGHT - 4); + // "-1" : + // in "TabWidget::addTab", under "Position tab's window", the widget is + // moved up by 1 pixel + w->setMinimumSize(INSTRUMENT_WIDTH - 4, INSTRUMENT_HEIGHT - 4 - 1); } #include "InstrumentTrack.moc" From 53942a146a50c7378d99737749bb88879416b16d Mon Sep 17 00:00:00 2001 From: Johannes Lorenz Date: Sat, 20 Apr 2019 18:32:17 +0200 Subject: [PATCH 6/7] Fix bad identation in old code --- src/gui/widgets/TabWidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/widgets/TabWidget.cpp b/src/gui/widgets/TabWidget.cpp index 6049ce6cb..10e139ce4 100644 --- a/src/gui/widgets/TabWidget.cpp +++ b/src/gui/widgets/TabWidget.cpp @@ -290,7 +290,7 @@ void TabWidget::wheelEvent( QWheelEvent * we ) if( we->y() > m_tabheight ) { return; - } + } we->accept(); int dir = ( we->delta() < 0 ) ? 1 : -1; From e1df16c45b8ac2923dec8e475b6cf44f23752512 Mon Sep 17 00:00:00 2001 From: Johannes Lorenz Date: Sat, 20 Apr 2019 22:12:32 +0200 Subject: [PATCH 7/7] Coding conventions --- src/gui/widgets/TabWidget.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/gui/widgets/TabWidget.cpp b/src/gui/widgets/TabWidget.cpp index 10e139ce4..9bdbec2e0 100644 --- a/src/gui/widgets/TabWidget.cpp +++ b/src/gui/widgets/TabWidget.cpp @@ -83,7 +83,8 @@ void TabWidget::addTab( QWidget * w, const QString & name, const char *pixmap, i m_widgets[idx] = d; // Position tab's window - if(!m_resizable) { + if (!m_resizable) + { w->setFixedSize( width() - 4, height() - m_tabbarHeight ); } w->move( 2, m_tabbarHeight - 1 ); @@ -193,9 +194,9 @@ void TabWidget::mousePressEvent( QMouseEvent * me ) void TabWidget::resizeEvent( QResizeEvent * ) { - if(!m_resizable) + if (!m_resizable) { - for( widgetStack::iterator it = m_widgets.begin(); + for ( widgetStack::iterator it = m_widgets.begin(); it != m_widgets.end(); ++it ) { ( *it ).w->setFixedSize( width() - 4, height() - m_tabbarHeight ); @@ -312,10 +313,10 @@ void TabWidget::wheelEvent( QWheelEvent * we ) // Let parent widgets know how much space this tab widget needs QSize TabWidget::minimumSizeHint() const { - if(m_resizable) + if (m_resizable) { int maxWidth = 0, maxHeight = 0; - for( widgetStack::const_iterator it = m_widgets.begin(); + for ( widgetStack::const_iterator it = m_widgets.begin(); it != m_widgets.end(); ++it ) { maxWidth = std::max(maxWidth, it->w->width()); @@ -326,9 +327,7 @@ QSize TabWidget::minimumSizeHint() const // moved up by 1 pixel return QSize(maxWidth + 4, maxHeight + m_tabbarHeight - 1); } - else { - return QWidget::minimumSizeHint(); - } + else { return QWidget::minimumSizeHint(); } }