Changeset 561 for trunk/src/gui/widgets/qtoolbar.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/widgets/qtoolbar.cpp
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the QtGui module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 71 71 #include "qdebug.h" 72 72 73 #define POPUP_TIMER_INTERVAL 500 74 73 75 QT_BEGIN_NAMESPACE 74 76 … … 88 90 { 89 91 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;98 92 q->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed)); 99 93 q->setBackgroundRole(QPalette::Button); … … 190 184 if (visible) 191 185 q->show(); 186 187 if (floating != wasFloating) 188 emit q->topLevelChanged(floating); 192 189 } 193 190 … … 199 196 return; 200 197 201 QMainWindow *win = qobject_cast<QMainWindow*>( q->parentWidget());198 QMainWindow *win = qobject_cast<QMainWindow*>(parent); 202 199 Q_ASSERT(win != 0); 203 200 QMainWindowLayout *layout = qobject_cast<QMainWindowLayout*>(win->layout()); … … 212 209 state->widgetItem = 0; 213 210 214 if (q-> layoutDirection() == Qt::RightToLeft)211 if (q->isRightToLeft()) 215 212 state->pressPos = QPoint(q->width() - state->pressPos.x(), state->pressPos.y()); 216 213 } … … 225 222 return; 226 223 227 QMainWindow *win = qobject_cast<QMainWindow*>( q->parentWidget());224 QMainWindow *win = qobject_cast<QMainWindow*>(parent); 228 225 Q_ASSERT(win != 0); 229 226 QMainWindowLayout *layout = qobject_cast<QMainWindowLayout*>(win->layout()); … … 275 272 bool QToolBarPrivate::mousePressEvent(QMouseEvent *event) 276 273 { 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) { 278 278 #ifdef Q_WS_MAC 279 Q_Q(QToolBar);280 279 // When using the unified toolbar on Mac OS X the user can can click and 281 280 // drag between toolbar contents to move the window. Make this work by 282 281 // implementing the standard mouse-dragging code and then call 283 282 // window->move() in mouseMoveEvent below. 284 if (QMainWindow *mainWindow = qobject_cast<QMainWindow *>( q->parentWidget())) {283 if (QMainWindow *mainWindow = qobject_cast<QMainWindow *>(parent)) { 285 284 if (mainWindow->toolBarArea(q) == Qt::TopToolBarArea 286 285 && mainWindow->unifiedTitleAndToolBarOnMac() … … 312 311 } else { 313 312 #ifdef Q_WS_MAC 313 if (!macWindowDragging) 314 return false; 314 315 macWindowDragging = false; 315 316 macWindowDragPressPosition = QPoint(); … … 336 337 } 337 338 338 QMainWindow *win = qobject_cast<QMainWindow*>( q->parentWidget());339 QMainWindow *win = qobject_cast<QMainWindow*>(parent); 339 340 if (win == 0) 340 341 return true; … … 364 365 // if we are right-to-left, we move so as to keep the right edge the same distance 365 366 // from the mouse 366 if (q-> layoutDirection() == Qt::LeftToRight)367 if (q->isLeftToRight()) 367 368 pos -= state->pressPos; 368 369 else … … 374 375 375 376 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); 377 378 int pos = 0; 378 379 … … 381 382 pos = q->y() + delta.y(); 382 383 } else { 383 if (q-> layoutDirection() == Qt::RightToLeft) {384 if (q->isRightToLeft()) { 384 385 pos = win->width() - q->width() - q->x() - delta.x(); 385 386 } else { … … 396 397 { 397 398 Q_Q(QToolBar); 398 399 399 QRect r = _r; 400 400 r.moveTopLeft(q->mapToGlobal(QPoint(0, 0))); 401 401 setWindowState(true, true, r); 402 layout->setExpanded(false); 402 403 } 403 404 … … 417 418 set of controls. 418 419 419 \ingroup application420 \mainclass 420 \ingroup mainwindow-classes 421 421 422 422 423 Toolbar buttons are added by adding \e actions, using addAction() … … 519 520 \sa toolButtonStyle QMainWindow::toolButtonStyle 520 521 */ 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 521 535 522 536 /*! … … 879 893 Qt::ToolButtonStyle will not be respected. 880 894 881 Note:You should use QAction::setVisible() to change the895 \note You should use QAction::setVisible() to change the 882 896 visibility of the widget. Using QWidget::setVisible(), 883 897 QWidget::show() and QWidget::hide() does not work. … … 1042 1056 } 1043 1057 1044 opt.rect = d->layout->handleRect();1058 opt.rect = style->subElementRect(QStyle::SE_ToolBarHandle, &opt, this); 1045 1059 if (opt.rect.isValid()) 1046 1060 style->drawPrimitive(QStyle::PE_IndicatorToolBarHandle, &opt, &p, this); … … 1079 1093 } 1080 1094 1095 #if defined(Q_WS_MAC) 1096 static 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 1081 1104 /*! \reimp */ 1082 1105 bool QToolBar::event(QEvent *event) … … 1085 1108 1086 1109 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; 1087 1120 case QEvent::Hide: 1088 1121 if (!isHidden()) … … 1091 1124 case QEvent::Show: 1092 1125 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) 1094 1135 // Fall through 1095 1136 case QEvent::LayoutRequest: { … … 1106 1147 1107 1148 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)) { 1112 1152 DisableScreenUpdates(); 1113 1153 macWindowToolbarShow(this, false); … … 1121 1161 } 1122 1162 } 1123 #endif 1163 # endif // !QT_MAC_USE_COCOA 1164 #endif // Q_WS_MAC 1124 1165 break; 1125 1166 case QEvent::ParentChange: … … 1140 1181 return true; 1141 1182 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; 1142 1187 case QEvent::HoverMove: { 1143 1188 #ifndef QT_NO_CURSOR 1144 1189 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())) 1146 1193 setCursor(Qt::SizeAllCursor); 1147 1194 else … … 1154 1201 return true; 1155 1202 break; 1156 #ifdef Q_ OS_WINCE1203 #ifdef Q_WS_WINCE 1157 1204 case QEvent::ContextMenu: 1158 1205 { … … 1178 1225 break; 1179 1226 1180 QWidget *w = qApp->activePopupWidget();1227 QWidget *w = QApplication::activePopupWidget(); 1181 1228 if (waitForPopup(this, w)) { 1182 d->waitForPopupTimer ->start();1229 d->waitForPopupTimer.start(POPUP_TIMER_INTERVAL, this); 1183 1230 break; 1184 1231 } 1185 1232 1186 d->waitForPopupTimer ->stop();1233 d->waitForPopupTimer.stop(); 1187 1234 d->layout->setExpanded(false); 1188 1235 break; … … 1192 1239 } 1193 1240 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 }1206 1241 } 1207 1242
Note:
See TracChangeset
for help on using the changeset viewer.