From 655362452f0cbcbc43e18d6889491ed74050f3d9 Mon Sep 17 00:00:00 2001 From: Cyrille Bollu Date: Fri, 12 Feb 2016 15:58:45 +0100 Subject: [PATCH] First version of artwork tabs for the InstrumentTrackWindow. This version can only display & manage artwork tabs, which breaks the InstrumentSoundShapingView as it still uses text tabs. I'm planing to improve this implementation to let these artwork tabs fall back to text mode when no artwork is given. This would solve the problem of the InstrumentSoundShapingView. --- include/TabWidget.h | 10 ++-- .../widgets/InstrumentSoundShapingView.cpp | 3 +- src/gui/widgets/TabWidget.cpp | 57 ++++++++++++------- src/tracks/InstrumentTrack.cpp | 12 ++-- 4 files changed, 51 insertions(+), 31 deletions(-) diff --git a/include/TabWidget.h b/include/TabWidget.h index 1d5635c95..f7d76a437 100644 --- a/include/TabWidget.h +++ b/include/TabWidget.h @@ -29,6 +29,7 @@ #include #include +#include class TabWidget : public QWidget { @@ -37,7 +38,7 @@ public: TabWidget( const QString & _caption, QWidget * _parent ); virtual ~TabWidget(); - void addTab( QWidget * _w, const QString & _name, int _idx = -1 ); + void addTab( QWidget * _w, const QString & _name, const char * pixmapName, int _idx = -1 ); void setActiveTab( int _idx ); @@ -57,9 +58,10 @@ protected: private: struct widgetDesc { - QWidget * w; // ptr to widget - QString name; // name for widget - int nwidth; // width of name when painting + QWidget * w; // ptr to widget + const char *pixmapName; // artwork for the widget + QString name; // name for widget + int nwidth; // width of name when painting } ; typedef QMap widgetStack; diff --git a/src/gui/widgets/InstrumentSoundShapingView.cpp b/src/gui/widgets/InstrumentSoundShapingView.cpp index 8c2eb76ab..5d5f1a088 100644 --- a/src/gui/widgets/InstrumentSoundShapingView.cpp +++ b/src/gui/widgets/InstrumentSoundShapingView.cpp @@ -76,7 +76,8 @@ InstrumentSoundShapingView::InstrumentSoundShapingView( QWidget * _parent ) : { m_envLfoViews[i] = new EnvelopeAndLfoView( m_targetsTabWidget ); m_targetsTabWidget->addTab( m_envLfoViews[i], - tr( InstrumentSoundShaping::targetNames[i][0].toUtf8().constData() ) ); + tr( InstrumentSoundShaping::targetNames[i][0].toUtf8().constData() ), + "dummy" ); } diff --git a/src/gui/widgets/TabWidget.cpp b/src/gui/widgets/TabWidget.cpp index b29b27c70..96155e265 100644 --- a/src/gui/widgets/TabWidget.cpp +++ b/src/gui/widgets/TabWidget.cpp @@ -31,6 +31,7 @@ #include #include "gui_templates.h" +#include "embed.h" @@ -61,17 +62,25 @@ TabWidget::~TabWidget() -void TabWidget::addTab( QWidget * _w, const QString & _name, int _idx ) +void TabWidget::addTab( QWidget * _w, const QString & _name, const char * pixmapName, int _idx ) { setFont( pointSize<8>( font() ) ); - widgetDesc d = { _w, _name, fontMetrics().width( _name ) + 10 } ; + + // Append tab when position is not given if( _idx < 0/* || m_widgets.contains( _idx ) == true*/ ) { while( m_widgets.contains( ++_idx ) == true ) { } } + + fprintf( stderr, "adding tab %s. idx=%d\n", pixmapName, _idx); + + // Register new tab + widgetDesc d = { _w, pixmapName, _name, fontMetrics().width( _name ) + 10 } ; m_widgets[_idx] = d; + + // Initialize tab's window _w->setFixedSize( width() - 4, height() - 14 ); _w->move( 2, 13 ); _w->hide(); @@ -108,21 +117,22 @@ void TabWidget::setActiveTab( int _idx ) void TabWidget::mousePressEvent( QMouseEvent * _me ) { + + fprintf( stderr, "TabWidget::mousePressEvent x=%d y=%d\n", _me->x(), _me->y() ); + if( _me->y() > 1 && _me->y() < 13 ) { - int cx = ( ( m_caption == "" ) ? 4 : 14 ) + - fontMetrics().width( m_caption ); for( widgetStack::iterator it = m_widgets.begin(); it != m_widgets.end(); ++it ) { - if( _me->x() >= cx && - _me->x() <= cx + ( *it ).nwidth ) + if( _me->x() >= 8 + it.key() * 30 && + _me->x() <= 8 + it.key() * 30 + 14 ) { + fprintf( stderr, "TabWidget::mousePressEvent Pressed tab %d\n", it.key() ); setActiveTab( it.key() ); update(); return; } - cx += ( *it ).nwidth; } } } @@ -177,9 +187,6 @@ void TabWidget::paintEvent( QPaintEvent * _pe ) p.drawText( 5, 11, m_caption ); } - // Calculate the tabs' x (tabs are painted next to the caption) - int tab_x_offset = m_caption.isEmpty() ? 4 : 14 + fontMetrics().width( m_caption ); - QColor cap_col( 160, 160, 160 ); if( big_tab_captions ) { @@ -192,19 +199,29 @@ void TabWidget::paintEvent( QPaintEvent * _pe ) } p.setPen( cap_col ); + // Draw all tabs + int tab_x_offset = 8; + for( widgetStack::iterator it = m_widgets.begin(); + it != m_widgets.end(); ++it ) + { - for( widgetStack::iterator it = m_widgets.begin(); - it != m_widgets.end(); ++it ) - { - if( it.key() == m_activeTab ) + // Get active or inactive artwork + std::string tab = string( ( *it).pixmapName ); + if( it.key() == m_activeTab ) + { + tab += "_active"; + } else { - p.setPen( QColor( 32, 48, 64 ) ); - p.fillRect( tab_x_offset, 2, ( *it ).nwidth - 6, 10, cap_col ); + tab += "_inactive"; } - p.drawText( tab_x_offset + 3, m_tabheight, ( *it ).name ); - p.setPen( cap_col ); - tab_x_offset += ( *it ).nwidth; - } + QPixmap *artwork = new QPixmap( embed::getIconPixmap( tab.c_str() ) ); + + // Draw tab + p.drawPixmap(tab_x_offset, 0, *artwork ); + + // Next tab's horizontal position + tab_x_offset += 30; + } } diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index 545c82c01..fd200280c 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -1434,11 +1434,11 @@ InstrumentTrackWindow::InstrumentTrackWindow( InstrumentTrackView * _itv ) : m_miscView = new InstrumentMiscView( m_track, m_tabWidget ); - m_tabWidget->addTab( m_ssView, tr( "ENV/LFO" ), 1 ); - m_tabWidget->addTab( instrumentFunctions, tr( "FUNC" ), 2 ); - m_tabWidget->addTab( m_effectView, tr( "FX" ), 3 ); - m_tabWidget->addTab( m_midiView, tr( "MIDI" ), 4 ); - m_tabWidget->addTab( m_miscView, tr( "MISC" ), 5 ); + m_tabWidget->addTab( m_ssView, tr( "ENV/LFO" ), "usr_wave", 1 ); + m_tabWidget->addTab( instrumentFunctions, tr( "FUNC" ), "sin_wave", 2 ); + m_tabWidget->addTab( m_effectView, tr( "FX" ), "saw_wave", 3 ); + m_tabWidget->addTab( m_midiView, tr( "MIDI" ), "round_square_wave", 4 ); + m_tabWidget->addTab( m_miscView, tr( "MISC" ), "exp_wave", 5 ); // setup piano-widget m_pianoView = new PianoView( this ); @@ -1611,7 +1611,7 @@ void InstrumentTrackWindow::updateInstrumentView() if( m_track->m_instrument != NULL ) { m_instrumentView = m_track->m_instrument->createView( m_tabWidget ); - m_tabWidget->addTab( m_instrumentView, tr( "PLUGIN" ), 0 ); + m_tabWidget->addTab( m_instrumentView, tr( "PLUGIN" ), "moog_saw_wave", 0 ); m_tabWidget->setActiveTab( 0 ); m_ssView->setFunctionsHidden( m_track->m_instrument->flags().testFlag( Instrument::IsSingleStreamed ) );