diff options
-rw-r--r-- | doc/src/platforms/platform-notes.qdoc | 63 | ||||
-rw-r--r-- | src/corelib/global/qnamespace.h | 1 | ||||
-rw-r--r-- | src/corelib/global/qnamespace.qdoc | 29 | ||||
-rw-r--r-- | src/gui/dialogs/qfiledialog.cpp | 1 | ||||
-rw-r--r-- | src/gui/graphicsview/qgridlayoutengine.cpp | 2 | ||||
-rw-r--r-- | src/gui/itemviews/qheaderview.cpp | 14 | ||||
-rw-r--r-- | src/gui/kernel/qcursor_mac.mm | 2 | ||||
-rw-r--r-- | src/gui/kernel/qeventdispatcher_mac.mm | 68 | ||||
-rw-r--r-- | src/gui/kernel/qt_cocoa_helpers_mac.mm | 4 | ||||
-rw-r--r-- | src/gui/painting/qdrawingprimitive_sse2_p.h | 4 | ||||
-rw-r--r-- | src/gui/styles/qmacstyle_mac.mm | 7 | ||||
-rw-r--r-- | src/gui/widgets/qdialogbuttonbox.cpp | 8 | ||||
-rw-r--r-- | src/gui/widgets/qeffects.cpp | 29 | ||||
-rw-r--r-- | src/gui/widgets/qmdiarea.cpp | 79 | ||||
-rw-r--r-- | src/gui/widgets/qmdiarea.h | 12 | ||||
-rw-r--r-- | src/gui/widgets/qmdiarea_p.h | 4 | ||||
-rw-r--r-- | src/gui/widgets/qtoolbarlayout.cpp | 8 | ||||
-rw-r--r-- | tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp | 112 | ||||
-rw-r--r-- | tests/auto/qheaderview/tst_qheaderview.cpp | 37 | ||||
-rw-r--r-- | tests/auto/qmdiarea/tst_qmdiarea.cpp | 73 | ||||
-rw-r--r-- | tests/auto/qwidget/tst_qwidget.cpp | 2 |
21 files changed, 433 insertions, 126 deletions
diff --git a/doc/src/platforms/platform-notes.qdoc b/doc/src/platforms/platform-notes.qdoc index de6eb7f..113ad86 100644 --- a/doc/src/platforms/platform-notes.qdoc +++ b/doc/src/platforms/platform-notes.qdoc @@ -602,6 +602,69 @@ problem, it probably is a good idea to turn off precompiled headers. Also, consider filing a bug report with Apple so that they can improve support for this feature. + + \section2 Attributes + The following lists a set of useful attributes that can be used to tweak applications + on Mac: + + Qt::AA_MacPluginApplication, Qt::AA_DontUseNativeMenuBar, Qt::AA_MacDontSwapCtrlAndMeta + Qt::WA_MacNoClickThrough, Qt::WA_MacOpaqueSizeGrip, Qt::WA_MacShowFocusRect, + Qt::WA_MacNormalSize, Qt::WA_MacSmallSize, Qt::WA_MacMiniSize, Qt::WA_MacVariableSize, + Qt::WA_MacBrushedMetal, Qt::WA_MacAlwaysShowToolWindow, Qt::WA_MacFrameworkScaled, + Qt::WA_MacNoShadow, Qt::Sheet, Qt::Drawer, Qt::MacWindowToolBarButtonHint, + QMainWindow::unifiedTitleAndToolBarOnMac + + \section2 Mixing Qt with native code + Two classes are awailable for either adding native Cocoa views/controls + inside a Qt application, or the opposite, embedding Qt into a native + Cocoa application: + + QMacCocoaViewContainer, QMacNativeWidget + + \section3 Using native Cocoa panels + Launching native Cocoa panels from within a Qt application can sometimes + be problematic. The reason is that Qt's event dispatcher is more flexible + than what Cocoa offers, and lets the user spin the event dispatcher (and + running QEventLoop::exec) without having to think about whether or not modal + dialogs are showing on screen (which is a difference to Cocoa). Therefore + we need to do special bookkeeping in Qt to handle this correctly, which + unfortunately make mixing in native panels hard. The best way at the moment + to do this, is to follow the pattern below, where we post the call to the + function with native code rather than calling it directly. Then we now that + Qt has cleanly updated any pending event loop recursions before the native + panel is shown: + + \code + #include <QtGui> + + class NativeProxyObject : public QObject + { + Q_OBJECT + public slots: + void execNativeDialogLater() + { + QMetaObject::invokeMethod(this, "execNativeDialogNow", Qt::QueuedConnection); + } + + void execNativeDialogNow() + { + NSRunAlertPanel(@"A Native dialog", @"", @"OK", @"", @""); + } + + }; + + #include "main.moc" + + int main(int argc, char **argv){ + QApplication app(argc, argv); + NativeProxyObject proxy; + QPushButton button("Show native dialog"); + QObject::connect(&button, SIGNAL(clicked()), &proxy, SLOT(execNativeDialogLater())); + button.show(); + return app.exec(); + } + + \endcode */ /*! diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index afbaa27..f015ed0 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -1628,6 +1628,7 @@ public: AccessibleDescriptionRole = 12, // More general purpose SizeHintRole = 13, + InitialSortOrderRole = 14, // Internal UiLib roles. Start worrying when public roles go that high. DisplayPropertyRole = 27, DecorationPropertyRole = 28, diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index f98ea4a..bc15514 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -2699,19 +2699,22 @@ Roles describing appearance and meta data (with associated types): - \value FontRole The font used for items rendered with the default - delegate. (QFont) - \value TextAlignmentRole The alignment of the text for items rendered with the - default delegate. (Qt::AlignmentFlag) - \value BackgroundRole The background brush used for items rendered with - the default delegate. (QBrush) - \value BackgroundColorRole This role is obsolete. Use BackgroundRole instead. - \value ForegroundRole The foreground brush (text color, typically) - used for items rendered with the default delegate. - (QBrush) - \value TextColorRole This role is obsolete. Use ForegroundRole instead. - \value CheckStateRole This role is used to obtain the checked state of - an item. (Qt::CheckState) + \value FontRole The font used for items rendered with the default + delegate. (QFont) + \value TextAlignmentRole The alignment of the text for items rendered with the + default delegate. (Qt::AlignmentFlag) + \value BackgroundRole The background brush used for items rendered with + the default delegate. (QBrush) + \value BackgroundColorRole This role is obsolete. Use BackgroundRole instead. + \value ForegroundRole The foreground brush (text color, typically) + used for items rendered with the default delegate. + (QBrush) + \value TextColorRole This role is obsolete. Use ForegroundRole instead. + \value CheckStateRole This role is used to obtain the checked state of + an item. (Qt::CheckState) + \value InitialSortOrderRole This role is used to obtain the initial sort order + of a header view section. (Qt::SortOrder). This + role was introduced in Qt 4.8. Accessibility roles (with associated types): diff --git a/src/gui/dialogs/qfiledialog.cpp b/src/gui/dialogs/qfiledialog.cpp index 0c1304f..897a916 100644 --- a/src/gui/dialogs/qfiledialog.cpp +++ b/src/gui/dialogs/qfiledialog.cpp @@ -2996,6 +2996,7 @@ void QFileDialogPrivate::_q_useNameFilter(int index) const int fileNameExtensionLength = fileNameExtension.count(); fileName.replace(fileName.count() - fileNameExtensionLength, fileNameExtensionLength, newNameFilterExtension); + qFileDialogUi->listView->clearSelection(); lineEdit()->setText(fileName); } } diff --git a/src/gui/graphicsview/qgridlayoutengine.cpp b/src/gui/graphicsview/qgridlayoutengine.cpp index 375c723..b8586ce 100644 --- a/src/gui/graphicsview/qgridlayoutengine.cpp +++ b/src/gui/graphicsview/qgridlayoutengine.cpp @@ -1175,7 +1175,7 @@ QSizeF QGridLayoutEngine::sizeHint(const QLayoutStyleInfo &styleInfo, Qt::SizeHi //constraints to find the column widths q_rowData.calculateGeometries(0, rowCount(), height, sizehint_yy.data(), sizehint_heights.data(), 0, sizehint_totalBoxes[Ver], q_infos[Ver]); - ensureColumnAndRowData(&q_columnData, &sizehint_totalBoxes[Hor], styleInfo, sizehint_yy.data(), sizehint_heights.data(), Qt::Vertical); + ensureColumnAndRowData(&q_columnData, &sizehint_totalBoxes[Hor], styleInfo, sizehint_yy.data(), sizehint_heights.data(), Qt::Horizontal); sizeHintCalculated = true; } } diff --git a/src/gui/itemviews/qheaderview.cpp b/src/gui/itemviews/qheaderview.cpp index 6359f0b..d6d9536 100644 --- a/src/gui/itemviews/qheaderview.cpp +++ b/src/gui/itemviews/qheaderview.cpp @@ -3274,9 +3274,17 @@ void QHeaderViewPrivate::clear() void QHeaderViewPrivate::flipSortIndicator(int section) { Q_Q(QHeaderView); - bool ascending = (sortIndicatorSection != section - || sortIndicatorOrder == Qt::DescendingOrder); - q->setSortIndicator(section, ascending ? Qt::AscendingOrder : Qt::DescendingOrder); + Qt::SortOrder sortOrder; + if (sortIndicatorSection == section) { + sortOrder = (sortIndicatorOrder == Qt::DescendingOrder) ? Qt::AscendingOrder : Qt::DescendingOrder; + } else { + const QVariant value = model->headerData(section, orientation, Qt::InitialSortOrderRole); + if (value.canConvert(QVariant::Int)) + sortOrder = static_cast<Qt::SortOrder>(value.toInt()); + else + sortOrder = Qt::AscendingOrder; + } + q->setSortIndicator(section, sortOrder); } void QHeaderViewPrivate::cascadingResize(int visual, int newSize) diff --git a/src/gui/kernel/qcursor_mac.mm b/src/gui/kernel/qcursor_mac.mm index 0d57b85..0afa3ee 100644 --- a/src/gui/kernel/qcursor_mac.mm +++ b/src/gui/kernel/qcursor_mac.mm @@ -215,7 +215,7 @@ void qt_mac_update_cursor() widgetUnderMouse = qt_button_down; } else { QPoint localPoint; - QPoint globalPoint = QCursor::pos(); + QPoint globalPoint; qt_mac_getTargetForMouseEvent(0, QEvent::None, localPoint, globalPoint, 0, &widgetUnderMouse); } qt_mac_updateCursorWithWidgetUnderMouse(widgetUnderMouse); diff --git a/src/gui/kernel/qeventdispatcher_mac.mm b/src/gui/kernel/qeventdispatcher_mac.mm index 15410ad..677a736 100644 --- a/src/gui/kernel/qeventdispatcher_mac.mm +++ b/src/gui/kernel/qeventdispatcher_mac.mm @@ -561,6 +561,7 @@ bool QEventDispatcherMac::processEvents(QEventLoop::ProcessEventsFlags flags) wakeUp(); emit awake(); + bool excludeUserEvents = flags & QEventLoop::ExcludeUserInputEvents; bool retVal = false; forever { if (d->interrupt) @@ -571,7 +572,7 @@ bool QEventDispatcherMac::processEvents(QEventLoop::ProcessEventsFlags flags) NSEvent* event = 0; // First, send all previously excluded input events, if any: - if (!(flags & QEventLoop::ExcludeUserInputEvents)) { + if (!excludeUserEvents) { while (!d->queuedUserInputEvents.isEmpty()) { event = static_cast<NSEvent *>(d->queuedUserInputEvents.takeFirst()); if (!filterEvent(event)) { @@ -586,12 +587,12 @@ bool QEventDispatcherMac::processEvents(QEventLoop::ProcessEventsFlags flags) // application, we should not run or stop NSApplication; This will be // done from the application itself. And if processEvents is called // manually (rather than from a QEventLoop), we cannot enter a tight - // loop and block this call, but instead we need to return after one flush: + // loop and block this call, but instead we need to return after one flush. + // Finally, if we are to exclude user input events, we cannot call [NSApp run] + // as we then loose control over which events gets dispatched: const bool canExec_3rdParty = d->nsAppRunCalledByQt || ![NSApp isRunning]; - const bool canExec_Qt = - (flags & QEventLoop::DialogExec || flags & QEventLoop::EventLoopExec) - && !(flags & QEventLoop::ExcludeUserInputEvents); - + const bool canExec_Qt = !excludeUserEvents && + (flags & QEventLoop::DialogExec || flags & QEventLoop::EventLoopExec) ; if (canExec_Qt && canExec_3rdParty) { // We can use exec-mode, meaning that we can stay in a tight loop until @@ -619,22 +620,46 @@ bool QEventDispatcherMac::processEvents(QEventLoop::ProcessEventsFlags flags) // Instead we will process all current pending events and return. d->ensureNSAppInitialized(); if (NSModalSession session = d->currentModalSession()) { - if (flags & QEventLoop::WaitForMoreEvents) - qt_mac_waitForMoreModalSessionEvents(); - NSInteger status = [NSApp runModalSession:session]; - if (status != NSRunContinuesResponse && session == d->currentModalSessionCached) { - // INVARIANT: Someone called [NSApp stopModal:] from outside the event - // dispatcher (e.g to stop a native dialog). But that call wrongly stopped - // 'session' as well. As a result, we need to restart all internal sessions: - d->temporarilyStopAllModalSessions(); - } - retVal = true; - } else do { - event = [NSApp nextEventMatchingMask:NSAnyEventMask + // INVARIANT: a modal window is executing. + if (!excludeUserEvents) { + // Since we can dispatch all kinds of events, we choose + // to use cocoa's native way of running modal sessions: + if (flags & QEventLoop::WaitForMoreEvents) + qt_mac_waitForMoreModalSessionEvents(); + NSInteger status = [NSApp runModalSession:session]; + if (status != NSRunContinuesResponse && session == d->currentModalSessionCached) { + // INVARIANT: Someone called [NSApp stopModal:] from outside the event + // dispatcher (e.g to stop a native dialog). But that call wrongly stopped + // 'session' as well. As a result, we need to restart all internal sessions: + d->temporarilyStopAllModalSessions(); + } + retVal = true; + } else do { + // Dispatch all non-user events (but que non-user events up for later). In + // this case, we need more control over which events gets dispatched, and + // cannot use [NSApp runModalSession:session]: + event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil - inMode:NSDefaultRunLoopMode + inMode:NSModalPanelRunLoopMode dequeue: YES]; + if (event) { + if (IsMouseOrKeyEvent(event)) { + [event retain]; + d->queuedUserInputEvents.append(event); + continue; + } + if (!filterEvent(event) && qt_mac_send_event(flags, event, 0)) + retVal = true; + } + } while (!d->interrupt && event != nil); + } else do { + // INVARIANT: No modal window is executing. + event = [NSApp nextEventMatchingMask:NSAnyEventMask + untilDate:nil + inMode:NSDefaultRunLoopMode + dequeue: YES]; + if (event) { if (flags & QEventLoop::ExcludeUserInputEvents) { if (IsMouseOrKeyEvent(event)) { @@ -648,6 +673,11 @@ bool QEventDispatcherMac::processEvents(QEventLoop::ProcessEventsFlags flags) } } while (!d->interrupt && event != nil); + // Be sure to flush the Qt posted events when not using exec mode + // (exec mode will always do this call from the event loop source): + if (!d->interrupt) + QCoreApplicationPrivate::sendPostedEvents(0, 0, d->threadData); + // Since the window that holds modality might have changed while processing // events, we we need to interrupt when we return back the previous process // event recursion to ensure that we spin the correct modal session. diff --git a/src/gui/kernel/qt_cocoa_helpers_mac.mm b/src/gui/kernel/qt_cocoa_helpers_mac.mm index 1a93e8e..f4a1ea5 100644 --- a/src/gui/kernel/qt_cocoa_helpers_mac.mm +++ b/src/gui/kernel/qt_cocoa_helpers_mac.mm @@ -1048,7 +1048,6 @@ QWidget *qt_mac_getTargetForKeyEvent(QWidget *widgetThatReceivedEvent) // events QWidget *qt_mac_getTargetForMouseEvent( // You can call this function without providing an event. - // If so, set returnGlobalPoint before the call. NSEvent *event, QEvent::Type eventType, QPoint &returnLocalPoint, @@ -1057,7 +1056,8 @@ QWidget *qt_mac_getTargetForMouseEvent( QWidget **returnWidgetUnderMouse) { Q_UNUSED(event); - returnGlobalPoint = flipPoint([NSEvent mouseLocation]).toPoint(); + NSPoint nsglobalpoint = event ? [[event window] convertBaseToScreen:[event locationInWindow]] : [NSEvent mouseLocation]; + returnGlobalPoint = flipPoint(nsglobalpoint).toPoint(); QWidget *mouseGrabber = QWidget::mouseGrabber(); bool buttonDownNotBlockedByModal = qt_button_down && !QApplicationPrivate::isBlockedByModal(qt_button_down); QWidget *popup = QApplication::activePopupWidget(); diff --git a/src/gui/painting/qdrawingprimitive_sse2_p.h b/src/gui/painting/qdrawingprimitive_sse2_p.h index 2d61cc5..d8793c3 100644 --- a/src/gui/painting/qdrawingprimitive_sse2_p.h +++ b/src/gui/painting/qdrawingprimitive_sse2_p.h @@ -78,7 +78,7 @@ QT_BEGIN_NAMESPACE pixelVectorAG = _mm_mullo_epi16(pixelVectorAG, alphaChannel); \ pixelVectorRB = _mm_mullo_epi16(pixelVectorRB, alphaChannel); \ \ - /* 3. devide by 255, that's the tricky part. \ + /* 3. divide by 255, that's the tricky part. \ we do it like for BYTE_MUL(), with bit shift: X/255 ~= (X + X/256 + rounding)/256 */ \ /** so first (X + X/256 + rounding) */\ pixelVectorRB = _mm_add_epi16(pixelVectorRB, _mm_srli_epi16(pixelVectorRB, 8)); \ @@ -86,7 +86,7 @@ QT_BEGIN_NAMESPACE pixelVectorAG = _mm_add_epi16(pixelVectorAG, _mm_srli_epi16(pixelVectorAG, 8)); \ pixelVectorAG = _mm_add_epi16(pixelVectorAG, half); \ \ - /** second devide by 256 */\ + /** second divide by 256 */\ pixelVectorRB = _mm_srli_epi16(pixelVectorRB, 8); \ /** for AG, we could >> 8 to divide followed by << 8 to put the \ bytes in the correct position. By masking instead, we execute \ diff --git a/src/gui/styles/qmacstyle_mac.mm b/src/gui/styles/qmacstyle_mac.mm index ac05789..64722c7 100644 --- a/src/gui/styles/qmacstyle_mac.mm +++ b/src/gui/styles/qmacstyle_mac.mm @@ -4621,6 +4621,13 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex tdi.attributes &= ~kThemeTrackShowThumb; if (scrollBarLength < scrollButtonsCutoffSize(scrollButtonsCutoff, sizePolicy)) tdi.enableState = kThemeTrackNothingToScroll; + } 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 } HIThemeDrawTrack(&tdi, tracking ? 0 : &macRect, cg, diff --git a/src/gui/widgets/qdialogbuttonbox.cpp b/src/gui/widgets/qdialogbuttonbox.cpp index 5f17a2b..6fe87b6 100644 --- a/src/gui/widgets/qdialogbuttonbox.cpp +++ b/src/gui/widgets/qdialogbuttonbox.cpp @@ -562,6 +562,14 @@ QPushButton *QDialogButtonBoxPrivate::createButton(QDialogButtonBox::StandardBut } else { qWarning("QDialogButtonBox::createButton: Invalid ButtonRole, button not added"); } + +#ifdef Q_WS_MAC + // Since mnemonics is off by default on Mac, we add a Cmd-D + // shortcut here to e.g. make the "Don't Save" button work nativly: + if (sbutton == QDialogButtonBox::Discard) + button->setShortcut(QKeySequence(QLatin1String("Ctrl+D"))); +#endif + return button; } diff --git a/src/gui/widgets/qeffects.cpp b/src/gui/widgets/qeffects.cpp index 8e1e7c3..6b64d48 100644 --- a/src/gui/widgets/qeffects.cpp +++ b/src/gui/widgets/qeffects.cpp @@ -55,19 +55,6 @@ QT_BEGIN_NAMESPACE /* - Internal class to get access to protected QWidget-members -*/ - -class QAccessWidget : public QWidget -{ - friend class QAlphaWidget; - friend class QRollEffect; -public: - QAccessWidget(QWidget* parent=0, Qt::WindowFlags f = 0) - : QWidget(parent, f) {} -}; - -/* Internal class QAlphaWidget. The QAlphaWidget is shown while the animation lasts @@ -98,13 +85,12 @@ private: QImage backImage; QImage frontImage; QImage mixedImage; - QPointer<QAccessWidget> widget; + QPointer<QWidget> widget; int duration; int elapsed; bool showWidget; QTimer anim; QElapsedTimer checkTime; - double windowOpacity; }; static QAlphaWidget* q_blend = 0; @@ -119,8 +105,7 @@ QAlphaWidget::QAlphaWidget(QWidget* w, Qt::WindowFlags f) setEnabled(false); #endif setAttribute(Qt::WA_NoSystemBackground, true); - widget = (QAccessWidget*)w; - windowOpacity = w->windowOpacity(); + widget = w; alpha = 0; } @@ -129,7 +114,7 @@ QAlphaWidget::~QAlphaWidget() #if defined(Q_WS_WIN) && !defined(Q_WS_WINCE) // Restore user-defined opacity value if (widget) - widget->setWindowOpacity(windowOpacity); + widget->setWindowOpacity(1); #endif } @@ -268,10 +253,10 @@ void QAlphaWidget::render() alpha = 1; #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) - if (alpha >= windowOpacity || !showWidget) { + if (alpha >= 1 || !showWidget) { anim.stop(); qApp->removeEventFilter(this); - widget->setWindowOpacity(windowOpacity); + widget->setWindowOpacity(1); q_blend = 0; deleteLater(); } else { @@ -370,7 +355,7 @@ private slots: void scroll(); private: - QPointer<QAccessWidget> widget; + QPointer<QWidget> widget; int currentHeight; int currentWidth; @@ -401,7 +386,7 @@ QRollEffect::QRollEffect(QWidget* w, Qt::WindowFlags f, DirFlags orient) setEnabled(false); #endif - widget = (QAccessWidget*) w; + widget = w; Q_ASSERT(widget); setAttribute(Qt::WA_NoSystemBackground, true); diff --git a/src/gui/widgets/qmdiarea.cpp b/src/gui/widgets/qmdiarea.cpp index b02db4c..2a486bb 100644 --- a/src/gui/widgets/qmdiarea.cpp +++ b/src/gui/widgets/qmdiarea.cpp @@ -674,6 +674,8 @@ QMdiAreaPrivate::QMdiAreaPrivate() viewMode(QMdiArea::SubWindowView), #ifndef QT_NO_TABBAR documentMode(false), + tabsClosable(false), + tabsMovable(false), #endif #ifndef QT_NO_TABWIDGET tabShape(QTabWidget::Rounded), @@ -792,6 +794,27 @@ void QMdiAreaPrivate::_q_currentTabChanged(int index) #endif // QT_NO_TABBAR } +void QMdiAreaPrivate::_q_closeTab(int index) +{ +#ifdef QT_NO_TABBAR + Q_UNUSED(index); +#else + QMdiSubWindow *subWindow = childWindows.at(index); + Q_ASSERT(subWindow); + subWindow->close(); +#endif // QT_NO_TABBAR +} + +void QMdiAreaPrivate::_q_moveTab(int from, int to) +{ +#ifdef QT_NO_TABBAR + Q_UNUSED(from); + Q_UNUSED(to); +#else + childWindows.move(from, to); +#endif // QT_NO_TABBAR +} + /*! \internal */ @@ -1519,6 +1542,8 @@ void QMdiAreaPrivate::setViewMode(QMdiArea::ViewMode mode) Q_ASSERT(!tabBar); tabBar = new QMdiAreaTabBar(q); tabBar->setDocumentMode(documentMode); + tabBar->setTabsClosable(tabsClosable); + tabBar->setMovable(tabsMovable); #ifndef QT_NO_TABWIDGET tabBar->setShape(tabBarShapeFrom(tabShape, tabPosition)); #endif @@ -1550,6 +1575,8 @@ void QMdiAreaPrivate::setViewMode(QMdiArea::ViewMode mode) updateTabBarGeometry(); QObject::connect(tabBar, SIGNAL(currentChanged(int)), q, SLOT(_q_currentTabChanged(int))); + QObject::connect(tabBar, SIGNAL(tabCloseRequested(int)), q, SLOT(_q_closeTab(int))); + QObject::connect(tabBar, SIGNAL(tabMoved(int,int)), q, SLOT(_q_moveTab(int,int))); } else #endif // QT_NO_TABBAR { // SubWindowView @@ -1636,6 +1663,8 @@ void QMdiAreaPrivate::refreshTabBar() return; tabBar->setDocumentMode(documentMode); + tabBar->setTabsClosable(tabsClosable); + tabBar->setMovable(tabsMovable); #ifndef QT_NO_TABWIDGET tabBar->setShape(tabBarShapeFrom(tabShape, tabPosition)); #endif @@ -2114,6 +2143,56 @@ void QMdiArea::setDocumentMode(bool enabled) d->documentMode = enabled; d->refreshTabBar(); } + +/*! + \property QMdiArea::tabsClosable + \brief whether the tab bar should place close buttons on each tab in tabbed view mode. + \since 4.8 + + Tabs are not closable by default. + + \sa QTabBar::tabsClosable, setViewMode() +*/ +bool QMdiArea::tabsClosable() const +{ + Q_D(const QMdiArea); + return d->tabsClosable; +} + +void QMdiArea::setTabsClosable(bool closable) +{ + Q_D(QMdiArea); + if (d->tabsClosable == closable) + return; + + d->tabsClosable = closable; + d->refreshTabBar(); +} + +/*! + \property QMdiArea::tabsMovable + \brief whether the user can move the tabs within the tabbar area in tabbed view mode. + \since 4.8 + + Tabs are not movable by default. + + \sa QTabBar::tabsMovable, setViewMode() +*/ +bool QMdiArea::tabsMovable() const +{ + Q_D(const QMdiArea); + return d->tabsMovable; +} + +void QMdiArea::setTabsMovable(bool movable) +{ + Q_D(QMdiArea); + if (d->tabsMovable == movable) + return; + + d->tabsMovable = movable; + d->refreshTabBar(); +} #endif // QT_NO_TABBAR #ifndef QT_NO_TABWIDGET diff --git a/src/gui/widgets/qmdiarea.h b/src/gui/widgets/qmdiarea.h index 809bfe4..a4b357c 100644 --- a/src/gui/widgets/qmdiarea.h +++ b/src/gui/widgets/qmdiarea.h @@ -65,6 +65,8 @@ class Q_GUI_EXPORT QMdiArea : public QAbstractScrollArea Q_PROPERTY(ViewMode viewMode READ viewMode WRITE setViewMode) #ifndef QT_NO_TABBAR Q_PROPERTY(bool documentMode READ documentMode WRITE setDocumentMode) + Q_PROPERTY(bool tabsClosable READ tabsClosable WRITE setTabsClosable) + Q_PROPERTY(bool tabsMovable READ tabsMovable WRITE setTabsMovable) #endif #ifndef QT_NO_TABWIDGET Q_PROPERTY(QTabWidget::TabShape tabShape READ tabShape WRITE setTabShape) @@ -116,6 +118,12 @@ public: #ifndef QT_NO_TABBAR bool documentMode() const; void setDocumentMode(bool enabled); + + void setTabsClosable(bool closable); + bool tabsClosable() const; + + void setTabsMovable(bool movable); + bool tabsMovable() const; #endif #ifndef QT_NO_TABWIDGET void setTabShape(QTabWidget::TabShape shape); @@ -156,7 +164,9 @@ private: Q_DECLARE_PRIVATE(QMdiArea) Q_PRIVATE_SLOT(d_func(), void _q_deactivateAllWindows()) Q_PRIVATE_SLOT(d_func(), void _q_processWindowStateChanged(Qt::WindowStates, Qt::WindowStates)) - Q_PRIVATE_SLOT(d_func(), void _q_currentTabChanged(int index)) + Q_PRIVATE_SLOT(d_func(), void _q_currentTabChanged(int)) + Q_PRIVATE_SLOT(d_func(), void _q_closeTab(int)) + Q_PRIVATE_SLOT(d_func(), void _q_moveTab(int, int)) }; Q_DECLARE_OPERATORS_FOR_FLAGS(QMdiArea::AreaOptions) diff --git a/src/gui/widgets/qmdiarea_p.h b/src/gui/widgets/qmdiarea_p.h index 5d85659..e5e2057 100644 --- a/src/gui/widgets/qmdiarea_p.h +++ b/src/gui/widgets/qmdiarea_p.h @@ -165,6 +165,8 @@ public: QMdiArea::ViewMode viewMode; #ifndef QT_NO_TABBAR bool documentMode; + bool tabsClosable; + bool tabsMovable; #endif #ifndef QT_NO_TABWIDGET QTabWidget::TabShape tabShape; @@ -189,6 +191,8 @@ public: void _q_deactivateAllWindows(QMdiSubWindow *aboutToActivate = 0); void _q_processWindowStateChanged(Qt::WindowStates oldState, Qt::WindowStates newState); void _q_currentTabChanged(int index); + void _q_closeTab(int index); + void _q_moveTab(int from, int to); // Functions. void appendChild(QMdiSubWindow *child); diff --git a/src/gui/widgets/qtoolbarlayout.cpp b/src/gui/widgets/qtoolbarlayout.cpp index 813ec3e..531acb4 100644 --- a/src/gui/widgets/qtoolbarlayout.cpp +++ b/src/gui/widgets/qtoolbarlayout.cpp @@ -647,15 +647,15 @@ QSize QToolBarLayout::expandedSize(const QSize &size) const void QToolBarLayout::setExpanded(bool exp) { - if (exp == expanded) + QWidget *tb = qobject_cast<QToolBar*>(parentWidget()); + if (!tb) + return; + if (exp == expanded && !tb->isWindow()) return; expanded = exp; extension->setChecked(expanded); - QToolBar *tb = qobject_cast<QToolBar*>(parentWidget()); - if (!tb) - return; if (QMainWindow *win = qobject_cast<QMainWindow*>(tb->parentWidget())) { #ifdef QT_NO_DOCKWIDGET animating = false; diff --git a/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp b/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp index bac17b1..837df78 100644 --- a/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp +++ b/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp @@ -2541,7 +2541,7 @@ void tst_QGraphicsGridLayout::geometries_data() << QRectF(0, 0, 50,10) << QRectF(50, 0, 50,10) << QRectF(0, 10, 50,100) << QRectF(50, 10, 50,400) ); -#if 0 + QTest::newRow("hfw-100x470") << (ItemList() << ItemDesc(0,0) .minSize(QSizeF(1,1)) @@ -2556,9 +2556,9 @@ void tst_QGraphicsGridLayout::geometries_data() .preferredSize(QSizeF(50,10)) .maxSize(QSizeF(100, 100)) << ItemDesc(1,1) - .minSize(QSizeF(40,40)) - .preferredSize(QSizeF(50,400)) - .maxSize(QSizeF(500, 500)) + .sizeHint(Qt::MinimumSize, QSizeF(40,40)) + .sizeHint(Qt::PreferredSize, QSizeF(50,400)) + .sizeHint(Qt::MaximumSize, QSizeF(500,500)) .dynamicConstraint(hfw1, Qt::Vertical) ) << QSizeF(100, 470) @@ -2567,7 +2567,6 @@ void tst_QGraphicsGridLayout::geometries_data() << QRectF(0, 70, 50,100) << QRectF(50, 70, 50,400) ); - // change layout width and verify QTest::newRow("hfw-100x401") << (ItemList() << ItemDesc(0,0) @@ -2583,9 +2582,9 @@ void tst_QGraphicsGridLayout::geometries_data() .preferredSize(QSizeF(50,10)) .maxSize(QSizeF(100, 100)) << ItemDesc(1,1) - .minSize(QSizeF(40,40)) - .preferredSize(QSizeF(50,400)) - .maxSize(QSizeF(5000, 5000)) + .minSize(QSizeF(-1,-1)) + .preferredSize(QSizeF(-1,-1)) + .maxSize(QSizeF(-1, -1)) .dynamicConstraint(hfw1, Qt::Vertical) ) << QSizeF(100, 401) @@ -2594,7 +2593,7 @@ void tst_QGraphicsGridLayout::geometries_data() << QRectF( 0, 1, 50, 100) << QRectF( 50, 1, 50, 400) ); - QTest::newRow("hfw-160x400") << (ItemList() + QTest::newRow("hfw-160x350") << (ItemList() << ItemDesc(0,0) .minSize(QSizeF(1,1)) .preferredSize(QSizeF(50,10)) @@ -2608,18 +2607,17 @@ void tst_QGraphicsGridLayout::geometries_data() .preferredSize(QSizeF(50,10)) .maxSize(QSizeF(100, 100)) << ItemDesc(1,1) - .minSize(QSizeF(40,40)) - .preferredSize(QSizeF(50,400)) - .maxSize(QSizeF(5000, 5000)) - .dynamicConstraint(hfw1, Qt::Vertical) + .sizeHint(Qt::MinimumSize, QSizeF(40,40)) + .sizeHint(Qt::PreferredSize, QSizeF(50,400)) + .sizeHint(Qt::MaximumSize, QSizeF(5000,5000)) + .dynamicConstraint(hfw1, Qt::Vertical) ) - << QSizeF(160, 400) + << QSizeF(160, 350) << (RectList() << QRectF( 0, 0, 80, 100) << QRectF( 80, 0, 80, 100) << QRectF( 0, 100, 80, 100) << QRectF( 80, 100, 80, 250) ); - QTest::newRow("hfw-160x300") << (ItemList() << ItemDesc(0,0) .minSize(QSizeF(1,1)) @@ -2634,9 +2632,9 @@ void tst_QGraphicsGridLayout::geometries_data() .preferredSize(QSizeF(50,10)) .maxSize(QSizeF(100, 100)) << ItemDesc(1,1) - .minSize(QSizeF(40,40)) - .preferredSize(QSizeF(50,400)) - .maxSize(QSizeF(5000, 5000)) + .sizeHint(Qt::MinimumSize, QSizeF(40,40)) + .sizeHint(Qt::PreferredSize, QSizeF(50,400)) + .sizeHint(Qt::MaximumSize, QSizeF(5000, 5000)) .dynamicConstraint(hfw1, Qt::Vertical) ) << QSizeF(160, 300) @@ -2647,11 +2645,11 @@ void tst_QGraphicsGridLayout::geometries_data() QTest::newRow("hfw-20x40") << (ItemList() << ItemDesc(0,0) - .minSize(QSizeF(1,1)) + .minSize(QSizeF(1,10)) .preferredSize(QSizeF(50,50)) .maxSize(QSizeF(100, 100)) << ItemDesc(0,1) - .minSize(QSizeF(1,10)) + .minSize(QSizeF(1,1)) .preferredSize(QSizeF(50,50)) .maxSize(QSizeF(100, 100)) << ItemDesc(1,0) @@ -2659,9 +2657,9 @@ void tst_QGraphicsGridLayout::geometries_data() .preferredSize(QSizeF(50,50)) .maxSize(QSizeF(100, 100)) << ItemDesc(1,1) - .minSize(QSizeF(1,1)) - .preferredSize(QSizeF(50,50)) - .maxSize(QSizeF(100, 100)) + .sizeHint(Qt::MinimumSize, QSizeF(1, 1)) + .sizeHint(Qt::PreferredSize, QSizeF(50, 50)) + .sizeHint(Qt::MaximumSize, QSizeF(100, 100)) .dynamicConstraint(hfw3, Qt::Vertical) ) << QSizeF(20, 40) @@ -2684,9 +2682,9 @@ void tst_QGraphicsGridLayout::geometries_data() .preferredSize(QSizeF(10,50)) .maxSize(QSizeF(100, 100)) << ItemDesc(1,1) - .minSize(QSizeF(10,10)) - .preferredSize(QSizeF(400,50)) - .maxSize(QSizeF(5000, 5000)) + .sizeHint(Qt::MinimumSize, QSizeF(10,10)) + .sizeHint(Qt::PreferredSize, QSizeF(400,50)) + .sizeHint(Qt::MaximumSize, QSizeF(5000, 5000)) .dynamicConstraint(wfh1, Qt::Horizontal) ) << QSizeF(300, 160) @@ -2711,9 +2709,9 @@ void tst_QGraphicsGridLayout::geometries_data() .preferredSize(QSizeF(50,50)) .maxSize(QSizeF(100, 100)) << ItemDesc(1,1) - .minSize(QSizeF(1,1)) - .preferredSize(QSizeF(50,50)) - .maxSize(QSizeF(100, 100)) + .sizeHint(Qt::MinimumSize, QSizeF(1,1)) + .sizeHint(Qt::PreferredSize, QSizeF(50,50)) + .sizeHint(Qt::MaximumSize, QSizeF(100, 100)) .dynamicConstraint(wfh2, Qt::Horizontal) ) << QSizeF(40, 20) @@ -2736,9 +2734,9 @@ void tst_QGraphicsGridLayout::geometries_data() .preferredSize(QSizeF(50,50)) .maxSize(QSizeF(100, 100)) << ItemDesc(1,1) - .minSize(QSizeF(1,1)) - .preferredSize(QSizeF(50,50)) - .maxSize(QSizeF(100, 100)) + .sizeHint(Qt::MinimumSize, QSizeF(1,1)) + .sizeHint(Qt::PreferredSize, QSizeF(50,50)) + .sizeHint(Qt::MaximumSize, QSizeF(100, 100)) .dynamicConstraint(wfh2, Qt::Horizontal) ) @@ -2767,9 +2765,9 @@ void tst_QGraphicsGridLayout::geometries_data() .preferredSize(QSizeF(10,50)) .maxSize(QSizeF(100, 100)) << ItemDesc(1,1) - .minSize(QSizeF(1,1)) - .preferredSize(QSizeF(10,50)) - .maxSize(QSizeF(500, 500)) + .sizeHint(Qt::MinimumSize, QSizeF(1,1)) + .sizeHint(Qt::PreferredSize, QSizeF(10,50)) + .sizeHint(Qt::MaximumSize, QSizeF(500, 500)) .dynamicConstraint(wfh2, Qt::Horizontal) ) << QSizeF(160, 100) @@ -2777,7 +2775,6 @@ void tst_QGraphicsGridLayout::geometries_data() << QRectF(0, 0, 80, 50) << QRectF( 80, 0, 80, 50) << QRectF(0, 50, 80, 50) << QRectF( 80, 50, 50, 50) ); -#endif QTest::newRow("hfw-h470") << (ItemList() << ItemDesc(0,0) @@ -2804,7 +2801,6 @@ void tst_QGraphicsGridLayout::geometries_data() << QRectF(0, 70, 50,100) << QRectF(50, 70, 50,400) ); - // change layout width and verify QTest::newRow("hfw-w100") << (ItemList() << ItemDesc(0,0) @@ -3069,25 +3065,24 @@ void tst_QGraphicsGridLayout::heightForWidth() layout->setSpacing(0); RectWidget *w00 = new RectWidget; w00->setSizeHint(Qt::MinimumSize, QSizeF(1,1)); - w00->setSizeHint(Qt::PreferredSize, QSizeF(50,50)); + w00->setSizeHint(Qt::PreferredSize, QSizeF(10,10)); w00->setSizeHint(Qt::MaximumSize, QSizeF(100,100)); layout->addItem(w00, 0, 0); RectWidget *w01 = new RectWidget; w01->setSizeHint(Qt::MinimumSize, QSizeF(1,1)); - w01->setSizeHint(Qt::PreferredSize, QSizeF(50,50)); + w01->setSizeHint(Qt::PreferredSize, QSizeF(10,10)); w01->setSizeHint(Qt::MaximumSize, QSizeF(100,100)); layout->addItem(w01, 0, 1); RectWidget *w10 = new RectWidget; w10->setSizeHint(Qt::MinimumSize, QSizeF(1,1)); - w10->setSizeHint(Qt::PreferredSize, QSizeF(50,50)); + w10->setSizeHint(Qt::PreferredSize, QSizeF(10,10)); w10->setSizeHint(Qt::MaximumSize, QSizeF(100,100)); layout->addItem(w10, 1, 0); RectWidget *w11 = new RectWidget; w11->setSizeHint(Qt::MinimumSize, QSizeF(1,1)); - w11->setSizeHint(Qt::PreferredSize, QSizeF(50,400)); w11->setSizeHint(Qt::MaximumSize, QSizeF(30000,30000)); w11->setConstraintFunction(hfw); QSizePolicy sp(QSizePolicy::Preferred, QSizePolicy::Preferred); @@ -3096,34 +3091,37 @@ void tst_QGraphicsGridLayout::heightForWidth() layout->addItem(w11, 1, 1); QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, -1)), QSizeF(2, 2)); - QEXPECT_FAIL("", "QTBUG-14693", Continue); QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(-1, -1)), QSizeF(210, 110)); QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(-1, -1)), QSizeF(30100, 30100)); QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(2, -1)), QSizeF(2, 20001)); - QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(2, -1)), QSizeF(2, 20050)); + QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(2, -1)), QSizeF(2, 20010)); QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(2, -1)), QSizeF(2, 20100)); - QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(20, -1)), QSizeF(20, 1 + 2000)); - QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(20, -1)), QSizeF(20, 50 + 2000)); - QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(20, -1)), QSizeF(20, 100 + 2000)); + // Since 20 is somewhere between "minimum width hint" (2) and + // "preferred width hint" (210), it will try to do distribution by + // stretching them with different factors. + // Since column 1 has a "preferred width" of 200 it means that + // column 1 will be a bit wider than column 0. Thus it will also be a bit + // shorter than 2001, (the expected height if all columns had width=10) + QSizeF sh = layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(20, -1)); + // column 1 cannot be wider than 19, which means that it must be taller than 20000/19~=1052 + QVERIFY(sh.height() < 2000 + 1 && sh.height() > 1052 + 1); + + sh = layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(20, -1)); + QVERIFY(sh.height() < 2000 + 10 && sh.height() > 1052 + 10); - QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(300, -1)), QSizeF(300, 1 + 100)); - QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(300, -1)), QSizeF(300, 50 + 100)); - QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(300, -1)), QSizeF(300, 100 + 100)); + sh = layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(20, -1)); + QVERIFY(sh.height() < 2000 + 100 && sh.height() > 1052 + 100); // the height of the hfw widget is shorter than the one to the left, which is 100, so // the total height of the last row is 100 (which leaves the layout height to be 200) QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(500, -1)), QSizeF(500, 100 + 100)); - // hfw item size: (500, 40) -> preferred size is maxed up to preferred size of item w10 (50) - QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(600, -1)), QSizeF(600, 50 + 50)); - } void tst_QGraphicsGridLayout::widthForHeight() { -#if 0 QGraphicsWidget *widget = new QGraphicsWidget; QGraphicsGridLayout *layout = new QGraphicsGridLayout; widget->setLayout(layout); @@ -3150,9 +3148,10 @@ void tst_QGraphicsGridLayout::widthForHeight() layout->addItem(w10, 1, 0); RectWidget *w11 = new RectWidget; - w11->setMinimumSize(1,1); - w11->setPreferredSize(50, 50); - w11->setMaximumSize(30000,30000); + w11->setSizeHint(Qt::MinimumSize, QSizeF(1,1)); + w11->setSizeHint(Qt::PreferredSize, QSizeF(50,50)); + w11->setSizeHint(Qt::MaximumSize, QSizeF(30000,30000)); + // This will make sure its always square. w11->setConstraintFunction(wfh); QSizePolicy sp(QSizePolicy::Preferred, QSizePolicy::Preferred); @@ -3196,7 +3195,6 @@ void tst_QGraphicsGridLayout::widthForHeight() QCOMPARE(layout->effectiveSizeHint(Qt::MinimumSize, QSizeF(-1, 300)), QSizeF(1 + 200, 300)); QCOMPARE(layout->effectiveSizeHint(Qt::PreferredSize, QSizeF(-1, 300)), QSizeF(50 + 200, 300)); QCOMPARE(layout->effectiveSizeHint(Qt::MaximumSize, QSizeF(-1, 300)), QSizeF(100 + 200, 300)); -#endif } void tst_QGraphicsGridLayout::heightForWidthWithSpanning() diff --git a/tests/auto/qheaderview/tst_qheaderview.cpp b/tests/auto/qheaderview/tst_qheaderview.cpp index db71e39..9a25fb6 100644 --- a/tests/auto/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/qheaderview/tst_qheaderview.cpp @@ -195,6 +195,8 @@ private slots: void QTBUG8650_crashOnInsertSections(); void QTBUG12268_hiddenMovedSectionSorting(); + void initialSortOrderRole(); + protected: QWidget *topLevel; QHeaderView *view; @@ -2097,5 +2099,40 @@ void tst_QHeaderView::QTBUG12268_hiddenMovedSectionSorting() QCOMPARE(view.horizontalHeader()->hiddenSectionCount(), 1); } +void tst_QHeaderView::initialSortOrderRole() +{ + QTableView view; + QStandardItemModel *model = new QStandardItemModel(4, 3, &view); + for (int i = 0; i< model->rowCount(); ++i) + for (int j = 0; j< model->columnCount(); ++j) + model->setData(model->index(i,j), QString("item [%1,%2]").arg(i).arg(j)); + QStandardItem *ascendingItem = new QStandardItem(); + QStandardItem *descendingItem = new QStandardItem(); + ascendingItem->setData(Qt::AscendingOrder, Qt::InitialSortOrderRole); + descendingItem->setData(Qt::DescendingOrder, Qt::InitialSortOrderRole); + model->setHorizontalHeaderItem(1, ascendingItem); + model->setHorizontalHeaderItem(2, descendingItem); + view.setModel(model); + view.setSortingEnabled(true); + view.sortByColumn(0, Qt::AscendingOrder); + view.show(); + QTest::qWaitForWindowShown(&view); + + const int column1Pos = view.horizontalHeader()->sectionViewportPosition(1) + 5; // +5 not to be on the handle + QTest::mouseClick(view.horizontalHeader()->viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(column1Pos, 0)); + QCOMPARE(view.horizontalHeader()->sortIndicatorSection(), 1); + QCOMPARE(view.horizontalHeader()->sortIndicatorOrder(), Qt::AscendingOrder); + + const int column2Pos = view.horizontalHeader()->sectionViewportPosition(2) + 5; // +5 not to be on the handle + QTest::mouseClick(view.horizontalHeader()->viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(column2Pos, 0)); + QCOMPARE(view.horizontalHeader()->sortIndicatorSection(), 2); + QCOMPARE(view.horizontalHeader()->sortIndicatorOrder(), Qt::DescendingOrder); + + const int column0Pos = view.horizontalHeader()->sectionViewportPosition(0) + 5; // +5 not to be on the handle + QTest::mouseClick(view.horizontalHeader()->viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(column0Pos, 0)); + QCOMPARE(view.horizontalHeader()->sortIndicatorSection(), 0); + QCOMPARE(view.horizontalHeader()->sortIndicatorOrder(), Qt::AscendingOrder); +} + QTEST_MAIN(tst_QHeaderView) #include "tst_qheaderview.moc" diff --git a/tests/auto/qmdiarea/tst_qmdiarea.cpp b/tests/auto/qmdiarea/tst_qmdiarea.cpp index d44e632..67d3d0d 100644 --- a/tests/auto/qmdiarea/tst_qmdiarea.cpp +++ b/tests/auto/qmdiarea/tst_qmdiarea.cpp @@ -287,6 +287,8 @@ private slots: void setActivationOrder(); void tabBetweenSubWindows(); void setViewMode(); + void setTabsClosable(); + void setTabsMovable(); void setTabShape(); void setTabPosition_data(); void setTabPosition(); @@ -2464,6 +2466,77 @@ void tst_QMdiArea::setViewMode() QCOMPARE(mdiArea.viewMode(), QMdiArea::SubWindowView); } +void tst_QMdiArea::setTabsClosable() +{ + QMdiArea mdiArea; + mdiArea.addSubWindow(new QWidget); + + // test default + QCOMPARE(mdiArea.tabsClosable(), false); + + // change value before tab bar exists + QTabBar *tabBar = qFindChild<QTabBar *>(&mdiArea); + QVERIFY(!tabBar); + mdiArea.setTabsClosable(true); + QCOMPARE(mdiArea.tabsClosable(), true); + + // force tab bar creation + mdiArea.setViewMode(QMdiArea::TabbedView); + tabBar = qFindChild<QTabBar *>(&mdiArea); + QVERIFY(tabBar); + + // value must've been propagated + QCOMPARE(tabBar->tabsClosable(), true); + + // change value when tab bar exists + mdiArea.setTabsClosable(false); + QCOMPARE(mdiArea.tabsClosable(), false); + QCOMPARE(tabBar->tabsClosable(), false); +} + +void tst_QMdiArea::setTabsMovable() +{ + QMdiArea mdiArea; + QMdiSubWindow *subWindow1 = mdiArea.addSubWindow(new QWidget); + QMdiSubWindow *subWindow2 = mdiArea.addSubWindow(new QWidget); + QMdiSubWindow *subWindow3 = mdiArea.addSubWindow(new QWidget); + + // test default + QCOMPARE(mdiArea.tabsMovable(), false); + + // change value before tab bar exists + QTabBar *tabBar = qFindChild<QTabBar *>(&mdiArea); + QVERIFY(!tabBar); + mdiArea.setTabsMovable(true); + QCOMPARE(mdiArea.tabsMovable(), true); + + // force tab bar creation + mdiArea.setViewMode(QMdiArea::TabbedView); + tabBar = qFindChild<QTabBar *>(&mdiArea); + QVERIFY(tabBar); + + // value must've been propagated + QCOMPARE(tabBar->isMovable(), true); + + // test tab moving + QList<QMdiSubWindow *> subWindows; + subWindows << subWindow1 << subWindow2 << subWindow3; + QCOMPARE(mdiArea.subWindowList(QMdiArea::CreationOrder), subWindows); + tabBar->moveTab(1, 2); // 1,3,2 + subWindows.clear(); + subWindows << subWindow1 << subWindow3 << subWindow2; + QCOMPARE(mdiArea.subWindowList(QMdiArea::CreationOrder), subWindows); + tabBar->moveTab(0, 2); // 3,2,1 + subWindows.clear(); + subWindows << subWindow3 << subWindow2 << subWindow1; + QCOMPARE(mdiArea.subWindowList(QMdiArea::CreationOrder), subWindows); + + // change value when tab bar exists + mdiArea.setTabsMovable(false); + QCOMPARE(mdiArea.tabsMovable(), false); + QCOMPARE(tabBar->isMovable(), false); +} + void tst_QMdiArea::setTabShape() { QMdiArea mdiArea; diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index 2208bea..35014c9 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -10576,7 +10576,7 @@ void tst_QWidget::nativeChildFocus() QTest::qWaitForWindowShown(&w); QCOMPARE(QApplication::activeWindow(), &w); - QCOMPARE(QApplication::focusWidget(), p1); + QCOMPARE(QApplication::focusWidget(), static_cast<QWidget*>(p1)); } QTEST_MAIN(tst_QWidget) |