[Jahshaka-cvs] jah/jahwidgets/src/qt3/widgets rangeControl.cpp, 1.2, 1.3
Status: Beta
Brought to you by:
jahshaka
From: John B. <ok_...@us...> - 2006-09-20 09:46:43
|
Update of /cvsroot/jahshaka/jah/jahwidgets/src/qt3/widgets In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv20802/jahwidgets/src/qt3/widgets Modified Files: rangeControl.cpp Log Message: * Improved handling of null pixmaps Index: rangeControl.cpp =================================================================== RCS file: /cvsroot/jahshaka/jah/jahwidgets/src/qt3/widgets/rangeControl.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- rangeControl.cpp 20 Sep 2006 08:59:56 -0000 1.2 +++ rangeControl.cpp 20 Sep 2006 09:46:40 -0000 1.3 @@ -20,6 +20,7 @@ #include <qimage.h> #include <qpointarray.h> #include <qstring.h> +#include <qfont.h> #include <memory> @@ -273,13 +274,15 @@ valueDidChange(); } -QSize RangeControlButton::buttonSize = QSize( 7, 14 ); +QSize RangeControlButton::buttonSize = QSize( 9, 14 ); RangeControlButton::RangeControlButton( Qt::ButtonState state, QWidget* parent ) : QButton( parent ), state_( state ), color_( Qt::lightGray ) { + static const int margin = 2; + // Build our polygon. Whatever algorithm Qt uses to draw polygons isn't // stable, so we have to tweak the points to get symmetric arrow heads. // Hopefully these tweaks won't turn out to be platform specific... @@ -288,14 +291,14 @@ // Increase width/height by 1 pixel to match right arrow buttonSize.width() + 1, -1, buttonSize.width() + 1, buttonSize.height() + 1, - 0, buttonSize.height() / 2 ); + margin, buttonSize.height() / 2 ); } else { points_.putPoints( 0, 3, // Indent by 1px to match left arrow 1, 1, 1, buttonSize.height(), - buttonSize.width(), buttonSize.height() / 2 ); + buttonSize.width() - margin, buttonSize.height() / 2 ); } resize( RangeControlButton::buttonSize ); @@ -355,7 +358,6 @@ RangeControlImpl::RangeControlImpl( QWidget* owner ) : owner_( owner ), - //label_( "Contrast" ), bgPixmap_( Resource( "v3/rangeControl_bg.png" ).toQPixmap() ), fgOriginal_( Resource( "v3/rangeControl_fg.png" ).toQImage() ) { @@ -377,6 +379,16 @@ void RangeControlImpl::drawControl( QPaintEvent* ) { + if ( bgPixmap_.isNull() ) { + // Just draw some placeholder text + QPainter p( owner_ ); + p.setPen( Qt::white ); + p.setFont( QFont( "Arial", 16 ) ); + p.drawText( 0, 0, size().width(), size().height(), Qt::AlignHCenter | Qt::AlignVCenter, "No\nPixmap" ); + return; + } + + // Update our foreground if necessary if ( fgPixmap_.isNull() ) { updateFGPixmap(); } @@ -418,19 +430,21 @@ p.setPen( value() < 0 ? Qt::red : Qt::yellow ); p.drawText( imageRect(), Qt::AlignHCenter | Qt::AlignVCenter, QString::number( value() ) ); } + + p.end(); } void RangeControlImpl::updateButtonPositions() { - leftButton_->move( 0, (bgPixmap_.height() - RangeControlButton::buttonSize.height() ) / 2 ); - - rightButton_->move( RangeControlButton::buttonSize.width() + bgPixmap_.width(), - (bgPixmap_.height() - RangeControlButton::buttonSize.height() ) / 2 ); + int y = (size().height() - RangeControlButton::buttonSize.height()) / 2; + leftButton_->move( 0, y ); + rightButton_->move( size().width() - RangeControlButton::buttonSize.width(), y ); } QSize RangeControlImpl::size() const { QSize size = bgPixmap_.size(); + if ( size.isEmpty() ) size = QSize( 100, 100 ); size.setWidth( size.width() + 2 * RangeControlButton::buttonSize.width() ); return size; } |