diff options
Diffstat (limited to 'src/widgets/widgets')
114 files changed, 1982 insertions, 1736 deletions
diff --git a/src/widgets/widgets/qabstractbutton.h b/src/widgets/widgets/qabstractbutton.h index 01dbf4e92d..e8dee142f2 100644 --- a/src/widgets/widgets/qabstractbutton.h +++ b/src/widgets/widgets/qabstractbutton.h @@ -72,7 +72,7 @@ class Q_WIDGETS_EXPORT QAbstractButton : public QWidget Q_PROPERTY(bool down READ isDown WRITE setDown DESIGNABLE false) public: - explicit QAbstractButton(QWidget *parent = Q_NULLPTR); + explicit QAbstractButton(QWidget *parent = nullptr); ~QAbstractButton(); void setText(const QString &text); @@ -126,25 +126,25 @@ Q_SIGNALS: void toggled(bool checked); protected: - void paintEvent(QPaintEvent *e) Q_DECL_OVERRIDE = 0; + void paintEvent(QPaintEvent *e) override = 0; virtual bool hitButton(const QPoint &pos) const; virtual void checkStateSet(); virtual void nextCheckState(); - bool event(QEvent *e) Q_DECL_OVERRIDE; - void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE; - void keyReleaseEvent(QKeyEvent *e) Q_DECL_OVERRIDE; - void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE; - void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE; - void focusInEvent(QFocusEvent *e) Q_DECL_OVERRIDE; - void focusOutEvent(QFocusEvent *e) Q_DECL_OVERRIDE; - void changeEvent(QEvent *e) Q_DECL_OVERRIDE; - void timerEvent(QTimerEvent *e) Q_DECL_OVERRIDE; + bool event(QEvent *e) override; + void keyPressEvent(QKeyEvent *e) override; + void keyReleaseEvent(QKeyEvent *e) override; + void mousePressEvent(QMouseEvent *e) override; + void mouseReleaseEvent(QMouseEvent *e) override; + void mouseMoveEvent(QMouseEvent *e) override; + void focusInEvent(QFocusEvent *e) override; + void focusOutEvent(QFocusEvent *e) override; + void changeEvent(QEvent *e) override; + void timerEvent(QTimerEvent *e) override; protected: - QAbstractButton(QAbstractButtonPrivate &dd, QWidget* parent = Q_NULLPTR); + QAbstractButton(QAbstractButtonPrivate &dd, QWidget* parent = nullptr); private: Q_DECLARE_PRIVATE(QAbstractButton) diff --git a/src/widgets/widgets/qabstractscrollarea.cpp b/src/widgets/widgets/qabstractscrollarea.cpp index c6d66bafd4..917cddce6f 100644 --- a/src/widgets/widgets/qabstractscrollarea.cpp +++ b/src/widgets/widgets/qabstractscrollarea.cpp @@ -1163,7 +1163,7 @@ bool QAbstractScrollArea::event(QEvent *e) case QEvent::ApplicationLayoutDirectionChange: case QEvent::LayoutRequest: d->layoutChildren(); - // fall through + Q_FALLTHROUGH(); default: return QFrame::event(e); } diff --git a/src/widgets/widgets/qabstractscrollarea.h b/src/widgets/widgets/qabstractscrollarea.h index cee8481e6f..8a17036fb2 100644 --- a/src/widgets/widgets/qabstractscrollarea.h +++ b/src/widgets/widgets/qabstractscrollarea.h @@ -61,7 +61,7 @@ class Q_WIDGETS_EXPORT QAbstractScrollArea : public QFrame Q_PROPERTY(SizeAdjustPolicy sizeAdjustPolicy READ sizeAdjustPolicy WRITE setSizeAdjustPolicy) public: - explicit QAbstractScrollArea(QWidget *parent = Q_NULLPTR); + explicit QAbstractScrollArea(QWidget *parent = nullptr); ~QAbstractScrollArea(); enum SizeAdjustPolicy { @@ -91,9 +91,9 @@ public: void setViewport(QWidget *widget); QSize maximumViewportSize() const; - QSize minimumSizeHint() const Q_DECL_OVERRIDE; + QSize minimumSizeHint() const override; - QSize sizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; virtual void setupViewport(QWidget *viewport); @@ -101,35 +101,35 @@ public: void setSizeAdjustPolicy(SizeAdjustPolicy policy); protected: - QAbstractScrollArea(QAbstractScrollAreaPrivate &dd, QWidget *parent = Q_NULLPTR); + QAbstractScrollArea(QAbstractScrollAreaPrivate &dd, QWidget *parent = nullptr); void setViewportMargins(int left, int top, int right, int bottom); void setViewportMargins(const QMargins &margins); QMargins viewportMargins() const; - bool eventFilter(QObject *, QEvent *) Q_DECL_OVERRIDE; - bool event(QEvent *) Q_DECL_OVERRIDE; + bool eventFilter(QObject *, QEvent *) override; + bool event(QEvent *) override; virtual bool viewportEvent(QEvent *); - void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; - void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE; - void mouseDoubleClickEvent(QMouseEvent *) Q_DECL_OVERRIDE; - void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE; + void resizeEvent(QResizeEvent *) override; + void paintEvent(QPaintEvent *) override; + void mousePressEvent(QMouseEvent *) override; + void mouseReleaseEvent(QMouseEvent *) override; + void mouseDoubleClickEvent(QMouseEvent *) override; + void mouseMoveEvent(QMouseEvent *) override; #if QT_CONFIG(wheelevent) - void wheelEvent(QWheelEvent *) Q_DECL_OVERRIDE; + void wheelEvent(QWheelEvent *) override; #endif #ifndef QT_NO_CONTEXTMENU - void contextMenuEvent(QContextMenuEvent *) Q_DECL_OVERRIDE; + void contextMenuEvent(QContextMenuEvent *) override; #endif #ifndef QT_NO_DRAGANDDROP - void dragEnterEvent(QDragEnterEvent *) Q_DECL_OVERRIDE; - void dragMoveEvent(QDragMoveEvent *) Q_DECL_OVERRIDE; - void dragLeaveEvent(QDragLeaveEvent *) Q_DECL_OVERRIDE; - void dropEvent(QDropEvent *) Q_DECL_OVERRIDE; + void dragEnterEvent(QDragEnterEvent *) override; + void dragMoveEvent(QDragMoveEvent *) override; + void dragLeaveEvent(QDragLeaveEvent *) override; + void dropEvent(QDropEvent *) override; #endif - void keyPressEvent(QKeyEvent *) Q_DECL_OVERRIDE; + void keyPressEvent(QKeyEvent *) override; virtual void scrollContentsBy(int dx, int dy); diff --git a/src/widgets/widgets/qabstractscrollarea_p.h b/src/widgets/widgets/qabstractscrollarea_p.h index 49f97bcb61..732a2ab40d 100644 --- a/src/widgets/widgets/qabstractscrollarea_p.h +++ b/src/widgets/widgets/qabstractscrollarea_p.h @@ -125,7 +125,7 @@ class QAbstractScrollAreaFilter : public QObject public: QAbstractScrollAreaFilter(QAbstractScrollAreaPrivate *p) : d(p) { setObjectName(QLatin1String("qt_abstractscrollarea_filter")); } - bool eventFilter(QObject *o, QEvent *e) Q_DECL_OVERRIDE + bool eventFilter(QObject *o, QEvent *e) override { return (o == d->viewport ? d->viewportEvent(e) : false); } private: QAbstractScrollAreaPrivate *d; diff --git a/src/widgets/widgets/qabstractslider.h b/src/widgets/widgets/qabstractslider.h index d26d6a879c..7791d30d10 100644 --- a/src/widgets/widgets/qabstractslider.h +++ b/src/widgets/widgets/qabstractslider.h @@ -67,7 +67,7 @@ class Q_WIDGETS_EXPORT QAbstractSlider : public QWidget Q_PROPERTY(bool sliderDown READ isSliderDown WRITE setSliderDown DESIGNABLE false) public: - explicit QAbstractSlider(QWidget *parent = Q_NULLPTR); + explicit QAbstractSlider(QWidget *parent = nullptr); ~QAbstractSlider(); Qt::Orientation orientation() const; @@ -131,7 +131,7 @@ Q_SIGNALS: void actionTriggered(int action); protected: - bool event(QEvent *e) Q_DECL_OVERRIDE; + bool event(QEvent *e) override; void setRepeatAction(SliderAction action, int thresholdTime = 500, int repeatTime = 50); SliderAction repeatAction() const; @@ -144,16 +144,16 @@ protected: }; virtual void sliderChange(SliderChange change); - void keyPressEvent(QKeyEvent *ev) Q_DECL_OVERRIDE; - void timerEvent(QTimerEvent *) Q_DECL_OVERRIDE; + void keyPressEvent(QKeyEvent *ev) override; + void timerEvent(QTimerEvent *) override; #if QT_CONFIG(wheelevent) - void wheelEvent(QWheelEvent *e) Q_DECL_OVERRIDE; + void wheelEvent(QWheelEvent *e) override; #endif - void changeEvent(QEvent *e) Q_DECL_OVERRIDE; + void changeEvent(QEvent *e) override; protected: - QAbstractSlider(QAbstractSliderPrivate &dd, QWidget *parent = Q_NULLPTR); + QAbstractSlider(QAbstractSliderPrivate &dd, QWidget *parent = nullptr); private: Q_DISABLE_COPY(QAbstractSlider) diff --git a/src/widgets/widgets/qabstractspinbox.cpp b/src/widgets/widgets/qabstractspinbox.cpp index 3427579d1f..7ca47e9f0f 100644 --- a/src/widgets/widgets/qabstractspinbox.cpp +++ b/src/widgets/widgets/qabstractspinbox.cpp @@ -678,15 +678,20 @@ void QAbstractSpinBox::setLineEdit(QLineEdit *lineEdit) Q_ASSERT(lineEdit); return; } + + if (lineEdit == d->edit) + return; + delete d->edit; d->edit = lineEdit; + setProperty("_q_spinbox_lineedit", QVariant::fromValue<QWidget *>(d->edit)); if (!d->edit->validator()) d->edit->setValidator(d->validator); if (d->edit->parent() != this) d->edit->setParent(this); - d->edit->setFrame(false); + d->edit->setFrame(!style()->styleHint(QStyle::SH_SpinBox_ButtonsInsideFrame, nullptr, this)); d->edit->setFocusProxy(this); d->edit->setAcceptDrops(false); @@ -818,6 +823,8 @@ void QAbstractSpinBox::changeEvent(QEvent *event) d->spinClickTimerInterval = style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatRate, 0, this); d->spinClickThresholdTimerInterval = style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatThreshold, 0, this); + if (d->edit) + d->edit->setFrame(!style()->styleHint(QStyle::SH_SpinBox_ButtonsInsideFrame, nullptr, this)); d->reset(); d->updateEditFieldGeometry(); break; @@ -870,15 +877,15 @@ QSize QAbstractSpinBox::sizeHint() const s = d->textFromValue(d->minimum); s.truncate(18); s += fixedContent; - w = qMax(w, fm.width(s)); + w = qMax(w, fm.horizontalAdvance(s)); s = d->textFromValue(d->maximum); s.truncate(18); s += fixedContent; - w = qMax(w, fm.width(s)); + w = qMax(w, fm.horizontalAdvance(s)); if (d->specialValueText.size()) { s = d->specialValueText; - w = qMax(w, fm.width(s)); + w = qMax(w, fm.horizontalAdvance(s)); } w += 2; // cursor blinking space @@ -911,15 +918,15 @@ QSize QAbstractSpinBox::minimumSizeHint() const s = d->textFromValue(d->minimum); s.truncate(18); s += fixedContent; - w = qMax(w, fm.width(s)); + w = qMax(w, fm.horizontalAdvance(s)); s = d->textFromValue(d->maximum); s.truncate(18); s += fixedContent; - w = qMax(w, fm.width(s)); + w = qMax(w, fm.horizontalAdvance(s)); if (d->specialValueText.size()) { s = d->specialValueText; - w = qMax(w, fm.width(s)); + w = qMax(w, fm.horizontalAdvance(s)); } w += 2; // cursor blinking space @@ -1644,7 +1651,9 @@ void QAbstractSpinBox::initStyleOption(QStyleOptionSpinBox *option) const option->initFrom(this); option->activeSubControls = QStyle::SC_None; option->buttonSymbols = d->buttonSymbols; - option->subControls = QStyle::SC_SpinBoxFrame | QStyle::SC_SpinBoxEditField; + option->subControls = QStyle::SC_SpinBoxEditField; + if (!style()->styleHint(QStyle::SH_SpinBox_ButtonsInsideFrame, nullptr, this)) + option->subControls |= QStyle::SC_SpinBoxFrame; if (d->buttonSymbols != QAbstractSpinBox::NoButtons) { option->subControls |= QStyle::SC_SpinBoxUp | QStyle::SC_SpinBoxDown; if (d->buttonState & Up) { diff --git a/src/widgets/widgets/qabstractspinbox.h b/src/widgets/widgets/qabstractspinbox.h index 88735baf1c..83bf83d779 100644 --- a/src/widgets/widgets/qabstractspinbox.h +++ b/src/widgets/widgets/qabstractspinbox.h @@ -70,7 +70,7 @@ class Q_WIDGETS_EXPORT QAbstractSpinBox : public QWidget Q_PROPERTY(bool keyboardTracking READ keyboardTracking WRITE setKeyboardTracking) Q_PROPERTY(bool showGroupSeparator READ isGroupSeparatorShown WRITE setGroupSeparatorShown) public: - explicit QAbstractSpinBox(QWidget *parent = Q_NULLPTR); + explicit QAbstractSpinBox(QWidget *parent = nullptr); ~QAbstractSpinBox(); enum StepEnabledFlag { StepNone = 0x00, StepUpEnabled = 0x01, @@ -162,7 +162,7 @@ protected: Q_SIGNALS: void editingFinished(); protected: - QAbstractSpinBox(QAbstractSpinBoxPrivate &dd, QWidget *parent = Q_NULLPTR); + QAbstractSpinBox(QAbstractSpinBoxPrivate &dd, QWidget *parent = nullptr); private: Q_PRIVATE_SLOT(d_func(), void _q_editorTextChanged(const QString &)) diff --git a/src/widgets/widgets/qbuttongroup.h b/src/widgets/widgets/qbuttongroup.h index 1b4f2377ae..fec94ccb3e 100644 --- a/src/widgets/widgets/qbuttongroup.h +++ b/src/widgets/widgets/qbuttongroup.h @@ -57,7 +57,7 @@ class Q_WIDGETS_EXPORT QButtonGroup : public QObject Q_PROPERTY(bool exclusive READ exclusive WRITE setExclusive) public: - explicit QButtonGroup(QObject *parent = Q_NULLPTR); + explicit QButtonGroup(QObject *parent = nullptr); ~QButtonGroup(); void setExclusive(bool); diff --git a/src/widgets/widgets/qcalendarwidget.cpp b/src/widgets/widgets/qcalendarwidget.cpp index 94911d1cb1..059fb21295 100644 --- a/src/widgets/widgets/qcalendarwidget.cpp +++ b/src/widgets/widgets/qcalendarwidget.cpp @@ -115,11 +115,11 @@ class QCalendarDayValidator : public QCalendarDateSectionValidator public: QCalendarDayValidator(); - virtual Section handleKey(int key) Q_DECL_OVERRIDE; - virtual QDate applyToDate(const QDate &date) const Q_DECL_OVERRIDE; - virtual void setDate(const QDate &date) Q_DECL_OVERRIDE; - virtual QString text() const Q_DECL_OVERRIDE; - virtual QString text(const QDate &date, int repeat) const Q_DECL_OVERRIDE; + virtual Section handleKey(int key) override; + virtual QDate applyToDate(const QDate &date) const override; + virtual void setDate(const QDate &date) override; + virtual QString text() const override; + virtual QString text(const QDate &date, int repeat) const override; private: int m_pos; int m_day; @@ -223,11 +223,11 @@ class QCalendarMonthValidator : public QCalendarDateSectionValidator public: QCalendarMonthValidator(); - virtual Section handleKey(int key) Q_DECL_OVERRIDE; - virtual QDate applyToDate(const QDate &date) const Q_DECL_OVERRIDE; - virtual void setDate(const QDate &date) Q_DECL_OVERRIDE; - virtual QString text() const Q_DECL_OVERRIDE; - virtual QString text(const QDate &date, int repeat) const Q_DECL_OVERRIDE; + virtual Section handleKey(int key) override; + virtual QDate applyToDate(const QDate &date) const override; + virtual void setDate(const QDate &date) override; + virtual QString text() const override; + virtual QString text(const QDate &date, int repeat) const override; private: int m_pos; int m_month; @@ -333,11 +333,11 @@ class QCalendarYearValidator : public QCalendarDateSectionValidator public: QCalendarYearValidator(); - virtual Section handleKey(int key) Q_DECL_OVERRIDE; - virtual QDate applyToDate(const QDate &date) const Q_DECL_OVERRIDE; - virtual void setDate(const QDate &date) Q_DECL_OVERRIDE; - virtual QString text() const Q_DECL_OVERRIDE; - virtual QString text(const QDate &date, int repeat) const Q_DECL_OVERRIDE; + virtual Section handleKey(int key) override; + virtual QDate applyToDate(const QDate &date) const override; + virtual void setDate(const QDate &date) override; + virtual QString text() const override; + virtual QString text(const QDate &date, int repeat) const override; private: int pow10(int n); int m_pos; @@ -654,8 +654,8 @@ public: void setDate(const QDate &date); - bool eventFilter(QObject *o, QEvent *e) Q_DECL_OVERRIDE; - void timerEvent(QTimerEvent *e) Q_DECL_OVERRIDE; + bool eventFilter(QObject *o, QEvent *e) override; + void timerEvent(QTimerEvent *e) override; signals: void dateChanged(const QDate &date); @@ -861,32 +861,32 @@ class QCalendarModel : public QAbstractTableModel public: QCalendarModel(QObject *parent = 0); - int rowCount(const QModelIndex &) const Q_DECL_OVERRIDE + int rowCount(const QModelIndex &) const override { return RowCount + m_firstRow; } - int columnCount(const QModelIndex &) const Q_DECL_OVERRIDE + int columnCount(const QModelIndex &) const override { return ColumnCount + m_firstColumn; } - QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE; - Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; + QVariant data(const QModelIndex &index, int role) const override; + Qt::ItemFlags flags(const QModelIndex &index) const override; - bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE + bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override { beginInsertRows(parent, row, row + count - 1); endInsertRows(); return true; } - bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE + bool insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override { beginInsertColumns(parent, column, column + count - 1); endInsertColumns(); return true; } - bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE + bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override { beginRemoveRows(parent, row, row + count - 1); endRemoveRows(); return true; } - bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) Q_DECL_OVERRIDE + bool removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override { beginRemoveColumns(parent, column, column + count - 1); endRemoveColumns(); @@ -947,7 +947,7 @@ public: void internalUpdate() { updateGeometries(); } void setReadOnly(bool enable); - virtual void keyboardSearch(const QString & search) Q_DECL_OVERRIDE { Q_UNUSED(search) } + virtual void keyboardSearch(const QString & search) override { Q_UNUSED(search) } signals: void showDate(const QDate &date); @@ -955,16 +955,16 @@ signals: void clicked(const QDate &date); void editingFinished(); protected: - QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) Q_DECL_OVERRIDE; - void mouseDoubleClickEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override; + void mouseDoubleClickEvent(QMouseEvent *event) override; + void mousePressEvent(QMouseEvent *event) override; + void mouseMoveEvent(QMouseEvent *event) override; + void mouseReleaseEvent(QMouseEvent *event) override; #if QT_CONFIG(wheelevent) - void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; + void wheelEvent(QWheelEvent *event) override; #endif - void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE; - bool event(QEvent *event) Q_DECL_OVERRIDE; + void keyPressEvent(QKeyEvent *event) override; + bool event(QEvent *event) override; QDate handleMouseEvent(QMouseEvent *event); public: @@ -982,13 +982,13 @@ QCalendarModel::QCalendarModel(QObject *parent) m_firstRow(1), m_date(QDate::currentDate()), m_minimumDate(QDate::fromJulianDay(1)), - m_maximumDate(7999, 12, 31), + m_maximumDate(9999, 12, 31), m_shownYear(m_date.year()), m_shownMonth(m_date.month()), m_firstDay(QLocale().firstDayOfWeek()), m_horizontalHeaderFormat(QCalendarWidget::ShortDayNames), m_weekNumbersShown(true), - m_view(Q_NULLPTR) + m_view(nullptr) { } @@ -1563,7 +1563,7 @@ public: : QItemDelegate(parent), calendarWidgetPrivate(w) { } virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index) const Q_DECL_OVERRIDE; + const QModelIndex &index) const override; void paintCell(QPainter *painter, const QRect &rect, const QDate &date) const; private: @@ -1579,7 +1579,7 @@ public: : QToolButton(parent) { } protected: - void paintEvent(QPaintEvent *e) Q_DECL_OVERRIDE + void paintEvent(QPaintEvent *e) override { Q_UNUSED(e) @@ -1607,7 +1607,7 @@ class QPrevNextCalButton : public QToolButton public: QPrevNextCalButton(QWidget *parent) : QToolButton(parent) {} protected: - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE { + void paintEvent(QPaintEvent *) override { QStylePainter painter(this); QStyleOptionToolButton opt; initStyleOption(&opt); @@ -2196,7 +2196,7 @@ QSize QCalendarWidget::minimumSizeHint() const } else { for (int i = 1; i <= 7; i++) { QFontMetrics fm(d->m_model->formatForCell(0, i).font()); - w = qMax(w, fm.width(d->m_model->dayName(d->m_model->dayOfWeekForColumn(i))) + marginH); + w = qMax(w, fm.horizontalAdvance(d->m_model->dayName(d->m_model->dayOfWeekForColumn(i))) + marginH); h = qMax(h, fm.height()); } } @@ -2207,14 +2207,14 @@ QSize QCalendarWidget::minimumSizeHint() const for (int i = 1; i <= 6; i++) { QFontMetrics fm(d->m_model->formatForCell(i, 0).font()); for (int j = 1; j < end; j++) - w = qMax(w, fm.width(QString::number(j)) + marginH); + w = qMax(w, fm.horizontalAdvance(QString::number(j)) + marginH); h = qMax(h, fm.height()); } } QFontMetrics fm(d->m_model->formatForCell(1, 1).font()); for (int i = 1; i <= end; i++) { - w = qMax(w, fm.width(QString::number(i)) + marginH); + w = qMax(w, fm.horizontalAdvance(QString::number(i)) + marginH); h = qMax(h, fm.height()); } diff --git a/src/widgets/widgets/qcalendarwidget.h b/src/widgets/widgets/qcalendarwidget.h index 29e2ff698b..44ba340289 100644 --- a/src/widgets/widgets/qcalendarwidget.h +++ b/src/widgets/widgets/qcalendarwidget.h @@ -89,11 +89,11 @@ public: }; Q_ENUM(SelectionMode) - explicit QCalendarWidget(QWidget *parent = Q_NULLPTR); + explicit QCalendarWidget(QWidget *parent = nullptr); ~QCalendarWidget(); - virtual QSize sizeHint() const Q_DECL_OVERRIDE; - virtual QSize minimumSizeHint() const Q_DECL_OVERRIDE; + virtual QSize sizeHint() const override; + virtual QSize minimumSizeHint() const override; QDate selectedDate() const; @@ -138,11 +138,11 @@ public: void setDateEditAcceptDelay(int delay); protected: - bool event(QEvent *event) Q_DECL_OVERRIDE; - bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE; - void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - void resizeEvent(QResizeEvent * event) Q_DECL_OVERRIDE; - void keyPressEvent(QKeyEvent * event) Q_DECL_OVERRIDE; + bool event(QEvent *event) override; + bool eventFilter(QObject *watched, QEvent *event) override; + void mousePressEvent(QMouseEvent *event) override; + void resizeEvent(QResizeEvent * event) override; + void keyPressEvent(QKeyEvent * event) override; virtual void paintCell(QPainter *painter, const QRect &rect, const QDate &date) const; void updateCell(const QDate &date); diff --git a/src/widgets/widgets/qcheckbox.cpp b/src/widgets/widgets/qcheckbox.cpp index 9b49916774..81bfd3af35 100644 --- a/src/widgets/widgets/qcheckbox.cpp +++ b/src/widgets/widgets/qcheckbox.cpp @@ -45,6 +45,9 @@ #include "qstyle.h" #include "qstyleoption.h" #include "qevent.h" +#ifndef QT_NO_ACCESSIBILITY +#include "qaccessible.h" +#endif #include "private/qabstractbutton_p.h" @@ -144,6 +147,7 @@ void QCheckBoxPrivate::init() q->setCheckable(true); q->setMouseTracking(true); q->setForegroundRole(QPalette::WindowText); + q->setAttribute(Qt::WA_MacShowFocusRect); setLayoutItemMargins(QStyle::SE_CheckBoxLayoutItem); } @@ -243,6 +247,9 @@ Qt::CheckState QCheckBox::checkState() const void QCheckBox::setCheckState(Qt::CheckState state) { Q_D(QCheckBox); +#ifndef QT_NO_ACCESSIBILITY + bool noChange = d->noChange; +#endif if (state == Qt::PartiallyChecked) { d->tristate = true; d->noChange = true; @@ -257,6 +264,15 @@ void QCheckBox::setCheckState(Qt::CheckState state) d->publishedState = state; emit stateChanged(state); } + +#ifndef QT_NO_ACCESSIBILITY + if (noChange != d->noChange) { + QAccessible::State s; + s.checkStateMixed = true; + QAccessibleStateChangeEvent event(this, s); + QAccessible::updateAccessibility(&event); + } +#endif } diff --git a/src/widgets/widgets/qcheckbox.h b/src/widgets/widgets/qcheckbox.h index 8543c4c86f..80cb22b82e 100644 --- a/src/widgets/widgets/qcheckbox.h +++ b/src/widgets/widgets/qcheckbox.h @@ -58,12 +58,12 @@ class Q_WIDGETS_EXPORT QCheckBox : public QAbstractButton Q_PROPERTY(bool tristate READ isTristate WRITE setTristate) public: - explicit QCheckBox(QWidget *parent = Q_NULLPTR); - explicit QCheckBox(const QString &text, QWidget *parent = Q_NULLPTR); + explicit QCheckBox(QWidget *parent = nullptr); + explicit QCheckBox(const QString &text, QWidget *parent = nullptr); ~QCheckBox(); - QSize sizeHint() const Q_DECL_OVERRIDE; - QSize minimumSizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; + QSize minimumSizeHint() const override; void setTristate(bool y = true); bool isTristate() const; @@ -75,12 +75,12 @@ Q_SIGNALS: void stateChanged(int); protected: - bool event(QEvent *e) Q_DECL_OVERRIDE; - bool hitButton(const QPoint &pos) const Q_DECL_OVERRIDE; - void checkStateSet() Q_DECL_OVERRIDE; - void nextCheckState() Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; - void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE; + bool event(QEvent *e) override; + bool hitButton(const QPoint &pos) const override; + void checkStateSet() override; + void nextCheckState() override; + void paintEvent(QPaintEvent *) override; + void mouseMoveEvent(QMouseEvent *) override; void initStyleOption(QStyleOptionButton *option) const; diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 7ab3565a00..e70d096e04 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -45,6 +45,7 @@ #include <qlineedit.h> #include <qapplication.h> #include <qdesktopwidget.h> +#include <private/qdesktopwidget_p.h> #include <qlistview.h> #if QT_CONFIG(tableview) #include <qtableview.h> @@ -74,11 +75,6 @@ #include <private/qlineedit_p.h> #include <private/qcompleter_p.h> #include <qdebug.h> -#if 0 /* Used to be included in Qt4 for Q_WS_MAC */ && QT_CONFIG(effetcts) && QT_CONFIG(style_mac) -#include <private/qcore_mac_p.h> -#include <private/qmacstyle_mac_p.h> -#include <private/qt_cocoa_helpers_mac_p.h> -#endif #if QT_CONFIG(effects) # include <private/qeffects_p.h> #endif @@ -204,7 +200,21 @@ void QComboBoxPrivate::_q_completerActivated(const QModelIndex &index) if (index.isValid() && q->completer()) { QAbstractProxyModel *proxy = qobject_cast<QAbstractProxyModel *>(q->completer()->completionModel()); if (proxy) { - q->setCurrentIndex(proxy->mapToSource(index).row()); + const QModelIndex &completerIndex = proxy->mapToSource(index); + int row = -1; + if (completerIndex.model() == model) { + row = completerIndex.row(); + } else { + // if QCompleter uses a proxy model to host widget's one - map again + QAbstractProxyModel *completerProxy = qobject_cast<QAbstractProxyModel *>(q->completer()->model()); + if (completerProxy && completerProxy->sourceModel() == model) { + row = completerProxy->mapToSource(completerIndex).row(); + } else { + QString match = q->completer()->model()->data(completerIndex).toString(); + row = q->findText(match, matchFlags()); + } + } + q->setCurrentIndex(row); emitActivated(currentIndex); } } @@ -257,8 +267,8 @@ QRect QComboBoxPrivate::popupGeometry(int screen) const if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) useFullScreenForPopupMenu = theme->themeHint(QPlatformTheme::UseFullScreenForPopupMenu).toBool(); return useFullScreenForPopupMenu ? - QApplication::desktop()->screenGeometry(screen) : - QApplication::desktop()->availableGeometry(screen); + QDesktopWidgetPrivate::screenGeometry(screen) : + QDesktopWidgetPrivate::availableGeometry(screen); } bool QComboBoxPrivate::updateHoverControl(const QPoint &pos) @@ -303,7 +313,7 @@ int QComboBoxPrivate::computeWidthHint() const const QFontMetrics &fontMetrics = q->fontMetrics(); for (int i = 0; i < count; ++i) { - const int textWidth = fontMetrics.width(q->itemText(i)); + const int textWidth = fontMetrics.horizontalAdvance(q->itemText(i)); if (q->itemIcon(i).isNull()) width = (qMax(width, textWidth)); else @@ -332,7 +342,7 @@ QSize QComboBoxPrivate::recomputeSizeHint(QSize &sh) const case QComboBox::AdjustToContents: case QComboBox::AdjustToContentsOnFirstShow: if (count == 0) { - sh.rwidth() = 7 * fm.width(QLatin1Char('x')); + sh.rwidth() = 7 * fm.horizontalAdvance(QLatin1Char('x')); } else { for (int i = 0; i < count; ++i) { if (!q->itemIcon(i).isNull()) { @@ -355,7 +365,7 @@ QSize QComboBoxPrivate::recomputeSizeHint(QSize &sh) const hasIcon = !q->itemIcon(i).isNull(); } if (minimumContentsLength > 0) - sh.setWidth(qMax(sh.width(), minimumContentsLength * fm.width(QLatin1Char('X')) + (hasIcon ? iconSize.width() + 4 : 0))); + sh.setWidth(qMax(sh.width(), minimumContentsLength * fm.horizontalAdvance(QLatin1Char('X')) + (hasIcon ? iconSize.width() + 4 : 0))); // height @@ -419,6 +429,20 @@ void QComboBoxPrivateContainer::resizeEvent(QResizeEvent *e) QFrame::resizeEvent(e); } +void QComboBoxPrivateContainer::paintEvent(QPaintEvent *e) +{ + QStyleOptionComboBox cbOpt = comboStyleOption(); + if (combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &cbOpt, combo) + && mask().isEmpty()) { + QStyleOption opt; + opt.initFrom(this); + QPainter p(this); + style()->drawPrimitive(QStyle::PE_PanelMenu, &opt, &p, this); + } + + QFrame::paintEvent(e); +} + void QComboBoxPrivateContainer::leaveEvent(QEvent *) { // On Mac using the Mac style we want to clear the selection @@ -488,6 +512,14 @@ void QComboBoxPrivateContainer::scrollItemView(int action) #endif } +void QComboBoxPrivateContainer::hideScrollers() +{ + if (top) + top->hide(); + if (bottom) + bottom->hide(); +} + /* Hides or shows the scrollers when we emulate a popupmenu */ @@ -2614,7 +2646,7 @@ void QComboBox::showPopup() QComboBoxPrivateContainer* container = d->viewContainer(); QRect listRect(style->subControlRect(QStyle::CC_ComboBox, &opt, QStyle::SC_ComboBoxListBoxPopup, this)); - QRect screen = d->popupGeometry(QApplication::desktop()->screenNumber(this)); + QRect screen = d->popupGeometry(QDesktopWidgetPrivate::screenNumber(this)); QPoint below = mapToGlobal(listRect.bottomLeft()); int belowHeight = screen.bottom() - below.y(); @@ -2749,6 +2781,11 @@ void QComboBox::showPopup() if (needHorizontalScrollBar) { listRect.adjust(0, 0, 0, sb->height()); } + + // Hide the scrollers here, so that the listrect gets the full height of the container + // If the scrollers are truly needed, the later call to container->updateScrollers() + // will make them visible again. + container->hideScrollers(); container->setGeometry(listRect); #ifndef Q_OS_MAC @@ -3180,7 +3217,7 @@ void QComboBox::keyPressEvent(QKeyEvent *e) case Qt::Key_Up: if (e->modifiers() & Qt::ControlModifier) break; // pass to line edit for auto completion - // fall through + Q_FALLTHROUGH(); case Qt::Key_PageUp: #ifdef QT_KEYPAD_NAVIGATION if (QApplication::keypadNavigationEnabled()) @@ -3268,7 +3305,7 @@ void QComboBox::keyPressEvent(QKeyEvent *e) switch (move) { case MoveFirst: newIndex = -1; - // fall through + Q_FALLTHROUGH(); case MoveDown: newIndex++; while (newIndex < rowCount && !(d->model->index(newIndex, d->modelColumn, d->root).flags() & Qt::ItemIsEnabled)) @@ -3276,7 +3313,7 @@ void QComboBox::keyPressEvent(QKeyEvent *e) break; case MoveLast: newIndex = rowCount; - // fall through + Q_FALLTHROUGH(); case MoveUp: newIndex--; while ((newIndex >= 0) && !(d->model->flags(d->model->index(newIndex,d->modelColumn,d->root)) & Qt::ItemIsEnabled)) @@ -3315,11 +3352,11 @@ void QComboBox::keyReleaseEvent(QKeyEvent *e) #if QT_CONFIG(wheelevent) void QComboBox::wheelEvent(QWheelEvent *e) { -#ifdef Q_OS_DARWIN - Q_UNUSED(e); -#else Q_D(QComboBox); - if (!d->viewContainer()->isVisible()) { + QStyleOptionComboBox opt; + initStyleOption(&opt); + if (style()->styleHint(QStyle::SH_ComboBox_AllowWheelScrolling, &opt, this) && + !d->viewContainer()->isVisible()) { const int rowCount = count(); int newIndex = currentIndex(); @@ -3339,7 +3376,6 @@ void QComboBox::wheelEvent(QWheelEvent *e) } e->accept(); } -#endif } #endif diff --git a/src/widgets/widgets/qcombobox.h b/src/widgets/widgets/qcombobox.h index 59f2a425a0..671c883584 100644 --- a/src/widgets/widgets/qcombobox.h +++ b/src/widgets/widgets/qcombobox.h @@ -82,7 +82,7 @@ class Q_WIDGETS_EXPORT QComboBox : public QWidget Q_PROPERTY(int modelColumn READ modelColumn WRITE setModelColumn) public: - explicit QComboBox(QWidget *parent = Q_NULLPTR); + explicit QComboBox(QWidget *parent = nullptr); ~QComboBox(); int maxVisibleItems() const; @@ -196,14 +196,14 @@ public: QAbstractItemView *view() const; void setView(QAbstractItemView *itemView); - QSize sizeHint() const Q_DECL_OVERRIDE; - QSize minimumSizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; + QSize minimumSizeHint() const override; virtual void showPopup(); virtual void hidePopup(); - bool event(QEvent *event) Q_DECL_OVERRIDE; - QVariant inputMethodQuery(Qt::InputMethodQuery) const Q_DECL_OVERRIDE; + bool event(QEvent *event) override; + QVariant inputMethodQuery(Qt::InputMethodQuery) const override; Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery query, const QVariant &argument) const; public Q_SLOTS: @@ -224,24 +224,24 @@ Q_SIGNALS: void currentTextChanged(const QString &); protected: - void focusInEvent(QFocusEvent *e) Q_DECL_OVERRIDE; - void focusOutEvent(QFocusEvent *e) Q_DECL_OVERRIDE; - void changeEvent(QEvent *e) Q_DECL_OVERRIDE; - void resizeEvent(QResizeEvent *e) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *e) Q_DECL_OVERRIDE; - void showEvent(QShowEvent *e) Q_DECL_OVERRIDE; - void hideEvent(QHideEvent *e) Q_DECL_OVERRIDE; - void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE; - void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE; - void keyReleaseEvent(QKeyEvent *e) Q_DECL_OVERRIDE; + void focusInEvent(QFocusEvent *e) override; + void focusOutEvent(QFocusEvent *e) override; + void changeEvent(QEvent *e) override; + void resizeEvent(QResizeEvent *e) override; + void paintEvent(QPaintEvent *e) override; + void showEvent(QShowEvent *e) override; + void hideEvent(QHideEvent *e) override; + void mousePressEvent(QMouseEvent *e) override; + void mouseReleaseEvent(QMouseEvent *e) override; + void keyPressEvent(QKeyEvent *e) override; + void keyReleaseEvent(QKeyEvent *e) override; #if QT_CONFIG(wheelevent) - void wheelEvent(QWheelEvent *e) Q_DECL_OVERRIDE; + void wheelEvent(QWheelEvent *e) override; #endif #ifndef QT_NO_CONTEXTMENU - void contextMenuEvent(QContextMenuEvent *e) Q_DECL_OVERRIDE; + void contextMenuEvent(QContextMenuEvent *e) override; #endif // QT_NO_CONTEXTMENU - void inputMethodEvent(QInputMethodEvent *) Q_DECL_OVERRIDE; + void inputMethodEvent(QInputMethodEvent *) override; void initStyleOption(QStyleOptionComboBox *option) const; diff --git a/src/widgets/widgets/qcombobox_p.h b/src/widgets/widgets/qcombobox_p.h index 249610825a..3f75a357e4 100644 --- a/src/widgets/widgets/qcombobox_p.h +++ b/src/widgets/widgets/qcombobox_p.h @@ -215,7 +215,7 @@ private: bool fast; }; -class Q_AUTOTEST_EXPORT QComboBoxPrivateContainer : public QFrame +class Q_WIDGETS_EXPORT QComboBoxPrivateContainer : public QFrame { Q_OBJECT @@ -234,6 +234,7 @@ public: public Q_SLOTS: void scrollItemView(int action); + void hideScrollers(); void updateScrollers(); void viewDestroyed(); @@ -247,6 +248,7 @@ protected: void timerEvent(QTimerEvent *timerEvent) override; void leaveEvent(QEvent *e) override; void resizeEvent(QResizeEvent *e) override; + void paintEvent(QPaintEvent *e) override; QStyleOptionComboBox comboStyleOption() const; Q_SIGNALS: diff --git a/src/widgets/widgets/qcommandlinkbutton.cpp b/src/widgets/widgets/qcommandlinkbutton.cpp index b6ec2a8d31..68dfefb3b7 100644 --- a/src/widgets/widgets/qcommandlinkbutton.cpp +++ b/src/widgets/widgets/qcommandlinkbutton.cpp @@ -318,7 +318,7 @@ QSize QCommandLinkButton::sizeHint() const QSize size = QPushButton::sizeHint(); QFontMetrics fm(d->titleFont()); - int textWidth = qMax(fm.width(text()), 135); + int textWidth = qMax(fm.horizontalAdvance(text()), 135); int buttonWidth = textWidth + d->textOffset() + d->rightMargin(); int heightWithoutDescription = d->descriptionOffset() + d->bottomMargin(); diff --git a/src/widgets/widgets/qcommandlinkbutton.h b/src/widgets/widgets/qcommandlinkbutton.h index d8215a256e..2d01d63df8 100644 --- a/src/widgets/widgets/qcommandlinkbutton.h +++ b/src/widgets/widgets/qcommandlinkbutton.h @@ -58,20 +58,20 @@ class Q_WIDGETS_EXPORT QCommandLinkButton: public QPushButton Q_PROPERTY(bool flat READ isFlat WRITE setFlat DESIGNABLE false) public: - explicit QCommandLinkButton(QWidget *parent = Q_NULLPTR); - explicit QCommandLinkButton(const QString &text, QWidget *parent = Q_NULLPTR); - explicit QCommandLinkButton(const QString &text, const QString &description, QWidget *parent = Q_NULLPTR); + explicit QCommandLinkButton(QWidget *parent = nullptr); + explicit QCommandLinkButton(const QString &text, QWidget *parent = nullptr); + explicit QCommandLinkButton(const QString &text, const QString &description, QWidget *parent = nullptr); ~QCommandLinkButton(); QString description() const; void setDescription(const QString &description); protected: - QSize sizeHint() const Q_DECL_OVERRIDE; - int heightForWidth(int) const Q_DECL_OVERRIDE; - QSize minimumSizeHint() const Q_DECL_OVERRIDE; - bool event(QEvent *e) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; + QSize sizeHint() const override; + int heightForWidth(int) const override; + QSize minimumSizeHint() const override; + bool event(QEvent *e) override; + void paintEvent(QPaintEvent *) override; private: Q_DISABLE_COPY(QCommandLinkButton) diff --git a/src/widgets/widgets/qdatetimeedit.cpp b/src/widgets/widgets/qdatetimeedit.cpp index 053b184226..fca81bec48 100644 --- a/src/widgets/widgets/qdatetimeedit.cpp +++ b/src/widgets/widgets/qdatetimeedit.cpp @@ -42,6 +42,7 @@ #include <qapplication.h> #include <qdatetimeedit.h> #include <qdesktopwidget.h> +#include <private/qdesktopwidget_p.h> #include <qdebug.h> #include <qevent.h> #include <qlineedit.h> @@ -362,7 +363,7 @@ void QDateTimeEdit::setMinimumDateTime(const QDateTime &dt) clearMaximumDateTime(). By default, this property contains a date that refers to 31 December, - 7999 and a time of 23:59:59 and 999 milliseconds. + 9999 and a time of 23:59:59 and 999 milliseconds. \sa minimumDateTime(), minimumTime(), maximumTime(), minimumDate(), maximumDate(), setDateTimeRange(), setDateRange(), setTimeRange(), @@ -465,7 +466,7 @@ void QDateTimeEdit::clearMinimumDate() necessary to ensure that the range remains valid. If the date is not a valid QDate object, this function does nothing. - By default, this property contains a date that refers to December 31, 7999. + By default, this property contains a date that refers to December 31, 9999. \sa minimumDate, minimumTime, maximumTime, setDateRange() */ @@ -965,12 +966,12 @@ QSize QDateTimeEdit::sizeHint() const int w = 0; QString s; s = d->textFromValue(d->minimum) + QLatin1Char(' '); - w = qMax<int>(w, fm.width(s)); + w = qMax<int>(w, fm.horizontalAdvance(s)); s = d->textFromValue(d->maximum) + QLatin1Char(' '); - w = qMax<int>(w, fm.width(s)); + w = qMax<int>(w, fm.horizontalAdvance(s)); if (d->specialValueText.size()) { s = d->specialValueText; - w = qMax<int>(w, fm.width(s)); + w = qMax<int>(w, fm.horizontalAdvance(s)); } w += 2; // cursor blinking space @@ -1073,7 +1074,7 @@ void QDateTimeEdit::keyPressEvent(QKeyEvent *event) //hide cursor d->edit->d_func()->setCursorVisible(false); - d->edit->d_func()->control->setCursorBlinkPeriod(0); + d->edit->d_func()->control->setBlinkingCursorEnabled(false); d->setSelected(0); } } @@ -1094,7 +1095,7 @@ void QDateTimeEdit::keyPressEvent(QKeyEvent *event) //hide cursor d->edit->d_func()->setCursorVisible(false); - d->edit->d_func()->control->setCursorBlinkPeriod(0); + d->edit->d_func()->control->setBlinkingCursorEnabled(false); d->setSelected(0); oldCurrent = 0; } @@ -1128,7 +1129,7 @@ void QDateTimeEdit::keyPressEvent(QKeyEvent *event) } #endif } - // else fall through + Q_FALLTHROUGH(); case Qt::Key_Backtab: case Qt::Key_Tab: { event->accept(); @@ -1921,6 +1922,7 @@ QDateTime QDateTimeEditPrivate::validateAndInterpret(QString &input, int &positi } StateNode tmp = parse(input, position, value.toDateTime(), fixup); input = tmp.input; + position += tmp.padded; state = QValidator::State(int(tmp.state)); if (state == QValidator::Acceptable) { if (tmp.conflicts && conflictGuard != tmp.value) { @@ -2515,7 +2517,7 @@ void QDateTimeEditPrivate::positionCalendarPopup() pos = q->mapToGlobal(pos); pos2 = q->mapToGlobal(pos2); QSize size = monthCalendar->sizeHint(); - QRect screen = QApplication::desktop()->availableGeometry(pos); + QRect screen = QDesktopWidgetPrivate::availableGeometry(pos); //handle popup falling "off screen" if (q->layoutDirection() == Qt::RightToLeft) { pos.setX(pos.x()-size.width()); diff --git a/src/widgets/widgets/qdatetimeedit.h b/src/widgets/widgets/qdatetimeedit.h index b46434c1a4..b6fb35fc71 100644 --- a/src/widgets/widgets/qdatetimeedit.h +++ b/src/widgets/widgets/qdatetimeedit.h @@ -92,10 +92,10 @@ public: Q_DECLARE_FLAGS(Sections, Section) Q_FLAG(Sections) - explicit QDateTimeEdit(QWidget *parent = Q_NULLPTR); - explicit QDateTimeEdit(const QDateTime &dt, QWidget *parent = Q_NULLPTR); - explicit QDateTimeEdit(const QDate &d, QWidget *parent = Q_NULLPTR); - explicit QDateTimeEdit(const QTime &t, QWidget *parent = Q_NULLPTR); + explicit QDateTimeEdit(QWidget *parent = nullptr); + explicit QDateTimeEdit(const QDateTime &dt, QWidget *parent = nullptr); + explicit QDateTimeEdit(const QDate &d, QWidget *parent = nullptr); + explicit QDateTimeEdit(const QTime &t, QWidget *parent = nullptr); ~QDateTimeEdit(); QDateTime dateTime() const; @@ -191,7 +191,7 @@ protected: void paintEvent(QPaintEvent *event) override; void initStyleOption(QStyleOptionSpinBox *option) const; - QDateTimeEdit(const QVariant &val, QVariant::Type parserType, QWidget *parent = Q_NULLPTR); + QDateTimeEdit(const QVariant &val, QVariant::Type parserType, QWidget *parent = nullptr); private: Q_DECLARE_PRIVATE(QDateTimeEdit) Q_DISABLE_COPY(QDateTimeEdit) @@ -204,8 +204,8 @@ class Q_WIDGETS_EXPORT QTimeEdit : public QDateTimeEdit Q_OBJECT Q_PROPERTY(QTime time READ time WRITE setTime NOTIFY userTimeChanged USER true) public: - explicit QTimeEdit(QWidget *parent = Q_NULLPTR); - explicit QTimeEdit(const QTime &time, QWidget *parent = Q_NULLPTR); + explicit QTimeEdit(QWidget *parent = nullptr); + explicit QTimeEdit(const QTime &time, QWidget *parent = nullptr); ~QTimeEdit(); Q_SIGNALS: @@ -217,8 +217,8 @@ class Q_WIDGETS_EXPORT QDateEdit : public QDateTimeEdit Q_OBJECT Q_PROPERTY(QDate date READ date WRITE setDate NOTIFY userDateChanged USER true) public: - explicit QDateEdit(QWidget *parent = Q_NULLPTR); - explicit QDateEdit(const QDate &date, QWidget *parent = Q_NULLPTR); + explicit QDateEdit(QWidget *parent = nullptr); + explicit QDateEdit(const QDate &date, QWidget *parent = nullptr); ~QDateEdit(); Q_SIGNALS: diff --git a/src/widgets/widgets/qdatetimeedit_p.h b/src/widgets/widgets/qdatetimeedit_p.h index 5ac5a9db6a..1ebc98dedf 100644 --- a/src/widgets/widgets/qdatetimeedit_p.h +++ b/src/widgets/widgets/qdatetimeedit_p.h @@ -80,25 +80,25 @@ public: void clearSection(int index); // Override QAbstractSpinBoxPrivate: - void emitSignals(EmitPolicy ep, const QVariant &old) Q_DECL_OVERRIDE; - QString textFromValue(const QVariant &f) const Q_DECL_OVERRIDE; - QVariant valueFromText(const QString &f) const Q_DECL_OVERRIDE; - void _q_editorCursorPositionChanged(int oldpos, int newpos) Q_DECL_OVERRIDE; - void interpret(EmitPolicy ep) Q_DECL_OVERRIDE; - void clearCache() const Q_DECL_OVERRIDE; - QStyle::SubControl newHoverControl(const QPoint &pos) Q_DECL_OVERRIDE; - void updateEditFieldGeometry() Q_DECL_OVERRIDE; - QVariant getZeroVariant() const Q_DECL_OVERRIDE; - void setRange(const QVariant &min, const QVariant &max) Q_DECL_OVERRIDE; - void updateEdit() Q_DECL_OVERRIDE; + void emitSignals(EmitPolicy ep, const QVariant &old) override; + QString textFromValue(const QVariant &f) const override; + QVariant valueFromText(const QString &f) const override; + void _q_editorCursorPositionChanged(int oldpos, int newpos) override; + void interpret(EmitPolicy ep) override; + void clearCache() const override; + QStyle::SubControl newHoverControl(const QPoint &pos) override; + void updateEditFieldGeometry() override; + QVariant getZeroVariant() const override; + void setRange(const QVariant &min, const QVariant &max) override; + void updateEdit() override; // Override QDateTimeParser: - QString displayText() const Q_DECL_OVERRIDE { return edit->text(); } - QDateTime getMinimum() const Q_DECL_OVERRIDE { return minimum.toDateTime(); } - QDateTime getMaximum() const Q_DECL_OVERRIDE { return maximum.toDateTime(); } - QLocale locale() const Q_DECL_OVERRIDE { return q_func()->locale(); } - QString getAmPmText(AmPm ap, Case cs) const Q_DECL_OVERRIDE; - int cursorPosition() const Q_DECL_OVERRIDE { return edit ? edit->cursorPosition() : -1; } + QString displayText() const override { return edit->text(); } + QDateTime getMinimum() const override { return minimum.toDateTime(); } + QDateTime getMaximum() const override { return maximum.toDateTime(); } + QLocale locale() const override { return q_func()->locale(); } + QString getAmPmText(AmPm ap, Case cs) const override; + int cursorPosition() const override { return edit ? edit->cursorPosition() : -1; } int absoluteIndex(QDateTimeEdit::Section s, int index) const; int absoluteIndex(const SectionNode &s) const; diff --git a/src/widgets/widgets/qdial.cpp b/src/widgets/widgets/qdial.cpp index c08c820127..25d57970bf 100644 --- a/src/widgets/widgets/qdial.cpp +++ b/src/widgets/widgets/qdial.cpp @@ -79,7 +79,7 @@ public: int valueFromPoint(const QPoint &) const; double angle(const QPoint &, const QPoint &) const; void init(); - virtual int bound(int val) const Q_DECL_OVERRIDE; + virtual int bound(int val) const override; }; void QDialPrivate::init() diff --git a/src/widgets/widgets/qdial.h b/src/widgets/widgets/qdial.h index ed753d86b0..1db1f9bb07 100644 --- a/src/widgets/widgets/qdial.h +++ b/src/widgets/widgets/qdial.h @@ -61,7 +61,7 @@ class Q_WIDGETS_EXPORT QDial: public QAbstractSlider Q_PROPERTY(qreal notchTarget READ notchTarget WRITE setNotchTarget) Q_PROPERTY(bool notchesVisible READ notchesVisible WRITE setNotchesVisible) public: - explicit QDial(QWidget *parent = Q_NULLPTR); + explicit QDial(QWidget *parent = nullptr); ~QDial(); @@ -73,23 +73,23 @@ public: qreal notchTarget() const; bool notchesVisible() const; - QSize sizeHint() const Q_DECL_OVERRIDE; - QSize minimumSizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; + QSize minimumSizeHint() const override; public Q_SLOTS: void setNotchesVisible(bool visible); void setWrapping(bool on); protected: - bool event(QEvent *e) Q_DECL_OVERRIDE; - void resizeEvent(QResizeEvent *re) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *pe) Q_DECL_OVERRIDE; + bool event(QEvent *e) override; + void resizeEvent(QResizeEvent *re) override; + void paintEvent(QPaintEvent *pe) override; - void mousePressEvent(QMouseEvent *me) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent *me) Q_DECL_OVERRIDE; - void mouseMoveEvent(QMouseEvent *me) Q_DECL_OVERRIDE; + void mousePressEvent(QMouseEvent *me) override; + void mouseReleaseEvent(QMouseEvent *me) override; + void mouseMoveEvent(QMouseEvent *me) override; - void sliderChange(SliderChange change) Q_DECL_OVERRIDE; + void sliderChange(SliderChange change) override; void initStyleOption(QStyleOptionSlider *option) const; diff --git a/src/widgets/widgets/qdialogbuttonbox.cpp b/src/widgets/widgets/qdialogbuttonbox.cpp index 90cb17da59..9f5b739230 100644 --- a/src/widgets/widgets/qdialogbuttonbox.cpp +++ b/src/widgets/widgets/qdialogbuttonbox.cpp @@ -579,6 +579,8 @@ QDialogButtonBox::~QDialogButtonBox() \value MacLayout Use a policy appropriate for applications on \macos. \value KdeLayout Use a policy appropriate for applications on KDE. \value GnomeLayout Use a policy appropriate for applications on GNOME. + \value AndroidLayout Use a policy appropriate for applications on Android. + This enum value was added in Qt 5.10. The button layout is specified by the \l{style()}{current style}. However, on the X11 platform, it may be influenced by the desktop environment. @@ -925,8 +927,8 @@ void QDialogButtonBox::changeEvent(QEvent *event) for (StandardButtonHash::iterator it = d->standardButtonHash.begin(); it != end; ++it) it.key()->setStyle(newStyle); } - // fallthrough intended #ifdef Q_OS_MAC + Q_FALLTHROUGH(); case QEvent::MacSizeChange: #endif d->resetLayout(); diff --git a/src/widgets/widgets/qdialogbuttonbox.h b/src/widgets/widgets/qdialogbuttonbox.h index af9e705234..a9a1a3453d 100644 --- a/src/widgets/widgets/qdialogbuttonbox.h +++ b/src/widgets/widgets/qdialogbuttonbox.h @@ -108,18 +108,20 @@ public: Q_FLAG(StandardButtons) enum ButtonLayout { - // keep this in sync with QMessageBox::ButtonLayout and QPlatformDialogHelper::ButtonLayout + // keep this in sync with QPlatformDialogHelper::ButtonLayout WinLayout, MacLayout, KdeLayout, - GnomeLayout + GnomeLayout, + // MacModelessLayout, + AndroidLayout = GnomeLayout + 2 // ### Qt 6: reorder }; - QDialogButtonBox(QWidget *parent = Q_NULLPTR); - QDialogButtonBox(Qt::Orientation orientation, QWidget *parent = Q_NULLPTR); - explicit QDialogButtonBox(StandardButtons buttons, QWidget *parent = Q_NULLPTR); + QDialogButtonBox(QWidget *parent = nullptr); + QDialogButtonBox(Qt::Orientation orientation, QWidget *parent = nullptr); + explicit QDialogButtonBox(StandardButtons buttons, QWidget *parent = nullptr); QDialogButtonBox(StandardButtons buttons, Qt::Orientation orientation, - QWidget *parent = Q_NULLPTR); + QWidget *parent = nullptr); ~QDialogButtonBox(); void setOrientation(Qt::Orientation orientation); @@ -149,8 +151,8 @@ Q_SIGNALS: void rejected(); protected: - void changeEvent(QEvent *event) Q_DECL_OVERRIDE; - bool event(QEvent *event) Q_DECL_OVERRIDE; + void changeEvent(QEvent *event) override; + bool event(QEvent *event) override; private: Q_DISABLE_COPY(QDialogButtonBox) diff --git a/src/widgets/widgets/qdockarealayout.cpp b/src/widgets/widgets/qdockarealayout.cpp index 21d1d4cb85..71726eaeee 100644 --- a/src/widgets/widgets/qdockarealayout.cpp +++ b/src/widgets/widgets/qdockarealayout.cpp @@ -45,6 +45,7 @@ #endif #include "QtWidgets/qstyle.h" #include "QtWidgets/qdesktopwidget.h" +#include <private/qdesktopwidget_p.h> #include "QtWidgets/qapplication.h" #include "QtCore/qvariant.h" #include "qdockarealayout_p.h" @@ -1044,33 +1045,6 @@ QLayoutItem *QDockAreaLayoutInfo::plug(const QList<int> &path) Q_ASSERT(item.widgetItem != 0); Q_ASSERT(item.flags & QDockAreaLayoutItem::GapItem); item.flags &= ~QDockAreaLayoutItem::GapItem; - - QRect result; - -#if QT_CONFIG(tabbar) - if (tabbed) { - } else -#endif - { - int prev = this->prev(index); - int next = this->next(index); - - if (prev != -1 && !(item_list.at(prev).flags & QDockAreaLayoutItem::GapItem)) { - item.pos += *sep; - item.size -= *sep; - } - if (next != -1 && !(item_list.at(next).flags & QDockAreaLayoutItem::GapItem)) - item.size -= *sep; - - QPoint pos; - rpick(o, pos) = item.pos; - rperp(o, pos) = perp(o, rect.topLeft()); - QSize s; - rpick(o, s) = item.size; - rperp(o, s) = perp(o, rect.size()); - result = QRect(pos, s); - } - return item.widgetItem; } @@ -1323,29 +1297,46 @@ QDockAreaLayoutInfo *QDockAreaLayoutInfo::info(const QList<int> &path) return item_list[index].subinfo->info(path.mid(1)); } -QRect QDockAreaLayoutInfo::itemRect(int index) const +QRect QDockAreaLayoutInfo::itemRect(int index, bool isGap) const { const QDockAreaLayoutItem &item = item_list.at(index); if (item.skip()) return QRect(); + if (isGap && !(item.flags & QDockAreaLayoutItem::GapItem)) + return QRect(); + QRect result; #if QT_CONFIG(tabbar) if (tabbed) { - if (tabId(item) == currentTabId()) + if (isGap || tabId(item) == currentTabId()) result = tabContentRect(); } else #endif { - QPoint pos; - rpick(o, pos) = item.pos; - rperp(o, pos) = perp(o, rect.topLeft()); + int pos = item.pos; + int size = item.size; + + if (isGap) { + int prev = this->prev(index); + int next = this->next(index); + if (prev != -1 && !(item_list.at(prev).flags & QDockAreaLayoutItem::GapItem)) { + pos += *sep; + size -= *sep; + } + if (next != -1 && !(item_list.at(next).flags & QDockAreaLayoutItem::GapItem)) + size -= *sep; + } + + QPoint p; + rpick(o, p) = pos; + rperp(o, p) = perp(o, rect.topLeft()); QSize s; - rpick(o, s) = item.size; + rpick(o, s) = size; rperp(o, s) = perp(o, rect.size()); - result = QRect(pos, s); + result = QRect(p, s); } return result; @@ -2426,20 +2417,21 @@ QList<int> QDockAreaLayout::indexOf(QWidget *dockWidget) const return QList<int>(); } -QList<int> QDockAreaLayout::gapIndex(const QPoint &pos) const +QList<int> QDockAreaLayout::gapIndex(const QPoint &pos, bool disallowTabs) const { QMainWindow::DockOptions opts = mainWindow->dockOptions(); bool nestingEnabled = opts & QMainWindow::AllowNestedDocks; QDockAreaLayoutInfo::TabMode tabMode = QDockAreaLayoutInfo::NoTabs; #if QT_CONFIG(tabbar) - if (opts & QMainWindow::AllowTabbedDocks - || opts & QMainWindow::VerticalTabs) - tabMode = QDockAreaLayoutInfo::AllowTabs; - if (opts & QMainWindow::ForceTabbedDocks) - tabMode = QDockAreaLayoutInfo::ForceTabs; + if (!disallowTabs) { + if (opts & QMainWindow::AllowTabbedDocks || opts & QMainWindow::VerticalTabs) + tabMode = QDockAreaLayoutInfo::AllowTabs; + if (opts & QMainWindow::ForceTabbedDocks) + tabMode = QDockAreaLayoutInfo::ForceTabs; - if (tabMode == QDockAreaLayoutInfo::ForceTabs) - nestingEnabled = false; + if (tabMode == QDockAreaLayoutInfo::ForceTabs) + nestingEnabled = false; + } #endif @@ -3052,11 +3044,10 @@ QSize QDockAreaLayout::minimumSize() const QRect QDockAreaLayout::constrainedRect(QRect rect, QWidget* widget) { QRect desktop; - QDesktopWidget *desktopW = QApplication::desktop(); - if (desktopW->isVirtualDesktop()) - desktop = desktopW->screenGeometry(rect.topLeft()); + if (QDesktopWidgetPrivate::isVirtualDesktop()) + desktop = QDesktopWidgetPrivate::screenGeometry(rect.topLeft()); else - desktop = desktopW->screenGeometry(widget); + desktop = QDesktopWidgetPrivate::screenGeometry(widget); if (desktop.isValid()) { rect.setWidth(qMin(rect.width(), desktop.width())); @@ -3311,6 +3302,19 @@ int QDockAreaLayout::separatorMove(const QList<int> &separator, const QPoint &or return delta; } +int QDockAreaLayoutInfo::separatorMove(const QList<int> &separator, const QPoint &origin, + const QPoint &dest) +{ + int delta = 0; + int index = separator.last(); + QDockAreaLayoutInfo *info = this->info(separator); + delta = pick(info->o, dest - origin); + if (delta != 0) + delta = info->separatorMove(index, delta); + info->apply(false); + return delta; +} + #if QT_CONFIG(tabbar) // Sets the correct positions for the separator widgets // Allocates new sepearator widgets with getSeparatorWidget @@ -3420,47 +3424,10 @@ QRect QDockAreaLayout::gapRect(const QList<int> &path) const const QDockAreaLayoutInfo *info = this->info(path); if (info == 0) return QRect(); - const QList<QDockAreaLayoutItem> &item_list = info->item_list; - Qt::Orientation o = info->o; int index = path.last(); - if (index < 0 || index >= item_list.count()) - return QRect(); - const QDockAreaLayoutItem &item = item_list.at(index); - if (!(item.flags & QDockAreaLayoutItem::GapItem)) + if (index < 0 || index >= info->item_list.count()) return QRect(); - - QRect result; - -#if QT_CONFIG(tabbar) - if (info->tabbed) { - result = info->tabContentRect(); - } else -#endif - { - int pos = item.pos; - int size = item.size; - - int prev = info->prev(index); - int next = info->next(index); - - if (prev != -1 && !(item_list.at(prev).flags & QDockAreaLayoutItem::GapItem)) { - pos += sep; - size -= sep; - } - if (next != -1 && !(item_list.at(next).flags & QDockAreaLayoutItem::GapItem)) - size -= sep; - - QPoint p; - rpick(o, p) = pos; - rperp(o, p) = perp(o, info->rect.topLeft()); - QSize s; - rpick(o, s) = size; - rperp(o, s) = perp(o, info->rect.size()); - - result = QRect(p, s); - } - - return result; + return info->itemRect(index, true); } void QDockAreaLayout::keepSize(QDockWidget *w) diff --git a/src/widgets/widgets/qdockarealayout_p.h b/src/widgets/widgets/qdockarealayout_p.h index 82244c192e..49bd157179 100644 --- a/src/widgets/widgets/qdockarealayout_p.h +++ b/src/widgets/widgets/qdockarealayout_p.h @@ -160,7 +160,7 @@ public: void fitItems(); bool expansive(Qt::Orientation o) const; int changeSize(int index, int size, bool below); - QRect itemRect(int index) const; + QRect itemRect(int index, bool isGap = false) const; QRect itemRect(const QList<int> &path) const; QRect separatorRect(int index) const; QRect separatorRect(const QList<int> &path) const; @@ -182,6 +182,7 @@ public: const QPoint &mouse) const; QRegion separatorRegion() const; int separatorMove(int index, int delta); + int separatorMove(const QList<int> &separator, const QPoint &origin, const QPoint &dest); QLayoutItem *itemAt(int *x, int index) const; QLayoutItem *takeAt(int *x, int index); @@ -246,7 +247,7 @@ public: QList<int> indexOfPlaceHolder(const QString &objectName) const; QList<int> indexOf(QWidget *dockWidget) const; - QList<int> gapIndex(const QPoint &pos) const; + QList<int> gapIndex(const QPoint &pos, bool disallowTabs) const; QList<int> findSeparator(const QPoint &pos) const; QDockAreaLayoutItem &item(const QList<int> &path); diff --git a/src/widgets/widgets/qdockwidget.cpp b/src/widgets/widgets/qdockwidget.cpp index 8d7d2a82d5..e17c2c1f4c 100644 --- a/src/widgets/widgets/qdockwidget.cpp +++ b/src/widgets/widgets/qdockwidget.cpp @@ -53,14 +53,10 @@ #include <qdebug.h> #include <private/qwidgetresizehandler_p.h> +#include <private/qstylesheetstyle_p.h> #include "qdockwidget_p.h" #include "qmainwindowlayout_p.h" -#if 0 // Used to be included in Qt4 for Q_WS_MAC -#include <private/qapplication_p.h> -#include <private/qt_mac_p.h> -#include <private/qmacstyle_mac_p.h> -#endif QT_BEGIN_NAMESPACE @@ -78,7 +74,7 @@ static inline QMainWindowLayout *qt_mainwindow_layout_from_dock(const QDockWidge return qt_mainwindow_layout(window); p = p->parentWidget(); } - return Q_NULLPTR; + return nullptr; } static inline bool hasFeature(const QDockWidgetPrivate *priv, QDockWidget::DockWidgetFeature feature) @@ -125,15 +121,22 @@ class QDockWidgetTitleButton : public QAbstractButton public: QDockWidgetTitleButton(QDockWidget *dockWidget); - QSize sizeHint() const Q_DECL_OVERRIDE; - QSize minimumSizeHint() const Q_DECL_OVERRIDE + QSize sizeHint() const override; + QSize minimumSizeHint() const override { return sizeHint(); } - void enterEvent(QEvent *event) Q_DECL_OVERRIDE; - void leaveEvent(QEvent *event) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; -}; + void enterEvent(QEvent *event) override; + void leaveEvent(QEvent *event) override; + void paintEvent(QPaintEvent *event) override; +protected: + bool event(QEvent *event) override; + +private: + QSize dockButtonIconSize() const; + + mutable int m_iconSize = -1; +}; QDockWidgetTitleButton::QDockWidgetTitleButton(QDockWidget *dockWidget) : QAbstractButton(dockWidget) @@ -141,14 +144,49 @@ QDockWidgetTitleButton::QDockWidgetTitleButton(QDockWidget *dockWidget) setFocusPolicy(Qt::NoFocus); } +bool QDockWidgetTitleButton::event(QEvent *event) +{ + switch (event->type()) { + case QEvent::StyleChange: + case QEvent::ScreenChangeInternal: + m_iconSize = -1; + break; + default: + break; + } + return QAbstractButton::event(event); +} + +static inline bool isWindowsStyle(const QStyle *style) +{ + // Note: QStyleSheetStyle inherits QWindowsStyle + const QStyle *effectiveStyle = style->inherits("QStyleSheetStyle") + ? static_cast<const QStyleSheetStyle *>(style)->baseStyle() + : style; + return effectiveStyle->inherits("QWindowsStyle"); +} + +QSize QDockWidgetTitleButton::dockButtonIconSize() const +{ + if (m_iconSize < 0) { + m_iconSize = style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, this); + // Dock Widget title buttons on Windows where historically limited to size 10 + // (from small icon size 16) since only a 10x10 XPM was provided. + // Adding larger pixmaps to the icons thus caused the icons to grow; limit + // this to qpiScaled(10) here. + if (isWindowsStyle(style())) + m_iconSize = qMin((10 * logicalDpiX()) / 96, m_iconSize); + } + return QSize(m_iconSize, m_iconSize); +} + QSize QDockWidgetTitleButton::sizeHint() const { ensurePolished(); int size = 2*style()->pixelMetric(QStyle::PM_DockWidgetTitleBarButtonMargin, 0, this); if (!icon().isNull()) { - int iconSize = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this); - QSize sz = icon().actualSize(QSize(iconSize, iconSize)); + const QSize sz = icon().actualSize(dockButtonIconSize()); size += qMax(sz.width(), sz.height()); } @@ -191,8 +229,7 @@ void QDockWidgetTitleButton::paintEvent(QPaintEvent *) opt.activeSubControls = 0; opt.features = QStyleOptionToolButton::None; opt.arrowType = Qt::NoArrow; - int size = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this); - opt.iconSize = QSize(size, size); + opt.iconSize = dockButtonIconSize(); style()->drawComplexControl(QStyle::CC_ToolButton, &opt, &p, this); } @@ -217,10 +254,9 @@ QDockWidgetLayout::~QDockWidgetLayout() bool QDockWidgetLayout::nativeWindowDeco() const { bool floating = parentWidget()->isWindow(); - if (!floating) { - if (auto groupWindow = qobject_cast<const QDockWidgetGroupWindow*>(parentWidget()->parentWidget())) - return groupWindow->hasNativeDecos(); - } + if (auto groupWindow = + qobject_cast<const QDockWidgetGroupWindow *>(parentWidget()->parentWidget())) + floating = floating || groupWindow->tabLayoutInfo(); return nativeWindowDeco(floating); } @@ -617,6 +653,8 @@ void QDockWidgetPrivate::init() QObject::connect(button, SIGNAL(clicked()), q, SLOT(close())); layout->setWidgetForRole(QDockWidgetLayout::CloseButton, button); + font = QApplication::font("QDockWidgetTitle"); + #ifndef QT_NO_ACTION toggleViewAction = new QAction(q); toggleViewAction->setCheckable(true); @@ -649,6 +687,7 @@ void QDockWidget::initStyleOption(QStyleOptionDockWidget *option) const // If we are in a floating tab, init from the parent because the attributes and the geometry // of the title bar should be taken from the floating window. option->initFrom(floatingTab && !isFloating() ? parentWidget() : this); + option->fontMetrics = QFontMetrics(d->font); option->rect = dwlayout->titleArea(); option->title = d->fixedWindowTitle; option->closable = hasFeature(this, QDockWidget::DockWidgetClosable); @@ -1442,9 +1481,10 @@ void QDockWidget::paintEvent(QPaintEvent *event) } // Title must be painted after the frame, since the areas overlap, and - // the title may wish to extend out to all sides (eg. XP style) + // the title may wish to extend out to all sides (eg. Vista style) QStyleOptionDockWidget titleOpt; initStyleOption(&titleOpt); + p.setFont(d_func()->font); p.drawControl(QStyle::CE_DockWidgetTitle, titleOpt); } } diff --git a/src/widgets/widgets/qdockwidget.h b/src/widgets/widgets/qdockwidget.h index b53fa19a03..b53a991dae 100644 --- a/src/widgets/widgets/qdockwidget.h +++ b/src/widgets/widgets/qdockwidget.h @@ -63,9 +63,9 @@ class Q_WIDGETS_EXPORT QDockWidget : public QWidget Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle DESIGNABLE true) public: - explicit QDockWidget(const QString &title, QWidget *parent = Q_NULLPTR, + explicit QDockWidget(const QString &title, QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); - explicit QDockWidget(QWidget *parent = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags()); + explicit QDockWidget(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); ~QDockWidget(); QWidget *widget() const; @@ -113,10 +113,10 @@ Q_SIGNALS: void dockLocationChanged(Qt::DockWidgetArea area); protected: - void changeEvent(QEvent *event) Q_DECL_OVERRIDE; - void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; - bool event(QEvent *event) Q_DECL_OVERRIDE; + void changeEvent(QEvent *event) override; + void closeEvent(QCloseEvent *event) override; + void paintEvent(QPaintEvent *event) override; + bool event(QEvent *event) override; void initStyleOption(QStyleOptionDockWidget *option) const; private: diff --git a/src/widgets/widgets/qdockwidget_p.h b/src/widgets/widgets/qdockwidget_p.h index 2c16176c37..766e4ed161 100644 --- a/src/widgets/widgets/qdockwidget_p.h +++ b/src/widgets/widgets/qdockwidget_p.h @@ -99,6 +99,8 @@ public: QDockWidget::DockWidgetFeatures features; Qt::DockWidgetAreas allowedAreas; + QFont font; + #ifndef QT_NO_ACTION QAction *toggleViewAction; #endif @@ -135,18 +137,18 @@ class Q_WIDGETS_EXPORT QDockWidgetLayout : public QLayout public: QDockWidgetLayout(QWidget *parent = 0); ~QDockWidgetLayout(); - void addItem(QLayoutItem *item) Q_DECL_OVERRIDE; - QLayoutItem *itemAt(int index) const Q_DECL_OVERRIDE; - QLayoutItem *takeAt(int index) Q_DECL_OVERRIDE; - int count() const Q_DECL_OVERRIDE; + void addItem(QLayoutItem *item) override; + QLayoutItem *itemAt(int index) const override; + QLayoutItem *takeAt(int index) override; + int count() const override; - QSize maximumSize() const Q_DECL_OVERRIDE; - QSize minimumSize() const Q_DECL_OVERRIDE; - QSize sizeHint() const Q_DECL_OVERRIDE; + QSize maximumSize() const override; + QSize minimumSize() const override; + QSize sizeHint() const override; QSize sizeFromContent(const QSize &content, bool floating) const; - void setGeometry(const QRect &r) Q_DECL_OVERRIDE; + void setGeometry(const QRect &r) override; enum Role { Content, CloseButton, FloatButton, TitleBar, RoleCount }; QWidget *widgetForRole(Role r) const; @@ -178,9 +180,9 @@ class QDockWidgetItem : public QWidgetItem { public: QDockWidgetItem(QDockWidget *dockWidget); - QSize minimumSize() const Q_DECL_OVERRIDE; - QSize maximumSize() const Q_DECL_OVERRIDE; - QSize sizeHint() const Q_DECL_OVERRIDE; + QSize minimumSize() const override; + QSize maximumSize() const override; + QSize sizeHint() const override; private: inline QLayoutItem *dockWidgetChildItem() const; diff --git a/src/widgets/widgets/qeffects.cpp b/src/widgets/widgets/qeffects.cpp index 437cee93df..bcc8d7815d 100644 --- a/src/widgets/widgets/qeffects.cpp +++ b/src/widgets/widgets/qeffects.cpp @@ -50,6 +50,8 @@ #include "qelapsedtimer.h" #include "qdebug.h" +#include <private/qdesktopwidget_p.h> + QT_BEGIN_NAMESPACE /* @@ -69,10 +71,10 @@ public: void run(int time); protected: - void paintEvent(QPaintEvent* e) Q_DECL_OVERRIDE; - void closeEvent(QCloseEvent*) Q_DECL_OVERRIDE; + void paintEvent(QPaintEvent* e) override; + void closeEvent(QCloseEvent*) override; void alphaBlend(); - bool eventFilter(QObject *, QEvent *) Q_DECL_OVERRIDE; + bool eventFilter(QObject *, QEvent *) override; protected slots: void render(); @@ -96,9 +98,12 @@ static QAlphaWidget* q_blend = 0; /* Constructs a QAlphaWidget. */ +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED // QDesktopWidget::screen() QAlphaWidget::QAlphaWidget(QWidget* w, Qt::WindowFlags f) - : QWidget(QApplication::desktop()->screen(QApplication::desktop()->screenNumber(w)), f) + : QWidget(QApplication::desktop()->screen(QDesktopWidgetPrivate::screenNumber(w)), f) { +QT_WARNING_POP #ifndef Q_OS_WIN setEnabled(false); #endif @@ -346,8 +351,8 @@ public: void run(int time); protected: - void paintEvent(QPaintEvent*) Q_DECL_OVERRIDE; - void closeEvent(QCloseEvent*) Q_DECL_OVERRIDE; + void paintEvent(QPaintEvent*) override; + void closeEvent(QCloseEvent*) override; private slots: void scroll(); diff --git a/src/widgets/widgets/qfocusframe.h b/src/widgets/widgets/qfocusframe.h index a1fc6d345d..73d5b42bd8 100644 --- a/src/widgets/widgets/qfocusframe.h +++ b/src/widgets/widgets/qfocusframe.h @@ -53,17 +53,17 @@ class Q_WIDGETS_EXPORT QFocusFrame : public QWidget { Q_OBJECT public: - QFocusFrame(QWidget *parent = Q_NULLPTR); + QFocusFrame(QWidget *parent = nullptr); ~QFocusFrame(); void setWidget(QWidget *widget); QWidget *widget() const; protected: - bool event(QEvent *e) Q_DECL_OVERRIDE; + bool event(QEvent *e) override; - bool eventFilter(QObject *, QEvent *) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; + bool eventFilter(QObject *, QEvent *) override; + void paintEvent(QPaintEvent *) override; void initStyleOption(QStyleOption *option) const; private: diff --git a/src/widgets/widgets/qfontcombobox.cpp b/src/widgets/widgets/qfontcombobox.cpp index f206d01999..957a464b71 100644 --- a/src/widgets/widgets/qfontcombobox.cpp +++ b/src/widgets/widgets/qfontcombobox.cpp @@ -47,6 +47,7 @@ #include <qapplication.h> #include <private/qcombobox_p.h> #include <QDesktopWidget> +#include <private/qdesktopwidget_p.h> #include <qdebug.h> QT_BEGIN_NAMESPACE @@ -188,10 +189,10 @@ public: // painting void paint(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index) const Q_DECL_OVERRIDE; + const QModelIndex &index) const override; QSize sizeHint(const QStyleOptionViewItem &option, - const QModelIndex &index) const Q_DECL_OVERRIDE; + const QModelIndex &index) const override; const QIcon truetype; const QIcon bitmap; @@ -262,7 +263,7 @@ void QFontFamilyDelegate::paint(QPainter *painter, system = writingSystem; if (system != QFontDatabase::Any) { - int w = painter->fontMetrics().width(text + QLatin1String(" ")); + int w = painter->fontMetrics().horizontalAdvance(text + QLatin1String(" ")); painter->setFont(font2); QString sample = QFontDatabase().writingSystemSample(system); if (option.direction == Qt::RightToLeft) @@ -286,7 +287,7 @@ QSize QFontFamilyDelegate::sizeHint(const QStyleOptionViewItem &option, // font.setFamily(text); font.setPointSize(QFontInfo(font).pointSize() * 3/2); QFontMetrics fontMetrics(font); - return QSize(fontMetrics.width(text), fontMetrics.height()); + return QSize(fontMetrics.horizontalAdvance(text), fontMetrics.height()); } @@ -523,7 +524,7 @@ void QFontComboBox::setCurrentFont(const QFont &font) } /*! - \fn QFontComboBox::currentFontChanged(const QFont &font) + \fn void QFontComboBox::currentFontChanged(const QFont &font) This signal is emitted whenever the current font changes, with the new \a font. @@ -540,7 +541,7 @@ bool QFontComboBox::event(QEvent *e) QListView *lview = qobject_cast<QListView*>(view()); if (lview) { lview->window()->setFixedWidth(qMin(width() * 5 / 3, - QApplication::desktop()->availableGeometry(lview).width())); + QDesktopWidgetPrivate::availableGeometry(lview).width())); } } return QComboBox::event(e); @@ -553,7 +554,7 @@ QSize QFontComboBox::sizeHint() const { QSize sz = QComboBox::sizeHint(); QFontMetrics fm(font()); - sz.setWidth(fm.width(QLatin1Char('m'))*14); + sz.setWidth(fm.horizontalAdvance(QLatin1Char('m'))*14); return sz; } diff --git a/src/widgets/widgets/qfontcombobox.h b/src/widgets/widgets/qfontcombobox.h index 1e4555ce2d..6c1871dd2d 100644 --- a/src/widgets/widgets/qfontcombobox.h +++ b/src/widgets/widgets/qfontcombobox.h @@ -58,7 +58,7 @@ class Q_WIDGETS_EXPORT QFontComboBox : public QComboBox Q_PROPERTY(QFont currentFont READ currentFont WRITE setCurrentFont NOTIFY currentFontChanged) public: - explicit QFontComboBox(QWidget *parent = Q_NULLPTR); + explicit QFontComboBox(QWidget *parent = nullptr); ~QFontComboBox(); void setWritingSystem(QFontDatabase::WritingSystem); @@ -78,7 +78,7 @@ public: FontFilters fontFilters() const; QFont currentFont() const; - QSize sizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; public Q_SLOTS: void setCurrentFont(const QFont &f); @@ -87,7 +87,7 @@ Q_SIGNALS: void currentFontChanged(const QFont &f); protected: - bool event(QEvent *e) Q_DECL_OVERRIDE; + bool event(QEvent *e) override; private: Q_DISABLE_COPY(QFontComboBox) diff --git a/src/widgets/widgets/qframe.h b/src/widgets/widgets/qframe.h index 986915a28f..595dfa929d 100644 --- a/src/widgets/widgets/qframe.h +++ b/src/widgets/widgets/qframe.h @@ -61,7 +61,7 @@ class Q_WIDGETS_EXPORT QFrame : public QWidget Q_PROPERTY(QRect frameRect READ frameRect WRITE setFrameRect DESIGNABLE false) public: - explicit QFrame(QWidget* parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()); + explicit QFrame(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); ~QFrame(); int frameStyle() const; @@ -69,7 +69,7 @@ public: int frameWidth() const; - QSize sizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; enum Shape { NoFrame = 0, // no frame @@ -108,14 +108,14 @@ public: void setFrameRect(const QRect &); protected: - bool event(QEvent *e) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; - void changeEvent(QEvent *) Q_DECL_OVERRIDE; + bool event(QEvent *e) override; + void paintEvent(QPaintEvent *) override; + void changeEvent(QEvent *) override; void drawFrame(QPainter *); protected: - QFrame(QFramePrivate &dd, QWidget* parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()); + QFrame(QFramePrivate &dd, QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); void initStyleOption(QStyleOptionFrame *option) const; private: diff --git a/src/widgets/widgets/qgroupbox.cpp b/src/widgets/widgets/qgroupbox.cpp index 611f3f88db..69eac1ebf7 100644 --- a/src/widgets/widgets/qgroupbox.cpp +++ b/src/widgets/widgets/qgroupbox.cpp @@ -484,7 +484,7 @@ QSize QGroupBox::minimumSizeHint() const QFontMetrics metrics(fontMetrics()); - int baseWidth = metrics.width(d->title) + metrics.width(QLatin1Char(' ')); + int baseWidth = metrics.horizontalAdvance(d->title) + metrics.horizontalAdvance(QLatin1Char(' ')); int baseHeight = metrics.height(); if (d->checkable) { baseWidth += style()->pixelMetric(QStyle::PM_IndicatorWidth); diff --git a/src/widgets/widgets/qgroupbox.h b/src/widgets/widgets/qgroupbox.h index 668dc03f3d..deaeba4656 100644 --- a/src/widgets/widgets/qgroupbox.h +++ b/src/widgets/widgets/qgroupbox.h @@ -59,8 +59,8 @@ class Q_WIDGETS_EXPORT QGroupBox : public QWidget Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable) Q_PROPERTY(bool checked READ isChecked WRITE setChecked DESIGNABLE isCheckable NOTIFY toggled USER true) public: - explicit QGroupBox(QWidget *parent = Q_NULLPTR); - explicit QGroupBox(const QString &title, QWidget *parent = Q_NULLPTR); + explicit QGroupBox(QWidget *parent = nullptr); + explicit QGroupBox(const QString &title, QWidget *parent = nullptr); ~QGroupBox(); QString title() const; @@ -69,7 +69,7 @@ public: Qt::Alignment alignment() const; void setAlignment(int alignment); - QSize minimumSizeHint() const Q_DECL_OVERRIDE; + QSize minimumSizeHint() const override; bool isFlat() const; void setFlat(bool flat); @@ -85,15 +85,15 @@ Q_SIGNALS: void toggled(bool); protected: - bool event(QEvent *event) Q_DECL_OVERRIDE; - void childEvent(QChildEvent *event) Q_DECL_OVERRIDE; - void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; - void focusInEvent(QFocusEvent *event) Q_DECL_OVERRIDE; - void changeEvent(QEvent *event) Q_DECL_OVERRIDE; - void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + bool event(QEvent *event) override; + void childEvent(QChildEvent *event) override; + void resizeEvent(QResizeEvent *event) override; + void paintEvent(QPaintEvent *event) override; + void focusInEvent(QFocusEvent *event) override; + void changeEvent(QEvent *event) override; + void mousePressEvent(QMouseEvent *event) override; + void mouseMoveEvent(QMouseEvent *event) override; + void mouseReleaseEvent(QMouseEvent *event) override; void initStyleOption(QStyleOptionGroupBox *option) const; diff --git a/src/widgets/widgets/qkeysequenceedit.h b/src/widgets/widgets/qkeysequenceedit.h index d5b4b199cd..85d76f14a3 100644 --- a/src/widgets/widgets/qkeysequenceedit.h +++ b/src/widgets/widgets/qkeysequenceedit.h @@ -55,8 +55,8 @@ class Q_WIDGETS_EXPORT QKeySequenceEdit : public QWidget Q_PROPERTY(QKeySequence keySequence READ keySequence WRITE setKeySequence NOTIFY keySequenceChanged USER true) public: - explicit QKeySequenceEdit(QWidget *parent = Q_NULLPTR); - explicit QKeySequenceEdit(const QKeySequence &keySequence, QWidget *parent = Q_NULLPTR); + explicit QKeySequenceEdit(QWidget *parent = nullptr); + explicit QKeySequenceEdit(const QKeySequence &keySequence, QWidget *parent = nullptr); ~QKeySequenceEdit(); QKeySequence keySequence() const; @@ -72,10 +72,10 @@ Q_SIGNALS: protected: QKeySequenceEdit(QKeySequenceEditPrivate &d, QWidget *parent, Qt::WindowFlags f); - bool event(QEvent *) Q_DECL_OVERRIDE; - void keyPressEvent(QKeyEvent *) Q_DECL_OVERRIDE; - void keyReleaseEvent(QKeyEvent *) Q_DECL_OVERRIDE; - void timerEvent(QTimerEvent *) Q_DECL_OVERRIDE; + bool event(QEvent *) override; + void keyPressEvent(QKeyEvent *) override; + void keyReleaseEvent(QKeyEvent *) override; + void timerEvent(QTimerEvent *) override; private: Q_DISABLE_COPY(QKeySequenceEdit) diff --git a/src/widgets/widgets/qlabel.cpp b/src/widgets/widgets/qlabel.cpp index e3225800cc..ee4825d3e5 100644 --- a/src/widgets/widgets/qlabel.cpp +++ b/src/widgets/widgets/qlabel.cpp @@ -66,16 +66,16 @@ QLabelPrivate::QLabelPrivate() sh(), msh(), text(), - pixmap(Q_NULLPTR), - scaledpixmap(Q_NULLPTR), - cachedimage(Q_NULLPTR), + pixmap(nullptr), + scaledpixmap(nullptr), + cachedimage(nullptr), #ifndef QT_NO_PICTURE - picture(Q_NULLPTR), + picture(nullptr), #endif #if QT_CONFIG(movie) movie(), #endif - control(Q_NULLPTR), + control(nullptr), shortcutCursor(), #ifndef QT_NO_CURSOR cursor(), @@ -583,7 +583,7 @@ QSize QLabelPrivate::sizeForWidth(int w) const int m = indent; if (m < 0 && q->frameWidth()) // no indent, but we do have a frame - m = fm.width(QLatin1Char('x')) - margin*2; + m = fm.horizontalAdvance(QLatin1Char('x')) - margin*2; if (m > 0) { if ((align & Qt::AlignLeft) || (align & Qt::AlignRight)) hextra += m; @@ -1440,7 +1440,7 @@ QRect QLabelPrivate::documentRect() const : q->layoutDirection(), QFlag(this->align)); int m = indent; if (m < 0 && q->frameWidth()) // no indent, but we do have a frame - m = q->fontMetrics().width(QLatin1Char('x')) / 2 - margin; + m = q->fontMetrics().horizontalAdvance(QLatin1Char('x')) / 2 - margin; if (m > 0) { if (align & Qt::AlignLeft) cr.setLeft(cr.left() + m); diff --git a/src/widgets/widgets/qlabel.h b/src/widgets/widgets/qlabel.h index 469254a145..e1cc333a1c 100644 --- a/src/widgets/widgets/qlabel.h +++ b/src/widgets/widgets/qlabel.h @@ -67,8 +67,8 @@ class Q_WIDGETS_EXPORT QLabel : public QFrame Q_PROPERTY(QString selectedText READ selectedText) public: - explicit QLabel(QWidget *parent=Q_NULLPTR, Qt::WindowFlags f=Qt::WindowFlags()); - explicit QLabel(const QString &text, QWidget *parent=Q_NULLPTR, Qt::WindowFlags f=Qt::WindowFlags()); + explicit QLabel(QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags()); + explicit QLabel(const QString &text, QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags()); ~QLabel(); QString text() const; @@ -97,13 +97,13 @@ public: bool hasScaledContents() const; void setScaledContents(bool); - QSize sizeHint() const Q_DECL_OVERRIDE; - QSize minimumSizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; + QSize minimumSizeHint() const override; #ifndef QT_NO_SHORTCUT void setBuddy(QWidget *); QWidget *buddy() const; #endif - int heightForWidth(int) const Q_DECL_OVERRIDE; + int heightForWidth(int) const override; bool openExternalLinks() const; void setOpenExternalLinks(bool open); @@ -134,19 +134,19 @@ Q_SIGNALS: void linkHovered(const QString& link); protected: - bool event(QEvent *e) Q_DECL_OVERRIDE; - void keyPressEvent(QKeyEvent *ev) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; - void changeEvent(QEvent *) Q_DECL_OVERRIDE; - void mousePressEvent(QMouseEvent *ev) Q_DECL_OVERRIDE; - void mouseMoveEvent(QMouseEvent *ev) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent *ev) Q_DECL_OVERRIDE; + bool event(QEvent *e) override; + void keyPressEvent(QKeyEvent *ev) override; + void paintEvent(QPaintEvent *) override; + void changeEvent(QEvent *) override; + void mousePressEvent(QMouseEvent *ev) override; + void mouseMoveEvent(QMouseEvent *ev) override; + void mouseReleaseEvent(QMouseEvent *ev) override; #ifndef QT_NO_CONTEXTMENU - void contextMenuEvent(QContextMenuEvent *ev) Q_DECL_OVERRIDE; + void contextMenuEvent(QContextMenuEvent *ev) override; #endif // QT_NO_CONTEXTMENU - void focusInEvent(QFocusEvent *ev) Q_DECL_OVERRIDE; - void focusOutEvent(QFocusEvent *ev) Q_DECL_OVERRIDE; - bool focusNextPrevChild(bool next) Q_DECL_OVERRIDE; + void focusInEvent(QFocusEvent *ev) override; + void focusOutEvent(QFocusEvent *ev) override; + bool focusNextPrevChild(bool next) override; private: diff --git a/src/widgets/widgets/qlcdnumber.h b/src/widgets/widgets/qlcdnumber.h index 28fd530e6e..644c39eaf3 100644 --- a/src/widgets/widgets/qlcdnumber.h +++ b/src/widgets/widgets/qlcdnumber.h @@ -59,8 +59,8 @@ class Q_WIDGETS_EXPORT QLCDNumber : public QFrame // LCD number widget Q_PROPERTY(int intValue READ intValue WRITE display) public: - explicit QLCDNumber(QWidget* parent = Q_NULLPTR); - explicit QLCDNumber(uint numDigits, QWidget* parent = Q_NULLPTR); + explicit QLCDNumber(QWidget* parent = nullptr); + explicit QLCDNumber(uint numDigits, QWidget* parent = nullptr); ~QLCDNumber(); enum Mode { @@ -88,7 +88,7 @@ public: double value() const; int intValue() const; - QSize sizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; public Q_SLOTS: void display(const QString &str); @@ -104,8 +104,8 @@ Q_SIGNALS: void overflow(); protected: - bool event(QEvent *e) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; + bool event(QEvent *e) override; + void paintEvent(QPaintEvent *) override; public: diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp index 13b204e825..e3b348f0ef 100644 --- a/src/widgets/widgets/qlineedit.cpp +++ b/src/widgets/widgets/qlineedit.cpp @@ -80,7 +80,10 @@ #include "private/qapplication_p.h" #include "private/qshortcutmap_p.h" #include "qkeysequence.h" -#define ACCEL_KEY(k) (!qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? \ +#define ACCEL_KEY(k) ((qApp->testAttribute(Qt::AA_DontShowIconsInMenus) \ + ? false \ + : qApp->styleHints()->showShortcutsInContextMenus()) \ + && !qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? \ QLatin1Char('\t') + QKeySequence(k).toString(QKeySequence::NativeText) : QString()) #else #define ACCEL_KEY(k) QString() @@ -93,10 +96,6 @@ QT_BEGIN_NAMESPACE -#if 0 // Used to be included in Qt4 for Q_WS_MAC -extern void qt_mac_secure_keyboard(bool); //qapplication_mac.cpp -#endif - /*! Initialize \a option with the values from this QLineEdit. This method is useful for subclasses when they need a QStyleOptionFrame, but don't want @@ -232,10 +231,10 @@ void QLineEdit::initStyleOption(QStyleOptionFrame *option) const */ /*! - \fn void QLineEdit::cursorPositionChanged(int old, int new) + \fn void QLineEdit::cursorPositionChanged(int oldPos, int newPos) This signal is emitted whenever the cursor moves. The previous - position is given by \a old, and the new position by \a new. + position is given by \a oldPos, and the new position by \a newPos. \sa setCursorPosition(), cursorPosition() */ @@ -578,10 +577,6 @@ void QLineEdit::setEchoMode(EchoMode mode) setInputMethodHints(imHints); d->control->setEchoMode(mode); update(); -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (hasFocus()) - qt_mac_secure_keyboard(mode == Password || mode == NoEcho); -#endif } @@ -687,7 +682,7 @@ QSize QLineEdit::sizeHint() const int h = qMax(fm.height(), 14) + 2*d->verticalMargin + d->topTextMargin + d->bottomTextMargin + d->topmargin + d->bottommargin; - int w = fm.width(QLatin1Char('x')) * 17 + 2*d->horizontalMargin + int w = fm.horizontalAdvance(QLatin1Char('x')) * 17 + 2*d->horizontalMargin + d->effectiveLeftTextMargin() + d->effectiveRightTextMargin() + d->leftmargin + d->rightmargin; // "some" QStyleOptionFrame opt; @@ -964,6 +959,8 @@ QString QLineEdit::selectedText() const line edit or -1 if no text is selected. \sa selectedText() + \sa selectionEnd() + \sa selectionLength() */ int QLineEdit::selectionStart() const @@ -972,8 +969,33 @@ int QLineEdit::selectionStart() const return d->control->selectionStart(); } +/*! + Returns the index of the character directly after the selection + in the line edit or -1 if no text is selected. + \since 5.10 + + \sa selectedText() + \sa selectionStart() + \sa selectionLength() +*/ +int QLineEdit::selectionEnd() const +{ + Q_D(const QLineEdit); + return d->control->selectionEnd(); +} +/*! + Returns the length of the selection. + \since 5.10 + \sa selectedText() + \sa selectionStart() + \sa selectionEnd() +*/ +int QLineEdit::selectionLength() const +{ + return selectionEnd() - selectionStart(); +} /*! Selects text from position \a start and for \a length characters. @@ -1444,6 +1466,8 @@ bool QLineEdit::event(QEvent * e) #endif } else if (e->type() == QEvent::Resize) { d->positionSideWidgets(); + } else if (e->type() == QEvent::StyleChange) { + d->initMouseYThreshold(); } #ifdef QT_KEYPAD_NAVIGATION if (QApplication::keypadNavigationEnabled()) { @@ -1524,7 +1548,17 @@ void QLineEdit::mouseMoveEvent(QMouseEvent * e) const bool select = (d->imHints & Qt::ImhNoPredictiveText); #endif #ifndef QT_NO_IM - if (d->control->composeMode() && select) { + if (d->mouseYThreshold > 0 && e->pos().y() > d->mousePressPos.y() + d->mouseYThreshold) { + if (layoutDirection() == Qt::RightToLeft) + d->control->home(select); + else + d->control->end(select); + } else if (d->mouseYThreshold > 0 && e->pos().y() + d->mouseYThreshold < d->mousePressPos.y()) { + if (layoutDirection() == Qt::RightToLeft) + d->control->end(select); + else + d->control->home(select); + } else if (d->control->composeMode() && select) { int startPos = d->xToPos(d->mousePressPos.x()); int currentPos = d->xToPos(e->pos().x()); if (startPos != currentPos) @@ -1563,7 +1597,7 @@ void QLineEdit::mouseReleaseEvent(QMouseEvent* e) d->control->copy(QClipboard::Selection); } else if (!d->control->isReadOnly() && e->button() == Qt::MidButton) { deselect(); - insert(QApplication::clipboard()->text(QClipboard::Selection)); + d->control->paste(QClipboard::Selection); } } #endif @@ -1818,10 +1852,6 @@ void QLineEdit::focusInEvent(QFocusEvent *e) if((!hasSelectedText() && d->control->preeditAreaText().isEmpty()) || style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this)) d->setCursorVisible(true); -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (d->control->echoMode() == Password || d->control->echoMode() == NoEcho) - qt_mac_secure_keyboard(true); -#endif #ifdef QT_KEYPAD_NAVIGATION d->control->setCancelText(d->control->text()); } @@ -1866,10 +1896,6 @@ void QLineEdit::focusOutEvent(QFocusEvent *e) if (hasAcceptableInput() || d->control->fixup()) emit editingFinished(); } -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (d->control->echoMode() == Password || d->control->echoMode() == NoEcho) - qt_mac_secure_keyboard(false); -#endif #ifdef QT_KEYPAD_NAVIGATION d->control->setCancelText(QString()); #endif diff --git a/src/widgets/widgets/qlineedit.h b/src/widgets/widgets/qlineedit.h index 08dd6f3b83..099bf4bb18 100644 --- a/src/widgets/widgets/qlineedit.h +++ b/src/widgets/widgets/qlineedit.h @@ -90,8 +90,8 @@ public: }; Q_ENUM(ActionPosition) - explicit QLineEdit(QWidget *parent = Q_NULLPTR); - explicit QLineEdit(const QString &, QWidget *parent = Q_NULLPTR); + explicit QLineEdit(QWidget *parent = nullptr); + explicit QLineEdit(const QString &, QWidget *parent = nullptr); ~QLineEdit(); QString text() const; @@ -128,8 +128,8 @@ public: QCompleter *completer() const; #endif - QSize sizeHint() const Q_DECL_OVERRIDE; - QSize minimumSizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; + QSize minimumSizeHint() const override; int cursorPosition() const; void setCursorPosition(int); @@ -154,6 +154,8 @@ public: bool hasSelectedText() const; QString selectedText() const; int selectionStart() const; + int selectionEnd() const; + int selectionLength() const; bool isUndoAvailable() const; bool isRedoAvailable() const; @@ -207,31 +209,31 @@ Q_SIGNALS: void selectionChanged(); protected: - void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE; - void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE; - void mouseDoubleClickEvent(QMouseEvent *) Q_DECL_OVERRIDE; - void keyPressEvent(QKeyEvent *) Q_DECL_OVERRIDE; - void focusInEvent(QFocusEvent *) Q_DECL_OVERRIDE; - void focusOutEvent(QFocusEvent *) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; + void mousePressEvent(QMouseEvent *) override; + void mouseMoveEvent(QMouseEvent *) override; + void mouseReleaseEvent(QMouseEvent *) override; + void mouseDoubleClickEvent(QMouseEvent *) override; + void keyPressEvent(QKeyEvent *) override; + void focusInEvent(QFocusEvent *) override; + void focusOutEvent(QFocusEvent *) override; + void paintEvent(QPaintEvent *) override; #ifndef QT_NO_DRAGANDDROP - void dragEnterEvent(QDragEnterEvent *) Q_DECL_OVERRIDE; - void dragMoveEvent(QDragMoveEvent *e) Q_DECL_OVERRIDE; - void dragLeaveEvent(QDragLeaveEvent *e) Q_DECL_OVERRIDE; - void dropEvent(QDropEvent *) Q_DECL_OVERRIDE; + void dragEnterEvent(QDragEnterEvent *) override; + void dragMoveEvent(QDragMoveEvent *e) override; + void dragLeaveEvent(QDragLeaveEvent *e) override; + void dropEvent(QDropEvent *) override; #endif - void changeEvent(QEvent *) Q_DECL_OVERRIDE; + void changeEvent(QEvent *) override; #ifndef QT_NO_CONTEXTMENU - void contextMenuEvent(QContextMenuEvent *) Q_DECL_OVERRIDE; + void contextMenuEvent(QContextMenuEvent *) override; #endif - void inputMethodEvent(QInputMethodEvent *) Q_DECL_OVERRIDE; + void inputMethodEvent(QInputMethodEvent *) override; void initStyleOption(QStyleOptionFrame *option) const; public: - QVariant inputMethodQuery(Qt::InputMethodQuery) const Q_DECL_OVERRIDE; + QVariant inputMethodQuery(Qt::InputMethodQuery) const override; Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery property, QVariant argument) const; - bool event(QEvent *) Q_DECL_OVERRIDE; + bool event(QEvent *) override; protected: QRect cursorRect() const; diff --git a/src/widgets/widgets/qlineedit_p.cpp b/src/widgets/widgets/qlineedit_p.cpp index 5b352f5554..6a8af53c97 100644 --- a/src/widgets/widgets/qlineedit_p.cpp +++ b/src/widgets/widgets/qlineedit_p.cpp @@ -56,6 +56,7 @@ #endif #include <qpainter.h> #include <qpropertyanimation.h> +#include <qstylehints.h> #include <qvalidator.h> QT_BEGIN_NAMESPACE @@ -232,6 +233,13 @@ void QLineEditPrivate::init(const QString& txt) q->setAcceptDrops(true); q->setAttribute(Qt::WA_MacShowFocusRect); + + initMouseYThreshold(); +} + +void QLineEditPrivate::initMouseYThreshold() +{ + mouseYThreshold = QGuiApplication::styleHints()->mouseQuickSelectionThreshold(); } QRect QLineEditPrivate::adjustedContentsRect() const @@ -330,13 +338,13 @@ QLineEditIconButton::QLineEditIconButton(QWidget *parent) QLineEditPrivate *QLineEditIconButton::lineEditPrivate() const { QLineEdit *le = qobject_cast<QLineEdit *>(parentWidget()); - return le ? static_cast<QLineEditPrivate *>(qt_widget_private(le)) : Q_NULLPTR; + return le ? static_cast<QLineEditPrivate *>(qt_widget_private(le)) : nullptr; } void QLineEditIconButton::paintEvent(QPaintEvent *) { QPainter painter(this); - QWindow *window = Q_NULLPTR; + QWindow *window = nullptr; if (const QWidget *nativeParent = nativeParentWidget()) window = nativeParent->windowHandle(); // Note isDown should really use the active state but in most styles diff --git a/src/widgets/widgets/qlineedit_p.h b/src/widgets/widgets/qlineedit_p.h index 77a91880df..39f670b0b0 100644 --- a/src/widgets/widgets/qlineedit_p.h +++ b/src/widgets/widgets/qlineedit_p.h @@ -94,8 +94,8 @@ public: #endif protected: - void actionEvent(QActionEvent *e) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; + void actionEvent(QActionEvent *e) override; + void paintEvent(QPaintEvent *event) override; private slots: void updateCursor(); @@ -141,7 +141,7 @@ public: dragEnabled(0), clickCausedFocus(0), hscroll(0), vscroll(0), alignment(Qt::AlignLeading | Qt::AlignVCenter), leftTextMargin(0), topTextMargin(0), rightTextMargin(0), bottomTextMargin(0), - lastTextSize(0) + lastTextSize(0), mouseYThreshold(0) { } @@ -155,6 +155,7 @@ public: QPointer<QAction> selectAllAction; #endif void init(const QString&); + void initMouseYThreshold(); QRect adjustedControlRect(const QRect &) const; @@ -253,6 +254,7 @@ private: SideWidgetEntryList leadingSideWidgets; SideWidgetEntryList trailingSideWidgets; int lastTextSize; + int mouseYThreshold; }; Q_DECLARE_TYPEINFO(QLineEditPrivate::SideWidgetEntry, Q_PRIMITIVE_TYPE); Q_DECLARE_TYPEINFO(QLineEditPrivate::SideWidgetLocation, Q_PRIMITIVE_TYPE); diff --git a/src/widgets/widgets/qmaccocoaviewcontainer_mac.h b/src/widgets/widgets/qmaccocoaviewcontainer_mac.h index d926ef8569..0de3989167 100644 --- a/src/widgets/widgets/qmaccocoaviewcontainer_mac.h +++ b/src/widgets/widgets/qmaccocoaviewcontainer_mac.h @@ -52,7 +52,7 @@ class Q_WIDGETS_EXPORT QMacCocoaViewContainer : public QWidget { Q_OBJECT public: - QMacCocoaViewContainer(NSView *cocoaViewToWrap, QWidget *parent = Q_NULLPTR); + QMacCocoaViewContainer(NSView *cocoaViewToWrap, QWidget *parent = nullptr); virtual ~QMacCocoaViewContainer(); void setCocoaView(NSView *view); diff --git a/src/widgets/widgets/qmaccocoaviewcontainer_mac.mm b/src/widgets/widgets/qmaccocoaviewcontainer_mac.mm index 610df2125b..98ee90deb7 100644 --- a/src/widgets/widgets/qmaccocoaviewcontainer_mac.mm +++ b/src/widgets/widgets/qmaccocoaviewcontainer_mac.mm @@ -108,11 +108,9 @@ QMacCocoaViewContainerPrivate::~QMacCocoaViewContainerPrivate() } /*! - \fn QMacCocoaViewContainer::QMacCocoaViewContainer(NSView *cocoaViewToWrap, QWidget *parent) - - Create a new QMacCocoaViewContainer using the NSView pointer in \a - cocoaViewToWrap with parent, \a parent. QMacCocoaViewContainer will - retain \a cocoaViewToWrap. + Create a new QMacCocoaViewContainer using the NSView pointer in + the \a view with parent, \a parent. QMacCocoaViewContainer will + retain the \a view. */ QMacCocoaViewContainer::QMacCocoaViewContainer(NSView *view, QWidget *parent) diff --git a/src/widgets/widgets/qmacnativewidget_mac.h b/src/widgets/widgets/qmacnativewidget_mac.h index a8faffd6be..6fd90516ac 100644 --- a/src/widgets/widgets/qmacnativewidget_mac.h +++ b/src/widgets/widgets/qmacnativewidget_mac.h @@ -51,7 +51,7 @@ class Q_WIDGETS_EXPORT QMacNativeWidget : public QWidget { Q_OBJECT public: - QMacNativeWidget(NSView *parentView = Q_NULLPTR); + QMacNativeWidget(NSView *parentView = nullptr); ~QMacNativeWidget(); QSize sizeHint() const override; diff --git a/src/widgets/widgets/qmacnativewidget_mac.mm b/src/widgets/widgets/qmacnativewidget_mac.mm index 9ad8aa1305..874ca84b61 100644 --- a/src/widgets/widgets/qmacnativewidget_mac.mm +++ b/src/widgets/widgets/qmacnativewidget_mac.mm @@ -145,8 +145,7 @@ QSize QMacNativeWidget::sizeHint() const return QWidget::sizeHint(); } -/*! \fn NSView *QMacNativeWidget::nativeView() const - +/*! Returns the native view backing the QMacNativeWidget. */ diff --git a/src/widgets/widgets/qmainwindow.cpp b/src/widgets/widgets/qmainwindow.cpp index ced7ec38ea..bf0a88e7fb 100644 --- a/src/widgets/widgets/qmainwindow.cpp +++ b/src/widgets/widgets/qmainwindow.cpp @@ -66,13 +66,6 @@ #ifdef Q_OS_OSX #include <qpa/qplatformnativeinterface.h> #endif -#if 0 // Used to be included in Qt4 for Q_WS_MAC -#include <private/qt_mac_p.h> -#include <private/qt_cocoa_helpers_mac_p.h> -QT_BEGIN_NAMESPACE -extern OSWindowRef qt_mac_window_for(const QWidget *); // qwidget_mac.cpp -QT_END_NAMESPACE -#endif QT_BEGIN_NAMESPACE @@ -85,13 +78,6 @@ public: #ifdef Q_OS_OSX , useUnifiedToolBar(false) #endif -#if 0 // Used to be included in Qt4 for Q_WS_MAC - , useHIToolBar(false) - , activateUnifiedToolbarAfterFullScreen(false) -#endif -#if QT_CONFIG(dockwidget) && !defined(QT_NO_CURSOR) - , hasOldCursor(false) , cursorAdjusted(false) -#endif { } QMainWindowLayout *layout; QSize iconSize; @@ -100,22 +86,7 @@ public: #ifdef Q_OS_OSX bool useUnifiedToolBar; #endif -#if 0 // Used to be included in Qt4 for Q_WS_MAC - bool useHIToolBar; - bool activateUnifiedToolbarAfterFullScreen; -#endif void init(); - QList<int> hoverSeparator; - QPoint hoverPos; - -#if QT_CONFIG(dockwidget) && !defined(QT_NO_CURSOR) - QCursor separatorCursor(const QList<int> &path) const; - void adjustCursor(const QPoint &pos); - QCursor oldCursor; - QCursor adjustedCursor; - uint hasOldCursor : 1; - uint cursorAdjusted : 1; -#endif static inline QMainWindowLayout *mainWindowLayout(const QMainWindow *mainWindow) { @@ -811,11 +782,7 @@ void QMainWindow::addToolBar(Qt::ToolBarArea area, QToolBar *toolbar) #endif } - if (!d->layout->usesHIToolBar(toolbar)) { - d->layout->removeWidget(toolbar); - } else { - d->layout->removeToolBar(toolbar); - } + d->layout->removeToolBar(toolbar); toolbar->d_func()->_q_updateIconSize(d->iconSize); toolbar->d_func()->_q_updateToolButtonStyle(d->toolButtonStyle); @@ -984,7 +951,9 @@ void QMainWindow::setDockNestingEnabled(bool enabled) } #if 0 -/*! \property QMainWindow::verticalTabsEnabled +// If added back in, add the '!' to the qdoc comment marker as well. +/* + \property QMainWindow::verticalTabsEnabled \brief whether left and right dock areas use vertical tabs \since 4.2 @@ -1117,21 +1086,6 @@ void QMainWindow::addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget } d_func()->layout->removeWidget(dockwidget); // in case it was already in here addDockWidget(area, dockwidget, orientation); - -#if 0 // Used to be included in Qt4 for Q_WS_MAC //drawer support - QMacAutoReleasePool pool; - extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp - if (qt_mac_is_macdrawer(dockwidget)) { - extern bool qt_mac_set_drawer_preferred_edge(QWidget *, Qt::DockWidgetArea); //qwidget_mac.cpp - window()->createWinId(); - dockwidget->window()->createWinId(); - qt_mac_set_drawer_preferred_edge(dockwidget, area); - if (dockwidget->isVisible()) { - dockwidget->hide(); - dockwidget->show(); - } - } -#endif } /*! @@ -1350,153 +1304,14 @@ bool QMainWindow::restoreState(const QByteArray &state, int version) return restored; } -#if QT_CONFIG(dockwidget) && !defined(QT_NO_CURSOR) -QCursor QMainWindowPrivate::separatorCursor(const QList<int> &path) const -{ - QDockAreaLayoutInfo *info = layout->layoutState.dockAreaLayout.info(path); - Q_ASSERT(info != 0); - if (path.size() == 1) { // is this the "top-level" separator which separates a dock area - // from the central widget? - switch (path.first()) { - case QInternal::LeftDock: - case QInternal::RightDock: - return Qt::SplitHCursor; - case QInternal::TopDock: - case QInternal::BottomDock: - return Qt::SplitVCursor; - default: - break; - } - } - - // no, it's a splitter inside a dock area, separating two dock widgets - - return info->o == Qt::Horizontal - ? Qt::SplitHCursor : Qt::SplitVCursor; -} - -void QMainWindowPrivate::adjustCursor(const QPoint &pos) -{ - Q_Q(QMainWindow); - - hoverPos = pos; - - if (pos == QPoint(0, 0)) { - if (!hoverSeparator.isEmpty()) - q->update(layout->layoutState.dockAreaLayout.separatorRect(hoverSeparator)); - hoverSeparator.clear(); - - if (cursorAdjusted) { - cursorAdjusted = false; - if (hasOldCursor) - q->setCursor(oldCursor); - else - q->unsetCursor(); - } - } else if (layout->movingSeparator.isEmpty()) { // Don't change cursor when moving separator - QList<int> pathToSeparator - = layout->layoutState.dockAreaLayout.findSeparator(pos); - - if (pathToSeparator != hoverSeparator) { - if (!hoverSeparator.isEmpty()) - q->update(layout->layoutState.dockAreaLayout.separatorRect(hoverSeparator)); - - hoverSeparator = pathToSeparator; - - if (hoverSeparator.isEmpty()) { - if (cursorAdjusted) { - cursorAdjusted = false; - if (hasOldCursor) - q->setCursor(oldCursor); - else - q->unsetCursor(); - } - } else { - q->update(layout->layoutState.dockAreaLayout.separatorRect(hoverSeparator)); - if (!cursorAdjusted) { - oldCursor = q->cursor(); - hasOldCursor = q->testAttribute(Qt::WA_SetCursor); - } - adjustedCursor = separatorCursor(hoverSeparator); - q->setCursor(adjustedCursor); - cursorAdjusted = true; - } - } - } -} -#endif - /*! \reimp */ bool QMainWindow::event(QEvent *event) { Q_D(QMainWindow); + if (d->layout && d->layout->windowEvent(event)) + return true; switch (event->type()) { -#if QT_CONFIG(dockwidget) - case QEvent::Paint: { - QPainter p(this); - QRegion r = static_cast<QPaintEvent*>(event)->region(); - d->layout->layoutState.dockAreaLayout.paintSeparators(&p, this, r, d->hoverPos); - break; - } - -#ifndef QT_NO_CURSOR - case QEvent::HoverMove: { - d->adjustCursor(static_cast<QHoverEvent*>(event)->pos()); - break; - } - - // We don't want QWidget to call update() on the entire QMainWindow - // on HoverEnter and HoverLeave, hence accept the event (return true). - case QEvent::HoverEnter: - return true; - case QEvent::HoverLeave: - d->adjustCursor(QPoint(0, 0)); - return true; - case QEvent::ShortcutOverride: // when a menu pops up - d->adjustCursor(QPoint(0, 0)); - break; -#endif // QT_NO_CURSOR - - case QEvent::MouseButtonPress: { - QMouseEvent *e = static_cast<QMouseEvent*>(event); - if (e->button() == Qt::LeftButton && d->layout->startSeparatorMove(e->pos())) { - // The click was on a separator, eat this event - e->accept(); - return true; - } - break; - } - - case QEvent::MouseMove: { - QMouseEvent *e = static_cast<QMouseEvent*>(event); - -#ifndef QT_NO_CURSOR - d->adjustCursor(e->pos()); -#endif - if (e->buttons() & Qt::LeftButton) { - if (d->layout->separatorMove(e->pos())) { - // We're moving a separator, eat this event - e->accept(); - return true; - } - } - - break; - } - - case QEvent::MouseButtonRelease: { - QMouseEvent *e = static_cast<QMouseEvent*>(event); - if (d->layout->endSeparatorMove(e->pos())) { - // We've released a separator, eat this event - e->accept(); - return true; - } - break; - } - -#endif - #ifndef QT_NO_TOOLBAR case QEvent::ToolBarChange: { d->layout->toggleToolBarsVisible(); @@ -1522,40 +1337,6 @@ bool QMainWindow::event(QEvent *event) if (!d->explicitIconSize) setIconSize(QSize()); break; -#if 0 // Used to be included in Qt4 for Q_WS_MAC - case QEvent::Show: - if (unifiedTitleAndToolBarOnMac()) - d->layout->syncUnifiedToolbarVisibility(); - d->layout->blockVisiblityCheck = false; - break; - case QEvent::WindowStateChange: - { - if (isHidden()) { - // We are coming out of a minimize, leave things as is. - d->layout->blockVisiblityCheck = true; - } - // We need to update the HIToolbar status when we go out of or into fullscreen. - QWindowStateChangeEvent *wce = static_cast<QWindowStateChangeEvent *>(event); - if ((windowState() & Qt::WindowFullScreen) || (wce->oldState() & Qt::WindowFullScreen)) { - d->layout->updateHIToolBarStatus(); - } - } - break; -#endif -#if QT_CONFIG(dockwidget) && !defined(QT_NO_CURSOR) - case QEvent::CursorChange: - // CursorChange events are triggered as mouse moves to new widgets even - // if the cursor doesn't actually change, so do not change oldCursor if - // the "changed" cursor has same shape as adjusted cursor. - if (d->cursorAdjusted && d->adjustedCursor.shape() != cursor().shape()) { - d->oldCursor = cursor(); - d->hasOldCursor = testAttribute(Qt::WA_SetCursor); - - // Ensure our adjusted cursor stays visible - setCursor(d->adjustedCursor); - } - break; -#endif default: break; } @@ -1595,33 +1376,6 @@ void QMainWindow::setUnifiedTitleAndToolBarOnMac(bool set) (reinterpret_cast<SetContentBorderEnabledFunction>(function))(window()->windowHandle(), set); update(); } -#endif - -#if 0 // Used to be included in Qt4 for Q_WS_MAC - Q_D(QMainWindow); - if (!isWindow() || d->useHIToolBar == set || QSysInfo::MacintoshVersion < QSysInfo::MV_10_3) - return; - - d->useHIToolBar = set; - createWinId(); // We need the hiview for down below. - - // Activate the unified toolbar with the raster engine. - if (windowSurface() && set) { - d->layout->unifiedSurface = new QUnifiedToolbarSurface(this); - } - - d->layout->updateHIToolBarStatus(); - - // Deactivate the unified toolbar with the raster engine. - if (windowSurface() && !set) { - if (d->layout->unifiedSurface) { - delete d->layout->unifiedSurface; - d->layout->unifiedSurface = 0; - } - } - - // Enabling the unified toolbar clears the opaque size grip setting, update it. - d->macUpdateOpaqueSizeGrip(); #else Q_UNUSED(set) #endif @@ -1632,9 +1386,6 @@ bool QMainWindow::unifiedTitleAndToolBarOnMac() const #ifdef Q_OS_OSX return d_func()->useUnifiedToolBar; #endif -#if 0 // Used to be included in Qt4 for Q_WS_MAC - return d_func()->useHIToolBar && !testAttribute(Qt::WA_MacBrushedMetal) && !(windowFlags() & Qt::FramelessWindowHint); -#endif return false; } diff --git a/src/widgets/widgets/qmainwindow.h b/src/widgets/widgets/qmainwindow.h index 50d840cf61..069683d4ac 100644 --- a/src/widgets/widgets/qmainwindow.h +++ b/src/widgets/widgets/qmainwindow.h @@ -91,7 +91,7 @@ public: Q_DECLARE_FLAGS(DockOptions, DockOption) Q_FLAG(DockOptions) - explicit QMainWindow(QWidget *parent = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags()); + explicit QMainWindow(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); ~QMainWindow(); QSize iconSize() const; @@ -203,9 +203,9 @@ Q_SIGNALS: protected: #ifndef QT_NO_CONTEXTMENU - void contextMenuEvent(QContextMenuEvent *event) Q_DECL_OVERRIDE; + void contextMenuEvent(QContextMenuEvent *event) override; #endif - bool event(QEvent *event) Q_DECL_OVERRIDE; + bool event(QEvent *event) override; private: Q_DECLARE_PRIVATE(QMainWindow) diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp index 91c012d8d8..9b38da340c 100644 --- a/src/widgets/widgets/qmainwindowlayout.cpp +++ b/src/widgets/widgets/qmainwindowlayout.cpp @@ -77,10 +77,6 @@ #include <private/qapplication_p.h> #include <private/qlayoutengine_p.h> #include <private/qwidgetresizehandler_p.h> -#if 0 // Used to be included in Qt4 for Q_WS_MAC -# include <private/qcore_mac_p.h> -# include <private/qt_cocoa_helpers_mac_p.h> -#endif QT_BEGIN_NAMESPACE @@ -184,13 +180,17 @@ QDebug operator<<(QDebug debug, const QMainWindowLayout *layout) /****************************************************************************** ** QDockWidgetGroupWindow */ -// QDockWidgetGroupWindow is the floating window containing the tabbed dockwidgets in case several -// dockwidgets are dragged together (QMainWindow::GroupedDragging feature). +// QDockWidgetGroupWindow is the floating window containing several QDockWidgets floating together. +// (QMainWindow::GroupedDragging feature) // QDockWidgetGroupLayout is the layout of that window and use a QDockAreaLayoutInfo to layout -// the tabs inside it. +// the QDockWidgets inside it. +// If there is only one QDockWidgets, or all QDockWidgets are tabbed together, it is equivalent +// of a floating QDockWidget (the title of the QDockWidget is the title of the window). But if there +// are nested QDockWidget, an additional title bar is there. #if QT_CONFIG(dockwidget) -class QDockWidgetGroupLayout : public QLayout { - QDockAreaLayoutInfo info; +class QDockWidgetGroupLayout : public QLayout, + public QMainWindowLayoutSeparatorHelper<QDockWidgetGroupLayout> +{ QWidgetResizeHandler *resizer; public: QDockWidgetGroupLayout(QDockWidgetGroupWindow* parent) : QLayout(parent) { @@ -199,40 +199,51 @@ public: resizer->setMovingEnabled(false); } ~QDockWidgetGroupLayout() { - info.deleteAllLayoutItems(); + layoutState.deleteAllLayoutItems(); } - void addItem(QLayoutItem*) Q_DECL_OVERRIDE { Q_UNREACHABLE(); } - int count() const Q_DECL_OVERRIDE { return 0; } - QLayoutItem* itemAt(int index) const Q_DECL_OVERRIDE + void addItem(QLayoutItem*) override { Q_UNREACHABLE(); } + int count() const override { return 0; } + QLayoutItem* itemAt(int index) const override { int x = 0; - return info.itemAt(&x, index); + return layoutState.itemAt(&x, index); } - QLayoutItem* takeAt(int index) Q_DECL_OVERRIDE + QLayoutItem* takeAt(int index) override { int x = 0; - return info.takeAt(&x, index); + QLayoutItem *ret = layoutState.takeAt(&x, index); + if (savedState.rect.isValid() && ret->widget()) { + // we need to remove the item also from the saved state to prevent crash + QList<int> path = savedState.indexOf(ret->widget()); + if (!path.isEmpty()) + savedState.remove(path); + // Also, the item may be contained several times as a gap item. + path = layoutState.indexOf(ret->widget()); + if (!path.isEmpty()) + layoutState.remove(path); + } + return ret; } - QSize sizeHint() const Q_DECL_OVERRIDE + QSize sizeHint() const override { int fw = frameWidth(); - return info.sizeHint() + QSize(fw, fw); + return layoutState.sizeHint() + QSize(fw, fw); } - QSize minimumSize() const Q_DECL_OVERRIDE + QSize minimumSize() const override { int fw = frameWidth(); - return info.minimumSize() + QSize(fw, fw); + return layoutState.minimumSize() + QSize(fw, fw); } - QSize maximumSize() const Q_DECL_OVERRIDE + QSize maximumSize() const override { int fw = frameWidth(); - return info.maximumSize() + QSize(fw, fw); + return layoutState.maximumSize() + QSize(fw, fw); } - void setGeometry(const QRect&r) Q_DECL_OVERRIDE + void setGeometry(const QRect&r) override { groupWindow()->destroyOrHideIfEmpty(); - QDockAreaLayoutInfo *li = layoutInfo(); + QDockAreaLayoutInfo *li = dockAreaLayoutInfo(); if (li->isEmpty()) return; int fw = frameWidth(); @@ -242,12 +253,12 @@ public: li->rect = r.adjusted(fw, fw, -fw, -fw); li->fitItems(); li->apply(false); + if (savedState.rect.isValid()) + savedState.rect = li->rect; resizer->setActive(QWidgetResizeHandler::Resize, !nativeWindowDeco()); } - QDockAreaLayoutInfo *layoutInfo() { - return &info; - } + QDockAreaLayoutInfo *dockAreaLayoutInfo() { return &layoutState; } bool nativeWindowDeco() const { @@ -264,14 +275,21 @@ public: { return static_cast<QDockWidgetGroupWindow *>(parent()); } + + QDockAreaLayoutInfo layoutState; + QDockAreaLayoutInfo savedState; }; bool QDockWidgetGroupWindow::event(QEvent *e) { + auto lay = static_cast<QDockWidgetGroupLayout *>(layout()); + if (lay && lay->windowEvent(e)) + return true; + switch (e->type()) { case QEvent::Close: // Forward the close to the QDockWidget just as if its close button was pressed - if (QDockWidget *dw = topDockWidget()) { + if (QDockWidget *dw = activeTabbedDockWidget()) { e->ignore(); dw->close(); adjustFlags(); @@ -279,7 +297,7 @@ bool QDockWidgetGroupWindow::event(QEvent *e) return true; case QEvent::Move: // Let QDockWidgetPrivate::moseEvent handle the dragging - if (QDockWidget *dw = topDockWidget()) + if (QDockWidget *dw = activeTabbedDockWidget()) static_cast<QDockWidgetPrivate *>(QObjectPrivate::get(dw))->moveEvent(static_cast<QMoveEvent*>(e)); return true; case QEvent::NonClientAreaMouseMove: @@ -287,7 +305,7 @@ bool QDockWidgetGroupWindow::event(QEvent *e) case QEvent::NonClientAreaMouseButtonRelease: case QEvent::NonClientAreaMouseButtonDblClick: // Let the QDockWidgetPrivate of the currently visible dock widget handle the drag and drop - if (QDockWidget *dw = topDockWidget()) + if (QDockWidget *dw = activeTabbedDockWidget()) static_cast<QDockWidgetPrivate *>(QObjectPrivate::get(dw))->nonClientAreaMouseEvent(static_cast<QMouseEvent*>(e)); return true; case QEvent::ChildAdded: @@ -319,17 +337,49 @@ void QDockWidgetGroupWindow::paintEvent(QPaintEvent *) QDockAreaLayoutInfo *QDockWidgetGroupWindow::layoutInfo() const { - return static_cast<QDockWidgetGroupLayout*>(layout())->layoutInfo(); + return static_cast<QDockWidgetGroupLayout *>(layout())->dockAreaLayoutInfo(); +} + +/*! \internal + If this is a floating tab bar returns the currently the QDockWidgetGroupWindow that contains + tab, otherwise, return nullptr; + \note: if there is only one QDockWidget, it's still considered as a floating tab + */ +const QDockAreaLayoutInfo *QDockWidgetGroupWindow::tabLayoutInfo() const +{ + const QDockAreaLayoutInfo *info = layoutInfo(); + while (info && !info->tabbed) { + // There should be only one tabbed subinfo otherwise we are not a floating tab but a real + // window + const QDockAreaLayoutInfo *next = nullptr; + bool isSingle = false; + for (const auto &item : info->item_list) { + if (item.skip() || (item.flags & QDockAreaLayoutItem::GapItem)) + continue; + if (next || isSingle) // Two visible things + return nullptr; + if (item.subinfo) + next = item.subinfo; + else if (item.widgetItem) + isSingle = true; + } + if (isSingle) + return info; + info = next; + } + return info; } /*! \internal - Returns the currently active QDockWidget. + If this is a floating tab bar returns the currently active QDockWidget, otherwise nullptr */ -QDockWidget *QDockWidgetGroupWindow::topDockWidget() const +QDockWidget *QDockWidgetGroupWindow::activeTabbedDockWidget() const { - QDockAreaLayoutInfo *info = layoutInfo(); - QDockWidget *dw = 0; + QDockWidget *dw = nullptr; #if QT_CONFIG(tabbar) + const QDockAreaLayoutInfo *info = tabLayoutInfo(); + if (!info) + return nullptr; if (info->tabBar && info->tabBar->currentIndex() >= 0) { int i = info->tabIndexToListIndex(info->tabBar->currentIndex()); if (i >= 0) { @@ -338,7 +388,6 @@ QDockWidget *QDockWidgetGroupWindow::topDockWidget() const dw = qobject_cast<QDockWidget *>(item.widgetItem->widget()); } } -#endif if (!dw) { for (int i = 0; !dw && i < info->item_list.count(); ++i) { const QDockAreaLayoutItem &item = info->item_list.at(i); @@ -349,6 +398,7 @@ QDockWidget *QDockWidgetGroupWindow::topDockWidget() const dw = qobject_cast<QDockWidget *>(item.widgetItem->widget()); } } +#endif return dw; } @@ -395,18 +445,18 @@ void QDockWidgetGroupWindow::destroyOrHideIfEmpty() } /*! \internal - Sets the flags of this window in accordence to the capabilities of the dock widgets + Sets the flags of this window in accordance to the capabilities of the dock widgets */ void QDockWidgetGroupWindow::adjustFlags() { - QDockWidget *top = topDockWidget(); - if (!top) - return; - const bool nativeDeco = static_cast<QDockWidgetGroupLayout *>(layout())->nativeWindowDeco(); - Qt::WindowFlags oldFlags = windowFlags(); Qt::WindowFlags flags = oldFlags; - if (nativeDeco) { + + QDockWidget *top = activeTabbedDockWidget(); + if (!top) { // nested tabs, show window decoration + flags = + ((oldFlags & ~Qt::FramelessWindowHint) | Qt::CustomizeWindowHint | Qt::WindowTitleHint); + } else if (static_cast<QDockWidgetGroupLayout *>(layout())->nativeWindowDeco()) { flags |= Qt::CustomizeWindowHint | Qt::WindowTitleHint; flags.setFlag(Qt::WindowCloseButtonHint, top->features() & QDockWidget::DockWidgetClosable); flags &= ~Qt::FramelessWindowHint; @@ -439,21 +489,99 @@ void QDockWidgetGroupWindow::adjustFlags() show(); // setWindowFlags hides the window } - setWindowTitle(top->windowTitle()); - setWindowIcon(top->windowIcon()); + QWidget *titleBarOf = top ? top : parentWidget(); + setWindowTitle(titleBarOf->windowTitle()); + setWindowIcon(titleBarOf->windowIcon()); } bool QDockWidgetGroupWindow::hasNativeDecos() const { + QDockWidget *dw = activeTabbedDockWidget(); + if (!dw) // We have a group of nested QDockWidgets (not just floating tabs) + return true; + if (!QDockWidgetLayout::wmSupportsNativeWindowDeco()) return false; - if (QDockWidget *dw = topDockWidget()) - return dw->titleBarWidget() == nullptr; + return dw->titleBarWidget() == nullptr; +} +/* + The given widget is hovered over this floating group. + This function will save the state and create a gap in the actual state. + currentGapRect and currentGapPos will be set. + One must call restore() or apply() after this function. + Returns true if there was any change in the currentGapPos + */ +bool QDockWidgetGroupWindow::hover(QLayoutItem *widgetItem, const QPoint &mousePos) +{ + QDockAreaLayoutInfo &savedState = static_cast<QDockWidgetGroupLayout *>(layout())->savedState; + if (savedState.isEmpty()) + savedState = *layoutInfo(); + + QMainWindow::DockOptions opts = static_cast<QMainWindow *>(parentWidget())->dockOptions(); + bool nestingEnabled = + (opts & QMainWindow::AllowNestedDocks) && !(opts & QMainWindow::ForceTabbedDocks); + QDockAreaLayoutInfo::TabMode tabMode = + nestingEnabled ? QDockAreaLayoutInfo::AllowTabs : QDockAreaLayoutInfo::ForceTabs; + if (auto group = qobject_cast<QDockWidgetGroupWindow *>(widgetItem->widget())) { + if (!group->tabLayoutInfo()) + tabMode = QDockAreaLayoutInfo::NoTabs; + } + + QDockAreaLayoutInfo newState = savedState; + if (newState.tabbed) { + // insertion into a top-level tab + newState.item_list = { QDockAreaLayoutItem(new QDockAreaLayoutInfo(newState)) }; + newState.item_list.first().size = pick(savedState.o, savedState.rect.size()); + newState.tabbed = false; + newState.tabBar = nullptr; + } + + auto newGapPos = newState.gapIndex(mousePos, nestingEnabled, tabMode); + Q_ASSERT(!newGapPos.isEmpty()); + if (newGapPos == currentGapPos) + return false; // gap is already there + currentGapPos = newGapPos; + newState.insertGap(currentGapPos, widgetItem); + newState.fitItems(); + currentGapRect = newState.info(currentGapPos)->itemRect(currentGapPos.last(), true); + *layoutInfo() = std::move(newState); + layoutInfo()->apply(opts & QMainWindow::AnimatedDocks); return true; } +/* + Remove the gap that was created by hover() + */ +void QDockWidgetGroupWindow::restore() +{ + QDockAreaLayoutInfo &savedState = static_cast<QDockWidgetGroupLayout *>(layout())->savedState; + if (!savedState.isEmpty()) { + *layoutInfo() = savedState; + savedState = QDockAreaLayoutInfo(); + } + currentGapRect = QRect(); + currentGapPos.clear(); + adjustFlags(); + layoutInfo()->fitItems(); + layoutInfo()->apply(static_cast<QMainWindow *>(parentWidget())->dockOptions() + & QMainWindow::AnimatedDocks); +} + +/* + Apply the state that was created by hover + */ +void QDockWidgetGroupWindow::apply() +{ + static_cast<QDockWidgetGroupLayout *>(layout())->savedState.clear(); + currentGapRect = QRect(); + layoutInfo()->plug(currentGapPos); + currentGapPos.clear(); + adjustFlags(); + layoutInfo()->apply(false); +} + #endif /****************************************************************************** @@ -707,7 +835,14 @@ QList<int> QMainWindowLayoutState::gapIndex(QWidget *widget, // is it a dock widget? if (qobject_cast<QDockWidget *>(widget) != 0 || qobject_cast<QDockWidgetGroupWindow *>(widget)) { - result = dockAreaLayout.gapIndex(pos); + bool disallowTabs = false; +#if QT_CONFIG(tabbar) + if (auto *group = qobject_cast<QDockWidgetGroupWindow *>(widget)) { + if (!group->tabLayoutInfo()) // Disallow to drop nested docks as a tab + disallowTabs = true; + } +#endif + result = dockAreaLayout.gapIndex(pos, disallowTabs); if (!result.isEmpty()) result.prepend(1); return result; @@ -1190,14 +1325,7 @@ void QMainWindowLayout::removeToolBar(QToolBar *toolbar) QObject::disconnect(parentWidget(), SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)), toolbar, SLOT(_q_updateToolButtonStyle(Qt::ToolButtonStyle))); -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (usesHIToolBar(toolbar)) { - removeFromMacToolbar(toolbar); - } else -#endif - { - removeWidget(toolbar); - } + removeWidget(toolbar); } } @@ -1209,25 +1337,17 @@ void QMainWindowLayout::addToolBar(Qt::ToolBarArea area, bool) { validateToolBarArea(area); -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if ((area == Qt::TopToolBarArea) - && layoutState.mainWindow->unifiedTitleAndToolBarOnMac()) { - insertIntoMacToolbar(0, toolbar); - } else -#endif - { - //let's add the toolbar to the layout - addChildWidget(toolbar); - QLayoutItem * item = layoutState.toolBarAreaLayout.addToolBar(toDockPos(area), toolbar); - if (savedState.isValid() && item) { - // copy the toolbar also in the saved state - savedState.toolBarAreaLayout.insertItem(toDockPos(area), item); - } - invalidate(); - - //this ensures that the toolbar has the right window flags (not floating any more) - toolbar->d_func()->updateWindowFlags(false /*floating*/); + // let's add the toolbar to the layout + addChildWidget(toolbar); + QLayoutItem *item = layoutState.toolBarAreaLayout.addToolBar(toDockPos(area), toolbar); + if (savedState.isValid() && item) { + // copy the toolbar also in the saved state + savedState.toolBarAreaLayout.insertItem(toDockPos(area), item); } + invalidate(); + + // this ensures that the toolbar has the right window flags (not floating any more) + toolbar->d_func()->updateWindowFlags(false /*floating*/); } /*! @@ -1235,27 +1355,20 @@ void QMainWindowLayout::addToolBar(Qt::ToolBarArea area, */ void QMainWindowLayout::insertToolBar(QToolBar *before, QToolBar *toolbar) { -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (usesHIToolBar(before)) { - insertIntoMacToolbar(before, toolbar); - } else -#endif - { - addChildWidget(toolbar); - QLayoutItem * item = layoutState.toolBarAreaLayout.insertToolBar(before, toolbar); - if (savedState.isValid() && item) { - // copy the toolbar also in the saved state - savedState.toolBarAreaLayout.insertItem(before, item); + addChildWidget(toolbar); + QLayoutItem *item = layoutState.toolBarAreaLayout.insertToolBar(before, toolbar); + if (savedState.isValid() && item) { + // copy the toolbar also in the saved state + savedState.toolBarAreaLayout.insertItem(before, item); + } + if (!currentGapPos.isEmpty() && currentGapPos.constFirst() == 0) { + currentGapPos = layoutState.toolBarAreaLayout.currentGapIndex(); + if (!currentGapPos.isEmpty()) { + currentGapPos.prepend(0); + currentGapRect = layoutState.itemRect(currentGapPos); } - if (!currentGapPos.isEmpty() && currentGapPos.constFirst() == 0) { - currentGapPos = layoutState.toolBarAreaLayout.currentGapIndex(); - if (!currentGapPos.isEmpty()) { - currentGapPos.prepend(0); - currentGapRect = layoutState.itemRect(currentGapPos); - } - } - invalidate(); } + invalidate(); } Qt::ToolBarArea QMainWindowLayout::toolBarArea(QToolBar *toolbar) const @@ -1268,12 +1381,6 @@ Qt::ToolBarArea QMainWindowLayout::toolBarArea(QToolBar *toolbar) const case QInternal::BottomDock: return Qt::BottomToolBarArea; default: break; } -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (pos == QInternal::DockCount) { - if (qtoolbarsInUnifiedToolbarList.contains(toolbar)) - return Qt::TopToolBarArea; - } -#endif return Qt::NoToolBarArea; } @@ -1290,70 +1397,15 @@ void QMainWindowLayout::getStyleOptionInfo(QStyleOptionToolBar *option, QToolBar void QMainWindowLayout::toggleToolBarsVisible() { - bool updateNonUnifiedParts = true; -#if 0 // Used to be included in Qt4 for Q_WS_MAC - if (layoutState.mainWindow->unifiedTitleAndToolBarOnMac()) { - // If we hit this case, someone has pressed the "toolbar button" which will - // toggle the unified toolbar visibility, because that's what the user wants. - // We might be in a situation where someone has hidden all the toolbars - // beforehand (maybe in construction), but now they've hit this button and - // and are expecting the items to show. What do we do? - // 1) Check the visibility of all the toolbars, if one is visible, do nothing, this - // preserves what people would expect (these toolbars were visible when I clicked last time). - // 2) If NONE are visible, then show them all. Again, this preserves the user expectation - // of, "I want to see the toolbars." The user may get more toolbars than expected, but this - // is better seeing nothing. - // Don't worry about any of this if we are going invisible. This does mean we may get - // into issues when switching into and out of fullscreen mode, but this is probably minor. - // If we ever need to do hiding, that would have to be taken care of after the unified toolbar - // has finished hiding. - // People can of course handle the QEvent::ToolBarChange event themselves and do - // WHATEVER they want if they don't like what we are doing (though the unified toolbar - // will fire regardless). - - // Check if we REALLY need to update the geometry below. If we only have items in the - // unified toolbar, all the docks will be empty, so there's very little point - // in doing the geometry as Apple will do it (we also avoid flicker in Cocoa as well). - // FWIW, layoutState.toolBarAreaLayout.visible and the state of the unified toolbar - // visibility can get out of sync. I really don't think it's a big issue. It is kept - // to a minimum because we only change the visibility if we absolutely must. - // update the "non unified parts." - updateNonUnifiedParts = !layoutState.toolBarAreaLayout.isEmpty(); - - // We get this function before the unified toolbar does its thing. - // So, the value will be opposite of what we expect. - bool goingVisible = !macWindowToolbarIsVisible(qt_mac_window_for(layoutState.mainWindow)); - if (goingVisible) { - const int ToolBarCount = qtoolbarsInUnifiedToolbarList.size(); - bool needAllVisible = true; - for (int i = 0; i < ToolBarCount; ++i) { - if (!qtoolbarsInUnifiedToolbarList.at(i)->isHidden()) { - needAllVisible = false; - break; - } - } - if (needAllVisible) { - QBoolBlocker blocker(blockVisiblityCheck); // Disable the visibilty check because - // the toggle has already happened. - for (int i = 0; i < ToolBarCount; ++i) - qtoolbarsInUnifiedToolbarList.at(i)->setVisible(true); - } - } - if (!updateNonUnifiedParts) - layoutState.toolBarAreaLayout.visible = goingVisible; - } -#endif - if (updateNonUnifiedParts) { - layoutState.toolBarAreaLayout.visible = !layoutState.toolBarAreaLayout.visible; - if (!layoutState.mainWindow->isMaximized()) { - QPoint topLeft = parentWidget()->geometry().topLeft(); - QRect r = parentWidget()->geometry(); - r = layoutState.toolBarAreaLayout.rectHint(r); - r.moveTo(topLeft); - parentWidget()->setGeometry(r); - } else { - update(); - } + layoutState.toolBarAreaLayout.visible = !layoutState.toolBarAreaLayout.visible; + if (!layoutState.mainWindow->isMaximized()) { + QPoint topLeft = parentWidget()->geometry().topLeft(); + QRect r = parentWidget()->geometry(); + r = layoutState.toolBarAreaLayout.rectHint(r); + r.moveTo(topLeft); + parentWidget()->setGeometry(r); + } else { + update(); } } @@ -1606,9 +1658,9 @@ class QMainWindowTabBar : public QTabBar public: QMainWindowTabBar(QMainWindow *parent); protected: - bool event(QEvent *e) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent*) Q_DECL_OVERRIDE; - void mouseMoveEvent(QMouseEvent*) Q_DECL_OVERRIDE; + bool event(QEvent *e) override; + void mouseReleaseEvent(QMouseEvent*) override; + void mouseMoveEvent(QMouseEvent*) override; }; @@ -1783,39 +1835,6 @@ void QMainWindowLayout::tabMoved(int from, int to) } #endif // QT_CONFIG(tabbar) -bool QMainWindowLayout::startSeparatorMove(const QPoint &pos) -{ - movingSeparator = layoutState.dockAreaLayout.findSeparator(pos); - - if (movingSeparator.isEmpty()) - return false; - - layoutState.dockAreaLayout.fallbackToSizeHints = false; - - savedState = layoutState; - movingSeparatorPos = movingSeparatorOrigin = pos; - - return true; -} - -bool QMainWindowLayout::separatorMove(const QPoint &pos) -{ - if (movingSeparator.isEmpty()) - return false; - movingSeparatorPos = pos; - separatorMoveTimer.start(0, this); - return true; -} - -bool QMainWindowLayout::endSeparatorMove(const QPoint&) -{ - if (movingSeparator.isEmpty()) - return false; - movingSeparator.clear(); - savedState.clear(); - return true; -} - void QMainWindowLayout::raise(QDockWidget *widget) { #if QT_CONFIG(tabbar) @@ -1940,14 +1959,6 @@ QSize QMainWindowLayout::minimumSize() const const QSize sbMin = statusbar ? statusbar->minimumSize() : QSize(0, 0); minSize = QSize(qMax(sbMin.width(), minSize.width()), sbMin.height() + minSize.height()); -#if 0 // Used to be included in Qt4 for Q_WS_MAC - const QSize storedSize = minSize; - int minWidth = 0; - foreach (QToolBar *toolbar, qtoolbarsInUnifiedToolbarList) { - minWidth += toolbar->sizeHint().width() + 20; - } - minSize = QSize(qMax(minWidth, storedSize.width()), storedSize.height()); -#endif } return minSize; } @@ -1959,12 +1970,16 @@ void QMainWindowLayout::invalidate() } #if QT_CONFIG(dockwidget) -void QMainWindowLayout::setCurrentHoveredFloat(QWidget *w) +void QMainWindowLayout::setCurrentHoveredFloat(QDockWidgetGroupWindow *w) { if (currentHoveredFloat != w) { if (currentHoveredFloat) { disconnect(currentHoveredFloat.data(), &QObject::destroyed, this, &QMainWindowLayout::updateGapIndicator); + if (currentHoveredFloat) + currentHoveredFloat->restore(); + } else if (w) { + restore(true); } currentHoveredFloat = w; @@ -2035,52 +2050,30 @@ void QMainWindowLayout::revert(QLayoutItem *widgetItem) bool QMainWindowLayout::plug(QLayoutItem *widgetItem) { -#if QT_CONFIG(dockwidget) +#if QT_CONFIG(dockwidget) && QT_CONFIG(tabwidget) && QT_CONFIG(tabbar) if (currentHoveredFloat) { QWidget *widget = widgetItem->widget(); QList<int> previousPath = layoutState.indexOf(widget); if (!previousPath.isEmpty()) layoutState.remove(previousPath); + previousPath = currentHoveredFloat->layoutInfo()->indexOf(widget); // Let's remove the widget from any possible group window foreach (QDockWidgetGroupWindow *dwgw, parent()->findChildren<QDockWidgetGroupWindow*>(QString(), Qt::FindDirectChildrenOnly)) { + if (dwgw == currentHoveredFloat) + continue; QList<int> path = dwgw->layoutInfo()->indexOf(widget); if (!path.isEmpty()) dwgw->layoutInfo()->remove(path); } currentGapRect = QRect(); -#if QT_CONFIG(tabwidget) - if (QDockWidget *dropTo = qobject_cast<QDockWidget*>(currentHoveredFloat)) { - //dropping to a normal widget, we mutate it in a QDockWidgetGroupWindow with two tabs - QDockWidgetGroupWindow *floatingTabs = createTabbedDockWindow(); - floatingTabs->setGeometry(dropTo->geometry()); - QDockAreaLayoutInfo *info = floatingTabs->layoutInfo(); - *info = QDockAreaLayoutInfo(&layoutState.dockAreaLayout.sep, QInternal::LeftDock, - Qt::Horizontal, QTabBar::RoundedSouth, - static_cast<QMainWindow*>(parentWidget())); - info->tabbed = true; - QLayout *parentLayout = currentHoveredFloat->parentWidget()->layout(); - info->item_list.append(QDockAreaLayoutItem(parentLayout->takeAt(parentLayout->indexOf(currentHoveredFloat)))); - - dropTo->setParent(floatingTabs); - dropTo->show(); - dropTo->d_func()->plug(QRect()); - setCurrentHoveredFloat(floatingTabs); - } -#endif // QT_CONFIG(tabwidget) -#if QT_CONFIG(tabbar) - QDockWidgetGroupWindow *dwgw = qobject_cast<QDockWidgetGroupWindow *>(currentHoveredFloat); - Q_ASSERT(dwgw); - Q_ASSERT(dwgw->layoutInfo()->tabbed); // because floating group should always be tabbed - previousPath = dwgw->layoutInfo()->indexOf(widget); + currentHoveredFloat->apply(); if (!previousPath.isEmpty()) - dwgw->layoutInfo()->remove(previousPath); - dwgw->layoutInfo()->tab(0, widgetItem); - QRect globalRect = dwgw->layoutInfo()->tabContentRect(); - globalRect.moveTopLeft(dwgw->mapToGlobal(globalRect.topLeft())); + currentHoveredFloat->layoutInfo()->remove(previousPath); + QRect globalRect = currentHoveredFloat->currentGapRect; + globalRect.moveTopLeft(currentHoveredFloat->mapToGlobal(globalRect.topLeft())); pluggingWidget = widget; widgetAnimator.animate(widget, globalRect, dockOptions & QMainWindow::AnimatedDocks); -#endif // QT_CONFIG(tabbar) return true; } #endif @@ -2149,57 +2142,55 @@ void QMainWindowLayout::animationFinished(QWidget *widget) if (widget == pluggingWidget) { #if QT_CONFIG(dockwidget) +#if QT_CONFIG(tabbar) if (QDockWidgetGroupWindow *dwgw = qobject_cast<QDockWidgetGroupWindow *>(widget)) { // When the animated widget was a QDockWidgetGroupWindow, it means each of the // embedded QDockWidget needs to be plugged back into the QMainWindow layout. savedState.clear(); - QDockAreaLayoutInfo* info = dwgw->layoutInfo(); - QDockAreaLayoutInfo* parentInfo; - QList<int> path; - - if (QDockWidgetGroupWindow *dropTo = qobject_cast<QDockWidgetGroupWindow *>(currentHoveredFloat)) { - parentInfo = dropTo->layoutInfo(); -#if QT_CONFIG(tabbar) - Q_ASSERT(parentInfo->tabbed); -#endif - path = parentInfo->indexOf(widget); - Q_ASSERT(path.size() == 1); + QDockAreaLayoutInfo *srcInfo = dwgw->layoutInfo(); + const QDockAreaLayoutInfo *srcTabInfo = dwgw->tabLayoutInfo(); + QDockAreaLayoutInfo *dstParentInfo; + QList<int> dstPath; + + if (currentHoveredFloat) { + dstPath = currentHoveredFloat->layoutInfo()->indexOf(widget); + Q_ASSERT(dstPath.size() >= 1); + dstParentInfo = currentHoveredFloat->layoutInfo()->info(dstPath); } else { - path = layoutState.dockAreaLayout.indexOf(widget); - Q_ASSERT(path.size() >= 2); - parentInfo = layoutState.dockAreaLayout.info(path); - Q_ASSERT(parentInfo); + dstPath = layoutState.dockAreaLayout.indexOf(widget); + Q_ASSERT(dstPath.size() >= 2); + dstParentInfo = layoutState.dockAreaLayout.info(dstPath); } -#if QT_CONFIG(tabbar) - if (parentInfo->tabbed) { + Q_ASSERT(dstParentInfo); + int idx = dstPath.constLast(); + Q_ASSERT(dstParentInfo->item_list[idx].widgetItem->widget() == dwgw); + if (dstParentInfo->tabbed && srcTabInfo) { // merge the two tab widgets - int idx = path.constLast(); - Q_ASSERT(parentInfo->item_list[idx].widgetItem->widget() == dwgw); - delete parentInfo->item_list[idx].widgetItem; - parentInfo->item_list.removeAt(idx); - std::copy(info->item_list.cbegin(), info->item_list.cend(), - std::inserter(parentInfo->item_list, parentInfo->item_list.begin() + idx)); - quintptr currentId = info->currentTabId(); - *info = QDockAreaLayoutInfo(); - parentInfo->reparentWidgets(currentHoveredFloat ? currentHoveredFloat.data() : parentWidget()); - parentInfo->updateTabBar(); - parentInfo->setCurrentTabId(currentId); - } else -#endif // QT_CONFIG(tabbar) - { - QDockAreaLayoutItem &item = layoutState.dockAreaLayout.item(path); + delete dstParentInfo->item_list[idx].widgetItem; + dstParentInfo->item_list.removeAt(idx); + std::copy(srcTabInfo->item_list.cbegin(), srcTabInfo->item_list.cend(), + std::inserter(dstParentInfo->item_list, + dstParentInfo->item_list.begin() + idx)); + quintptr currentId = srcTabInfo->currentTabId(); + *srcInfo = QDockAreaLayoutInfo(); + dstParentInfo->reparentWidgets(currentHoveredFloat ? currentHoveredFloat.data() + : parentWidget()); + dstParentInfo->updateTabBar(); + dstParentInfo->setCurrentTabId(currentId); + } else { + QDockAreaLayoutItem &item = dstParentInfo->item_list[idx]; Q_ASSERT(item.widgetItem->widget() == dwgw); delete item.widgetItem; item.widgetItem = 0; - item.subinfo = new QDockAreaLayoutInfo(qMove(*info)); - *info = QDockAreaLayoutInfo(); -#if QT_CONFIG(tabbar) - item.subinfo->reparentWidgets(parentWidget()); - item.subinfo->setTabBarShape(parentInfo->tabBarShape); -#endif + item.subinfo = new QDockAreaLayoutInfo(std::move(*srcInfo)); + *srcInfo = QDockAreaLayoutInfo(); + item.subinfo->reparentWidgets(currentHoveredFloat ? currentHoveredFloat.data() + : parentWidget()); + item.subinfo->setTabBarShape(dstParentInfo->tabBarShape); } dwgw->destroyOrHideIfEmpty(); } +#endif if (QDockWidget *dw = qobject_cast<QDockWidget*>(widget)) { dw->setParent(currentHoveredFloat ? currentHoveredFloat.data() : parentWidget()); @@ -2279,9 +2270,6 @@ QMainWindowLayout::QMainWindowLayout(QMainWindow *mainwindow, QLayout *parentLay #endif // QT_CONFIG(dockwidget) , widgetAnimator(this) , pluggingWidget(0) -#if 0 // Used to be included in Qt4 for Q_WS_MAC - , blockVisiblityCheck(false) -#endif { if (parentLayout) setParent(parentLayout); @@ -2306,10 +2294,6 @@ QMainWindowLayout::~QMainWindowLayout() layoutState.deleteAllLayoutItems(); layoutState.deleteCentralWidgetItem(); -#if 0 // Used to be included in Qt4 for Q_WS_MAC - cleanUpMacToolbarItems(); -#endif - delete statusbar; } @@ -2362,6 +2346,36 @@ void QMainWindowLayout::setCentralWidget(QWidget *widget) invalidate(); } +#if QT_CONFIG(dockwidget) && QT_CONFIG(tabwidget) +/*! \internal + This helper function is called by QMainWindowLayout::unplug if QMainWindow::GroupedDragging is + set and we are dragging the title bar of a non-floating QDockWidget. + If one should unplug the whole group, do so and return true, otherwise return false. + \a item is pointing to the QLayoutItem that holds the QDockWidget, but will be updated to the + QLayoutItem that holds the new QDockWidgetGroupWindow if the group is unplugged. +*/ +static bool unplugGroup(QMainWindowLayout *layout, QLayoutItem **item, + QDockAreaLayoutItem &parentItem) +{ + if (!parentItem.subinfo || !parentItem.subinfo->tabbed) + return false; + + // The QDockWidget is part of a group of tab and we need to unplug them all. + + QDockWidgetGroupWindow *floatingTabs = layout->createTabbedDockWindow(); + QDockAreaLayoutInfo *info = floatingTabs->layoutInfo(); + *info = std::move(*parentItem.subinfo); + delete parentItem.subinfo; + parentItem.subinfo = nullptr; + floatingTabs->setGeometry(info->rect.translated(layout->parentWidget()->pos())); + floatingTabs->show(); + floatingTabs->raise(); + *item = new QDockWidgetGroupWindowItem(floatingTabs); + parentItem.widgetItem = *item; + return true; +} +#endif + /*! \internal Unplug \a widget (QDockWidget or QToolBar) from it's parent container. @@ -2375,19 +2389,31 @@ void QMainWindowLayout::setCentralWidget(QWidget *widget) QLayoutItem *QMainWindowLayout::unplug(QWidget *widget, bool group) { #if QT_CONFIG(dockwidget) && QT_CONFIG(tabbar) - if (!widget->isWindow() && qobject_cast<const QDockWidgetGroupWindow *>(widget->parentWidget())) { - if (group) { + auto *groupWindow = qobject_cast<const QDockWidgetGroupWindow *>(widget->parentWidget()); + if (!widget->isWindow() && groupWindow) { + if (group && groupWindow->tabLayoutInfo()) { // We are just dragging a floating window as it, not need to do anything, we just have to // look up the corresponding QWidgetItem* if it exists - QList<int> tabbedWindowPath = layoutState.indexOf(widget->parentWidget()); - return tabbedWindowPath.isEmpty() ? 0 : layoutState.item(tabbedWindowPath); + if (QDockAreaLayoutInfo *info = dockInfo(widget->parentWidget())) { + QList<int> groupWindowPath = info->indexOf(widget->parentWidget()); + return groupWindowPath.isEmpty() ? nullptr : info->item(groupWindowPath).widgetItem; + } + return nullptr; + } + QList<int> path = groupWindow->layoutInfo()->indexOf(widget); + QLayoutItem *item = groupWindow->layoutInfo()->item(path).widgetItem; + if (group && path.size() > 1 + && unplugGroup(this, &item, + groupWindow->layoutInfo()->item(path.mid(0, path.size() - 1)))) { + return item; } else { // We are unplugging a dock widget from a floating window. - if (QDockWidget *dw = qobject_cast<QDockWidget*>(widget)) { - dw->d_func()->unplug(widget->geometry()); - int index = widget->parentWidget()->layout()->indexOf(widget); - return widget->parentWidget()->layout()->itemAt(index); - } + QDockWidget *dw = qobject_cast<QDockWidget *>(widget); + Q_ASSERT(dw); // cannot be a QDockWidgetGroupWindow because it's not floating. + dw->d_func()->unplug(widget->geometry()); + groupWindow->layoutInfo()->fitItems(); + groupWindow->layoutInfo()->apply(dockOptions & QMainWindow::AnimatedDocks); + return item; } } #endif @@ -2405,30 +2431,15 @@ QLayoutItem *QMainWindowLayout::unplug(QWidget *widget, bool group) #if QT_CONFIG(dockwidget) if (QDockWidget *dw = qobject_cast<QDockWidget*>(widget)) { Q_ASSERT(path.constFirst() == 1); - bool actualGroup = false; #if QT_CONFIG(tabwidget) - if (group && (dockOptions & QMainWindow::GroupedDragging) && path.size() > 3) { - QDockAreaLayoutItem &parentItem = layoutState.dockAreaLayout.item(path.mid(1, path.size() - 2)); - if (parentItem.subinfo && parentItem.subinfo->tabbed) { - // The QDockWidget is part of a group of tab and we need to unplug them all. - actualGroup = true; - path.removeLast(); - - QDockWidgetGroupWindow* floatingTabs = createTabbedDockWindow(); - QDockAreaLayoutInfo* info = floatingTabs->layoutInfo(); - *info = qMove(*parentItem.subinfo); - delete parentItem.subinfo; - parentItem.subinfo = 0; - floatingTabs->setGeometry(info->rect.translated(parentWidget()->pos())); - floatingTabs->show(); - floatingTabs->raise(); - item = new QDockWidgetGroupWindowItem(floatingTabs); - parentItem.widgetItem = item; - savedState = layoutState; - } - } + if (group && (dockOptions & QMainWindow::GroupedDragging) && path.size() > 3 + && unplugGroup(this, &item, + layoutState.dockAreaLayout.item(path.mid(1, path.size() - 2)))) { + path.removeLast(); + savedState = layoutState; + } else #endif // QT_CONFIG(tabwidget) - if (!actualGroup) { + { dw->d_func()->unplug(r); } } @@ -2457,11 +2468,11 @@ QLayoutItem *QMainWindowLayout::unplug(QWidget *widget, bool group) void QMainWindowLayout::updateGapIndicator() { #if QT_CONFIG(rubberband) - if ((!widgetAnimator.animating() && !currentGapPos.isEmpty()) + if (!widgetAnimator.animating() && (!currentGapPos.isEmpty() #if QT_CONFIG(dockwidget) - || currentHoveredFloat + || currentHoveredFloat #endif - ) { + )) { QWidget *expectedParent = #if QT_CONFIG(dockwidget) currentHoveredFloat ? currentHoveredFloat.data() : @@ -2474,11 +2485,13 @@ void QMainWindowLayout::updateGapIndicator() } else if (gapIndicator->parent() != expectedParent) { gapIndicator->setParent(expectedParent); } - gapIndicator->setGeometry( + #if QT_CONFIG(dockwidget) - currentHoveredFloat ? currentHoveredFloat->rect() : + if (currentHoveredFloat) + gapIndicator->setGeometry(currentHoveredFloat->currentGapRect); + else #endif - currentGapRect); + gapIndicator->setGeometry(currentGapRect); gapIndicator->show(); gapIndicator->raise(); } else if (gapIndicator) { @@ -2527,12 +2540,36 @@ void QMainWindowLayout::hover(QLayoutItem *widgetItem, const QPoint &mousePos) if (!w->geometry().contains(mousePos)) continue; - setCurrentHoveredFloat(w); - restore(true); + if (auto dropTo = qobject_cast<QDockWidget *>(w)) { + // dropping to a normal widget, we mutate it in a QDockWidgetGroupWindow with two + // tabs + QDockWidgetGroupWindow *floatingTabs = createTabbedDockWindow(); // FIXME + floatingTabs->setGeometry(dropTo->geometry()); + QDockAreaLayoutInfo *info = floatingTabs->layoutInfo(); + *info = QDockAreaLayoutInfo(&layoutState.dockAreaLayout.sep, QInternal::LeftDock, + Qt::Horizontal, QTabBar::RoundedSouth, + static_cast<QMainWindow *>(parentWidget())); + info->tabbed = true; + QLayout *parentLayout = dropTo->parentWidget()->layout(); + info->item_list.append( + QDockAreaLayoutItem(parentLayout->takeAt(parentLayout->indexOf(dropTo)))); + + dropTo->setParent(floatingTabs); + dropTo->show(); + dropTo->d_func()->plug(QRect()); + w = floatingTabs; + } + Q_ASSERT(qobject_cast<QDockWidgetGroupWindow *>(w)); + auto group = static_cast<QDockWidgetGroupWindow *>(w); + if (group->hover(widgetItem, group->mapFromGlobal(mousePos))) { + setCurrentHoveredFloat(group); + applyState(layoutState); // update the tabbars + } return; } } setCurrentHoveredFloat(nullptr); + layoutState.dockAreaLayout.fallbackToSizeHints = false; #endif // QT_CONFIG(dockwidget) QPoint pos = parentWidget()->mapFromGlobal(mousePos); @@ -2595,7 +2632,7 @@ void QMainWindowLayout::hover(QLayoutItem *widgetItem, const QPoint &mousePos) #if QT_CONFIG(dockwidget) parentWidget()->update(layoutState.dockAreaLayout.separatorRegion()); #endif - layoutState = newState; + layoutState = std::move(newState); applyState(layoutState); updateGapIndicator(); @@ -2684,45 +2721,6 @@ bool QMainWindowLayout::restoreState(QDataStream &stream) return true; } - -// Returns if this toolbar *should* be using HIToolbar. Won't work for all in between cases -// for example, you have a toolbar in the top area and then you suddenly turn on -// HIToolbar. -bool QMainWindowLayout::usesHIToolBar(QToolBar *toolbar) const -{ -#if 1 // Used to be excluded in Qt4 for Q_WS_MAC - Q_UNUSED(toolbar); - return false; -#else - return qtoolbarsInUnifiedToolbarList.contains(toolbar) - || ((toolBarArea(toolbar) == Qt::TopToolBarArea) - && layoutState.mainWindow->unifiedTitleAndToolBarOnMac()); -#endif -} - -void QMainWindowLayout::timerEvent(QTimerEvent *e) -{ -#if QT_CONFIG(dockwidget) - if (e->timerId() == separatorMoveTimer.timerId()) { - //let's move the separators - separatorMoveTimer.stop(); - if (movingSeparator.isEmpty()) - return; - if (movingSeparatorOrigin == movingSeparatorPos) - return; - - //when moving the separator, we need to update the previous position - parentWidget()->update(layoutState.dockAreaLayout.separatorRegion()); - - layoutState = savedState; - layoutState.dockAreaLayout.separatorMove(movingSeparator, movingSeparatorOrigin, - movingSeparatorPos); - movingSeparatorPos = movingSeparatorOrigin; - } -#endif - QLayout::timerEvent(e); -} - QT_END_NAMESPACE #include "moc_qmainwindowlayout_p.cpp" diff --git a/src/widgets/widgets/qmainwindowlayout_p.h b/src/widgets/widgets/qmainwindowlayout_p.h index 615035d2fe..168d4444b9 100644 --- a/src/widgets/widgets/qmainwindowlayout_p.h +++ b/src/widgets/widgets/qmainwindowlayout_p.h @@ -57,6 +57,8 @@ #include "QtWidgets/qlayout.h" #if QT_CONFIG(tabbar) #include "QtWidgets/qtabbar.h" +#include "QtGui/qpainter.h" +#include "QtGui/qevent.h" #endif #include "QtCore/qvector.h" #include "QtCore/qset.h" @@ -76,6 +78,251 @@ QT_BEGIN_NAMESPACE class QToolBar; class QRubberBand; +template <typename Layout> // Make use of the "Curiously recurring template pattern" +class QMainWindowLayoutSeparatorHelper +{ + Layout *layout() { return static_cast<Layout *>(this); } + const Layout *layout() const { return static_cast<const Layout *>(this); } + QWidget *window() { return layout()->parentWidget(); } + +public: + QList<int> hoverSeparator; + QPoint hoverPos; + +#if !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_CURSOR) + QCursor separatorCursor(const QList<int> &path); + void adjustCursor(const QPoint &pos); + QCursor oldCursor; + QCursor adjustedCursor; + bool hasOldCursor = false; + bool cursorAdjusted = false; + + QList<int> movingSeparator; + QPoint movingSeparatorOrigin, movingSeparatorPos; + QBasicTimer separatorMoveTimer; + + bool startSeparatorMove(const QPoint &pos); + bool separatorMove(const QPoint &pos); + bool endSeparatorMove(const QPoint &pos); + +#endif + + bool windowEvent(QEvent *e); +}; + +#if !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_CURSOR) +template <typename Layout> +QCursor QMainWindowLayoutSeparatorHelper<Layout>::separatorCursor(const QList<int> &path) +{ + const QDockAreaLayoutInfo *info = layout()->dockAreaLayoutInfo()->info(path); + Q_ASSERT(info != 0); + if (path.size() == 1) { // is this the "top-level" separator which separates a dock area + // from the central widget? + switch (path.first()) { + case QInternal::LeftDock: + case QInternal::RightDock: + return Qt::SplitHCursor; + case QInternal::TopDock: + case QInternal::BottomDock: + return Qt::SplitVCursor; + default: + break; + } + } + + // no, it's a splitter inside a dock area, separating two dock widgets + + return info->o == Qt::Horizontal ? Qt::SplitHCursor : Qt::SplitVCursor; +} + +template <typename Layout> +void QMainWindowLayoutSeparatorHelper<Layout>::adjustCursor(const QPoint &pos) +{ + QWidget *w = layout()->window(); + hoverPos = pos; + + if (pos == QPoint(0, 0)) { + if (!hoverSeparator.isEmpty()) + w->update(layout()->dockAreaLayoutInfo()->separatorRect(hoverSeparator)); + hoverSeparator.clear(); + + if (cursorAdjusted) { + cursorAdjusted = false; + if (hasOldCursor) + w->setCursor(oldCursor); + else + w->unsetCursor(); + } + } else if (movingSeparator.isEmpty()) { // Don't change cursor when moving separator + QList<int> pathToSeparator = layout()->dockAreaLayoutInfo()->findSeparator(pos); + + if (pathToSeparator != hoverSeparator) { + if (!hoverSeparator.isEmpty()) + w->update(layout()->dockAreaLayoutInfo()->separatorRect(hoverSeparator)); + + hoverSeparator = pathToSeparator; + + if (hoverSeparator.isEmpty()) { + if (cursorAdjusted) { + cursorAdjusted = false; + if (hasOldCursor) + w->setCursor(oldCursor); + else + w->unsetCursor(); + } + } else { + w->update(layout()->dockAreaLayoutInfo()->separatorRect(hoverSeparator)); + if (!cursorAdjusted) { + oldCursor = w->cursor(); + hasOldCursor = w->testAttribute(Qt::WA_SetCursor); + } + adjustedCursor = separatorCursor(hoverSeparator); + w->setCursor(adjustedCursor); + cursorAdjusted = true; + } + } + } +} + +template <typename Layout> +bool QMainWindowLayoutSeparatorHelper<Layout>::windowEvent(QEvent *event) +{ + QWidget *w = window(); + switch (event->type()) { + case QEvent::Paint: { + QPainter p(w); + QRegion r = static_cast<QPaintEvent *>(event)->region(); + layout()->dockAreaLayoutInfo()->paintSeparators(&p, w, r, hoverPos); + break; + } + +#ifndef QT_NO_CURSOR + case QEvent::HoverMove: { + adjustCursor(static_cast<QHoverEvent *>(event)->pos()); + break; + } + + // We don't want QWidget to call update() on the entire QMainWindow + // on HoverEnter and HoverLeave, hence accept the event (return true). + case QEvent::HoverEnter: + return true; + case QEvent::HoverLeave: + adjustCursor(QPoint(0, 0)); + return true; + case QEvent::ShortcutOverride: // when a menu pops up + adjustCursor(QPoint(0, 0)); + break; +#endif // QT_NO_CURSOR + + case QEvent::MouseButtonPress: { + QMouseEvent *e = static_cast<QMouseEvent *>(event); + if (e->button() == Qt::LeftButton && startSeparatorMove(e->pos())) { + // The click was on a separator, eat this event + e->accept(); + return true; + } + break; + } + + case QEvent::MouseMove: { + QMouseEvent *e = static_cast<QMouseEvent *>(event); + +#ifndef QT_NO_CURSOR + adjustCursor(e->pos()); +#endif + if (e->buttons() & Qt::LeftButton) { + if (separatorMove(e->pos())) { + // We're moving a separator, eat this event + e->accept(); + return true; + } + } + + break; + } + + case QEvent::MouseButtonRelease: { + QMouseEvent *e = static_cast<QMouseEvent *>(event); + if (endSeparatorMove(e->pos())) { + // We've released a separator, eat this event + e->accept(); + return true; + } + break; + } + +#if !defined(QT_NO_CURSOR) + case QEvent::CursorChange: + // CursorChange events are triggered as mouse moves to new widgets even + // if the cursor doesn't actually change, so do not change oldCursor if + // the "changed" cursor has same shape as adjusted cursor. + if (cursorAdjusted && adjustedCursor.shape() != w->cursor().shape()) { + oldCursor = w->cursor(); + hasOldCursor = w->testAttribute(Qt::WA_SetCursor); + + // Ensure our adjusted cursor stays visible + w->setCursor(adjustedCursor); + } + break; +#endif + case QEvent::Timer: + if (static_cast<QTimerEvent *>(event)->timerId() == separatorMoveTimer.timerId()) { + // let's move the separators + separatorMoveTimer.stop(); + if (movingSeparator.isEmpty()) + return true; + if (movingSeparatorOrigin == movingSeparatorPos) + return true; + + // when moving the separator, we need to update the previous position + window()->update(layout()->dockAreaLayoutInfo()->separatorRegion()); + + layout()->layoutState = layout()->savedState; + layout()->dockAreaLayoutInfo()->separatorMove(movingSeparator, movingSeparatorOrigin, + movingSeparatorPos); + movingSeparatorPos = movingSeparatorOrigin; + return true; + } + break; + default: + break; + } + return false; +} + +template <typename Layout> +bool QMainWindowLayoutSeparatorHelper<Layout>::startSeparatorMove(const QPoint &pos) +{ + movingSeparator = layout()->dockAreaLayoutInfo()->findSeparator(pos); + + if (movingSeparator.isEmpty()) + return false; + + layout()->savedState = layout()->layoutState; + movingSeparatorPos = movingSeparatorOrigin = pos; + + return true; +} +template <typename Layout> +bool QMainWindowLayoutSeparatorHelper<Layout>::separatorMove(const QPoint &pos) +{ + if (movingSeparator.isEmpty()) + return false; + movingSeparatorPos = pos; + separatorMoveTimer.start(0, window()); + return true; +} +template <typename Layout> +bool QMainWindowLayoutSeparatorHelper<Layout>::endSeparatorMove(const QPoint &) +{ + if (movingSeparator.isEmpty()) + return false; + movingSeparator.clear(); + layout()->savedState.clear(); + return true; +} +#endif + #if QT_CONFIG(dockwidget) class QDockWidgetGroupWindow : public QWidget { @@ -84,14 +331,22 @@ public: explicit QDockWidgetGroupWindow(QWidget* parent = 0, Qt::WindowFlags f = 0) : QWidget(parent, f) {} QDockAreaLayoutInfo *layoutInfo() const; - QDockWidget *topDockWidget() const; + const QDockAreaLayoutInfo *tabLayoutInfo() const; + QDockWidget *activeTabbedDockWidget() const; void destroyOrHideIfEmpty(); void adjustFlags(); bool hasNativeDecos() const; + bool hover(QLayoutItem *widgetItem, const QPoint &mousePos); + void restore(); + void apply(); + + QRect currentGapRect; + QList<int> currentGapPos; + protected: - bool event(QEvent *) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent*) Q_DECL_OVERRIDE; + bool event(QEvent *) override; + void paintEvent(QPaintEvent*) override; private: QSize m_removedFrameSize; @@ -103,9 +358,9 @@ class QDockWidgetGroupWindowItem : public QWidgetItem { public: explicit QDockWidgetGroupWindowItem(QDockWidgetGroupWindow *parent) : QWidgetItem(parent) {} - QSize minimumSize() const Q_DECL_OVERRIDE { return lay()->minimumSize(); } - QSize maximumSize() const Q_DECL_OVERRIDE { return lay()->maximumSize(); } - QSize sizeHint() const Q_DECL_OVERRIDE { return lay()->sizeHint(); } + QSize minimumSize() const override { return lay()->minimumSize(); } + QSize maximumSize() const override { return lay()->maximumSize(); } + QSize sizeHint() const override { return lay()->sizeHint(); } private: QLayout *lay() const { return const_cast<QDockWidgetGroupWindowItem *>(this)->widget()->layout(); } @@ -172,7 +427,9 @@ public: bool restoreState(QDataStream &stream, const QMainWindowLayoutState &oldState); }; -class Q_AUTOTEST_EXPORT QMainWindowLayout : public QLayout +class Q_AUTOTEST_EXPORT QMainWindowLayout + : public QLayout, + public QMainWindowLayoutSeparatorHelper<QMainWindowLayout> { Q_OBJECT @@ -184,9 +441,6 @@ public: QMainWindow::DockOptions dockOptions; void setDockOptions(QMainWindow::DockOptions opts); - bool usesHIToolBar(QToolBar *toolbar) const; - - void timerEvent(QTimerEvent *e) Q_DECL_OVERRIDE; // status bar @@ -265,15 +519,7 @@ public: #endif // QT_CONFIG(tabwidget) #endif // QT_CONFIG(tabbar) - // separators - - QList<int> movingSeparator; - QPoint movingSeparatorOrigin, movingSeparatorPos; - QBasicTimer separatorMoveTimer; - - bool startSeparatorMove(const QPoint &pos); - bool separatorMove(const QPoint &pos); - bool endSeparatorMove(const QPoint &pos); + QDockAreaLayout *dockAreaLayoutInfo() { return &layoutState.dockAreaLayout; } void keepSize(QDockWidget *w); #endif // QT_CONFIG(dockwidget) @@ -287,17 +533,17 @@ public: // QLayout interface - void addItem(QLayoutItem *item) Q_DECL_OVERRIDE; - void setGeometry(const QRect &r) Q_DECL_OVERRIDE; - QLayoutItem *itemAt(int index) const Q_DECL_OVERRIDE; - QLayoutItem *takeAt(int index) Q_DECL_OVERRIDE; - int count() const Q_DECL_OVERRIDE; + void addItem(QLayoutItem *item) override; + void setGeometry(const QRect &r) override; + QLayoutItem *itemAt(int index) const override; + QLayoutItem *takeAt(int index) override; + int count() const override; - QSize sizeHint() const Q_DECL_OVERRIDE; - QSize minimumSize() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; + QSize minimumSize() const override; mutable QSize szHint; mutable QSize minSize; - void invalidate() Q_DECL_OVERRIDE; + void invalidate() override; // animations @@ -309,8 +555,8 @@ public: QPointer<QRubberBand> gapIndicator; #endif #if QT_CONFIG(dockwidget) - QPointer<QWidget> currentHoveredFloat; // set when dragging over a floating dock widget - void setCurrentHoveredFloat(QWidget *w); + QPointer<QDockWidgetGroupWindow> currentHoveredFloat; // set when dragging over a floating dock widget + void setCurrentHoveredFloat(QDockWidgetGroupWindow *w); #endif void hover(QLayoutItem *widgetItem, const QPoint &mousePos); @@ -320,7 +566,6 @@ public: void paintDropIndicator(QPainter *p, QWidget *widget, const QRegion &clip); void applyState(QMainWindowLayoutState &newState, bool animate = true); void restore(bool keepSavedState = false); - void updateHIToolBarStatus(); void animationFinished(QWidget *widget); private Q_SLOTS: @@ -335,40 +580,6 @@ private: #if QT_CONFIG(tabbar) void updateTabBarShapes(); #endif -#if 0 // Used to be included in Qt4 for Q_WS_MAC - static OSStatus qtmacToolbarDelegate(EventHandlerCallRef, EventRef , void *); - static OSStatus qtoolbarInHIToolbarHandler(EventHandlerCallRef inCallRef, EventRef event, - void *data); - static void qtMacHIToolbarRegisterQToolBarInHIToolborItemClass(); - static HIToolbarItemRef CreateToolbarItemForIdentifier(CFStringRef identifier, CFTypeRef data); - static HIToolbarItemRef createQToolBarInHIToolbarItem(QToolBar *toolbar, - QMainWindowLayout *layout); -public: - struct ToolBarSaveState { - ToolBarSaveState() : movable(false) { } - ToolBarSaveState(bool newMovable, const QSize &newMax) - : movable(newMovable), maximumSize(newMax) { } - bool movable; - QSize maximumSize; - }; - QList<QToolBar *> qtoolbarsInUnifiedToolbarList; - QList<void *> toolbarItemsCopy; - QHash<void *, QToolBar *> unifiedToolbarHash; - QHash<QToolBar *, ToolBarSaveState> toolbarSaveState; - QHash<QString, QToolBar *> cocoaItemIDToToolbarHash; - void insertIntoMacToolbar(QToolBar *before, QToolBar *after); - void removeFromMacToolbar(QToolBar *toolbar); - void cleanUpMacToolbarItems(); - void fixSizeInUnifiedToolbar(QToolBar *tb) const; - bool useHIToolBar; - bool activateUnifiedToolbarAfterFullScreen; - void syncUnifiedToolbarVisibility(); - bool blockVisiblityCheck; - - QUnifiedToolbarSurface *unifiedSurface; - void updateUnifiedToolbarOffset(); - -#endif }; #if QT_CONFIG(dockwidget) && !defined(QT_NO_DEBUG_STREAM) diff --git a/src/widgets/widgets/qmdiarea.cpp b/src/widgets/widgets/qmdiarea.cpp index c90d915f4c..45c01dec80 100644 --- a/src/widgets/widgets/qmdiarea.cpp +++ b/src/widgets/widgets/qmdiarea.cpp @@ -100,7 +100,7 @@ */ /*! - \fn QMdiArea::subWindowActivated(QMdiSubWindow *window) + \fn void QMdiArea::subWindowActivated(QMdiSubWindow *window) QMdiArea emits this signal after \a window has been activated. When \a window is 0, QMdiArea has just deactivated its last active window, and @@ -158,9 +158,6 @@ #include <QApplication> #include <QStyle> -#if 0 /* Used to be included in Qt4 for Q_WS_MAC */ && QT_CONFIG(style_mac) -#include <private/qmacstyle_mac_p.h> -#endif #include <QChildEvent> #include <QResizeEvent> #include <QScrollBar> @@ -169,6 +166,7 @@ #include <QFontMetrics> #include <QStyleOption> #include <QDesktopWidget> +#include <private/qdesktopwidget_p.h> #include <QDebug> #include <qmath.h> #if QT_CONFIG(menu) @@ -572,9 +570,9 @@ public: QMdiAreaTabBar(QWidget *parent) : QTabBar(parent) {} protected: - void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; + void mousePressEvent(QMouseEvent *event) override; #ifndef QT_NO_CONTEXTMENU - void contextMenuEvent(QContextMenuEvent *event) Q_DECL_OVERRIDE; + void contextMenuEvent(QContextMenuEvent *event) override; #endif private: @@ -1750,7 +1748,7 @@ QSize QMdiArea::sizeHint() const } const int scaleFactor = 3 * (nestedCount + 1); - QSize desktopSize = QApplication::desktop()->size(); + QSize desktopSize = QDesktopWidgetPrivate::size(); QSize size(desktopSize.width() * 2 / scaleFactor, desktopSize.height() * 2 / scaleFactor); for (QMdiSubWindow *child : d_func()->childWindows) { if (!sanityCheck(child, "QMdiArea::sizeHint")) @@ -2640,7 +2638,7 @@ bool QMdiArea::eventFilter(QObject *object, QEvent *event) d->tabBar->setTabEnabled(tabIndex, true); } #endif // QT_CONFIG(tabbar) - // fall through + Q_FALLTHROUGH(); case QEvent::Hide: d->isSubWindowsTiled = false; break; diff --git a/src/widgets/widgets/qmdiarea.h b/src/widgets/widgets/qmdiarea.h index 05deb9e21f..35edde9eb8 100644 --- a/src/widgets/widgets/qmdiarea.h +++ b/src/widgets/widgets/qmdiarea.h @@ -87,11 +87,11 @@ public: }; Q_ENUM(ViewMode) - QMdiArea(QWidget *parent = Q_NULLPTR); + QMdiArea(QWidget *parent = nullptr); ~QMdiArea(); - QSize sizeHint() const Q_DECL_OVERRIDE; - QSize minimumSizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; + QSize minimumSizeHint() const override; QMdiSubWindow *currentSubWindow() const; QMdiSubWindow *activeSubWindow() const; @@ -143,18 +143,18 @@ public Q_SLOTS: void activatePreviousSubWindow(); protected Q_SLOTS: - void setupViewport(QWidget *viewport) Q_DECL_OVERRIDE; + void setupViewport(QWidget *viewport) override; protected: - bool event(QEvent *event) Q_DECL_OVERRIDE; - bool eventFilter(QObject *object, QEvent *event) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *paintEvent) Q_DECL_OVERRIDE; - void childEvent(QChildEvent *childEvent) Q_DECL_OVERRIDE; - void resizeEvent(QResizeEvent *resizeEvent) Q_DECL_OVERRIDE; - void timerEvent(QTimerEvent *timerEvent) Q_DECL_OVERRIDE; - void showEvent(QShowEvent *showEvent) Q_DECL_OVERRIDE; - bool viewportEvent(QEvent *event) Q_DECL_OVERRIDE; - void scrollContentsBy(int dx, int dy) Q_DECL_OVERRIDE; + bool event(QEvent *event) override; + bool eventFilter(QObject *object, QEvent *event) override; + void paintEvent(QPaintEvent *paintEvent) override; + void childEvent(QChildEvent *childEvent) override; + void resizeEvent(QResizeEvent *resizeEvent) override; + void timerEvent(QTimerEvent *timerEvent) override; + void showEvent(QShowEvent *showEvent) override; + bool viewportEvent(QEvent *event) override; + void scrollContentsBy(int dx, int dy) override; private: Q_DISABLE_COPY(QMdiArea) diff --git a/src/widgets/widgets/qmdiarea_p.h b/src/widgets/widgets/qmdiarea_p.h index 4740993af7..fd00118ec6 100644 --- a/src/widgets/widgets/qmdiarea_p.h +++ b/src/widgets/widgets/qmdiarea_p.h @@ -88,8 +88,8 @@ class RegularTiler : public Rearranger // Rearranges widgets according to a regular tiling pattern // covering the entire domain. // Both positions and sizes may change. - void rearrange(QList<QWidget *> &widgets, const QRect &domain) const Q_DECL_OVERRIDE; - Type type() const Q_DECL_OVERRIDE { return Rearranger::RegularTiler; } + void rearrange(QList<QWidget *> &widgets, const QRect &domain) const override; + Type type() const override { return Rearranger::RegularTiler; } }; class SimpleCascader : public Rearranger @@ -97,8 +97,8 @@ class SimpleCascader : public Rearranger // Rearranges widgets according to a simple, regular cascading pattern. // Widgets are resized to minimumSize. // Both positions and sizes may change. - void rearrange(QList<QWidget *> &widgets, const QRect &domain) const Q_DECL_OVERRIDE; - Type type() const Q_DECL_OVERRIDE { return Rearranger::SimpleCascader; } + void rearrange(QList<QWidget *> &widgets, const QRect &domain) const override; + Type type() const override { return Rearranger::SimpleCascader; } }; class IconTiler : public Rearranger @@ -106,8 +106,8 @@ class IconTiler : public Rearranger // Rearranges icons (assumed to be the same size) according to a regular // tiling pattern filling up the domain from the bottom. // Only positions may change. - void rearrange(QList<QWidget *> &widgets, const QRect &domain) const Q_DECL_OVERRIDE; - Type type() const Q_DECL_OVERRIDE { return Rearranger::IconTiler; } + void rearrange(QList<QWidget *> &widgets, const QRect &domain) const override; + Type type() const override { return Rearranger::IconTiler; } }; class Placer @@ -122,7 +122,7 @@ public: class MinOverlapPlacer : public Placer { - QPoint place(const QSize &size, const QVector<QRect> &rects, const QRect &domain) const Q_DECL_OVERRIDE; + QPoint place(const QSize &size, const QVector<QRect> &rects, const QRect &domain) const override; static int accumulatedOverlap(const QRect &source, const QVector<QRect> &rects); static QRect findMinOverlapRect(const QVector<QRect> &source, const QVector<QRect> &rects); static QVector<QRect> getCandidatePlacements(const QSize &size, const QVector<QRect> &rects, const QRect &domain); @@ -206,7 +206,7 @@ public: bool lastWindowAboutToBeDestroyed() const; void setChildActivationEnabled(bool enable = true, bool onlyNextActivationEvent = false) const; QRect resizeToMinimumTileSize(const QSize &minSubWindowSize, int subWindowCount); - void scrollBarPolicyChanged(Qt::Orientation, Qt::ScrollBarPolicy) Q_DECL_OVERRIDE; // reimp + void scrollBarPolicyChanged(Qt::Orientation, Qt::ScrollBarPolicy) override; // reimp QMdiSubWindow *nextVisibleSubWindow(int increaseFactor, QMdiArea::WindowOrder, int removed = -1, int fromIndex = -1) const; void highlightNextSubWindow(int increaseFactor); diff --git a/src/widgets/widgets/qmdisubwindow.cpp b/src/widgets/widgets/qmdisubwindow.cpp index 2e6c82f95a..794674c427 100644 --- a/src/widgets/widgets/qmdisubwindow.cpp +++ b/src/widgets/widgets/qmdisubwindow.cpp @@ -160,9 +160,6 @@ #endif #include <QScrollBar> #include <QDebug> -#if QT_CONFIG(style_mac) -#include <private/qmacstyle_mac_p.h> -#endif #include <QMdiArea> #include <QScopedValueRollback> #include <QAction> @@ -200,6 +197,11 @@ static const Qt::WindowFlags CustomizeWindowFlags = static const int BoundaryMargin = 5; +static inline bool isMacStyle(QStyle *style) +{ + return style->inherits("QMacStyle"); +} + static inline int getMoveDeltaComponent(uint cflags, uint moveFlag, uint resizeFlag, int delta, int maxDelta, int minDelta) { @@ -301,11 +303,8 @@ static void showToolTip(QHelpEvent *helpEvent, QWidget *widget, const QStyleOpti Q_ASSERT(helpEvent->type() == QEvent::ToolTip); Q_ASSERT(widget); -#if QT_CONFIG(style_mac) - // Native Mac windows don't show tool tip. - if (qobject_cast<QMacStyle *>(widget->style())) + if (widget->style()->styleHint(QStyle::SH_TitleBar_ShowToolTipsOnButtons, &opt, widget)) return; -#endif // Convert CC_MdiControls to CC_TitleBar. Sub controls of different complex // controls cannot be in the same switch as they might have the same value. @@ -374,18 +373,18 @@ class ControlLabel : public QWidget public: ControlLabel(QMdiSubWindow *subWindow, QWidget *parent = 0); - QSize sizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; signals: void _q_clicked(); void _q_doubleClicked(); protected: - bool event(QEvent *event) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *paintEvent) Q_DECL_OVERRIDE; - void mousePressEvent(QMouseEvent *mouseEvent) Q_DECL_OVERRIDE; - void mouseDoubleClickEvent(QMouseEvent *mouseEvent) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent *mouseEvent) Q_DECL_OVERRIDE; + bool event(QEvent *event) override; + void paintEvent(QPaintEvent *paintEvent) override; + void mousePressEvent(QMouseEvent *mouseEvent) override; + void mouseDoubleClickEvent(QMouseEvent *mouseEvent) override; + void mouseReleaseEvent(QMouseEvent *mouseEvent) override; private: QPixmap label; @@ -505,7 +504,7 @@ class ControllerWidget : public QWidget Q_OBJECT public: ControllerWidget(QMdiSubWindow *subWindow, QWidget *parent = 0); - QSize sizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; void setControlVisible(QMdiSubWindowPrivate::WindowStateAction action, bool visible); inline bool hasVisibleControls() const { @@ -520,12 +519,12 @@ signals: void _q_close(); protected: - void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; - void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - void leaveEvent(QEvent *event) Q_DECL_OVERRIDE; - bool event(QEvent *event) Q_DECL_OVERRIDE; + void paintEvent(QPaintEvent *event) override; + void mousePressEvent(QMouseEvent *event) override; + void mouseReleaseEvent(QMouseEvent *event) override; + void mouseMoveEvent(QMouseEvent *event) override; + void leaveEvent(QEvent *event) override; + bool event(QEvent *event) override; private: QStyle::SubControl activeControl; @@ -1082,10 +1081,8 @@ void QMdiSubWindowPrivate::updateCursor() { #ifndef QT_NO_CURSOR Q_Q(QMdiSubWindow); -#if QT_CONFIG(style_mac) - if (qobject_cast<QMacStyle *>(q->style())) + if (isMacStyle(q->style())) return; -#endif if (currentOperation == None) { q->unsetCursor(); @@ -1510,15 +1507,14 @@ void QMdiSubWindowPrivate::processClickedSubControl() q->showNormal(); break; case QStyle::SC_TitleBarMinButton: -#if QT_CONFIG(style_mac) - if (qobject_cast<QMacStyle *>(q->style())) { + if (isMacStyle(q->style())) { if (q->isMinimized()) q->showNormal(); else q->showMinimized(); break; } -#endif + q->showMinimized(); break; case QStyle::SC_TitleBarNormalButton: @@ -1527,15 +1523,14 @@ void QMdiSubWindowPrivate::processClickedSubControl() q->showNormal(); break; case QStyle::SC_TitleBarMaxButton: -#if QT_CONFIG(style_mac) - if (qobject_cast<QMacStyle *>(q->style())) { + if (isMacStyle(q->style())) { if (q->isMaximized()) q->showNormal(); else q->showMaximized(); break; } -#endif + q->showMaximized(); break; case QStyle::SC_TitleBarCloseButton: @@ -1574,10 +1569,8 @@ QRegion QMdiSubWindowPrivate::getRegion(Operation operation) const } QRegion region; -#if QT_CONFIG(style_mac) - if (qobject_cast<QMacStyle *>(q->style())) + if (isMacStyle(q->style())) return region; -#endif switch (operation) { case TopResize: @@ -1781,10 +1774,6 @@ bool QMdiSubWindowPrivate::drawTitleBarWhenMaximized() const if (isChildOfTabbedQMdiArea(q)) return false; -#if QT_CONFIG(style_mac) - Q_UNUSED(isChildOfQMdiSubWindow); - return true; -#else if (q->style()->styleHint(QStyle::SH_Workspace_FillSpaceOnMaximize, 0, q)) return true; #if !QT_CONFIG(menubar) || !QT_CONFIG(mainwindow) @@ -1798,7 +1787,6 @@ bool QMdiSubWindowPrivate::drawTitleBarWhenMaximized() const return isChildOfQMdiSubWindow(q); #endif -#endif } #if QT_CONFIG(menubar) @@ -1998,6 +1986,13 @@ void QMdiSubWindowPrivate::updateActions() for (int i = 0; i < NumWindowStateActions; ++i) setVisible(WindowStateAction(i), false); +#ifdef Q_OS_MACOS + if (q_func()->style()->inherits("QMacStyle")) + for (int i = 0; i < NumWindowStateActions; ++i) + if (QAction *action = actions[i]) + action->setIconVisibleInMenu(false); +#endif + if (windowFlags & Qt::FramelessWindowHint) return; @@ -2197,10 +2192,8 @@ void QMdiSubWindowPrivate::setSizeGrip(QSizeGrip *newSizeGrip) return; newSizeGrip->setFixedSize(newSizeGrip->sizeHint()); bool putSizeGripInLayout = layout ? true : false; -#if QT_CONFIG(style_mac) - if (qobject_cast<QMacStyle *>(q->style())) + if (isMacStyle(q->style())) putSizeGripInLayout = false; -#endif if (putSizeGripInLayout) { layout->addWidget(newSizeGrip); layout->setAlignment(newSizeGrip, Qt::AlignBottom | Qt::AlignRight); @@ -2849,8 +2842,8 @@ bool QMdiSubWindow::event(QEvent *event) d->isMaximizeMode = false; d->isWidgetHiddenByUs = false; if (!parent()) { -#if QT_CONFIG(sizegrip) && QT_CONFIG(style_mac) - if (qobject_cast<QMacStyle *>(style())) +#if QT_CONFIG(sizegrip) + if (isMacStyle(style())) delete d->sizeGrip; #endif setOption(RubberBandResize, false); @@ -2944,8 +2937,8 @@ void QMdiSubWindow::showEvent(QShowEvent *showEvent) return; } -#if QT_CONFIG(sizegrip) && QT_CONFIG(style_mac) - if (qobject_cast<QMacStyle *>(style()) && !d->sizeGrip +#if QT_CONFIG(sizegrip) + if (isMacStyle(style()) && !d->sizeGrip && !(windowFlags() & Qt::FramelessWindowHint)) { d->setSizeGrip(new QSizeGrip(this)); Q_ASSERT(d->sizeGrip); @@ -3339,10 +3332,10 @@ void QMdiSubWindow::mouseMoveEvent(QMouseEvent *mouseEvent) hoverRegion += style()->subControlRect(QStyle::CC_TitleBar, &options, d->hoveredSubControl, this); } -#if QT_CONFIG(style_mac) - if (qobject_cast<QMacStyle *>(style()) && !hoverRegion.isEmpty()) + + if (isMacStyle(style()) && !hoverRegion.isEmpty()) hoverRegion += QRegion(0, 0, width(), d->titleBarHeight(options)); -#endif + if (!hoverRegion.isEmpty()) update(hoverRegion); } @@ -3549,10 +3542,8 @@ QSize QMdiSubWindow::minimumSizeHint() const int sizeGripHeight = 0; if (d->sizeGrip && d->sizeGrip->isVisibleTo(const_cast<QMdiSubWindow *>(this))) sizeGripHeight = d->sizeGrip->height(); -#if QT_CONFIG(style_mac) - else if (parent() && qobject_cast<QMacStyle *>(style()) && !d->sizeGrip) + else if (parent() && isMacStyle(style()) && !d->sizeGrip) sizeGripHeight = style()->pixelMetric(QStyle::PM_SizeGripSize, 0, this); -#endif minHeight = qMax(minHeight, decorationHeight + sizeGripHeight); #endif diff --git a/src/widgets/widgets/qmdisubwindow.h b/src/widgets/widgets/qmdisubwindow.h index adaafa352a..302522e1c3 100644 --- a/src/widgets/widgets/qmdisubwindow.h +++ b/src/widgets/widgets/qmdisubwindow.h @@ -66,11 +66,11 @@ public: }; Q_DECLARE_FLAGS(SubWindowOptions, SubWindowOption) - QMdiSubWindow(QWidget *parent = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags()); + QMdiSubWindow(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); ~QMdiSubWindow(); - QSize sizeHint() const Q_DECL_OVERRIDE; - QSize minimumSizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; + QSize minimumSizeHint() const override; void setWidget(QWidget *widget); QWidget *widget() const; @@ -107,28 +107,28 @@ public Q_SLOTS: void showShaded(); protected: - bool eventFilter(QObject *object, QEvent *event) Q_DECL_OVERRIDE; - bool event(QEvent *event) Q_DECL_OVERRIDE; - void showEvent(QShowEvent *showEvent) Q_DECL_OVERRIDE; - void hideEvent(QHideEvent *hideEvent) Q_DECL_OVERRIDE; - void changeEvent(QEvent *changeEvent) Q_DECL_OVERRIDE; - void closeEvent(QCloseEvent *closeEvent) Q_DECL_OVERRIDE; - void leaveEvent(QEvent *leaveEvent) Q_DECL_OVERRIDE; - void resizeEvent(QResizeEvent *resizeEvent) Q_DECL_OVERRIDE; - void timerEvent(QTimerEvent *timerEvent) Q_DECL_OVERRIDE; - void moveEvent(QMoveEvent *moveEvent) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *paintEvent) Q_DECL_OVERRIDE; - void mousePressEvent(QMouseEvent *mouseEvent) Q_DECL_OVERRIDE; - void mouseDoubleClickEvent(QMouseEvent *mouseEvent) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent *mouseEvent) Q_DECL_OVERRIDE; - void mouseMoveEvent(QMouseEvent *mouseEvent) Q_DECL_OVERRIDE; - void keyPressEvent(QKeyEvent *keyEvent) Q_DECL_OVERRIDE; + bool eventFilter(QObject *object, QEvent *event) override; + bool event(QEvent *event) override; + void showEvent(QShowEvent *showEvent) override; + void hideEvent(QHideEvent *hideEvent) override; + void changeEvent(QEvent *changeEvent) override; + void closeEvent(QCloseEvent *closeEvent) override; + void leaveEvent(QEvent *leaveEvent) override; + void resizeEvent(QResizeEvent *resizeEvent) override; + void timerEvent(QTimerEvent *timerEvent) override; + void moveEvent(QMoveEvent *moveEvent) override; + void paintEvent(QPaintEvent *paintEvent) override; + void mousePressEvent(QMouseEvent *mouseEvent) override; + void mouseDoubleClickEvent(QMouseEvent *mouseEvent) override; + void mouseReleaseEvent(QMouseEvent *mouseEvent) override; + void mouseMoveEvent(QMouseEvent *mouseEvent) override; + void keyPressEvent(QKeyEvent *keyEvent) override; #ifndef QT_NO_CONTEXTMENU - void contextMenuEvent(QContextMenuEvent *contextMenuEvent) Q_DECL_OVERRIDE; + void contextMenuEvent(QContextMenuEvent *contextMenuEvent) override; #endif - void focusInEvent(QFocusEvent *focusInEvent) Q_DECL_OVERRIDE; - void focusOutEvent(QFocusEvent *focusOutEvent) Q_DECL_OVERRIDE; - void childEvent(QChildEvent *childEvent) Q_DECL_OVERRIDE; + void focusInEvent(QFocusEvent *focusInEvent) override; + void focusOutEvent(QFocusEvent *focusOutEvent) override; + void childEvent(QChildEvent *childEvent) override; private: Q_DISABLE_COPY(QMdiSubWindow) diff --git a/src/widgets/widgets/qmdisubwindow_p.h b/src/widgets/widgets/qmdisubwindow_p.h index d03aca168b..719984c8d4 100644 --- a/src/widgets/widgets/qmdisubwindow_p.h +++ b/src/widgets/widgets/qmdisubwindow_p.h @@ -271,7 +271,7 @@ public: void setFocusWidget(); bool restoreFocus(); void storeFocusWidget(); - void setWindowFlags(Qt::WindowFlags windowFlags) Q_DECL_OVERRIDE; + void setWindowFlags(Qt::WindowFlags windowFlags) override; void setVisible(WindowStateAction, bool visible = true); #ifndef QT_NO_ACTION void setEnabled(WindowStateAction, bool enable = true); diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index cf306e63bd..024f9a75a1 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -77,6 +77,7 @@ #include <private/qaction_p.h> #include <private/qguiapplication_p.h> #include <qpa/qplatformtheme.h> +#include <private/qdesktopwidget_p.h> QT_BEGIN_NAMESPACE @@ -102,7 +103,7 @@ class QTornOffMenu : public QMenu Q_Q(QTornOffMenu); QSize size = menuSize; const QPoint p = (!initialized) ? causedMenu->pos() : q->pos(); - QRect screen = popupGeometry(QApplication::desktop()->screenNumber(p)); + QRect screen = popupGeometry(QDesktopWidgetPrivate::screenNumber(p)); const int desktopFrame = q->style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, 0, q); const int titleBarHeight = q->style()->pixelMetric(QStyle::PM_TitleBarHeight, 0, q); if (scroll && (size.height() > screen.height() - titleBarHeight || size.width() > screen.width())) { @@ -115,7 +116,7 @@ class QTornOffMenu : public QMenu q->setFixedSize(size); } - QVector<QPointer<QWidget> > calcCausedStack() const Q_DECL_OVERRIDE { return causedStack; } + QVector<QPointer<QWidget> > calcCausedStack() const override { return causedStack; } QPointer<QMenu> causedMenu; QVector<QPointer<QWidget> > causedStack; bool initialized; @@ -161,7 +162,7 @@ public: } else if (act->type() == QEvent::ActionRemoved) removeAction(act->action()); } - void actionEvent(QActionEvent *e) Q_DECL_OVERRIDE + void actionEvent(QActionEvent *e) override { Q_D(QTornOffMenu); QMenu::actionEvent(e); @@ -233,59 +234,101 @@ void QMenuPrivate::setPlatformMenu(QPlatformMenu *menu) } } -// forward declare function -static void copyActionToPlatformItem(const QAction *action, QPlatformMenuItem *item, QPlatformMenu *itemsMenu); - void QMenuPrivate::syncPlatformMenu() { Q_Q(QMenu); if (platformMenu.isNull()) return; - QPlatformMenuItem *beforeItem = Q_NULLPTR; + QPlatformMenuItem *beforeItem = nullptr; const QList<QAction*> actions = q->actions(); for (QList<QAction*>::const_reverse_iterator it = actions.rbegin(), end = actions.rend(); it != end; ++it) { - QPlatformMenuItem *menuItem = platformMenu->createMenuItem(); - QAction *action = *it; - menuItem->setTag(reinterpret_cast<quintptr>(action)); - QObject::connect(menuItem, SIGNAL(activated()), action, SLOT(trigger()), Qt::QueuedConnection); - QObject::connect(menuItem, SIGNAL(hovered()), action, SIGNAL(hovered()), Qt::QueuedConnection); - copyActionToPlatformItem(action, menuItem, platformMenu.data()); - platformMenu->insertMenuItem(menuItem, beforeItem); + QPlatformMenuItem *menuItem = insertActionInPlatformMenu(*it, beforeItem); beforeItem = menuItem; } platformMenu->syncSeparatorsCollapsible(collapsibleSeparators); platformMenu->setEnabled(q->isEnabled()); } +void QMenuPrivate::copyActionToPlatformItem(const QAction *action, QPlatformMenuItem *item) +{ + item->setText(action->text()); + item->setIsSeparator(action->isSeparator()); + if (action->isIconVisibleInMenu()) { + item->setIcon(action->icon()); + if (QWidget *w = action->parentWidget()) { + QStyleOption opt; + opt.init(w); + item->setIconSize(w->style()->pixelMetric(QStyle::PM_SmallIconSize, &opt, w)); + } else { + QStyleOption opt; + item->setIconSize(qApp->style()->pixelMetric(QStyle::PM_SmallIconSize, &opt, 0)); + } + } else { + item->setIcon(QIcon()); + } + item->setVisible(action->isVisible()); +#if QT_CONFIG(shortcut) + item->setShortcut(action->shortcut()); +#endif + item->setCheckable(action->isCheckable()); + item->setChecked(action->isChecked()); + item->setHasExclusiveGroup(action->actionGroup() && action->actionGroup()->isExclusive()); + item->setFont(action->font()); + item->setRole((QPlatformMenuItem::MenuRole) action->menuRole()); + item->setEnabled(action->isEnabled()); + + if (action->menu()) { + if (!action->menu()->platformMenu()) + action->menu()->setPlatformMenu(platformMenu->createSubMenu()); + item->setMenu(action->menu()->platformMenu()); + } else { + item->setMenu(0); + } +} + +QPlatformMenuItem * QMenuPrivate::insertActionInPlatformMenu(const QAction *action, QPlatformMenuItem *beforeItem) +{ + QPlatformMenuItem *menuItem = platformMenu->createMenuItem(); + Q_ASSERT(menuItem); + + menuItem->setTag(reinterpret_cast<quintptr>(action)); + QObject::connect(menuItem, &QPlatformMenuItem::activated, action, &QAction::trigger, Qt::QueuedConnection); + QObject::connect(menuItem, &QPlatformMenuItem::hovered, action, &QAction::hovered, Qt::QueuedConnection); + copyActionToPlatformItem(action, menuItem); + platformMenu->insertMenuItem(menuItem, beforeItem); + + return menuItem; +} + int QMenuPrivate::scrollerHeight() const { Q_Q(const QMenu); return qMax(QApplication::globalStrut().height(), q->style()->pixelMetric(QStyle::PM_MenuScrollerHeight, 0, q)); } -//Windows and KDE allows menus to cover the taskbar, while GNOME and Mac don't +//Windows and KDE allow menus to cover the taskbar, while GNOME and Mac don't QRect QMenuPrivate::popupGeometry() const { Q_Q(const QMenu); if (!tornoff && // Torn-off menus are different QGuiApplicationPrivate::platformTheme() && QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::UseFullScreenForPopupMenu).toBool()) { - return QApplication::desktop()->screenGeometry(q); + return QDesktopWidgetPrivate::screenGeometry(q); } else { - return QApplication::desktop()->availableGeometry(q); + return QDesktopWidgetPrivate::availableGeometry(q); } } -//Windows and KDE allows menus to cover the taskbar, while GNOME and Mac don't +//Windows and KDE allow menus to cover the taskbar, while GNOME and Mac don't QRect QMenuPrivate::popupGeometry(int screen) const { if (!tornoff && // Torn-off menus are different QGuiApplicationPrivate::platformTheme() && QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::UseFullScreenForPopupMenu).toBool()) { - return QApplication::desktop()->screenGeometry(screen); + return QDesktopWidgetPrivate::screenGeometry(screen); } else { - return QApplication::desktop()->availableGeometry(screen); + return QDesktopWidgetPrivate::availableGeometry(screen); } } @@ -304,6 +347,11 @@ QVector<QPointer<QWidget> > QMenuPrivate::calcCausedStack() const return ret; } +bool QMenuPrivate::isContextMenu() const +{ + return qobject_cast<const QMenuBar *>(topCausedWidget()) == nullptr; +} + void QMenuPrivate::updateActionRects() const { updateActionRects(popupGeometry()); @@ -358,6 +406,7 @@ void QMenuPrivate::updateActionRects(const QRect &screen) const //calculate size QFontMetrics qfm = q->fontMetrics(); bool previousWasSeparator = true; // this is true to allow removing the leading separators + const bool contextMenu = isContextMenu(); for(int i = 0; i <= lastVisibleAction; i++) { QAction *action = actions.at(i); const bool isSection = action->isSeparator() && (!action->text().isEmpty() || !action->icon().isNull()); @@ -386,13 +435,13 @@ void QMenuPrivate::updateActionRects(const QRect &screen) const QString s = action->text(); int t = s.indexOf(QLatin1Char('\t')); if (t != -1) { - tabWidth = qMax(int(tabWidth), qfm.width(s.mid(t+1))); + tabWidth = qMax(int(tabWidth), qfm.horizontalAdvance(s.mid(t+1))); s = s.left(t); #ifndef QT_NO_SHORTCUT - } else { + } else if (action->isShortcutVisibleInContextMenu() || !contextMenu) { QKeySequence seq = action->shortcut(); if (!seq.isEmpty()) - tabWidth = qMax(int(tabWidth), qfm.width(seq.toString(QKeySequence::NativeText))); + tabWidth = qMax(int(tabWidth), qfm.horizontalAdvance(seq.toString(QKeySequence::NativeText))); #endif } sz.setWidth(fm.boundingRect(QRect(), Qt::TextSingleLine | Qt::TextShowMnemonic, s).width()); @@ -616,7 +665,7 @@ void QMenuPrivate::setCurrentAction(QAction *action, int popup, SelectionReason if (action && (action->isSeparator() || (!action->isEnabled() && !q->style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled, 0, q)))) - action = Q_NULLPTR; + action = nullptr; // Reselect the currently active action in case mouse moved over other menu items when // moving from sub menu action to sub menu (QTBUG-20094). @@ -690,13 +739,13 @@ void QMenuSloppyState::reset() m_use_reset_action = true; m_uni_dir_discarded_count = 0; m_time.stop(); - m_reset_action = Q_NULLPTR; - m_origin_action = Q_NULLPTR; + m_reset_action = nullptr; + m_origin_action = nullptr; m_action_rect = QRect(); m_previous_point = QPointF(); if (m_sub_menu) { - QMenuPrivate::get(m_sub_menu)->sloppyState.m_parent = Q_NULLPTR; - m_sub_menu = Q_NULLPTR; + QMenuPrivate::get(m_sub_menu)->sloppyState.m_parent = nullptr; + m_sub_menu = nullptr; } } void QMenuSloppyState::enter() @@ -805,7 +854,7 @@ void QMenuSloppyState::timeout() if (m_use_reset_action) menu_priv->setCurrentAction(m_reset_action, 0); } else { - menu_priv->setCurrentAction(Q_NULLPTR, 0); + menu_priv->setCurrentAction(nullptr, 0); } } @@ -854,8 +903,7 @@ void QMenuPrivate::adjustMenuScreen(const QPoint &p) // The (item) size calculations depend on the menu screen, // so a wrong screen would often cause wrong sizes (on high DPI) const QScreen *currentScreen = q->windowHandle() ? q->windowHandle()->screen() : nullptr; - const int screenNumberForPoint = QApplication::desktop()->screenNumber(p); - QScreen *actualScreen = QGuiApplication::screens().at(screenNumberForPoint); + QScreen *actualScreen = QGuiApplication::screenAt(p); if (actualScreen && currentScreen != actualScreen) { if (!q->windowHandle()) // Try to create a window handle if not created. createWinId(); @@ -1536,7 +1584,8 @@ void QMenu::initStyleOption(QStyleOptionMenuItem *option, const QAction *action) option->icon = action->icon(); QString textAndAccel = action->text(); #ifndef QT_NO_SHORTCUT - if (textAndAccel.indexOf(QLatin1Char('\t')) == -1) { + if ((action->isShortcutVisibleInContextMenu() || !d->isContextMenu()) + && textAndAccel.indexOf(QLatin1Char('\t')) == -1) { QKeySequence seq = action->shortcut(); if (!seq.isEmpty()) textAndAccel += QLatin1Char('\t') + seq.toString(QKeySequence::NativeText); @@ -1753,7 +1802,7 @@ QAction *QMenu::addAction(const QString &text, const QObject *receiver, const ch return action; } -/*!\fn QAction *QMenu::addAction(const QString &text, const QObject *receiver, PointerToMemberFunction method, const QKeySequence &shortcut = 0) +/*!\fn template<typename PointerToMemberFunction> QAction *QMenu::addAction(const QString &text, const QObject *receiver, PointerToMemberFunction method, const QKeySequence &shortcut = 0) \since 5.6 @@ -1768,7 +1817,7 @@ QAction *QMenu::addAction(const QString &text, const QObject *receiver, const ch QMenu takes ownership of the returned QAction. */ -/*!\fn QAction *QMenu::addAction(const QString &text, Functor functor, const QKeySequence &shortcut = 0) +/*!\fn template<typename Functor> QAction *QMenu::addAction(const QString &text, Functor functor, const QKeySequence &shortcut = 0) \since 5.6 @@ -1783,7 +1832,7 @@ QAction *QMenu::addAction(const QString &text, const QObject *receiver, const ch QMenu takes ownership of the returned QAction. */ -/*!\fn QAction *QMenu::addAction(const QString &text, const QObject *context, Functor functor, const QKeySequence &shortcut = 0) +/*!\fn template<typename Functor> QAction *QMenu::addAction(const QString &text, const QObject *context, Functor functor, const QKeySequence &shortcut) \since 5.6 @@ -1800,7 +1849,7 @@ QAction *QMenu::addAction(const QString &text, const QObject *receiver, const ch QMenu takes ownership of the returned QAction. */ -/*!\fn QAction *QMenu::addAction(const QIcon &icon, const QString &text, const QObject *receiver, PointerToMemberFunction method, const QKeySequence &shortcut = 0) +/*!\fn template<typename PointerToMemberFunction> QAction *QMenu::addAction(const QIcon &icon, const QString &text, const QObject *receiver, PointerToMemberFunction method, const QKeySequence &shortcut = 0) \since 5.6 @@ -1815,7 +1864,7 @@ QAction *QMenu::addAction(const QString &text, const QObject *receiver, const ch QMenu takes ownership of the returned QAction. */ -/*!\fn QAction *QMenu::addAction(const QIcon &icon, const QString &text, Functor functor, const QKeySequence &shortcut = 0) +/*!\fn template<typename Functor> QAction *QMenu::addAction(const QIcon &icon, const QString &text, Functor functor, const QKeySequence &shortcut = 0) \since 5.6 @@ -1830,7 +1879,7 @@ QAction *QMenu::addAction(const QString &text, const QObject *receiver, const ch QMenu takes ownership of the returned QAction. */ -/*!\fn QAction *QMenu::addAction(const QIcon &icon, const QString &text, const QObject *context, Functor functor, const QKeySequence &shortcut = 0) +/*!\fn template<typename Functor> QAction *QMenu::addAction(const QIcon &icon, const QString &text, const QObject *context, Functor functor, const QKeySequence &shortcut) \since 5.6 @@ -2176,7 +2225,7 @@ void QMenu::hideTearOffMenu() // should consider the torn-off menu deleted. // This way showTearOffMenu() will not try to // reuse the dying torn-off menu. - d->tornPopup = Q_NULLPTR; + d->tornPopup = nullptr; } } @@ -2330,6 +2379,12 @@ void QMenu::popup(const QPoint &p, QAction *atAction) d->updateLayoutDirection(); d->adjustMenuScreen(p); + const bool contextMenu = d->isContextMenu(); + if (d->lastContextMenu != contextMenu) { + d->itemsDirty = true; + d->lastContextMenu = contextMenu; + } + #if QT_CONFIG(menubar) // if this menu is part of a chain attached to a QMenuBar, set the // _NET_WM_WINDOW_TYPE_DROPDOWN_MENU X11 window type @@ -2347,7 +2402,7 @@ void QMenu::popup(const QPoint &p, QAction *atAction) screen = d->popupGeometry(); else #endif - screen = d->popupGeometry(QApplication::desktop()->screenNumber(p)); + screen = d->popupGeometry(QDesktopWidgetPrivate::screenNumber(p)); d->updateActionRects(screen); QPoint pos; @@ -2447,8 +2502,6 @@ void QMenu::popup(const QPoint &p, QAction *atAction) pos.setY(qMin(mouse.y() - (size.height() + desktopFrame), screen.bottom()-desktopFrame-size.height()+1)); else pos.setY(qMax(p.y() - (size.height() + desktopFrame), screen.bottom()-desktopFrame-size.height()+1)); - } else if (pos.y() < screen.top() + desktopFrame) { - pos.setY(screen.top() + desktopFrame); } if (pos.y() < screen.top() + desktopFrame) @@ -2680,7 +2733,8 @@ void QMenu::hideEvent(QHideEvent *) if (QMenuBar *mb = qobject_cast<QMenuBar*>(d->causedPopup.widget)) mb->d_func()->setCurrentAction(0); #endif - d->mouseDown = 0; + if (d->mouseDown == this) + d->mouseDown = 0; d->hasHadMouse = false; if (d->activeMenu) d->hideMenu(d->activeMenu); @@ -3469,43 +3523,6 @@ QMenu::timerEvent(QTimerEvent *e) } } -static void copyActionToPlatformItem(const QAction *action, QPlatformMenuItem *item, QPlatformMenu *itemsMenu) -{ - item->setText(action->text()); - item->setIsSeparator(action->isSeparator()); - if (action->isIconVisibleInMenu()) { - item->setIcon(action->icon()); - if (QWidget *w = action->parentWidget()) { - QStyleOption opt; - opt.init(w); - item->setIconSize(w->style()->pixelMetric(QStyle::PM_SmallIconSize, &opt, w)); - } else { - QStyleOption opt; - item->setIconSize(qApp->style()->pixelMetric(QStyle::PM_SmallIconSize, &opt, 0)); - } - } else { - item->setIcon(QIcon()); - } - item->setVisible(action->isVisible()); -#ifndef QT_NO_SHORTCUT - item->setShortcut(action->shortcut()); -#endif - item->setCheckable(action->isCheckable()); - item->setChecked(action->isChecked()); - item->setHasExclusiveGroup(action->actionGroup() && action->actionGroup()->isExclusive()); - item->setFont(action->font()); - item->setRole((QPlatformMenuItem::MenuRole) action->menuRole()); - item->setEnabled(action->isEnabled()); - - if (action->menu()) { - if (!action->menu()->platformMenu()) - action->menu()->setPlatformMenu(itemsMenu->createSubMenu()); - item->setMenu(action->menu()->platformMenu()); - } else { - item->setMenu(0); - } -} - /*! \reimp */ @@ -3517,9 +3534,13 @@ void QMenu::actionEvent(QActionEvent *e) if (d->tornPopup) d->tornPopup->syncWithMenu(this, e); if (e->type() == QEvent::ActionAdded) { - if(!d->tornoff) { - connect(e->action(), SIGNAL(triggered()), this, SLOT(_q_actionTriggered())); - connect(e->action(), SIGNAL(hovered()), this, SLOT(_q_actionHovered())); + + if (!d->tornoff + && !qobject_cast<QMenuBar*>(e->action()->parent())) { + // Only connect if the action was not directly added by QMenuBar::addAction(const QString &text) + // to avoid the signal being emitted twice + connect(e->action(), SIGNAL(triggered()), this, SLOT(_q_actionTriggered()), Qt::UniqueConnection); + connect(e->action(), SIGNAL(hovered()), this, SLOT(_q_actionHovered()), Qt::UniqueConnection); } if (QWidgetAction *wa = qobject_cast<QWidgetAction *>(e->action())) { QWidget *widget = wa->requestWidget(this); @@ -3559,15 +3580,10 @@ void QMenu::actionEvent(QActionEvent *e) if (!d->platformMenu.isNull()) { if (e->type() == QEvent::ActionAdded) { - QPlatformMenuItem *menuItem = d->platformMenu->createMenuItem(); - menuItem->setTag(reinterpret_cast<quintptr>(e->action())); - QObject::connect(menuItem, SIGNAL(activated()), e->action(), SLOT(trigger())); - QObject::connect(menuItem, SIGNAL(hovered()), e->action(), SIGNAL(hovered())); - copyActionToPlatformItem(e->action(), menuItem, d->platformMenu); QPlatformMenuItem *beforeItem = e->before() ? d->platformMenu->menuItemForTag(reinterpret_cast<quintptr>(e->before())) : nullptr; - d->platformMenu->insertMenuItem(menuItem, beforeItem); + d->insertActionInPlatformMenu(e->action(), beforeItem); } else if (e->type() == QEvent::ActionRemoved) { QPlatformMenuItem *menuItem = d->platformMenu->menuItemForTag(reinterpret_cast<quintptr>(e->action())); d->platformMenu->removeMenuItem(menuItem); @@ -3575,7 +3591,7 @@ void QMenu::actionEvent(QActionEvent *e) } else if (e->type() == QEvent::ActionChanged) { QPlatformMenuItem *menuItem = d->platformMenu->menuItemForTag(reinterpret_cast<quintptr>(e->action())); if (menuItem) { - copyActionToPlatformItem(e->action(), menuItem, d->platformMenu); + d->copyActionToPlatformItem(e->action(), menuItem); d->platformMenu->syncMenuItem(menuItem); } } @@ -3617,7 +3633,7 @@ void QMenu::internalDelayedPopup() screen = d->popupGeometry(); else #endif - screen = d->popupGeometry(QApplication::desktop()->screenNumber(pos())); + screen = d->popupGeometry(QDesktopWidgetPrivate::screenNumber(pos())); int subMenuOffset = style()->pixelMetric(QStyle::PM_SubMenuOverlap, 0, this); const QRect actionRect(d->actionRect(d->currentAction)); diff --git a/src/widgets/widgets/qmenu.h b/src/widgets/widgets/qmenu.h index 0b5ed579cd..86d927e919 100644 --- a/src/widgets/widgets/qmenu.h +++ b/src/widgets/widgets/qmenu.h @@ -71,8 +71,8 @@ private: Q_PROPERTY(bool toolTipsVisible READ toolTipsVisible WRITE setToolTipsVisible) public: - explicit QMenu(QWidget *parent = Q_NULLPTR); - explicit QMenu(const QString &title, QWidget *parent = Q_NULLPTR); + explicit QMenu(QWidget *parent = nullptr); + explicit QMenu(const QString &title, QWidget *parent = nullptr); ~QMenu(); using QWidget::addAction; @@ -107,7 +107,7 @@ public: #else result->setShortcut(shortcut); #endif - connect(result, &QAction::triggered, object, slot); + connect(result, &QAction::triggered, object, std::move(slot)); return result; } // addAction(QString): Connect to a functor or function pointer (without context) @@ -120,7 +120,7 @@ public: #else result->setShortcut(shortcut); #endif - connect(result, &QAction::triggered, slot); + connect(result, &QAction::triggered, std::move(slot)); return result; } // addAction(QIcon, QString): Connect to a QObject slot / functor or function pointer (with context) @@ -135,7 +135,7 @@ public: #else result->setShortcut(shortcut); #endif - connect(result, &QAction::triggered, object, slot); + connect(result, &QAction::triggered, object, std::move(slot)); return result; } // addAction(QIcon, QString): Connect to a functor or function pointer (without context) @@ -148,7 +148,7 @@ public: #else result->setShortcut(shortcut); #endif - connect(result, &QAction::triggered, slot); + connect(result, &QAction::triggered, std::move(slot)); return result; } #endif // !Q_QDOC @@ -184,17 +184,17 @@ public: void setActiveAction(QAction *act); QAction *activeAction() const; - void popup(const QPoint &pos, QAction *at = Q_NULLPTR); + void popup(const QPoint &pos, QAction *at = nullptr); QAction *exec(); - QAction *exec(const QPoint &pos, QAction *at = Q_NULLPTR); + QAction *exec(const QPoint &pos, QAction *at = nullptr); #if QT_VERSION >= QT_VERSION_CHECK(6,0,0) - static QAction *exec(const QList<QAction *> &actions, const QPoint &pos, QAction *at = Q_NULLPTR, QWidget *parent = Q_NULLPTR); + static QAction *exec(const QList<QAction *> &actions, const QPoint &pos, QAction *at = nullptr, QWidget *parent = nullptr); #else - static QAction *exec(QList<QAction*> actions, const QPoint &pos, QAction *at = Q_NULLPTR, QWidget *parent = Q_NULLPTR); + static QAction *exec(QList<QAction*> actions, const QPoint &pos, QAction *at = nullptr, QWidget *parent = nullptr); #endif - QSize sizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; QRect actionGeometry(QAction *) const; QAction *actionAt(const QPoint &) const; @@ -231,22 +231,22 @@ Q_SIGNALS: protected: int columnCount() const; - void changeEvent(QEvent *) Q_DECL_OVERRIDE; - void keyPressEvent(QKeyEvent *) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE; - void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE; - void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE; + void changeEvent(QEvent *) override; + void keyPressEvent(QKeyEvent *) override; + void mouseReleaseEvent(QMouseEvent *) override; + void mousePressEvent(QMouseEvent *) override; + void mouseMoveEvent(QMouseEvent *) override; #if QT_CONFIG(wheelevent) - void wheelEvent(QWheelEvent *) Q_DECL_OVERRIDE; + void wheelEvent(QWheelEvent *) override; #endif - void enterEvent(QEvent *) Q_DECL_OVERRIDE; - void leaveEvent(QEvent *) Q_DECL_OVERRIDE; - void hideEvent(QHideEvent *) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; - void actionEvent(QActionEvent *) Q_DECL_OVERRIDE; - void timerEvent(QTimerEvent *) Q_DECL_OVERRIDE; - bool event(QEvent *) Q_DECL_OVERRIDE; - bool focusNextPrevChild(bool next) Q_DECL_OVERRIDE; + void enterEvent(QEvent *) override; + void leaveEvent(QEvent *) override; + void hideEvent(QHideEvent *) override; + void paintEvent(QPaintEvent *) override; + void actionEvent(QActionEvent *) override; + void timerEvent(QTimerEvent *) override; + bool event(QEvent *) override; + bool focusNextPrevChild(bool next) override; void initStyleOption(QStyleOptionMenuItem *option, const QAction *action) const; private Q_SLOTS: @@ -259,7 +259,7 @@ private: Q_PRIVATE_SLOT(d_func(), void _q_platformMenuAboutToShow()) protected: - QMenu(QMenuPrivate &dd, QWidget* parent = Q_NULLPTR); + QMenu(QMenuPrivate &dd, QWidget* parent = nullptr); private: Q_DISABLE_COPY(QMenu) diff --git a/src/widgets/widgets/qmenu_mac.mm b/src/widgets/widgets/qmenu_mac.mm index 7d932c670f..0d680fb4dc 100644 --- a/src/widgets/widgets/qmenu_mac.mm +++ b/src/widgets/widgets/qmenu_mac.mm @@ -135,6 +135,11 @@ void QMenuPrivate::moveWidgetToPlatformItem(QWidget *widget, QPlatformMenuItem* containerWindow->setFlags(wf | Qt::SubWindow); [(NSView *)widget->winId() setAutoresizingMask:NSViewWidthSizable]; + if (QPlatformNativeInterface::NativeResourceForIntegrationFunction function = resolvePlatformFunction("setEmbeddedInForeignView")) { + typedef void (*SetEmbeddedInForeignViewFunction)(QPlatformWindow *window, bool embedded); + reinterpret_cast<SetEmbeddedInForeignViewFunction>(function)(containerWindow->handle(), true); + } + item->setNativeContents((WId)containerView); container->show(); } diff --git a/src/widgets/widgets/qmenu_p.h b/src/widgets/widgets/qmenu_p.h index 64d22087e3..b6afb05e3a 100644 --- a/src/widgets/widgets/qmenu_p.h +++ b/src/widgets/widgets/qmenu_p.h @@ -177,7 +177,7 @@ public: QSetValueOnDestroy<QPointF> setPreviousPoint(m_previous_point, mousePos); if (resetAction && resetAction->isSeparator()) { - m_reset_action = Q_NULLPTR; + m_reset_action = nullptr; m_use_reset_action = true; } else if (m_reset_action != resetAction) { if (m_use_reset_action && resetAction) { @@ -272,6 +272,7 @@ public: QMenuPrivate() : itemsDirty(false), hasCheckableItems(false), + lastContextMenu(false), collapsibleSeparators(true), toolTipsVisible(false), delayedPopupGuard(false), @@ -294,6 +295,9 @@ public: QPlatformMenu *createPlatformMenu(); void setPlatformMenu(QPlatformMenu *menu); void syncPlatformMenu(); + void copyActionToPlatformItem(const QAction *action, QPlatformMenuItem *item); + QPlatformMenuItem *insertActionInPlatformMenu(const QAction *action, QPlatformMenuItem *beforeItem); + #ifdef Q_OS_OSX void moveWidgetToPlatformItem(QWidget *w, QPlatformMenuItem* item); #endif @@ -301,6 +305,8 @@ public: static QMenuPrivate *get(QMenu *m) { return m->d_func(); } int scrollerHeight() const; + bool isContextMenu() const; + //item calculations QRect actionRect(QAction *) const; @@ -436,8 +442,8 @@ public: public: enum Type { ScrollUp, ScrollDown }; ScrollerTearOffItem(Type type, QMenuPrivate *mPrivate, - QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()); - void paintEvent(QPaintEvent *e) Q_DECL_OVERRIDE; + QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); + void paintEvent(QPaintEvent *e) override; void updateScrollerRects(const QRect &rect); private: @@ -462,6 +468,7 @@ public: mutable bool itemsDirty : 1; mutable bool hasCheckableItems : 1; + bool lastContextMenu : 1; bool collapsibleSeparators : 1; bool toolTipsVisible : 1; bool delayedPopupGuard : 1; diff --git a/src/widgets/widgets/qmenubar.cpp b/src/widgets/widgets/qmenubar.cpp index 6dfbb7c8a1..b0a75288e8 100644 --- a/src/widgets/widgets/qmenubar.cpp +++ b/src/widgets/widgets/qmenubar.cpp @@ -62,6 +62,7 @@ #include <qpa/qplatformtheme.h> #include "private/qguiapplication_p.h" #include "qpa/qplatformintegration.h" +#include <private/qdesktopwidget_p.h> #include "qmenu_p.h" #include "qmenubar_p.h" @@ -74,8 +75,8 @@ class QMenuBarExtension : public QToolButton public: explicit QMenuBarExtension(QWidget *parent); - QSize sizeHint() const Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; + QSize sizeHint() const override; + void paintEvent(QPaintEvent *) override; }; QMenuBarExtension::QMenuBarExtension(QWidget *parent) @@ -321,7 +322,7 @@ void QMenuBarPrivate::popupAction(QAction *action, bool activateFirst) QSize popup_size = activeMenu->sizeHint(); //we put the popup menu on the screen containing the bottom-center of the action rect - QRect screenRect = QApplication::desktop()->screenGeometry(pos + QPoint(adjustedActionRect.width() / 2, 0)); + QRect screenRect = QDesktopWidgetPrivate::screenGeometry(pos + QPoint(adjustedActionRect.width() / 2, 0)); pos = QPoint(qMax(pos.x(), screenRect.x()), qMax(pos.y(), screenRect.y())); const bool fitUp = (q->mapToGlobal(adjustedActionRect.topLeft()).y() >= popup_size.height()); @@ -780,6 +781,40 @@ QAction *QMenuBar::addAction(const QString &text, const QObject *receiver, const } /*! + \fn template<typename Obj, typename PointerToMemberFunctionOrFunctor> QAction *QMenuBar::addAction(const QString &text, const Obj *receiver, PointerToMemberFunctionOrFunctor method) + + \since 5.11 + + \overload + + This convenience function creates a new action with the given \a + text. The action's triggered() signal is connected to the + \a method of the \a receiver. The function adds the newly created + action to the menu's list of actions and returns it. + + QMenuBar takes ownership of the returned QAction. + + \sa QWidget::addAction(), QWidget::actions() +*/ + +/*! + \fn template<typename Functor> QAction *QMenuBar::addAction(const QString &text, Functor functor) + + \since 5.11 + + \overload + + This convenience function creates a new action with the given \a + text. The action's triggered() signal is connected to the + \a functor. The function adds the newly created + action to the menu's list of actions and returns it. + + QMenuBar takes ownership of the returned QAction. + + \sa QWidget::addAction(), QWidget::actions() +*/ + +/*! Appends a new QMenu with \a title to the menu bar. The menu bar takes ownership of the menu. Returns the new menu. @@ -1045,6 +1080,10 @@ void QMenuBar::mouseReleaseEvent(QMouseEvent *e) d->mouseDown = false; QAction *action = d->actionAt(e->pos()); + + // do noting if the action is hidden + if (!d->isVisible(action)) + return; if((d->closePopupMode && action == d->currentAction) || !action || !action->menu()) { //we set the current action before activating //so that we let the leave event set the current back to 0 @@ -1330,7 +1369,7 @@ void QMenuBarPrivate::handleReparent() //Note: if parent is reparented, then window may change even if parent doesn't. // We need to install an avent filter on each parent up to the parent that is // also a window (for shortcuts) - QWidget *newWindow = newParent ? newParent->window() : Q_NULLPTR; + QWidget *newWindow = newParent ? newParent->window() : nullptr; QVector<QPointer<QWidget> > newParents; // Remove event filters on ex-parents, keep them on still-parents @@ -1505,7 +1544,7 @@ bool QMenuBar::eventFilter(QObject *object, QEvent *event) d->setKeyboardMode(!d->keyboardState); } } - // fall through + Q_FALLTHROUGH(); case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: case QEvent::MouseMove: @@ -1573,7 +1612,7 @@ QSize QMenuBar::minimumSizeHint() const int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this); int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this); if(as_gui_menubar) { - int w = parentWidget() ? parentWidget()->width() : QApplication::desktop()->width(); + int w = parentWidget() ? parentWidget()->width() : QDesktopWidgetPrivate::width(); d->calcActionRects(w - (2 * fw), 0); for (int i = 0; ret.isNull() && i < d->actions.count(); ++i) ret = d->actionRects.at(i).size(); @@ -1625,7 +1664,7 @@ QSize QMenuBar::sizeHint() const int fw = style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, this); int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this); if(as_gui_menubar) { - const int w = parentWidget() ? parentWidget()->width() : QApplication::desktop()->width(); + const int w = parentWidget() ? parentWidget()->width() : QDesktopWidgetPrivate::width(); d->calcActionRects(w - (2 * fw), 0); for (int i = 0; i < d->actionRects.count(); ++i) { const QRect &actionRect = d->actionRects.at(i); @@ -1709,7 +1748,7 @@ void QMenuBarPrivate::_q_internalShortcutActivated(int id) QAction *act = actions.at(id); if (act && act->menu()) { if (QPlatformMenu *platformMenu = act->menu()->platformMenu()) { - platformMenu->showPopup(q->windowHandle(), actionRects.at(id), Q_NULLPTR); + platformMenu->showPopup(q->windowHandle(), actionRects.at(id), nullptr); return; } } diff --git a/src/widgets/widgets/qmenubar.h b/src/widgets/widgets/qmenubar.h index be70f4ea48..2f071e7e3b 100644 --- a/src/widgets/widgets/qmenubar.h +++ b/src/widgets/widgets/qmenubar.h @@ -60,13 +60,39 @@ class Q_WIDGETS_EXPORT QMenuBar : public QWidget Q_PROPERTY(bool nativeMenuBar READ isNativeMenuBar WRITE setNativeMenuBar) public: - explicit QMenuBar(QWidget *parent = Q_NULLPTR); + explicit QMenuBar(QWidget *parent = nullptr); ~QMenuBar(); using QWidget::addAction; QAction *addAction(const QString &text); QAction *addAction(const QString &text, const QObject *receiver, const char* member); +#ifdef Q_QDOC + template<typename Obj, typename PointerToMemberFunctionOrFunctor> + QAction *addAction(const QString &text, const Obj *receiver, PointerToMemberFunctionOrFunctor method); + template<typename Functor> + QAction *addAction(const QString &text, Functor functor); +#else + // addAction(QString): Connect to a QObject slot / functor or function pointer (with context) + template<typename Obj, typename Func1> + inline typename std::enable_if<!std::is_same<const char*, Func1>::value + && QtPrivate::IsPointerToTypeDerivedFromQObject<Obj*>::Value, QAction *>::type + addAction(const QString &text, const Obj *object, Func1 slot) + { + QAction *result = addAction(text); + connect(result, &QAction::triggered, object, std::move(slot)); + return result; + } + // addAction(QString): Connect to a functor or function pointer (without context) + template <typename Func1> + inline QAction *addAction(const QString &text, Func1 slot) + { + QAction *result = addAction(text); + connect(result, &QAction::triggered, std::move(slot)); + return result; + } +#endif // !Q_QDOC + QAction *addMenu(QMenu *menu); QMenu *addMenu(const QString &title); QMenu *addMenu(const QIcon &icon, const QString &title); diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp index 6b51388990..e66b702ffd 100644 --- a/src/widgets/widgets/qplaintextedit.cpp +++ b/src/widgets/widgets/qplaintextedit.cpp @@ -364,7 +364,7 @@ void QPlainTextDocumentLayout::layoutBlock(const QTextBlock &block) int extraMargin = 0; if (option.flags() & QTextOption::AddSpaceForLineAndParagraphSeparators) { QFontMetrics fm(block.charFormat().font()); - extraMargin += fm.width(QChar(0x21B5)); + extraMargin += fm.horizontalAdvance(QChar(0x21B5)); } tl->beginLayout(); qreal availableWidth = d->width; @@ -747,7 +747,8 @@ QPlainTextEditPrivate::QPlainTextEditPrivate() tabChangesFocus(false), lineWrap(QPlainTextEdit::WidgetWidth), wordWrap(QTextOption::WrapAtWordBoundaryOrAnywhere), - clickCausedFocus(0),topLine(0),topLineFracture(0), + clickCausedFocus(0), placeholderVisible(1), + topLine(0), topLineFracture(0), pageUpDownLastCursorYIsValid(false) { showCursorOnInitialShow = true; @@ -784,6 +785,7 @@ void QPlainTextEditPrivate::init(const QString &txt) QObject::connect(control, SIGNAL(selectionChanged()), q, SIGNAL(selectionChanged())); QObject::connect(control, SIGNAL(cursorPositionChanged()), q, SLOT(_q_cursorPositionChanged())); + QObject::connect(control, SIGNAL(textChanged()), q, SLOT(_q_textChanged())); QObject::connect(control, SIGNAL(textChanged()), q, SLOT(updateMicroFocus())); // set a null page size initially to avoid any relayouting until the textedit @@ -816,6 +818,24 @@ void QPlainTextEditPrivate::init(const QString &txt) #endif } +void QPlainTextEditPrivate::_q_textChanged() +{ + Q_Q(QPlainTextEdit); + + // We normally only repaint the part of view that contains text in the + // document that has changed (in _q_repaintContents). But the placeholder + // text is not a part of the document, but is drawn on separately. So whenever + // we either show or hide the placeholder text, we issue a full update. + bool placeholderCurrentyVisible = placeholderVisible; + + placeholderVisible = !placeholderText.isEmpty() + && q->document()->isEmpty() + && q->firstVisibleBlock().layout()->preeditAreaText().isEmpty(); + + if (placeholderCurrentyVisible != placeholderVisible) + viewport->update(); +} + void QPlainTextEditPrivate::_q_repaintContents(const QRectF &contentsRect) { Q_Q(QPlainTextEdit); @@ -1881,6 +1901,7 @@ static void fillBackground(QPainter *p, const QRectF &rect, QBrush brush, const */ void QPlainTextEdit::paintEvent(QPaintEvent *e) { + Q_D(QPlainTextEdit); QPainter painter(viewport()); Q_ASSERT(qobject_cast<QPlainTextDocumentLayout*>(document()->documentLayout())); @@ -1903,6 +1924,15 @@ void QPlainTextEdit::paintEvent(QPaintEvent *e) er.setRight(qMin(er.right(), maxX)); painter.setClipRect(er); + if (d->placeholderVisible) { + QColor col = d->control->palette().text().color(); + col.setAlpha(128); + painter.setPen(col); + painter.setClipRect(e->rect()); + const int margin = int(document()->documentMargin()); + QRectF textRect = viewportRect.adjusted(margin, margin, 0, 0); + painter.drawText(textRect, Qt::AlignTop | Qt::TextWordWrap, placeholderText()); + } QAbstractTextDocumentLayout::PaintContext context = getPaintContext(); @@ -1977,17 +2007,8 @@ void QPlainTextEdit::paintEvent(QPaintEvent *e) } } + layout->draw(&painter, offset, selections, er); - if (!placeholderText().isEmpty() && document()->isEmpty() && layout->preeditAreaText().isEmpty()) { - Q_D(QPlainTextEdit); - QColor col = d->control->palette().text().color(); - col.setAlpha(128); - painter.setPen(col); - const int margin = int(document()->documentMargin()); - painter.drawText(r.adjusted(margin, 0, 0, 0), Qt::AlignTop | Qt::TextWordWrap, placeholderText()); - } else { - layout->draw(&painter, offset, selections, er); - } if ((drawCursor && !drawCursorAsBlock) || (editable && context.cursorPosition < -1 && !layout->preeditAreaText().isEmpty())) { @@ -2453,29 +2474,51 @@ void QPlainTextEdit::setOverwriteMode(bool overwrite) d->control->setOverwriteMode(overwrite); } +#if QT_DEPRECATED_SINCE(5, 10) /*! \property QPlainTextEdit::tabStopWidth \brief the tab stop width in pixels + \deprecated in Qt 5.10. Use tabStopDistance instead. By default, this property contains a value of 80. */ int QPlainTextEdit::tabStopWidth() const { - Q_D(const QPlainTextEdit); - return qRound(d->control->document()->defaultTextOption().tabStop()); + return qRound(tabStopDistance()); } void QPlainTextEdit::setTabStopWidth(int width) { + setTabStopDistance(width); +} +#endif + +/*! + \property QPlainTextEdit::tabStopDistance + \brief the tab stop distance in pixels + \since 5.10 + + By default, this property contains a value of 80. +*/ + +qreal QPlainTextEdit::tabStopDistance() const +{ + Q_D(const QPlainTextEdit); + return d->control->document()->defaultTextOption().tabStopDistance(); +} + +void QPlainTextEdit::setTabStopDistance(qreal distance) +{ Q_D(QPlainTextEdit); QTextOption opt = d->control->document()->defaultTextOption(); - if (opt.tabStop() == width || width < 0) + if (opt.tabStopDistance() == distance || distance < 0) return; - opt.setTabStop(width); + opt.setTabStopDistance(distance); d->control->document()->setDefaultTextOption(opt); } + /*! \property QPlainTextEdit::cursorWidth diff --git a/src/widgets/widgets/qplaintextedit.h b/src/widgets/widgets/qplaintextedit.h index 29d610a129..34ec96715e 100644 --- a/src/widgets/widgets/qplaintextedit.h +++ b/src/widgets/widgets/qplaintextedit.h @@ -73,7 +73,10 @@ class Q_WIDGETS_EXPORT QPlainTextEdit : public QAbstractScrollArea Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) Q_PROPERTY(QString plainText READ toPlainText WRITE setPlainText NOTIFY textChanged USER true) Q_PROPERTY(bool overwriteMode READ overwriteMode WRITE setOverwriteMode) +#if QT_DEPRECATED_SINCE(5, 10) Q_PROPERTY(int tabStopWidth READ tabStopWidth WRITE setTabStopWidth) +#endif + Q_PROPERTY(qreal tabStopDistance READ tabStopDistance WRITE setTabStopDistance) Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth) Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags) Q_PROPERTY(int blockCount READ blockCount) @@ -88,8 +91,8 @@ public: }; Q_ENUM(LineWrapMode) - explicit QPlainTextEdit(QWidget *parent = Q_NULLPTR); - explicit QPlainTextEdit(const QString &text, QWidget *parent = Q_NULLPTR); + explicit QPlainTextEdit(QWidget *parent = nullptr); + explicit QPlainTextEdit(const QString &text, QWidget *parent = nullptr); virtual ~QPlainTextEdit(); void setDocument(QTextDocument *document); @@ -167,8 +170,13 @@ public: bool overwriteMode() const; void setOverwriteMode(bool overwrite); - int tabStopWidth() const; - void setTabStopWidth(int width); +#if QT_DEPRECATED_SINCE(5, 10) + QT_DEPRECATED int tabStopWidth() const; + QT_DEPRECATED void setTabStopWidth(int width); +#endif + + qreal tabStopDistance() const; + void setTabStopDistance(qreal distance); int cursorWidth() const; void setCursorWidth(int width); @@ -183,7 +191,7 @@ public: void print(QPagedPaintDevice *printer) const; int blockCount() const; - QVariant inputMethodQuery(Qt::InputMethodQuery property) const Q_DECL_OVERRIDE; + QVariant inputMethodQuery(Qt::InputMethodQuery property) const override; Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery query, QVariant argument) const; public Q_SLOTS: @@ -225,43 +233,43 @@ Q_SIGNALS: void modificationChanged(bool); protected: - virtual bool event(QEvent *e) Q_DECL_OVERRIDE; - virtual void timerEvent(QTimerEvent *e) Q_DECL_OVERRIDE; - virtual void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE; - virtual void keyReleaseEvent(QKeyEvent *e) Q_DECL_OVERRIDE; - virtual void resizeEvent(QResizeEvent *e) Q_DECL_OVERRIDE; - virtual void paintEvent(QPaintEvent *e) Q_DECL_OVERRIDE; - virtual void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE; - virtual void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE; - virtual void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE; - virtual void mouseDoubleClickEvent(QMouseEvent *e) Q_DECL_OVERRIDE; - virtual bool focusNextPrevChild(bool next) Q_DECL_OVERRIDE; + virtual bool event(QEvent *e) override; + virtual void timerEvent(QTimerEvent *e) override; + virtual void keyPressEvent(QKeyEvent *e) override; + virtual void keyReleaseEvent(QKeyEvent *e) override; + virtual void resizeEvent(QResizeEvent *e) override; + virtual void paintEvent(QPaintEvent *e) override; + virtual void mousePressEvent(QMouseEvent *e) override; + virtual void mouseMoveEvent(QMouseEvent *e) override; + virtual void mouseReleaseEvent(QMouseEvent *e) override; + virtual void mouseDoubleClickEvent(QMouseEvent *e) override; + virtual bool focusNextPrevChild(bool next) override; #ifndef QT_NO_CONTEXTMENU - virtual void contextMenuEvent(QContextMenuEvent *e) Q_DECL_OVERRIDE; + virtual void contextMenuEvent(QContextMenuEvent *e) override; #endif #ifndef QT_NO_DRAGANDDROP - virtual void dragEnterEvent(QDragEnterEvent *e) Q_DECL_OVERRIDE; - virtual void dragLeaveEvent(QDragLeaveEvent *e) Q_DECL_OVERRIDE; - virtual void dragMoveEvent(QDragMoveEvent *e) Q_DECL_OVERRIDE; - virtual void dropEvent(QDropEvent *e) Q_DECL_OVERRIDE; + virtual void dragEnterEvent(QDragEnterEvent *e) override; + virtual void dragLeaveEvent(QDragLeaveEvent *e) override; + virtual void dragMoveEvent(QDragMoveEvent *e) override; + virtual void dropEvent(QDropEvent *e) override; #endif - virtual void focusInEvent(QFocusEvent *e) Q_DECL_OVERRIDE; - virtual void focusOutEvent(QFocusEvent *e) Q_DECL_OVERRIDE; - virtual void showEvent(QShowEvent *) Q_DECL_OVERRIDE; - virtual void changeEvent(QEvent *e) Q_DECL_OVERRIDE; + virtual void focusInEvent(QFocusEvent *e) override; + virtual void focusOutEvent(QFocusEvent *e) override; + virtual void showEvent(QShowEvent *) override; + virtual void changeEvent(QEvent *e) override; #if QT_CONFIG(wheelevent) - virtual void wheelEvent(QWheelEvent *e) Q_DECL_OVERRIDE; + virtual void wheelEvent(QWheelEvent *e) override; #endif virtual QMimeData *createMimeDataFromSelection() const; virtual bool canInsertFromMimeData(const QMimeData *source) const; virtual void insertFromMimeData(const QMimeData *source); - virtual void inputMethodEvent(QInputMethodEvent *) Q_DECL_OVERRIDE; + virtual void inputMethodEvent(QInputMethodEvent *) override; QPlainTextEdit(QPlainTextEditPrivate &dd, QWidget *parent); - virtual void scrollContentsBy(int dx, int dy) Q_DECL_OVERRIDE; + virtual void scrollContentsBy(int dx, int dy) override; virtual void doSetTextCursor(const QTextCursor &cursor); QTextBlock firstVisibleBlock() const; @@ -275,6 +283,7 @@ protected: private: Q_DISABLE_COPY(QPlainTextEdit) Q_PRIVATE_SLOT(d_func(), void _q_repaintContents(const QRectF &r)) + Q_PRIVATE_SLOT(d_func(), void _q_textChanged()) Q_PRIVATE_SLOT(d_func(), void _q_adjustScrollbars()) Q_PRIVATE_SLOT(d_func(), void _q_verticalScrollbarActionTriggered(int)) Q_PRIVATE_SLOT(d_func(), void _q_cursorPositionChanged()) @@ -294,14 +303,14 @@ public: QPlainTextDocumentLayout(QTextDocument *document); ~QPlainTextDocumentLayout(); - void draw(QPainter *, const PaintContext &) Q_DECL_OVERRIDE; - int hitTest(const QPointF &, Qt::HitTestAccuracy ) const Q_DECL_OVERRIDE; + void draw(QPainter *, const PaintContext &) override; + int hitTest(const QPointF &, Qt::HitTestAccuracy ) const override; - int pageCount() const Q_DECL_OVERRIDE; - QSizeF documentSize() const Q_DECL_OVERRIDE; + int pageCount() const override; + QSizeF documentSize() const override; - QRectF frameBoundingRect(QTextFrame *) const Q_DECL_OVERRIDE; - QRectF blockBoundingRect(const QTextBlock &block) const Q_DECL_OVERRIDE; + QRectF frameBoundingRect(QTextFrame *) const override; + QRectF blockBoundingRect(const QTextBlock &block) const override; void ensureBlockLayout(const QTextBlock &block) const; @@ -311,7 +320,7 @@ public: void requestUpdate(); protected: - void documentChanged(int from, int /*charsRemoved*/, int charsAdded) Q_DECL_OVERRIDE; + void documentChanged(int from, int /*charsRemoved*/, int charsAdded) override; private: diff --git a/src/widgets/widgets/qplaintextedit_p.h b/src/widgets/widgets/qplaintextedit_p.h index 3d6e7781ed..534f0d4681 100644 --- a/src/widgets/widgets/qplaintextedit_p.h +++ b/src/widgets/widgets/qplaintextedit_p.h @@ -84,19 +84,19 @@ public: QPlainTextEditControl(QPlainTextEdit *parent); - QMimeData *createMimeDataFromSelection() const Q_DECL_OVERRIDE; - bool canInsertFromMimeData(const QMimeData *source) const Q_DECL_OVERRIDE; - void insertFromMimeData(const QMimeData *source) Q_DECL_OVERRIDE; - int hitTest(const QPointF &point, Qt::HitTestAccuracy = Qt::FuzzyHit) const Q_DECL_OVERRIDE; - QRectF blockBoundingRect(const QTextBlock &block) const Q_DECL_OVERRIDE; - QString anchorAt(const QPointF &pos) const Q_DECL_OVERRIDE; + QMimeData *createMimeDataFromSelection() const override; + bool canInsertFromMimeData(const QMimeData *source) const override; + void insertFromMimeData(const QMimeData *source) override; + int hitTest(const QPointF &point, Qt::HitTestAccuracy = Qt::FuzzyHit) const override; + QRectF blockBoundingRect(const QTextBlock &block) const override; + QString anchorAt(const QPointF &pos) const override; inline QRectF cursorRect(const QTextCursor &cursor) const { QRectF r = QWidgetTextControl::cursorRect(cursor); r.setLeft(qMax(r.left(), (qreal) 0.)); return r; } inline QRectF cursorRect() { return cursorRect(textCursor()); } - void ensureCursorVisible() Q_DECL_OVERRIDE { + void ensureCursorVisible() override { textEdit->ensureCursorVisible(); emit microFocusChanged(); } @@ -106,7 +106,7 @@ public: int topBlock; QTextBlock firstVisibleBlock() const; - QVariant loadResource(int type, const QUrl &name) Q_DECL_OVERRIDE { + QVariant loadResource(int type, const QUrl &name) override { return textEdit->loadResource(type, name); } @@ -121,6 +121,7 @@ public: void init(const QString &txt = QString()); void _q_repaintContents(const QRectF &contentsRect); + void _q_textChanged(); inline QPoint mapToContents(const QPoint &point) const { return QPoint(point.x() + horizontalOffset(), point.y() + verticalOffset()); } @@ -157,6 +158,7 @@ public: uint centerOnScroll : 1; uint inDrag : 1; uint clickCausedFocus : 1; + uint placeholderVisible : 1; int topLine; qreal topLineFracture; // for non-int sized fonts diff --git a/src/widgets/widgets/qprogressbar.cpp b/src/widgets/widgets/qprogressbar.cpp index c408a87339..56253b8e44 100644 --- a/src/widgets/widgets/qprogressbar.cpp +++ b/src/widgets/widgets/qprogressbar.cpp @@ -213,7 +213,7 @@ bool QProgressBarPrivate::repaintRequired() const Note that whether or not the text is drawn is dependent on the style. Currently CleanLooks and Plastique draw the text. Mac, Windows - and WindowsXP style do not. + and WindowsVista style do not. \sa textDirection */ @@ -421,7 +421,7 @@ QSize QProgressBar::sizeHint() const QStyleOptionProgressBar opt; initStyleOption(&opt); int cw = style()->pixelMetric(QStyle::PM_ProgressBarChunkWidth, &opt, this); - QSize size = QSize(qMax(9, cw) * 7 + fm.width(QLatin1Char('0')) * 4, fm.height() + 8); + QSize size = QSize(qMax(9, cw) * 7 + fm.horizontalAdvance(QLatin1Char('0')) * 4, fm.height() + 8); if (opt.orientation == Qt::Vertical) size = size.transposed(); return style()->sizeFromContents(QStyle::CT_ProgressBar, &opt, size, this); diff --git a/src/widgets/widgets/qprogressbar.h b/src/widgets/widgets/qprogressbar.h index e0f5e9084b..ec9686068c 100644 --- a/src/widgets/widgets/qprogressbar.h +++ b/src/widgets/widgets/qprogressbar.h @@ -68,7 +68,7 @@ public: enum Direction { TopToBottom, BottomToTop }; Q_ENUM(Direction) - explicit QProgressBar(QWidget *parent = Q_NULLPTR); + explicit QProgressBar(QWidget *parent = nullptr); ~QProgressBar(); int minimum() const; @@ -83,8 +83,8 @@ public: Qt::Alignment alignment() const; void setAlignment(Qt::Alignment alignment); - QSize sizeHint() const Q_DECL_OVERRIDE; - QSize minimumSizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; + QSize minimumSizeHint() const override; Qt::Orientation orientation() const; @@ -109,8 +109,8 @@ Q_SIGNALS: void valueChanged(int value); protected: - bool event(QEvent *e) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; + bool event(QEvent *e) override; + void paintEvent(QPaintEvent *) override; void initStyleOption(QStyleOptionProgressBar *option) const; private: diff --git a/src/widgets/widgets/qpushbutton.cpp b/src/widgets/widgets/qpushbutton.cpp index 90b1e7ef29..afb17f533b 100644 --- a/src/widgets/widgets/qpushbutton.cpp +++ b/src/widgets/widgets/qpushbutton.cpp @@ -40,6 +40,7 @@ #include "qapplication.h" #include "qbitmap.h" #include "qdesktopwidget.h" +#include <private/qdesktopwidget_p.h> #if QT_CONFIG(dialog) #include <private/qdialog_p.h> #endif @@ -58,10 +59,6 @@ #if QT_CONFIG(dialogbuttonbox) #include "qdialogbuttonbox.h" #endif -#if 0 // Used to be included in Qt4 for Q_WS_MAC -#include "private/qmacstyle_mac_p.h" -#include "private/qmacstyle_mac_p_p.h" -#endif #ifndef QT_NO_ACCESSIBILITY #include "qaccessible.h" @@ -83,7 +80,7 @@ QT_BEGIN_NAMESPACE \ingroup basicwidgets \inmodule QtWidgets - \image windows-pushbutton.jpg + \image windows-pushbutton.png The push button, or command button, is perhaps the most commonly used widget in any graphical user interface. Push (click) a button @@ -464,7 +461,7 @@ void QPushButton::keyPressEvent(QKeyEvent *e) click(); break; } - // fall through + Q_FALLTHROUGH(); default: QAbstractButton::keyPressEvent(e); } @@ -613,7 +610,7 @@ QPoint QPushButtonPrivate::adjustedMenuPosition() QPoint globalPos = q->mapToGlobal(rect.topLeft()); int x = globalPos.x(); int y = globalPos.y(); - const QRect availableGeometry = QApplication::desktop()->availableGeometry(q); + const QRect availableGeometry = QDesktopWidgetPrivate::availableGeometry(q); if (horizontal) { if (globalPos.y() + rect.height() + menuSize.height() <= availableGeometry.bottom()) { y += rect.height(); diff --git a/src/widgets/widgets/qpushbutton.h b/src/widgets/widgets/qpushbutton.h index c005f320cc..b02ba63d07 100644 --- a/src/widgets/widgets/qpushbutton.h +++ b/src/widgets/widgets/qpushbutton.h @@ -61,13 +61,13 @@ class Q_WIDGETS_EXPORT QPushButton : public QAbstractButton Q_PROPERTY(bool flat READ isFlat WRITE setFlat) public: - explicit QPushButton(QWidget *parent = Q_NULLPTR); - explicit QPushButton(const QString &text, QWidget *parent = Q_NULLPTR); - QPushButton(const QIcon& icon, const QString &text, QWidget *parent = Q_NULLPTR); + explicit QPushButton(QWidget *parent = nullptr); + explicit QPushButton(const QString &text, QWidget *parent = nullptr); + QPushButton(const QIcon& icon, const QString &text, QWidget *parent = nullptr); ~QPushButton(); - QSize sizeHint() const Q_DECL_OVERRIDE; - QSize minimumSizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; + QSize minimumSizeHint() const override; bool autoDefault() const; void setAutoDefault(bool); @@ -88,13 +88,13 @@ public Q_SLOTS: #endif protected: - bool event(QEvent *e) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; - void keyPressEvent(QKeyEvent *) Q_DECL_OVERRIDE; - void focusInEvent(QFocusEvent *) Q_DECL_OVERRIDE; - void focusOutEvent(QFocusEvent *) Q_DECL_OVERRIDE; + bool event(QEvent *e) override; + void paintEvent(QPaintEvent *) override; + void keyPressEvent(QKeyEvent *) override; + void focusInEvent(QFocusEvent *) override; + void focusOutEvent(QFocusEvent *) override; void initStyleOption(QStyleOptionButton *option) const; - QPushButton(QPushButtonPrivate &dd, QWidget* parent = Q_NULLPTR); + QPushButton(QPushButtonPrivate &dd, QWidget* parent = nullptr); public: diff --git a/src/widgets/widgets/qradiobutton.cpp b/src/widgets/widgets/qradiobutton.cpp index dfba32d3e8..fd8922ed28 100644 --- a/src/widgets/widgets/qradiobutton.cpp +++ b/src/widgets/widgets/qradiobutton.cpp @@ -72,6 +72,7 @@ void QRadioButtonPrivate::init() q->setAutoExclusive(true); q->setMouseTracking(true); q->setForegroundRole(QPalette::WindowText); + q->setAttribute(Qt::WA_MacShowFocusRect); setLayoutItemMargins(QStyle::SE_RadioButtonLayoutItem); } diff --git a/src/widgets/widgets/qradiobutton.h b/src/widgets/widgets/qradiobutton.h index 137ae01380..c6b5ddce84 100644 --- a/src/widgets/widgets/qradiobutton.h +++ b/src/widgets/widgets/qradiobutton.h @@ -56,18 +56,18 @@ class Q_WIDGETS_EXPORT QRadioButton : public QAbstractButton Q_OBJECT public: - explicit QRadioButton(QWidget *parent = Q_NULLPTR); - explicit QRadioButton(const QString &text, QWidget *parent = Q_NULLPTR); + explicit QRadioButton(QWidget *parent = nullptr); + explicit QRadioButton(const QString &text, QWidget *parent = nullptr); ~QRadioButton(); - QSize sizeHint() const Q_DECL_OVERRIDE; - QSize minimumSizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; + QSize minimumSizeHint() const override; protected: - bool event(QEvent *e) Q_DECL_OVERRIDE; - bool hitButton(const QPoint &) const Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; - void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE; + bool event(QEvent *e) override; + bool hitButton(const QPoint &) const override; + void paintEvent(QPaintEvent *) override; + void mouseMoveEvent(QMouseEvent *) override; void initStyleOption(QStyleOptionButton *button) const; diff --git a/src/widgets/widgets/qrubberband.h b/src/widgets/widgets/qrubberband.h index a05eb0d543..c683c24a18 100644 --- a/src/widgets/widgets/qrubberband.h +++ b/src/widgets/widgets/qrubberband.h @@ -56,7 +56,7 @@ class Q_WIDGETS_EXPORT QRubberBand : public QWidget public: enum Shape { Line, Rectangle }; - explicit QRubberBand(Shape, QWidget * = Q_NULLPTR); + explicit QRubberBand(Shape, QWidget * = nullptr); ~QRubberBand(); Shape shape() const; @@ -73,12 +73,12 @@ public: { resize(s.width(), s.height()); } protected: - bool event(QEvent *e) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; - void changeEvent(QEvent *) Q_DECL_OVERRIDE; - void showEvent(QShowEvent *) Q_DECL_OVERRIDE; - void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE; - void moveEvent(QMoveEvent *) Q_DECL_OVERRIDE; + bool event(QEvent *e) override; + void paintEvent(QPaintEvent *) override; + void changeEvent(QEvent *) override; + void showEvent(QShowEvent *) override; + void resizeEvent(QResizeEvent *) override; + void moveEvent(QMoveEvent *) override; void initStyleOption(QStyleOptionRubberBand *option) const; private: diff --git a/src/widgets/widgets/qscrollarea.h b/src/widgets/widgets/qscrollarea.h index d38bced2f2..6d252821c5 100644 --- a/src/widgets/widgets/qscrollarea.h +++ b/src/widgets/widgets/qscrollarea.h @@ -56,7 +56,7 @@ class Q_WIDGETS_EXPORT QScrollArea : public QAbstractScrollArea Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) public: - explicit QScrollArea(QWidget *parent = Q_NULLPTR); + explicit QScrollArea(QWidget *parent = nullptr); ~QScrollArea(); QWidget *widget() const; @@ -66,9 +66,9 @@ public: bool widgetResizable() const; void setWidgetResizable(bool resizable); - QSize sizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; - bool focusNextPrevChild(bool next) Q_DECL_OVERRIDE; + bool focusNextPrevChild(bool next) override; Qt::Alignment alignment() const; void setAlignment(Qt::Alignment); @@ -77,13 +77,13 @@ public: void ensureWidgetVisible(QWidget *childWidget, int xmargin = 50, int ymargin = 50); protected: - QScrollArea(QScrollAreaPrivate &dd, QWidget *parent = Q_NULLPTR); - bool event(QEvent *) Q_DECL_OVERRIDE; - bool eventFilter(QObject *, QEvent *) Q_DECL_OVERRIDE; - void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE; - void scrollContentsBy(int dx, int dy) Q_DECL_OVERRIDE; + QScrollArea(QScrollAreaPrivate &dd, QWidget *parent = nullptr); + bool event(QEvent *) override; + bool eventFilter(QObject *, QEvent *) override; + void resizeEvent(QResizeEvent *) override; + void scrollContentsBy(int dx, int dy) override; - QSize viewportSizeHint() const Q_DECL_OVERRIDE; + QSize viewportSizeHint() const override; private: Q_DECLARE_PRIVATE(QScrollArea) diff --git a/src/widgets/widgets/qscrollbar.h b/src/widgets/widgets/qscrollbar.h index 22b9bfcddb..171195fd24 100644 --- a/src/widgets/widgets/qscrollbar.h +++ b/src/widgets/widgets/qscrollbar.h @@ -56,25 +56,25 @@ class Q_WIDGETS_EXPORT QScrollBar : public QAbstractSlider { Q_OBJECT public: - explicit QScrollBar(QWidget *parent = Q_NULLPTR); - explicit QScrollBar(Qt::Orientation, QWidget *parent = Q_NULLPTR); + explicit QScrollBar(QWidget *parent = nullptr); + explicit QScrollBar(Qt::Orientation, QWidget *parent = nullptr); ~QScrollBar(); - QSize sizeHint() const Q_DECL_OVERRIDE; - bool event(QEvent *event) Q_DECL_OVERRIDE; + QSize sizeHint() const override; + bool event(QEvent *event) override; protected: #if QT_CONFIG(wheelevent) - void wheelEvent(QWheelEvent *) Q_DECL_OVERRIDE; + void wheelEvent(QWheelEvent *) override; #endif - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; - void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE; - void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE; - void hideEvent(QHideEvent*) Q_DECL_OVERRIDE; - void sliderChange(SliderChange change) Q_DECL_OVERRIDE; + void paintEvent(QPaintEvent *) override; + void mousePressEvent(QMouseEvent *) override; + void mouseReleaseEvent(QMouseEvent *) override; + void mouseMoveEvent(QMouseEvent *) override; + void hideEvent(QHideEvent*) override; + void sliderChange(SliderChange change) override; #ifndef QT_NO_CONTEXTMENU - void contextMenuEvent(QContextMenuEvent *) Q_DECL_OVERRIDE; + void contextMenuEvent(QContextMenuEvent *) override; #endif void initStyleOption(QStyleOptionSlider *option) const; diff --git a/src/widgets/widgets/qsizegrip.cpp b/src/widgets/widgets/qsizegrip.cpp index 1e1d847751..dc5a7158dd 100644 --- a/src/widgets/widgets/qsizegrip.cpp +++ b/src/widgets/widgets/qsizegrip.cpp @@ -55,6 +55,7 @@ #endif #include <private/qwidget_p.h> +#include <private/qdesktopwidget_p.h> #include <QtWidgets/qabstractscrollarea.h> QT_BEGIN_NAMESPACE @@ -312,7 +313,7 @@ void QSizeGrip::mousePressEvent(QMouseEvent * e) bool hasVerticalSizeConstraint = true; bool hasHorizontalSizeConstraint = true; if (tlw->isWindow()) - availableGeometry = QApplication::desktop()->availableGeometry(tlw); + availableGeometry = QDesktopWidgetPrivate::availableGeometry(tlw); else { const QWidget *tlwParent = tlw->parentWidget(); // Check if tlw is inside QAbstractScrollArea/QScrollArea. diff --git a/src/widgets/widgets/qsizegrip.h b/src/widgets/widgets/qsizegrip.h index 6ad2405339..5285ffdfb8 100644 --- a/src/widgets/widgets/qsizegrip.h +++ b/src/widgets/widgets/qsizegrip.h @@ -55,19 +55,19 @@ public: explicit QSizeGrip(QWidget *parent); ~QSizeGrip(); - QSize sizeHint() const Q_DECL_OVERRIDE; - void setVisible(bool) Q_DECL_OVERRIDE; + QSize sizeHint() const override; + void setVisible(bool) override; protected: - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; - void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE; - void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent *mouseEvent) Q_DECL_OVERRIDE; - void moveEvent(QMoveEvent *moveEvent) Q_DECL_OVERRIDE; - void showEvent(QShowEvent *showEvent) Q_DECL_OVERRIDE; - void hideEvent(QHideEvent *hideEvent) Q_DECL_OVERRIDE; - bool eventFilter(QObject *, QEvent *) Q_DECL_OVERRIDE; - bool event(QEvent *) Q_DECL_OVERRIDE; + void paintEvent(QPaintEvent *) override; + void mousePressEvent(QMouseEvent *) override; + void mouseMoveEvent(QMouseEvent *) override; + void mouseReleaseEvent(QMouseEvent *mouseEvent) override; + void moveEvent(QMoveEvent *moveEvent) override; + void showEvent(QShowEvent *showEvent) override; + void hideEvent(QHideEvent *hideEvent) override; + bool eventFilter(QObject *, QEvent *) override; + bool event(QEvent *) override; public: diff --git a/src/widgets/widgets/qslider.h b/src/widgets/widgets/qslider.h index 642e836af7..f74f9c8576 100644 --- a/src/widgets/widgets/qslider.h +++ b/src/widgets/widgets/qslider.h @@ -68,13 +68,13 @@ public: }; Q_ENUM(TickPosition) - explicit QSlider(QWidget *parent = Q_NULLPTR); - explicit QSlider(Qt::Orientation orientation, QWidget *parent = Q_NULLPTR); + explicit QSlider(QWidget *parent = nullptr); + explicit QSlider(Qt::Orientation orientation, QWidget *parent = nullptr); ~QSlider(); - QSize sizeHint() const Q_DECL_OVERRIDE; - QSize minimumSizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; + QSize minimumSizeHint() const override; void setTickPosition(TickPosition position); TickPosition tickPosition() const; @@ -82,13 +82,13 @@ public: void setTickInterval(int ti); int tickInterval() const; - bool event(QEvent *event) Q_DECL_OVERRIDE; + bool event(QEvent *event) override; protected: - void paintEvent(QPaintEvent *ev) Q_DECL_OVERRIDE; - void mousePressEvent(QMouseEvent *ev) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent *ev) Q_DECL_OVERRIDE; - void mouseMoveEvent(QMouseEvent *ev) Q_DECL_OVERRIDE; + void paintEvent(QPaintEvent *ev) override; + void mousePressEvent(QMouseEvent *ev) override; + void mouseReleaseEvent(QMouseEvent *ev) override; + void mouseMoveEvent(QMouseEvent *ev) override; void initStyleOption(QStyleOptionSlider *option) const; diff --git a/src/widgets/widgets/qspinbox.cpp b/src/widgets/widgets/qspinbox.cpp index b62a7768ce..561215ec85 100644 --- a/src/widgets/widgets/qspinbox.cpp +++ b/src/widgets/widgets/qspinbox.cpp @@ -61,10 +61,10 @@ class QSpinBoxPrivate : public QAbstractSpinBoxPrivate Q_DECLARE_PUBLIC(QSpinBox) public: QSpinBoxPrivate(); - void emitSignals(EmitPolicy ep, const QVariant &) Q_DECL_OVERRIDE; + void emitSignals(EmitPolicy ep, const QVariant &) override; - virtual QVariant valueFromText(const QString &n) const Q_DECL_OVERRIDE; - virtual QString textFromValue(const QVariant &n) const Q_DECL_OVERRIDE; + virtual QVariant valueFromText(const QString &n) const override; + virtual QString textFromValue(const QVariant &n) const override; QVariant validateAndInterpret(QString &input, int &pos, QValidator::State &state) const; @@ -82,10 +82,10 @@ class QDoubleSpinBoxPrivate : public QAbstractSpinBoxPrivate Q_DECLARE_PUBLIC(QDoubleSpinBox) public: QDoubleSpinBoxPrivate(); - void emitSignals(EmitPolicy ep, const QVariant &) Q_DECL_OVERRIDE; + void emitSignals(EmitPolicy ep, const QVariant &) override; - virtual QVariant valueFromText(const QString &n) const Q_DECL_OVERRIDE; - virtual QString textFromValue(const QVariant &n) const Q_DECL_OVERRIDE; + virtual QVariant valueFromText(const QString &n) const override; + virtual QString textFromValue(const QVariant &n) const override; QVariant validateAndInterpret(QString &input, int &pos, QValidator::State &state) const; double round(double input) const; diff --git a/src/widgets/widgets/qspinbox.h b/src/widgets/widgets/qspinbox.h index b61e665413..73489c9a68 100644 --- a/src/widgets/widgets/qspinbox.h +++ b/src/widgets/widgets/qspinbox.h @@ -62,7 +62,7 @@ class Q_WIDGETS_EXPORT QSpinBox : public QAbstractSpinBox Q_PROPERTY(int displayIntegerBase READ displayIntegerBase WRITE setDisplayIntegerBase) public: - explicit QSpinBox(QWidget *parent = Q_NULLPTR); + explicit QSpinBox(QWidget *parent = nullptr); ~QSpinBox(); int value() const; @@ -123,7 +123,7 @@ class Q_WIDGETS_EXPORT QDoubleSpinBox : public QAbstractSpinBox Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep) Q_PROPERTY(double value READ value WRITE setValue NOTIFY valueChanged USER true) public: - explicit QDoubleSpinBox(QWidget *parent = Q_NULLPTR); + explicit QDoubleSpinBox(QWidget *parent = nullptr); ~QDoubleSpinBox(); double value() const; diff --git a/src/widgets/widgets/qsplashscreen.cpp b/src/widgets/widgets/qsplashscreen.cpp index fb92d5de0d..468fc272b5 100644 --- a/src/widgets/widgets/qsplashscreen.cpp +++ b/src/widgets/widgets/qsplashscreen.cpp @@ -41,6 +41,7 @@ #include "qapplication.h" #include "qdesktopwidget.h" +#include <private/qdesktopwidget_p.h> #include "qpainter.h" #include "qpixmap.h" #include "qtextdocument.h" @@ -140,7 +141,7 @@ QSplashScreen::QSplashScreen(const QPixmap &pixmap, Qt::WindowFlags f) one. In that case pass the proper desktop() as the \a parent. */ QSplashScreen::QSplashScreen(QWidget *parent, const QPixmap &pixmap, Qt::WindowFlags f) - : QWidget(*new QSplashScreenPrivate, parent, Qt::SplashScreen | f) + : QWidget(*new QSplashScreenPrivate, parent, Qt::SplashScreen | Qt::FramelessWindowHint | f) { d_func()->pixmap = pixmap; setPixmap(d_func()->pixmap); // Does an implicit repaint @@ -282,7 +283,7 @@ void QSplashScreen::setPixmap(const QPixmap &pixmap) QRect r(QPoint(), d->pixmap.size() / d->pixmap.devicePixelRatio()); resize(r.size()); - move(QApplication::desktop()->screenGeometry().center() - r.center()); + move(QDesktopWidgetPrivate::screenGeometry().center() - r.center()); if (isVisible()) repaint(); } diff --git a/src/widgets/widgets/qsplashscreen.h b/src/widgets/widgets/qsplashscreen.h index 1971b8bacf..8bdf4e7749 100644 --- a/src/widgets/widgets/qsplashscreen.h +++ b/src/widgets/widgets/qsplashscreen.h @@ -73,9 +73,9 @@ Q_SIGNALS: void messageChanged(const QString &message); protected: - bool event(QEvent *e) Q_DECL_OVERRIDE; + bool event(QEvent *e) override; virtual void drawContents(QPainter *painter); - void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE; + void mousePressEvent(QMouseEvent *) override; private: Q_DISABLE_COPY(QSplashScreen) diff --git a/src/widgets/widgets/qsplitter.cpp b/src/widgets/widgets/qsplitter.cpp index 5f49623941..8e4c846402 100644 --- a/src/widgets/widgets/qsplitter.cpp +++ b/src/widgets/widgets/qsplitter.cpp @@ -1372,7 +1372,7 @@ bool QSplitter::event(QEvent *e) if (!d->firstShow) break; d->firstShow = false; - // fall through + Q_FALLTHROUGH(); case QEvent::HideToParent: case QEvent::ShowToParent: case QEvent::LayoutRequest: diff --git a/src/widgets/widgets/qsplitter.h b/src/widgets/widgets/qsplitter.h index bc4d7bca39..16fac48d1c 100644 --- a/src/widgets/widgets/qsplitter.h +++ b/src/widgets/widgets/qsplitter.h @@ -64,8 +64,8 @@ class Q_WIDGETS_EXPORT QSplitter : public QFrame Q_PROPERTY(bool childrenCollapsible READ childrenCollapsible WRITE setChildrenCollapsible) public: - explicit QSplitter(QWidget* parent = Q_NULLPTR); - explicit QSplitter(Qt::Orientation, QWidget* parent = Q_NULLPTR); + explicit QSplitter(QWidget* parent = nullptr); + explicit QSplitter(Qt::Orientation, QWidget* parent = nullptr); ~QSplitter(); void addWidget(QWidget *widget); @@ -84,8 +84,8 @@ public: bool opaqueResize() const; void refresh(); - QSize sizeHint() const Q_DECL_OVERRIDE; - QSize minimumSizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; + QSize minimumSizeHint() const override; QList<int> sizes() const; void setSizes(const QList<int> &list); @@ -111,12 +111,12 @@ Q_SIGNALS: protected: virtual QSplitterHandle *createHandle(); - void childEvent(QChildEvent *) Q_DECL_OVERRIDE; + void childEvent(QChildEvent *) override; - bool event(QEvent *) Q_DECL_OVERRIDE; - void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE; + bool event(QEvent *) override; + void resizeEvent(QResizeEvent *) override; - void changeEvent(QEvent *) Q_DECL_OVERRIDE; + void changeEvent(QEvent *) override; void moveSplitter(int pos, int index); void setRubberBand(int position); int closestLegalPosition(int, int); @@ -145,15 +145,15 @@ public: bool opaqueResize() const; QSplitter *splitter() const; - QSize sizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; protected: - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; - void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE; - void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE; - void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE; - bool event(QEvent *) Q_DECL_OVERRIDE; + void paintEvent(QPaintEvent *) override; + void mouseMoveEvent(QMouseEvent *) override; + void mousePressEvent(QMouseEvent *) override; + void mouseReleaseEvent(QMouseEvent *) override; + void resizeEvent(QResizeEvent *) override; + bool event(QEvent *) override; void moveSplitter(int p); int closestLegalPosition(int p); diff --git a/src/widgets/widgets/qstackedwidget.cpp b/src/widgets/widgets/qstackedwidget.cpp index 9d92855a40..2217dab870 100644 --- a/src/widgets/widgets/qstackedwidget.cpp +++ b/src/widgets/widgets/qstackedwidget.cpp @@ -101,7 +101,7 @@ public: widget is removed from the stacked widget, the currentChanged() and widgetRemoved() signals are emitted respectively. - \sa QStackedLayout, QTabWidget, {Config Dialog Example} + \sa QStackedLayout, QTabWidget */ /*! diff --git a/src/widgets/widgets/qstackedwidget.h b/src/widgets/widgets/qstackedwidget.h index 29df145b70..5508f905d4 100644 --- a/src/widgets/widgets/qstackedwidget.h +++ b/src/widgets/widgets/qstackedwidget.h @@ -56,7 +56,7 @@ class Q_WIDGETS_EXPORT QStackedWidget : public QFrame Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentChanged) Q_PROPERTY(int count READ count) public: - explicit QStackedWidget(QWidget *parent = Q_NULLPTR); + explicit QStackedWidget(QWidget *parent = nullptr); ~QStackedWidget(); int addWidget(QWidget *w); @@ -79,7 +79,7 @@ Q_SIGNALS: void widgetRemoved(int index); protected: - bool event(QEvent *e) Q_DECL_OVERRIDE; + bool event(QEvent *e) override; private: Q_DISABLE_COPY(QStackedWidget) diff --git a/src/widgets/widgets/qstatusbar.cpp b/src/widgets/widgets/qstatusbar.cpp index 4635b73a81..fb551158bf 100644 --- a/src/widgets/widgets/qstatusbar.cpp +++ b/src/widgets/widgets/qstatusbar.cpp @@ -601,7 +601,7 @@ QString QStatusBar::currentMessage() const } /*! - \fn QStatusBar::messageChanged(const QString &message) + \fn void QStatusBar::messageChanged(const QString &message) This signal is emitted whenever the temporary status message changes. The new temporary message is passed in the \a message diff --git a/src/widgets/widgets/qstatusbar.h b/src/widgets/widgets/qstatusbar.h index 9ac637931c..2492e8487f 100644 --- a/src/widgets/widgets/qstatusbar.h +++ b/src/widgets/widgets/qstatusbar.h @@ -56,7 +56,7 @@ class Q_WIDGETS_EXPORT QStatusBar: public QWidget Q_PROPERTY(bool sizeGripEnabled READ isSizeGripEnabled WRITE setSizeGripEnabled) public: - explicit QStatusBar(QWidget *parent = Q_NULLPTR); + explicit QStatusBar(QWidget *parent = nullptr); virtual ~QStatusBar(); void addWidget(QWidget *widget, int stretch = 0); @@ -79,14 +79,14 @@ Q_SIGNALS: void messageChanged(const QString &text); protected: - void showEvent(QShowEvent *) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; - void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE; + void showEvent(QShowEvent *) override; + void paintEvent(QPaintEvent *) override; + void resizeEvent(QResizeEvent *) override; // ### Qt 6: consider making reformat() and hideOrShow() private void reformat(); void hideOrShow(); - bool event(QEvent *) Q_DECL_OVERRIDE; + bool event(QEvent *) override; private: Q_DISABLE_COPY(QStatusBar) diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp index adaafc7d21..258e018151 100644 --- a/src/widgets/widgets/qtabbar.cpp +++ b/src/widgets/widgets/qtabbar.cpp @@ -1034,7 +1034,7 @@ void QTabBar::removeTab(int index) newIndex--; if (d->validIndex(newIndex)) break; - // else fallthrough + Q_FALLTHROUGH(); case SelectRightTab: newIndex = index; if (newIndex >= d->tabList.size()) @@ -2221,7 +2221,7 @@ void QTabBar::changeEvent(QEvent *event) d->elideMode = Qt::TextElideMode(style()->styleHint(QStyle::SH_TabBar_ElideMode, 0, this)); if (!d->useScrollButtonsSetByUser) d->useScrollButtons = !style()->styleHint(QStyle::SH_TabBar_PreferNoArrows, 0, this); - // fallthrough + Q_FALLTHROUGH(); case QEvent::FontChange: d->textSizes.clear(); d->refresh(); diff --git a/src/widgets/widgets/qtabbar.h b/src/widgets/widgets/qtabbar.h index ebcd1094ef..fc619355f0 100644 --- a/src/widgets/widgets/qtabbar.h +++ b/src/widgets/widgets/qtabbar.h @@ -71,7 +71,7 @@ class Q_WIDGETS_EXPORT QTabBar: public QWidget Q_PROPERTY(bool changeCurrentOnDrag READ changeCurrentOnDrag WRITE setChangeCurrentOnDrag) public: - explicit QTabBar(QWidget *parent = Q_NULLPTR); + explicit QTabBar(QWidget *parent = nullptr); ~QTabBar(); enum Shape { RoundedNorth, RoundedSouth, RoundedWest, RoundedEast, @@ -136,8 +136,8 @@ public: int currentIndex() const; int count() const; - QSize sizeHint() const Q_DECL_OVERRIDE; - QSize minimumSizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; + QSize minimumSizeHint() const override; void setDrawBase(bool drawTheBase); bool drawBase() const; @@ -194,20 +194,20 @@ protected: virtual void tabRemoved(int index); virtual void tabLayoutChange(); - bool event(QEvent *) Q_DECL_OVERRIDE; - void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE; - void showEvent(QShowEvent *) Q_DECL_OVERRIDE; - void hideEvent(QHideEvent *) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; - void mousePressEvent (QMouseEvent *) Q_DECL_OVERRIDE; - void mouseMoveEvent (QMouseEvent *) Q_DECL_OVERRIDE; - void mouseReleaseEvent (QMouseEvent *) Q_DECL_OVERRIDE; + bool event(QEvent *) override; + void resizeEvent(QResizeEvent *) override; + void showEvent(QShowEvent *) override; + void hideEvent(QHideEvent *) override; + void paintEvent(QPaintEvent *) override; + void mousePressEvent (QMouseEvent *) override; + void mouseMoveEvent (QMouseEvent *) override; + void mouseReleaseEvent (QMouseEvent *) override; #if QT_CONFIG(wheelevent) - void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; + void wheelEvent(QWheelEvent *event) override; #endif - void keyPressEvent(QKeyEvent *) Q_DECL_OVERRIDE; - void changeEvent(QEvent *) Q_DECL_OVERRIDE; - void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE; + void keyPressEvent(QKeyEvent *) override; + void changeEvent(QEvent *) override; + void timerEvent(QTimerEvent *event) override; void initStyleOption(QStyleOptionTab *option, int tabIndex) const; #ifndef QT_NO_ACCESSIBILITY diff --git a/src/widgets/widgets/qtabbar_p.h b/src/widgets/widgets/qtabbar_p.h index 52e139c707..1092878f2c 100644 --- a/src/widgets/widgets/qtabbar_p.h +++ b/src/widgets/widgets/qtabbar_p.h @@ -71,17 +71,17 @@ QT_BEGIN_NAMESPACE class QMovableTabWidget : public QWidget { public: - explicit QMovableTabWidget(QWidget *parent = Q_NULLPTR); + explicit QMovableTabWidget(QWidget *parent = nullptr); void setPixmap(const QPixmap &pixmap); protected: - void paintEvent(QPaintEvent *e) Q_DECL_OVERRIDE; + void paintEvent(QPaintEvent *e) override; private: QPixmap m_pixmap; }; -class QTabBarPrivate : public QWidgetPrivate +class Q_WIDGETS_EXPORT QTabBarPrivate : public QWidgetPrivate { Q_DECLARE_PUBLIC(QTabBar) public: @@ -142,9 +142,9 @@ public: TabBarAnimation(Tab *t, QTabBarPrivate *_priv) : tab(t), priv(_priv) { setEasingCurve(QEasingCurve::InOutQuad); } - void updateCurrentValue(const QVariant ¤t) Q_DECL_OVERRIDE; + void updateCurrentValue(const QVariant ¤t) override; - void updateState(State, State newState) Q_DECL_OVERRIDE; + void updateState(State, State newState) override; private: //these are needed for the callbacks Tab *tab; @@ -180,7 +180,7 @@ public: int indexAtPos(const QPoint &p) const; - inline bool isAnimated() const { Q_Q(const QTabBar); return q->style()->styleHint(QStyle::SH_Widget_Animate, 0, q); } + inline bool isAnimated() const { Q_Q(const QTabBar); return q->style()->styleHint(QStyle::SH_Widget_Animation_Duration, 0, q) > 0; } inline bool validIndex(int index) const { return index >= 0 && index < tabList.count(); } void setCurrentNextEnabledIndex(int offset); @@ -278,12 +278,12 @@ class CloseButton : public QAbstractButton public: explicit CloseButton(QWidget *parent = 0); - QSize sizeHint() const Q_DECL_OVERRIDE; - QSize minimumSizeHint() const Q_DECL_OVERRIDE + QSize sizeHint() const override; + QSize minimumSizeHint() const override { return sizeHint(); } - void enterEvent(QEvent *event) Q_DECL_OVERRIDE; - void leaveEvent(QEvent *event) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; + void enterEvent(QEvent *event) override; + void leaveEvent(QEvent *event) override; + void paintEvent(QPaintEvent *event) override; }; QT_END_NAMESPACE diff --git a/src/widgets/widgets/qtabwidget.cpp b/src/widgets/widgets/qtabwidget.cpp index dc866a38cf..60a924510a 100644 --- a/src/widgets/widgets/qtabwidget.cpp +++ b/src/widgets/widgets/qtabwidget.cpp @@ -44,6 +44,7 @@ #include "qapplication.h" #include "qbitmap.h" #include "qdesktopwidget.h" +#include <private/qdesktopwidget_p.h> #include "qevent.h" #include "qlayout.h" #include "qstackedwidget.h" @@ -844,7 +845,7 @@ QSize QTabWidget::sizeHint() const if(usesScrollButtons()) t = t.boundedTo(QSize(200,200)); else - t = t.boundedTo(QApplication::desktop()->size()); + t = t.boundedTo(QDesktopWidgetPrivate::size()); QSize sz = basicSize(d->pos == North || d->pos == South, lc, rc, s, t); @@ -912,7 +913,7 @@ int QTabWidget::heightForWidth(int width) const if(usesScrollButtons()) t = t.boundedTo(QSize(200,200)); else - t = t.boundedTo(QApplication::desktop()->size()); + t = t.boundedTo(QDesktopWidgetPrivate::size()); const bool tabIsHorizontal = (d->pos == North || d->pos == South); const int contentsWidth = width - padding.width(); diff --git a/src/widgets/widgets/qtabwidget.h b/src/widgets/widgets/qtabwidget.h index b80fdba1fb..f55e71488b 100644 --- a/src/widgets/widgets/qtabwidget.h +++ b/src/widgets/widgets/qtabwidget.h @@ -68,7 +68,7 @@ class Q_WIDGETS_EXPORT QTabWidget : public QWidget Q_PROPERTY(bool tabBarAutoHide READ tabBarAutoHide WRITE setTabBarAutoHide) public: - explicit QTabWidget(QWidget *parent = Q_NULLPTR); + explicit QTabWidget(QWidget *parent = nullptr); ~QTabWidget(); int addTab(QWidget *widget, const QString &); @@ -120,10 +120,10 @@ public: TabShape tabShape() const; void setTabShape(TabShape s); - QSize sizeHint() const Q_DECL_OVERRIDE; - QSize minimumSizeHint() const Q_DECL_OVERRIDE; - int heightForWidth(int width) const Q_DECL_OVERRIDE; - bool hasHeightForWidth() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; + QSize minimumSizeHint() const override; + int heightForWidth(int width) const override; + bool hasHeightForWidth() const override; void setCornerWidget(QWidget * w, Qt::Corner corner = Qt::TopRightCorner); QWidget * cornerWidget(Qt::Corner corner = Qt::TopRightCorner) const; @@ -161,13 +161,13 @@ protected: virtual void tabInserted(int index); virtual void tabRemoved(int index); - void showEvent(QShowEvent *) Q_DECL_OVERRIDE; - void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE; - void keyPressEvent(QKeyEvent *) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; + void showEvent(QShowEvent *) override; + void resizeEvent(QResizeEvent *) override; + void keyPressEvent(QKeyEvent *) override; + void paintEvent(QPaintEvent *) override; void setTabBar(QTabBar *); - void changeEvent(QEvent *) Q_DECL_OVERRIDE; - bool event(QEvent *) Q_DECL_OVERRIDE; + void changeEvent(QEvent *) override; + bool event(QEvent *) override; void initStyleOption(QStyleOptionTabWidgetFrame *option) const; diff --git a/src/widgets/widgets/qtextbrowser.cpp b/src/widgets/widgets/qtextbrowser.cpp index 0797120960..fa4dd14c92 100644 --- a/src/widgets/widgets/qtextbrowser.cpp +++ b/src/widgets/widgets/qtextbrowser.cpp @@ -135,7 +135,7 @@ public: void setSource(const QUrl &url); // re-imlemented from QTextEditPrivate - virtual QUrl resolveUrl(const QUrl &url) const Q_DECL_OVERRIDE; + virtual QUrl resolveUrl(const QUrl &url) const override; inline QUrl resolveUrl(const QString &url) const { return resolveUrl(QUrl(url)); } diff --git a/src/widgets/widgets/qtextbrowser.h b/src/widgets/widgets/qtextbrowser.h index f36c86bc86..ea81256f50 100644 --- a/src/widgets/widgets/qtextbrowser.h +++ b/src/widgets/widgets/qtextbrowser.h @@ -63,7 +63,7 @@ class Q_WIDGETS_EXPORT QTextBrowser : public QTextEdit Q_PROPERTY(bool openLinks READ openLinks WRITE setOpenLinks) public: - explicit QTextBrowser(QWidget* parent = Q_NULLPTR); + explicit QTextBrowser(QWidget* parent = nullptr); virtual ~QTextBrowser(); QUrl source() const; @@ -71,7 +71,7 @@ public: QStringList searchPaths() const; void setSearchPaths(const QStringList &paths); - virtual QVariant loadResource(int type, const QUrl &name) Q_DECL_OVERRIDE; + virtual QVariant loadResource(int type, const QUrl &name) override; bool isBackwardAvailable() const; bool isForwardAvailable() const; @@ -104,14 +104,14 @@ Q_SIGNALS: void anchorClicked(const QUrl &); protected: - bool event(QEvent *e) Q_DECL_OVERRIDE; - virtual void keyPressEvent(QKeyEvent *ev) Q_DECL_OVERRIDE; - virtual void mouseMoveEvent(QMouseEvent *ev) Q_DECL_OVERRIDE; - virtual void mousePressEvent(QMouseEvent *ev) Q_DECL_OVERRIDE; - virtual void mouseReleaseEvent(QMouseEvent *ev) Q_DECL_OVERRIDE; - virtual void focusOutEvent(QFocusEvent *ev) Q_DECL_OVERRIDE; - virtual bool focusNextPrevChild(bool next) Q_DECL_OVERRIDE; - virtual void paintEvent(QPaintEvent *e) Q_DECL_OVERRIDE; + bool event(QEvent *e) override; + virtual void keyPressEvent(QKeyEvent *ev) override; + virtual void mouseMoveEvent(QMouseEvent *ev) override; + virtual void mousePressEvent(QMouseEvent *ev) override; + virtual void mouseReleaseEvent(QMouseEvent *ev) override; + virtual void focusOutEvent(QFocusEvent *ev) override; + virtual bool focusNextPrevChild(bool next) override; + virtual void paintEvent(QPaintEvent *e) override; private: Q_DISABLE_COPY(QTextBrowser) diff --git a/src/widgets/widgets/qtextedit.cpp b/src/widgets/widgets/qtextedit.cpp index 374267f9f2..95c85dc4fe 100644 --- a/src/widgets/widgets/qtextedit.cpp +++ b/src/widgets/widgets/qtextedit.cpp @@ -84,19 +84,19 @@ class QTextEditControl : public QWidgetTextControl public: inline QTextEditControl(QObject *parent) : QWidgetTextControl(parent) {} - virtual QMimeData *createMimeDataFromSelection() const Q_DECL_OVERRIDE { + virtual QMimeData *createMimeDataFromSelection() const override { QTextEdit *ed = qobject_cast<QTextEdit *>(parent()); if (!ed) return QWidgetTextControl::createMimeDataFromSelection(); return ed->createMimeDataFromSelection(); } - virtual bool canInsertFromMimeData(const QMimeData *source) const Q_DECL_OVERRIDE { + virtual bool canInsertFromMimeData(const QMimeData *source) const override { QTextEdit *ed = qobject_cast<QTextEdit *>(parent()); if (!ed) return QWidgetTextControl::canInsertFromMimeData(source); return ed->canInsertFromMimeData(source); } - virtual void insertFromMimeData(const QMimeData *source) Q_DECL_OVERRIDE { + virtual void insertFromMimeData(const QMimeData *source) override { QTextEdit *ed = qobject_cast<QTextEdit *>(parent()); if (!ed) QWidgetTextControl::insertFromMimeData(source); @@ -1955,27 +1955,48 @@ void QTextEdit::setOverwriteMode(bool overwrite) d->control->setOverwriteMode(overwrite); } +#if QT_DEPRECATED_SINCE(5, 10) /*! \property QTextEdit::tabStopWidth \brief the tab stop width in pixels \since 4.1 + \deprecated in Qt 5.10. Use tabStopDistance instead. By default, this property contains a value of 80 pixels. */ int QTextEdit::tabStopWidth() const { - Q_D(const QTextEdit); - return qRound(d->control->document()->defaultTextOption().tabStop()); + return qRound(tabStopDistance()); } void QTextEdit::setTabStopWidth(int width) { + setTabStopDistance(width); +} +#endif + +/*! + \property QTextEdit::tabStopDistance + \brief the tab stop distance in pixels + \since 5.10 + + By default, this property contains a value of 80 pixels. +*/ + +qreal QTextEdit::tabStopDistance() const +{ + Q_D(const QTextEdit); + return d->control->document()->defaultTextOption().tabStopDistance(); +} + +void QTextEdit::setTabStopDistance(qreal distance) +{ Q_D(QTextEdit); QTextOption opt = d->control->document()->defaultTextOption(); - if (opt.tabStop() == width || width < 0) + if (opt.tabStopDistance() == distance || distance < 0) return; - opt.setTabStop(width); + opt.setTabStopDistance(distance); d->control->document()->setDefaultTextOption(opt); } diff --git a/src/widgets/widgets/qtextedit.h b/src/widgets/widgets/qtextedit.h index ff52fde2ed..9e0913160d 100644 --- a/src/widgets/widgets/qtextedit.h +++ b/src/widgets/widgets/qtextedit.h @@ -75,7 +75,10 @@ class Q_WIDGETS_EXPORT QTextEdit : public QAbstractScrollArea #endif Q_PROPERTY(QString plainText READ toPlainText WRITE setPlainText DESIGNABLE false) Q_PROPERTY(bool overwriteMode READ overwriteMode WRITE setOverwriteMode) +#if QT_DEPRECATED_SINCE(5, 10) Q_PROPERTY(int tabStopWidth READ tabStopWidth WRITE setTabStopWidth) +#endif + Q_PROPERTY(qreal tabStopDistance READ tabStopDistance WRITE setTabStopDistance) Q_PROPERTY(bool acceptRichText READ acceptRichText WRITE setAcceptRichText) Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth) Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags) @@ -99,8 +102,8 @@ public: Q_DECLARE_FLAGS(AutoFormatting, AutoFormattingFlag) Q_FLAG(AutoFormatting) - explicit QTextEdit(QWidget *parent = Q_NULLPTR); - explicit QTextEdit(const QString &text, QWidget *parent = Q_NULLPTR); + explicit QTextEdit(QWidget *parent = nullptr); + explicit QTextEdit(const QString &text, QWidget *parent = nullptr); virtual ~QTextEdit(); void setDocument(QTextDocument *document); @@ -185,8 +188,13 @@ public: bool overwriteMode() const; void setOverwriteMode(bool overwrite); - int tabStopWidth() const; - void setTabStopWidth(int width); +#if QT_DEPRECATED_SINCE(5, 10) + QT_DEPRECATED int tabStopWidth() const; + QT_DEPRECATED void setTabStopWidth(int width); +#endif + + qreal tabStopDistance() const; + void setTabStopDistance(qreal distance); int cursorWidth() const; void setCursorWidth(int width); @@ -208,7 +216,7 @@ public: void print(QPagedPaintDevice *printer) const; - QVariant inputMethodQuery(Qt::InputMethodQuery property) const Q_DECL_OVERRIDE; + QVariant inputMethodQuery(Qt::InputMethodQuery property) const override; Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery query, QVariant argument) const; public Q_SLOTS: @@ -262,43 +270,43 @@ Q_SIGNALS: void cursorPositionChanged(); protected: - virtual bool event(QEvent *e) Q_DECL_OVERRIDE; - virtual void timerEvent(QTimerEvent *e) Q_DECL_OVERRIDE; - virtual void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE; - virtual void keyReleaseEvent(QKeyEvent *e) Q_DECL_OVERRIDE; - virtual void resizeEvent(QResizeEvent *e) Q_DECL_OVERRIDE; - virtual void paintEvent(QPaintEvent *e) Q_DECL_OVERRIDE; - virtual void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE; - virtual void mouseMoveEvent(QMouseEvent *e) Q_DECL_OVERRIDE; - virtual void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE; - virtual void mouseDoubleClickEvent(QMouseEvent *e) Q_DECL_OVERRIDE; - virtual bool focusNextPrevChild(bool next) Q_DECL_OVERRIDE; + virtual bool event(QEvent *e) override; + virtual void timerEvent(QTimerEvent *e) override; + virtual void keyPressEvent(QKeyEvent *e) override; + virtual void keyReleaseEvent(QKeyEvent *e) override; + virtual void resizeEvent(QResizeEvent *e) override; + virtual void paintEvent(QPaintEvent *e) override; + virtual void mousePressEvent(QMouseEvent *e) override; + virtual void mouseMoveEvent(QMouseEvent *e) override; + virtual void mouseReleaseEvent(QMouseEvent *e) override; + virtual void mouseDoubleClickEvent(QMouseEvent *e) override; + virtual bool focusNextPrevChild(bool next) override; #ifndef QT_NO_CONTEXTMENU - virtual void contextMenuEvent(QContextMenuEvent *e) Q_DECL_OVERRIDE; + virtual void contextMenuEvent(QContextMenuEvent *e) override; #endif #ifndef QT_NO_DRAGANDDROP - virtual void dragEnterEvent(QDragEnterEvent *e) Q_DECL_OVERRIDE; - virtual void dragLeaveEvent(QDragLeaveEvent *e) Q_DECL_OVERRIDE; - virtual void dragMoveEvent(QDragMoveEvent *e) Q_DECL_OVERRIDE; - virtual void dropEvent(QDropEvent *e) Q_DECL_OVERRIDE; + virtual void dragEnterEvent(QDragEnterEvent *e) override; + virtual void dragLeaveEvent(QDragLeaveEvent *e) override; + virtual void dragMoveEvent(QDragMoveEvent *e) override; + virtual void dropEvent(QDropEvent *e) override; #endif - virtual void focusInEvent(QFocusEvent *e) Q_DECL_OVERRIDE; - virtual void focusOutEvent(QFocusEvent *e) Q_DECL_OVERRIDE; - virtual void showEvent(QShowEvent *) Q_DECL_OVERRIDE; - virtual void changeEvent(QEvent *e) Q_DECL_OVERRIDE; + virtual void focusInEvent(QFocusEvent *e) override; + virtual void focusOutEvent(QFocusEvent *e) override; + virtual void showEvent(QShowEvent *) override; + virtual void changeEvent(QEvent *e) override; #if QT_CONFIG(wheelevent) - virtual void wheelEvent(QWheelEvent *e) Q_DECL_OVERRIDE; + virtual void wheelEvent(QWheelEvent *e) override; #endif virtual QMimeData *createMimeDataFromSelection() const; virtual bool canInsertFromMimeData(const QMimeData *source) const; virtual void insertFromMimeData(const QMimeData *source); - virtual void inputMethodEvent(QInputMethodEvent *) Q_DECL_OVERRIDE; + virtual void inputMethodEvent(QInputMethodEvent *) override; QTextEdit(QTextEditPrivate &dd, QWidget *parent); - virtual void scrollContentsBy(int dx, int dy) Q_DECL_OVERRIDE; + virtual void scrollContentsBy(int dx, int dy) override; virtual void doSetTextCursor(const QTextCursor &cursor); void zoomInF(float range); diff --git a/src/widgets/widgets/qtoolbar.cpp b/src/widgets/widgets/qtoolbar.cpp index 243fb6d555..7b6a2a329f 100644 --- a/src/widgets/widgets/qtoolbar.cpp +++ b/src/widgets/widgets/qtoolbar.cpp @@ -92,7 +92,6 @@ void QToolBarPrivate::init() q->setBackgroundRole(QPalette::Button); q->setAttribute(Qt::WA_Hover); q->setAttribute(Qt::WA_X11NetWmWindowTypeToolBar); - q->setProperty("_q_platform_MacUseNSWindow", QVariant(true)); QStyle *style = q->style(); int e = style->pixelMetric(QStyle::PM_ToolBarIconSize, 0, q); @@ -804,7 +803,7 @@ QAction *QToolBar::addAction(const QIcon &icon, const QString &text, return action; } -/*!\fn QAction *QToolBar::addAction(const QString &text, const QObject *receiver, PointerToMemberFunction method) +/*!\fn template<typename PointerToMemberFunction> QAction *QToolBar::addAction(const QString &text, const QObject *receiver, PointerToMemberFunction method) \since 5.6 @@ -816,7 +815,7 @@ QAction *QToolBar::addAction(const QIcon &icon, const QString &text, \a method of the \a receiver. */ -/*!\fn QAction *QToolBar::addAction(const QString &text, Functor functor) +/*!\fn template<typename Functor> QAction *QToolBar::addAction(const QString &text, Functor functor) \since 5.6 @@ -828,7 +827,7 @@ QAction *QToolBar::addAction(const QIcon &icon, const QString &text, \a functor. */ -/*!\fn QAction *QToolBar::addAction(const QString &text, const QObject *context, Functor functor) +/*!\fn template<typename Functor> QAction *QToolBar::addAction(const QString &text, const QObject *context, Functor functor) \since 5.6 @@ -842,7 +841,7 @@ QAction *QToolBar::addAction(const QIcon &icon, const QString &text, If \a context is destroyed, the functor will not be called. */ -/*!\fn QAction *QToolBar::addAction(const QIcon &icon, const QString &text, const QObject *receiver, PointerToMemberFunction method) +/*!\fn template<typename PointerToMemberFunction> QAction *QToolBar::addAction(const QIcon &icon, const QString &text, const QObject *receiver, PointerToMemberFunction method) \since 5.6 @@ -854,7 +853,7 @@ QAction *QToolBar::addAction(const QIcon &icon, const QString &text, \a method of the \a receiver. */ -/*!\fn QAction *QToolBar::addAction(const QIcon &icon, const QString &text, Functor functor) +/*!\fn template<typename Functor> QAction *QToolBar::addAction(const QIcon &icon, const QString &text, Functor functor) \since 5.6 @@ -866,7 +865,7 @@ QAction *QToolBar::addAction(const QIcon &icon, const QString &text, \a functor. */ -/*!\fn QAction *QToolBar::addAction(const QIcon &icon, const QString &text, const QObject *context, Functor functor) +/*!\fn template<typename Functor> QAction *QToolBar::addAction(const QIcon &icon, const QString &text, const QObject *context, Functor functor) \since 5.6 diff --git a/src/widgets/widgets/qtoolbar.h b/src/widgets/widgets/qtoolbar.h index e0f2d9b073..0253541a2e 100644 --- a/src/widgets/widgets/qtoolbar.h +++ b/src/widgets/widgets/qtoolbar.h @@ -76,8 +76,8 @@ class Q_WIDGETS_EXPORT QToolBar : public QWidget Q_PROPERTY(bool floatable READ isFloatable WRITE setFloatable) public: - explicit QToolBar(const QString &title, QWidget *parent = Q_NULLPTR); - explicit QToolBar(QWidget *parent = Q_NULLPTR); + explicit QToolBar(const QString &title, QWidget *parent = nullptr); + explicit QToolBar(QWidget *parent = nullptr); ~QToolBar(); void setMovable(bool movable); @@ -121,7 +121,7 @@ public: addAction(const QString &text, const Obj *object, Func1 slot) { QAction *result = addAction(text); - connect(result, &QAction::triggered, object, slot); + connect(result, &QAction::triggered, object, std::move(slot)); return result; } // addAction(QString): Connect to a functor or function pointer (without context) @@ -139,7 +139,7 @@ public: addAction(const QIcon &actionIcon, const QString &text, const Obj *object, Func1 slot) { QAction *result = addAction(actionIcon, text); - connect(result, &QAction::triggered, object, slot); + connect(result, &QAction::triggered, object, std::move(slot)); return result; } // addAction(QIcon, QString): Connect to a functor or function pointer (without context) @@ -188,10 +188,10 @@ Q_SIGNALS: void visibilityChanged(bool visible); protected: - void actionEvent(QActionEvent *event) Q_DECL_OVERRIDE; - void changeEvent(QEvent *event) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; - bool event(QEvent *event) Q_DECL_OVERRIDE; + void actionEvent(QActionEvent *event) override; + void changeEvent(QEvent *event) override; + void paintEvent(QPaintEvent *event) override; + bool event(QEvent *event) override; void initStyleOption(QStyleOptionToolBar *option) const; diff --git a/src/widgets/widgets/qtoolbarextension_p.h b/src/widgets/widgets/qtoolbarextension_p.h index b6223107c4..a388f1e40f 100644 --- a/src/widgets/widgets/qtoolbarextension_p.h +++ b/src/widgets/widgets/qtoolbarextension_p.h @@ -64,8 +64,8 @@ class Q_AUTOTEST_EXPORT QToolBarExtension : public QToolButton public: explicit QToolBarExtension(QWidget *parent); - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; - QSize sizeHint() const Q_DECL_OVERRIDE; + void paintEvent(QPaintEvent *) override; + QSize sizeHint() const override; public Q_SLOTS: void setOrientation(Qt::Orientation o); diff --git a/src/widgets/widgets/qtoolbarlayout_p.h b/src/widgets/widgets/qtoolbarlayout_p.h index 9a81c4e50e..8c60164439 100644 --- a/src/widgets/widgets/qtoolbarlayout_p.h +++ b/src/widgets/widgets/qtoolbarlayout_p.h @@ -68,7 +68,7 @@ class QToolBarItem : public QWidgetItem { public: QToolBarItem(QWidget *widget); - bool isEmpty() const Q_DECL_OVERRIDE; + bool isEmpty() const override; QAction *action; bool customWidget; @@ -82,22 +82,22 @@ public: QToolBarLayout(QWidget *parent = 0); ~QToolBarLayout(); - void addItem(QLayoutItem *item) Q_DECL_OVERRIDE; - QLayoutItem *itemAt(int index) const Q_DECL_OVERRIDE; - QLayoutItem *takeAt(int index) Q_DECL_OVERRIDE; - int count() const Q_DECL_OVERRIDE; + void addItem(QLayoutItem *item) override; + QLayoutItem *itemAt(int index) const override; + QLayoutItem *takeAt(int index) override; + int count() const override; - bool isEmpty() const Q_DECL_OVERRIDE; - void invalidate() Q_DECL_OVERRIDE; - Qt::Orientations expandingDirections() const Q_DECL_OVERRIDE; + bool isEmpty() const override; + void invalidate() override; + Qt::Orientations expandingDirections() const override; - void setGeometry(const QRect &r) Q_DECL_OVERRIDE; - QSize minimumSize() const Q_DECL_OVERRIDE; - QSize sizeHint() const Q_DECL_OVERRIDE; + void setGeometry(const QRect &r) override; + QSize minimumSize() const override; + QSize sizeHint() const override; void insertAction(int index, QAction *action); int indexOf(QAction *action) const; - int indexOf(QWidget *widget) const Q_DECL_OVERRIDE { return QLayout::indexOf(widget); } + int indexOf(QWidget *widget) const override { return QLayout::indexOf(widget); } bool layoutActions(const QSize &size); QSize expandedSize(const QSize &size) const; diff --git a/src/widgets/widgets/qtoolbarseparator_p.h b/src/widgets/widgets/qtoolbarseparator_p.h index 8c9cf9f46a..d52b4fa6ae 100644 --- a/src/widgets/widgets/qtoolbarseparator_p.h +++ b/src/widgets/widgets/qtoolbarseparator_p.h @@ -71,9 +71,9 @@ public: Qt::Orientation orientation() const; - QSize sizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; + void paintEvent(QPaintEvent *) override; void initStyleOption(QStyleOption *option) const; public Q_SLOTS: diff --git a/src/widgets/widgets/qtoolbox.cpp b/src/widgets/widgets/qtoolbox.cpp index fdcd07eb06..46ade0277c 100644 --- a/src/widgets/widgets/qtoolbox.cpp +++ b/src/widgets/widgets/qtoolbox.cpp @@ -69,12 +69,12 @@ public: inline void setSelected(bool b) { selected = b; update(); } inline void setIndex(int newIndex) { indexInPage = newIndex; } - QSize sizeHint() const Q_DECL_OVERRIDE; - QSize minimumSizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; + QSize minimumSizeHint() const override; protected: void initStyleOption(QStyleOptionToolBox *opt) const; - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; + void paintEvent(QPaintEvent *) override; private: bool selected; diff --git a/src/widgets/widgets/qtoolbox.h b/src/widgets/widgets/qtoolbox.h index 321507ba07..2796631b94 100644 --- a/src/widgets/widgets/qtoolbox.h +++ b/src/widgets/widgets/qtoolbox.h @@ -57,7 +57,7 @@ class Q_WIDGETS_EXPORT QToolBox : public QFrame Q_PROPERTY(int count READ count) public: - explicit QToolBox(QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags()); + explicit QToolBox(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); ~QToolBox(); int addItem(QWidget *widget, const QString &text); @@ -95,11 +95,11 @@ Q_SIGNALS: void currentChanged(int index); protected: - bool event(QEvent *e) Q_DECL_OVERRIDE; + bool event(QEvent *e) override; virtual void itemInserted(int index); virtual void itemRemoved(int index); - void showEvent(QShowEvent *e) Q_DECL_OVERRIDE; - void changeEvent(QEvent *) Q_DECL_OVERRIDE; + void showEvent(QShowEvent *e) override; + void changeEvent(QEvent *) override; private: diff --git a/src/widgets/widgets/qtoolbutton.cpp b/src/widgets/widgets/qtoolbutton.cpp index 58f1a296b2..c2bf13a3e9 100644 --- a/src/widgets/widgets/qtoolbutton.cpp +++ b/src/widgets/widgets/qtoolbutton.cpp @@ -41,6 +41,7 @@ #include <qapplication.h> #include <qdesktopwidget.h> +#include <private/qdesktopwidget_p.h> #include <qdrawutil.h> #include <qevent.h> #include <qicon.h> @@ -347,7 +348,7 @@ QSize QToolButton::sizeHint() const if (opt.toolButtonStyle != Qt::ToolButtonIconOnly) { QSize textSize = fm.size(Qt::TextShowMnemonic, text()); - textSize.setWidth(textSize.width() + fm.width(QLatin1Char(' '))*2); + textSize.setWidth(textSize.width() + fm.horizontalAdvance(QLatin1Char(' '))*2); if (opt.toolButtonStyle == Qt::ToolButtonTextUnderIcon) { h += 4 + textSize.height(); if (textSize.width() > w) @@ -749,7 +750,7 @@ void QToolButtonPrivate::popupTimerDone() #endif QPoint p; const QRect rect = q->rect(); // Find screen via point in case of QGraphicsProxyWidget. - QRect screen = QApplication::desktop()->availableGeometry(q->mapToGlobal(rect.center())); + QRect screen = QDesktopWidgetPrivate::availableGeometry(q->mapToGlobal(rect.center())); QSize sh = ((QToolButton*)(QMenu*)actualMenu)->receivers(SIGNAL(aboutToShow()))? QSize() : actualMenu->sizeHint(); if (horizontal) { if (q->isRightToLeft()) { diff --git a/src/widgets/widgets/qtoolbutton.h b/src/widgets/widgets/qtoolbutton.h index dd9964cb94..52bd2d5f7a 100644 --- a/src/widgets/widgets/qtoolbutton.h +++ b/src/widgets/widgets/qtoolbutton.h @@ -71,11 +71,11 @@ public: }; Q_ENUM(ToolButtonPopupMode) - explicit QToolButton(QWidget *parent = Q_NULLPTR); + explicit QToolButton(QWidget *parent = nullptr); ~QToolButton(); - QSize sizeHint() const Q_DECL_OVERRIDE; - QSize minimumSizeHint() const Q_DECL_OVERRIDE; + QSize sizeHint() const override; + QSize minimumSizeHint() const override; Qt::ToolButtonStyle toolButtonStyle() const; @@ -106,19 +106,19 @@ Q_SIGNALS: void triggered(QAction *); protected: - bool event(QEvent *e) Q_DECL_OVERRIDE; - void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; - void actionEvent(QActionEvent *) Q_DECL_OVERRIDE; - - void enterEvent(QEvent *) Q_DECL_OVERRIDE; - void leaveEvent(QEvent *) Q_DECL_OVERRIDE; - void timerEvent(QTimerEvent *) Q_DECL_OVERRIDE; - void changeEvent(QEvent *) Q_DECL_OVERRIDE; - - bool hitButton(const QPoint &pos) const Q_DECL_OVERRIDE; - void nextCheckState() Q_DECL_OVERRIDE; + bool event(QEvent *e) override; + void mousePressEvent(QMouseEvent *) override; + void mouseReleaseEvent(QMouseEvent *) override; + void paintEvent(QPaintEvent *) override; + void actionEvent(QActionEvent *) override; + + void enterEvent(QEvent *) override; + void leaveEvent(QEvent *) override; + void timerEvent(QTimerEvent *) override; + void changeEvent(QEvent *) override; + + bool hitButton(const QPoint &pos) const override; + void nextCheckState() override; void initStyleOption(QStyleOptionToolButton *option) const; private: diff --git a/src/widgets/widgets/qwidgetanimator.cpp b/src/widgets/widgets/qwidgetanimator.cpp index fdf2b5d321..b6828a14ef 100644 --- a/src/widgets/widgets/qwidgetanimator.cpp +++ b/src/widgets/widgets/qwidgetanimator.cpp @@ -93,13 +93,13 @@ void QWidgetAnimator::animate(QWidget *widget, const QRect &_final_geometry, boo #ifndef QT_NO_ANIMATION //If the QStyle has animations, animate - if (widget->style()->styleHint(QStyle::SH_Widget_Animate, 0, widget)) { + if (const int animationDuration = widget->style()->styleHint(QStyle::SH_Widget_Animation_Duration, 0, widget)) { AnimationMap::const_iterator it = m_animation_map.constFind(widget); if (it != m_animation_map.constEnd() && (*it)->endValue().toRect() == final_geometry) return; QPropertyAnimation *anim = new QPropertyAnimation(widget, "geometry", widget); - anim->setDuration(animate ? 200 : 0); + anim->setDuration(animate ? animationDuration : 0); anim->setEasingCurve(QEasingCurve::InOutQuad); anim->setEndValue(final_geometry); m_animation_map[widget] = anim; diff --git a/src/widgets/widgets/qwidgetlinecontrol.cpp b/src/widgets/widgets/qwidgetlinecontrol.cpp index 4f4a6f70b5..623ca5b0a1 100644 --- a/src/widgets/widgets/qwidgetlinecontrol.cpp +++ b/src/widgets/widgets/qwidgetlinecontrol.cpp @@ -44,7 +44,9 @@ #endif #include "qclipboard.h" #include <private/qguiapplication_p.h> +#if QT_CONFIG(completer) #include <private/qcompleter_p.h> +#endif #include <qpa/qplatformtheme.h> #include <qstylehints.h> #ifndef QT_NO_ACCESSIBILITY @@ -1177,9 +1179,9 @@ bool QWidgetLineControl::hasAcceptableInput(const QString &str) const that blanks will be used, false that previous input is used. Calling this when no inputMask is set is undefined. */ -QString QWidgetLineControl::maskString(uint pos, const QString &str, bool clear) const +QString QWidgetLineControl::maskString(int pos, const QString &str, bool clear) const { - if (pos >= (uint)m_maxLength) + if (pos >= m_maxLength) return QString::fromLatin1(""); QString fill; @@ -1252,13 +1254,13 @@ QString QWidgetLineControl::maskString(uint pos, const QString &str, bool clear) Returns a "cleared" string with only separators and blank chars. Calling this when no inputMask is set is undefined. */ -QString QWidgetLineControl::clearString(uint pos, uint len) const +QString QWidgetLineControl::clearString(int pos, int len) const { - if (pos >= (uint)m_maxLength) + if (pos >= m_maxLength) return QString(); QString s; - int end = qMin((uint)m_maxLength, pos + len); + int end = qMin(m_maxLength, pos + len); for (int i = pos; i < end; ++i) if (m_maskData[i].separator) s += m_maskData[i].maskChar; diff --git a/src/widgets/widgets/qwidgetlinecontrol_p.h b/src/widgets/widgets/qwidgetlinecontrol_p.h index 16c9cc71eb..ca70e2c02f 100644 --- a/src/widgets/widgets/qwidgetlinecontrol_p.h +++ b/src/widgets/widgets/qwidgetlinecontrol_p.h @@ -500,8 +500,8 @@ private: void parseInputMask(const QString &maskFields); bool isValidInput(QChar key, QChar mask) const; bool hasAcceptableInput(const QString &text) const; - QString maskString(uint pos, const QString &str, bool clear = false) const; - QString clearString(uint pos, uint len) const; + QString maskString(int pos, const QString &str, bool clear = false) const; + QString clearString(int pos, int len) const; QString stripString(const QString &str) const; int findInMask(int pos, bool forward, bool findSeparator, QChar searchChar = QChar()) const; @@ -550,7 +550,7 @@ Q_SIGNALS: void editFocusChange(bool); #endif protected: - virtual void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE; + virtual void timerEvent(QTimerEvent *event) override; private Q_SLOTS: void _q_deleteSelected(); diff --git a/src/widgets/widgets/qwidgetresizehandler.cpp b/src/widgets/widgets/qwidgetresizehandler.cpp index 8a1f26dbc2..45010d1768 100644 --- a/src/widgets/widgets/qwidgetresizehandler.cpp +++ b/src/widgets/widgets/qwidgetresizehandler.cpp @@ -42,6 +42,7 @@ #include "qframe.h" #include "qapplication.h" #include "qdesktopwidget.h" +#include <private/qdesktopwidget_p.h> #include "qcursor.h" #if QT_CONFIG(sizegrip) #include "qsizegrip.h" @@ -261,7 +262,7 @@ void QWidgetResizeHandler::mouseMoveEvent(QMouseEvent *e) // Workaround for window managers which refuse to move a tool window partially offscreen. if (QGuiApplication::platformName() == QLatin1String("xcb")) { - const QRect desktop = QApplication::desktop()->availableGeometry(widget); + const QRect desktop = QDesktopWidgetPrivate::availableGeometry(widget); pp.rx() = qMax(pp.x(), desktop.left()); pp.ry() = qMax(pp.y(), desktop.top()); p.rx() = qMin(p.x(), desktop.right()); @@ -382,7 +383,7 @@ void QWidgetResizeHandler::keyPressEvent(QKeyEvent * e) switch (e->key()) { case Qt::Key_Left: pos.rx() -= delta; - if (pos.x() <= QApplication::desktop()->geometry().left()) { + if (pos.x() <= QDesktopWidgetPrivate::geometry().left()) { if (mode == TopLeft || mode == BottomLeft) { moveOffset.rx() += delta; invertedMoveOffset.rx() += delta; @@ -407,7 +408,7 @@ void QWidgetResizeHandler::keyPressEvent(QKeyEvent * e) break; case Qt::Key_Right: pos.rx() += delta; - if (pos.x() >= QApplication::desktop()->geometry().right()) { + if (pos.x() >= QDesktopWidgetPrivate::geometry().right()) { if (mode == TopRight || mode == BottomRight) { moveOffset.rx() += delta; invertedMoveOffset.rx() += delta; @@ -432,7 +433,7 @@ void QWidgetResizeHandler::keyPressEvent(QKeyEvent * e) break; case Qt::Key_Up: pos.ry() -= delta; - if (pos.y() <= QApplication::desktop()->geometry().top()) { + if (pos.y() <= QDesktopWidgetPrivate::geometry().top()) { if (mode == TopLeft || mode == TopRight) { moveOffset.ry() += delta; invertedMoveOffset.ry() += delta; @@ -457,7 +458,7 @@ void QWidgetResizeHandler::keyPressEvent(QKeyEvent * e) break; case Qt::Key_Down: pos.ry() += delta; - if (pos.y() >= QApplication::desktop()->geometry().bottom()) { + if (pos.y() >= QDesktopWidgetPrivate::geometry().bottom()) { if (mode == BottomLeft || mode == BottomRight) { moveOffset.ry() += delta; invertedMoveOffset.ry() += delta; diff --git a/src/widgets/widgets/qwidgetresizehandler_p.h b/src/widgets/widgets/qwidgetresizehandler_p.h index 669cb6f256..b87bbd6229 100644 --- a/src/widgets/widgets/qwidgetresizehandler_p.h +++ b/src/widgets/widgets/qwidgetresizehandler_p.h @@ -95,7 +95,7 @@ Q_SIGNALS: void activate(); protected: - bool eventFilter(QObject *o, QEvent *e) Q_DECL_OVERRIDE; + bool eventFilter(QObject *o, QEvent *e) override; void mouseMoveEvent(QMouseEvent *e); void keyPressEvent(QKeyEvent *e); diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index da6dcfbe8b..93158dcdba 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -93,7 +93,10 @@ #include "private/qapplication_p.h" #include "private/qshortcutmap_p.h" #include <qkeysequence.h> -#define ACCEL_KEY(k) (!qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? \ +#define ACCEL_KEY(k) ((qApp->testAttribute(Qt::AA_DontShowIconsInMenus) \ + ? false \ + : qApp->styleHints()->showShortcutsInContextMenus()) \ + && !qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? \ QLatin1Char('\t') + QKeySequence(k).toString(QKeySequence::NativeText) : QString()) #else @@ -1411,7 +1414,7 @@ QRectF QWidgetTextControlPrivate::rectForPosition(int position) const if (relativePos < line.textLength() - line.textStart()) w = line.cursorToX(relativePos + 1) - x; else - w = QFontMetrics(block.layout()->font()).width(QLatin1Char(' ')); // in sync with QTextLine::draw() + w = QFontMetrics(block.layout()->font()).horizontalAdvance(QLatin1Char(' ')); // in sync with QTextLine::draw() } r = QRectF(layoutPos.x() + x, layoutPos.y() + line.y(), cursorWidth + w, line.height()); @@ -1424,10 +1427,6 @@ QRectF QWidgetTextControlPrivate::rectForPosition(int position) const namespace { struct QTextFrameComparator { -#if defined(Q_CC_MSVC) && _MSC_VER < 1600 -//The STL implementation of MSVC 2008 requires the definition - bool operator()(QTextFrame *frame1, QTextFrame *frame2) { return frame1->firstPosition() < frame2->firstPosition(); } -#endif bool operator()(QTextFrame *frame, int position) { return frame->firstPosition() < position; } bool operator()(int position, QTextFrame *frame) { return position < frame->firstPosition(); } }; @@ -1884,8 +1883,6 @@ void QWidgetTextControlPrivate::contextMenuEvent(const QPoint &screenPos, const Q_UNUSED(contextWidget); #else Q_Q(QWidgetTextControl); - if (!hasFocus) - return; QMenu *menu = q->createStandardContextMenu(docPos, contextWidget); if (!menu) return; diff --git a/src/widgets/widgets/qwidgettextcontrol_p.h b/src/widgets/widgets/qwidgettextcontrol_p.h index 11ff63c5e4..4b2acbd934 100644 --- a/src/widgets/widgets/qwidgettextcontrol_p.h +++ b/src/widgets/widgets/qwidgettextcontrol_p.h @@ -258,9 +258,9 @@ public: bool findNextPrevAnchor(const QTextCursor& from, bool next, QTextCursor& newAnchor); protected: - virtual void timerEvent(QTimerEvent *e) Q_DECL_OVERRIDE; + virtual void timerEvent(QTimerEvent *e) override; - virtual bool event(QEvent *e) Q_DECL_OVERRIDE; + virtual bool event(QEvent *e) override; private: Q_DISABLE_COPY(QWidgetTextControl) @@ -296,9 +296,9 @@ class QTextEditMimeData : public QMimeData public: inline QTextEditMimeData(const QTextDocumentFragment &aFragment) : fragment(aFragment) {} - virtual QStringList formats() const Q_DECL_OVERRIDE; + virtual QStringList formats() const override; protected: - virtual QVariant retrieveData(const QString &mimeType, QVariant::Type type) const Q_DECL_OVERRIDE; + virtual QVariant retrieveData(const QString &mimeType, QVariant::Type type) const override; private: void setup() const; |