diff options
Diffstat (limited to 'src/widgets')
79 files changed, 919 insertions, 421 deletions
diff --git a/src/widgets/accessible/qaccessiblewidget.cpp b/src/widgets/accessible/qaccessiblewidget.cpp index 840a990799..94cf58ae3b 100644 --- a/src/widgets/accessible/qaccessiblewidget.cpp +++ b/src/widgets/accessible/qaccessiblewidget.cpp @@ -44,7 +44,9 @@ #include "qaction.h" #include "qapplication.h" #include "qgroupbox.h" +#if QT_CONFIG(label) #include "qlabel.h" +#endif #include "qtooltip.h" #include "qwhatsthis.h" #include "qwidget.h" @@ -81,7 +83,7 @@ static QString buddyString(const QWidget *widget) QWidget *parent = widget->parentWidget(); if (!parent) return QString(); -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) && QT_CONFIG(label) for (QObject *o : parent->children()) { QLabel *label = qobject_cast<QLabel*>(o); if (label && label->buddy() == widget) @@ -309,7 +311,7 @@ QAccessibleWidget::relations(QAccessible::Relation match /*= QAccessible::AllRel if (match & QAccessible::Label) { const QAccessible::Relation rel = QAccessible::Label; if (QWidget *parent = widget()->parentWidget()) { -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) && QT_CONFIG(label) // first check for all siblings that are labels to us // ideally we would go through all objects and check, but that // will be too expensive diff --git a/src/widgets/accessible/qaccessiblewidgetfactory.cpp b/src/widgets/accessible/qaccessiblewidgetfactory.cpp index da184fd90d..c95b5b1097 100644 --- a/src/widgets/accessible/qaccessiblewidgetfactory.cpp +++ b/src/widgets/accessible/qaccessiblewidgetfactory.cpp @@ -45,7 +45,6 @@ #include "complexwidgets_p.h" #include "itemviews_p.h" -#include <qpushbutton.h> #include <qtoolbutton.h> #include <qtreeview.h> #include <qvariant.h> @@ -184,8 +183,10 @@ QAccessibleInterface *qAccessibleFactory(const QString &classname, QObject *obje } else if (classname == QLatin1String("QMdiSubWindow")) { iface = new QAccessibleMdiSubWindow(widget); #endif +#if QT_CONFIG(dialogbuttonbox) } else if (classname == QLatin1String("QDialogButtonBox")) { iface = new QAccessibleDialogButtonBox(widget); +#endif #ifndef QT_NO_DIAL } else if (classname == QLatin1String("QDial")) { iface = new QAccessibleDial(widget); diff --git a/src/widgets/accessible/qaccessiblewidgets.cpp b/src/widgets/accessible/qaccessiblewidgets.cpp index 4c48ecb465..40aca37f11 100644 --- a/src/widgets/accessible/qaccessiblewidgets.cpp +++ b/src/widgets/accessible/qaccessiblewidgets.cpp @@ -54,7 +54,9 @@ #include <QToolBox> #include <QMdiArea> #include <QMdiSubWindow> +#if QT_CONFIG(dialogbuttonbox) #include <QDialogButtonBox> +#endif #include <limits.h> #include <QRubberBand> #include <QTextBrowser> @@ -480,7 +482,7 @@ QMdiSubWindow *QAccessibleMdiSubWindow::mdiSubWindow() const } #endif // QT_NO_MDIAREA -#ifndef QT_NO_DIALOGBUTTONBOX +#if QT_CONFIG(dialogbuttonbox) // ======================= QAccessibleDialogButtonBox ====================== QAccessibleDialogButtonBox::QAccessibleDialogButtonBox(QWidget *widget) : QAccessibleWidget(widget, QAccessible::Grouping) @@ -488,7 +490,7 @@ QAccessibleDialogButtonBox::QAccessibleDialogButtonBox(QWidget *widget) Q_ASSERT(qobject_cast<QDialogButtonBox*>(widget)); } -#endif // QT_NO_DIALOGBUTTONBOX +#endif // QT_CONFIG(dialogbuttonbox) #if !defined(QT_NO_TEXTBROWSER) && !defined(QT_NO_CURSOR) QAccessibleTextBrowser::QAccessibleTextBrowser(QWidget *widget) diff --git a/src/widgets/accessible/qaccessiblewidgets_p.h b/src/widgets/accessible/qaccessiblewidgets_p.h index 052958d4c7..4d945a2016 100644 --- a/src/widgets/accessible/qaccessiblewidgets_p.h +++ b/src/widgets/accessible/qaccessiblewidgets_p.h @@ -248,11 +248,13 @@ protected: }; #endif // QT_NO_MDIAREA +#if QT_CONFIG(dialogbuttonbox) class QAccessibleDialogButtonBox : public QAccessibleWidget { public: explicit QAccessibleDialogButtonBox(QWidget *widget); }; +#endif #if !defined(QT_NO_TEXTBROWSER) && !defined(QT_NO_CURSOR) class QAccessibleTextBrowser : public QAccessibleTextEdit diff --git a/src/widgets/accessible/simplewidgets.cpp b/src/widgets/accessible/simplewidgets.cpp index a2805a2458..113172ff5a 100644 --- a/src/widgets/accessible/simplewidgets.cpp +++ b/src/widgets/accessible/simplewidgets.cpp @@ -40,14 +40,22 @@ #include "simplewidgets_p.h" #include <qabstractbutton.h> +#if QT_CONFIG(checkbox) #include <qcheckbox.h> +#endif +#if QT_CONFIG(pushbutton) #include <qpushbutton.h> +#endif #include <qprogressbar.h> #include <qstatusbar.h> +#if QT_CONFIG(radiobutton) #include <qradiobutton.h> +#endif #include <qtoolbutton.h> #include <qmenu.h> +#if QT_CONFIG(label) #include <qlabel.h> +#endif #include <qgroupbox.h> #include <qlcdnumber.h> #include <qlineedit.h> @@ -109,7 +117,7 @@ QString QAccessibleButton::text(QAccessible::Text t) const switch (t) { case QAccessible::Accelerator: { -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) && QT_CONFIG(pushbutton) QPushButton *pb = qobject_cast<QPushButton*>(object()); if (pb && pb->isDefault()) str = QKeySequence(Qt::Key_Enter).toString(QKeySequence::NativeText); @@ -136,15 +144,20 @@ QAccessible::State QAccessibleButton::state() const QAccessible::State state = QAccessibleWidget::state(); QAbstractButton *b = button(); +#if QT_CONFIG(checkbox) QCheckBox *cb = qobject_cast<QCheckBox *>(b); +#endif if (b->isCheckable()) state.checkable = true; if (b->isChecked()) state.checked = true; +#if QT_CONFIG(checkbox) else if (cb && cb->checkState() == Qt::PartiallyChecked) state.checkStateMixed = true; +#endif if (b->isDown()) state.pressed = true; +#if QT_CONFIG(pushbutton) QPushButton *pb = qobject_cast<QPushButton*>(b); if (pb) { if (pb->isDefault()) @@ -154,6 +167,7 @@ QAccessible::State QAccessibleButton::state() const state.hasPopup = true; #endif } +#endif return state; } @@ -164,17 +178,22 @@ QRect QAccessibleButton::rect() const if (!ab->isVisible()) return QRect(); +#if QT_CONFIG(checkbox) if (QCheckBox *cb = qobject_cast<QCheckBox *>(ab)) { QPoint wpos = cb->mapToGlobal(QPoint(0, 0)); QStyleOptionButton opt; cb->initStyleOption(&opt); return cb->style()->subElementRect(QStyle::SE_CheckBoxClickRect, &opt, cb).translated(wpos); - } else if (QRadioButton *rb = qobject_cast<QRadioButton *>(ab)) { + } +#endif +#if QT_CONFIG(radiobutton) + else if (QRadioButton *rb = qobject_cast<QRadioButton *>(ab)) { QPoint wpos = rb->mapToGlobal(QPoint(0, 0)); QStyleOptionButton opt; rb->initStyleOption(&opt); return rb->style()->subElementRect(QStyle::SE_RadioButtonClickRect, &opt, rb).translated(wpos); } +#endif return QAccessibleWidget::rect(); } @@ -390,6 +409,7 @@ QAccessibleDisplay::QAccessibleDisplay(QWidget *w, QAccessible::Role role) QAccessible::Role QAccessibleDisplay::role() const { +#if QT_CONFIG(label) QLabel *l = qobject_cast<QLabel*>(object()); if (l) { if (l->pixmap()) @@ -411,6 +431,7 @@ QAccessible::Role QAccessibleDisplay::role() const return QAccessible::StatusBar; #endif } +#endif return QAccessibleWidget::role(); } @@ -421,7 +442,9 @@ QString QAccessibleDisplay::text(QAccessible::Text t) const case QAccessible::Name: str = widget()->accessibleName(); if (str.isEmpty()) { - if (qobject_cast<QLabel*>(object())) { + if (false) { +#if QT_CONFIG(label) + } else if (qobject_cast<QLabel*>(object())) { QLabel *label = qobject_cast<QLabel*>(object()); str = label->text(); #ifndef QT_NO_TEXTHTMLPARSER @@ -436,6 +459,7 @@ QString QAccessibleDisplay::text(QAccessible::Text t) const if (label->buddy()) str = qt_accStripAmp(str); #endif +#endif // QT_CONFIG(label) #ifndef QT_NO_LCDNUMBER } else if (qobject_cast<QLCDNumber*>(object())) { QLCDNumber *l = qobject_cast<QLCDNumber*>(object()); @@ -470,7 +494,7 @@ QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > QAccessibleDisplay::relations(QAccessible::Relation match /* = QAccessible::AllRelations */) const { QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > rels = QAccessibleWidget::relations(match); -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) && QT_CONFIG(label) if (match & QAccessible::Labelled) { if (QLabel *label = qobject_cast<QLabel*>(object())) { const QAccessible::Relation rel = QAccessible::Labelled; @@ -502,26 +526,34 @@ QString QAccessibleDisplay::imageDescription() const /*! \internal */ QSize QAccessibleDisplay::imageSize() const { +#if QT_CONFIG(label) QLabel *label = qobject_cast<QLabel *>(widget()); if (!label) +#endif return QSize(); +#if QT_CONFIG(label) const QPixmap *pixmap = label->pixmap(); if (!pixmap) return QSize(); return pixmap->size(); +#endif } /*! \internal */ QPoint QAccessibleDisplay::imagePosition() const { +#if QT_CONFIG(label) QLabel *label = qobject_cast<QLabel *>(widget()); if (!label) +#endif return QPoint(); +#if QT_CONFIG(label) const QPixmap *pixmap = label->pixmap(); if (!pixmap) return QPoint(); return QPoint(label->mapToGlobal(label->pos())); +#endif } #ifndef QT_NO_GROUPBOX @@ -664,11 +696,13 @@ void QAccessibleLineEdit::setText(QAccessible::Text t, const QString &text) } QString newText = text; +#if QT_CONFIG(validator) if (lineEdit()->validator()) { int pos = 0; if (lineEdit()->validator()->validate(newText, pos) != QValidator::Acceptable) return; } +#endif lineEdit()->setText(newText); } diff --git a/src/widgets/configure.json b/src/widgets/configure.json index 7bc2e06a32..99e1bd6940 100644 --- a/src/widgets/configure.json +++ b/src/widgets/configure.json @@ -117,6 +117,13 @@ "condition": "features.tableview", "output": [ "publicFeature", "feature" ] }, + "commandlinkbutton": { + "label": "QCommandLinkButton", + "purpose": "Provides a Vista style command link button.", + "section": "Widgets", + "condition": "features.pushbutton", + "output": [ "publicFeature" ] + }, "datetimeedit": { "label": "QDateTimeEdit", "purpose": "Supports editing dates and times.", @@ -150,6 +157,19 @@ "condition": "features.rubberband", "output": [ "publicFeature", "feature" ] }, + "label": { + "label": "QLabel", + "purpose": "Provides a text or image display.", + "section": "Widgets", + "output": [ "publicFeature" ] + }, + "formlayout": { + "label": "QFormLayout", + "purpose": "Manages forms of input widgets and their associated labels.", + "section": "Widgets", + "condition": "features.label", + "output": [ "publicFeature" ] + }, "lcdnumber": { "label": "QLCDNumber", "purpose": "Provides LCD-like digits.", @@ -160,7 +180,7 @@ "label": "QMenu", "purpose": "Provides popup-menus.", "section": "Widgets", - "condition": "features.action", + "condition": "features.action && features.pushbutton", "output": [ "publicFeature", "feature" ] }, "lineedit": { @@ -169,6 +189,12 @@ "section": "Widgets", "output": [ "publicFeature", "feature" ] }, + "radiobutton": { + "label": "QRadioButton", + "purpose": "Provides a radio button with a text label.", + "section": "Widgets", + "output": [ "publicFeature" ] + }, "spinbox": { "label": "QSpinBox", "purpose": "Provides spin boxes handling integers and discrete sets of values.", @@ -204,6 +230,19 @@ "condition": "features.combobox && features.stringlistmodel", "output": [ "publicFeature", "feature" ] }, + "checkbox": { + "label": "QCheckBox(", + "purpose": "Provides a checkbox with a text label.", + "section": "Widgets", + "output": [ "publicFeature" ] + }, + "pushbutton": { + "label": "QPushButton", + "purpose": "Provides a command button.", + "section": "Widgets", + "condition": "features.action", + "output": [ "publicFeature" ] + }, "toolbutton": { "label": "QToolButton", "purpose": "Provides quick-access buttons to commands and options.", @@ -291,10 +330,17 @@ "section": "Widgets", "output": [ "publicFeature", "feature" ] }, + "abstractslider": { + "label": "QAbstractSlider", + "purpose": "Common super class for widgets like QScrollBar, QSlider and QDial.", + "section": "Widgets", + "output": [ "publicFeature" ] + }, "slider": { "label": "QSlider", "purpose": "Provides sliders controlling a bounded value.", "section": "Widgets", + "condition": "features.abstractslider", "output": [ "publicFeature", "feature" ] }, "scrollbar": { @@ -318,6 +364,12 @@ "condition": "features.scrollbar", "output": [ "publicFeature", "feature" ] }, + "scroller": { + "label": "QScroller", + "purpose": "Enables kinetic scrolling for any scrolling widget or graphics item.", + "section": "Widgets", + "output": [ "publicFeature" ] + }, "graphicsview": { "label": "QGraphicsView", "purpose": "Provides a canvas/sprite framework.", @@ -356,6 +408,7 @@ "label": "QToolTip", "purpose": "Supports presentation of tooltips.", "section": "Widgets", + "condition": "features.label", "output": [ "publicFeature", "feature" ] }, "statustip": { @@ -381,7 +434,15 @@ "label": "QCalendarWidget", "purpose": "Provides a monthly based calendar widget allowing the user to select a date.", "section": "Widgets", - "condition": "features.tableview && features.menu && features.textdate && features.spinbox && features.toolbutton", + "condition": [ + "features.label", + "features.menu", + "features.pushbutton", + "features.spinbox", + "features.tableview", + "features.textdate", + "features.toolbutton" + ], "output": [ "publicFeature", "feature" ] }, "keysequenceedit": { @@ -391,59 +452,119 @@ "condition": "features.lineedit && features.shortcut", "output": [ "publicFeature", "feature" ] }, + "dialogbuttonbox": { + "label": "QDialogButtonBox", + "purpose": "Presents buttons in a layout that is appropriate for the current widget style.", + "section": "Dialogs", + "condition": "features.pushbutton", + "output": [ "publicFeature" ] + }, "messagebox": { "label": "QMessageBox", "purpose": "Provides message boxes displaying informative messages and simple questions.", "section": "Dialogs", + "condition" : [ + "features.checkbox", + "features.dialogbuttonbox", + "features.label", + "features.pushbutton" + ], "output": [ "publicFeature", "feature" ] }, "colordialog": { "label": "QColorDialog", "purpose": "Provides a dialog widget for specifying colors.", "section": "Dialogs", - "condition": "features.spinbox", + "condition": [ + "features.dialogbuttonbox", + "features.label", + "features.pushbutton", + "features.spinbox" + ], "output": [ "publicFeature", "feature" ] }, "filedialog": { "label": "QFileDialog", "purpose": "Provides a dialog widget for selecting files or directories.", "section": "Dialogs", - "condition": "features.dirmodel && features.treeview && features.combobox && features.toolbutton && features.buttongroup && features.tooltip && features.splitter && features.stackedwidget && features.proxymodel", + "condition": [ + "features.buttongroup", + "features.combobox", + "features.dialogbuttonbox", + "features.dirmodel", + "features.label", + "features.proxymodel", + "features.splitter", + "features.stackedwidget", + "features.treeview", + "features.toolbutton" + ], "output": [ "publicFeature", "feature" ] }, "fontdialog": { "label": "QFontDialog", "purpose": "Provides a dialog widget for selecting fonts.", "section": "Dialogs", - "condition": "features.stringlistmodel && features.combobox && features.validator && features.groupbox", + "condition": [ + "features.checkbox", + "features.combobox", + "features.dialogbuttonbox", + "features.groupbox", + "features.label", + "features.pushbutton", + "features.stringlistmodel", + "features.validator" + ], "output": [ "publicFeature", "feature" ] }, "progressdialog": { "label": "QProgressDialog", "purpose": "Provides feedback on the progress of a slow operation.", "section": "Dialogs", - "condition": "features.progressbar", + "condition": [ + "features.label", + "features.pushbutton", + "features.progressbar" + ], "output": [ "publicFeature", "feature" ] }, "inputdialog": { "label": "QInputDialog", "purpose": "Provides a simple convenience dialog to get a single value from the user.", "section": "Dialogs", - "condition": "features.combobox && features.spinbox && features.stackedwidget && features.textedit", + "condition": [ + "features.combobox", + "features.dialogbuttonbox", + "features.label", + "features.pushbutton", + "features.spinbox", + "features.stackedwidget", + "features.textedit" + ], "output": [ "publicFeature", "feature" ] }, "errormessage": { "label": "QErrorMessage", "purpose": "Provides an error message display dialog.", "section": "Dialogs", - "condition": "features.textedit", + "condition": [ + "features.checkbox", + "features.textedit", + "features.label", + "features.pushbutton", + "features.textedit" + ], "output": [ "publicFeature", "feature" ] }, "wizard": { "label": "QWizard", "purpose": "Provides a framework for multi-page click-through dialogs.", "section": "Dialogs", - "condition": "features.properties", + "condition": [ + "features.pushbutton", + "features.properties", + "features.label" + ], "output": [ "publicFeature", "feature" ] }, "dirmodel": { diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp index ab3099dfe8..dbcd2d7fe2 100644 --- a/src/widgets/dialogs/qcolordialog.cpp +++ b/src/widgets/dialogs/qcolordialog.cpp @@ -2246,10 +2246,13 @@ bool QColorDialogPrivate::handleColorPickingMouseButtonRelease(QMouseEvent *e) bool QColorDialogPrivate::handleColorPickingKeyPress(QKeyEvent *e) { Q_Q(QColorDialog); +#if QT_CONFIG(shortcut) if (e->matches(QKeySequence::Cancel)) { releaseColorPicking(); q->setCurrentColor(beforeScreenColorPicking); - } else if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) { + } else +#endif + if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) { q->setCurrentColor(grabScreenColor(QCursor::pos())); releaseColorPicking(); } diff --git a/src/widgets/dialogs/qdialog.cpp b/src/widgets/dialogs/qdialog.cpp index e5715ecd57..8e74c659fa 100644 --- a/src/widgets/dialogs/qdialog.cpp +++ b/src/widgets/dialogs/qdialog.cpp @@ -43,7 +43,6 @@ #include "qevent.h" #include "qdesktopwidget.h" -#include "qpushbutton.h" #include "qapplication.h" #include "qlayout.h" #include "qsizegrip.h" @@ -367,6 +366,7 @@ QDialog::~QDialog() default default button becomes the default button. This is what a push button calls when it loses focus. */ +#if QT_CONFIG(pushbutton) void QDialogPrivate::setDefault(QPushButton *pushButton) { Q_Q(QDialog); @@ -411,6 +411,7 @@ void QDialogPrivate::hideDefault() list.at(i)->setDefault(false); } } +#endif void QDialogPrivate::resetModalitySetByOpen() { @@ -644,6 +645,7 @@ void QDialog::keyPressEvent(QKeyEvent *e) #endif if (!e->modifiers() || (e->modifiers() & Qt::KeypadModifier && e->key() == Qt::Key_Enter)) { switch (e->key()) { +#if QT_CONFIG(pushbutton) case Qt::Key_Enter: case Qt::Key_Return: { QList<QPushButton*> list = findChildren<QPushButton*>(); @@ -657,6 +659,7 @@ void QDialog::keyPressEvent(QKeyEvent *e) } } break; +#endif default: e->ignore(); return; @@ -716,6 +719,7 @@ void QDialog::setVisible(bool visible) and actually catches most cases... If not, then they simply have to use [widget*]->setFocus() themselves... */ +#if QT_CONFIG(pushbutton) if (d->mainDef && fw->focusPolicy() == Qt::NoFocus) { QWidget *first = fw; while ((first = first->nextInFocusChain()) != fw && first->focusPolicy() == Qt::NoFocus) @@ -733,6 +737,7 @@ void QDialog::setVisible(bool visible) } } } +#endif if (fw && !fw->hasFocus()) { QFocusEvent e(QEvent::FocusIn, Qt::TabFocusReason); QApplication::sendEvent(fw, &e); @@ -760,10 +765,12 @@ void QDialog::setVisible(bool visible) d->eventLoop->exit(); } +#if QT_CONFIG(pushbutton) const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme(); if (d->mainDef && isActiveWindow() && theme->themeHint(QPlatformTheme::DialogSnapToDefaultButton).toBool()) QCursor::setPos(d->mainDef->mapToGlobal(d->mainDef->rect().center())); +#endif } /*!\reimp */ diff --git a/src/widgets/dialogs/qdialog_p.h b/src/widgets/dialogs/qdialog_p.h index ae9e3bcc93..6723edae38 100644 --- a/src/widgets/dialogs/qdialog_p.h +++ b/src/widgets/dialogs/qdialog_p.h @@ -56,7 +56,9 @@ #include "QtCore/qeventloop.h" #include "QtCore/qpointer.h" #include "QtWidgets/qdialog.h" +#if QT_CONFIG(pushbutton) #include "QtWidgets/qpushbutton.h" +#endif #include <qpa/qplatformdialoghelper.h> QT_BEGIN_NAMESPACE @@ -69,7 +71,11 @@ class Q_WIDGETS_EXPORT QDialogPrivate : public QWidgetPrivate public: QDialogPrivate() - : mainDef(0), orientation(Qt::Horizontal),extension(0), doShowExtension(false), + : +#if QT_CONFIG(pushbutton) + mainDef(0), +#endif + orientation(Qt::Horizontal),extension(0), doShowExtension(false), #ifndef QT_NO_SIZEGRIP resizer(0), sizeGripEnabled(false), @@ -84,7 +90,9 @@ public: QVariant styleHint(QPlatformDialogHelper::StyleHint hint) const; void deletePlatformHelper(); +#if QT_CONFIG(pushbutton) QPointer<QPushButton> mainDef; +#endif Qt::Orientation orientation; QWidget *extension; bool doShowExtension; @@ -95,9 +103,11 @@ public: #endif QPoint lastRMBPress; +#if QT_CONFIG(pushbutton) void setDefault(QPushButton *); void setMainDefault(QPushButton *); void hideDefault(); +#endif void resetModalitySetByOpen(); int rescode; diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index a552746385..78e304950a 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -3813,12 +3813,12 @@ void QFileDialogPrivate::_q_nativeEnterDirectory(const QUrl &directory) bool QFileDialogPrivate::itemViewKeyboardEvent(QKeyEvent *event) { Q_Q(QFileDialog); - +#if QT_CONFIG(shortcut) if (event->matches(QKeySequence::Cancel)) { q->reject(); return true; } - +#endif switch (event->key()) { case Qt::Key_Backspace: _q_navigateToParent(); @@ -4020,7 +4020,9 @@ void QFileDialogLineEdit::keyPressEvent(QKeyEvent *e) int key = e->key(); QLineEdit::keyPressEvent(e); +#if QT_CONFIG(shortcut) if (!e->matches(QKeySequence::Cancel) && key != Qt::Key_Back) +#endif e->accept(); } diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index 98d070e493..3b0a71518d 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -1405,7 +1405,7 @@ void QMessageBox::changeEvent(QEvent *ev) void QMessageBox::keyPressEvent(QKeyEvent *e) { Q_D(QMessageBox); - +#if QT_CONFIG(shortcut) if (e->matches(QKeySequence::Cancel)) { if (d->detectedEscapeButton) { #ifdef Q_OS_MAC @@ -1416,7 +1416,7 @@ void QMessageBox::keyPressEvent(QKeyEvent *e) } return; } - +#endif // QT_CONFIG(shortcut) #if !defined(QT_NO_CLIPBOARD) && !defined(QT_NO_SHORTCUT) diff --git a/src/widgets/dialogs/qwizard.cpp b/src/widgets/dialogs/qwizard.cpp index 532ee4700f..5e598ba990 100644 --- a/src/widgets/dialogs/qwizard.cpp +++ b/src/widgets/dialogs/qwizard.cpp @@ -1465,8 +1465,10 @@ void QWizardPrivate::updateButtonTexts() // Vista: Add shortcut for 'next'. Note: native dialogs use ALT-Right // even in RTL mode, so do the same, even if it might be counter-intuitive. // The shortcut for 'back' is set in class QVistaBackButton. +#if QT_CONFIG(shortcut) if (btns[QWizard::NextButton]) btns[QWizard::NextButton]->setShortcut(isVistaThemeEnabled() ? QKeySequence(Qt::ALT | Qt::Key_Right) : QKeySequence()); +#endif } void QWizardPrivate::updateButtonLayout() diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp index 41f5eddd99..9d7412340f 100644 --- a/src/widgets/graphicsview/qgraphicsview.cpp +++ b/src/widgets/graphicsview/qgraphicsview.cpp @@ -2996,12 +2996,12 @@ void QGraphicsView::contextMenuEvent(QContextMenuEvent *event) } #endif // QT_NO_CONTEXTMENU +#if QT_CONFIG(draganddrop) /*! \reimp */ void QGraphicsView::dropEvent(QDropEvent *event) { -#ifndef QT_NO_DRAGANDDROP Q_D(QGraphicsView); if (!d->scene || !d->sceneInteractionAllowed) return; @@ -3020,10 +3020,6 @@ void QGraphicsView::dropEvent(QDropEvent *event) delete d->lastDragDropEvent; d->lastDragDropEvent = 0; - -#else - Q_UNUSED(event) -#endif } /*! @@ -3031,7 +3027,6 @@ void QGraphicsView::dropEvent(QDropEvent *event) */ void QGraphicsView::dragEnterEvent(QDragEnterEvent *event) { -#ifndef QT_NO_DRAGANDDROP Q_D(QGraphicsView); if (!d->scene || !d->sceneInteractionAllowed) return; @@ -3054,9 +3049,6 @@ void QGraphicsView::dragEnterEvent(QDragEnterEvent *event) event->setAccepted(true); event->setDropAction(sceneEvent.dropAction()); } -#else - Q_UNUSED(event) -#endif } /*! @@ -3064,7 +3056,6 @@ void QGraphicsView::dragEnterEvent(QDragEnterEvent *event) */ void QGraphicsView::dragLeaveEvent(QDragLeaveEvent *event) { -#ifndef QT_NO_DRAGANDDROP Q_D(QGraphicsView); if (!d->scene || !d->sceneInteractionAllowed) return; @@ -3094,9 +3085,6 @@ void QGraphicsView::dragLeaveEvent(QDragLeaveEvent *event) // Accept the originating event if the scene accepted the scene event. if (sceneEvent.isAccepted()) event->setAccepted(true); -#else - Q_UNUSED(event) -#endif } /*! @@ -3104,7 +3092,6 @@ void QGraphicsView::dragLeaveEvent(QDragLeaveEvent *event) */ void QGraphicsView::dragMoveEvent(QDragMoveEvent *event) { -#ifndef QT_NO_DRAGANDDROP Q_D(QGraphicsView); if (!d->scene || !d->sceneInteractionAllowed) return; @@ -3123,10 +3110,8 @@ void QGraphicsView::dragMoveEvent(QDragMoveEvent *event) event->setAccepted(sceneEvent.isAccepted()); if (sceneEvent.isAccepted()) event->setDropAction(sceneEvent.dropAction()); -#else - Q_UNUSED(event) -#endif } +#endif // QT_CONFIG(draganddrop) /*! \reimp diff --git a/src/widgets/graphicsview/qgraphicsview.h b/src/widgets/graphicsview/qgraphicsview.h index 327a75c374..64d5f5b430 100644 --- a/src/widgets/graphicsview/qgraphicsview.h +++ b/src/widgets/graphicsview/qgraphicsview.h @@ -244,10 +244,12 @@ protected: #ifndef QT_NO_CONTEXTMENU void contextMenuEvent(QContextMenuEvent *event) Q_DECL_OVERRIDE; #endif +#if QT_CONFIG(draganddrop) void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE; void dragLeaveEvent(QDragLeaveEvent *event) Q_DECL_OVERRIDE; void dragMoveEvent(QDragMoveEvent *event) Q_DECL_OVERRIDE; void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE; +#endif void focusInEvent(QFocusEvent *event) Q_DECL_OVERRIDE; bool focusNextPrevChild(bool next) Q_DECL_OVERRIDE; void focusOutEvent(QFocusEvent *event) Q_DECL_OVERRIDE; diff --git a/src/widgets/itemviews/qabstractitemdelegate.cpp b/src/widgets/itemviews/qabstractitemdelegate.cpp index 8cd2a957be..f63e258e8e 100644 --- a/src/widgets/itemviews/qabstractitemdelegate.cpp +++ b/src/widgets/itemviews/qabstractitemdelegate.cpp @@ -537,11 +537,13 @@ bool QAbstractItemDelegatePrivate::tryFixup(QWidget *editor) #ifndef QT_NO_LINEEDIT if (QLineEdit *e = qobject_cast<QLineEdit*>(editor)) { if (!e->hasAcceptableInput()) { +#if QT_CONFIG(validator) if (const QValidator *validator = e->validator()) { QString text = e->text(); validator->fixup(text); e->setText(text); } +#endif return e->hasAcceptableInput(); } } diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index 6ecf5a664f..939e2a3d79 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -64,7 +64,7 @@ #ifndef QT_NO_ACCESSIBILITY #include <qaccessible.h> #endif -#ifndef QT_NO_GESTURES +#if QT_CONFIG(gestures) && QT_CONFIG(scroller) # include <qscroller.h> #endif @@ -196,7 +196,7 @@ void QAbstractItemViewPrivate::checkMouseMove(const QPersistentModelIndex &index } } -#ifndef QT_NO_GESTURES +#if QT_CONFIG(gestures) && QT_CONFIG(scroller) // stores and restores the selection and current item when flicking void QAbstractItemViewPrivate::_q_scrollerStateChanged() @@ -1736,7 +1736,7 @@ bool QAbstractItemView::viewportEvent(QEvent *event) break; case QEvent::ScrollPrepare: executeDelayedItemsLayout(); -#ifndef QT_NO_GESTURES +#if QT_CONFIG(gestures) && QT_CONFIG(scroller) connect(QScroller::scroller(d->viewport), SIGNAL(stateChanged(QScroller::State)), this, SLOT(_q_scrollerStateChanged()), Qt::UniqueConnection); #endif break; diff --git a/src/widgets/itemviews/qabstractitemview.h b/src/widgets/itemviews/qabstractitemview.h index 309b8c4d59..f315ea6e4c 100644 --- a/src/widgets/itemviews/qabstractitemview.h +++ b/src/widgets/itemviews/qabstractitemview.h @@ -367,7 +367,7 @@ private: Q_PRIVATE_SLOT(d_func(), void _q_modelDestroyed()) Q_PRIVATE_SLOT(d_func(), void _q_layoutChanged()) Q_PRIVATE_SLOT(d_func(), void _q_headerDataChanged()) -#ifndef QT_NO_GESTURES +#if QT_CONFIG(gestures) && QT_CONFIG(scroller) Q_PRIVATE_SLOT(d_func(), void _q_scrollerStateChanged()) #endif diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index 1310a060ea..d2f9618c29 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -2479,7 +2479,10 @@ void QHeaderView::mouseMoveEvent(QMouseEvent *e) if (d->shouldAutoScroll(e->pos())) d->startAutoScroll(); if (qAbs(pos - d->firstPos) >= QApplication::startDragDistance() - || !d->sectionIndicator->isHidden()) { +#if QT_CONFIG(label) + || !d->sectionIndicator->isHidden() +#endif + ) { int visual = visualIndexAt(pos); if (visual == -1) return; @@ -2548,7 +2551,11 @@ void QHeaderView::mouseReleaseEvent(QMouseEvent *e) int pos = d->orientation == Qt::Horizontal ? e->x() : e->y(); switch (d->state) { case QHeaderViewPrivate::MoveSection: - if (!d->sectionIndicator->isHidden()) { // moving + if (true +#if QT_CONFIG(label) + && !d->sectionIndicator->isHidden() +#endif + ) { // moving int from = visualIndex(d->section); Q_ASSERT(from != -1); int to = visualIndex(d->target); @@ -3138,9 +3145,11 @@ int QHeaderViewPrivate::sectionHandleAt(int position) void QHeaderViewPrivate::setupSectionIndicator(int section, int position) { Q_Q(QHeaderView); +#if QT_CONFIG(label) if (!sectionIndicator) { sectionIndicator = new QLabel(viewport); } +#endif int w, h; int p = q->sectionViewportPosition(section); @@ -3151,7 +3160,9 @@ void QHeaderViewPrivate::setupSectionIndicator(int section, int position) w = viewport->width(); h = q->sectionSize(section); } +#if QT_CONFIG(label) sectionIndicator->resize(w, h); +#endif QPixmap pm(w, h); pm.fill(QColor(0, 0, 0, 45)); @@ -3162,12 +3173,15 @@ void QHeaderViewPrivate::setupSectionIndicator(int section, int position) q->paintSection(&painter, rect, section); painter.end(); +#if QT_CONFIG(label) sectionIndicator->setPixmap(pm); +#endif sectionIndicatorOffset = position - qMax(p, 0); } void QHeaderViewPrivate::updateSectionIndicator(int section, int position) { +#if QT_CONFIG(label) if (!sectionIndicator) return; @@ -3182,6 +3196,7 @@ void QHeaderViewPrivate::updateSectionIndicator(int section, int position) sectionIndicator->move(0, position - sectionIndicatorOffset); sectionIndicator->show(); +#endif } /*! diff --git a/src/widgets/itemviews/qheaderview_p.h b/src/widgets/itemviews/qheaderview_p.h index 6affe7af95..d6b119512c 100644 --- a/src/widgets/itemviews/qheaderview_p.h +++ b/src/widgets/itemviews/qheaderview_p.h @@ -58,7 +58,9 @@ #include "QtCore/qbitarray.h" #include "QtWidgets/qapplication.h" +#if QT_CONFIG(label) #include "QtWidgets/qlabel.h" +#endif QT_BEGIN_NAMESPACE @@ -99,7 +101,9 @@ public: lastSectionSize(0), lastSectionLogicalIdx(-1), // Only trust when we stretch last section sectionIndicatorOffset(0), +#if QT_CONFIG(label) sectionIndicator(0), +#endif globalResizeMode(QHeaderView::Interactive), sectionStartposRecalc(true), resizeContentsPrecision(1000) @@ -296,7 +300,9 @@ public: int lastSectionLogicalIdx; // Only trust if we stretch LastSection int sectionIndicatorOffset; Qt::Alignment defaultAlignment; +#if QT_CONFIG(label) QLabel *sectionIndicator; +#endif QHeaderView::ResizeMode globalResizeMode; QList<QPersistentModelIndex> persistentHiddenSections; mutable bool sectionStartposRecalc; diff --git a/src/widgets/itemviews/qitemeditorfactory.cpp b/src/widgets/itemviews/qitemeditorfactory.cpp index 5356ce3ad0..c044d37575 100644 --- a/src/widgets/itemviews/qitemeditorfactory.cpp +++ b/src/widgets/itemviews/qitemeditorfactory.cpp @@ -45,7 +45,9 @@ #include <qcombobox.h> #include <qdatetimeedit.h> +#if QT_CONFIG(label) #include <qlabel.h> +#endif #include <qlineedit.h> #include <qspinbox.h> #include <limits.h> @@ -261,8 +263,10 @@ QWidget *QDefaultItemEditorFactory::createEditor(int userType, QWidget *parent) ed->setFrame(false); return ed; } #endif +#if QT_CONFIG(label) case QVariant::Pixmap: return new QLabel(parent); +#endif #ifndef QT_NO_SPINBOX case QVariant::Double: { QDoubleSpinBox *sb = new QDoubleSpinBox(parent); diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index 45c547d313..653b03ef0d 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -1625,33 +1625,6 @@ bool QListView::isSelectionRectVisible() const } /*! - \property QListView::expandingListItems - \brief if items occupy the entire width of the column - \since 5.9 - - If this property is \c true then all items in the column - will have the width of the column; otherwise the width of - each item will be determined by it's size hint. - - By default, this property is \c true. -*/ -void QListView::setExpandingListItems(bool enable) -{ - Q_D(QListView); - if (d->expandingListItems == enable) - return; - d->expandingListItems = enable; - if (viewMode() == ListMode && flow() == QListView::TopToBottom && isWrapping()) - d->doDelayedItemsLayout(); -} - -bool QListView::isExpandingListItems() const -{ - Q_D(const QListView); - return d->expandingListItems; -} - -/*! \reimp */ bool QListView::event(QEvent *e) @@ -1677,8 +1650,7 @@ QListViewPrivate::QListViewPrivate() column(0), uniformItemSizes(false), batchSize(100), - showElasticBand(false), - expandingListItems(true) + showElasticBand(false) { } @@ -2020,7 +1992,9 @@ int QCommonListViewBase::horizontalScrollToValue(const int /*index*/, QListView: QListModeViewBase::QListModeViewBase(QListView *q, QListViewPrivate *d) : QCommonListViewBase(q, d) { +#if QT_CONFIG(draganddrop) dd->defaultDropAction = Qt::CopyAction; +#endif } #ifndef QT_NO_DRAGANDDROP @@ -2393,8 +2367,7 @@ QListViewItem QListModeViewBase::indexToListViewItem(const QModelIndex &index) c int right = (segment + 1 >= segmentPositions.count() ? contentsSize.width() : segmentPositions.at(segment + 1)); - size.setWidth(dd->expandingListItems ? right - pos.x() - : qMin(size.width(), right - pos.x())); + size.setWidth(right - pos.x()); } else { // make the items as wide as the viewport size.setWidth(qMax(size.width(), viewport()->width() - 2 * spacing())); } @@ -2578,15 +2551,8 @@ QVector<QModelIndex> QListModeViewBase::intersectingSet(const QRect &area) const if (isHidden(row)) continue; QModelIndex index = modelIndex(row); - if (index.isValid()) { - if (flow() == QListView::LeftToRight || dd->expandingListItems) { - ret += index; - } else { - const int iw = indexToListViewItem(index).width(); // item width - if (iw > 0 && segStartPosition - segmentPositions.at(seg) < iw) - ret += index; - } - } + if (index.isValid()) + ret += index; #if 0 // for debugging else qWarning("intersectingSet: row %d was invalid", row); diff --git a/src/widgets/itemviews/qlistview.h b/src/widgets/itemviews/qlistview.h index 4cf53f9bab..e918e66d38 100644 --- a/src/widgets/itemviews/qlistview.h +++ b/src/widgets/itemviews/qlistview.h @@ -66,7 +66,6 @@ class Q_WIDGETS_EXPORT QListView : public QAbstractItemView Q_PROPERTY(int batchSize READ batchSize WRITE setBatchSize) Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap) Q_PROPERTY(bool selectionRectVisible READ isSelectionRectVisible WRITE setSelectionRectVisible) - Q_PROPERTY(bool expandingListItems READ isExpandingListItems WRITE setExpandingListItems) public: enum Movement { Static, Free, Snap }; @@ -127,9 +126,6 @@ public: void setSelectionRectVisible(bool show); bool isSelectionRectVisible() const; - void setExpandingListItems(bool enable); - bool isExpandingListItems() const; - QRect visualRect(const QModelIndex &index) const Q_DECL_OVERRIDE; void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible) Q_DECL_OVERRIDE; QModelIndex indexAt(const QPoint &p) const Q_DECL_OVERRIDE; diff --git a/src/widgets/itemviews/qlistview_p.h b/src/widgets/itemviews/qlistview_p.h index a66e007195..47effcdfd9 100644 --- a/src/widgets/itemviews/qlistview_p.h +++ b/src/widgets/itemviews/qlistview_p.h @@ -431,8 +431,6 @@ public: QRect elasticBand; bool showElasticBand; - - bool expandingListItems; }; // inline implementations diff --git a/src/widgets/itemviews/qlistwidget.h b/src/widgets/itemviews/qlistwidget.h index c70e0522b7..85ca639e50 100644 --- a/src/widgets/itemviews/qlistwidget.h +++ b/src/widgets/itemviews/qlistwidget.h @@ -252,8 +252,9 @@ public: bool isItemHidden(const QListWidgetItem *item) const; void setItemHidden(const QListWidgetItem *item, bool hide); +#if QT_CONFIG(draganddrop) void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE; - +#endif public Q_SLOTS: void scrollToItem(const QListWidgetItem *item, QAbstractItemView::ScrollHint hint = EnsureVisible); void clear(); diff --git a/src/widgets/itemviews/qtablewidget.h b/src/widgets/itemviews/qtablewidget.h index 5dde93f628..b91bcf7ce4 100644 --- a/src/widgets/itemviews/qtablewidget.h +++ b/src/widgets/itemviews/qtablewidget.h @@ -331,8 +331,9 @@ protected: QModelIndex indexFromItem(QTableWidgetItem *item) const; QTableWidgetItem *itemFromIndex(const QModelIndex &index) const; +#if QT_CONFIG(draganddrop) void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE; - +#endif private: void setModel(QAbstractItemModel *model) Q_DECL_OVERRIDE; diff --git a/src/widgets/itemviews/qtreewidget.h b/src/widgets/itemviews/qtreewidget.h index 36ba9985bd..fc0bccf2fe 100644 --- a/src/widgets/itemviews/qtreewidget.h +++ b/src/widgets/itemviews/qtreewidget.h @@ -360,8 +360,9 @@ protected: QModelIndex indexFromItem(const QTreeWidgetItem *item, int column = 0) const; QModelIndex indexFromItem(QTreeWidgetItem *item, int column = 0) const; // ### Qt 6: remove QTreeWidgetItem *itemFromIndex(const QModelIndex &index) const; +#if QT_CONFIG(draganddrop) void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE; - +#endif private: void setModel(QAbstractItemModel *model) Q_DECL_OVERRIDE; diff --git a/src/widgets/kernel/kernel.pri b/src/widgets/kernel/kernel.pri index ad2180bbfd..c91be918b6 100644 --- a/src/widgets/kernel/kernel.pri +++ b/src/widgets/kernel/kernel.pri @@ -15,7 +15,6 @@ HEADERS += \ kernel/qwidgetbackingstore_p.h \ kernel/qboxlayout.h \ kernel/qdesktopwidget.h \ - kernel/qformlayout.h \ kernel/qgridlayout.h \ kernel/qlayout.h \ kernel/qlayout_p.h \ @@ -45,7 +44,6 @@ SOURCES += \ kernel/qapplication.cpp \ kernel/qwidgetbackingstore.cpp \ kernel/qboxlayout.cpp \ - kernel/qformlayout.cpp \ kernel/qgridlayout.cpp \ kernel/qlayout.cpp \ kernel/qlayoutengine.cpp \ @@ -84,3 +82,8 @@ qtConfig(opengl) { HEADERS += kernel/qopenglwidget.h SOURCES += kernel/qopenglwidget.cpp } + +qtConfig(formlayout) { + HEADERS += kernel/qformlayout.h + SOURCES += kernel/qformlayout.cpp +} diff --git a/src/widgets/kernel/qformlayout.h b/src/widgets/kernel/qformlayout.h index b4185374fd..5ec27433d3 100644 --- a/src/widgets/kernel/qformlayout.h +++ b/src/widgets/kernel/qformlayout.h @@ -43,6 +43,8 @@ #include <QtWidgets/qtwidgetsglobal.h> #include <QtWidgets/QLayout> +QT_REQUIRE_CONFIG(formlayout); + QT_BEGIN_NAMESPACE diff --git a/src/widgets/kernel/qlayout.cpp b/src/widgets/kernel/qlayout.cpp index 1a341d155b..b90be2b4f1 100644 --- a/src/widgets/kernel/qlayout.cpp +++ b/src/widgets/kernel/qlayout.cpp @@ -49,7 +49,9 @@ #include "qvariant.h" #include "qwidget_p.h" #include "qlayout_p.h" +#if QT_CONFIG(formlayout) #include "qformlayout.h" +#endif QT_BEGIN_NAMESPACE @@ -320,8 +322,10 @@ int QLayout::spacing() const return boxlayout->spacing(); } else if (const QGridLayout* gridlayout = qobject_cast<const QGridLayout*>(this)) { return gridlayout->spacing(); +#if QT_CONFIG(formlayout) } else if (const QFormLayout* formlayout = qobject_cast<const QFormLayout*>(this)) { return formlayout->spacing(); +#endif } else { Q_D(const QLayout); if (d->insideSpacing >=0) { @@ -347,8 +351,10 @@ void QLayout::setSpacing(int spacing) boxlayout->setSpacing(spacing); } else if (QGridLayout* gridlayout = qobject_cast<QGridLayout*>(this)) { gridlayout->setSpacing(spacing); +#if QT_CONFIG(formlayout) } else if (QFormLayout* formlayout = qobject_cast<QFormLayout*>(this)) { formlayout->setSpacing(spacing); +#endif } else { Q_D(QLayout); d->insideSpacing = spacing; diff --git a/src/widgets/kernel/qsizepolicy.h b/src/widgets/kernel/qsizepolicy.h index 07d8393c6f..6cb4e147e9 100644 --- a/src/widgets/kernel/qsizepolicy.h +++ b/src/widgets/kernel/qsizepolicy.h @@ -112,7 +112,7 @@ public: QT_SIZEPOLICY_CONSTEXPR QSizePolicy() Q_DECL_NOTHROW : data(0) { } -#ifdef Q_COMPILER_UNIFORM_INIT +#if defined(Q_COMPILER_UNIFORM_INIT) && !defined(Q_QDOC) QT_SIZEPOLICY_CONSTEXPR QSizePolicy(Policy horizontal, Policy vertical, ControlType type = DefaultType) Q_DECL_NOTHROW : bits{0, 0, quint32(horizontal), quint32(vertical), type == DefaultType ? 0 : toControlTypeFieldValue(type), 0, 0, 0} diff --git a/src/widgets/kernel/qtooltip.cpp b/src/widgets/kernel/qtooltip.cpp index a92dc2cbf7..48afeb1dcc 100644 --- a/src/widgets/kernel/qtooltip.cpp +++ b/src/widgets/kernel/qtooltip.cpp @@ -43,18 +43,19 @@ #include <qapplication.h> #include <qdesktopwidget.h> #include <qevent.h> -#include <qlabel.h> #include <qpointer.h> #include <qstyle.h> #include <qstyleoption.h> #include <qstylepainter.h> #include <qtimer.h> -#include <qtooltip.h> #include <private/qeffects_p.h> #include <qtextdocument.h> #include <qdebug.h> #include <private/qstylesheetstyle_p.h> + #ifndef QT_NO_TOOLTIP +#include <qlabel.h> +#include <qtooltip.h> #if 0 // Used to be included in Qt4 for Q_WS_MAC # include <private/qcore_mac_p.h> diff --git a/src/widgets/kernel/qwhatsthis.cpp b/src/widgets/kernel/qwhatsthis.cpp index 6061af5f38..4286019717 100644 --- a/src/widgets/kernel/qwhatsthis.cpp +++ b/src/widgets/kernel/qwhatsthis.cpp @@ -462,11 +462,13 @@ bool QWhatsThisPrivate::eventFilter(QObject *o, QEvent *e) case QEvent::KeyPress: { QKeyEvent* kev = (QKeyEvent*)e; - +#if QT_CONFIG(shortcut) if (kev->matches(QKeySequence::Cancel)) { QWhatsThis::leaveWhatsThisMode(); return true; - } else if (customWhatsThis) { + } else +#endif + if (customWhatsThis) { return false; } else if (kev->key() == Qt::Key_Menu || (kev->key() == Qt::Key_F10 && diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 8a642940cd..8d5c3e415a 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -12769,8 +12769,6 @@ void QWidget::activateWindow() */ int QWidget::metric(PaintDeviceMetric m) const { - Q_D(const QWidget); - QWindow *topLevelWindow = 0; QScreen *screen = 0; if (QWidget *topLevel = window()) { @@ -12798,16 +12796,16 @@ int QWidget::metric(PaintDeviceMetric m) const } else if (m == PdmDepth) { return screen->depth(); } else if (m == PdmDpiX) { - if (d->extra && d->extra->customDpiX) - return d->extra->customDpiX; - else if (d->parent) - return static_cast<QWidget *>(d->parent)->metric(m); + for (const QWidget *p = this; p; p = p->parentWidget()) { + if (p->d_func()->extra && p->d_func()->extra->customDpiX) + return p->d_func()->extra->customDpiX; + } return qRound(screen->logicalDotsPerInchX()); } else if (m == PdmDpiY) { - if (d->extra && d->extra->customDpiY) - return d->extra->customDpiY; - else if (d->parent) - return static_cast<QWidget *>(d->parent)->metric(m); + for (const QWidget *p = this; p; p = p->parentWidget()) { + if (p->d_func()->extra && p->d_func()->extra->customDpiY) + return p->d_func()->extra->customDpiY; + } return qRound(screen->logicalDotsPerInchY()); } else if (m == PdmPhysicalDpiX) { return qRound(screen->physicalDotsPerInchX()); diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp index 5abce140ce..31f2d672bb 100644 --- a/src/widgets/kernel/qwidgetwindow.cpp +++ b/src/widgets/kernel/qwidgetwindow.cpp @@ -285,6 +285,7 @@ bool QWidgetWindow::event(QEvent *event) return true; case QEvent::WindowStateChange: + QWindow::event(event); // Update QWindow::Visibility and emit signals. handleWindowStateChangedEvent(static_cast<QWindowStateChangeEvent *>(event)); return true; diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 095cda1949..92cd5cc0f1 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -48,8 +48,14 @@ #include <qcache.h> #include <qdockwidget.h> #include <qdrawutil.h> +#if QT_CONFIG(dialogbuttonbox) #include <qdialogbuttonbox.h> +#endif +#if QT_CONFIG(formlayout) #include <qformlayout.h> +#else +#include <qlayout.h> +#endif #include <qgroupbox.h> #include <qmath.h> #include <qmenu.h> @@ -4922,9 +4928,11 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget case SH_ScrollBar_ContextMenu: ret = true; break; +#if QT_CONFIG(dialogbuttonbox) case SH_DialogButtons_DefaultButton: // This value not used anywhere. ret = QDialogButtonBox::AcceptRole; break; +#endif #ifndef QT_NO_GROUPBOX case SH_GroupBox_TextLabelVerticalAlignment: ret = Qt::AlignVCenter; @@ -5112,11 +5120,13 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget case SH_TabBar_ElideMode: ret = Qt::ElideNone; break; +#if QT_CONFIG(dialogbuttonbox) case SH_DialogButtonLayout: ret = QDialogButtonBox::WinLayout; if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) ret = theme->themeHint(QPlatformTheme::DialogButtonBoxLayout).toInt(); break; +#endif case SH_ComboBox_PopupFrameStyle: ret = QFrame::StyledPanel | QFrame::Plain; break; @@ -5162,12 +5172,14 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget ret = QWizard::ClassicStyle; break; #endif +#if QT_CONFIG(formlayout) case SH_FormLayoutWrapPolicy: ret = QFormLayout::DontWrapRows; break; case SH_FormLayoutFieldGrowthPolicy: ret = QFormLayout::AllNonFixedFieldsGrow; break; +#endif case SH_FormLayoutFormAlignment: ret = Qt::AlignLeft | Qt::AlignTop; break; @@ -5242,6 +5254,7 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget return ret; } +#if QT_CONFIG(imageformat_xpm) static QPixmap cachedPixmapFromXPM(const char * const *xpm) { QPixmap result; @@ -5254,6 +5267,7 @@ static QPixmap cachedPixmapFromXPM(const char * const *xpm) } static inline QPixmap titleBarMenuCachedPixmapFromXPM() { return cachedPixmapFromXPM(qt_menu_xpm); } +#endif // QT_CONFIG(imageformat_xpm) #ifndef QT_NO_IMAGEFORMAT_PNG static inline QString clearText16IconPath() diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index 75c50bb146..1267907303 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -43,7 +43,11 @@ #if QT_CONFIG(style_fusion) || defined(QT_PLUGIN) #include "qcommonstyle_p.h" #include <qcombobox.h> +#if QT_CONFIG(pushbutton) #include <qpushbutton.h> +#else +#include <qabstractbutton.h> +#endif #include <qpainter.h> #include <qdir.h> #include <qstyleoption.h> @@ -53,9 +57,11 @@ #include <qgroupbox.h> #include <qprocess.h> #include <qpixmapcache.h> -#include <qdialogbuttonbox.h> #include <qscrollbar.h> #include <qspinbox.h> +#if QT_CONFIG(abstractslider) +#include <qabstractslider.h> +#endif #include <qslider.h> #include <qsplitter.h> #include <qprogressbar.h> @@ -86,7 +92,7 @@ static const int windowsRightBorder = 15; // right border on windows static const int groupBoxBottomMargin = 0; // space below the groupbox static const int groupBoxTopMargin = 3; - +#if QT_CONFIG(imageformat_xpm) /* XPM */ static const char * const dock_widget_close_xpm[] = { "11 13 7 1", @@ -173,7 +179,7 @@ static const char * const qt_titlebar_context_help[] = { " ", " ## ", " ## "}; - +#endif // QT_CONFIG(imageformat_xpm) static QColor mergedColors(const QColor &colorA, const QColor &colorB, int factor = 50) { @@ -2368,6 +2374,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption bool hover = (titleBar->activeSubControls & SC_TitleBarContextHelpButton) && (titleBar->state & State_MouseOver); bool sunken = (titleBar->activeSubControls & SC_TitleBarContextHelpButton) && (titleBar->state & State_Sunken); qt_fusion_draw_mdibutton(painter, titleBar, contextHelpButtonRect, hover, sunken); +#if QT_CONFIG(imageformat_xpm) QImage image(qt_titlebar_context_help); QColor alpha = textColor; alpha.setAlpha(128); @@ -2375,6 +2382,7 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption image.setColor(2, alpha.rgba()); painter->setRenderHint(QPainter::SmoothPixmapTransform); painter->drawImage(contextHelpButtonRect.adjusted(4, 4, -4, -4), image); +#endif } } @@ -3289,7 +3297,9 @@ void QFusionStyle::polish(QWidget *widget) #if QT_CONFIG(splitter) || qobject_cast<QSplitterHandle *>(widget) #endif +#if QT_CONFIG(abstractslider) || qobject_cast<QAbstractSlider *>(widget) +#endif #if QT_CONFIG(spinbox) || qobject_cast<QAbstractSpinBox *>(widget) #endif @@ -3328,7 +3338,9 @@ void QFusionStyle::unpolish(QWidget *widget) #if QT_CONFIG(splitter) || qobject_cast<QSplitterHandle *>(widget) #endif +#if QT_CONFIG(abstractslider) || qobject_cast<QAbstractSlider *>(widget) +#endif #if QT_CONFIG(spinbox) || qobject_cast<QAbstractSpinBox *>(widget) #endif diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index 241f647b26..d9d30efc8b 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -52,12 +52,14 @@ #include <private/qcore_mac_p.h> #include <private/qcombobox_p.h> +#include <private/qtabbar_p.h> #include <private/qpainter_p.h> #include <qapplication.h> #include <qbitmap.h> -#include <qcheckbox.h> #include <qcombobox.h> +#if QT_CONFIG(dialogbuttonbox) #include <qdialogbuttonbox.h> +#endif #include <qdockwidget.h> #include <qevent.h> #include <qfocusframe.h> @@ -74,7 +76,9 @@ #include <qpixmapcache.h> #include <qpointer.h> #include <qprogressbar.h> +#if QT_CONFIG(pushbutton) #include <qpushbutton.h> +#endif #include <qradiobutton.h> #include <qrubberband.h> #include <qscrollbar.h> @@ -187,11 +191,33 @@ static const QColor mainWindowGradientEnd(200, 200, 200); static const int DisclosureOffset = 4; +// Tab bar colors +// active: window is active +// selected: tab is selected +// hovered: tab is hovered +static const QColor tabBarTabBackgroundActive(190, 190, 190); +static const QColor tabBarTabBackgroundActiveHovered(178, 178, 178); +static const QColor tabBarTabBackgroundActiveSelected(211, 211, 211); +static const QColor tabBarTabBackground(227, 227, 227); +static const QColor tabBarTabBackgroundSelected(246, 246, 246); +static const QColor tabBarTabLineActive(160, 160, 160); +static const QColor tabBarTabLineActiveHovered(150, 150, 150); +static const QColor tabBarTabLine(210, 210, 210); +static const QColor tabBarTabLineSelected(189, 189, 189); +static const QColor tabBarCloseButtonBackgroundHovered(162, 162, 162); +static const QColor tabBarCloseButtonBackgroundPressed(153, 153, 153); +static const QColor tabBarCloseButtonBackgroundSelectedHovered(192, 192, 192); +static const QColor tabBarCloseButtonBackgroundSelectedPressed(181, 181, 181); +static const QColor tabBarCloseButtonCross(100, 100, 100); +static const QColor tabBarCloseButtonCrossSelected(115, 115, 115); + +static const int closeButtonSize = 14; +static const qreal closeButtonCornerRadius = 2.0; + // Resolve these at run-time, since the functions was moved in Leopard. typedef HIRect * (*PtrHIShapeGetBounds)(HIShapeRef, HIRect *); static PtrHIShapeGetBounds ptrHIShapeGetBounds = 0; -static int closeButtonSize = 12; #ifndef QT_NO_TABBAR static bool isVerticalTabs(const QTabBar::Shape shape) { return (shape == QTabBar::RoundedEast @@ -214,41 +240,35 @@ static bool isInMacUnifiedToolbarArea(QWindow *window, int windowY) } -void drawTabCloseButton(QPainter *p, bool hover, bool active, bool selected) +void drawTabCloseButton(QPainter *p, bool hover, bool selected, bool pressed) { - // draw background circle p->setRenderHints(QPainter::Antialiasing); QRect rect(0, 0, closeButtonSize, closeButtonSize); - QColor background; + const int width = rect.width(); + const int height = rect.height(); + if (hover) { - background = QColor(124, 124, 124); - } else { - if (active) { - if (selected) - background = QColor(104, 104, 104); - else - background = QColor(83, 83, 83); + // draw background circle + QColor background; + if (selected) { + background = pressed ? tabBarCloseButtonBackgroundSelectedPressed : tabBarCloseButtonBackgroundSelectedHovered; } else { - if (selected) - background = QColor(144, 144, 144); - else - background = QColor(114, 114, 114); + background = pressed ? tabBarCloseButtonBackgroundPressed : tabBarCloseButtonBackgroundHovered; } + p->setPen(Qt::transparent); + p->setBrush(background); + p->drawRoundedRect(rect, closeButtonCornerRadius, closeButtonCornerRadius); } - p->setPen(Qt::transparent); - p->setBrush(background); - p->drawEllipse(rect); // draw cross - int min = 3; - int max = 9; + const int margin = 3; QPen crossPen; - crossPen.setColor(QColor(194, 194, 194)); - crossPen.setWidthF(1.3); + crossPen.setColor(selected ? tabBarCloseButtonCrossSelected : tabBarCloseButtonCross); + crossPen.setWidthF(1.1); crossPen.setCapStyle(Qt::FlatCap); p->setPen(crossPen); - p->drawLine(min, min, max, max); - p->drawLine(min, max, max, min); + p->drawLine(margin, margin, width - margin, height - margin); + p->drawLine(margin, height - margin, width - margin, margin); } #ifndef QT_NO_TABBAR @@ -275,108 +295,71 @@ QRect rotateTabPainter(QPainter *p, QTabBar::Shape shape, QRect tabRect) return tabRect; } -void drawTabShape(QPainter *p, const QStyleOptionTab *tabOpt, bool isUnified) +void drawTabShape(QPainter *p, const QStyleOptionTab *tabOpt, bool isUnified, int tabOverlap) { - QRect r = tabOpt->rect; - p->translate(tabOpt->rect.x(), tabOpt->rect.y()); - r.moveLeft(0); - r.moveTop(0); - QRect tabRect = rotateTabPainter(p, tabOpt->shape, r); + QRect rect = tabOpt->rect; - int width = tabRect.width(); - int height = 20; - bool active = (tabOpt->state & QStyle::State_Active); - bool selected = (tabOpt->state & QStyle::State_Selected); + switch (tabOpt->shape) { + case QTabBar::RoundedNorth: + case QTabBar::TriangularNorth: + case QTabBar::RoundedSouth: + case QTabBar::TriangularSouth: + rect.adjust(-tabOverlap, 0, 0, 0); + break; + case QTabBar::RoundedEast: + case QTabBar::TriangularEast: + case QTabBar::RoundedWest: + case QTabBar::TriangularWest: + rect.adjust(0, -tabOverlap, 0, 0); + break; + default: + break; + } - if (selected) { - QRect rect(1, 0, width - 2, height); + p->translate(rect.x(), rect.y()); + rect.moveLeft(0); + rect.moveTop(0); + const QRect tabRect = rotateTabPainter(p, tabOpt->shape, rect); + + const int width = tabRect.width(); + const int height = tabRect.height(); + const bool active = (tabOpt->state & QStyle::State_Active); + const bool selected = (tabOpt->state & QStyle::State_Selected); + const QRect bodyRect(1, 1, width - 2, height - 2); + const QRect topLineRect(1, 0, width - 2, 1); + const QRect bottomLineRect(1, height - 1, width - 2, 1); + if (selected) { // fill body if (tabOpt->documentMode && isUnified) { p->save(); p->setCompositionMode(QPainter::CompositionMode_Source); - p->fillRect(rect, QColor(Qt::transparent)); + p->fillRect(tabRect, QColor(Qt::transparent)); p->restore(); } else if (active) { - p->fillRect(rect, QColor(167, 167, 167)); - } else { - QLinearGradient gradient(rect.topLeft(), rect.bottomLeft()); - gradient.setColorAt(0, QColor(216, 216, 216)); - gradient.setColorAt(0.5, QColor(215, 215, 215)); - gradient.setColorAt(1, QColor(210, 210, 210)); - p->fillRect(rect, gradient); - } - - // draw border - QColor borderSides; - QColor borderBottom; - if (active) { - borderSides = QColor(88, 88, 88); - borderBottom = QColor(88, 88, 88); + p->fillRect(bodyRect, tabBarTabBackgroundActiveSelected); + // top line + p->fillRect(topLineRect, tabBarTabLineSelected); } else { - borderSides = QColor(121, 121, 121); - borderBottom = QColor(116, 116, 116); + p->fillRect(bodyRect, tabBarTabBackgroundSelected); } - - p->setPen(borderSides); - - int bottom = height; - // left line - p->drawLine(0, 1, 0, bottom-2); - // right line - p->drawLine(width-1, 1, width-1, bottom-2); - - // bottom line - if (active) { - p->setPen(QColor(168, 168, 168)); - p->drawLine(3, bottom-1, width-3, bottom-1); - } - p->setPen(borderBottom); - p->drawLine(2, bottom, width-2, bottom); - - int w = 3; - QRectF rectangleLeft(1, height - w, w, w); - QRectF rectangleRight(width - 2, height - 1, w, w); - int startAngle = 180 * 16; - int spanAngle = 90 * 16; - p->setRenderHint(QPainter::Antialiasing); - p->drawArc(rectangleLeft, startAngle, spanAngle); - p->drawArc(rectangleRight, startAngle, -spanAngle); } else { // when the mouse is over non selected tabs they get a new color - bool hover = (tabOpt->state & QStyle::State_MouseOver); + const bool hover = (tabOpt->state & QStyle::State_MouseOver); if (hover) { - QRect rect(1, 2, width - 1, height - 1); - p->fillRect(rect, QColor(110, 110, 110)); - } - - // seperator lines between tabs - bool west = (tabOpt->shape == QTabBar::RoundedWest || tabOpt->shape == QTabBar::TriangularWest); - bool drawOnRight = !west; - if ((!drawOnRight && tabOpt->selectedPosition != QStyleOptionTab::NextIsSelected) - || (drawOnRight && tabOpt->selectedPosition != QStyleOptionTab::NextIsSelected)) { - QColor borderColor; - QColor borderHighlightColor; - if (active) { - borderColor = QColor(64, 64, 64); - borderHighlightColor = QColor(140, 140, 140); - } else { - borderColor = QColor(135, 135, 135); - borderHighlightColor = QColor(178, 178, 178); - } - - int x = drawOnRight ? width : 0; - - // tab seperator line - p->setPen(borderColor); - p->drawLine(x, 2, x, height + 1); - - // tab seperator highlight - p->setPen(borderHighlightColor); - p->drawLine(x-1, 2, x-1, height + 1); - p->drawLine(x+1, 2, x+1, height + 1); + // fill body + p->fillRect(bodyRect, tabBarTabBackgroundActiveHovered); + // bottom line + p->fillRect(bottomLineRect, tabBarTabLineActiveHovered); } } + + // separator lines between tabs + const QRect leftLineRect(0, 1, 1, height - 2); + const QRect rightLineRect(width - 1, 1, 1, height - 2); + const QColor separatorLineColor = active ? tabBarTabLineActive : tabBarTabLine; + p->fillRect(leftLineRect, separatorLineColor); + p->fillRect(rightLineRect, separatorLineColor); } void drawTabBase(QPainter *p, const QStyleOptionTabBarBase *tbb, const QWidget *w) @@ -387,53 +370,25 @@ void drawTabBase(QPainter *p, const QStyleOptionTabBarBase *tbb, const QWidget * } else { r.setHeight(w->height()); } - QRect tabRect = rotateTabPainter(p, tbb->shape, r); - int width = tabRect.width(); - int height = tabRect.height(); - bool active = (tbb->state & QStyle::State_Active); - - // top border lines - QColor borderHighlightTop; - QColor borderTop; - if (active) { - borderTop = QColor(64, 64, 64); - borderHighlightTop = QColor(174, 174, 174); - } else { - borderTop = QColor(135, 135, 135); - borderHighlightTop = QColor(207, 207, 207); - } - p->setPen(borderHighlightTop); - p->drawLine(tabRect.x(), 0, width, 0); - p->setPen(borderTop); - p->drawLine(tabRect.x(), 1, width, 1); - - // center block - QRect centralRect(tabRect.x(), 2, width, height - 2); - if (active) { - QColor mainColor = QColor(120, 120, 120); - p->fillRect(centralRect, mainColor); - } else { - QLinearGradient gradient(centralRect.topLeft(), centralRect.bottomLeft()); - gradient.setColorAt(0, QColor(165, 165, 165)); - gradient.setColorAt(0.5, QColor(164, 164, 164)); - gradient.setColorAt(1, QColor(158, 158, 158)); - p->fillRect(centralRect, gradient); - } - - // bottom border lines - QColor borderHighlightBottom; - QColor borderBottom; - if (active) { - borderHighlightBottom = QColor(153, 153, 153); - borderBottom = QColor(64, 64, 64); - } else { - borderHighlightBottom = QColor(177, 177, 177); - borderBottom = QColor(127, 127, 127); - } - p->setPen(borderHighlightBottom); - p->drawLine(tabRect.x(), height - 2, width, height - 2); - p->setPen(borderBottom); - p->drawLine(tabRect.x(), height - 1, width, height - 1); + const QRect tabRect = rotateTabPainter(p, tbb->shape, r); + const int width = tabRect.width(); + const int height = tabRect.height(); + const bool active = (tbb->state & QStyle::State_Active); + + // fill body + const QRect bodyRect(0, 1, width, height - 1); + const QColor bodyColor = active ? tabBarTabBackgroundActive : tabBarTabBackground; + p->fillRect(bodyRect, bodyColor); + + // top line + const QRect topLineRect(0, 0, width, 1); + const QColor topLineColor = active ? tabBarTabLineActive : tabBarTabLine; + p->fillRect(topLineRect, topLineColor); + + // bottom line + const QRect bottomLineRect(0, height - 1, width, 1); + const QColor bottomLineColor = active ? tabBarTabLineActive : tabBarTabLine; + p->fillRect(bottomLineRect, bottomLineColor); } #endif @@ -662,12 +617,16 @@ static QSize qt_aqua_get_known_size(QStyle::ContentsType ct, const QWidget *widg } if (ct == QStyle::CT_CustomBase && widg) { +#if QT_CONFIG(pushbutton) if (qobject_cast<const QPushButton *>(widg)) ct = QStyle::CT_PushButton; +#endif else if (qobject_cast<const QRadioButton *>(widg)) ct = QStyle::CT_RadioButton; +#if QT_CONFIG(checkbox) else if (qobject_cast<const QCheckBox *>(widg)) ct = QStyle::CT_CheckBox; +#endif #ifndef QT_NO_COMBOBOX else if (qobject_cast<const QComboBox *>(widg)) ct = QStyle::CT_ComboBox; @@ -701,6 +660,7 @@ static QSize qt_aqua_get_known_size(QStyle::ContentsType ct, const QWidget *widg } switch (ct) { +#if QT_CONFIG(pushbutton) case QStyle::CT_PushButton: { const QPushButton *psh = qobject_cast<const QPushButton *>(widg); // If this comparison is false, then the widget was not a push button. @@ -743,6 +703,7 @@ static QSize qt_aqua_get_known_size(QStyle::ContentsType ct, const QWidget *widg // Since there's no default size we return the large size... ret = QSize(-1, qt_mac_aqua_get_metric(kThemeMetricPushButtonHeight)); } +#endif #if 0 //Not sure we are applying the rules correctly for RadioButtons/CheckBoxes --Sam } else if (ct == QStyle::CT_RadioButton) { QRadioButton *rdo = static_cast<QRadioButton *>(widg); @@ -1096,6 +1057,55 @@ void QMacStylePrivate::drawFocusRing(QPainter *p, const QRect &targetRect, int h QRect(focusRingPixmap.width() - shCornerSize, svCornerSize, shCornerSize, focusRingPixmap.width() - 2 * svCornerSize)); } +#ifndef QT_NO_TABBAR +void QMacStylePrivate::tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect) const +{ + Q_ASSERT(textRect); + QRect tr = opt->rect; + const bool verticalTabs = opt->shape == QTabBar::RoundedEast + || opt->shape == QTabBar::RoundedWest + || 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 + + int verticalShift = proxyStyle->pixelMetric(QStyle::PM_TabBarTabShiftVertical, opt, widget); + int horizontalShift = proxyStyle->pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, opt, widget); + const int hpadding = 4; + const int vpadding = proxyStyle->pixelMetric(QStyle::PM_TabBarTabVSpace, opt, widget) / 2; + if (opt->shape == QTabBar::RoundedSouth || opt->shape == QTabBar::TriangularSouth) + verticalShift = -verticalShift; + tr.adjust(hpadding, verticalShift - vpadding, horizontalShift - hpadding, vpadding); + const bool selected = opt->state & QStyle::State_Selected; + if (selected) { + tr.setTop(tr.top() - verticalShift); + tr.setRight(tr.right() - horizontalShift); + } + + // left widget + if (!opt->leftButtonSize.isEmpty()) { + const int buttonSize = verticalTabs ? opt->leftButtonSize.height() : opt->leftButtonSize.width(); + tr.setLeft(tr.left() + 4 + buttonSize); + // make text aligned to center + if (opt->rightButtonSize.isEmpty()) + tr.setRight(tr.right() - 4 - buttonSize); + } + // right widget + if (!opt->rightButtonSize.isEmpty()) { + const int buttonSize = verticalTabs ? opt->rightButtonSize.height() : opt->rightButtonSize.width(); + tr.setRight(tr.right() - 4 - buttonSize); + // make text aligned to center + if (opt->leftButtonSize.isEmpty()) + tr.setLeft(tr.left() + 4 + buttonSize); + } + + if (!verticalTabs) + tr = proxyStyle->visualRect(opt->direction, opt->rect, tr); + + *textRect = tr; +} +#endif //QT_NO_TABBAR + QAquaWidgetSize QMacStylePrivate::effectiveAquaSizeConstrain(const QStyleOption *option, const QWidget *widg, QStyle::ContentsType ct, @@ -1304,6 +1314,7 @@ void QMacStylePrivate::initHIThemePushButton(const QStyleOptionButton *btn, } } +#if QT_CONFIG(pushbutton) bool qt_mac_buttonIsRenderedFlat(const QPushButton *pushButton, const QStyleOptionButton *option) { QMacStyle *macStyle = qobject_cast<QMacStyle *>(pushButton->style()); @@ -1313,6 +1324,7 @@ bool qt_mac_buttonIsRenderedFlat(const QPushButton *pushButton, const QStyleOpti macStyle->d_func()->initHIThemePushButton(option, pushButton, kThemeStateActive, &bdi); return bdi.kind == kThemeBevelButton; } +#endif /** Creates a HIThemeButtonDrawInfo structure that specifies the correct button @@ -2461,6 +2473,26 @@ int QMacStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QW ret = int([NSWindow frameRectForContentRect:NSZeroRect styleMask:NSTitledWindowMask].size.height); break; + case QStyle::PM_TabBarTabHSpace: + switch (d->aquaSizeConstrain(opt, widget)) { + case QAquaSizeLarge: + ret = QCommonStyle::pixelMetric(metric, opt, widget); + break; + case QAquaSizeSmall: + ret = 20; + break; + case QAquaSizeMini: + ret = 16; + break; + case QAquaSizeUnknown: + const QStyleOptionTab *tb = qstyleoption_cast<const QStyleOptionTab *>(opt); + if (tb && tb->documentMode) + ret = 24; + else + ret = QCommonStyle::pixelMetric(metric, opt, widget); + break; + } + break; case PM_TabBarTabVSpace: ret = 4; break; @@ -2469,10 +2501,10 @@ int QMacStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QW ret = 0; break; case PM_TabBarBaseHeight: - ret = 0; + ret = 21; break; case PM_TabBarTabOverlap: - ret = 0; + ret = 1; break; case PM_TabBarBaseOverlap: switch (d->aquaSizeConstrain(opt, widget)) { @@ -2649,20 +2681,6 @@ int QMacStyle::pixelMetric(PixelMetric metric, const QStyleOption *opt, const QW case PM_LayoutHorizontalSpacing: case PM_LayoutVerticalSpacing: return -1; - case QStyle::PM_TabBarTabHSpace: - switch (d->aquaSizeConstrain(opt, widget)) { - case QAquaSizeLarge: - case QAquaSizeUnknown: - ret = QCommonStyle::pixelMetric(metric, opt, widget); - break; - case QAquaSizeSmall: - ret = 20; - break; - case QAquaSizeMini: - ret = 16; - break; - } - break; case PM_MenuHMargin: ret = 0; break; @@ -2930,9 +2948,11 @@ int QMacStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *w case SH_TabBar_ElideMode: ret = Qt::ElideRight; break; +#if QT_CONFIG(dialogbuttonbox) case SH_DialogButtonLayout: ret = QDialogButtonBox::MacLayout; break; +#endif case SH_FormLayoutWrapPolicy: ret = QFormLayout::DontWrapRows; break; @@ -3487,10 +3507,18 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai case PE_FrameStatusBarItem: break; case PE_IndicatorTabClose: { - bool hover = (opt->state & State_MouseOver); - bool selected = (opt->state & State_Selected); - bool active = (opt->state & State_Active); - drawTabCloseButton(p, hover, active, selected); + // Make close button visible only on the hovered tab. + if (QTabBar *tabBar = qobject_cast<QTabBar*>(w->parentWidget())) { + const QTabBarPrivate *tabBarPrivate = static_cast<QTabBarPrivate *>(QObjectPrivate::get(tabBar)); + const int hoveredTabIndex = tabBarPrivate->hoveredTabIndex(); + if (hoveredTabIndex != -1 && ((w == tabBar->tabButton(hoveredTabIndex, QTabBar::LeftSide)) || + (w == tabBar->tabButton(hoveredTabIndex, QTabBar::RightSide)))) { + const bool hover = (opt->state & State_MouseOver); + const bool selected = (opt->state & State_Selected); + const bool pressed = (opt->state & State_Sunken); + drawTabCloseButton(p, hover, selected, pressed); + } + } } break; case PE_PanelStatusBar: { // Fill the status bar with the titlebar gradient. @@ -4027,7 +4055,6 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter #ifndef QT_NO_TABBAR case CE_TabBarTabShape: if (const QStyleOptionTab *tabOpt = qstyleoption_cast<const QStyleOptionTab *>(opt)) { - if (tabOpt->documentMode) { p->save(); bool isUnified = false; @@ -4037,7 +4064,9 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter isUnified = isInMacUnifiedToolbarArea(w->window()->windowHandle(), windowTabStart.y()); } - drawTabShape(p, tabOpt, isUnified); + const int tabOverlap = proxy()->pixelMetric(PM_TabBarTabOverlap, opt, w); + drawTabShape(p, tabOpt, isUnified, tabOverlap); + p->restore(); return; } @@ -4163,23 +4192,6 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter } myTab.rect.setHeight(myTab.rect.height() + heightOffset); - if (myTab.documentMode) { - p->save(); - rotateTabPainter(p, myTab.shape, myTab.rect); - - QColor shadowColor = QColor(myTab.documentMode ? Qt::white : Qt::black); - shadowColor.setAlpha(75); - QPalette np = tab->palette; - np.setColor(QPalette::WindowText, shadowColor); - - QRect nr = proxy()->subElementRect(SE_TabBarTabText, opt, w); - nr.moveTop(-1); - int alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextHideMnemonic; - proxy()->drawItemText(p, nr, alignment, np, tab->state & State_Enabled, - tab->text, QPalette::WindowText); - p->restore(); - } - QCommonStyle::drawControl(ce, &myTab, p, w); } else { p->save(); @@ -4897,6 +4909,73 @@ QRect QMacStyle::subElementRect(SubElement sr, const QStyleOption *opt, } } break; + case SE_TabBarTabText: + if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) { + d->tabLayout(tab, widget, &rect); + } + break; + case SE_TabBarTabLeftButton: + case SE_TabBarTabRightButton: + if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) { + bool selected = tab->state & State_Selected; + int verticalShift = proxy()->pixelMetric(QStyle::PM_TabBarTabShiftVertical, tab, widget); + int horizontalShift = proxy()->pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, tab, widget); + int hpadding = 5; + + bool verticalTabs = tab->shape == QTabBar::RoundedEast + || tab->shape == QTabBar::RoundedWest + || tab->shape == QTabBar::TriangularEast + || tab->shape == QTabBar::TriangularWest; + + QRect tr = tab->rect; + if (tab->shape == QTabBar::RoundedSouth || tab->shape == QTabBar::TriangularSouth) + verticalShift = -verticalShift; + if (verticalTabs) { + qSwap(horizontalShift, verticalShift); + horizontalShift *= -1; + verticalShift *= -1; + } + if (tab->shape == QTabBar::RoundedWest || tab->shape == QTabBar::TriangularWest) + horizontalShift = -horizontalShift; + + tr.adjust(0, 0, horizontalShift, verticalShift); + if (selected) + { + tr.setBottom(tr.bottom() - verticalShift); + tr.setRight(tr.right() - horizontalShift); + } + + QSize size = (sr == SE_TabBarTabLeftButton) ? tab->leftButtonSize : tab->rightButtonSize; + int w = size.width(); + int h = size.height(); + int midHeight = static_cast<int>(qCeil(float(tr.height() - h) / 2)); + int midWidth = ((tr.width() - w) / 2); + + bool atTheTop = true; + switch (tab->shape) { + case QTabBar::RoundedWest: + case QTabBar::TriangularWest: + atTheTop = (sr == SE_TabBarTabLeftButton); + break; + case QTabBar::RoundedEast: + case QTabBar::TriangularEast: + atTheTop = (sr == SE_TabBarTabRightButton); + break; + default: + if (sr == SE_TabBarTabLeftButton) + rect = QRect(tab->rect.x() + hpadding, midHeight, w, h); + else + rect = QRect(tab->rect.right() - w - hpadding, midHeight, w, h); + rect = visualRect(tab->direction, tab->rect, rect); + } + if (verticalTabs) { + if (atTheTop) + rect = QRect(midWidth, tr.y() + tab->rect.height() - hpadding - h, w, h); + else + rect = QRect(midWidth, tr.y() + hpadding, w, h); + } + } + break; #endif case SE_LineEditContents: rect = QCommonStyle::subElementRect(sr, opt, widget); @@ -6504,13 +6583,14 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, if (vertTabs) sz = sz.transposed(); int defaultTabHeight; - int defaultExtraSpace = proxy()->pixelMetric(PM_TabBarTabHSpace, tab, widget); // Remove spurious gcc warning (AFAIK) + int extraHSpace = proxy()->pixelMetric(PM_TabBarTabHSpace, tab, widget); + int extraVSpace = proxy()->pixelMetric(PM_TabBarTabVSpace, tab, widget); QFontMetrics fm = opt->fontMetrics; switch (AquaSize) { case QAquaSizeUnknown: case QAquaSizeLarge: if (tab->documentMode) - defaultTabHeight = 23; + defaultTabHeight = 24; else defaultTabHeight = 21; break; @@ -6524,10 +6604,11 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, bool setWidth = false; if (differentFont || !tab->icon.isNull()) { sz.rheight() = qMax(defaultTabHeight, sz.height()); + sz.rwidth() += extraHSpace; } else { QSize textSize = fm.size(Qt::TextShowMnemonic, tab->text); sz.rheight() = qMax(defaultTabHeight, textSize.height()); - sz.rwidth() = textSize.width() + defaultExtraSpace; + sz.rwidth() = textSize.width() + extraVSpace; setWidth = true; } diff --git a/src/widgets/styles/qmacstyle_mac_p.h b/src/widgets/styles/qmacstyle_mac_p.h index 2fb6265d75..03f5d7280f 100644 --- a/src/widgets/styles/qmacstyle_mac_p.h +++ b/src/widgets/styles/qmacstyle_mac_p.h @@ -121,7 +121,9 @@ private: Q_DISABLE_COPY(QMacStyle) Q_DECLARE_PRIVATE(QMacStyle) +#if QT_CONFIG(pushbutton) friend bool qt_mac_buttonIsRenderedFlat(const QPushButton *pushButton, const QStyleOptionButton *option); +#endif }; #endif diff --git a/src/widgets/styles/qmacstyle_mac_p_p.h b/src/widgets/styles/qmacstyle_mac_p_p.h index 798f6ed90b..59f6e893b1 100644 --- a/src/widgets/styles/qmacstyle_mac_p_p.h +++ b/src/widgets/styles/qmacstyle_mac_p_p.h @@ -53,9 +53,13 @@ #include <private/qstylehelper_p.h> #include <qapplication.h> #include <qbitmap.h> +#if QT_CONFIG(checkbox) #include <qcheckbox.h> +#endif #include <qcombobox.h> +#if QT_CONFIG(dialogbuttonbox) #include <qdialogbuttonbox.h> +#endif #include <qdockwidget.h> #include <qevent.h> #include <qfocusframe.h> @@ -74,7 +78,9 @@ #include <qpixmapcache.h> #include <qpointer.h> #include <qprogressbar.h> +#if QT_CONFIG(pushbutton) #include <qpushbutton.h> +#endif #include <qradiobutton.h> #include <qrubberband.h> #include <qsizegrip.h> @@ -154,7 +160,9 @@ typedef void (^QCocoaDrawRectBlock)(NSRect, CGContextRef); return sizes[controlSize]; \ } while (0) +#if QT_CONFIG(pushbutton) bool qt_mac_buttonIsRenderedFlat(const QPushButton *pushButton, const QStyleOptionButton *option); +#endif class QMacStylePrivate : public QCommonStylePrivate { @@ -221,6 +229,10 @@ public: void drawFocusRing(QPainter *p, const QRect &targetRect, int hMargin, int vMargin, qreal radius = 0) const; +#ifndef QT_NO_TABBAR + void tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect) const; +#endif + public: mutable QPointer<QObject> pressedButton; mutable QPointer<QObject> defaultButton; diff --git a/src/widgets/styles/qpixmapstyle.cpp b/src/widgets/styles/qpixmapstyle.cpp index a947f5d079..3aec3cf991 100644 --- a/src/widgets/styles/qpixmapstyle.cpp +++ b/src/widgets/styles/qpixmapstyle.cpp @@ -60,7 +60,9 @@ #include <QAbstractScrollArea> #include <QScrollBar> +#if QT_CONFIG(scroller) #include <qscroller.h> +#endif QT_BEGIN_NAMESPACE @@ -194,7 +196,7 @@ void QPixmapStyle::polish(QWidget *widget) view->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); } #endif -#if QT_CONFIG(gestures) +#if QT_CONFIG(gestures) && QT_CONFIG(scroller) QScroller::grabGesture(scrollArea->viewport(), QScroller::LeftMouseButtonGesture); #endif } @@ -235,7 +237,7 @@ void QPixmapStyle::unpolish(QWidget *widget) if (qstrcmp(widget->metaObject()->className(),"QComboBoxPrivateContainer") == 0) widget->removeEventFilter(this); -#if QT_CONFIG(gestures) && QT_CONFIG(scrollarea) +#if QT_CONFIG(gestures) && QT_CONFIG(scrollarea) && QT_CONFIG(scroller) if (QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea*>(widget)) QScroller::ungrabGesture(scrollArea->viewport()); #endif diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 085c743437..7dc1c35333 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -58,12 +58,16 @@ #include "private/qabstractscrollarea_p.h" #include <qtooltip.h> #include <qshareddata.h> -#include <qradiobutton.h> #include <qtoolbutton.h> #include <qscrollbar.h> +#if QT_CONFIG(abstractslider) +#include <qabstractslider.h> +#endif #include <qstring.h> #include <qfile.h> +#if QT_CONFIG(checkbox) #include <qcheckbox.h> +#endif #include <qstatusbar.h> #include <qheaderview.h> #include <private/qwindowsstyle_p_p.h> @@ -76,7 +80,9 @@ #include <qdialog.h> #include <private/qwidget_p.h> #include <QAbstractSpinBox> +#if QT_CONFIG(label) #include <QLabel> +#endif #include "qdrawutil.h" #include <limits.h> @@ -1416,11 +1422,13 @@ void QRenderRule::configurePalette(QPalette *p, QPalette::ColorGroup cg, const Q static inline QObject *parentObject(const QObject *obj) { +#if QT_CONFIG(tooltip) if (qobject_cast<const QLabel *>(obj) && qstrcmp(obj->metaObject()->className(), "QTipLabel") == 0) { QObject *p = qvariant_cast<QObject *>(obj->property("_q_stylesheet_parent")); if (p) return p; } +#endif return obj->parent(); } @@ -2422,9 +2430,11 @@ static bool unstylable(const QWidget *w) static quint64 extendedPseudoClass(const QWidget *w) { quint64 pc = w->isWindow() ? quint64(PseudoClass_Window) : 0; +#if QT_CONFIG(abstractslider) if (const QAbstractSlider *slider = qobject_cast<const QAbstractSlider *>(w)) { pc |= ((slider->orientation() == Qt::Vertical) ? PseudoClass_Vertical : PseudoClass_Horizontal); } else +#endif #ifndef QT_NO_COMBOBOX if (const QComboBox *combo = qobject_cast<const QComboBox *>(w)) { if (combo->isEditable()) @@ -2590,7 +2600,7 @@ void QStyleSheetStyle::setPalette(QWidget *w) if (!useStyleSheetPropagationInWidgetStyles || p.resolve() != 0) { QPalette wp = w->palette(); - styleSheetCaches->customPaletteWidgets.insert(w, qMakePair(wp, p.resolve())); + styleSheetCaches->customPaletteWidgets.insert(w, {wp, p.resolve()}); if (useStyleSheetPropagationInWidgetStyles) { p = p.resolve(wp); @@ -2610,20 +2620,14 @@ void QStyleSheetStyle::unsetPalette(QWidget *w) const auto it = styleSheetCaches->customPaletteWidgets.find(w); if (it != styleSheetCaches->customPaletteWidgets.end()) { - QPair<QPalette, uint> p = std::move(*it); + auto customizedPalette = std::move(*it); styleSheetCaches->customPaletteWidgets.erase(it); - QPalette original = p.first; - - if (useStyleSheetPropagationInWidgetStyles) { - original.resolve(original.resolve() & p.second); - - QPalette wp = w->palette(); - wp.resolve(wp.resolve() & ~p.second); - wp.resolve(original); - wp.resolve(wp.resolve() | original.resolve()); - original = wp; - } + QPalette original; + if (useStyleSheetPropagationInWidgetStyles) + original = std::move(customizedPalette).reverted(w->palette()); + else + original = customizedPalette.oldWidgetValue; w->setPalette(original); QWidget *ew = embeddedWidget(w); @@ -2653,18 +2657,9 @@ void QStyleSheetStyle::unsetStyleSheetFont(QWidget *w) const { const auto it = styleSheetCaches->customFontWidgets.find(w); if (it != styleSheetCaches->customFontWidgets.end()) { - QPair<QFont, uint> f = std::move(*it); + auto customizedFont = std::move(*it); styleSheetCaches->customFontWidgets.erase(it); - - QFont original = f.first; - original.resolve(original.resolve() & f.second); - - QFont font = w->font(); - font.resolve(font.resolve() & ~f.second); - font.resolve(original); - font.resolve(font.resolve() | original.resolve()); - - w->setFont(font); + w->setFont(std::move(customizedFont).reverted(w->font())); } } @@ -4738,10 +4733,12 @@ int QStyleSheetStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const return rule.box()->spacing; break; case PM_CheckBoxLabelSpacing: +#if QT_CONFIG(checkbox) if (qobject_cast<const QCheckBox *>(w)) { if (rule.hasBox() && rule.box()->spacing != -1) return rule.box()->spacing; } +#endif // assume group box subRule = renderRule(w, opt, PseudoElement_GroupBoxTitle); if (subRule.hasBox() && subRule.box()->spacing != -1) @@ -5948,7 +5945,7 @@ void QStyleSheetStyle::updateStyleSheetFont(QWidget* w) const if (rule.font.resolve()) { QFont wf = w->font(); - styleSheetCaches->customFontWidgets.insert(w, qMakePair(wf, rule.font.resolve())); + styleSheetCaches->customFontWidgets.insert(w, {wf, rule.font.resolve()}); QFont font = rule.font.resolve(wf); font.resolve(wf.resolve() | rule.font.resolve()); diff --git a/src/widgets/styles/qstylesheetstyle_p.h b/src/widgets/styles/qstylesheetstyle_p.h index 55dd2df329..2d302305bd 100644 --- a/src/widgets/styles/qstylesheetstyle_p.h +++ b/src/widgets/styles/qstylesheetstyle_p.h @@ -189,12 +189,31 @@ public: QHash<const QObject *, QRenderRules> renderRulesCache; QHash<const void *, QCss::StyleSheet> styleSheetCache; // parsed style sheets QSet<const QWidget *> autoFillDisabledWidgets; - // widgets whose palettes and fonts we have tampered. stored value pair is - // QPair<old widget value, resolve mask of stylesheet value> - QHash<const QWidget *, QPair<QPalette, uint> > customPaletteWidgets; - QHash<const QWidget *, QPair<QFont, uint> > customFontWidgets; + // widgets with whose palettes and fonts we have tampered: + template <typename T> + struct Tampered { + T oldWidgetValue; + uint resolveMask; + + // only call this function on an rvalue *this (it mangles oldWidgetValue) + T reverted(T current) +#ifdef Q_COMPILER_REF_QUALIFIERS + && +#endif + { + oldWidgetValue.resolve(oldWidgetValue.resolve() & resolveMask); + current.resolve(current.resolve() & ~resolveMask); + current.resolve(oldWidgetValue); + current.resolve(current.resolve() | oldWidgetValue.resolve()); + return current; + } + }; + QHash<const QWidget *, Tampered<QPalette>> customPaletteWidgets; + QHash<const QWidget *, Tampered<QFont>> customFontWidgets; }; - +template <typename T> +class QTypeInfo<QStyleSheetStyleCaches::Tampered<T>> + : QTypeInfoMerger<QStyleSheetStyleCaches::Tampered<T>, T> {}; QT_END_NAMESPACE #endif // QT_NO_STYLE_STYLESHEET diff --git a/src/widgets/styles/qwindowsvistastyle.cpp b/src/widgets/styles/qwindowsvistastyle.cpp index 1bdd8bf0c8..5a53627e95 100644 --- a/src/widgets/styles/qwindowsvistastyle.cpp +++ b/src/widgets/styles/qwindowsvistastyle.cpp @@ -775,6 +775,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt } case PE_Widget: { +#if QT_CONFIG(dialogbuttonbox) const QDialogButtonBox *buttonBox = 0; if (qobject_cast<const QMessageBox *> (widget)) @@ -801,6 +802,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt theme.partId = TDLG_SECONDARYPANEL; d->drawBackground(theme); } +#endif } break; default: @@ -2315,16 +2317,20 @@ void QWindowsVistaStyle::polish(QWidget *widget) } } else if (qobject_cast<QMessageBox *> (widget)) { widget->setAttribute(Qt::WA_StyledBackground); +#if QT_CONFIG(dialogbuttonbox) QDialogButtonBox *buttonBox = widget->findChild<QDialogButtonBox *>(QLatin1String("qt_msgbox_buttonbox")); if (buttonBox) buttonBox->setContentsMargins(0, 9, 0, 0); +#endif } #ifndef QT_NO_INPUTDIALOG else if (qobject_cast<QInputDialog *> (widget)) { widget->setAttribute(Qt::WA_StyledBackground); +#if QT_CONFIG(dialogbuttonbox) QDialogButtonBox *buttonBox = widget->findChild<QDialogButtonBox *>(QLatin1String("qt_inputdlg_buttonbox")); if (buttonBox) buttonBox->setContentsMargins(0, 9, 0, 0); +#endif } #endif // QT_NO_INPUTDIALOG else if (QTreeView *tree = qobject_cast<QTreeView *> (widget)) { @@ -2355,16 +2361,20 @@ void QWindowsVistaStyle::unpolish(QWidget *widget) widget->setAttribute(Qt::WA_Hover, false); else if (qobject_cast<QMessageBox *> (widget)) { widget->setAttribute(Qt::WA_StyledBackground, false); +#if QT_CONFIG(dialogbuttonbox) QDialogButtonBox *buttonBox = widget->findChild<QDialogButtonBox *>(QLatin1String("qt_msgbox_buttonbox")); if (buttonBox) buttonBox->setContentsMargins(0, 0, 0, 0); +#endif } #ifndef QT_NO_INPUTDIALOG else if (qobject_cast<QInputDialog *> (widget)) { widget->setAttribute(Qt::WA_StyledBackground, false); +#if QT_CONFIG(dialogbuttonbox) QDialogButtonBox *buttonBox = widget->findChild<QDialogButtonBox *>(QLatin1String("qt_inputdlg_buttonbox")); if (buttonBox) buttonBox->setContentsMargins(0, 0, 0, 0); +#endif } #endif // QT_NO_INPUTDIALOG else if (QTreeView *tree = qobject_cast<QTreeView *> (widget)) { diff --git a/src/widgets/styles/qwindowsvistastyle_p_p.h b/src/widgets/styles/qwindowsvistastyle_p_p.h index 18b6f9c3f7..ec7c2caad3 100644 --- a/src/widgets/styles/qwindowsvistastyle_p_p.h +++ b/src/widgets/styles/qwindowsvistastyle_p_p.h @@ -64,9 +64,10 @@ #include <qapplication.h> #include <qpixmapcache.h> #include <qstyleoption.h> +#if QT_CONFIG(pushbutton) #include <qpushbutton.h> +#endif #include <qradiobutton.h> -#include <qcheckbox.h> #include <qlineedit.h> #include <qgroupbox.h> #include <qtoolbutton.h> @@ -80,7 +81,9 @@ #include <qtreeview.h> #include <qtextedit.h> #include <qmessagebox.h> +#if QT_CONFIG(dialogbuttonbox) #include <qdialogbuttonbox.h> +#endif #include <qinputdialog.h> #include <qtableview.h> #include <qdatetime.h> diff --git a/src/widgets/styles/qwindowsxpstyle.cpp b/src/widgets/styles/qwindowsxpstyle.cpp index f50c143a4a..f3c6069f8a 100644 --- a/src/widgets/styles/qwindowsxpstyle.cpp +++ b/src/widgets/styles/qwindowsxpstyle.cpp @@ -65,7 +65,9 @@ #include <qspinbox.h> #include <qlistview.h> #include <qstackedwidget.h> +#if QT_CONFIG(pushbutton) #include <qpushbutton.h> +#endif #include <qtoolbar.h> #include <qlabel.h> #include <qvarlengtharray.h> diff --git a/src/widgets/util/qcompleter.cpp b/src/widgets/util/qcompleter.cpp index 3006f0c9ce..e8f23f08bc 100644 --- a/src/widgets/util/qcompleter.cpp +++ b/src/widgets/util/qcompleter.cpp @@ -1347,11 +1347,12 @@ bool QCompleter::eventFilter(QObject *o, QEvent *e) } // default implementation for keys not handled by the widget when popup is open +#if QT_CONFIG(shortcut) if (ke->matches(QKeySequence::Cancel)) { d->popup->hide(); return true; } - +#endif switch (key) { #ifdef QT_KEYPAD_NAVIGATION case Qt::Key_Select: diff --git a/src/widgets/util/qscroller.h b/src/widgets/util/qscroller.h index 561dcfaefc..ca8d059f50 100644 --- a/src/widgets/util/qscroller.h +++ b/src/widgets/util/qscroller.h @@ -45,6 +45,8 @@ #include <QtCore/QPointF> #include <QtWidgets/QScrollerProperties> +QT_REQUIRE_CONFIG(scroller); + QT_BEGIN_NAMESPACE diff --git a/src/widgets/util/qscrollerproperties.h b/src/widgets/util/qscrollerproperties.h index 4fdc9bd32f..2fc1a5dc18 100644 --- a/src/widgets/util/qscrollerproperties.h +++ b/src/widgets/util/qscrollerproperties.h @@ -45,6 +45,8 @@ #include <QtCore/QMetaType> #include <QtCore/QVariant> +QT_REQUIRE_CONFIG(scroller); + QT_BEGIN_NAMESPACE diff --git a/src/widgets/util/qsystemtrayicon.cpp b/src/widgets/util/qsystemtrayicon.cpp index 83c1764f38..1e0d2ab857 100644 --- a/src/widgets/util/qsystemtrayicon.cpp +++ b/src/widgets/util/qsystemtrayicon.cpp @@ -46,8 +46,13 @@ #include "qlist.h" #include "qevent.h" #include "qpoint.h" +#if QT_CONFIG(label) #include "qlabel.h" +#include "private/qlabel_p.h" +#endif +#if QT_CONFIG(pushbutton) #include "qpushbutton.h" +#endif #include "qpainterpath.h" #include "qpainter.h" #include "qstyle.h" @@ -55,7 +60,6 @@ #include "qapplication.h" #include "qdesktopwidget.h" #include "qbitmap.h" -#include "private/qlabel_p.h" QT_BEGIN_NAMESPACE @@ -481,6 +485,7 @@ QBalloonTip::QBalloonTip(const QIcon &icon, const QString &title, setAttribute(Qt::WA_DeleteOnClose); QObject::connect(ti, SIGNAL(destroyed()), this, SLOT(close())); +#if QT_CONFIG(label) QLabel *titleLabel = new QLabel; titleLabel->installEventFilter(this); titleLabel->setText(title); @@ -488,17 +493,21 @@ QBalloonTip::QBalloonTip(const QIcon &icon, const QString &title, f.setBold(true); titleLabel->setFont(f); titleLabel->setTextFormat(Qt::PlainText); // to maintain compat with windows +#endif const int iconSize = 18; const int closeButtonSize = 15; +#if QT_CONFIG(pushbutton) QPushButton *closeButton = new QPushButton; closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton)); closeButton->setIconSize(QSize(closeButtonSize, closeButtonSize)); closeButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); closeButton->setFixedSize(closeButtonSize, closeButtonSize); QObject::connect(closeButton, SIGNAL(clicked()), this, SLOT(close())); +#endif +#if QT_CONFIG(label) QLabel *msgLabel = new QLabel; msgLabel->installEventFilter(this); msgLabel->setText(message); @@ -521,8 +530,10 @@ QBalloonTip::QBalloonTip(const QIcon &icon, const QString &title, // to emulate the weird standard windows behavior. msgLabel->setFixedSize(limit, msgLabel->heightForWidth(limit)); } +#endif QGridLayout *layout = new QGridLayout; +#if QT_CONFIG(label) if (!icon.isNull()) { QLabel *iconLabel = new QLabel; iconLabel->setPixmap(icon.pixmap(iconSize, iconSize)); @@ -533,9 +544,15 @@ QBalloonTip::QBalloonTip(const QIcon &icon, const QString &title, } else { layout->addWidget(titleLabel, 0, 0, 1, 2); } +#endif +#if QT_CONFIG(pushbutton) layout->addWidget(closeButton, 0, 2); +#endif + +#if QT_CONFIG(label) layout->addWidget(msgLabel, 1, 0, 1, 3); +#endif layout->setSizeConstraint(QLayout::SetFixedSize); layout->setMargin(3); setLayout(layout); diff --git a/src/widgets/util/qsystemtrayicon_x11.cpp b/src/widgets/util/qsystemtrayicon_x11.cpp index ac6c14dc63..cbd5d9eb80 100644 --- a/src/widgets/util/qsystemtrayicon_x11.cpp +++ b/src/widgets/util/qsystemtrayicon_x11.cpp @@ -37,7 +37,10 @@ ** ****************************************************************************/ +#include "qtwidgetsglobal.h" +#if QT_CONFIG(label) #include "qlabel.h" +#endif #include "qpainter.h" #include "qpixmap.h" #include "qbitmap.h" diff --git a/src/widgets/util/util.pri b/src/widgets/util/util.pri index cb19c1fc95..b9b62d9bb0 100644 --- a/src/widgets/util/util.pri +++ b/src/widgets/util/util.pri @@ -6,11 +6,6 @@ HEADERS += \ util/qcompleter.h \ util/qcompleter_p.h \ util/qsystemtrayicon_p.h \ - util/qscroller.h \ - util/qscroller_p.h \ - util/qscrollerproperties.h \ - util/qscrollerproperties_p.h \ - util/qflickgesture_p.h \ util/qundogroup.h \ util/qundostack.h \ util/qundostack_p.h \ @@ -20,13 +15,24 @@ SOURCES += \ util/qsystemtrayicon.cpp \ util/qcolormap.cpp \ util/qcompleter.cpp \ - util/qscroller.cpp \ - util/qscrollerproperties.cpp \ - util/qflickgesture.cpp \ util/qundogroup.cpp \ util/qundostack.cpp \ util/qundoview.cpp +qtConfig(scroller) { + HEADERS += \ + util/qscroller.h \ + util/qscroller_p.h \ + util/qscrollerproperties.h \ + util/qscrollerproperties_p.h \ + util/qflickgesture_p.h + + SOURCES += \ + util/qscroller.cpp \ + util/qscrollerproperties.cpp \ + util/qflickgesture.cpp \ +} + win32:!winrt { SOURCES += util/qsystemtrayicon_win.cpp } else: qtConfig(xcb) { diff --git a/src/widgets/widgets/qabstractslider.h b/src/widgets/widgets/qabstractslider.h index 86d6830f10..8979685724 100644 --- a/src/widgets/widgets/qabstractslider.h +++ b/src/widgets/widgets/qabstractslider.h @@ -43,6 +43,8 @@ #include <QtWidgets/qtwidgetsglobal.h> #include <QtWidgets/qwidget.h> +QT_REQUIRE_CONFIG(abstractslider); + QT_BEGIN_NAMESPACE diff --git a/src/widgets/widgets/qabstractslider_p.h b/src/widgets/widgets/qabstractslider_p.h index 600616061a..419ce2ba07 100644 --- a/src/widgets/widgets/qabstractslider_p.h +++ b/src/widgets/widgets/qabstractslider_p.h @@ -57,6 +57,8 @@ #include "private/qwidget_p.h" #include "qstyle.h" +QT_REQUIRE_CONFIG(abstractslider); + QT_BEGIN_NAMESPACE class QAbstractSliderPrivate : public QWidgetPrivate diff --git a/src/widgets/widgets/qcalendarwidget.cpp b/src/widgets/widgets/qcalendarwidget.cpp index da4850a816..f81377a85c 100644 --- a/src/widgets/widgets/qcalendarwidget.cpp +++ b/src/widgets/widgets/qcalendarwidget.cpp @@ -770,8 +770,10 @@ bool QCalendarTextNavigator::eventFilter(QObject *o, QEvent *e) applyDate(); emit editingFinished(); removeDateLabel(); +#if QT_CONFIG(shortcut) } else if (ke->matches(QKeySequence::Cancel)) { removeDateLabel(); +#endif } else if (e->type() == QEvent::KeyPress) { createDateLabel(); m_dateValidator->handleKeyEvent(ke); @@ -3107,12 +3109,14 @@ void QCalendarWidget::resizeEvent(QResizeEvent * event) */ void QCalendarWidget::keyPressEvent(QKeyEvent * event) { +#if QT_CONFIG(shortcut) Q_D(QCalendarWidget); if (d->yearEdit->isVisible()&& event->matches(QKeySequence::Cancel)) { d->yearEdit->setValue(yearShown()); d->_q_yearEditingFinished(); return; } +#endif QWidget::keyPressEvent(event); } diff --git a/src/widgets/widgets/qcheckbox.h b/src/widgets/widgets/qcheckbox.h index 22f26b6667..8543c4c86f 100644 --- a/src/widgets/widgets/qcheckbox.h +++ b/src/widgets/widgets/qcheckbox.h @@ -43,6 +43,8 @@ #include <QtWidgets/qtwidgetsglobal.h> #include <QtWidgets/qabstractbutton.h> +QT_REQUIRE_CONFIG(checkbox); + QT_BEGIN_NAMESPACE diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 37d0e5c51e..272032d76f 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -677,10 +677,12 @@ bool QComboBoxPrivateContainer::eventFilter(QObject *o, QEvent *e) combo->hidePopup(); return true; default: +#if QT_CONFIG(shortcut) if (keyEvent->matches(QKeySequence::Cancel)) { combo->hidePopup(); return true; } +#endif break; } break; diff --git a/src/widgets/widgets/qcommandlinkbutton.h b/src/widgets/widgets/qcommandlinkbutton.h index 4f81651ce4..d8215a256e 100644 --- a/src/widgets/widgets/qcommandlinkbutton.h +++ b/src/widgets/widgets/qcommandlinkbutton.h @@ -43,6 +43,8 @@ #include <QtWidgets/qtwidgetsglobal.h> #include <QtWidgets/qpushbutton.h> +QT_REQUIRE_CONFIG(commandlinkbutton); + QT_BEGIN_NAMESPACE diff --git a/src/widgets/widgets/qdatetimeedit.cpp b/src/widgets/widgets/qdatetimeedit.cpp index c5eab55a53..cebfb9316a 100644 --- a/src/widgets/widgets/qdatetimeedit.cpp +++ b/src/widgets/widgets/qdatetimeedit.cpp @@ -2662,11 +2662,13 @@ void QCalendarPopup::mouseReleaseEvent(QMouseEvent*) bool QCalendarPopup::event(QEvent *event) { +#if QT_CONFIG(shortcut) if (event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); if (keyEvent->matches(QKeySequence::Cancel)) dateChanged = false; } +#endif return QWidget::event(event); } diff --git a/src/widgets/widgets/qdatetimeedit_p.h b/src/widgets/widgets/qdatetimeedit_p.h index 730aa0f0b2..5302d6d9a7 100644 --- a/src/widgets/widgets/qdatetimeedit_p.h +++ b/src/widgets/widgets/qdatetimeedit_p.h @@ -57,7 +57,6 @@ #include "QtWidgets/qspinbox.h" #include "QtWidgets/qtoolbutton.h" #include "QtWidgets/qmenu.h" -#include "QtWidgets/qlabel.h" #include "QtWidgets/qdatetimeedit.h" #include "private/qabstractspinbox_p.h" #include "private/qdatetimeparser_p.h" diff --git a/src/widgets/widgets/qdial.h b/src/widgets/widgets/qdial.h index 3629ebf8f6..472b14fcdb 100644 --- a/src/widgets/widgets/qdial.h +++ b/src/widgets/widgets/qdial.h @@ -42,13 +42,14 @@ #define QDIAL_H #include <QtWidgets/qtwidgetsglobal.h> + +#if QT_CONFIG(dial) + #include <QtWidgets/qabstractslider.h> QT_BEGIN_NAMESPACE -#ifndef QT_NO_DIAL - class QDialPrivate; class QStyleOptionSlider; @@ -98,8 +99,8 @@ private: Q_DISABLE_COPY(QDial) }; -#endif // QT_NO_DIAL - QT_END_NAMESPACE +#endif // QT_CONFIG(dial) + #endif // QDIAL_H diff --git a/src/widgets/widgets/qdialogbuttonbox.cpp b/src/widgets/widgets/qdialogbuttonbox.cpp index 61ef8e8c93..5a789c2d66 100644 --- a/src/widgets/widgets/qdialogbuttonbox.cpp +++ b/src/widgets/widgets/qdialogbuttonbox.cpp @@ -410,9 +410,9 @@ QPushButton *QDialogButtonBoxPrivate::createButton(QDialogButtonBox::StandardBut qWarning("QDialogButtonBox::createButton: Invalid ButtonRole, button not added"); else addButton(button, static_cast<QDialogButtonBox::ButtonRole>(role), doLayout); - +#if QT_CONFIG(shortcut) button->setShortcut(QGuiApplicationPrivate::platformTheme()->standardButtonShortcut(sbutton)); - +#endif return button; } diff --git a/src/widgets/widgets/qdialogbuttonbox.h b/src/widgets/widgets/qdialogbuttonbox.h index 00ec315555..af9e705234 100644 --- a/src/widgets/widgets/qdialogbuttonbox.h +++ b/src/widgets/widgets/qdialogbuttonbox.h @@ -43,6 +43,8 @@ #include <QtWidgets/qtwidgetsglobal.h> #include <QtWidgets/qwidget.h> +QT_REQUIRE_CONFIG(dialogbuttonbox); + QT_BEGIN_NAMESPACE diff --git a/src/widgets/widgets/qdockarealayout.cpp b/src/widgets/widgets/qdockarealayout.cpp index e730eddd57..2863d8c054 100644 --- a/src/widgets/widgets/qdockarealayout.cpp +++ b/src/widgets/widgets/qdockarealayout.cpp @@ -2578,12 +2578,16 @@ bool QDockAreaLayout::insertGap(const QList<int> &path, QLayoutItem *dockWidgetI QLayoutItem *QDockAreaLayout::plug(const QList<int> &path) { +#if QT_CONFIG(tabbar) Q_ASSERT(!path.isEmpty()); const int index = path.first(); Q_ASSERT(index >= 0 && index < QInternal::DockCount); QLayoutItem *item = docks[index].plug(path.mid(1)); docks[index].reparentWidgets(mainWindow); return item; +#else + return nullptr; +#endif } QLayoutItem *QDockAreaLayout::unplug(const QList<int> &path) diff --git a/src/widgets/widgets/qgroupbox.cpp b/src/widgets/widgets/qgroupbox.cpp index a9b32ae065..fda68879d1 100644 --- a/src/widgets/widgets/qgroupbox.cpp +++ b/src/widgets/widgets/qgroupbox.cpp @@ -44,7 +44,9 @@ #include "qdrawutil.h" #include "qevent.h" #include "qlayout.h" +#if QT_CONFIG(radiobutton) #include "qradiobutton.h" +#endif #include "qstyle.h" #include "qstyleoption.h" #include "qstylepainter.h" @@ -430,11 +432,13 @@ void QGroupBoxPrivate::_q_fixFocus(Qt::FocusReason reason) QWidget * w = q; while ((w = w->nextInFocusChain()) != q) { if (q->isAncestorOf(w) && (w->focusPolicy() & Qt::TabFocus) == Qt::TabFocus && w->isVisibleTo(q)) { +#if QT_CONFIG(radiobutton) if (!best && qobject_cast<QRadioButton*>(w) && ((QRadioButton*)w)->isChecked()) // we prefer a checked radio button or a widget that // already has focus, if there is one best = w; else +#endif if (!candidate) // but we'll accept anything that takes focus candidate = w; diff --git a/src/widgets/widgets/qlabel.h b/src/widgets/widgets/qlabel.h index 1f76937a63..3978e34d14 100644 --- a/src/widgets/widgets/qlabel.h +++ b/src/widgets/widgets/qlabel.h @@ -43,6 +43,8 @@ #include <QtWidgets/qtwidgetsglobal.h> #include <QtWidgets/qframe.h> +QT_REQUIRE_CONFIG(label); + QT_BEGIN_NAMESPACE diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp index 419968db75..5926476470 100644 --- a/src/widgets/widgets/qlineedit.cpp +++ b/src/widgets/widgets/qlineedit.cpp @@ -440,6 +440,7 @@ bool QLineEdit::hasFrame() const \since 5.2 */ +#if QT_CONFIG(action) /*! \overload @@ -469,7 +470,7 @@ QAction *QLineEdit::addAction(const QIcon &icon, ActionPosition position) addAction(result, position); return result; } - +#endif // QT_CONFIG(action) /*! \property QLineEdit::clearButtonEnabled \brief Whether the line edit displays a clear button when it is not empty. @@ -486,6 +487,7 @@ static const char clearButtonActionNameC[] = "_q_qlineeditclearaction"; void QLineEdit::setClearButtonEnabled(bool enable) { +#if QT_CONFIG(action) Q_D(QLineEdit); if (enable == isClearButtonEnabled()) return; @@ -500,11 +502,16 @@ void QLineEdit::setClearButtonEnabled(bool enable) d->removeAction(clearAction); delete clearAction; } +#endif // QT_CONFIG(action) } bool QLineEdit::isClearButtonEnabled() const { +#if QT_CONFIG(action) return findChild<QAction *>(QLatin1String(clearButtonActionNameC)); +#else + return false; +#endif } void QLineEdit::setFrame(bool enable) @@ -1435,8 +1442,10 @@ bool QLineEdit::event(QEvent * e) || style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this)) d->setCursorVisible(true); } +#if QT_CONFIG(action) } else if (e->type() == QEvent::ActionRemoved) { d->removeAction(static_cast<QActionEvent *>(e)->action()); +#endif } else if (e->type() == QEvent::Resize) { d->positionSideWidgets(); } diff --git a/src/widgets/widgets/qlineedit.h b/src/widgets/widgets/qlineedit.h index 96dd64164f..4d32b11f06 100644 --- a/src/widgets/widgets/qlineedit.h +++ b/src/widgets/widgets/qlineedit.h @@ -174,9 +174,11 @@ public: void getTextMargins(int *left, int *top, int *right, int *bottom) const; QMargins textMargins() const; +#if QT_CONFIG(action) using QWidget::addAction; void addAction(QAction *action, ActionPosition position); QAction *addAction(const QIcon &icon, ActionPosition position); +#endif public Q_SLOTS: void setText(const QString &); diff --git a/src/widgets/widgets/qlineedit_p.cpp b/src/widgets/widgets/qlineedit_p.cpp index 13f18f66d2..1d81d1fcb5 100644 --- a/src/widgets/widgets/qlineedit_p.cpp +++ b/src/widgets/widgets/qlineedit_p.cpp @@ -448,12 +448,14 @@ QIcon QLineEditPrivate::clearButtonIcon() const void QLineEditPrivate::setClearButtonEnabled(bool enabled) { +#if QT_CONFIG(action) for (const SideWidgetEntry &e : trailingSideWidgets) { if (e.flags & SideWidgetClearButton) { e.action->setEnabled(enabled); break; } } +#endif } void QLineEditPrivate::positionSideWidgets() @@ -467,33 +469,37 @@ void QLineEditPrivate::positionSideWidgets() QSize(p.widgetWidth, p.widgetHeight)); for (const SideWidgetEntry &e : leftSideWidgetList()) { e.widget->setGeometry(widgetGeometry); +#if QT_CONFIG(action) if (e.action->isVisible()) widgetGeometry.moveLeft(widgetGeometry.left() + delta); +#endif } widgetGeometry.moveLeft(contentRect.width() - p.widgetWidth - p.margin); for (const SideWidgetEntry &e : rightSideWidgetList()) { e.widget->setGeometry(widgetGeometry); +#if QT_CONFIG(action) if (e.action->isVisible()) widgetGeometry.moveLeft(widgetGeometry.left() - delta); +#endif } } } -QLineEditPrivate::PositionIndexPair QLineEditPrivate::findSideWidget(const QAction *a) const +QLineEditPrivate::SideWidgetLocation QLineEditPrivate::findSideWidget(const QAction *a) const { int i = 0; for (const auto &e : leadingSideWidgets) { if (a == e.action) - return PositionIndexPair(QLineEdit::LeadingPosition, i); + return {QLineEdit::LeadingPosition, i}; ++i; } i = 0; for (const auto &e : trailingSideWidgets) { if (a == e.action) - return PositionIndexPair(QLineEdit::TrailingPosition, i); + return {QLineEdit::TrailingPosition, i}; ++i; } - return PositionIndexPair(QLineEdit::LeadingPosition, -1); + return {QLineEdit::LeadingPosition, -1}; } QWidget *QLineEditPrivate::addAction(QAction *newAction, QAction *before, QLineEdit::ActionPosition position, int flags) @@ -508,10 +514,12 @@ QWidget *QLineEditPrivate::addAction(QAction *newAction, QAction *before, QLineE QWidget *w = 0; // Store flags about QWidgetAction here since removeAction() may be called from ~QAction, // in which a qobject_cast<> no longer works. +#if QT_CONFIG(action) if (QWidgetAction *widgetAction = qobject_cast<QWidgetAction *>(newAction)) { if ((w = widgetAction->requestWidget(q))) flags |= SideWidgetCreatedByWidgetAction; } +#endif if (!w) { #if QT_CONFIG(toolbutton) QLineEditIconButton *toolButton = new QLineEditIconButton(q); @@ -526,11 +534,10 @@ QWidget *QLineEditPrivate::addAction(QAction *newAction, QAction *before, QLineE #endif } // If there is a 'before' action, it takes preference - PositionIndexPair positionIndex = before ? findSideWidget(before) : PositionIndexPair(position, -1); - SideWidgetEntryList &list = positionIndex.first == QLineEdit::TrailingPosition ? trailingSideWidgets : leadingSideWidgets; - if (positionIndex.second < 0) - positionIndex.second = int(list.size()); - list.insert(list.begin() + positionIndex.second, SideWidgetEntry(w, newAction, flags)); + const auto location = before ? findSideWidget(before) : SideWidgetLocation{position, -1}; + SideWidgetEntryList &list = location.position == QLineEdit::TrailingPosition ? trailingSideWidgets : leadingSideWidgets; + list.insert(location.isValid() ? list.begin() + location.index : list.end(), + SideWidgetEntry(w, newAction, flags)); positionSideWidgets(); w->show(); return w; @@ -538,13 +545,14 @@ QWidget *QLineEditPrivate::addAction(QAction *newAction, QAction *before, QLineE void QLineEditPrivate::removeAction(QAction *action) { +#if QT_CONFIG(action) Q_Q(QLineEdit); - const PositionIndexPair positionIndex = findSideWidget(action); - if (positionIndex.second == -1) + const auto location = findSideWidget(action); + if (!location.isValid()) return; - SideWidgetEntryList &list = positionIndex.first == QLineEdit::TrailingPosition ? trailingSideWidgets : leadingSideWidgets; - SideWidgetEntry entry = list[positionIndex.second]; - list.erase(list.begin() + positionIndex.second); + SideWidgetEntryList &list = location.position == QLineEdit::TrailingPosition ? trailingSideWidgets : leadingSideWidgets; + SideWidgetEntry entry = list[location.index]; + list.erase(list.begin() + location.index); if (entry.flags & SideWidgetCreatedByWidgetAction) static_cast<QWidgetAction *>(entry.action)->releaseWidget(entry.widget); else @@ -553,6 +561,7 @@ void QLineEditPrivate::removeAction(QAction *action) if (!hasSideWidgets()) // Last widget, remove connection QObject::disconnect(q, SIGNAL(textChanged(QString)), q, SLOT(_q_textChanged(QString))); q->update(); +#endif // QT_CONFIG(action) } static bool isSideWidgetVisible(const QLineEditPrivate::SideWidgetEntry &e) diff --git a/src/widgets/widgets/qlineedit_p.h b/src/widgets/widgets/qlineedit_p.h index a903c003e6..2d695f8411 100644 --- a/src/widgets/widgets/qlineedit_p.h +++ b/src/widgets/widgets/qlineedit_p.h @@ -235,15 +235,22 @@ public: int effectiveRightTextMargin() const; private: - typedef QPair<QLineEdit::ActionPosition, int> PositionIndexPair; + struct SideWidgetLocation { + QLineEdit::ActionPosition position; + int index; - PositionIndexPair findSideWidget(const QAction *a) const; + bool isValid() const { return index >= 0; } + }; + friend class QTypeInfo<SideWidgetLocation>; + + SideWidgetLocation findSideWidget(const QAction *a) const; SideWidgetEntryList leadingSideWidgets; SideWidgetEntryList trailingSideWidgets; int lastTextSize; }; Q_DECLARE_TYPEINFO(QLineEditPrivate::SideWidgetEntry, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(QLineEditPrivate::SideWidgetLocation, Q_PRIMITIVE_TYPE); #endif // QT_NO_LINEEDIT diff --git a/src/widgets/widgets/qpushbutton.cpp b/src/widgets/widgets/qpushbutton.cpp index cae1f9d169..1beea7edc5 100644 --- a/src/widgets/widgets/qpushbutton.cpp +++ b/src/widgets/widgets/qpushbutton.cpp @@ -55,7 +55,9 @@ #include "qtoolbar.h" #include "qdebug.h" #include "qlayoutitem.h" +#if QT_CONFIG(dialogbuttonbox) #include "qdialogbuttonbox.h" +#endif #ifndef QT_NO_ACCESSIBILITY #include "qaccessible.h" @@ -396,8 +398,7 @@ QSize QPushButton::sizeHint() const initStyleOption(&opt); // calculate contents size... -#ifndef QT_NO_ICON - +#if !defined(QT_NO_ICON) && QT_CONFIG(dialogbuttonbox) bool showButtonBoxIcons = qobject_cast<QDialogButtonBox*>(parentWidget()) && style()->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons); diff --git a/src/widgets/widgets/qpushbutton.h b/src/widgets/widgets/qpushbutton.h index b0d1ccacdb..ea9baa8ccb 100644 --- a/src/widgets/widgets/qpushbutton.h +++ b/src/widgets/widgets/qpushbutton.h @@ -43,6 +43,8 @@ #include <QtWidgets/qtwidgetsglobal.h> #include <QtWidgets/qabstractbutton.h> +QT_REQUIRE_CONFIG(pushbutton); + QT_BEGIN_NAMESPACE diff --git a/src/widgets/widgets/qpushbutton_p.h b/src/widgets/widgets/qpushbutton_p.h index ee41c345c8..198091503a 100644 --- a/src/widgets/widgets/qpushbutton_p.h +++ b/src/widgets/widgets/qpushbutton_p.h @@ -43,6 +43,8 @@ #include <QtWidgets/private/qtwidgetsglobal_p.h> #include "private/qabstractbutton_p.h" +QT_REQUIRE_CONFIG(pushbutton); + // // W A R N I N G // ------------- diff --git a/src/widgets/widgets/qradiobutton.h b/src/widgets/widgets/qradiobutton.h index 2dcb0d0fdf..137ae01380 100644 --- a/src/widgets/widgets/qradiobutton.h +++ b/src/widgets/widgets/qradiobutton.h @@ -43,6 +43,8 @@ #include <QtWidgets/qtwidgetsglobal.h> #include <QtWidgets/qabstractbutton.h> +QT_REQUIRE_CONFIG(radiobutton); + QT_BEGIN_NAMESPACE diff --git a/src/widgets/widgets/qscrollbar.h b/src/widgets/widgets/qscrollbar.h index 2b8a110c99..b99ad219eb 100644 --- a/src/widgets/widgets/qscrollbar.h +++ b/src/widgets/widgets/qscrollbar.h @@ -42,12 +42,12 @@ #include <QtWidgets/qtwidgetsglobal.h> #include <QtWidgets/qwidget.h> -#include <QtWidgets/qabstractslider.h> -QT_BEGIN_NAMESPACE +#if QT_CONFIG(scrollbar) +#include <QtWidgets/qabstractslider.h> -#ifndef QT_NO_SCROLLBAR +QT_BEGIN_NAMESPACE class QScrollBarPrivate; class QStyleOptionSlider; @@ -94,8 +94,8 @@ private: #endif }; -#endif // QT_NO_SCROLLBAR - QT_END_NAMESPACE +#endif // QT_CONFIG(scrollbar) + #endif // QSCROLLBAR_H diff --git a/src/widgets/widgets/qslider.h b/src/widgets/widgets/qslider.h index 33b90ece06..001863c18d 100644 --- a/src/widgets/widgets/qslider.h +++ b/src/widgets/widgets/qslider.h @@ -41,13 +41,14 @@ #define QSLIDER_H #include <QtWidgets/qtwidgetsglobal.h> + +#if QT_CONFIG(slider) + #include <QtWidgets/qabstractslider.h> QT_BEGIN_NAMESPACE -#ifndef QT_NO_SLIDER - class QSliderPrivate; class QStyleOptionSlider; class Q_WIDGETS_EXPORT QSlider : public QAbstractSlider @@ -99,8 +100,8 @@ private: Q_DECLARE_PRIVATE(QSlider) }; -#endif // QT_NO_SLIDER - QT_END_NAMESPACE +#endif // QT_CONFIG(slider) + #endif // QSLIDER_H diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp index 9bf062b407..eeece1a42a 100644 --- a/src/widgets/widgets/qtabbar.cpp +++ b/src/widgets/widgets/qtabbar.cpp @@ -519,12 +519,14 @@ void QTabBarPrivate::layoutTabs() maxExtent = maxWidth; } + if (!expanding) { + // Mirror our front item. + tabChain[tabChainIndex].init(); + tabChain[tabChainIndex].expansive = (tabAlignment != Qt::AlignRight) + && (tabAlignment != Qt::AlignJustify); + tabChain[tabChainIndex].empty = true; + } Q_ASSERT(tabChainIndex == tabChain.count() - 1); // add an assert just to make sure. - // Mirror our front item. - tabChain[tabChainIndex].init(); - tabChain[tabChainIndex].expansive = (tabAlignment != Qt::AlignRight) - && (tabAlignment != Qt::AlignJustify); - tabChain[tabChainIndex].empty = true; // Do the calculation qGeomCalc(tabChain, 0, tabChain.count(), 0, qMax(available, last), 0); @@ -664,6 +666,15 @@ QRect QTabBarPrivate::normalizedScrollRect(int index) } } +int QTabBarPrivate::hoveredTabIndex() const +{ + if (dragInProgress) + return currentIndex; + if (hoverIndex >= 0) + return hoverIndex; + return -1; +} + void QTabBarPrivate::makeVisible(int index) { Q_Q(QTabBar); @@ -1053,6 +1064,17 @@ void QTabBar::removeTab(int index) } d->refresh(); d->autoHideTabs(); + if (!d->hoverRect.isEmpty()) { + for (int i = 0; i < d->tabList.count(); ++i) { + const QRect area = tabRect(i); + if (area.contains(mapFromGlobal(QCursor::pos()))) { + d->hoverIndex = i; + d->hoverRect = area; + break; + } + } + update(d->hoverRect); + } tabRemoved(index); } } @@ -1577,20 +1599,28 @@ bool QTabBar::event(QEvent *event) QHoverEvent *he = static_cast<QHoverEvent *>(event); if (!d->hoverRect.contains(he->pos())) { QRect oldHoverRect = d->hoverRect; + bool cursorOverTabs = false; for (int i = 0; i < d->tabList.count(); ++i) { QRect area = tabRect(i); if (area.contains(he->pos())) { + d->hoverIndex = i; d->hoverRect = area; + cursorOverTabs = true; break; } } + if (!cursorOverTabs) { + d->hoverIndex = -1; + d->hoverRect = QRect(); + } if (he->oldPos() != QPoint(-1, -1)) update(oldHoverRect); update(d->hoverRect); } return true; - } else if (event->type() == QEvent::HoverLeave ) { + } else if (event->type() == QEvent::HoverLeave) { QRect oldHoverRect = d->hoverRect; + d->hoverIndex = -1; d->hoverRect = QRect(); update(oldHoverRect); return true; @@ -2435,7 +2465,7 @@ void QTabBar::setMovable(bool movable) This property is used as a hint for styles to draw the tabs in a different way then they would normally look in a tab widget. On \macos this will - look similar to the tabs in Safari or Leopard's Terminal.app. + look similar to the tabs in Safari or Sierra's Terminal.app. \sa QTabWidget::documentMode */ diff --git a/src/widgets/widgets/qtabbar_p.h b/src/widgets/widgets/qtabbar_p.h index e8d5503fdf..7c653a95e9 100644 --- a/src/widgets/widgets/qtabbar_p.h +++ b/src/widgets/widgets/qtabbar_p.h @@ -87,7 +87,7 @@ class QTabBarPrivate : public QWidgetPrivate public: QTabBarPrivate() :currentIndex(-1), pressedIndex(-1), shape(QTabBar::RoundedNorth), layoutDirty(false), - drawBase(true), scrollOffset(0), elideModeSetByUser(false), useScrollButtonsSetByUser(false), expanding(true), closeButtonOnTabs(false), + drawBase(true), scrollOffset(0), hoverIndex(-1), elideModeSetByUser(false), useScrollButtonsSetByUser(false), expanding(true), closeButtonOnTabs(false), selectionBehaviorOnRemove(QTabBar::SelectRightTab), paintWithOffsets(true), movable(false), dragInProgress(false), documentMode(false), autoHide(false), changeCurrentOnDrag(false), switchTabCurrentIndex(-1), switchTabTimerId(0), movingTab(0) @@ -192,6 +192,7 @@ public: void moveTab(int index, int offset); void moveTabFinished(int index); QRect hoverRect; + int hoverIndex; void refresh(); void layoutTabs(); @@ -202,6 +203,7 @@ public: void setupMovableTab(); void autoHideTabs(); QRect normalizedScrollRect(int index = -1); + int hoveredTabIndex() const; void initBasicStyleOption(QStyleOptionTab *option, int tabIndex) const; diff --git a/src/widgets/widgets/qtabwidget.cpp b/src/widgets/widgets/qtabwidget.cpp index 1394c6b44c..be870133ee 100644 --- a/src/widgets/widgets/qtabwidget.cpp +++ b/src/widgets/widgets/qtabwidget.cpp @@ -209,7 +209,6 @@ public: bool dirty; QTabWidget::TabPosition pos; QTabWidget::TabShape shape; - int alignment; QWidget *leftCornerWidget; QWidget *rightCornerWidget; }; diff --git a/src/widgets/widgets/widgets.pri b/src/widgets/widgets/widgets.pri index abba3e0472..f67640e40f 100644 --- a/src/widgets/widgets/widgets.pri +++ b/src/widgets/widgets/widgets.pri @@ -5,19 +5,14 @@ HEADERS += \ widgets/qbuttongroup_p.h \ widgets/qabstractbutton.h \ widgets/qabstractbutton_p.h \ - widgets/qabstractslider.h \ - widgets/qabstractslider_p.h \ widgets/qabstractspinbox.h \ widgets/qabstractspinbox_p.h \ widgets/qcalendarwidget.h \ - widgets/qcheckbox.h \ widgets/qcombobox.h \ widgets/qcombobox_p.h \ - widgets/qcommandlinkbutton.h \ widgets/qdatetimeedit.h \ widgets/qdatetimeedit_p.h \ widgets/qdial.h \ - widgets/qdialogbuttonbox.h \ widgets/qdockwidget.h \ widgets/qdockwidget_p.h \ widgets/qdockarealayout_p.h \ @@ -27,8 +22,6 @@ HEADERS += \ widgets/qgroupbox.h \ widgets/qkeysequenceedit.h \ widgets/qkeysequenceedit_p.h \ - widgets/qlabel.h \ - widgets/qlabel_p.h \ widgets/qlcdnumber.h \ widgets/qlineedit.h \ widgets/qlineedit_p.h \ @@ -43,9 +36,6 @@ HEADERS += \ widgets/qmenubar.h \ widgets/qmenubar_p.h \ widgets/qprogressbar.h \ - widgets/qpushbutton.h \ - widgets/qpushbutton_p.h \ - widgets/qradiobutton.h \ widgets/qrubberband.h \ widgets/qscrollbar.h \ widgets/qscrollbar_p.h \ @@ -87,15 +77,11 @@ HEADERS += \ SOURCES += \ widgets/qbuttongroup.cpp \ widgets/qabstractbutton.cpp \ - widgets/qabstractslider.cpp \ widgets/qabstractspinbox.cpp \ widgets/qcalendarwidget.cpp \ - widgets/qcheckbox.cpp \ widgets/qcombobox.cpp \ - widgets/qcommandlinkbutton.cpp \ widgets/qdatetimeedit.cpp \ widgets/qdial.cpp \ - widgets/qdialogbuttonbox.cpp \ widgets/qdockwidget.cpp \ widgets/qdockarealayout.cpp \ widgets/qeffects.cpp \ @@ -103,7 +89,6 @@ SOURCES += \ widgets/qframe.cpp \ widgets/qgroupbox.cpp \ widgets/qkeysequenceedit.cpp \ - widgets/qlabel.cpp \ widgets/qlcdnumber.cpp \ widgets/qlineedit_p.cpp \ widgets/qlineedit.cpp \ @@ -114,8 +99,6 @@ SOURCES += \ widgets/qmenu.cpp \ widgets/qmenubar.cpp \ widgets/qprogressbar.cpp \ - widgets/qpushbutton.cpp \ - widgets/qradiobutton.cpp \ widgets/qrubberband.cpp \ widgets/qscrollbar.cpp \ widgets/qsizegrip.cpp \ @@ -145,6 +128,66 @@ SOURCES += \ widgets/qtoolbararealayout.cpp \ widgets/qplaintextedit.cpp +qtConfig(abstractslider) { + HEADERS += \ + widgets/qabstractslider.h \ + widgets/qabstractslider_p.h + + SOURCES += \ + widgets/qabstractslider.cpp +} + +qtConfig(checkbox) { + HEADERS += \ + widgets/qcheckbox.h + + SOURCES += \ + widgets/qcheckbox.cpp +} + +qtConfig(commandlinkbutton) { + HEADERS += \ + widgets/qcommandlinkbutton.h + + SOURCES += \ + widgets/qcommandlinkbutton.cpp +} + +qtConfig(label) { + HEADERS += \ + widgets/qlabel.h \ + widgets/qlabel_p.h + + SOURCES += \ + widgets/qlabel.cpp +} + + +qtConfig(pushbutton) { + HEADERS += \ + widgets/qpushbutton.h \ + widgets/qpushbutton_p.h + + SOURCES += \ + widgets/qpushbutton.cpp +} + +qtConfig(radiobutton) { + HEADERS += \ + widgets/qradiobutton.h + + SOURCES += \ + widgets/qradiobutton.cpp +} + +qtConfig(dialogbuttonbox) { + HEADERS += \ + widgets/qdialogbuttonbox.h + + SOURCES += \ + widgets/qdialogbuttonbox.cpp +} + macx { HEADERS += \ widgets/qmacnativewidget_mac.h \ |