TabWidget is 20 pixels tall when it's going to display artwork tabs.

This commit is contained in:
Cyrille Bollu
2016-02-21 22:06:44 +01:00
parent f071393e55
commit 312764b38c
9 changed files with 78 additions and 49 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 230 B

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 378 B

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 235 B

After

Width:  |  Height:  |  Size: 642 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 961 B

After

Width:  |  Height:  |  Size: 672 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 242 B

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 378 B

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@@ -29,16 +29,14 @@
#include <QWidget>
#include <QtCore/QMap>
#include <string>
class TabWidget : public QWidget
{
Q_OBJECT
public:
TabWidget( const QString & _caption, QWidget * _parent );
TabWidget( const QString & _caption, QWidget * _parent, bool usePixmap = false );
virtual ~TabWidget();
void addTab( QWidget * _w, const QString & _name, const char * pixmapName, int _idx = -1 );
void addTab( QWidget *_w, const QString &_name, const char *activePixmap = NULL, const char *inactivePixmap = NULL, int _idx = -1 );
void setActiveTab( int _idx );
@@ -58,17 +56,20 @@ protected:
private:
struct widgetDesc
{
QWidget * w; // ptr to widget
const char *pixmapName; // artwork for the widget
QString name; // name for widget
int nwidth; // width of name when painting
QWidget * w; // ptr to widget
const char *activePixmap; // artwork for the widget
const char *inactivePixmap; // artwork for the widget
QString name; // name for widget
int nwidth; // width of name when painting (only valid for text tab)
} ;
typedef QMap<int, widgetDesc> widgetStack;
widgetStack m_widgets;
int m_activeTab;
int m_activeTab;
QString m_caption;
quint8 m_tabheight;
quint8 m_tabheight;
bool m_usePixmap; // true if the tabs are to be displayed with icons. False for text tabs.
} ;
#endif

View File

@@ -33,14 +33,27 @@
#include "gui_templates.h"
#include "embed.h"
const int GRAPHICAL_TAB_HEIGHT = 20;
const int TEXT_TAB_HEIGHT = 14;
TabWidget::TabWidget( const QString & _caption, QWidget * _parent ) :
TabWidget::TabWidget( const QString & _caption, QWidget * _parent, bool usePixmap ) :
QWidget( _parent ),
m_activeTab( 0 ),
m_caption( _caption ),
m_tabheight( _caption.isEmpty() ? 11: 10 )
{
// TabWidget with artwork tabs have a height of 20 pixels
if ( usePixmap )
{
m_usePixmap = true;
m_tabheight = GRAPHICAL_TAB_HEIGHT;
} else
{
m_usePixmap = false;
m_tabheight = _caption.isEmpty() ? TEXT_TAB_HEIGHT - 3 : TEXT_TAB_HEIGHT - 4;
}
setFont( pointSize<8>( font() ) );
setAutoFillBackground( true );
@@ -62,7 +75,7 @@ TabWidget::~TabWidget()
void TabWidget::addTab( QWidget * _w, const QString & _name, const char * pixmapName, int _idx )
void TabWidget::addTab( QWidget * _w, const QString & _name, const char *activePixmap, const char *inactivePixmap, int _idx )
{
setFont( pointSize<8>( font() ) );
@@ -78,14 +91,21 @@ void TabWidget::addTab( QWidget * _w, const QString & _name, const char * pixma
int w = fontMetrics().width( _name ) + 10;
// Register new tab
widgetDesc d = { _w, pixmapName, _name, w } ;
widgetDesc d = { _w, activePixmap, inactivePixmap, _name, w } ;
m_widgets[_idx] = d;
// Initialize tab's window
_w->setFixedSize( width() - 4, height() - 14 );
_w->move( 2, 13 );
// Position tab's window
if (m_usePixmap) {
_w->setFixedSize( width() - 4, height() - GRAPHICAL_TAB_HEIGHT );
_w->move( 2, GRAPHICAL_TAB_HEIGHT -1 );
} else
{
_w->setFixedSize( width() - 4, height() - TEXT_TAB_HEIGHT );
_w->move( 2, TEXT_TAB_HEIGHT - 1 );
}
_w->hide();
// Show tab's window if it's active
if( m_widgets.contains( m_activeTab ) )
{
// make sure new tab doesn't overlap current widget
@@ -119,7 +139,9 @@ void TabWidget::setActiveTab( int _idx )
void TabWidget::mousePressEvent( QMouseEvent * _me )
{
if( _me->y() > 1 && _me->y() < 13 )
int height = ( m_usePixmap ? GRAPHICAL_TAB_HEIGHT -1 : TEXT_TAB_HEIGHT -1 );
if( _me->y() > 1 && _me->y() < height )
{
int cx = ( ( m_caption == "" ) ? 4 : 14 ) +
fontMetrics().width( m_caption );
@@ -146,7 +168,12 @@ void TabWidget::resizeEvent( QResizeEvent * )
for( widgetStack::iterator it = m_widgets.begin();
it != m_widgets.end(); ++it )
{
( *it ).w->setFixedSize( width() - 4, height() - 14 );
if ( m_usePixmap ) {
( *it ).w->setFixedSize( width() - 4, height() - GRAPHICAL_TAB_HEIGHT );
} else
{
( *it ).w->setFixedSize( width() - 4, height() - TEXT_TAB_HEIGHT );
}
}
}
@@ -206,19 +233,38 @@ void TabWidget::paintEvent( QPaintEvent * _pe )
// Draw all tabs
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 )
// Draw a text tab or a artwork tab.
if ( m_usePixmap )
{
// Recompute tab's width, because original size is only correct for text tabs
int size = std::distance(first,last);
( *it ).nwidth = width() / size;
// Get active or inactive artwork
QPixmap *artwork;
if( it.key() == m_activeTab )
{
artwork = new QPixmap( embed::getIconPixmap( ( *it ).activePixmap ) );
p.fillRect( tab_x_offset, 1, width() / size, GRAPHICAL_TAB_HEIGHT, cap_col );
} else
{
artwork = new QPixmap( embed::getIconPixmap( ( *it ).inactivePixmap ) );
}
// Draw artwork
p.drawPixmap(tab_x_offset + ( ( *it ).nwidth - ( *artwork ).width() ) / 2, 1, *artwork );
} else
{
// 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 );
p.fillRect( tab_x_offset, 2, ( *it ).nwidth - 6, TEXT_TAB_HEIGHT - 4, cap_col );
}
// Draw text
@@ -226,24 +272,6 @@ void TabWidget::paintEvent( QPaintEvent * _pe )
// Reset text color
p.setPen( cap_col );
} else
{
// 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;
}
// Next tab's horizontal position

View File

@@ -1406,8 +1406,8 @@ InstrumentTrackWindow::InstrumentTrackWindow( InstrumentTrackView * _itv ) :
generalSettingsLayout->addLayout( basicControlsLayout );
m_tabWidget = new TabWidget( "", this );
m_tabWidget->setFixedHeight( INSTRUMENT_HEIGHT + 10 );
m_tabWidget = new TabWidget( "", this, true );
m_tabWidget->setFixedHeight( INSTRUMENT_HEIGHT + 16 );
// create tab-widgets
@@ -1434,11 +1434,11 @@ InstrumentTrackWindow::InstrumentTrackWindow( InstrumentTrackView * _itv ) :
m_miscView = new InstrumentMiscView( m_track, m_tabWidget );
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_inactive", 4 );
m_tabWidget->addTab( m_miscView, tr( "MISC" ), "miscellaneous", 5 );
m_tabWidget->addTab( m_ssView, tr( "ENV/LFO" ), "env_lfo_active", "env_lfo_inactive", 1 );
m_tabWidget->addTab( instrumentFunctions, tr( "FUNC" ), "functions_active", "functions_inactive", 2 );
m_tabWidget->addTab( m_effectView, tr( "FX" ), "fx_active", "fx_inactive", 3 );
m_tabWidget->addTab( m_midiView, tr( "MIDI" ), "midi_active", "midi_inactive", 4 );
m_tabWidget->addTab( m_miscView, tr( "MISC" ), "miscellaneous_active", "miscellaneous_inactive", 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" ), "plugin", 0 );
m_tabWidget->addTab( m_instrumentView, tr( "PLUGIN" ), "plugin_active", "plugin_inactive", 0 );
m_tabWidget->setActiveTab( 0 );
m_ssView->setFunctionsHidden( m_track->m_instrument->flags().testFlag( Instrument::IsSingleStreamed ) );