From c896f0d8e89a9dada03c33dfe517a962e1d91cba Mon Sep 17 00:00:00 2001 From: Paul Giblock Date: Fri, 29 Feb 2008 19:08:50 +0000 Subject: [PATCH] touched-up combobox git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@737 0778d3d1-df1d-0410-868b-ea421aaaa00d --- ChangeLog | 7 ++ .../default/combobox_arrow_selected.png | Bin 0 -> 423 bytes data/themes/default/combobox_bg.png | Bin 139 -> 167 bytes include/combobox.h | 1 + src/widgets/combobox.cpp | 61 ++++++++++-------- 5 files changed, 41 insertions(+), 28 deletions(-) create mode 100644 data/themes/default/combobox_arrow_selected.png diff --git a/ChangeLog b/ChangeLog index b3ba4b3ec..8731a2491 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,13 @@ * src/core/track.cpp: playing with alternating colors per tact + * include/combobox.h: + * src/widgets/combobox.cpp: + * data/themes/default/combobox_bg.png: + * data/themes/default/combobox_arrow_selected.png: + - combobox now updates when incremented or decrementing. + - draw combo box with styled border, change arrow when pressed + 2008-02-28 Tobias Doerffel * src/core/plugin.cpp: diff --git a/data/themes/default/combobox_arrow_selected.png b/data/themes/default/combobox_arrow_selected.png new file mode 100644 index 0000000000000000000000000000000000000000..f841bcdb3a94cb3bda46544f6ef478481bacabeb GIT binary patch literal 423 zcmV;Y0a*TtP)4h^@9p za}h43sJY9z6bEt8LGYV@)1MFcH>1CS)=x3(bUHh=S}k8Lmq^nT>-8E+DHvlw2mxaZ zMNwcnor1O7?Ml5~Kea6DIL~ueYi(<-82|#n7-Qa&B)RVOdM7N)vPavtFRImQ({00{sI;FWxna~r@efGq&44OD;oiw}9Nk2&zA R`iB4j002ovPDHLkV1ltTtd;-( literal 0 HcmV?d00001 diff --git a/data/themes/default/combobox_bg.png b/data/themes/default/combobox_bg.png index 424ce88708714165efc353dd9808dfeb2e88081b..86b77c2e362cc3f66edaea88e1f1727d5cf8aedb 100644 GIT binary patch delta 125 zcmeBXT+TQ_TtgTe~DWM4f6EZMc delta 123 zcmZ3^*v&XWyhMnDiGhJ(+DEAiK#H@#BeIx*fwvQg6B&;g|2_y5WH0gbb!ETCC?dwk zlKr-8KTt@^)5S5wr9XSF_8$p Sx*!awi^0>?&t;ucLK6TvVl4>( diff --git a/include/combobox.h b/include/combobox.h index 8598ee2dd..1c68b4aa5 100644 --- a/include/combobox.h +++ b/include/combobox.h @@ -128,6 +128,7 @@ protected: private: static QPixmap * s_background; static QPixmap * s_arrow; + static QPixmap * s_arrowSelected; QMenu m_menu; diff --git a/src/widgets/combobox.cpp b/src/widgets/combobox.cpp index 86a30affd..6f12d0a81 100644 --- a/src/widgets/combobox.cpp +++ b/src/widgets/combobox.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include "automatable_model_templates.h" #include "automation_pattern.h" @@ -43,6 +44,7 @@ QPixmap * comboBox::s_background = NULL; QPixmap * comboBox::s_arrow = NULL; +QPixmap * comboBox::s_arrowSelected = NULL; const int CB_ARROW_BTN_WIDTH = 20; @@ -56,13 +58,19 @@ comboBox::comboBox( QWidget * _parent, const QString & _name ) : if( s_background == NULL ) { s_background = new QPixmap( embed::getIconPixmap( - "combobox_bg" ) ); + "combobox_bg" ) ); } if( s_arrow == NULL ) { s_arrow = new QPixmap( embed::getIconPixmap( - "combobox_arrow" ) ); + "combobox_arrow" ) ); + } + + if( s_arrowSelected == NULL ) + { + s_arrowSelected = new QPixmap( embed::getIconPixmap( + "combobox_arrow_selected" ) ); } setFont( pointSize<9>( font() ) ); @@ -140,10 +148,12 @@ void comboBox::mousePressEvent( QMouseEvent * _me ) else if( _me->button() == Qt::LeftButton ) { model()->setInitValue( model()->value() + 1 ); + update(); } else if( _me->button() == Qt::RightButton ) { model()->setInitValue( model()->value() - 1 ); + update(); } } @@ -154,36 +164,31 @@ void comboBox::paintEvent( QPaintEvent * _pe ) { QPainter p( this ); - p.fillRect( rect(), QColor( 0, 0, 0 ) ); - - for( int x = 2; x < width() - 2; x += s_background->width() ) + for( int x = 1; x < width() - 1; x += s_background->width() ) { - p.drawPixmap( x, 2, *s_background ); + p.drawPixmap( x, 1, *s_background ); } - p.setPen( QColor( 0, 0, 0 ) ); - p.drawLine( width() - 2, 1, width() - 2, height() - 2 ); - - // outer rect - p.setPen( QColor( 64, 64, 64 ) ); - p.drawRect( 0, 0, width(), height() ); - // button-separator - p.setPen( QColor( 64, 64, 64 ) ); - p.drawLine( width() - CB_ARROW_BTN_WIDTH - 1, 0, width() - - CB_ARROW_BTN_WIDTH - 1, height() - 2 ); - p.setPen( QColor( 0, 0, 0 ) ); - p.drawLine( width() - CB_ARROW_BTN_WIDTH, 0, width() - - CB_ARROW_BTN_WIDTH, height() - 2 ); + p.setPen( palette().color( QPalette::Normal, QPalette::Mid ) ); + p.drawLine( width() - CB_ARROW_BTN_WIDTH - 1, 1, width() - + CB_ARROW_BTN_WIDTH - 1, height() - 3 ); - // brighter line at bottom/right - p.setPen( QColor( 160, 160, 160 ) ); - p.drawLine( width() - 1, 0, width() - 1, height() - 1 ); - p.drawLine( 0, height() - 1, width() - 1, height() - 1 ); + p.setPen( palette().color( QPalette::Normal, QPalette::Dark ) ); + p.drawLine( width() - CB_ARROW_BTN_WIDTH, 1, width() - + CB_ARROW_BTN_WIDTH, height() - 3 ); - const int dxy = ( m_pressed == TRUE ) ? 1 : 0; - p.drawPixmap( width() - CB_ARROW_BTN_WIDTH + 4 + dxy, 4 + dxy, - *s_arrow ); + // Border + QStyleOptionFrame opt; + opt.initFrom( this ); + opt.state = QStyle::State_Sunken; + + style()->drawPrimitive( QStyle::PE_Frame, &opt, &p, this ); + + QPixmap * arrow = m_pressed ? s_arrowSelected : s_arrow; + + p.drawPixmap( width() - CB_ARROW_BTN_WIDTH + 5, 4, + *arrow ); if( model()->size() > 0 ) { @@ -204,10 +209,10 @@ void comboBox::paintEvent( QPaintEvent * _pe ) tx += pm.width() + 2; } p.setPen( QColor( 64, 64, 64 ) ); - p.drawText( tx+1, p.fontMetrics().height()-3, + p.drawText( tx+1, p.fontMetrics().height()-1, model()->currentText() ); p.setPen( QColor( 224, 224, 224 ) ); - p.drawText( tx, p.fontMetrics().height()-4, + p.drawText( tx, p.fontMetrics().height()-2, model()->currentText() ); } }