diff options
Diffstat (limited to 'src/widgets/widgets')
39 files changed, 419 insertions, 300 deletions
diff --git a/src/widgets/widgets/qabstractspinbox.cpp b/src/widgets/widgets/qabstractspinbox.cpp index 25369a01b6..92af91b66e 100644 --- a/src/widgets/widgets/qabstractspinbox.cpp +++ b/src/widgets/widgets/qabstractspinbox.cpp @@ -396,6 +396,30 @@ bool QAbstractSpinBox::isAccelerated() const } /*! + \property QAbstractSpinBox::showGroupSeparator + \since 5.3 + + + This property holds whether a thousands separator is enabled. By default this + property is false. +*/ +bool QAbstractSpinBox::isGroupSeparatorShown() const +{ + Q_D(const QAbstractSpinBox); + return d->showGroupSeparator; +} + +void QAbstractSpinBox::setGroupSeparatorShown(bool shown) +{ + Q_D(QAbstractSpinBox); + if (d->showGroupSeparator == shown) + return; + d->showGroupSeparator = shown; + d->setValue(d->value, EmitIfChanged); + updateGeometry(); +} + +/*! \enum QAbstractSpinBox::CorrectionMode This enum type describes the mode the spinbox will use to correct @@ -1316,7 +1340,8 @@ QAbstractSpinBoxPrivate::QAbstractSpinBoxPrivate() cachedState(QValidator::Invalid), pendingEmit(false), readOnly(false), wrapping(false), ignoreCursorPositionChanged(false), frame(true), accelerate(false), keyboardTracking(true), cleared(false), ignoreUpdateEdit(false), correctionMode(QAbstractSpinBox::CorrectToPreviousValue), - acceleration(0), hoverControl(QStyle::SC_None), buttonSymbols(QAbstractSpinBox::UpDownArrows), validator(0) + acceleration(0), hoverControl(QStyle::SC_None), buttonSymbols(QAbstractSpinBox::UpDownArrows), validator(0), + showGroupSeparator(0) { } @@ -1491,13 +1516,12 @@ void QAbstractSpinBoxPrivate::_q_editorCursorPositionChanged(int oldpos, int new * (newpos < pos ? -1 : 1)) - newpos + pos : 0; - const bool wasBlocked = edit->blockSignals(true); + const QSignalBlocker blocker(edit); if (selSize != 0) { edit->setSelection(pos - selSize, selSize); } else { edit->setCursorPosition(pos); } - edit->blockSignals(wasBlocked); } ignoreCursorPositionChanged = false; } @@ -1697,7 +1721,7 @@ void QAbstractSpinBoxPrivate::updateEdit() const bool empty = edit->text().isEmpty(); int cursor = edit->cursorPosition(); int selsize = edit->selectedText().size(); - const bool sb = edit->blockSignals(true); + const QSignalBlocker blocker(edit); edit->setText(newText); if (!specialValue()) { @@ -1709,7 +1733,6 @@ void QAbstractSpinBoxPrivate::updateEdit() edit->setCursorPosition(empty ? prefix.size() : cursor); } } - edit->blockSignals(sb); q->update(); } diff --git a/src/widgets/widgets/qabstractspinbox.h b/src/widgets/widgets/qabstractspinbox.h index 4f6aad0cde..7989000cc8 100644 --- a/src/widgets/widgets/qabstractspinbox.h +++ b/src/widgets/widgets/qabstractspinbox.h @@ -72,6 +72,7 @@ class Q_WIDGETS_EXPORT QAbstractSpinBox : public QWidget Q_PROPERTY(CorrectionMode correctionMode READ correctionMode WRITE setCorrectionMode) Q_PROPERTY(bool acceptableInput READ hasAcceptableInput) Q_PROPERTY(bool keyboardTracking READ keyboardTracking WRITE setKeyboardTracking) + Q_PROPERTY(bool showGroupSeparator READ isGroupSeparatorShown WRITE setGroupSeparatorShown) public: explicit QAbstractSpinBox(QWidget *parent = 0); ~QAbstractSpinBox(); @@ -114,6 +115,9 @@ public: void setAccelerated(bool on); bool isAccelerated() const; + void setGroupSeparatorShown(bool shown); + bool isGroupSeparatorShown() const; + QSize sizeHint() const; QSize minimumSizeHint() const; void interpretText(); diff --git a/src/widgets/widgets/qabstractspinbox_p.h b/src/widgets/widgets/qabstractspinbox_p.h index 0eeec02abc..da9f1d9757 100644 --- a/src/widgets/widgets/qabstractspinbox_p.h +++ b/src/widgets/widgets/qabstractspinbox_p.h @@ -150,6 +150,7 @@ public: QRect hoverRect; QAbstractSpinBox::ButtonSymbols buttonSymbols; QSpinBoxValidator *validator; + uint showGroupSeparator : 1; }; class QSpinBoxValidator : public QValidator diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 2c09f5a8f1..e0f5ac1050 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -2608,9 +2608,9 @@ void QComboBox::hidePopup() Q_D(QComboBox); if (d->container && d->container->isVisible()) { #if !defined(QT_NO_EFFECTS) - d->model->blockSignals(true); - d->container->itemView()->blockSignals(true); - d->container->blockSignals(true); + QSignalBlocker modelBlocker(d->model); + QSignalBlocker viewBlocker(d->container->itemView()); + QSignalBlocker containerBlocker(d->container); // Flash selected/triggered item (if any). if (style()->styleHint(QStyle::SH_Menu_FlashTriggeredItem)) { QItemSelectionModel *selectionModel = view() ? view()->selectionModel() : 0; @@ -2646,9 +2646,9 @@ void QComboBox::hidePopup() #endif // Q_OS_MAC // Other platform implementations welcome :-) } - d->model->blockSignals(false); - d->container->itemView()->blockSignals(false); - d->container->blockSignals(false); + containerBlocker.unblock(); + viewBlocker.unblock(); + modelBlocker.unblock(); if (!didFade) #endif // QT_NO_EFFECTS @@ -3057,6 +3057,8 @@ void QComboBox::keyReleaseEvent(QKeyEvent *e) Q_D(QComboBox); if (d->lineEdit) d->lineEdit->event(e); + else + QWidget::keyReleaseEvent(e); } /*! diff --git a/src/widgets/widgets/qdatetimeedit.cpp b/src/widgets/widgets/qdatetimeedit.cpp index a0bbbbf7c7..770c954c2a 100644 --- a/src/widgets/widgets/qdatetimeedit.cpp +++ b/src/widgets/widgets/qdatetimeedit.cpp @@ -993,7 +993,7 @@ QSize QDateTimeEdit::sizeHint() const QSize hint(w, h); -#ifdef Q_WS_MAC +#ifdef Q_OS_MAC if (d->calendarPopupEnabled()) { QStyleOptionComboBox opt; d->cachedSizeHint = style()->sizeFromContents(QStyle::CT_ComboBox, &opt, hint, this); @@ -1718,7 +1718,7 @@ void QDateTimeEditPrivate::updateEdit() if (newText == displayText()) return; int selsize = edit->selectedText().size(); - const bool sb = edit->blockSignals(true); + const QSignalBlocker blocker(edit); edit->setText(newText); @@ -1740,7 +1740,6 @@ void QDateTimeEditPrivate::updateEdit() } } - edit->blockSignals(sb); } @@ -1871,7 +1870,7 @@ void QDateTimeEditPrivate::clearSection(int index) { const QLatin1Char space(' '); int cursorPos = edit->cursorPosition(); - bool blocked = edit->blockSignals(true); + const QSignalBlocker blocker(edit); QString t = edit->text(); const int pos = sectionPos(index); if (pos == -1) { @@ -1883,8 +1882,6 @@ void QDateTimeEditPrivate::clearSection(int index) edit->setText(t); edit->setCursorPosition(cursorPos); QDTEDEBUG << cursorPos; - - edit->blockSignals(blocked); } @@ -2313,7 +2310,7 @@ void QDateTimeEdit::paintEvent(QPaintEvent *event) optCombo.init(this); optCombo.editable = true; - optCombo.frame = opt.frame; + optCombo.frame = opt.frame; optCombo.subControls = opt.subControls; optCombo.activeSubControls = opt.activeSubControls; optCombo.state = opt.state; @@ -2574,10 +2571,9 @@ void QDateTimeEditPrivate::syncCalendarWidget() { Q_Q(QDateTimeEdit); if (monthCalendar) { - const bool sb = monthCalendar->blockSignals(true); + const QSignalBlocker blocker(monthCalendar); monthCalendar->setDateRange(q->minimumDate(), q->maximumDate()); monthCalendar->setDate(q->date()); - monthCalendar->blockSignals(sb); } } diff --git a/src/widgets/widgets/qdialogbuttonbox.cpp b/src/widgets/widgets/qdialogbuttonbox.cpp index 6b183d3759..3acd4f0701 100644 --- a/src/widgets/widgets/qdialogbuttonbox.cpp +++ b/src/widgets/widgets/qdialogbuttonbox.cpp @@ -46,7 +46,9 @@ #include <QtWidgets/qdialog.h> #include <QtWidgets/qapplication.h> #include <private/qwidget_p.h> +#include <private/qguiapplication_p.h> #include <QtGui/qpa/qplatformdialoghelper.h> +#include <QtGui/qpa/qplatformtheme.h> #include <QtWidgets/qaction.h> #include "qdialogbuttonbox.h" @@ -148,77 +150,6 @@ QT_BEGIN_NAMESPACE \sa QMessageBox, QPushButton, QDialog */ -enum { - AcceptRole = QDialogButtonBox::AcceptRole, - RejectRole = QDialogButtonBox::RejectRole, - DestructiveRole = QDialogButtonBox::DestructiveRole, - ActionRole = QDialogButtonBox::ActionRole, - HelpRole = QDialogButtonBox::HelpRole, - YesRole = QDialogButtonBox::YesRole, - NoRole = QDialogButtonBox::NoRole, - ApplyRole = QDialogButtonBox::ApplyRole, - ResetRole = QDialogButtonBox::ResetRole, - - AlternateRole = 0x10000000, - Stretch = 0x20000000, - EOL = 0x40000000, - Reverse = 0x80000000 -}; - -static QDialogButtonBox::ButtonRole roleFor(QDialogButtonBox::StandardButton button) -{ - return static_cast<QDialogButtonBox::ButtonRole>(QMessageDialogOptions::buttonRole( - static_cast<QMessageDialogOptions::StandardButton>(button))); -} - -static const uint layouts[2][5][14] = -{ - // Qt::Horizontal - { - // WinLayout - { ResetRole, Stretch, YesRole, AcceptRole, AlternateRole, DestructiveRole, NoRole, ActionRole, RejectRole, ApplyRole, - HelpRole, EOL, EOL, EOL }, - - // MacLayout - { HelpRole, ResetRole, ApplyRole, ActionRole, Stretch, DestructiveRole | Reverse, - AlternateRole | Reverse, RejectRole | Reverse, AcceptRole | Reverse, NoRole | Reverse, YesRole | Reverse, EOL, EOL }, - - // KdeLayout - { HelpRole, ResetRole, Stretch, YesRole, NoRole, ActionRole, AcceptRole, AlternateRole, - ApplyRole, DestructiveRole, RejectRole, EOL }, - - // GnomeLayout - { HelpRole, ResetRole, Stretch, ActionRole, ApplyRole | Reverse, DestructiveRole | Reverse, - AlternateRole | Reverse, RejectRole | Reverse, AcceptRole | Reverse, NoRole | Reverse, YesRole | Reverse, EOL }, - - // Mac modeless - { ResetRole, ApplyRole, ActionRole, Stretch, HelpRole, EOL, EOL, EOL, EOL, EOL, EOL, EOL, EOL, EOL } - }, - - // Qt::Vertical - { - // WinLayout - { ActionRole, YesRole, AcceptRole, AlternateRole, DestructiveRole, NoRole, RejectRole, ApplyRole, ResetRole, - HelpRole, Stretch, EOL, EOL, EOL }, - - // MacLayout - { YesRole, NoRole, AcceptRole, RejectRole, AlternateRole, DestructiveRole, Stretch, ActionRole, ApplyRole, - ResetRole, HelpRole, EOL, EOL }, - - // KdeLayout - { AcceptRole, AlternateRole, ApplyRole, ActionRole, YesRole, NoRole, Stretch, ResetRole, - DestructiveRole, RejectRole, HelpRole, EOL }, - - // GnomeLayout - { YesRole, NoRole, AcceptRole, RejectRole, AlternateRole, DestructiveRole, ApplyRole, ActionRole, Stretch, - ResetRole, HelpRole, EOL, EOL, EOL }, - - // Mac modeless - { ActionRole, ApplyRole, ResetRole, Stretch, HelpRole, EOL, EOL, EOL, EOL, EOL, EOL, EOL, EOL, EOL } - } -}; - - class QDialogButtonBoxPrivate : public QWidgetPrivate { Q_DECLARE_PUBLIC(QDialogButtonBox) @@ -246,7 +177,6 @@ public: void _q_handleButtonClicked(); void addButtonsToLayout(const QList<QAbstractButton *> &buttonList, bool reverse); void retranslateStrings(); - const char *standardButtonText(QDialogButtonBox::StandardButton sbutton) const; }; QDialogButtonBoxPrivate::QDialogButtonBoxPrivate(Qt::Orientation orient) @@ -322,7 +252,8 @@ void QDialogButtonBoxPrivate::layoutButtons() int tmpPolicy = layoutPolicy; static const int M = 5; - static const int ModalRoles[M] = { AcceptRole, RejectRole, DestructiveRole, YesRole, NoRole }; + static const int ModalRoles[M] = { QPlatformDialogHelper::AcceptRole, QPlatformDialogHelper::RejectRole, + QPlatformDialogHelper::DestructiveRole, QPlatformDialogHelper::YesRole, QPlatformDialogHelper::NoRole }; if (tmpPolicy == QDialogButtonBox::MacLayout) { bool hasModalButton = false; for (int i = 0; i < M; ++i) { @@ -335,23 +266,24 @@ void QDialogButtonBoxPrivate::layoutButtons() tmpPolicy = 4; // Mac modeless } - const uint *currentLayout = layouts[orientation == Qt::Vertical][tmpPolicy]; + const int *currentLayout = QPlatformDialogHelper::buttonLayout( + orientation, static_cast<QPlatformDialogHelper::ButtonLayout>(tmpPolicy)); if (center) buttonLayout->addStretch(); - QList<QAbstractButton *> acceptRoleList = buttonLists[AcceptRole]; + QList<QAbstractButton *> acceptRoleList = buttonLists[QPlatformDialogHelper::AcceptRole]; - while (*currentLayout != EOL) { - int role = (*currentLayout & ~Reverse); - bool reverse = (*currentLayout & Reverse); + while (*currentLayout != QPlatformDialogHelper::EOL) { + int role = (*currentLayout & ~QPlatformDialogHelper::Reverse); + bool reverse = (*currentLayout & QPlatformDialogHelper::Reverse); switch (role) { - case Stretch: + case QPlatformDialogHelper::Stretch: if (!center) buttonLayout->addStretch(); break; - case AcceptRole: { + case QPlatformDialogHelper::AcceptRole: { if (acceptRoleList.isEmpty()) break; // Only the first one @@ -360,7 +292,7 @@ void QDialogButtonBoxPrivate::layoutButtons() button->show(); } break; - case AlternateRole: + case QPlatformDialogHelper::AlternateRole: { if (acceptRoleList.size() < 2) break; @@ -369,7 +301,7 @@ void QDialogButtonBoxPrivate::layoutButtons() addButtonsToLayout(list, reverse); } break; - case DestructiveRole: + case QPlatformDialogHelper::DestructiveRole: { const QList<QAbstractButton *> &list = buttonLists[role]; @@ -395,13 +327,13 @@ void QDialogButtonBoxPrivate::layoutButtons() buttonLayout->addSpacing(MacGap); } break; - case RejectRole: - case ActionRole: - case HelpRole: - case YesRole: - case NoRole: - case ApplyRole: - case ResetRole: + case QPlatformDialogHelper::RejectRole: + case QPlatformDialogHelper::ActionRole: + case QPlatformDialogHelper::HelpRole: + case QPlatformDialogHelper::YesRole: + case QPlatformDialogHelper::NoRole: + case QPlatformDialogHelper::ApplyRole: + case QPlatformDialogHelper::ResetRole: addButtonsToLayout(buttonLists[role], reverse); } ++currentLayout; @@ -428,7 +360,6 @@ QPushButton *QDialogButtonBoxPrivate::createButton(QDialogButtonBox::StandardBut bool doLayout) { Q_Q(QDialogButtonBox); - const char *buttonText = 0; int icon = 0; switch (sbutton) { @@ -477,17 +408,16 @@ QPushButton *QDialogButtonBoxPrivate::createButton(QDialogButtonBox::StandardBut return 0; ; } - buttonText = standardButtonText(sbutton); - - QPushButton *button = new QPushButton(QDialogButtonBox::tr(buttonText), q); + QPushButton *button = new QPushButton(QGuiApplicationPrivate::platformTheme()->standardButtonText(sbutton), q); QStyle *style = q->style(); if (style->styleHint(QStyle::SH_DialogButtonBox_ButtonsHaveIcons, 0, q) && icon != 0) button->setIcon(style->standardIcon(QStyle::StandardPixmap(icon), 0, q)); if (style != QApplication::style()) // Propagate style button->setStyle(style); standardButtonHash.insert(button, sbutton); - if (roleFor(sbutton) != QDialogButtonBox::InvalidRole) { - addButton(button, roleFor(sbutton), doLayout); + QPlatformDialogHelper::ButtonRole role = QPlatformDialogHelper::buttonRole(static_cast<QPlatformDialogHelper::StandardButton>(sbutton)); + if (role != QPlatformDialogHelper::InvalidRole) { + addButton(button, static_cast<QDialogButtonBox::ButtonRole>(role), doLayout); } else { qWarning("QDialogButtonBox::createButton: Invalid ButtonRole, button not added"); } @@ -525,87 +455,15 @@ void QDialogButtonBoxPrivate::createStandardButtons(QDialogButtonBox::StandardBu layoutButtons(); } -const char *QDialogButtonBoxPrivate::standardButtonText(QDialogButtonBox::StandardButton sbutton) const -{ - const char *buttonText = 0; - bool gnomeLayout = (layoutPolicy == QDialogButtonBox::GnomeLayout); - switch (sbutton) { - case QDialogButtonBox::Ok: - buttonText = gnomeLayout ? QT_TRANSLATE_NOOP("QDialogButtonBox", "&OK") : QT_TRANSLATE_NOOP("QDialogButtonBox", "OK"); - break; - case QDialogButtonBox::Save: - buttonText = gnomeLayout ? QT_TRANSLATE_NOOP("QDialogButtonBox", "&Save") : QT_TRANSLATE_NOOP("QDialogButtonBox", "Save"); - break; - case QDialogButtonBox::Open: - buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Open"); - break; - case QDialogButtonBox::Cancel: - buttonText = gnomeLayout ? QT_TRANSLATE_NOOP("QDialogButtonBox", "&Cancel") : QT_TRANSLATE_NOOP("QDialogButtonBox", "Cancel"); - break; - case QDialogButtonBox::Close: - buttonText = gnomeLayout ? QT_TRANSLATE_NOOP("QDialogButtonBox", "&Close") : QT_TRANSLATE_NOOP("QDialogButtonBox", "Close"); - break; - case QDialogButtonBox::Apply: - buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Apply"); - break; - case QDialogButtonBox::Reset: - buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Reset"); - break; - case QDialogButtonBox::Help: - buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Help"); - break; - case QDialogButtonBox::Discard: - if (layoutPolicy == QDialogButtonBox::MacLayout) - buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Don't Save"); - else if (layoutPolicy == QDialogButtonBox::GnomeLayout) - buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Close without Saving"); - else - buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Discard"); - break; - case QDialogButtonBox::Yes: - buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "&Yes"); - break; - case QDialogButtonBox::YesToAll: - buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Yes to &All"); - break; - case QDialogButtonBox::No: - buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "&No"); - break; - case QDialogButtonBox::NoToAll: - buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "N&o to All"); - break; - case QDialogButtonBox::SaveAll: - buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Save All"); - break; - case QDialogButtonBox::Abort: - buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Abort"); - break; - case QDialogButtonBox::Retry: - buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Retry"); - break; - case QDialogButtonBox::Ignore: - buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Ignore"); - break; - case QDialogButtonBox::RestoreDefaults: - buttonText = QT_TRANSLATE_NOOP("QDialogButtonBox", "Restore Defaults"); - break; - case QDialogButtonBox::NoButton: - ; - } // switch - return buttonText; -} - void QDialogButtonBoxPrivate::retranslateStrings() { - const char *buttonText = 0; - QHash<QPushButton *, QDialogButtonBox::StandardButton>::iterator it = standardButtonHash.begin(); - while (it != standardButtonHash.end()) { - buttonText = standardButtonText(it.value()); - if (buttonText) { - QPushButton *button = it.key(); - button->setText(QDialogButtonBox::tr(buttonText)); - } - ++it; + typedef QHash<QPushButton *, QDialogButtonBox::StandardButton>::iterator Iterator; + + const Iterator end = standardButtonHash.end(); + for (Iterator it = standardButtonHash.begin(); it != end; ++it) { + const QString text = QGuiApplicationPrivate::platformTheme()->standardButtonText(it.value()); + if (!text.isEmpty()) + it.key()->setText(text); } } @@ -1008,15 +866,15 @@ void QDialogButtonBoxPrivate::_q_handleButtonClicked() emit q->clicked(button); switch (q->buttonRole(button)) { - case AcceptRole: - case YesRole: + case QPlatformDialogHelper::AcceptRole: + case QPlatformDialogHelper::YesRole: emit q->accepted(); break; - case RejectRole: - case NoRole: + case QPlatformDialogHelper::RejectRole: + case QPlatformDialogHelper::NoRole: emit q->rejected(); break; - case HelpRole: + case QPlatformDialogHelper::HelpRole: emit q->helpRequested(); break; default: diff --git a/src/widgets/widgets/qdialogbuttonbox.h b/src/widgets/widgets/qdialogbuttonbox.h index d8e1a997d4..5cd94f88b0 100644 --- a/src/widgets/widgets/qdialogbuttonbox.h +++ b/src/widgets/widgets/qdialogbuttonbox.h @@ -61,7 +61,7 @@ class Q_WIDGETS_EXPORT QDialogButtonBox : public QWidget public: enum ButtonRole { - // keep this in sync with QMessageBox::ButtonRole + // keep this in sync with QMessageBox::ButtonRole and QPlatformDialogHelper::ButtonRole InvalidRole = -1, AcceptRole, RejectRole, @@ -77,7 +77,7 @@ public: }; enum StandardButton { - // keep this in sync with QMessageBox::StandardButton + // keep this in sync with QMessageBox::StandardButton and QPlatformDialogHelper::StandardButton NoButton = 0x00000000, Ok = 0x00000400, Save = 0x00000800, @@ -107,6 +107,7 @@ public: Q_DECLARE_FLAGS(StandardButtons, StandardButton) enum ButtonLayout { + // keep this in sync with QMessageBox::ButtonLayout and QPlatformDialogHelper::ButtonLayout WinLayout, MacLayout, KdeLayout, diff --git a/src/widgets/widgets/qdockarealayout.cpp b/src/widgets/widgets/qdockarealayout.cpp index 72a463b30b..066b3c7a86 100644 --- a/src/widgets/widgets/qdockarealayout.cpp +++ b/src/widgets/widgets/qdockarealayout.cpp @@ -1940,9 +1940,9 @@ bool QDockAreaLayoutInfo::restoreState(QDataStream &stream, QList<QDockWidget*> } else { QDockAreaLayoutItem item(new QDockWidgetItem(widget)); if (flags & StateFlagFloating) { - bool drawer = false; + bool drawer = false; #ifdef Q_WS_MAC // drawer support - extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp + extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp extern bool qt_mac_set_drawer_preferred_edge(QWidget *, Qt::DockWidgetArea); //qwidget_mac.cpp drawer = qt_mac_is_macdrawer(widget); #endif @@ -1988,10 +1988,10 @@ bool QDockAreaLayoutInfo::restoreState(QDataStream &stream, QList<QDockWidget*> emit widget->dockLocationChanged(toDockWidgetArea(dockPos)); } } - if (testing) { - //was it is not really added to the layout, we need to delete the object here - delete item.widgetItem; - } + if (testing) { + //was it is not really added to the layout, we need to delete the object here + delete item.widgetItem; + } } } else if (nextMarker == SequenceMarker) { int dummy; @@ -2096,7 +2096,7 @@ bool QDockAreaLayoutInfo::updateTabBar() const that->tabBar->setDrawBase(true); } - bool blocked = tabBar->blockSignals(true); + const QSignalBlocker blocker(tabBar); bool gap = false; int tab_idx = 0; @@ -2147,8 +2147,6 @@ bool QDockAreaLayoutInfo::updateTabBar() const tabBar->removeTab(tab_idx); } - tabBar->blockSignals(blocked); - //returns if the tabbar is visible or not return ( (gap ? 1 : 0) + tabBar->count()) > 1; } diff --git a/src/widgets/widgets/qdockwidget.cpp b/src/widgets/widgets/qdockwidget.cpp index 46929397a0..ad9481a928 100644 --- a/src/widgets/widgets/qdockwidget.cpp +++ b/src/widgets/widgets/qdockwidget.cpp @@ -667,6 +667,7 @@ void QDockWidgetPrivate::updateButtons() button->setIcon(q->style()->standardIcon(QStyle::SP_TitleBarNormalButton, &opt, q)); button->setVisible(canFloat && !hideButtons); #ifndef QT_NO_ACCESSIBILITY + //: Accessible name for button undocking a dock widget (floating state) button->setAccessibleName(QDockWidget::tr("Float")); button->setAccessibleDescription(QDockWidget::tr("Undocks and re-attaches the dock widget")); #endif @@ -675,6 +676,7 @@ void QDockWidgetPrivate::updateButtons() button->setIcon(q->style()->standardIcon(QStyle::SP_TitleBarCloseButton, &opt, q)); button->setVisible(canClose && !hideButtons); #ifndef QT_NO_ACCESSIBILITY + //: Accessible name for button closing a dock widget button->setAccessibleName(QDockWidget::tr("Close")); button->setAccessibleDescription(QDockWidget::tr("Closes the dock widget")); #endif @@ -1104,8 +1106,8 @@ void QDockWidgetPrivate::setWindowState(bool floating, bool unplug, const QRect \enum QDockWidget::DockWidgetFeature \value DockWidgetClosable The dock widget can be closed. On some systems the dock - widget always has a close button when it's floating - (for example on MacOS 10.5). + widget always has a close button when it's floating + (for example on MacOS 10.5). \value DockWidgetMovable The dock widget can be moved between docks by the user. \value DockWidgetFloatable The dock widget can be detached from the diff --git a/src/widgets/widgets/qdockwidget_p.h b/src/widgets/widgets/qdockwidget_p.h index 800f523825..f7cd8c0039 100644 --- a/src/widgets/widgets/qdockwidget_p.h +++ b/src/widgets/widgets/qdockwidget_p.h @@ -84,7 +84,7 @@ class QDockWidgetPrivate : public QWidgetPrivate public: inline QDockWidgetPrivate() - : QWidgetPrivate(), state(0), + : QWidgetPrivate(), state(0), features(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable), diff --git a/src/widgets/widgets/qeffects.cpp b/src/widgets/widgets/qeffects.cpp index 83060bb571..cd8ae81ace 100644 --- a/src/widgets/widgets/qeffects.cpp +++ b/src/widgets/widgets/qeffects.cpp @@ -189,32 +189,32 @@ bool QAlphaWidget::eventFilter(QObject *o, QEvent *e) { switch (e->type()) { case QEvent::Move: - if (o != widget) - break; - move(widget->geometry().x(),widget->geometry().y()); - update(); - break; + if (o != widget) + break; + move(widget->geometry().x(),widget->geometry().y()); + update(); + break; case QEvent::Hide: case QEvent::Close: - if (o != widget) - break; + if (o != widget) + break; case QEvent::MouseButtonPress: - case QEvent::MouseButtonDblClick: - showWidget = false; - render(); - break; + case QEvent::MouseButtonDblClick: + showWidget = false; + render(); + break; case QEvent::KeyPress: { - QKeyEvent *ke = (QKeyEvent*)e; - if (ke->key() == Qt::Key_Escape) { - showWidget = false; - } else { - duration = 0; - } - render(); - break; - } + QKeyEvent *ke = (QKeyEvent*)e; + if (ke->key() == Qt::Key_Escape) { + showWidget = false; + } else { + duration = 0; + } + render(); + break; + } default: - break; + break; } return QWidget::eventFilter(o, e); } diff --git a/src/widgets/widgets/qfontcombobox.cpp b/src/widgets/widgets/qfontcombobox.cpp index 0b0efa2bdf..2bbf3730db 100644 --- a/src/widgets/widgets/qfontcombobox.cpp +++ b/src/widgets/widgets/qfontcombobox.cpp @@ -346,9 +346,10 @@ void QFontComboBoxPrivate::_q_updateModel() //this prevents the current index from changing //it will be updated just after this ///TODO: we should finda way to avoid blocking signals and have a real update of the model - const bool old = m->blockSignals(true); - m->setStringList(list); - m->blockSignals(old); + { + const QSignalBlocker blocker(m); + m->setStringList(list); + } if (list.isEmpty()) { if (currentFont != QFont()) { diff --git a/src/widgets/widgets/qlcdnumber.h b/src/widgets/widgets/qlcdnumber.h index 3dde1527f2..ba7b2d8494 100644 --- a/src/widgets/widgets/qlcdnumber.h +++ b/src/widgets/widgets/qlcdnumber.h @@ -43,7 +43,6 @@ #define QLCDNUMBER_H #include <QtWidgets/qframe.h> -#include <QtCore/qbitarray.h> QT_BEGIN_NAMESPACE diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp index df5ae0171c..ba4dbcc878 100644 --- a/src/widgets/widgets/qlineedit.cpp +++ b/src/widgets/widgets/qlineedit.cpp @@ -333,7 +333,12 @@ void QLineEdit::setText(const QString& text) \brief the line edit's placeholder text Setting this property makes the line edit display a grayed-out - placeholder text as long as the text() is empty. + placeholder text as long as the line edit is empty. + + Normally, an empty line edit shows the placeholder text even + when it has focus. However, if the content is horizontally + centered, the placeholder text is not displayed under + the cursor when the line edit has focus. By default, this property contains an empty string. @@ -350,7 +355,7 @@ void QLineEdit::setPlaceholderText(const QString& placeholderText) Q_D(QLineEdit); if (d->placeholderText != placeholderText) { d->placeholderText = placeholderText; - if (d->control->text().isEmpty()) + if (d->shouldShowPlaceholderText()) update(); } } @@ -1488,6 +1493,9 @@ void QLineEdit::mousePressEvent(QMouseEvent* e) return; } bool mark = e->modifiers() & Qt::ShiftModifier; +#ifdef Q_OS_ANDROID + mark = mark && (d->imHints & Qt::ImhNoPredictiveText); +#endif // Q_OS_ANDROID int cursor = d->xToPos(e->pos().x()); #ifndef QT_NO_DRAGANDDROP if (!mark && d->dragEnabled && d->control->echoMode() == Normal && @@ -1515,14 +1523,19 @@ void QLineEdit::mouseMoveEvent(QMouseEvent * e) } else #endif { - if (d->control->composeMode()) { +#ifndef Q_OS_ANDROID + const bool select = true; +#else + const bool select = (d->imHints & Qt::ImhNoPredictiveText); +#endif + if (d->control->composeMode() && select) { int startPos = d->xToPos(d->mousePressPos.x()); int currentPos = d->xToPos(e->pos().x()); if (startPos != currentPos) d->control->setSelection(startPos, currentPos - startPos); } else { - d->control->moveCursor(d->xToPos(e->pos().x()), true); + d->control->moveCursor(d->xToPos(e->pos().x()), select); } } } @@ -1895,7 +1908,7 @@ void QLineEdit::paintEvent(QPaintEvent *) int minLB = qMax(0, -fm.minLeftBearing()); int minRB = qMax(0, -fm.minRightBearing()); - if (d->control->text().isEmpty() && d->control->preeditAreaText().isEmpty()) { + if (d->shouldShowPlaceholderText()) { if (!d->placeholderText.isEmpty()) { QColor col = pal.text().color(); col.setAlpha(128); diff --git a/src/widgets/widgets/qlineedit_p.cpp b/src/widgets/widgets/qlineedit_p.cpp index 891839ed56..9ff77c87de 100644 --- a/src/widgets/widgets/qlineedit_p.cpp +++ b/src/widgets/widgets/qlineedit_p.cpp @@ -95,7 +95,12 @@ void QLineEditPrivate::_q_completionHighlighted(QString newText) QString text = control->text(); q->setText(text.left(c) + newText.mid(c)); control->moveCursor(control->end(), false); - control->moveCursor(c, true); +#ifndef Q_OS_ANDROID + const bool mark = true; +#else + const bool mark = (imHints & Qt::ImhNoPredictiveText); +#endif + control->moveCursor(c, mark); } } diff --git a/src/widgets/widgets/qlineedit_p.h b/src/widgets/widgets/qlineedit_p.h index 181a23449b..aa5b57a920 100644 --- a/src/widgets/widgets/qlineedit_p.h +++ b/src/widgets/widgets/qlineedit_p.h @@ -148,6 +148,11 @@ public: { return !control->isReadOnly(); } + inline bool shouldShowPlaceholderText() const + { + return control->text().isEmpty() && control->preeditAreaText().isEmpty() + && !((alignment & Qt::AlignHCenter) && q_func()->hasFocus()); + } static inline QLineEditPrivate *get(QLineEdit *lineEdit) { return lineEdit->d_func(); diff --git a/src/widgets/widgets/qmaccocoaviewcontainer_mac.mm b/src/widgets/widgets/qmaccocoaviewcontainer_mac.mm index a94273c574..965e9301e9 100644 --- a/src/widgets/widgets/qmaccocoaviewcontainer_mac.mm +++ b/src/widgets/widgets/qmaccocoaviewcontainer_mac.mm @@ -164,7 +164,7 @@ NSView *QMacCocoaViewContainer::cocoaView() const } /*! - Sets the NSView to contain to be \a cocoaViewToWrap and retains it. If this + Sets \a view as the NSView to contain and retains it. If this container already had a view set, it will release the previously set view. */ void QMacCocoaViewContainer::setCocoaView(NSView *view) diff --git a/src/widgets/widgets/qmdiarea.cpp b/src/widgets/widgets/qmdiarea.cpp index 349d8c3423..600d9b536f 100644 --- a/src/widgets/widgets/qmdiarea.cpp +++ b/src/widgets/widgets/qmdiarea.cpp @@ -1115,10 +1115,9 @@ void QMdiAreaPrivate::updateActiveWindow(int removedIndex, bool activeRemoved) #ifndef QT_NO_TABBAR if (tabBar && removedIndex >= 0) { - tabBar->blockSignals(true); + const QSignalBlocker blocker(tabBar); tabBar->removeTab(removedIndex); updateTabBarGeometry(); - tabBar->blockSignals(false); } #endif diff --git a/src/widgets/widgets/qmdisubwindow.cpp b/src/widgets/widgets/qmdisubwindow.cpp index 8e1dcbee18..94674319bc 100644 --- a/src/widgets/widgets/qmdisubwindow.cpp +++ b/src/widgets/widgets/qmdisubwindow.cpp @@ -2057,13 +2057,13 @@ void QMdiSubWindowPrivate::restoreFocus() /*! \internal - ### Please add QEvent::WindowFlagsChange event */ void QMdiSubWindowPrivate::setWindowFlags(Qt::WindowFlags windowFlags) { Q_Q(QMdiSubWindow); + if (!parent) { - q->setWindowFlags(windowFlags); + QWidgetPrivate::setWindowFlags(windowFlags); return; } @@ -2097,7 +2097,7 @@ void QMdiSubWindowPrivate::setWindowFlags(Qt::WindowFlags windowFlags) delete sizeGrip; #endif - q->setWindowFlags(windowFlags); + QWidgetPrivate::setWindowFlags(windowFlags); updateGeometryConstraints(); updateActions(); QSize currentSize = q->size(); diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 3a4fd449c8..2820608621 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -153,13 +153,48 @@ void QMenuPrivate::init() scroll->scrollFlags = QMenuPrivate::QMenuScroller::ScrollNone; } - platformMenu = QGuiApplicationPrivate::platformTheme()->createPlatformMenu(); + setPlatformMenu(QGuiApplicationPrivate::platformTheme()->createPlatformMenu()); +} + +void QMenuPrivate::setPlatformMenu(QPlatformMenu *menu) +{ + Q_Q(QMenu); + if (!platformMenu.isNull() && !platformMenu->parent()) + delete platformMenu.data(); + + platformMenu = menu; if (!platformMenu.isNull()) { QObject::connect(platformMenu, SIGNAL(aboutToShow()), q, SIGNAL(aboutToShow())); QObject::connect(platformMenu, SIGNAL(aboutToHide()), q, SIGNAL(aboutToHide())); } } +// forward declare function +static void copyActionToPlatformItem(const QAction *action, QPlatformMenuItem* item); + +void QMenuPrivate::syncPlatformMenu() +{ + Q_Q(QMenu); + if (platformMenu.isNull()) + return; + + QPlatformMenuItem *beforeItem = Q_NULLPTR; + QListIterator<QAction*> it(q->actions()); + it.toBack(); + while (it.hasPrevious()) { + QPlatformMenuItem *menuItem = platformMenu->createMenuItem(); + QAction *action = it.previous(); + menuItem->setTag(reinterpret_cast<quintptr>(action)); + QObject::connect(menuItem, SIGNAL(activated()), action, SLOT(trigger())); + QObject::connect(menuItem, SIGNAL(hovered()), action, SIGNAL(hovered())); + copyActionToPlatformItem(action, menuItem); + platformMenu->insertMenuItem(menuItem, beforeItem); + beforeItem = menuItem; + } + platformMenu->syncSeparatorsCollapsible(collapsibleSeparators); + platformMenu->setEnabled(q->isEnabled()); +} + int QMenuPrivate::scrollerHeight() const { Q_Q(const QMenu); @@ -435,7 +470,7 @@ void QMenuPrivate::hideMenu(QMenu *menu) if (!menu) return; #if !defined(QT_NO_EFFECTS) - menu->blockSignals(true); + QSignalBlocker blocker(menu); aboutToHide = true; // Flash item which is about to trigger (if any). if (menu->style()->styleHint(QStyle::SH_Menu_FlashTriggeredItem) @@ -455,7 +490,7 @@ void QMenuPrivate::hideMenu(QMenu *menu) } aboutToHide = false; - menu->blockSignals(false); + blocker.unblock(); #endif // QT_NO_EFFECTS menu->close(); } @@ -2976,8 +3011,7 @@ void QMenu::actionEvent(QActionEvent *e) if (!d->platformMenu.isNull()) { if (e->type() == QEvent::ActionAdded) { - QPlatformMenuItem *menuItem = - QGuiApplicationPrivate::platformTheme()->createPlatformMenuItem(); + 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())); @@ -3139,11 +3173,7 @@ void QMenu::internalDelayedPopup() */ void QMenu::setNoReplayFor(QWidget *noReplayFor) { -#ifdef Q_OS_WIN d_func()->noReplayFor = noReplayFor; -#else - Q_UNUSED(noReplayFor); -#endif } /*!\internal @@ -3154,6 +3184,14 @@ QPlatformMenu *QMenu::platformMenu() return d_func()->platformMenu; } +/*!\internal +*/ +void QMenu::setPlatformMenu(QPlatformMenu *platformMenu) +{ + d_func()->setPlatformMenu(platformMenu); + d_func()->syncPlatformMenu(); +} + /*! \property QMenu::separatorsCollapsible \since 4.2 diff --git a/src/widgets/widgets/qmenu.h b/src/widgets/widgets/qmenu.h index 7a128e871c..8a8eaf3bae 100644 --- a/src/widgets/widgets/qmenu.h +++ b/src/widgets/widgets/qmenu.h @@ -140,6 +140,7 @@ public: void setNoReplayFor(QWidget *widget); QPlatformMenu *platformMenu(); + void setPlatformMenu(QPlatformMenu *platformMenu); #ifdef Q_OS_WINCE HMENU wceMenu(); diff --git a/src/widgets/widgets/qmenu_p.h b/src/widgets/widgets/qmenu_p.h index 71a3fca237..afd34a5c47 100644 --- a/src/widgets/widgets/qmenu_p.h +++ b/src/widgets/widgets/qmenu_p.h @@ -108,6 +108,8 @@ public: #endif } void init(); + void setPlatformMenu(QPlatformMenu *menu); + void syncPlatformMenu(); static QMenuPrivate *get(QMenu *m) { return m->d_func(); } int scrollerHeight() const; diff --git a/src/widgets/widgets/qmenubar.cpp b/src/widgets/widgets/qmenubar.cpp index 01db2bda7a..03ab490823 100644 --- a/src/widgets/widgets/qmenubar.cpp +++ b/src/widgets/widgets/qmenubar.cpp @@ -1833,9 +1833,9 @@ void QMenuBar::setNativeMenuBar(bool nativeMenuBar) d->platformMenuBar = QGuiApplicationPrivate::platformTheme()->createPlatformMenuBar(); } - updateGeometry(); - if (!d->nativeMenuBar && parentWidget()) - setVisible(true); + updateGeometry(); + if (!d->nativeMenuBar && parentWidget()) + setVisible(true); } } diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp index 5f055d436a..d51dce4765 100644 --- a/src/widgets/widgets/qplaintextedit.cpp +++ b/src/widgets/widgets/qplaintextedit.cpp @@ -347,7 +347,7 @@ void QPlainTextDocumentLayout::documentChanged(int from, int /*charsRemoved*/, i } if (!d->blockUpdate) - emit update(QRectF(0., -doc->documentMargin(), 1000000000., 1000000000.)); // optimization potential + emit update(QRectF(0., -doc->documentMargin(), 1000000000., 1000000000.)); // optimization potential } @@ -639,9 +639,10 @@ void QPlainTextEditPrivate::setTopBlock(int blockNumber, int lineNumber, int dx) lineNumber = maxTopLine - block.firstLineNumber(); } - bool vbarSignalsBlocked = vbar->blockSignals(true); - vbar->setValue(newTopLine); - vbar->blockSignals(vbarSignalsBlocked); + { + const QSignalBlocker blocker(vbar); + vbar->setValue(newTopLine); + } if (!dx && blockNumber == control->topBlock && lineNumber == topLine) return; @@ -657,9 +658,10 @@ void QPlainTextEditPrivate::setTopBlock(int blockNumber, int lineNumber, int dx) control->topBlock = blockNumber; topLine = lineNumber; - bool vbarSignalsBlocked = vbar->blockSignals(true); - vbar->setValue(block.firstLineNumber() + lineNumber); - vbar->blockSignals(vbarSignalsBlocked); + { + const QSignalBlocker blocker(vbar); + vbar->setValue(block.firstLineNumber() + lineNumber); + } if (dx || dy) { viewport->scroll(q->isRightToLeft() ? -dx : dx, dy); @@ -1007,9 +1009,11 @@ void QPlainTextEditPrivate::_q_adjustScrollbars() QTextBlock firstVisibleBlock = q->firstVisibleBlock(); if (firstVisibleBlock.isValid()) visualTopLine = firstVisibleBlock.firstLineNumber() + topLine; - bool vbarSignalsBlocked = vbar->blockSignals(true); - vbar->setValue(visualTopLine); - vbar->blockSignals(vbarSignalsBlocked); + + { + const QSignalBlocker blocker(vbar); + vbar->setValue(visualTopLine); + } hbar->setRange(0, (int)documentSize.width() - viewport->width()); hbar->setPageStep(viewport->width()); @@ -1317,6 +1321,35 @@ QTextDocument *QPlainTextEdit::document() const } /*! + \since 5.3 + + \property QPlainTextEdit::placeholderText + \brief the editor placeholder text + + Setting this property makes the editor display a grayed-out + placeholder text as long as the document() is empty. + + By default, this property contains an empty string. + + \sa document() +*/ +void QPlainTextEdit::setPlaceholderText(const QString &placeholderText) +{ + Q_D(QPlainTextEdit); + if (d->placeholderText != placeholderText) { + d->placeholderText = placeholderText; + if (d->control->document()->isEmpty()) + d->viewport->update(); + } +} + +QString QPlainTextEdit::placeholderText() const +{ + Q_D(const QPlainTextEdit); + return d->placeholderText; +} + +/*! Sets the visible \a cursor. */ void QPlainTextEdit::setTextCursor(const QTextCursor &cursor) @@ -1942,7 +1975,16 @@ void QPlainTextEdit::paintEvent(QPaintEvent *e) } - layout->draw(&painter, offset, selections, er); + if (!placeholderText().isEmpty() && document()->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())) { @@ -2150,7 +2192,7 @@ QVariant QPlainTextEdit::inputMethodQuery(Qt::InputMethodQuery property) const v = QWidget::inputMethodQuery(property); break; default: - v = d->control->inputMethodQuery(property); + v = d->control->inputMethodQuery(property, QVariant()); const QPoint offset(-d->horizontalOffset(), -0); if (v.type() == QVariant::RectF) v = v.toRectF().toRect().translated(offset); @@ -2758,6 +2800,27 @@ bool QPlainTextEdit::find(const QString &exp, QTextDocument::FindFlags options) } /*! + \fn bool QPlainTextEdit::find(const QRegExp &exp, QTextDocument::FindFlags options) + + \since 5.3 + \overload + + Finds the next occurrence, matching the regular expression, \a exp, using the given + \a options. The QTextDocument::FindCaseSensitively option is ignored for this overload, + use QRegExp::caseSensitivity instead. + + Returns \c true if a match was found and changes the cursor to select the match; + otherwise returns \c false. +*/ +#ifndef QT_NO_REGEXP +bool QPlainTextEdit::find(const QRegExp &exp, QTextDocument::FindFlags options) +{ + Q_D(QPlainTextEdit); + return d->control->find(exp, options); +} +#endif + +/*! \fn void QPlainTextEdit::copyAvailable(bool yes) This signal is emitted when text is selected or de-selected in the diff --git a/src/widgets/widgets/qplaintextedit.h b/src/widgets/widgets/qplaintextedit.h index 81548818ef..1fb4625fb1 100644 --- a/src/widgets/widgets/qplaintextedit.h +++ b/src/widgets/widgets/qplaintextedit.h @@ -83,6 +83,7 @@ class Q_WIDGETS_EXPORT QPlainTextEdit : public QAbstractScrollArea Q_PROPERTY(int maximumBlockCount READ maximumBlockCount WRITE setMaximumBlockCount) Q_PROPERTY(bool backgroundVisible READ backgroundVisible WRITE setBackgroundVisible) Q_PROPERTY(bool centerOnScroll READ centerOnScroll WRITE setCenterOnScroll) + Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText) public: enum LineWrapMode { NoWrap, @@ -96,6 +97,9 @@ public: void setDocument(QTextDocument *document); QTextDocument *document() const; + void setPlaceholderText(const QString &placeholderText); + QString placeholderText() const; + void setTextCursor(const QTextCursor &cursor); QTextCursor textCursor() const; @@ -141,6 +145,9 @@ public: bool centerOnScroll() const; bool find(const QString &exp, QTextDocument::FindFlags options = 0); +#ifndef QT_NO_REGEXP + bool find(const QRegExp &exp, QTextDocument::FindFlags options = 0); +#endif inline QString toPlainText() const { return document()->toPlainText(); } diff --git a/src/widgets/widgets/qplaintextedit_p.h b/src/widgets/widgets/qplaintextedit_p.h index ab464676e5..3585b8307f 100644 --- a/src/widgets/widgets/qplaintextedit_p.h +++ b/src/widgets/widgets/qplaintextedit_p.h @@ -179,6 +179,7 @@ public: void _q_modificationChanged(bool); int originalOffsetY; + QString placeholderText; }; QT_END_NAMESPACE diff --git a/src/widgets/widgets/qpushbutton.cpp b/src/widgets/widgets/qpushbutton.cpp index a10d726e36..264123abf0 100644 --- a/src/widgets/widgets/qpushbutton.cpp +++ b/src/widgets/widgets/qpushbutton.cpp @@ -647,7 +647,7 @@ void QPushButton::setFlat(bool flat) if (d->flat == flat) return; d->flat = flat; - d->resetLayoutItemMargins(); + d->resetLayoutItemMargins(); d->sizeHint = QSize(); update(); updateGeometry(); @@ -673,8 +673,8 @@ bool QPushButton::event(QEvent *e) || e->type() == QEvent::MacSizeChange #endif ) { - d->resetLayoutItemMargins(); - updateGeometry(); + d->resetLayoutItemMargins(); + updateGeometry(); } else if (e->type() == QEvent::PolishRequest) { updateGeometry(); } diff --git a/src/widgets/widgets/qsizegrip.cpp b/src/widgets/widgets/qsizegrip.cpp index 106a8d770a..e46de3958f 100644 --- a/src/widgets/widgets/qsizegrip.cpp +++ b/src/widgets/widgets/qsizegrip.cpp @@ -482,7 +482,7 @@ bool QSizeGrip::eventFilter(QObject *o, QEvent *e) Q_D(QSizeGrip); if ((isHidden() && testAttribute(Qt::WA_WState_ExplicitShowHide)) || e->type() != QEvent::WindowStateChange - || o != d->tlw) { + || o != d->tlw) { return QWidget::eventFilter(o, e); } Qt::WindowStates sizeGripNotVisibleState = Qt::WindowFullScreen; diff --git a/src/widgets/widgets/qslider.cpp b/src/widgets/widgets/qslider.cpp index 2d91cd07e6..0ff31af630 100644 --- a/src/widgets/widgets/qslider.cpp +++ b/src/widgets/widgets/qslider.cpp @@ -63,7 +63,7 @@ public: QSlider::TickPosition tickPosition; int clickOffset; void init(); - void resetLayoutItemMargins(); + void resetLayoutItemMargins(); int pixelPosToRangeValue(int pos) const; inline int pick(const QPoint &pt) const; @@ -86,7 +86,7 @@ void QSliderPrivate::init() sp.transpose(); q->setSizePolicy(sp); q->setAttribute(Qt::WA_WState_OwnSizePolicy, false); - resetLayoutItemMargins(); + resetLayoutItemMargins(); } void QSliderPrivate::resetLayoutItemMargins() diff --git a/src/widgets/widgets/qspinbox.cpp b/src/widgets/widgets/qspinbox.cpp index 2a34451408..e198dae168 100644 --- a/src/widgets/widgets/qspinbox.cpp +++ b/src/widgets/widgets/qspinbox.cpp @@ -463,8 +463,8 @@ void QSpinBox::setDisplayIntegerBase(int base) display the given \a value. The default implementation returns a string containing \a value printed in the standard way using QWidget::locale().toString(), but with the thousand separator - removed. Reimplementations may return anything. (See the example - in the detailed description.) + removed unless setGroupSeparatorShown() is set. Reimplementations may + return anything. (See the example in the detailed description.) Note: QSpinBox does not call this function for specialValueText() and that neither prefix() nor suffix() should be included in the @@ -487,7 +487,7 @@ QString QSpinBox::textFromValue(int value) const str.prepend('-'); } else { str = locale().toString(value); - if (qAbs(value) >= 1000 || value == INT_MIN) { + if (!d->showGroupSeparator && (qAbs(value) >= 1000 || value == INT_MIN)) { str.remove(locale().groupSeparator()); } } @@ -538,7 +538,8 @@ QValidator::State QSpinBox::validate(QString &text, int &pos) const */ void QSpinBox::fixup(QString &input) const { - input.remove(locale().groupSeparator()); + if (!isGroupSeparatorShown()) + input.remove(locale().groupSeparator()); } @@ -891,7 +892,8 @@ void QDoubleSpinBox::setDecimals(int decimals) display the given \a value. The default implementation returns a string containing \a value printed using QWidget::locale().toString(\a value, QLatin1Char('f'), decimals()) and will remove the thousand - separator. Reimplementations may return anything. + separator unless setGroupSeparatorShown() is set. Reimplementations may + return anything. Note: QDoubleSpinBox does not call this function for specialValueText() and that neither prefix() nor suffix() should @@ -908,9 +910,9 @@ QString QDoubleSpinBox::textFromValue(double value) const { Q_D(const QDoubleSpinBox); QString str = locale().toString(value, 'f', d->decimals); - if (qAbs(value) >= 1000.0) { + if (!d->showGroupSeparator && qAbs(value) >= 1000.0) str.remove(locale().groupSeparator()); - } + return str; } diff --git a/src/widgets/widgets/qsplashscreen.cpp b/src/widgets/widgets/qsplashscreen.cpp index b2a0d3f8b8..db9db68039 100644 --- a/src/widgets/widgets/qsplashscreen.cpp +++ b/src/widgets/widgets/qsplashscreen.cpp @@ -251,7 +251,9 @@ inline static bool waitForWindowExposed(QWindow *window, int timeout = 1000) break; QCoreApplication::processEvents(QEventLoop::AllEvents, remaining); QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); -#ifdef Q_OS_WIN +#if defined(Q_OS_WINRT) + WaitForSingleObjectEx(GetCurrentThread(), TimeOutMs, false); +#elif defined(Q_OS_WIN) Sleep(uint(TimeOutMs)); #else struct timespec ts = { TimeOutMs / 1000, (TimeOutMs % 1000) * 1000 * 1000 }; diff --git a/src/widgets/widgets/qtabwidget.cpp b/src/widgets/widgets/qtabwidget.cpp index 8c15b3e58e..fced1c01ec 100644 --- a/src/widgets/widgets/qtabwidget.cpp +++ b/src/widgets/widgets/qtabwidget.cpp @@ -759,11 +759,10 @@ void QTabWidgetPrivate::_q_removeTab(int index) void QTabWidgetPrivate::_q_tabMoved(int from, int to) { - stack->blockSignals(true); + const QSignalBlocker blocker(stack); QWidget *w = stack->widget(from); stack->removeWidget(w); stack->insertWidget(to, w); - stack->blockSignals(false); } /* diff --git a/src/widgets/widgets/qtextbrowser.cpp b/src/widgets/widgets/qtextbrowser.cpp index 273a5dabeb..9ecc87aac4 100644 --- a/src/widgets/widgets/qtextbrowser.cpp +++ b/src/widgets/widgets/qtextbrowser.cpp @@ -296,7 +296,7 @@ void QTextBrowserPrivate::setSource(const QUrl &url) QTextCodec *codec = Qt::codecForHtml(ba); txt = codec->toUnicode(ba); #else - txt = data.toString(); + txt = data.toString(); #endif } if (txt.isEmpty()) diff --git a/src/widgets/widgets/qtextedit.cpp b/src/widgets/widgets/qtextedit.cpp index 29538e1b70..a33ac0817f 100644 --- a/src/widgets/widgets/qtextedit.cpp +++ b/src/widgets/widgets/qtextedit.cpp @@ -1717,14 +1717,21 @@ void QTextEdit::scrollContentsBy(int dx, int dy) */ QVariant QTextEdit::inputMethodQuery(Qt::InputMethodQuery property) const { + return inputMethodQuery(property, QVariant()); +} + +/*!\internal + */ +QVariant QTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant argument) const +{ Q_D(const QTextEdit); QVariant v; - switch (property) { + switch (query) { case Qt::ImHints: - v = QWidget::inputMethodQuery(property); + v = QWidget::inputMethodQuery(query); break; default: - v = d->control->inputMethodQuery(property); + v = d->control->inputMethodQuery(query, argument); const QPoint offset(-d->horizontalOffset(), -d->verticalOffset()); if (v.type() == QVariant::RectF) v = v.toRectF().toRect().translated(offset); @@ -2456,6 +2463,27 @@ bool QTextEdit::find(const QString &exp, QTextDocument::FindFlags options) } /*! + \fn bool QTextEdit::find(const QRegExp &exp, QTextDocument::FindFlags options) + + \since 5.3 + \overload + + Finds the next occurrence, matching the regular expression, \a exp, using the given + \a options. The QTextDocument::FindCaseSensitively option is ignored for this overload, + use QRegExp::caseSensitivity instead. + + Returns \c true if a match was found and changes the cursor to select the match; + otherwise returns \c false. +*/ +#ifndef QT_NO_REGEXP +bool QTextEdit::find(const QRegExp &exp, QTextDocument::FindFlags options) +{ + Q_D(QTextEdit); + return d->control->find(exp, options); +} +#endif + +/*! \fn void QTextEdit::copyAvailable(bool yes) This signal is emitted when text is selected or de-selected in the diff --git a/src/widgets/widgets/qtextedit.h b/src/widgets/widgets/qtextedit.h index 06ec5fb889..a283a51b90 100644 --- a/src/widgets/widgets/qtextedit.h +++ b/src/widgets/widgets/qtextedit.h @@ -162,6 +162,9 @@ public: void setWordWrapMode(QTextOption::WrapMode policy); bool find(const QString &exp, QTextDocument::FindFlags options = 0); +#ifndef QT_NO_REGEXP + bool find(const QRegExp &exp, QTextDocument::FindFlags options = 0); +#endif QString toPlainText() const; #ifndef QT_NO_TEXTHTMLPARSER @@ -209,6 +212,7 @@ public: void print(QPagedPaintDevice *printer) const; QVariant inputMethodQuery(Qt::InputMethodQuery property) const; + Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery query, QVariant argument) const; public Q_SLOTS: void setFontPointSize(qreal s); diff --git a/src/widgets/widgets/qtoolbar.cpp b/src/widgets/widgets/qtoolbar.cpp index 5e7eb943ab..d20b7a380d 100644 --- a/src/widgets/widgets/qtoolbar.cpp +++ b/src/widgets/widgets/qtoolbar.cpp @@ -650,9 +650,9 @@ void QToolBar::setOrientation(Qt::Orientation orientation) d->orientation = orientation; if (orientation == Qt::Vertical) - setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred)); + setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred)); else - setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed)); + setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed)); d->layout->invalidate(); d->layout->activate(); diff --git a/src/widgets/widgets/qtoolbar.h b/src/widgets/widgets/qtoolbar.h index 663497493f..fbe509f522 100644 --- a/src/widgets/widgets/qtoolbar.h +++ b/src/widgets/widgets/qtoolbar.h @@ -105,7 +105,7 @@ public: QAction *addAction(const QIcon &icon, const QString &text); QAction *addAction(const QString &text, const QObject *receiver, const char* member); QAction *addAction(const QIcon &icon, const QString &text, - const QObject *receiver, const char* member); + const QObject *receiver, const char* member); QAction *addSeparator(); QAction *insertSeparator(QAction *before); diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index b8f8762240..03a65aa8e5 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -115,7 +115,11 @@ static QTextLine currentTextLine(const QTextCursor &cursor) QWidgetTextControlPrivate::QWidgetTextControlPrivate() : doc(0), cursorOn(false), cursorIsFocusIndicator(false), +#ifndef Q_OS_ANDROID interactionFlags(Qt::TextEditorInteraction), +#else + interactionFlags(Qt::TextEditable), +#endif dragEnabled(true), #ifndef QT_NO_DRAGANDDROP mousePressed(false), mightStartDrag(false), @@ -2024,7 +2028,7 @@ void QWidgetTextControlPrivate::inputMethodEvent(QInputMethodEvent *e) emit q->microFocusChanged(); } -QVariant QWidgetTextControl::inputMethodQuery(Qt::InputMethodQuery property) const +QVariant QWidgetTextControl::inputMethodQuery(Qt::InputMethodQuery property, QVariant argument) const { Q_D(const QWidgetTextControl); QTextBlock block = d->cursor.block(); @@ -2043,6 +2047,47 @@ QVariant QWidgetTextControl::inputMethodQuery(Qt::InputMethodQuery property) con return QVariant(); // No limit. case Qt::ImAnchorPosition: return QVariant(d->cursor.anchor() - block.position()); + case Qt::ImAbsolutePosition: + return QVariant(d->cursor.position()); + case Qt::ImTextAfterCursor: + { + int maxLength = argument.isValid() ? argument.toInt() : 1024; + QTextCursor tmpCursor = d->cursor; + int localPos = d->cursor.position() - block.position(); + QString result = block.text().mid(localPos); + while (result.length() < maxLength) { + int currentBlock = tmpCursor.blockNumber(); + tmpCursor.movePosition(QTextCursor::NextBlock); + if (tmpCursor.blockNumber() == currentBlock) + break; + result += QLatin1Char('\n') + tmpCursor.block().text(); + } + return QVariant(result); + } + case Qt::ImTextBeforeCursor: + { + int maxLength = argument.isValid() ? argument.toInt() : 1024; + QTextCursor tmpCursor = d->cursor; + int localPos = d->cursor.position() - block.position(); + int numBlocks = 0; + int resultLen = localPos; + while (resultLen < maxLength) { + int currentBlock = tmpCursor.blockNumber(); + tmpCursor.movePosition(QTextCursor::PreviousBlock); + if (tmpCursor.blockNumber() == currentBlock) + break; + numBlocks++; + resultLen += tmpCursor.block().length(); + } + QString result; + while (numBlocks) { + result += tmpCursor.block().text() + QLatin1Char('\n'); + tmpCursor.movePosition(QTextCursor::NextBlock); + --numBlocks; + } + result += block.text().mid(0,localPos); + return QVariant(result); + } default: return QVariant(); } @@ -2958,6 +3003,19 @@ bool QWidgetTextControl::find(const QString &exp, QTextDocument::FindFlags optio return true; } +#ifndef QT_NO_REGEXP +bool QWidgetTextControl::find(const QRegExp &exp, QTextDocument::FindFlags options) +{ + Q_D(QWidgetTextControl); + QTextCursor search = d->doc->find(exp, d->cursor, options); + if (search.isNull()) + return false; + + setTextCursor(search); + return true; +} +#endif + QString QWidgetTextControl::toPlainText() const { return document()->toPlainText(); @@ -3126,7 +3184,7 @@ QRectF QWidgetTextControl::blockBoundingRect(const QTextBlock &block) const } #ifndef QT_NO_CONTEXTMENU -#define NUM_CONTROL_CHARACTERS 10 +#define NUM_CONTROL_CHARACTERS 14 const struct QUnicodeControlCharacter { const char *text; ushort character; @@ -3141,6 +3199,10 @@ const struct QUnicodeControlCharacter { { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "LRO Start of left-to-right override"), 0x202d }, { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "RLO Start of right-to-left override"), 0x202e }, { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "PDF Pop directional formatting"), 0x202c }, + { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "LRI Left-to-right isolate"), 0x2066 }, + { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "RLI Right-to-left isolate"), 0x2067 }, + { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "FSI First strong isolate"), 0x2068 }, + { QT_TRANSLATE_NOOP("QUnicodeControlCharacterMenu", "PDI Pop directional isolate"), 0x2069 } }; QUnicodeControlCharacterMenu::QUnicodeControlCharacterMenu(QObject *_editWidget, QWidget *parent) diff --git a/src/widgets/widgets/qwidgettextcontrol_p.h b/src/widgets/widgets/qwidgettextcontrol_p.h index e857fffba5..0c76355ca1 100644 --- a/src/widgets/widgets/qwidgettextcontrol_p.h +++ b/src/widgets/widgets/qwidgettextcontrol_p.h @@ -110,6 +110,9 @@ public: QTextCharFormat currentCharFormat() const; bool find(const QString &exp, QTextDocument::FindFlags options = 0); +#ifndef QT_NO_REGEXP + bool find(const QRegExp &exp, QTextDocument::FindFlags options = 0); +#endif QString toPlainText() const; #ifndef QT_NO_TEXTHTMLPARSER @@ -236,7 +239,7 @@ public: void setFocus(bool focus, Qt::FocusReason = Qt::OtherFocusReason); - virtual QVariant inputMethodQuery(Qt::InputMethodQuery property) const; + virtual QVariant inputMethodQuery(Qt::InputMethodQuery property, QVariant argument) const; virtual QMimeData *createMimeDataFromSelection() const; virtual bool canInsertFromMimeData(const QMimeData *source) const; |