diff options
Diffstat (limited to 'src/widgets/qprogressbar.cpp')
-rw-r--r-- | src/widgets/qprogressbar.cpp | 116 |
1 files changed, 86 insertions, 30 deletions
diff --git a/src/widgets/qprogressbar.cpp b/src/widgets/qprogressbar.cpp index 7a4ec3831..bf40d9e45 100644 --- a/src/widgets/qprogressbar.cpp +++ b/src/widgets/qprogressbar.cpp @@ -44,6 +44,7 @@ #include "ntqdrawutil.h" #include "ntqpixmap.h" #include "ntqstyle.h" +#include "ntqwmatrix.h" #include "../kernel/qinternal_p.h" #if defined(QT_ACCESSIBILITY_SUPPORT) #include "ntqaccessible.h" @@ -102,7 +103,8 @@ TQProgressBar::TQProgressBar( TQWidget *parent, const char *name, WFlags f ) center_indicator( TRUE ), auto_indicator( TRUE ), percentage_visible( TRUE ), - d( 0 ) + d( 0 ), + m_orientation( Horizontal ) { setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed ) ); initFrame(); @@ -133,7 +135,8 @@ TQProgressBar::TQProgressBar( int totalSteps, center_indicator( TRUE ), auto_indicator( TRUE ), percentage_visible( TRUE ), - d( 0 ) + d( 0 ), + m_orientation( Horizontal ) { setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed ) ); initFrame(); @@ -234,9 +237,15 @@ TQSize TQProgressBar::sizeHint() const constPolish(); TQFontMetrics fm = fontMetrics(); int cw = style().pixelMetric(TQStyle::PM_ProgressBarChunkWidth, this); - return style().sizeFromContents(TQStyle::CT_ProgressBar, this, + TQSize sh = style().sizeFromContents(TQStyle::CT_ProgressBar, this, TQSize( cw * 7 + fm.width( '0' ) * 4, fm.height() + 8)); + if (m_orientation == TQt::Horizontal) { + return sh; + } + else { + return TQSize(sh.height(), sh.width()); + } } @@ -321,6 +330,22 @@ void TQProgressBar::styleChange( TQStyle& old ) TQFrame::styleChange( old ); } +TQt::Orientation TQProgressBar::orientation() const +{ + return m_orientation; +} + +void TQProgressBar::setOrientation(Orientation orient) +{ + m_orientation = orient; + if (m_orientation == TQt::Horizontal) { + setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Fixed ) ); + } + else { + setSizePolicy( TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Expanding ) ); + } +} + /*! This method is called to generate the text displayed in the center @@ -371,40 +396,71 @@ bool TQProgressBar::setIndicator( TQString & indicator, int progress, */ void TQProgressBar::drawContents( TQPainter *p ) { - const TQRect bar = contentsRect(); + const TQRect bar = contentsRect(); + + TQSharedDoubleBuffer buffer( p, bar.x(), bar.y(), bar.width(), bar.height() ); + + TQPoint pn = backgroundOffset(); + buffer.painter()->setBrushOrigin( -pn.x(), -pn.y() ); + + const TQPixmap *bpm = paletteBackgroundPixmap(); + if ( bpm ) { + buffer.painter()->fillRect( bar, TQBrush( paletteBackgroundColor(), *bpm ) ); + } + else { + buffer.painter()->fillRect( bar, paletteBackgroundColor() ); + } + buffer.painter()->setFont( p->font() ); - TQSharedDoubleBuffer buffer( p, bar.x(), bar.y(), bar.width(), bar.height() ); + TQStyle::SFlags flags = TQStyle::Style_Default; + if (isEnabled()) { + flags |= TQStyle::Style_Enabled; + } + if (hasFocus()) { + flags |= TQStyle::Style_HasFocus; + } + if (hasMouse()) { + flags |= TQStyle::Style_MouseOver; + } - TQPoint pn = backgroundOffset(); - buffer.painter()->setBrushOrigin( -pn.x(), -pn.y() ); + style().drawControl(TQStyle::CE_ProgressBarGroove, buffer.painter(), this, + TQStyle::visualRect(style().subRect(TQStyle::SR_ProgressBarGroove, this), this ), + colorGroup(), flags); - const TQPixmap *bpm = paletteBackgroundPixmap(); - if ( bpm ) - buffer.painter()->fillRect( bar, TQBrush( paletteBackgroundColor(), *bpm ) ); - else - buffer.painter()->fillRect( bar, paletteBackgroundColor() ); - buffer.painter()->setFont( p->font() ); + TQWMatrix oldMatrix = buffer.painter()->worldMatrix(); - TQStyle::SFlags flags = TQStyle::Style_Default; - if (isEnabled()) - flags |= TQStyle::Style_Enabled; - if (hasFocus()) - flags |= TQStyle::Style_HasFocus; - if (hasMouse()) - flags |= TQStyle::Style_MouseOver; + TQStyleControlElementData ceData = populateControlElementDataFromWidget(this, TQStyleOption()); + TQStyle::ControlElementFlags elementFlags = getControlElementFlagsForObject(this, ceData.widgetObjectTypes, TQStyleOption()); - style().drawControl(TQStyle::CE_ProgressBarGroove, buffer.painter(), this, - TQStyle::visualRect(style().subRect(TQStyle::SR_ProgressBarGroove, this), this ), - colorGroup(), flags); + // Draw contents + if (m_orientation == TQt::Vertical) { + // If oriented vertically, apply a 90 degree rotation matrix to the painter + TQWMatrix m; - style().drawControl(TQStyle::CE_ProgressBarContents, buffer.painter(), this, - TQStyle::visualRect(style().subRect(TQStyle::SR_ProgressBarContents, this), this ), - colorGroup(), flags); +// // Upside down +// m.rotate(90.0); +// m.translate(0, (bar.width())*(-1.0)); + + // Right side up + m.rotate(-90.0); + m.translate((bar.height())*(-1.0), 0); - if (percentageVisible()) - style().drawControl(TQStyle::CE_ProgressBarLabel, buffer.painter(), this, - TQStyle::visualRect(style().subRect(TQStyle::SR_ProgressBarLabel, this), this ), - colorGroup(), flags); + buffer.painter()->setWorldMatrix(m, TRUE); + + ceData.rect = TQRect(ceData.rect.y(), ceData.rect.x(), ceData.rect.height(), ceData.rect.width()); + } + + style().drawControl(TQStyle::CE_ProgressBarContents, buffer.painter(), ceData, elementFlags, + TQStyle::visualRect(style().subRect(TQStyle::SR_ProgressBarContents, ceData, elementFlags, this), ceData, elementFlags), + colorGroup(), flags, TQStyleOption(), this); + + buffer.painter()->setWorldMatrix(oldMatrix, TRUE); + + if (percentageVisible()) { + style().drawControl(TQStyle::CE_ProgressBarLabel, buffer.painter(), this, + TQStyle::visualRect(style().subRect(TQStyle::SR_ProgressBarLabel, this), this ), + colorGroup(), flags); + } } #endif |