From f071393e555c73b53f9e86784bd070ceb0aa0d8e Mon Sep 17 00:00:00 2001 From: Cyrille Bollu Date: Sun, 21 Feb 2016 17:43:00 +0100 Subject: [PATCH] 1st PoC for autosizeable artwork tabs. --- data/themes/default/midi_inactive.png | Bin 378 -> 961 bytes src/gui/widgets/TabWidget.cpp | 56 ++++++++++++++------------ src/tracks/InstrumentTrack.cpp | 2 +- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/data/themes/default/midi_inactive.png b/data/themes/default/midi_inactive.png index bbf6a4976239c913ab5c5553e37d29cb7c212d1d..2bafb3217e976f62d6c9a696515efda79cc45aa4 100644 GIT binary patch literal 961 zcmeAS@N?(olHy`uVBq!ia0vp^d?3uh1|;P@bT0xawj^(N7l!{JxM1({$v_d#0*}aI z1_o|n5N2eUHAey{$X?><>&pIsNt92GeZuCtB%qLFiEBiObAE1aYF-J0b5UwyNotBh zd1gt5g1e`0KzJjcI0FN-rl*Tzh=wSm9P`6Jj6h8&;Q#;s8bARi6hQ`te~gTbH_*fw z7=Vhw1_0?zK#U7)0%-(Fg4M!p1gSHA%gD4pLK9CJk0|Hub zjZjldA>vrcQY6=CF@kk7FkA%*k^r>P}id3{U47wLTO{y;3=s#uJ*0`YE3E0G)>c6hp+3u Y0YOE5l^=*XtN;K207*qoM6N<$f>hg{J^%m! diff --git a/src/gui/widgets/TabWidget.cpp b/src/gui/widgets/TabWidget.cpp index d068ea9a9..9eaed1a7d 100644 --- a/src/gui/widgets/TabWidget.cpp +++ b/src/gui/widgets/TabWidget.cpp @@ -74,13 +74,8 @@ void TabWidget::addTab( QWidget * _w, const QString & _name, const char * pixma } } - // Compute tab's width - int w; - if ( pixmapName == NULL ) { - w = fontMetrics().width( _name ) + 10; - } else { - w = 28; // artwork's width - } + // Tab's width when it is a text tab + int w = fontMetrics().width( _name ) + 10; // Register new tab widgetDesc d = { _w, pixmapName, _name, w } ; @@ -209,48 +204,57 @@ void TabWidget::paintEvent( QPaintEvent * _pe ) p.setPen( cap_col ); // Draw all tabs - for( widgetStack::iterator it = m_widgets.begin(); - it != m_widgets.end(); ++it ) + widgetStack::iterator first = m_widgets.begin(); + widgetStack::iterator last = m_widgets.end(); + int size = std::distance(first,last); + for( widgetStack::iterator it = first ; it != last ; ++it ) { // Draw a text tab when no artwork has been defined for the tab. if ( (*it ).pixmapName == NULL ) - { - // Highlight text tabs when they are active - if ( it.key() == m_activeTab ) { + { + + // Highlight tab when active + if( it.key() == m_activeTab ) + { p.setPen( QColor( 32, 48, 64 ) ); p.fillRect( tab_x_offset, 2, ( *it ).nwidth - 6, 10, cap_col ); } - // Draw tab + // Draw text p.drawText( tab_x_offset + 3, m_tabheight, ( *it ).name ); + + // Reset text color p.setPen( cap_col ); + + } else { - // Get active or inactive artwork - std::string tab = std::string( ( *it ).pixmapName ); - if( it.key() == m_activeTab ) - { - tab += "_active"; - } else - { - tab += "_inactive"; - } - QPixmap *artwork = new QPixmap( embed::getIconPixmap( tab.c_str() ) ); + // Get artwork + QPixmap *artwork = new QPixmap( embed::getIconPixmap( ( *it ).pixmapName ) ); + + if( it.key() == m_activeTab ) + { + p.fillRect( tab_x_offset, 1, width() / size, 12, cap_col ); + } + + // Draw artwork + p.drawPixmap(tab_x_offset + ( width() / ( size * 2 ) ) - 7, 0, *artwork ); + + // Recompute tab's width, because original size is only correct for text tabs + ( *it).nwidth = width() / size; - // Draw tab - p.drawPixmap(tab_x_offset, 0, *artwork ); } // Next tab's horizontal position tab_x_offset += ( *it ).nwidth; - } } +// Switch between tabs with mouse wheel void TabWidget::wheelEvent( QWheelEvent * _we ) { if (_we->y() > m_tabheight) diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index be42007fc..eee8b98f2 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -1437,7 +1437,7 @@ InstrumentTrackWindow::InstrumentTrackWindow( InstrumentTrackView * _itv ) : m_tabWidget->addTab( m_ssView, tr( "ENV/LFO" ), "env_lfo", 1 ); m_tabWidget->addTab( instrumentFunctions, tr( "FUNC" ), "functions", 2 ); m_tabWidget->addTab( m_effectView, tr( "FX" ), "fx", 3 ); - m_tabWidget->addTab( m_midiView, tr( "MIDI" ), "midi", 4 ); + m_tabWidget->addTab( m_midiView, tr( "MIDI" ), "midi_inactive", 4 ); m_tabWidget->addTab( m_miscView, tr( "MISC" ), "miscellaneous", 5 ); // setup piano-widget