Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/widgets/qmainwindow.cpp

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    4040****************************************************************************/
    4141
     42//#define QT_EXPERIMENTAL_CLIENT_DECORATIONS
     43
    4244#include "qmainwindow.h"
    4345#include "qmainwindowlayout_p.h"
     
    7779#ifdef Q_WS_MAC
    7880            , useHIToolBar(false)
     81            , activateUnifiedToolbarAfterFullScreen(false)
    7982#endif
    8083#if !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_CURSOR)
     
    8891#ifdef Q_WS_MAC
    8992    bool useHIToolBar;
     93    bool activateUnifiedToolbarAfterFullScreen;
    9094#endif
    9195    void init();
     
    100104    uint cursorAdjusted : 1;
    101105#endif
     106
     107    static inline QMainWindowLayout *mainWindowLayout(const QMainWindow *mainWindow)
     108    {
     109        return mainWindow ? mainWindow->d_func()->layout : static_cast<QMainWindowLayout *>(0);
     110    }
    102111};
    103112
     113QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *mainWindow)
     114{
     115    return QMainWindowPrivate::mainWindowLayout(mainWindow);
     116}
     117
     118#ifdef QT_EXPERIMENTAL_CLIENT_DECORATIONS
     119Q_GUI_EXPORT void qt_setMainWindowTitleWidget(QMainWindow *mainWindow, Qt::DockWidgetArea area, QWidget *widget)
     120{
     121    QGridLayout *topLayout = qobject_cast<QGridLayout *>(mainWindow->layout());
     122    Q_ASSERT(topLayout);
     123
     124    int row = 0;
     125    int column = 0;
     126
     127    switch (area) {
     128    case Qt::LeftDockWidgetArea:
     129        row = 1;
     130        column = 0;
     131        break;
     132    case Qt::TopDockWidgetArea:
     133        row = 0;
     134        column = 1;
     135        break;
     136    case Qt::BottomDockWidgetArea:
     137        row = 2;
     138        column = 1;
     139        break;
     140    case Qt::RightDockWidgetArea:
     141        row = 1;
     142        column = 2;
     143        break;
     144    default:
     145        Q_ASSERT_X(false, "qt_setMainWindowTitleWidget", "Unknown area");
     146        return;
     147    }
     148
     149    if (QLayoutItem *oldItem = topLayout->itemAtPosition(row, column))
     150        delete oldItem->widget();
     151    topLayout->addWidget(widget, row, column);
     152}
     153#endif
     154
    104155void QMainWindowPrivate::init()
    105156{
    106157    Q_Q(QMainWindow);
    107     layout = new QMainWindowLayout(q);
     158
     159#ifdef QT_EXPERIMENTAL_CLIENT_DECORATIONS
     160    QGridLayout *topLayout = new QGridLayout(q);
     161    topLayout->setContentsMargins(0, 0, 0, 0);
     162
     163    layout = new QMainWindowLayout(q, topLayout);
     164
     165    topLayout->addItem(layout, 1, 1);
     166#else
     167    layout = new QMainWindowLayout(q, 0);
     168#endif
     169
    108170    const int metric = q->style()->pixelMetric(QStyle::PM_ToolBarIconSize, 0, q);
    109171    iconSize = QSize(metric, metric);
     
    443505QMenuBar *QMainWindow::menuBar() const
    444506{
    445     QMenuBar *menuBar = qobject_cast<QMenuBar *>(d_func()->layout->menuBar());
     507    QMenuBar *menuBar = qobject_cast<QMenuBar *>(layout()->menuBar());
    446508    if (!menuBar) {
    447509        QMainWindow *self = const_cast<QMainWindow *>(this);
     
    462524void QMainWindow::setMenuBar(QMenuBar *menuBar)
    463525{
    464     Q_D(QMainWindow);
    465     if (d->layout->menuBar() && d->layout->menuBar() != menuBar) {
     526    QLayout *topLayout = layout();
     527
     528    if (topLayout->menuBar() && topLayout->menuBar() != menuBar) {
    466529        // Reparent corner widgets before we delete the old menu bar.
    467         QMenuBar *oldMenuBar = qobject_cast<QMenuBar *>(d->layout->menuBar());
     530        QMenuBar *oldMenuBar = qobject_cast<QMenuBar *>(topLayout->menuBar());
    468531        if (menuBar) {
    469532            // TopLeftCorner widget.
     
    479542        oldMenuBar->deleteLater();
    480543    }
    481     d->layout->setMenuBar(menuBar);
     544    topLayout->setMenuBar(menuBar);
    482545}
    483546
     
    13751438
    13761439        case QEvent::StyleChange:
     1440#ifndef QT_NO_DOCKWIDGET
     1441            d->layout->layoutState.dockAreaLayout.styleChangedEvent();
     1442#endif
    13771443            if (!d->explicitIconSize)
    13781444                setIconSize(QSize());
     
    14381504        disappear since it is considered to be part of the title bar. Qt 4.5 and up will now work around this by pulling
    14391505        the toolbars out and back into the regular toolbar and vice versa when you swap out.
    1440         However, a good practice would be that turning off the unified toolbar before you call
    1441         showFullScreen() and restoring it after you call showNormal().
    14421506    \endlist
    14431507
     
    14541518
    14551519    // ### Disable the unified toolbar when using anything but the native graphics system.
    1456     if (windowSurface())
     1520    // ### Disable when using alien widgets as well
     1521    if (windowSurface() || testAttribute(Qt::WA_NativeWindow) == false)
    14571522        return;
    14581523
     
    15361601#ifndef QT_NO_MENU
    15371602    QMenu *popup = createPopupMenu();
    1538     if (popup && !popup->isEmpty()) {
    1539         popup->exec(event->globalPos());
    1540         event->accept();
    1541     }
    1542     delete popup;
     1603    if (popup) {
     1604        if (!popup->isEmpty()) {
     1605            popup->setAttribute(Qt::WA_DeleteOnClose);
     1606            popup->popup(event->globalPos());
     1607            event->accept();
     1608        } else {
     1609            delete popup;
     1610        }
     1611    }
    15431612#endif
    15441613}
Note: See TracChangeset for help on using the changeset viewer.