diff options
Diffstat (limited to 'src/widgets')
196 files changed, 2969 insertions, 895 deletions
diff --git a/src/widgets/accessible/qaccessiblewidget.cpp b/src/widgets/accessible/qaccessiblewidget.cpp index bed0480059..254ecc92dd 100644 --- a/src/widgets/accessible/qaccessiblewidget.cpp +++ b/src/widgets/accessible/qaccessiblewidget.cpp @@ -383,6 +383,8 @@ int QAccessibleWidget::childCount() const /*! \reimp */ int QAccessibleWidget::indexOfChild(const QAccessibleInterface *child) const { + if (!child) + return -1; QWidgetList cl = childWidgets(widget()); return cl.indexOf(qobject_cast<QWidget *>(child->object())); } diff --git a/src/widgets/accessible/qaccessiblewidget.h b/src/widgets/accessible/qaccessiblewidget.h index 5e43f201cb..9830ee32fe 100644 --- a/src/widgets/accessible/qaccessiblewidget.h +++ b/src/widgets/accessible/qaccessiblewidget.h @@ -44,8 +44,6 @@ #include <QtGui/qaccessibleobject.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -99,6 +97,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QACCESSIBLEWIDGET_H diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp index af43ecc8df..c22258b3d2 100644 --- a/src/widgets/dialogs/qcolordialog.cpp +++ b/src/widgets/dialogs/qcolordialog.cpp @@ -1857,15 +1857,12 @@ void QColorDialog::setVisible(bool visible) } #else - if (!(options() & DontUseNativeDialog)) + if (!(options() & DontUseNativeDialog) && d->nativeDialogInUse) { d->setNativeDialogVisible(visible); - - if (d->nativeDialogInUse) { // Set WA_DontShowOnScreen so that QDialog::setVisible(visible) below // updates the state correctly, but skips showing the non-native version: setAttribute(Qt::WA_DontShowOnScreen); } else { - d->nativeDialogInUse = false; setAttribute(Qt::WA_DontShowOnScreen, false); } #endif diff --git a/src/widgets/dialogs/qcolordialog.h b/src/widgets/dialogs/qcolordialog.h index 2149c9c6d2..5db42629d8 100644 --- a/src/widgets/dialogs/qcolordialog.h +++ b/src/widgets/dialogs/qcolordialog.h @@ -44,8 +44,6 @@ #include <QtWidgets/qdialog.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -133,6 +131,4 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QColorDialog::ColorDialogOptions) QT_END_NAMESPACE -QT_END_HEADER - #endif // QCOLORDIALOG_H diff --git a/src/widgets/dialogs/qdialog.h b/src/widgets/dialogs/qdialog.h index eeb0ac56b5..a083a9f640 100644 --- a/src/widgets/dialogs/qdialog.h +++ b/src/widgets/dialogs/qdialog.h @@ -44,8 +44,6 @@ #include <QtWidgets/qwidget.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -125,6 +123,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QDIALOG_H diff --git a/src/widgets/dialogs/qerrormessage.h b/src/widgets/dialogs/qerrormessage.h index 4bba3131c9..b66cbca9e0 100644 --- a/src/widgets/dialogs/qerrormessage.h +++ b/src/widgets/dialogs/qerrormessage.h @@ -44,8 +44,6 @@ #include <QtWidgets/qdialog.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -79,6 +77,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QERRORMESSAGE_H diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index c60f2476c3..f4aa91974b 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -941,7 +941,9 @@ Q_AUTOTEST_EXPORT QString qt_tildeExpansion(const QString &path, bool *expanded } else { QString userName = tokens.first(); userName.remove(0, 1); -#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) +#if defined(Q_OS_VXWORKS) + const QString homePath = QDir::homePath(); +#elif defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_OPENBSD) passwd pw; passwd *tmpPw; char buf[200]; diff --git a/src/widgets/dialogs/qfiledialog.h b/src/widgets/dialogs/qfiledialog.h index 18aaa781fd..973bccf940 100644 --- a/src/widgets/dialogs/qfiledialog.h +++ b/src/widgets/dialogs/qfiledialog.h @@ -46,8 +46,6 @@ #include <QtCore/qstring.h> #include <QtWidgets/qdialog.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -265,6 +263,4 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDialog::Options) QT_END_NAMESPACE -QT_END_HEADER - #endif // QFILEDIALOG_H diff --git a/src/widgets/dialogs/qfilesystemmodel.cpp b/src/widgets/dialogs/qfilesystemmodel.cpp index 4d3c7a24ec..251af273b9 100644 --- a/src/widgets/dialogs/qfilesystemmodel.cpp +++ b/src/widgets/dialogs/qfilesystemmodel.cpp @@ -964,6 +964,8 @@ Qt::ItemFlags QFileSystemModel::flags(const QModelIndex &index) const flags |= Qt::ItemIsEditable; if (indexNode->isDir()) flags |= Qt::ItemIsDropEnabled; + else + flags |= Qt::ItemNeverHasChildren; } return flags; } diff --git a/src/widgets/dialogs/qfilesystemmodel.h b/src/widgets/dialogs/qfilesystemmodel.h index 18df89d736..cf26a4545d 100644 --- a/src/widgets/dialogs/qfilesystemmodel.h +++ b/src/widgets/dialogs/qfilesystemmodel.h @@ -48,8 +48,6 @@ #include <QtGui/qicon.h> #include <QtCore/qdiriterator.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -173,7 +171,5 @@ inline QFileInfo QFileSystemModel::fileInfo(const QModelIndex &aindex) const QT_END_NAMESPACE -QT_END_HEADER - #endif // QFILESYSTEMMODEL_H diff --git a/src/widgets/dialogs/qfontdialog.h b/src/widgets/dialogs/qfontdialog.h index 51d68d1b88..ceec0b71fc 100644 --- a/src/widgets/dialogs/qfontdialog.h +++ b/src/widgets/dialogs/qfontdialog.h @@ -46,8 +46,6 @@ #include <QtWidgets/qdialog.h> #include <QtGui/qfont.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -126,6 +124,4 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QFontDialog::FontDialogOptions) QT_END_NAMESPACE -QT_END_HEADER - #endif // QFONTDIALOG_H diff --git a/src/widgets/dialogs/qinputdialog.h b/src/widgets/dialogs/qinputdialog.h index 096a81d4bc..e55c2da1ff 100644 --- a/src/widgets/dialogs/qinputdialog.h +++ b/src/widgets/dialogs/qinputdialog.h @@ -46,8 +46,6 @@ #include <QtCore/qstring.h> #include <QtWidgets/qlineedit.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -215,6 +213,4 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QInputDialog::InputDialogOptions) QT_END_NAMESPACE -QT_END_HEADER - #endif // QINPUTDIALOG_H diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp index 57ed4da8a6..c644314ccd 100644 --- a/src/widgets/dialogs/qmessagebox.cpp +++ b/src/widgets/dialogs/qmessagebox.cpp @@ -1225,6 +1225,30 @@ void QMessageBox::setTextFormat(Qt::TextFormat format) } /*! + \property QMessageBox::textInteractionFlags + \since 5.1 + + Specifies how the label of the message box should interact with user + input. + + The default value depends on the style. + + \sa QStyle::SH_MessageBox_TextInteractionFlags +*/ + +Qt::TextInteractionFlags QMessageBox::textInteractionFlags() const +{ + Q_D(const QMessageBox); + return d->label->textInteractionFlags(); +} + +void QMessageBox::setTextInteractionFlags(Qt::TextInteractionFlags flags) +{ + Q_D(QMessageBox); + d->label->setTextInteractionFlags(flags); +} + +/*! \reimp */ bool QMessageBox::event(QEvent *e) diff --git a/src/widgets/dialogs/qmessagebox.h b/src/widgets/dialogs/qmessagebox.h index e0eb47ea2a..a170360fd5 100644 --- a/src/widgets/dialogs/qmessagebox.h +++ b/src/widgets/dialogs/qmessagebox.h @@ -44,8 +44,6 @@ #include <QtWidgets/qdialog.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -69,6 +67,7 @@ class Q_WIDGETS_EXPORT QMessageBox : public QDialog Q_PROPERTY(QString detailedText READ detailedText WRITE setDetailedText) #endif Q_PROPERTY(QString informativeText READ informativeText WRITE setInformativeText) + Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags) public: enum Icon { @@ -186,6 +185,9 @@ public: Qt::TextFormat textFormat() const; void setTextFormat(Qt::TextFormat format); + void setTextInteractionFlags(Qt::TextInteractionFlags flags); + Qt::TextInteractionFlags textInteractionFlags() const; + static StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton); @@ -329,6 +331,4 @@ str)).arg(QString::fromLatin1(qVersion())); QMessageBox::critical(0, QApplicatio QT_END_NAMESPACE -QT_END_HEADER - #endif // QMESSAGEBOX_H diff --git a/src/widgets/dialogs/qprogressdialog.h b/src/widgets/dialogs/qprogressdialog.h index 1f17727900..4eb9feeb7d 100644 --- a/src/widgets/dialogs/qprogressdialog.h +++ b/src/widgets/dialogs/qprogressdialog.h @@ -44,8 +44,6 @@ #include <QtWidgets/qdialog.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -139,6 +137,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QPROGRESSDIALOG_H diff --git a/src/widgets/dialogs/qwizard.cpp b/src/widgets/dialogs/qwizard.cpp index 8bc2eb92c1..aab6494d98 100644 --- a/src/widgets/dialogs/qwizard.cpp +++ b/src/widgets/dialogs/qwizard.cpp @@ -1557,7 +1557,7 @@ void QWizardPrivate::handleAeroStyleChange() _q_updateButtonStates(); if (q->isVisible()) - vistaHelper->setWindowPosHack(); + vistaHelper->updateCustomMargins(); inHandleAeroStyleChange = false; } @@ -2922,6 +2922,10 @@ QWidget *QWizard::sideWidget() const void QWizard::setVisible(bool visible) { Q_D(QWizard); +#if !defined(QT_NO_STYLE_WINDOWSVISTA) + if (visible) + d->vistaHelper->updateCustomMargins(); +#endif if (visible) { if (d->current == -1) restart(); diff --git a/src/widgets/dialogs/qwizard.h b/src/widgets/dialogs/qwizard.h index 7a95492f94..fe2e5f2d13 100644 --- a/src/widgets/dialogs/qwizard.h +++ b/src/widgets/dialogs/qwizard.h @@ -44,8 +44,6 @@ #include <QtWidgets/qdialog.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -261,8 +259,6 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QT_NO_WIZARD #endif // QWIZARD_H diff --git a/src/widgets/dialogs/qwizard_win.cpp b/src/widgets/dialogs/qwizard_win.cpp index 2bcb7a2167..ec04fed702 100644 --- a/src/widgets/dialogs/qwizard_win.cpp +++ b/src/widgets/dialogs/qwizard_win.cpp @@ -49,7 +49,9 @@ #include "qwizard.h" #include "qpaintengine.h" #include "qapplication.h" +#include <QtCore/QVariant> #include <QtGui/QMouseEvent> +#include <QtGui/QWindow> #include <QtWidgets/QDesktopWidget> // Note, these tests are duplicates in qwindowsxpstyle_p.h. @@ -66,6 +68,8 @@ #include <uxtheme.h> +Q_DECLARE_METATYPE(QMargins) + QT_BEGIN_NAMESPACE //DWM related @@ -265,6 +269,26 @@ QVistaHelper::~QVistaHelper() --instanceCount; } +void QVistaHelper::updateCustomMargins() +{ + if (QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS8) + return; // Negative margins are not supported on Windows 8. + if (QWindow *window = wizard->windowHandle()) { + // Reduce top frame to zero since we paint it ourselves. + const QMargins customMargins = vistaState() == VistaAero ? + QMargins(0, -titleBarSize(), 0, 0) : QMargins(); + const QVariant customMarginsV = qVariantFromValue(customMargins); + // The dynamic property takes effect when creating the platform window. + window->setProperty("_q_windowsCustomMargins", customMarginsV); + // If a platform window exists, change via native interface. + if (QPlatformWindow *platformWindow = window->handle()) { + QGuiApplication::platformNativeInterface()-> + setWindowProperty(platformWindow, QStringLiteral("WindowsCustomMargins"), + customMarginsV); + } + } +} + bool QVistaHelper::isCompositionEnabled() { bool value = is_vista; @@ -291,6 +315,12 @@ QVistaHelper::VistaState QVistaHelper::vistaState() return cachedVistaState; } +void QVistaHelper::disconnectBackButton() +{ + if (backButton_) // Leave QStyleSheetStyle's connections on destroyed() intact. + backButton_->disconnect(SIGNAL(clicked())); +} + QColor QVistaHelper::basicWindowFrameColor() { DWORD rgb; @@ -402,13 +432,6 @@ bool QVistaHelper::winEvent(MSG* msg, long* result) } break; } -// case WM_NCCALCSIZE: { #fixme: If the frame size is changed, it needs to be communicated to the QWindow. -// NCCALCSIZE_PARAMS* lpncsp = (NCCALCSIZE_PARAMS*)msg->lParam; -// *result = DefWindowProc(msg->hwnd, msg->message, msg->wParam, msg->lParam); -// lpncsp->rgrc[0].top -= (vistaState() == VistaAero ? titleBarSize() : 0); -// -// break; -// } default: LRESULT lResult; // Pass to DWM to handle @@ -449,38 +472,6 @@ void QVistaHelper::mouseEvent(QEvent *event) } } -// The following hack ensures that the titlebar is updated correctly -// when the wizard style changes to and from AeroStyle. Specifically, -// this function causes a Windows message of type WM_NCCALCSIZE to -// be triggered. -void QVistaHelper::setWindowPosHack() -{ - const int x = wizard->geometry().x(); // ignored by SWP_NOMOVE - const int y = wizard->geometry().y(); // ignored by SWP_NOMOVE - const int w = wizard->width(); - const int h = wizard->height(); - HWND handle = QApplicationPrivate::getHWNDForWidget(wizard); - SetWindowPos(handle, 0, x, y, w, h, SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED); -} - -// The following hack allows any QWidget subclass to access -// QWidgetPrivate::topData() without being declared as a -// friend by QWidget. -class QHackWidget : public QWidget -{ -public: - Q_DECLARE_PRIVATE(QWidget) - QTLWExtra* topData() { return d_func()->topData(); } -}; - -void QVistaHelper::collapseTopFrameStrut() -{ - QTLWExtra *top = ((QHackWidget *)wizard)->d_func()->topData(); - int x1, y1, x2, y2; - top->frameStrut.getCoords(&x1, &y1, &x2, &y2); - top->frameStrut.setCoords(x1, 0, x2, y2); -} - bool QVistaHelper::handleWinEvent(MSG *message, long *result) { if (message->message == WIZ_WM_THEMECHANGED || message->message == WIZ_WM_DWMCOMPOSITIONCHANGED) @@ -489,12 +480,8 @@ bool QVistaHelper::handleWinEvent(MSG *message, long *result) bool status = false; if (wizard->wizardStyle() == QWizard::AeroStyle && vistaState() == VistaAero) { status = winEvent(message, result); - if (message->message == WM_NCCALCSIZE) { -// if (status) #fixme -// collapseTopFrameStrut(); - } else if (message->message == WM_NCPAINT) { + if (message->message == WM_NCPAINT) wizard->update(); - } } return status; } @@ -789,6 +776,19 @@ int QVistaHelper::titleOffset() return leftMargin() + iconOffset; } +int QVistaHelper::topOffset() +{ + if (vistaState() != VistaAero) + return titleBarSize() + 3; + static const int aeroOffset = + QSysInfo::WindowsVersion == QSysInfo::WV_WINDOWS7 ? + QStyleHelper::dpiScaled(4) : QStyleHelper::dpiScaled(13); + int result = aeroOffset; + if (QSysInfo::WindowsVersion < QSysInfo::WV_WINDOWS8) + result += titleBarSize(); + return result; +} + QT_END_NAMESPACE #endif // QT_NO_STYLE_WINDOWSVISTA diff --git a/src/widgets/dialogs/qwizard_win_p.h b/src/widgets/dialogs/qwizard_win_p.h index cd0b2da38e..8b370d4e74 100644 --- a/src/widgets/dialogs/qwizard_win_p.h +++ b/src/widgets/dialogs/qwizard_win_p.h @@ -87,6 +87,7 @@ public: QVistaHelper(QWizard *wizard); ~QVistaHelper(); enum TitleBarChangeType { NormalTitleBar, ExtendedTitleBar }; + void updateCustomMargins(); bool setDWMTitleBar(TitleBarChangeType type); void setTitleBarIconAndCaptionVisible(bool visible); void mouseEvent(QEvent *event); @@ -94,9 +95,8 @@ public: void resizeEvent(QResizeEvent *event); void paintEvent(QPaintEvent *event); QVistaBackButton *backButton() const { return backButton_; } - void disconnectBackButton() { if (backButton_) backButton_->disconnect(); } + void disconnectBackButton(); void hideBackButton() { if (backButton_) backButton_->hide(); } - void setWindowPosHack(); QColor basicWindowFrameColor(); enum VistaState { VistaAero, VistaBasic, Classic, Dirty }; static VistaState vistaState(); @@ -105,10 +105,8 @@ public: return int(QStyleHelper::dpiScaled( QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS7 ? 4 : 6)); } - static int topOffset() { - static int aeroOffset = QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS7 ? - QStyleHelper::dpiScaled(4) : QStyleHelper::dpiScaled(13); - return (titleBarSize() + (vistaState() == VistaAero ? aeroOffset : 3)); } + static int topOffset(); + private: static HFONT getCaptionFont(HANDLE hTheme); bool drawTitleText(QPainter *painter, const QString &text, const QRect &rect, HDC hdc); diff --git a/src/widgets/effects/qgraphicseffect.h b/src/widgets/effects/qgraphicseffect.h index f08f937799..8ba3a9c6d7 100644 --- a/src/widgets/effects/qgraphicseffect.h +++ b/src/widgets/effects/qgraphicseffect.h @@ -49,8 +49,6 @@ #include <QtGui/qbrush.h> #ifndef QT_NO_GRAPHICSEFFECT -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -281,7 +279,6 @@ private: QT_END_NAMESPACE -QT_END_HEADER #endif //QT_NO_GRAPHICSEFFECT #endif // QGRAPHICSEFFECT_H diff --git a/src/widgets/effects/qpixmapfilter_p.h b/src/widgets/effects/qpixmapfilter_p.h index e93c1adc3c..6f08e87928 100644 --- a/src/widgets/effects/qpixmapfilter_p.h +++ b/src/widgets/effects/qpixmapfilter_p.h @@ -58,8 +58,6 @@ #include <QtWidgets/qgraphicseffect.h> #ifndef QT_NO_GRAPHICSEFFECT -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -189,7 +187,5 @@ public: QT_END_NAMESPACE -QT_END_HEADER - #endif //QT_NO_GRAPHICSEFFECT #endif // QPIXMAPFILTER_H diff --git a/src/widgets/graphicsview/qgraphicsanchorlayout.h b/src/widgets/graphicsview/qgraphicsanchorlayout.h index b8aa221630..0adf18f9ba 100644 --- a/src/widgets/graphicsview/qgraphicsanchorlayout.h +++ b/src/widgets/graphicsview/qgraphicsanchorlayout.h @@ -46,8 +46,6 @@ #include <QtWidgets/qgraphicslayout.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -122,6 +120,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif diff --git a/src/widgets/graphicsview/qgraphicsgridlayout.h b/src/widgets/graphicsview/qgraphicsgridlayout.h index d833ea3b33..308be67531 100644 --- a/src/widgets/graphicsview/qgraphicsgridlayout.h +++ b/src/widgets/graphicsview/qgraphicsgridlayout.h @@ -45,8 +45,6 @@ #include <QtWidgets/qgraphicsitem.h> #include <QtWidgets/qgraphicslayout.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -137,7 +135,5 @@ inline void QGraphicsGridLayout::addItem(QGraphicsLayoutItem *aitem, int arow, i QT_END_NAMESPACE -QT_END_HEADER - #endif diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp index 5c9651f1c9..a396053a82 100644 --- a/src/widgets/graphicsview/qgraphicsitem.cpp +++ b/src/widgets/graphicsview/qgraphicsitem.cpp @@ -1867,15 +1867,46 @@ void QGraphicsItem::setFlags(GraphicsItemFlags flags) d_ptr->scene->d_func()->updateInputMethodSensitivityInViews(); } + if ((flags & ItemIsPanel) != (oldFlags & ItemIsPanel)) { + bool becomesPanel = (flags & ItemIsPanel); + if ((d_ptr->panelModality != NonModal) && d_ptr->scene) { + // update the panel's modal state + if (becomesPanel) + d_ptr->scene->d_func()->enterModal(this); + else + d_ptr->scene->d_func()->leaveModal(this); + } + if (d_ptr->isWidget && (becomesPanel || parentWidget())) { + QGraphicsWidget *w = static_cast<QGraphicsWidget *>(this); + QGraphicsWidget *focusFirst = w; + QGraphicsWidget *focusLast = w; + for (;;) { + QGraphicsWidget *test = focusLast->d_func()->focusNext; + if (!w->isAncestorOf(test) || test == w) + break; + focusLast = test; + } - if ((d_ptr->panelModality != NonModal) - && d_ptr->scene - && (flags & ItemIsPanel) != (oldFlags & ItemIsPanel)) { - // update the panel's modal state - if (flags & ItemIsPanel) - d_ptr->scene->d_func()->enterModal(this); - else - d_ptr->scene->d_func()->leaveModal(this); + if (becomesPanel) { + // unlink own widgets from focus chain + QGraphicsWidget *beforeMe = w->d_func()->focusPrev; + QGraphicsWidget *afterMe = focusLast->d_func()->focusNext; + beforeMe->d_func()->focusNext = afterMe; + afterMe->d_func()->focusPrev = beforeMe; + focusFirst->d_func()->focusPrev = focusLast; + focusLast->d_func()->focusNext = focusFirst; + if (!isAncestorOf(focusFirst->d_func()->focusNext)) + focusFirst->d_func()->focusNext = w; + } else if (QGraphicsWidget *pw = parentWidget()) { + // link up own widgets to focus chain + QGraphicsWidget *beforeMe = pw; + QGraphicsWidget *afterMe = pw->d_func()->focusNext; + beforeMe->d_func()->focusNext = w; + afterMe->d_func()->focusPrev = focusLast; + w->d_func()->focusPrev = beforeMe; + focusLast->d_func()->focusNext = afterMe; + } + } } if (d_ptr->scene) { @@ -2259,7 +2290,7 @@ void QGraphicsItemPrivate::setVisibleHelper(bool newVisible, bool explicitly, scene->d_func()->leaveModal(q_ptr); } if (hasFocus && scene) { - // Hiding the closest non-panel ancestor of the focus item + // Hiding the focus item or the closest non-panel ancestor of the focus item QGraphicsItem *focusItem = scene->focusItem(); bool clear = true; if (isWidget && !focusItem->isPanel()) { @@ -3156,16 +3187,20 @@ void QGraphicsItem::setActive(bool active) // Activate this item. d_ptr->scene->setActivePanel(this); } else { - // Deactivate this item, and reactivate the parent panel, - // or the last active panel (if any). - QGraphicsItem *nextToActivate = 0; - if (d_ptr->parent) - nextToActivate = d_ptr->parent->panel(); - if (!nextToActivate) - nextToActivate = d_ptr->scene->d_func()->lastActivePanel; - if (nextToActivate == this || isAncestorOf(nextToActivate)) - nextToActivate = 0; - d_ptr->scene->setActivePanel(nextToActivate); + QGraphicsItem *activePanel = d_ptr->scene->activePanel(); + QGraphicsItem *thisPanel = panel(); + if (!activePanel || activePanel == thisPanel) { + // Deactivate this item, and reactivate the parent panel, + // or the last active panel (if any). + QGraphicsItem *nextToActivate = 0; + if (d_ptr->parent) + nextToActivate = d_ptr->parent->panel(); + if (!nextToActivate) + nextToActivate = d_ptr->scene->d_func()->lastActivePanel; + if (nextToActivate == this || isAncestorOf(nextToActivate)) + nextToActivate = 0; + d_ptr->scene->setActivePanel(nextToActivate); + } } } } diff --git a/src/widgets/graphicsview/qgraphicsitem.h b/src/widgets/graphicsview/qgraphicsitem.h index 446aea4754..c6b1c2dd66 100644 --- a/src/widgets/graphicsview/qgraphicsitem.h +++ b/src/widgets/graphicsview/qgraphicsitem.h @@ -52,8 +52,6 @@ class tst_QGraphicsItem; -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -1059,6 +1057,4 @@ QT_BEGIN_NAMESPACE QT_END_NAMESPACE -QT_END_HEADER - #endif // QGRAPHICSITEM_H diff --git a/src/widgets/graphicsview/qgraphicsitemanimation.h b/src/widgets/graphicsview/qgraphicsitemanimation.h index d87fc8a868..f0006e3c34 100644 --- a/src/widgets/graphicsview/qgraphicsitemanimation.h +++ b/src/widgets/graphicsview/qgraphicsitemanimation.h @@ -46,8 +46,6 @@ #if !defined(QT_NO_GRAPHICSVIEW) -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -113,7 +111,5 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QT_NO_GRAPHICSVIEW #endif diff --git a/src/widgets/graphicsview/qgraphicslayout.h b/src/widgets/graphicsview/qgraphicslayout.h index 85668d8deb..e9574933a6 100644 --- a/src/widgets/graphicsview/qgraphicslayout.h +++ b/src/widgets/graphicsview/qgraphicslayout.h @@ -44,8 +44,6 @@ #include <QtWidgets/qgraphicslayoutitem.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -93,7 +91,5 @@ Q_DECLARE_INTERFACE(QGraphicsLayout, "org.qt-project.Qt.QGraphicsLayout") QT_END_NAMESPACE -QT_END_HEADER - #endif diff --git a/src/widgets/graphicsview/qgraphicslayoutitem.h b/src/widgets/graphicsview/qgraphicslayoutitem.h index b753790121..ffd82b0720 100644 --- a/src/widgets/graphicsview/qgraphicslayoutitem.h +++ b/src/widgets/graphicsview/qgraphicslayoutitem.h @@ -46,8 +46,6 @@ #include <QtWidgets/qsizepolicy.h> #include <QtGui/qevent.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -148,6 +146,4 @@ inline qreal QGraphicsLayoutItem::maximumHeight() const QT_END_NAMESPACE -QT_END_HEADER - #endif diff --git a/src/widgets/graphicsview/qgraphicslinearlayout.h b/src/widgets/graphicsview/qgraphicslinearlayout.h index 0aabc808a0..2ddbda02df 100644 --- a/src/widgets/graphicsview/qgraphicslinearlayout.h +++ b/src/widgets/graphicsview/qgraphicslinearlayout.h @@ -45,8 +45,6 @@ #include <QtWidgets/qgraphicsitem.h> #include <QtWidgets/qgraphicslayout.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -112,7 +110,5 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif diff --git a/src/widgets/graphicsview/qgraphicsproxywidget.h b/src/widgets/graphicsview/qgraphicsproxywidget.h index a88899b900..641881ed71 100644 --- a/src/widgets/graphicsview/qgraphicsproxywidget.h +++ b/src/widgets/graphicsview/qgraphicsproxywidget.h @@ -44,8 +44,6 @@ #include <QtWidgets/qgraphicswidget.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -140,7 +138,5 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif diff --git a/src/widgets/graphicsview/qgraphicsscene.cpp b/src/widgets/graphicsview/qgraphicsscene.cpp index a9c045ea80..78611a27ca 100644 --- a/src/widgets/graphicsview/qgraphicsscene.cpp +++ b/src/widgets/graphicsview/qgraphicsscene.cpp @@ -607,7 +607,7 @@ void QGraphicsScenePrivate::removeItemHelper(QGraphicsItem *item) q->removeItem(item->d_ptr->children.at(i)); } - if (!item->d_ptr->inDestructor && item == tabFocusFirst) { + if (!item->d_ptr->inDestructor && !item->parentItem() && item->isWidget()) { QGraphicsWidget *widget = static_cast<QGraphicsWidget *>(item); widget->d_func()->fixFocusChainBeforeReparenting(0, oldScene, 0); } @@ -742,12 +742,14 @@ void QGraphicsScenePrivate::setActivePanelHelper(QGraphicsItem *item, bool durin if (panel == activePanel || (!q->isActive() && !duringActivationEvent)) return; + QGraphicsItem *oldFocusItem = focusItem; + // Deactivate the last active panel. if (activePanel) { if (QGraphicsItem *fi = activePanel->focusItem()) { // Remove focus from the current focus item. if (fi == q->focusItem()) - q->setFocusItem(0, Qt::ActiveWindowFocusReason); + setFocusItemHelper(0, Qt::ActiveWindowFocusReason, /* emitFocusChanged = */ false); } QEvent event(QEvent::WindowDeactivate); @@ -771,9 +773,23 @@ void QGraphicsScenePrivate::setActivePanelHelper(QGraphicsItem *item, bool durin QEvent event(QEvent::WindowActivate); q->sendEvent(panel, &event); - // Set focus on the panel's focus item. - if (QGraphicsItem *focusItem = panel->focusItem()) - focusItem->setFocus(Qt::ActiveWindowFocusReason); + // Set focus on the panel's focus item, or itself if it's + // focusable, or on the first focusable item in the panel's + // focus chain as a last resort. + if (QGraphicsItem *focusItem = panel->focusItem()) { + setFocusItemHelper(focusItem, Qt::ActiveWindowFocusReason, /* emitFocusChanged = */ false); + } else if (panel->flags() & QGraphicsItem::ItemIsFocusable) { + setFocusItemHelper(panel, Qt::ActiveWindowFocusReason, /* emitFocusChanged = */ false); + } else if (panel->isWidget()) { + QGraphicsWidget *fw = static_cast<QGraphicsWidget *>(panel)->d_func()->focusNext; + do { + if (fw->focusPolicy() & Qt::TabFocus) { + setFocusItemHelper(fw, Qt::ActiveWindowFocusReason, /* emitFocusChanged = */ false); + break; + } + fw = fw->d_func()->focusNext; + } while (fw != panel); + } } else if (q->isActive()) { // Activate the scene QEvent event(QEvent::WindowActivate); @@ -782,13 +798,23 @@ void QGraphicsScenePrivate::setActivePanelHelper(QGraphicsItem *item, bool durin q->sendEvent(item, &event); } } + + emit q->focusItemChanged(focusItem, oldFocusItem, Qt::ActiveWindowFocusReason); } /*! \internal + + \a emitFocusChanged needs to be false when focus passes from one + item to another through setActivePanel(); i.e. when activation + passes from one panel to another, to avoid getting two focusChanged() + emissions; one focusChanged(0, lastFocus), then one + focusChanged(newFocus, 0). Instead setActivePanel() emits the signal + once itself: focusChanged(newFocus, oldFocus). */ void QGraphicsScenePrivate::setFocusItemHelper(QGraphicsItem *item, - Qt::FocusReason focusReason) + Qt::FocusReason focusReason, + bool emitFocusChanged) { Q_Q(QGraphicsScene); if (item == focusItem) @@ -804,10 +830,14 @@ void QGraphicsScenePrivate::setFocusItemHelper(QGraphicsItem *item, // Set focus on the scene if an item requests focus. if (item) { q->setFocus(focusReason); - if (item == focusItem) + if (item == focusItem) { + if (emitFocusChanged) + emit q->focusItemChanged(focusItem, (QGraphicsItem *)0, focusReason); return; + } } + QGraphicsItem *oldFocusItem = focusItem; if (focusItem) { lastFocusItem = focusItem; @@ -848,6 +878,9 @@ void QGraphicsScenePrivate::setFocusItemHelper(QGraphicsItem *item, QFocusEvent event(QEvent::FocusIn, focusReason); sendEvent(item, &event); } + + if (emitFocusChanged) + emit q->focusItemChanged(focusItem, oldFocusItem, focusReason); } /*! @@ -2528,14 +2561,13 @@ void QGraphicsScene::addItem(QGraphicsItem *item) // No first tab focus widget - make this the first tab focus // widget. d->tabFocusFirst = widget; - } else if (!widget->parentWidget()) { + } else if (!widget->parentWidget() && !widget->isPanel()) { // Adding a widget that is not part of a tab focus chain. - QGraphicsWidget *last = d->tabFocusFirst->d_func()->focusPrev; - QGraphicsWidget *lastNew = widget->d_func()->focusPrev; - last->d_func()->focusNext = widget; - widget->d_func()->focusPrev = last; - d->tabFocusFirst->d_func()->focusPrev = lastNew; - lastNew->d_func()->focusNext = d->tabFocusFirst; + QGraphicsWidget *myNewPrev = d->tabFocusFirst->d_func()->focusPrev; + myNewPrev->d_func()->focusNext = widget; + widget->d_func()->focusPrev->d_func()->focusNext = d->tabFocusFirst; + d->tabFocusFirst->d_func()->focusPrev = widget->d_func()->focusPrev; + widget->d_func()->focusPrev = myNewPrev; } } @@ -5329,8 +5361,23 @@ bool QGraphicsScene::focusNextPrevChild(bool next) setFocusItem(d->lastFocusItem, next ? Qt::TabFocusReason : Qt::BacktabFocusReason); return true; } + if (d->activePanel) { + if (d->activePanel->flags() & QGraphicsItem::ItemIsFocusable) { + setFocusItem(d->activePanel, next ? Qt::TabFocusReason : Qt::BacktabFocusReason); + return true; + } + if (d->activePanel->isWidget()) { + QGraphicsWidget *fw = static_cast<QGraphicsWidget *>(d->activePanel)->d_func()->focusNext; + do { + if (fw->focusPolicy() & Qt::TabFocus) { + setFocusItem(fw, next ? Qt::TabFocusReason : Qt::BacktabFocusReason); + return true; + } + } while (fw != d->activePanel); + } + } } - if (!d->tabFocusFirst) { + if (!item && !d->tabFocusFirst) { // No widgets... return false; } @@ -5342,8 +5389,10 @@ bool QGraphicsScene::focusNextPrevChild(bool next) } else { QGraphicsWidget *test = static_cast<QGraphicsWidget *>(item); widget = next ? test->d_func()->focusNext : test->d_func()->focusPrev; - if ((next && widget == d->tabFocusFirst) || (!next && widget == d->tabFocusFirst->d_func()->focusPrev)) + if (!widget->panel() && ((next && widget == d->tabFocusFirst) || (!next && widget == d->tabFocusFirst->d_func()->focusPrev))) { + // Tab out of the scene. return false; + } } QGraphicsWidget *widgetThatHadFocus = widget; @@ -5407,6 +5456,25 @@ bool QGraphicsScene::focusNextPrevChild(bool next) */ /*! + \fn QGraphicsScene::focusChanged(QGraphicsItem *newFocusItem, QGraphicsItem *oldFocusItem, Qt::FocusReason reason) + + This signal is emitted by QGraphicsScene whenever focus changes in the + scene (i.e., when an item gains or loses input focus, or when focus + passes from one item to another). You can connect to this signal if you + need to keep track of when other items gain input focus. It is + particularily useful for implementing virtual keyboards, input methods, + and cursor items. + + \a oldFocusItem is a pointer to the item that previously had focus, or + 0 if no item had focus before the signal was emitted. \a newFocusItem + is a pointer to the item that gained input focus, or 0 if focus was lost. + \a reason is the reason for the focus change (e.g., if the scene was + deactivated while an input field had focus, \a oldFocusItem would point + to the input field item, \a newFocusItem would be 0, and \a reason would be + Qt::ActiveWindowFocusReason. +*/ + +/*! \since 4.4 Returns the scene's style, or the same as QApplication::style() if the diff --git a/src/widgets/graphicsview/qgraphicsscene.h b/src/widgets/graphicsview/qgraphicsscene.h index 802d9c4970..1a575d987e 100644 --- a/src/widgets/graphicsview/qgraphicsscene.h +++ b/src/widgets/graphicsview/qgraphicsscene.h @@ -51,8 +51,6 @@ #include <QtGui/qmatrix.h> #include <QtGui/qpen.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -292,6 +290,7 @@ Q_SIGNALS: void changed(const QList<QRectF> ®ion); void sceneRectChanged(const QRectF &rect); void selectionChanged(); + void focusItemChanged(QGraphicsItem *newFocus, QGraphicsItem *oldFocus, Qt::FocusReason reason); private: Q_DECLARE_PRIVATE(QGraphicsScene) @@ -324,6 +323,4 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsScene::SceneLayers) QT_END_NAMESPACE -QT_END_HEADER - #endif diff --git a/src/widgets/graphicsview/qgraphicsscene_p.h b/src/widgets/graphicsview/qgraphicsscene_p.h index 14cc240fa3..8c1fa69cf4 100644 --- a/src/widgets/graphicsview/qgraphicsscene_p.h +++ b/src/widgets/graphicsview/qgraphicsscene_p.h @@ -157,7 +157,8 @@ public: int activationRefCount; int childExplicitActivation; void setActivePanelHelper(QGraphicsItem *item, bool duringActivationEvent); - void setFocusItemHelper(QGraphicsItem *item, Qt::FocusReason focusReason); + void setFocusItemHelper(QGraphicsItem *item, Qt::FocusReason focusReason, + bool emitFocusChanged = true); QList<QGraphicsWidget *> popupWidgets; void addPopup(QGraphicsWidget *widget); diff --git a/src/widgets/graphicsview/qgraphicssceneevent.h b/src/widgets/graphicsview/qgraphicssceneevent.h index 81a5321e0c..616b0b1151 100644 --- a/src/widgets/graphicsview/qgraphicssceneevent.h +++ b/src/widgets/graphicsview/qgraphicssceneevent.h @@ -50,8 +50,6 @@ #include <QtCore/qset.h> #include <QtCore/qhash.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -320,6 +318,4 @@ public: QT_END_NAMESPACE -QT_END_HEADER - #endif diff --git a/src/widgets/graphicsview/qgraphicssceneindex_p.h b/src/widgets/graphicsview/qgraphicssceneindex_p.h index c5500e3d6e..29b321fb1d 100644 --- a/src/widgets/graphicsview/qgraphicssceneindex_p.h +++ b/src/widgets/graphicsview/qgraphicssceneindex_p.h @@ -61,8 +61,6 @@ #include <QtCore/qobject.h> #include <QtGui/qtransform.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -176,6 +174,4 @@ public: QT_END_NAMESPACE -QT_END_HEADER - #endif // QGRAPHICSSCENEINDEX_H diff --git a/src/widgets/graphicsview/qgraphicsscenelinearindex_p.h b/src/widgets/graphicsview/qgraphicsscenelinearindex_p.h index 607a15b949..7debcfb501 100644 --- a/src/widgets/graphicsview/qgraphicsscenelinearindex_p.h +++ b/src/widgets/graphicsview/qgraphicsscenelinearindex_p.h @@ -62,8 +62,6 @@ #include <QtWidgets/qgraphicsitem.h> #include <private/qgraphicssceneindex_p.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -103,6 +101,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QGRAPHICSSCENELINEARINDEX_H diff --git a/src/widgets/graphicsview/qgraphicstransform.h b/src/widgets/graphicsview/qgraphicstransform.h index 6c2c0d67f0..ebcfbb32f1 100644 --- a/src/widgets/graphicsview/qgraphicstransform.h +++ b/src/widgets/graphicsview/qgraphicstransform.h @@ -48,8 +48,6 @@ #include <QtGui/QMatrix4x4> #ifndef QT_NO_GRAPHICSVIEW -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -152,7 +150,6 @@ private: QT_END_NAMESPACE -QT_END_HEADER #endif //QT_NO_GRAPHICSVIEW #endif // QFXTRANSFORM_H diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp index 22ec829507..dd10c95e2a 100644 --- a/src/widgets/graphicsview/qgraphicsview.cpp +++ b/src/widgets/graphicsview/qgraphicsview.cpp @@ -256,6 +256,20 @@ static const int QGRAPHICSVIEW_PREALLOC_STYLE_OPTIONS = 503; // largest prime < \sa dragMode, QGraphicsScene::setSelectionArea() */ +/*! + \since 5.1 + + \fn void QGraphicsView::rubberBandChanged(QRect rubberBandRect, QPointF fromScenePoint, QPointF toScenePoint) + + This signal is emitted when the rubber band rect is changed. The viewport Rect is specified by \a rubberBandRect. + The drag start position and drag end position are provided in scene points with \a fromScenePoint and \a toScenePoint. + + When rubberband selection ends this signal will be emitted with null vales. + + \sa rubberBandRect() +*/ + + #include "qgraphicsview.h" #include "qgraphicsview_p.h" @@ -706,56 +720,61 @@ QRegion QGraphicsViewPrivate::rubberBandRegion(const QWidget *widget, const QRec return tmp; } -void QGraphicsViewPrivate::updateRubberBand(QMouseEvent *event) +void QGraphicsViewPrivate::updateRubberBand(const QMouseEvent *event) { Q_Q(QGraphicsView); - if (dragMode == QGraphicsView::RubberBandDrag && sceneInteractionAllowed) { - storeMouseEvent(event); - if (rubberBanding) { - // Check for enough drag distance - if ((mousePressViewPoint - event->pos()).manhattanLength() - < QApplication::startDragDistance()) { - return; - } + if (dragMode != QGraphicsView::RubberBandDrag || !sceneInteractionAllowed || !rubberBanding) + return; + // Check for enough drag distance + if ((mousePressViewPoint - event->pos()).manhattanLength() < QApplication::startDragDistance()) + return; - // Update old rubberband - if (viewportUpdateMode != QGraphicsView::NoViewportUpdate && !rubberBandRect.isEmpty()) { - if (viewportUpdateMode != QGraphicsView::FullViewportUpdate) - q->viewport()->update(rubberBandRegion(q->viewport(), rubberBandRect)); - else - updateAll(); - } + // Update old rubberband + if (viewportUpdateMode != QGraphicsView::NoViewportUpdate && !rubberBandRect.isEmpty()) { + if (viewportUpdateMode != QGraphicsView::FullViewportUpdate) + q->viewport()->update(rubberBandRegion(q->viewport(), rubberBandRect)); + else + updateAll(); + } - // Stop rubber banding if the user has let go of all buttons (even - // if we didn't get the release events). - if (!event->buttons()) { - rubberBanding = false; - rubberBandRect = QRect(); - return; - } + // Stop rubber banding if the user has let go of all buttons (even + // if we didn't get the release events). + if (!event->buttons()) { + rubberBanding = false; + if (!rubberBandRect.isNull()) { + rubberBandRect = QRect(); + emit q->rubberBandChanged(rubberBandRect, QPointF(), QPointF()); + } + return; + } - // Update rubberband position - const QPoint mp = q->mapFromScene(mousePressScenePoint); - const QPoint ep = event->pos(); - rubberBandRect = QRect(qMin(mp.x(), ep.x()), qMin(mp.y(), ep.y()), - qAbs(mp.x() - ep.x()) + 1, qAbs(mp.y() - ep.y()) + 1); + QRect oldRubberband = rubberBandRect; - // Update new rubberband - if (viewportUpdateMode != QGraphicsView::NoViewportUpdate){ - if (viewportUpdateMode != QGraphicsView::FullViewportUpdate) - q->viewport()->update(rubberBandRegion(q->viewport(), rubberBandRect)); - else - updateAll(); - } - // Set the new selection area - QPainterPath selectionArea; - selectionArea.addPolygon(mapToScene(rubberBandRect)); - selectionArea.closeSubpath(); - if (scene) - scene->setSelectionArea(selectionArea, rubberBandSelectionMode, - q->viewportTransform()); - } + // Update rubberband position + const QPoint mp = q->mapFromScene(mousePressScenePoint); + const QPoint ep = event->pos(); + rubberBandRect = QRect(qMin(mp.x(), ep.x()), qMin(mp.y(), ep.y()), + qAbs(mp.x() - ep.x()) + 1, qAbs(mp.y() - ep.y()) + 1); + + if (rubberBandRect != oldRubberband || lastRubberbandScenePoint != lastMouseMoveScenePoint) { + lastRubberbandScenePoint = lastMouseMoveScenePoint; + oldRubberband = rubberBandRect; + emit q->rubberBandChanged(rubberBandRect, mousePressScenePoint, lastRubberbandScenePoint); } + + // Update new rubberband + if (viewportUpdateMode != QGraphicsView::NoViewportUpdate) { + if (viewportUpdateMode != QGraphicsView::FullViewportUpdate) + q->viewport()->update(rubberBandRegion(q->viewport(), rubberBandRect)); + else + updateAll(); + } + // Set the new selection area + QPainterPath selectionArea; + selectionArea.addPolygon(mapToScene(rubberBandRect)); + selectionArea.closeSubpath(); + if (scene) + scene->setSelectionArea(selectionArea, rubberBandSelectionMode, q->viewportTransform()); } #endif @@ -1502,7 +1521,7 @@ void QGraphicsView::setDragMode(DragMode mode) The default value is Qt::IntersectsItemShape; all items whose shape intersects with or is contained by the rubber band are selected. - \sa dragMode, items() + \sa dragMode, items(), rubberBandRect() */ Qt::ItemSelectionMode QGraphicsView::rubberBandSelectionMode() const { @@ -1514,6 +1533,27 @@ void QGraphicsView::setRubberBandSelectionMode(Qt::ItemSelectionMode mode) Q_D(QGraphicsView); d->rubberBandSelectionMode = mode; } + +/*! + \since 5.1 + This functions returns the current rubber band area (in viewport coordinates) if the user + is currently doing an itemselection with rubber band. When the user is not using the + rubber band this functions returns (a null) QRectF(). + + Notice that part of this QRect can be outise the visual viewport. It can e.g + contain negative values. + + \sa rubberBandSelectionMode, rubberBandChanged() +*/ + +QRect QGraphicsView::rubberBandRect() const +{ + Q_D(const QGraphicsView); + if (d->dragMode != QGraphicsView::RubberBandDrag || !d->sceneInteractionAllowed || !d->rubberBanding) + return QRect(); + + return d->rubberBandRect; +} #endif /*! @@ -3301,7 +3341,10 @@ void QGraphicsView::mouseReleaseEvent(QMouseEvent *event) d->updateAll(); } d->rubberBanding = false; - d->rubberBandRect = QRect(); + if (!d->rubberBandRect.isNull()) { + d->rubberBandRect = QRect(); + emit rubberBandChanged(d->rubberBandRect, QPointF(), QPointF()); + } } } else #endif diff --git a/src/widgets/graphicsview/qgraphicsview.h b/src/widgets/graphicsview/qgraphicsview.h index 488e12511c..d812728237 100644 --- a/src/widgets/graphicsview/qgraphicsview.h +++ b/src/widgets/graphicsview/qgraphicsview.h @@ -47,8 +47,6 @@ #include <QtWidgets/qscrollarea.h> #include <QtWidgets/qgraphicsscene.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -148,6 +146,7 @@ public: #ifndef QT_NO_RUBBERBAND Qt::ItemSelectionMode rubberBandSelectionMode() const; void setRubberBandSelectionMode(Qt::ItemSelectionMode mode); + QRect rubberBandRect() const; #endif CacheMode cacheMode() const; @@ -228,6 +227,11 @@ public Q_SLOTS: void invalidateScene(const QRectF &rect = QRectF(), QGraphicsScene::SceneLayers layers = QGraphicsScene::AllLayers); void updateSceneRect(const QRectF &rect); +#ifndef QT_NO_RUBBERBAND +Q_SIGNALS: + void rubberBandChanged(QRect viewportRect, QPointF fromScenePoint, QPointF toScenePoint); +#endif + protected Q_SLOTS: void setupViewport(QWidget *widget); @@ -310,6 +314,4 @@ inline QPolygon QGraphicsView::mapFromScene(qreal ax, qreal ay, qreal w, qreal h QT_END_NAMESPACE -QT_END_HEADER - #endif // QGRAPHICSVIEW_H diff --git a/src/widgets/graphicsview/qgraphicsview_p.h b/src/widgets/graphicsview/qgraphicsview_p.h index 9f0e3e3b24..44d37ef992 100644 --- a/src/widgets/graphicsview/qgraphicsview_p.h +++ b/src/widgets/graphicsview/qgraphicsview_p.h @@ -110,6 +110,7 @@ public: QPoint mousePressViewPoint; QPoint mousePressScreenPoint; QPointF lastMouseMoveScenePoint; + QPointF lastRubberbandScenePoint; QPoint lastMouseMoveScreenPoint; QPoint dirtyScrollOffset; Qt::MouseButton mousePressButton; @@ -138,7 +139,7 @@ public: #ifndef QT_NO_RUBBERBAND QRect rubberBandRect; QRegion rubberBandRegion(const QWidget *widget, const QRect &rect) const; - void updateRubberBand(QMouseEvent *event); + void updateRubberBand(const QMouseEvent *event); bool rubberBanding; Qt::ItemSelectionMode rubberBandSelectionMode; #endif diff --git a/src/widgets/graphicsview/qgraphicswidget.h b/src/widgets/graphicsview/qgraphicswidget.h index 3f8720f6e9..66cce3d961 100644 --- a/src/widgets/graphicsview/qgraphicswidget.h +++ b/src/widgets/graphicsview/qgraphicswidget.h @@ -47,8 +47,6 @@ #include <QtWidgets/qgraphicsitem.h> #include <QtGui/qpalette.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -245,7 +243,5 @@ inline void QGraphicsWidget::setGeometry(qreal ax, qreal ay, qreal aw, qreal ah) QT_END_NAMESPACE -QT_END_HEADER - #endif diff --git a/src/widgets/graphicsview/qgraphicswidget_p.cpp b/src/widgets/graphicsview/qgraphicswidget_p.cpp index e97ec90cd0..4101615fb3 100644 --- a/src/widgets/graphicsview/qgraphicswidget_p.cpp +++ b/src/widgets/graphicsview/qgraphicswidget_p.cpp @@ -764,73 +764,59 @@ bool QGraphicsWidgetPrivate::hasDecoration() const void QGraphicsWidgetPrivate::fixFocusChainBeforeReparenting(QGraphicsWidget *newParent, QGraphicsScene *oldScene, QGraphicsScene *newScene) { Q_Q(QGraphicsWidget); - Q_ASSERT(focusNext && focusPrev); - QGraphicsWidget *n = q; //last one in 'new' list - QGraphicsWidget *o = 0; //last one in 'old' list - - QGraphicsWidget *w = focusNext; - - QGraphicsWidget *firstOld = 0; - bool wasPreviousNew = true; - - while (w != q) { - bool isCurrentNew = q->isAncestorOf(w); - if (isCurrentNew) { - if (!wasPreviousNew) { - n->d_func()->focusNext = w; - w->d_func()->focusPrev = n; - } - n = w; - } else /*if (!isCurrentNew)*/ { - if (wasPreviousNew) { - if (o) { - o->d_func()->focusNext = w; - w->d_func()->focusPrev = o; - } else { - firstOld = w; - } - } - o = w; - } - w = w->d_func()->focusNext; - wasPreviousNew = isCurrentNew; - } - - // repair the 'old' chain - if (firstOld) { - o->d_func()->focusNext = firstOld; - firstOld->d_func()->focusPrev = o; + if (q_ptr->isPanel()) { + // panels are never a part of their parent's or ancestors' focus + // chains. so reparenting a panel is easy; there's nothing to + // do. + return; } - // update tabFocusFirst for oldScene if the item is going to be removed from oldScene - if (newParent) - newScene = newParent->scene(); - - if (oldScene && newScene != oldScene) - oldScene->d_func()->tabFocusFirst = (firstOld && firstOld->scene() == oldScene) ? firstOld : 0; - - QGraphicsItem *topLevelItem = newParent ? newParent->topLevelItem() : 0; - QGraphicsWidget *topLevel = 0; - if (topLevelItem && topLevelItem->isWidget()) - topLevel = static_cast<QGraphicsWidget *>(topLevelItem); + // we're not a panel, so find the first widget in the focus chain + // (this), and the last (this, or the last widget that is still + // a descendent of this). also find the widgets that currently / + // before reparenting point to this widgets' focus chain. + QGraphicsWidget *focusFirst = q; + QGraphicsWidget *focusBefore = focusPrev; + QGraphicsWidget *focusLast = focusFirst; + QGraphicsWidget *focusAfter = focusNext; + do { + if (!q->isAncestorOf(focusAfter)) + break; + focusLast = focusAfter; + } while ((focusAfter = focusAfter->d_func()->focusNext)); - if (topLevel && newParent) { - QGraphicsWidget *last = topLevel->d_func()->focusPrev; - // link last with new chain - last->d_func()->focusNext = q; - focusPrev = last; + if (!parent && oldScene && oldScene != newScene && oldScene->d_func()->tabFocusFirst == q) { + // detach from old scene's top level focus chain. + oldScene->d_func()->tabFocusFirst = (focusAfter != q) ? focusAfter : 0; + } - // link last in chain with - topLevel->d_func()->focusPrev = n; - n->d_func()->focusNext = topLevel; + // detach from current focus chain; skip this widget subtree. + focusBefore->d_func()->focusNext = focusAfter; + focusAfter->d_func()->focusPrev = focusBefore; + + if (newParent) { + // attach to new parent's focus chain as the last element + // in its chain. + QGraphicsWidget *newFocusFirst = newParent; + QGraphicsWidget *newFocusLast = newFocusFirst; + QGraphicsWidget *newFocusAfter = newFocusFirst->d_func()->focusNext; + do { + if (!newParent->isAncestorOf(newFocusAfter)) + break; + newFocusLast = newFocusAfter; + } while ((newFocusAfter = newFocusAfter->d_func()->focusNext)); + + newFocusLast->d_func()->focusNext = q; + focusLast->d_func()->focusNext = newFocusAfter; + newFocusAfter->d_func()->focusPrev = focusLast; + focusPrev = newFocusLast; } else { - // q is the start of the focus chain - n->d_func()->focusNext = q; - focusPrev = n; + // no new parent, so just link up our own prev->last widgets. + focusPrev = focusLast; + focusLast->d_func()->focusNext = q; } - } void QGraphicsWidgetPrivate::setLayout_helper(QGraphicsLayout *l) diff --git a/src/widgets/itemviews/qabstractitemdelegate.h b/src/widgets/itemviews/qabstractitemdelegate.h index 28635b0595..f72076b515 100644 --- a/src/widgets/itemviews/qabstractitemdelegate.h +++ b/src/widgets/itemviews/qabstractitemdelegate.h @@ -45,8 +45,6 @@ #include <QtCore/qobject.h> #include <QtWidgets/qstyleoption.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -131,6 +129,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QABSTRACTITEMDELEGATE_H diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index fa873b63a5..fdefeb7bb3 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -1853,7 +1853,8 @@ void QAbstractItemView::mouseReleaseEvent(QMouseEvent *event) QStyleOptionViewItem option = d->viewOptions(); if (d->pressedAlreadySelected) option.state |= QStyle::State_Selected; - if (style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, &option, this)) + if ((model()->flags(index) & Qt::ItemIsEnabled) + && style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick, &option, this)) emit activated(index); } } @@ -3816,13 +3817,31 @@ QItemSelectionModel::SelectionFlags QAbstractItemView::selectionCommand(const QM const QEvent *event) const { Q_D(const QAbstractItemView); + Qt::KeyboardModifiers keyModifiers = Qt::NoModifier; + if (event) { + switch (event->type()) { + case QEvent::MouseButtonDblClick: + case QEvent::MouseButtonPress: + case QEvent::MouseButtonRelease: + case QEvent::MouseMove: + case QEvent::KeyPress: + case QEvent::KeyRelease: + keyModifiers = (static_cast<const QInputEvent*>(event))->modifiers(); + break; + default: + keyModifiers = QApplication::keyboardModifiers(); + } + } switch (d->selectionMode) { case NoSelection: // Never update selection model return QItemSelectionModel::NoUpdate; case SingleSelection: // ClearAndSelect on valid index otherwise NoUpdate if (event && event->type() == QEvent::MouseButtonRelease) return QItemSelectionModel::NoUpdate; - return QItemSelectionModel::ClearAndSelect|d->selectionBehaviorFlags(); + if ((keyModifiers & Qt::ControlModifier) && d->selectionModel->isSelected(index)) + return QItemSelectionModel::Deselect | d->selectionBehaviorFlags(); + else + return QItemSelectionModel::ClearAndSelect | d->selectionBehaviorFlags(); case MultiSelection: return d->multiSelectionCommand(index, event); case ExtendedSelection: diff --git a/src/widgets/itemviews/qabstractitemview.h b/src/widgets/itemviews/qabstractitemview.h index ad5e1de562..b48047bdc3 100644 --- a/src/widgets/itemviews/qabstractitemview.h +++ b/src/widgets/itemviews/qabstractitemview.h @@ -47,8 +47,6 @@ #include <QtCore/qitemselectionmodel.h> #include <QtWidgets/qabstractitemdelegate.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -376,6 +374,4 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractItemView::EditTriggers) QT_END_NAMESPACE -QT_END_HEADER - #endif // QABSTRACTITEMVIEW_H diff --git a/src/widgets/itemviews/qcolumnview.h b/src/widgets/itemviews/qcolumnview.h index a340be0823..660b5f387e 100644 --- a/src/widgets/itemviews/qcolumnview.h +++ b/src/widgets/itemviews/qcolumnview.h @@ -44,8 +44,6 @@ #include <QtWidgets/qabstractitemview.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -116,7 +114,5 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QCOLUMNVIEW_H diff --git a/src/widgets/itemviews/qdatawidgetmapper.h b/src/widgets/itemviews/qdatawidgetmapper.h index d65d06a4ab..9fb9c2db05 100644 --- a/src/widgets/itemviews/qdatawidgetmapper.h +++ b/src/widgets/itemviews/qdatawidgetmapper.h @@ -46,8 +46,6 @@ #ifndef QT_NO_DATAWIDGETMAPPER -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -120,8 +118,6 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QT_NO_DATAWIDGETMAPPER #endif diff --git a/src/widgets/itemviews/qdirmodel.h b/src/widgets/itemviews/qdirmodel.h index 6ecd9a3990..45bc3511d8 100644 --- a/src/widgets/itemviews/qdirmodel.h +++ b/src/widgets/itemviews/qdirmodel.h @@ -46,8 +46,6 @@ #include <QtCore/qdir.h> #include <QtWidgets/qfileiconprovider.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -154,6 +152,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QDIRMODEL_H diff --git a/src/widgets/itemviews/qfileiconprovider.h b/src/widgets/itemviews/qfileiconprovider.h index a7a7d508ce..3a8a42f07b 100644 --- a/src/widgets/itemviews/qfileiconprovider.h +++ b/src/widgets/itemviews/qfileiconprovider.h @@ -46,8 +46,6 @@ #include <QtCore/qscopedpointer.h> #include <QtGui/qicon.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -75,7 +73,5 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QFILEICONPROVIDER_H diff --git a/src/widgets/itemviews/qheaderview.h b/src/widgets/itemviews/qheaderview.h index 4e2b7d24c6..1cbfc957a8 100644 --- a/src/widgets/itemviews/qheaderview.h +++ b/src/widgets/itemviews/qheaderview.h @@ -44,8 +44,6 @@ #include <QtWidgets/qabstractitemview.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -263,6 +261,4 @@ inline void QHeaderView::showSection(int alogicalIndex) QT_END_NAMESPACE -QT_END_HEADER - #endif // QHEADERVIEW_H diff --git a/src/widgets/itemviews/qitemdelegate.h b/src/widgets/itemviews/qitemdelegate.h index 17b0e94625..884a09e8c6 100644 --- a/src/widgets/itemviews/qitemdelegate.h +++ b/src/widgets/itemviews/qitemdelegate.h @@ -47,8 +47,6 @@ #include <QtGui/qpixmap.h> #include <QtCore/qvariant.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -135,6 +133,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QITEMDELEGATE_H diff --git a/src/widgets/itemviews/qitemeditorfactory.h b/src/widgets/itemviews/qitemeditorfactory.h index f52f4c5b64..5aed89fb70 100644 --- a/src/widgets/itemviews/qitemeditorfactory.h +++ b/src/widgets/itemviews/qitemeditorfactory.h @@ -47,8 +47,6 @@ #include <QtCore/qhash.h> #include <QtCore/qvariant.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -118,6 +116,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QITEMEDITORFACTORY_H diff --git a/src/widgets/itemviews/qlistview.h b/src/widgets/itemviews/qlistview.h index a7164142dd..ff880a889c 100644 --- a/src/widgets/itemviews/qlistview.h +++ b/src/widgets/itemviews/qlistview.h @@ -44,8 +44,6 @@ #include <QtWidgets/qabstractitemview.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -193,6 +191,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QLISTVIEW_H diff --git a/src/widgets/itemviews/qlistwidget.h b/src/widgets/itemviews/qlistwidget.h index 1a8c56c907..2cddd4eb6f 100644 --- a/src/widgets/itemviews/qlistwidget.h +++ b/src/widgets/itemviews/qlistwidget.h @@ -47,8 +47,6 @@ #include <QtCore/qvector.h> #include <QtCore/qitemselectionmodel.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -329,6 +327,4 @@ inline bool QListWidgetItem::isHidden() const QT_END_NAMESPACE -QT_END_HEADER - #endif // QLISTWIDGET_H diff --git a/src/widgets/itemviews/qstyleditemdelegate.h b/src/widgets/itemviews/qstyleditemdelegate.h index 8aa056d769..d88da60c89 100644 --- a/src/widgets/itemviews/qstyleditemdelegate.h +++ b/src/widgets/itemviews/qstyleditemdelegate.h @@ -47,8 +47,6 @@ #include <QtGui/qpixmap.h> #include <QtCore/qvariant.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -110,6 +108,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QSTYLEDITEMDELEGATE_H diff --git a/src/widgets/itemviews/qtableview.h b/src/widgets/itemviews/qtableview.h index 8f4c73d9f1..4d1129c60b 100644 --- a/src/widgets/itemviews/qtableview.h +++ b/src/widgets/itemviews/qtableview.h @@ -44,8 +44,6 @@ #include <QtWidgets/qabstractitemview.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -192,6 +190,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QTABLEVIEW_H diff --git a/src/widgets/itemviews/qtablewidget.h b/src/widgets/itemviews/qtablewidget.h index 6d9da27fdf..a6c355c6a6 100644 --- a/src/widgets/itemviews/qtablewidget.h +++ b/src/widgets/itemviews/qtablewidget.h @@ -47,8 +47,6 @@ #include <QtCore/qvector.h> //#include <QtWidgets/qitemselectionmodel.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -371,6 +369,4 @@ inline bool QTableWidgetItem::isSelected() const QT_END_NAMESPACE -QT_END_HEADER - #endif // QTABLEWIDGET_H diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index 6046ef50a5..8d0a578f61 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -52,6 +52,7 @@ #include <qevent.h> #include <qpen.h> #include <qdebug.h> +#include <QMetaMethod> #ifndef QT_NO_ACCESSIBILITY #include <qaccessible.h> #include <qaccessible2.h> @@ -749,6 +750,8 @@ void QTreeView::expand(const QModelIndex &index) Q_D(QTreeView); if (!d->isIndexValid(index)) return; + if (index.flags() & Qt::ItemNeverHasChildren) + return; if (d->delayedPendingLayout) { //A complete relayout is going to be performed, just store the expanded index, no need to layout. if (d->storeExpanded(index)) @@ -2644,7 +2647,17 @@ void QTreeView::expandAll() void QTreeView::collapseAll() { Q_D(QTreeView); + QSet<QPersistentModelIndex> old_expandedIndexes; + old_expandedIndexes = d->expandedIndexes; d->expandedIndexes.clear(); + if (!signalsBlocked() && isSignalConnected(QMetaMethod::fromSignal(&QTreeView::collapsed))) { + QSet<QPersistentModelIndex>::const_iterator i = old_expandedIndexes.constBegin(); + for (; i != old_expandedIndexes.constEnd(); ++i) { + const QPersistentModelIndex &mi = (*i); + if (mi.isValid() && !(mi.flags() & Qt::ItemNeverHasChildren)) + emit collapsed(mi); + } + } doItemsLayout(); } @@ -2658,6 +2671,8 @@ void QTreeView::expandToDepth(int depth) { Q_D(QTreeView); d->viewItems.clear(); + QSet<QPersistentModelIndex> old_expandedIndexes; + old_expandedIndexes = d->expandedIndexes; d->expandedIndexes.clear(); d->interruptDelayedItemsLayout(); d->layout(-1); @@ -2668,6 +2683,29 @@ void QTreeView::expandToDepth(int depth) d->storeExpanded(d->viewItems.at(i).index); } } + + bool someSignalEnabled = isSignalConnected(QMetaMethod::fromSignal(&QTreeView::collapsed)); + someSignalEnabled |= isSignalConnected(QMetaMethod::fromSignal(&QTreeView::expanded)); + + if (!signalsBlocked() && someSignalEnabled) { + // emit signals + QSet<QPersistentModelIndex> collapsedIndexes = old_expandedIndexes - d->expandedIndexes; + QSet<QPersistentModelIndex>::const_iterator i = collapsedIndexes.constBegin(); + for (; i != collapsedIndexes.constEnd(); ++i) { + const QPersistentModelIndex &mi = (*i); + if (mi.isValid() && !(mi.flags() & Qt::ItemNeverHasChildren)) + emit collapsed(mi); + } + + QSet<QPersistentModelIndex> expandedIndexs = d->expandedIndexes - old_expandedIndexes; + i = expandedIndexs.constBegin(); + for (; i != expandedIndexs.constEnd(); ++i) { + const QPersistentModelIndex &mi = (*i); + if (mi.isValid() && !(mi.flags() & Qt::ItemNeverHasChildren)) + emit expanded(mi); + } + } + updateGeometries(); d->viewport->update(); } @@ -2887,6 +2925,9 @@ void QTreeViewPrivate::expand(int item, bool emitSignal) if (item == -1 || viewItems.at(item).expanded) return; + const QModelIndex index = viewItems.at(item).index; + if (index.flags() & Qt::ItemNeverHasChildren) + return; #ifndef QT_NO_ANIMATION if (emitSignal && animationsEnabled) @@ -2896,7 +2937,6 @@ void QTreeViewPrivate::expand(int item, bool emitSignal) if (state != QAbstractItemView::AnimatingState) stateBeforeAnimation = state; q->setState(QAbstractItemView::ExpandingState); - const QModelIndex index = viewItems.at(item).index; storeExpanded(index); viewItems[item].expanded = true; layout(item); @@ -3189,9 +3229,9 @@ void QTreeViewPrivate::layout(int i, bool recursiveExpanding, bool afterIsUninit item->expanded = false; item->total = 0; item->hasMoreSiblings = false; - if (recursiveExpanding || isIndexExpanded(current)) { - if (recursiveExpanding) - expandedIndexes.insert(current); + if ((recursiveExpanding && !(current.flags() & Qt::ItemNeverHasChildren)) || isIndexExpanded(current)) { + if (recursiveExpanding && storeExpanded(current) && !q->signalsBlocked()) + emit q->expanded(current); item->expanded = true; layout(last, recursiveExpanding, afterIsUninitialized); item = &viewItems[last]; diff --git a/src/widgets/itemviews/qtreeview.h b/src/widgets/itemviews/qtreeview.h index 54e580985c..7127994969 100644 --- a/src/widgets/itemviews/qtreeview.h +++ b/src/widgets/itemviews/qtreeview.h @@ -44,8 +44,6 @@ #include <QtWidgets/qabstractitemview.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -235,6 +233,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QTREEVIEW_H diff --git a/src/widgets/itemviews/qtreeview_p.h b/src/widgets/itemviews/qtreeview_p.h index 5a0821c9cf..6778446ed3 100644 --- a/src/widgets/itemviews/qtreeview_p.h +++ b/src/widgets/itemviews/qtreeview_p.h @@ -203,7 +203,7 @@ public: inline bool isIndexExpanded(const QModelIndex &idx) const { //We first check if the idx is a QPersistentModelIndex, because creating QPersistentModelIndex is slow - return isPersistent(idx) && expandedIndexes.contains(idx); + return !(idx.flags() & Qt::ItemNeverHasChildren) && isPersistent(idx) && expandedIndexes.contains(idx); } // used when hiding and showing items diff --git a/src/widgets/itemviews/qtreewidget.h b/src/widgets/itemviews/qtreewidget.h index a16a1cd9c2..0796797273 100644 --- a/src/widgets/itemviews/qtreewidget.h +++ b/src/widgets/itemviews/qtreewidget.h @@ -47,8 +47,6 @@ #include <QtCore/qvariant.h> #include <QtCore/qvector.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -423,6 +421,4 @@ inline bool QTreeWidgetItem::isDisabled() const QT_END_NAMESPACE -QT_END_HEADER - #endif // QTREEWIDGET_H diff --git a/src/widgets/itemviews/qtreewidgetitemiterator.h b/src/widgets/itemviews/qtreewidgetitemiterator.h index ec604e8b1a..e124a72afd 100644 --- a/src/widgets/itemviews/qtreewidgetitemiterator.h +++ b/src/widgets/itemviews/qtreewidgetitemiterator.h @@ -45,8 +45,6 @@ #include <QtCore/qglobal.h> #include <QtCore/qscopedpointer.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -153,6 +151,4 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QTreeWidgetItemIterator::IteratorFlags) QT_END_NAMESPACE #endif // QT_NO_TREEWIDGET -QT_END_HEADER - #endif // QTREEWIDGETITEMITERATOR_H diff --git a/src/widgets/kernel/kernel.pri b/src/widgets/kernel/kernel.pri index 4d3d7c4e0a..533b696faa 100644 --- a/src/widgets/kernel/kernel.pri +++ b/src/widgets/kernel/kernel.pri @@ -34,7 +34,8 @@ HEADERS += \ kernel/qgesturerecognizer.h \ kernel/qgesturemanager_p.h \ kernel/qdesktopwidget_qpa_p.h \ - kernel/qwidgetwindow_qpa_p.h + kernel/qwidgetwindow_qpa_p.h \ + kernel/qwindowcontainer_p.h SOURCES += \ kernel/qaction.cpp \ @@ -62,7 +63,8 @@ SOURCES += \ kernel/qapplication_qpa.cpp \ kernel/qdesktopwidget_qpa.cpp \ kernel/qwidget_qpa.cpp \ - kernel/qwidgetwindow.cpp + kernel/qwidgetwindow.cpp \ + kernel/qwindowcontainer.cpp # TODO diff --git a/src/widgets/kernel/mac.pri b/src/widgets/kernel/mac.pri index 5474a41f15..4c507ae80e 100644 --- a/src/widgets/kernel/mac.pri +++ b/src/widgets/kernel/mac.pri @@ -1,4 +1,4 @@ -!x11::mac { +!x11:mac:!ios { LIBS_PRIVATE += -framework Carbon -framework Cocoa -lz *-mwerks:INCLUDEPATH += compat } diff --git a/src/widgets/kernel/qaction.h b/src/widgets/kernel/qaction.h index 5fb4c655eb..975073201a 100644 --- a/src/widgets/kernel/qaction.h +++ b/src/widgets/kernel/qaction.h @@ -48,8 +48,6 @@ #include <QtCore/qvariant.h> #include <QtGui/qicon.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -221,6 +219,4 @@ QT_END_INCLUDE_NAMESPACE QT_END_NAMESPACE -QT_END_HEADER - #endif // QACTION_H diff --git a/src/widgets/kernel/qactiongroup.h b/src/widgets/kernel/qactiongroup.h index 13c5ea8ef1..747cc83865 100644 --- a/src/widgets/kernel/qactiongroup.h +++ b/src/widgets/kernel/qactiongroup.h @@ -44,8 +44,6 @@ #include <QtWidgets/qaction.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -99,6 +97,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QACTIONGROUP_H diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 4c6d8cfdc7..cff75f258e 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -3560,8 +3560,8 @@ int QApplication::doubleClickInterval() \since 4.2 \deprecated - Returns the current keyboard input direction. Replaced with QInputPanel::inputDirection() - \sa QInputPanel::inputDirection() + Returns the current keyboard input direction. Replaced with QInputMethod::inputDirection() + \sa QInputMethod::inputDirection() */ /*! diff --git a/src/widgets/kernel/qapplication.h b/src/widgets/kernel/qapplication.h index 29f5ddf455..07ee638738 100644 --- a/src/widgets/kernel/qapplication.h +++ b/src/widgets/kernel/qapplication.h @@ -55,8 +55,6 @@ #endif #include <QtGui/qguiapplication.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -247,6 +245,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QAPPLICATION_H diff --git a/src/widgets/kernel/qboxlayout.h b/src/widgets/kernel/qboxlayout.h index 3ced397c1d..dabb96ccd8 100644 --- a/src/widgets/kernel/qboxlayout.h +++ b/src/widgets/kernel/qboxlayout.h @@ -49,8 +49,6 @@ #include <limits.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -141,6 +139,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QBOXLAYOUT_H diff --git a/src/widgets/kernel/qdesktopwidget.h b/src/widgets/kernel/qdesktopwidget.h index c27e96a2d9..d823e3ce47 100644 --- a/src/widgets/kernel/qdesktopwidget.h +++ b/src/widgets/kernel/qdesktopwidget.h @@ -44,8 +44,6 @@ #include <QtWidgets/qwidget.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -104,6 +102,4 @@ inline int QDesktopWidget::screenCount() const QT_END_NAMESPACE -QT_END_HEADER - #endif // QDESKTOPWIDGET_H diff --git a/src/widgets/kernel/qformlayout.h b/src/widgets/kernel/qformlayout.h index a206e90009..29abc6b548 100644 --- a/src/widgets/kernel/qformlayout.h +++ b/src/widgets/kernel/qformlayout.h @@ -44,8 +44,6 @@ #include <QtWidgets/QLayout> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -157,6 +155,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif diff --git a/src/widgets/kernel/qgesture.h b/src/widgets/kernel/qgesture.h index 4384600f80..a9609ffad9 100644 --- a/src/widgets/kernel/qgesture.h +++ b/src/widgets/kernel/qgesture.h @@ -52,8 +52,6 @@ #ifndef QT_NO_GESTURES -QT_BEGIN_HEADER - Q_DECLARE_METATYPE(Qt::GestureState) Q_DECLARE_METATYPE(Qt::GestureType) @@ -328,8 +326,6 @@ private: QT_END_NAMESPACE Q_DECLARE_METATYPE(QGesture::GestureCancelPolicy) -QT_END_HEADER - #endif // QT_NO_GESTURES #endif // QGESTURE_H diff --git a/src/widgets/kernel/qgesturerecognizer.h b/src/widgets/kernel/qgesturerecognizer.h index b85aa54a6b..e313920f0a 100644 --- a/src/widgets/kernel/qgesturerecognizer.h +++ b/src/widgets/kernel/qgesturerecognizer.h @@ -47,8 +47,6 @@ #ifndef QT_NO_GESTURES -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -94,8 +92,6 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QGestureRecognizer::Result) QT_END_NAMESPACE -QT_END_HEADER - #endif // QT_NO_GESTURES #endif // QGESTURERECOGNIZER_H diff --git a/src/widgets/kernel/qgridlayout.h b/src/widgets/kernel/qgridlayout.h index 9349c7807d..39c26619c3 100644 --- a/src/widgets/kernel/qgridlayout.h +++ b/src/widgets/kernel/qgridlayout.h @@ -49,8 +49,6 @@ #include <limits.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -132,6 +130,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QGRIDLAYOUT_H diff --git a/src/widgets/kernel/qlayout.h b/src/widgets/kernel/qlayout.h index 09ddebeb2a..3f09419b05 100644 --- a/src/widgets/kernel/qlayout.h +++ b/src/widgets/kernel/qlayout.h @@ -50,8 +50,6 @@ #include <limits.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -171,6 +169,4 @@ QT_END_NAMESPACE #include <QtWidgets/qboxlayout.h> #include <QtWidgets/qgridlayout.h> -QT_END_HEADER - #endif // QLAYOUT_H diff --git a/src/widgets/kernel/qlayoutitem.h b/src/widgets/kernel/qlayoutitem.h index b19a7c789f..808cc9ff5d 100644 --- a/src/widgets/kernel/qlayoutitem.h +++ b/src/widgets/kernel/qlayoutitem.h @@ -47,12 +47,10 @@ #include <limits.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE -static const int QLAYOUTSIZE_MAX = INT_MAX/256/16; +static const Q_DECL_UNUSED int QLAYOUTSIZE_MAX = INT_MAX/256/16; class QLayout; class QLayoutItem; @@ -180,6 +178,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QLAYOUTITEM_H diff --git a/src/widgets/kernel/qshortcut.h b/src/widgets/kernel/qshortcut.h index f5daa381f7..001c6814ee 100644 --- a/src/widgets/kernel/qshortcut.h +++ b/src/widgets/kernel/qshortcut.h @@ -45,8 +45,6 @@ #include <QtWidgets/qwidget.h> #include <QtGui/qkeysequence.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -101,6 +99,4 @@ protected: QT_END_NAMESPACE -QT_END_HEADER - #endif // QSHORTCUT_H diff --git a/src/widgets/kernel/qsizepolicy.h b/src/widgets/kernel/qsizepolicy.h index 0a878674cc..383c7d0512 100644 --- a/src/widgets/kernel/qsizepolicy.h +++ b/src/widgets/kernel/qsizepolicy.h @@ -44,8 +44,6 @@ #include <QtCore/qobject.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -183,6 +181,4 @@ inline void QSizePolicy::transpose() { QT_END_NAMESPACE -QT_END_HEADER - #endif // QSIZEPOLICY_H diff --git a/src/widgets/kernel/qstackedlayout.h b/src/widgets/kernel/qstackedlayout.h index a8067b5bab..5067f4e457 100644 --- a/src/widgets/kernel/qstackedlayout.h +++ b/src/widgets/kernel/qstackedlayout.h @@ -44,8 +44,6 @@ #include <QtWidgets/qlayout.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -111,6 +109,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QSTACKEDLAYOUT_H diff --git a/src/widgets/kernel/qtooltip.h b/src/widgets/kernel/qtooltip.h index 3a09803598..c7fb9809dc 100644 --- a/src/widgets/kernel/qtooltip.h +++ b/src/widgets/kernel/qtooltip.h @@ -44,8 +44,6 @@ #include <QtWidgets/qwidget.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -72,6 +70,4 @@ public: QT_END_NAMESPACE -QT_END_HEADER - #endif // QTOOLTIP_H diff --git a/src/widgets/kernel/qwhatsthis.h b/src/widgets/kernel/qwhatsthis.h index 7e41e5ab58..80a8be5227 100644 --- a/src/widgets/kernel/qwhatsthis.h +++ b/src/widgets/kernel/qwhatsthis.h @@ -45,8 +45,6 @@ #include <QtCore/qobject.h> #include <QtGui/qcursor.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -74,6 +72,4 @@ public: QT_END_NAMESPACE -QT_END_HEADER - #endif // QWHATSTHIS_H diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index f82d33f283..e5df25e972 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -354,6 +354,7 @@ void QWidgetPrivate::updateWidgetTransform() QPoint p = q->mapTo(q->topLevelWidget(), QPoint(0,0)); t.translate(p.x(), p.y()); qApp->inputMethod()->setInputItemTransform(t); + qApp->inputMethod()->setInputItemRectangle(q->rect()); } } @@ -8575,6 +8576,10 @@ void QWidget::focusOutEvent(QFocusEvent *) { if (focusPolicy() != Qt::NoFocus || !isWindow()) update(); + + // automatically hide the SIP + if (qApp->autoSipEnabled() && testAttribute(Qt::WA_InputMethodEnabled)) + qApp->inputMethod()->hide(); } /*! @@ -8797,7 +8802,7 @@ void QWidget::inputMethodEvent(QInputMethodEvent *event) \a query specifies which property is queried. - \sa inputMethodEvent(), QInputMethodEven, inputMethodHints + \sa inputMethodEvent(), QInputMethodEvent, QInputMethodQueryEvent, inputMethodHints */ QVariant QWidget::inputMethodQuery(Qt::InputMethodQuery query) const { @@ -9097,7 +9102,7 @@ QLayout *QWidget::layout() const existing layout manager (returned by layout()) before you can call setLayout() with the new layout. - If \a layout is the layout manger on a different widget, setLayout() + If \a layout is the layout manager on a different widget, setLayout() will reparent the layout and make it the layout manager for this widget. Example: diff --git a/src/widgets/kernel/qwidget.h b/src/widgets/kernel/qwidget.h index 25dac1ed5e..5965eb8601 100644 --- a/src/widgets/kernel/qwidget.h +++ b/src/widgets/kernel/qwidget.h @@ -60,8 +60,6 @@ #include <QtGui/qevent.h> #endif -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -593,6 +591,8 @@ public: QWindow *windowHandle() const; + static QWidget *createWindowContainer(QWindow *window, QWidget *parent=0, Qt::WindowFlags flags=0); + friend class QDesktopScreenWidget; Q_SIGNALS: @@ -855,6 +855,4 @@ inline bool QWidget::testAttribute(Qt::WidgetAttribute attribute) const QT_END_NAMESPACE -QT_END_HEADER - #endif // QWIDGET_H diff --git a/src/widgets/kernel/qwidget_qpa.cpp b/src/widgets/kernel/qwidget_qpa.cpp index 2ffe9c5de5..b65ce29b84 100644 --- a/src/widgets/kernel/qwidget_qpa.cpp +++ b/src/widgets/kernel/qwidget_qpa.cpp @@ -989,6 +989,12 @@ static inline void applyCursor(QWidget *w, QCursor c) window->setCursor(c); } +static inline void unsetCursor(QWidget *w) +{ + if (QWindow *window = w->windowHandle()) + window->unsetCursor(); +} + void qt_qpa_set_cursor(QWidget *w, bool force) { if (!w->testAttribute(Qt::WA_WState_Created)) @@ -1022,9 +1028,9 @@ void qt_qpa_set_cursor(QWidget *w, bool force) else // Enforce the windows behavior of clearing the cursor on // disabled widgets. - applyCursor(nativeParent, Qt::ArrowCursor); + unsetCursor(nativeParent); } else { - applyCursor(nativeParent, Qt::ArrowCursor); + unsetCursor(nativeParent); } } #endif //QT_NO_CURSOR diff --git a/src/widgets/kernel/qwidgetaction.h b/src/widgets/kernel/qwidgetaction.h index 14f1bfaf7f..3956445bc8 100644 --- a/src/widgets/kernel/qwidgetaction.h +++ b/src/widgets/kernel/qwidgetaction.h @@ -44,8 +44,6 @@ #include <QtWidgets/qaction.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -85,6 +83,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QWIDGETACTION_H diff --git a/src/widgets/kernel/qwidgetsfunctions_wince.h b/src/widgets/kernel/qwidgetsfunctions_wince.h index 5d3640ae75..cc8c1e4a03 100644 --- a/src/widgets/kernel/qwidgetsfunctions_wince.h +++ b/src/widgets/kernel/qwidgetsfunctions_wince.h @@ -44,10 +44,8 @@ #include <QtCore/qfunctions_wince.h> #ifdef QT_BUILD_GUI_LIB -QT_BEGIN_HEADER QT_BEGIN_NAMESPACE QT_END_NAMESPACE -QT_END_HEADER #endif diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp index 50b61beb05..c543303024 100644 --- a/src/widgets/kernel/qwidgetwindow.cpp +++ b/src/widgets/kernel/qwidgetwindow.cpp @@ -352,6 +352,27 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event) && qt_replay_popup_mouse_event) { if (m_widget->windowType() != Qt::Popup) qt_button_down = 0; + if (event->type() == QEvent::MouseButtonPress) { + // the popup disappeared, replay the mouse press event + QWidget *w = QApplication::widgetAt(event->globalPos()); + if (w && !QApplicationPrivate::isBlockedByModal(w)) { + // activate window of the widget under mouse pointer + if (!w->isActiveWindow()) { + w->activateWindow(); + w->raise(); + } + + QWindow *win = w->windowHandle(); + if (!win) + win = w->nativeParentWidget()->windowHandle(); + if (win && win->geometry().contains(event->globalPos())) { + const QPoint localPos = win->mapFromGlobal(event->globalPos()); + QMouseEvent e(QEvent::MouseButtonPress, localPos, localPos, event->globalPos(), event->button(), event->buttons(), event->modifiers()); + e.setTimestamp(event->timestamp()); + QApplication::sendSpontaneousEvent(win, &e); + } + } + } qt_replay_popup_mouse_event = false; #ifndef QT_NO_CONTEXTMENU } else if (event->type() == QEvent::MouseButtonPress diff --git a/src/widgets/kernel/qwidgetwindow_qpa_p.h b/src/widgets/kernel/qwidgetwindow_qpa_p.h index 7e40ded8c8..84c1b90826 100644 --- a/src/widgets/kernel/qwidgetwindow_qpa_p.h +++ b/src/widgets/kernel/qwidgetwindow_qpa_p.h @@ -47,8 +47,6 @@ #include <QtCore/private/qobject_p.h> #include <QtGui/private/qevent_p.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -111,6 +109,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QWIDGETWINDOW_QPA_P_H diff --git a/src/widgets/kernel/qwindowcontainer.cpp b/src/widgets/kernel/qwindowcontainer.cpp new file mode 100644 index 0000000000..81322f49b4 --- /dev/null +++ b/src/widgets/kernel/qwindowcontainer.cpp @@ -0,0 +1,218 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwindowcontainer_p.h" +#include "qwidget_p.h" +#include <QtGui/qwindow.h> + +QT_BEGIN_NAMESPACE + +class QWindowContainerPrivate : public QWidgetPrivate +{ +public: + Q_DECLARE_PUBLIC(QWindowContainer) + + QWindowContainerPrivate() : window(0), oldFocusWindow(0) { } + ~QWindowContainerPrivate() { } + + QPointer<QWindow> window; + QWindow *oldFocusWindow; +}; + + + +/*! + \fn QWidget *QWidget::createWindowContainer(QWindow *window, QWidget *parent, Qt::WindowFlags flags); + + Creates a QWidget that makes it possible to embed \a window into + a QWidget-based application. + + The window container is created as a child of \a parent and with + window flags \a flags. + + Once the window has been embedded into the container, the + container will control the window's geometry and + visibility. Explicit calls to QWindow::setGeometry(), + QWindow::show() or QWindow::hide() on an embedded window is not + recommended. + + The container takes over ownership of \a window. The window can + be removed from the window container with a call to + QWindow::setParent(). + + The window container has a number of known limitations: + + \list + + \li Stacking order; The embedded window will stack on top of the + widget hierarchy as an opaque box. The stacking order of multiple + overlapping window container instances is undefined. + + \li Window Handles; The window container will explicitly invoke + winId() which will force the use of native window handles + inside the application. See \l {Native Widgets vs Alien Widgets} + {QWidget documentation} for more details. + + \li Rendering Integration; The window container does not interoperate + with QGraphicsProxyWidget, QWidget::render() or similar functionality. + + \li Focus Handling; It is possible to let the window container + instance have any focus policy and it will delegate focus to the + window via a call to QWindow::requestActivate(). However, + returning to the normal focus chain from the QWindow instance will + be up to the QWindow instance implementation itself. For instance, + when entering a Qt Quick based window with tab focus, it is quite + likely that further tab presses will only cycle inside the QML + application. Also, whether QWindow::requestActivate() actually + gives the window focus, is platform dependent. + + \li Using many window container instances in a QWidget-based + application can greatly hurt the overall performance of the + application. + + \endlist + */ + +QWidget *QWidget::createWindowContainer(QWindow *window, QWidget *parent, Qt::WindowFlags flags) +{ + return new QWindowContainer(window, parent, flags); +} + + + +/*! + \internal + */ + +QWindowContainer::QWindowContainer(QWindow *embeddedWindow, QWidget *parent, Qt::WindowFlags flags) + : QWidget(*new QWindowContainerPrivate, parent, flags) +{ + Q_D(QWindowContainer); + if (!embeddedWindow) { + qWarning("QWindowContainer: embedded window cannot be null"); + return; + } + + d->window = embeddedWindow; + + // We force this window to become a native window and reparent the + // window directly to it. This is done so that the order in which + // the QWindowContainer is added to a QWidget tree and when it + // gets a window does not matter. + winId(); + d->window->setParent(windowHandle()); + + connect(QGuiApplication::instance(), SIGNAL(focusWindowChanged(QWindow *)), this, SLOT(focusWindowChanged(QWindow *))); +} + + + +/*! + \internal + */ + +QWindowContainer::~QWindowContainer() +{ + Q_D(QWindowContainer); + delete d->window; +} + + + +/*! + \internal + */ + +void QWindowContainer::focusWindowChanged(QWindow *focusWindow) +{ + Q_D(QWindowContainer); + d->oldFocusWindow = focusWindow; +} + + + +/*! + \internal + */ + +bool QWindowContainer::event(QEvent *e) +{ + Q_D(QWindowContainer); + if (!d->window) + return QWidget::event(e); + + QEvent::Type type = e->type(); + switch (type) { + case QEvent::ChildRemoved: { + QChildEvent *ce = static_cast<QChildEvent *>(e); + if (ce->child() == d->window) + d->window = 0; + break; + } + // The only thing we are interested in is making sure our sizes stay + // in sync, so do a catch-all case. + case QEvent::Resize: + case QEvent::Move: + case QEvent::PolishRequest: + d->window->setGeometry(0, 0, width(), height()); + break; + case QEvent::Show: + d->window->show(); + break; + case QEvent::Hide: + d->window->hide(); + break; + case QEvent::FocusIn: + if (d->oldFocusWindow != d->window) { + d->window->requestActivate(); + } else { + QWidget *next = nextInFocusChain(); + next->setFocus(); + } + break; + default: + break; + } + + return QWidget::event(e); +} + +QT_END_NAMESPACE diff --git a/src/widgets/kernel/qwindowcontainer_p.h b/src/widgets/kernel/qwindowcontainer_p.h new file mode 100644 index 0000000000..e8d089c9bd --- /dev/null +++ b/src/widgets/kernel/qwindowcontainer_p.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWINDOWCONTAINER_H +#define QWINDOWCONTAINER_H + +#include <QtWidgets/qwidget.h> + +QT_BEGIN_NAMESPACE + +class QWindowContainerPrivate; + +class QWindowContainer : public QWidget +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QWindowContainer) + +public: + explicit QWindowContainer(QWindow *embeddedWindow, QWidget *parent = 0, Qt::WindowFlags f = 0); + ~QWindowContainer(); + +protected: + bool event(QEvent *ev); + +private slots: + void focusWindowChanged(QWindow *focusWindow); +}; + +QT_END_NAMESPACE + +#endif // QWINDOWCONTAINER_H diff --git a/src/widgets/statemachine/qkeyeventtransition.h b/src/widgets/statemachine/qkeyeventtransition.h index 9be5a67c0f..d2ea7cb93a 100644 --- a/src/widgets/statemachine/qkeyeventtransition.h +++ b/src/widgets/statemachine/qkeyeventtransition.h @@ -44,8 +44,6 @@ #include <QtCore/qeventtransition.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -82,6 +80,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif diff --git a/src/widgets/statemachine/qmouseeventtransition.h b/src/widgets/statemachine/qmouseeventtransition.h index b215df8bc1..b96f1ef542 100644 --- a/src/widgets/statemachine/qmouseeventtransition.h +++ b/src/widgets/statemachine/qmouseeventtransition.h @@ -44,8 +44,6 @@ #include <QtCore/qeventtransition.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -86,6 +84,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif diff --git a/src/widgets/styles/qandroidstyle.cpp b/src/widgets/styles/qandroidstyle.cpp new file mode 100644 index 0000000000..a3c1063b41 --- /dev/null +++ b/src/widgets/styles/qandroidstyle.cpp @@ -0,0 +1,1601 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra <bogdan@kde.org> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWidgets module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qandroidstyle_p.h" + +#if !defined(QT_NO_STYLE_ANDROID) || defined(QT_PLUGIN) + +#include <QFile> +#include <QFont> +#include <QApplication> +#include <QTime> +#include <qdrawutil.h> +#include <QPixmapCache> +#include <QFileInfo> +#include <QStyleOption> +#include <QPainter> +#include <QJsonDocument> +#include <QJsonObject> + +#include <QDebug> + +QT_BEGIN_NAMESPACE + +namespace { + const int textStyle_bold = 1; + const int textStyle_italic = 2; + + const int typeface_sans = 1; + const int typeface_serif = 2; + const int typeface_monospace = 3; + + const quint32 NO_COLOR = 1; + const quint32 TRANSPARENT_COLOR = 0; +} + + +QAndroidStyle::QAndroidStyle() + : QCommonStyle() +{ + QString stylePath(QLatin1String(qgetenv("MINISTRO_ANDROID_STYLE_PATH"))); + + if (stylePath.isEmpty()) + stylePath = QLatin1String("/data/data/org.kde.necessitas.ministro/files/qt/style/"); + Q_ASSERT(!stylePath.isEmpty()); + + QFile f(stylePath + QLatin1String("style.json")); + if (!f.open(QIODevice::ReadOnly)) + return; + + QJsonParseError error; + QJsonDocument document = QJsonDocument::fromJson(f.readAll(), &error); + if (document.isNull()) { + qCritical() << error.errorString(); + return; + } + + if (!document.isObject()) { + qCritical() << "Style.json does not contain a valid style."; + return; + } + + QJsonObject object = document.object(); + for (QJsonObject::const_iterator objectIterator = object.constBegin(); + objectIterator != object.constEnd(); + ++objectIterator) { + QString key = objectIterator.key(); + QJsonValue value = objectIterator.value(); + if (!value.isObject()) { + qWarning("Style.json structure is unrecognized."); + continue; + } + + QJsonObject item = value.toObject(); + QJsonObject::const_iterator attributeIterator = item.find(QLatin1String("qtClass")); + if (attributeIterator != item.constEnd()) { + // The item has palette and font information for a specific Qt Class (e.g. QWidget, QPushButton, etc.) + const QString qtClassName = attributeIterator.value().toString(); + + // Extract font information + QFont font; + + // Font size (in pixels) + attributeIterator = item.find(QLatin1String("TextAppearance_textSize")); + if (attributeIterator != item.constEnd()) + font.setPixelSize(int(attributeIterator.value().toDouble())); + + // Font style + attributeIterator = item.find(QLatin1String("TextAppearance_textStyle")); + if (attributeIterator != item.constEnd()) { + const int style = int(attributeIterator.value().toDouble()); + font.setBold(style & textStyle_bold); + font.setItalic(style & textStyle_italic); + } + + // Font typeface + attributeIterator = item.find(QLatin1String("TextAppearance_typeface")); + if (attributeIterator != item.constEnd()) { + QFont::StyleHint styleHint = QFont::AnyStyle; + switch (int(attributeIterator.value().toDouble())) { + case typeface_sans: + styleHint = QFont::SansSerif; + break; + case typeface_serif: + styleHint = QFont::Serif; + break; + case typeface_monospace: + styleHint = QFont::Monospace; + break; + } + font.setStyleHint(styleHint, QFont::PreferMatch); + } + QApplication::setFont(font, qtClassName.toUtf8()); + // Extract font information + + // Extract palette information + QPalette palette; + attributeIterator = item.find(QLatin1String("TextAppearance_textColor")); + if (attributeIterator != item.constEnd()) + setPaletteColor(attributeIterator.value().toObject().toVariantMap(), palette, QPalette::WindowText); + + attributeIterator = item.find(QLatin1String("TextAppearance_textColorLink")); + if (attributeIterator != item.constEnd()) + setPaletteColor(attributeIterator.value().toObject().toVariantMap(), palette, QPalette::Link); + + attributeIterator = item.find(QLatin1String("TextAppearance_textColorHighlight")); + if (attributeIterator != item.constEnd()) + palette.setColor(QPalette::Highlight, QRgb(int(attributeIterator.value().toDouble()))); + palette.setColor(QPalette::Window, Qt::black); + QApplication::setPalette(palette, qtClassName.toUtf8()); + if (QLatin1String("QWidget") == qtClassName) + m_standardPalette = palette; + // Extract palette information + } + QAndroidStyle::ItemType itemType = qtControl(key); + if (QC_UnknownType == itemType) + continue; + + switch (itemType) { + case QC_Checkbox: + case QC_RadioButton: + m_androidControlsHash[int(itemType)] = new AndroidCompoundButtonControl(item.toVariantMap(), + itemType); + break; + + case QC_ProgressBar: + m_androidControlsHash[int(itemType)] = new AndroidProgressBarControl(item.toVariantMap(), + itemType); + break; + + case QC_Slider: + m_androidControlsHash[int(itemType)] = new AndroidSeekBarControl(item.toVariantMap(), + itemType); + break; + + case QC_Combobox: + m_androidControlsHash[int(itemType)] = new AndroidSpinnerControl(item.toVariantMap(), + itemType); + break; + + default: + m_androidControlsHash[int(itemType)] = new AndroidControl(item.toVariantMap(), + itemType); + break; + } + } + QApplication::setPalette(QApplication::palette("simple_list_item"), "QListView"); + QApplication::setFont(QApplication::font("simple_list_item"), "QListView"); + QApplication::setPalette(QApplication::palette("simple_list_item"), "QAbstractItemView"); + QApplication::setFont(QApplication::font("simple_list_item"), "QAbstractItemView"); +} + +QAndroidStyle::~QAndroidStyle() +{ + qDeleteAll(m_androidControlsHash); +} + + +void QAndroidStyle::setPaletteColor(const QVariantMap &object, + QPalette &palette, + QPalette::ColorRole role) +{ + // QPalette::Active -> ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET + palette.setColor(QPalette::Active, + role, + QRgb(object.value(QLatin1String("ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET")).toInt())); + + // QPalette::Inactive -> ENABLED_STATE_SET + palette.setColor(QPalette::Inactive, + role, + QRgb(object.value(QLatin1String("ENABLED_STATE_SET")).toInt())); + + // QPalette::Disabled -> EMPTY_STATE_SET + palette.setColor(QPalette::Disabled, + role, + QRgb(object.value(QLatin1String("EMPTY_STATE_SET")).toInt())); + + palette.setColor(QPalette::Current, role, palette.color(QPalette::Active, role)); + + if (role == QPalette::WindowText) { + // QPalette::BrightText -> PRESSED + // QPalette::Active -> PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET + palette.setColor(QPalette::Active, + QPalette::BrightText, + QRgb(object.value(QLatin1String("PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET")).toInt())); + + // QPalette::Inactive -> PRESSED_ENABLED_STATE_SET + palette.setColor(QPalette::Inactive, + QPalette::BrightText, + QRgb(object.value(QLatin1String("PRESSED_ENABLED_STATE_SET")).toInt())); + + // QPalette::Disabled -> PRESSED_STATE_SET + palette.setColor(QPalette::Disabled, + QPalette::BrightText, + QRgb(object.value(QLatin1String("PRESSED_STATE_SET")).toInt())); + + palette.setColor(QPalette::Current, QPalette::BrightText, palette.color(QPalette::Active, QPalette::BrightText)); + + // QPalette::HighlightedText -> SELECTED + // QPalette::Active -> ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET + palette.setColor(QPalette::Active, + QPalette::HighlightedText, + QRgb(object.value(QLatin1String("ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET")).toInt())); + + // QPalette::Inactive -> ENABLED_SELECTED_STATE_SET + palette.setColor(QPalette::Inactive, + QPalette::HighlightedText, + QRgb(object.value(QLatin1String("ENABLED_SELECTED_STATE_SET")).toInt())); + + // QPalette::Disabled -> SELECTED_STATE_SET + palette.setColor(QPalette::Disabled, + QPalette::HighlightedText, + QRgb(object.value(QLatin1String("SELECTED_STATE_SET")).toInt())); + + palette.setColor(QPalette::Current, + QPalette::HighlightedText, + palette.color(QPalette::Active, QPalette::HighlightedText)); + + // Same colors for Text + palette.setColor(QPalette::Active, QPalette::Text, palette.color(QPalette::Active, role)); + palette.setColor(QPalette::Inactive, QPalette::Text, palette.color(QPalette::Inactive, role)); + palette.setColor(QPalette::Disabled, QPalette::Text, palette.color(QPalette::Disabled, role)); + palette.setColor(QPalette::Current, QPalette::Text, palette.color(QPalette::Current, role)); + + // And for ButtonText + palette.setColor(QPalette::Active, QPalette::ButtonText, palette.color(QPalette::Active, role)); + palette.setColor(QPalette::Inactive, QPalette::ButtonText, palette.color(QPalette::Inactive, role)); + palette.setColor(QPalette::Disabled, QPalette::ButtonText, palette.color(QPalette::Disabled, role)); + palette.setColor(QPalette::Current, QPalette::ButtonText, palette.color(QPalette::Current, role)); + } +} + +QAndroidStyle::ItemType QAndroidStyle::qtControl(const QString &android) +{ + if (android == QLatin1String("buttonStyle")) + return QC_Button; + if (android == QLatin1String("editTextStyle")) + return QC_EditText; + if (android == QLatin1String("radioButtonStyle")) + return QC_RadioButton; + if (android == QLatin1String("checkboxStyle")) + return QC_Checkbox; + if (android == QLatin1String("textViewStyle")) + return QC_View; + if (android == QLatin1String("buttonStyleToggle")) + return QC_Switch; + if (android == QLatin1String("spinnerStyle")) + return QC_Combobox; + if (android == QLatin1String("progressBarStyleHorizontal")) + return QC_ProgressBar; + if (android == QLatin1String("seekBarStyle")) + return QC_Slider; + + return QC_UnknownType; +} + +QAndroidStyle::ItemType QAndroidStyle::qtControl(QStyle::ComplexControl control) +{ + switch (control) { + case CC_ComboBox: + return QC_Combobox; + case CC_Slider: + return QC_Slider; + case CC_GroupBox: + return QC_View; + default: + return QC_UnknownType; + } +} + +QAndroidStyle::ItemType QAndroidStyle::qtControl(QStyle::ContentsType contentsType) +{ + switch (contentsType) { + case CT_PushButton: + return QC_Button; + case CT_CheckBox: + return QC_Checkbox; + case CT_RadioButton: + return QC_RadioButton; + case CT_ComboBox: + return QC_Combobox; + case CT_ProgressBar: + return QC_ProgressBar; + case CT_Slider: + return QC_Slider; + case CT_TabWidget: + return QC_Tab; + case CT_TabBarTab: + return QC_TabButton; + case CT_LineEdit: + return QC_EditText; + case CT_GroupBox: + return QC_GroupBox; + default: + return QC_UnknownType; + } +} + +QAndroidStyle::ItemType QAndroidStyle::qtControl(QStyle::ControlElement controlElement) +{ + switch (controlElement) { + case CE_PushButton: + case CE_PushButtonBevel: + case CE_PushButtonLabel: + return QC_Button; + + case CE_CheckBox: + case CE_CheckBoxLabel: + return QC_Checkbox; + + case CE_RadioButton: + case CE_RadioButtonLabel: + return QC_RadioButton; + + case CE_TabBarTab: + case CE_TabBarTabShape: + case CE_TabBarTabLabel: + return QC_Tab; + + case CE_ProgressBar: + case CE_ProgressBarGroove: + case CE_ProgressBarContents: + case CE_ProgressBarLabel: + return QC_ProgressBar; + + case CE_ComboBoxLabel: + return QC_Combobox; + + default: + return QC_UnknownType; + } +} + +QAndroidStyle::ItemType QAndroidStyle::qtControl(QStyle::PrimitiveElement primitiveElement) +{ + switch (primitiveElement) { + case QStyle::PE_PanelLineEdit: + case QStyle::PE_FrameLineEdit: + return QC_EditText; + + case QStyle::PE_FrameWindow: + case QStyle::PE_Widget: + case QStyle::PE_Frame: + case QStyle::PE_FrameFocusRect: + return QC_View; + default: + return QC_UnknownType; + } +} + +QAndroidStyle::ItemType QAndroidStyle::qtControl(QStyle::SubElement subElement) +{ + switch (subElement) { + case QStyle::SE_LineEditContents: + return QC_EditText; + + case QStyle::SE_PushButtonContents: + case QStyle::SE_PushButtonFocusRect: + return QC_Button; + + case SE_RadioButtonContents: + return QC_RadioButton; + + case SE_CheckBoxContents: + return QC_Checkbox; + + default: + return QC_UnknownType; + } +} + +void QAndroidStyle::drawPrimitive(PrimitiveElement pe, + const QStyleOption *opt, + QPainter *p, + const QWidget *w) const +{ + const ItemType itemType = qtControl(pe); + AndroidControlsHash::const_iterator it = itemType != QC_UnknownType + ? m_androidControlsHash.find(itemType) + : m_androidControlsHash.end(); + if (it != m_androidControlsHash.end()) + it.value()->drawControl(opt, p, w); + else + QCommonStyle::drawPrimitive(pe, opt, p, w); +} + + +void QAndroidStyle::drawControl(QStyle::ControlElement element, + const QStyleOption *opt, + QPainter *p, + const QWidget *w) const +{ + const ItemType itemType = qtControl(element); + AndroidControlsHash::const_iterator it = itemType != QC_UnknownType + ? m_androidControlsHash.find(itemType) + : m_androidControlsHash.end(); + if (it != m_androidControlsHash.end()) { + it.value()->drawControl(opt, p, w); + + switch (itemType) { + case QC_Button: + if (const QStyleOptionButton *buttonOption = + qstyleoption_cast<const QStyleOptionButton *>(opt)) { + QMargins padding = it.value()->padding(); + QStyleOptionButton copy (*buttonOption); + copy.rect.adjust(padding.left(), padding.top(), -padding.right(), -padding.bottom()); + QCommonStyle::drawControl(CE_PushButtonLabel, ©, p, w); + } + break; + case QC_Checkbox: + case QC_RadioButton: + if (const QStyleOptionButton *btn = + qstyleoption_cast<const QStyleOptionButton *>(opt)) { + const bool isRadio = (element == CE_RadioButton); + QStyleOptionButton subopt(*btn); + subopt.rect = subElementRect(isRadio ? SE_RadioButtonContents + : SE_CheckBoxContents, btn, w); + QCommonStyle::drawControl(isRadio ? CE_RadioButtonLabel : CE_CheckBoxLabel, &subopt, p, w); + } + break; + case QC_Combobox: + if (const QStyleOptionComboBox *comboboxOption = + qstyleoption_cast<const QStyleOptionComboBox *>(opt)) { + QMargins padding = it.value()->padding(); + QStyleOptionComboBox copy (*comboboxOption); + copy.rect.adjust(padding.left(), padding.top(), -padding.right(), -padding.bottom()); + p->setFont(QApplication::font("simple_spinner_item")); + p->setPen(QApplication::palette("QPushButton").color(QPalette::Active, QPalette::Text)); + QCommonStyle::drawControl(CE_ComboBoxLabel, comboboxOption, p, w); + } + break; + default: + break; + } + } + else + QCommonStyle::drawControl(element, opt, p, w); +} + +QRect QAndroidStyle::subElementRect(SubElement subElement, + const QStyleOption *option, + const QWidget *widget) const +{ + const ItemType itemType = qtControl(subElement); + AndroidControlsHash::const_iterator it = itemType != QC_UnknownType + ? m_androidControlsHash.find(itemType) + : m_androidControlsHash.end(); + if (it != m_androidControlsHash.end()) + return it.value()->subElementRect(subElement, option, widget); + return QCommonStyle::subElementRect(subElement, option, widget); +} + +void QAndroidStyle::drawComplexControl(ComplexControl cc, + const QStyleOptionComplex *opt, + QPainter *p, + const QWidget *widget) const +{ + const ItemType itemType = qtControl(cc); + AndroidControlsHash::const_iterator it = itemType != QC_UnknownType + ? m_androidControlsHash.find(itemType) + : m_androidControlsHash.end(); + if (it != m_androidControlsHash.end()) + it.value()->drawControl(opt, p, widget); + else + QCommonStyle::drawComplexControl(cc, opt, p, widget); +} + +QStyle::SubControl QAndroidStyle::hitTestComplexControl(ComplexControl cc, + const QStyleOptionComplex *opt, + const QPoint &pt, + const QWidget *widget) const +{ + const ItemType itemType = qtControl(cc); + AndroidControlsHash::const_iterator it = itemType != QC_UnknownType + ? m_androidControlsHash.find(itemType) + : m_androidControlsHash.end(); + if (it != m_androidControlsHash.end()) { + switch (cc) { + case CC_Slider: + if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) { + QRect r = it.value()->subControlRect(slider, SC_SliderHandle, widget); + if (r.isValid() && r.contains(pt)) { + return SC_SliderHandle; + } else { + r = it.value()->subControlRect(slider, SC_SliderGroove, widget); + if (r.isValid() && r.contains(pt)) + return SC_SliderGroove; + } + } + break; + default: + break; + } + } + return QCommonStyle::hitTestComplexControl(cc, opt, pt, widget); +} + +QRect QAndroidStyle::subControlRect(ComplexControl cc, + const QStyleOptionComplex *opt, + SubControl sc, + const QWidget *widget) const +{ + const ItemType itemType = qtControl(cc); + AndroidControlsHash::const_iterator it = itemType != QC_UnknownType + ? m_androidControlsHash.find(itemType) + : m_androidControlsHash.end(); + if (it != m_androidControlsHash.end()) + return it.value()->subControlRect(opt, sc, widget); + return QCommonStyle::subControlRect(cc, opt, sc, widget); +} + +int QAndroidStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, + const QWidget *widget) const +{ + switch (metric) { + case PM_ButtonMargin: + case PM_FocusFrameVMargin: + case PM_FocusFrameHMargin: + case PM_ComboBoxFrameWidth: + case PM_SpinBoxFrameWidth: + return 0; + default: + return QCommonStyle::pixelMetric(metric, option, widget); + } + +} + +QSize QAndroidStyle::sizeFromContents(ContentsType ct, + const QStyleOption *opt, + const QSize &contentsSize, + const QWidget *w) const +{ + QSize sz=QCommonStyle::sizeFromContents(ct, opt, contentsSize, w); + const ItemType itemType = qtControl(ct); + AndroidControlsHash::const_iterator it = itemType != QC_UnknownType + ? m_androidControlsHash.find(itemType) + : m_androidControlsHash.end(); + if (it != m_androidControlsHash.end()) + return it.value()->sizeFromContents(opt, sz, w); + return sz; +} + +QPixmap QAndroidStyle::standardPixmap(StandardPixmap standardPixmap, + const QStyleOption *opt, + const QWidget *widget) const +{ + return QCommonStyle::standardPixmap(standardPixmap, opt, widget); +} + +QPixmap QAndroidStyle::generatedIconPixmap(QIcon::Mode iconMode, + const QPixmap &pixmap, + const QStyleOption *opt) const +{ + return QCommonStyle::generatedIconPixmap(iconMode, pixmap, opt); +} + +QPalette QAndroidStyle::standardPalette() const +{ + return m_standardPalette; +} + +QAndroidStyle::AndroidDrawable::AndroidDrawable(const QVariantMap &drawable, + QAndroidStyle::ItemType itemType) +{ + initPadding(drawable); + m_itemType = itemType; +} + +QAndroidStyle::AndroidDrawable::~AndroidDrawable() +{ +} + +void QAndroidStyle::AndroidDrawable::initPadding(const QVariantMap &drawable) +{ + QVariantMap::const_iterator it = drawable.find(QLatin1String("padding")); + if (it != drawable.end()) + m_padding = extractMargins(it.value().toMap()); +} + +const QMargins &QAndroidStyle::AndroidDrawable::padding() const +{ + return m_padding; +} + +QSize QAndroidStyle::AndroidDrawable::size() const +{ + if (type() == Image || type() == NinePatch) + return static_cast<const QAndroidStyle::AndroidImageDrawable *>(this)->size(); + + return QSize(); +} + +QAndroidStyle::AndroidDrawable * QAndroidStyle::AndroidDrawable::fromMap(const QVariantMap &drawable, + ItemType itemType) +{ + const QString type = drawable.value(QLatin1String("type")).toString(); + if (type == QLatin1String("image")) + return new QAndroidStyle::AndroidImageDrawable(drawable, itemType); + if (type == QLatin1String("9patch")) + return new QAndroidStyle::Android9PatchDrawable(drawable, itemType); + if (type == QLatin1String("stateslist")) + return new QAndroidStyle::AndroidStateDrawable(drawable, itemType); + if (type == QLatin1String("layer")) + return new QAndroidStyle::AndroidLayerDrawable(drawable, itemType); + if (type == QLatin1String("gradient")) + return new QAndroidStyle::AndroidGradientDrawable(drawable, itemType); + if (type == QLatin1String("clipDrawable")) + return new QAndroidStyle::AndroidClipDrawable(drawable, itemType); + if (type == QLatin1String("color")) + return new QAndroidStyle::AndroidColorDrawable(drawable, itemType); + return 0; +} + +QMargins QAndroidStyle::AndroidDrawable::extractMargins(const QVariantMap &value) +{ + QMargins m; + m.setLeft(value.value(QLatin1String("left")).toInt()); + m.setRight(value.value(QLatin1String("right")).toInt()); + m.setTop(value.value(QLatin1String("top")).toInt()); + m.setBottom(value.value(QLatin1String("bottom")).toInt()); + return m; +} + + +QAndroidStyle::AndroidImageDrawable::AndroidImageDrawable(const QVariantMap &drawable, + QAndroidStyle::ItemType itemType) + : AndroidDrawable(drawable, itemType) +{ + m_filePath = drawable.value(QLatin1String("path")).toString(); + m_size.setHeight(drawable.value(QLatin1String("height")).toInt()); + m_size.setWidth(drawable.value(QLatin1String("width")).toInt()); +} + +QAndroidStyle::AndroidDrawableType QAndroidStyle::AndroidImageDrawable::type() const +{ + return QAndroidStyle::Image; +} + +void QAndroidStyle::AndroidImageDrawable::draw(QPainter *painter, const QStyleOption *opt) const +{ + if (m_hashKey.isEmpty()) + m_hashKey = QFileInfo(m_filePath).fileName(); + + QPixmap pm; + if (!QPixmapCache::find(m_hashKey, &pm)) { + pm.load(m_filePath); + QPixmapCache::insert(m_hashKey, pm); + } + + painter->drawPixmap(opt->rect.x(), (opt->rect.height() - pm.height()) / 2, pm); +} + +QSize QAndroidStyle::AndroidImageDrawable::size() const +{ + return m_size; +} + +QAndroidStyle::AndroidColorDrawable::AndroidColorDrawable(const QVariantMap &drawable, + ItemType itemType) + : AndroidDrawable(drawable, itemType) +{ + m_color.setRgba(QRgb(drawable.value(QLatin1String("color")).toInt())); +} + +QAndroidStyle::AndroidDrawableType QAndroidStyle::AndroidColorDrawable::type() const +{ + return QAndroidStyle::Color; +} + +void QAndroidStyle::AndroidColorDrawable::draw(QPainter *painter, const QStyleOption *opt) const +{ + painter->fillRect(opt->rect, m_color); +} + +QAndroidStyle::Android9PatchDrawable::Android9PatchDrawable(const QVariantMap &drawable, + QAndroidStyle::ItemType itemType) + : AndroidImageDrawable(drawable.value(QLatin1String("drawable")).toMap(), itemType) +{ + initPadding(drawable); + QVariantMap chunk = drawable.value(QLatin1String("chunkInfo")).toMap(); + extractIntArray(chunk.value(QLatin1String("xdivs")).toList(), m_chunkData.xDivs); + extractIntArray(chunk.value(QLatin1String("ydivs")).toList(), m_chunkData.yDivs); + extractIntArray(chunk.value(QLatin1String("colors")).toList(), m_chunkData.colors); +} + +QAndroidStyle::AndroidDrawableType QAndroidStyle::Android9PatchDrawable::type() const +{ + return QAndroidStyle::NinePatch; +} + +int QAndroidStyle::Android9PatchDrawable::calculateStretch(int boundsLimit, + int startingPoint, + int srcSpace, + int numStrechyPixelsRemaining, + int numFixedPixelsRemaining) +{ + int spaceRemaining = boundsLimit - startingPoint; + int stretchySpaceRemaining = spaceRemaining - numFixedPixelsRemaining; + return (float(srcSpace) * stretchySpaceRemaining / numStrechyPixelsRemaining + .5); +} + +void QAndroidStyle::Android9PatchDrawable::extractIntArray(const QVariantList &values, + QVector<int> & array) +{ + foreach (QVariant value, values) + array << value.toInt(); +} + + +void QAndroidStyle::Android9PatchDrawable::draw(QPainter * painter, const QStyleOption *opt) const +{ + if (m_hashKey.isEmpty()) + m_hashKey = QFileInfo(m_filePath).fileName(); + + QPixmap pixmap; + if (!QPixmapCache::find(m_hashKey, &pixmap)) { + pixmap.load(m_filePath); + QPixmapCache::insert(m_hashKey, pixmap); + } + + const QRect &bounds=opt->rect; + + // shamelessly stolen from Android's sources (NinepatchImpl.cpp) and adapted for Qt + const int pixmapWidth = pixmap.width(); + const int pixmapHeight = pixmap.height(); + + if (bounds.isNull() || !pixmapWidth || !pixmapHeight) + return; + + QPainter::RenderHints savedHints = painter->renderHints(); + + // The patchs doesn't need smooth transform ! + painter->setRenderHints(QPainter::SmoothPixmapTransform, false); + + QRectF dst; + QRectF src; + + const int32_t x0 = m_chunkData.xDivs[0]; + const int32_t y0 = m_chunkData.yDivs[0]; + const quint8 numXDivs = m_chunkData.xDivs.size(); + const quint8 numYDivs = m_chunkData.yDivs.size(); + int i; + int j; + int colorIndex = 0; + quint32 color; + bool xIsStretchable; + const bool initialXIsStretchable = (x0 == 0); + bool yIsStretchable = (y0 == 0); + const int bitmapWidth = pixmap.width(); + const int bitmapHeight = pixmap.height(); + + int *dstRights = static_cast<int *>(alloca((numXDivs + 1) * sizeof(int))); + bool dstRightsHaveBeenCached = false; + + int numStretchyXPixelsRemaining = 0; + for (i = 0; i < numXDivs; i += 2) + numStretchyXPixelsRemaining += m_chunkData.xDivs[i + 1] - m_chunkData.xDivs[i]; + + int numFixedXPixelsRemaining = bitmapWidth - numStretchyXPixelsRemaining; + int numStretchyYPixelsRemaining = 0; + for (i = 0; i < numYDivs; i += 2) + numStretchyYPixelsRemaining += m_chunkData.yDivs[i + 1] - m_chunkData.yDivs[i]; + + int numFixedYPixelsRemaining = bitmapHeight - numStretchyYPixelsRemaining; + src.setTop(0); + dst.setTop(bounds.top()); + // The first row always starts with the top being at y=0 and the bottom + // being either yDivs[1] (if yDivs[0]=0) of yDivs[0]. In the former case + // the first row is stretchable along the Y axis, otherwise it is fixed. + // The last row always ends with the bottom being bitmap.height and the top + // being either yDivs[numYDivs-2] (if yDivs[numYDivs-1]=bitmap.height) or + // yDivs[numYDivs-1]. In the former case the last row is stretchable along + // the Y axis, otherwise it is fixed. + // + // The first and last columns are similarly treated with respect to the X + // axis. + // + // The above is to help explain some of the special casing that goes on the + // code below. + + // The initial yDiv and whether the first row is considered stretchable or + // not depends on whether yDiv[0] was zero or not. + for (j = yIsStretchable ? 1 : 0; + j <= numYDivs && src.top() < bitmapHeight; + j++, yIsStretchable = !yIsStretchable) { + src.setLeft(0); + dst.setLeft(bounds.left()); + if (j == numYDivs) { + src.setBottom(bitmapHeight); + dst.setBottom(bounds.bottom()); + } else { + src.setBottom(m_chunkData.yDivs[j]); + const int srcYSize = src.bottom() - src.top(); + if (yIsStretchable) { + dst.setBottom(dst.top() + calculateStretch(bounds.bottom(), dst.top(), + srcYSize, + numStretchyYPixelsRemaining, + numFixedYPixelsRemaining)); + numStretchyYPixelsRemaining -= srcYSize; + } else { + dst.setBottom(dst.top() + srcYSize); + numFixedYPixelsRemaining -= srcYSize; + } + } + + xIsStretchable = initialXIsStretchable; + // The initial xDiv and whether the first column is considered + // stretchable or not depends on whether xDiv[0] was zero or not. + for (i = xIsStretchable ? 1 : 0; + i <= numXDivs && src.left() < bitmapWidth; + i++, xIsStretchable = !xIsStretchable) { + color = m_chunkData.colors[colorIndex++]; + if (i == numXDivs) { + src.setRight(bitmapWidth); + dst.setRight(bounds.right()); + } else { + src.setRight(m_chunkData.xDivs[i]); + if (dstRightsHaveBeenCached) { + dst.setRight(dstRights[i]); + } else { + const int srcXSize = src.right() - src.left(); + if (xIsStretchable) { + dst.setRight(dst.left() + calculateStretch(bounds.right(), dst.left(), + srcXSize, + numStretchyXPixelsRemaining, + numFixedXPixelsRemaining)); + numStretchyXPixelsRemaining -= srcXSize; + } else { + dst.setRight(dst.left() + srcXSize); + numFixedXPixelsRemaining -= srcXSize; + } + dstRights[i] = dst.right(); + } + } + // If this horizontal patch is too small to be displayed, leave + // the destination left edge where it is and go on to the next patch + // in the source. + if (src.left() >= src.right()) { + src.setLeft(src.right()); + continue; + } + // Make sure that we actually have room to draw any bits + if (dst.right() <= dst.left() || dst.bottom() <= dst.top()) { + goto nextDiv; + } + // If this patch is transparent, skip and don't draw. + if (color == TRANSPARENT_COLOR) + goto nextDiv; + if (color != NO_COLOR) + painter->fillRect(dst, (QRgb)color); + else + painter->drawPixmap(dst, pixmap, src); +nextDiv: + src.setLeft(src.right()); + dst.setLeft(dst.right()); + } + src.setTop(src.bottom()); + dst.setTop(dst.bottom()); + dstRightsHaveBeenCached = true; + } + painter->setRenderHints(savedHints); +} + +QAndroidStyle::AndroidGradientDrawable::AndroidGradientDrawable(const QVariantMap &drawable, + QAndroidStyle::ItemType itemType) + : AndroidDrawable(drawable, itemType), m_orientation(TOP_BOTTOM) +{ + m_radius = drawable.value(QLatin1String("radius")).toInt(); + if (m_radius < 0) + m_radius = 0; + + QVariantList colors = drawable.value(QLatin1String("colors")).toList(); + QVariantList positions = drawable.value(QLatin1String("positions")).toList(); + int min=colors.size() < positions.size() ? colors.size() : positions.size(); + for (int i = 0; i < min; i++) + m_gradient.setColorAt(positions.at(i).toDouble(), (QRgb)colors.at(i).toInt()); + + QByteArray orientation=drawable.value(QLatin1String("orientation")).toByteArray(); + if (orientation == "TOP_BOTTOM") // draw the gradient from the top to the bottom + m_orientation = TOP_BOTTOM; + else if (orientation == "TR_BL") // draw the gradient from the top-right to the bottom-left + m_orientation = TR_BL; + else if (orientation == "RIGHT_LEFT") // draw the gradient from the right to the left + m_orientation = RIGHT_LEFT; + else if (orientation == "BR_TL") // draw the gradient from the bottom-right to the top-left + m_orientation = BR_TL; + else if (orientation == "BOTTOM_TOP") // draw the gradient from the bottom to the top + m_orientation = BOTTOM_TOP; + else if (orientation == "BL_TR") // draw the gradient from the bottom-left to the top-right + m_orientation = BL_TR; + else if (orientation == "LEFT_RIGHT") // draw the gradient from the left to the right + m_orientation = LEFT_RIGHT; + else if (orientation == "TL_BR") // draw the gradient from the top-left to the bottom-right + m_orientation = TL_BR; + else + qWarning("AndroidGradientDrawable: unknown orientation"); +} + +QAndroidStyle::AndroidDrawableType QAndroidStyle::AndroidGradientDrawable::type() const +{ + return QAndroidStyle::Gradient; +} + +void QAndroidStyle::AndroidGradientDrawable::draw(QPainter *painter, const QStyleOption *opt) const +{ + const int width = opt->rect.width(); + const int height = opt->rect.height(); + switch (m_orientation) { + case TOP_BOTTOM: + // draw the gradient from the top to the bottom + m_gradient.setStart(width/2,0); + m_gradient.setFinalStop(width/2,height); + break; + case TR_BL: + // draw the gradient from the top-right to the bottom-left + m_gradient.setStart(width,0); + m_gradient.setFinalStop(0,height); + break; + case RIGHT_LEFT: + // draw the gradient from the right to the left + m_gradient.setStart(width,height/2); + m_gradient.setFinalStop(0,height/2); + break; + case BR_TL: + // draw the gradient from the bottom-right to the top-left + m_gradient.setStart(width,height); + m_gradient.setFinalStop(0,0); + break; + case BOTTOM_TOP: + // draw the gradient from the bottom to the top + m_gradient.setStart(width/2,height); + m_gradient.setFinalStop(width/2,0); + break; + case BL_TR: + // draw the gradient from the bottom-left to the top-right + m_gradient.setStart(0,height); + m_gradient.setFinalStop(width,0); + break; + case LEFT_RIGHT: + // draw the gradient from the left to the right + m_gradient.setStart(0,height/2); + m_gradient.setFinalStop(width,height/2); + break; + case TL_BR: + // draw the gradient from the top-left to the bottom-right + m_gradient.setStart(0,0); + m_gradient.setFinalStop(width,height); + break; + } + + const QBrush &oldBrush = painter->brush(); + const QPen oldPen = painter->pen(); + painter->setPen(Qt::NoPen); + painter->setBrush(m_gradient); + painter->drawRoundedRect(opt->rect, m_radius, m_radius); + painter->setBrush(oldBrush); + painter->setPen(oldPen); +} + +QSize QAndroidStyle::AndroidGradientDrawable::size() const +{ + return QSize(m_radius*2, m_radius*2); +} + +QAndroidStyle::AndroidClipDrawable::AndroidClipDrawable(const QVariantMap &drawable, + QAndroidStyle::ItemType itemType) + : AndroidDrawable(drawable, itemType) +{ + m_drawable = fromMap(drawable.value(QLatin1String("drawable")).toMap(), itemType); + m_factor = 0; + m_orientation = Qt::Horizontal; +} + +QAndroidStyle::AndroidClipDrawable::~AndroidClipDrawable() +{ + delete m_drawable; +} + +QAndroidStyle::AndroidDrawableType QAndroidStyle::AndroidClipDrawable::type() const +{ + return QAndroidStyle::Clip; +} + +void QAndroidStyle::AndroidClipDrawable::setFactor(double factor, Qt::Orientation orientation) +{ + m_factor = factor; + m_orientation = orientation; +} + +void QAndroidStyle::AndroidClipDrawable::draw(QPainter *painter, const QStyleOption *opt) const +{ + QStyleOption copy(*opt); + if (m_orientation == Qt::Horizontal) + copy.rect.setWidth(copy.rect.width()*m_factor); + else + copy.rect.setHeight(copy.rect.height()*m_factor); + + m_drawable->draw(painter, ©); +} + +QAndroidStyle::AndroidStateDrawable::AndroidStateDrawable(const QVariantMap &drawable, + QAndroidStyle::ItemType itemType) + : AndroidDrawable(drawable, itemType) +{ + QVariantList states = drawable.value(QLatin1String("stateslist")).toList(); + foreach (QVariant stateVariant, states) { + QVariantMap state = stateVariant.toMap(); + const int s = extractState(state.value(QLatin1String("states")).toMap()); + if (-1 == s) + continue; + const AndroidDrawable *ad = fromMap(state.value(QLatin1String("drawable")).toMap(), itemType); + if (!ad) + continue; + StateType item; + item.first = s; + item.second = ad; + m_states<<item; + } +} + +QAndroidStyle::AndroidStateDrawable::~AndroidStateDrawable() +{ + foreach (const StateType type, m_states) + delete type.second; +} + +QAndroidStyle::AndroidDrawableType QAndroidStyle::AndroidStateDrawable::type() const +{ + return QAndroidStyle::State; +} + +void QAndroidStyle::AndroidStateDrawable::draw(QPainter *painter, const QStyleOption *opt) const +{ + const AndroidDrawable *drawable=bestAndroidStateMatch(opt); + if (drawable) + drawable->draw(painter, opt); +} + +const QAndroidStyle::AndroidDrawable* QAndroidStyle::AndroidStateDrawable::bestAndroidStateMatch(const QStyleOption *opt) const +{ + const AndroidDrawable *bestMatch = 0; + if (!opt) { + if (m_states.size()) + return m_states[0].second; + return bestMatch; + } + + uint bestCost=0xffff; + foreach (const StateType & state, m_states) { + if (int(opt->state) == state.first) + return state.second; + uint cost = 0; + + int difference = int(opt->state^state.first); + + if (difference & QStyle::State_Active) + cost += 1000; + + if (difference & QStyle::State_Enabled) + cost += 1000; + + if ((m_itemType == QC_Button || m_itemType == QC_EditText) && (difference & QStyle::State_Raised)) + cost += 1000; + + if ((m_itemType == QC_Button || m_itemType == QC_EditText) && (difference & QStyle::State_Sunken)) + cost += 1000; + + if (difference & QStyle::State_Off) + cost += 1000; + + if (difference & QStyle::State_On) + cost += 1000; + + if (difference & QStyle::State_HasFocus) + cost += 1000; + + if (difference & QStyle::State_Selected) + cost += 1000; + + if (cost < bestCost) { + bestCost = cost; + bestMatch = state.second; + } + } + return bestMatch; +} + +int QAndroidStyle::AndroidStateDrawable::extractState(const QVariantMap &value) +{ + int state = QStyle::State_None; + foreach (const QString key, value.keys()) { + bool val = value.value(key).toString() == QLatin1String("true"); + if (key == QLatin1String("enabled") && val) { + state |= QStyle::State_Enabled; + continue; + } + + if (key == QLatin1String("window_focused") && val) { + state |= QStyle::State_Active; + continue; + } + + if (key == QLatin1String("focused") && val) { + state |= QStyle::State_HasFocus; + continue; + } + + if (key == QLatin1String("checked")) { + state |= val ? QStyle::State_On : QStyle::State_Off; + continue; + } + + if (key == QLatin1String("pressed")) { + state |= val ? QStyle::State_Raised : QStyle::State_Sunken; + state |= QStyle::State_Enabled | QStyle::State_HasFocus; + continue; + } + + if (key == QLatin1String("selected") && val) { + state |= QStyle::State_Selected; + state |= QStyle::State_Enabled | QStyle::State_HasFocus; + continue; + } + + if (key == QLatin1String("active") && val) { + state |= QStyle::State_Active; + continue; + } + + // Keep misspelling for compatibility + if (key == QLatin1String("backgroud") && val) + return -1; + } + return state; +} + +QAndroidStyle::AndroidLayerDrawable::AndroidLayerDrawable(const QVariantMap &drawable, + QAndroidStyle::ItemType itemType) + : AndroidDrawable(drawable, itemType) +{ + QVariantList layers = drawable.value(QLatin1String("layers")).toList(); + foreach (QVariant layer, layers) { + QVariantMap layerMap = layer.toMap(); + AndroidDrawable *ad = fromMap(layerMap, itemType); + if (ad) { + LayerType l; + l.second = ad; + l.first = layerMap.value(QLatin1String("id")).toInt(); + m_layers << l; + } + } +} + +QAndroidStyle::AndroidLayerDrawable::~AndroidLayerDrawable() +{ + foreach (const LayerType &layer, m_layers) + delete layer.second; +} + +QAndroidStyle::AndroidDrawableType QAndroidStyle::AndroidLayerDrawable::type() const +{ + return QAndroidStyle::Layer; +} + +void QAndroidStyle::AndroidLayerDrawable::draw(QPainter *painter, const QStyleOption *opt) const +{ + foreach (const LayerType &layer, m_layers) + layer.second->draw(painter, opt); +} + +QAndroidStyle::AndroidDrawable *QAndroidStyle::AndroidLayerDrawable::layer(int id) const +{ + foreach (const LayerType &layer, m_layers) + if (layer.first == id) + return layer.second; + return 0; +} + +QSize QAndroidStyle::AndroidLayerDrawable::size() const +{ + QSize sz; + foreach (const LayerType &layer, m_layers) + sz = sz.expandedTo(layer.second->size()); + return sz; +} + +QAndroidStyle::AndroidControl::AndroidControl(const QVariantMap &control, + QAndroidStyle::ItemType itemType) +{ + QVariantMap::const_iterator it = control.find(QLatin1String("View_background")); + if (it != control.end()) + m_background = AndroidDrawable::fromMap(it.value().toMap(), itemType); + else + m_background = 0; + + it = control.find(QLatin1String("View_minWidth")); + if (it!=control.end()) + m_minSize.setWidth(it.value().toInt()); + + it = control.find(QLatin1String("View_minHeight")); + if (it != control.end()) + m_minSize.setHeight(it.value().toInt()); + + it = control.find(QLatin1String("View_maxWidth")); + if (it != control.end()) + m_maxSize.setWidth(it.value().toInt()); + + it = control.find(QLatin1String("View_maxHeight")); + if (it != control.end()) + m_maxSize.setHeight(it.value().toInt()); +} + +QAndroidStyle::AndroidControl::~AndroidControl() +{ + delete m_background; +} + +void QAndroidStyle::AndroidControl::drawControl(const QStyleOption *opt, QPainter *p, const QWidget */*w*/) +{ + if (m_background) + m_background->draw(p, opt); +} + +QRect QAndroidStyle::AndroidControl::subElementRect(QStyle::SubElement /*subElement*/, + const QStyleOption *option, + const QWidget */*widget*/) const +{ + if (const AndroidDrawable *drawable=m_background) { + if (drawable->type() == State) + drawable = static_cast<const AndroidStateDrawable *>(m_background)->bestAndroidStateMatch(option); + + const QMargins &padding = drawable->padding(); + + QRect r = option->rect.adjusted(padding.left(), padding.top(), + -padding.right(), -padding.bottom()); + + if (r.width() < m_minSize.width()) + r.setWidth(m_minSize.width()); + + if (r.height() < m_minSize.height()) + r.setHeight(m_minSize.height()); + + return visualRect(option->direction, option->rect, r); + } + return option->rect; + +} + +QRect QAndroidStyle::AndroidControl::subControlRect(const QStyleOptionComplex *option, + QStyle::SubControl /*sc*/, + const QWidget *widget) const +{ + return subElementRect(QStyle::SE_CustomBase, option, widget); +} + +QSize QAndroidStyle::AndroidControl::sizeFromContents(const QStyleOption *opt, + const QSize &contentsSize, + const QWidget */*w*/) const +{ + QSize sz; + if (const AndroidDrawable *drawable=m_background) { + + if (drawable->type() == State) + drawable = static_cast<const AndroidStateDrawable*>(m_background)->bestAndroidStateMatch(opt); + const QMargins &padding = drawable->padding(); + sz.setWidth(padding.left() + padding.right()); + sz.setHeight(padding.top() + padding.bottom()); + if (sz.isEmpty()) + sz = drawable->size(); + } + sz += contentsSize; + if (contentsSize.height() < opt->fontMetrics.height()) + sz.setHeight(sz.height() + (opt->fontMetrics.height() - contentsSize.height())); + if (sz.height() < m_minSize.height()) + sz.setHeight(m_minSize.height()); + if (sz.width() < m_minSize.width()) + sz.setWidth(m_minSize.width()); + return sz; +} + +QMargins QAndroidStyle::AndroidControl::padding() +{ + if (const AndroidDrawable *drawable = m_background) + { + if (drawable->type() == State) + drawable=static_cast<const AndroidStateDrawable *>(m_background)->bestAndroidStateMatch(0); + return drawable->padding(); + } + return QMargins(); +} + +QAndroidStyle::AndroidCompoundButtonControl::AndroidCompoundButtonControl(const QVariantMap &control, + ItemType itemType) + : AndroidControl(control, itemType) +{ + QVariantMap::const_iterator it = control.find(QLatin1String("CompoundButton_button")); + if (it != control.end()) + m_button = AndroidDrawable::fromMap(it.value().toMap(), itemType); + else + m_button = 0; +} + +QAndroidStyle::AndroidCompoundButtonControl::~AndroidCompoundButtonControl() +{ + delete m_button; +} + +void QAndroidStyle::AndroidCompoundButtonControl::drawControl(const QStyleOption *opt, + QPainter *p, + const QWidget *w) +{ + AndroidControl::drawControl(opt, p, w); + if (m_button) + m_button->draw(p, opt); +} + +QAndroidStyle::AndroidProgressBarControl::AndroidProgressBarControl(const QVariantMap &control, + ItemType itemType) + : AndroidControl(control, itemType) +{ + QVariantMap::const_iterator it = control.find(QLatin1String("ProgressBar_indeterminateDrawable")); + if (it != control.end()) + m_indeterminateDrawable = AndroidDrawable::fromMap(it.value().toMap(), itemType); + else + m_indeterminateDrawable = 0; + + it = control.find(QLatin1String("ProgressBar_progressDrawable")); + if (it != control.end()) + m_progressDrawable = AndroidDrawable::fromMap(it.value().toMap(), itemType); + else + m_progressDrawable = 0; + + it = control.find(QLatin1String("ProgressBar_progress_id")); + if (it != control.end()) + m_progressId = it.value().toInt(); + + it = control.find(QLatin1String("ProgressBar_secondaryProgress_id")); + if (it != control.end()) + m_secondaryProgress_id = it.value().toInt(); + + it = control.find(QLatin1String("ProgressBar_minWidth")); + if (it != control.end()) + m_minSize.setWidth(it.value().toInt()); + + it = control.find(QLatin1String("ProgressBar_minHeight")); + if (it != control.end()) + m_minSize.setHeight(it.value().toInt()); + + it = control.find(QLatin1String("ProgressBar_maxWidth")); + if (it != control.end()) + m_maxSize.setWidth(it.value().toInt()); + + it = control.find(QLatin1String("ProgressBar_maxHeight")); + if (it != control.end()) + m_maxSize.setHeight(it.value().toInt()); +} + +QAndroidStyle::AndroidProgressBarControl::~AndroidProgressBarControl() +{ + delete m_progressDrawable; + delete m_indeterminateDrawable; +} + +void QAndroidStyle::AndroidProgressBarControl::drawControl(const QStyleOption *option, QPainter *p, const QWidget */*w*/) +{ + if (!m_progressDrawable) + return; + + if (const QStyleOptionProgressBar *progressBarOption = + qstyleoption_cast<const QStyleOptionProgressBar *>(option)) { + QStyleOptionProgressBarV2 progressBarV2(*progressBarOption); + if (m_progressDrawable->type() == QAndroidStyle::Layer) { + QAndroidStyle::AndroidDrawable *clipDrawable = static_cast<QAndroidStyle::AndroidLayerDrawable *>(m_progressDrawable)->layer(m_progressId); + if (clipDrawable->type() == QAndroidStyle::Clip) + static_cast<QAndroidStyle::AndroidClipDrawable *>(clipDrawable)->setFactor(double(progressBarV2.progress/(progressBarV2.maximum-progressBarV2.minimum)), + progressBarV2.orientation); + } + m_progressDrawable->draw(p, option); + } +} + +QRect QAndroidStyle::AndroidProgressBarControl::subElementRect(QStyle::SubElement subElement, + const QStyleOption *option, + const QWidget *widget) const +{ + if (const QStyleOptionProgressBar *progressBarOption = + qstyleoption_cast<const QStyleOptionProgressBar *>(option)) { + QStyleOptionProgressBarV2 progressBarV2(*progressBarOption); + const bool horizontal = progressBarV2.orientation == Qt::Vertical; + if (!m_background) + return option->rect; + + QMargins padding = m_background->padding(); + QRect p(padding.left(), padding.top(), padding.right()-padding.left(), padding.bottom()-padding.top()); + padding = m_indeterminateDrawable->padding(); + p |= QRect(padding.left(), padding.top(), padding.right()-padding.left(), padding.bottom()-padding.top()); + padding = m_progressDrawable->padding(); + p |= QRect(padding.left(), padding.top(), padding.right()-padding.left(), padding.bottom()-padding.top()); + + QRect r = option->rect.adjusted(p.left(), p.top(), -p.right(), -p.bottom()); + + if (horizontal) { + if (r.height()<m_minSize.height()) + r.setHeight(m_minSize.height()); + + if (r.height()>m_maxSize.height()) + r.setHeight(m_maxSize.height()); + } else { + if (r.width()<m_minSize.width()) + r.setWidth(m_minSize.width()); + + if (r.width()>m_maxSize.width()) + r.setWidth(m_maxSize.width()); + } + return visualRect(option->direction, option->rect, r); + } + return AndroidControl::subElementRect(subElement, option, widget); +} + +QSize QAndroidStyle::AndroidProgressBarControl::sizeFromContents(const QStyleOption *opt, + const QSize &contentsSize, + const QWidget */*w*/) const +{ + QSize sz(contentsSize); + if (sz.height() < m_minSize.height()) + sz.setHeight(m_minSize.height()); + if (sz.width() < m_minSize.width()) + sz.setWidth(m_minSize.width()); + + if (const QStyleOptionProgressBar *progressBarOption = + qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) { + QStyleOptionProgressBarV2 progressBarV2(*progressBarOption); + if (progressBarV2.orientation == Qt::Vertical) { + if (sz.height() > m_maxSize.height()) + sz.setHeight(m_maxSize.height()); + } else { + if (sz.width() > m_maxSize.width()) + sz.setWidth(m_maxSize.width()); + } + } + return contentsSize; +} + +QAndroidStyle::AndroidSeekBarControl::AndroidSeekBarControl(const QVariantMap &control, + ItemType itemType) + : AndroidProgressBarControl(control, itemType) +{ + QVariantMap::const_iterator it = control.find(QLatin1String("SeekBar_thumb")); + if (it != control.end()) + m_seekBarThumb = AndroidDrawable::fromMap(it.value().toMap(), itemType); + else + m_seekBarThumb = 0; +} + +QAndroidStyle::AndroidSeekBarControl::~AndroidSeekBarControl() +{ + delete m_seekBarThumb; +} + +void QAndroidStyle::AndroidSeekBarControl::drawControl(const QStyleOption *option, + QPainter *p, + const QWidget */*w*/) +{ + if (!m_seekBarThumb || !m_progressDrawable) + return; + + if (const QStyleOptionSlider *styleOption = + qstyleoption_cast<const QStyleOptionSlider *>(option)) { + double factor = double(styleOption->sliderPosition/(styleOption->maximum-styleOption->minimum)); + if (m_progressDrawable->type()==QAndroidStyle::Layer) { + QAndroidStyle::AndroidDrawable *clipDrawable = static_cast<QAndroidStyle::AndroidLayerDrawable *>(m_progressDrawable)->layer(m_progressId); + if (clipDrawable->type() == QAndroidStyle::Clip) + static_cast<QAndroidStyle::AndroidClipDrawable *>(clipDrawable)->setFactor(factor, styleOption->orientation); + } + const AndroidDrawable *drawable=m_seekBarThumb; + if (drawable->type() == State) + drawable = static_cast<const QAndroidStyle::AndroidStateDrawable *>(m_seekBarThumb)->bestAndroidStateMatch(option); + QStyleOption copy(*option); + copy.rect.setY((copy.rect.height()-m_minSize.height())/2); + copy.rect.setHeight(m_minSize.height()); + copy.rect.setWidth(copy.rect.width()-drawable->size().width()); + copy.rect.translate(drawable->size().width()/2,0); + m_progressDrawable->draw(p, ©); + if (styleOption->orientation == Qt::Vertical) + qCritical() << "Vertical slider are not supported"; + int pos = (double(copy.rect.width()*factor - drawable->size().width()) / 2); + copy.rect.translate(pos, 0); + copy.rect.setSize(drawable->size()); + m_seekBarThumb->draw(p, ©); + } +} + +QSize QAndroidStyle::AndroidSeekBarControl::sizeFromContents(const QStyleOption *opt, + const QSize &contentsSize, + const QWidget *w) const +{ + QSize sz = AndroidProgressBarControl::sizeFromContents(opt, contentsSize, w); + if (!m_seekBarThumb) + return sz; + const AndroidDrawable *drawable=m_seekBarThumb; + if (drawable->type() == State) + drawable = static_cast<const QAndroidStyle::AndroidStateDrawable *>(m_seekBarThumb)->bestAndroidStateMatch(opt); + return sz.expandedTo(drawable->size()); +} + +QRect QAndroidStyle::AndroidSeekBarControl::subControlRect(const QStyleOptionComplex *option, + SubControl sc, + const QWidget */*widget*/) const +{ + const QStyleOptionSlider *styleOption = + qstyleoption_cast<const QStyleOptionSlider *>(option); + + if (m_seekBarThumb && sc == SC_SliderHandle && styleOption) { + const AndroidDrawable *drawable = m_seekBarThumb; + if (drawable->type() == State) + drawable = static_cast<const QAndroidStyle::AndroidStateDrawable *>(m_seekBarThumb)->bestAndroidStateMatch(option); + + QRect r(option->rect); + double factor = double(styleOption->sliderPosition/(styleOption->maximum-styleOption->minimum)); + int pos=(double(option->rect.width()*factor - drawable->size().width()) / 2); + r.setX(r.x()+pos); + r.setSize(drawable->size()); + return r; + } + return option->rect; +} + +QAndroidStyle::AndroidSpinnerControl::AndroidSpinnerControl(const QVariantMap &control, + QAndroidStyle::ItemType itemType) + : AndroidControl(control, itemType) +{} + +QRect QAndroidStyle::AndroidSpinnerControl::subControlRect(const QStyleOptionComplex *option, + SubControl sc, + const QWidget *widget) const +{ + if (sc == QStyle::SC_ComboBoxListBoxPopup) + return option->rect; + return AndroidControl::subControlRect(option, sc, widget); +} + +QT_END_NAMESPACE + +#endif // !defined(QT_NO_STYLE_ANDROID) || defined(QT_PLUGIN) diff --git a/src/widgets/styles/qandroidstyle_p.h b/src/widgets/styles/qandroidstyle_p.h new file mode 100644 index 0000000000..35fa61983a --- /dev/null +++ b/src/widgets/styles/qandroidstyle_p.h @@ -0,0 +1,382 @@ +/**************************************************************************** +** +** Copyright (C) 2012 BogDan Vatra <bogdan@kde.org> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWidgets module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QANDROIDSTYLE_P_H +#define QANDROIDSTYLE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of qstylefactory.cpp. This header may change from version to version +// without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/QList> +#include <QtCore/QMargins> +#include <QtWidgets/QCommonStyle> +#include <QtCore/QHash> +#include <QtCore/QVariantMap> + +QT_BEGIN_NAMESPACE + +#if !defined(QT_NO_STYLE_ANDROID) + +class Q_GUI_EXPORT QAndroidStyle : public QCommonStyle +{ + Q_OBJECT + +public: + enum ItemType + { + QC_UnknownType = -1, + QC_View, + QC_GroupBox, + QC_Button, + QC_Checkbox, + QC_RadioButton, + QC_Slider, + QC_Switch, + QC_EditText, + QC_Combobox, + QC_BusyIndicator, + QC_ProgressBar, + QC_Tab, + QC_TabButton, + QC_RatingIndicator, + QC_SearchBox, + QC_CustomCOntrol=0xf00, + QC_ControlMask=0xfff + }; + + struct Android9PatchChunk + { + QVector<int> xDivs; + QVector<int> yDivs; + QVector<int> colors; + }; + + struct AndroidItemStateInfo + { + AndroidItemStateInfo():state(0){} + int state; + QByteArray filePath; + QByteArray hashKey; + Android9PatchChunk chunkData; + QSize size; + QMargins padding; + }; + + enum AndroidDrawableType + { + Color, + Image, + Clip, + NinePatch, + Gradient, + State, + Layer + }; + + class AndroidDrawable + { + public: + AndroidDrawable(const QVariantMap &drawable, ItemType itemType); + virtual ~AndroidDrawable(); + virtual void initPadding(const QVariantMap &drawable); + virtual AndroidDrawableType type() const = 0; + virtual void draw(QPainter *painter,const QStyleOption *opt) const = 0; + const QMargins &padding() const; + virtual QSize size() const; + static AndroidDrawable *fromMap(const QVariantMap &drawable, ItemType itemType); + static QMargins extractMargins(const QVariantMap &value); + protected: + ItemType m_itemType; + QMargins m_padding; + }; + + class AndroidColorDrawable: public AndroidDrawable + { + public: + AndroidColorDrawable(const QVariantMap &drawable, ItemType itemType); + virtual AndroidDrawableType type() const; + virtual void draw(QPainter *painter,const QStyleOption *opt) const; + + protected: + QColor m_color; + }; + + class AndroidImageDrawable: public AndroidDrawable + { + public: + AndroidImageDrawable(const QVariantMap &drawable, ItemType itemType); + virtual AndroidDrawableType type() const; + virtual void draw(QPainter *painter,const QStyleOption *opt) const; + virtual QSize size() const; + + protected: + QString m_filePath; + mutable QString m_hashKey; + QSize m_size; + }; + + class Android9PatchDrawable: public AndroidImageDrawable + { + public: + Android9PatchDrawable(const QVariantMap &drawable, ItemType itemType); + virtual AndroidDrawableType type() const; + virtual void draw(QPainter *painter, const QStyleOption *opt) const; + private: + static int calculateStretch(int boundsLimit, int startingPoint, + int srcSpace, int numStrechyPixelsRemaining, + int numFixedPixelsRemaining); + void extractIntArray(const QVariantList &values, QVector<int> &array); + private: + Android9PatchChunk m_chunkData; + }; + + class AndroidGradientDrawable: public AndroidDrawable + { + public: + enum GradientOrientation + { + TOP_BOTTOM, + TR_BL, + RIGHT_LEFT, + BR_TL, + BOTTOM_TOP, + BL_TR, + LEFT_RIGHT, + TL_BR + }; + + public: + AndroidGradientDrawable(const QVariantMap &drawable, ItemType itemType); + virtual AndroidDrawableType type() const; + virtual void draw(QPainter *painter, const QStyleOption *opt) const; + QSize size() const; + private: + mutable QLinearGradient m_gradient; + GradientOrientation m_orientation; + int m_radius; + }; + + class AndroidClipDrawable: public AndroidDrawable + { + public: + AndroidClipDrawable(const QVariantMap &drawable, ItemType itemType); + ~AndroidClipDrawable(); + virtual AndroidDrawableType type() const; + virtual void setFactor(double factor, Qt::Orientation orientation); + virtual void draw(QPainter *painter, const QStyleOption *opt) const; + + private: + double m_factor; + Qt::Orientation m_orientation; + const AndroidDrawable *m_drawable; + }; + + class AndroidStateDrawable: public AndroidDrawable + { + public: + AndroidStateDrawable(const QVariantMap &drawable, ItemType itemType); + ~AndroidStateDrawable(); + virtual AndroidDrawableType type() const; + virtual void draw(QPainter *painter, const QStyleOption *opt) const; + inline const AndroidDrawable *bestAndroidStateMatch(const QStyleOption *opt) const; + static int extractState(const QVariantMap &value); + + private: + typedef QPair<int, const AndroidDrawable *> StateType; + QList<StateType> m_states; + }; + + class AndroidLayerDrawable: public AndroidDrawable + { + public: + AndroidLayerDrawable(const QVariantMap &drawable, QAndroidStyle::ItemType itemType); + ~AndroidLayerDrawable(); + virtual AndroidDrawableType type() const; + virtual void draw(QPainter *painter, const QStyleOption *opt) const; + AndroidDrawable *layer(int id) const; + QSize size() const; + private: + typedef QPair<int, AndroidDrawable *> LayerType; + QList<LayerType> m_layers; + }; + + class AndroidControl + { + public: + AndroidControl(const QVariantMap &control, ItemType itemType); + virtual ~AndroidControl(); + virtual void drawControl(const QStyleOption *opt, QPainter *p, const QWidget *w); + virtual QRect subElementRect(SubElement subElement, + const QStyleOption *option, + const QWidget *widget = 0) const; + virtual QRect subControlRect(const QStyleOptionComplex *option, + SubControl sc, + const QWidget *widget = 0) const; + virtual QSize sizeFromContents(const QStyleOption *opt, + const QSize &contentsSize, + const QWidget *w) const; + virtual QMargins padding(); + protected: + const AndroidDrawable *m_background; + QSize m_minSize; + QSize m_maxSize; + }; + + class AndroidCompoundButtonControl : public AndroidControl + { + public: + AndroidCompoundButtonControl(const QVariantMap &control, ItemType itemType); + virtual ~AndroidCompoundButtonControl(); + virtual void drawControl(const QStyleOption *opt, QPainter *p, const QWidget *w); + + protected: + const AndroidDrawable *m_button; + }; + + class AndroidProgressBarControl : public AndroidControl + { + public: + AndroidProgressBarControl(const QVariantMap &control, ItemType itemType); + virtual ~AndroidProgressBarControl(); + virtual void drawControl(const QStyleOption *option, QPainter *p, const QWidget *w); + virtual QRect subElementRect(SubElement subElement, + const QStyleOption *option, + const QWidget *widget = 0) const; + + QSize sizeFromContents(const QStyleOption *opt, + const QSize &contentsSize, + const QWidget *w) const; + protected: + AndroidDrawable *m_progressDrawable; + AndroidDrawable *m_indeterminateDrawable; + int m_secondaryProgress_id; + int m_progressId; + }; + + class AndroidSeekBarControl : public AndroidProgressBarControl + { + public: + AndroidSeekBarControl(const QVariantMap &control, ItemType itemType); + virtual ~AndroidSeekBarControl(); + virtual void drawControl(const QStyleOption *option, QPainter *p, const QWidget *w); + QSize sizeFromContents(const QStyleOption *opt, + const QSize &contentsSize, const QWidget *w) const; + QRect subControlRect(const QStyleOptionComplex *option, SubControl sc, + const QWidget *widget = 0) const; + private: + AndroidDrawable *m_seekBarThumb; + }; + + class AndroidSpinnerControl : public AndroidControl + { + public: + AndroidSpinnerControl(const QVariantMap &control, ItemType itemType); + virtual ~AndroidSpinnerControl(){} + virtual QRect subControlRect(const QStyleOptionComplex *option, + SubControl sc, + const QWidget *widget = 0) const; + }; + + typedef QList<AndroidItemStateInfo *> AndroidItemStateInfoList; + +public: + QAndroidStyle(); + ~QAndroidStyle(); + + virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, + const QWidget *w = 0) const; + + virtual void drawControl(QStyle::ControlElement element, const QStyleOption *opt, QPainter *p, + const QWidget *w = 0) const; + + virtual QRect subElementRect(SubElement subElement, const QStyleOption *option, + const QWidget *widget = 0) const; + virtual void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, + const QWidget *widget = 0) const; + virtual SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, + const QPoint &pt, const QWidget *widget = 0) const; + virtual QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, + SubControl sc, const QWidget *widget = 0) const; + + virtual int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, + const QWidget *widget = 0) const; + + virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, + const QSize &contentsSize, const QWidget *w = 0) const; + + virtual QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt = 0, + const QWidget *widget = 0) const; + + virtual QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, + const QStyleOption *opt) const; + + virtual QPalette standardPalette() const; +private: + Q_DISABLE_COPY(QAndroidStyle) + static ItemType qtControl(QStyle::ComplexControl control); + static ItemType qtControl(QStyle::ContentsType contentsType); + static ItemType qtControl(QStyle::ControlElement controlElement); + static ItemType qtControl(QStyle::PrimitiveElement primitiveElement); + static ItemType qtControl(QStyle::SubElement subElement); + static ItemType qtControl(const QString &android); + + static void setPaletteColor(const QVariantMap &object, + QPalette &palette, + QPalette::ColorRole role); +private: + typedef QHash<int, AndroidControl *> AndroidControlsHash; + AndroidControlsHash m_androidControlsHash; + QPalette m_standardPalette; +}; + +#endif // QT_NO_STYLE_ANDROID + +QT_END_NAMESPACE + +#endif // QANDROIDSTYLE_P_H diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 4b6ba17595..64eb76dbb4 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -2138,9 +2138,9 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, p->save(); p->setClipRect(opt->rect); - QRect checkRect = subElementRect(SE_ItemViewItemCheckIndicator, vopt, widget); - QRect iconRect = subElementRect(SE_ItemViewItemDecoration, vopt, widget); - QRect textRect = subElementRect(SE_ItemViewItemText, vopt, widget); + QRect checkRect = proxy()->subElementRect(SE_ItemViewItemCheckIndicator, vopt, widget); + QRect iconRect = proxy()->subElementRect(SE_ItemViewItemDecoration, vopt, widget); + QRect textRect = proxy()->subElementRect(SE_ItemViewItemText, vopt, widget); // draw the background proxy()->drawPrimitive(PE_PanelItemViewItem, opt, p, widget); @@ -4808,6 +4808,16 @@ QSize QCommonStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, } break; #endif // QT_NO_ITEMVIEWS +#ifndef QT_NO_SPINBOX + case CT_SpinBox: + if (const QStyleOptionSpinBox *vopt = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) { + // Add button + frame widths + int buttonWidth = 20; + int fw = vopt->frame ? proxy()->pixelMetric(PM_SpinBoxFrameWidth, vopt, widget) : 0; + sz += QSize(buttonWidth + 2*fw, 2*fw); + } + break; +#endif case CT_ScrollBar: case CT_MenuBar: case CT_Menu: @@ -5090,7 +5100,11 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget ret = theme->themeHint(QPlatformTheme::ToolButtonStyle).toInt(); break; case SH_RequestSoftwareInputPanel: +#ifdef Q_OS_ANDROID + ret = RSIP_OnMouseClick; +#else ret = RSIP_OnMouseClickAndAlreadyFocused; +#endif break; case SH_ScrollBar_Transient: ret = false; diff --git a/src/widgets/styles/qcommonstyle.h b/src/widgets/styles/qcommonstyle.h index 1d203ded34..d11f57dac0 100644 --- a/src/widgets/styles/qcommonstyle.h +++ b/src/widgets/styles/qcommonstyle.h @@ -44,8 +44,6 @@ #include <QtWidgets/qstyle.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE class QCommonStylePrivate; @@ -105,6 +103,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QCOMMONSTYLE_H diff --git a/src/widgets/styles/qdrawutil.h b/src/widgets/styles/qdrawutil.h index f0cc98f54a..37e02bb1a9 100644 --- a/src/widgets/styles/qdrawutil.h +++ b/src/widgets/styles/qdrawutil.h @@ -46,8 +46,6 @@ #include <QtCore/qstring.h> // char*->QString conversion #include <QtCore/qmargins.h> #include <QtGui/qpixmap.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -169,6 +167,4 @@ inline void qDrawBorderPixmap(QPainter *painter, QT_END_NAMESPACE -QT_END_HEADER - #endif // QDRAWUTIL_H diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index 11558de16a..defdf30b6b 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -1768,12 +1768,10 @@ void QFusionStyle::drawControl(ControlElement element, const QStyleOption *optio painter->save(); { painter->fillRect(rect, option->palette.window()); - if (widget && qobject_cast<const QMainWindow *>(widget->parentWidget())) { - QColor shadow = mergedColors(option->palette.background().color().darker(120), - outline.lighter(140), 60); - painter->setPen(QPen(shadow)); - painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight()); - } + QColor shadow = mergedColors(option->palette.background().color().darker(120), + outline.lighter(140), 60); + painter->setPen(QPen(shadow)); + painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight()); } painter->restore(); break; diff --git a/src/widgets/styles/qfusionstyle_p.h b/src/widgets/styles/qfusionstyle_p.h index e024677a9b..2fa7779b7b 100644 --- a/src/widgets/styles/qfusionstyle_p.h +++ b/src/widgets/styles/qfusionstyle_p.h @@ -44,8 +44,6 @@ #include <QtWidgets/qcommonstyle.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -106,6 +104,4 @@ protected: QT_END_NAMESPACE -QT_END_HEADER - #endif //QFUSIONSTYLE_P_H diff --git a/src/widgets/styles/qfusionstyle_p_p.h b/src/widgets/styles/qfusionstyle_p_p.h index d3f2ff5f40..58595fe889 100644 --- a/src/widgets/styles/qfusionstyle_p_p.h +++ b/src/widgets/styles/qfusionstyle_p_p.h @@ -88,9 +88,9 @@ public: // On mac we want a standard blue color used when the system palette is used bool isMacSystemPalette(const QPalette &pal) const { Q_UNUSED(pal); -#ifdef Q_OS_MAC +#if defined(Q_OS_MAC) && !defined(Q_OS_IOS) const QPalette *themePalette = QGuiApplicationPrivate::platformTheme()->palette(); - if (themePalette->color(QPalette::Normal, QPalette::Highlight) == + if (themePalette && themePalette->color(QPalette::Normal, QPalette::Highlight) == pal.color(QPalette::Normal, QPalette::Highlight) && themePalette->color(QPalette::Normal, QPalette::HighlightedText) == pal.color(QPalette::Normal, QPalette::HighlightedText)) diff --git a/src/widgets/styles/qgtkstyle.cpp b/src/widgets/styles/qgtkstyle.cpp index 159f8dce83..9ebab8d52d 100644 --- a/src/widgets/styles/qgtkstyle.cpp +++ b/src/widgets/styles/qgtkstyle.cpp @@ -3171,7 +3171,8 @@ void QGtkStyle::drawControl(ControlElement element, #ifndef QT_NO_COMBOBOX - if (qobject_cast<const QComboBox*>(widget)) + if (qobject_cast<const QComboBox*>(widget) || + (option->styleObject && option->styleObject->property("_q_isComboBoxPopupItem").toBool())) ignoreCheckMark = true; // Ignore the checkmarks provided by the QComboMenuDelegate #endif @@ -3912,7 +3913,7 @@ QSize QGtkStyle::sizeFromContents(ContentsType type, const QStyleOption *option, break; case CT_SpinBox: // QSpinBox does some nasty things that depends on CT_LineEdit - newSize = size + QSize(0, -d->gtk_widget_get_style(d->gtkWidget("GtkSpinButton"))->ythickness * 2); + newSize = newSize + QSize(0, -d->gtk_widget_get_style(d->gtkWidget("GtkSpinButton"))->ythickness * 2); break; case CT_RadioButton: case CT_CheckBox: diff --git a/src/widgets/styles/qgtkstyle_p.h b/src/widgets/styles/qgtkstyle_p.h index f2710af4c6..0713f30bb9 100644 --- a/src/widgets/styles/qgtkstyle_p.h +++ b/src/widgets/styles/qgtkstyle_p.h @@ -47,8 +47,6 @@ #include <QtGui/QFont> #include <QtWidgets/QFileDialog> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -119,6 +117,4 @@ public: QT_END_NAMESPACE -QT_END_HEADER - #endif //QGTKSTYLE_P_H diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index ea73ff6296..de7bac93a0 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -586,11 +586,9 @@ CGColorSpaceRef qt_mac_genericColorSpace() { #if 0 if (!m_genericColorSpace) { -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) { m_genericColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); } else -#endif { m_genericColorSpace = CGColorSpaceCreateDeviceRGB(); } @@ -4913,14 +4911,12 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex } else { if (!(slider->subControls & SC_SliderHandle)) tdi.attributes &= ~kThemeTrackShowThumb; -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 if (!(slider->subControls & SC_SliderGroove)) tdi.attributes |= kThemeTrackHideTrack; -#endif } #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 - if (cc == CC_ScrollBar && proxy()->styleHint(SH_ScrollBar_Transient, 0, widget)) { + if (cc == CC_ScrollBar && proxy()->styleHint(SH_ScrollBar_Transient, opt, widget)) { bool wasActive = false; CGFloat opacity = 1.0; CGFloat expandScale = 1.0; @@ -5988,10 +5984,11 @@ QSize QMacStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, switch (ct) { case QStyle::CT_SpinBox: - // hack to work around horrible sizeHint() code in QAbstractSpinBox + // hack to work around horrible sizeHint() code in QAbstractSpinBox + sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget); sz.setHeight(sz.height() - 3); break; - case QStyle::CT_TabWidget: + case QStyle::CT_TabWidget: // the size between the pane and the "contentsRect" (+4,+4) // (the "contentsRect" is on the inside of the pane) sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget); diff --git a/src/widgets/styles/qmacstyle_mac_p.h b/src/widgets/styles/qmacstyle_mac_p.h index d06a5a951f..aef04a93bc 100644 --- a/src/widgets/styles/qmacstyle_mac_p.h +++ b/src/widgets/styles/qmacstyle_mac_p.h @@ -44,8 +44,6 @@ #include <QtWidgets/qcommonstyle.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -130,6 +128,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QMACSTYLE_MAC_P_H diff --git a/src/widgets/styles/qproxystyle.cpp b/src/widgets/styles/qproxystyle.cpp index 66ace0f60b..911223cae2 100644 --- a/src/widgets/styles/qproxystyle.cpp +++ b/src/widgets/styles/qproxystyle.cpp @@ -108,10 +108,9 @@ void QProxyStylePrivate::ensureBaseStyle() const } /*! - Constructs a QProxyStyle object for overriding behavior in \a style - or in the current application \l{QStyle}{style} if \a style is 0 - (default). Normally \a style is 0, because you want to override - behavior in the system style. + Constructs a QProxyStyle object for overriding behavior in the + specified base \a style, or in the current \l{QApplication::style} + {application style} if base \a style is not specified. Ownership of \a style is transferred to QProxyStyle. */ @@ -127,6 +126,26 @@ QProxyStyle::QProxyStyle(QStyle *style) : } /*! + Constructs a QProxyStyle object for overriding behavior in + the base style specified by style \a key, or in the current + \l{QApplication::style}{application style} if the specified + style \a key is unrecognized. + + \sa QStyleFactory::create() +*/ +QProxyStyle::QProxyStyle(const QString &key) : + QCommonStyle(*new QProxyStylePrivate()) +{ + Q_D(QProxyStyle); + QStyle *style = QStyleFactory::create(key); + if (style) { + d->baseStyle = style; + style->setProxy(this); + style->setParent(this); // Take ownership + } +} + +/*! Destroys the QProxyStyle object. */ QProxyStyle::~QProxyStyle() diff --git a/src/widgets/styles/qproxystyle.h b/src/widgets/styles/qproxystyle.h index 52b02c8e5b..d1623c745c 100644 --- a/src/widgets/styles/qproxystyle.h +++ b/src/widgets/styles/qproxystyle.h @@ -44,8 +44,6 @@ #include <QtWidgets/QCommonStyle> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -57,7 +55,8 @@ class Q_WIDGETS_EXPORT QProxyStyle : public QCommonStyle Q_OBJECT public: - QProxyStyle(QStyle *baseStyle = 0); + QProxyStyle(QStyle *style = 0); + QProxyStyle(const QString &key); ~QProxyStyle(); QStyle *baseStyle() const; @@ -107,6 +106,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QPROXYSTYLE_H diff --git a/src/widgets/styles/qstyle.h b/src/widgets/styles/qstyle.h index b69f5da6c5..a9ac1813c5 100644 --- a/src/widgets/styles/qstyle.h +++ b/src/widgets/styles/qstyle.h @@ -50,8 +50,6 @@ #include <QtGui/qpalette.h> #include <QtWidgets/qsizepolicy.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -831,6 +829,4 @@ Q_WIDGETS_EXPORT QDebug operator<<(QDebug debug, QStyle::State state); QT_END_NAMESPACE -QT_END_HEADER - #endif // QSTYLE_H diff --git a/src/widgets/styles/qstyleanimation.cpp b/src/widgets/styles/qstyleanimation.cpp index 61048df96a..4deafdebcc 100644 --- a/src/widgets/styles/qstyleanimation.cpp +++ b/src/widgets/styles/qstyleanimation.cpp @@ -46,13 +46,9 @@ QT_BEGIN_NAMESPACE -QStyleAnimation::QStyleAnimation(QObject *target) : QAbstractAnimation(), +QStyleAnimation::QStyleAnimation(QObject *target) : QAbstractAnimation(target), _delay(0), _duration(-1), _startTime(QTime::currentTime()) { - if (target) { - moveToThread(target->thread()); - setParent(target); - } } QStyleAnimation::~QStyleAnimation() diff --git a/src/widgets/styles/qstylefactory.cpp b/src/widgets/styles/qstylefactory.cpp index 471d3b748d..5028371e23 100644 --- a/src/widgets/styles/qstylefactory.cpp +++ b/src/widgets/styles/qstylefactory.cpp @@ -48,6 +48,9 @@ #include "qwindowsstyle_p.h" #ifndef QT_NO_STYLE_FUSION #include "qfusionstyle_p.h" +#ifndef QT_NO_STYLE_ANDROID +#include "qandroidstyle_p.h" +#endif #endif #ifndef QT_NO_STYLE_GTK #include "qgtkstyle_p.h" @@ -143,6 +146,11 @@ QStyle *QStyleFactory::create(const QString& key) ret = new QFusionStyle; else #endif +#ifndef QT_NO_STYLE_ANDROID + if (style == QLatin1String("android")) + ret = new QAndroidStyle; + else +#endif #ifndef QT_NO_STYLE_GTK if (style == QLatin1String("gtk") || style == QLatin1String("gtk+")) ret = new QGtkStyle; @@ -206,6 +214,10 @@ QStringList QStyleFactory::keys() (QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA && (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based))) list << QLatin1String("WindowsVista"); #endif +#ifndef QT_NO_STYLE_ANDROID + if (!list.contains(QLatin1String("Android"))) + list << QLatin1String("Android"); +#endif #ifndef QT_NO_STYLE_GTK if (!list.contains(QLatin1String("GTK+"))) list << QLatin1String("GTK+"); diff --git a/src/widgets/styles/qstylefactory.h b/src/widgets/styles/qstylefactory.h index 500e86a9d4..fb0f0c4851 100644 --- a/src/widgets/styles/qstylefactory.h +++ b/src/widgets/styles/qstylefactory.h @@ -44,8 +44,6 @@ #include <QtCore/qstringlist.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -60,6 +58,4 @@ public: QT_END_NAMESPACE -QT_END_HEADER - #endif // QSTYLEFACTORY_H diff --git a/src/widgets/styles/qstyleoption.cpp b/src/widgets/styles/qstyleoption.cpp index 01e51d594d..eff6837c5a 100644 --- a/src/widgets/styles/qstyleoption.cpp +++ b/src/widgets/styles/qstyleoption.cpp @@ -206,7 +206,7 @@ void QStyleOption::init(const QWidget *widget) if (!(state & QStyle::State_Active) && !qt_mac_can_clickThrough(widget)) state &= ~QStyle::State_Enabled; #endif -#ifdef Q_OS_MAC +#if defined(Q_OS_MAC) && !defined(Q_OS_IOS) switch (QMacStyle::widgetSizePolicy(widget)) { case QMacStyle::SizeSmall: state |= QStyle::State_Small; diff --git a/src/widgets/styles/qstyleoption.h b/src/widgets/styles/qstyleoption.h index 4109c8e702..d2af5d14d8 100644 --- a/src/widgets/styles/qstyleoption.h +++ b/src/widgets/styles/qstyleoption.h @@ -56,8 +56,6 @@ # include <QtCore/qabstractitemmodel.h> #endif -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -751,6 +749,4 @@ Q_WIDGETS_EXPORT QDebug operator<<(QDebug debug, const QStyleOption &option); QT_END_NAMESPACE -QT_END_HEADER - #endif // QSTYLEOPTION_H diff --git a/src/widgets/styles/qstylepainter.h b/src/widgets/styles/qstylepainter.h index dee01c09a3..681997b0f2 100644 --- a/src/widgets/styles/qstylepainter.h +++ b/src/widgets/styles/qstylepainter.h @@ -46,8 +46,6 @@ #include <QtWidgets/qstyle.h> #include <QtWidgets/qwidget.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -106,6 +104,4 @@ void QStylePainter::drawItemPixmap(const QRect &r, int flags, const QPixmap &pix QT_END_NAMESPACE -QT_END_HEADER - #endif // QSTYLEPAINTER_H diff --git a/src/widgets/styles/qstyleplugin.h b/src/widgets/styles/qstyleplugin.h index d34f0c0a15..77c1f906fd 100644 --- a/src/widgets/styles/qstyleplugin.h +++ b/src/widgets/styles/qstyleplugin.h @@ -45,8 +45,6 @@ #include <QtCore/qplugin.h> #include <QtCore/qfactoryinterface.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -66,6 +64,4 @@ public: QT_END_NAMESPACE -QT_END_HEADER - #endif // QSTYLEPLUGIN_H diff --git a/src/widgets/styles/qwindowscestyle_p.h b/src/widgets/styles/qwindowscestyle_p.h index 5d38abe41b..cd23afb480 100644 --- a/src/widgets/styles/qwindowscestyle_p.h +++ b/src/widgets/styles/qwindowscestyle_p.h @@ -44,8 +44,6 @@ #include <private/qwindowsstyle_p.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -98,6 +96,4 @@ public: QT_END_NAMESPACE -QT_END_HEADER - #endif // QWINDOWSCESTYLE_P_H diff --git a/src/widgets/styles/qwindowsmobilestyle_p.h b/src/widgets/styles/qwindowsmobilestyle_p.h index 21df982344..c0a6f779c9 100644 --- a/src/widgets/styles/qwindowsmobilestyle_p.h +++ b/src/widgets/styles/qwindowsmobilestyle_p.h @@ -44,8 +44,6 @@ #include <private/qwindowsstyle_p.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -111,6 +109,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif //QWINDOWSMOBILESTYLE_P_H diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp index 2b48096a7b..e288b1854d 100644 --- a/src/widgets/styles/qwindowsstyle.cpp +++ b/src/widgets/styles/qwindowsstyle.cpp @@ -2358,7 +2358,6 @@ QSize QWindowsStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, sz += QSize(QWindowsStylePrivate::windowsItemHMargin * 4, QWindowsStylePrivate::windowsItemVMargin * 2); break; #endif - // Otherwise, fall through case CT_ToolButton: if (qstyleoption_cast<const QStyleOptionToolButton *>(opt)) return sz += QSize(7, 6); diff --git a/src/widgets/styles/qwindowsstyle_p.h b/src/widgets/styles/qwindowsstyle_p.h index 65573acf67..5a52dcd683 100644 --- a/src/widgets/styles/qwindowsstyle_p.h +++ b/src/widgets/styles/qwindowsstyle_p.h @@ -44,8 +44,6 @@ #include <QtWidgets/qcommonstyle.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -103,6 +101,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QWINDOWSSTYLE_P_H diff --git a/src/widgets/styles/qwindowsvistastyle.cpp b/src/widgets/styles/qwindowsvistastyle.cpp index a621cab04d..e9bc17f78f 100644 --- a/src/widgets/styles/qwindowsvistastyle.cpp +++ b/src/widgets/styles/qwindowsvistastyle.cpp @@ -1585,7 +1585,7 @@ void QWindowsVistaStyle::drawComplexControl(ComplexControl control, const QStyle bool doTransition = ((state & State_Sunken) != (oldState & State_Sunken) || (state & State_On) != (oldState & State_On) || (state & State_MouseOver) != (oldState & State_MouseOver) || - oldActiveControls != option->activeSubControls); + oldActiveControls != int(option->activeSubControls)); if (qstyleoption_cast<const QStyleOptionSlider *>(option)) { QRect oldSliderPos = styleObject->property("_q_stylesliderpos").toRect(); diff --git a/src/widgets/styles/qwindowsvistastyle_p.h b/src/widgets/styles/qwindowsvistastyle_p.h index 2a06c78806..7a559325bd 100644 --- a/src/widgets/styles/qwindowsvistastyle_p.h +++ b/src/widgets/styles/qwindowsvistastyle_p.h @@ -44,8 +44,6 @@ #include <private/qwindowsxpstyle_p.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -99,6 +97,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QWINDOWSVISTASTYLE_P_H diff --git a/src/widgets/styles/qwindowsxpstyle_p.h b/src/widgets/styles/qwindowsxpstyle_p.h index 626bcc4ad7..cf171b1436 100644 --- a/src/widgets/styles/qwindowsxpstyle_p.h +++ b/src/widgets/styles/qwindowsxpstyle_p.h @@ -44,8 +44,6 @@ #include <private/qwindowsstyle_p.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -99,6 +97,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QWINDOWSXPSTYLE_P_H diff --git a/src/widgets/styles/styles.pri b/src/widgets/styles/styles.pri index b15eb1fa48..a207cd2761 100644 --- a/src/widgets/styles/styles.pri +++ b/src/widgets/styles/styles.pri @@ -40,7 +40,7 @@ contains( styles, all ) { styles = fusion mac windows windowsxp windowsvista } -!macx-*|ios:styles -= mac +!mac:styles -= mac contains(QT_CONFIG, gtkstyle) { QMAKE_CXXFLAGS += $$QT_CFLAGS_QGTKSTYLE @@ -136,3 +136,10 @@ contains( styles, windowsmobile ) { } else { DEFINES += QT_NO_STYLE_WINDOWSMOBILE } + +contains( styles, android ) { + HEADERS += styles/qandroidstyle_p.h + SOURCES += styles/qandroidstyle.cpp +} else { + DEFINES += QT_NO_STYLE_ANDROID +} diff --git a/src/widgets/util/qcolormap.h b/src/widgets/util/qcolormap.h index d3b9535923..a41b1e472b 100644 --- a/src/widgets/util/qcolormap.h +++ b/src/widgets/util/qcolormap.h @@ -47,8 +47,6 @@ #include <QtCore/qvector.h> #include <QtGui/qwindowdefs.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -91,6 +89,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QCOLORMAP_H diff --git a/src/widgets/util/qcompleter.h b/src/widgets/util/qcompleter.h index ba43e4470a..57a1676d01 100644 --- a/src/widgets/util/qcompleter.h +++ b/src/widgets/util/qcompleter.h @@ -48,8 +48,6 @@ #include <QtCore/qabstractitemmodel.h> #include <QtCore/qrect.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -165,6 +163,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QCOMPLETER_H diff --git a/src/widgets/util/qscroller.h b/src/widgets/util/qscroller.h index b0ff9dc5c5..fac9b519c7 100644 --- a/src/widgets/util/qscroller.h +++ b/src/widgets/util/qscroller.h @@ -46,8 +46,6 @@ #include <QtCore/QPointF> #include <QtWidgets/QScrollerProperties> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -149,6 +147,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QSCROLLER_H diff --git a/src/widgets/util/qscrollerproperties.h b/src/widgets/util/qscrollerproperties.h index 58bce74bca..27b71e4d27 100644 --- a/src/widgets/util/qscrollerproperties.h +++ b/src/widgets/util/qscrollerproperties.h @@ -46,8 +46,6 @@ #include <QtCore/QMetaType> #include <QtCore/QVariant> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -134,6 +132,4 @@ QT_END_NAMESPACE Q_DECLARE_METATYPE(QScrollerProperties::OvershootPolicy) Q_DECLARE_METATYPE(QScrollerProperties::FrameRates) -QT_END_HEADER - #endif // QSCROLLERPROPERTIES_H diff --git a/src/widgets/util/qsystemtrayicon.cpp b/src/widgets/util/qsystemtrayicon.cpp index a5d3aedf76..48bba9701c 100644 --- a/src/widgets/util/qsystemtrayicon.cpp +++ b/src/widgets/util/qsystemtrayicon.cpp @@ -81,7 +81,7 @@ QT_BEGIN_NAMESPACE tray specification, including recent versions of KDE and GNOME. \li All supported versions of Mac OS X. Note that the Growl notification system must be installed for - QSystemTrayIcon::showMessage() to display messages. + QSystemTrayIcon::showMessage() to display messages on Mac OS X prior to 10.8 (Mountain Lion). \endlist To check whether a system tray is present on the user's desktop, diff --git a/src/widgets/util/qsystemtrayicon.h b/src/widgets/util/qsystemtrayicon.h index 201ea85253..6745319993 100644 --- a/src/widgets/util/qsystemtrayicon.h +++ b/src/widgets/util/qsystemtrayicon.h @@ -48,8 +48,6 @@ #include <QtGui/qicon.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -126,7 +124,5 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QT_NO_SYSTEMTRAYICON #endif // QSYSTEMTRAYICON_H diff --git a/src/widgets/util/qundogroup.h b/src/widgets/util/qundogroup.h index 8e888f993b..31e6aea1f1 100644 --- a/src/widgets/util/qundogroup.h +++ b/src/widgets/util/qundogroup.h @@ -45,8 +45,6 @@ #include <QtCore/qobject.h> #include <QtCore/qstring.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE class QUndoGroupPrivate; @@ -104,6 +102,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QUNDOGROUP_H diff --git a/src/widgets/util/qundostack.h b/src/widgets/util/qundostack.h index 44b8337f57..c7071fe42a 100644 --- a/src/widgets/util/qundostack.h +++ b/src/widgets/util/qundostack.h @@ -45,8 +45,6 @@ #include <QtCore/qobject.h> #include <QtCore/qstring.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -153,6 +151,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QUNDOSTACK_H diff --git a/src/widgets/util/qundoview.h b/src/widgets/util/qundoview.h index bc262799d9..a9c0ac4e95 100644 --- a/src/widgets/util/qundoview.h +++ b/src/widgets/util/qundoview.h @@ -47,8 +47,6 @@ #ifndef QT_NO_UNDOVIEW -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE class QUndoViewPrivate; @@ -95,7 +93,5 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QT_NO_UNDOVIEW #endif // QUNDOVIEW_H diff --git a/src/widgets/util/util.pri b/src/widgets/util/util.pri index 5847b12166..598a3082c0 100644 --- a/src/widgets/util/util.pri +++ b/src/widgets/util/util.pri @@ -36,6 +36,6 @@ win32:!wince* { SOURCES += util/qsystemtrayicon_qpa.cpp } -macx { +mac { OBJECTIVE_SOURCES += util/qscroller_mac.mm } diff --git a/src/widgets/widgets/qabstractbutton.h b/src/widgets/widgets/qabstractbutton.h index 9c27e3523f..793f984fa0 100644 --- a/src/widgets/widgets/qabstractbutton.h +++ b/src/widgets/widgets/qabstractbutton.h @@ -46,8 +46,6 @@ #include <QtGui/qkeysequence.h> #include <QtWidgets/qwidget.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -155,6 +153,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QABSTRACTBUTTON_H diff --git a/src/widgets/widgets/qabstractscrollarea.h b/src/widgets/widgets/qabstractscrollarea.h index 79038e9fdd..5c3c5aaace 100644 --- a/src/widgets/widgets/qabstractscrollarea.h +++ b/src/widgets/widgets/qabstractscrollarea.h @@ -44,8 +44,6 @@ #include <QtWidgets/qframe.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -140,6 +138,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QABSTRACTSCROLLAREA_H diff --git a/src/widgets/widgets/qabstractslider.h b/src/widgets/widgets/qabstractslider.h index a49970a2d5..e82adcf71d 100644 --- a/src/widgets/widgets/qabstractslider.h +++ b/src/widgets/widgets/qabstractslider.h @@ -44,8 +44,6 @@ #include <QtWidgets/qwidget.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -163,6 +161,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QABSTRACTSLIDER_H diff --git a/src/widgets/widgets/qabstractspinbox.cpp b/src/widgets/widgets/qabstractspinbox.cpp index 14d22c458b..c2b04ce461 100644 --- a/src/widgets/widgets/qabstractspinbox.cpp +++ b/src/widgets/widgets/qabstractspinbox.cpp @@ -825,14 +825,13 @@ QSize QAbstractSpinBox::sizeHint() const ensurePolished(); const QFontMetrics fm(fontMetrics()); - int h = d->edit->sizeHint().height() + 4; + int h = d->edit->sizeHint().height(); int w = 0; QString s; - s = d->prefix + d->textFromValue(d->minimum) + d->suffix + QLatin1Char(' '); - s.truncate(18); + QString fixedContent = d->prefix + d->suffix + QLatin1Char(' '); + s = d->textFromValue(d->minimum) + fixedContent; w = qMax(w, fm.width(s)); - s = d->prefix + d->textFromValue(d->maximum) + d->suffix + QLatin1Char(' '); - s.truncate(18); + s = d->textFromValue(d->maximum) + fixedContent; w = qMax(w, fm.width(s)); if (d->specialValueText.size()) { s = d->specialValueText; @@ -857,27 +856,29 @@ QSize QAbstractSpinBox::minimumSizeHint() const { Q_D(const QAbstractSpinBox); if (d->cachedMinimumSizeHint.isEmpty()) { + //Use the prefix and range to calculate the minimumSizeHint ensurePolished(); const QFontMetrics fm(fontMetrics()); int h = d->edit->minimumSizeHint().height(); - int w = fm.width(QLatin1String("1000")); + int w = 0; + + QString s; + QString fixedContent = d->prefix + QLatin1Char(' '); + s = d->textFromValue(d->minimum) + fixedContent; + w = qMax(w, fm.width(s)); + s = d->textFromValue(d->maximum) + fixedContent; + w = qMax(w, fm.width(s)); + + if (d->specialValueText.size()) { + s = d->specialValueText; + w = qMax(w, fm.width(s)); + } w += 2; // cursor blinking space QStyleOptionSpinBox opt; initStyleOption(&opt); QSize hint(w, h); - QSize extra(35, 6); - opt.rect.setSize(hint + extra); - extra += hint - style()->subControlRect(QStyle::CC_SpinBox, &opt, - QStyle::SC_SpinBoxEditField, this).size(); - // get closer to final result by repeating the calculation - opt.rect.setSize(hint + extra); - extra += hint - style()->subControlRect(QStyle::CC_SpinBox, &opt, - QStyle::SC_SpinBoxEditField, this).size(); - hint += extra; - - opt.rect = rect(); d->cachedMinimumSizeHint = style()->sizeFromContents(QStyle::CT_SpinBox, &opt, hint, this) .expandedTo(QApplication::globalStrut()); @@ -1724,7 +1725,8 @@ void QAbstractSpinBoxPrivate::setRange(const QVariant &min, const QVariant &max) clearCache(); minimum = min; maximum = (variantCompare(min, max) < 0 ? max : min); - cachedSizeHint = QSize(); // minimumSizeHint doesn't care about min/max + cachedSizeHint = QSize(); + cachedMinimumSizeHint = QSize(); // minimumSizeHint cares about min/max reset(); if (!(bound(value) == value)) { diff --git a/src/widgets/widgets/qabstractspinbox.h b/src/widgets/widgets/qabstractspinbox.h index 49cd8f38f1..e29f9de0d5 100644 --- a/src/widgets/widgets/qabstractspinbox.h +++ b/src/widgets/widgets/qabstractspinbox.h @@ -45,8 +45,6 @@ #include <QtWidgets/qwidget.h> #include <QtGui/qvalidator.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -175,6 +173,4 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstractSpinBox::StepEnabled) QT_END_NAMESPACE -QT_END_HEADER - #endif // QABSTRACTSPINBOX_H diff --git a/src/widgets/widgets/qbuttongroup.h b/src/widgets/widgets/qbuttongroup.h index 76ce549d95..600df83d76 100644 --- a/src/widgets/widgets/qbuttongroup.h +++ b/src/widgets/widgets/qbuttongroup.h @@ -44,8 +44,6 @@ #include <QtCore/qobject.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -100,6 +98,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QBUTTONGROUP_H diff --git a/src/widgets/widgets/qcalendarwidget.h b/src/widgets/widgets/qcalendarwidget.h index 5d4c1722b4..815fcc823a 100644 --- a/src/widgets/widgets/qcalendarwidget.h +++ b/src/widgets/widgets/qcalendarwidget.h @@ -45,8 +45,6 @@ #include <QtWidgets/qwidget.h> #include <QtCore/qdatetime.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -191,7 +189,5 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QCALENDARWIDGET_H diff --git a/src/widgets/widgets/qcheckbox.h b/src/widgets/widgets/qcheckbox.h index 1bf1bf56a0..3a1e6fc020 100644 --- a/src/widgets/widgets/qcheckbox.h +++ b/src/widgets/widgets/qcheckbox.h @@ -44,8 +44,6 @@ #include <QtWidgets/qabstractbutton.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -92,6 +90,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QCHECKBOX_H diff --git a/src/widgets/widgets/qcombobox.h b/src/widgets/widgets/qcombobox.h index 0eb5881b93..26e9f0882c 100644 --- a/src/widgets/widgets/qcombobox.h +++ b/src/widgets/widgets/qcombobox.h @@ -47,8 +47,6 @@ #include <QtCore/qabstractitemmodel.h> #include <QtCore/qvariant.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE #ifndef QT_NO_COMBOBOX @@ -280,6 +278,4 @@ inline void QComboBox::insertItem(int aindex, const QString &atext, QT_END_NAMESPACE -QT_END_HEADER - #endif // QCOMBOBOX_H diff --git a/src/widgets/widgets/qcommandlinkbutton.h b/src/widgets/widgets/qcommandlinkbutton.h index a74d6a7b84..d8d2617587 100644 --- a/src/widgets/widgets/qcommandlinkbutton.h +++ b/src/widgets/widgets/qcommandlinkbutton.h @@ -44,8 +44,6 @@ #include <QtWidgets/qpushbutton.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -81,6 +79,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QCOMMANDLINKBUTTON diff --git a/src/widgets/widgets/qdatetimeedit.cpp b/src/widgets/widgets/qdatetimeedit.cpp index fb64850923..7ee2bf64fb 100644 --- a/src/widgets/widgets/qdatetimeedit.cpp +++ b/src/widgets/widgets/qdatetimeedit.cpp @@ -981,9 +981,9 @@ QSize QDateTimeEdit::sizeHint() const int h = d->edit->sizeHint().height(); int w = 0; QString s; - s = d->textFromValue(d->minimum) + QLatin1String(" "); + s = d->textFromValue(d->minimum) + QLatin1Char(' '); w = qMax<int>(w, fm.width(s)); - s = d->textFromValue(d->maximum) + QLatin1String(" "); + s = d->textFromValue(d->maximum) + QLatin1Char(' '); w = qMax<int>(w, fm.width(s)); if (d->specialValueText.size()) { s = d->specialValueText; @@ -1000,19 +1000,8 @@ QSize QDateTimeEdit::sizeHint() const } else #endif { - QSize extra(35, 6); QStyleOptionSpinBox opt; initStyleOption(&opt); - opt.rect.setSize(hint + extra); - extra += hint - style()->subControlRect(QStyle::CC_SpinBox, &opt, - QStyle::SC_SpinBoxEditField, this).size(); - // get closer to final result by repeating the calculation - opt.rect.setSize(hint + extra); - extra += hint - style()->subControlRect(QStyle::CC_SpinBox, &opt, - QStyle::SC_SpinBoxEditField, this).size(); - hint += extra; - - opt.rect = rect(); d->cachedSizeHint = style()->sizeFromContents(QStyle::CT_SpinBox, &opt, hint, this) .expandedTo(QApplication::globalStrut()); } @@ -1023,6 +1012,7 @@ QSize QDateTimeEdit::sizeHint() const return d->cachedSizeHint; } + /*! \reimp */ diff --git a/src/widgets/widgets/qdatetimeedit.h b/src/widgets/widgets/qdatetimeedit.h index d3197632cf..30978113d0 100644 --- a/src/widgets/widgets/qdatetimeedit.h +++ b/src/widgets/widgets/qdatetimeedit.h @@ -46,8 +46,6 @@ #include <QtCore/qvariant.h> #include <QtWidgets/qabstractspinbox.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -235,6 +233,4 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QDateTimeEdit::Sections) QT_END_NAMESPACE -QT_END_HEADER - #endif // QDATETIMEEDIT_H diff --git a/src/widgets/widgets/qdial.h b/src/widgets/widgets/qdial.h index c7be201b96..ee53edc8dd 100644 --- a/src/widgets/widgets/qdial.h +++ b/src/widgets/widgets/qdial.h @@ -45,8 +45,6 @@ #include <QtWidgets/qabstractslider.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -105,6 +103,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QDIAL_H diff --git a/src/widgets/widgets/qdialogbuttonbox.h b/src/widgets/widgets/qdialogbuttonbox.h index 06776bbd93..d2969d2eda 100644 --- a/src/widgets/widgets/qdialogbuttonbox.h +++ b/src/widgets/widgets/qdialogbuttonbox.h @@ -44,8 +44,6 @@ #include <QtWidgets/qwidget.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -162,6 +160,4 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QDialogButtonBox::StandardButtons) QT_END_NAMESPACE -QT_END_HEADER - #endif // QDIALOGBUTTONBOX_H diff --git a/src/widgets/widgets/qdockwidget.h b/src/widgets/widgets/qdockwidget.h index 993ae6b914..a886aee1d0 100644 --- a/src/widgets/widgets/qdockwidget.h +++ b/src/widgets/widgets/qdockwidget.h @@ -44,8 +44,6 @@ #include <QtWidgets/qwidget.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -140,6 +138,4 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QDockWidget::DockWidgetFeatures) QT_END_NAMESPACE -QT_END_HEADER - #endif // QDYNAMICDOCKWIDGET_H diff --git a/src/widgets/widgets/qfocusframe.h b/src/widgets/widgets/qfocusframe.h index 2993ed5c7f..aab76c2569 100644 --- a/src/widgets/widgets/qfocusframe.h +++ b/src/widgets/widgets/qfocusframe.h @@ -44,8 +44,6 @@ #include <QtWidgets/qwidget.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -76,6 +74,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QFOCUSFRAME_H diff --git a/src/widgets/widgets/qfontcombobox.h b/src/widgets/widgets/qfontcombobox.h index e5e1580cdb..4101b37e2b 100644 --- a/src/widgets/widgets/qfontcombobox.h +++ b/src/widgets/widgets/qfontcombobox.h @@ -47,8 +47,6 @@ #ifndef QT_NO_FONTCOMBOBOX -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -105,7 +103,5 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QFontComboBox::FontFilters) QT_END_NAMESPACE -QT_END_HEADER - #endif // QT_NO_FONTCOMBOBOX #endif diff --git a/src/widgets/widgets/qframe.h b/src/widgets/widgets/qframe.h index 021d7f5ab0..3539f9fae0 100644 --- a/src/widgets/widgets/qframe.h +++ b/src/widgets/widgets/qframe.h @@ -44,8 +44,6 @@ #include <QtWidgets/qwidget.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -125,6 +123,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QFRAME_H diff --git a/src/widgets/widgets/qgroupbox.h b/src/widgets/widgets/qgroupbox.h index d462a574fd..cfe32df3cc 100644 --- a/src/widgets/widgets/qgroupbox.h +++ b/src/widgets/widgets/qgroupbox.h @@ -44,8 +44,6 @@ #include <QtWidgets/qframe.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -111,6 +109,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QGROUPBOX_H diff --git a/src/widgets/widgets/qlabel.cpp b/src/widgets/widgets/qlabel.cpp index a9a9c0cea5..f34b30013f 100644 --- a/src/widgets/widgets/qlabel.cpp +++ b/src/widgets/widgets/qlabel.cpp @@ -1032,20 +1032,6 @@ void QLabel::paintEvent(QPaintEvent *) d->ensureTextLayouted(); QAbstractTextDocumentLayout::PaintContext context; - if (!isEnabled() && !d->control && - // We cannot support etched for rich text controls because custom - // colors and links will override the light palette - style->styleHint(QStyle::SH_EtchDisabledText, &opt, this)) { - context.palette = opt.palette; - context.palette.setColor(QPalette::Text, context.palette.light().color()); - painter.save(); - painter.translate(lr.x() + 1, lr.y() + 1); - painter.setClipRect(lr.translated(-lr.x() - 1, -lr.y() - 1)); - QAbstractTextDocumentLayout *layout = d->control->document()->documentLayout(); - layout->draw(&painter, context); - painter.restore(); - } - // Adjust the palette context.palette = opt.palette; diff --git a/src/widgets/widgets/qlabel.h b/src/widgets/widgets/qlabel.h index 114d239918..311eab958f 100644 --- a/src/widgets/widgets/qlabel.h +++ b/src/widgets/widgets/qlabel.h @@ -44,8 +44,6 @@ #include <QtWidgets/qframe.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -164,6 +162,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QLABEL_H diff --git a/src/widgets/widgets/qlcdnumber.h b/src/widgets/widgets/qlcdnumber.h index 4495f40f7f..e5c2b40cf8 100644 --- a/src/widgets/widgets/qlcdnumber.h +++ b/src/widgets/widgets/qlcdnumber.h @@ -45,8 +45,6 @@ #include <QtWidgets/qframe.h> #include <QtCore/qbitarray.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -122,6 +120,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QLCDNUMBER_H diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp index 65969a7ebb..5187968ddf 100644 --- a/src/widgets/widgets/qlineedit.cpp +++ b/src/widgets/widgets/qlineedit.cpp @@ -1758,7 +1758,7 @@ void QLineEdit::focusOutEvent(QFocusEvent *e) QObject::disconnect(d->control->completer(), 0, this, 0); } #endif - update(); + QWidget::focusOutEvent(e); } /*!\reimp @@ -1801,7 +1801,7 @@ void QLineEdit::paintEvent(QPaintEvent *) int minRB = qMax(0, -fm.minRightBearing()); if (d->control->text().isEmpty()) { - if (!hasFocus() && !d->placeholderText.isEmpty()) { + if (!d->placeholderText.isEmpty()) { QColor col = pal.text().color(); col.setAlpha(128); QPen oldpen = p.pen(); @@ -1810,7 +1810,6 @@ void QLineEdit::paintEvent(QPaintEvent *) QString elidedText = fm.elidedText(d->placeholderText, Qt::ElideRight, lineRect.width()); p.drawText(lineRect, va, elidedText); p.setPen(oldpen); - return; } } diff --git a/src/widgets/widgets/qlineedit.h b/src/widgets/widgets/qlineedit.h index af50170d3d..56a18d4fab 100644 --- a/src/widgets/widgets/qlineedit.h +++ b/src/widgets/widgets/qlineedit.h @@ -47,8 +47,6 @@ #include <QtCore/qstring.h> #include <QtCore/qmargins.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -248,6 +246,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QLINEEDIT_H diff --git a/src/widgets/widgets/qmaccocoaviewcontainer_mac.h b/src/widgets/widgets/qmaccocoaviewcontainer_mac.h index 1bb631d296..d555d5cedd 100644 --- a/src/widgets/widgets/qmaccocoaviewcontainer_mac.h +++ b/src/widgets/widgets/qmaccocoaviewcontainer_mac.h @@ -44,8 +44,6 @@ #include <QtWidgets/QWidget> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -67,6 +65,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QCOCOAVIEWCONTAINER_H diff --git a/src/widgets/widgets/qmacnativewidget_mac.h b/src/widgets/widgets/qmacnativewidget_mac.h index 0a227f1756..47d7e17638 100644 --- a/src/widgets/widgets/qmacnativewidget_mac.h +++ b/src/widgets/widgets/qmacnativewidget_mac.h @@ -44,8 +44,6 @@ #include <QtWidgets/QWidget> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -68,6 +66,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QMACNATIVEWIDGET_H diff --git a/src/widgets/widgets/qmainwindow.h b/src/widgets/widgets/qmainwindow.h index d00e75d7ae..0527725976 100644 --- a/src/widgets/widgets/qmainwindow.h +++ b/src/widgets/widgets/qmainwindow.h @@ -45,8 +45,6 @@ #include <QtWidgets/qwidget.h> #include <QtWidgets/qtabwidget.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -210,6 +208,4 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QMainWindow::DockOptions) QT_END_NAMESPACE -QT_END_HEADER - #endif // QDYNAMICMAINWINDOW_H diff --git a/src/widgets/widgets/qmdiarea.h b/src/widgets/widgets/qmdiarea.h index 52278e35aa..9cb8cb01dc 100644 --- a/src/widgets/widgets/qmdiarea.h +++ b/src/widgets/widgets/qmdiarea.h @@ -45,8 +45,6 @@ #include <QtWidgets/qabstractscrollarea.h> #include <QtWidgets/qtabwidget.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -172,7 +170,5 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QMdiArea::AreaOptions) QT_END_NAMESPACE -QT_END_HEADER - #endif // QT_NO_MDIAREA #endif // QMDIAREA_H diff --git a/src/widgets/widgets/qmdisubwindow.cpp b/src/widgets/widgets/qmdisubwindow.cpp index 01ee2528f3..7ea2369ba5 100644 --- a/src/widgets/widgets/qmdisubwindow.cpp +++ b/src/widgets/widgets/qmdisubwindow.cpp @@ -183,14 +183,6 @@ static const QStyle::SubControl SubControls[] = }; static const int NumSubControls = sizeof(SubControls) / sizeof(SubControls[0]); -static const QStyle::StandardPixmap ButtonPixmaps[] = -{ - QStyle::SP_TitleBarMinButton, - QStyle::SP_TitleBarNormalButton, - QStyle::SP_TitleBarCloseButton -}; -static const int NumButtonPixmaps = sizeof(ButtonPixmaps) / sizeof(ButtonPixmaps[0]); - static const Qt::WindowFlags CustomizeWindowFlags = Qt::FramelessWindowHint | Qt::CustomizeWindowHint diff --git a/src/widgets/widgets/qmdisubwindow.h b/src/widgets/widgets/qmdisubwindow.h index 9dac7e1ee0..db5238f07f 100644 --- a/src/widgets/widgets/qmdisubwindow.h +++ b/src/widgets/widgets/qmdisubwindow.h @@ -44,8 +44,6 @@ #include <QtWidgets/qwidget.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -151,8 +149,6 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QMdiSubWindow::SubWindowOptions) QT_END_NAMESPACE -QT_END_HEADER - #endif // QT_NO_MDIAREA #endif // QMDISUBWINDOW_H diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index 922a38b324..117d56ff18 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -67,6 +67,7 @@ #include "qwidgetaction.h" #include "qtoolbutton.h" #include "qpushbutton.h" +#include "qtooltip.h" #include <private/qpushbutton_p.h> #include <private/qaction_p.h> #include <private/qguiapplication_p.h> @@ -2368,6 +2369,19 @@ QMenu::event(QEvent *e) if (d->currentAction) d->popupAction(d->currentAction, 0, false); break; +#ifndef QT_NO_TOOLTIP + case QEvent::ToolTip: + if (d->toolTipsVisible) { + const QHelpEvent *ev = static_cast<const QHelpEvent*>(e); + if (const QAction *action = actionAt(ev->pos())) { + const QString toolTip = action->d_func()->tooltip; + if (!toolTip.isEmpty()) + QToolTip::showText(ev->globalPos(), toolTip, this); + return true; + } + } + break; +#endif // QT_NO_TOOLTIP #ifndef QT_NO_WHATSTHIS case QEvent::QueryWhatsThis: e->setAccepted(d->whatsThis.size()); @@ -2826,7 +2840,7 @@ QMenu::timerEvent(QTimerEvent *e) } } -void copyActionToPlatformItem(const QAction *action, QPlatformMenuItem* item) +static void copyActionToPlatformItem(const QAction *action, QPlatformMenuItem* item) { item->setText(action->text()); item->setIsSeparator(action->isSeparator()); @@ -2834,6 +2848,7 @@ void copyActionToPlatformItem(const QAction *action, QPlatformMenuItem* item) item->setIcon(action->icon()); item->setVisible(action->isVisible()); item->setShortcut(action->shortcut()); + item->setCheckable(action->isCheckable()); item->setChecked(action->isChecked()); item->setFont(action->font()); item->setRole((QPlatformMenuItem::MenuRole) action->menuRole()); @@ -3089,6 +3104,32 @@ void QMenu::setSeparatorsCollapsible(bool collapse) d->platformMenu->syncSeparatorsCollapsible(collapse); } +/*! + \property QMenu::toolTipsVisible + \since 5.1 + + \brief whether tooltips of menu actions should be visible + + This property specifies whether action menu entries show + their tooltip. + + By default, this property is false. +*/ +bool QMenu::toolTipsVisible() const +{ + Q_D(const QMenu); + return d->toolTipsVisible; +} + +void QMenu::setToolTipsVisible(bool visible) +{ + Q_D(QMenu); + if (d->toolTipsVisible == visible) + return; + + d->toolTipsVisible = visible; +} + QT_END_NAMESPACE // for private slots diff --git a/src/widgets/widgets/qmenu.h b/src/widgets/widgets/qmenu.h index e58e7a231f..7547c69a10 100644 --- a/src/widgets/widgets/qmenu.h +++ b/src/widgets/widgets/qmenu.h @@ -51,8 +51,6 @@ #include <windef.h> // for HMENU #endif -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -72,6 +70,7 @@ private: Q_PROPERTY(QString title READ title WRITE setTitle) Q_PROPERTY(QIcon icon READ icon WRITE setIcon) Q_PROPERTY(bool separatorsCollapsible READ separatorsCollapsible WRITE setSeparatorsCollapsible) + Q_PROPERTY(bool toolTipsVisible READ toolTipsVisible WRITE setToolTipsVisible) public: explicit QMenu(QWidget *parent = 0); @@ -141,6 +140,9 @@ public: bool separatorsCollapsible() const; void setSeparatorsCollapsible(bool collapse); + bool toolTipsVisible() const; + void setToolTipsVisible(bool visible); + Q_SIGNALS: void aboutToShow(); void aboutToHide(); @@ -201,6 +203,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QMENU_H diff --git a/src/widgets/widgets/qmenu_p.h b/src/widgets/widgets/qmenu_p.h index 0b8137cff3..27b4745951 100644 --- a/src/widgets/widgets/qmenu_p.h +++ b/src/widgets/widgets/qmenu_p.h @@ -84,7 +84,8 @@ class QMenuPrivate : public QWidgetPrivate Q_DECLARE_PUBLIC(QMenu) public: QMenuPrivate() : itemsDirty(0), maxIconWidth(0), tabWidth(0), ncols(0), - collapsibleSeparators(true), activationRecursionGuard(false), hasHadMouse(0), aboutToHide(0), motions(0), + collapsibleSeparators(true), toolTipsVisible(false), + activationRecursionGuard(false), hasHadMouse(0), aboutToHide(0), motions(0), currentAction(0), #ifdef QT_KEYPAD_NAVIGATION selectAction(0), @@ -123,6 +124,7 @@ public: QRect popupGeometry(int screen = -1) const; mutable uint ncols : 4; //4 bits is probably plenty uint collapsibleSeparators : 1; + uint toolTipsVisible : 1; QSize adjustMenuSizeForScreen(const QRect & screen); int getLastVisibleAction() const; diff --git a/src/widgets/widgets/qmenu_wince_resource_p.h b/src/widgets/widgets/qmenu_wince_resource_p.h index c3ec386780..783f3285af 100644 --- a/src/widgets/widgets/qmenu_wince_resource_p.h +++ b/src/widgets/widgets/qmenu_wince_resource_p.h @@ -50,7 +50,6 @@ // We mean it. // -QT_BEGIN_HEADER #define IDR_MAIN_MENU 102 #define IDR_MAIN_MENU2 103 @@ -90,5 +89,3 @@ QT_BEGIN_HEADER #define IDM_MENU7 40009 #define IDM_MENU8 40010 -QT_END_HEADER - diff --git a/src/widgets/widgets/qmenubar.h b/src/widgets/widgets/qmenubar.h index 4b850ca3fe..592c951815 100644 --- a/src/widgets/widgets/qmenubar.h +++ b/src/widgets/widgets/qmenubar.h @@ -44,8 +44,6 @@ #include <QtWidgets/qmenu.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -159,6 +157,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QMENUBAR_H diff --git a/src/widgets/widgets/qplaintextedit.h b/src/widgets/widgets/qplaintextedit.h index 1e9fc373bb..7e2e10d8e4 100644 --- a/src/widgets/widgets/qplaintextedit.h +++ b/src/widgets/widgets/qplaintextedit.h @@ -53,8 +53,6 @@ #ifndef QT_NO_TEXTEDIT -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -319,8 +317,6 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QT_NO_TEXTEDIT diff --git a/src/widgets/widgets/qprogressbar.cpp b/src/widgets/widgets/qprogressbar.cpp index 72e937b604..6b3dadddf0 100644 --- a/src/widgets/widgets/qprogressbar.cpp +++ b/src/widgets/widgets/qprogressbar.cpp @@ -41,6 +41,7 @@ #include "qprogressbar.h" #ifndef QT_NO_PROGRESSBAR +#include <qlocale.h> #include <qevent.h> #include <qpainter.h> #include <qstylepainter.h> @@ -61,6 +62,7 @@ public: QProgressBarPrivate(); void init(); + void initDefaultFormat(); inline void resetLayoutItemMargins(); int minimum; @@ -68,6 +70,7 @@ public: int value; Qt::Alignment alignment; uint textVisible : 1; + uint defaultFormat: 1; int lastPaintedValue; Qt::Orientation orientation; bool invertedAppearance; @@ -79,9 +82,16 @@ public: QProgressBarPrivate::QProgressBarPrivate() : minimum(0), maximum(100), value(-1), alignment(Qt::AlignLeft), textVisible(true), - lastPaintedValue(-1), orientation(Qt::Horizontal), invertedAppearance(false), - textDirection(QProgressBar::TopToBottom), format(QLatin1String("%p%")) + defaultFormat(true), lastPaintedValue(-1), orientation(Qt::Horizontal), invertedAppearance(false), + textDirection(QProgressBar::TopToBottom) { + initDefaultFormat(); +} + +void QProgressBarPrivate::initDefaultFormat() +{ + if (defaultFormat) + format = QLatin1String("%p") + locale.percent(); } void QProgressBarPrivate::init() @@ -466,19 +476,21 @@ QString QProgressBar::text() const qint64 totalSteps = qint64(d->maximum) - d->minimum; QString result = d->format; - result.replace(QLatin1String("%m"), QString::number(totalSteps)); - result.replace(QLatin1String("%v"), QString::number(d->value)); + QLocale locale = d->locale; // Omit group separators for compatibility with previous versions that were non-localized. + locale.setNumberOptions(locale.numberOptions() | QLocale::OmitGroupSeparator); + result.replace(QLatin1String("%m"), locale.toString(totalSteps)); + result.replace(QLatin1String("%v"), locale.toString(d->value)); // If max and min are equal and we get this far, it means that the // progress bar has one step and that we are on that step. Return // 100% here in order to avoid division by zero further down. if (totalSteps == 0) { - result.replace(QLatin1String("%p"), QString::number(100)); + result.replace(QLatin1String("%p"), locale.toString(int(100))); return result; } int progress = (qreal(d->value) - d->minimum) * 100.0 / totalSteps; - result.replace(QLatin1String("%p"), QString::number(progress)); + result.replace(QLatin1String("%p"), locale.toString(progress)); return result; } @@ -568,12 +580,19 @@ QProgressBar::Direction QProgressBar::textDirection() const bool QProgressBar::event(QEvent *e) { Q_D(QProgressBar); - if (e->type() == QEvent::StyleChange + switch (e->type()) { + case QEvent::StyleChange: #ifdef Q_OS_MAC - || e->type() == QEvent::MacSizeChange + case QEvent::MacSizeChange: #endif - ) d->resetLayoutItemMargins(); + break; + case QEvent::LocaleChange: + d->initDefaultFormat(); + break; + default: + break; + } return QWidget::event(e); } @@ -596,6 +615,15 @@ void QProgressBar::setFormat(const QString &format) if (d->format == format) return; d->format = format; + d->defaultFormat = false; + update(); +} + +void QProgressBar::resetFormat() +{ + Q_D(QProgressBar); + d->defaultFormat = true; + d->initDefaultFormat(); update(); } diff --git a/src/widgets/widgets/qprogressbar.h b/src/widgets/widgets/qprogressbar.h index a1b0fcee1d..71bb2fc8f8 100644 --- a/src/widgets/widgets/qprogressbar.h +++ b/src/widgets/widgets/qprogressbar.h @@ -44,8 +44,6 @@ #include <QtWidgets/qframe.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -67,7 +65,7 @@ class Q_WIDGETS_EXPORT QProgressBar : public QWidget Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) Q_PROPERTY(bool invertedAppearance READ invertedAppearance WRITE setInvertedAppearance) Q_PROPERTY(Direction textDirection READ textDirection WRITE setTextDirection) - Q_PROPERTY(QString format READ format WRITE setFormat) + Q_PROPERTY(QString format READ format WRITE setFormat RESET resetFormat) public: enum Direction { TopToBottom, BottomToTop }; @@ -98,6 +96,7 @@ public: QProgressBar::Direction textDirection() const; void setFormat(const QString &format); + void resetFormat(); QString format() const; public Q_SLOTS: @@ -125,6 +124,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QPROGRESSBAR_H diff --git a/src/widgets/widgets/qpushbutton.h b/src/widgets/widgets/qpushbutton.h index 3aa3673478..1638123e0e 100644 --- a/src/widgets/widgets/qpushbutton.h +++ b/src/widgets/widgets/qpushbutton.h @@ -44,8 +44,6 @@ #include <QtWidgets/qabstractbutton.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -112,6 +110,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QPUSHBUTTON_H diff --git a/src/widgets/widgets/qradiobutton.h b/src/widgets/widgets/qradiobutton.h index 13a73ba3c9..ad73d0387c 100644 --- a/src/widgets/widgets/qradiobutton.h +++ b/src/widgets/widgets/qradiobutton.h @@ -44,8 +44,6 @@ #include <QtWidgets/qabstractbutton.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -79,6 +77,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QRADIOBUTTON_H diff --git a/src/widgets/widgets/qrubberband.h b/src/widgets/widgets/qrubberband.h index 34962e52cc..3b74ec9f10 100644 --- a/src/widgets/widgets/qrubberband.h +++ b/src/widgets/widgets/qrubberband.h @@ -44,8 +44,6 @@ #include <QtWidgets/qwidget.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -98,6 +96,4 @@ inline void QRubberBand::move(int ax, int ay) QT_END_NAMESPACE -QT_END_HEADER - #endif // QRUBBERBAND_H diff --git a/src/widgets/widgets/qscrollarea.h b/src/widgets/widgets/qscrollarea.h index 18a9fac598..d506cd829c 100644 --- a/src/widgets/widgets/qscrollarea.h +++ b/src/widgets/widgets/qscrollarea.h @@ -44,8 +44,6 @@ #include <QtWidgets/qabstractscrollarea.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -95,6 +93,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QSCROLLAREA_H diff --git a/src/widgets/widgets/qscrollbar.h b/src/widgets/widgets/qscrollbar.h index e9514c59a9..b452c97c10 100644 --- a/src/widgets/widgets/qscrollbar.h +++ b/src/widgets/widgets/qscrollbar.h @@ -45,8 +45,6 @@ #include <QtWidgets/qwidget.h> #include <QtWidgets/qabstractslider.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -94,6 +92,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QSCROLLBAR_H diff --git a/src/widgets/widgets/qsizegrip.h b/src/widgets/widgets/qsizegrip.h index c79e4716da..61f71b788f 100644 --- a/src/widgets/widgets/qsizegrip.h +++ b/src/widgets/widgets/qsizegrip.h @@ -44,8 +44,6 @@ #include <QtWidgets/qwidget.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -83,6 +81,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QSIZEGRIP_H diff --git a/src/widgets/widgets/qslider.h b/src/widgets/widgets/qslider.h index 460d52e57c..5c4aade02c 100644 --- a/src/widgets/widgets/qslider.h +++ b/src/widgets/widgets/qslider.h @@ -44,8 +44,6 @@ #include <QtWidgets/qabstractslider.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -106,6 +104,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QSLIDER_H diff --git a/src/widgets/widgets/qspinbox.cpp b/src/widgets/widgets/qspinbox.cpp index e61c1c877a..b51bf4c078 100644 --- a/src/widgets/widgets/qspinbox.cpp +++ b/src/widgets/widgets/qspinbox.cpp @@ -268,6 +268,7 @@ void QSpinBox::setPrefix(const QString &prefix) d->updateEdit(); d->cachedSizeHint = QSize(); + d->cachedMinimumSizeHint = QSize(); // minimumSizeHint cares about the prefix updateGeometry(); } diff --git a/src/widgets/widgets/qspinbox.h b/src/widgets/widgets/qspinbox.h index 7be16f460b..501e6388ce 100644 --- a/src/widgets/widgets/qspinbox.h +++ b/src/widgets/widgets/qspinbox.h @@ -44,8 +44,6 @@ #include <QtWidgets/qabstractspinbox.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -172,6 +170,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QSPINBOX_H diff --git a/src/widgets/widgets/qsplashscreen.h b/src/widgets/widgets/qsplashscreen.h index af97a38cf8..b356291adc 100644 --- a/src/widgets/widgets/qsplashscreen.h +++ b/src/widgets/widgets/qsplashscreen.h @@ -45,8 +45,6 @@ #include <QtGui/qpixmap.h> #include <QtWidgets/qwidget.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -88,6 +86,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QSPLASHSCREEN_H diff --git a/src/widgets/widgets/qsplitter.h b/src/widgets/widgets/qsplitter.h index 79785b257e..511aadd2c9 100644 --- a/src/widgets/widgets/qsplitter.h +++ b/src/widgets/widgets/qsplitter.h @@ -45,8 +45,6 @@ #include <QtWidgets/qframe.h> #include <QtWidgets/qsizepolicy.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -170,6 +168,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QSPLITTER_H diff --git a/src/widgets/widgets/qstackedwidget.h b/src/widgets/widgets/qstackedwidget.h index 451de7fe40..59b340d03e 100644 --- a/src/widgets/widgets/qstackedwidget.h +++ b/src/widgets/widgets/qstackedwidget.h @@ -44,8 +44,6 @@ #include <QtWidgets/qframe.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -94,6 +92,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QSTACKEDWIDGET_H diff --git a/src/widgets/widgets/qstatusbar.h b/src/widgets/widgets/qstatusbar.h index de3982cffd..989d3b9623 100644 --- a/src/widgets/widgets/qstatusbar.h +++ b/src/widgets/widgets/qstatusbar.h @@ -44,8 +44,6 @@ #include <QtWidgets/qwidget.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -101,6 +99,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QSTATUSBAR_H diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp index e0ea3e798d..787cc754f6 100644 --- a/src/widgets/widgets/qtabbar.cpp +++ b/src/widgets/widgets/qtabbar.cpp @@ -80,7 +80,7 @@ inline static bool verticalTabs(QTabBar::Shape shape) void QTabBarPrivate::updateMacBorderMetrics() { -#if (defined Q_WS_MAC) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) +#if defined(Q_WS_MAC) if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) { Q_Q(QTabBar); ::HIContentBorderMetrics metrics; diff --git a/src/widgets/widgets/qtabbar.h b/src/widgets/widgets/qtabbar.h index 0bb10c2aa9..8d2bb6d11d 100644 --- a/src/widgets/widgets/qtabbar.h +++ b/src/widgets/widgets/qtabbar.h @@ -44,8 +44,6 @@ #include <QtWidgets/qwidget.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -212,6 +210,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QTABBAR_H diff --git a/src/widgets/widgets/qtabwidget.h b/src/widgets/widgets/qtabwidget.h index 54bf1e638d..5bed379931 100644 --- a/src/widgets/widgets/qtabwidget.h +++ b/src/widgets/widgets/qtabwidget.h @@ -45,8 +45,6 @@ #include <QtWidgets/qwidget.h> #include <QtGui/qicon.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -181,6 +179,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QTABWIDGET_H diff --git a/src/widgets/widgets/qtextbrowser.cpp b/src/widgets/widgets/qtextbrowser.cpp index 61e7a5fbfb..b4158e3b8d 100644 --- a/src/widgets/widgets/qtextbrowser.cpp +++ b/src/widgets/widgets/qtextbrowser.cpp @@ -151,12 +151,18 @@ public: QString QTextBrowserPrivate::findFile(const QUrl &name) const { QString fileName; - if (name.scheme() == QLatin1String("qrc")) + if (name.scheme() == QLatin1String("qrc")) { fileName = QLatin1String(":/") + name.path(); - else if (name.scheme().isEmpty()) + } else if (name.scheme().isEmpty()) { fileName = name.path(); - else - fileName = name.toLocalFile(); + } else { +#if defined(Q_OS_ANDROID) + if (name.scheme() == QLatin1String("assets")) + fileName = QLatin1String("assets:") + name.path(); + else +#endif + fileName = name.toLocalFile(); + } if (QFileInfo(fileName).isAbsolute()) return fileName; @@ -217,13 +223,14 @@ void QTextBrowserPrivate::_q_activateAnchor(const QString &href) textOrSourceChanged = false; #ifndef QT_NO_DESKTOPSERVICES - if ((openExternalLinks - && url.scheme() != QLatin1String("file") - && url.scheme() != QLatin1String("qrc") - && !url.isRelative()) - || (url.isRelative() && !currentURL.isRelative() - && currentURL.scheme() != QLatin1String("file") - && currentURL.scheme() != QLatin1String("qrc"))) { + bool isFileScheme = + url.scheme() == QLatin1String("file") +#if defined(Q_OS_ANDROID) + || url.scheme() == QLatin1String("assets") +#endif + || url.scheme() == QLatin1String("qrc"); + if ((openExternalLinks && !isFileScheme && !url.isRelative()) + || (url.isRelative() && !currentURL.isRelative() && !isFileScheme)) { QDesktopServices::openUrl(url); return; } diff --git a/src/widgets/widgets/qtextbrowser.h b/src/widgets/widgets/qtextbrowser.h index 900dd27211..3f9488152a 100644 --- a/src/widgets/widgets/qtextbrowser.h +++ b/src/widgets/widgets/qtextbrowser.h @@ -45,8 +45,6 @@ #include <QtWidgets/qtextedit.h> #include <QtCore/qurl.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -129,6 +127,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QTEXTBROWSER_H diff --git a/src/widgets/widgets/qtextedit.cpp b/src/widgets/widgets/qtextedit.cpp index f033b6544c..a79cea31a1 100644 --- a/src/widgets/widgets/qtextedit.cpp +++ b/src/widgets/widgets/qtextedit.cpp @@ -182,7 +182,7 @@ void QTextEditPrivate::init(const QString &html) q->setFocusPolicy(Qt::WheelFocus); q->setAttribute(Qt::WA_KeyCompression); q->setAttribute(Qt::WA_InputMethodEnabled); - + q->setInputMethodHints(Qt::ImhMultiLine); #ifndef QT_NO_CURSOR viewport->setCursor(Qt::IBeamCursor); #endif diff --git a/src/widgets/widgets/qtextedit.h b/src/widgets/widgets/qtextedit.h index b44083a502..8eb274342f 100644 --- a/src/widgets/widgets/qtextedit.h +++ b/src/widgets/widgets/qtextedit.h @@ -51,8 +51,6 @@ #ifndef QT_NO_TEXTEDIT -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -314,8 +312,6 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QTextEdit::AutoFormatting) QT_END_NAMESPACE -QT_END_HEADER - #endif // QT_NO_TEXTEDIT #endif // QTEXTEDIT_H diff --git a/src/widgets/widgets/qtoolbar.h b/src/widgets/widgets/qtoolbar.h index a706ccf46e..99a8544153 100644 --- a/src/widgets/widgets/qtoolbar.h +++ b/src/widgets/widgets/qtoolbar.h @@ -44,8 +44,6 @@ #include <QtWidgets/qwidget.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -172,6 +170,4 @@ inline QAction *QToolBar::actionAt(int ax, int ay) const QT_END_NAMESPACE -QT_END_HEADER - #endif // QDYNAMICTOOLBAR_H diff --git a/src/widgets/widgets/qtoolbox.h b/src/widgets/widgets/qtoolbox.h index 6d7166f2ac..dc3dbad5b2 100644 --- a/src/widgets/widgets/qtoolbox.h +++ b/src/widgets/widgets/qtoolbox.h @@ -45,8 +45,6 @@ #include <QtWidgets/qframe.h> #include <QtGui/qicon.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -126,6 +124,4 @@ inline int QToolBox::insertItem(int index, QWidget *item, const QString &text) QT_END_NAMESPACE -QT_END_HEADER - #endif // QTOOLBOX_H diff --git a/src/widgets/widgets/qtoolbutton.h b/src/widgets/widgets/qtoolbutton.h index 778f2d8f15..40ebfed9fb 100644 --- a/src/widgets/widgets/qtoolbutton.h +++ b/src/widgets/widgets/qtoolbutton.h @@ -44,8 +44,6 @@ #include <QtWidgets/qabstractbutton.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -139,6 +137,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QTOOLBUTTON_H diff --git a/src/widgets/widgets/qwidgetlinecontrol_p.h b/src/widgets/widgets/qwidgetlinecontrol_p.h index f5fd900681..b114648c3c 100644 --- a/src/widgets/widgets/qwidgetlinecontrol_p.h +++ b/src/widgets/widgets/qwidgetlinecontrol_p.h @@ -69,8 +69,6 @@ #include "qplatformdefs.h" -QT_BEGIN_HEADER - #ifdef DrawText # undef DrawText #endif @@ -533,8 +531,6 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QT_NO_LINEEDIT #endif // QWidgetLineControl_P_H diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index 9a2a83503b..d4801f6d5a 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -1726,12 +1726,13 @@ void QWidgetTextControlPrivate::mouseReleaseEvent(QEvent *e, Qt::MouseButton but { Q_Q(QWidgetTextControl); + const QTextCursor oldSelection = cursor; if (sendMouseEventToInputContext( e, QEvent::MouseButtonRelease, button, pos, modifiers, buttons, globalPos)) { + repaintOldAndNewSelection(oldSelection); return; } - const QTextCursor oldSelection = cursor; const int oldCursorPos = cursor.position(); #ifndef QT_NO_DRAGANDDROP diff --git a/src/widgets/widgets/qwidgettextcontrol_p.h b/src/widgets/widgets/qwidgettextcontrol_p.h index 070dc660c6..c805e38da7 100644 --- a/src/widgets/widgets/qwidgettextcontrol_p.h +++ b/src/widgets/widgets/qwidgettextcontrol_p.h @@ -65,8 +65,6 @@ #include <QtGui/qclipboard.h> #include <QtCore/qmimedata.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -297,6 +295,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QWidgetTextControl_H |