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/qtoolbar.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**
     
    7171#include  "qdebug.h"
    7272
     73#define POPUP_TIMER_INTERVAL 500
     74
    7375QT_BEGIN_NAMESPACE
    7476
     
    8890{
    8991    Q_Q(QToolBar);
    90 
    91     waitForPopupTimer = new QTimer(q);
    92     waitForPopupTimer->setSingleShot(false);
    93     waitForPopupTimer->setInterval(500);
    94     QObject::connect(waitForPopupTimer, SIGNAL(timeout()), q, SLOT(_q_waitForPopup()));
    95 
    96     floatable = true;
    97     movable = true;
    9892    q->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed));
    9993    q->setBackgroundRole(QPalette::Button);
     
    190184    if (visible)
    191185        q->show();
     186
     187    if (floating != wasFloating)
     188        emit q->topLevelChanged(floating);
    192189}
    193190
     
    199196        return;
    200197
    201     QMainWindow *win = qobject_cast<QMainWindow*>(q->parentWidget());
     198    QMainWindow *win = qobject_cast<QMainWindow*>(parent);
    202199    Q_ASSERT(win != 0);
    203200    QMainWindowLayout *layout = qobject_cast<QMainWindowLayout*>(win->layout());
     
    212209    state->widgetItem = 0;
    213210
    214     if (q->layoutDirection() == Qt::RightToLeft)
     211    if (q->isRightToLeft())
    215212        state->pressPos = QPoint(q->width() - state->pressPos.x(), state->pressPos.y());
    216213}
     
    225222        return;
    226223
    227     QMainWindow *win = qobject_cast<QMainWindow*>(q->parentWidget());
     224    QMainWindow *win = qobject_cast<QMainWindow*>(parent);
    228225    Q_ASSERT(win != 0);
    229226    QMainWindowLayout *layout = qobject_cast<QMainWindowLayout*>(win->layout());
     
    275272bool QToolBarPrivate::mousePressEvent(QMouseEvent *event)
    276273{
    277     if (layout->handleRect().contains(event->pos()) == false) {
     274    Q_Q(QToolBar);
     275    QStyleOptionToolBar opt;
     276    q->initStyleOption(&opt);
     277    if (q->style()->subElementRect(QStyle::SE_ToolBarHandle, &opt, q).contains(event->pos()) == false) {
    278278#ifdef Q_WS_MAC
    279         Q_Q(QToolBar);
    280279        // When using the unified toolbar on Mac OS X the user can can click and
    281280        // drag between toolbar contents to move the window. Make this work by
    282281        // implementing the standard mouse-dragging code and then call
    283282        // window->move() in mouseMoveEvent below.
    284         if (QMainWindow *mainWindow = qobject_cast<QMainWindow *>(q->parentWidget())) {
     283        if (QMainWindow *mainWindow = qobject_cast<QMainWindow *>(parent)) {
    285284            if (mainWindow->toolBarArea(q) == Qt::TopToolBarArea
    286285                    && mainWindow->unifiedTitleAndToolBarOnMac()
     
    312311    } else {
    313312#ifdef Q_WS_MAC
     313        if (!macWindowDragging)
     314            return false;
    314315        macWindowDragging = false;
    315316        macWindowDragPressPosition = QPoint();
     
    336337    }
    337338
    338     QMainWindow *win = qobject_cast<QMainWindow*>(q->parentWidget());
     339    QMainWindow *win = qobject_cast<QMainWindow*>(parent);
    339340    if (win == 0)
    340341        return true;
     
    364365        // if we are right-to-left, we move so as to keep the right edge the same distance
    365366        // from the mouse
    366         if (q->layoutDirection() == Qt::LeftToRight)
     367        if (q->isLeftToRight())
    367368            pos -= state->pressPos;
    368369        else
     
    374375
    375376        const QPoint rtl(q->width() - state->pressPos.x(), state->pressPos.y()); //for RTL
    376         const QPoint globalPressPos = q->mapToGlobal(q->layoutDirection() == Qt::RightToLeft ? rtl : state->pressPos);
     377        const QPoint globalPressPos = q->mapToGlobal(q->isRightToLeft() ? rtl : state->pressPos);
    377378        int pos = 0;
    378379
     
    381382            pos = q->y() + delta.y();
    382383        } else {
    383             if (q->layoutDirection() == Qt::RightToLeft) {
     384            if (q->isRightToLeft()) {
    384385                pos = win->width() - q->width() - q->x()  - delta.x();
    385386            } else {
     
    396397{
    397398    Q_Q(QToolBar);
    398 
    399399    QRect r = _r;
    400400    r.moveTopLeft(q->mapToGlobal(QPoint(0, 0)));
    401401    setWindowState(true, true, r);
     402    layout->setExpanded(false);
    402403}
    403404
     
    417418    set of controls.
    418419
    419     \ingroup application
    420     \mainclass
     420    \ingroup mainwindow-classes
     421
    421422
    422423    Toolbar buttons are added by adding \e actions, using addAction()
     
    519520    \sa toolButtonStyle QMainWindow::toolButtonStyle
    520521*/
     522
     523/*!
     524    \since 4.6
     525
     526    \fn void QToolBar::topLevelChanged(bool topLevel)
     527
     528    This signal is emitted when the \l floating property changes.
     529    The \a topLevel parameter is true if the toolbar is now floating;
     530    otherwise it is false.
     531
     532    \sa isWindow()
     533*/
     534
    521535
    522536/*!
     
    879893    Qt::ToolButtonStyle will not be respected.
    880894
    881     Note: You should use QAction::setVisible() to change the
     895    \note You should use QAction::setVisible() to change the
    882896    visibility of the widget. Using QWidget::setVisible(),
    883897    QWidget::show() and QWidget::hide() does not work.
     
    10421056    }
    10431057
    1044     opt.rect = d->layout->handleRect();
     1058    opt.rect = style->subElementRect(QStyle::SE_ToolBarHandle, &opt, this);
    10451059    if (opt.rect.isValid())
    10461060        style->drawPrimitive(QStyle::PE_IndicatorToolBarHandle, &opt, &p, this);
     
    10791093}
    10801094
     1095#if defined(Q_WS_MAC)
     1096static bool toolbarInUnifiedToolBar(QToolBar *toolbar)
     1097{
     1098    const QMainWindow *mainWindow = qobject_cast<const QMainWindow *>(toolbar->parentWidget());
     1099    return mainWindow && mainWindow->unifiedTitleAndToolBarOnMac()
     1100            && mainWindow->toolBarArea(toolbar) == Qt::TopToolBarArea;
     1101}
     1102#endif
     1103
    10811104/*! \reimp */
    10821105bool QToolBar::event(QEvent *event)
     
    10851108
    10861109    switch (event->type()) {
     1110    case QEvent::Timer:
     1111        if (d->waitForPopupTimer.timerId() == static_cast<QTimerEvent*>(event)->timerId()) {
     1112            QWidget *w = QApplication::activePopupWidget();
     1113            if (!waitForPopup(this, w)) {
     1114                d->waitForPopupTimer.stop();
     1115                if (!this->underMouse())
     1116                    d->layout->setExpanded(false);
     1117            }
     1118        }
     1119        break;
    10871120    case QEvent::Hide:
    10881121        if (!isHidden())
     
    10911124    case QEvent::Show:
    10921125        d->toggleViewAction->setChecked(event->type() == QEvent::Show);
    1093 #if defined(Q_WS_MAC) && !defined(QT_MAC_USE_COCOA)
     1126#if defined(Q_WS_MAC)
     1127        if (toolbarInUnifiedToolBar(this)) {
     1128             // I can static_cast because I did the qobject_cast in the if above, therefore
     1129            // we must have a QMainWindowLayout here.
     1130            QMainWindowLayout *mwLayout = static_cast<QMainWindowLayout *>(parentWidget()->layout());
     1131            mwLayout->fixSizeInUnifiedToolbar(this);
     1132            mwLayout->syncUnifiedToolbarVisibility();
     1133        }
     1134#  if !defined(QT_MAC_USE_COCOA)
    10941135        // Fall through
    10951136    case QEvent::LayoutRequest: {
     
    11061147
    11071148            if (needUpdate) {
    1108                 OSWindowRef windowRef = qt_mac_window_for(this);
    1109                 if (mainWindow->unifiedTitleAndToolBarOnMac()
    1110                         && mainWindow->toolBarArea(this) == Qt::TopToolBarArea
    1111                         && macWindowToolbarVisible(windowRef))   {
     1149                OSWindowRef windowRef = qt_mac_window_for(mainWindow);
     1150                if (toolbarInUnifiedToolBar(this)
     1151                        && macWindowToolbarIsVisible(windowRef))   {
    11121152                    DisableScreenUpdates();
    11131153                    macWindowToolbarShow(this, false);
     
    11211161        }
    11221162    }
    1123 #endif
     1163#  endif // !QT_MAC_USE_COCOA
     1164#endif // Q_WS_MAC
    11241165        break;
    11251166    case QEvent::ParentChange:
     
    11401181            return true;
    11411182        break;
     1183    case QEvent::HoverEnter:
     1184    case QEvent::HoverLeave:
     1185        // there's nothing special to do here and we don't want to update the whole widget
     1186        return true;
    11421187    case QEvent::HoverMove: {
    11431188#ifndef QT_NO_CURSOR
    11441189        QHoverEvent *e = static_cast<QHoverEvent*>(event);
    1145         if (d->layout->handleRect().contains(e->pos()))
     1190        QStyleOptionToolBar opt;
     1191        initStyleOption(&opt);
     1192        if (style()->subElementRect(QStyle::SE_ToolBarHandle, &opt, this).contains(e->pos()))
    11461193            setCursor(Qt::SizeAllCursor);
    11471194        else
     
    11541201            return true;
    11551202        break;
    1156 #ifdef Q_OS_WINCE
     1203#ifdef Q_WS_WINCE
    11571204    case QEvent::ContextMenu:
    11581205        {
     
    11781225                break;
    11791226
    1180             QWidget *w = qApp->activePopupWidget();
     1227            QWidget *w = QApplication::activePopupWidget();
    11811228            if (waitForPopup(this, w)) {
    1182                 d->waitForPopupTimer->start();
     1229                d->waitForPopupTimer.start(POPUP_TIMER_INTERVAL, this);
    11831230                break;
    11841231            }
    11851232
    1186             d->waitForPopupTimer->stop();
     1233            d->waitForPopupTimer.stop();
    11871234            d->layout->setExpanded(false);
    11881235            break;
     
    11921239    }
    11931240    return QWidget::event(event);
    1194 }
    1195 
    1196 void QToolBarPrivate::_q_waitForPopup()
    1197 {
    1198     Q_Q(QToolBar);
    1199 
    1200     QWidget *w = qApp->activePopupWidget();
    1201     if (!waitForPopup(q, w)) {
    1202         waitForPopupTimer->stop();
    1203         if (!q->underMouse())
    1204             layout->setExpanded(false);
    1205     }
    12061241}
    12071242
Note: See TracChangeset for help on using the changeset viewer.