Merge branch 'variable-tab-widget'

This commit is contained in:
Johannes Lorenz
2019-04-22 08:59:59 +02:00
5 changed files with 75 additions and 20 deletions

View File

@@ -431,6 +431,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;

View File

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

View File

@@ -34,7 +34,6 @@ InstrumentView::InstrumentView( Instrument * _Instrument, QWidget * _parent ) :
PluginView( _Instrument, _parent )
{
setModel( _Instrument );
setFixedSize( 250, 250 );
setAttribute( Qt::WA_DeleteOnClose, true );
}

View File

@@ -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,10 @@ 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 +194,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 );
@@ -284,7 +291,7 @@ void TabWidget::wheelEvent( QWheelEvent * we )
if( we->y() > m_tabheight )
{
return;
}
}
we->accept();
int dir = ( we->delta() < 0 ) ? 1 : -1;
@@ -300,6 +307,32 @@ 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());
}
// "-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(); }
}
// Return the color to be used to draw a TabWidget's title text (if any)
QColor TabWidget::tabTitleText() const
{

View File

@@ -1298,7 +1298,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
@@ -1410,8 +1410,11 @@ 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 );
// "-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
@@ -1443,24 +1446,27 @@ 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 );
adjustTabSize(m_ssView);
adjustTabSize(instrumentFunctions);
adjustTabSize(m_effectView);
adjustTabSize(m_midiView);
adjustTabSize(m_miscView);
// 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 );
QMdiSubWindow* subWin = gui->mainWindow()->addWindowedWidget( this );
Qt::WindowFlags flags = subWin->windowFlags();
flags |= Qt::MSWindowsFixedSizeDialogHint;
flags &= ~Qt::WindowMaximizeButtonHint;
@@ -1473,7 +1479,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();
}
@@ -1624,6 +1630,7 @@ void InstrumentTrackWindow::updateInstrumentView()
modelChanged(); // Get the instrument window to refresh
m_track->dataChanged(); // Get the text on the trackButton to change
adjustTabSize(m_instrumentView);
m_pianoView->setVisible(m_track->m_instrument->hasNoteInput());
}
}
@@ -1819,6 +1826,7 @@ void InstrumentTrackWindow::viewInstrumentInDirection(int d)
// get the instrument window to refresh
modelChanged();
}
Q_ASSERT(bringToFront);
bringToFront->getInstrumentTrackWindow()->setFocus();
}
@@ -1831,4 +1839,12 @@ void InstrumentTrackWindow::viewPrevInstrument()
viewInstrumentInDirection(-1);
}
void InstrumentTrackWindow::adjustTabSize(QWidget *w)
{
// "-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"