summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/widgets')
-rw-r--r--src/widgets/widgets/qabstractspinbox.cpp4
-rw-r--r--src/widgets/widgets/qcombobox.cpp2
-rw-r--r--src/widgets/widgets/qcombobox.h6
-rw-r--r--src/widgets/widgets/qdatetimeedit.cpp19
-rw-r--r--src/widgets/widgets/qdockwidget.cpp2
-rw-r--r--src/widgets/widgets/qlineedit.cpp6
-rw-r--r--src/widgets/widgets/qmainwindow.cpp6
-rw-r--r--src/widgets/widgets/qmdiarea.cpp6
-rw-r--r--src/widgets/widgets/qmenu.cpp11
-rw-r--r--src/widgets/widgets/qmenubar.cpp4
-rw-r--r--src/widgets/widgets/qplaintextedit.cpp16
-rw-r--r--src/widgets/widgets/qsplitter.cpp4
-rw-r--r--src/widgets/widgets/qtextbrowser.cpp10
-rw-r--r--src/widgets/widgets/qtextedit.cpp90
-rw-r--r--src/widgets/widgets/qtextedit.h11
-rw-r--r--src/widgets/widgets/qtoolbox.cpp86
-rw-r--r--src/widgets/widgets/qwidgetanimator.cpp6
-rw-r--r--src/widgets/widgets/qwidgetanimator_p.h2
-rw-r--r--src/widgets/widgets/qwidgetresizehandler.cpp2
-rw-r--r--src/widgets/widgets/qwidgettextcontrol.cpp26
-rw-r--r--src/widgets/widgets/qwidgettextcontrol_p.h8
-rw-r--r--src/widgets/widgets/qwidgettextcontrol_p_p.h2
22 files changed, 244 insertions, 85 deletions
diff --git a/src/widgets/widgets/qabstractspinbox.cpp b/src/widgets/widgets/qabstractspinbox.cpp
index c617525c45..04276aa400 100644
--- a/src/widgets/widgets/qabstractspinbox.cpp
+++ b/src/widgets/widgets/qabstractspinbox.cpp
@@ -212,6 +212,7 @@ void QAbstractSpinBox::setButtonSymbols(ButtonSymbols buttonSymbols)
if (d->buttonSymbols != buttonSymbols) {
d->buttonSymbols = buttonSymbols;
d->updateEditFieldGeometry();
+ updateGeometry();
update();
}
}
@@ -1319,6 +1320,7 @@ void QAbstractSpinBox::contextMenuEvent(QContextMenuEvent *event)
d->reset();
QAction *selAll = new QAction(tr("&Select All"), menu);
+ selAll->setShortcut(QKeySequence::SelectAll);
menu->insertAction(d->edit->d_func()->selectAllAction,
selAll);
menu->removeAction(d->edit->d_func()->selectAllAction);
@@ -2097,7 +2099,7 @@ QVariant operator*(const QVariant &arg1, double multiplier)
days -= daysInt;
qint64 msecs = qint64(arg1.toDateTime().time().msecsSinceStartOfDay() * multiplier
+ days * (24 * 3600 * 1000));
- ret = QDateTime(QDATETIMEEDIT_DATE_MIN.addDays(daysInt), QTime::fromMSecsSinceStartOfDay(msecs));
+ ret = QDATETIMEEDIT_DATE_MIN.addDays(daysInt).startOfDay().addMSecs(msecs);
break;
}
#endif // datetimeparser
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp
index 17090efb56..07c55e4db6 100644
--- a/src/widgets/widgets/qcombobox.cpp
+++ b/src/widgets/widgets/qcombobox.cpp
@@ -691,7 +691,7 @@ void QComboBoxPrivateContainer::changeEvent(QEvent *e)
setFrameStyle(combo->style()->styleHint(QStyle::SH_ComboBox_PopupFrameStyle, &opt, combo));
}
- QWidget::changeEvent(e);
+ QFrame::changeEvent(e);
}
diff --git a/src/widgets/widgets/qcombobox.h b/src/widgets/widgets/qcombobox.h
index 6a87a675a4..37b155774d 100644
--- a/src/widgets/widgets/qcombobox.h
+++ b/src/widgets/widgets/qcombobox.h
@@ -226,13 +226,13 @@ Q_SIGNALS:
void currentIndexChanged(int index);
void currentTextChanged(const QString &);
#if QT_DEPRECATED_SINCE(5, 13)
- QT_DEPRECATED_X("Use currentTextChanged() instead")
+ QT_DEPRECATED_VERSION_X(5, 13, "Use currentTextChanged() instead")
void currentIndexChanged(const QString &);
#endif
#if QT_DEPRECATED_SINCE(5, 15)
- QT_DEPRECATED_X("Use textActivated() instead")
+ QT_DEPRECATED_VERSION_X(5, 15, "Use textActivated() instead")
void activated(const QString &);
- QT_DEPRECATED_X("Use textHighlighted() instead")
+ QT_DEPRECATED_VERSION_X(5, 15, "Use textHighlighted() instead")
void highlighted(const QString &);
#endif
diff --git a/src/widgets/widgets/qdatetimeedit.cpp b/src/widgets/widgets/qdatetimeedit.cpp
index b874e4e3a9..3f41fdeb59 100644
--- a/src/widgets/widgets/qdatetimeedit.cpp
+++ b/src/widgets/widgets/qdatetimeedit.cpp
@@ -153,7 +153,7 @@ QDateTimeEdit::QDateTimeEdit(QWidget *parent)
: QAbstractSpinBox(*new QDateTimeEditPrivate, parent)
{
Q_D(QDateTimeEdit);
- d->init(QDateTime(QDATETIMEEDIT_DATE_INITIAL, QDATETIMEEDIT_TIME_MIN));
+ d->init(QDATETIMEEDIT_DATE_INITIAL.startOfDay());
}
/*!
@@ -165,8 +165,7 @@ QDateTimeEdit::QDateTimeEdit(const QDateTime &datetime, QWidget *parent)
: QAbstractSpinBox(*new QDateTimeEditPrivate, parent)
{
Q_D(QDateTimeEdit);
- d->init(datetime.isValid() ? datetime : QDateTime(QDATETIMEEDIT_DATE_INITIAL,
- QDATETIMEEDIT_TIME_MIN));
+ d->init(datetime.isValid() ? datetime : QDATETIMEEDIT_DATE_INITIAL.startOfDay());
}
/*!
@@ -342,7 +341,7 @@ QDateTime QDateTimeEdit::minimumDateTime() const
void QDateTimeEdit::clearMinimumDateTime()
{
- setMinimumDateTime(QDateTime(QDATETIMEEDIT_COMPAT_DATE_MIN, QDATETIMEEDIT_TIME_MIN));
+ setMinimumDateTime(QDATETIMEEDIT_COMPAT_DATE_MIN.startOfDay());
}
void QDateTimeEdit::setMinimumDateTime(const QDateTime &dt)
@@ -385,7 +384,7 @@ QDateTime QDateTimeEdit::maximumDateTime() const
void QDateTimeEdit::clearMaximumDateTime()
{
- setMaximumDateTime(QDATETIMEEDIT_DATETIME_MAX);
+ setMaximumDateTime(QDATETIMEEDIT_DATE_MAX.endOfDay());
}
void QDateTimeEdit::setMaximumDateTime(const QDateTime &dt)
@@ -1658,8 +1657,8 @@ QDateTimeEditPrivate::QDateTimeEditPrivate()
first.pos = 0;
sections = 0;
calendarPopup = false;
- minimum = QDATETIMEEDIT_COMPAT_DATETIME_MIN;
- maximum = QDATETIMEEDIT_DATETIME_MAX;
+ minimum = QDATETIMEEDIT_COMPAT_DATE_MIN.startOfDay();
+ maximum = QDATETIMEEDIT_DATE_MAX.endOfDay();
arrowState = QStyle::State_None;
monthCalendar = 0;
readLocaleSettings();
@@ -1683,8 +1682,8 @@ void QDateTimeEditPrivate::updateTimeSpec()
const bool dateShown = (sections & QDateTimeEdit::DateSections_Mask);
if (!dateShown) {
if (minimum.toTime() >= maximum.toTime()){
- minimum = QDateTime(value.toDate(), QDATETIMEEDIT_TIME_MIN, spec);
- maximum = QDateTime(value.toDate(), QDATETIMEEDIT_TIME_MAX, spec);
+ minimum = value.toDate().startOfDay(spec);
+ maximum = value.toDate().endOfDay(spec);
}
}
}
@@ -2382,7 +2381,7 @@ void QDateTimeEditPrivate::init(const QVariant &var)
Q_Q(QDateTimeEdit);
switch (var.type()) {
case QVariant::Date:
- value = QDateTime(var.toDate(), QDATETIMEEDIT_TIME_MIN);
+ value = var.toDate().startOfDay();
updateTimeSpec();
q->setDisplayFormat(defaultDateFormat);
if (sectionNodes.isEmpty()) // ### safeguard for broken locale
diff --git a/src/widgets/widgets/qdockwidget.cpp b/src/widgets/widgets/qdockwidget.cpp
index 4041c730b8..f98e0e44db 100644
--- a/src/widgets/widgets/qdockwidget.cpp
+++ b/src/widgets/widgets/qdockwidget.cpp
@@ -1182,6 +1182,8 @@ void QDockWidgetPrivate::setWindowState(bool floating, bool unplug, const QRect
QMainWindowLayout *mwlayout = qt_mainwindow_layout_from_dock(q);
if (mwlayout)
emit q->dockLocationChanged(mwlayout->dockWidgetArea(q));
+ } else {
+ emit q->dockLocationChanged(Qt::NoDockWidgetArea);
}
}
diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp
index 02aa703289..09b7687d8e 100644
--- a/src/widgets/widgets/qlineedit.cpp
+++ b/src/widgets/widgets/qlineedit.cpp
@@ -1369,6 +1369,12 @@ void QLineEdit::setReadOnly(bool enable)
QEvent event(QEvent::ReadOnlyChange);
QCoreApplication::sendEvent(this, &event);
update();
+#ifndef QT_NO_ACCESSIBILITY
+ QAccessible::State changedState;
+ changedState.readOnly = true;
+ QAccessibleStateChangeEvent ev(this, changedState);
+ QAccessible::updateAccessibility(&ev);
+#endif
}
}
diff --git a/src/widgets/widgets/qmainwindow.cpp b/src/widgets/widgets/qmainwindow.cpp
index fae3aebba4..9c4c46f2d6 100644
--- a/src/widgets/widgets/qmainwindow.cpp
+++ b/src/widgets/widgets/qmainwindow.cpp
@@ -596,7 +596,7 @@ QStatusBar *QMainWindow::statusBar() const
/*!
Sets the status bar for the main window to \a statusbar.
- Setting the status bar to 0 will remove it from the main window.
+ Setting the status bar to \nullptr will remove it from the main window.
Note that QMainWindow takes ownership of the \a statusbar pointer
and deletes it at the appropriate time.
@@ -1464,8 +1464,8 @@ void QMainWindow::contextMenuEvent(QContextMenuEvent *event)
#if QT_CONFIG(menu)
/*!
Returns a popup menu containing checkable entries for the toolbars and
- dock widgets present in the main window. If there are no toolbars and
- dock widgets present, this function returns a null pointer.
+ dock widgets present in the main window. If there are no toolbars and
+ dock widgets present, this function returns \nullptr.
By default, this function is called by the main window when the user
activates a context menu, typically by right-clicking on a toolbar or a dock
diff --git a/src/widgets/widgets/qmdiarea.cpp b/src/widgets/widgets/qmdiarea.cpp
index 0ce561860e..fe3d1663a8 100644
--- a/src/widgets/widgets/qmdiarea.cpp
+++ b/src/widgets/widgets/qmdiarea.cpp
@@ -2000,9 +2000,9 @@ QMdiSubWindow *QMdiArea::addSubWindow(QWidget *widget, Qt::WindowFlags windowFla
Removes \a widget from the MDI area. The \a widget must be
either a QMdiSubWindow or a widget that is the internal widget of
a subwindow. Note \a widget is never actually deleted by QMdiArea.
- If a QMdiSubWindow is passed in its parent is set to 0 and it is
- removed, but if an internal widget is passed in the child widget
- is set to 0 but the QMdiSubWindow is not removed.
+ If a QMdiSubWindow is passed in, its parent is set to \nullptr and it is
+ removed; but if an internal widget is passed in, the child widget
+ is set to \nullptr and the QMdiSubWindow is \e not removed.
\sa addSubWindow()
*/
diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp
index 14964a696d..287be3e272 100644
--- a/src/widgets/widgets/qmenu.cpp
+++ b/src/widgets/widgets/qmenu.cpp
@@ -73,6 +73,7 @@
#endif
#include "qpushbutton.h"
#include "qtooltip.h"
+#include <qwindow.h>
#include <private/qpushbutton_p.h>
#include <private/qaction_p.h>
#include <private/qguiapplication_p.h>
@@ -1485,6 +1486,8 @@ void QMenuPrivate::_q_platformMenuAboutToShow()
{
Q_Q(QMenu);
+ emit q->aboutToShow();
+
#ifdef Q_OS_OSX
if (platformMenu) {
const auto actions = q->actions();
@@ -1498,8 +1501,6 @@ void QMenuPrivate::_q_platformMenuAboutToShow()
}
}
#endif
-
- emit q->aboutToShow();
}
bool QMenuPrivate::hasMouseMoved(const QPoint &globalPos)
@@ -2328,8 +2329,10 @@ void QMenu::popup(const QPoint &p, QAction *atAction)
d->motions = 0;
d->doChildEffects = true;
d->updateLayoutDirection();
- // Ensure that we get correct sizeHints by placing this window on the right screen.
- d->setScreenForPoint(p);
+
+ // Ensure that we get correct sizeHints by placing this window on the correct screen.
+ if (d->setScreenForPoint(p))
+ d->itemsDirty = true;
const bool contextMenu = d->isContextMenu();
if (d->lastContextMenu != contextMenu) {
diff --git a/src/widgets/widgets/qmenubar.cpp b/src/widgets/widgets/qmenubar.cpp
index e7984078de..a53d7841f4 100644
--- a/src/widgets/widgets/qmenubar.cpp
+++ b/src/widgets/widgets/qmenubar.cpp
@@ -897,8 +897,8 @@ QAction *QMenuBar::insertMenu(QAction *before, QMenu *menu)
}
/*!
- Returns the QAction that is currently highlighted. A null pointer
- will be returned if no action is currently selected.
+ Returns the QAction that is currently highlighted, if any,
+ else \nullptr.
*/
QAction *QMenuBar::activeAction() const
{
diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp
index dc8765ad88..bc1ff78de0 100644
--- a/src/widgets/widgets/qplaintextedit.cpp
+++ b/src/widgets/widgets/qplaintextedit.cpp
@@ -1239,6 +1239,8 @@ void QPlainTextEditPrivate::ensureViewportLayouted()
This property gets and sets the plain text editor's contents. The previous
contents are removed and undo/redo history is reset when this property is set.
+ currentCharFormat() is also reset, unless textCursor() is already at the
+ beginning of the document.
By default, for an editor with no contents, this property contains an empty string.
*/
@@ -1518,7 +1520,12 @@ void QPlainTextEdit::paste()
/*!
Deletes all the text in the text edit.
- Note that the undo/redo history is cleared by this function.
+ Notes:
+ \list
+ \li The undo/redo history is also cleared.
+ \li currentCharFormat() is reset, unless textCursor()
+ is already at the beginning of the document.
+ \endlist
\sa cut(), setPlainText()
*/
@@ -1651,7 +1658,12 @@ void QPlainTextEdit::timerEvent(QTimerEvent *e)
\a text is interpreted as plain text.
- Note that the undo/redo history is cleared by this function.
+ Notes:
+ \list
+ \li The undo/redo history is also cleared.
+ \li currentCharFormat() is reset, unless textCursor()
+ is already at the beginning of the document.
+ \endlist
\sa toPlainText()
*/
diff --git a/src/widgets/widgets/qsplitter.cpp b/src/widgets/widgets/qsplitter.cpp
index de838a8f93..08533040a7 100644
--- a/src/widgets/widgets/qsplitter.cpp
+++ b/src/widgets/widgets/qsplitter.cpp
@@ -1378,7 +1378,7 @@ bool QSplitter::event(QEvent *e)
default:
;
}
- return QWidget::event(e);
+ return QFrame::event(e);
}
/*!
@@ -1793,7 +1793,7 @@ void QSplitter::setStretchFactor(int index, int stretch)
QTextStream& operator<<(QTextStream& ts, const QSplitter& splitter)
{
- ts << splitter.saveState() << endl;
+ ts << splitter.saveState() << Qt::endl;
return ts;
}
diff --git a/src/widgets/widgets/qtextbrowser.cpp b/src/widgets/widgets/qtextbrowser.cpp
index bb9a4fed91..91c5f62246 100644
--- a/src/widgets/widgets/qtextbrowser.cpp
+++ b/src/widgets/widgets/qtextbrowser.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWidgets module of the Qt Toolkit.
@@ -327,9 +327,15 @@ void QTextBrowserPrivate::setSource(const QUrl &url)
home = url;
if (doSetText) {
+ // Setting the base URL helps QTextDocument::resource() to find resources with relative paths.
+ // But don't set it unless it contains the document's path, because QTextBrowserPrivate::resolveUrl()
+ // can already deal with local files on the filesystem in case the base URL was not set.
+ QUrl baseUrl = currentURL.adjusted(QUrl::RemoveFilename);
+ if (!baseUrl.path().isEmpty())
+ q->document()->setBaseUrl(baseUrl);
+ q->document()->setMetaInformation(QTextDocument::DocumentUrl, currentURL.toString());
#ifndef QT_NO_TEXTHTMLPARSER
q->QTextEdit::setHtml(txt);
- q->document()->setMetaInformation(QTextDocument::DocumentUrl, currentURL.toString());
#else
q->QTextEdit::setPlainText(txt);
#endif
diff --git a/src/widgets/widgets/qtextedit.cpp b/src/widgets/widgets/qtextedit.cpp
index 920133d493..5f734258b2 100644
--- a/src/widgets/widgets/qtextedit.cpp
+++ b/src/widgets/widgets/qtextedit.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWidgets module of the Qt Toolkit.
@@ -366,8 +366,8 @@ void QTextEditPrivate::_q_ensureVisible(const QRectF &_rect)
\section1 Introduction and Concepts
QTextEdit is an advanced WYSIWYG viewer/editor supporting rich
- text formatting using HTML-style tags. It is optimized to handle
- large documents and to respond quickly to user input.
+ text formatting using HTML-style tags, or Markdown format. It is optimized
+ to handle large documents and to respond quickly to user input.
QTextEdit works on paragraphs and characters. A paragraph is a
formatted string which is word-wrapped to fit into the width of
@@ -381,7 +381,7 @@ void QTextEditPrivate::_q_ensureVisible(const QRectF &_rect)
QTextEdit can display images, lists and tables. If the text is
too large to view within the text edit's viewport, scroll bars will
appear. The text edit can load both plain text and rich text files.
- Rich text is described using a subset of HTML 4 markup, refer to the
+ Rich text can be described using a subset of HTML 4 markup; refer to the
\l {Supported HTML Subset} page for more information.
If you just need to display a small piece of rich text use QLabel.
@@ -401,12 +401,19 @@ void QTextEditPrivate::_q_ensureVisible(const QRectF &_rect)
QTextEdit can display a large HTML subset, including tables and
images.
- The text is set or replaced using setHtml() which deletes any
+ The text can be set or replaced using \l setHtml() which deletes any
existing text and replaces it with the text passed in the
setHtml() call. If you call setHtml() with legacy HTML, and then
call toHtml(), the text that is returned may have different markup,
but will render the same. The entire text can be deleted with clear().
+ Text can also be set or replaced using \l setMarkdown(), and the same
+ caveats apply: if you then call \l toMarkdown(), the text that is returned
+ may be different, but the meaning is preserved as much as possible.
+ Markdown with some embedded HTML can be parsed, with the same limitations
+ that \l setHtml() has; but \l toMarkdown() only writes "pure" Markdown,
+ without any embedded HTML.
+
Text itself can be inserted using the QTextCursor class or using the
convenience functions insertHtml(), insertPlainText(), append() or
paste(). QTextCursor is also able to insert complex objects like tables
@@ -556,7 +563,8 @@ void QTextEditPrivate::_q_ensureVisible(const QRectF &_rect)
This property gets and sets the text editor's contents as plain
text. Previous contents are removed and undo/redo history is reset
- when the property is set.
+ when the property is set. currentCharFormat() is also reset, unless
+ textCursor() is already at the beginning of the document.
If the text edit has another content type, it will not be replaced
by plain text if you call toPlainText(). The only exception to this
@@ -1034,7 +1042,12 @@ void QTextEdit::paste()
/*!
Deletes all the text in the text edit.
- Note that the undo/redo history is cleared by this function.
+ Notes:
+ \list
+ \li The undo/redo history is also cleared.
+ \li currentCharFormat() is reset, unless textCursor()
+ is already at the beginning of the document.
+ \endlist
\sa cut(), setPlainText(), setHtml()
*/
@@ -1139,9 +1152,13 @@ void QTextEdit::timerEvent(QTimerEvent *e)
Changes the text of the text edit to the string \a text.
Any previous text is removed.
- \a text is interpreted as plain text.
-
- Note that the undo/redo history is cleared by this function.
+ Notes:
+ \list
+ \li \a text is interpreted as plain text.
+ \li The undo/redo history is also cleared.
+ \li currentCharFormat() is reset, unless textCursor()
+ is already at the beginning of the document.
+ \endlist
\sa toPlainText()
*/
@@ -1175,7 +1192,8 @@ QString QTextEdit::toPlainText() const
setHtml() changes the text of the text edit. Any previous text is
removed and the undo/redo history is cleared. The input text is
- interpreted as rich text in html format.
+ interpreted as rich text in html format. currentCharFormat() is also
+ reset, unless textCursor() is already at the beginning of the document.
\note It is the responsibility of the caller to make sure that the
text is correctly decoded when a QString containing HTML is created
@@ -1202,6 +1220,56 @@ QString QTextEdit::toHtml() const
}
#endif
+#if QT_CONFIG(textmarkdownreader) && QT_CONFIG(textmarkdownwriter)
+/*!
+ \property QTextEdit::markdown
+
+ This property provides a Markdown interface to the text of the text edit.
+
+ \c toMarkdown() returns the text of the text edit as "pure" Markdown,
+ without any embedded HTML formatting. Some features that QTextDocument
+ supports (such as the use of specific colors and named fonts) cannot be
+ expressed in "pure" Markdown, and they will be omitted.
+
+ \c setMarkdown() changes the text of the text edit. Any previous text is
+ removed and the undo/redo history is cleared. The input text is
+ interpreted as rich text in Markdown format.
+
+ Parsing of HTML included in the \a markdown string is handled in the same
+ way as in \l setHtml; however, Markdown formatting inside HTML blocks is
+ not supported.
+
+ Some features of the parser can be enabled or disabled via the \a features
+ argument:
+
+ \value MarkdownNoHTML
+ Any HTML tags in the Markdown text will be discarded
+ \value MarkdownDialectCommonMark
+ The parser supports only the features standardized by CommonMark
+ \value MarkdownDialectGitHub
+ The parser supports the GitHub dialect
+
+ The default is \c MarkdownDialectGitHub.
+
+ \sa plainText, html, QTextDocument::toMarkdown(), QTextDocument::setMarkdown()
+*/
+#endif
+
+#if QT_CONFIG(textmarkdownreader)
+void QTextEdit::setMarkdown(const QString &markdown)
+{
+ Q_D(const QTextEdit);
+ d->control->setMarkdown(markdown);
+}
+#endif
+
+#if QT_CONFIG(textmarkdownwriter)
+QString QTextEdit::toMarkdown(QTextDocument::MarkdownFeatures features) const
+{
+ Q_D(const QTextEdit);
+ return d->control->toMarkdown(features);
+}
+#endif
/*! \reimp
*/
diff --git a/src/widgets/widgets/qtextedit.h b/src/widgets/widgets/qtextedit.h
index 3aa23aaace..3b7e610786 100644
--- a/src/widgets/widgets/qtextedit.h
+++ b/src/widgets/widgets/qtextedit.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWidgets module of the Qt Toolkit.
@@ -71,6 +71,9 @@ class Q_WIDGETS_EXPORT QTextEdit : public QAbstractScrollArea
QDOC_PROPERTY(QTextOption::WrapMode wordWrapMode READ wordWrapMode WRITE setWordWrapMode)
Q_PROPERTY(int lineWrapColumnOrWidth READ lineWrapColumnOrWidth WRITE setLineWrapColumnOrWidth)
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
+#if QT_CONFIG(textmarkdownreader) && QT_CONFIG(textmarkdownwriter)
+ Q_PROPERTY(QString markdown READ toMarkdown WRITE setMarkdown NOTIFY textChanged)
+#endif
#ifndef QT_NO_TEXTHTMLPARSER
Q_PROPERTY(QString html READ toHtml WRITE setHtml NOTIFY textChanged USER true)
#endif
@@ -174,6 +177,9 @@ public:
#ifndef QT_NO_TEXTHTMLPARSER
QString toHtml() const;
#endif
+#if QT_CONFIG(textmarkdownwriter)
+ QString toMarkdown(QTextDocument::MarkdownFeatures features = QTextDocument::MarkdownDialectGitHub) const;
+#endif
void ensureCursorVisible();
@@ -238,6 +244,9 @@ public Q_SLOTS:
#ifndef QT_NO_TEXTHTMLPARSER
void setHtml(const QString &text);
#endif
+#if QT_CONFIG(textmarkdownreader)
+ void setMarkdown(const QString &markdown);
+#endif
void setText(const QString &text);
#ifndef QT_NO_CLIPBOARD
diff --git a/src/widgets/widgets/qtoolbox.cpp b/src/widgets/widgets/qtoolbox.cpp
index 1c83485bff..4d7f543a99 100644
--- a/src/widgets/widgets/qtoolbox.cpp
+++ b/src/widgets/widgets/qtoolbox.cpp
@@ -50,6 +50,8 @@
#include <qtooltip.h>
#include <qabstractbutton.h>
+#include <private/qmemory_p.h>
+
#include "qframe_p.h"
QT_BEGIN_NAMESPACE
@@ -106,7 +108,7 @@ public:
return widget == other.widget;
}
};
- typedef QList<Page> PageList;
+ typedef std::vector<std::unique_ptr<Page>> PageList;
inline QToolBoxPrivate()
: currentPage(0)
@@ -130,26 +132,27 @@ public:
const QToolBoxPrivate::Page *QToolBoxPrivate::page(const QObject *widget) const
{
if (!widget)
- return 0;
+ return nullptr;
- for (PageList::ConstIterator i = pageList.constBegin(); i != pageList.constEnd(); ++i)
- if ((*i).widget == widget)
- return (const Page*) &(*i);
- return 0;
+ for (const auto &page : pageList) {
+ if (page->widget == widget)
+ return page.get();
+ }
+ return nullptr;
}
QToolBoxPrivate::Page *QToolBoxPrivate::page(int index)
{
- if (index >= 0 && index < pageList.size())
- return &pageList[index];
- return 0;
+ if (index >= 0 && index < static_cast<int>(pageList.size()))
+ return pageList[index].get();
+ return nullptr;
}
const QToolBoxPrivate::Page *QToolBoxPrivate::page(int index) const
{
- if (index >= 0 && index < pageList.size())
- return &pageList.at(index);
- return 0;
+ if (index >= 0 && index < static_cast<int>(pageList.size()))
+ return pageList[index].get();
+ return nullptr;
}
void QToolBoxPrivate::updateTabs()
@@ -157,13 +160,12 @@ void QToolBoxPrivate::updateTabs()
QToolBoxButton *lastButton = currentPage ? currentPage->button : 0;
bool after = false;
int index = 0;
- for (index = 0; index < pageList.count(); ++index) {
- const Page &page = pageList.at(index);
- QToolBoxButton *tB = page.button;
+ for (const auto &page : pageList) {
+ QToolBoxButton *tB = page->button;
// update indexes, since the updates are delayed, the indexes will be correct
// when we actually paint.
tB->setIndex(index);
- QWidget *tW = page.widget;
+ QWidget *tW = page->widget;
if (after) {
QPalette p = tB->palette();
p.setColor(tB->backgroundRole(), tW->palette().color(tW->backgroundRole()));
@@ -174,6 +176,7 @@ void QToolBoxPrivate::updateTabs()
tB->update();
}
after = tB == lastButton;
+ ++index;
}
}
@@ -345,7 +348,8 @@ int QToolBox::insertItem(int index, QWidget *widget, const QIcon &icon, const QS
Q_D(QToolBox);
connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(_q_widgetDestroyed(QObject*)));
- QToolBoxPrivate::Page c;
+ auto newPage = qt_make_unique<QToolBoxPrivate::Page>();
+ auto &c = *newPage;
c.widget = widget;
c.button = new QToolBoxButton(this);
c.button->setObjectName(QLatin1String("qt_toolbox_toolboxbutton"));
@@ -360,15 +364,15 @@ int QToolBox::insertItem(int index, QWidget *widget, const QIcon &icon, const QS
c.setText(text);
c.setIcon(icon);
- if (index < 0 || index >= (int)d->pageList.count()) {
- index = d->pageList.count();
- d->pageList.append(c);
+ if (index < 0 || index >= static_cast<int>(d->pageList.size())) {
+ index = static_cast<int>(d->pageList.size());
+ d->pageList.push_back(std::move(newPage));
d->layout->addWidget(c.button);
d->layout->addWidget(c.sv);
if (index == 0)
setCurrentIndex(index);
} else {
- d->pageList.insert(index, c);
+ d->pageList.insert(d->pageList.cbegin() + index, std::move(newPage));
d->relayout();
if (d->currentPage) {
QWidget *current = d->currentPage->widget;
@@ -391,12 +395,13 @@ void QToolBoxPrivate::_q_buttonClicked()
{
Q_Q(QToolBox);
QToolBoxButton *tb = qobject_cast<QToolBoxButton*>(q->sender());
- QWidget* item = 0;
- for (QToolBoxPrivate::PageList::ConstIterator i = pageList.constBegin(); i != pageList.constEnd(); ++i)
- if ((*i).button == tb) {
- item = (*i).widget;
+ QWidget* item = nullptr;
+ for (const auto &page : pageList) {
+ if (page->button == tb) {
+ item = page->widget;
break;
}
+ }
q->setCurrentIndex(q->indexOf(item));
}
@@ -411,7 +416,7 @@ void QToolBoxPrivate::_q_buttonClicked()
int QToolBox::count() const
{
Q_D(const QToolBox);
- return d->pageList.count();
+ return static_cast<int>(d->pageList.size());
}
void QToolBox::setCurrentIndex(int index)
@@ -438,12 +443,18 @@ void QToolBoxPrivate::relayout()
delete layout;
layout = new QVBoxLayout(q);
layout->setContentsMargins(QMargins());
- for (QToolBoxPrivate::PageList::ConstIterator i = pageList.constBegin(); i != pageList.constEnd(); ++i) {
- layout->addWidget((*i).button);
- layout->addWidget((*i).sv);
+ for (const auto &page : pageList) {
+ layout->addWidget(page->button);
+ layout->addWidget(page->sv);
}
}
+auto pageEquals = [](const QToolBoxPrivate::Page *page) {
+ return [page](const std::unique_ptr<QToolBoxPrivate::Page> &ptr) {
+ return ptr.get() == page;
+ };
+};
+
void QToolBoxPrivate::_q_widgetDestroyed(QObject *object)
{
Q_Q(QToolBox);
@@ -458,9 +469,9 @@ void QToolBoxPrivate::_q_widgetDestroyed(QObject *object)
delete c->button;
bool removeCurrent = c == currentPage;
- pageList.removeAll(*c);
+ pageList.erase(std::remove_if(pageList.begin(), pageList.end(), pageEquals(c)), pageList.end());
- if (!pageList.count()) {
+ if (pageList.empty()) {
currentPage = 0;
emit q->currentChanged(-1);
} else if (removeCurrent) {
@@ -538,9 +549,9 @@ void QToolBox::setCurrentWidget(QWidget *widget)
QWidget *QToolBox::widget(int index) const
{
Q_D(const QToolBox);
- if (index < 0 || index >= (int) d->pageList.size())
+ if (index < 0 || index >= static_cast<int>(d->pageList.size()))
return nullptr;
- return d->pageList.at(index).widget;
+ return d->pageList[index]->widget;
}
/*!
@@ -552,7 +563,12 @@ int QToolBox::indexOf(QWidget *widget) const
{
Q_D(const QToolBox);
const QToolBoxPrivate::Page *c = (widget ? d->page(widget) : 0);
- return c ? d->pageList.indexOf(*c) : -1;
+ if (!c)
+ return -1;
+ const auto it = std::find_if(d->pageList.cbegin(), d->pageList.cend(), pageEquals(c));
+ if (it == d->pageList.cend())
+ return -1;
+ return static_cast<int>(it - d->pageList.cbegin());
}
/*!
@@ -571,7 +587,7 @@ void QToolBox::setItemEnabled(int index, bool enabled)
if (!enabled && c == d->currentPage) {
int curIndexUp = index;
int curIndexDown = curIndexUp;
- const int count = d->pageList.count();
+ const int count = static_cast<int>(d->pageList.size());
while (curIndexUp > 0 || curIndexDown < count-1) {
if (curIndexDown < count-1) {
if (d->page(++curIndexDown)->button->isEnabled()) {
diff --git a/src/widgets/widgets/qwidgetanimator.cpp b/src/widgets/widgets/qwidgetanimator.cpp
index b1e527e3b6..486d65d92c 100644
--- a/src/widgets/widgets/qwidgetanimator.cpp
+++ b/src/widgets/widgets/qwidgetanimator.cpp
@@ -50,8 +50,12 @@
QT_BEGIN_NAMESPACE
-QWidgetAnimator::QWidgetAnimator(QMainWindowLayout *layout) : m_mainWindowLayout(layout)
+QWidgetAnimator::QWidgetAnimator(QMainWindowLayout *layout)
+#if QT_CONFIG(mainwindow)
+: m_mainWindowLayout(layout)
+#endif
{
+ Q_UNUSED(layout)
}
void QWidgetAnimator::abort(QWidget *w)
diff --git a/src/widgets/widgets/qwidgetanimator_p.h b/src/widgets/widgets/qwidgetanimator_p.h
index 920cc3ffc8..9d08d03593 100644
--- a/src/widgets/widgets/qwidgetanimator_p.h
+++ b/src/widgets/widgets/qwidgetanimator_p.h
@@ -81,7 +81,9 @@ private Q_SLOTS:
private:
typedef QHash<QWidget*, QPointer<QPropertyAnimation> > AnimationMap;
AnimationMap m_animation_map;
+#if QT_CONFIG(mainwindow)
QMainWindowLayout *m_mainWindowLayout;
+#endif
};
QT_END_NAMESPACE
diff --git a/src/widgets/widgets/qwidgetresizehandler.cpp b/src/widgets/widgets/qwidgetresizehandler.cpp
index 7ed6f6d78d..e8d435429f 100644
--- a/src/widgets/widgets/qwidgetresizehandler.cpp
+++ b/src/widgets/widgets/qwidgetresizehandler.cpp
@@ -121,7 +121,7 @@ bool QWidgetResizeHandler::eventFilter(QObject *o, QEvent *ee)
break;
const QRect widgetRect = widget->rect().marginsAdded(QMargins(range, range, range, range));
const QPoint cursorPoint = widget->mapFromGlobal(e->globalPos());
- if (!widgetRect.contains(cursorPoint) || mode == Nowhere)
+ if (!widgetRect.contains(cursorPoint))
return false;
if (e->button() == Qt::LeftButton) {
#if 0 // Used to be included in Qt4 for Q_WS_X11
diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp
index 711c4bfd2a..f85c7cdc6d 100644
--- a/src/widgets/widgets/qwidgettextcontrol.cpp
+++ b/src/widgets/widgets/qwidgettextcontrol.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWidgets module of the Qt Toolkit.
@@ -491,6 +491,11 @@ void QWidgetTextControlPrivate::setContent(Qt::TextFormat format, const QString
formatCursor.select(QTextCursor::Document);
formatCursor.setCharFormat(charFormatForInsertion);
formatCursor.endEditBlock();
+#if QT_CONFIG(textmarkdownreader)
+ } else if (format == Qt::MarkdownText) {
+ doc->setMarkdown(text);
+ doc->setUndoRedoEnabled(false);
+#endif
} else {
#ifndef QT_NO_TEXTHTMLPARSER
doc->setHtml(text);
@@ -1194,6 +1199,14 @@ void QWidgetTextControl::setPlainText(const QString &text)
d->setContent(Qt::PlainText, text);
}
+#if QT_CONFIG(textmarkdownreader)
+void QWidgetTextControl::setMarkdown(const QString &text)
+{
+ Q_D(QWidgetTextControl);
+ d->setContent(Qt::MarkdownText, text);
+}
+#endif
+
void QWidgetTextControl::setHtml(const QString &text)
{
Q_D(QWidgetTextControl);
@@ -1972,6 +1985,8 @@ void QWidgetTextControlPrivate::inputMethodEvent(QInputMethodEvent *e)
|| e->preeditString() != cursor.block().layout()->preeditAreaText()
|| e->replacementLength() > 0;
+ int oldCursorPos = cursor.position();
+
cursor.beginEditBlock();
if (isGettingInput) {
cursor.removeSelectedText();
@@ -2076,6 +2091,8 @@ void QWidgetTextControlPrivate::inputMethodEvent(QInputMethodEvent *e)
if (cursor.d)
cursor.d->setX();
+ if (oldCursorPos != cursor.position())
+ emit q->cursorPositionChanged();
if (oldPreeditCursor != preeditCursor)
emit q->microFocusChanged();
}
@@ -3117,6 +3134,13 @@ QString QWidgetTextControl::toHtml() const
}
#endif
+#ifndef QT_NO_TEXTHTMLPARSER
+QString QWidgetTextControl::toMarkdown(QTextDocument::MarkdownFeatures features) const
+{
+ return document()->toMarkdown(features);
+}
+#endif
+
void QWidgetTextControlPrivate::append(const QString &text, Qt::TextFormat format)
{
QTextCursor tmp(doc);
diff --git a/src/widgets/widgets/qwidgettextcontrol_p.h b/src/widgets/widgets/qwidgettextcontrol_p.h
index 9c80d53728..e521e7b356 100644
--- a/src/widgets/widgets/qwidgettextcontrol_p.h
+++ b/src/widgets/widgets/qwidgettextcontrol_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWidgets module of the Qt Toolkit.
@@ -128,6 +128,9 @@ public:
#ifndef QT_NO_TEXTHTMLPARSER
QString toHtml() const;
#endif
+#if QT_CONFIG(textmarkdownwriter)
+ QString toMarkdown(QTextDocument::MarkdownFeatures features = QTextDocument::MarkdownDialectGitHub) const;
+#endif
virtual void ensureCursorVisible();
@@ -194,6 +197,9 @@ public:
public Q_SLOTS:
void setPlainText(const QString &text);
+#if QT_CONFIG(textmarkdownreader)
+ void setMarkdown(const QString &text);
+#endif
void setHtml(const QString &text);
#ifndef QT_NO_CLIPBOARD
diff --git a/src/widgets/widgets/qwidgettextcontrol_p_p.h b/src/widgets/widgets/qwidgettextcontrol_p_p.h
index 6a1ee564cd..6ccdfafe2b 100644
--- a/src/widgets/widgets/qwidgettextcontrol_p_p.h
+++ b/src/widgets/widgets/qwidgettextcontrol_p_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWidgets module of the Qt Toolkit.