diff options
| author | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2017-02-01 21:00:55 +0100 |
|---|---|---|
| committer | Oswald Buddenhagen <oswald.buddenhagen@qt.io> | 2017-02-01 21:00:55 +0100 |
| commit | dcd5cb973622d059818dba1a2c7b9a7b7601a14c (patch) | |
| tree | fbda1c8c6d36cae42b084f7298cf5b1904e21e9f /src/widgets/styles | |
| parent | f299b565b5904e39a47b6133643448e46810f0ed (diff) | |
| parent | ff68e5d667cc62141f177d01f747a62c95f08d3e (diff) | |
| download | qtbase-dcd5cb973622d059818dba1a2c7b9a7b7601a14c.tar.gz | |
Merge remote-tracking branch 'gerrit/dev' into HEAD
Diffstat (limited to 'src/widgets/styles')
| -rw-r--r-- | src/widgets/styles/qandroidstyle.cpp | 9 | ||||
| -rw-r--r-- | src/widgets/styles/qcommonstyle.cpp | 12 | ||||
| -rw-r--r-- | src/widgets/styles/qfusionstyle.cpp | 66 | ||||
| -rw-r--r-- | src/widgets/styles/qpixmapstyle.cpp | 72 | ||||
| -rw-r--r-- | src/widgets/styles/qstylehelper.cpp | 2 | ||||
| -rw-r--r-- | src/widgets/styles/qstylesheetstyle.cpp | 19 | ||||
| -rw-r--r-- | src/widgets/styles/qwindowsstyle.cpp | 2 | ||||
| -rw-r--r-- | src/widgets/styles/qwindowsvistastyle.cpp | 3 |
8 files changed, 142 insertions, 43 deletions
diff --git a/src/widgets/styles/qandroidstyle.cpp b/src/widgets/styles/qandroidstyle.cpp index b37dffbe80..110153d0f6 100644 --- a/src/widgets/styles/qandroidstyle.cpp +++ b/src/widgets/styles/qandroidstyle.cpp @@ -1606,15 +1606,14 @@ void QAndroidStyle::AndroidProgressBarControl::drawControl(const QStyleOption *o if (!m_progressDrawable) return; - if (const QStyleOptionProgressBar *progressBarOption = - qstyleoption_cast<const QStyleOptionProgressBar *>(option)) { + if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) { if (m_progressDrawable->type() == QAndroidStyle::Layer) { - const double fraction = progressBarOption->progress / double(progressBarOption->maximum - progressBarOption->minimum); + const double fraction = double(qint64(pb->progress) - pb->minimum) / (qint64(pb->maximum) - pb->minimum); QAndroidStyle::AndroidDrawable *clipDrawable = static_cast<QAndroidStyle::AndroidLayerDrawable *>(m_progressDrawable)->layer(m_progressId); if (clipDrawable->type() == QAndroidStyle::Clip) - static_cast<AndroidClipDrawable *>(clipDrawable)->setFactor(fraction, progressBarOption->orientation); + static_cast<AndroidClipDrawable *>(clipDrawable)->setFactor(fraction, pb->orientation); else - static_cast<AndroidLayerDrawable *>(m_progressDrawable)->setFactor(m_progressId, fraction, progressBarOption->orientation); + static_cast<AndroidLayerDrawable *>(m_progressDrawable)->setFactor(m_progressId, fraction, pb->orientation); } m_progressDrawable->draw(p, option); } diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index b75088ae50..18a0c4fb64 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -1099,7 +1099,7 @@ void QCommonStylePrivate::tabLayout(const QStyleOptionTab *opt, const QWidget *w || opt->shape == QTabBar::TriangularEast || opt->shape == QTabBar::TriangularWest; if (verticalTabs) - tr.setRect(0, 0, tr.height(), tr.width()); //0, 0 as we will have a translate transform + tr.setRect(0, 0, tr.height(), tr.width()); // 0, 0 as we will have a translate transform int verticalShift = proxyStyle->pixelMetric(QStyle::PM_TabBarTabShiftVertical, opt, widget); int horizontalShift = proxyStyle->pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, opt, widget); @@ -1122,7 +1122,7 @@ void QCommonStylePrivate::tabLayout(const QStyleOptionTab *opt, const QWidget *w // right widget if (!opt->rightButtonSize.isEmpty()) { tr.setRight(tr.right() - 4 - - (verticalTabs ? opt->rightButtonSize.height() : opt->rightButtonSize.width())); + (verticalTabs ? opt->rightButtonSize.height() : opt->rightButtonSize.width())); } // icon @@ -1134,12 +1134,12 @@ void QCommonStylePrivate::tabLayout(const QStyleOptionTab *opt, const QWidget *w } QSize tabIconSize = opt->icon.actualSize(iconSize, (opt->state & QStyle::State_Enabled) ? QIcon::Normal : QIcon::Disabled, - (opt->state & QStyle::State_Selected) ? QIcon::On : QIcon::Off ); - // High-dpi icons do not need adjustmet; make sure tabIconSize is not larger than iconSize + (opt->state & QStyle::State_Selected) ? QIcon::On : QIcon::Off); + // High-dpi icons do not need adjustment; make sure tabIconSize is not larger than iconSize tabIconSize = QSize(qMin(tabIconSize.width(), iconSize.width()), qMin(tabIconSize.height(), iconSize.height())); *iconRect = QRect(tr.left(), tr.center().y() - tabIconSize.height() / 2, - tabIconSize.width(), tabIconSize .height()); + tabIconSize.width(), tabIconSize.height()); if (!verticalTabs) *iconRect = proxyStyle->visualRect(opt->direction, opt->rect, *iconRect); tr.setLeft(tr.left() + tabIconSize.width() + 4); @@ -5226,9 +5226,11 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget case SH_Splitter_OpaqueResize: ret = true; break; +#if QT_CONFIG(itemviews) case SH_ItemView_ScrollMode: ret = QAbstractItemView::ScrollPerItem; break; +#endif default: ret = 0; break; diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index 70af751fd3..75c50bb146 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -453,6 +453,7 @@ void QFusionStyle::drawPrimitive(PrimitiveElement elem, drawPrimitive(PE_IndicatorArrowRight, option, painter, widget); break; } +#if QT_CONFIG(tabbar) case PE_FrameTabBarBase: if (const QStyleOptionTabBarBase *tbb = qstyleoption_cast<const QStyleOptionTabBarBase *>(option)) { @@ -489,6 +490,7 @@ void QFusionStyle::drawPrimitive(PrimitiveElement elem, painter->restore(); } return; +#endif // QT_CONFIG(tabbar) case PE_PanelScrollAreaCorner: { painter->save(); QColor alphaOutline = outline; @@ -938,6 +940,7 @@ void QFusionStyle::drawPrimitive(PrimitiveElement elem, case PE_FrameTabWidget: painter->save(); painter->fillRect(option->rect.adjusted(0, 0, -1, -1), tabFrameColor); +#if QT_CONFIG(tabwidget) if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(option)) { QColor borderColor = outline.lighter(110); QRect rect = option->rect.adjusted(0, 0, -1, -1); @@ -960,6 +963,7 @@ void QFusionStyle::drawPrimitive(PrimitiveElement elem, painter->drawRect(rect.adjusted(1, 1, -1, -1)); } +#endif // QT_CONFIG(tabwidget) painter->restore(); break ; @@ -1057,6 +1061,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio } break; } +#if QT_CONFIG(rubberband) case CE_RubberBand: if (qstyleoption_cast<const QStyleOptionRubberBand *>(option)) { QColor highlight = option->palette.color(QPalette::Active, QPalette::Highlight); @@ -1082,6 +1087,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio painter->restore(); } break; +#endif //QT_CONFIG(rubberband) case CE_SizeGrip: painter->save(); { @@ -1097,6 +1103,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio } painter->restore(); break; +#if QT_CONFIG(toolbar) case CE_ToolBar: if (const QStyleOptionToolBar *toolBar = qstyleoption_cast<const QStyleOptionToolBar *>(option)) { // Reserve the beveled appearance only for mainwindow toolbars @@ -1217,6 +1224,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio painter->setPen(oldPen); } break; +#endif // QT_CONFIG(toolbar) case CE_DockWidgetTitle: painter->save(); if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(option)) { @@ -1352,10 +1360,11 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio } int maxWidth = rect.width(); - int minWidth = 0; - qreal progress = qMax(bar->progress, bar->minimum); // workaround for bug in QProgressBar - int progressBarWidth = (progress - bar->minimum) * qreal(maxWidth) / qMax(qreal(1.0), qreal(bar->maximum) - bar->minimum); - int width = indeterminate ? maxWidth : qMax(minWidth, progressBarWidth); + const auto progress = qMax(bar->progress, bar->minimum); // workaround for bug in QProgressBar + const auto totalSteps = qMax(Q_INT64_C(1), qint64(bar->maximum) - bar->minimum); + const auto progressSteps = qint64(progress) - bar->minimum; + const auto progressBarWidth = progressSteps * maxWidth / totalSteps; + int width = indeterminate ? maxWidth : progressBarWidth; bool reverse = (!vertical && (bar->direction == Qt::RightToLeft)) || vertical; if (inverted) @@ -1450,8 +1459,9 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio inverted = bar->invertedAppearance; if (vertical) rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height - const int progressIndicatorPos = (bar->progress - qreal(bar->minimum)) * rect.width() / - qMax(qreal(1.0), qreal(bar->maximum) - bar->minimum); + const auto totalSteps = qMax(Q_INT64_C(1), qint64(bar->maximum) - bar->minimum); + const auto progressSteps = qint64(bar->progress) - bar->minimum; + const auto progressIndicatorPos = progressSteps * rect.width() / totalSteps; if (progressIndicatorPos >= 0 && progressIndicatorPos <= rect.width()) leftRect = QRect(rect.left(), rect.top(), progressIndicatorPos, rect.height()); if (vertical) @@ -1548,7 +1558,10 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio bool ignoreCheckMark = false; int checkcol = qMax(menuItem->maxIconWidth, 20); - if (qobject_cast<const QComboBox*>(widget) || + if ( +#if QT_CONFIG(combobox) + qobject_cast<const QComboBox*>(widget) || +#endif (option->styleObject && option->styleObject->property("_q_isComboBoxPopupItem").toBool())) ignoreCheckMark = true; //ignore the checkmarks provided by the QComboMenuDelegate @@ -1605,8 +1618,10 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio int smallIconSize = proxy()->pixelMetric(PM_SmallIconSize, option, widget); QSize iconSize(smallIconSize, smallIconSize); +#if QT_CONFIG(combobox) if (const QComboBox *combo = qobject_cast<const QComboBox*>(widget)) iconSize = combo->iconSize(); +#endif if (checked) pixmap = menuItem->icon.pixmap(iconSize, mode, QIcon::On); else @@ -1791,6 +1806,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio } painter->restore(); break; +#if QT_CONFIG(tabbar) case CE_TabBarTabShape: painter->save(); if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) { @@ -1906,6 +1922,7 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio } painter->restore(); break; +#endif //QT_CONFIG(tabbar) default: QCommonStyle::drawControl(element,option,painter,widget); break; @@ -1991,6 +2008,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption } painter->restore(); break; +#if QT_CONFIG(spinbox) case CC_SpinBox: if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) { QPixmap cache; @@ -2141,6 +2159,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption painter->drawPixmap(spinBox->rect.topLeft(), cache); } break; +#endif // QT_CONFIG(spinbox) case CC_TitleBar: painter->save(); if (const QStyleOptionTitleBar *titleBar = qstyleoption_cast<const QStyleOptionTitleBar *>(option)) { @@ -2401,6 +2420,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption } painter->restore(); break; +#if QT_CONFIG(slider) case CC_ScrollBar: painter->save(); if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) { @@ -2709,6 +2729,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption } painter->restore(); break;; +#endif // QT_CONFIG(slider) case CC_ComboBox: painter->save(); if (const QStyleOptionComboBox *comboBox = qstyleoption_cast<const QStyleOptionComboBox *>(option)) { @@ -2806,6 +2827,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption } painter->restore(); break; +#if QT_CONFIG(slider) case CC_Slider: if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) { QRect groove = proxy()->subControlRect(CC_Slider, option, SC_SliderGroove, widget); @@ -3016,10 +3038,13 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption painter->setPen(oldPen); } break; +#endif // QT_CONFIG(slider) +#if QT_CONFIG(dial) case CC_Dial: if (const QStyleOptionSlider *dial = qstyleoption_cast<const QStyleOptionSlider *>(option)) QStyleHelper::drawDial(dial, painter); break; +#endif default: QCommonStyle::drawComplexControl(control, option, painter, widget); break; @@ -3215,9 +3240,11 @@ QSize QFusionStyle::sizeFromContents(ContentsType type, const QStyleOption *opti } } else if (!menuItem->icon.isNull()) { +#if QT_CONFIG(combobox) if (const QComboBox *combo = qobject_cast<const QComboBox*>(widget)) { newSize.setHeight(qMax(combo->iconSize().height() + 2, newSize.height())); } +#endif } newSize.setWidth(newSize.width() + 12); newSize.setWidth(qMax(newSize.width(), 120)); @@ -3250,12 +3277,22 @@ void QFusionStyle::polish(QWidget *widget) { QCommonStyle::polish(widget); if (qobject_cast<QAbstractButton*>(widget) +#if QT_CONFIG(combobox) || qobject_cast<QComboBox *>(widget) +#endif +#if QT_CONFIG(progressbar) || qobject_cast<QProgressBar *>(widget) +#endif +#if QT_CONFIG(scrollbar) || qobject_cast<QScrollBar *>(widget) +#endif +#if QT_CONFIG(splitter) || qobject_cast<QSplitterHandle *>(widget) +#endif || qobject_cast<QAbstractSlider *>(widget) +#if QT_CONFIG(spinbox) || qobject_cast<QAbstractSpinBox *>(widget) +#endif || (widget->inherits("QDockSeparator")) || (widget->inherits("QDockWidgetSeparator")) ) { @@ -3279,12 +3316,22 @@ void QFusionStyle::unpolish(QWidget *widget) { QCommonStyle::unpolish(widget); if (qobject_cast<QAbstractButton*>(widget) +#if QT_CONFIG(combobox) || qobject_cast<QComboBox *>(widget) +#endif +#if QT_CONFIG(progressbar) || qobject_cast<QProgressBar *>(widget) +#endif +#if QT_CONFIG(scrollbar) || qobject_cast<QScrollBar *>(widget) +#endif +#if QT_CONFIG(splitter) || qobject_cast<QSplitterHandle *>(widget) +#endif || qobject_cast<QAbstractSlider *>(widget) +#if QT_CONFIG(spinbox) || qobject_cast<QAbstractSpinBox *>(widget) +#endif || (widget->inherits("QDockSeparator")) || (widget->inherits("QDockWidgetSeparator")) ) { @@ -3309,6 +3356,7 @@ QRect QFusionStyle::subControlRect(ComplexControl control, const QStyleOptionCom QRect rect = QCommonStyle::subControlRect(control, option, subControl, widget); switch (control) { +#if QT_CONFIG(slider) case CC_Slider: if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) { int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget); @@ -3359,6 +3407,8 @@ QRect QFusionStyle::subControlRect(ComplexControl control, const QStyleOptionCom } } break; +#endif // QT_CONFIG(slider) +#if QT_CONFIG(spinbox) case CC_SpinBox: if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) { int center = spinbox->rect.height() / 2; @@ -3396,7 +3446,7 @@ QRect QFusionStyle::subControlRect(ComplexControl control, const QStyleOptionCom rect = visualRect(spinbox->direction, spinbox->rect, rect); } break; - +#endif // QT_CONFIG(spinbox) case CC_GroupBox: if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(option)) { rect = option->rect; diff --git a/src/widgets/styles/qpixmapstyle.cpp b/src/widgets/styles/qpixmapstyle.cpp index e973a96a91..a947f5d079 100644 --- a/src/widgets/styles/qpixmapstyle.cpp +++ b/src/widgets/styles/qpixmapstyle.cpp @@ -129,12 +129,14 @@ void QPixmapStyle::polish(QWidget *widget) Q_D(QPixmapStyle); // Don't fill the interior of the QTextEdit +#if QT_CONFIG(textedit) if (qobject_cast<QTextEdit*>(widget)) { QPalette p = widget->palette(); p.setBrush(QPalette::Base, Qt::NoBrush); widget->setPalette(p); } - +#endif +#if QT_CONFIG(progressbar) if (QProgressBar *pb = qobject_cast<QProgressBar*>(widget)) { // Center the text in the progress bar pb->setAlignment(Qt::AlignCenter); @@ -143,10 +145,12 @@ void QPixmapStyle::polish(QWidget *widget) font.setPixelSize(d->descriptors.value(PB_HBackground).size.height()/2); pb->setFont(font); } - +#endif +#if QT_CONFIG(slider) if (qobject_cast<QSlider*>(widget)) widget->installEventFilter(this); - +#endif +#if QT_CONFIG(combobox) if (QComboBox *cb = qobject_cast<QComboBox*>(widget)) { widget->installEventFilter(this); // NOTE: This will break if the private API of QComboBox changes drastically @@ -177,24 +181,28 @@ void QPixmapStyle::polish(QWidget *widget) #endif } } - +#endif // QT_CONFIG(combobox) if (qstrcmp(widget->metaObject()->className(),"QComboBoxPrivateContainer") == 0) widget->installEventFilter(this); +#if QT_CONFIG(scrollarea) if (QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea*>(widget)) { scrollArea->viewport()->setAutoFillBackground(false); +#if QT_CONFIG(itemviews) if (QAbstractItemView *view = qobject_cast<QAbstractItemView*>(scrollArea)) { view->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); view->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); } +#endif #if QT_CONFIG(gestures) QScroller::grabGesture(scrollArea->viewport(), QScroller::LeftMouseButtonGesture); #endif } - +#endif // QT_CONFIG(scrollarea) +#if QT_CONFIG(scrollbar) if (qobject_cast<QScrollBar*>(widget)) widget->setAttribute(Qt::WA_OpaquePaintEvent, false); - +#endif QCommonStyle::polish(widget); } @@ -211,15 +219,23 @@ void QPixmapStyle::unpolish(QApplication *application) */ void QPixmapStyle::unpolish(QWidget *widget) { - if (qobject_cast<QSlider*>(widget) || - qobject_cast<QComboBox*>(widget)) { + if ( +#if QT_CONFIG(slider) + qobject_cast<QSlider*>(widget) +#else + false +#endif +#if QT_CONFIG(combobox) + || qobject_cast<QComboBox*>(widget) +#endif + ) { widget->removeEventFilter(this); } if (qstrcmp(widget->metaObject()->className(),"QComboBoxPrivateContainer") == 0) widget->removeEventFilter(this); -#if QT_CONFIG(gestures) +#if QT_CONFIG(gestures) && QT_CONFIG(scrollarea) if (QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea*>(widget)) QScroller::ungrabGesture(scrollArea->viewport()); #endif @@ -245,10 +261,12 @@ void QPixmapStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *o drawLineEdit(option, painter, widget); break; case PE_Frame: +#if QT_CONFIG(textedit) case PE_FrameDefaultButton: if (qobject_cast<const QTextEdit*>(widget)) drawTextEdit(option, painter, widget); break; +#endif case PE_IndicatorCheckBox: drawCheckBox(option, painter, widget); break; @@ -256,9 +274,11 @@ void QPixmapStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *o drawRadioButton(option, painter, widget); break; case PE_PanelItemViewItem: +#if QT_CONFIG(listview) if (qobject_cast<const QListView*>(widget)) drawPanelItemViewItem(option, painter, widget); else +#endif QCommonStyle::drawPrimitive(element, option, painter, widget); break; default: @@ -404,11 +424,13 @@ int QPixmapStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, case PM_ButtonShiftVertical: return 0; case PM_DefaultFrameWidth: +#if QT_CONFIG(textedit) if (qobject_cast<const QTextEdit*>(widget)) { const QPixmapStyleDescriptor &desc = d->descriptors.value(LE_Enabled); return qMax(qMax(desc.margins.left(), desc.margins.right()), qMax(desc.margins.top(), desc.margins.bottom())); } +#endif return 0; case PM_IndicatorWidth: return d->pixmaps.value(CB_Enabled).pixmap.width(); @@ -430,6 +452,7 @@ int QPixmapStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, return qMax(qMax(pix.margins.left(), pix.margins.right()), qMax(pix.margins.top(), pix.margins.bottom())); } +#if QT_CONFIG(slider) case PM_SliderThickness: if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider*>(option)) { @@ -470,6 +493,7 @@ int QPixmapStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, ? desc.size.height() : desc.size.width(); } break; +#endif // QT_CONFIG(slider) case PM_ScrollBarSliderMin: return 0; default: ; @@ -520,7 +544,7 @@ QStyle::SubControl QPixmapStyle::hitTestComplexControl(QStyle::ComplexControl co bool QPixmapStyle::eventFilter(QObject *watched, QEvent *event) { Q_D(QPixmapStyle); - +#if QT_CONFIG(slider) if (QSlider *slider = qobject_cast<QSlider*>(watched)) { switch (event->type()) { case QEvent::MouseButtonPress: @@ -531,7 +555,8 @@ bool QPixmapStyle::eventFilter(QObject *watched, QEvent *event) default: ; } } - +#endif // QT_CONFIG(slider) +#if QT_CONFIG(combobox) if (QComboBox *comboBox = qobject_cast<QComboBox*>(watched)) { switch (event->type()) { case QEvent::MouseButtonPress: @@ -552,6 +577,7 @@ bool QPixmapStyle::eventFilter(QObject *watched, QEvent *event) default: ; } } +#endif // QT_CONFIG(combobox) if (qstrcmp(watched->metaObject()->className(),"QComboBoxPrivateContainer") == 0) { if (event->type() == QEvent::Show) { @@ -701,9 +727,10 @@ void QPixmapStyle::drawLineEdit(const QStyleOption *option, QPainter *painter, const QWidget *widget) const { // Don't draw for the line edit inside a combobox +#if QT_CONFIG(combobox) if (widget && qobject_cast<const QComboBox*>(widget->parentWidget())) return; - +#endif const bool enabled = option->state & State_Enabled; const bool focused = option->state & State_HasFocus; ControlDescriptor control = enabled ? (focused ? LE_Focused : LE_Enabled) : LE_Disabled; @@ -819,11 +846,14 @@ void QPixmapStyle::drawProgressBarFill(const QStyleOption *option, drawCachedPixmap(vertical ? PB_VComplete : PB_HComplete, option->rect, painter); } else { - if (pbar->progress == 0) + if (pbar->progress == pbar->minimum) return; - const int maximum = pbar->maximum; - const qreal ratio = qreal(vertical?option->rect.height():option->rect.width())/maximum; - const int progress = pbar->progress*ratio; + const auto totalSteps = qint64(pbar->maximum) - pbar->minimum; + const auto progressSteps = qint64(pbar->progress) - pbar->minimum; + const auto availablePixels = vertical ? option->rect.height() : option->rect.width(); + const auto pixelsPerStep = double(availablePixels) / totalSteps; + + const auto progress = static_cast<int>(progressSteps * pixelsPerStep); // width in pixels QRect optRect = option->rect; if (vertical) { @@ -845,6 +875,7 @@ void QPixmapStyle::drawProgressBarFill(const QStyleOption *option, void QPixmapStyle::drawSlider(const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const { +#if QT_CONFIG(slider) Q_D(const QPixmapStyle); const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider*>(option); @@ -894,6 +925,7 @@ void QPixmapStyle::drawSlider(const QStyleOptionComplex *option, painter->drawPixmap(handle, d->pixmaps.value(pix).pixmap); } } +#endif // QT_CONFIG(slider) } void QPixmapStyle::drawComboBox(const QStyleOptionComplex *option, @@ -920,6 +952,7 @@ void QPixmapStyle::drawComboBox(const QStyleOptionComplex *option, void QPixmapStyle::drawScrollBar(const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const { +#if QT_CONFIG(slider) if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider*>(option)) { // Do not draw the scrollbar @@ -931,6 +964,7 @@ void QPixmapStyle::drawScrollBar(const QStyleOptionComplex *option, ? SB_Horizontal : SB_Vertical; drawCachedPixmap(control, rect, painter); } +#endif // QT_CONFIG(slider) } QSize QPixmapStyle::pushButtonSizeFromContents(const QStyleOption *option, @@ -989,6 +1023,7 @@ QSize QPixmapStyle::sliderSizeFromContents(const QStyleOption *option, const QSize &contentsSize, const QWidget *widget) const { +#if QT_CONFIG(slider) Q_D(const QPixmapStyle); const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider*>(option); @@ -1004,6 +1039,9 @@ QSize QPixmapStyle::sliderSizeFromContents(const QStyleOption *option, return QSize(result.width(), desc.size.height()); else return QSize(desc.size.width(), result.height()); +#else // QT_CONFIG(slider) + return QSize(); +#endif // QT_CONFIG(slider) } QSize QPixmapStyle::comboBoxSizeFromContents(const QStyleOption *option, @@ -1071,6 +1109,7 @@ QRect QPixmapStyle::comboBoxSubControlRect(const QStyleOptionComplex *option, QRect QPixmapStyle::scrollBarSubControlRect(const QStyleOptionComplex *option, QStyle::SubControl sc, const QWidget *) const { +#if QT_CONFIG(slider) if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider*>(option)) { int length = (slider->orientation == Qt::Horizontal) @@ -1117,6 +1156,7 @@ QRect QPixmapStyle::scrollBarSubControlRect(const QStyleOptionComplex *option, } } } +#endif // QT_CONFIG(slider) return QRect(); } diff --git a/src/widgets/styles/qstylehelper.cpp b/src/widgets/styles/qstylehelper.cpp index 602421725f..9b381c383b 100644 --- a/src/widgets/styles/qstylehelper.cpp +++ b/src/widgets/styles/qstylehelper.cpp @@ -411,7 +411,7 @@ void drawBorderPixmap(const QPixmap &pixmap, QPainter *painter, const QRect &rec QColor backgroundColor(const QPalette &pal, const QWidget* widget) { -#ifndef QT_NO_SCROLLBAR +#if QT_CONFIG(scrollarea) if (qobject_cast<const QScrollBar *>(widget) && widget->parent() && qobject_cast<const QAbstractScrollArea *>(widget->parent()->parent())) return widget->parentWidget()->parentWidget()->palette().color(QPalette::Base); diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index d63c96bf0e..d9d270643c 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -38,10 +38,10 @@ ****************************************************************************/ #include <qglobal.h> +#include "qstylesheetstyle_p.h" -#ifndef QT_NO_STYLE_STYLESHEET +#if QT_CONFIG(style_stylesheet) -#include "qstylesheetstyle_p.h" #include "private/qcssutil_p.h" #include <qdebug.h> #include <qapplication.h> @@ -3903,8 +3903,8 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q if (inverted) reverse = !reverse; const bool indeterminate = pb->minimum == pb->maximum; - qreal fillRatio = indeterminate ? 0.50 : qreal(progress - minimum)/(maximum - minimum); - int fillWidth = int(rect.width() * fillRatio); + const auto fillRatio = indeterminate ? 0.50 : double(progress - minimum) / (maximum - minimum); + const auto fillWidth = static_cast<int>(rect.width() * fillRatio); int chunkWidth = fillWidth; if (subRule.hasContentsSize()) { QSize sz = subRule.size(); @@ -4415,14 +4415,18 @@ void QStyleSheetStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *op break; case PE_IndicatorColumnViewArrow: +#if QT_CONFIG(itemviews) if (const QStyleOptionViewItem *viewOpt = qstyleoption_cast<const QStyleOptionViewItem *>(opt)) { bool reverse = (viewOpt->direction == Qt::RightToLeft); pseudoElement = reverse ? PseudoElement_LeftArrow : PseudoElement_RightArrow; - } else { + } else +#endif + { pseudoElement = PseudoElement_RightArrow; } break; +#if QT_CONFIG(itemviews) case PE_IndicatorBranch: if (const QStyleOptionViewItem *vopt = qstyleoption_cast<const QStyleOptionViewItem *>(opt)) { QRenderRule subRule = renderRule(w, opt, PseudoElement_TreeViewBranch); @@ -4437,6 +4441,7 @@ void QStyleSheetStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *op } } return; +#endif // QT_CONFIG(itemviews) case PE_PanelTipLabel: if (!rule.hasDrawable()) @@ -4898,6 +4903,7 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op QSize sz = rule.adjustSize(csz); switch (ct) { +#if QT_CONFIG(spinbox) case CT_SpinBox: // ### hopelessly broken QAbstractSpinBox (part 1) if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) { // Add some space for the up/down buttons @@ -4915,6 +4921,7 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op return sz; } break; +#endif // QT_CONFIG(spinbox) case CT_ToolButton: if (rule.hasBox() || !rule.hasNativeBorder() || !rule.baseStyleCanDraw()) sz += QSize(3, 3); // ### broken QToolButton @@ -6024,4 +6031,4 @@ QT_END_NAMESPACE #include "moc_qstylesheetstyle_p.cpp" -#endif // QT_NO_STYLE_STYLESHEET +#endif // QT_CONFIG(style_stylesheet) diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp index a8ee881a30..f9370a2cc7 100644 --- a/src/widgets/styles/qwindowsstyle.cpp +++ b/src/widgets/styles/qwindowsstyle.cpp @@ -815,6 +815,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, p->save(); doRestore = true; } +#if QT_CONFIG(itemviews) if (pe == PE_IndicatorViewItemCheck) { const QStyleOptionViewItem *itemViewOpt = qstyleoption_cast<const QStyleOptionViewItem *>(opt); p->setPen(itemViewOpt @@ -826,6 +827,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, p->setBrush(opt->palette.brush(QPalette::Button)); p->drawRect(opt->rect.x() + 1, opt->rect.y() + 1, 11, 11); } +#endif // QT_CONFIG(itemviews) if (!(opt->state & State_Off)) { QLineF lines[7]; int i, xx, yy; diff --git a/src/widgets/styles/qwindowsvistastyle.cpp b/src/widgets/styles/qwindowsvistastyle.cpp index d6a4016e4c..972deef150 100644 --- a/src/widgets/styles/qwindowsvistastyle.cpp +++ b/src/widgets/styles/qwindowsvistastyle.cpp @@ -1872,8 +1872,7 @@ QSize QWindowsVistaStyle::sizeFromContents(ContentsType type, const QStyleOption case CT_MenuBarItem: if (!sz.isEmpty()) sz += QSize(windowsItemHMargin * 5 + 1, 5); - return sz; - break; + return sz; #endif case CT_ItemViewItem: sz = QWindowsXPStyle::sizeFromContents(type, option, size, widget); |
