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.
This commit is contained in:
Cyrille Bollu
2016-02-12 15:58:45 +01:00
parent 14046684a5
commit 655362452f
4 changed files with 51 additions and 31 deletions

View File

@@ -29,6 +29,7 @@
#include <QWidget>
#include <QtCore/QMap>
#include <string>
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<int, widgetDesc> widgetStack;

View File

@@ -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" );
}

View File

@@ -31,6 +31,7 @@
#include <QWheelEvent>
#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;
}
}

View File

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