Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable tab widget #4906

Merged
merged 7 commits into from
Apr 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/InstrumentTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions include/TabWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -74,7 +77,7 @@ class TabWidget : public QWidget
virtual void paintEvent( QPaintEvent * _pe );
virtual void resizeEvent( QResizeEvent * _re );
virtual void wheelEvent( QWheelEvent * _we );

virtual QSize minimumSizeHint() const;

private:
struct widgetDesc
Expand All @@ -88,6 +91,7 @@ class TabWidget : public QWidget

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
Expand Down
1 change: 0 additions & 1 deletion src/gui/InstrumentView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ InstrumentView::InstrumentView( Instrument * _Instrument, QWidget * _parent ) :
PluginView( _Instrument, _parent )
{
setModel( _Instrument );
setFixedSize( 250, 250 );
setAttribute( Qt::WA_DeleteOnClose, true );
}

Expand Down
47 changes: 40 additions & 7 deletions src/gui/widgets/TabWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ),
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -284,7 +291,7 @@ void TabWidget::wheelEvent( QWheelEvent * we )
if( we->y() > m_tabheight )
{
return;
}
}

we->accept();
int dir = ( we->delta() < 0 ) ? 1 : -1;
Expand All @@ -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
{
Expand Down
37 changes: 27 additions & 10 deletions src/tracks/InstrumentTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1438,8 +1438,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
Expand Down Expand Up @@ -1471,24 +1474,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;
Expand All @@ -1501,7 +1507,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();
}

Expand Down Expand Up @@ -1650,6 +1656,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);
}
}

Expand Down Expand Up @@ -1837,6 +1845,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();
}

Expand All @@ -1849,4 +1858,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"