diff --git a/src/plugins/styles/android/qandroidstyle.cpp b/src/plugins/styles/android/qandroidstyle.cpp index 0a4e4286e0..8036655b04 100644 --- a/src/plugins/styles/android/qandroidstyle.cpp +++ b/src/plugins/styles/android/qandroidstyle.cpp @@ -1619,10 +1619,11 @@ void QAndroidStyle::AndroidProgressBarControl::drawControl(const QStyleOption *o if (m_progressDrawable->type() == QAndroidStyle::Layer) { const double fraction = double(qint64(pb->progress) - pb->minimum) / (qint64(pb->maximum) - pb->minimum); QAndroidStyle::AndroidDrawable *clipDrawable = static_cast(m_progressDrawable)->layer(m_progressId); + const Qt::Orientation orientation = pb->state & QStyle::State_Horizontal ? Qt::Horizontal : Qt::Vertical; if (clipDrawable->type() == QAndroidStyle::Clip) - static_cast(clipDrawable)->setFactor(fraction, pb->orientation); + static_cast(clipDrawable)->setFactor(fraction, orientation); else - static_cast(m_progressDrawable)->setFactor(m_progressId, fraction, pb->orientation); + static_cast(m_progressDrawable)->setFactor(m_progressId, fraction, orientation); } m_progressDrawable->draw(p, option); } @@ -1634,7 +1635,7 @@ QRect QAndroidStyle::AndroidProgressBarControl::subElementRect(QStyle::SubElemen { if (const QStyleOptionProgressBar *progressBarOption = qstyleoption_cast(option)) { - const bool horizontal = progressBarOption->orientation == Qt::Vertical; + const bool horizontal = progressBarOption->state & QStyle::State_Horizontal; if (!m_background) return option->rect; @@ -1676,12 +1677,12 @@ QSize QAndroidStyle::AndroidProgressBarControl::sizeFromContents(const QStyleOpt if (const QStyleOptionProgressBar *progressBarOption = qstyleoption_cast(opt)) { - if (progressBarOption->orientation == Qt::Vertical) { - if (sz.height() > m_maxSize.height()) - sz.setHeight(m_maxSize.height()); - } else { + if (progressBarOption->state & QStyle::State_Horizontal) { if (sz.width() > m_maxSize.width()) sz.setWidth(m_maxSize.width()); + } else { + if (sz.height() > m_maxSize.height()) + sz.setHeight(m_maxSize.height()); } } return contentsSize; diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index f970f08889..b78a977e2a 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -4382,7 +4382,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter case CE_ProgressBarContents: if (const QStyleOptionProgressBar *pb = qstyleoption_cast(opt)) { const bool isIndeterminate = (pb->minimum == 0 && pb->maximum == 0); - const bool vertical = pb->orientation == Qt::Vertical; + const bool vertical = !(pb->state & QStyle::State_Horizontal); const bool inverted = pb->invertedAppearance; bool reverse = (!vertical && (pb->direction == Qt::RightToLeft)); if (inverted) diff --git a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp index 7ad5fbe34d..016fd3a6cc 100644 --- a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp +++ b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp @@ -1006,7 +1006,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption if (const QStyleOptionProgressBar *bar = qstyleoption_cast(option)) { bool isIndeterminate = (bar->minimum == 0 && bar->maximum == 0); - const bool vertical = bar->orientation == Qt::Vertical; + const bool vertical = !(bar->state & QStyle::State_Horizontal); const bool inverted = bar->invertedAppearance; if (isIndeterminate || (bar->progress > 0 && (bar->progress < bar->maximum) && d->transitionsEnabled())) { diff --git a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp index d00413538b..bbd0401ff1 100644 --- a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp +++ b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp @@ -383,6 +383,13 @@ bool QWindowsXPStylePrivate::isLineEditBaseColorSet(const QStyleOption *option, return (resolveMask & (1 << QPalette::Base)) != 0; } +static inline Qt::Orientation progressBarOrientation(const QStyleOption *option = nullptr) +{ + if (const QStyleOptionProgressBar *pb = qstyleoption_cast(option)) + return pb->state & QStyle::State_Horizontal ? Qt::Horizontal : Qt::Vertical; + return Qt::Horizontal; +} + /*! \internal This function will always return a valid window handle, and might create a limbo widget to do so. @@ -1739,10 +1746,10 @@ case PE_Frame: Qt::Orientation orient = Qt::Horizontal; bool inverted = false; if (const QStyleOptionProgressBar *pb = qstyleoption_cast(option)) { - orient = pb->orientation; + orient = pb->state & QStyle::State_Horizontal ? Qt::Horizontal : Qt::Vertical; inverted = pb->invertedAppearance; } - if (orient == Qt::Horizontal) { + if (orient & Qt::Horizontal) { partId = PP_CHUNK; rect = QRect(option->rect.x(), option->rect.y(), option->rect.width(), option->rect.height() ); if (inverted && option->direction == Qt::LeftToRight) @@ -2117,9 +2124,7 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op case CE_ProgressBarGroove: { - Qt::Orientation orient = Qt::Horizontal; - if (const QStyleOptionProgressBar *pb = qstyleoption_cast(option)) - orient = pb->orientation; + Qt::Orientation orient = progressBarOrientation(option); partId = (orient == Qt::Horizontal) ? PP_BAR : PP_BARVERT; themeNumber = QWindowsXPStylePrivate::ProgressTheme; stateId = 1; @@ -3155,13 +3160,6 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo } } -static inline Qt::Orientation progressBarOrientation(const QStyleOption *option = nullptr) -{ - if (const QStyleOptionProgressBar *pb = qstyleoption_cast(option)) - return pb->orientation; - return Qt::Horizontal; -} - int QWindowsXPStylePrivate::pixelMetricFromSystemDp(QStyle::PixelMetric pm, const QStyleOption *option, const QWidget *widget) { switch (pm) { diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 94745d3ec9..37f17f784a 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -307,7 +307,7 @@ void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, Q { bool vertical = false; if (const QStyleOptionProgressBar *pb = qstyleoption_cast(opt)) - vertical = pb->orientation == Qt::Vertical; + vertical = !(pb->state & QStyle::State_Horizontal); if (!vertical) { p->fillRect(opt->rect.x(), opt->rect.y() + 3, opt->rect.width() -2, opt->rect.height() - 6, opt->palette.brush(QPalette::Highlight)); @@ -1526,7 +1526,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, break; case CE_ProgressBarLabel: if (const QStyleOptionProgressBar *pb = qstyleoption_cast(opt)) { - const bool vertical = pb->orientation == Qt::Vertical; + const bool vertical = !(pb->state & QStyle::State_Horizontal); if (!vertical) { QPalette::ColorRole textRole = QPalette::NoRole; if ((pb->textAlignment & Qt::AlignCenter) && pb->textVisible @@ -1551,7 +1551,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, if (const QStyleOptionProgressBar *pb = qstyleoption_cast(opt)) { QRect rect = pb->rect; - const bool vertical = pb->orientation == Qt::Vertical; + const bool vertical = !(pb->state & QStyle::State_Horizontal); const bool inverted = pb->invertedAppearance; qint64 minimum = qint64(pb->minimum); qint64 maximum = qint64(pb->maximum); @@ -2591,7 +2591,7 @@ QRect QCommonStyle::subElementRect(SubElement sr, const QStyleOption *opt, case SE_ProgressBarLabel: if (const QStyleOptionProgressBar *pb = qstyleoption_cast(opt)) { int textw = 0; - const bool vertical = pb->orientation == Qt::Vertical; + const bool vertical = !(pb->state & QStyle::State_Horizontal); if (!vertical) { if (pb->textVisible) textw = qMax(pb->fontMetrics.horizontalAdvance(pb->text), pb->fontMetrics.horizontalAdvance(QLatin1String("100%"))) + 6; diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index 3f985bfe4c..daf0710b70 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -1364,8 +1364,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio bool indeterminate = (bar->minimum == 0 && bar->maximum == 0); bool complete = bar->progress == bar->maximum; - // Get extra style options if version 2 - vertical = (bar->orientation == Qt::Vertical); + vertical = !(bar->state & QStyle::State_Horizontal); inverted = bar->invertedAppearance; // If the orientation is vertical, we use a transform to rotate @@ -1474,7 +1473,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio painter->save(); bool vertical = false, inverted = false; - vertical = (bar->orientation == Qt::Vertical); + vertical = !(bar->state & QStyle::State_Horizontal); inverted = bar->invertedAppearance; if (vertical) rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height diff --git a/src/widgets/styles/qpixmapstyle.cpp b/src/widgets/styles/qpixmapstyle.cpp index 7cc32b2039..9213ff759e 100644 --- a/src/widgets/styles/qpixmapstyle.cpp +++ b/src/widgets/styles/qpixmapstyle.cpp @@ -825,7 +825,7 @@ void QPixmapStyle::drawProgressBarBackground(const QStyleOption *option, bool vertical = false; if (const QStyleOptionProgressBar *pb = qstyleoption_cast(option)) { - vertical = pb->orientation == Qt::Vertical; + vertical = !(pb->state & QStyle::State_Horizontal); } drawCachedPixmap(vertical ? PB_VBackground : PB_HBackground, option->rect, painter); } @@ -835,7 +835,7 @@ void QPixmapStyle::drawProgressBarLabel(const QStyleOption *option, { if (const QStyleOptionProgressBar *pb = qstyleoption_cast(option)) { - const bool vertical = pb->orientation == Qt::Vertical; + const bool vertical = !(pb->state & QStyle::State_Horizontal); if (!vertical) { QPalette::ColorRole textRole = QPalette::ButtonText; proxy()->drawItemText(painter, pb->rect, @@ -850,7 +850,7 @@ void QPixmapStyle::drawProgressBarFill(const QStyleOption *option, { const QStyleOptionProgressBar *pbar = qstyleoption_cast(option); - const bool vertical = pbar->orientation == Qt::Vertical; + const bool vertical = !(pbar->state & QStyle::State_Horizontal); const bool flip = (pbar->direction == Qt::RightToLeft) ^ pbar->invertedAppearance; if (pbar->progress == pbar->maximum) { @@ -1026,7 +1026,7 @@ QSize QPixmapStyle::progressBarSizeFromContents(const QStyleOption *option, bool vertical = false; if (const QStyleOptionProgressBar *pb = qstyleoption_cast(option)) { - vertical = pb->orientation == Qt::Vertical; + vertical = !(pb->state & QStyle::State_Horizontal); } QSize result = QCommonStyle::sizeFromContents(CT_Slider, option, contentsSize, widget); if (vertical) { diff --git a/src/widgets/styles/qstyleoption.cpp b/src/widgets/styles/qstyleoption.cpp index aab5696398..b7b5b99e3a 100644 --- a/src/widgets/styles/qstyleoption.cpp +++ b/src/widgets/styles/qstyleoption.cpp @@ -1496,7 +1496,7 @@ QStyleOptionTab::QStyleOptionTab(int version) QStyleOptionProgressBar::QStyleOptionProgressBar() : QStyleOption(QStyleOptionProgressBar::Version, SO_ProgressBar), minimum(0), maximum(0), progress(0), textAlignment(Qt::AlignLeft), textVisible(false), - orientation(Qt::Horizontal), invertedAppearance(false), bottomToTop(false) + invertedAppearance(false), bottomToTop(false) { } @@ -1506,7 +1506,7 @@ QStyleOptionProgressBar::QStyleOptionProgressBar() QStyleOptionProgressBar::QStyleOptionProgressBar(int version) : QStyleOption(version, SO_ProgressBar), minimum(0), maximum(0), progress(0), textAlignment(Qt::AlignLeft), textVisible(false), - orientation(Qt::Horizontal), invertedAppearance(false), bottomToTop(false) + invertedAppearance(false), bottomToTop(false) { } @@ -1608,17 +1608,6 @@ QStyleOptionProgressBar::QStyleOptionProgressBar(int version) \sa QProgressBar::value */ -/*! - \variable QStyleOptionProgressBar::orientation - \brief the progress bar's orientation (horizontal or vertical); - the default orentation is Qt::Horizontal - - \deprecated - Use the QStyle::State_Horizontal flag instead (in the QStyleOption::state member). - - \sa QProgressBar::orientation -*/ - /*! \variable QStyleOptionProgressBar::invertedAppearance \brief whether the progress bar's appearance is inverted diff --git a/src/widgets/styles/qstyleoption.h b/src/widgets/styles/qstyleoption.h index fb5e92526e..22ac309cc6 100644 --- a/src/widgets/styles/qstyleoption.h +++ b/src/widgets/styles/qstyleoption.h @@ -336,7 +336,6 @@ public: QString text; Qt::Alignment textAlignment; bool textVisible; - Qt::Orientation orientation; // ### Qt 6: remove bool invertedAppearance; bool bottomToTop; diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index b2f84e2f30..e53b81b292 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -3993,7 +3993,7 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q qint64 minimum = qint64(pb->minimum); qint64 maximum = qint64(pb->maximum); qint64 progress = qint64(pb->progress); - bool vertical = (pb->orientation == Qt::Vertical); + bool vertical = !(pb->state & QStyle::State_Horizontal); bool inverted = pb->invertedAppearance; QTransform m; diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp index 619dbcdb52..e3c2a54051 100644 --- a/src/widgets/styles/qwindowsstyle.cpp +++ b/src/widgets/styles/qwindowsstyle.cpp @@ -1025,7 +1025,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, { bool vertical = false, inverted = false; if (const QStyleOptionProgressBar *pb = qstyleoption_cast(opt)) { - vertical = pb->orientation == Qt::Vertical; + vertical = !(pb->state & QStyle::State_Horizontal); inverted = pb->invertedAppearance; } @@ -1691,7 +1691,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai if (!rect.isValid()) return; - const bool vertical = pb->orientation == Qt::Vertical; + const bool vertical = !(pb->state & QStyle::State_Horizontal); const bool inverted = pb->invertedAppearance; QTransform m; diff --git a/src/widgets/widgets/qprogressbar.cpp b/src/widgets/widgets/qprogressbar.cpp index f94cbd3172..e2d4875f54 100644 --- a/src/widgets/widgets/qprogressbar.cpp +++ b/src/widgets/widgets/qprogressbar.cpp @@ -135,7 +135,6 @@ void QProgressBar::initStyleOption(QStyleOptionProgressBar *option) const option->textAlignment = d->alignment; option->textVisible = d->textVisible; option->text = text(); - option->orientation = d->orientation; // ### Qt 6: remove this member from QStyleOptionProgressBar option->invertedAppearance = d->invertedAppearance; option->bottomToTop = d->textDirection == QProgressBar::BottomToTop; } @@ -424,7 +423,7 @@ QSize QProgressBar::sizeHint() const initStyleOption(&opt); int cw = style()->pixelMetric(QStyle::PM_ProgressBarChunkWidth, &opt, this); QSize size = QSize(qMax(9, cw) * 7 + fm.horizontalAdvance(QLatin1Char('0')) * 4, fm.height() + 8); - if (opt.orientation == Qt::Vertical) + if (!(opt.state & QStyle::State_Horizontal)) size = size.transposed(); return style()->sizeFromContents(QStyle::CT_ProgressBar, &opt, size, this); }