Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

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

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    6060#include "qmainwindowlayout_p.h"
    6161#ifdef Q_WS_MAC
     62#include <private/qapplication_p.h>
    6263#include <private/qt_mac_p.h>
    6364#include <qmacstyle_mac.h>
     
    6869extern QString qt_setWindowTitle_helperHelper(const QString&, const QWidget*); // qwidget.cpp
    6970
    70 extern QHash<QByteArray, QFont> *qt_app_fonts_hash(); // qapplication.cpp
     71static inline bool hasFeature(const QDockWidgetPrivate *priv, QDockWidget::DockWidgetFeature feature)
     72{ return (priv->features & feature) == feature; }
    7173
    7274static inline bool hasFeature(const QDockWidget *dockwidget, QDockWidget::DockWidgetFeature feature)
     
    204206bool QDockWidgetLayout::nativeWindowDeco(bool floating) const
    205207{
    206 #if defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_OS_WINCE)
     208#if defined(Q_WS_X11) || defined(Q_WS_QWS) || defined(Q_WS_WINCE)
    207209    Q_UNUSED(floating);
    208210    return false;
     
    222224{
    223225    int cnt = 0;
    224     foreach (QLayoutItem *item, item_list) {
     226    for (int i = 0; i < item_list.count(); ++i) {
     227        QLayoutItem *item = item_list.at(i);
    225228        if (item == 0)
    226229            continue;
     
    251254{
    252255    int result = 0;
    253     foreach (QLayoutItem *item, item_list) {
    254         if (item != 0)
     256    for (int i = 0; i < item_list.count(); ++i) {
     257        if (item_list.at(i))
    255258            ++result;
    256259    }
     
    454457    int mw = q->style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, 0, q);
    455458
    456     return qMax(buttonHeight + 2, titleFontMetrics.lineSpacing() + 2*mw);
     459    return qMax(buttonHeight + 2, titleFontMetrics.height() + 2*mw);
    457460}
    458461
     
    647650{
    648651    Q_Q(QDockWidget);
    649     QDockWidgetLayout *layout = qobject_cast<QDockWidgetLayout*>(q->layout());
     652    QDockWidgetLayout *dwLayout = qobject_cast<QDockWidgetLayout*>(layout);
    650653
    651654    QStyleOptionDockWidget opt;
    652655    q->initStyleOption(&opt);
    653656
    654     bool customTitleBar = layout->widgetForRole(QDockWidgetLayout::TitleBar) != 0;
    655     bool nativeDeco = layout->nativeWindowDeco();
     657    bool customTitleBar = dwLayout->widgetForRole(QDockWidgetLayout::TitleBar) != 0;
     658    bool nativeDeco = dwLayout->nativeWindowDeco();
    656659    bool hideButtons = nativeDeco || customTitleBar;
    657660
    658     bool canClose = hasFeature(q, QDockWidget::DockWidgetClosable);
    659     bool canFloat = hasFeature(q, QDockWidget::DockWidgetFloatable);
     661    bool canClose = hasFeature(this, QDockWidget::DockWidgetClosable);
     662    bool canFloat = hasFeature(this, QDockWidget::DockWidgetFloatable);
    660663
    661664    QAbstractButton *button
    662         = qobject_cast<QAbstractButton*>(layout->widgetForRole(QDockWidgetLayout::FloatButton));
     665        = qobject_cast<QAbstractButton*>(dwLayout->widgetForRole(QDockWidgetLayout::FloatButton));
    663666    button->setIcon(q->style()->standardIcon(QStyle::SP_TitleBarNormalButton, &opt, q));
    664667    button->setVisible(canFloat && !hideButtons);
    665668
    666669    button
    667         = qobject_cast <QAbstractButton*>(layout->widgetForRole(QDockWidgetLayout::CloseButton));
     670        = qobject_cast <QAbstractButton*>(dwLayout->widgetForRole(QDockWidgetLayout::CloseButton));
    668671    button->setIcon(q->style()->standardIcon(QStyle::SP_TitleBarCloseButton, &opt, q));
    669672    button->setVisible(canClose && !hideButtons);
     
    683686void QDockWidgetPrivate::initDrag(const QPoint &pos, bool nca)
    684687{
    685     Q_Q(QDockWidget);
    686 
    687688    if (state != 0)
    688689        return;
    689690
    690     QMainWindow *win = qobject_cast<QMainWindow*>(q->parentWidget());
     691    QMainWindow *win = qobject_cast<QMainWindow*>(parent);
    691692    Q_ASSERT(win != 0);
    692693    QMainWindowLayout *layout = qobject_cast<QMainWindowLayout*>(win->layout());
    693694    Q_ASSERT(layout != 0);
    694     if (layout->layoutState.indexOf(q).isEmpty()) //The dock widget has not been added into the main window
    695         return;
    696695    if (layout->pluggingWidget != 0) // the main window is animating a docking operation
    697696        return;
     
    741740
    742741    if (state->dragging) {
    743         QMainWindowLayout *layout =
     742        QMainWindowLayout *mwLayout =
    744743            qobject_cast<QMainWindowLayout *>(q->parentWidget()->layout());
    745         Q_ASSERT(layout != 0);
    746 
    747         if (abort || !layout->plug(state->widgetItem)) {
    748             if (hasFeature(q, QDockWidget::DockWidgetFloatable)) {
     744        Q_ASSERT(mwLayout != 0);
     745
     746        if (abort || !mwLayout->plug(state->widgetItem)) {
     747            if (hasFeature(this, QDockWidget::DockWidgetFloatable)) {
    749748                if (state->ownWidgetItem)
    750749                    delete state->widgetItem;
    751                 layout->restore();
     750                mwLayout->restore();
    752751#ifdef Q_WS_X11
    753752                // get rid of the X11BypassWindowManager window flag and activate the resizer
     
    759758#else
    760759                QDockWidgetLayout *myLayout
    761                     = qobject_cast<QDockWidgetLayout*>(q->layout());
     760                    = qobject_cast<QDockWidgetLayout*>(layout);
    762761                resizer->setActive(QWidgetResizeHandler::Resize,
    763762                                    myLayout->widgetForRole(QDockWidgetLayout::TitleBar) != 0);
     
    766765                q->activateWindow();
    767766            } else {
    768                 layout->revert(state->widgetItem);
     767                mwLayout->revert(state->widgetItem);
    769768            }
    770769        }
     
    778777    Q_Q(const QDockWidget);
    779778
    780     QMainWindow *mainWin = qobject_cast<QMainWindow*>(q->parentWidget());
     779    QMainWindow *mainWin = qobject_cast<QMainWindow*>(parent);
    781780    if (mainWin == 0)
    782781        return false;
     
    795794    Q_Q(QDockWidget);
    796795
    797     QDockWidgetLayout *layout
    798         = qobject_cast<QDockWidgetLayout*>(q->layout());
    799 
    800     if (!layout->nativeWindowDeco()) {
    801         QRect titleArea = layout->titleArea();
     796    QDockWidgetLayout *dwLayout
     797        = qobject_cast<QDockWidgetLayout*>(layout);
     798
     799    if (!dwLayout->nativeWindowDeco()) {
     800        QRect titleArea = dwLayout->titleArea();
    802801
    803802        if (event->button() != Qt::LeftButton ||
     
    805804            // check if the tool window is movable... do nothing if it
    806805            // is not (but allow moving if the window is floating)
    807             (!hasFeature(q, QDockWidget::DockWidgetMovable) && !q->isFloating()) ||
    808             qobject_cast<QMainWindow*>(q->parentWidget()) == 0 ||
     806            (!hasFeature(this, QDockWidget::DockWidgetMovable) && !q->isFloating()) ||
     807            qobject_cast<QMainWindow*>(parent) == 0 ||
    809808            isAnimating() || state != 0) {
    810809            return false;
     
    814813
    815814        if (state)
    816             state->ctrlDrag = hasFeature(q, QDockWidget::DockWidgetFloatable) && event->modifiers() & Qt::ControlModifier;
     815            state->ctrlDrag = hasFeature(this, QDockWidget::DockWidgetFloatable) && event->modifiers() & Qt::ControlModifier;
    817816
    818817        return true;
     
    825824bool QDockWidgetPrivate::mouseDoubleClickEvent(QMouseEvent *event)
    826825{
    827     Q_Q(QDockWidget);
    828 
    829     QDockWidgetLayout *layout = qobject_cast<QDockWidgetLayout*>(q->layout());
    830 
    831     if (!layout->nativeWindowDeco()) {
    832         QRect titleArea = layout->titleArea();
     826    QDockWidgetLayout *dwLayout = qobject_cast<QDockWidgetLayout*>(layout);
     827
     828    if (!dwLayout->nativeWindowDeco()) {
     829        QRect titleArea = dwLayout->titleArea();
    833830
    834831        if (event->button() == Qt::LeftButton && titleArea.contains(event->pos()) &&
    835             hasFeature(q, QDockWidget::DockWidgetFloatable)) {
     832            hasFeature(this, QDockWidget::DockWidgetFloatable)) {
    836833            _q_toggleTopLevel();
    837834            return true;
     
    851848
    852849    QDockWidgetLayout *dwlayout
    853         = qobject_cast<QDockWidgetLayout*>(q->layout());
     850        = qobject_cast<QDockWidgetLayout*>(layout);
    854851    QMainWindowLayout *mwlayout
    855852        = qobject_cast<QMainWindowLayout*>(q->parentWidget()->layout());
     
    924921            if (state != 0)
    925922                break;
    926             if (qobject_cast<QMainWindow*>(q->parentWidget()) == 0)
     923            if (qobject_cast<QMainWindow*>(parent) == 0)
    927924                break;
    928925            if (isAnimating())
     
    997994    QRect r = rect;
    998995    r.moveTopLeft(q->mapToGlobal(QPoint(0, 0)));
    999     QDockWidgetLayout *layout = qobject_cast<QDockWidgetLayout*>(q->layout());
    1000     if (layout->nativeWindowDeco(true))
    1001         r.adjust(0, layout->titleHeight(), 0, 0);
     996    QDockWidgetLayout *dwLayout = qobject_cast<QDockWidgetLayout*>(layout);
     997    if (dwLayout->nativeWindowDeco(true))
     998        r.adjust(0, dwLayout->titleHeight(), 0, 0);
    1002999    setWindowState(true, true, r);
    10031000}
     
    10111008{
    10121009    Q_Q(QDockWidget);
     1010
     1011    if (!floating && parent) {
     1012        QMainWindowLayout *mwlayout = qobject_cast<QMainWindowLayout *>(q->parentWidget()->layout());
     1013        if (!mwlayout || mwlayout->dockWidgetArea(q) == Qt::NoDockWidgetArea)
     1014            return; // this dockwidget can't be redocked
     1015    }
    10131016
    10141017    bool wasFloating = q->isFloating();
     
    10201023    Qt::WindowFlags flags = floating ? Qt::Tool : Qt::Widget;
    10211024
    1022     QDockWidgetLayout *layout = qobject_cast<QDockWidgetLayout*>(q->layout());
    1023     const bool nativeDeco = layout->nativeWindowDeco(floating);
     1025    QDockWidgetLayout *dwLayout = qobject_cast<QDockWidgetLayout*>(layout);
     1026    const bool nativeDeco = dwLayout->nativeWindowDeco(floating);
    10241027
    10251028    if (nativeDeco) {
    10261029        flags |= Qt::CustomizeWindowHint | Qt::WindowTitleHint;
    1027         if (hasFeature(q, QDockWidget::DockWidgetClosable))
     1030        if (hasFeature(this, QDockWidget::DockWidgetClosable))
    10281031            flags |= Qt::WindowCloseButtonHint;
    10291032    } else {
     
    10521055    if (floating != wasFloating) {
    10531056        emit q->topLevelChanged(floating);
    1054         if (!floating && q->parentWidget()) {
     1057        if (!floating && parent) {
    10551058            QMainWindowLayout *mwlayout = qobject_cast<QMainWindowLayout *>(q->parentWidget()->layout());
    10561059            if (mwlayout)
     
    10691072    desktop.
    10701073
    1071     \ingroup application
     1074    \ingroup mainwindow-classes
    10721075
    10731076    QDockWidget provides the concept of dock widgets, also know as
     
    11361139/*!
    11371140    \property QDockWidget::windowTitle
    1138     \internal
     1141    \brief the dock widget title (caption)
    11391142
    11401143    By default, this property contains an empty string.
     
    12231226    if (d->features == features)
    12241227        return;
     1228    const bool closableChanged = (d->features ^ features) & DockWidgetClosable;
    12251229    d->features = features;
    12261230    QDockWidgetLayout *layout
     
    12311235    emit featuresChanged(d->features);
    12321236    update();
     1237    if (closableChanged && layout->nativeWindowDeco()) {
     1238        //this ensures the native decoration is drawn
     1239        d->setWindowState(true /*floating*/, true /*unplug*/);
     1240    }
    12331241}
    12341242
     
    13221330            if (QMainWindowLayout *winLayout =
    13231331                (win ? qobject_cast<QMainWindowLayout*>(win->layout()) : 0))
    1324                 if (QDockAreaLayoutInfo *info =
    1325                     (winLayout ? winLayout->layoutState.dockAreaLayout.info(this) : 0))
     1332                if (QDockAreaLayoutInfo *info = winLayout->layoutState.dockAreaLayout.info(this))
    13261333                    info->updateTabBar();
    13271334        }
     
    13911398    case QEvent::Show:
    13921399        d->toggleViewAction->setChecked(true);
    1393         emit visibilityChanged(true);
     1400        emit visibilityChanged(geometry().right() >= 0 && geometry().bottom() >= 0);
    13941401        break;
    13951402#endif
Note: See TracChangeset for help on using the changeset viewer.