diff options
Diffstat (limited to 'src/widgets')
42 files changed, 642 insertions, 436 deletions
diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp index 92ab846a41..c0bacd553d 100644 --- a/src/widgets/dialogs/qcolordialog.cpp +++ b/src/widgets/dialogs/qcolordialog.cpp @@ -1179,7 +1179,8 @@ QColorShower::QColorShower(QColorDialog *parent) curQColor = Qt::white; gl = new QGridLayout(this); - gl->setMargin(gl->spacing()); + const int s = gl->spacing(); + gl->setContentsMargins(s, s, s, s); lab = new QColorShowLabel(this); #ifdef QT_SMALL_COLORDIALOG @@ -1807,7 +1808,7 @@ void QColorDialogPrivate::initWidgets() rightLay->addStretch(); cs = new QColorShower(q); - pickLay->setMargin(cs->gl->margin()); + pickLay->setContentsMargins(cs->gl->contentsMargins()); QObject::connect(cs, SIGNAL(newCol(QRgb)), q, SLOT(_q_newColorTypedIn(QRgb))); QObject::connect(cs, SIGNAL(currentColorChanged(QColor)), q, SIGNAL(currentColorChanged(QColor))); @@ -1816,7 +1817,7 @@ void QColorDialogPrivate::initWidgets() #else rightLay->addWidget(cs); if (leftLay) - leftLay->addSpacing(cs->gl->margin()); + leftLay->addSpacing(cs->gl->contentsMargins().right()); #endif buttons = new QDialogButtonBox(q); @@ -1887,7 +1888,7 @@ bool QColorDialogPrivate::canBeNativeDialog() const } static const Qt::WindowFlags DefaultWindowFlags = - Qt::Dialog | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint + Qt::Dialog | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint; /*! diff --git a/src/widgets/dialogs/qdialog.cpp b/src/widgets/dialogs/qdialog.cpp index cc04110a30..3c49016e2c 100644 --- a/src/widgets/dialogs/qdialog.cpp +++ b/src/widgets/dialogs/qdialog.cpp @@ -779,7 +779,9 @@ void QDialog::setVisible(bool visible) return; QWidget::setVisible(visible); +#if QT_DEPRECATED_SINCE(5, 13) showExtension(d->doShowExtension); +#endif QWidget *fw = window()->focusWidget(); if (!fw) fw = this; @@ -946,6 +948,7 @@ void QDialog::adjustPosition(QWidget* w) move(p); } +#if QT_DEPRECATED_SINCE(5, 13) /*! \obsolete @@ -1090,7 +1093,7 @@ void QDialog::showExtension(bool showIt) #endif } } - +#endif /*! \reimp */ QSize QDialog::sizeHint() const diff --git a/src/widgets/dialogs/qdialog.h b/src/widgets/dialogs/qdialog.h index 7f267dd939..ce57ce5de7 100644 --- a/src/widgets/dialogs/qdialog.h +++ b/src/widgets/dialogs/qdialog.h @@ -69,11 +69,12 @@ public: void setVisible(bool visible) override; - void setOrientation(Qt::Orientation orientation); - Qt::Orientation orientation() const; - - void setExtension(QWidget* extension); - QWidget* extension() const; +#if QT_DEPRECATED_SINCE(5, 13) + QT_DEPRECATED void setOrientation(Qt::Orientation orientation); + QT_DEPRECATED Qt::Orientation orientation() const; + QT_DEPRECATED void setExtension(QWidget* extension); + QT_DEPRECATED QWidget* extension() const; +#endif QSize sizeHint() const override; QSize minimumSizeHint() const override; @@ -96,7 +97,9 @@ public Q_SLOTS: virtual void accept(); virtual void reject(); - void showExtension(bool); +#if QT_DEPRECATED_SINCE(5, 13) + QT_DEPRECATED void showExtension(bool); +#endif protected: QDialog(QDialogPrivate &, QWidget *parent, Qt::WindowFlags f = Qt::WindowFlags()); diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index edaa7854ba..d8a4ad5f24 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -73,6 +73,9 @@ #elif defined(Q_OS_WIN) # include <QtCore/qt_windows.h> #endif +#if defined(Q_OS_WASM) +#include <private/qwasmlocalfileaccess_p.h> +#endif QT_BEGIN_NAMESPACE @@ -1359,6 +1362,7 @@ void QFileDialog::setNameFilter(const QString &filter) } +#if QT_DEPRECATED_SINCE(5, 13) /*! \property QFileDialog::nameFilterDetailsVisible \obsolete @@ -1380,6 +1384,7 @@ bool QFileDialog::isNameFilterDetailsVisible() const { return !testOption(HideNameFilterDetails); } +#endif /* @@ -1859,6 +1864,7 @@ QFileDialog::AcceptMode QFileDialog::acceptMode() const return static_cast<AcceptMode>(d->options->acceptMode()); } +#if QT_DEPRECATED_SINCE(5, 13) /*! \property QFileDialog::readOnly \obsolete @@ -1918,6 +1924,7 @@ bool QFileDialog::confirmOverwrite() const { return !testOption(DontConfirmOverwrite); } +#endif /*! \property QFileDialog::defaultSuffix @@ -2344,6 +2351,85 @@ QList<QUrl> QFileDialog::getOpenFileUrls(QWidget *parent, } /*! + This is a convenience static function that will return the content of a file + selected by the user. + + This function is used to access local files on Qt for WebAssembly, where the web + sandbox places restrictions on how such access may happen. Its implementation will + make the browser display a native file dialog, where the user makes the file selection. + + It can also be used on other platforms, where it will fall back to using QFileDialog. + + The function is asynchronous and returns immediately. The \a fileOpenCompleted + callback will be called when a file has been selected and its contents has been + read into memory. + + \snippet code/src_gui_dialogs_qfiledialog.cpp 14 + \since 5.13 +*/ +void QFileDialog::getOpenFileContent(const QString &nameFilter, const std::function<void(const QString &, const QByteArray &)> &fileOpenCompleted) +{ +#ifdef Q_OS_WASM + auto openFileImpl = std::make_shared<std::function<void(void)>>(); + QString fileName; + QByteArray fileContent; + *openFileImpl = [=]() mutable { + auto fileDialogClosed = [&](bool fileSelected) { + if (!fileSelected) { + fileOpenCompleted(fileName, fileContent); + openFileImpl.reset(); + } + }; + auto acceptFile = [&](uint64_t size, const std::string name) -> char * { + const uint64_t twoGB = 1ULL << 31; // QByteArray limit + if (size > twoGB) + return nullptr; + + fileName = QString::fromStdString(name); + fileContent.resize(size); + return fileContent.data(); + }; + auto fileContentReady = [&]() mutable { + fileOpenCompleted(fileName, fileContent); + openFileImpl.reset(); + }; + + auto qtFilterStringToWebAcceptString = [](const QString &qtString) { + // The Qt and Web name filter string formats are similar, but + // not identical. + return qtString.toStdString(); // ### TODO + }; + + QWasmLocalFileAccess::openFile(qtFilterStringToWebAcceptString(nameFilter), fileDialogClosed, acceptFile, fileContentReady); + }; + + (*openFileImpl)(); +#else + QFileDialog *dialog = new QFileDialog(); + dialog->selectNameFilter(nameFilter); + + auto fileSelected = [=](const QString &fileName) { + QByteArray fileContent; + if (!fileName.isNull()) { + QFile selectedFile(fileName); + selectedFile.open(QIODevice::ReadOnly); + fileContent = selectedFile.readAll(); + } + fileOpenCompleted(fileName, fileContent); + }; + + auto dialogClosed = [=](int code) { + Q_UNUSED(code); + delete dialog; + }; + + connect(dialog, &QFileDialog::fileSelected, fileSelected); + connect(dialog, &QFileDialog::finished, dialogClosed); + dialog->show(); +#endif +} + +/*! This is a convenience static function that will return a file name selected by the user. The file does not have to exist. diff --git a/src/widgets/dialogs/qfiledialog.h b/src/widgets/dialogs/qfiledialog.h index a4d289a77a..95e03618ac 100644 --- a/src/widgets/dialogs/qfiledialog.h +++ b/src/widgets/dialogs/qfiledialog.h @@ -46,6 +46,8 @@ #include <QtCore/qurl.h> #include <QtWidgets/qdialog.h> +#include <functional> + QT_REQUIRE_CONFIG(filedialog); QT_BEGIN_NAMESPACE @@ -64,19 +66,22 @@ class Q_WIDGETS_EXPORT QFileDialog : public QDialog Q_PROPERTY(ViewMode viewMode READ viewMode WRITE setViewMode) Q_PROPERTY(FileMode fileMode READ fileMode WRITE setFileMode) Q_PROPERTY(AcceptMode acceptMode READ acceptMode WRITE setAcceptMode) + Q_PROPERTY(QString defaultSuffix READ defaultSuffix WRITE setDefaultSuffix) +#if QT_DEPRECATED_SINCE(5, 13) Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly DESIGNABLE false) - Q_PROPERTY(bool resolveSymlinks READ resolveSymlinks WRITE setResolveSymlinks DESIGNABLE false) Q_PROPERTY(bool confirmOverwrite READ confirmOverwrite WRITE setConfirmOverwrite DESIGNABLE false) - Q_PROPERTY(QString defaultSuffix READ defaultSuffix WRITE setDefaultSuffix) + Q_PROPERTY(bool resolveSymlinks READ resolveSymlinks WRITE setResolveSymlinks DESIGNABLE false) Q_PROPERTY(bool nameFilterDetailsVisible READ isNameFilterDetailsVisible WRITE setNameFilterDetailsVisible DESIGNABLE false) +#endif Q_PROPERTY(Options options READ options WRITE setOptions) Q_PROPERTY(QStringList supportedSchemes READ supportedSchemes WRITE setSupportedSchemes) public: enum ViewMode { Detail, List }; Q_ENUM(ViewMode) - enum FileMode { AnyFile, ExistingFile, Directory, ExistingFiles, DirectoryOnly }; + enum FileMode { AnyFile, ExistingFile, Directory, ExistingFiles, + DirectoryOnly Q_DECL_ENUMERATOR_DEPRECATED_X("Use setOption(ShowDirsOnly, true) instead")}; Q_ENUM(FileMode) enum AcceptMode { AcceptOpen, AcceptSave }; Q_ENUM(AcceptMode) @@ -117,8 +122,12 @@ public: void selectUrl(const QUrl &url); QList<QUrl> selectedUrls() const; +#if QT_DEPRECATED_SINCE(5, 13) + QT_DEPRECATED_X("Use setOption(HideNameFilterDetails, !enabled) instead") void setNameFilterDetailsVisible(bool enabled); + QT_DEPRECATED_X("Use !testOption(HideNameFilterDetails) instead") bool isNameFilterDetailsVisible() const; +#endif void setNameFilter(const QString &filter); void setNameFilters(const QStringList &filters); @@ -145,11 +154,15 @@ public: void setAcceptMode(AcceptMode mode); AcceptMode acceptMode() const; +#if QT_DEPRECATED_SINCE(5, 13) void setReadOnly(bool enabled); bool isReadOnly() const; + QT_DEPRECATED_X("Use setOption(DontResolveSymlinks, !enabled) instead") void setResolveSymlinks(bool enabled); + QT_DEPRECATED_X("Use !testOption(DontResolveSymlinks) instead") bool resolveSymlinks() const; +#endif void setSidebarUrls(const QList<QUrl> &urls); QList<QUrl> sidebarUrls() const; @@ -157,8 +170,12 @@ public: QByteArray saveState() const; bool restoreState(const QByteArray &state); +#if QT_DEPRECATED_SINCE(5, 13) + QT_DEPRECATED_X("Use setOption(DontConfirmOverwrite, !enabled) instead") void setConfirmOverwrite(bool enabled); + QT_DEPRECATED_X("Use !testOption(DontConfirmOverwrite) instead") bool confirmOverwrite() const; +#endif void setDefaultSuffix(const QString &suffix); QString defaultSuffix() const; @@ -263,6 +280,8 @@ public: Options options = Options(), const QStringList &supportedSchemes = QStringList()); + static void getOpenFileContent(const QString &nameFilter, + const std::function<void(const QString &, const QByteArray &)> &fileContentsReady); protected: QFileDialog(const QFileDialogArgs &args); diff --git a/src/widgets/dialogs/qinputdialog.cpp b/src/widgets/dialogs/qinputdialog.cpp index 5a7d6edddf..3cfe8367e0 100644 --- a/src/widgets/dialogs/qinputdialog.cpp +++ b/src/widgets/dialogs/qinputdialog.cpp @@ -168,6 +168,18 @@ private: } }; +class QInputDialogListView : public QListView +{ +public: + QInputDialogListView(QWidget *parent = 0) : QListView(parent) {} + QVariant inputMethodQuery(Qt::InputMethodQuery query) const override + { + if (query == Qt::ImEnabled) + return false; + return QListView::inputMethodQuery(query); + } +}; + class QInputDialogPrivate : public QDialogPrivate { Q_DECLARE_PUBLIC(QInputDialog) @@ -201,7 +213,7 @@ public: mutable QSpinBox *intSpinBox; mutable QDoubleSpinBox *doubleSpinBox; mutable QComboBox *comboBox; - mutable QListView *listView; + mutable QInputDialogListView *listView; mutable QWidget *inputWidget; mutable QVBoxLayout *mainLayout; QInputDialog::InputDialogOptions opts; @@ -298,8 +310,7 @@ void QInputDialogPrivate::ensureListView() Q_Q(QInputDialog); if (!listView) { ensureComboBox(); - - listView = new QListView(q); + listView = new QInputDialogListView(q); listView->hide(); listView->setEditTriggers(QAbstractItemView::NoEditTriggers); listView->setSelectionMode(QAbstractItemView::SingleSelection); diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index c9818624fb..f143e3b527 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -113,7 +113,7 @@ public: , copyAvailable(false) { QVBoxLayout *layout = new QVBoxLayout; - layout->setMargin(0); + layout->setContentsMargins(QMargins()); QFrame *line = new QFrame(this); line->setFrameShape(QFrame::HLine); line->setFrameShadow(QFrame::Sunken); diff --git a/src/widgets/dialogs/qwizard.cpp b/src/widgets/dialogs/qwizard.cpp index 9345a4b583..88b187cd7f 100644 --- a/src/widgets/dialogs/qwizard.cpp +++ b/src/widgets/dialogs/qwizard.cpp @@ -331,7 +331,7 @@ QWizardHeader::QWizardHeader(QWidget *parent) titleLabel->setFont(font); layout = new QGridLayout(this); - layout->setMargin(0); + layout->setContentsMargins(QMargins()); layout->setSpacing(0); layout->setRowMinimumHeight(3, 1); @@ -456,7 +456,7 @@ public: QSize minimumSizeHint() const override { if (pixmap() && !pixmap()->isNull()) - return pixmap()->size(); + return pixmap()->size() / pixmap()->devicePixelRatio(); return QFrame::minimumSizeHint(); } @@ -1032,13 +1032,13 @@ void QWizardPrivate::recreateLayout(const QWizardLayoutInfo &info) int pageColumn = qMin(1, numColumns - 1); if (mac) { - mainLayout->setMargin(0); + mainLayout->setContentsMargins(QMargins()); mainLayout->setSpacing(0); buttonLayout->setContentsMargins(MacLayoutLeftMargin, MacButtonTopMargin, MacLayoutRightMargin, MacLayoutBottomMargin); - pageVBoxLayout->setMargin(7); + pageVBoxLayout->setContentsMargins(7, 7, 7, 7); } else { if (modern) { - mainLayout->setMargin(0); + mainLayout->setContentsMargins(QMargins()); mainLayout->setSpacing(0); pageVBoxLayout->setContentsMargins(deltaMarginLeft, deltaMarginTop, deltaMarginRight, deltaMarginBottom); diff --git a/src/widgets/doc/snippets/code/src_gui_dialogs_qfiledialog.cpp b/src/widgets/doc/snippets/code/src_gui_dialogs_qfiledialog.cpp index 06cca37111..1e9daf824b 100644 --- a/src/widgets/doc/snippets/code/src_gui_dialogs_qfiledialog.cpp +++ b/src/widgets/doc/snippets/code/src_gui_dialogs_qfiledialog.cpp @@ -144,3 +144,14 @@ dialog.exec(); //! [14] "Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)" //! [14] + +//! [14] +auto fileOpenCompleted = [](const QSting &fileName, const QByteArray &fileContent) { + if (fileName.isEmpty()) { + // No file was selected + } else { + // Use fileName and fileContent + } +} +QFileDialog::getOpenFileContent("Images (*.png *.xpm *.jpg)", fileContentReady); +//! [14] diff --git a/src/widgets/graphicsview/qgraphicsscene.h b/src/widgets/graphicsview/qgraphicsscene.h index 71b8fc3013..3cc00ead08 100644 --- a/src/widgets/graphicsview/qgraphicsscene.h +++ b/src/widgets/graphicsview/qgraphicsscene.h @@ -103,7 +103,9 @@ class Q_WIDGETS_EXPORT QGraphicsScene : public QObject Q_PROPERTY(int bspTreeDepth READ bspTreeDepth WRITE setBspTreeDepth) Q_PROPERTY(QPalette palette READ palette WRITE setPalette) Q_PROPERTY(QFont font READ font WRITE setFont) +#if QT_DEPRECATED_SINCE(5, 13) Q_PROPERTY(bool sortCacheEnabled READ isSortCacheEnabled WRITE setSortCacheEnabled) +#endif Q_PROPERTY(bool stickyFocus READ stickyFocus WRITE setStickyFocus) Q_PROPERTY(qreal minimumRenderSize READ minimumRenderSize WRITE setMinimumRenderSize) Q_PROPERTY(bool focusOnTouch READ focusOnTouch WRITE setFocusOnTouch) diff --git a/src/widgets/itemviews/qitemdelegate.cpp b/src/widgets/itemviews/qitemdelegate.cpp index f85004c49c..6e57e0c32b 100644 --- a/src/widgets/itemviews/qitemdelegate.cpp +++ b/src/widgets/itemviews/qitemdelegate.cpp @@ -1005,11 +1005,14 @@ static QString qPixmapSerial(quint64 i, bool enabled) QPixmap *QItemDelegate::selected(const QPixmap &pixmap, const QPalette &palette, bool enabled) const { const QString key = qPixmapSerial(pixmap.cacheKey(), enabled); +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED QPixmap *pm = QPixmapCache::find(key); if (pm) return pm; selectedPixmap(pixmap, palette, enabled); return QPixmapCache::find(key); +QT_WARNING_POP } #endif diff --git a/src/widgets/itemviews/qitemeditorfactory.h b/src/widgets/itemviews/qitemeditorfactory.h index f2610ad3de..118f6e45e8 100644 --- a/src/widgets/itemviews/qitemeditorfactory.h +++ b/src/widgets/itemviews/qitemeditorfactory.h @@ -66,8 +66,8 @@ class QItemEditorCreator : public QItemEditorCreatorBase { public: inline explicit QItemEditorCreator(const QByteArray &valuePropertyName); - inline QWidget *createWidget(QWidget *parent) const { return new T(parent); } - inline QByteArray valuePropertyName() const { return propertyName; } + inline QWidget *createWidget(QWidget *parent) const override { return new T(parent); } + inline QByteArray valuePropertyName() const override { return propertyName; } private: QByteArray propertyName; diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index 143b243091..e7b2aaec29 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -1100,19 +1100,45 @@ QModelIndex QListView::moveCursor(CursorAction cursorAction, Qt::KeyboardModifie Q_D(QListView); Q_UNUSED(modifiers); - QModelIndex current = currentIndex(); - if (!current.isValid()) { + auto findAvailableRowBackward = [d](int row) { + while (row >= 0 && d->isHiddenOrDisabled(row)) + --row; + return row; + }; + + auto findAvailableRowForward = [d](int row) { int rowCount = d->model->rowCount(d->root); if (!rowCount) - return QModelIndex(); - int row = 0; + return -1; while (row < rowCount && d->isHiddenOrDisabled(row)) ++row; if (row >= rowCount) + return -1; + return row; + }; + + QModelIndex current = currentIndex(); + if (!current.isValid()) { + int row = findAvailableRowForward(0); + if (row == -1) return QModelIndex(); return d->model->index(row, d->column, d->root); } + if ((d->flow == LeftToRight && cursorAction == MoveLeft) || + (d->flow == TopToBottom && (cursorAction == MoveUp || cursorAction == MovePrevious))) { + const int row = findAvailableRowBackward(current.row() - 1); + if (row == -1) + return current; + return d->model->index(row, d->column, d->root); + } else if ((d->flow == LeftToRight && cursorAction == MoveRight) || + (d->flow == TopToBottom && (cursorAction == MoveDown || cursorAction == MoveNext))) { + const int row = findAvailableRowForward(current.row() + 1); + if (row == -1) + return current; + return d->model->index(row, d->column, d->root); + } + const QRect initialRect = rectForIndex(current); QRect rect = initialRect; if (rect.isEmpty()) { diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index e189e5ba50..9e784b41c6 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -1239,6 +1239,7 @@ QStyle* QApplication::setStyle(const QString& style) return s; } +#if QT_DEPRECATED_SINCE(5, 8) /*! Returns the color specification. \obsolete @@ -1313,6 +1314,7 @@ void QApplication::setColorSpec(int spec) { Q_UNUSED(spec) } +#endif /*! \property QApplication::globalStrut diff --git a/src/widgets/kernel/qdesktopwidget.cpp b/src/widgets/kernel/qdesktopwidget.cpp index 5fb7882932..d17c7eb36c 100644 --- a/src/widgets/kernel/qdesktopwidget.cpp +++ b/src/widgets/kernel/qdesktopwidget.cpp @@ -176,26 +176,32 @@ void QDesktopWidgetPrivate::_q_updateScreens() // Notice that we trigger screenCountChanged even if a screen was removed and another one added, // in which case the total number of screens did not change. This is the only way for applications // to notice that a screen was swapped out against another one. +#if QT_DEPRECATED_SINCE(5, 11) QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED emit q->screenCountChanged(targetLength); QT_WARNING_POP +#endif } +#if QT_DEPRECATED_SINCE(5, 11) foreach (int changedScreen, changedScreens) QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED emit q->resized(changedScreen); QT_WARNING_POP +#endif } void QDesktopWidgetPrivate::_q_availableGeometryChanged() { +#if QT_DEPRECATED_SINCE(5, 11) Q_Q(QDesktopWidget); if (QScreen *screen = qobject_cast<QScreen *>(q->sender())) QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED emit q->workAreaResized(QGuiApplication::screens().indexOf(screen)); QT_WARNING_POP +#endif } QDesktopWidget::QDesktopWidget() @@ -212,10 +218,12 @@ QDesktopWidget::~QDesktopWidget() { } +#if QT_DEPRECATED_SINCE(5, 11) bool QDesktopWidget::isVirtualDesktop() const { return QDesktopWidgetPrivate::isVirtualDesktop(); } +#endif bool QDesktopWidgetPrivate::isVirtualDesktop() { @@ -242,24 +250,27 @@ int QDesktopWidgetPrivate::height() return geometry().height(); } +#if QT_DEPRECATED_SINCE(5, 11) int QDesktopWidget::primaryScreen() const { return QDesktopWidgetPrivate::primaryScreen(); } +#endif int QDesktopWidgetPrivate::primaryScreen() { return 0; } -int QDesktopWidget::numScreens() const +int QDesktopWidgetPrivate::numScreens() { - return QDesktopWidgetPrivate::numScreens(); + return qMax(QGuiApplication::screens().size(), 1); } -int QDesktopWidgetPrivate::numScreens() +#if QT_DEPRECATED_SINCE(5, 11) +int QDesktopWidget::numScreens() const { - return qMax(QGuiApplication::screens().size(), 1); + return QDesktopWidgetPrivate::numScreens(); } QWidget *QDesktopWidget::screen(int screen) @@ -274,6 +285,7 @@ const QRect QDesktopWidget::availableGeometry(int screenNo) const { return QDesktopWidgetPrivate::availableGeometry(screenNo); } +#endif const QRect QDesktopWidgetPrivate::availableGeometry(int screenNo) { @@ -281,10 +293,12 @@ const QRect QDesktopWidgetPrivate::availableGeometry(int screenNo) return screen ? screen->availableGeometry() : QRect(); } +#if QT_DEPRECATED_SINCE(5, 11) const QRect QDesktopWidget::screenGeometry(int screenNo) const { return QDesktopWidgetPrivate::screenGeometry(screenNo); } +#endif const QRect QDesktopWidgetPrivate::screenGeometry(int screenNo) { @@ -344,10 +358,12 @@ int QDesktopWidgetPrivate::screenNumber(const QWidget *w) return allScreens.indexOf(widgetScreen); } +#if QT_DEPRECATED_SINCE(5, 11) int QDesktopWidget::screenNumber(const QPoint &p) const { return QDesktopWidgetPrivate::screenNumber(p); } +#endif int QDesktopWidgetPrivate::screenNumber(const QPoint &p) { diff --git a/src/widgets/kernel/qdesktopwidget.h b/src/widgets/kernel/qdesktopwidget.h index f986f0db20..e5c587984f 100644 --- a/src/widgets/kernel/qdesktopwidget.h +++ b/src/widgets/kernel/qdesktopwidget.h @@ -52,9 +52,11 @@ class QDesktopWidgetPrivate; class Q_WIDGETS_EXPORT QDesktopWidget : public QWidget { Q_OBJECT +#if QT_DEPRECATED_SINCE(5, 11) Q_PROPERTY(bool virtualDesktop READ isVirtualDesktop) Q_PROPERTY(int screenCount READ screenCount NOTIFY screenCountChanged) Q_PROPERTY(int primaryScreen READ primaryScreen NOTIFY primaryScreenChanged) +#endif public: QDesktopWidget(); ~QDesktopWidget(); diff --git a/src/widgets/kernel/qlayout.cpp b/src/widgets/kernel/qlayout.cpp index 090abc883d..f27851c7bb 100644 --- a/src/widgets/kernel/qlayout.cpp +++ b/src/widgets/kernel/qlayout.cpp @@ -282,6 +282,7 @@ bool QLayout::setAlignment(QLayout *l, Qt::Alignment alignment) return false; } +#if QT_DEPRECATED_SINCE(5, 13) /*! \property QLayout::margin \brief the width of the outside border of the layout @@ -307,6 +308,15 @@ int QLayout::margin() const } /*! + \obsolete +*/ +void QLayout::setMargin(int margin) +{ + setContentsMargins(margin, margin, margin, margin); +} + +#endif +/*! \property QLayout::spacing \brief the spacing between widgets inside the layout @@ -344,14 +354,6 @@ int QLayout::spacing() const } } -/*! - \obsolete -*/ -void QLayout::setMargin(int margin) -{ - setContentsMargins(margin, margin, margin, margin); -} - void QLayout::setSpacing(int spacing) { if (QBoxLayout* boxlayout = qobject_cast<QBoxLayout*>(this)) { diff --git a/src/widgets/kernel/qlayout.h b/src/widgets/kernel/qlayout.h index 616f4e7164..35a04a35b2 100644 --- a/src/widgets/kernel/qlayout.h +++ b/src/widgets/kernel/qlayout.h @@ -63,7 +63,9 @@ class Q_WIDGETS_EXPORT QLayout : public QObject, public QLayoutItem Q_OBJECT Q_DECLARE_PRIVATE(QLayout) +#if QT_DEPRECATED_SINCE(5, 13) Q_PROPERTY(int margin READ margin WRITE setMargin) +#endif Q_PROPERTY(int spacing READ spacing WRITE setSpacing) Q_PROPERTY(SizeConstraint sizeConstraint READ sizeConstraint WRITE setSizeConstraint) public: @@ -81,10 +83,12 @@ public: QLayout(); ~QLayout(); +#if QT_DEPRECATED_SINCE(5, 13) int margin() const; - int spacing() const; - void setMargin(int); +#endif + + int spacing() const; void setSpacing(int); void setContentsMargins(int left, int top, int right, int bottom); diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index e1ce731418..51b2bf8b5f 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -4508,8 +4508,7 @@ void QWidget::setForegroundRole(QPalette::ColorRole role) style, depend on third party APIs to render the content of widgets, and these styles typically do not follow the palette. Because of this, assigning roles to a widget's palette is not guaranteed to change the - appearance of the widget. Instead, you may choose to apply a \l - styleSheet. + appearance of the widget. Instead, you may choose to apply a \l {styleSheet}. \warning Do not use this function in conjunction with \l{Qt Style Sheets}. When using style sheets, the palette of a widget can be customized using @@ -5313,7 +5312,7 @@ void QWidget::setGraphicsEffect(QGraphicsEffect *effect) return; if (d->graphicsEffect) { - d->invalidateBuffer(rect()); + d->invalidateBackingStore(rect()); delete d->graphicsEffect; d->graphicsEffect = 0; } @@ -7330,11 +7329,11 @@ void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove) if (renderToTexture) { QRegion updateRegion(q->geometry()); updateRegion += QRect(oldPos, olds); - q->parentWidget()->d_func()->invalidateBuffer(updateRegion); + q->parentWidget()->d_func()->invalidateBackingStore(updateRegion); } else if (isMove && !isResize) { moveRect(QRect(oldPos, olds), x - oldPos.x(), y - oldPos.y()); } else { - invalidateBuffer_resizeHelper(oldPos, olds); + invalidateBackingStore_resizeHelper(oldPos, olds); } } } @@ -8096,7 +8095,7 @@ void QWidgetPrivate::show_sys() QWidgetWindow *window = windowHandle(); if (q->testAttribute(Qt::WA_DontShowOnScreen)) { - invalidateBuffer(q->rect()); + invalidateBackingStore(q->rect()); q->setAttribute(Qt::WA_Mapped); // add our window the modal window list (native dialogs) if (window && q->isWindow() @@ -8139,7 +8138,7 @@ void QWidgetPrivate::show_sys() #ifndef QT_NO_CURSOR qt_qpa_set_cursor(q, false); // Needed in case cursor was set before show #endif - invalidateBuffer(q->rect()); + invalidateBackingStore(q->rect()); window->setNativeWindowVisibility(true); // Was the window moved by the Window system or QPlatformWindow::initialGeometry() ? if (window->isTopLevel()) { @@ -8253,12 +8252,12 @@ void QWidgetPrivate::hide_sys() QWidget *p = q->parentWidget(); if (p &&p->isVisible()) { if (renderToTexture) - p->d_func()->invalidateBuffer(q->geometry()); + p->d_func()->invalidateBackingStore(q->geometry()); else - invalidateBuffer(q->rect()); + invalidateBackingStore(q->rect()); } } else { - invalidateBuffer(q->rect()); + invalidateBackingStore(q->rect()); } if (window) @@ -8288,49 +8287,57 @@ void QWidgetPrivate::hide_sys() \endlist */ - void QWidget::setVisible(bool visible) { - if (visible) { // show - if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden)) - return; + if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden) == !visible) + return; - Q_D(QWidget); + // Remember that setVisible was called explicitly + setAttribute(Qt::WA_WState_ExplicitShowHide); + + Q_D(QWidget); + d->setVisible(visible); +} +// This method is called from QWidgetWindow in response to QWindow::setVisible, +// and should match the semantics of QWindow::setVisible. QWidget::setVisible on +// the other hand keeps track of WA_WState_ExplicitShowHide in addition. +void QWidgetPrivate::setVisible(bool visible) +{ + Q_Q(QWidget); + if (visible) { // show // Designer uses a trick to make grabWidget work without showing - if (!isWindow() && parentWidget() && parentWidget()->isVisible() - && !parentWidget()->testAttribute(Qt::WA_WState_Created)) - parentWidget()->window()->d_func()->createRecursively(); + if (!q->isWindow() && q->parentWidget() && q->parentWidget()->isVisible() + && !q->parentWidget()->testAttribute(Qt::WA_WState_Created)) + q->parentWidget()->window()->d_func()->createRecursively(); //create toplevels but not children of non-visible parents - QWidget *pw = parentWidget(); - if (!testAttribute(Qt::WA_WState_Created) - && (isWindow() || pw->testAttribute(Qt::WA_WState_Created))) { - create(); + QWidget *pw = q->parentWidget(); + if (!q->testAttribute(Qt::WA_WState_Created) + && (q->isWindow() || pw->testAttribute(Qt::WA_WState_Created))) { + q->create(); } - bool wasResized = testAttribute(Qt::WA_Resized); - Qt::WindowStates initialWindowState = windowState(); + bool wasResized = q->testAttribute(Qt::WA_Resized); + Qt::WindowStates initialWindowState = q->windowState(); // polish if necessary - ensurePolished(); + q->ensurePolished(); - // remember that show was called explicitly - setAttribute(Qt::WA_WState_ExplicitShowHide); // whether we need to inform the parent widget immediately - bool needUpdateGeometry = !isWindow() && testAttribute(Qt::WA_WState_Hidden); + bool needUpdateGeometry = !q->isWindow() && q->testAttribute(Qt::WA_WState_Hidden); // we are no longer hidden - setAttribute(Qt::WA_WState_Hidden, false); + q->setAttribute(Qt::WA_WState_Hidden, false); if (needUpdateGeometry) - d->updateGeometry_helper(true); + updateGeometry_helper(true); // activate our layout before we and our children become visible - if (d->layout) - d->layout->activate(); + if (layout) + layout->activate(); - if (!isWindow()) { - QWidget *parent = parentWidget(); + if (!q->isWindow()) { + QWidget *parent = q->parentWidget(); while (parent && parent->isVisible() && parent->d_func()->layout && !parent->data->in_show) { parent->d_func()->layout->activate(); if (parent->isWindow()) @@ -8343,30 +8350,28 @@ void QWidget::setVisible(bool visible) // adjust size if necessary if (!wasResized - && (isWindow() || !parentWidget()->d_func()->layout)) { - if (isWindow()) { - adjustSize(); - if (windowState() != initialWindowState) - setWindowState(initialWindowState); + && (q->isWindow() || !q->parentWidget()->d_func()->layout)) { + if (q->isWindow()) { + q->adjustSize(); + if (q->windowState() != initialWindowState) + q->setWindowState(initialWindowState); } else { - adjustSize(); + q->adjustSize(); } - setAttribute(Qt::WA_Resized, false); + q->setAttribute(Qt::WA_Resized, false); } - setAttribute(Qt::WA_KeyboardFocusChange, false); + q->setAttribute(Qt::WA_KeyboardFocusChange, false); - if (isWindow() || parentWidget()->isVisible()) { - d->show_helper(); + if (q->isWindow() || q->parentWidget()->isVisible()) { + show_helper(); - qApp->d_func()->sendSyntheticEnterLeave(this); + qApp->d_func()->sendSyntheticEnterLeave(q); } QEvent showToParentEvent(QEvent::ShowToParent); - QApplication::sendEvent(this, &showToParentEvent); + QApplication::sendEvent(q, &showToParentEvent); } else { // hide - if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden)) - return; #if 0 // Used to be included in Qt4 for Q_WS_WIN // reset WS_DISABLED style in a Blocked window if(isWindow() && testAttribute(Qt::WA_WState_Created) @@ -8377,33 +8382,30 @@ void QWidget::setVisible(bool visible) SetWindowLong(winId(), GWL_STYLE, dwStyle); } #endif - if (QApplicationPrivate::hidden_focus_widget == this) + if (QApplicationPrivate::hidden_focus_widget == q) QApplicationPrivate::hidden_focus_widget = 0; - Q_D(QWidget); - // hw: The test on getOpaqueRegion() needs to be more intelligent // currently it doesn't work if the widget is hidden (the region will // be clipped). The real check should be testing the cached region // (and dirty flag) directly. - if (!isWindow() && parentWidget()) // && !d->getOpaqueRegion().isEmpty()) - parentWidget()->d_func()->setDirtyOpaqueRegion(); + if (!q->isWindow() && q->parentWidget()) // && !d->getOpaqueRegion().isEmpty()) + q->parentWidget()->d_func()->setDirtyOpaqueRegion(); - setAttribute(Qt::WA_WState_Hidden); - setAttribute(Qt::WA_WState_ExplicitShowHide); - if (testAttribute(Qt::WA_WState_Created)) - d->hide_helper(); + q->setAttribute(Qt::WA_WState_Hidden); + if (q->testAttribute(Qt::WA_WState_Created)) + hide_helper(); // invalidate layout similar to updateGeometry() - if (!isWindow() && parentWidget()) { - if (parentWidget()->d_func()->layout) - parentWidget()->d_func()->layout->invalidate(); - else if (parentWidget()->isVisible()) - QApplication::postEvent(parentWidget(), new QEvent(QEvent::LayoutRequest)); + if (!q->isWindow() && q->parentWidget()) { + if (q->parentWidget()->d_func()->layout) + q->parentWidget()->d_func()->layout->invalidate(); + else if (q->parentWidget()->isVisible()) + QApplication::postEvent(q->parentWidget(), new QEvent(QEvent::LayoutRequest)); } QEvent hideToParentEvent(QEvent::HideToParent); - QApplication::sendEvent(this, &hideToParentEvent); + QApplication::sendEvent(q, &hideToParentEvent); } } @@ -11891,7 +11893,7 @@ void QWidget::raise() QRegion region(rect()); d->subtractOpaqueSiblings(region); - d->invalidateBuffer(region); + d->invalidateBackingStore(region); } if (testAttribute(Qt::WA_WState_Created)) d->raise_sys(); @@ -11911,7 +11913,7 @@ void QWidgetPrivate::raise_sys() } else if (renderToTexture) { if (QWidget *p = q->parentWidget()) { setDirtyOpaqueRegion(); - p->d_func()->invalidateBuffer(effectiveRectFor(q->geometry())); + p->d_func()->invalidateBackingStore(effectiveRectFor(q->geometry())); } } } @@ -11961,7 +11963,7 @@ void QWidgetPrivate::lower_sys() q->windowHandle()->lower(); } else if (QWidget *p = q->parentWidget()) { setDirtyOpaqueRegion(); - p->d_func()->invalidateBuffer(effectiveRectFor(q->geometry())); + p->d_func()->invalidateBackingStore(effectiveRectFor(q->geometry())); } } @@ -12005,7 +12007,7 @@ void QWidgetPrivate::stackUnder_sys(QWidget*) Q_Q(QWidget); if (QWidget *p = q->parentWidget()) { setDirtyOpaqueRegion(); - p->d_func()->invalidateBuffer(effectiveRectFor(q->geometry())); + p->d_func()->invalidateBackingStore(effectiveRectFor(q->geometry())); } } @@ -12447,7 +12449,7 @@ void QWidget::destroy(bool destroyWindow, bool destroySubWindows) d->aboutToDestroy(); if (!isWindow() && parentWidget()) - parentWidget()->d_func()->invalidateBuffer(d->effectiveRectFor(geometry())); + parentWidget()->d_func()->invalidateBackingStore(d->effectiveRectFor(geometry())); d->deactivateWidgetCleanup(); if ((windowType() == Qt::Popup) && qApp) diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h index ab5dc6bfba..797963b931 100644 --- a/src/widgets/kernel/qwidget_p.h +++ b/src/widgets/kernel/qwidget_p.h @@ -452,10 +452,11 @@ public: void scrollChildren(int dx, int dy); void moveRect(const QRect &, int dx, int dy); void scrollRect(const QRect &, int dx, int dy); - void invalidateBuffer_resizeHelper(const QPoint &oldPos, const QSize &oldSize); - // ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore). - void invalidateBuffer(const QRegion &); - void invalidateBuffer(const QRect &); + void invalidateBackingStore_resizeHelper(const QPoint &oldPos, const QSize &oldSize); + + template <class T> + void invalidateBackingStore(const T &); + QRegion overlappedRegion(const QRect &rect, bool breakAfterFirst = false) const; void syncBackingStore(); void syncBackingStore(const QRegion ®ion); @@ -484,6 +485,7 @@ public: void hide_sys(); void hide_helper(); void _q_showIfNotHidden(); + void setVisible(bool); void setEnabled_helper(bool); static void adjustFlags(Qt::WindowFlags &flags, QWidget *w = 0); @@ -606,6 +608,11 @@ public: return extra ? extra->nativeChildrenForced : false; } + inline QRect effectiveRectFor(const QRegion ®ion) const + { + return effectiveRectFor(region.boundingRect()); + } + inline QRect effectiveRectFor(const QRect &rect) const { #if QT_CONFIG(graphicseffect) diff --git a/src/widgets/kernel/qwidgetbackingstore.cpp b/src/widgets/kernel/qwidgetbackingstore.cpp index 69460bcd54..595beeaf47 100644 --- a/src/widgets/kernel/qwidgetbackingstore.cpp +++ b/src/widgets/kernel/qwidgetbackingstore.cpp @@ -501,6 +501,9 @@ void QWidgetBackingStore::sendUpdateRequest(QWidget *widget, UpdateTime updateTi } } +static inline QRect widgetRectFor(QWidget *, const QRect &r) { return r; } +static inline QRect widgetRectFor(QWidget *widget, const QRegion &) { return widget->rect(); } + /*! Marks the region of the widget as dirty (if not already marked as dirty) and posts an UpdateRequest event to the top-level widget (if not already posted). @@ -511,42 +514,44 @@ void QWidgetBackingStore::sendUpdateRequest(QWidget *widget, UpdateTime updateTi If the widget paints directly on screen, the event is sent to the widget instead of the top-level widget, and bufferState is completely ignored. - - ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore). */ -void QWidgetBackingStore::markDirty(const QRegion &rgn, QWidget *widget, - UpdateTime updateTime, BufferState bufferState) +template <class T> +void QWidgetBackingStore::markDirty(const T &r, QWidget *widget, UpdateTime updateTime, BufferState bufferState) { Q_ASSERT(tlw->d_func()->extra); Q_ASSERT(tlw->d_func()->extra->topextra); Q_ASSERT(!tlw->d_func()->extra->topextra->inTopLevelResize); Q_ASSERT(widget->isVisible() && widget->updatesEnabled()); Q_ASSERT(widget->window() == tlw); - Q_ASSERT(!rgn.isEmpty()); + Q_ASSERT(!r.isEmpty()); #if QT_CONFIG(graphicseffect) widget->d_func()->invalidateGraphicsEffectsRecursively(); -#endif // QT_CONFIG(graphicseffect) +#endif + + QRect widgetRect = widgetRectFor(widget, r); + + // --------------------------------------------------------------------------- if (widget->d_func()->paintOnScreen()) { if (widget->d_func()->dirty.isEmpty()) { - widget->d_func()->dirty = rgn; + widget->d_func()->dirty = r; sendUpdateRequest(widget, updateTime); return; - } else if (qt_region_strictContains(widget->d_func()->dirty, widget->rect())) { + } else if (qt_region_strictContains(widget->d_func()->dirty, widgetRect)) { if (updateTime == UpdateNow) sendUpdateRequest(widget, updateTime); - return; // Already dirty. + return; // Already dirty } const bool eventAlreadyPosted = !widget->d_func()->dirty.isEmpty(); - widget->d_func()->dirty += rgn; + widget->d_func()->dirty += r; if (!eventAlreadyPosted || updateTime == UpdateNow) sendUpdateRequest(widget, updateTime); return; } - const QPoint offset = widget->mapTo(tlw, QPoint()); + // --------------------------------------------------------------------------- if (QWidgetPrivate::get(widget)->renderToTexture) { if (!widget->d_func()->inDirtyList) @@ -556,133 +561,67 @@ void QWidgetBackingStore::markDirty(const QRegion &rgn, QWidget *widget, return; } - const QRect widgetRect = widget->d_func()->effectiveRectFor(widget->rect()); - if (qt_region_strictContains(dirty, widgetRect.translated(offset))) { + // --------------------------------------------------------------------------- + + QRect effectiveWidgetRect = widget->d_func()->effectiveRectFor(widgetRect); + const QPoint offset = widget->mapTo(tlw, QPoint()); + QRect translatedRect = effectiveWidgetRect.translated(offset); +#if QT_CONFIG(graphicseffect) + // Graphics effects may exceed window size, clamp + translatedRect = translatedRect.intersected(QRect(QPoint(), tlw->size())); +#endif + if (qt_region_strictContains(dirty, translatedRect)) { if (updateTime == UpdateNow) sendUpdateRequest(tlw, updateTime); - return; // Already dirty. + return; // Already dirty } + // --------------------------------------------------------------------------- + if (bufferState == BufferInvalid) { const bool eventAlreadyPosted = !dirty.isEmpty() || updateRequestSent; #if QT_CONFIG(graphicseffect) if (widget->d_func()->graphicsEffect) - dirty += widget->d_func()->effectiveRectFor(rgn.boundingRect()).translated(offset); + dirty += widget->d_func()->effectiveRectFor(r).translated(offset); else -#endif // QT_CONFIG(graphicseffect) - dirty += rgn.translated(offset); +#endif + dirty += r.translated(offset); + if (!eventAlreadyPosted || updateTime == UpdateNow) sendUpdateRequest(tlw, updateTime); return; } + // --------------------------------------------------------------------------- + if (dirtyWidgets.isEmpty()) { - addDirtyWidget(widget, rgn); + addDirtyWidget(widget, r); sendUpdateRequest(tlw, updateTime); return; } + // --------------------------------------------------------------------------- + if (widget->d_func()->inDirtyList) { - if (!qt_region_strictContains(widget->d_func()->dirty, widgetRect)) { + if (!qt_region_strictContains(widget->d_func()->dirty, effectiveWidgetRect)) { #if QT_CONFIG(graphicseffect) if (widget->d_func()->graphicsEffect) - widget->d_func()->dirty += widget->d_func()->effectiveRectFor(rgn.boundingRect()); + widget->d_func()->dirty += widget->d_func()->effectiveRectFor(r); else -#endif // QT_CONFIG(graphicseffect) - widget->d_func()->dirty += rgn; +#endif + widget->d_func()->dirty += r; } } else { - addDirtyWidget(widget, rgn); - } - - if (updateTime == UpdateNow) - sendUpdateRequest(tlw, updateTime); -} - -/*! - This function is equivalent to calling markDirty(QRegion(rect), ...), but - is more efficient as it eliminates QRegion operations/allocations and can - use the rect more precisely for additional cut-offs. - - ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore). -*/ -void QWidgetBackingStore::markDirty(const QRect &rect, QWidget *widget, - UpdateTime updateTime, BufferState bufferState) -{ - Q_ASSERT(tlw->d_func()->extra); - Q_ASSERT(tlw->d_func()->extra->topextra); - Q_ASSERT(!tlw->d_func()->extra->topextra->inTopLevelResize); - Q_ASSERT(widget->isVisible() && widget->updatesEnabled()); - Q_ASSERT(widget->window() == tlw); - Q_ASSERT(!rect.isEmpty()); - -#if QT_CONFIG(graphicseffect) - widget->d_func()->invalidateGraphicsEffectsRecursively(); -#endif // QT_CONFIG(graphicseffect) - - if (widget->d_func()->paintOnScreen()) { - if (widget->d_func()->dirty.isEmpty()) { - widget->d_func()->dirty = QRegion(rect); - sendUpdateRequest(widget, updateTime); - return; - } else if (qt_region_strictContains(widget->d_func()->dirty, rect)) { - if (updateTime == UpdateNow) - sendUpdateRequest(widget, updateTime); - return; // Already dirty. - } - - const bool eventAlreadyPosted = !widget->d_func()->dirty.isEmpty(); - widget->d_func()->dirty += rect; - if (!eventAlreadyPosted || updateTime == UpdateNow) - sendUpdateRequest(widget, updateTime); - return; - } - - if (QWidgetPrivate::get(widget)->renderToTexture) { - if (!widget->d_func()->inDirtyList) - addDirtyRenderToTextureWidget(widget); - if (!updateRequestSent || updateTime == UpdateNow) - sendUpdateRequest(tlw, updateTime); - return; + addDirtyWidget(widget, r); } - - const QRect widgetRect = widget->d_func()->effectiveRectFor(rect); - QRect translatedRect = widgetRect; - if (widget != tlw) - translatedRect.translate(widget->mapTo(tlw, QPoint())); - // Graphics effects may exceed window size, clamp. - translatedRect = translatedRect.intersected(QRect(QPoint(), tlw->size())); - if (qt_region_strictContains(dirty, translatedRect)) { - if (updateTime == UpdateNow) - sendUpdateRequest(tlw, updateTime); - return; // Already dirty - } - - if (bufferState == BufferInvalid) { - const bool eventAlreadyPosted = !dirty.isEmpty(); - dirty += translatedRect; - if (!eventAlreadyPosted || updateTime == UpdateNow) - sendUpdateRequest(tlw, updateTime); - return; - } - - if (dirtyWidgets.isEmpty()) { - addDirtyWidget(widget, rect); - sendUpdateRequest(tlw, updateTime); - return; - } - - if (widget->d_func()->inDirtyList) { - if (!qt_region_strictContains(widget->d_func()->dirty, widgetRect)) - widget->d_func()->dirty += widgetRect; - } else { - addDirtyWidget(widget, rect); - } + // --------------------------------------------------------------------------- if (updateTime == UpdateNow) sendUpdateRequest(tlw, updateTime); } +template void QWidgetBackingStore::markDirty<QRect>(const QRect &, QWidget *, UpdateTime, BufferState); +template void QWidgetBackingStore::markDirty<QRegion>(const QRegion &, QWidget *, UpdateTime, BufferState); /*! Marks the \a region of the \a widget as dirty on screen. The \a region will be copied from @@ -853,11 +792,11 @@ void QWidgetPrivate::moveRect(const QRect &rect, int dx, int dy) if (!extra || !extra->hasMask) { parentR -= newRect; } else { - // invalidateBuffer() excludes anything outside the mask + // invalidateBackingStore() excludes anything outside the mask parentR += newRect & clipR; } - pd->invalidateBuffer(parentR); - invalidateBuffer((newRect & clipR).translated(-data.crect.topLeft())); + pd->invalidateBackingStore(parentR); + invalidateBackingStore((newRect & clipR).translated(-data.crect.topLeft())); } else { QWidgetBackingStore *wbs = x->backingStoreTracker.data(); @@ -888,7 +827,7 @@ void QWidgetPrivate::moveRect(const QRect &rect, int dx, int dy) if (childUpdatesEnabled) { if (!overlappedExpose.isEmpty()) { overlappedExpose.translate(-data.crect.topLeft()); - invalidateBuffer(overlappedExpose); + invalidateBackingStore(overlappedExpose); } if (!childExpose.isEmpty()) { childExpose.translate(-data.crect.topLeft()); @@ -938,9 +877,9 @@ void QWidgetPrivate::scrollRect(const QRect &rect, int dx, int dy) if (!overlappedRegion(scrollRect.translated(data.crect.topLeft()), true).isEmpty()) { QRegion region(scrollRect); subtractOpaqueSiblings(region); - invalidateBuffer(region); + invalidateBackingStore(region); }else { - invalidateBuffer(scrollRect); + invalidateBackingStore(scrollRect); } } else { const QPoint toplevelOffset = q->mapTo(tlw, QPoint()); @@ -981,7 +920,7 @@ void QWidgetPrivate::scrollRect(const QRect &rect, int dx, int dy) return; if (!overlappedExpose.isEmpty()) - invalidateBuffer(overlappedExpose); + invalidateBackingStore(overlappedExpose); if (!childExpose.isEmpty()) { wbs->markDirty(childExpose, q); isScrolled = true; @@ -1465,26 +1404,11 @@ void QWidgetBackingStore::flush(QWidget *widget) dirtyOnScreenWidgets->clear(); } -static inline bool discardInvalidateBufferRequest(QWidget *widget, QTLWExtra *tlwExtra) -{ - Q_ASSERT(widget); - if (QApplication::closingDown()) - return true; - - if (!tlwExtra || tlwExtra->inTopLevelResize || !tlwExtra->backingStore) - return true; - - if (!widget->isVisible() || !widget->updatesEnabled()) - return true; - - return false; -} - /*! - Invalidates the buffer when the widget is resized. + Invalidates the backing store when the widget is resized. Static areas are never invalidated unless absolutely needed. */ -void QWidgetPrivate::invalidateBuffer_resizeHelper(const QPoint &oldPos, const QSize &oldSize) +void QWidgetPrivate::invalidateBackingStore_resizeHelper(const QPoint &oldPos, const QSize &oldSize) { Q_Q(QWidget); Q_ASSERT(!q->isWindow()); @@ -1509,10 +1433,10 @@ void QWidgetPrivate::invalidateBuffer_resizeHelper(const QPoint &oldPos, const Q if (hasStaticChildren) { QRegion dirty(newWidgetRect); dirty -= staticChildren; - invalidateBuffer(dirty); + invalidateBackingStore(dirty); } else { // Entire widget needs repaint. - invalidateBuffer(newWidgetRect); + invalidateBackingStore(newWidgetRect); } if (!parentAreaExposed) @@ -1524,14 +1448,14 @@ void QWidgetPrivate::invalidateBuffer_resizeHelper(const QPoint &oldPos, const Q parentExpose &= QRect(oldPos, oldSize); if (hasStaticChildren) parentExpose -= data.crect; // Offset is unchanged, safe to do this. - q->parentWidget()->d_func()->invalidateBuffer(parentExpose); + q->parentWidget()->d_func()->invalidateBackingStore(parentExpose); } else { if (hasStaticChildren && !graphicsEffect) { QRegion parentExpose(QRect(oldPos, oldSize)); parentExpose -= data.crect; // Offset is unchanged, safe to do this. - q->parentWidget()->d_func()->invalidateBuffer(parentExpose); + q->parentWidget()->d_func()->invalidateBackingStore(parentExpose); } else { - q->parentWidget()->d_func()->invalidateBuffer(effectiveRectFor(QRect(oldPos, oldSize))); + q->parentWidget()->d_func()->invalidateBackingStore(effectiveRectFor(QRect(oldPos, oldSize))); } } return; @@ -1552,7 +1476,7 @@ void QWidgetPrivate::invalidateBuffer_resizeHelper(const QPoint &oldPos, const Q if (!sizeDecreased || !oldWidgetRect.contains(newWidgetRect)) { QRegion newVisible(newWidgetRect); newVisible -= oldWidgetRect; - invalidateBuffer(newVisible); + invalidateBackingStore(newVisible); } if (!parentAreaExposed) @@ -1564,74 +1488,56 @@ void QWidgetPrivate::invalidateBuffer_resizeHelper(const QPoint &oldPos, const Q QRegion parentExpose(oldRect); parentExpose &= extra->mask.translated(oldPos); parentExpose -= (extra->mask.translated(data.crect.topLeft()) & data.crect); - q->parentWidget()->d_func()->invalidateBuffer(parentExpose); + q->parentWidget()->d_func()->invalidateBackingStore(parentExpose); } else { QRegion parentExpose(oldRect); parentExpose -= data.crect; - q->parentWidget()->d_func()->invalidateBuffer(parentExpose); + q->parentWidget()->d_func()->invalidateBackingStore(parentExpose); } } /*! - Invalidates the \a rgn (in widget's coordinates) of the backing store, i.e. - all widgets intersecting with the region will be repainted when the backing store - is synced. - - ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore). + Invalidates the \a r (in widget's coordinates) of the backing store, i.e. + all widgets intersecting with the region will be repainted when the backing + store is synced. */ -void QWidgetPrivate::invalidateBuffer(const QRegion &rgn) +template <class T> +void QWidgetPrivate::invalidateBackingStore(const T &r) { - Q_Q(QWidget); - - QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData(); - if (discardInvalidateBufferRequest(q, tlwExtra) || rgn.isEmpty()) + if (r.isEmpty()) return; - QRegion wrgn(rgn); - wrgn &= clipRect(); - if (!graphicsEffect && extra && extra->hasMask) - wrgn &= extra->mask; - if (wrgn.isEmpty()) + if (QApplication::closingDown()) return; - tlwExtra->backingStoreTracker->markDirty(wrgn, q, - QWidgetBackingStore::UpdateLater, QWidgetBackingStore::BufferInvalid); -} - -/*! - This function is equivalent to calling invalidateBuffer(QRegion(rect), ...), but - is more efficient as it eliminates QRegion operations/allocations and can - use the rect more precisely for additional cut-offs. - - ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore). -*/ -void QWidgetPrivate::invalidateBuffer(const QRect &rect) -{ Q_Q(QWidget); - - QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData(); - if (discardInvalidateBufferRequest(q, tlwExtra) || rect.isEmpty()) + if (!q->isVisible() || !q->updatesEnabled()) return; - QRect wRect(rect); - wRect &= clipRect(); - if (wRect.isEmpty()) + QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData(); + if (!tlwExtra || tlwExtra->inTopLevelResize || !tlwExtra->backingStore) return; - if (graphicsEffect || !extra || !extra->hasMask) { - tlwExtra->backingStoreTracker->markDirty(wRect, q, - QWidgetBackingStore::UpdateLater, QWidgetBackingStore::BufferInvalid); + T clipped(r); + clipped &= clipRect(); + if (clipped.isEmpty()) return; - } - QRegion wRgn(extra->mask); - wRgn &= wRect; - if (wRgn.isEmpty()) - return; + if (!graphicsEffect && extra && extra->hasMask) { + QRegion masked(extra->mask); + masked &= clipped; + if (masked.isEmpty()) + return; - tlwExtra->backingStoreTracker->markDirty(wRgn, q, + tlwExtra->backingStoreTracker->markDirty(masked, q, QWidgetBackingStore::UpdateLater, QWidgetBackingStore::BufferInvalid); + } else { + tlwExtra->backingStoreTracker->markDirty(clipped, q, + QWidgetBackingStore::UpdateLater, QWidgetBackingStore::BufferInvalid); + } } +// Needed by tst_QWidget +template Q_AUTOTEST_EXPORT void QWidgetPrivate::invalidateBackingStore<QRect>(const QRect &r); void QWidgetPrivate::repaint_sys(const QRegion &rgn) { diff --git a/src/widgets/kernel/qwidgetbackingstore_p.h b/src/widgets/kernel/qwidgetbackingstore_p.h index a1846da44e..e7a2bca33a 100644 --- a/src/widgets/kernel/qwidgetbackingstore_p.h +++ b/src/widgets/kernel/qwidgetbackingstore_p.h @@ -118,10 +118,8 @@ public: return !(dirtyWidgets.isEmpty() && dirty.isEmpty() && dirtyRenderToTextureWidgets.isEmpty()); } - // ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore). - void markDirty(const QRegion &rgn, QWidget *widget, UpdateTime updateTime = UpdateLater, - BufferState bufferState = BufferValid); - void markDirty(const QRect &rect, QWidget *widget, UpdateTime updateTime = UpdateLater, + template <class T> + void markDirty(const T &r, QWidget *widget, UpdateTime updateTime = UpdateLater, BufferState bufferState = BufferValid); private: diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp index 991a05fa02..e9b749d7c2 100644 --- a/src/widgets/kernel/qwidgetwindow.cpp +++ b/src/widgets/kernel/qwidgetwindow.cpp @@ -73,7 +73,7 @@ public: { Q_Q(QWidgetWindow); if (QWidget *widget = q->widget()) - widget->setVisible(visible); + QWidgetPrivate::get(widget)->setVisible(visible); else QWindowPrivate::setVisible(visible); } diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 1980dc47a9..56bc329827 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -846,8 +846,6 @@ static void drawArrow(const QStyle *style, const QStyleOptionToolButton *toolbut } #endif // QT_CONFIG(toolbutton) -#if QT_CONFIG(itemviews) - static QSizeF viewItemTextLayout(QTextLayout &textLayout, int lineWidth) { qreal height = 0; @@ -866,6 +864,80 @@ static QSizeF viewItemTextLayout(QTextLayout &textLayout, int lineWidth) return QSizeF(widthUsed, height); } +QString QCommonStylePrivate::calculateElidedText(const QString &text, const QTextOption &textOption, + const QFont &font, const QRect &textRect, const Qt::Alignment valign, + Qt::TextElideMode textElideMode, int flags, + bool lastVisibleLineShouldBeElided, QPointF *paintStartPosition) const +{ + QTextLayout textLayout(text, font); + textLayout.setTextOption(textOption); + + viewItemTextLayout(textLayout, textRect.width()); + + const QRectF boundingRect = textLayout.boundingRect(); + // don't care about LTR/RTL here, only need the height + const QRect layoutRect = QStyle::alignedRect(Qt::LayoutDirectionAuto, valign, + boundingRect.size().toSize(), textRect); + + if (paintStartPosition) + *paintStartPosition = QPointF(textRect.x(), layoutRect.top()); + + QString ret; + qreal height = 0; + const int lineCount = textLayout.lineCount(); + for (int i = 0; i < lineCount; ++i) { + const QTextLine line = textLayout.lineAt(i); + height += line.height(); + + // above visible rect + if (height + layoutRect.top() <= textRect.top()) { + if (paintStartPosition) + paintStartPosition->ry() += line.height(); + continue; + } + + const int start = line.textStart(); + const int length = line.textLength(); + const bool drawElided = line.naturalTextWidth() > textRect.width(); + bool elideLastVisibleLine = false; + if (!drawElided && i + 1 < lineCount && lastVisibleLineShouldBeElided) { + const QTextLine nextLine = textLayout.lineAt(i + 1); + const int nextHeight = height + nextLine.height() / 2; + // elide when less than the next half line is visible + if (nextHeight + layoutRect.top() > textRect.height() + textRect.top()) + elideLastVisibleLine = true; + } + + QString text = textLayout.text().mid(start, length); + if (drawElided || elideLastVisibleLine) { + if (elideLastVisibleLine) { + if (text.endsWith(QChar::LineSeparator)) + text.chop(1); + text += QChar(0x2026); + } + const QStackTextEngine engine(text, font); + ret += engine.elidedText(textElideMode, textRect.width(), flags); + + // no newline for the last line (last visible or real) + // sometimes drawElided is true but no eliding is done so the text ends + // with QChar::LineSeparator - don't add another one. This happened with + // arabic text in the testcase for QTBUG-72805 + if (i < lineCount - 1 && + !ret.endsWith(QChar::LineSeparator)) + ret += QChar::LineSeparator; + } else { + ret += text; + } + + // below visible text, can stop + if (height + layoutRect.top() >= textRect.bottom()) + break; + } + return ret; +} + +#if QT_CONFIG(itemviews) + QSize QCommonStylePrivate::viewItemSize(const QStyleOptionViewItem *option, int role) const { const QWidget *widget = option->widget; @@ -938,67 +1010,15 @@ void QCommonStylePrivate::viewItemDrawText(QPainter *p, const QStyleOptionViewIt textOption.setWrapMode(wrapText ? QTextOption::WordWrap : QTextOption::ManualWrap); textOption.setTextDirection(option->direction); textOption.setAlignment(QStyle::visualAlignment(option->direction, option->displayAlignment)); - QTextLayout textLayout(option->text, option->font); - textLayout.setTextOption(textOption); - - viewItemTextLayout(textLayout, textRect.width()); - - const QRectF boundingRect = textLayout.boundingRect(); - const QRect layoutRect = QStyle::alignedRect(option->direction, option->displayAlignment, - boundingRect.size().toSize(), textRect); - QPointF paintPosition = QPointF(textRect.x(), layoutRect.top()); - - QString newText; - qreal height = 0; - const int lineCount = textLayout.lineCount(); - for (int i = 0; i < lineCount; ++i) { - const QTextLine line = textLayout.lineAt(i); - height += line.height(); - - // above visible rect - if (height + layoutRect.top() <= textRect.top()) { - paintPosition.ry() += line.height(); - continue; - } - - const int start = line.textStart(); - const int length = line.textLength(); - - const bool drawElided = line.naturalTextWidth() > textRect.width(); - bool elideLastVisibleLine = false; - if (!drawElided && i + 1 < lineCount) { - const QTextLine nextLine = textLayout.lineAt(i + 1); - const int nextHeight = height + nextLine.height() / 2; - // elide when less than the next half line is visible - if (nextHeight + layoutRect.top() > textRect.height() + textRect.top()) - elideLastVisibleLine = true; - } - - QString text = textLayout.text().mid(start, length); - if (drawElided || elideLastVisibleLine) { - if (elideLastVisibleLine) { - if (text.endsWith(QChar::LineSeparator)) - text.chop(1); - text += QChar(0x2026); - } - const QStackTextEngine engine(text, option->font); - newText += engine.elidedText(option->textElideMode, textRect.width()); - // sometimes drawElided is true but no eliding is done so the text ends - // with QChar::LineSeparator - don't add another one. This happened with - // arabic text in the testcase for QTBUG-72805 - if (i < lineCount - 1 && - !newText.endsWith(QChar::LineSeparator)) - newText += QChar::LineSeparator; - } else { - newText += text; - } - // below visible text, can stop - if (height + layoutRect.top() >= textRect.bottom()) - break; - } + QPointF paintPosition; + const QString newText = calculateElidedText(option->text, textOption, + option->font, textRect, option->displayAlignment, + option->textElideMode, 0, + true, &paintPosition); - textLayout.setText(newText); + QTextLayout textLayout(newText, option->font); + textLayout.setTextOption(textOption); viewItemTextLayout(textLayout, textRect.width()); textLayout.draw(p, paintPosition); } @@ -1140,6 +1160,25 @@ void QCommonStylePrivate::viewItemLayout(const QStyleOptionViewItem *opt, QRect } #endif // QT_CONFIG(itemviews) +#if QT_CONFIG(toolbutton) +QString QCommonStylePrivate::toolButtonElideText(const QStyleOptionToolButton *option, + const QRect &textRect, int flags) const +{ + if (option->fontMetrics.horizontalAdvance(option->text) <= textRect.width()) + return option->text; + + QString text = option->text; + text.replace('\n', QChar::LineSeparator); + QTextOption textOption; + textOption.setWrapMode(QTextOption::ManualWrap); + textOption.setTextDirection(option->direction); + + return calculateElidedText(text, textOption, + option->font, textRect, Qt::AlignTop, + Qt::ElideMiddle, flags, + false, nullptr); +} +#endif // QT_CONFIG(toolbutton) #if QT_CONFIG(tabbar) /*! \internal @@ -1689,8 +1728,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, alignment |= Qt::AlignLeft | Qt::AlignVCenter; } tr.translate(shiftX, shiftY); - const QString text = toolbutton->fontMetrics.elidedText(toolbutton->text, Qt::ElideMiddle, - tr.width(), alignment); + const QString text = d->toolButtonElideText(toolbutton, tr, alignment); proxy()->drawItemText(p, QStyle::visualRect(opt->direction, rect, tr), alignment, toolbutton->palette, toolbutton->state & State_Enabled, text, QPalette::ButtonText); @@ -3102,13 +3140,17 @@ QRect QCommonStyle::subElementRect(SubElement sr, const QStyleOption *opt, ///we need to access the widget here because the style option doesn't //have all the information we need (ie. the layout's margin) const QToolBar *tb = qobject_cast<const QToolBar*>(widget); - const int margin = tb && tb->layout() ? tb->layout()->margin() : 2; + const QMargins margins = tb && tb->layout() ? tb->layout()->contentsMargins() : QMargins(2, 2, 2, 2); const int handleExtent = proxy()->pixelMetric(QStyle::PM_ToolBarHandleExtent, opt, tb); if (tbopt->state & QStyle::State_Horizontal) { - r = QRect(margin, margin, handleExtent, tbopt->rect.height() - 2*margin); + r = QRect(margins.left(), margins.top(), + handleExtent, + tbopt->rect.height() - (margins.top() + margins.bottom())); r = QStyle::visualRect(tbopt->direction, tbopt->rect, r); } else { - r = QRect(margin, margin, tbopt->rect.width() - 2*margin, handleExtent); + r = QRect(margins.left(), margins.top(), + tbopt->rect.width() - (margins.left() + margins.right()), + handleExtent); } } } diff --git a/src/widgets/styles/qcommonstyle_p.h b/src/widgets/styles/qcommonstyle_p.h index b347c8563a..296f89ce5f 100644 --- a/src/widgets/styles/qcommonstyle_p.h +++ b/src/widgets/styles/qcommonstyle_p.h @@ -62,6 +62,7 @@ QT_BEGIN_NAMESPACE // class QStringList; +class QTextOption; // Private class class Q_WIDGETS_EXPORT QCommonStylePrivate : public QStylePrivate @@ -85,6 +86,10 @@ public: #endif } + QString calculateElidedText(const QString &text, const QTextOption &textOption, + const QFont &font, const QRect &textRect, const Qt::Alignment valign, + Qt::TextElideMode textElideMode, int flags, + bool lastVisibleLineShouldBeElided, QPointF *paintStartPosition) const; #if QT_CONFIG(itemviews) void viewItemDrawText(QPainter *p, const QStyleOptionViewItem *option, const QRect &rect) const; void viewItemLayout(const QStyleOptionViewItem *opt, QRect *checkRect, @@ -110,6 +115,11 @@ public: && option.viewItemPosition == cachedOption->viewItemPosition); } #endif +#if QT_CONFIG(toolbutton) + QString toolButtonElideText(const QStyleOptionToolButton *toolbutton, + const QRect &textRect, int flags) const; +#endif + mutable QIcon tabBarcloseButtonIcon; #if QT_CONFIG(tabbar) void tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect, QRect *pixmapRect) const; diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index c0f0321fce..1ad67f248a 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -3708,21 +3708,17 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q QRenderRule subSubRule = renderRule(w, opt, PseudoElement_MenuCheckMark); QStyleOptionMenuItem newMi = mi; newMi.rect = positionRect(w, subRule, subSubRule, PseudoElement_MenuCheckMark, opt->rect, opt->direction); - checkableOffset = newMi.rect.width(); + // align with icons if there are some + checkableOffset = std::max(m->maxIconWidth, newMi.rect.width()); if (subSubRule.hasDrawable() || checked) drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, w); } - int iconOffset = 0; if (!mi.icon.isNull()) { QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal; if (act && !dis) mode = QIcon::Active; - QPixmap pixmap; - if (checked) - pixmap = mi.icon.pixmap(pixelMetric(PM_SmallIconSize), mode, QIcon::On); - else - pixmap = mi.icon.pixmap(pixelMetric(PM_SmallIconSize), mode); + const QPixmap pixmap(mi.icon.pixmap(pixelMetric(PM_SmallIconSize), mode, checked ? QIcon::On : QIcon::Off)); const int pixw = pixmap.width() / pixmap.devicePixelRatio(); const int pixh = pixmap.height() / pixmap.devicePixelRatio(); QRenderRule iconRule = renderRule(w, opt, PseudoElement_MenuIcon); @@ -3741,15 +3737,20 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q QRect pmr(0, 0, pixw, pixh); pmr.moveCenter(iconRect.center()); p->drawPixmap(pmr.topLeft(), pixmap); - iconOffset = iconRule.geo->width; } + int textOffset = 0; + // padding overrules it all + if (!subRule.hasBox() || subRule.box()->paddings[LeftEdge] == 0) { + textOffset = checkableOffset; + if (!m->icon.isNull() || !checkable) + textOffset += m->maxIconWidth; + } QRect textRect = subRule.contentsRect(opt->rect); - if (opt->direction == Qt::LeftToRight) - textRect.setLeft(textRect.left() + checkableOffset + iconOffset); - else - textRect.setRight(textRect.right() - checkableOffset - iconOffset); + textRect.setLeft(textRect.left() + textOffset); textRect.setWidth(textRect.width() - mi.tabWidth); + const QRect vTextRect = visualRect(opt->direction, m->rect, textRect); + QStringRef s(&mi.text); p->setPen(mi.palette.buttonText().color()); if (!s.isEmpty()) { @@ -3763,7 +3764,7 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q p->drawText(vShortcutRect, text_flags, s.mid(t + 1).toString()); s = s.left(t); } - p->drawText(textRect, text_flags, s.left(t).toString()); + p->drawText(vTextRect, text_flags, s.left(t).toString()); } if (mi.menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow @@ -5093,10 +5094,11 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op if (mi->text.contains(QLatin1Char('\t'))) sz.rwidth() += 12; //as in QCommonStyle bool checkable = mi->checkType != QStyleOptionMenuItem::NotCheckable; + int checkableWidth = 0; if (checkable) { QRenderRule subSubRule = renderRule(w, opt, PseudoElement_MenuCheckMark); QRect checkmarkRect = positionRect(w, subRule, subSubRule, PseudoElement_MenuCheckMark, opt->rect, opt->direction); - sz.rwidth() += checkmarkRect.width(); + checkableWidth = std::max(mi->maxIconWidth, checkmarkRect.width()); } if (!mi->icon.isNull()) { QPixmap pixmap = mi->icon.pixmap(pixelMetric(PM_SmallIconSize)); @@ -5107,6 +5109,12 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op const QRect r = fm.boundingRect(QRect(), Qt::TextSingleLine | Qt::TextShowMnemonic, mi->text); sz = sz.expandedTo(r.size()); } + // padding overrules it all + if (!subRule.hasBox() || subRule.box()->paddings[LeftEdge] == 0) { + sz.rwidth() += checkableWidth; + if (!mi->icon.isNull() || !checkable) + sz.rwidth() += mi->maxIconWidth; + } return subRule.boxSize(subRule.adjustSize(sz)); } } diff --git a/src/widgets/util/qsystemtrayicon.cpp b/src/widgets/util/qsystemtrayicon.cpp index d15f5e5955..a38a50d3df 100644 --- a/src/widgets/util/qsystemtrayicon.cpp +++ b/src/widgets/util/qsystemtrayicon.cpp @@ -574,7 +574,7 @@ QBalloonTip::QBalloonTip(const QIcon &icon, const QString &title, layout->addWidget(msgLabel, 1, 0, 1, 3); #endif layout->setSizeConstraint(QLayout::SetFixedSize); - layout->setMargin(3); + layout->setContentsMargins(3, 3, 3, 3); setLayout(layout); QPalette pal = palette(); diff --git a/src/widgets/widgets/qabstractscrollarea.cpp b/src/widgets/widgets/qabstractscrollarea.cpp index b378884275..5ea8330db2 100644 --- a/src/widgets/widgets/qabstractscrollarea.cpp +++ b/src/widgets/widgets/qabstractscrollarea.cpp @@ -185,7 +185,7 @@ QAbstractScrollAreaScrollBarContainer::QAbstractScrollAreaScrollBarContainer(Qt: orientation(orientation) { setLayout(layout); - layout->setMargin(0); + layout->setContentsMargins(QMargins()); layout->setSpacing(0); layout->addWidget(scrollBar); layout->setSizeConstraint(QLayout::SetMaximumSize); diff --git a/src/widgets/widgets/qcalendarwidget.cpp b/src/widgets/widgets/qcalendarwidget.cpp index 5649243d1d..47c5267c73 100644 --- a/src/widgets/widgets/qcalendarwidget.cpp +++ b/src/widgets/widgets/qcalendarwidget.cpp @@ -1778,7 +1778,7 @@ void QCalendarWidgetPrivate::createNavigationBar(QWidget *widget) spaceHolder = new QSpacerItem(0,0); QHBoxLayout *headerLayout = new QHBoxLayout; - headerLayout->setMargin(0); + headerLayout->setContentsMargins(QMargins()); headerLayout->setSpacing(0); headerLayout->addWidget(prevMonth); headerLayout->insertStretch(headerLayout->count()); @@ -2101,7 +2101,7 @@ QCalendarWidget::QCalendarWidget(QWidget *parent) setBackgroundRole(QPalette::Window); QVBoxLayout *layoutV = new QVBoxLayout(this); - layoutV->setMargin(0); + layoutV->setContentsMargins(QMargins()); d->m_model = new QCalendarModel(this); QTextCharFormat fmt; fmt.setForeground(QBrush(Qt::red)); @@ -2148,7 +2148,7 @@ QCalendarWidget::QCalendarWidget(QWidget *parent) connect(d->yearEdit, SIGNAL(editingFinished()), this, SLOT(_q_yearEditingFinished())); - layoutV->setMargin(0); + layoutV->setContentsMargins(QMargins()); layoutV->setSpacing(0); layoutV->addWidget(d->navBarBackground); layoutV->addWidget(d->m_view); @@ -3064,19 +3064,22 @@ bool QCalendarWidget::eventFilter(QObject *watched, QEvent *event) { Q_D(QCalendarWidget); if (event->type() == QEvent::MouseButtonPress && d->yearEdit->hasFocus()) { + // We can get filtered press events that were intended for Qt Virtual Keyboard's + // input panel (QQuickView), so we have to make sure that the window is indeed a QWidget - no static_cast. + // In addition, as we have a event filter on the whole application we first make sure that the top level widget + // of both this and the watched widget are the same to decide if we should finish the year edition. QWidget *tlw = window(); - QWidget *widget = static_cast<QWidget*>(watched); - //as we have a event filter on the whole application we first make sure that the top level widget - //of both this and the watched widget are the same to decide if we should finish the year edition. - if (widget->window() == tlw) { - QPoint mousePos = widget->mapTo(tlw, static_cast<QMouseEvent *>(event)->pos()); - QRect geom = QRect(d->yearEdit->mapTo(tlw, QPoint(0, 0)), d->yearEdit->size()); - if (!geom.contains(mousePos)) { - event->accept(); - d->_q_yearEditingFinished(); - setFocus(); - return true; - } + QWidget *widget = qobject_cast<QWidget *>(watched); + if (!widget || widget->window() != tlw) + return QWidget::eventFilter(watched, event); + + QPoint mousePos = widget->mapTo(tlw, static_cast<QMouseEvent *>(event)->pos()); + QRect geom = QRect(d->yearEdit->mapTo(tlw, QPoint(0, 0)), d->yearEdit->size()); + if (!geom.contains(mousePos)) { + event->accept(); + d->_q_yearEditingFinished(); + setFocus(); + return true; } } return QWidget::eventFilter(watched, event); diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 2f67a9202c..1ad43fffb4 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -472,7 +472,7 @@ QComboBoxPrivateContainer::QComboBoxPrivateContainer(QAbstractItemView *itemView // we need a vertical layout QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom, this); layout->setSpacing(0); - layout->setMargin(0); + layout->setContentsMargins(QMargins()); // set item view setItemView(itemView); @@ -895,14 +895,21 @@ QStyleOptionComboBox QComboBoxPrivateContainer::comboStyleOption() const currentIndex was reset. */ +#if QT_DEPRECATED_SINCE(5, 13) /*! \fn void QComboBox::currentIndexChanged(const QString &text) \since 4.1 + \obsolete + + Use currentTextChanged(const QString &) or currentIndexChanged(int) + instead. + This signal is sent whenever the currentIndex in the combobox changes either through user interaction or programmatically. The item's \a text is passed. */ +#endif /*! \fn void QComboBox::currentTextChanged(const QString &text) @@ -1375,7 +1382,9 @@ void QComboBoxPrivate::_q_emitCurrentIndexChanged(const QModelIndex &index) Q_Q(QComboBox); const QString text = itemText(index); emit q->currentIndexChanged(index.row()); +#if QT_DEPRECATED_SINCE(5, 13) emit q->currentIndexChanged(text); +#endif // signal lineEdit.textChanged already connected to signal currentTextChanged, so don't emit double here if (!lineEdit) emit q->currentTextChanged(text); @@ -1483,6 +1492,7 @@ int QComboBox::maxCount() const } #if QT_CONFIG(completer) +#if QT_DEPRECATED_SINCE(5, 13) /*! \property QComboBox::autoCompletion @@ -1576,6 +1586,7 @@ void QComboBox::setAutoCompletionCaseSensitivity(Qt::CaseSensitivity sensitivity if (d->lineEdit && d->lineEdit->completer()) d->lineEdit->completer()->setCaseSensitivity(sensitivity); } +#endif // QT_DEPRECATED_SINCE(5, 13) #endif // QT_CONFIG(completer) diff --git a/src/widgets/widgets/qcombobox.h b/src/widgets/widgets/qcombobox.h index 671c883584..64fbebb3c5 100644 --- a/src/widgets/widgets/qcombobox.h +++ b/src/widgets/widgets/qcombobox.h @@ -73,8 +73,10 @@ class Q_WIDGETS_EXPORT QComboBox : public QWidget Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize) #if QT_CONFIG(completer) +#if QT_DEPRECATED_SINCE(5, 13) Q_PROPERTY(bool autoCompletion READ autoCompletion WRITE setAutoCompletion DESIGNABLE false) Q_PROPERTY(Qt::CaseSensitivity autoCompletionCaseSensitivity READ autoCompletionCaseSensitivity WRITE setAutoCompletionCaseSensitivity DESIGNABLE false) +#endif #endif // QT_CONFIG(completer) Q_PROPERTY(bool duplicatesEnabled READ duplicatesEnabled WRITE setDuplicatesEnabled) @@ -93,12 +95,14 @@ public: int maxCount() const; #if QT_CONFIG(completer) +#if QT_DEPRECATED_SINCE(5, 13) bool autoCompletion() const; void setAutoCompletion(bool enable); Qt::CaseSensitivity autoCompletionCaseSensitivity() const; void setAutoCompletionCaseSensitivity(Qt::CaseSensitivity sensitivity); #endif +#endif bool duplicatesEnabled() const; void setDuplicatesEnabled(bool enable); @@ -220,7 +224,10 @@ Q_SIGNALS: void highlighted(int index); void highlighted(const QString &); void currentIndexChanged(int index); +#if QT_DEPRECATED_SINCE(5, 13) + QT_DEPRECATED_X("Use currentTextChanged() instead") void currentIndexChanged(const QString &); +#endif void currentTextChanged(const QString &); protected: diff --git a/src/widgets/widgets/qdatetimeedit.cpp b/src/widgets/widgets/qdatetimeedit.cpp index c66400f423..4dda01f0c7 100644 --- a/src/widgets/widgets/qdatetimeedit.cpp +++ b/src/widgets/widgets/qdatetimeedit.cpp @@ -2598,7 +2598,7 @@ void QCalendarPopup::setCalendarWidget(QCalendarWidget *cw) QVBoxLayout *widgetLayout = qobject_cast<QVBoxLayout*>(layout()); if (!widgetLayout) { widgetLayout = new QVBoxLayout(this); - widgetLayout->setMargin(0); + widgetLayout->setContentsMargins(QMargins()); widgetLayout->setSpacing(0); } delete calendar.data(); diff --git a/src/widgets/widgets/qfontcombobox.cpp b/src/widgets/widgets/qfontcombobox.cpp index 957a464b71..4a99b0f962 100644 --- a/src/widgets/widgets/qfontcombobox.cpp +++ b/src/widgets/widgets/qfontcombobox.cpp @@ -236,9 +236,10 @@ void QFontFamilyDelegate::paint(QPainter *painter, if (QFontDatabase().isSmoothlyScalable(text)) { icon = &truetype; } - QSize actualSize = icon->actualSize(r.size()); - - icon->paint(painter, r, Qt::AlignLeft|Qt::AlignVCenter); + const QSize actualSize = icon->actualSize(r.size()); + const QRect iconRect = QStyle::alignedRect(option.direction, option.displayAlignment, + actualSize, r); + icon->paint(painter, iconRect, Qt::AlignLeft|Qt::AlignVCenter); if (option.direction == Qt::RightToLeft) r.setRight(r.right() - actualSize.width() - 4); else @@ -247,6 +248,7 @@ void QFontFamilyDelegate::paint(QPainter *painter, QFont old = painter->font(); painter->setFont(font); + const Qt::Alignment textAlign = QStyle::visualAlignment(option.direction, option.displayAlignment); // If the ascent of the font is larger than the height of the rect, // we will clip the text, so it's better to align the tight bounding rect in this case // This is specifically for fonts where the ascent is very large compared to @@ -254,9 +256,11 @@ void QFontFamilyDelegate::paint(QPainter *painter, QFontMetricsF fontMetrics(font); if (fontMetrics.ascent() > r.height()) { QRectF tbr = fontMetrics.tightBoundingRect(text); - painter->drawText(r.x(), r.y() + (r.height() + tbr.height()) / 2.0, text); + QRect textRect(r); + textRect.setHeight(textRect.height() + (r.height() - tbr.height())); + painter->drawText(textRect, Qt::AlignBottom|Qt::TextSingleLine|textAlign, text); } else { - painter->drawText(r, Qt::AlignVCenter|Qt::AlignLeading|Qt::TextSingleLine, text); + painter->drawText(r, Qt::AlignVCenter|Qt::TextSingleLine|textAlign, text); } if (writingSystem != QFontDatabase::Any) @@ -270,7 +274,7 @@ void QFontFamilyDelegate::paint(QPainter *painter, r.setRight(r.right() - w); else r.setLeft(r.left() + w); - painter->drawText(r, Qt::AlignVCenter|Qt::AlignLeading|Qt::TextSingleLine, sample); + painter->drawText(r, Qt::AlignVCenter|Qt::TextSingleLine|textAlign, sample); } painter->setFont(old); diff --git a/src/widgets/widgets/qmdisubwindow.cpp b/src/widgets/widgets/qmdisubwindow.cpp index c7e0603309..e25bc6de7a 100644 --- a/src/widgets/widgets/qmdisubwindow.cpp +++ b/src/widgets/widgets/qmdisubwindow.cpp @@ -2268,7 +2268,7 @@ QMdiSubWindow::QMdiSubWindow(QWidget *parent, Qt::WindowFlags flags) setMouseTracking(true); setLayout(new QVBoxLayout); setFocusPolicy(Qt::StrongFocus); - layout()->setMargin(0); + layout()->setContentsMargins(QMargins()); d->updateGeometryConstraints(); setAttribute(Qt::WA_Resized, false); d->titleBarPalette = d->desktopPalette(); diff --git a/src/widgets/widgets/qmenu_p.h b/src/widgets/widgets/qmenu_p.h index 3e1aa2f738..12521e7a36 100644 --- a/src/widgets/widgets/qmenu_p.h +++ b/src/widgets/widgets/qmenu_p.h @@ -95,6 +95,12 @@ static inline int &rperp(Qt::Orientation o, QPoint &pos) static inline int &rperp(Qt::Orientation o, QSize &size) { return o == Qt::Vertical ? size.rwidth() : size.rheight(); } +static inline int pick(Qt::Orientation o, const QMargins &m) +{ return o == Qt::Horizontal ? (m.left() + m.right()) : (m.top() + m.bottom()); } + +static inline int perp(Qt::Orientation o, const QMargins &m) +{ return o == Qt::Vertical ? (m.left() + m.right()) : (m.top() + m.bottom()); } + class QTornOffMenu; class QEventLoop; diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp index 0b79a990a9..363422ac74 100644 --- a/src/widgets/widgets/qplaintextedit.cpp +++ b/src/widgets/widgets/qplaintextedit.cpp @@ -312,10 +312,11 @@ void QPlainTextDocumentLayout::documentChanged(int from, int charsRemoved, int c QTextBlock block = changeStartBlock; do { block.clearLayout(); - const int lineCount = block.isVisible() ? 1 : 0; - if (block.lineCount() != lineCount) { + if (block.isVisible() + ? (block.lineCount() == 0) + : (block.lineCount() > 0)) { blockVisibilityChanged = true; - block.setLineCount(lineCount); + block.setLineCount(block.isVisible() ? 1 : 0); } if (block == changeEndBlock) break; diff --git a/src/widgets/widgets/qsplitter.cpp b/src/widgets/widgets/qsplitter.cpp index 9e38c8f18a..0b90714363 100644 --- a/src/widgets/widgets/qsplitter.cpp +++ b/src/widgets/widgets/qsplitter.cpp @@ -1783,6 +1783,7 @@ void QSplitter::setStretchFactor(int index, int stretch) } +#if QT_DEPRECATED_SINCE(5, 13) /*! \relates QSplitter \obsolete @@ -1813,6 +1814,7 @@ QTextStream& operator>>(QTextStream& ts, QSplitter& splitter) splitter.restoreState(std::move(line).toLatin1()); return ts; } +#endif QT_END_NAMESPACE diff --git a/src/widgets/widgets/qsplitter.h b/src/widgets/widgets/qsplitter.h index 16fac48d1c..ec980d9ee3 100644 --- a/src/widgets/widgets/qsplitter.h +++ b/src/widgets/widgets/qsplitter.h @@ -129,8 +129,12 @@ private: friend class QSplitterHandle; }; +#if QT_DEPRECATED_SINCE(5, 13) +QT_DEPRECATED_X("Use QSplitter::saveState() instead") Q_WIDGETS_EXPORT QTextStream& operator<<(QTextStream&, const QSplitter&); +QT_DEPRECATED_X("Use QSplitter::restoreState() instead") Q_WIDGETS_EXPORT QTextStream& operator>>(QTextStream&, QSplitter&); +#endif class QSplitterHandlePrivate; class Q_WIDGETS_EXPORT QSplitterHandle : public QWidget diff --git a/src/widgets/widgets/qstatusbar.cpp b/src/widgets/widgets/qstatusbar.cpp index ae67cbd890..e9044e6cad 100644 --- a/src/widgets/widgets/qstatusbar.cpp +++ b/src/widgets/widgets/qstatusbar.cpp @@ -482,14 +482,14 @@ void QStatusBar::reformat() #if QT_CONFIG(sizegrip) if (d->resizer) { d->box = new QHBoxLayout(this); - d->box->setMargin(0); + d->box->setContentsMargins(QMargins()); vbox = new QVBoxLayout; d->box->addLayout(vbox); } else #endif { vbox = d->box = new QVBoxLayout(this); - d->box->setMargin(0); + d->box->setContentsMargins(QMargins()); } vbox->addSpacing(3); QBoxLayout* l = new QHBoxLayout; diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp index 05a98fc1a5..b13f4da9d2 100644 --- a/src/widgets/widgets/qtabbar.cpp +++ b/src/widgets/widgets/qtabbar.cpp @@ -2093,7 +2093,6 @@ void QTabBarPrivate::setupMovableTab() grabImage.setDevicePixelRatio(q->devicePixelRatioF()); grabImage.fill(Qt::transparent); QStylePainter p(&grabImage, q); - p.initFrom(q); QStyleOptionTab tab; q->initStyleOption(&tab, pressedIndex); diff --git a/src/widgets/widgets/qtoolbarlayout.cpp b/src/widgets/widgets/qtoolbarlayout.cpp index f2d329d59d..d50e19a5ed 100644 --- a/src/widgets/widgets/qtoolbarlayout.cpp +++ b/src/widgets/widgets/qtoolbarlayout.cpp @@ -119,8 +119,9 @@ void QToolBarLayout::updateMarginAndSpacing() QStyle *style = tb->style(); QStyleOptionToolBar opt; tb->initStyleOption(&opt); - setMargin(style->pixelMetric(QStyle::PM_ToolBarItemMargin, &opt, tb) - + style->pixelMetric(QStyle::PM_ToolBarFrameWidth, &opt, tb)); + const int margin = style->pixelMetric(QStyle::PM_ToolBarItemMargin, &opt, tb) + + style->pixelMetric(QStyle::PM_ToolBarFrameWidth, &opt, tb); + setContentsMargins(margin, margin, margin, margin); setSpacing(style->pixelMetric(QStyle::PM_ToolBarItemSpacing, &opt, tb)); } @@ -268,7 +269,7 @@ void QToolBarLayout::updateGeomArray() const tb->initStyleOption(&opt); const int handleExtent = movable() ? style->pixelMetric(QStyle::PM_ToolBarHandleExtent, &opt, tb) : 0; - const int margin = this->margin(); + const QMargins margins = contentsMargins(); const int spacing = this->spacing(); const int extensionExtent = style->pixelMetric(QStyle::PM_ToolBarExtensionExtent, &opt, tb); Qt::Orientation o = tb->orientation(); @@ -330,12 +331,12 @@ void QToolBarLayout::updateGeomArray() const that->empty = count == 0; rpick(o, that->minSize) += handleExtent; - that->minSize += QSize(2*margin, 2*margin); + that->minSize += QSize(pick(Qt::Horizontal, margins), pick(Qt::Vertical, margins)); if (items.count() > 1) rpick(o, that->minSize) += spacing + extensionExtent; rpick(o, that->hint) += handleExtent; - that->hint += QSize(2*margin, 2*margin); + that->hint += QSize(pick(Qt::Horizontal, margins), pick(Qt::Vertical, margins)); that->dirty = false; } @@ -384,7 +385,7 @@ void QToolBarLayout::setGeometry(const QRect &rect) QStyle *style = tb->style(); QStyleOptionToolBar opt; tb->initStyleOption(&opt); - const int margin = this->margin(); + const QMargins margins = contentsMargins(); const int extensionExtent = style->pixelMetric(QStyle::PM_ToolBarExtensionExtent, &opt, tb); Qt::Orientation o = tb->orientation(); @@ -403,14 +404,18 @@ void QToolBarLayout::setGeometry(const QRect &rect) QSize hint = sizeHint(); QPoint pos; - rpick(o, pos) = pick(o, rect.bottomRight()) - margin - extensionExtent + 2; + rpick(o, pos) = pick(o, rect.bottomRight()) - + pick(o, QSize(margins.bottom(), margins.right())) - extensionExtent + 2; if (area == Qt::LeftToolBarArea || area == Qt::TopToolBarArea) - rperp(o, pos) = perp(o, rect.topLeft()) + margin; + rperp(o, pos) = perp(o, rect.topLeft()) + + perp(o, QSize(margins.top(), margins.left())); else - rperp(o, pos) = perp(o, rect.bottomRight()) - margin - (perp(o, hint) - 2*margin) + 1; + rperp(o, pos) = perp(o, rect.bottomRight()) - + perp(o, QSize(margins.bottom(), margins.right())) - + (perp(o, hint) - perp(o, margins)) + 1; QSize size; rpick(o, size) = extensionExtent; - rperp(o, size) = perp(o, hint) - 2*margin; + rperp(o, size) = perp(o, hint) - perp(o, margins); QRect r(pos, size); if (o == Qt::Horizontal) @@ -443,13 +448,13 @@ bool QToolBarLayout::layoutActions(const QSize &size) tb->initStyleOption(&opt); const int handleExtent = movable() ? style->pixelMetric(QStyle::PM_ToolBarHandleExtent, &opt, tb) : 0; - const int margin = this->margin(); + const QMargins margins = contentsMargins(); const int spacing = this->spacing(); const int extensionExtent = style->pixelMetric(QStyle::PM_ToolBarExtensionExtent, &opt, tb); Qt::Orientation o = tb->orientation(); bool extensionMenuContainsOnlyWidgetActions = true; - int space = pick(o, rect.size()) - 2*margin - handleExtent; + int space = pick(o, rect.size()) - pick(o, margins) - handleExtent; if (space <= 0) return false; // nothing to do. @@ -458,7 +463,7 @@ bool QToolBarLayout::layoutActions(const QSize &size) bool ranOutOfSpace = false; int rows = 0; - int rowPos = perp(o, rect.topLeft()) + margin; + int rowPos = perp(o, rect.topLeft()) + perp(o, QSize(margins.top(), margins.left())); int i = 0; while (i < items.count()) { QVector<QLayoutStruct> a = geomArray; @@ -521,14 +526,14 @@ bool QToolBarLayout::layoutActions(const QSize &size) } QPoint pos; - rpick(o, pos) = margin + handleExtent + a[j].pos; + rpick(o, pos) = pick(o, QSize(margins.top(), margins.left())) + handleExtent + a[j].pos; rperp(o, pos) = rowPos; QSize size; rpick(o, size) = a[j].size; if (expanded) rperp(o, size) = rowHeight; else - rperp(o, size) = perp(o, rect.size()) - 2*margin; + rperp(o, size) = perp(o, rect.size()) - perp(o, QSize(margins.top(), margins.left())); QRect r(pos, size); if (o == Qt::Horizontal) @@ -589,7 +594,7 @@ QSize QToolBarLayout::expandedSize(const QSize &size) const tb->initStyleOption(&opt); const int handleExtent = movable() ? style->pixelMetric(QStyle::PM_ToolBarHandleExtent, &opt, tb) : 0; - const int margin = this->margin(); + const QMargins margins = contentsMargins(); const int spacing = this->spacing(); const int extensionExtent = style->pixelMetric(QStyle::PM_ToolBarExtensionExtent, &opt, tb); @@ -609,9 +614,9 @@ QSize QToolBarLayout::expandedSize(const QSize &size) const if (rows == 1) ++rows; // we want to expand to at least two rows int space = total_w/rows + spacing + extensionExtent; - space = qMax(space, min_w - 2*margin - handleExtent); + space = qMax(space, min_w - pick(o, margins) - handleExtent); if (win != 0) - space = qMin(space, pick(o, win->size()) - 2*margin - handleExtent); + space = qMin(space, pick(o, win->size()) - pick(o, margins) - handleExtent); int w = 0; int h = 0; @@ -644,11 +649,11 @@ QSize QToolBarLayout::expandedSize(const QSize &size) const h += rowHeight + spacing; } - w += 2*margin + handleExtent + spacing + extensionExtent; + w += pick(Qt::Horizontal, margins) + handleExtent + spacing + extensionExtent; w = qMax(w, min_w); if (win != 0) w = qMin(w, pick(o, win->size())); - h += 2*margin - spacing; //there is no spacing before the first row + h += pick(Qt::Vertical, margins) - spacing; //there is no spacing before the first row QSize result; rpick(o, result) = w; diff --git a/src/widgets/widgets/qtoolbox.cpp b/src/widgets/widgets/qtoolbox.cpp index eee112f02f..1c83485bff 100644 --- a/src/widgets/widgets/qtoolbox.cpp +++ b/src/widgets/widgets/qtoolbox.cpp @@ -294,7 +294,7 @@ QToolBox::QToolBox(QWidget *parent, Qt::WindowFlags f) { Q_D(QToolBox); d->layout = new QVBoxLayout(this); - d->layout->setMargin(0); + d->layout->setContentsMargins(QMargins()); setBackgroundRole(QPalette::Button); } @@ -437,7 +437,7 @@ void QToolBoxPrivate::relayout() Q_Q(QToolBox); delete layout; layout = new QVBoxLayout(q); - layout->setMargin(0); + layout->setContentsMargins(QMargins()); for (QToolBoxPrivate::PageList::ConstIterator i = pageList.constBegin(); i != pageList.constEnd(); ++i) { layout->addWidget((*i).button); layout->addWidget((*i).sv); |