|
|
|
@ -44,6 +44,7 @@
|
|
|
|
|
#include "qdrawutil.h"
|
|
|
|
|
#include "qpixmap.h"
|
|
|
|
|
#include "qstyle.h"
|
|
|
|
|
#include "qwmatrix.h"
|
|
|
|
|
#include "../kernel/qinternal_p.h"
|
|
|
|
|
#if defined(QT_ACCESSIBILITY_SUPPORT)
|
|
|
|
|
#include "qaccessible.h"
|
|
|
|
@ -102,7 +103,8 @@ QProgressBar::QProgressBar( QWidget *parent, const char *name, WFlags f )
|
|
|
|
|
center_indicator( TRUE ),
|
|
|
|
|
auto_indicator( TRUE ),
|
|
|
|
|
percentage_visible( TRUE ),
|
|
|
|
|
d( 0 )
|
|
|
|
|
d( 0 ),
|
|
|
|
|
m_orientation( Horizontal )
|
|
|
|
|
{
|
|
|
|
|
setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
|
|
|
|
|
initFrame();
|
|
|
|
@ -133,7 +135,8 @@ QProgressBar::QProgressBar( int totalSteps,
|
|
|
|
|
center_indicator( TRUE ),
|
|
|
|
|
auto_indicator( TRUE ),
|
|
|
|
|
percentage_visible( TRUE ),
|
|
|
|
|
d( 0 )
|
|
|
|
|
d( 0 ),
|
|
|
|
|
m_orientation( Horizontal )
|
|
|
|
|
{
|
|
|
|
|
setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
|
|
|
|
|
initFrame();
|
|
|
|
@ -234,9 +237,15 @@ QSize QProgressBar::sizeHint() const
|
|
|
|
|
constPolish();
|
|
|
|
|
QFontMetrics fm = fontMetrics();
|
|
|
|
|
int cw = style().pixelMetric(QStyle::PM_ProgressBarChunkWidth, this);
|
|
|
|
|
return style().sizeFromContents(QStyle::CT_ProgressBar, this,
|
|
|
|
|
QSize sh = style().sizeFromContents(QStyle::CT_ProgressBar, this,
|
|
|
|
|
QSize( cw * 7 + fm.width( '0' ) * 4,
|
|
|
|
|
fm.height() + 8));
|
|
|
|
|
if (m_orientation == Qt::Horizontal) {
|
|
|
|
|
return sh;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return QSize(sh.height(), sh.width());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -321,6 +330,22 @@ void QProgressBar::styleChange( QStyle& old )
|
|
|
|
|
QFrame::styleChange( old );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt::Orientation QProgressBar::orientation() const
|
|
|
|
|
{
|
|
|
|
|
return m_orientation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QProgressBar::setOrientation(Orientation orient)
|
|
|
|
|
{
|
|
|
|
|
m_orientation = orient;
|
|
|
|
|
if (m_orientation == Qt::Horizontal) {
|
|
|
|
|
setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Expanding ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
This method is called to generate the text displayed in the center
|
|
|
|
@ -371,40 +396,71 @@ bool QProgressBar::setIndicator( QString & indicator, int progress,
|
|
|
|
|
*/
|
|
|
|
|
void QProgressBar::drawContents( QPainter *p )
|
|
|
|
|
{
|
|
|
|
|
const QRect bar = contentsRect();
|
|
|
|
|
const QRect bar = contentsRect();
|
|
|
|
|
|
|
|
|
|
QSharedDoubleBuffer buffer( p, bar.x(), bar.y(), bar.width(), bar.height() );
|
|
|
|
|
|
|
|
|
|
QPoint pn = backgroundOffset();
|
|
|
|
|
buffer.painter()->setBrushOrigin( -pn.x(), -pn.y() );
|
|
|
|
|
|
|
|
|
|
const QPixmap *bpm = paletteBackgroundPixmap();
|
|
|
|
|
if ( bpm ) {
|
|
|
|
|
buffer.painter()->fillRect( bar, QBrush( paletteBackgroundColor(), *bpm ) );
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
buffer.painter()->fillRect( bar, paletteBackgroundColor() );
|
|
|
|
|
}
|
|
|
|
|
buffer.painter()->setFont( p->font() );
|
|
|
|
|
|
|
|
|
|
QSharedDoubleBuffer buffer( p, bar.x(), bar.y(), bar.width(), bar.height() );
|
|
|
|
|
QStyle::SFlags flags = QStyle::Style_Default;
|
|
|
|
|
if (isEnabled()) {
|
|
|
|
|
flags |= QStyle::Style_Enabled;
|
|
|
|
|
}
|
|
|
|
|
if (hasFocus()) {
|
|
|
|
|
flags |= QStyle::Style_HasFocus;
|
|
|
|
|
}
|
|
|
|
|
if (hasMouse()) {
|
|
|
|
|
flags |= QStyle::Style_MouseOver;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QPoint pn = backgroundOffset();
|
|
|
|
|
buffer.painter()->setBrushOrigin( -pn.x(), -pn.y() );
|
|
|
|
|
style().drawControl(QStyle::CE_ProgressBarGroove, buffer.painter(), this,
|
|
|
|
|
QStyle::visualRect(style().subRect(QStyle::SR_ProgressBarGroove, this), this ),
|
|
|
|
|
colorGroup(), flags);
|
|
|
|
|
|
|
|
|
|
const QPixmap *bpm = paletteBackgroundPixmap();
|
|
|
|
|
if ( bpm )
|
|
|
|
|
buffer.painter()->fillRect( bar, QBrush( paletteBackgroundColor(), *bpm ) );
|
|
|
|
|
else
|
|
|
|
|
buffer.painter()->fillRect( bar, paletteBackgroundColor() );
|
|
|
|
|
buffer.painter()->setFont( p->font() );
|
|
|
|
|
QWMatrix oldMatrix = buffer.painter()->worldMatrix();
|
|
|
|
|
|
|
|
|
|
QStyle::SFlags flags = QStyle::Style_Default;
|
|
|
|
|
if (isEnabled())
|
|
|
|
|
flags |= QStyle::Style_Enabled;
|
|
|
|
|
if (hasFocus())
|
|
|
|
|
flags |= QStyle::Style_HasFocus;
|
|
|
|
|
if (hasMouse())
|
|
|
|
|
flags |= QStyle::Style_MouseOver;
|
|
|
|
|
QStyleControlElementData ceData = populateControlElementDataFromWidget(this, QStyleOption());
|
|
|
|
|
QStyle::ControlElementFlags elementFlags = getControlElementFlagsForObject(this, ceData.widgetObjectTypes, QStyleOption());
|
|
|
|
|
|
|
|
|
|
style().drawControl(QStyle::CE_ProgressBarGroove, buffer.painter(), this,
|
|
|
|
|
QStyle::visualRect(style().subRect(QStyle::SR_ProgressBarGroove, this), this ),
|
|
|
|
|
colorGroup(), flags);
|
|
|
|
|
// Draw contents
|
|
|
|
|
if (m_orientation == Qt::Vertical) {
|
|
|
|
|
// If oriented vertically, apply a 90 degree rotation matrix to the painter
|
|
|
|
|
QWMatrix m;
|
|
|
|
|
|
|
|
|
|
style().drawControl(QStyle::CE_ProgressBarContents, buffer.painter(), this,
|
|
|
|
|
QStyle::visualRect(style().subRect(QStyle::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(QStyle::CE_ProgressBarLabel, buffer.painter(), this,
|
|
|
|
|
QStyle::visualRect(style().subRect(QStyle::SR_ProgressBarLabel, this), this ),
|
|
|
|
|
colorGroup(), flags);
|
|
|
|
|
buffer.painter()->setWorldMatrix(m, TRUE);
|
|
|
|
|
|
|
|
|
|
ceData.rect = QRect(ceData.rect.y(), ceData.rect.x(), ceData.rect.height(), ceData.rect.width());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
style().drawControl(QStyle::CE_ProgressBarContents, buffer.painter(), ceData, elementFlags,
|
|
|
|
|
QStyle::visualRect(style().subRect(QStyle::SR_ProgressBarContents, ceData, elementFlags, this), ceData, elementFlags),
|
|
|
|
|
colorGroup(), flags, QStyleOption(), this);
|
|
|
|
|
|
|
|
|
|
buffer.painter()->setWorldMatrix(oldMatrix, TRUE);
|
|
|
|
|
|
|
|
|
|
if (percentageVisible()) {
|
|
|
|
|
style().drawControl(QStyle::CE_ProgressBarLabel, buffer.painter(), this,
|
|
|
|
|
QStyle::visualRect(style().subRect(QStyle::SR_ProgressBarLabel, this), this ),
|
|
|
|
|
colorGroup(), flags);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|