Changeset 561 for trunk/src/gui/widgets
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 152 edited
- 7 copied
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/qabstractbutton.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 ** … … 166 166 #endif 167 167 checkable(false), checked(false), autoRepeat(false), autoExclusive(false), 168 down(false), blockRefresh(false), 168 down(false), blockRefresh(false), pressed(false), 169 169 #ifndef QT_NO_BUTTONGROUP 170 170 group(0), … … 216 216 } 217 217 218 /*! 219 Adds the given \a button to the end of the group's internal list of buttons. 220 221 \sa removeButton() 222 */ 218 219 // TODO: Qt 5: Merge with addButton(QAbstractButton *button, int id) 223 220 void QButtonGroup::addButton(QAbstractButton *button) 224 221 { … … 233 230 button->d_func()->group = this; 234 231 d->buttonList.append(button); 235 if (id != -1) 232 if (id == -1) { 233 QList<int> ids = d->mapping.values(); 234 if (ids.isEmpty()) 235 d->mapping[button] = -2; 236 else { 237 qSort(ids); 238 d->mapping[button] = ids.first()-1; 239 } 240 } else { 236 241 d->mapping[button] = id; 242 } 243 237 244 if (d->exclusive && button->isChecked()) 238 245 button->d_func()->notifyChecked(); … … 313 320 #endif 314 321 315 Q_Q(const QAbstractButton); 316 QList<QAbstractButton*>candidates; 317 if (q->parentWidget()) { 318 candidates = qFindChildren<QAbstractButton *>(q->parentWidget()); 319 if (autoExclusive) { 320 for (int i = candidates.count() - 1; i >= 0; --i) { 321 QAbstractButton *candidate = candidates.at(i); 322 if (!candidate->autoExclusive() 323 #ifndef QT_NO_BUTTONGROUP 324 || candidate->group() 325 #endif 326 ) 327 candidates.removeAt(i); 328 } 322 QList<QAbstractButton*>candidates = qFindChildren<QAbstractButton *>(parent); 323 if (autoExclusive) { 324 for (int i = candidates.count() - 1; i >= 0; --i) { 325 QAbstractButton *candidate = candidates.at(i); 326 if (!candidate->autoExclusive() 327 #ifndef QT_NO_BUTTONGROUP 328 || candidate->group() 329 #endif 330 ) 331 candidates.removeAt(i); 329 332 } 330 333 } … … 377 380 bool exclusive = autoExclusive; 378 381 #endif 379 QWidget *f = qApp->focusWidget();382 QWidget *f = QApplication::focusWidget(); 380 383 QAbstractButton *fb = qobject_cast<QAbstractButton *>(f); 381 384 if (!fb || !buttonList.contains(fb)) … … 1088 1091 if (hitButton(e->pos())) { 1089 1092 setDown(true); 1093 d->pressed = true; 1090 1094 repaint(); //flush paint event before invoking potentially expensive operation 1091 1095 QApplication::flush(); … … 1101 1105 { 1102 1106 Q_D(QAbstractButton); 1107 d->pressed = false; 1108 1103 1109 if (e->button() != Qt::LeftButton) { 1104 1110 e->ignore(); … … 1125 1131 { 1126 1132 Q_D(QAbstractButton); 1127 if (!(e->buttons() & Qt::LeftButton) ) {1133 if (!(e->buttons() & Qt::LeftButton) || !d->pressed) { 1128 1134 e->ignore(); 1129 1135 return; … … 1170 1176 case Qt::Key_Down: 1171 1177 #ifdef QT_KEYPAD_NAVIGATION 1172 if (QApplication::keypadNavigationEnabled() && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right)) { 1178 if ((QApplication::keypadNavigationEnabled() 1179 && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right)) 1180 || (!QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional 1181 || (e->key() == Qt::Key_Up || e->key() == Qt::Key_Down))) { 1173 1182 e->ignore(); 1174 1183 return; … … 1237 1246 if (d->down) { 1238 1247 QPointer<QAbstractButton> guard(this); 1239 d->emitReleased(); 1248 nextCheckState(); 1249 if (guard) 1250 d->emitReleased(); 1240 1251 if (guard) 1241 1252 d->emitClicked(); -
trunk/src/gui/widgets/qabstractbutton.h
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 ** -
trunk/src/gui/widgets/qabstractbutton_p.h
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 ** … … 78 78 uint down :1; 79 79 uint blockRefresh :1; 80 uint pressed : 1; 80 81 81 82 #ifndef QT_NO_BUTTONGROUP -
trunk/src/gui/widgets/qabstractscrollarea.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 ** … … 52 52 #include "qboxlayout.h" 53 53 #include "qpainter.h" 54 #include "qmargins.h" 54 55 55 56 #include "qabstractscrollarea_p.h" 56 57 #include <qwidget.h> 58 59 #include <private/qapplication_p.h> 57 60 58 61 #ifdef Q_WS_MAC … … 158 161 viewport(0), cornerWidget(0), left(0), top(0), right(0), bottom(0), 159 162 xoffset(0), yoffset(0), viewportFilter(0) 163 #ifdef Q_WS_WIN 164 , singleFingerPanEnabled(false) 165 #endif 160 166 { 161 167 } … … 282 288 QObject::connect(vbar, SIGNAL(valueChanged(int)), q, SLOT(_q_vslide(int))); 283 289 QObject::connect(vbar, SIGNAL(rangeChanged(int,int)), q, SLOT(_q_showOrHideScrollBars()), Qt::QueuedConnection); 284 viewportFilter = new QAbstractScrollAreaFilter(this);285 viewport->installEventFilter(viewportFilter );290 viewportFilter.reset(new QAbstractScrollAreaFilter(this)); 291 viewport->installEventFilter(viewportFilter.data()); 286 292 viewport->setFocusProxy(q); 287 293 q->setFocusPolicy(Qt::WheelFocus); … … 289 295 q->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); 290 296 layoutChildren(); 291 } 297 #ifndef Q_WS_MAC 298 viewport->grabGesture(Qt::PanGesture); 299 #endif 300 } 301 302 #ifdef Q_WS_WIN 303 void QAbstractScrollAreaPrivate::setSingleFingerPanEnabled(bool on) 304 { 305 singleFingerPanEnabled = on; 306 QWidgetPrivate *dd = static_cast<QWidgetPrivate *>(QObjectPrivate::get(viewport)); 307 if (dd) 308 dd->winSetupGestures(); 309 } 310 #endif // Q_WS_WIN 292 311 293 312 void QAbstractScrollAreaPrivate::layoutChildren() … … 460 479 } 461 480 462 // ### Fix for 4.4, talk to Bjoern E or Girish.463 void QAbstractScrollAreaPrivate::scrollBarPolicyChanged(Qt::Orientation, Qt::ScrollBarPolicy) {}464 465 481 /*! 466 482 \internal … … 472 488 { 473 489 Q_D(QAbstractScrollArea); 474 d->init(); 490 QT_TRY { 491 d->init(); 492 } QT_CATCH(...) { 493 d->viewportFilter.reset(); 494 QT_RETHROW; 495 } 475 496 } 476 497 … … 484 505 { 485 506 Q_D(QAbstractScrollArea); 486 d->init(); 507 QT_TRY { 508 d->init(); 509 } QT_CATCH(...) { 510 d->viewportFilter.reset(); 511 QT_RETHROW; 512 } 487 513 } 488 514 … … 494 520 { 495 521 Q_D(QAbstractScrollArea); 496 delete d->viewportFilter; 522 // reset it here, otherwise we'll have a dangling pointer in ~QWidget 523 d->viewportFilter.reset(); 497 524 } 498 525 … … 518 545 d->viewport->setParent(this); 519 546 d->viewport->setFocusProxy(this); 520 d->viewport->installEventFilter(d->viewportFilter); 547 d->viewport->installEventFilter(d->viewportFilter.data()); 548 #ifndef Q_WS_MAC 549 d->viewport->grabGesture(Qt::PanGesture); 550 #endif 521 551 d->layoutChildren(); 522 552 if (isVisible()) … … 841 871 d->bottom = bottom; 842 872 d->layoutChildren(); 873 } 874 875 /*! 876 \since 4.6 877 Sets \a margins around the scrolling area. This is useful for 878 applications such as spreadsheets with "locked" rows and columns. 879 The marginal space is is left blank; put widgets in the unused 880 area. 881 882 By default all margins are zero. 883 884 */ 885 void QAbstractScrollArea::setViewportMargins(const QMargins &margins) 886 { 887 setViewportMargins(margins.left(), margins.top(), 888 margins.right(), margins.bottom()); 843 889 } 844 890 … … 874 920 d->layoutChildren(); 875 921 break; 876 case QEvent::Paint: 922 case QEvent::Paint: { 923 QStyleOption option; 924 option.initFrom(this); 877 925 if (d->cornerPaintingRect.isValid()) { 878 QStyleOption option;879 926 option.rect = d->cornerPaintingRect; 880 927 QPainter p(this); … … 883 930 #ifdef Q_WS_MAC 884 931 if (d->reverseCornerPaintingRect.isValid()) { 885 QStyleOption option;886 932 option.rect = d->reverseCornerPaintingRect; 887 933 QPainter p(this); … … 889 935 } 890 936 #endif 937 } 891 938 QFrame::paintEvent((QPaintEvent*)e); 892 939 break; … … 909 956 case QEvent::DragLeave: 910 957 #endif 958 // ignore touch events in case they have been propagated from the viewport 959 case QEvent::TouchBegin: 960 case QEvent::TouchUpdate: 961 case QEvent::TouchEnd: 911 962 return false; 963 case QEvent::Gesture: 964 { 965 QGestureEvent *ge = static_cast<QGestureEvent *>(e); 966 QPanGesture *g = static_cast<QPanGesture *>(ge->gesture(Qt::PanGesture)); 967 if (g) { 968 QScrollBar *hBar = horizontalScrollBar(); 969 QScrollBar *vBar = verticalScrollBar(); 970 QPointF delta = g->delta(); 971 if (!delta.isNull()) { 972 if (QApplication::isRightToLeft()) 973 delta.rx() *= -1; 974 int newX = hBar->value() - delta.x(); 975 int newY = vBar->value() - delta.y(); 976 hBar->setValue(newX); 977 vBar->setValue(newY); 978 } 979 return true; 980 } 981 return false; 982 } 912 983 case QEvent::StyleChange: 913 984 case QEvent::LayoutDirectionChange: … … 949 1020 case QEvent::MouseButtonRelease: 950 1021 case QEvent::MouseButtonDblClick: 1022 case QEvent::TouchBegin: 1023 case QEvent::TouchUpdate: 1024 case QEvent::TouchEnd: 951 1025 case QEvent::MouseMove: 952 1026 case QEvent::ContextMenu: … … 962 1036 return QFrame::event(e); 963 1037 case QEvent::LayoutRequest: 1038 case QEvent::Gesture: 1039 case QEvent::GestureOverride: 964 1040 return event(e); 965 1041 default: … … 1059 1135 { 1060 1136 Q_D(QAbstractScrollArea); 1061 if (static_cast<QWheelEvent*>(e)->orientation() == Qt::Horizontal) 1062 QApplication::sendEvent(d->hbar, e); 1063 else 1064 QApplication::sendEvent(d->vbar, e); 1137 QScrollBar *const bars[2] = { d->hbar, d->vbar }; 1138 int idx = (e->orientation() == Qt::Vertical) ? 1 : 0; 1139 int other = (idx + 1) % 2; 1140 if (!bars[idx]->isVisible() && bars[other]->isVisible()) 1141 idx = other; // If the scrollbar of the event orientation is hidden, fallback to the other. 1142 1143 QApplication::sendEvent(bars[idx], e); 1065 1144 } 1066 1145 #endif … … 1238 1317 { 1239 1318 layoutChildren(); 1319 #ifdef Q_WS_WIN 1320 // Need to re-subscribe to gestures as the content changes to make sure we 1321 // enable/disable panning when needed. 1322 QWidgetPrivate *dd = static_cast<QWidgetPrivate *>(QObjectPrivate::get(viewport)); 1323 if (dd) 1324 dd->winSetupGestures(); 1325 #endif // Q_WS_WIN 1240 1326 } 1241 1327 … … 1265 1351 int vsbExt = d->vbar->sizeHint().width(); 1266 1352 int extra = 2 * d->frameWidth; 1353 QStyleOption opt; 1354 opt.initFrom(this); 1355 if ((d->frameStyle != QFrame::NoFrame) 1356 && style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents, &opt, this)) { 1357 extra += style()->pixelMetric(QStyle::PM_ScrollView_ScrollBarSpacing, &opt, this); 1358 } 1267 1359 return QSize(d->scrollBarContainers[Qt::Horizontal]->sizeHint().width() + vsbExt + extra, 1268 1360 d->scrollBarContainers[Qt::Vertical]->sizeHint().height() + hsbExt + extra); -
trunk/src/gui/widgets/qabstractscrollarea.h
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 ** … … 53 53 #ifndef QT_NO_SCROLLAREA 54 54 55 class QMargins; 55 56 class QScrollBar; 56 57 class QAbstractScrollAreaPrivate; … … 96 97 QAbstractScrollArea(QAbstractScrollAreaPrivate &dd, QWidget *parent = 0); 97 98 void setViewportMargins(int left, int top, int right, int bottom); 99 void setViewportMargins(const QMargins &margins); 98 100 99 101 bool event(QEvent *); … … 131 133 132 134 friend class QStyleSheetStyle; 135 friend class QWidgetPrivate; 133 136 }; 134 137 -
trunk/src/gui/widgets/qabstractscrollarea_p.h
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 ** … … 63 63 class QScrollBar; 64 64 class QAbstractScrollAreaScrollBarContainer; 65 class Q_ GUI_EXPORT QAbstractScrollAreaPrivate: public QFramePrivate65 class Q_AUTOTEST_EXPORT QAbstractScrollAreaPrivate: public QFramePrivate 66 66 { 67 67 Q_DECLARE_PUBLIC(QAbstractScrollArea) … … 89 89 void layoutChildren(); 90 90 // ### Fix for 4.4, talk to Bjoern E or Girish. 91 virtual void scrollBarPolicyChanged(Qt::Orientation, Qt::ScrollBarPolicy) ;91 virtual void scrollBarPolicyChanged(Qt::Orientation, Qt::ScrollBarPolicy) {} 92 92 93 93 void _q_hslide(int); … … 99 99 inline bool viewportEvent(QEvent *event) 100 100 { return q_func()->viewportEvent(event); } 101 QObject *viewportFilter; 101 QScopedPointer<QObject> viewportFilter; 102 103 #ifdef Q_WS_WIN 104 bool singleFingerPanEnabled; 105 void setSingleFingerPanEnabled(bool on = true); 106 #endif 102 107 }; 103 108 -
trunk/src/gui/widgets/qabstractslider.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 ** … … 48 48 #include "qaccessible.h" 49 49 #endif 50 #ifdef QT_KEYPAD_NAVIGATION 51 #include "qtabwidget.h" // Needed in inTabWidget() 52 #endif // QT_KEYPAD_NAVIGATION 50 53 #include <limits.h> 51 54 … … 213 216 QAbstractSliderPrivate::QAbstractSliderPrivate() 214 217 : minimum(0), maximum(99), singleStep(1), pageStep(10), 215 value(0), position(0), pressValue(-1), tracking(true), blocktracking(false), pressed(false), 218 value(0), position(0), pressValue(-1), offset_accumulated(0), tracking(true), 219 blocktracking(false), pressed(false), 216 220 invertedAppearance(false), invertedControls(false), 217 221 orientation(Qt::Horizontal), repeatAction(QAbstractSlider::SliderNoAction) 222 #ifdef QT_KEYPAD_NAVIGATION 223 , isAutoRepeating(false) 224 , repeatMultiplier(1) 225 #endif 218 226 { 219 227 } … … 367 375 abstract sliders provides and typically corresponds to the user 368 376 pressing an arrow key. 377 378 If the property is modified during an auto repeating key event, behavior 379 is undefined. 369 380 370 381 \sa pageStep … … 595 606 switch (action) { 596 607 case SliderSingleStepAdd: 597 setSliderPosition(d->overflowSafeAdd(d-> singleStep));608 setSliderPosition(d->overflowSafeAdd(d->effectiveSingleStep())); 598 609 break; 599 610 case SliderSingleStepSub: 600 setSliderPosition(d->overflowSafeAdd(-d-> singleStep));611 setSliderPosition(d->overflowSafeAdd(-d->effectiveSingleStep())); 601 612 break; 602 613 case SliderPageStepAdd: … … 687 698 Q_D(QAbstractSlider); 688 699 e->ignore(); 689 if (e->orientation() != d->orientation && !rect().contains(e->pos())) 690 return; 691 692 static qreal offset = 0; 693 static QAbstractSlider *offset_owner = 0; 694 if (offset_owner != this){ 695 offset_owner = this; 696 offset = 0; 697 } 698 699 // On Mac/Cocoa, always scroll one step. The mouse wheel acceleration 700 // is higher than on other systems, so this works well in practice. 701 #ifdef QT_MAC_USE_COCOA 702 int step = 1; 703 #else 704 int step = qMin(QApplication::wheelScrollLines() * d->singleStep, d->pageStep); 700 701 int stepsToScroll = 0; 702 qreal offset = qreal(e->delta()) / 120; 703 704 if ((e->modifiers() & Qt::ControlModifier) || (e->modifiers() & Qt::ShiftModifier)) { 705 // Scroll one page regardless of delta: 706 stepsToScroll = qBound(-d->pageStep, int(offset * d->pageStep), d->pageStep); 707 d->offset_accumulated = 0; 708 } else { 709 // Calculate how many lines to scroll. Depending on what delta is (and 710 // offset), we might end up with a fraction (e.g. scroll 1.3 lines). We can 711 // only scroll whole lines, so we keep the reminder until next event. 712 qreal stepsToScrollF = offset * QApplication::wheelScrollLines() * d->effectiveSingleStep(); 713 // Check if wheel changed direction since last event: 714 if (d->offset_accumulated != 0 && (offset / d->offset_accumulated) < 0) 715 d->offset_accumulated = 0; 716 717 d->offset_accumulated += stepsToScrollF; 718 stepsToScroll = qBound(-d->pageStep, int(d->offset_accumulated), d->pageStep); 719 d->offset_accumulated -= int(d->offset_accumulated); 720 if (stepsToScroll == 0) 721 return; 722 } 723 724 if (d->invertedControls) 725 stepsToScroll = -stepsToScroll; 726 727 int prevValue = d->value; 728 d->position = d->overflowSafeAdd(stepsToScroll); // value will be updated by triggerAction() 729 triggerAction(SliderMove); 730 731 if (prevValue == d->value) 732 d->offset_accumulated = 0; 733 else 734 e->accept(); 735 } 705 736 #endif 706 if ((e->modifiers() & Qt::ControlModifier) || (e->modifiers() & Qt::ShiftModifier)) 707 step = d->pageStep; 708 int currentOffset = qRound(qreal(e->delta()) * step / 120); 709 if (currentOffset == 0) 710 currentOffset = (e->delta() < 0 ? -1 : 1); 711 offset += currentOffset; 712 713 if (d->invertedControls) 714 offset = -offset; 715 716 int prevValue = d->value; 717 d->position = d->overflowSafeAdd(int(offset)); // value will be updated by triggerAction() 718 719 triggerAction(SliderMove); 720 if (prevValue == d->value) { 721 offset = 0; 722 } else { 723 offset -= int(offset); 724 e->accept(); 725 } 726 } 737 #ifdef QT_KEYPAD_NAVIGATION 738 /*! 739 \internal 740 741 Tells us if it there is currently a reachable widget by keypad navigation in 742 a certain \a orientation. 743 If no navigation is possible, occuring key events in that \a orientation may 744 be used to interact with the value in the focussed widget, even though it 745 currently has not the editFocus. 746 747 \sa QWidgetPrivate::widgetInNavigationDirection(), QWidget::hasEditFocus() 748 */ 749 inline static bool canKeypadNavigate(Qt::Orientation orientation) 750 { 751 return orientation == Qt::Horizontal? 752 (QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionEast) 753 || QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionWest)) 754 :(QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionNorth) 755 || QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionSouth)); 756 } 757 /*! 758 \internal 759 760 Checks, if the \a widget is inside a QTabWidget. If is is inside 761 one, left/right key events will be used to switch between tabs in keypad 762 navigation. If there is no QTabWidget, the horizontal key events can be used to 763 interact with the value in the focussed widget, even though it currently has 764 not the editFocus. 765 766 \sa QWidget::hasEditFocus() 767 */ 768 inline static bool inTabWidget(QWidget *widget) 769 { 770 for (QWidget *tabWidget = widget; tabWidget; tabWidget = tabWidget->parentWidget()) 771 if (qobject_cast<const QTabWidget*>(tabWidget)) 772 return true; 773 return false; 774 } 775 #endif // QT_KEYPAD_NAVIGATION 776 /*! 777 \reimp 778 */ 779 void QAbstractSlider::keyPressEvent(QKeyEvent *ev) 780 { 781 Q_D(QAbstractSlider); 782 SliderAction action = SliderNoAction; 783 #ifdef QT_KEYPAD_NAVIGATION 784 if (ev->isAutoRepeat()) { 785 if (d->firstRepeat.isNull()) 786 d->firstRepeat = QTime::currentTime(); 787 else if (1 == d->repeatMultiplier) { 788 // This is the interval in milli seconds which one key repetition 789 // takes. 790 const int repeatMSecs = d->firstRepeat.msecsTo(QTime::currentTime()); 791 792 /** 793 * The time it takes to currently navigate the whole slider. 794 */ 795 const qreal currentTimeElapse = (qreal(maximum()) / singleStep()) * repeatMSecs; 796 797 /** 798 * This is an arbitrarily determined constant in msecs that 799 * specifies how long time it should take to navigate from the 800 * start to the end(excluding starting key auto repeat). 801 */ 802 const int SliderRepeatElapse = 2500; 803 804 d->repeatMultiplier = currentTimeElapse / SliderRepeatElapse; 805 } 806 807 } 808 else if (!d->firstRepeat.isNull()) { 809 d->firstRepeat = QTime(); 810 d->repeatMultiplier = 1; 811 } 812 727 813 #endif 728 /*! 729 \reimp 730 */ 731 void QAbstractSlider::keyPressEvent(QKeyEvent *ev) 732 { 733 Q_D(QAbstractSlider); 734 SliderAction action = SliderNoAction; 814 735 815 switch (ev->key()) { 736 816 #ifdef QT_KEYPAD_NAVIGATION … … 753 833 case Qt::Key_Left: 754 834 #ifdef QT_KEYPAD_NAVIGATION 755 if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { 835 // In QApplication::KeypadNavigationDirectional, we want to change the slider 836 // value if there is no left/right navigation possible and if this slider is not 837 // inside a tab widget. 838 if (QApplication::keypadNavigationEnabled() 839 && (!hasEditFocus() && QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder 840 || d->orientation == Qt::Vertical 841 || !hasEditFocus() && (canKeypadNavigate(Qt::Horizontal) || inTabWidget(this)))) { 756 842 ev->ignore(); 757 843 return; … … 768 854 case Qt::Key_Right: 769 855 #ifdef QT_KEYPAD_NAVIGATION 770 if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { 856 // Same logic as in Qt::Key_Left 857 if (QApplication::keypadNavigationEnabled() 858 && (!hasEditFocus() && QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder 859 || d->orientation == Qt::Vertical 860 || !hasEditFocus() && (canKeypadNavigate(Qt::Horizontal) || inTabWidget(this)))) { 771 861 ev->ignore(); 772 862 return; … … 783 873 case Qt::Key_Up: 784 874 #ifdef QT_KEYPAD_NAVIGATION 785 if (QApplication::keypadNavigationEnabled()) { 875 // In QApplication::KeypadNavigationDirectional, we want to change the slider 876 // value if there is no up/down navigation possible. 877 if (QApplication::keypadNavigationEnabled() 878 && (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder 879 || d->orientation == Qt::Horizontal 880 || !hasEditFocus() && canKeypadNavigate(Qt::Vertical))) { 786 881 ev->ignore(); 787 882 break; … … 792 887 case Qt::Key_Down: 793 888 #ifdef QT_KEYPAD_NAVIGATION 794 if (QApplication::keypadNavigationEnabled()) { 889 // Same logic as in Qt::Key_Up 890 if (QApplication::keypadNavigationEnabled() 891 && (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder 892 || d->orientation == Qt::Horizontal 893 || !hasEditFocus() && canKeypadNavigate(Qt::Vertical))) { 795 894 ev->ignore(); 796 895 break; -
trunk/src/gui/widgets/qabstractslider.h
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 ** -
trunk/src/gui/widgets/qabstractslider_p.h
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 ** … … 69 69 void setSteps(int single, int page); 70 70 71 int minimum, maximum, singleStep, pageStep, value, position, pressValue; 71 int minimum, maximum, pageStep, value, position, pressValue; 72 73 /** 74 * Call effectiveSingleStep() when changing the slider value. 75 */ 76 int singleStep; 77 78 float offset_accumulated; 72 79 uint tracking : 1; 73 80 uint blocktracking :1; … … 83 90 #ifdef QT_KEYPAD_NAVIGATION 84 91 int origValue; 92 93 /** 94 */ 95 bool isAutoRepeating; 96 97 /** 98 * When we're auto repeating, we multiply singleStep with this value to 99 * get our effective step. 100 */ 101 qreal repeatMultiplier; 102 103 /** 104 * The time of when the first auto repeating key press event occurs. 105 */ 106 QTime firstRepeat; 107 85 108 #endif 109 110 inline int effectiveSingleStep() const 111 { 112 return singleStep 113 #ifdef QT_KEYPAD_NAVIGATION 114 * repeatMultiplier 115 #endif 116 ; 117 } 86 118 87 119 inline int bound(int val) const { return qMax(minimum, qMin(maximum, val)); } -
trunk/src/gui/widgets/qabstractspinbox.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 ** … … 58 58 #include <qstylepainter.h> 59 59 #include <qdebug.h> 60 #ifndef QT_NO_ACCESSIBILITY 61 # include <qaccessible.h> 62 #endif 60 63 61 64 #if defined(Q_WS_X11) 62 65 #include <limits.h> 66 #endif 67 68 #if defined(Q_OS_SYMBIAN) 69 #include <W32STD.H> 70 #include <private/qt_s60_p.h> 63 71 #endif 64 72 … … 194 202 if (d->buttonSymbols != buttonSymbols) { 195 203 d->buttonSymbols = buttonSymbols; 204 d->updateEditFieldGeometry(); 196 205 update(); 197 206 } … … 660 669 661 670 d->edit->setFrame(false); 662 d->edit->setAttribute(Qt::WA_InputMethodEnabled, false);663 671 d->edit->setFocusProxy(this); 664 672 d->edit->setAcceptDrops(false); … … 689 697 Q_D(QAbstractSpinBox); 690 698 d->interpret(EmitIfChanged); 699 } 700 701 /* 702 Reimplemented in 4.6, so be careful. 703 */ 704 /*! 705 \reimp 706 */ 707 QVariant QAbstractSpinBox::inputMethodQuery(Qt::InputMethodQuery query) const 708 { 709 Q_D(const QAbstractSpinBox); 710 return d->edit->inputMethodQuery(query); 691 711 } 692 712 … … 925 945 926 946 int steps = 1; 947 bool isPgUpOrDown = false; 927 948 switch (event->key()) { 928 949 case Qt::Key_PageUp: 929 950 case Qt::Key_PageDown: 930 951 steps *= 10; 952 isPgUpOrDown = true; 931 953 case Qt::Key_Up: 932 954 case Qt::Key_Down: { … … 950 972 d->buttonState = (Keyboard | (up ? Up : Down)); 951 973 } 952 stepBy(steps); 974 if (d->spinClickTimerId == -1) 975 stepBy(steps); 976 if(event->isAutoRepeat() && !isPgUpOrDown) { 977 if(d->spinClickThresholdTimerId == -1 && d->spinClickTimerId == -1) { 978 d->updateState(up, true); 979 } 980 } 981 #ifndef QT_NO_ACCESSIBILITY 982 QAccessible::updateAccessibility(this, 0, QAccessible::ValueChanged); 983 #endif 953 984 return; 954 985 } … … 970 1001 case Qt::Key_Enter: 971 1002 case Qt::Key_Return: 972 d->edit->d_func()-> modifiedState = d->edit->d_func()->undoState = 0;1003 d->edit->d_func()->control->clearUndo(); 973 1004 d->interpret(d->keyboardTracking ? AlwaysEmit : EmitIfChanged); 974 1005 selectAll(); … … 1044 1075 Q_D(QAbstractSpinBox); 1045 1076 1046 if (d->buttonState & Keyboard && !event->isAutoRepeat() 1047 && style()->styleHint(QStyle::SH_SpinBox_AnimateButton, 0, this)) { 1077 if (d->buttonState & Keyboard && !event->isAutoRepeat()) { 1048 1078 d->reset(); 1049 1079 } else { … … 1131 1161 } 1132 1162 1163 1164 /*! 1165 \internal 1166 1167 Used when acceleration is turned on. We need to get the 1168 keyboard auto repeat rate from OS. This value is used as 1169 argument when starting acceleration related timers. 1170 1171 Every platform should, either, use native calls to obtain 1172 the value or hard code some reasonable rate. 1173 1174 Remember that time value should be given in msecs. 1175 */ 1176 static int getKeyboardAutoRepeatRate() { 1177 int ret = 30; 1178 #if defined(Q_OS_SYMBIAN) 1179 TTimeIntervalMicroSeconds32 initialTime; 1180 TTimeIntervalMicroSeconds32 time; 1181 S60->wsSession().GetKeyboardRepeatRate(initialTime, time); 1182 ret = time.Int() / 1000; // msecs 1183 #elif defined(Q_OS_WIN) && !defined(Q_OS_WINCE) 1184 DWORD time; 1185 if (SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, &time, 0) != FALSE) 1186 ret = static_cast<int>(1000 / static_cast<int>(time)); // msecs 1187 #endif 1188 return ret; // msecs 1189 } 1190 1133 1191 /*! 1134 1192 \reimp … … 1143 1201 killTimer(d->spinClickThresholdTimerId); 1144 1202 d->spinClickThresholdTimerId = -1; 1145 d->spinClickTimerId = startTimer(d->spinClickTimerInterval); 1203 d->effectiveSpinRepeatRate = d->buttonState & Keyboard 1204 ? getKeyboardAutoRepeatRate() 1205 : d->spinClickTimerInterval; 1206 d->spinClickTimerId = startTimer(d->effectiveSpinRepeatRate); 1146 1207 doStep = true; 1147 1208 } else if (event->timerId() == d->spinClickTimerId) { 1148 1209 if (d->accelerate) { 1149 d->acceleration = d->acceleration + (int)(d-> spinClickTimerInterval* 0.05);1150 if (d-> spinClickTimerInterval- d->acceleration >= 10) {1210 d->acceleration = d->acceleration + (int)(d->effectiveSpinRepeatRate * 0.05); 1211 if (d->effectiveSpinRepeatRate - d->acceleration >= 10) { 1151 1212 killTimer(d->spinClickTimerId); 1152 d->spinClickTimerId = startTimer(d-> spinClickTimerInterval- d->acceleration);1213 d->spinClickTimerId = startTimer(d->effectiveSpinRepeatRate - d->acceleration); 1153 1214 } 1154 1215 } … … 1291 1352 : edit(0), type(QVariant::Invalid), spinClickTimerId(-1), 1292 1353 spinClickTimerInterval(100), spinClickThresholdTimerId(-1), spinClickThresholdTimerInterval(-1), 1293 buttonState(None), cachedText(QLatin1String("\x01")), cachedState(QValidator::Invalid),1294 pendingEmit(false), readOnly(false), wrapping(false),1354 effectiveSpinRepeatRate(1), buttonState(None), cachedText(QLatin1String("\x01")), 1355 cachedState(QValidator::Invalid), pendingEmit(false), readOnly(false), wrapping(false), 1295 1356 ignoreCursorPositionChanged(false), frame(true), accelerate(false), keyboardTracking(true), 1296 1357 cleared(false), ignoreUpdateEdit(false), correctionMode(QAbstractSpinBox::CorrectToPreviousValue), … … 1537 1598 */ 1538 1599 1539 void QAbstractSpinBoxPrivate::updateState(bool up )1600 void QAbstractSpinBoxPrivate::updateState(bool up, bool fromKeyboard /* = false */) 1540 1601 { 1541 1602 Q_Q(QAbstractSpinBox); … … 1546 1607 : QAbstractSpinBox::StepDownEnabled))) { 1547 1608 spinClickThresholdTimerId = q->startTimer(spinClickThresholdTimerInterval); 1548 buttonState = (up ? (Mouse | Up) : (Mouse | Down));1609 buttonState = (up ? Up : Down) | (fromKeyboard ? Keyboard : Mouse); 1549 1610 q->stepBy(up ? 1 : -1); 1611 #ifndef QT_NO_ACCESSIBILITY 1612 QAccessible::updateAccessibility(q, 0, QAccessible::ValueChanged); 1613 #endif 1550 1614 } 1551 1615 } … … 1568 1632 option->activeSubControls = QStyle::SC_None; 1569 1633 option->buttonSymbols = d->buttonSymbols; 1570 option->subControls = QStyle::SC_SpinBoxFrame ;1634 option->subControls = QStyle::SC_SpinBoxFrame | QStyle::SC_SpinBoxEditField; 1571 1635 if (d->buttonSymbols != QAbstractSpinBox::NoButtons) { 1572 1636 option->subControls |= QStyle::SC_SpinBoxUp | QStyle::SC_SpinBoxDown; … … 1696 1760 void QAbstractSpinBoxPrivate::setRange(const QVariant &min, const QVariant &max) 1697 1761 { 1762 Q_Q(QAbstractSpinBox); 1763 1698 1764 clearCache(); 1699 1765 minimum = min; … … 1707 1773 updateEdit(); 1708 1774 } 1775 1776 q->updateGeometry(); 1709 1777 } 1710 1778 … … 1781 1849 QASBDEBUG() << "QAbstractSpinBoxPrivate::interpret() text '" 1782 1850 << edit->displayText() 1783 << "' >> '" << copy << "'"1784 << "' >> '" << tmp << "'";1851 << "' >> '" << copy << '\'' 1852 << "' >> '" << tmp << '\''; 1785 1853 1786 1854 doInterpret = tmp != copy && (q->validate(tmp, pos) == QValidator::Acceptable); … … 1832 1900 return QValidator::Acceptable; 1833 1901 1834 if (!dptr->prefix.isEmpty() && !input.startsWith(dptr->prefix)) 1902 if (!dptr->prefix.isEmpty() && !input.startsWith(dptr->prefix)) { 1835 1903 input.prepend(dptr->prefix); 1904 pos += dptr->prefix.length(); 1905 } 1836 1906 1837 1907 if (!dptr->suffix.isEmpty() && !input.endsWith(dptr->suffix)) -
trunk/src/gui/widgets/qabstractspinbox.h
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 ** … … 123 123 bool event(QEvent *event); 124 124 125 QVariant inputMethodQuery(Qt::InputMethodQuery) const; 126 125 127 virtual QValidator::State validate(QString &input, int &pos) const; 126 128 virtual void fixup(QString &input) const; -
trunk/src/gui/widgets/qabstractspinbox_p.h
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 ** … … 99 99 void init(); 100 100 void reset(); 101 void updateState(bool up );101 void updateState(bool up, bool fromKeyboard = false); 102 102 QString stripped(const QString &text, int *pos = 0) const; 103 103 bool specialValue() const; … … 130 130 QVariant::Type type; 131 131 int spinClickTimerId, spinClickTimerInterval, spinClickThresholdTimerId, spinClickThresholdTimerInterval; 132 int effectiveSpinRepeatRate; 132 133 uint buttonState; 133 134 mutable QString cachedText; … … 136 137 mutable QSize cachedSizeHint, cachedMinimumSizeHint; 137 138 uint pendingEmit : 1; 138 uint spindownEnabled : 1;139 uint spinupEnabled : 1;140 139 uint readOnly : 1; 141 140 uint wrapping : 1; -
trunk/src/gui/widgets/qbuttongroup.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 ** … … 49 49 \ingroup organizers 50 50 \ingroup geomanagement 51 \ingroup appearance52 \mainclass53 51 54 52 QButtonGroup provides an abstract container into which button widgets can … … 177 175 178 176 /*! 179 \fn void QButtonGroup::addButton(QAbstractButton *button, int id = -1); 177 \fn void QButtonGroup::addButton(QAbstractButton *button); 178 179 Adds the given \a button to the end of the group's internal list 180 of buttons. An id will be assigned to the button by this 181 QButtonGroup. Automatically assigned ids are guaranteed to be 182 negative, starting with -2. If you are also assigning your own 183 ids, use positive values to avoid conflicts. 184 185 \sa removeButton() buttons() 186 */ 187 188 /*! 189 \fn void QButtonGroup::addButton(QAbstractButton *button, int id); 180 190 181 191 Adds the given \a button to the button group, with the given \a 182 id. If \a id is -1 (the default), an id will be assigned to the 183 button by this QButtonGroup. 192 id. It is recommended to assign only positive ids. 184 193 185 194 \sa removeButton() buttons() -
trunk/src/gui/widgets/qbuttongroup.h
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 ** -
trunk/src/gui/widgets/qcalendartextnavigator_p.h
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 ** -
trunk/src/gui/widgets/qcalendarwidget.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 ** … … 199 199 QString str; 200 200 if (m_day / 10 == 0) 201 str += QLatin1 String("0");201 str += QLatin1Char('0'); 202 202 str += QString::number(m_day); 203 203 return highlightString(str, m_pos); … … 211 211 QString str; 212 212 if (date.day() / 10 == 0) 213 str += QLatin1 String("0");213 str += QLatin1Char('0'); 214 214 return str + QString::number(date.day()); 215 215 } else if (repeat == 3) { … … 317 317 QString str; 318 318 if (m_month / 10 == 0) 319 str += QLatin1 String("0");319 str += QLatin1Char('0'); 320 320 str += QString::number(m_month); 321 321 return highlightString(str, m_pos); … … 329 329 QString str; 330 330 if (date.month() / 10 == 0) 331 str += QLatin1 String("0");331 str += QLatin1Char('0'); 332 332 return str + QString::number(date.month()); 333 333 } else if (repeat == 3) { 334 334 return m_locale.standaloneMonthName(date.month(), QLocale::ShortFormat); 335 } else if (repeat >= 4){335 } else /*if (repeat >= 4)*/ { 336 336 return m_locale.standaloneMonthName(date.month(), QLocale::LongFormat); 337 337 } 338 return QString();339 338 } 340 339 … … 433 432 for (int i = 0; i < 3; i++) { 434 433 if (m_year / pow == 0) 435 str += QLatin1 String("0");434 str += QLatin1Char('0'); 436 435 pow *= 10; 437 436 } … … 446 445 int year = date.year() % 100; 447 446 if (year / 10 == 0) 448 str = QLatin1 String("0");447 str = QLatin1Char('0'); 449 448 return str + QString::number(year); 450 449 } … … 578 577 579 578 int pos = 0; 580 const QLatin1 String quote("'");579 const QLatin1Char quote('\''); 581 580 bool quoting = false; 582 581 QString separator; … … 1962 1961 calendar widget allowing the user to select a date. 1963 1962 \since 4.2 1964 \mainclass 1963 1965 1964 \ingroup advanced 1966 1965 … … 1969 1968 The widget is initialized with the current month and year, but 1970 1969 QCalendarWidget provides several public slots to change the year 1971 and month that is shown. The currently displayed month and year 1972 can be retrieved using the currentPageMonth() and currentPageYear() 1973 functions, respectively. 1970 and month that is shown. 1974 1971 1975 1972 By default, today's date is selected, and the user can select a … … 1983 1980 all. Note that a date also can be selected programmatically using 1984 1981 the setSelectedDate() slot. 1982 1983 The currently displayed month and year can be retrieved using the 1984 monthShown() and yearShown() functions, respectively. 1985 1985 1986 1986 A newly created calendar widget uses abbreviated day names, and … … 2143 2143 int rows = 7; 2144 2144 int cols = 8; 2145 int startRow = 0;2146 int startCol = 0;2147 2145 2148 2146 const int marginH = (style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1) * 2; … … 2150 2148 if (horizontalHeaderFormat() == QCalendarWidget::NoHorizontalHeader) { 2151 2149 rows = 6; 2152 startRow = 1;2153 2150 } else { 2154 2151 for (int i = 1; i <= 7; i++) { … … 2161 2158 if (verticalHeaderFormat() == QCalendarWidget::NoVerticalHeader) { 2162 2159 cols = 7; 2163 startCol = 1;2164 2160 } else { 2165 2161 for (int i = 1; i <= 6; i++) { … … 2293 2289 2294 2290 The currently displayed month and year can be retrieved using the 2295 currentPageMonth() and currentPageYear() functions respectively.2291 monthShown() and yearShown() functions respectively. 2296 2292 2297 2293 \sa yearShown(), monthShown(), showPreviousMonth(), showNextMonth(), … … 2302 2298 { 2303 2299 Q_D(QCalendarWidget); 2300 QDate currentDate = d->getCurrentDate(); 2301 int day = currentDate.day(); 2302 int daysInMonths = QDate(year, month, 1).daysInMonth(); 2303 if (day > daysInMonths) 2304 day = daysInMonths; 2305 2304 2306 d->showMonth(year, month); 2307 2308 QDate newDate(year, month, day); 2309 int row = -1, col = -1; 2310 d->m_model->cellForDate(newDate, &row, &col); 2311 if (row != -1 && col != -1) { 2312 d->m_view->selectionModel()->setCurrentIndex(d->m_model->index(row, col), 2313 QItemSelectionModel::NoUpdate); 2314 } 2305 2315 } 2306 2316 … … 2527 2537 if (!min.isValid() || !max.isValid()) 2528 2538 return; 2529 2530 QDate minimum = min;2531 QDate maximum = max;2532 if (min > max) {2533 minimum = max;2534 maximum = min;2535 }2536 2539 2537 2540 QDate oldDate = d->m_model->m_date; … … 2792 2795 { 2793 2796 Q_D(QCalendarWidget); 2794 if ( date.isNull() && !format.isValid())2797 if (date.isNull()) 2795 2798 d->m_model->m_dateFormats.clear(); 2796 2799 else … … 3034 3037 { 3035 3038 Q_D(QCalendarWidget); 3036 if (event->type() == QEvent::MouseButtonPress && d->yearEdit->hasFocus() && !QRect(d->yearEdit->mapToGlobal(QPoint(0, 0)), d->yearEdit->size()).contains(static_cast<QMouseEvent *>(event)->globalPos())) { 3037 event->accept(); 3038 d->_q_yearEditingFinished(); 3039 setFocus(); 3040 return true; 3039 if (event->type() == QEvent::MouseButtonPress && d->yearEdit->hasFocus()) { 3040 QWidget *tlw = window(); 3041 QWidget *widget = static_cast<QWidget*>(watched); 3042 //as we have a event filter on the whole application we first make sure that the top level widget 3043 //of both this and the watched widget are the same to decide if we should finish the year edition. 3044 if (widget->window() == tlw) { 3045 QPoint mousePos = widget->mapTo(tlw, static_cast<QMouseEvent *>(event)->pos()); 3046 QRect geom = QRect(d->yearEdit->mapTo(tlw, QPoint(0, 0)), d->yearEdit->size()); 3047 if (!geom.contains(mousePos)) { 3048 event->accept(); 3049 d->_q_yearEditingFinished(); 3050 setFocus(); 3051 return true; 3052 } 3053 } 3041 3054 } 3042 3055 return QWidget::eventFilter(watched, event); -
trunk/src/gui/widgets/qcalendarwidget.h
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 ** -
trunk/src/gui/widgets/qcheckbox.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 ** … … 74 74 75 75 \ingroup basicwidgets 76 \mainclass 77 78 A QCheckBox is an option button that can be switched on (checked) 79 or off (unchecked). Checkboxes are typically used to represent 80 features in an application that can be enabled or disabled without 81 affecting others, but different types of behavior can be 82 implemented. 83 84 A QButtonGroup can be used to group check buttons visually. 76 77 78 A QCheckBox is an option button that can be switched on (checked) or off 79 (unchecked). Checkboxes are typically used to represent features in an 80 application that can be enabled or disabled without affecting others, but 81 different types of behavior can be implemented. For example, a 82 QButtonGroup can be used to group check buttons logically, allowing 83 exclusive checkboxes. However, QButtonGroup does not provide any visual 84 representation. 85 86 The image below further illustrates the differences between exclusive and 87 non-exclusive checkboxes. 88 89 \table 90 \row \o \inlineimage checkboxes-exclusive.png 91 \o \inlineimage checkboxes-non-exclusive.png 92 \endtable 85 93 86 94 Whenever a checkbox is checked or cleared it emits the signal 87 stateChanged(). Connect to this signal if you want to trigger an 88 action each time the checkbox changes state. You can use 89 isChecked() to query whether or not a checkbox is checked. 90 91 In addition to the usual checked and unchecked states, QCheckBox 92 optionally provides a third state to indicate "no change". This 93 is useful whenever you need to give the user the option of neither 94 checking nor unchecking a checkbox. If you need this third state, 95 enable it with setTristate(), and use checkState() to query the current 96 toggle state. 97 98 Just like QPushButton, a checkbox displays text, and optionally a 99 small icon. The icon is set with setIcon(). The text can be set in 100 the constructor or with setText(). A shortcut key can be specified 101 by preceding the preferred character with an ampersand. For 102 example: 95 stateChanged(). Connect to this signal if you want to trigger an action 96 each time the checkbox changes state. You can use isChecked() to query 97 whether or not a checkbox is checked. 98 99 In addition to the usual checked and unchecked states, QCheckBox optionally 100 provides a third state to indicate "no change". This is useful whenever you 101 need to give the user the option of neither checking nor unchecking a 102 checkbox. If you need this third state, enable it with setTristate(), and 103 use checkState() to query the current toggle state. 104 105 Just like QPushButton, a checkbox displays text, and optionally a small 106 icon. The icon is set with setIcon(). The text can be set in the 107 constructor or with setText(). A shortcut key can be specified by preceding 108 the preferred character with an ampersand. For example: 103 109 104 110 \snippet doc/src/snippets/code/src_gui_widgets_qcheckbox.cpp 0 105 111 106 In this example the shortcut is \e{Alt+A}. See the \l 107 {QShortcut#mnemonic}{QShortcut} documentation for details (to 108 display an actual ampersand, use '&&'). 109 110 Important inherited functions: text(), setText(), text(), 111 pixmap(), setPixmap(), accel(), setAccel(), isToggleButton(), 112 setDown(), isDown(), isOn(), checkState(), autoRepeat(), 113 isExclusiveToggle(), group(), setAutoRepeat(), toggle(), 114 pressed(), released(), clicked(), toggled(), checkState(), and 115 stateChanged(). 112 In this example the shortcut is \e{Alt+A}. See the \l{QShortcut#mnemonic} 113 {QShortcut} documentation for details (to display an actual ampersand, 114 use '&&'). 115 116 Important inherited functions: text(), setText(), text(), pixmap(), 117 setPixmap(), accel(), setAccel(), isToggleButton(), setDown(), isDown(), 118 isOn(), checkState(), autoRepeat(), isExclusiveToggle(), group(), 119 setAutoRepeat(), toggle(), pressed(), released(), clicked(), toggled(), 120 checkState(), and stateChanged(). 116 121 117 122 \table 100% 118 \row \o \inlineimage macintosh-checkbox.png Screenshot of a Macintosh style checkbox 119 \o A checkbox shown in the \l{Macintosh Style Widget Gallery}{Macintosh widget style}. 120 \row \o \inlineimage windows-checkbox.png Screenshot of a Windows XP style checkbox 121 \o A checkbox shown in the \l{Windows XP Style Widget Gallery}{Windows XP widget style}. 122 \row \o \inlineimage plastique-checkbox.png Screenshot of a Plastique style checkbox 123 \o A checkbox shown in the \l{Plastique Style Widget Gallery}{Plastique widget style}. 123 \row 124 \o \inlineimage macintosh-checkbox.png Screenshot of a Macintosh style checkbox 125 \o A checkbox shown in the \l{Macintosh Style Widget Gallery}{Macintosh widget style}. 126 \row 127 \o \inlineimage windows-checkbox.png Screenshot of a Windows XP style checkbox 128 \o A checkbox shown in the \l{Windows XP Style Widget Gallery}{Windows XP widget style}. 129 \row 130 \o \inlineimage plastique-checkbox.png Screenshot of a Plastique style checkbox 131 \o A checkbox shown in the \l{Plastique Style Widget Gallery}{Plastique widget style}. 124 132 \endtable 125 133 … … 139 147 \fn void QCheckBox::stateChanged(int state) 140 148 141 This signal is emitted whenever the check box's state changes, 142 i.e.whenever the user checks or unchecks it.149 This signal is emitted whenever the check box's state changes, i.e. 150 whenever the user checks or unchecks it. 143 151 144 152 \a state contains the check box's new Qt::CheckState. … … 162 170 163 171 /*! 164 Initialize \a option with the values from this QCheckBox. This method is useful165 for subclasses when they need a QStyleOptionButton, but don't want to fill166 in all the information themselves.172 Initializes \a option with the values from this QCheckBox. This method is 173 useful for subclasses that require a QStyleOptionButton, but do not want 174 to fill in all the information themselves. 167 175 168 176 \sa QStyleOption::initFrom() … … 194 202 Constructs a checkbox with the given \a parent, but with no text. 195 203 196 The \a parent argument is passed on to the QAbstractButton constructor.204 \a parent is passed on to the QAbstractButton constructor. 197 205 */ 198 206 … … 207 215 Constructs a checkbox with the given \a parent and \a text. 208 216 209 The \a parent argument is passed on to the QAbstractButton constructor.217 \a parent is passed on to the QAbstractButton constructor. 210 218 */ 211 219 … … 232 240 233 241 /*! 234 Returns the check box's check state. 235 If you do not need tristate support, you can also 236 use \l QAbstractButton::isChecked() which returns 237 a boolean. 242 Returns the check box's check state. If you do not need tristate support, 243 you can also use \l QAbstractButton::isChecked() which returns a boolean. 238 244 239 245 \sa setCheckState() Qt::CheckState … … 248 254 249 255 /*! 250 Sets the check box's check state to \a state. 251 If you do not need tristate support, you can also 252 use \l QAbstractButton::setChecked() which takes 253 a boolean. 256 Sets the check box's check state to \a state. If you do not need tristate 257 support, you can also use \l QAbstractButton::setChecked() which takes a 258 boolean. 254 259 255 260 \sa checkState() Qt::CheckState … … 275 280 276 281 277 /*!\reimp 282 /*! 283 \reimp 278 284 */ 279 285 QSize QCheckBox::sizeHint() const … … 295 301 } 296 302 297 /*!\reimp 303 /*! 304 \reimp 298 305 */ 299 306 void QCheckBox::paintEvent(QPaintEvent *) … … 326 333 327 334 328 /*!\reimp*/ 335 /*! 336 \reimp 337 */ 329 338 bool QCheckBox::hitButton(const QPoint &pos) const 330 339 { … … 334 343 } 335 344 336 /*!\reimp*/ 345 /*! 346 \reimp 347 */ 337 348 void QCheckBox::checkStateSet() 338 349 { … … 346 357 } 347 358 348 /*!\reimp*/ 359 /*! 360 \reimp 361 */ 349 362 void QCheckBox::nextCheckState() 350 363 { -
trunk/src/gui/widgets/qcheckbox.h
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 ** -
trunk/src/gui/widgets/qcocoamenu_mac.mm
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 **40 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE41 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.42 39 ** 43 40 ****************************************************************************/ … … 99 96 = QApplication::activePopupWidget()) 100 97 popup->close(); 101 qt_mac_emit_menuSignals(((QT_MANGLE_NAMESPACE(QCocoaMenu) *)menu)->qmenu, true); 98 QMenu *qtmenu = static_cast<QT_MANGLE_NAMESPACE(QCocoaMenu) *>(menu)->qmenu; 99 qt_mac_emit_menuSignals(qtmenu, true); 100 qt_mac_menu_collapseSeparators(menu, qtmenu->separatorsCollapsible()); 102 101 } 103 102 -
trunk/src/gui/widgets/qcocoamenu_mac_p.h
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 ** … … 57 57 QT_FORWARD_DECLARE_CLASS(QMenu) 58 58 59 @interface QT_MANGLE_NAMESPACE(QCocoaMenu) : NSMenu 60 { 61 QMenu *qmenu; 62 } 63 - (id)initWithQMenu:(QMenu*)menu; 59 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5 60 61 @protocol NSMenuDelegate <NSObject> 64 62 - (void)menu:(NSMenu*)menu willHighlightItem:(NSMenuItem*)item; 65 63 - (void)menuWillOpen:(NSMenu*)menu; … … 67 65 - (BOOL)hasShortcut:(NSMenu *)menu forKey:(NSString *)key forModifiers:(NSUInteger)modifier 68 66 whichItem:(NSMenuItem**)outItem; 67 @end 68 69 #endif 70 71 @interface QT_MANGLE_NAMESPACE(QCocoaMenu) : NSMenu <NSMenuDelegate> 72 { 73 QMenu *qmenu; 74 } 75 - (id)initWithQMenu:(QMenu*)menu; 69 76 - (BOOL)menuHasKeyEquivalent:(NSMenu *)menu forEvent:(NSEvent *)event target:(id *)target action:(SEL *)action; 70 77 @end -
trunk/src/gui/widgets/qcocoatoolbardelegate_mac.mm
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 ** … … 44 44 #include <private/qmainwindowlayout_p.h> 45 45 #include <private/qt_mac_p.h> 46 #include <private/qt_cocoa_helpers_mac_p.h> 46 47 #include <private/qcocoaview_mac_p.h> 47 48 #include <private/qwidget_p.h> … … 100 101 Q_UNUSED(flag); 101 102 Q_UNUSED(nstoolbar); 102 QToolBar *tb = mainWindowLayout->cocoaItemIDToToolbarHash.value(QCFString::toQString(CFStringRef(itemIdentifier))); 103 QToolBar *tb = mainWindowLayout->cocoaItemIDToToolbarHash.value( 104 QT_PREPEND_NAMESPACE(qt_mac_NSStringToQString)(itemIdentifier)); 103 105 NSToolbarItem *item = nil; 104 106 if (tb) { … … 112 114 { 113 115 NSToolbarItem *item = [[notification userInfo] valueForKey:@"item"]; 114 QToolBar *tb = mainWindowLayout->cocoaItemIDToToolbarHash.value(QCFString::toQString(CFStringRef([item itemIdentifier]))); 116 QToolBar *tb = mainWindowLayout->cocoaItemIDToToolbarHash.value( 117 QT_PREPEND_NAMESPACE(qt_mac_NSStringToQString)([item itemIdentifier])); 115 118 if (!tb) 116 119 return; // I can't really do anything about this. … … 120 123 NSArray *items = [[qt_mac_window_for(mainWindowLayout->layoutState.mainWindow->window()) toolbar] items]; 121 124 int someIndex = 0; 122 bool foundItem = false;123 125 for (NSToolbarItem *i in items) { 124 if (i == item) { 125 foundItem = true; 126 if (i == item) 126 127 break; 127 }128 128 ++someIndex; 129 129 } -
trunk/src/gui/widgets/qcocoatoolbardelegate_mac_p.h
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 ** -
trunk/src/gui/widgets/qcombobox.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 ** … … 60 60 #include "qinputcontext.h" 61 61 #endif 62 #include <private/qapplication_p.h> 62 63 #include <private/qcombobox_p.h> 63 64 #include <private/qabstractitemmodel_p.h> 64 65 #include <private/qabstractscrollarea_p.h> 66 #include <private/qsoftkeymanager_p.h> 65 67 #include <qdebug.h> 66 67 68 #ifdef Q_WS_X11 68 69 #include <private/qt_x11_p.h> … … 77 78 #endif 78 79 QT_BEGIN_NAMESPACE 79 80 extern QHash<QByteArray, QFont> *qt_app_fonts_hash();81 80 82 81 QComboBoxPrivate::QComboBoxPrivate() … … 150 149 151 150 // Make sure fonts set on the combo box also overrides the font for the popup menu. 152 if (mCombo->testAttribute(Qt::WA_SetFont) || mCombo->testAttribute(Qt::WA_MacSmallSize) 153 || mCombo->testAttribute(Qt::WA_MacMiniSize)) 151 if (mCombo->testAttribute(Qt::WA_SetFont) 152 || mCombo->testAttribute(Qt::WA_MacSmallSize) 153 || mCombo->testAttribute(Qt::WA_MacMiniSize) 154 || mCombo->font() != qt_app_fonts_hash()->value("QComboBox", QFont())) 154 155 menuOption.font = mCombo->font(); 155 156 else … … 192 193 updateLineEditGeometry(); 193 194 } 195 if (currentIndex.row() != indexBeforeChange) 196 _q_emitCurrentIndexChanged(currentIndex); 194 197 q->update(); 195 198 } … … 314 317 315 318 // height 316 sh.setHeight(qMax(fm. lineSpacing(), 14) + 2);319 sh.setHeight(qMax(fm.height(), 14) + 2); 317 320 if (hasIcon) { 318 321 sh.setHeight(qMax(sh.height(), iconSize.height() + 2)); … … 487 490 488 491 /* 489 Sets currentIndex on entered if the LeftButton is not pressed. This490 means that if mouseTracking(...) is on, we setCurrentIndex and select491 even when LeftButton is not pressed.492 */493 void QComboBoxPrivateContainer::setCurrentIndex(const QModelIndex &index)494 {495 if (QComboBoxDelegate::isSeparator(index))496 return;497 view->setCurrentIndex(index);498 }499 500 /*501 492 Returns the item view used for the combobox popup. 502 493 */ … … 523 514 this, SLOT(updateScrollers())); 524 515 #endif 525 disconnect(view, SIGNAL(entered(QModelIndex)),526 this, SLOT(setCurrentIndex(QModelIndex)));527 516 disconnect(view, SIGNAL(destroyed()), 528 517 this, SLOT(viewDestroyed())); 518 529 519 delete view; 530 520 view = 0; … … 560 550 this, SLOT(updateScrollers())); 561 551 #endif 562 connect(view, SIGNAL(entered(QModelIndex)),563 this, SLOT(setCurrentIndex(QModelIndex)));564 552 connect(view, SIGNAL(destroyed()), 565 553 this, SLOT(viewDestroyed())); 554 555 #ifdef QT_SOFTKEYS_ENABLED 556 selectAction = QSoftKeyManager::createKeyedAction(QSoftKeyManager::SelectSoftKey, Qt::Key_Select, itemView); 557 cancelAction = QSoftKeyManager::createKeyedAction(QSoftKeyManager::CancelSoftKey, Qt::Key_Escape, itemView); 558 addAction(selectAction); 559 addAction(cancelAction); 560 #endif 566 561 } 567 562 … … 639 634 case Qt::Key_F4: 640 635 case Qt::Key_Escape: 641 #ifdef QT_KEYPAD_NAVIGATION642 case Qt::Key_Back:643 #endif644 636 combo->hidePopup(); 645 637 return true; … … 648 640 } 649 641 break; 650 case QEvent::MouseMove: {642 case QEvent::MouseMove: 651 643 if (isVisible()) { 652 644 QMouseEvent *m = static_cast<QMouseEvent *>(e); … … 655 647 if (vector.manhattanLength() > 9 && blockMouseReleaseTimer.isActive()) 656 648 blockMouseReleaseTimer.stop(); 649 QModelIndex indexUnderMouse = view->indexAt(m->pos()); 650 if (indexUnderMouse.isValid() && indexUnderMouse != view->currentIndex() 651 && !QComboBoxDelegate::isSeparator(indexUnderMouse)) { 652 view->setCurrentIndex(indexUnderMouse); 653 } 657 654 } 658 655 break; 659 }660 656 case QEvent::MouseButtonRelease: { 661 657 QMouseEvent *m = static_cast<QMouseEvent *>(e); … … 863 859 864 860 \ingroup basicwidgets 865 \mainclass 861 866 862 867 863 A QComboBox provides a means of presenting a list of options to the user … … 936 932 setLayoutItemMargins(QStyle::SE_ComboBoxLayoutItem); 937 933 q->setModel(new QStandardItemModel(0, 1, q)); 938 q->setAttribute(Qt::WA_InputMethodEnabled); 934 if (!q->isEditable()) 935 q->setAttribute(Qt::WA_InputMethodEnabled, false); 936 else 937 q->setAttribute(Qt::WA_InputMethodEnabled); 939 938 } 940 939 … … 948 947 container->itemView()->setModel(model); 949 948 container->itemView()->setTextElideMode(Qt::ElideMiddle); 950 updateDelegate( );949 updateDelegate(true); 951 950 updateLayoutDirection(); 951 updateViewContainerPaletteAndOpacity(); 952 952 QObject::connect(container, SIGNAL(itemSelected(QModelIndex)), 953 953 q, SLOT(_q_itemSelected(QModelIndex))); … … 986 986 } 987 987 988 void QComboBoxPrivate::_q_rowsAboutToBeInserted(const QModelIndex & parent,989 int /*start*/, int /*end*/)990 {991 if (parent != root)992 return;993 indexBeforeChange = currentIndex.row();994 }995 996 988 void QComboBoxPrivate::_q_rowsInserted(const QModelIndex &parent, int start, int end) 997 989 { … … 1016 1008 } 1017 1009 1018 void QComboBoxPrivate::_q_rowsAboutToBeRemoved(const QModelIndex &parent, int /*start*/, int /*end*/) 1019 { 1020 if (parent != root) 1021 return; 1022 1010 void QComboBoxPrivate::_q_updateIndexBeforeChange() 1011 { 1023 1012 indexBeforeChange = currentIndex.row(); 1024 1013 } … … 1051 1040 } 1052 1041 1042 1043 void QComboBoxPrivate::updateViewContainerPaletteAndOpacity() 1044 { 1045 if (!container) 1046 return; 1047 Q_Q(QComboBox); 1048 QStyleOptionComboBox opt; 1049 q->initStyleOption(&opt); 1050 #ifndef QT_NO_MENU 1051 if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) { 1052 QMenu menu; 1053 menu.ensurePolished(); 1054 container->setPalette(menu.palette()); 1055 container->setWindowOpacity(menu.windowOpacity()); 1056 } else 1057 #endif 1058 { 1059 container->setPalette(q->palette()); 1060 container->setWindowOpacity(1.0); 1061 } 1062 } 1053 1063 1054 1064 /*! … … 1105 1115 } 1106 1116 1117 Qt::MatchFlags QComboBoxPrivate::matchFlags() const 1118 { 1119 // Base how duplicates are determined on the autocompletion case sensitivity 1120 Qt::MatchFlags flags = Qt::MatchFixedString; 1121 #ifndef QT_NO_COMPLETER 1122 if (!lineEdit->completer() || lineEdit->completer()->caseSensitivity() == Qt::CaseSensitive) 1123 #endif 1124 flags |= Qt::MatchCaseSensitive; 1125 return flags; 1126 } 1127 1128 1129 void QComboBoxPrivate::_q_editingFinished() 1130 { 1131 Q_Q(QComboBox); 1132 if (lineEdit && !lineEdit->text().isEmpty()) { 1133 //here we just check if the current item was entered 1134 const int index = q_func()->findText(lineEdit->text(), matchFlags()); 1135 if (index != -1 && itemText(currentIndex) != lineEdit->text()) { 1136 q->setCurrentIndex(index); 1137 emitActivated(currentIndex); 1138 } 1139 } 1140 1141 } 1142 1107 1143 void QComboBoxPrivate::_q_returnPressed() 1108 1144 { … … 1117 1153 int index = -1; 1118 1154 if (!duplicatesEnabled) { 1119 // Base how duplicates are determined on the autocompletion case sensitivity 1120 Qt::MatchFlags flags = Qt::MatchFixedString; 1121 #ifndef QT_NO_COMPLETER 1122 if (!lineEdit->completer() || lineEdit->completer()->caseSensitivity() == Qt::CaseSensitive) 1123 #endif 1124 flags |= Qt::MatchCaseSensitive; 1125 index = q->findText(text, flags); 1155 index = q->findText(text, matchFlags()); 1126 1156 if (index != -1) { 1127 1157 q->setCurrentIndex(index); … … 1225 1255 Q_D(QComboBox); 1226 1256 1227 disconnect(d->model, SIGNAL(destroyed()), 1228 this, SLOT(_q_modelDestroyed())); 1257 QT_TRY { 1258 disconnect(d->model, SIGNAL(destroyed()), 1259 this, SLOT(_q_modelDestroyed())); 1260 } QT_CATCH(...) { 1261 ; // objects can't throw in destructor 1262 } 1229 1263 } 1230 1264 … … 1568 1602 } 1569 1603 1570 void QComboBoxPrivate::updateDelegate() 1604 /*! \internal 1605 update the default delegate 1606 depending on the style's SH_ComboBox_Popup hint, we use a different default delegate. 1607 1608 but we do not change the delegate is the combobox use a custom delegate, 1609 unless \a force is set to true. 1610 */ 1611 void QComboBoxPrivate::updateDelegate(bool force) 1571 1612 { 1572 1613 Q_Q(QComboBox); 1573 1614 QStyleOptionComboBox opt; 1574 1615 q->initStyleOption(&opt); 1575 if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) 1576 q->setItemDelegate(new QComboMenuDelegate(q->view(), q)); 1577 else 1578 q->setItemDelegate(new QComboBoxDelegate(q->view(), q)); 1616 if (q->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, q)) { 1617 if (force || qobject_cast<QComboBoxDelegate *>(q->itemDelegate())) 1618 q->setItemDelegate(new QComboMenuDelegate(q->view(), q)); 1619 } else { 1620 if (force || qobject_cast<QComboMenuDelegate *>(q->itemDelegate())) 1621 q->setItemDelegate(new QComboBoxDelegate(q->view(), q)); 1622 } 1579 1623 } 1580 1624 … … 1644 1688 d->lineEdit->setParent(this); 1645 1689 connect(d->lineEdit, SIGNAL(returnPressed()), this, SLOT(_q_returnPressed())); 1690 connect(d->lineEdit, SIGNAL(editingFinished()), this, SLOT(_q_editingFinished())); 1646 1691 connect(d->lineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(editTextChanged(QString))); 1647 1692 #ifdef QT3_SUPPORT … … 1827 1872 this, SLOT(_q_dataChanged(QModelIndex,QModelIndex))); 1828 1873 disconnect(d->model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), 1829 this, SLOT(_q_ rowsAboutToBeInserted(QModelIndex,int,int)));1874 this, SLOT(_q_updateIndexBeforeChange())); 1830 1875 disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)), 1831 1876 this, SLOT(_q_rowsInserted(QModelIndex,int,int))); 1832 1877 disconnect(d->model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), 1833 this, SLOT(_q_ rowsAboutToBeRemoved(QModelIndex,int,int)));1878 this, SLOT(_q_updateIndexBeforeChange())); 1834 1879 disconnect(d->model, SIGNAL(rowsRemoved(QModelIndex,int,int)), 1835 1880 this, SLOT(_q_rowsRemoved(QModelIndex,int,int))); 1836 1881 disconnect(d->model, SIGNAL(destroyed()), 1837 1882 this, SLOT(_q_modelDestroyed())); 1883 disconnect(d->model, SIGNAL(modelAboutToBeReset()), 1884 this, SLOT(_q_updateIndexBeforeChange())); 1838 1885 disconnect(d->model, SIGNAL(modelReset()), 1839 1886 this, SLOT(_q_modelReset())); … … 1847 1894 this, SLOT(_q_dataChanged(QModelIndex,QModelIndex))); 1848 1895 connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), 1849 this, SLOT(_q_ rowsAboutToBeInserted(QModelIndex,int,int)));1896 this, SLOT(_q_updateIndexBeforeChange())); 1850 1897 connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), 1851 1898 this, SLOT(_q_rowsInserted(QModelIndex,int,int))); 1852 1899 connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), 1853 this, SLOT(_q_ rowsAboutToBeRemoved(QModelIndex,int,int)));1900 this, SLOT(_q_updateIndexBeforeChange())); 1854 1901 connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), 1855 1902 this, SLOT(_q_rowsRemoved(QModelIndex,int,int))); 1856 1903 connect(model, SIGNAL(destroyed()), 1857 1904 this, SLOT(_q_modelDestroyed())); 1905 connect(model, SIGNAL(modelAboutToBeReset()), 1906 this, SLOT(_q_updateIndexBeforeChange())); 1858 1907 connect(model, SIGNAL(modelReset()), 1859 1908 this, SLOT(_q_modelReset())); … … 1936 1985 QString newText = q->itemText(currentIndex.row()); 1937 1986 if (lineEdit->text() != newText) 1938 lineEdit->setText( q->itemText(currentIndex.row()));1987 lineEdit->setText(newText); 1939 1988 updateLineEditGeometry(); 1940 1989 } … … 2133 2182 Removes the item at the given \a index from the combobox. 2134 2183 This will update the current index if the index is removed. 2184 2185 This function does nothing if \a index is out of range. 2135 2186 */ 2136 2187 void QComboBox::removeItem(int index) 2137 2188 { 2138 Q_ASSERT(index >= 0 && index < count()); 2139 Q_D(QComboBox); 2189 Q_D(QComboBox); 2190 if (index < 0 || index >= count()) 2191 return; 2140 2192 d->model->removeRows(index, 1, d->root); 2141 2193 } … … 2402 2454 container->setGeometry(listRect); 2403 2455 2404 bool updatesEnabled = container->updatesEnabled(); 2456 #ifndef Q_WS_MAC 2457 const bool updatesEnabled = container->updatesEnabled(); 2458 #endif 2459 2405 2460 #if defined(Q_WS_WIN) && !defined(QT_NO_EFFECTS) 2406 2461 bool scrollDown = (listRect.topLeft() == below); 2407 if (QApplication::isEffectEnabled(Qt::UI_AnimateCombo) 2462 if (QApplication::isEffectEnabled(Qt::UI_AnimateCombo) 2408 2463 && !style->styleHint(QStyle::SH_ComboBox_Popup, &opt, this) && !window()->testAttribute(Qt::WA_DontShowOnScreen)) 2409 2464 qScrollEffect(container, scrollDown ? QEffects::DownScroll : QEffects::UpScroll, 150); 2410 2465 #endif 2466 2467 // Don't disable updates on Mac OS X. Windows are displayed immediately on this platform, 2468 // which means that the window will be visible before the call to container->show() returns. 2469 // If updates are disabled at this point we'll miss our chance at painting the popup 2470 // menu before it's shown, causing flicker since the window then displays the standard gray 2471 // background. 2472 #ifndef Q_WS_MAC 2411 2473 container->setUpdatesEnabled(false); 2474 #endif 2475 2412 2476 container->raise(); 2413 2477 container->show(); … … 2420 2484 : QAbstractItemView::EnsureVisible); 2421 2485 2486 #ifndef Q_WS_MAC 2422 2487 container->setUpdatesEnabled(updatesEnabled); 2488 #endif 2489 2423 2490 container->update(); 2491 #ifdef QT_KEYPAD_NAVIGATION 2492 if (QApplication::keypadNavigationEnabled()) 2493 view()->setEditFocus(true); 2494 #endif 2424 2495 } 2425 2496 … … 2573 2644 break; 2574 2645 case QEvent::PaletteChange: { 2575 QStyleOptionComboBox opt; 2576 initStyleOption(&opt); 2577 #ifndef QT_NO_MENU 2578 if (style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, this)) { 2579 QMenu menu; 2580 menu.ensurePolished(); 2581 d->viewContainer()->setPalette(menu.palette()); 2582 d->viewContainer()->setWindowOpacity(menu.windowOpacity()); 2583 } else 2584 #endif 2585 { 2586 d->viewContainer()->setPalette(palette()); 2587 d->viewContainer()->setWindowOpacity(1.0); 2588 } 2646 d->updateViewContainerPaletteAndOpacity(); 2589 2647 break; 2590 2648 } -
trunk/src/gui/widgets/qcombobox.h
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 ** … … 53 53 54 54 QT_MODULE(Gui) 55 56 55 #ifndef QT_NO_COMBOBOX 57 56 … … 306 305 Q_PRIVATE_SLOT(d_func(), void _q_emitHighlighted(const QModelIndex &)) 307 306 Q_PRIVATE_SLOT(d_func(), void _q_emitCurrentIndexChanged(const QModelIndex &index)) 307 Q_PRIVATE_SLOT(d_func(), void _q_editingFinished()) 308 308 Q_PRIVATE_SLOT(d_func(), void _q_returnPressed()) 309 309 Q_PRIVATE_SLOT(d_func(), void _q_resetButton()) 310 310 Q_PRIVATE_SLOT(d_func(), void _q_dataChanged(const QModelIndex &, const QModelIndex &)) 311 Q_PRIVATE_SLOT(d_func(), void _q_ rowsAboutToBeInserted(const QModelIndex & parent, int start, int end))311 Q_PRIVATE_SLOT(d_func(), void _q_updateIndexBeforeChange()) 312 312 Q_PRIVATE_SLOT(d_func(), void _q_rowsInserted(const QModelIndex & parent, int start, int end)) 313 Q_PRIVATE_SLOT(d_func(), void _q_rowsAboutToBeRemoved(const QModelIndex & parent, int start, int end))314 313 Q_PRIVATE_SLOT(d_func(), void _q_rowsRemoved(const QModelIndex & parent, int start, int end)) 315 314 Q_PRIVATE_SLOT(d_func(), void _q_modelDestroyed()) -
trunk/src/gui/widgets/qcombobox_p.h
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 ** … … 78 78 79 79 QT_BEGIN_NAMESPACE 80 81 class QAction; 80 82 81 83 class QComboBoxListView : public QListView … … 230 232 void scrollItemView(int action); 231 233 void updateScrollers(); 232 void setCurrentIndex(const QModelIndex &index);233 234 void viewDestroyed(); 234 235 … … 254 255 QComboBoxPrivateScroller *top; 255 256 QComboBoxPrivateScroller *bottom; 257 #ifdef QT_SOFTKEYS_ENABLED 258 QAction *selectAction; 259 QAction *cancelAction; 260 #endif 256 261 }; 257 262 258 263 class QComboMenuDelegate : public QAbstractItemDelegate 259 { 264 { Q_OBJECT 260 265 public: 261 266 QComboMenuDelegate(QObject *parent, QComboBox *cmb) : QAbstractItemDelegate(parent), mCombo(cmb) {} … … 286 291 // be other side effects from using the new class 287 292 class QComboBoxDelegate : public QItemDelegate 288 { 293 { Q_OBJECT 289 294 public: 290 295 QComboBoxDelegate(QObject *parent, QComboBox *cmb) : QItemDelegate(parent), mCombo(cmb) {} 291 296 292 297 static bool isSeparator(const QModelIndex &index) { 293 return index.data(Qt::AccessibleDescriptionRole).toString() == Q String::fromLatin1("separator");298 return index.data(Qt::AccessibleDescriptionRole).toString() == QLatin1String("separator"); 294 299 } 295 300 static void setSeparator(QAbstractItemModel *model, const QModelIndex &index) { … … 338 343 QComboBoxPrivateContainer* viewContainer(); 339 344 void updateLineEditGeometry(); 345 Qt::MatchFlags matchFlags() const; 346 void _q_editingFinished(); 340 347 void _q_returnPressed(); 341 348 void _q_complete(); … … 352 359 void _q_resetButton(); 353 360 void _q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); 354 void _q_ rowsAboutToBeInserted(const QModelIndex & parent, int start, int end);361 void _q_updateIndexBeforeChange(); 355 362 void _q_rowsInserted(const QModelIndex & parent, int start, int end); 356 void _q_rowsAboutToBeRemoved(const QModelIndex & parent, int start, int end);357 363 void _q_rowsRemoved(const QModelIndex & parent, int start, int end); 358 364 void updateArrow(QStyle::StateFlag state); … … 368 374 void updateLayoutDirection(); 369 375 void setCurrentIndex(const QModelIndex &index); 370 void updateDelegate( );376 void updateDelegate(bool force = false); 371 377 void keyboardSearchString(const QString &text); 372 378 void modelChanged(); 379 void updateViewContainerPaletteAndOpacity(); 373 380 374 381 QAbstractItemModel *model; -
trunk/src/gui/widgets/qcommandlinkbutton.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 ** … … 58 58 59 59 \ingroup basicwidgets 60 \mainclass 60 61 61 62 62 The command link is a new control that was introduced by Windows Vista. It's … … 146 146 font.setPointSizeF(9.0); 147 147 } 148 return font; 148 149 // Note the font will be resolved against 150 // QPainters font, so we need to restore the mask 151 int resolve_mask = font.resolve_mask; 152 QFont modifiedFont = q->font().resolve(font); 153 modifiedFont.detach(); 154 modifiedFont.resolve_mask = resolve_mask; 155 return modifiedFont; 149 156 } 150 157 … … 154 161 QFont font = q->font(); 155 162 font.setPointSizeF(9.0); 156 return font; 163 164 // Note the font will be resolved against 165 // QPainters font, so we need to restore the mask 166 int resolve_mask = font.resolve_mask; 167 QFont modifiedFont = q->font().resolve(font); 168 modifiedFont.detach(); 169 modifiedFont.resolve_mask = resolve_mask; 170 return modifiedFont; 157 171 } 158 172 … … 203 217 204 218 q->setIconSize(QSize(20, 20)); 205 q->setIcon(q->style()->standardIcon(QStyle::SP_CommandLink)); 219 QStyleOptionButton opt; 220 q->initStyleOption(&opt); 221 q->setIcon(q->style()->standardIcon(QStyle::SP_CommandLink, &opt)); 206 222 } 207 223 … … 311 327 int heightWithoutDescription = d->descriptionOffset() + d->bottomMargin(); 312 328 // find the width available for the description area 313 return heightWithoutDescription + d->descriptionHeight(width); 329 return qMax(heightWithoutDescription + d->descriptionHeight(width), 330 iconSize().height() + d->topMargin() + d->bottomMargin()); 314 331 } 315 332 -
trunk/src/gui/widgets/qcommandlinkbutton.h
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 ** -
trunk/src/gui/widgets/qdatetimeedit.cpp
r2 r561 1 /**************************************************************************** )1 /**************************************************************************** 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 ** … … 76 76 77 77 \ingroup basicwidgets 78 \mainclass 78 79 79 80 80 QDateTimeEdit allows the user to edit dates by using the keyboard or … … 221 221 \brief the QDateTime that is set in the QDateTimeEdit 222 222 223 When setting this property the timespec of the QDateTimeEdit remains the same 224 and the timespec of the new QDateTime is ignored. 225 223 226 By default, this property contains a date that refers to January 1, 224 227 2000 and a time of 00:00:00 and 0 milliseconds. … … 240 243 if (!(d->sections & DateSections_Mask)) 241 244 setDateRange(datetime.date(), datetime.date()); 242 d->setValue(Q Variant(datetime), EmitIfChanged);245 d->setValue(QDateTime(datetime.date(), datetime.time(), d->spec), EmitIfChanged); 243 246 } 244 247 } … … 933 936 \brief the current timespec used by the date time edit. 934 937 \since 4.4 935 936 All dates/passed to the date time edit will be converted to this937 timespec.938 938 */ 939 939 … … 1087 1087 //hide cursor 1088 1088 d->edit->d_func()->setCursorVisible(false); 1089 if (d->edit->d_func()->cursorTimer > 0) 1090 killTimer(d->edit->d_func()->cursorTimer); 1091 d->edit->d_func()->cursorTimer = 0; 1092 1089 d->edit->d_func()->control->setCursorBlinkPeriod(0); 1093 1090 d->setSelected(0); 1094 1091 } … … 1111 1108 //hide cursor 1112 1109 d->edit->d_func()->setCursorVisible(false); 1113 if (d->edit->d_func()->cursorTimer > 0) 1114 killTimer(d->edit->d_func()->cursorTimer); 1115 d->edit->d_func()->cursorTimer = 0; 1116 1110 d->edit->d_func()->control->setCursorBlinkPeriod(0); 1117 1111 d->setSelected(0); 1118 1112 oldCurrent = 0; … … 1127 1121 case Qt::Key_Right: 1128 1122 if (event->key() == Qt::Key_Left || event->key() == Qt::Key_Right) { 1123 if ( 1129 1124 #ifdef QT_KEYPAD_NAVIGATION 1130 if (!QApplication::keypadNavigationEnabled() || !hasEditFocus()) { 1131 select = false; 1132 break; 1133 } 1134 #else 1135 if (!(event->modifiers() & Qt::ControlModifier)) { 1125 QApplication::keypadNavigationEnabled() && !hasEditFocus() 1126 || !QApplication::keypadNavigationEnabled() && 1127 #endif 1128 !(event->modifiers() & Qt::ControlModifier)) { 1136 1129 select = false; 1137 1130 break; 1138 1131 } 1139 1132 #ifdef Q_WS_MAC 1140 else { 1133 else 1134 #ifdef QT_KEYPAD_NAVIGATION 1135 if (!QApplication::keypadNavigationEnabled()) 1136 #endif 1137 { 1141 1138 select = (event->modifiers() & Qt::ShiftModifier); 1142 1139 break; 1143 1140 } 1144 1141 #endif 1145 #endif // QT_KEYPAD_NAVIGATION1146 1142 } 1147 1143 // else fall through … … 1511 1507 1512 1508 \ingroup basicwidgets 1513 \mainclass 1509 1514 1510 1515 1511 Many of the properties and functions provided by QTimeEdit are implemented in … … 1573 1569 1574 1570 \ingroup basicwidgets 1575 \mainclass 1571 1576 1572 1577 1573 Many of the properties and functions provided by QDateEdit are implemented in … … 1648 1644 currentSectionIndex = FirstSectionIndex; 1649 1645 1650 layoutDirection = QApplication::layoutDirection();1651 1646 first.type = FirstSection; 1652 1647 last.type = LastSection; … … 1935 1930 /*! 1936 1931 \internal 1937 \reimp1938 1932 */ 1939 1933 … … 1946 1940 /*! 1947 1941 \internal 1948 \reimp1949 1942 1950 1943 This function's name is slightly confusing; it is not to be confused … … 2104 2097 /*! 2105 2098 \internal 2106 \reimp2107 2099 */ 2108 2100 … … 2134 2126 /*! 2135 2127 \internal 2136 \reimp2137 2128 */ 2138 2129 … … 2279 2270 optCombo.init(this); 2280 2271 optCombo.editable = true; 2272 optCombo.frame = opt.frame; 2281 2273 optCombo.subControls = opt.subControls; 2282 2274 optCombo.activeSubControls = opt.activeSubControls; … … 2391 2383 #endif 2392 2384 updateTimeSpec(); 2385 q->setInputMethodHints(Qt::ImhPreferNumbers); 2393 2386 setLayoutItemMargins(QStyle::SE_DateTimeEditLayoutItem); 2394 2387 } -
trunk/src/gui/widgets/qdatetimeedit.h
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 ** -
trunk/src/gui/widgets/qdatetimeedit_p.h
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 ** … … 90 90 bool fixup = false) const; 91 91 void clearSection(int index); 92 virtual QString displayText() const { return edit-> displayText(); } // this is from QDateTimeParser92 virtual QString displayText() const { return edit->text(); } // this is from QDateTimeParser 93 93 94 94 int absoluteIndex(QDateTimeEdit::Section s, int index) const; … … 133 133 134 134 QString defaultDateFormat, defaultTimeFormat, defaultDateTimeFormat, unreversedFormat; 135 Qt::LayoutDirection layoutDirection;136 135 mutable QVariant conflictGuard; 137 136 bool hasHadFocus, formatExplicitlySet, calendarPopup; -
trunk/src/gui/widgets/qdial.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 ** … … 60 60 #include "qaccessible.h" 61 61 #endif 62 #include <qmath.h> 62 63 63 64 QT_BEGIN_NAMESPACE … … 136 137 double yy = (double)q->height()/2.0 - p.y(); 137 138 double xx = (double)p.x() - q->width()/2.0; 138 double a = (xx || yy) ? atan2(yy, xx) : 0;139 double a = (xx || yy) ? qAtan2(yy, xx) : 0; 139 140 140 141 if (a < Q_PI / -2) … … 169 170 170 171 \ingroup basicwidgets 171 \mainclass 172 172 173 173 174 QDial is used when the user needs to control a value within a -
trunk/src/gui/widgets/qdial.h
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 ** -
trunk/src/gui/widgets/qdialogbuttonbox.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 ** … … 47 47 #include <QtGui/qapplication.h> 48 48 #include <QtGui/private/qwidget_p.h> 49 #include <QtGui/qaction.h> 49 50 50 51 #include "qdialogbuttonbox.h" 52 53 #ifdef QT_SOFTKEYS_ENABLED 54 #include <QtGui/qaction.h> 55 #endif 56 51 57 52 58 QT_BEGIN_NAMESPACE … … 58 64 layout that is appropriate to the current widget style. 59 65 60 \ingroup application61 \mainclass 66 \ingroup dialog-classes 67 62 68 63 69 Dialogs and message boxes typically present buttons in a layout that … … 255 261 }; 256 262 263 class QDialogButtonEnabledProxy : public QObject 264 { 265 public: 266 QDialogButtonEnabledProxy(QObject *parent, QWidget *src, QAction *trg) : QObject(parent), source(src), target(trg) 267 { 268 source->installEventFilter(this); 269 target->setEnabled(source->isEnabled()); 270 } 271 ~QDialogButtonEnabledProxy() 272 { 273 source->removeEventFilter(this); 274 } 275 bool eventFilter(QObject *object, QEvent *event) 276 { 277 if (object == source && event->type() == QEvent::EnabledChange) { 278 target->setEnabled(source->isEnabled()); 279 } 280 return false; 281 }; 282 private: 283 QWidget *source; 284 QAction *target; 285 }; 286 287 257 288 class QDialogButtonBoxPrivate : public QWidgetPrivate 258 289 { … … 264 295 QList<QAbstractButton *> buttonLists[QDialogButtonBox::NRoles]; 265 296 QHash<QPushButton *, QDialogButtonBox::StandardButton> standardButtonHash; 297 #ifdef QT_SOFTKEYS_ENABLED 298 QHash<QAbstractButton *, QAction *> softKeyActions; 299 #endif 266 300 267 301 Qt::Orientation orientation; … … 283 317 void retranslateStrings(); 284 318 const char *standardButtonText(QDialogButtonBox::StandardButton sbutton) const; 319 #ifdef QT_SOFTKEYS_ENABLED 320 QAction *createSoftKey(QAbstractButton *button, QDialogButtonBox::ButtonRole role); 321 #endif 285 322 }; 286 323 … … 305 342 } 306 343 307 344 int left, top, right, bottom; 308 345 setLayoutItemMargins(QStyle::SE_PushButtonLayoutItem); 309 346 getLayoutItemMargins(&left, &top, &right, &bottom); 310 347 buttonLayout->setContentsMargins(-left, -top, -right, -bottom); 311 348 … … 346 383 { 347 384 Q_Q(QDialogButtonBox); 348 const int MacGap = 36 - 8; 385 const int MacGap = 36 - 8; // 8 is the default gap between a widget and a spacer item 349 386 350 387 for (int i = buttonLayout->count() - 1; i >= 0; --i) { … … 537 574 QObject::connect(button, SIGNAL(destroyed()), q, SLOT(_q_handleButtonDestroyed())); 538 575 buttonLists[role].append(button); 576 #ifdef QT_SOFTKEYS_ENABLED 577 QAction *action = createSoftKey(button, role); 578 softKeyActions.insert(button, action); 579 new QDialogButtonEnabledProxy(action, button, action); 580 #endif 539 581 if (doLayout) 540 582 layoutButtons(); 541 583 } 584 585 #ifdef QT_SOFTKEYS_ENABLED 586 QAction* QDialogButtonBoxPrivate::createSoftKey(QAbstractButton *button, QDialogButtonBox::ButtonRole role) 587 { 588 Q_Q(QDialogButtonBox); 589 QAction::SoftKeyRole softkeyRole; 590 591 QAction *action = new QAction(button->text(), button); 592 593 switch (role) { 594 case ApplyRole: 595 case AcceptRole: 596 case YesRole: 597 case ActionRole: 598 case HelpRole: 599 softkeyRole = QAction::PositiveSoftKey; 600 break; 601 case RejectRole: 602 case DestructiveRole: 603 case NoRole: 604 case ResetRole: 605 softkeyRole = QAction::NegativeSoftKey; 606 break; 607 default: 608 break; 609 } 610 QObject::connect(action, SIGNAL(triggered()), button, SIGNAL(clicked())); 611 action->setSoftKeyRole(softkeyRole); 612 613 614 QWidget *dialog = 0; 615 QWidget *p = q; 616 while (p && !p->isWindow()) { 617 p = p->parentWidget(); 618 if ((dialog = qobject_cast<QDialog *>(p))) 619 break; 620 } 621 622 if (dialog) { 623 dialog->addAction(action); 624 } else { 625 q->addAction(action); 626 } 627 628 return action; 629 } 630 #endif 542 631 543 632 void QDialogButtonBoxPrivate::createStandardButtons(QDialogButtonBox::StandardButtons buttons) … … 632 721 QPushButton *button = it.key(); 633 722 button->setText(QDialogButtonBox::tr(buttonText)); 723 #ifdef QT_SOFTKEYS_ENABLED 724 QAction *action = softKeyActions.value(button, 0); 725 if (action) 726 action->setText(button->text()); 727 #endif 634 728 } 635 729 ++it; … … 824 918 { 825 919 Q_D(QDialogButtonBox); 920 #ifdef QT_SOFTKEYS_ENABLED 921 // Delete softkey actions as they have the buttons as parents 922 qDeleteAll(d->softKeyActions.values()); 923 d->softKeyActions.clear(); 924 #endif 826 925 // Remove the created standard buttons, they should be in the other lists, which will 827 926 // do the deletion … … 901 1000 } 902 1001 } 1002 #ifdef QT_SOFTKEYS_ENABLED 1003 QAction *action = d->softKeyActions.value(button, 0); 1004 if (action) { 1005 d->softKeyActions.remove(button); 1006 delete action; 1007 } 1008 #endif 903 1009 if (!d->internalRemove) 904 1010 button->setParent(0); … … 969 1075 { 970 1076 Q_D(QDialogButtonBox); 1077 #ifdef QT_SOFTKEYS_ENABLED 1078 // Delete softkey actions since they have the buttons as parents 1079 qDeleteAll(d->softKeyActions.values()); 1080 d->softKeyActions.clear(); 1081 #endif 971 1082 // Clear out all the old standard buttons, then recreate them. 972 1083 qDeleteAll(d->standardButtonHash.keys()); … … 1126 1237 if (!hasDefault && firstAcceptButton) 1127 1238 firstAcceptButton->setDefault(true); 1239 #ifdef QT_SOFTKEYS_ENABLED 1240 if (dialog) 1241 setFixedSize(0,0); 1242 #endif 1128 1243 }else if (event->type() == QEvent::LanguageChange) { 1129 1244 d->retranslateStrings(); 1130 1245 } 1246 #ifdef QT_SOFTKEYS_ENABLED 1247 else if (event->type() == QEvent::ParentChange) { 1248 QWidget *dialog = 0; 1249 QWidget *p = this; 1250 while (p && !p->isWindow()) { 1251 p = p->parentWidget(); 1252 if ((dialog = qobject_cast<QDialog *>(p))) 1253 break; 1254 } 1255 1256 // If the parent changes, then move the softkeys 1257 for (QHash<QAbstractButton *, QAction *>::const_iterator it = d->softKeyActions.constBegin(); 1258 it != d->softKeyActions.constEnd(); ++it) { 1259 QAction *current = it.value(); 1260 QList<QWidget *> widgets = current->associatedWidgets(); 1261 foreach (QWidget *w, widgets) 1262 w->removeAction(current); 1263 if (dialog) 1264 dialog->addAction(current); 1265 else 1266 addAction(current); 1267 } 1268 } 1269 #endif 1131 1270 1132 1271 return QWidget::event(event); -
trunk/src/gui/widgets/qdialogbuttonbox.h
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 ** -
trunk/src/gui/widgets/qdockarealayout.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 ** … … 156 156 } 157 157 158 bool QDockAreaLayoutItem::hasFixedSize(Qt::Orientation o) const 159 { 160 return perp(o, minimumSize()) == perp(o, maximumSize()); 161 } 162 158 163 bool QDockAreaLayoutItem::expansive(Qt::Orientation o) const 159 164 { … … 217 222 218 223 QDockAreaLayoutInfo::QDockAreaLayoutInfo() 219 : sep(0), dockPos(QInternal::LeftDock), o(Qt::Horizontal), rect(0, 0, -1, -1),mainWindow(0)220 #ifndef QT_NO_TABBAR 221 , tabbed(false), tabBar(0), tabBarShape(QTabBar::RoundedSouth) 224 : sep(0), dockPos(QInternal::LeftDock), o(Qt::Horizontal), mainWindow(0) 225 #ifndef QT_NO_TABBAR 226 , tabbed(false), tabBar(0), tabBarShape(QTabBar::RoundedSouth), tabBarVisible(false) 222 227 #endif 223 228 { … … 227 232 Qt::Orientation _o, int tbshape, 228 233 QMainWindow *window) 229 : sep(_sep), dockPos(_dockPos), o(_o), rect(0, 0, -1, -1),mainWindow(window)230 #ifndef QT_NO_TABBAR 231 , tabbed(false), tabBar(0), tabBarShape(static_cast<QTabBar::Shape>(tbshape)) 234 : sep(_sep), dockPos(_dockPos), o(_o), mainWindow(window) 235 #ifndef QT_NO_TABBAR 236 , tabbed(false), tabBar(0), tabBarShape(static_cast<QTabBar::Shape>(tbshape)), tabBarVisible(false) 232 237 #endif 233 238 { … … 245 250 { 246 251 item_list.clear(); 247 rect = QRect( 0, 0, -1, -1);252 rect = QRect(); 248 253 #ifndef QT_NO_TABBAR 249 254 tabbed = false; … … 389 394 390 395 int a = 0, b = 0; 391 bool prev_gap = false;392 bool first = true;393 396 int min_perp = 0; 394 397 int max_perp = QWIDGETSIZE_MAX; 398 const QDockAreaLayoutItem *previous = 0; 395 399 for (int i = 0; i < item_list.size(); ++i) { 396 400 const QDockAreaLayoutItem &item = item_list.at(i); … … 410 414 #endif 411 415 { 412 if (!first && !gap && !prev_gap) 416 if (previous && !gap && !(previous->flags & QDockAreaLayoutItem::GapItem) 417 && !previous->hasFixedSize(o)) { 413 418 a += sep; 419 } 414 420 a += gap ? item.size : pick(o, size_hint); 415 421 } 416 422 b = qMax(b, perp(o, size_hint)); 417 423 418 prev_gap = gap; 419 first = false; 424 previous = &item; 420 425 } 421 426 … … 540 545 int last_index = -1; 541 546 542 bool prev_gap = false; 543 bool first = true; 547 const QDockAreaLayoutItem *previous = 0; 544 548 for (int i = 0; i < item_list.size(); ++i) { 545 549 QDockAreaLayoutItem &item = item_list[i]; … … 548 552 549 553 bool gap = item.flags & QDockAreaLayoutItem::GapItem; 550 if ( !first && !gap && !prev_gap) {551 QLayoutStruct &ls = layout_struct_list[j++];552 ls.init();553 ls.minimumSize = sep;554 ls.maximumSize =sep;555 ls.sizeHint = sep;556 ls.empty = false;554 if (previous && !gap) { 555 if (!(previous->flags & QDockAreaLayoutItem::GapItem)) { 556 QLayoutStruct &ls = layout_struct_list[j++]; 557 ls.init(); 558 ls.minimumSize = ls.maximumSize = ls.sizeHint = previous->hasFixedSize(o) ? 0 : sep; 559 ls.empty = false; 560 } 557 561 } 558 562 … … 593 597 594 598 item.flags &= ~QDockAreaLayoutItem::KeepSize; 595 prev_gap = gap; 596 first = false; 599 previous = &item; 597 600 } 598 601 layout_struct_list.resize(j); … … 608 611 609 612 j = 0; 610 prev_gap = false;611 first = true;613 bool prev_gap = false; 614 bool first = true; 612 615 for (int i = 0; i < item_list.size(); ++i) { 613 616 QDockAreaLayoutItem &item = item_list[i]; … … 922 925 } 923 926 924 int QDockAreaLayoutInfo::separatorMove(int index, int delta , QVector<QLayoutStruct> *cache)927 int QDockAreaLayoutInfo::separatorMove(int index, int delta) 925 928 { 926 929 #ifndef QT_NO_TABBAR … … 928 931 #endif 929 932 930 if (cache->isEmpty()) { 931 QVector<QLayoutStruct> &list = *cache; 932 list.resize(item_list.size()); 933 for (int i = 0; i < item_list.size(); ++i) { 934 const QDockAreaLayoutItem &item = item_list.at(i); 935 QLayoutStruct &ls = list[i]; 936 Q_ASSERT(!(item.flags & QDockAreaLayoutItem::GapItem)); 937 if (item.skip()) { 938 ls.empty = true; 939 } else { 940 ls.empty = false; 941 ls.pos = item.pos; 942 ls.size = item.size; 943 ls.minimumSize = pick(o, item.minimumSize()); 944 ls.maximumSize = pick(o, item.maximumSize()); 945 } 946 } 947 } 948 949 QVector<QLayoutStruct> list = *cache; 950 951 delta = separatorMoveHelper(list, index, delta, sep); 952 953 for (int i = 0; i < item_list.size(); ++i) { 933 QVector<QLayoutStruct> list(item_list.size()); 934 for (int i = 0; i < list.size(); ++i) { 935 const QDockAreaLayoutItem &item = item_list.at(i); 936 QLayoutStruct &ls = list[i]; 937 Q_ASSERT(!(item.flags & QDockAreaLayoutItem::GapItem)); 938 if (item.skip()) { 939 ls.empty = true; 940 } else { 941 const int separatorSpace = item.hasFixedSize(o) ? 0 : sep; 942 ls.empty = false; 943 ls.pos = item.pos; 944 ls.size = item.size + separatorSpace; 945 ls.minimumSize = pick(o, item.minimumSize()) + separatorSpace; 946 ls.maximumSize = pick(o, item.maximumSize()) + separatorSpace; 947 948 } 949 } 950 951 //the separator space has been added to the size, so we pass 0 as a parameter 952 delta = separatorMoveHelper(list, index, delta, 0 /*separator*/); 953 954 for (int i = 0; i < list.size(); ++i) { 954 955 QDockAreaLayoutItem &item = item_list[i]; 955 956 if (item.skip()) 956 957 continue; 957 958 QLayoutStruct &ls = list[i]; 958 item.size = ls.size; 959 const int separatorSpace = item.hasFixedSize(o) ? 0 : sep; 960 item.size = ls.size - separatorSpace; 959 961 item.pos = ls.pos; 960 961 962 if (item.subinfo != 0) { 962 963 item.subinfo->rect = itemRect(i); … … 994 995 } 995 996 996 void QDockAreaLayoutInfo::remove( QList<int>path)997 void QDockAreaLayoutInfo::remove(const QList<int> &path) 997 998 { 998 999 Q_ASSERT(!path.isEmpty()); 999 1000 1000 1001 if (path.count() > 1) { 1001 int index = path.takeFirst();1002 const int index = path.first(); 1002 1003 QDockAreaLayoutItem &item = item_list[index]; 1003 1004 Q_ASSERT(item.subinfo != 0); 1004 item.subinfo->remove(path );1005 item.subinfo->remove(path.mid(1)); 1005 1006 unnest(index); 1006 1007 } else { … … 1010 1011 } 1011 1012 1012 QLayoutItem *QDockAreaLayoutInfo::plug( QList<int>path)1013 QLayoutItem *QDockAreaLayoutInfo::plug(const QList<int> &path) 1013 1014 { 1014 1015 Q_ASSERT(!path.isEmpty()); 1015 1016 1016 int index = path. takeFirst();1017 int index = path.first(); 1017 1018 if (index < 0) 1018 1019 index = -index - 1; 1019 1020 1020 if ( !path.isEmpty()) {1021 if (path.count() > 1) { 1021 1022 const QDockAreaLayoutItem &item = item_list.at(index); 1022 1023 Q_ASSERT(item.subinfo != 0); 1023 return item.subinfo->plug(path );1024 return item.subinfo->plug(path.mid(1)); 1024 1025 } 1025 1026 … … 1059 1060 } 1060 1061 1061 QLayoutItem *QDockAreaLayoutInfo::unplug( QList<int>path)1062 QLayoutItem *QDockAreaLayoutInfo::unplug(const QList<int> &path) 1062 1063 { 1063 1064 Q_ASSERT(!path.isEmpty()); 1064 1065 1066 const int index = path.first(); 1065 1067 if (path.count() > 1) { 1066 int index = path.takeFirst();1067 1068 const QDockAreaLayoutItem &item = item_list.at(index); 1068 1069 Q_ASSERT(item.subinfo != 0); 1069 return item.subinfo->unplug(path); 1070 } 1071 1072 int index = path.first(); 1070 return item.subinfo->unplug(path.mid(1)); 1071 } 1072 1073 1073 QDockAreaLayoutItem &item = item_list[index]; 1074 1074 int prev = this->prev(index); … … 1142 1142 } 1143 1143 1144 bool QDockAreaLayoutInfo::insertGap( QList<int>path, QLayoutItem *dockWidgetItem)1144 bool QDockAreaLayoutInfo::insertGap(const QList<int> &path, QLayoutItem *dockWidgetItem) 1145 1145 { 1146 1146 Q_ASSERT(!path.isEmpty()); 1147 1147 1148 1148 bool insert_tabbed = false; 1149 int index = path. takeFirst();1149 int index = path.first(); 1150 1150 if (index < 0) { 1151 1151 insert_tabbed = true; … … 1155 1155 // dump(qDebug() << "insertGap() before:" << index << tabIndex, *this, QString()); 1156 1156 1157 if ( !path.isEmpty()) {1157 if (path.count() > 1) { 1158 1158 QDockAreaLayoutItem &item = item_list[index]; 1159 1159 … … 1168 1168 QDockAreaLayoutInfo *subinfo = item.subinfo; 1169 1169 QLayoutItem *widgetItem = item.widgetItem; 1170 QRect r = subinfo == 0 ? dockedGeometry(widgetItem->widget()) : subinfo->rect; 1170 QPlaceHolderItem *placeHolderItem = item.placeHolderItem; 1171 QRect r = subinfo == 0 ? widgetItem ? dockedGeometry(widgetItem->widget()) : placeHolderItem->topLevelRect : subinfo->rect; 1171 1172 1172 1173 Qt::Orientation opposite = o == Qt::Horizontal ? Qt::Vertical : Qt::Horizontal; … … 1177 1178 = new QDockAreaLayoutInfo(sep, dockPos, opposite, tabBarShape, mainWindow); 1178 1179 1180 //item become a new top-level 1179 1181 item.subinfo = new_info; 1180 1182 item.widgetItem = 0; 1183 item.placeHolderItem = 0; 1181 1184 1182 1185 QDockAreaLayoutItem new_item 1183 1186 = widgetItem == 0 1184 1187 ? QDockAreaLayoutItem(subinfo) 1185 : QDockAreaLayoutItem(widgetItem);1188 : widgetItem ? QDockAreaLayoutItem(widgetItem) : QDockAreaLayoutItem(placeHolderItem); 1186 1189 new_item.size = pick(opposite, r.size()); 1187 1190 new_item.pos = pick(opposite, r.topLeft()); … … 1194 1197 } 1195 1198 1196 bool result = item.subinfo->insertGap(path, dockWidgetItem); 1197 return result; 1199 return item.subinfo->insertGap(path.mid(1), dockWidgetItem); 1198 1200 } 1199 1201 … … 1295 1297 } 1296 1298 1297 QDockAreaLayoutInfo *QDockAreaLayoutInfo::info( QList<int>path)1298 { 1299 int index = path. takeFirst();1299 QDockAreaLayoutInfo *QDockAreaLayoutInfo::info(const QList<int> &path) 1300 { 1301 int index = path.first(); 1300 1302 if (index < 0) 1301 1303 index = -index - 1; 1302 1304 if (index >= item_list.count()) 1303 1305 return this; 1304 if (path. isEmpty() || item_list.at(index).subinfo == 0)1306 if (path.count() == 1 || item_list[index].subinfo == 0) 1305 1307 return this; 1306 return item_list .at(index).subinfo->info(path);1308 return item_list[index].subinfo->info(path.mid(1)); 1307 1309 } 1308 1310 … … 1335 1337 } 1336 1338 1337 QRect QDockAreaLayoutInfo::itemRect( QList<int>path) const1339 QRect QDockAreaLayoutInfo::itemRect(const QList<int> &path) const 1338 1340 { 1339 1341 Q_ASSERT(!path.isEmpty()); 1340 1342 1343 const int index = path.first(); 1341 1344 if (path.count() > 1) { 1342 const QDockAreaLayoutItem &item = item_list.at( path.takeFirst());1345 const QDockAreaLayoutItem &item = item_list.at(index); 1343 1346 Q_ASSERT(item.subinfo != 0); 1344 return item.subinfo->itemRect(path );1345 } 1346 1347 return itemRect( path.first());1347 return item.subinfo->itemRect(path.mid(1)); 1348 } 1349 1350 return itemRect(index); 1348 1351 } 1349 1352 … … 1367 1370 } 1368 1371 1369 QRect QDockAreaLayoutInfo::separatorRect( QList<int>path) const1372 QRect QDockAreaLayoutInfo::separatorRect(const QList<int> &path) const 1370 1373 { 1371 1374 Q_ASSERT(!path.isEmpty()); 1372 1375 1376 const int index = path.first(); 1373 1377 if (path.count() > 1) { 1374 const QDockAreaLayoutItem &item = item_list.at( path.takeFirst());1378 const QDockAreaLayoutItem &item = item_list.at(index); 1375 1379 Q_ASSERT(item.subinfo != 0); 1376 return item.subinfo->separatorRect(path );1377 } 1378 return separatorRect( path.first());1380 return item.subinfo->separatorRect(path.mid(1)); 1381 } 1382 return separatorRect(index); 1379 1383 } 1380 1384 … … 1409 1413 continue; 1410 1414 1411 int margin = (sep == 1? 2 : 0); 1412 if (pos >= item.pos + item.size - margin && item.pos + item.size + sep + margin > pos) { 1413 QList<int> result; 1414 result.append(i); 1415 return result; 1415 QRect sepRect = separatorRect(i); 1416 if (!sepRect.isNull() && sep == 1) 1417 sepRect.adjust(-2, -2, 2, 2); 1418 //we also make sure we don't find a separator that's not there 1419 if (sepRect.contains(_pos) && !item.hasFixedSize(o)) { 1420 return QList<int>() << i; 1416 1421 } 1417 1422 … … 1479 1484 } 1480 1485 1486 bool QDockAreaLayoutInfo::hasFixedSize() const 1487 { 1488 return perp(o, minimumSize()) == perp(o, maximumSize()); 1489 } 1490 1491 1481 1492 void QDockAreaLayoutInfo::apply(bool animate) 1482 1493 { 1483 QWidgetAnimator *widgetAnimator = mainWindowLayout()->widgetAnimator;1494 QWidgetAnimator &widgetAnimator = mainWindowLayout()->widgetAnimator; 1484 1495 1485 1496 #ifndef QT_NO_TABBAR … … 1514 1525 } 1515 1526 1516 widgetAnimator ->animate(tabBar, tab_rect, animate);1527 widgetAnimator.animate(tabBar, tab_rect, animate); 1517 1528 } 1518 1529 #endif // QT_NO_TABBAR … … 1537 1548 1538 1549 QRect geo = w->geometry(); 1539 widgetAnimator ->animate(w, r, animate);1540 if (!w->isHidden() ) {1550 widgetAnimator.animate(w, r, animate); 1551 if (!w->isHidden() && w->window()->isVisible()) { 1541 1552 QDockWidget *dw = qobject_cast<QDockWidget*>(w); 1542 1553 if (!r.isValid() && geo.right() >= 0 && geo.bottom() >= 0) { … … 1549 1560 } 1550 1561 } 1551 1562 #ifndef QT_NO_TABBAR 1552 1563 if (sep == 1) 1553 1564 updateSeparatorWidgets(); 1565 #endif //QT_NO_TABBAR 1554 1566 } 1555 1567 … … 1630 1642 break; 1631 1643 QRect r = separatorRect(i); 1632 if (clip.contains(r) )1644 if (clip.contains(r) && !item.hasFixedSize(o)) 1633 1645 paintSep(p, widget, r, o, r.contains(mouse)); 1634 1646 } … … 1695 1707 } 1696 1708 1697 QDockAreaLayoutItem &QDockAreaLayoutInfo::item( QList<int>path)1709 QDockAreaLayoutItem &QDockAreaLayoutInfo::item(const QList<int> &path) 1698 1710 { 1699 1711 Q_ASSERT(!path.isEmpty()); 1712 const int index = path.first(); 1700 1713 if (path.count() > 1) { 1701 QDockAreaLayoutItem &item = item_list[path.takeFirst()];1714 const QDockAreaLayoutItem &item = item_list[index]; 1702 1715 Q_ASSERT(item.subinfo != 0); 1703 return item.subinfo->item(path );1704 } 1705 return item_list[ path.first()];1716 return item.subinfo->item(path.mid(1)); 1717 } 1718 return item_list[index]; 1706 1719 } 1707 1720 … … 1832 1845 } 1833 1846 1834 #ifdef Q_WS_MAC1835 1847 static Qt::DockWidgetArea toDockWidgetArea(QInternal::DockPosition pos) 1836 1848 { … … 1844 1856 return Qt::NoDockWidgetArea; 1845 1857 } 1846 #endif1847 1858 1848 1859 static QRect constrainedRect(QRect rect, const QRect &desktop) … … 1961 1972 if (!testing) { 1962 1973 widget->setVisible(flags & StateFlagVisible); 1974 item_list.append(item); 1963 1975 } 1964 1976 } else { 1965 1977 int dummy; 1966 1978 stream >> item.pos >> item.size >> dummy >> dummy; 1967 // qDebug() << widget << item.pos << item.size;1968 1979 if (!testing) { 1980 item_list.append(item); 1969 1981 widget->setFloating(false); 1970 1982 widget->setVisible(flags & StateFlagVisible); 1983 emit widget->dockLocationChanged(toDockWidgetArea(dockPos)); 1971 1984 } 1972 1985 } 1973 1986 1974 if (!testing) {1975 item_list.append(item);1976 }1977 1987 } 1978 1988 } else if (nextMarker == SequenceMarker) { … … 2001 2011 setCurrentTabId(tabId(item_list.at(index))); 2002 2012 } 2003 #endif2004 2013 if (!testing && sep == 1) 2005 2014 updateSeparatorWidgets(); 2015 #endif 2006 2016 2007 2017 return true; 2008 2018 } 2009 2019 2020 #ifndef QT_NO_TABBAR 2010 2021 void QDockAreaLayoutInfo::updateSeparatorWidgets() const 2011 2022 { 2012 QDockAreaLayoutInfo *that = const_cast<QDockAreaLayoutInfo*>(this);2013 2014 2023 if (tabbed) { 2015 that->separatorWidgets.clear();2024 separatorWidgets.clear(); 2016 2025 return; 2017 2026 } … … 2041 2050 } else { 2042 2051 sepWidget = mainWindowLayout()->getSeparatorWidget(); 2043 that->separatorWidgets.append(sepWidget);2052 separatorWidgets.append(sepWidget); 2044 2053 } 2045 2054 j++; … … 2054 2063 } 2055 2064 2056 for (int k = j; k < that->separatorWidgets.size(); ++k) {2057 that->separatorWidgets[k]->hide();2058 } 2059 that->separatorWidgets.resize(j);2065 for (int k = j; k < separatorWidgets.size(); ++k) { 2066 separatorWidgets[k]->hide(); 2067 } 2068 separatorWidgets.resize(j); 2060 2069 Q_ASSERT(separatorWidgets.size() == j); 2061 2070 } 2071 #endif //QT_NO_TABBAR 2062 2072 2063 2073 #ifndef QT_NO_TABBAR … … 2069 2079 QDockAreaLayoutInfo *that = const_cast<QDockAreaLayoutInfo*>(this); 2070 2080 2071 if (t abBar == 0) {2081 if (that->tabBar == 0) { 2072 2082 that->tabBar = mainWindowLayout()->getTabBar(); 2073 2083 that->tabBar->setShape(static_cast<QTabBar::Shape>(tabBarShape)); … … 2203 2213 QSet<QWidget*> result; 2204 2214 2205 for each (QWidget *sepWidget, separatorWidgets)2206 result << sep Widget;2215 for (int i = 0; i < separatorWidgets.count(); ++i) 2216 result << separatorWidgets.at(i); 2207 2217 2208 2218 for (int i = 0; i < item_list.count(); ++i) { … … 2254 2264 */ 2255 2265 2256 QDockAreaLayout::QDockAreaLayout(QMainWindow *win) 2266 QDockAreaLayout::QDockAreaLayout(QMainWindow *win) : fallbackToSizeHints(true) 2257 2267 { 2258 2268 mainWindow = win; … … 2272 2282 = QDockAreaLayoutInfo(sep, QInternal::BottomDock, Qt::Horizontal, tabShape, win); 2273 2283 centralWidgetItem = 0; 2274 centralWidgetRect = QRect(0, 0, -1, -1); 2284 2275 2285 2276 2286 corners[Qt::TopLeftCorner] = Qt::TopDockWidgetArea; … … 2341 2351 corners[i] = static_cast<Qt::DockWidgetArea>(cornerData[i]); 2342 2352 } 2353 2354 if (!testing) 2355 fallbackToSizeHints = false; 2343 2356 } 2344 2357 … … 2443 2456 continue; 2444 2457 QRect rect = separatorRect(i); 2445 if ( sep == 1)2458 if (!rect.isNull() && sep == 1) 2446 2459 rect.adjust(-2, -2, 2, 2); 2447 if (rect.contains(pos) ) {2460 if (rect.contains(pos) && !info.hasFixedSize()) { 2448 2461 result << i; 2449 2462 break; … … 2470 2483 } 2471 2484 2472 QDockAreaLayoutInfo *QDockAreaLayout::info( QList<int>path)2485 QDockAreaLayoutInfo *QDockAreaLayout::info(const QList<int> &path) 2473 2486 { 2474 2487 Q_ASSERT(!path.isEmpty()); 2475 int index = path.takeFirst();2488 const int index = path.first(); 2476 2489 Q_ASSERT(index >= 0 && index < QInternal::DockCount); 2477 2490 2478 if (path. isEmpty())2491 if (path.count() == 1) 2479 2492 return &docks[index]; 2480 2493 2481 return docks[index].info(path );2482 } 2483 2484 const QDockAreaLayoutInfo *QDockAreaLayout::info( QList<int>path) const2494 return docks[index].info(path.mid(1)); 2495 } 2496 2497 const QDockAreaLayoutInfo *QDockAreaLayout::info(const QList<int> &path) const 2485 2498 { 2486 2499 return const_cast<QDockAreaLayout*>(this)->info(path); 2487 2500 } 2488 2501 2489 QDockAreaLayoutItem &QDockAreaLayout::item( QList<int>path)2502 QDockAreaLayoutItem &QDockAreaLayout::item(const QList<int> &path) 2490 2503 { 2491 2504 Q_ASSERT(!path.isEmpty()); 2492 int index = path.takeFirst();2505 const int index = path.first(); 2493 2506 Q_ASSERT(index >= 0 && index < QInternal::DockCount); 2494 return docks[index].item(path );2495 } 2496 2497 QRect QDockAreaLayout::itemRect( QList<int>path) const2507 return docks[index].item(path.mid(1)); 2508 } 2509 2510 QRect QDockAreaLayout::itemRect(const QList<int> &path) const 2498 2511 { 2499 2512 Q_ASSERT(!path.isEmpty()); 2500 int index = path.takeFirst();2513 const int index = path.first(); 2501 2514 Q_ASSERT(index >= 0 && index < QInternal::DockCount); 2502 return docks[index].itemRect(path );2515 return docks[index].itemRect(path.mid(1)); 2503 2516 } 2504 2517 2505 2518 QRect QDockAreaLayout::separatorRect(int index) const 2506 2519 { 2507 if (docks[index].isEmpty()) 2520 const QDockAreaLayoutInfo &dock = docks[index]; 2521 if (dock.isEmpty()) 2508 2522 return QRect(); 2509 QRect r = dock s[index].rect;2523 QRect r = dock.rect; 2510 2524 switch (index) { 2511 2525 case QInternal::LeftDock: … … 2523 2537 } 2524 2538 2525 QRect QDockAreaLayout::separatorRect( QList<int>path) const2539 QRect QDockAreaLayout::separatorRect(const QList<int> &path) const 2526 2540 { 2527 2541 Q_ASSERT(!path.isEmpty()); 2528 2542 2529 int index = path.takeFirst();2543 const int index = path.first(); 2530 2544 Q_ASSERT(index >= 0 && index < QInternal::DockCount); 2531 2545 2532 if (path. isEmpty())2546 if (path.count() == 1) 2533 2547 return separatorRect(index); 2534 2548 else 2535 return docks[index].separatorRect(path );2536 } 2537 2538 bool QDockAreaLayout::insertGap( QList<int>path, QLayoutItem *dockWidgetItem)2549 return docks[index].separatorRect(path.mid(1)); 2550 } 2551 2552 bool QDockAreaLayout::insertGap(const QList<int> &path, QLayoutItem *dockWidgetItem) 2539 2553 { 2540 2554 Q_ASSERT(!path.isEmpty()); 2541 int index = path.takeFirst();2555 const int index = path.first(); 2542 2556 Q_ASSERT(index >= 0 && index < QInternal::DockCount); 2543 return docks[index].insertGap(path , dockWidgetItem);2544 } 2545 2546 QLayoutItem *QDockAreaLayout::plug( QList<int>path)2557 return docks[index].insertGap(path.mid(1), dockWidgetItem); 2558 } 2559 2560 QLayoutItem *QDockAreaLayout::plug(const QList<int> &path) 2547 2561 { 2548 2562 Q_ASSERT(!path.isEmpty()); 2549 int index = path.takeFirst();2563 const int index = path.first(); 2550 2564 Q_ASSERT(index >= 0 && index < QInternal::DockCount); 2551 return docks[index].plug(path );2552 } 2553 2554 QLayoutItem *QDockAreaLayout::unplug( QList<int>path)2565 return docks[index].plug(path.mid(1)); 2566 } 2567 2568 QLayoutItem *QDockAreaLayout::unplug(const QList<int> &path) 2555 2569 { 2556 2570 Q_ASSERT(!path.isEmpty()); 2557 int index = path.takeFirst();2571 const int index = path.first(); 2558 2572 Q_ASSERT(index >= 0 && index < QInternal::DockCount); 2559 return docks[index].unplug(path );2560 } 2561 2562 void QDockAreaLayout::remove( QList<int>path)2573 return docks[index].unplug(path.mid(1)); 2574 } 2575 2576 void QDockAreaLayout::remove(const QList<int> &path) 2563 2577 { 2564 2578 Q_ASSERT(!path.isEmpty()); 2565 int index = path.takeFirst();2579 const int index = path.first(); 2566 2580 Q_ASSERT(index >= 0 && index < QInternal::DockCount); 2567 docks[index].remove(path );2581 docks[index].remove(path.mid(1)); 2568 2582 } 2569 2583 … … 2576 2590 QSize center_hint(0, 0); 2577 2591 QSize center_min(0, 0); 2578 bool have_central = centralWidgetItem != 0 && !centralWidgetItem->isEmpty();2592 const bool have_central = centralWidgetItem != 0 && !centralWidgetItem->isEmpty(); 2579 2593 if (have_central) { 2580 2594 center_hint = centralWidgetRect.size(); … … 2595 2609 2596 2610 QSize left_hint = docks[QInternal::LeftDock].size(); 2597 if ( !left_hint.isValid())2611 if (left_hint.isNull() || fallbackToSizeHints) 2598 2612 left_hint = docks[QInternal::LeftDock].sizeHint(); 2599 2613 QSize left_min = docks[QInternal::LeftDock].minimumSize(); … … 2602 2616 2603 2617 QSize right_hint = docks[QInternal::RightDock].size(); 2604 if ( !right_hint.isValid())2618 if (right_hint.isNull() || fallbackToSizeHints) 2605 2619 right_hint = docks[QInternal::RightDock].sizeHint(); 2606 2620 QSize right_min = docks[QInternal::RightDock].minimumSize(); … … 2609 2623 2610 2624 QSize top_hint = docks[QInternal::TopDock].size(); 2611 if ( !top_hint.isValid())2625 if (top_hint.isNull() || fallbackToSizeHints) 2612 2626 top_hint = docks[QInternal::TopDock].sizeHint(); 2613 2627 QSize top_min = docks[QInternal::TopDock].minimumSize(); … … 2616 2630 2617 2631 QSize bottom_hint = docks[QInternal::BottomDock].size(); 2618 if ( !bottom_hint.isValid())2632 if (bottom_hint.isNull() || fallbackToSizeHints) 2619 2633 bottom_hint = docks[QInternal::BottomDock].sizeHint(); 2620 2634 QSize bottom_min = docks[QInternal::BottomDock].minimumSize(); 2621 2635 QSize bottom_max = docks[QInternal::BottomDock].maximumSize(); 2622 2636 bottom_hint = bottom_hint.boundedTo(bottom_max).expandedTo(bottom_min); 2637 2638 fallbackToSizeHints = !have_central; 2623 2639 2624 2640 if (_ver_struct_list != 0) { … … 2855 2871 docks[i].clear(); 2856 2872 2857 rect = QRect( 0, 0, -1, -1);2858 centralWidgetRect = QRect( 0, 0, -1, -1);2873 rect = QRect(); 2874 centralWidgetRect = QRect(); 2859 2875 } 2860 2876 … … 3058 3074 void QDockAreaLayout::apply(bool animate) 3059 3075 { 3060 QWidgetAnimator *widgetAnimator3076 QWidgetAnimator &widgetAnimator 3061 3077 = qobject_cast<QMainWindowLayout*>(mainWindow->layout())->widgetAnimator; 3062 3078 … … 3064 3080 docks[i].apply(animate); 3065 3081 if (centralWidgetItem != 0 && !centralWidgetItem->isEmpty()) { 3066 widgetAnimator ->animate(centralWidgetItem->widget(), centralWidgetRect,3082 widgetAnimator.animate(centralWidgetItem->widget(), centralWidgetRect, 3067 3083 animate); 3068 3084 } 3069 3085 #ifndef QT_NO_TABBAR 3070 3086 if (sep == 1) 3071 3087 updateSeparatorWidgets(); 3088 #endif //QT_NO_TABBAR 3072 3089 } 3073 3090 … … 3081 3098 continue; 3082 3099 QRect r = separatorRect(i); 3083 if (clip.contains(r) ) {3100 if (clip.contains(r) && !dock.hasFixedSize()) { 3084 3101 Qt::Orientation opposite = dock.o == Qt::Horizontal 3085 3102 ? Qt::Vertical : Qt::Horizontal; … … 3106 3123 } 3107 3124 3108 int QDockAreaLayout::separatorMove(QList<int> separator, const QPoint &origin, 3109 const QPoint &dest, 3110 QVector<QLayoutStruct> *cache) 3125 int QDockAreaLayout::separatorMove(const QList<int> &separator, const QPoint &origin, 3126 const QPoint &dest) 3111 3127 { 3112 3128 int delta = 0; … … 3117 3133 delta = pick(info->o, dest - origin); 3118 3134 if (delta != 0) 3119 delta = info->separatorMove(index, delta , cache);3135 delta = info->separatorMove(index, delta); 3120 3136 info->apply(false); 3121 3137 return delta; 3122 3138 } 3123 3139 3124 if (cache->isEmpty()) { 3125 QVector<QLayoutStruct> &list = *cache; 3126 3127 if (index == QInternal::LeftDock || index == QInternal::RightDock) 3128 getGrid(0, &list); 3129 else 3130 getGrid(&list, 0); 3131 } 3132 3133 QVector<QLayoutStruct> list = *cache; 3140 QVector<QLayoutStruct> list; 3141 3142 if (index == QInternal::LeftDock || index == QInternal::RightDock) 3143 getGrid(0, &list); 3144 else 3145 getGrid(&list, 0); 3146 3134 3147 int sep_index = index == QInternal::LeftDock || index == QInternal::TopDock 3135 3148 ? 0 : 1; … … 3151 3164 } 3152 3165 3166 #ifndef QT_NO_TABBAR 3153 3167 // Sets the correct positions for the seperator widgets 3154 3168 // Allocates new sepearator widgets with getSeparatorWidget 3155 3169 void QDockAreaLayout::updateSeparatorWidgets() const 3156 3170 { 3157 QDockAreaLayout *that = const_cast<QDockAreaLayout*>(this);3158 3159 3171 int j = 0; 3160 3172 … … 3169 3181 } else { 3170 3182 sepWidget = qobject_cast<QMainWindowLayout*>(mainWindow->layout())->getSeparatorWidget(); 3171 that->separatorWidgets.append(sepWidget);3183 separatorWidgets.append(sepWidget); 3172 3184 } 3173 3185 j++; … … 3184 3196 separatorWidgets.at(i)->hide(); 3185 3197 3186 that->separatorWidgets.resize(j); 3187 } 3198 separatorWidgets.resize(j); 3199 } 3200 #endif //QT_NO_TABBAR 3188 3201 3189 3202 QLayoutItem *QDockAreaLayout::itemAt(int *x, int index) const … … 3238 3251 return result; 3239 3252 } 3240 #endif3241 3253 3242 3254 // Returns the set of all used separator widgets … … 3245 3257 QSet<QWidget*> result; 3246 3258 3247 for each (QWidget *sepWidget, separatorWidgets)3248 result << sep Widget;3259 for (int i = 0; i < separatorWidgets.count(); ++i) 3260 result << separatorWidgets.at(i); 3249 3261 for (int i = 0; i < QInternal::DockCount; ++i) { 3250 3262 const QDockAreaLayoutInfo &dock = docks[i]; … … 3253 3265 return result; 3254 3266 } 3255 3256 QRect QDockAreaLayout::gapRect(QList<int> path) const 3267 #endif 3268 3269 QRect QDockAreaLayout::gapRect(const QList<int> &path) const 3257 3270 { 3258 3271 const QDockAreaLayoutInfo *info = this->info(path); -
trunk/src/gui/widgets/qdockarealayout_p.h
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 ** … … 104 104 QSize sizeHint() const; 105 105 bool expansive(Qt::Orientation o) const; 106 bool hasFixedSize(Qt::Orientation o) const; 106 107 107 108 QLayoutItem *widgetItem; … … 136 137 QSize size() const; 137 138 138 bool insertGap( QList<int>path, QLayoutItem *dockWidgetItem);139 QLayoutItem *plug( QList<int>path);140 QLayoutItem *unplug( QList<int>path);139 bool insertGap(const QList<int> &path, QLayoutItem *dockWidgetItem); 140 QLayoutItem *plug(const QList<int> &path); 141 QLayoutItem *unplug(const QList<int> &path); 141 142 enum TabMode { NoTabs, AllowTabs, ForceTabs }; 142 143 QList<int> gapIndex(const QPoint &pos, bool nestingEnabled, 143 144 TabMode tabMode) const; 144 void remove( QList<int>path);145 void remove(const QList<int> &path); 145 146 void unnest(int index); 146 147 void split(int index, Qt::Orientation orientation, QLayoutItem *dockWidgetItem); 147 148 void tab(int index, QLayoutItem *dockWidgetItem); 148 QDockAreaLayoutItem &item( QList<int>path);149 QDockAreaLayoutInfo *info( QList<int>path);149 QDockAreaLayoutItem &item(const QList<int> &path); 150 QDockAreaLayoutInfo *info(const QList<int> &path); 150 151 QDockAreaLayoutInfo *info(QWidget *widget); 151 152 … … 162 163 int changeSize(int index, int size, bool below); 163 164 QRect itemRect(int index) const; 164 QRect itemRect( QList<int>path) const;165 QRect itemRect(const QList<int> &path) const; 165 166 QRect separatorRect(int index) const; 166 QRect separatorRect( QList<int>path) const;167 QRect separatorRect(const QList<int> &path) const; 167 168 168 169 void clear(); 169 170 bool isEmpty() const; 171 bool hasFixedSize() const; 170 172 QList<int> findSeparator(const QPoint &pos) const; 171 173 int next(int idx) const; … … 180 182 const QPoint &mouse) const; 181 183 QRegion separatorRegion() const; 182 int separatorMove(int index, int delta , QVector<QLayoutStruct> *cache);184 int separatorMove(int index, int delta); 183 185 184 186 QLayoutItem *itemAt(int *x, int index) const; … … 189 191 190 192 int sep; 191 QVector<QWidget*> separatorWidgets;193 mutable QVector<QWidget*> separatorWidgets; 192 194 QInternal::DockPosition dockPos; 193 195 Qt::Orientation o; … … 195 197 QMainWindow *mainWindow; 196 198 QList<QDockAreaLayoutItem> item_list; 197 199 #ifndef QT_NO_TABBAR 198 200 void updateSeparatorWidgets() const; 199 201 QSet<QWidget*> usedSeparatorWidgets() const; 202 #endif //QT_NO_TABBAR 200 203 201 204 #ifndef QT_NO_TABBAR … … 232 235 QDockAreaLayoutInfo docks[4]; 233 236 int sep; // separator extent 234 QVector<QWidget*> separatorWidgets; 237 bool fallbackToSizeHints; //determines if we should use the sizehint for the dock areas (true until the layout is restored or the central widget is set) 238 mutable QVector<QWidget*> separatorWidgets; 235 239 236 240 bool isValid() const; … … 245 249 QList<int> findSeparator(const QPoint &pos) const; 246 250 247 QDockAreaLayoutItem &item( QList<int>path);248 QDockAreaLayoutInfo *info( QList<int>path);249 const QDockAreaLayoutInfo *info( QList<int>path) const;251 QDockAreaLayoutItem &item(const QList<int> &path); 252 QDockAreaLayoutInfo *info(const QList<int> &path); 253 const QDockAreaLayoutInfo *info(const QList<int> &path) const; 250 254 QDockAreaLayoutInfo *info(QWidget *widget); 251 QRect itemRect( QList<int>path) const;255 QRect itemRect(const QList<int> &path) const; 252 256 QRect separatorRect(int index) const; 253 QRect separatorRect( QList<int>path) const;254 255 bool insertGap( QList<int>path, QLayoutItem *dockWidgetItem);256 QLayoutItem *plug( QList<int>path);257 QLayoutItem *unplug( QList<int>path);258 void remove( QList<int>path);257 QRect separatorRect(const QList<int> &path) const; 258 259 bool insertGap(const QList<int> &path, QLayoutItem *dockWidgetItem); 260 QLayoutItem *plug(const QList<int> &path); 261 QLayoutItem *unplug(const QList<int> &path); 262 void remove(const QList<int> &path); 259 263 260 264 void fitLayout(); … … 276 280 const QPoint &mouse) const; 277 281 QRegion separatorRegion() const; 278 int separatorMove( QList<int> separator, const QPoint &origin, const QPoint &dest,279 QVector<QLayoutStruct> *cache); 282 int separatorMove(const QList<int> &separator, const QPoint &origin, const QPoint &dest); 283 #ifndef QT_NO_TABBAR 280 284 void updateSeparatorWidgets() const; 285 #endif //QT_NO_TABBAR 281 286 282 287 QLayoutItem *itemAt(int *x, int index) const; … … 289 294 QVector<QLayoutStruct> *hor_struct_list); 290 295 291 QRect gapRect( QList<int>path) const;296 QRect gapRect(const QList<int> &path) const; 292 297 293 298 void keepSize(QDockWidget *w); 294 299 #ifndef QT_NO_TABBAR 295 300 QSet<QTabBar*> usedTabBars() const; 296 301 QSet<QWidget*> usedSeparatorWidgets() const; 302 #endif //QT_NO_TABBAR 297 303 }; 298 304 -
trunk/src/gui/widgets/qdockwidget.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 ** … … 60 60 #include "qmainwindowlayout_p.h" 61 61 #ifdef Q_WS_MAC 62 #include <private/qapplication_p.h> 62 63 #include <private/qt_mac_p.h> 63 64 #include <qmacstyle_mac.h> … … 68 69 extern QString qt_setWindowTitle_helperHelper(const QString&, const QWidget*); // qwidget.cpp 69 70 70 extern QHash<QByteArray, QFont> *qt_app_fonts_hash(); // qapplication.cpp 71 static inline bool hasFeature(const QDockWidgetPrivate *priv, QDockWidget::DockWidgetFeature feature) 72 { return (priv->features & feature) == feature; } 71 73 72 74 static inline bool hasFeature(const QDockWidget *dockwidget, QDockWidget::DockWidgetFeature feature) … … 204 206 bool QDockWidgetLayout::nativeWindowDeco(bool floating) const 205 207 { 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) 207 209 Q_UNUSED(floating); 208 210 return false; … … 222 224 { 223 225 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); 225 228 if (item == 0) 226 229 continue; … … 251 254 { 252 255 int result = 0; 253 for each (QLayoutItem *item, item_list) {254 if (item != 0)256 for (int i = 0; i < item_list.count(); ++i) { 257 if (item_list.at(i)) 255 258 ++result; 256 259 } … … 454 457 int mw = q->style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, 0, q); 455 458 456 return qMax(buttonHeight + 2, titleFontMetrics. lineSpacing() + 2*mw);459 return qMax(buttonHeight + 2, titleFontMetrics.height() + 2*mw); 457 460 } 458 461 … … 647 650 { 648 651 Q_Q(QDockWidget); 649 QDockWidgetLayout * layout = qobject_cast<QDockWidgetLayout*>(q->layout());652 QDockWidgetLayout *dwLayout = qobject_cast<QDockWidgetLayout*>(layout); 650 653 651 654 QStyleOptionDockWidget opt; 652 655 q->initStyleOption(&opt); 653 656 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(); 656 659 bool hideButtons = nativeDeco || customTitleBar; 657 660 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); 660 663 661 664 QAbstractButton *button 662 = qobject_cast<QAbstractButton*>( layout->widgetForRole(QDockWidgetLayout::FloatButton));665 = qobject_cast<QAbstractButton*>(dwLayout->widgetForRole(QDockWidgetLayout::FloatButton)); 663 666 button->setIcon(q->style()->standardIcon(QStyle::SP_TitleBarNormalButton, &opt, q)); 664 667 button->setVisible(canFloat && !hideButtons); 665 668 666 669 button 667 = qobject_cast <QAbstractButton*>( layout->widgetForRole(QDockWidgetLayout::CloseButton));670 = qobject_cast <QAbstractButton*>(dwLayout->widgetForRole(QDockWidgetLayout::CloseButton)); 668 671 button->setIcon(q->style()->standardIcon(QStyle::SP_TitleBarCloseButton, &opt, q)); 669 672 button->setVisible(canClose && !hideButtons); … … 683 686 void QDockWidgetPrivate::initDrag(const QPoint &pos, bool nca) 684 687 { 685 Q_Q(QDockWidget);686 687 688 if (state != 0) 688 689 return; 689 690 690 QMainWindow *win = qobject_cast<QMainWindow*>( q->parentWidget());691 QMainWindow *win = qobject_cast<QMainWindow*>(parent); 691 692 Q_ASSERT(win != 0); 692 693 QMainWindowLayout *layout = qobject_cast<QMainWindowLayout*>(win->layout()); 693 694 Q_ASSERT(layout != 0); 694 if (layout->layoutState.indexOf(q).isEmpty()) //The dock widget has not been added into the main window695 return;696 695 if (layout->pluggingWidget != 0) // the main window is animating a docking operation 697 696 return; … … 741 740 742 741 if (state->dragging) { 743 QMainWindowLayout * layout =742 QMainWindowLayout *mwLayout = 744 743 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)) { 749 748 if (state->ownWidgetItem) 750 749 delete state->widgetItem; 751 layout->restore();750 mwLayout->restore(); 752 751 #ifdef Q_WS_X11 753 752 // get rid of the X11BypassWindowManager window flag and activate the resizer … … 759 758 #else 760 759 QDockWidgetLayout *myLayout 761 = qobject_cast<QDockWidgetLayout*>( q->layout());760 = qobject_cast<QDockWidgetLayout*>(layout); 762 761 resizer->setActive(QWidgetResizeHandler::Resize, 763 762 myLayout->widgetForRole(QDockWidgetLayout::TitleBar) != 0); … … 766 765 q->activateWindow(); 767 766 } else { 768 layout->revert(state->widgetItem);767 mwLayout->revert(state->widgetItem); 769 768 } 770 769 } … … 778 777 Q_Q(const QDockWidget); 779 778 780 QMainWindow *mainWin = qobject_cast<QMainWindow*>( q->parentWidget());779 QMainWindow *mainWin = qobject_cast<QMainWindow*>(parent); 781 780 if (mainWin == 0) 782 781 return false; … … 795 794 Q_Q(QDockWidget); 796 795 797 QDockWidgetLayout * layout798 = 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(); 802 801 803 802 if (event->button() != Qt::LeftButton || … … 805 804 // check if the tool window is movable... do nothing if it 806 805 // 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 || 809 808 isAnimating() || state != 0) { 810 809 return false; … … 814 813 815 814 if (state) 816 state->ctrlDrag = hasFeature( q, QDockWidget::DockWidgetFloatable) && event->modifiers() & Qt::ControlModifier;815 state->ctrlDrag = hasFeature(this, QDockWidget::DockWidgetFloatable) && event->modifiers() & Qt::ControlModifier; 817 816 818 817 return true; … … 825 824 bool QDockWidgetPrivate::mouseDoubleClickEvent(QMouseEvent *event) 826 825 { 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(); 833 830 834 831 if (event->button() == Qt::LeftButton && titleArea.contains(event->pos()) && 835 hasFeature( q, QDockWidget::DockWidgetFloatable)) {832 hasFeature(this, QDockWidget::DockWidgetFloatable)) { 836 833 _q_toggleTopLevel(); 837 834 return true; … … 851 848 852 849 QDockWidgetLayout *dwlayout 853 = qobject_cast<QDockWidgetLayout*>( q->layout());850 = qobject_cast<QDockWidgetLayout*>(layout); 854 851 QMainWindowLayout *mwlayout 855 852 = qobject_cast<QMainWindowLayout*>(q->parentWidget()->layout()); … … 924 921 if (state != 0) 925 922 break; 926 if (qobject_cast<QMainWindow*>( q->parentWidget()) == 0)923 if (qobject_cast<QMainWindow*>(parent) == 0) 927 924 break; 928 925 if (isAnimating()) … … 997 994 QRect r = rect; 998 995 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); 1002 999 setWindowState(true, true, r); 1003 1000 } … … 1011 1008 { 1012 1009 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 } 1013 1016 1014 1017 bool wasFloating = q->isFloating(); … … 1020 1023 Qt::WindowFlags flags = floating ? Qt::Tool : Qt::Widget; 1021 1024 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); 1024 1027 1025 1028 if (nativeDeco) { 1026 1029 flags |= Qt::CustomizeWindowHint | Qt::WindowTitleHint; 1027 if (hasFeature( q, QDockWidget::DockWidgetClosable))1030 if (hasFeature(this, QDockWidget::DockWidgetClosable)) 1028 1031 flags |= Qt::WindowCloseButtonHint; 1029 1032 } else { … … 1052 1055 if (floating != wasFloating) { 1053 1056 emit q->topLevelChanged(floating); 1054 if (!floating && q->parentWidget()) {1057 if (!floating && parent) { 1055 1058 QMainWindowLayout *mwlayout = qobject_cast<QMainWindowLayout *>(q->parentWidget()->layout()); 1056 1059 if (mwlayout) … … 1069 1072 desktop. 1070 1073 1071 \ingroup application1074 \ingroup mainwindow-classes 1072 1075 1073 1076 QDockWidget provides the concept of dock widgets, also know as … … 1136 1139 /*! 1137 1140 \property QDockWidget::windowTitle 1138 \ internal1141 \brief the dock widget title (caption) 1139 1142 1140 1143 By default, this property contains an empty string. … … 1223 1226 if (d->features == features) 1224 1227 return; 1228 const bool closableChanged = (d->features ^ features) & DockWidgetClosable; 1225 1229 d->features = features; 1226 1230 QDockWidgetLayout *layout … … 1231 1235 emit featuresChanged(d->features); 1232 1236 update(); 1237 if (closableChanged && layout->nativeWindowDeco()) { 1238 //this ensures the native decoration is drawn 1239 d->setWindowState(true /*floating*/, true /*unplug*/); 1240 } 1233 1241 } 1234 1242 … … 1322 1330 if (QMainWindowLayout *winLayout = 1323 1331 (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)) 1326 1333 info->updateTabBar(); 1327 1334 } … … 1391 1398 case QEvent::Show: 1392 1399 d->toggleViewAction->setChecked(true); 1393 emit visibilityChanged( true);1400 emit visibilityChanged(geometry().right() >= 0 && geometry().bottom() >= 0); 1394 1401 break; 1395 1402 #endif -
trunk/src/gui/widgets/qdockwidget.h
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 ** -
trunk/src/gui/widgets/qdockwidget_p.h
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 ** -
trunk/src/gui/widgets/qeffects.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 ** … … 127 127 QAlphaWidget::~QAlphaWidget() 128 128 { 129 #if def Q_WS_WIN129 #if defined(Q_WS_WIN) && !defined(Q_WS_WINCE) 130 130 // Restore user-defined opacity value 131 if (widget && QSysInfo::WindowsVersion >= QSysInfo::WV_2000 && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based)131 if (widget) 132 132 widget->setWindowOpacity(windowOpacity); 133 133 #endif … … 161 161 162 162 showWidget = true; 163 #if defined(Q_OS_WIN) 164 if (QSysInfo::WindowsVersion >= QSysInfo::WV_2000 && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based) { 165 qApp->installEventFilter(this); 166 widget->setWindowOpacity(0.0); 167 widget->show(); 163 #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) 164 qApp->installEventFilter(this); 165 widget->setWindowOpacity(0.0); 166 widget->show(); 167 connect(&anim, SIGNAL(timeout()), this, SLOT(render())); 168 anim.start(1); 169 #else 170 //This is roughly equivalent to calling setVisible(true) without actually showing the widget 171 widget->setAttribute(Qt::WA_WState_ExplicitShowHide, true); 172 widget->setAttribute(Qt::WA_WState_Hidden, false); 173 174 qApp->installEventFilter(this); 175 176 move(widget->geometry().x(),widget->geometry().y()); 177 resize(widget->size().width(), widget->size().height()); 178 179 frontImage = QPixmap::grabWidget(widget).toImage(); 180 backImage = QPixmap::grabWindow(QApplication::desktop()->winId(), 181 widget->geometry().x(), widget->geometry().y(), 182 widget->geometry().width(), widget->geometry().height()).toImage(); 183 184 if (!backImage.isNull() && checkTime.elapsed() < duration / 2) { 185 mixedImage = backImage.copy(); 186 pm = QPixmap::fromImage(mixedImage); 187 show(); 188 setEnabled(false); 189 168 190 connect(&anim, SIGNAL(timeout()), this, SLOT(render())); 169 191 anim.start(1); 170 } else 192 } else { 193 duration = 0; 194 render(); 195 } 171 196 #endif 172 {173 //This is roughly equivalent to calling setVisible(true) without actually showing the widget174 widget->setAttribute(Qt::WA_WState_ExplicitShowHide, true);175 widget->setAttribute(Qt::WA_WState_Hidden, false);176 177 qApp->installEventFilter(this);178 179 move(widget->geometry().x(),widget->geometry().y());180 resize(widget->size().width(), widget->size().height());181 182 frontImage = QPixmap::grabWidget(widget).toImage();183 backImage = QPixmap::grabWindow(QApplication::desktop()->winId(),184 widget->geometry().x(), widget->geometry().y(),185 widget->geometry().width(), widget->geometry().height()).toImage();186 187 if (!backImage.isNull() && checkTime.elapsed() < duration / 2) {188 mixedImage = backImage.copy();189 pm = QPixmap::fromImage(mixedImage);190 show();191 setEnabled(false);192 193 connect(&anim, SIGNAL(timeout()), this, SLOT(render()));194 anim.start(1);195 } else {196 duration = 0;197 render();198 }199 }200 197 } 201 198 … … 271 268 alpha = 1; 272 269 273 #if defined(Q_OS_WIN) 274 if (QSysInfo::WindowsVersion >= QSysInfo::WV_2000 && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based) { 275 if (alpha >= windowOpacity || !showWidget) { 276 anim.stop(); 277 qApp->removeEventFilter(this); 278 widget->setWindowOpacity(windowOpacity); 279 q_blend = 0; 280 deleteLater(); 281 } else { 282 widget->setWindowOpacity(alpha); 283 } 284 } else 285 #endif 270 #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) 271 if (alpha >= windowOpacity || !showWidget) { 272 anim.stop(); 273 qApp->removeEventFilter(this); 274 widget->setWindowOpacity(windowOpacity); 275 q_blend = 0; 276 deleteLater(); 277 } else { 278 widget->setWindowOpacity(alpha); 279 } 280 #else 286 281 if (alpha >= 1 || !showWidget) { 287 282 anim.stop(); … … 293 288 setEnabled(true); 294 289 setFocus(); 295 #endif 290 #endif // Q_WS_WIN 296 291 widget->hide(); 297 292 } else { … … 310 305 repaint(); 311 306 } 307 #endif // defined(Q_OS_WIN) && !defined(Q_OS_WINCE) 312 308 } 313 309 … … 589 585 return; 590 586 591 qApp->sendPostedEvents(w, QEvent::Move);592 qApp->sendPostedEvents(w, QEvent::Resize);587 QApplication::sendPostedEvents(w, QEvent::Move); 588 QApplication::sendPostedEvents(w, QEvent::Resize); 593 589 Qt::WindowFlags flags = Qt::ToolTip; 594 590 … … 611 607 return; 612 608 613 qApp->sendPostedEvents(w, QEvent::Move);614 qApp->sendPostedEvents(w, QEvent::Resize);609 QApplication::sendPostedEvents(w, QEvent::Move); 610 QApplication::sendPostedEvents(w, QEvent::Resize); 615 611 616 612 Qt::WindowFlags flags = Qt::ToolTip; -
trunk/src/gui/widgets/qeffects_p.h
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 ** -
trunk/src/gui/widgets/qfocusframe.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 ** … … 119 119 120 120 \ingroup basicwidgets 121 \mainclass 121 122 122 123 123 Normally an application will not need to create its own -
trunk/src/gui/widgets/qfocusframe.h
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 ** -
trunk/src/gui/widgets/qfontcombobox.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 ** … … 195 195 font.setPointSize(QFontInfo(font).pointSize() * 3/2); 196 196 QFontMetrics fontMetrics(font); 197 return QSize(fontMetrics.width(text), fontMetrics. lineSpacing());197 return QSize(fontMetrics.width(text), fontMetrics.height()); 198 198 } 199 199 … … 248 248 list = result; 249 249 250 //we need to block the signals so that the model doesn't emit reset 251 //this prevents the current index from changing 252 //it will be updated just after this 253 ///TODO: we should finda way to avoid blocking signals and have a real update of the model 254 const bool old = m->blockSignals(true); 250 255 m->setStringList(list); 256 m->blockSignals(old); 257 251 258 if (list.isEmpty()) { 252 259 if (currentFont != QFont()) { … … 263 270 { 264 271 Q_Q(QFontComboBox); 265 QFont newFont(text); 266 if (currentFont != newFont) { 267 currentFont = newFont; 272 if (currentFont.family() != text) { 273 currentFont.setFamily(text); 268 274 emit q->currentFontChanged(currentFont); 269 275 } … … 277 283 \since 4.2 278 284 \ingroup basicwidgets 279 \ingroup text280 285 281 286 The combobox is populated with an alphabetized list of font … … 422 427 if (font != d->currentFont) { 423 428 d->currentFont = font; 424 emit currentFontChanged(d->currentFont);425 429 d->_q_updateModel(); 430 if (d->currentFont == font) { //else the signal has already be emitted by _q_updateModel 431 emit currentFontChanged(d->currentFont); 432 } 426 433 } 427 434 } -
trunk/src/gui/widgets/qfontcombobox.h
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 ** -
trunk/src/gui/widgets/qframe.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 ** … … 60 60 frameWidth(0), 61 61 leftFrameWidth(0), rightFrameWidth(0), 62 topFrameWidth(0), bottomFrameWidth(0), 63 oldFrameStyle(QFrame::NoFrame | QFrame::Plain) 62 topFrameWidth(0), bottomFrameWidth(0) 64 63 { 65 64 } … … 75 74 76 75 \ingroup abstractwidgets 77 \mainclass 76 78 77 79 78 QMenu uses this to "raise" the menu above the surrounding … … 137 136 (useful as separator) 138 137 \value WinPanel draws a rectangular panel that can be raised or 139 sunken like those in Windows 95. Specifying this shape sets138 sunken like those in Windows 2000. Specifying this shape sets 140 139 the line width to 2 pixels. WinPanel is provided for compatibility. 141 140 For GUI style independence we recommend using StyledPanel instead. … … 334 333 update(); 335 334 d->updateFrameWidth(); 336 d->oldFrameStyle = (short)style;337 335 } 338 336 -
trunk/src/gui/widgets/qframe.h
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 ** -
trunk/src/gui/widgets/qframe_p.h
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 ** … … 59 59 QT_BEGIN_NAMESPACE 60 60 61 class Q _GUI_EXPORT QFramePrivate : public QWidgetPrivate61 class QFramePrivate : public QWidgetPrivate 62 62 { 63 63 Q_DECLARE_PUBLIC(QFrame) … … 75 75 short leftFrameWidth, rightFrameWidth; 76 76 short topFrameWidth, bottomFrameWidth; 77 short oldFrameStyle;78 77 79 78 inline void init(); -
trunk/src/gui/widgets/qgroupbox.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 ** … … 148 148 \ingroup organizers 149 149 \ingroup geomanagement 150 \ingroup appearance151 \mainclass152 150 153 151 A group box provides a frame, a title and a keyboard shortcut, and … … 432 430 Q_Q(QGroupBox); 433 431 QWidget *fw = q->focusWidget(); 434 if (!fw ) {432 if (!fw || fw == q) { 435 433 QWidget * best = 0; 436 434 QWidget * candidate = 0; … … 450 448 if (best) 451 449 fw = best; 452 else 453 if (candidate) 450 else if (candidate) 454 451 fw = candidate; 455 452 } … … 480 477 d->_q_fixFocus(fe->reason()); 481 478 } else { 482 QStyleOptionGroupBox box; 483 initStyleOption(&box); 484 QRect rect = style()->subControlRect(QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxCheckBox, this) 485 | style()->subControlRect(QStyle::CC_GroupBox, &box, QStyle::SC_GroupBoxLabel, this); 486 update(rect); 479 QWidget::focusInEvent(fe); 487 480 } 488 481 } … … 645 638 { 646 639 Q_D(QGroupBox); 647 if (d->checkable) { 648 if (d->checked != b) 649 update(); 650 bool wasToggled = (b != d->checked); 640 if (d->checkable && b != d->checked) { 641 update(); 651 642 d->checked = b; 652 if (wasToggled) { 653 d->_q_setChildrenEnabled(b); 654 emit toggled(b); 655 } 643 d->_q_setChildrenEnabled(b); 644 emit toggled(b); 656 645 } 657 646 } -
trunk/src/gui/widgets/qgroupbox.h
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 ** -
trunk/src/gui/widgets/qlabel.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 ** … … 62 62 63 63 \ingroup basicwidgets 64 \ingroup text65 \mainclass66 64 67 65 QLabel is used for displaying text or an image. No user … … 889 887 { 890 888 Q_D(QLabel); 891 d->sendControlEvent(ev); 889 if (d->control) { 890 d->sendControlEvent(ev); 891 QTextCursor cursor = d->control->textCursor(); 892 Qt::FocusReason reason = ev->reason(); 893 if (reason != Qt::ActiveWindowFocusReason 894 && reason != Qt::PopupFocusReason 895 && cursor.hasSelection()) { 896 cursor.clearSelection(); 897 d->control->setTextCursor(cursor); 898 } 899 } 900 892 901 QFrame::focusOutEvent(ev); 893 902 } … … 972 981 if (d->isTextLabel) { 973 982 QRectF lr = d->layoutRect(); 983 QStyleOption opt; 984 opt.initFrom(this); 985 #ifndef QT_NO_STYLE_STYLESHEET 986 if (QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(style)) { 987 cssStyle->styleSheetPalette(this, &opt, &opt.palette); 988 } 989 #endif 974 990 if (d->control) { 975 991 #ifndef QT_NO_SHORTCUT … … 985 1001 986 1002 QAbstractTextDocumentLayout::PaintContext context; 987 QStyleOption opt(0);988 opt.init(this);989 990 if (!isEnabled() &&style->styleHint(QStyle::SH_EtchDisabledText, &opt, this)) {991 context.palette = palette();1003 if (!isEnabled() && !d->control && 1004 // We cannot support etched for rich text controls because custom 1005 // colors and links will override the light palette 1006 style->styleHint(QStyle::SH_EtchDisabledText, &opt, this)) { 1007 context.palette = opt.palette; 992 1008 context.palette.setColor(QPalette::Text, context.palette.light().color()); 993 1009 painter.save(); … … 1000 1016 1001 1017 // Adjust the palette 1002 context.palette = palette(); 1003 #ifndef QT_NO_STYLE_STYLESHEET 1004 if (QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(style)) { 1005 cssStyle->focusPalette(this, &opt, &context.palette); 1006 } 1007 #endif 1018 context.palette = opt.palette; 1008 1019 1009 1020 if (foregroundRole() != QPalette::Text && isEnabled()) … … 1020 1031 if (d->hasShortcut) { 1021 1032 flags |= Qt::TextShowMnemonic; 1022 QStyleOption opt;1023 opt.initFrom(this);1024 1033 if (!style->styleHint(QStyle::SH_UnderlineShortcut, &opt, this)) 1025 1034 flags |= Qt::TextHideMnemonic; 1026 1035 } 1027 style->drawItemText(&painter, lr.toRect(), flags, palette(), isEnabled(), d->text, foregroundRole());1036 style->drawItemText(&painter, lr.toRect(), flags, opt.palette, isEnabled(), d->text, foregroundRole()); 1028 1037 } 1029 1038 } else … … 1162 1171 hasShortcut = false; 1163 1172 1164 if (control) { 1165 ensureTextPopulated(); 1166 // Underline the first character that follows an ampersand 1167 shortcutCursor = control->document()->find(QLatin1String("&")); 1168 if (shortcutCursor.isNull()) 1169 return; 1170 hasShortcut = true; 1171 shortcutId = q->grabShortcut(QKeySequence::mnemonic(text)); 1172 shortcutCursor.deleteChar(); // remove the ampersand 1173 shortcutCursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor); 1174 } else { 1175 if (!text.contains(QLatin1String("&"))) 1176 return; 1177 hasShortcut = true; 1178 shortcutId = q->grabShortcut(QKeySequence::mnemonic(text)); 1179 } 1173 if (!text.contains(QLatin1Char('&'))) 1174 return; 1175 hasShortcut = true; 1176 shortcutId = q->grabShortcut(QKeySequence::mnemonic(text)); 1180 1177 } 1181 1178 … … 1448 1445 #endif 1449 1446 doc->setUndoRedoEnabled(false); 1447 1448 #ifndef QT_NO_SHORTCUT 1449 if (hasShortcut) { 1450 // Underline the first character that follows an ampersand (and remove the others ampersands) 1451 int from = 0; 1452 bool found = false; 1453 QTextCursor cursor; 1454 while (!(cursor = control->document()->find((QLatin1String("&")), from)).isNull()) { 1455 cursor.deleteChar(); // remove the ampersand 1456 cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor); 1457 from = cursor.position(); 1458 if (!found && cursor.selectedText() != QLatin1String("&")) { //not a second & 1459 found = true; 1460 shortcutCursor = cursor; 1461 } 1462 } 1463 } 1464 #endif 1450 1465 } 1451 1466 } -
trunk/src/gui/widgets/qlabel.h
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 ** -
trunk/src/gui/widgets/qlabel_p.h
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 ** … … 114 114 Qt::TextFormat textformat; 115 115 mutable QTextControl *control; 116 QTextCursor shortcutCursor;116 mutable QTextCursor shortcutCursor; 117 117 Qt::TextInteractionFlags textInteractionFlags; 118 118 -
trunk/src/gui/widgets/qlcdnumber.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 ** … … 75 75 76 76 \ingroup basicwidgets 77 \mainclass 77 78 78 79 79 It can display a number in just about any size. It can display … … 86 86 87 87 QLCDNumber emits the overflow() signal when it is asked to display 88 something beyond its range. The range is set by set NumDigits(),88 something beyond its range. The range is set by setDigitCount(), 89 89 but setSmallDecimalPoint() also influences it. If the display is 90 90 set to hexadecimal, octal or binary, the integer equivalent of the … … 161 161 a too-large number or a too-long string. 162 162 163 It is never emitted by set NumDigits().163 It is never emitted by setDigitCount(). 164 164 */ 165 165 … … 346 346 constructor. 347 347 348 \sa set NumDigits(), setSmallDecimalPoint()348 \sa setDigitCount(), setSmallDecimalPoint() 349 349 */ 350 350 … … 368 368 constructor. 369 369 370 \sa set NumDigits(), setSmallDecimalPoint()370 \sa setDigitCount(), setSmallDecimalPoint() 371 371 */ 372 372 … … 388 388 The \a parent argument is passed to the QFrame constructor. 389 389 390 \sa set NumDigits(), setSmallDecimalPoint()390 \sa setDigitCount(), setSmallDecimalPoint() 391 391 */ 392 392 … … 404 404 numDigits, the base to decimal, the decimal point mode to 'small' 405 405 and the frame style to a raised box. The segmentStyle() is set to 406 \c Outline.406 \c Filled. 407 407 408 408 The \a parent argument is passed to the QFrame constructor. 409 409 410 \sa set NumDigits(), setSmallDecimalPoint()410 \sa setDigitCount(), setSmallDecimalPoint() 411 411 */ 412 412 … … 427 427 base = QLCDNumber::Dec; 428 428 smallPoint = false; 429 q->set NumDigits(ndigits);430 q->setSegmentStyle(QLCDNumber:: Outline);429 q->setDigitCount(ndigits); 430 q->setSegmentStyle(QLCDNumber::Filled); 431 431 q->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum)); 432 432 } … … 442 442 443 443 /*! 444 \deprecated 444 445 \property QLCDNumber::numDigits 446 \brief the current number of digits displayed 447 \sa digitCount 448 */ 449 450 void QLCDNumber::setNumDigits(int numDigits) 451 { 452 setDigitCount(numDigits); 453 } 454 455 /*! 456 \since 4.6 457 \property QLCDNumber::digitCount 445 458 \brief the current number of digits displayed 446 459 … … 454 467 */ 455 468 456 void QLCDNumber::setNumDigits(int numDigits) 469 /*! 470 Sets the current number of digits to \a numDigits. Must 471 be in the range 0..99. 472 */ 473 void QLCDNumber::setDigitCount(int numDigits) 457 474 { 458 475 Q_D(QLCDNumber); … … 471 488 d->digitStr.fill(QLatin1Char(' '), d->ndigits); 472 489 d->points.fill(0, d->ndigits); 473 d->digitStr[d->ndigits - 1] = QLatin1Char('0'); 490 d->digitStr[d->ndigits - 1] = QLatin1Char('0'); // "0" is the default number 474 491 } else { 475 492 bool doDisplay = d->ndigits == 0; … … 510 527 511 528 /*! 529 Returns the current number of digits. 530 */ 531 int QLCDNumber::digitCount() const 532 { 533 Q_D(const QLCDNumber); 534 return d->ndigits; 535 } 536 537 /*! 512 538 \overload 513 539 … … 515 541 otherwise returns false. 516 542 517 \sa display(), numDigits(), smallDecimalPoint()543 \sa display(), digitCount(), smallDecimalPoint() 518 544 */ 519 545 … … 531 557 otherwise returns false. 532 558 533 \sa display(), numDigits(), smallDecimalPoint()559 \sa display(), digitCount(), smallDecimalPoint() 534 560 */ 535 561 … … 757 783 QPainter p(this); 758 784 drawFrame(&p); 785 p.setRenderHint(QPainter::Antialiasing); 786 if (d->shadow) 787 p.translate(0.5, 0.5); 788 759 789 if (d->smallPoint) 760 790 d->drawString(d->digitStr, p, &d->points, false); … … 1071 1101 } 1072 1102 // End exact copy 1073 p.setPen( fgColor);1103 p.setPen(Qt::NoPen); 1074 1104 p.setBrush(fgColor); 1075 1105 p.drawPolygon(a); … … 1219 1249 \row \i \c Outline 1220 1250 \i Produces raised segments filled with the background color 1251 \row \i \c Filled 1221 1252 (this is the default). 1222 \row \i \c Filled1223 1253 \i Produces raised segments filled with the foreground color. 1224 1254 \row \i \c Flat … … 1253 1283 QSize QLCDNumber::sizeHint() const 1254 1284 { 1255 return QSize(10 + 9 * ( numDigits() + (smallDecimalPoint() ? 0 : 1)), 23);1285 return QSize(10 + 9 * (digitCount() + (smallDecimalPoint() ? 0 : 1)), 23); 1256 1286 } 1257 1287 … … 1272 1302 /*! 1273 1303 \fn int QLCDNumber::margin() const 1274 Returns the wi th of thethe margin around the contents of the widget.1304 Returns the width of the margin around the contents of the widget. 1275 1305 1276 1306 Use QWidget::getContentsMargins() instead. -
trunk/src/gui/widgets/qlcdnumber.h
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 ** … … 61 61 Q_PROPERTY(bool smallDecimalPoint READ smallDecimalPoint WRITE setSmallDecimalPoint) 62 62 Q_PROPERTY(int numDigits READ numDigits WRITE setNumDigits) 63 Q_PROPERTY(int digitCount READ digitCount WRITE setDigitCount) 63 64 Q_PROPERTY(Mode mode READ mode WRITE setMode) 64 65 Q_PROPERTY(SegmentStyle segmentStyle READ segmentStyle WRITE setSegmentStyle) … … 82 83 83 84 bool smallDecimalPoint() const; 84 85 int numDigits() const; 86 void setNumDigits(int nDigits); 85 #ifdef QT_DEPRECATED 86 QT_DEPRECATED int numDigits() const; 87 QT_DEPRECATED void setNumDigits(int nDigits); 88 #endif 89 int digitCount() const; 90 void setDigitCount(int nDigits); 87 91 88 92 bool checkOverflow(double num) const; -
trunk/src/gui/widgets/qlineedit.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 ** … … 80 80 #include "private/qshortcutmap_p.h" 81 81 #include "qkeysequence.h" 82 #define ACCEL_KEY(k) (!qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? QLatin1 String("\t") + QString(QKeySequence(k)) : QString())82 #define ACCEL_KEY(k) (!qApp->d_func()->shortcutMap.hasShortcutForKeySequence(k) ? QLatin1Char('\t') + QString(QKeySequence(k)) : QString()) 83 83 #else 84 84 #define ACCEL_KEY(k) QString() … … 87 87 #include <limits.h> 88 88 89 #define verticalMargin 190 #define horizontalMargin 291 92 89 QT_BEGIN_NAMESPACE 93 90 … … 95 92 extern void qt_mac_secure_keyboard(bool); //qapplication_mac.cpp 96 93 #endif 97 98 static inline bool shouldEnableInputMethod(QLineEdit *lineedit)99 {100 const QLineEdit::EchoMode mode = lineedit->echoMode();101 return !lineedit->isReadOnly() && (mode == QLineEdit::Normal || mode == QLineEdit::PasswordEchoOnEdit);102 }103 94 104 95 /*! … … 123 114 option->midLineWidth = 0; 124 115 option->state |= QStyle::State_Sunken; 125 if (d-> readOnly)116 if (d->control->isReadOnly()) 126 117 option->state |= QStyle::State_ReadOnly; 127 118 #ifdef QT_KEYPAD_NAVIGATION … … 138 129 139 130 \ingroup basicwidgets 140 \mainclass 131 141 132 142 133 A line edit allows the user to enter and edit a single line of … … 351 342 Q_D(QLineEdit); 352 343 setObjectName(QString::fromAscii(name)); 353 d->parseInputMask(inputMask); 354 if (d->maskData) { 355 QString ms = d->maskString(0, contents); 356 d->init(ms + d->clearString(ms.length(), d->maxLength - ms.length())); 357 d->cursor = d->nextMaskBlank(ms.length()); 358 } else { 359 d->init(contents); 360 } 344 d->init(contents); 345 d->control->setInputMask(inputMask); 346 d->control->moveCursor(d->control->nextMaskBlank(contents.length())); 361 347 } 362 348 #endif … … 389 375 { 390 376 Q_D(const QLineEdit); 391 QString res = d->text; 392 if (d->maskData) 393 res = d->stripString(d->text); 394 return (res.isNull() ? QString::fromLatin1("") : res); 377 return d->control->text(); 395 378 } 396 379 … … 398 381 { 399 382 Q_D(QLineEdit); 400 d->setText(text, -1, false); 401 #ifdef QT_KEYPAD_NAVIGATION 402 d->origText = d->text; 403 #endif 404 } 405 383 d->control->setText(text); 384 } 385 386 // ### Qt 4.7: remove this #if guard 387 #if (QT_VERSION >= 0x407000) || defined(Q_WS_MAEMO_5) 388 /*! 389 \since 4.7 390 391 \property QLineEdit::placeholderText 392 \brief the line edit's placeholder text 393 394 Setting this property makes the line edit display a grayed-out 395 placeholder text as long as the text() is empty and the widget doesn't 396 have focus. 397 398 By default, this property contains an empty string. 399 400 \sa text() 401 */ 402 QString QLineEdit::placeholderText() const 403 { 404 Q_D(const QLineEdit); 405 return d->placeholderText; 406 } 407 408 void QLineEdit::setPlaceholderText(const QString& placeholderText) 409 { 410 Q_D(QLineEdit); 411 if (d->placeholderText != placeholderText) { 412 d->placeholderText = placeholderText; 413 if (!hasFocus()) 414 update(); 415 } 416 } 417 #endif 406 418 407 419 /*! … … 422 434 { 423 435 Q_D(const QLineEdit); 424 if (d->echoMode == NoEcho) 425 return QString::fromLatin1(""); 426 QString res = d->text; 427 428 if (d->echoMode == Password || (d->echoMode == PasswordEchoOnEdit 429 && !d->passwordEchoEditing)) { 430 QStyleOptionFrameV2 opt; 431 initStyleOption(&opt); 432 res.fill(style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, &opt, this)); 433 } 434 return (res.isNull() ? QString::fromLatin1("") : res); 436 return d->control->displayText(); 435 437 } 436 438 … … 457 459 { 458 460 Q_D(const QLineEdit); 459 return d-> maxLength;461 return d->control->maxLength(); 460 462 } 461 463 … … 463 465 { 464 466 Q_D(QLineEdit); 465 if (d->maskData) 466 return; 467 d->maxLength = maxLength; 468 setText(d->text); 469 } 470 471 467 d->control->setMaxLength(maxLength); 468 } 472 469 473 470 /*! … … 537 534 { 538 535 Q_D(const QLineEdit); 539 return (EchoMode) d-> echoMode;536 return (EchoMode) d->control->echoMode(); 540 537 } 541 538 … … 543 540 { 544 541 Q_D(QLineEdit); 545 if (mode == (EchoMode)d-> echoMode)542 if (mode == (EchoMode)d->control->echoMode()) 546 543 return; 547 setAttribute(Qt::WA_InputMethodEnabled, shouldEnableInputMethod(this)); 548 d->echoMode = mode; 549 d->passwordEchoEditing = false; 550 d->updateTextLayout(); 544 Qt::InputMethodHints imHints = inputMethodHints(); 545 if (mode == Password) { 546 imHints |= Qt::ImhHiddenText; 547 } else { 548 imHints &= ~Qt::ImhHiddenText; 549 } 550 setInputMethodHints(imHints); 551 d->control->setEchoMode(mode); 551 552 update(); 552 553 #ifdef Q_WS_MAC 553 554 if (hasFocus()) 554 qt_mac_secure_keyboard( d->echoMode == Password || d->echoMode == NoEcho);555 qt_mac_secure_keyboard(mode == Password || mode == NoEcho); 555 556 #endif 556 557 } … … 568 569 { 569 570 Q_D(const QLineEdit); 570 return d-> validator;571 return d->control->validator(); 571 572 } 572 573 … … 586 587 { 587 588 Q_D(QLineEdit); 588 d-> validator = const_cast<QValidator*>(v);589 d->control->setValidator(v); 589 590 } 590 591 #endif // QT_NO_VALIDATOR … … 610 611 { 611 612 Q_D(QLineEdit); 612 if (c == d->co mpleter)613 if (c == d->control->completer()) 613 614 return; 614 if (d->co mpleter) {615 disconnect(d->co mpleter, 0, this, 0);616 d->co mpleter->setWidget(0);617 if (d->co mpleter->parent() == this)618 delete d->co mpleter;619 } 620 d->co mpleter = c;615 if (d->control->completer()) { 616 disconnect(d->control->completer(), 0, this, 0); 617 d->control->completer()->setWidget(0); 618 if (d->control->completer()->parent() == this) 619 delete d->control->completer(); 620 } 621 d->control->setCompleter(c); 621 622 if (!c) 622 623 return; … … 624 625 c->setWidget(this); 625 626 if (hasFocus()) { 626 QObject::connect(d->co mpleter, SIGNAL(activated(QString)),627 QObject::connect(d->control->completer(), SIGNAL(activated(QString)), 627 628 this, SLOT(setText(QString))); 628 QObject::connect(d->co mpleter, SIGNAL(highlighted(QString)),629 QObject::connect(d->control->completer(), SIGNAL(highlighted(QString)), 629 630 this, SLOT(_q_completionHighlighted(QString))); 630 631 } … … 639 640 { 640 641 Q_D(const QLineEdit); 641 return d->completer; 642 } 643 644 // looks for an enabled item iterating forward(dir=1)/backward(dir=-1) from the 645 // current row based. dir=0 indicates a new completion prefix was set. 646 bool QLineEditPrivate::advanceToEnabledItem(int dir) 647 { 648 int start = completer->currentRow(); 649 if (start == -1) 650 return false; 651 int i = start + dir; 652 if (dir == 0) dir = 1; 653 do { 654 if (!completer->setCurrentRow(i)) { 655 if (!completer->wrapAround()) 656 break; 657 i = i > 0 ? 0 : completer->completionCount() - 1; 658 } else { 659 QModelIndex currentIndex = completer->currentIndex(); 660 if (completer->completionModel()->flags(currentIndex) & Qt::ItemIsEnabled) 661 return true; 662 i += dir; 663 } 664 } while (i != start); 665 666 completer->setCurrentRow(start); // restore 667 return false; 668 } 669 670 void QLineEditPrivate::complete(int key) 671 { 672 if (!completer || readOnly || echoMode != QLineEdit::Normal) 673 return; 674 675 if (completer->completionMode() == QCompleter::InlineCompletion) { 676 if (key == Qt::Key_Backspace) 677 return; 678 int n = 0; 679 if (key == Qt::Key_Up || key == Qt::Key_Down) { 680 if (selend != 0 && selend != text.length()) 681 return; 682 QString prefix = hasSelectedText() ? text.left(selstart) : text; 683 if (text.compare(completer->currentCompletion(), completer->caseSensitivity()) != 0 684 || prefix.compare(completer->completionPrefix(), completer->caseSensitivity()) != 0) { 685 completer->setCompletionPrefix(prefix); 686 } else { 687 n = (key == Qt::Key_Up) ? -1 : +1; 688 } 689 } else { 690 completer->setCompletionPrefix(text); 691 } 692 if (!advanceToEnabledItem(n)) 693 return; 694 } else { 695 #ifndef QT_KEYPAD_NAVIGATION 696 if (text.isEmpty()) { 697 completer->popup()->hide(); 698 return; 699 } 700 #endif 701 completer->setCompletionPrefix(text); 702 } 703 704 completer->complete(); 705 } 706 707 void QLineEditPrivate::_q_completionHighlighted(QString newText) 708 { 709 Q_Q(QLineEdit); 710 if (completer->completionMode() != QCompleter::InlineCompletion) 711 q->setText(newText); 712 else { 713 int c = cursor; 714 q->setText(text.left(c) + newText.mid(c)); 715 q->setSelection(text.length(), c - newText.length()); 716 } 717 } 642 return d->control->completer(); 643 } 644 718 645 #endif // QT_NO_COMPLETER 719 646 … … 730 657 ensurePolished(); 731 658 QFontMetrics fm(font()); 732 int h = qMax(fm. lineSpacing(), 14) + 2*verticalMargin659 int h = qMax(fm.height(), 14) + 2*d->verticalMargin 733 660 + d->topTextMargin + d->bottomTextMargin 734 661 + d->topmargin + d->bottommargin; 735 int w = fm.width(QLatin1Char('x')) * 17 + 2* horizontalMargin662 int w = fm.width(QLatin1Char('x')) * 17 + 2*d->horizontalMargin 736 663 + d->leftTextMargin + d->rightTextMargin 737 664 + d->leftmargin + d->rightmargin; // "some" … … 754 681 ensurePolished(); 755 682 QFontMetrics fm = fontMetrics(); 756 int h = fm.height() + qMax(2* verticalMargin, fm.leading())683 int h = fm.height() + qMax(2*d->verticalMargin, fm.leading()) 757 684 + d->topmargin + d->bottommargin; 758 685 int w = fm.maxWidth() + d->leftmargin + d->rightmargin; … … 776 703 { 777 704 Q_D(const QLineEdit); 778 return d->c ursor;705 return d->control->cursorPosition(); 779 706 } 780 707 … … 782 709 { 783 710 Q_D(QLineEdit); 784 if (pos < 0) 785 pos = 0; 786 787 if (pos <= d->text.length()) 788 d->moveCursor(pos); 711 d->control->setCursorPosition(pos); 789 712 } 790 713 … … 808 731 int newMarkAnchor, int newMarkDrag) 809 732 { 810 Q_D(QLineEdit); 811 int priorState = d->undoState; 812 d->selstart = 0; 813 d->selend = d->text.length(); 814 d->removeSelectedText(); 815 d->insert(newText); 816 d->finishChange(priorState); 817 if (d->undoState > priorState) { 818 d->cursor = newPos; 819 d->selstart = qMin(newMarkAnchor, newMarkDrag); 820 d->selend = qMax(newMarkAnchor, newMarkDrag); 821 update(); 822 d->emitCursorPositionChanged(); 823 return true; 824 } 825 return false; 733 // The suggested functions above in the docs don't seem to validate, 734 // below code tries to mimic previous behaviour. 735 QString oldText = text(); 736 setText(newText); 737 if(!hasAcceptableInput()){ 738 setText(oldText); 739 return false; 740 } 741 setCursorPosition(newPos); 742 setSelection(qMin(newMarkAnchor, newMarkDrag), qAbs(newMarkAnchor - newMarkDrag)); 743 return true; 826 744 } 827 745 #endif //QT3_SUPPORT … … 864 782 { 865 783 Q_D(QLineEdit); 866 int cursor = d->cursor; 867 if (steps > 0) { 868 while(steps--) 869 cursor = d->textLayout.nextCursorPosition(cursor); 870 } else if (steps < 0) { 871 while (steps++) 872 cursor = d->textLayout.previousCursorPosition(cursor); 873 } 874 d->moveCursor(cursor, mark); 784 d->control->cursorForward(mark, steps); 875 785 } 876 786 … … 897 807 { 898 808 Q_D(QLineEdit); 899 d-> moveCursor(d->textLayout.nextCursorPosition(d->cursor, QTextLayout::SkipWords),mark);809 d->control->cursorWordForward(mark); 900 810 } 901 811 … … 910 820 { 911 821 Q_D(QLineEdit); 912 d-> moveCursor(d->textLayout.previousCursorPosition(d->cursor, QTextLayout::SkipWords),mark);822 d->control->cursorWordBackward(mark); 913 823 } 914 824 … … 925 835 { 926 836 Q_D(QLineEdit); 927 int priorState = d->undoState; 928 if (d->hasSelectedText()) { 929 d->removeSelectedText(); 930 } else if (d->cursor) { 931 --d->cursor; 932 if (d->maskData) 933 d->cursor = d->prevMaskBlank(d->cursor); 934 QChar uc = d->text.at(d->cursor); 935 if (d->cursor > 0 && uc.unicode() >= 0xdc00 && uc.unicode() < 0xe000) { 936 // second half of a surrogate, check if we have the first half as well, 937 // if yes delete both at once 938 uc = d->text.at(d->cursor - 1); 939 if (uc.unicode() >= 0xd800 && uc.unicode() < 0xdc00) { 940 d->del(true); 941 --d->cursor; 942 } 943 } 944 d->del(true); 945 } 946 d->finishChange(priorState); 837 d->control->backspace(); 947 838 } 948 839 … … 958 849 { 959 850 Q_D(QLineEdit); 960 int priorState = d->undoState; 961 if (d->hasSelectedText()) { 962 d->removeSelectedText(); 963 } else { 964 int n = d->textLayout.nextCursorPosition(d->cursor) - d->cursor; 965 while (n--) 966 d->del(); 967 } 968 d->finishChange(priorState); 851 d->control->del(); 969 852 } 970 853 … … 981 864 { 982 865 Q_D(QLineEdit); 983 d-> moveCursor(0,mark);866 d->control->home(mark); 984 867 } 985 868 … … 996 879 { 997 880 Q_D(QLineEdit); 998 d-> moveCursor(d->text.length(),mark);881 d->control->end(mark); 999 882 } 1000 883 … … 1021 904 { 1022 905 Q_D(const QLineEdit); 1023 return d-> modifiedState != d->undoState;906 return d->control->isModified(); 1024 907 } 1025 908 … … 1027 910 { 1028 911 Q_D(QLineEdit); 1029 if (modified) 1030 d->modifiedState = -1; 1031 else 1032 d->modifiedState = d->undoState; 912 d->control->setModified(modified); 1033 913 } 1034 914 … … 1058 938 { 1059 939 Q_D(const QLineEdit); 1060 return d-> hasSelectedText();940 return d->control->hasSelectedText(); 1061 941 } 1062 942 … … 1076 956 { 1077 957 Q_D(const QLineEdit); 1078 if (d->hasSelectedText()) 1079 return d->text.mid(d->selstart, d->selend - d->selstart); 1080 return QString(); 958 return d->control->selectedText(); 1081 959 } 1082 960 … … 1091 969 { 1092 970 Q_D(const QLineEdit); 1093 return d-> hasSelectedText() ? d->selstart : -1;971 return d->control->selectionStart(); 1094 972 } 1095 973 … … 1121 999 { 1122 1000 Q_D(const QLineEdit); 1123 int pos = d->xToPos(xpos + contentsRect().x() - d->hscroll + horizontalMargin); 1124 if (chr && pos < (int) d->text.length()) 1125 *chr = d->text.at(pos); 1001 int pos = d->xToPos(xpos + contentsRect().x() - d->hscroll + d->horizontalMargin); 1002 QString txt = d->control->text(); 1003 if (chr && pos < (int) txt.length()) 1004 *chr = txt.at(pos); 1126 1005 return pos; 1127 1006 … … 1134 1013 { 1135 1014 Q_D(QLineEdit); 1136 if (d-> hasSelectedText() && start && end) {1137 *start = d->selstart;1138 *end = d->selend;1015 if (d->control->hasSelectedText() && start && end) { 1016 *start = selectionStart(); 1017 *end = *start + selectedText().length(); 1139 1018 return true; 1140 1019 } … … 1154 1033 { 1155 1034 Q_D(QLineEdit); 1156 if (start < 0 || start > (int)d-> text.length()) {1035 if (start < 0 || start > (int)d->control->text().length()) { 1157 1036 qWarning("QLineEdit::setSelection: Invalid start position (%d)", start); 1158 1037 return; 1159 } else { 1160 if (length > 0) { 1161 d->selstart = start; 1162 d->selend = qMin(start + length, (int)d->text.length()); 1163 d->cursor = d->selend; 1164 } else { 1165 d->selstart = qMax(start + length, 0); 1166 d->selend = start; 1167 d->cursor = d->selstart; 1168 } 1169 } 1170 1171 if (d->hasSelectedText()){ 1038 } 1039 1040 d->control->setSelection(start, length); 1041 1042 if (d->control->hasSelectedText()){ 1172 1043 QStyleOptionFrameV2 opt; 1173 1044 initStyleOption(&opt); … … 1175 1046 d->setCursorVisible(false); 1176 1047 } 1177 1178 update();1179 d->emitCursorPositionChanged();1180 1048 } 1181 1049 … … 1193 1061 { 1194 1062 Q_D(const QLineEdit); 1195 return d-> isUndoAvailable();1063 return d->control->isUndoAvailable(); 1196 1064 } 1197 1065 … … 1209 1077 { 1210 1078 Q_D(const QLineEdit); 1211 return d-> isRedoAvailable();1079 return d->control->isRedoAvailable(); 1212 1080 } 1213 1081 … … 1245 1113 { 1246 1114 Q_D(const QLineEdit); 1247 return d-> hasAcceptableInput(d->text);1115 return d->control->hasAcceptableInput(); 1248 1116 } 1249 1117 … … 1264 1132 updateGeometry(); 1265 1133 update(); 1134 } 1135 1136 /*! 1137 \since 4.6 1138 Sets the \a margins around the text inside the frame. 1139 1140 See also textMargins(). 1141 */ 1142 void QLineEdit::setTextMargins(const QMargins &margins) 1143 { 1144 setTextMargins(margins.left(), margins.top(), margins.right(), margins.bottom()); 1266 1145 } 1267 1146 … … 1283 1162 if (bottom) 1284 1163 *bottom = d->bottomTextMargin; 1164 } 1165 1166 /*! 1167 \since 4.6 1168 Returns the widget's text margins. 1169 1170 \sa setTextMargins() 1171 */ 1172 QMargins QLineEdit::textMargins() const 1173 { 1174 Q_D(const QLineEdit); 1175 return QMargins(d->leftTextMargin, d->topTextMargin, d->rightTextMargin, d->bottomTextMargin); 1285 1176 } 1286 1177 … … 1351 1242 { 1352 1243 Q_D(const QLineEdit); 1353 return (d->maskData ? d->inputMask + QLatin1Char(';') + d->blank : QString());1244 return d->control->inputMask(); 1354 1245 } 1355 1246 … … 1357 1248 { 1358 1249 Q_D(QLineEdit); 1359 d->parseInputMask(inputMask); 1360 if (d->maskData) 1361 d->moveCursor(d->nextMaskBlank(0)); 1250 d->control->setInputMask(inputMask); 1362 1251 } 1363 1252 … … 1374 1263 { 1375 1264 Q_D(QLineEdit); 1376 d->selstart = d->selend = d->cursor = 0; 1377 d->moveCursor(d->text.length(), true); 1265 d->control->selectAll(); 1378 1266 } 1379 1267 … … 1387 1275 { 1388 1276 Q_D(QLineEdit); 1389 d->deselect(); 1390 d->finishChange(); 1277 d->control->deselect(); 1391 1278 } 1392 1279 … … 1403 1290 // q->resetInputContext(); //#### FIX ME IN QT 1404 1291 Q_D(QLineEdit); 1405 int priorState = d->undoState; 1406 d->removeSelectedText(); 1407 d->insert(newText); 1408 d->finishChange(priorState); 1292 d->control->insert(newText); 1409 1293 } 1410 1294 … … 1417 1301 { 1418 1302 Q_D(QLineEdit); 1419 int priorState = d->undoState;1420 1303 resetInputContext(); 1421 d->selstart = 0; 1422 d->selend = d->text.length(); 1423 d->removeSelectedText(); 1424 d->separate(); 1425 d->finishChange(priorState, /*update*/false, /*edited*/false); 1304 d->control->clear(); 1426 1305 } 1427 1306 … … 1436 1315 Q_D(QLineEdit); 1437 1316 resetInputContext(); 1438 d->undo(); 1439 d->finishChange(-1, true); 1317 d->control->undo(); 1440 1318 } 1441 1319 … … 1448 1326 Q_D(QLineEdit); 1449 1327 resetInputContext(); 1450 d->redo(); 1451 d->finishChange(); 1328 d->control->redo(); 1452 1329 } 1453 1330 … … 1471 1348 { 1472 1349 Q_D(const QLineEdit); 1473 return d-> readOnly;1350 return d->control->isReadOnly(); 1474 1351 } 1475 1352 … … 1477 1354 { 1478 1355 Q_D(QLineEdit); 1479 if (d-> readOnly!= enable) {1480 d-> readOnly = enable;1481 setAttribute(Qt::WA_MacShowFocusRect, ! d->readOnly);1482 setAttribute(Qt::WA_InputMethodEnabled, shouldEnableInputMethod(this));1356 if (d->control->isReadOnly() != enable) { 1357 d->control->setReadOnly(enable); 1358 setAttribute(Qt::WA_MacShowFocusRect, !enable); 1359 setAttribute(Qt::WA_InputMethodEnabled, d->shouldEnableInputMethod()); 1483 1360 #ifndef QT_NO_CURSOR 1484 1361 setCursor(enable ? Qt::ArrowCursor : Qt::IBeamCursor); … … 1519 1396 { 1520 1397 Q_D(const QLineEdit); 1521 d->co py();1398 d->control->copy(); 1522 1399 } 1523 1400 … … 1536 1413 { 1537 1414 Q_D(QLineEdit); 1538 if (echoMode() == PasswordEchoOnEdit && !d->passwordEchoEditing) { 1539 // Clear the edit and reset to normal echo mode when pasting; the echo 1540 // mode switches back when the edit loses focus. ### changes a public 1541 // property, resets current content 1542 d->updatePasswordEchoEditing(true); 1543 clear(); 1544 } 1545 insert(QApplication::clipboard()->text(QClipboard::Clipboard)); 1546 } 1547 1548 void QLineEditPrivate::copy(bool clipboard) const 1549 { 1550 Q_Q(const QLineEdit); 1551 QString t = q->selectedText(); 1552 if (!t.isEmpty() && echoMode == QLineEdit::Normal) { 1553 q->disconnect(QApplication::clipboard(), SIGNAL(selectionChanged()), q, 0); 1554 QApplication::clipboard()->setText(t, clipboard ? QClipboard::Clipboard : QClipboard::Selection); 1555 q->connect(QApplication::clipboard(), SIGNAL(selectionChanged()), 1556 q, SLOT(_q_clipboardChanged())); 1557 } 1415 d->control->paste(); 1558 1416 } 1559 1417 … … 1565 1423 { 1566 1424 Q_D(QLineEdit); 1567 #ifndef QT_NO_SHORTCUT 1568 if (e->type() == QEvent::ShortcutOverride && !d->readOnly) { 1569 QKeyEvent* ke = (QKeyEvent*) e; 1570 if (ke == QKeySequence::Copy 1571 || ke == QKeySequence::Paste 1572 || ke == QKeySequence::Cut 1573 || ke == QKeySequence::Redo 1574 || ke == QKeySequence::Undo 1575 || ke == QKeySequence::MoveToNextWord 1576 || ke == QKeySequence::MoveToPreviousWord 1577 || ke == QKeySequence::MoveToStartOfDocument 1578 || ke == QKeySequence::MoveToEndOfDocument 1579 || ke == QKeySequence::SelectNextWord 1580 || ke == QKeySequence::SelectPreviousWord 1581 || ke == QKeySequence::SelectStartOfLine 1582 || ke == QKeySequence::SelectEndOfLine 1583 || ke == QKeySequence::SelectStartOfBlock 1584 || ke == QKeySequence::SelectEndOfBlock 1585 || ke == QKeySequence::SelectStartOfDocument 1586 || ke == QKeySequence::SelectAll 1587 || ke == QKeySequence::SelectEndOfDocument) { 1588 ke->accept(); 1589 } else if (ke->modifiers() == Qt::NoModifier || ke->modifiers() == Qt::ShiftModifier 1590 || ke->modifiers() == Qt::KeypadModifier) { 1591 if (ke->key() < Qt::Key_Escape) { 1592 ke->accept(); 1593 } else { 1594 switch (ke->key()) { 1595 case Qt::Key_Delete: 1596 case Qt::Key_Home: 1597 case Qt::Key_End: 1598 case Qt::Key_Backspace: 1599 case Qt::Key_Left: 1600 case Qt::Key_Right: 1601 ke->accept(); 1602 default: 1603 break; 1604 } 1605 } 1606 } 1607 } else 1608 #endif 1609 if (e->type() == QEvent::Timer) { 1425 if (e->type() == QEvent::Timer) { 1610 1426 // should be timerEvent, is here for binary compatibility 1611 1427 int timerId = ((QTimerEvent*)e)->timerId(); 1612 if (timerId == d->cursorTimer) { 1613 QStyleOptionFrameV2 opt; 1614 initStyleOption(&opt); 1615 if(!hasSelectedText() 1616 || style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this)) 1617 d->setCursorVisible(!d->cursorVisible); 1428 if (false) { 1618 1429 #ifndef QT_NO_DRAGANDDROP 1619 1430 } else if (timerId == d->dndTimer.timerId()) { … … 1623 1434 else if (timerId == d->tripleClickTimer.timerId()) 1624 1435 d->tripleClickTimer.stop(); 1625 #ifdef QT_KEYPAD_NAVIGATION1626 else if (timerId == d->deleteAllTimer.timerId()) {1627 d->deleteAllTimer.stop();1628 clear();1629 }1630 #endif1631 1436 } else if (e->type() == QEvent::ContextMenu) { 1632 1437 #ifndef QT_NO_IM 1633 if (d->co mposeMode())1438 if (d->control->composeMode()) 1634 1439 return true; 1635 1440 #endif 1636 d->separate();1441 //d->separate(); 1637 1442 } else if (e->type() == QEvent::WindowActivate) { 1638 1443 QTimer::singleShot(0, this, SLOT(_q_handleWindowActivate())); 1639 } 1444 }else if(e->type() == QEvent::ShortcutOverride){ 1445 d->control->processEvent(e); 1446 } else if (e->type() == QEvent::KeyRelease) { 1447 d->control->setCursorBlinkPeriod(QApplication::cursorFlashTime()); 1448 } else if (e->type() == QEvent::Show) { 1449 //In order to get the cursor blinking if QComboBox::setEditable is called when the combobox has focus 1450 if (hasFocus()) { 1451 d->control->setCursorBlinkPeriod(QApplication::cursorFlashTime()); 1452 QStyleOptionFrameV2 opt; 1453 initStyleOption(&opt); 1454 if ((!hasSelectedText() && d->control->preeditAreaText().isEmpty()) 1455 || style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this)) 1456 d->setCursorVisible(true); 1457 } 1458 } 1459 1640 1460 #ifdef QT_KEYPAD_NAVIGATION 1641 1461 if (QApplication::keypadNavigationEnabled()) { 1642 if ((e->type() == QEvent::KeyPress) || (e->type() == QEvent::KeyRelease)) { 1643 QKeyEvent *ke = (QKeyEvent *)e; 1644 if (ke->key() == Qt::Key_Back) { 1645 if (ke->isAutoRepeat()) { 1646 // Swallow it. We don't want back keys running amok. 1647 ke->accept(); 1648 return true; 1649 } 1650 if ((e->type() == QEvent::KeyRelease) 1651 && !isReadOnly() 1652 && d->deleteAllTimer.isActive()) { 1653 d->deleteAllTimer.stop(); 1654 backspace(); 1655 ke->accept(); 1656 return true; 1657 } 1658 } 1659 } else if (e->type() == QEvent::EnterEditFocus) { 1462 if (e->type() == QEvent::EnterEditFocus) { 1660 1463 end(false); 1661 if (!d->cursorTimer) { 1662 int cft = QApplication::cursorFlashTime(); 1663 d->cursorTimer = cft ? startTimer(cft/2) : -1; 1664 } 1464 d->setCursorVisible(true); 1465 d->control->setCursorBlinkPeriod(QApplication::cursorFlashTime()); 1665 1466 } else if (e->type() == QEvent::LeaveEditFocus) { 1666 1467 d->setCursorVisible(false); 1667 if (d->cursorTimer > 0) 1668 killTimer(d->cursorTimer); 1669 d->cursorTimer = 0; 1670 1671 if (!d->emitingEditingFinished) { 1672 if (hasAcceptableInput() || d->fixup()) { 1673 d->emitingEditingFinished = true; 1674 emit editingFinished(); 1675 d->emitingEditingFinished = false; 1676 } 1677 } 1468 d->control->setCursorBlinkPeriod(0); 1469 if (d->control->hasAcceptableInput() || d->control->fixup()) 1470 emit editingFinished(); 1678 1471 } 1679 1472 } … … 1688 1481 Q_D(QLineEdit); 1689 1482 if (d->sendMouseEventToInputContext(e)) 1690 1483 return; 1691 1484 if (e->button() == Qt::RightButton) 1692 1485 return; … … 1695 1488 setEditFocus(true); 1696 1489 // Get the completion list to pop up. 1697 if (d->co mpleter)1698 d->co mpleter->complete();1490 if (d->control->completer()) 1491 d->control->completer()->complete(); 1699 1492 } 1700 1493 #endif … … 1707 1500 int cursor = d->xToPos(e->pos().x()); 1708 1501 #ifndef QT_NO_DRAGANDDROP 1709 if (!mark && d->dragEnabled && d->echoMode == Normal && 1710 e->button() == Qt::LeftButton && d->inSelection(e->pos().x())) { 1711 d->cursor = cursor; 1712 update(); 1502 if (!mark && d->dragEnabled && d->control->echoMode() == Normal && 1503 e->button() == Qt::LeftButton && d->control->inSelection(e->pos().x())) { 1713 1504 d->dndPos = e->pos(); 1714 1505 if (!d->dndTimer.isActive()) 1715 1506 d->dndTimer.start(QApplication::startDragTime(), this); 1716 d->emitCursorPositionChanged();1717 1507 } else 1718 1508 #endif 1719 1509 { 1720 d-> moveCursor(cursor, mark);1510 d->control->moveCursor(cursor, mark); 1721 1511 } 1722 1512 } … … 1728 1518 Q_D(QLineEdit); 1729 1519 if (d->sendMouseEventToInputContext(e)) 1730 1520 return; 1731 1521 1732 1522 if (e->buttons() & Qt::LeftButton) { … … 1738 1528 #endif 1739 1529 { 1740 d-> moveCursor(d->xToPos(e->pos().x()), true);1530 d->control->moveCursor(d->xToPos(e->pos().x()), true); 1741 1531 } 1742 1532 } … … 1749 1539 Q_D(QLineEdit); 1750 1540 if (d->sendMouseEventToInputContext(e)) 1751 1541 return; 1752 1542 #ifndef QT_NO_DRAGANDDROP 1753 1543 if (e->button() == Qt::LeftButton) { … … 1762 1552 if (QApplication::clipboard()->supportsSelection()) { 1763 1553 if (e->button() == Qt::LeftButton) { 1764 d->co py(false);1765 } else if (!d-> readOnly&& e->button() == Qt::MidButton) {1766 d ->deselect();1554 d->control->copy(QClipboard::Selection); 1555 } else if (!d->control->isReadOnly() && e->button() == Qt::MidButton) { 1556 deselect(); 1767 1557 insert(QApplication::clipboard()->text(QClipboard::Selection)); 1768 1558 } 1769 1559 } 1770 1560 #endif 1561 1562 if (!isReadOnly() && rect().contains(e->pos())) 1563 d->handleSoftwareInputPanel(e->button(), d->clickCausedFocus); 1564 d->clickCausedFocus = 0; 1771 1565 } 1772 1566 … … 1777 1571 Q_D(QLineEdit); 1778 1572 if (d->sendMouseEventToInputContext(e)) 1779 1573 return; 1780 1574 if (e->button() == Qt::LeftButton) { 1781 deselect(); 1782 d->cursor = d->xToPos(e->pos().x()); 1783 d->cursor = d->textLayout.previousCursorPosition(d->cursor, QTextLayout::SkipWords); 1784 // ## text layout should support end of words. 1785 int end = d->textLayout.nextCursorPosition(d->cursor, QTextLayout::SkipWords); 1786 while (end > d->cursor && d->text[end-1].isSpace()) 1787 --end; 1788 d->moveCursor(end, true); 1575 d->control->selectWordAtPos(d->xToPos(e->pos().x())); 1789 1576 d->tripleClickTimer.start(QApplication::doubleClickInterval(), this); 1790 1577 d->tripleClick = e->pos(); … … 1826 1613 { 1827 1614 Q_D(QLineEdit); 1828 1829 bool inlineCompletionAccepted = false; 1830 1831 #ifndef QT_NO_COMPLETER 1832 if (d->completer) { 1833 QCompleter::CompletionMode completionMode = d->completer->completionMode(); 1834 if ((completionMode == QCompleter::PopupCompletion 1835 || completionMode == QCompleter::UnfilteredPopupCompletion) 1836 &&d->completer->popup() 1837 && d->completer->popup()->isVisible()) { 1838 // The following keys are forwarded by the completer to the widget 1839 // Ignoring the events lets the completer provide suitable default behavior 1840 switch (event->key()) { 1841 case Qt::Key_Escape: 1842 event->ignore(); 1843 return; 1844 case Qt::Key_Enter: 1845 case Qt::Key_Return: 1846 case Qt::Key_F4: 1847 #ifdef QT_KEYPAD_NAVIGATION 1848 case Qt::Key_Select: 1849 if (!QApplication::keypadNavigationEnabled()) 1850 break; 1851 #endif 1852 d->completer->popup()->hide(); // just hide. will end up propagating to parent 1853 default: 1854 break; // normal key processing 1855 } 1856 } else if (completionMode == QCompleter::InlineCompletion) { 1857 switch (event->key()) { 1858 case Qt::Key_Enter: 1859 case Qt::Key_Return: 1860 case Qt::Key_F4: 1861 #ifdef QT_KEYPAD_NAVIGATION 1862 case Qt::Key_Select: 1863 if (!QApplication::keypadNavigationEnabled()) 1864 break; 1865 #endif 1866 if (!d->completer->currentCompletion().isEmpty() && d->selend > d->selstart 1867 && d->selend == d->text.length()) { 1868 setText(d->completer->currentCompletion()); 1869 inlineCompletionAccepted = true; 1870 } 1871 default: 1872 break; // normal key processing 1873 } 1874 } 1875 } 1876 #endif // QT_NO_COMPLETER 1877 1878 #ifdef QT_KEYPAD_NAVIGATION 1615 #ifdef QT_KEYPAD_NAVIGATION 1879 1616 bool select = false; 1880 1617 switch (event->key()) { … … 1883 1620 if (hasEditFocus()) { 1884 1621 setEditFocus(false); 1885 if (d->co mpleter && d->completer->popup()->isVisible())1886 d->co mpleter->popup()->hide();1622 if (d->control->completer() && d->control->completer()->popup()->isVisible()) 1623 d->control->completer()->popup()->hide(); 1887 1624 select = true; 1888 1625 } … … 1903 1640 { 1904 1641 setEditFocus(true); 1642 #ifndef Q_OS_SYMBIAN 1905 1643 clear(); 1644 #endif 1906 1645 } else { 1907 1646 event->ignore(); … … 1920 1659 } 1921 1660 #endif 1922 1923 if (echoMode() == PasswordEchoOnEdit 1924 && !d->passwordEchoEditing 1925 && !isReadOnly() 1926 && !event->text().isEmpty() 1927 #ifdef QT_KEYPAD_NAVIGATION 1928 && event->key() != Qt::Key_Select 1929 && event->key() != Qt::Key_Up 1930 && event->key() != Qt::Key_Down 1931 && event->key() != Qt::Key_Back 1932 #endif 1933 && !(event->modifiers() & Qt::ControlModifier)) { 1934 // Clear the edit and reset to normal echo mode while editing; the 1935 // echo mode switches back when the edit loses focus. ### changes a 1936 // public property, resets current content. dubious code; you can 1937 // navigate with keys up, down, back, and select(?), but if you press 1938 // "left" or "right" it clears? 1939 d->updatePasswordEchoEditing(true); 1940 clear(); 1941 } 1942 1943 d->setCursorVisible(true); 1944 if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) { 1945 if (hasAcceptableInput() || d->fixup()) { 1946 emit returnPressed(); 1947 d->emitingEditingFinished = true; 1948 emit editingFinished(); 1949 d->emitingEditingFinished = false; 1950 } 1951 if (inlineCompletionAccepted) 1952 event->accept(); 1953 else 1954 event->ignore(); 1955 return; 1956 } 1957 bool unknown = false; 1958 1959 if (false) { 1960 } 1961 #ifndef QT_NO_SHORTCUT 1962 else if (event == QKeySequence::Undo) { 1963 if (!d->readOnly) 1964 undo(); 1965 } 1966 else if (event == QKeySequence::Redo) { 1967 if (!d->readOnly) 1968 redo(); 1969 } 1970 else if (event == QKeySequence::SelectAll) { 1971 selectAll(); 1972 } 1973 #ifndef QT_NO_CLIPBOARD 1974 else if (event == QKeySequence::Copy) { 1975 copy(); 1976 } 1977 else if (event == QKeySequence::Paste) { 1978 if (!d->readOnly) 1979 paste(); 1980 } 1981 else if (event == QKeySequence::Cut) { 1982 if (!d->readOnly) { 1983 cut(); 1984 } 1985 } 1986 else if (event == QKeySequence::DeleteEndOfLine) { 1987 if (!d->readOnly) { 1988 setSelection(d->cursor, d->text.size()); 1989 copy(); 1990 del(); 1991 } 1992 } 1993 #endif //QT_NO_CLIPBOARD 1994 else if (event == QKeySequence::MoveToStartOfLine) { 1995 home(0); 1996 } 1997 else if (event == QKeySequence::MoveToEndOfLine) { 1998 end(0); 1999 } 2000 else if (event == QKeySequence::SelectStartOfLine) { 2001 home(1); 2002 } 2003 else if (event == QKeySequence::SelectEndOfLine) { 2004 end(1); 2005 } 2006 else if (event == QKeySequence::MoveToNextChar) { 2007 #if !defined(Q_WS_WIN) || defined(QT_NO_COMPLETER) 2008 if (d->hasSelectedText()) { 2009 #else 2010 if (d->hasSelectedText() && d->completer 2011 && d->completer->completionMode() == QCompleter::InlineCompletion) { 2012 #endif 2013 d->moveCursor(d->selend, false); 2014 } else { 2015 cursorForward(0, layoutDirection() == Qt::LeftToRight ? 1 : -1); 2016 } 2017 } 2018 else if (event == QKeySequence::SelectNextChar) { 2019 cursorForward(1, layoutDirection() == Qt::LeftToRight ? 1 : -1); 2020 } 2021 else if (event == QKeySequence::MoveToPreviousChar) { 2022 #if !defined(Q_WS_WIN) || defined(QT_NO_COMPLETER) 2023 if (d->hasSelectedText()) { 2024 #else 2025 if (d->hasSelectedText() && d->completer 2026 && d->completer->completionMode() == QCompleter::InlineCompletion) { 2027 #endif 2028 d->moveCursor(d->selstart, false); 2029 } else { 2030 cursorBackward(0, layoutDirection() == Qt::LeftToRight ? 1 : -1); 2031 } 2032 } 2033 else if (event == QKeySequence::SelectPreviousChar) { 2034 cursorBackward(1, layoutDirection() == Qt::LeftToRight ? 1 : -1); 2035 } 2036 else if (event == QKeySequence::MoveToNextWord) { 2037 if (echoMode() == Normal) 2038 layoutDirection() == Qt::LeftToRight ? cursorWordForward(0) : cursorWordBackward(0); 2039 else 2040 layoutDirection() == Qt::LeftToRight ? end(0) : home(0); 2041 } 2042 else if (event == QKeySequence::MoveToPreviousWord) { 2043 if (echoMode() == Normal) 2044 layoutDirection() == Qt::LeftToRight ? cursorWordBackward(0) : cursorWordForward(0); 2045 else if (!d->readOnly) { 2046 layoutDirection() == Qt::LeftToRight ? home(0) : end(0); 2047 } 2048 } 2049 else if (event == QKeySequence::SelectNextWord) { 2050 if (echoMode() == Normal) 2051 layoutDirection() == Qt::LeftToRight ? cursorWordForward(1) : cursorWordBackward(1); 2052 else 2053 layoutDirection() == Qt::LeftToRight ? end(1) : home(1); 2054 } 2055 else if (event == QKeySequence::SelectPreviousWord) { 2056 if (echoMode() == Normal) 2057 layoutDirection() == Qt::LeftToRight ? cursorWordBackward(1) : cursorWordForward(1); 2058 else 2059 layoutDirection() == Qt::LeftToRight ? home(1) : end(1); 2060 } 2061 else if (event == QKeySequence::Delete) { 2062 if (!d->readOnly) 2063 del(); 2064 } 2065 else if (event == QKeySequence::DeleteEndOfWord) { 2066 if (!d->readOnly) { 2067 cursorWordForward(true); 2068 del(); 2069 } 2070 } 2071 else if (event == QKeySequence::DeleteStartOfWord) { 2072 if (!d->readOnly) { 2073 cursorWordBackward(true); 2074 del(); 2075 } 2076 } 2077 #endif // QT_NO_SHORTCUT 2078 else { 2079 #ifdef Q_WS_MAC 2080 if (event->key() == Qt::Key_Up || event->key() == Qt::Key_Down) { 2081 Qt::KeyboardModifiers myModifiers = (event->modifiers() & ~Qt::KeypadModifier); 2082 if (myModifiers & Qt::ShiftModifier) { 2083 if (myModifiers == (Qt::ControlModifier|Qt::ShiftModifier) 2084 || myModifiers == (Qt::AltModifier|Qt::ShiftModifier) 2085 || myModifiers == Qt::ShiftModifier) { 2086 2087 event->key() == Qt::Key_Up ? home(1) : end(1); 2088 } 2089 } else { 2090 if ((myModifiers == Qt::ControlModifier 2091 || myModifiers == Qt::AltModifier 2092 || myModifiers == Qt::NoModifier)) { 2093 event->key() == Qt::Key_Up ? home(0) : end(0); 2094 } 2095 } 2096 } 2097 #endif 2098 if (event->modifiers() & Qt::ControlModifier) { 2099 switch (event->key()) { 2100 case Qt::Key_Backspace: 2101 if (!d->readOnly) { 2102 cursorWordBackward(true); 2103 del(); 2104 } 2105 break; 2106 #ifndef QT_NO_COMPLETER 2107 case Qt::Key_Up: 2108 case Qt::Key_Down: 2109 d->complete(event->key()); 2110 break; 2111 #endif 2112 #if defined(Q_WS_X11) 2113 case Qt::Key_E: 2114 end(0); 2115 break; 2116 2117 case Qt::Key_U: 2118 if (!d->readOnly) { 2119 setSelection(0, d->text.size()); 2120 #ifndef QT_NO_CLIPBOARD 2121 copy(); 2122 #endif 2123 del(); 2124 } 2125 break; 2126 #endif 2127 default: 2128 unknown = true; 2129 } 2130 } else { // ### check for *no* modifier 2131 switch (event->key()) { 2132 case Qt::Key_Backspace: 2133 if (!d->readOnly) { 2134 backspace(); 2135 #ifndef QT_NO_COMPLETER 2136 d->complete(Qt::Key_Backspace); 2137 #endif 2138 } 2139 break; 2140 #ifdef QT_KEYPAD_NAVIGATION 2141 case Qt::Key_Back: 2142 if (QApplication::keypadNavigationEnabled() && !event->isAutoRepeat() 2143 && !isReadOnly()) { 2144 if (text().length() == 0) { 2145 setText(d->origText); 2146 2147 if (d->passwordEchoEditing) 2148 d->updatePasswordEchoEditing(false); 2149 2150 setEditFocus(false); 2151 } else if (!d->deleteAllTimer.isActive()) { 2152 d->deleteAllTimer.start(750, this); 2153 } 2154 } else { 2155 unknown = true; 2156 } 2157 break; 2158 #endif 2159 2160 default: 2161 unknown = true; 2162 } 2163 } 2164 } 2165 2166 if (event->key() == Qt::Key_Direction_L || event->key() == Qt::Key_Direction_R) { 2167 setLayoutDirection((event->key() == Qt::Key_Direction_L) ? Qt::LeftToRight : Qt::RightToLeft); 2168 d->updateTextLayout(); 2169 update(); 2170 unknown = false; 2171 } 2172 2173 if (unknown && !d->readOnly) { 2174 QString t = event->text(); 2175 if (!t.isEmpty() && t.at(0).isPrint()) { 2176 insert(t); 2177 #ifndef QT_NO_COMPLETER 2178 d->complete(event->key()); 2179 #endif 2180 event->accept(); 2181 return; 2182 } 2183 } 2184 2185 if (unknown) 2186 event->ignore(); 2187 else 2188 event->accept(); 1661 d->control->processKeyEvent(event); 1662 if (event->isAccepted()) 1663 d->control->setCursorBlinkPeriod(0); 2189 1664 } 2190 1665 … … 2198 1673 Q_D(const QLineEdit); 2199 1674 return d->cursorRect(); 2200 }2201 2202 /*!2203 This function is not intended as polymorphic usage. Just a shared code2204 fragment that calls QInputContext::mouseHandler for this2205 class.2206 */2207 bool QLineEditPrivate::sendMouseEventToInputContext( QMouseEvent *e )2208 {2209 #if !defined QT_NO_IM2210 Q_Q(QLineEdit);2211 if ( composeMode() ) {2212 int tmp_cursor = xToPos(e->pos().x());2213 int mousePos = tmp_cursor - cursor;2214 if ( mousePos < 0 || mousePos > textLayout.preeditAreaText().length() ) {2215 mousePos = -1;2216 // don't send move events outside the preedit area2217 if ( e->type() == QEvent::MouseMove )2218 return true;2219 }2220 2221 QInputContext *qic = q->inputContext();2222 if ( qic )2223 // may be causing reset() in some input methods2224 qic->mouseHandler(mousePos, e);2225 if (!textLayout.preeditAreaText().isEmpty())2226 return true;2227 }2228 #else2229 Q_UNUSED(e);2230 #endif2231 2232 return false;2233 1675 } 2234 1676 … … 2238 1680 { 2239 1681 Q_D(QLineEdit); 2240 if (d-> readOnly) {1682 if (d->control->isReadOnly()) { 2241 1683 e->ignore(); 2242 1684 return; 2243 1685 } 2244 1686 2245 if (echoMode() == PasswordEchoOnEdit && !d-> passwordEchoEditing) {1687 if (echoMode() == PasswordEchoOnEdit && !d->control->passwordEchoEditing()) { 2246 1688 // Clear the edit and reset to normal echo mode while entering input 2247 1689 // method data; the echo mode switches back when the edit loses focus. … … 2259 1701 && !e->preeditString().isEmpty()) { 2260 1702 setEditFocus(true); 1703 #ifndef Q_OS_SYMBIAN 2261 1704 selectAll(); // so text is replaced rather than appended to 2262 } 2263 #endif 2264 2265 int priorState = d->undoState; 2266 d->removeSelectedText(); 2267 2268 int c = d->cursor; // cursor position after insertion of commit string 2269 if (e->replacementStart() <= 0) 2270 c += e->commitString().length() + qMin(-e->replacementStart(), e->replacementLength()); 2271 2272 d->cursor += e->replacementStart(); 2273 2274 // insert commit string 2275 if (e->replacementLength()) { 2276 d->selstart = d->cursor; 2277 d->selend = d->selstart + e->replacementLength(); 2278 d->removeSelectedText(); 2279 } 2280 if (!e->commitString().isEmpty()) 2281 d->insert(e->commitString()); 2282 2283 d->cursor = qMin(c, d->text.length()); 2284 2285 d->textLayout.setPreeditArea(d->cursor, e->preeditString()); 2286 d->preeditCursor = e->preeditString().length(); 2287 d->hideCursor = false; 2288 QList<QTextLayout::FormatRange> formats; 2289 for (int i = 0; i < e->attributes().size(); ++i) { 2290 const QInputMethodEvent::Attribute &a = e->attributes().at(i); 2291 if (a.type == QInputMethodEvent::Cursor) { 2292 d->preeditCursor = a.start; 2293 d->hideCursor = !a.length; 2294 } else if (a.type == QInputMethodEvent::TextFormat) { 2295 QTextCharFormat f = qvariant_cast<QTextFormat>(a.value).toCharFormat(); 2296 if (f.isValid()) { 2297 QTextLayout::FormatRange o; 2298 o.start = a.start + d->cursor; 2299 o.length = a.length; 2300 o.format = f; 2301 formats.append(o); 2302 } 2303 } 2304 } 2305 d->textLayout.setAdditionalFormats(formats); 2306 d->updateTextLayout(); 2307 update(); 2308 if (!e->commitString().isEmpty()) 2309 d->emitCursorPositionChanged(); 2310 d->finishChange(priorState); 1705 #endif 1706 } 1707 #endif 1708 1709 d->control->processInputMethodEvent(e); 1710 2311 1711 #ifndef QT_NO_COMPLETER 2312 1712 if (!e->commitString().isEmpty()) 2313 d->co mplete(Qt::Key_unknown);1713 d->control->complete(Qt::Key_unknown); 2314 1714 #endif 2315 1715 } … … 2326 1726 return font(); 2327 1727 case Qt::ImCursorPosition: 2328 return QVariant( (d->selend - d->selstart == 0) ? d->cursor : d->selend);1728 return QVariant(d->control->cursor()); 2329 1729 case Qt::ImSurroundingText: 2330 return QVariant( d->text);1730 return QVariant(text()); 2331 1731 case Qt::ImCurrentSelection: 2332 1732 return QVariant(selectedText()); 1733 case Qt::ImMaximumTextLength: 1734 return QVariant(maxLength()); 1735 case Qt::ImAnchorPosition: 1736 if (d->control->selectionStart() == d->control->selectionEnd()) 1737 return QVariant(d->control->cursor()); 1738 else if (d->control->selectionStart() == d->control->cursor()) 1739 return QVariant(d->control->selectionEnd()); 1740 else 1741 return QVariant(d->control->selectionStart()); 2333 1742 default: 2334 1743 return QVariant(); … … 2345 1754 e->reason() == Qt::BacktabFocusReason || 2346 1755 e->reason() == Qt::ShortcutFocusReason) { 2347 if ( d->maskData)2348 d-> moveCursor(d->nextMaskBlank(0));2349 else if (!d-> hasSelectedText())1756 if (!d->control->inputMask().isEmpty()) 1757 d->control->moveCursor(d->control->nextMaskBlank(0)); 1758 else if (!d->control->hasSelectedText()) 2350 1759 selectAll(); 1760 } else if (e->reason() == Qt::MouseFocusReason) { 1761 d->clickCausedFocus = 1; 2351 1762 } 2352 1763 #ifdef QT_KEYPAD_NAVIGATION 2353 if (!QApplication::keypadNavigationEnabled() || (hasEditFocus() && e->reason() == Qt::PopupFocusReason)) 2354 #endif 2355 if (!d->cursorTimer) { 2356 int cft = QApplication::cursorFlashTime(); 2357 d->cursorTimer = cft ? startTimer(cft/2) : -1; 2358 } 1764 if (!QApplication::keypadNavigationEnabled() || (hasEditFocus() && ( e->reason() == Qt::PopupFocusReason 1765 #ifdef Q_OS_SYMBIAN 1766 || e->reason() == Qt::ActiveWindowFocusReason 1767 #endif 1768 ))) { 1769 #endif 1770 d->control->setCursorBlinkPeriod(QApplication::cursorFlashTime()); 2359 1771 QStyleOptionFrameV2 opt; 2360 1772 initStyleOption(&opt); 2361 if((!hasSelectedText() && d-> textLayout.preeditAreaText().isEmpty())1773 if((!hasSelectedText() && d->control->preeditAreaText().isEmpty()) 2362 1774 || style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, this)) 2363 1775 d->setCursorVisible(true); 2364 1776 #ifdef Q_WS_MAC 2365 if (d-> echoMode == Password || d->echoMode== NoEcho)1777 if (d->control->echoMode() == Password || d->control->echoMode() == NoEcho) 2366 1778 qt_mac_secure_keyboard(true); 2367 1779 #endif 2368 1780 #ifdef QT_KEYPAD_NAVIGATION 2369 d->origText = d->text; 1781 d->control->setCancelText(d->control->text()); 1782 } 2370 1783 #endif 2371 1784 #ifndef QT_NO_COMPLETER 2372 if (d->co mpleter) {2373 d->co mpleter->setWidget(this);2374 QObject::connect(d->co mpleter, SIGNAL(activated(QString)),1785 if (d->control->completer()) { 1786 d->control->completer()->setWidget(this); 1787 QObject::connect(d->control->completer(), SIGNAL(activated(QString)), 2375 1788 this, SLOT(setText(QString))); 2376 QObject::connect(d->co mpleter, SIGNAL(highlighted(QString)),1789 QObject::connect(d->control->completer(), SIGNAL(highlighted(QString)), 2377 1790 this, SLOT(_q_completionHighlighted(QString))); 2378 1791 } … … 2387 1800 { 2388 1801 Q_D(QLineEdit); 2389 if (d-> passwordEchoEditing) {1802 if (d->control->passwordEchoEditing()) { 2390 1803 // Reset the echomode back to PasswordEchoOnEdit when the widget loses 2391 1804 // focus. … … 2399 1812 2400 1813 d->setCursorVisible(false); 2401 if (d->cursorTimer > 0) 2402 killTimer(d->cursorTimer); 2403 d->cursorTimer = 0; 2404 1814 d->control->setCursorBlinkPeriod(0); 2405 1815 #ifdef QT_KEYPAD_NAVIGATION 2406 1816 // editingFinished() is already emitted on LeaveEditFocus … … 2409 1819 if (reason != Qt::PopupFocusReason 2410 1820 || !(QApplication::activePopupWidget() && QApplication::activePopupWidget()->parentWidget() == this)) { 2411 if (!d->emitingEditingFinished) { 2412 if (hasAcceptableInput() || d->fixup()) { 2413 d->emitingEditingFinished = true; 1821 if (hasAcceptableInput() || d->control->fixup()) 2414 1822 emit editingFinished(); 2415 d->emitingEditingFinished = false;2416 }2417 }2418 1823 #ifdef QT3_SUPPORT 2419 1824 emit lostFocus(); … … 2421 1826 } 2422 1827 #ifdef Q_WS_MAC 2423 if (d-> echoMode == Password || d->echoMode== NoEcho)1828 if (d->control->echoMode() == Password || d->control->echoMode() == NoEcho) 2424 1829 qt_mac_secure_keyboard(false); 2425 1830 #endif 2426 1831 #ifdef QT_KEYPAD_NAVIGATION 2427 d-> origText = QString();1832 d->control->setCancelText(QString()); 2428 1833 #endif 2429 1834 #ifndef QT_NO_COMPLETER 2430 if (d->co mpleter) {2431 QObject::disconnect(d->co mpleter, 0, this, 0);1835 if (d->control->completer()) { 1836 QObject::disconnect(d->control->completer(), 0, this, 0); 2432 1837 } 2433 1838 #endif … … 2459 1864 switch (va & Qt::AlignVertical_Mask) { 2460 1865 case Qt::AlignBottom: 2461 d->vscroll = r.y() + r.height() - fm.height() - verticalMargin;1866 d->vscroll = r.y() + r.height() - fm.height() - d->verticalMargin; 2462 1867 break; 2463 1868 case Qt::AlignTop: 2464 d->vscroll = r.y() + verticalMargin;1869 d->vscroll = r.y() + d->verticalMargin; 2465 1870 break; 2466 1871 default: … … 2469 1874 break; 2470 1875 } 2471 QRect lineRect(r.x() + horizontalMargin, d->vscroll, r.width() - 2*horizontalMargin, fm.height()); 2472 QTextLine line = d->textLayout.lineAt(0); 2473 2474 int cursor = d->cursor; 2475 if (d->preeditCursor != -1) 2476 cursor += d->preeditCursor; 2477 // locate cursor position 2478 int cix = qRound(line.cursorToX(cursor)); 1876 QRect lineRect(r.x() + d->horizontalMargin, d->vscroll, r.width() - 2*d->horizontalMargin, fm.height()); 1877 1878 if (d->control->text().isEmpty()) { 1879 if (!hasFocus() && !d->placeholderText.isEmpty()) { 1880 QColor col = pal.text().color(); 1881 col.setAlpha(128); 1882 QPen oldpen = p.pen(); 1883 p.setPen(col); 1884 p.drawText(lineRect, va, d->placeholderText); 1885 p.setPen(oldpen); 1886 return; 1887 } 1888 } 1889 1890 int cix = qRound(d->control->cursorToX()); 2479 1891 2480 1892 // horizontal scrolling. d->hscroll is the left indent from the beginning … … 2486 1898 int minLB = qMax(0, -fm.minLeftBearing()); 2487 1899 int minRB = qMax(0, -fm.minRightBearing()); 2488 int widthUsed = qRound( line.naturalTextWidth()) + 1 + minRB;1900 int widthUsed = qRound(d->control->naturalTextWidth()) + 1 + minRB; 2489 1901 if ((minLB + widthUsed) <= lineRect.width()) { 2490 1902 // text fits in lineRect; use hscroll for alignment … … 2514 1926 } 2515 1927 // the y offset is there to keep the baseline constant in case we have script changes in the text. 2516 QPoint topLeft = lineRect.topLeft() - QPoint(d->hscroll, d-> ascent- fm.ascent());1928 QPoint topLeft = lineRect.topLeft() - QPoint(d->hscroll, d->control->ascent() - fm.ascent()); 2517 1929 2518 1930 // draw text, selections and cursors 2519 1931 #ifndef QT_NO_STYLE_STYLESHEET 2520 1932 if (QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(style())) { 2521 cssStyle-> focusPalette(this, &panel, &pal);1933 cssStyle->styleSheetPalette(this, &panel, &pal); 2522 1934 } 2523 1935 #endif 2524 1936 p.setPen(pal.text().color()); 2525 1937 2526 QVector<QTextLayout::FormatRange> selections; 1938 int flags = QLineControl::DrawText; 1939 2527 1940 #ifdef QT_KEYPAD_NAVIGATION 2528 1941 if (!QApplication::keypadNavigationEnabled() || hasEditFocus()) 2529 1942 #endif 2530 if (d->selstart < d->selend || (d->cursorVisible && d->maskData && !d->readOnly)) { 2531 QTextLayout::FormatRange o; 2532 if (d->selstart < d->selend) { 2533 o.start = d->selstart; 2534 o.length = d->selend - d->selstart; 2535 o.format.setBackground(pal.brush(QPalette::Highlight)); 2536 o.format.setForeground(pal.brush(QPalette::HighlightedText)); 2537 } else { 2538 // mask selection 2539 o.start = d->cursor; 2540 o.length = 1; 2541 o.format.setBackground(pal.brush(QPalette::Text)); 2542 o.format.setForeground(pal.brush(QPalette::Window)); 2543 } 2544 selections.append(o); 1943 if (d->control->hasSelectedText() || (d->cursorVisible && !d->control->inputMask().isEmpty() && !d->control->isReadOnly())){ 1944 flags |= QLineControl::DrawSelections; 1945 // Palette only used for selections/mask and may not be in sync 1946 if(d->control->palette() != pal) 1947 d->control->setPalette(pal); 2545 1948 } 2546 1949 … … 2548 1951 // selection phase of input method, so the ordinary cursor should be 2549 1952 // invisible if we have a preedit string. 2550 d->textLayout.draw(&p, topLeft, selections, r); 2551 if (d->cursorVisible && !d->readOnly && !d->hideCursor) 2552 d->textLayout.drawCursor(&p, topLeft, cursor, style()->pixelMetric(QStyle::PM_TextCursorWidth)); 1953 if (d->cursorVisible && !d->control->isReadOnly()) 1954 flags |= QLineControl::DrawCursor; 1955 1956 d->control->setCursorWidth(style()->pixelMetric(QStyle::PM_TextCursorWidth)); 1957 d->control->draw(&p, topLeft, r, flags); 1958 2553 1959 } 2554 1960 … … 2560 1966 { 2561 1967 Q_D(QLineEdit); 2562 if (!d-> readOnly&& e->mimeData()->hasFormat(QLatin1String("text/plain"))) {1968 if (!d->control->isReadOnly() && e->mimeData()->hasFormat(QLatin1String("text/plain"))) { 2563 1969 e->acceptProposedAction(); 2564 d->c ursor = d->xToPos(e->pos().x());1970 d->control->moveCursor(d->xToPos(e->pos().x()), false); 2565 1971 d->cursorVisible = true; 2566 1972 update(); 2567 d->emitCursorPositionChanged();2568 1973 } 2569 1974 } … … 2591 1996 QString str = e->mimeData()->text(); 2592 1997 2593 if (!str.isNull() && !d-> readOnly) {1998 if (!str.isNull() && !d->control->isReadOnly()) { 2594 1999 if (e->source() == this && e->dropAction() == Qt::CopyAction) 2595 2000 deselect(); 2596 d->cursor =d->xToPos(e->pos().x()); 2597 int selStart = d->cursor; 2598 int oldSelStart = d->selstart; 2599 int oldSelEnd = d->selend; 2001 int cursorPos = d->xToPos(e->pos().x()); 2002 int selStart = cursorPos; 2003 int oldSelStart = d->control->selectionStart(); 2004 int oldSelEnd = d->control->selectionEnd(); 2005 d->control->moveCursor(cursorPos, false); 2600 2006 d->cursorVisible = false; 2601 2007 e->acceptProposedAction(); … … 2619 2025 } 2620 2026 2621 void QLineEditPrivate::drag()2622 {2623 Q_Q(QLineEdit);2624 dndTimer.stop();2625 QMimeData *data = new QMimeData;2626 data->setText(q->selectedText());2627 QDrag *drag = new QDrag(q);2628 drag->setMimeData(data);2629 Qt::DropAction action = drag->start();2630 if (action == Qt::MoveAction && !readOnly && drag->target() != q) {2631 int priorState = undoState;2632 removeSelectedText();2633 finishChange(priorState);2634 }2635 }2636 2637 2027 #endif // QT_NO_DRAGANDDROP 2638 2028 … … 2677 2067 QMenu *popup = new QMenu(this); 2678 2068 popup->setObjectName(QLatin1String("qt_edit_menu")); 2679 2680 QAction *action = popup->addAction(QLineEdit::tr("&Undo") + ACCEL_KEY(QKeySequence::Undo)); 2681 action->setEnabled(d->isUndoAvailable()); 2682 connect(action, SIGNAL(triggered()), SLOT(undo())); 2683 2684 action = popup->addAction(QLineEdit::tr("&Redo") + ACCEL_KEY(QKeySequence::Redo)); 2685 action->setEnabled(d->isRedoAvailable()); 2686 connect(action, SIGNAL(triggered()), SLOT(redo())); 2687 2688 popup->addSeparator(); 2069 QAction *action = 0; 2070 2071 if (!isReadOnly()) { 2072 action = popup->addAction(QLineEdit::tr("&Undo") + ACCEL_KEY(QKeySequence::Undo)); 2073 action->setEnabled(d->control->isUndoAvailable()); 2074 connect(action, SIGNAL(triggered()), SLOT(undo())); 2075 2076 action = popup->addAction(QLineEdit::tr("&Redo") + ACCEL_KEY(QKeySequence::Redo)); 2077 action->setEnabled(d->control->isRedoAvailable()); 2078 connect(action, SIGNAL(triggered()), SLOT(redo())); 2079 2080 popup->addSeparator(); 2081 } 2689 2082 2690 2083 #ifndef QT_NO_CLIPBOARD 2691 action = popup->addAction(QLineEdit::tr("Cu&t") + ACCEL_KEY(QKeySequence::Cut)); 2692 action->setEnabled(!d->readOnly && d->hasSelectedText()); 2693 connect(action, SIGNAL(triggered()), SLOT(cut())); 2084 if (!isReadOnly()) { 2085 action = popup->addAction(QLineEdit::tr("Cu&t") + ACCEL_KEY(QKeySequence::Cut)); 2086 action->setEnabled(!d->control->isReadOnly() && d->control->hasSelectedText() 2087 && d->control->echoMode() == QLineEdit::Normal); 2088 connect(action, SIGNAL(triggered()), SLOT(cut())); 2089 } 2694 2090 2695 2091 action = popup->addAction(QLineEdit::tr("&Copy") + ACCEL_KEY(QKeySequence::Copy)); 2696 action->setEnabled(d->hasSelectedText()); 2092 action->setEnabled(d->control->hasSelectedText() 2093 && d->control->echoMode() == QLineEdit::Normal); 2697 2094 connect(action, SIGNAL(triggered()), SLOT(copy())); 2698 2095 2699 action = popup->addAction(QLineEdit::tr("&Paste") + ACCEL_KEY(QKeySequence::Paste)); 2700 action->setEnabled(!d->readOnly && !QApplication::clipboard()->text().isEmpty()); 2701 connect(action, SIGNAL(triggered()), SLOT(paste())); 2702 #endif 2703 2704 action = popup->addAction(QLineEdit::tr("Delete")); 2705 action->setEnabled(!d->readOnly && !d->text.isEmpty() && d->hasSelectedText()); 2706 connect(action, SIGNAL(triggered()), SLOT(_q_deleteSelected())); 2707 2708 popup->addSeparator(); 2096 if (!isReadOnly()) { 2097 action = popup->addAction(QLineEdit::tr("&Paste") + ACCEL_KEY(QKeySequence::Paste)); 2098 action->setEnabled(!d->control->isReadOnly() && !QApplication::clipboard()->text().isEmpty()); 2099 connect(action, SIGNAL(triggered()), SLOT(paste())); 2100 } 2101 #endif 2102 2103 if (!isReadOnly()) { 2104 action = popup->addAction(QLineEdit::tr("Delete")); 2105 action->setEnabled(!d->control->isReadOnly() && !d->control->text().isEmpty() && d->control->hasSelectedText()); 2106 connect(action, SIGNAL(triggered()), d->control, SLOT(_q_deleteSelected())); 2107 } 2108 2109 if (!popup->isEmpty()) 2110 popup->addSeparator(); 2709 2111 2710 2112 action = popup->addAction(QLineEdit::tr("Select All") + ACCEL_KEY(QKeySequence::SelectAll)); 2711 action->setEnabled(!d-> text.isEmpty() && !d->allSelected());2113 action->setEnabled(!d->control->text().isEmpty() && !d->control->allSelected()); 2712 2114 d->selectAllAction = action; 2713 2115 connect(action, SIGNAL(triggered()), SLOT(selectAll())); … … 2723 2125 2724 2126 #if defined(Q_WS_WIN) 2725 if (!d-> readOnly&& qt_use_rtl_extensions) {2127 if (!d->control->isReadOnly() && qt_use_rtl_extensions) { 2726 2128 #else 2727 if (!d-> readOnly) {2129 if (!d->control->isReadOnly()) { 2728 2130 #endif 2729 2131 popup->addSeparator(); … … 2739 2141 { 2740 2142 Q_D(QLineEdit); 2741 if(ev->type() == QEvent::ActivationChange) { 2143 switch(ev->type()) 2144 { 2145 case QEvent::ActivationChange: 2742 2146 if (!palette().isEqual(QPalette::Active, QPalette::Inactive)) 2743 2147 update(); 2744 } else if (ev->type() == QEvent::FontChange 2745 || ev->type() == QEvent::StyleChange 2746 || ev->type() == QEvent::LayoutDirectionChange) { 2747 d->updateTextLayout(); 2748 } 2749 QWidget::changeEvent(ev); 2750 } 2751 2752 void QLineEditPrivate::_q_clipboardChanged() 2753 { 2754 } 2755 2756 void QLineEditPrivate::_q_handleWindowActivate() 2757 { 2758 Q_Q(QLineEdit); 2759 if (!q->hasFocus() && q->hasSelectedText()) 2760 q->deselect(); 2761 } 2762 2763 void QLineEditPrivate::_q_deleteSelected() 2764 { 2765 Q_Q(QLineEdit); 2766 if (!hasSelectedText()) 2767 return; 2768 2769 int priorState = undoState; 2770 q->resetInputContext(); 2771 removeSelectedText(); 2772 separate(); 2773 finishChange(priorState); 2774 } 2775 2776 void QLineEditPrivate::init(const QString& txt) 2777 { 2778 Q_Q(QLineEdit); 2779 #ifndef QT_NO_CURSOR 2780 q->setCursor(Qt::IBeamCursor); 2781 #endif 2782 q->setFocusPolicy(Qt::StrongFocus); 2783 q->setAttribute(Qt::WA_InputMethodEnabled); 2784 // Specifies that this widget can use more, but is able to survive on 2785 // less, horizontal space; and is fixed vertically. 2786 q->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed, QSizePolicy::LineEdit)); 2787 q->setBackgroundRole(QPalette::Base); 2788 q->setAttribute(Qt::WA_KeyCompression); 2789 q->setMouseTracking(true); 2790 q->setAcceptDrops(true); 2791 text = txt; 2792 updateTextLayout(); 2793 cursor = text.length(); 2794 2795 q->setAttribute(Qt::WA_MacShowFocusRect); 2796 } 2797 2798 void QLineEditPrivate::updatePasswordEchoEditing(bool editing) 2799 { 2800 Q_Q(QLineEdit); 2801 passwordEchoEditing = editing; 2802 q->setAttribute(Qt::WA_InputMethodEnabled, shouldEnableInputMethod(q)); 2803 updateTextLayout(); 2804 q->update(); 2805 } 2806 2807 void QLineEditPrivate::updateTextLayout() 2808 { 2809 // replace certain non-printable characters with spaces (to avoid 2810 // drawing boxes when using fonts that don't have glyphs for such 2811 // characters) 2812 Q_Q(QLineEdit); 2813 QString str = q->displayText(); 2814 QChar* uc = str.data(); 2815 for (int i = 0; i < (int)str.length(); ++i) { 2816 if ((uc[i] < 0x20 && uc[i] != 0x09) 2817 || uc[i] == QChar::LineSeparator 2818 || uc[i] == QChar::ParagraphSeparator 2819 || uc[i] == QChar::ObjectReplacementCharacter) 2820 uc[i] = QChar(0x0020); 2821 } 2822 textLayout.setFont(q->font()); 2823 textLayout.setText(str); 2824 QTextOption option; 2825 option.setTextDirection(q->layoutDirection()); 2826 option.setFlags(QTextOption::IncludeTrailingSpaces); 2827 textLayout.setTextOption(option); 2828 2829 textLayout.beginLayout(); 2830 QTextLine l = textLayout.createLine(); 2831 textLayout.endLayout(); 2832 ascent = qRound(l.ascent()); 2833 } 2834 2835 int QLineEditPrivate::xToPos(int x, QTextLine::CursorPosition betweenOrOn) const 2836 { 2837 QRect cr = adjustedContentsRect(); 2838 x-= cr.x() - hscroll + horizontalMargin; 2839 QTextLine l = textLayout.lineAt(0); 2840 return l.xToCursor(x, betweenOrOn); 2841 } 2842 2843 QRect QLineEditPrivate::cursorRect() const 2844 { 2845 Q_Q(const QLineEdit); 2846 QRect cr = adjustedContentsRect(); 2847 int cix = cr.x() - hscroll + horizontalMargin; 2848 QTextLine l = textLayout.lineAt(0); 2849 int c = cursor; 2850 if (preeditCursor != -1) 2851 c += preeditCursor; 2852 cix += qRound(l.cursorToX(c)); 2853 int ch = qMin(cr.height(), q->fontMetrics().height() + 1); 2854 int w = q->style()->pixelMetric(QStyle::PM_TextCursorWidth); 2855 return QRect(cix-5, vscroll, w + 9, ch); 2856 } 2857 2858 QRect QLineEditPrivate::adjustedContentsRect() const 2859 { 2860 Q_Q(const QLineEdit); 2861 QStyleOptionFrameV2 opt; 2862 q->initStyleOption(&opt); 2863 QRect r = q->style()->subElementRect(QStyle::SE_LineEditContents, &opt, q); 2864 r.setX(r.x() + leftTextMargin); 2865 r.setY(r.y() + topTextMargin); 2866 r.setRight(r.right() - rightTextMargin); 2867 r.setBottom(r.bottom() - bottomTextMargin); 2868 return r; 2869 } 2870 2871 bool QLineEditPrivate::fixup() // this function assumes that validate currently returns != Acceptable 2872 { 2873 #ifndef QT_NO_VALIDATOR 2874 if (validator) { 2875 QString textCopy = text; 2876 int cursorCopy = cursor; 2877 validator->fixup(textCopy); 2878 if (validator->validate(textCopy, cursorCopy) == QValidator::Acceptable) { 2879 if (textCopy != text || cursorCopy != cursor) 2880 setText(textCopy, cursorCopy); 2881 return true; 2148 break; 2149 case QEvent::FontChange: 2150 d->control->setFont(font()); 2151 break; 2152 case QEvent::StyleChange: 2153 { 2154 QStyleOptionFrameV2 opt; 2155 initStyleOption(&opt); 2156 d->control->setPasswordCharacter(style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, &opt, this)); 2882 2157 } 2883 } 2884 #endif 2885 return false; 2886 } 2887 2888 void QLineEditPrivate::moveCursor(int pos, bool mark) 2889 { 2890 Q_Q(QLineEdit); 2891 if (pos != cursor) { 2892 separate(); 2893 if (maskData) 2894 pos = pos > cursor ? nextMaskBlank(pos) : prevMaskBlank(pos); 2895 } 2896 bool fullUpdate = mark || hasSelectedText(); 2897 if (mark) { 2898 int anchor; 2899 if (selend > selstart && cursor == selstart) 2900 anchor = selend; 2901 else if (selend > selstart && cursor == selend) 2902 anchor = selstart; 2903 else 2904 anchor = cursor; 2905 selstart = qMin(anchor, pos); 2906 selend = qMax(anchor, pos); 2907 updateTextLayout(); 2908 } else { 2909 deselect(); 2910 } 2911 if (fullUpdate) { 2912 cursor = pos; 2913 q->update(); 2914 } else { 2915 setCursorVisible(false); 2916 cursor = pos; 2917 setCursorVisible(true); 2918 if (!adjustedContentsRect().contains(cursorRect())) 2919 q->update(); 2920 } 2921 QStyleOptionFrameV2 opt; 2922 q->initStyleOption(&opt); 2923 if (mark && !q->style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, q)) 2924 setCursorVisible(false); 2925 if (mark || selDirty) { 2926 selDirty = false; 2927 emit q->selectionChanged(); 2928 } 2929 emitCursorPositionChanged(); 2930 } 2931 2932 void QLineEditPrivate::finishChange(int validateFromState, bool update, bool edited) 2933 { 2934 Q_Q(QLineEdit); 2935 bool lineDirty = selDirty; 2936 if (textDirty) { 2937 // do validation 2938 bool wasValidInput = validInput; 2939 validInput = true; 2940 #ifndef QT_NO_VALIDATOR 2941 if (validator) { 2942 validInput = false; 2943 QString textCopy = text; 2944 int cursorCopy = cursor; 2945 validInput = (validator->validate(textCopy, cursorCopy) != QValidator::Invalid); 2946 if (validInput) { 2947 if (text != textCopy) { 2948 setText(textCopy, cursorCopy); 2949 return; 2950 } 2951 cursor = cursorCopy; 2952 } 2953 } 2954 #endif 2955 if (validateFromState >= 0 && wasValidInput && !validInput) { 2956 undo(validateFromState); 2957 history.resize(undoState); 2958 if (modifiedState > undoState) 2959 modifiedState = -1; 2960 validInput = true; 2961 textDirty = false; 2962 } 2963 updateTextLayout(); 2964 lineDirty |= textDirty; 2965 if (textDirty) { 2966 textDirty = false; 2967 QString actualText = maskData ? stripString(text) : text; 2968 if (edited) 2969 emit q->textEdited(actualText); 2970 q->updateMicroFocus(); 2971 #ifndef QT_NO_COMPLETER 2972 if (edited && completer && completer->completionMode() != QCompleter::InlineCompletion) 2973 complete(-1); // update the popup on cut/paste/del 2974 #endif 2975 emit q->textChanged(actualText); 2976 } 2977 #ifndef QT_NO_ACCESSIBILITY 2978 QAccessible::updateAccessibility(q, 0, QAccessible::ValueChanged); 2979 #endif 2980 } 2981 if (selDirty) { 2982 selDirty = false; 2983 emit q->selectionChanged(); 2984 } 2985 if (lineDirty || update) 2986 q->update(); 2987 emitCursorPositionChanged(); 2988 } 2989 2990 void QLineEditPrivate::emitCursorPositionChanged() 2991 { 2992 Q_Q(QLineEdit); 2993 if (cursor != lastCursorPos) { 2994 const int oldLast = lastCursorPos; 2995 lastCursorPos = cursor; 2996 emit q->cursorPositionChanged(oldLast, cursor); 2997 } 2998 } 2999 3000 void QLineEditPrivate::setText(const QString& txt, int pos, bool edited) 3001 { 3002 Q_Q(QLineEdit); 3003 q->resetInputContext(); 3004 deselect(); 3005 QString oldText = text; 3006 if (maskData) { 3007 text = maskString(0, txt, true); 3008 text += clearString(text.length(), maxLength - text.length()); 3009 } else { 3010 text = txt.isEmpty() ? txt : txt.left(maxLength); 3011 } 3012 history.clear(); 3013 modifiedState = undoState = 0; 3014 cursor = (pos < 0 || pos > text.length()) ? text.length() : pos; 3015 textDirty = (oldText != text); 3016 finishChange(-1, true, edited); 3017 } 3018 3019 3020 void QLineEditPrivate::setCursorVisible(bool visible) 3021 { 3022 Q_Q(QLineEdit); 3023 if ((bool)cursorVisible == visible) 3024 return; 3025 if (cursorTimer) 3026 cursorVisible = visible; 3027 QRect r = cursorRect(); 3028 if (maskData) 3029 q->update(); 3030 else 3031 q->update(r); 3032 } 3033 3034 void QLineEditPrivate::addCommand(const Command& cmd) 3035 { 3036 if (separator && undoState && history[undoState-1].type != Separator) { 3037 history.resize(undoState + 2); 3038 history[undoState++] = Command(Separator, cursor, 0, selstart, selend); 3039 } else { 3040 history.resize(undoState + 1); 3041 } 3042 separator = false; 3043 history[undoState++] = cmd; 3044 } 3045 3046 void QLineEditPrivate::insert(const QString& s) 3047 { 3048 if (hasSelectedText()) 3049 addCommand(Command(SetSelection, cursor, 0, selstart, selend)); 3050 if (maskData) { 3051 QString ms = maskString(cursor, s); 3052 for (int i = 0; i < (int) ms.length(); ++i) { 3053 addCommand (Command(DeleteSelection, cursor+i, text.at(cursor+i), -1, -1)); 3054 addCommand(Command(Insert, cursor+i, ms.at(i), -1, -1)); 3055 } 3056 text.replace(cursor, ms.length(), ms); 3057 cursor += ms.length(); 3058 cursor = nextMaskBlank(cursor); 3059 textDirty = true; 3060 } else { 3061 int remaining = maxLength - text.length(); 3062 if (remaining != 0) { 3063 text.insert(cursor, s.left(remaining)); 3064 for (int i = 0; i < (int) s.left(remaining).length(); ++i) 3065 addCommand(Command(Insert, cursor++, s.at(i), -1, -1)); 3066 textDirty = true; 3067 } 3068 } 3069 } 3070 3071 void QLineEditPrivate::del(bool wasBackspace) 3072 { 3073 if (cursor < (int) text.length()) { 3074 if (hasSelectedText()) 3075 addCommand(Command(SetSelection, cursor, 0, selstart, selend)); 3076 addCommand (Command((CommandType)((maskData?2:0)+(wasBackspace?Remove:Delete)), cursor, text.at(cursor), -1, -1)); 3077 if (maskData) { 3078 text.replace(cursor, 1, clearString(cursor, 1)); 3079 addCommand(Command(Insert, cursor, text.at(cursor), -1, -1)); 3080 } else { 3081 text.remove(cursor, 1); 3082 } 3083 textDirty = true; 3084 } 3085 } 3086 3087 void QLineEditPrivate::removeSelectedText() 3088 { 3089 if (selstart < selend && selend <= (int) text.length()) { 3090 separate(); 3091 int i ; 3092 addCommand(Command(SetSelection, cursor, 0, selstart, selend)); 3093 if (selstart <= cursor && cursor < selend) { 3094 // cursor is within the selection. Split up the commands 3095 // to be able to restore the correct cursor position 3096 for (i = cursor; i >= selstart; --i) 3097 addCommand (Command(DeleteSelection, i, text.at(i), -1, 1)); 3098 for (i = selend - 1; i > cursor; --i) 3099 addCommand (Command(DeleteSelection, i - cursor + selstart - 1, text.at(i), -1, -1)); 3100 } else { 3101 for (i = selend-1; i >= selstart; --i) 3102 addCommand (Command(RemoveSelection, i, text.at(i), -1, -1)); 3103 } 3104 if (maskData) { 3105 text.replace(selstart, selend - selstart, clearString(selstart, selend - selstart)); 3106 for (int i = 0; i < selend - selstart; ++i) 3107 addCommand(Command(Insert, selstart + i, text.at(selstart + i), -1, -1)); 3108 } else { 3109 text.remove(selstart, selend - selstart); 3110 } 3111 if (cursor > selstart) 3112 cursor -= qMin(cursor, selend) - selstart; 3113 deselect(); 3114 textDirty = true; 3115 3116 // adjust hscroll to avoid gap 3117 const int minRB = qMax(0, -q_func()->fontMetrics().minRightBearing()); 3118 updateTextLayout(); 3119 const QTextLine line = textLayout.lineAt(0); 3120 const int widthUsed = qRound(line.naturalTextWidth()) + 1 + minRB; 3121 hscroll = qMin(hscroll, widthUsed); 3122 } 3123 } 3124 3125 void QLineEditPrivate::parseInputMask(const QString &maskFields) 3126 { 3127 int delimiter = maskFields.indexOf(QLatin1Char(';')); 3128 if (maskFields.isEmpty() || delimiter == 0) { 3129 if (maskData) { 3130 delete [] maskData; 3131 maskData = 0; 3132 maxLength = 32767; 3133 setText(QString()); 3134 } 3135 return; 3136 } 3137 3138 if (delimiter == -1) { 3139 blank = QLatin1Char(' '); 3140 inputMask = maskFields; 3141 } else { 3142 inputMask = maskFields.left(delimiter); 3143 blank = (delimiter + 1 < maskFields.length()) ? maskFields[delimiter + 1] : QLatin1Char(' '); 3144 } 3145 3146 // calculate maxLength / maskData length 3147 maxLength = 0; 3148 QChar c = 0; 3149 for (int i=0; i<inputMask.length(); i++) { 3150 c = inputMask.at(i); 3151 if (i > 0 && inputMask.at(i-1) == QLatin1Char('\\')) { 3152 maxLength++; 3153 continue; 3154 } 3155 if (c != QLatin1Char('\\') && c != QLatin1Char('!') && 3156 c != QLatin1Char('<') && c != QLatin1Char('>') && 3157 c != QLatin1Char('{') && c != QLatin1Char('}') && 3158 c != QLatin1Char('[') && c != QLatin1Char(']')) 3159 maxLength++; 3160 } 3161 3162 delete [] maskData; 3163 maskData = new MaskInputData[maxLength]; 3164 3165 MaskInputData::Casemode m = MaskInputData::NoCaseMode; 3166 c = 0; 3167 bool s; 3168 bool escape = false; 3169 int index = 0; 3170 for (int i = 0; i < inputMask.length(); i++) { 3171 c = inputMask.at(i); 3172 if (escape) { 3173 s = true; 3174 maskData[index].maskChar = c; 3175 maskData[index].separator = s; 3176 maskData[index].caseMode = m; 3177 index++; 3178 escape = false; 3179 } else if (c == QLatin1Char('<')) { 3180 m = MaskInputData::Lower; 3181 } else if (c == QLatin1Char('>')) { 3182 m = MaskInputData::Upper; 3183 } else if (c == QLatin1Char('!')) { 3184 m = MaskInputData::NoCaseMode; 3185 } else if (c != QLatin1Char('{') && c != QLatin1Char('}') && c != QLatin1Char('[') && c != QLatin1Char(']')) { 3186 switch (c.unicode()) { 3187 case 'A': 3188 case 'a': 3189 case 'N': 3190 case 'n': 3191 case 'X': 3192 case 'x': 3193 case '9': 3194 case '0': 3195 case 'D': 3196 case 'd': 3197 case '#': 3198 case 'H': 3199 case 'h': 3200 case 'B': 3201 case 'b': 3202 s = false; 3203 break; 3204 case '\\': 3205 escape = true; 3206 default: 3207 s = true; 3208 break; 3209 } 3210 3211 if (!escape) { 3212 maskData[index].maskChar = c; 3213 maskData[index].separator = s; 3214 maskData[index].caseMode = m; 3215 index++; 3216 } 3217 } 3218 } 3219 setText(text); 3220 } 3221 3222 3223 /* checks if the key is valid compared to the inputMask */ 3224 bool QLineEditPrivate::isValidInput(QChar key, QChar mask) const 3225 { 3226 switch (mask.unicode()) { 3227 case 'A': 3228 if (key.isLetter()) 3229 return true; 2158 update(); 3230 2159 break; 3231 case 'a': 3232 if (key.isLetter() || key == blank) 3233 return true; 3234 break; 3235 case 'N': 3236 if (key.isLetterOrNumber()) 3237 return true; 3238 break; 3239 case 'n': 3240 if (key.isLetterOrNumber() || key == blank) 3241 return true; 3242 break; 3243 case 'X': 3244 if (key.isPrint()) 3245 return true; 3246 break; 3247 case 'x': 3248 if (key.isPrint() || key == blank) 3249 return true; 3250 break; 3251 case '9': 3252 if (key.isNumber()) 3253 return true; 3254 break; 3255 case '0': 3256 if (key.isNumber() || key == blank) 3257 return true; 3258 break; 3259 case 'D': 3260 if (key.isNumber() && key.digitValue() > 0) 3261 return true; 3262 break; 3263 case 'd': 3264 if ((key.isNumber() && key.digitValue() > 0) || key == blank) 3265 return true; 3266 break; 3267 case '#': 3268 if (key.isNumber() || key == QLatin1Char('+') || key == QLatin1Char('-') || key == blank) 3269 return true; 3270 break; 3271 case 'B': 3272 if (key == QLatin1Char('0') || key == QLatin1Char('1')) 3273 return true; 3274 break; 3275 case 'b': 3276 if (key == QLatin1Char('0') || key == QLatin1Char('1') || key == blank) 3277 return true; 3278 break; 3279 case 'H': 3280 if (key.isNumber() || (key >= QLatin1Char('a') && key <= QLatin1Char('f')) || (key >= QLatin1Char('A') && key <= QLatin1Char('F'))) 3281 return true; 3282 break; 3283 case 'h': 3284 if (key.isNumber() || (key >= QLatin1Char('a') && key <= QLatin1Char('f')) || (key >= QLatin1Char('A') && key <= QLatin1Char('F')) || key == blank) 3285 return true; 2160 case QEvent::LayoutDirectionChange: 2161 d->control->setLayoutDirection(layoutDirection()); 3286 2162 break; 3287 2163 default: 3288 2164 break; 3289 2165 } 3290 return false; 3291 } 3292 3293 bool QLineEditPrivate::hasAcceptableInput(const QString &str) const 3294 { 3295 #ifndef QT_NO_VALIDATOR 3296 QString textCopy = str; 3297 int cursorCopy = cursor; 3298 if (validator && validator->validate(textCopy, cursorCopy) 3299 != QValidator::Acceptable) 3300 return false; 3301 #endif 3302 3303 if (!maskData) 3304 return true; 3305 3306 if (str.length() != maxLength) 3307 return false; 3308 3309 for (int i=0; i < maxLength; ++i) { 3310 if (maskData[i].separator) { 3311 if (str.at(i) != maskData[i].maskChar) 3312 return false; 3313 } else { 3314 if (!isValidInput(str.at(i), maskData[i].maskChar)) 3315 return false; 3316 } 3317 } 3318 return true; 3319 } 3320 3321 /* 3322 Applies the inputMask on \a str starting from position \a pos in the mask. \a clear 3323 specifies from where characters should be gotten when a separator is met in \a str - true means 3324 that blanks will be used, false that previous input is used. 3325 Calling this when no inputMask is set is undefined. 3326 */ 3327 QString QLineEditPrivate::maskString(uint pos, const QString &str, bool clear) const 3328 { 3329 if (pos >= (uint)maxLength) 3330 return QString::fromLatin1(""); 3331 3332 QString fill; 3333 fill = clear ? clearString(0, maxLength) : text; 3334 3335 int strIndex = 0; 3336 QString s = QString::fromLatin1(""); 3337 int i = pos; 3338 while (i < maxLength) { 3339 if (strIndex < str.length()) { 3340 if (maskData[i].separator) { 3341 s += maskData[i].maskChar; 3342 if (str[(int)strIndex] == maskData[i].maskChar) 3343 strIndex++; 3344 ++i; 3345 } else { 3346 if (isValidInput(str[(int)strIndex], maskData[i].maskChar)) { 3347 switch (maskData[i].caseMode) { 3348 case MaskInputData::Upper: 3349 s += str[(int)strIndex].toUpper(); 3350 break; 3351 case MaskInputData::Lower: 3352 s += str[(int)strIndex].toLower(); 3353 break; 3354 default: 3355 s += str[(int)strIndex]; 3356 } 3357 ++i; 3358 } else { 3359 // search for separator first 3360 int n = findInMask(i, true, true, str[(int)strIndex]); 3361 if (n != -1) { 3362 if (str.length() != 1 || i == 0 || (i > 0 && (!maskData[i-1].separator || maskData[i-1].maskChar != str[(int)strIndex]))) { 3363 s += fill.mid(i, n-i+1); 3364 i = n + 1; // update i to find + 1 3365 } 3366 } else { 3367 // search for valid blank if not 3368 n = findInMask(i, true, false, str[(int)strIndex]); 3369 if (n != -1) { 3370 s += fill.mid(i, n-i); 3371 switch (maskData[n].caseMode) { 3372 case MaskInputData::Upper: 3373 s += str[(int)strIndex].toUpper(); 3374 break; 3375 case MaskInputData::Lower: 3376 s += str[(int)strIndex].toLower(); 3377 break; 3378 default: 3379 s += str[(int)strIndex]; 3380 } 3381 i = n + 1; // updates i to find + 1 3382 } 3383 } 3384 } 3385 strIndex++; 3386 } 3387 } else 3388 break; 3389 } 3390 3391 return s; 3392 } 3393 3394 3395 3396 /* 3397 Returns a "cleared" string with only separators and blank chars. 3398 Calling this when no inputMask is set is undefined. 3399 */ 3400 QString QLineEditPrivate::clearString(uint pos, uint len) const 3401 { 3402 if (pos >= (uint)maxLength) 3403 return QString(); 3404 3405 QString s; 3406 int end = qMin((uint)maxLength, pos + len); 3407 for (int i=pos; i<end; i++) 3408 if (maskData[i].separator) 3409 s += maskData[i].maskChar; 3410 else 3411 s += blank; 3412 3413 return s; 3414 } 3415 3416 /* 3417 Strips blank parts of the input in a QLineEdit when an inputMask is set, 3418 separators are still included. Typically "127.0__.0__.1__" becomes "127.0.0.1". 3419 */ 3420 QString QLineEditPrivate::stripString(const QString &str) const 3421 { 3422 if (!maskData) 3423 return str; 3424 3425 QString s; 3426 int end = qMin(maxLength, (int)str.length()); 3427 for (int i=0; i < end; i++) 3428 if (maskData[i].separator) 3429 s += maskData[i].maskChar; 3430 else 3431 if (str[i] != blank) 3432 s += str[i]; 3433 3434 return s; 3435 } 3436 3437 /* searches forward/backward in maskData for either a separator or a blank */ 3438 int QLineEditPrivate::findInMask(int pos, bool forward, bool findSeparator, QChar searchChar) const 3439 { 3440 if (pos >= maxLength || pos < 0) 3441 return -1; 3442 3443 int end = forward ? maxLength : -1; 3444 int step = forward ? 1 : -1; 3445 int i = pos; 3446 3447 while (i != end) { 3448 if (findSeparator) { 3449 if (maskData[i].separator && maskData[i].maskChar == searchChar) 3450 return i; 3451 } else { 3452 if (!maskData[i].separator) { 3453 if (searchChar.isNull()) 3454 return i; 3455 else if (isValidInput(searchChar, maskData[i].maskChar)) 3456 return i; 3457 } 3458 } 3459 i += step; 3460 } 3461 return -1; 3462 } 3463 3464 void QLineEditPrivate::undo(int until) 3465 { 3466 if (!isUndoAvailable()) 3467 return; 3468 deselect(); 3469 while (undoState && undoState > until) { 3470 Command& cmd = history[--undoState]; 3471 switch (cmd.type) { 3472 case Insert: 3473 text.remove(cmd.pos, 1); 3474 cursor = cmd.pos; 3475 break; 3476 case SetSelection: 3477 selstart = cmd.selStart; 3478 selend = cmd.selEnd; 3479 cursor = cmd.pos; 3480 break; 3481 case Remove: 3482 case RemoveSelection: 3483 text.insert(cmd.pos, cmd.uc); 3484 cursor = cmd.pos + 1; 3485 break; 3486 case Delete: 3487 case DeleteSelection: 3488 text.insert(cmd.pos, cmd.uc); 3489 cursor = cmd.pos; 3490 break; 3491 case Separator: 3492 continue; 3493 } 3494 if (until < 0 && undoState) { 3495 Command& next = history[undoState-1]; 3496 if (next.type != cmd.type && next.type < RemoveSelection 3497 && (cmd.type < RemoveSelection || next.type == Separator)) 3498 break; 3499 } 3500 } 3501 textDirty = true; 3502 emitCursorPositionChanged(); 3503 } 3504 3505 void QLineEditPrivate::redo() { 3506 if (!isRedoAvailable()) 3507 return; 3508 deselect(); 3509 while (undoState < (int)history.size()) { 3510 Command& cmd = history[undoState++]; 3511 switch (cmd.type) { 3512 case Insert: 3513 text.insert(cmd.pos, cmd.uc); 3514 cursor = cmd.pos + 1; 3515 break; 3516 case SetSelection: 3517 selstart = cmd.selStart; 3518 selend = cmd.selEnd; 3519 cursor = cmd.pos; 3520 break; 3521 case Remove: 3522 case Delete: 3523 case RemoveSelection: 3524 case DeleteSelection: 3525 text.remove(cmd.pos, 1); 3526 cursor = cmd.pos; 3527 break; 3528 case Separator: 3529 selstart = cmd.selStart; 3530 selend = cmd.selEnd; 3531 cursor = cmd.pos; 3532 break; 3533 } 3534 if (undoState < (int)history.size()) { 3535 Command& next = history[undoState]; 3536 if (next.type != cmd.type && cmd.type < RemoveSelection && next.type != Separator 3537 && (next.type < RemoveSelection || cmd.type == Separator)) 3538 break; 3539 } 3540 } 3541 textDirty = true; 3542 emitCursorPositionChanged(); 2166 QWidget::changeEvent(ev); 3543 2167 } 3544 2168 … … 3674 2298 /*! 3675 2299 \fn int QLineEdit::margin() const 3676 Returns the wi th of thethe margin around the contents of the widget.2300 Returns the width of the margin around the contents of the widget. 3677 2301 3678 2302 Use QWidget::getContentsMargins() instead. -
trunk/src/gui/widgets/qlineedit.h
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 ** … … 45 45 #include <QtGui/qframe.h> 46 46 #include <QtCore/qstring.h> 47 #include <QtCore/qmargins.h> 47 48 48 49 QT_BEGIN_HEADER … … 83 84 Q_PROPERTY(bool redoAvailable READ isRedoAvailable) 84 85 Q_PROPERTY(bool acceptableInput READ hasAcceptableInput) 86 // ### Qt 4.7: remove this #if guard 87 #if (QT_VERSION >= 0x407000) || defined(Q_WS_MAEMO_5) 88 Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText) 89 #endif 85 90 86 91 public: … … 97 102 98 103 QString displayText() const; 104 105 // ### Qt 4.7: remove this #if guard 106 #if (QT_VERSION >= 0x407000) || defined(Q_WS_MAEMO_5) 107 QString placeholderText() const; 108 void setPlaceholderText(const QString &); 109 #endif 99 110 100 111 int maxLength() const; … … 159 170 160 171 void setTextMargins(int left, int top, int right, int bottom); 172 void setTextMargins(const QMargins &margins); 161 173 void getTextMargins(int *left, int *top, int *right, int *bottom) const; 174 QMargins textMargins() const; 162 175 163 176 public Q_SLOTS: … … 267 280 Q_DISABLE_COPY(QLineEdit) 268 281 Q_DECLARE_PRIVATE(QLineEdit) 269 Q_PRIVATE_SLOT(d_func(), void _q_clipboardChanged())270 282 Q_PRIVATE_SLOT(d_func(), void _q_handleWindowActivate()) 271 Q_PRIVATE_SLOT(d_func(), void _q_deleteSelected()) 283 Q_PRIVATE_SLOT(d_func(), void _q_textEdited(const QString &)) 284 Q_PRIVATE_SLOT(d_func(), void _q_cursorPositionChanged(int, int)) 272 285 #ifndef QT_NO_COMPLETER 273 286 Q_PRIVATE_SLOT(d_func(), void _q_completionHighlighted(QString)) 274 287 #endif 288 #ifdef QT_KEYPAD_NAVIGATION 289 Q_PRIVATE_SLOT(d_func(), void _q_editFocusChange(bool)) 290 #endif 291 Q_PRIVATE_SLOT(d_func(), void _q_selectionChanged()) 275 292 }; 276 293 -
trunk/src/gui/widgets/qlineedit_p.h
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 ** … … 66 66 #include "QtGui/qlineedit.h" 67 67 68 #include "private/qlinecontrol_p.h" 69 68 70 QT_BEGIN_NAMESPACE 69 71 … … 74 76 75 77 QLineEditPrivate() 76 : cursor(0), preeditCursor(0), cursorTimer(0), frame(1), 77 cursorVisible(0), hideCursor(false), separator(0), readOnly(0), 78 dragEnabled(0), contextMenuEnabled(1), echoMode(0), textDirty(0), 79 selDirty(0), validInput(1), alignment(Qt::AlignLeading | Qt::AlignVCenter), ascent(0), 80 maxLength(32767), hscroll(0), vscroll(0), lastCursorPos(-1), maskData(0), 81 modifiedState(0), undoState(0), selstart(0), selend(0), userInput(false), 82 emitingEditingFinished(false), passwordEchoEditing(false) 83 #ifndef QT_NO_COMPLETER 84 , completer(0) 85 #endif 86 , leftTextMargin(0), topTextMargin(0), rightTextMargin(0), bottomTextMargin(0) 87 { 88 } 78 : control(0), frame(1), contextMenuEnabled(1), cursorVisible(0), 79 dragEnabled(0), clickCausedFocus(0), hscroll(0), vscroll(0), 80 alignment(Qt::AlignLeading | Qt::AlignVCenter), 81 leftTextMargin(0), topTextMargin(0), rightTextMargin(0), bottomTextMargin(0) 82 { 83 } 89 84 90 85 ~QLineEditPrivate() 91 86 { 92 delete [] maskData;87 delete control; 93 88 } 94 void init(const QString&);95 89 96 QString text; 97 int cursor; 98 int preeditCursor; 99 int cursorTimer; // -1 for non blinking cursor. 100 QPoint tripleClick; 101 QBasicTimer tripleClickTimer; 102 uint frame : 1; 103 uint cursorVisible : 1; 104 uint hideCursor : 1; // used to hide the cursor inside preedit areas 105 uint separator : 1; 106 uint readOnly : 1; 107 uint dragEnabled : 1; 108 uint contextMenuEnabled : 1; 109 uint echoMode : 2; 110 uint textDirty : 1; 111 uint selDirty : 1; 112 uint validInput : 1; 113 uint alignment; 114 int ascent; 115 int maxLength; 116 int hscroll; 117 int vscroll; 118 int lastCursorPos; 90 QLineControl *control; 119 91 120 92 #ifndef QT_NO_CONTEXTMENU 121 93 QPointer<QAction> selectAllAction; 122 94 #endif 95 void init(const QString&); 123 96 124 inline void emitCursorPositionChanged(); 125 bool sendMouseEventToInputContext(QMouseEvent *e); 97 int xToPos(int x, QTextLine::CursorPosition = QTextLine::CursorBetweenCharacters) const; 98 QRect cursorRect() const; 99 void setCursorVisible(bool visible); 126 100 127 void finishChange(int validateFromState = -1, bool update = false, bool edited = true);101 void updatePasswordEchoEditing(bool); 128 102 129 QPointer<QValidator> validator; 130 struct MaskInputData { 131 enum Casemode { NoCaseMode, Upper, Lower }; 132 QChar maskChar; // either the separator char or the inputmask 133 bool separator; 134 Casemode caseMode; 135 }; 136 QString inputMask; 137 QChar blank; 138 MaskInputData *maskData; 139 inline int nextMaskBlank(int pos) { 140 int c = findInMask(pos, true, false); 141 separator |= (c != pos); 142 return (c != -1 ? c : maxLength); 143 } 144 inline int prevMaskBlank(int pos) { 145 int c = findInMask(pos, false, false); 146 separator |= (c != pos); 147 return (c != -1 ? c : 0); 103 inline bool shouldEnableInputMethod() const 104 { 105 return !control->isReadOnly(); 148 106 } 149 107 150 void setCursorVisible(bool visible); 108 QPoint tripleClick; 109 QBasicTimer tripleClickTimer; 110 uint frame : 1; 111 uint contextMenuEnabled : 1; 112 uint cursorVisible : 1; 113 uint dragEnabled : 1; 114 uint clickCausedFocus : 1; 115 int hscroll; 116 int vscroll; 117 uint alignment; 118 static const int verticalMargin; 119 static const int horizontalMargin; 151 120 152 153 // undo/redo handling 154 enum CommandType { Separator, Insert, Remove, Delete, RemoveSelection, DeleteSelection, SetSelection }; 155 struct Command { 156 inline Command() {} 157 inline Command(CommandType t, int p, QChar c, int ss, int se) : type(t),uc(c),pos(p),selStart(ss),selEnd(se) {} 158 uint type : 4; 159 QChar uc; 160 int pos, selStart, selEnd; 161 }; 162 int modifiedState; 163 int undoState; 164 QVector<Command> history; 165 void addCommand(const Command& cmd); 166 void insert(const QString& s); 167 void del(bool wasBackspace = false); 168 void remove(int pos); 169 170 inline void separate() { separator = true; } 171 void undo(int until = -1); 172 void redo(); 173 inline bool isUndoAvailable() const { return !readOnly && undoState; } 174 inline bool isRedoAvailable() const { return !readOnly && undoState < (int)history.size(); } 175 176 // selection 177 int selstart, selend; 178 inline bool allSelected() const { return !text.isEmpty() && selstart == 0 && selend == (int)text.length(); } 179 inline bool hasSelectedText() const { return !text.isEmpty() && selend > selstart; } 180 inline void deselect() { selDirty |= (selend > selstart); selstart = selend = 0; } 181 void removeSelectedText(); 182 #ifndef QT_NO_CLIPBOARD 183 void copy(bool clipboard = true) const; 184 #endif 185 inline bool inSelection(int x) const 186 { if (selstart >= selend) return false; 187 int pos = xToPos(x, QTextLine::CursorOnCharacter); return pos >= selstart && pos < selend; } 188 189 // masking 190 void parseInputMask(const QString &maskFields); 191 bool isValidInput(QChar key, QChar mask) const; 192 bool hasAcceptableInput(const QString &text) const; 193 QString maskString(uint pos, const QString &str, bool clear = false) const; 194 QString clearString(uint pos, uint len) const; 195 QString stripString(const QString &str) const; 196 int findInMask(int pos, bool forward, bool findSeparator, QChar searchChar = QChar()) const; 197 198 // input methods 199 bool composeMode() const { return !textLayout.preeditAreaText().isEmpty(); } 200 201 // complex text layout 202 QTextLayout textLayout; 203 void updateTextLayout(); 204 void moveCursor(int pos, bool mark = false); 205 void setText(const QString& txt, int pos = -1, bool edited = true); 206 int xToPos(int x, QTextLine::CursorPosition = QTextLine::CursorBetweenCharacters) const; 207 QRect cursorRect() const; 208 bool fixup(); 121 bool sendMouseEventToInputContext(QMouseEvent *e); 209 122 210 123 QRect adjustedContentsRect() const; 211 124 125 void _q_handleWindowActivate(); 126 void _q_textEdited(const QString &); 127 void _q_cursorPositionChanged(int, int); 128 #ifdef QT_KEYPAD_NAVIGATION 129 void _q_editFocusChange(bool); 130 #endif 131 void _q_selectionChanged(); 132 #ifndef QT_NO_COMPLETER 133 void _q_completionHighlighted(QString); 134 #endif 212 135 #ifndef QT_NO_DRAGANDDROP 213 // drag and drop214 136 QPoint dndPos; 215 137 QBasicTimer dndTimer; 216 138 void drag(); 217 #endif218 219 void _q_clipboardChanged();220 void _q_handleWindowActivate();221 void _q_deleteSelected();222 bool userInput;223 bool emitingEditingFinished;224 225 #ifdef QT_KEYPAD_NAVIGATION226 QBasicTimer deleteAllTimer; // keypad navigation227 QString origText;228 #endif229 230 bool passwordEchoEditing;231 void updatePasswordEchoEditing(bool editing);232 233 #ifndef QT_NO_COMPLETER234 QPointer<QCompleter> completer;235 void complete(int key = -1);236 void _q_completionHighlighted(QString);237 bool advanceToEnabledItem(int n);238 139 #endif 239 140 … … 242 143 int rightTextMargin; 243 144 int bottomTextMargin; 145 146 QString placeholderText; 244 147 }; 245 148 -
trunk/src/gui/widgets/qmaccocoaviewcontainer_mac.h
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 ** -
trunk/src/gui/widgets/qmaccocoaviewcontainer_mac.mm
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 **40 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE41 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.42 39 ** 43 40 ****************************************************************************/ -
trunk/src/gui/widgets/qmacnativewidget_mac.h
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 ** … … 65 65 66 66 private: 67 Q_DECLARE_PRIVATE _D(QWidget::d_ptr,QMacNativeWidget)67 Q_DECLARE_PRIVATE(QMacNativeWidget) 68 68 }; 69 69 -
trunk/src/gui/widgets/qmacnativewidget_mac.mm
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 **40 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE41 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.42 39 ** 43 40 ****************************************************************************/ -
trunk/src/gui/widgets/qmainwindow.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 ** … … 66 66 QT_END_NAMESPACE 67 67 #endif 68 #ifdef QT_SOFTKEYS_ENABLED 69 #include <private/qsoftkeymanager_p.h> 70 #endif 68 71 69 72 QT_BEGIN_NAMESPACE … … 74 77 public: 75 78 inline QMainWindowPrivate() 76 : layout(0), toolButtonStyle(Qt::ToolButtonIconOnly)79 : layout(0), explicitIconSize(false), toolButtonStyle(Qt::ToolButtonIconOnly) 77 80 #ifdef Q_WS_MAC 78 81 , useHIToolBar(false) 82 #endif 83 #ifdef QT_SOFTKEYS_ENABLED 84 , menuBarAction(0) 79 85 #endif 80 86 #if !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_CURSOR) … … 89 95 bool useHIToolBar; 90 96 #endif 97 #ifdef QT_SOFTKEYS_ENABLED 98 QAction *menuBarAction; 99 #endif 91 100 void init(); 92 101 QList<int> hoverSeparator; … … 108 117 const int metric = q->style()->pixelMetric(QStyle::PM_ToolBarIconSize, 0, q); 109 118 iconSize = QSize(metric, metric); 110 explicitIconSize = false;111 112 119 q->setAttribute(Qt::WA_Hover); 120 #ifdef QT_SOFTKEYS_ENABLED 121 menuBarAction = QSoftKeyManager::createAction(QSoftKeyManager::MenuSoftKey, q); 122 menuBarAction->setObjectName(QLatin1String("_q_menuSoftKeyAction")); 123 menuBarAction->setVisible(false); 124 #endif 113 125 } 114 126 … … 149 161 \brief The QMainWindow class provides a main application 150 162 window. 151 \ingroup application152 \mainclass 163 \ingroup mainwindow-classes 164 153 165 154 166 \tableofcontents … … 481 493 oldMenuBar->deleteLater(); 482 494 } 483 #ifdef Q_OS_WINCE484 if (menuBar && menuBar->size().height() > 0)485 #endif486 495 d->layout->setMenuBar(menuBar); 496 497 #ifdef QT_SOFTKEYS_ENABLED 498 if (menuBar) 499 addAction(d->menuBarAction); 500 else 501 removeAction(d->menuBarAction); 502 #endif 487 503 } 488 504 … … 919 935 920 936 #ifndef QT_NO_TABBAR 921 /*! 937 /*! 922 938 \property QMainWindow::documentMode 923 939 \brief whether the tab bar for tabbed dockwidgets is set to document mode. … … 940 956 941 957 #ifndef QT_NO_TABWIDGET 942 /*! 958 /*! 943 959 \property QMainWindow::tabShape 944 960 \brief the tab shape used for tabbed dock widgets. … … 1033 1049 to restoreState(). Returns true if the state was restored; otherwise 1034 1050 returns false. 1051 1052 \sa restoreState(), saveState() 1035 1053 */ 1036 1054 … … 1164 1182 number to restoreState(). 1165 1183 1184 To save the geometry when the window closes, you can 1185 implement a close event like this: 1186 1187 \snippet doc/src/snippets/code/src_gui_widgets_qmainwindow.cpp 0 1188 1166 1189 \sa restoreState(), QWidget::saveGeometry(), QWidget::restoreGeometry() 1167 1190 */ … … 1183 1206 is restored, and this function returns \c true. 1184 1207 1185 \sa saveState(), QWidget::saveGeometry(), QWidget::restoreGeometry() 1208 To restore geometry saved using QSettings, you can use code like 1209 this: 1210 1211 \snippet doc/src/snippets/code/src_gui_widgets_qmainwindow.cpp 1 1212 1213 \sa saveState(), QWidget::saveGeometry(), 1214 QWidget::restoreGeometry(), restoreDockWidget() 1186 1215 */ 1187 1216 bool QMainWindow::restoreState(const QByteArray &state, int version) … … 1373 1402 case QEvent::Show: 1374 1403 if (unifiedTitleAndToolBarOnMac()) 1375 macWindowToolbarShow(this, true); 1404 d->layout->syncUnifiedToolbarVisibility(); 1405 d->layout->blockVisiblityCheck = false; 1376 1406 break; 1377 # ifdef QT_MAC_USE_COCOA1378 1407 case QEvent::WindowStateChange: 1379 1408 { 1409 if (isHidden()) { 1410 // We are coming out of a minimize, leave things as is. 1411 d->layout->blockVisiblityCheck = true; 1412 } 1413 # ifdef QT_MAC_USE_COCOA 1380 1414 // We need to update the HIToolbar status when we go out of or into fullscreen. 1381 1415 QWindowStateChangeEvent *wce = static_cast<QWindowStateChangeEvent *>(event); … … 1383 1417 d->layout->updateHIToolBarStatus(); 1384 1418 } 1419 # endif // Cocoa 1385 1420 } 1386 1421 break; 1387 # endif // Cocoa 1388 #endif 1422 #endif // Q_WS_MAC 1389 1423 #if !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_CURSOR) 1390 1424 case QEvent::CursorChange: … … 1395 1429 break; 1396 1430 #endif 1397 1398 1431 default: 1399 1432 break; … … 1412 1445 This property is false by default and only has any effect on Mac OS X 10.4 or higher. 1413 1446 1414 If set to true, then the top toolbar area is replaced with a Carbon 1415 HIToolbar and all toolbars in the top toolbar area are moved to that. Any1416 toolbars added afterwards will also be added to the Carbon HIToolbar. This1417 m eans a couple of things.1447 If set to true, then the top toolbar area is replaced with a Carbon HIToolbar 1448 or a Cocoa NSToolbar (depending on whether Qt was built with Carbon or Cocoa). 1449 All toolbars in the top toolbar area and any toolbars added afterwards are 1450 moved to that. This means a couple of things. 1418 1451 1419 1452 \list … … 1423 1456 \i Any custom widgets in the toolbar will not be shown if the toolbar 1424 1457 becomes too small (only actions will be shown) 1425 \i If you call showFullScreen() on the main window, the QToolbar will 1426 disappear since it is considered to be part of the title bar. You can 1427 work around this by turning off the unified toolbar before you call 1458 \i Before Qt 4.5, if you called showFullScreen() on the main window, the QToolbar would 1459 disappear since it is considered to be part of the title bar. Qt 4.5 and up will now work around this by pulling 1460 the toolbars out and back into the regular toolbar and vice versa when you swap out. 1461 However, a good practice would be that turning off the unified toolbar before you call 1428 1462 showFullScreen() and restoring it after you call showNormal(). 1429 1463 \endlist -
trunk/src/gui/widgets/qmainwindow.h
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 ** -
trunk/src/gui/widgets/qmainwindowlayout.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 ** … … 238 238 QMainWindowLayout *layout = qobject_cast<QMainWindowLayout*>(mainWindow->layout()); 239 239 Q_ASSERT(layout != 0); 240 layout->widgetAnimator ->animate(centralWidgetItem->widget(), centralWidgetRect, animated);240 layout->widgetAnimator.animate(centralWidgetItem->widget(), centralWidgetRect, animated); 241 241 } 242 242 #endif … … 427 427 } 428 428 429 bool QMainWindowLayoutState::insertGap( QList<int>path, QLayoutItem *item)429 bool QMainWindowLayoutState::insertGap(const QList<int> &path, QLayoutItem *item) 430 430 { 431 431 if (path.isEmpty()) 432 432 return false; 433 433 434 int i = path. takeFirst();434 int i = path.first(); 435 435 436 436 #ifndef QT_NO_TOOLBAR 437 437 if (i == 0) { 438 438 Q_ASSERT(qobject_cast<QToolBar*>(item->widget()) != 0); 439 return toolBarAreaLayout.insertGap(path , item);439 return toolBarAreaLayout.insertGap(path.mid(1), item); 440 440 } 441 441 #endif … … 444 444 if (i == 1) { 445 445 Q_ASSERT(qobject_cast<QDockWidget*>(item->widget()) != 0); 446 return dockAreaLayout.insertGap(path , item);446 return dockAreaLayout.insertGap(path.mid(1), item); 447 447 } 448 448 #endif //QT_NO_DOCKWIDGET … … 451 451 } 452 452 453 void QMainWindowLayoutState::remove( QList<int>path)454 { 455 int i = path. takeFirst();453 void QMainWindowLayoutState::remove(const QList<int> &path) 454 { 455 int i = path.first(); 456 456 457 457 #ifndef QT_NO_TOOLBAR 458 458 if (i == 0) 459 toolBarAreaLayout.remove(path );459 toolBarAreaLayout.remove(path.mid(1)); 460 460 #endif 461 461 462 462 #ifndef QT_NO_DOCKWIDGET 463 463 if (i == 1) 464 dockAreaLayout.remove(path );464 dockAreaLayout.remove(path.mid(1)); 465 465 #endif //QT_NO_DOCKWIDGET 466 466 } … … 491 491 dockAreaLayout.clear(); 492 492 #else 493 centralWidgetRect = QRect( 0, 0, -1, -1);494 #endif 495 496 rect = QRect( 0, 0, -1, -1);493 centralWidgetRect = QRect(); 494 #endif 495 496 rect = QRect(); 497 497 } 498 498 … … 502 502 } 503 503 504 QLayoutItem *QMainWindowLayoutState::item( QList<int>path)505 { 506 int i = path. takeFirst();504 QLayoutItem *QMainWindowLayoutState::item(const QList<int> &path) 505 { 506 int i = path.first(); 507 507 508 508 #ifndef QT_NO_TOOLBAR 509 509 if (i == 0) 510 return toolBarAreaLayout.item(path ).widgetItem;510 return toolBarAreaLayout.item(path.mid(1)).widgetItem; 511 511 #endif 512 512 513 513 #ifndef QT_NO_DOCKWIDGET 514 514 if (i == 1) 515 return dockAreaLayout.item(path ).widgetItem;515 return dockAreaLayout.item(path.mid(1)).widgetItem; 516 516 #endif //QT_NO_DOCKWIDGET 517 517 … … 519 519 } 520 520 521 QRect QMainWindowLayoutState::itemRect( QList<int>path) const522 { 523 int i = path. takeFirst();521 QRect QMainWindowLayoutState::itemRect(const QList<int> &path) const 522 { 523 int i = path.first(); 524 524 525 525 #ifndef QT_NO_TOOLBAR 526 526 if (i == 0) 527 return toolBarAreaLayout.itemRect(path );527 return toolBarAreaLayout.itemRect(path.mid(1)); 528 528 #endif 529 529 530 530 #ifndef QT_NO_DOCKWIDGET 531 531 if (i == 1) 532 return dockAreaLayout.itemRect(path );532 return dockAreaLayout.itemRect(path.mid(1)); 533 533 #endif //QT_NO_DOCKWIDGET 534 534 … … 536 536 } 537 537 538 QRect QMainWindowLayoutState::gapRect( QList<int>path) const539 { 540 int i = path. takeFirst();538 QRect QMainWindowLayoutState::gapRect(const QList<int> &path) const 539 { 540 int i = path.first(); 541 541 542 542 #ifndef QT_NO_TOOLBAR 543 543 if (i == 0) 544 return toolBarAreaLayout.itemRect(path );544 return toolBarAreaLayout.itemRect(path.mid(1)); 545 545 #endif 546 546 547 547 #ifndef QT_NO_DOCKWIDGET 548 548 if (i == 1) 549 return dockAreaLayout.gapRect(path );549 return dockAreaLayout.gapRect(path.mid(1)); 550 550 #endif //QT_NO_DOCKWIDGET 551 551 … … 553 553 } 554 554 555 QLayoutItem *QMainWindowLayoutState::plug( QList<int>path)556 { 557 int i = path. takeFirst();555 QLayoutItem *QMainWindowLayoutState::plug(const QList<int> &path) 556 { 557 int i = path.first(); 558 558 559 559 #ifndef QT_NO_TOOLBAR 560 560 if (i == 0) 561 return toolBarAreaLayout.plug(path );561 return toolBarAreaLayout.plug(path.mid(1)); 562 562 #endif 563 563 564 564 #ifndef QT_NO_DOCKWIDGET 565 565 if (i == 1) 566 return dockAreaLayout.plug(path );566 return dockAreaLayout.plug(path.mid(1)); 567 567 #endif //QT_NO_DOCKWIDGET 568 568 … … 570 570 } 571 571 572 QLayoutItem *QMainWindowLayoutState::unplug( QList<int>path, QMainWindowLayoutState *other)573 { 574 int i = path. takeFirst();572 QLayoutItem *QMainWindowLayoutState::unplug(const QList<int> &path, QMainWindowLayoutState *other) 573 { 574 int i = path.first(); 575 575 576 576 #ifdef QT_NO_TOOLBAR … … 578 578 #else 579 579 if (i == 0) 580 return toolBarAreaLayout.unplug(path , other ? &other->toolBarAreaLayout : 0);580 return toolBarAreaLayout.unplug(path.mid(1), other ? &other->toolBarAreaLayout : 0); 581 581 #endif 582 582 583 583 #ifndef QT_NO_DOCKWIDGET 584 584 if (i == 1) 585 return dockAreaLayout.unplug(path );585 return dockAreaLayout.unplug(path.mid(1)); 586 586 #endif //QT_NO_DOCKWIDGET 587 587 … … 940 940 void QMainWindowLayout::toggleToolBarsVisible() 941 941 { 942 layoutState.toolBarAreaLayout.visible = !layoutState.toolBarAreaLayout.visible; 943 if (!layoutState.mainWindow->isMaximized()){ 944 QPoint topLeft = parentWidget()->geometry().topLeft(); 945 QRect r = parentWidget()->geometry(); 946 r = layoutState.toolBarAreaLayout.rectHint(r); 947 r.moveTo(topLeft); 948 parentWidget()->setGeometry(r); 949 // widgetAnimator->animate(parentWidget(), r, true); 950 } else{ 951 update(); 942 bool updateNonUnifiedParts = true; 943 #ifdef Q_WS_MAC 944 if (layoutState.mainWindow->unifiedTitleAndToolBarOnMac()) { 945 // If we hit this case, someone has pressed the "toolbar button" which will 946 // toggle the unified toolbar visiblity, because that's what the user wants. 947 // We might be in a situation where someone has hidden all the toolbars 948 // beforehand (maybe in construction), but now they've hit this button and 949 // and are expecting the items to show. What do we do? 950 // 1) Check the visibility of all the toolbars, if one is visible, do nothing, this 951 // preserves what people would expect (these toolbars were visible when I clicked last time). 952 // 2) If NONE are visible, then show them all. Again, this preserves the user expectation 953 // of, "I want to see the toolbars." The user may get more toolbars than expected, but this 954 // is better seeing nothing. 955 // Don't worry about any of this if we are going invisible. This does mean we may get 956 // into issues when switching into and out of fullscreen mode, but this is probably minor. 957 // If we ever need to do hiding, that would have to be taken care of after the unified toolbar 958 // has finished hiding. 959 // People can of course handle the QEvent::ToolBarChange event themselves and do 960 // WHATEVER they want if they don't like what we are doing (though the unified toolbar 961 // will fire regardless). 962 963 // Check if we REALLY need to update the geometry below. If we only have items in the 964 // unified toolbar, all the docks will be empty, so there's very little point 965 // in doing the geometry as Apple will do it (we also avoid flicker in Cocoa as well). 966 // FWIW, layoutState.toolBarAreaLayout.visible and the state of the unified toolbar 967 // visibility can get out of sync. I really don't think it's a big issue. It is kept 968 // to a minimum because we only change the visibility if we absolutely must. 969 // update the "non unified parts." 970 updateNonUnifiedParts = !layoutState.toolBarAreaLayout.isEmpty(); 971 972 // We get this function before the unified toolbar does its thing. 973 // So, the value will be opposite of what we expect. 974 bool goingVisible = !macWindowToolbarIsVisible(qt_mac_window_for(layoutState.mainWindow)); 975 if (goingVisible) { 976 const int ToolBarCount = qtoolbarsInUnifiedToolbarList.size(); 977 bool needAllVisible = true; 978 for (int i = 0; i < ToolBarCount; ++i) { 979 if (!qtoolbarsInUnifiedToolbarList.at(i)->isHidden()) { 980 needAllVisible = false; 981 break; 982 } 983 } 984 if (needAllVisible) { 985 QBoolBlocker blocker(blockVisiblityCheck); // Disable the visibilty check because 986 // the toggle has already happened. 987 for (int i = 0; i < ToolBarCount; ++i) 988 qtoolbarsInUnifiedToolbarList.at(i)->setVisible(true); 989 } 990 } 991 if (!updateNonUnifiedParts) 992 layoutState.toolBarAreaLayout.visible = goingVisible; 993 } 994 #endif 995 if (updateNonUnifiedParts) { 996 layoutState.toolBarAreaLayout.visible = !layoutState.toolBarAreaLayout.visible; 997 if (!layoutState.mainWindow->isMaximized()) { 998 QPoint topLeft = parentWidget()->geometry().topLeft(); 999 QRect r = parentWidget()->geometry(); 1000 r = layoutState.toolBarAreaLayout.rectHint(r); 1001 r.moveTo(topLeft); 1002 parentWidget()->setGeometry(r); 1003 } else { 1004 update(); 1005 } 952 1006 } 953 1007 } … … 1305 1359 return false; 1306 1360 movingSeparatorPos = pos; 1307 separatorMoveTimer ->start();1361 separatorMoveTimer.start(0, this); 1308 1362 return true; 1309 }1310 1311 void QMainWindowLayout::doSeparatorMove()1312 {1313 if (movingSeparator.isEmpty())1314 return;1315 if (movingSeparatorOrigin == movingSeparatorPos)1316 return;1317 1318 layoutState = savedState;1319 layoutState.dockAreaLayout.separatorMove(movingSeparator, movingSeparatorOrigin,1320 movingSeparatorPos,1321 &separatorMoveCache);1322 movingSeparatorPos = movingSeparatorOrigin;1323 1363 } 1324 1364 … … 1328 1368 movingSeparator.clear(); 1329 1369 savedState.clear(); 1330 separatorMoveCache.clear();1331 1370 return result; 1332 1371 } … … 1377 1416 // the widget might in fact have been destroyed by now 1378 1417 if (QWidget *w = ret->widget()) { 1379 widgetAnimator ->abort(w);1418 widgetAnimator.abort(w); 1380 1419 if (w == pluggingWidget) 1381 1420 pluggingWidget = 0; … … 1425 1464 .expandedTo(statusbar->minimumSize())); 1426 1465 sbr.moveBottom(r.bottom()); 1427 QRect vr = QStyle::visualRect( QApplication::layoutDirection(), _r, sbr);1466 QRect vr = QStyle::visualRect(parentWidget()->layoutDirection(), _r, sbr); 1428 1467 statusbar->setGeometry(vr); 1429 1468 r.setBottom(sbr.top() - 1); … … 1544 1583 1545 1584 pluggingWidget = widget; 1546 if (dockOptions & QMainWindow::AnimatedDocks) { 1547 QRect globalRect = currentGapRect; 1548 globalRect.moveTopLeft(parentWidget()->mapToGlobal(globalRect.topLeft())); 1549 #ifndef QT_NO_DOCKWIDGET 1550 if (qobject_cast<QDockWidget*>(widget) != 0) { 1551 QDockWidgetLayout *layout = qobject_cast<QDockWidgetLayout*>(widget->layout()); 1552 if (layout->nativeWindowDeco()) { 1553 globalRect.adjust(0, layout->titleHeight(), 0, 0); 1554 } else { 1555 int fw = widget->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, 0, widget); 1556 globalRect.adjust(-fw, -fw, fw, fw); 1557 } 1585 QRect globalRect = currentGapRect; 1586 globalRect.moveTopLeft(parentWidget()->mapToGlobal(globalRect.topLeft())); 1587 #ifndef QT_NO_DOCKWIDGET 1588 if (qobject_cast<QDockWidget*>(widget) != 0) { 1589 QDockWidgetLayout *layout = qobject_cast<QDockWidgetLayout*>(widget->layout()); 1590 if (layout->nativeWindowDeco()) { 1591 globalRect.adjust(0, layout->titleHeight(), 0, 0); 1592 } else { 1593 int fw = widget->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, 0, widget); 1594 globalRect.adjust(-fw, -fw, fw, fw); 1558 1595 } 1559 #endif 1560 widgetAnimator->animate(widget, globalRect, 1561 dockOptions & QMainWindow::AnimatedDocks); 1562 } else { 1563 #ifndef QT_NO_DOCKWIDGET 1564 if (QDockWidget *dw = qobject_cast<QDockWidget*>(widget)) 1565 dw->d_func()->plug(currentGapRect); 1566 #endif 1567 #ifndef QT_NO_TOOLBAR 1568 if (QToolBar *tb = qobject_cast<QToolBar*>(widget)) 1569 tb->d_func()->plug(currentGapRect); 1570 #endif 1571 applyState(layoutState); 1572 savedState.clear(); 1573 #ifndef QT_NO_DOCKWIDGET 1574 parentWidget()->update(layoutState.dockAreaLayout.separatorRegion()); 1575 #endif 1576 currentGapPos.clear(); 1577 updateGapIndicator(); 1578 pluggingWidget = 0; 1579 } 1596 } 1597 #endif 1598 widgetAnimator.animate(widget, globalRect, dockOptions & QMainWindow::AnimatedDocks); 1580 1599 1581 1600 return true; 1582 1601 } 1583 1602 1584 void QMainWindowLayout::allAnimationsFinished()1585 {1586 #ifndef QT_NO_DOCKWIDGET1587 parentWidget()->update(layoutState.dockAreaLayout.separatorRegion());1588 1589 #ifndef QT_NO_TABBAR1590 foreach (QTabBar *tab_bar, usedTabBars)1591 tab_bar->show();1592 #endif // QT_NO_TABBAR1593 #endif // QT_NO_DOCKWIDGET1594 1595 updateGapIndicator();1596 }1597 1598 1603 void QMainWindowLayout::animationFinished(QWidget *widget) 1599 1604 { 1600 1601 /* This signal is delivered from QWidgetAnimator over a qeued connection. The problem is that 1602 the widget can be deleted. This is handled as follows: 1603 1604 The animator only ever animates widgets that have been added to this layout. If a widget 1605 is deleted during animation, the widget's destructor removes the widget form this layout. 1606 This in turn aborts the animation (see takeAt()) and this signal will never be delivered. 1607 1608 If the widget is deleted after the animation is finished but before this qeued signal 1609 is delivered, the widget is no longer in the layout and we catch it here. The key is that 1610 QMainWindowLayoutState::contains() never dereferences the pointer. */ 1611 1612 if (!layoutState.contains(widget)) 1613 return; 1614 1605 //this function is called from within the Widget Animator whenever an animation is finished 1606 //on a certain widget 1615 1607 #ifndef QT_NO_TOOLBAR 1616 1608 if (QToolBar *tb = qobject_cast<QToolBar*>(widget)) { … … 1625 1617 #endif 1626 1618 1627 if (widget != pluggingWidget) 1628 return; 1629 1630 #ifndef QT_NO_DOCKWIDGET 1631 if (QDockWidget *dw = qobject_cast<QDockWidget*>(widget)) 1632 dw->d_func()->plug(currentGapRect); 1633 #endif 1634 #ifndef QT_NO_TOOLBAR 1635 if (QToolBar *tb = qobject_cast<QToolBar*>(widget)) 1636 tb->d_func()->plug(currentGapRect); 1637 #endif 1638 1639 applyState(layoutState, false); 1619 if (widget == pluggingWidget) { 1620 1621 #ifndef QT_NO_DOCKWIDGET 1622 if (QDockWidget *dw = qobject_cast<QDockWidget*>(widget)) 1623 dw->d_func()->plug(currentGapRect); 1624 #endif 1625 #ifndef QT_NO_TOOLBAR 1626 if (QToolBar *tb = qobject_cast<QToolBar*>(widget)) 1627 tb->d_func()->plug(currentGapRect); 1628 #endif 1629 1640 1630 #ifndef QT_NO_DOCKWIDGET 1641 1631 #ifndef QT_NO_TABBAR 1642 if (qobject_cast<QDockWidget*>(widget) != 0) { 1643 // info() might return null if the widget is destroyed while 1644 // animating but before the animationFinished signal is received. 1645 if (QDockAreaLayoutInfo *info = layoutState.dockAreaLayout.info(widget)) 1646 info->setCurrentTab(widget); 1647 } 1648 #endif 1649 #endif 1650 savedState.clear(); 1651 currentGapPos.clear(); 1652 pluggingWidget = 0; 1632 if (qobject_cast<QDockWidget*>(widget) != 0) { 1633 // info() might return null if the widget is destroyed while 1634 // animating but before the animationFinished signal is received. 1635 if (QDockAreaLayoutInfo *info = layoutState.dockAreaLayout.info(widget)) 1636 info->setCurrentTab(widget); 1637 } 1638 #endif 1639 #endif 1640 1641 savedState.clear(); 1642 currentGapPos.clear(); 1643 pluggingWidget = 0; 1644 //applying the state will make sure that the currentGap is updated correctly 1645 //and all the geometries (especially the one from the central widget) is correct 1646 layoutState.apply(false); 1647 } 1648 1649 if (!widgetAnimator.animating()) { 1650 //all animations are finished 1651 #ifndef QT_NO_DOCKWIDGET 1652 parentWidget()->update(layoutState.dockAreaLayout.separatorRegion()); 1653 #ifndef QT_NO_TABBAR 1654 foreach (QTabBar *tab_bar, usedTabBars) 1655 tab_bar->show(); 1656 #endif // QT_NO_TABBAR 1657 #endif // QT_NO_DOCKWIDGET 1658 } 1659 1653 1660 updateGapIndicator(); 1654 1661 } … … 1683 1690 #endif 1684 1691 #endif // QT_NO_DOCKWIDGET 1692 , widgetAnimator(this) 1693 , pluggingWidget(0) 1694 #ifndef QT_NO_RUBBERBAND 1695 , gapIndicator(new QRubberBand(QRubberBand::Rectangle, mainwindow)) 1696 #endif //QT_NO_RUBBERBAND 1697 #ifdef Q_WS_MAC 1698 , blockVisiblityCheck(false) 1699 #endif 1685 1700 { 1686 1701 #ifndef QT_NO_DOCKWIDGET … … 1688 1703 sep = mainwindow->style()->pixelMetric(QStyle::PM_DockWidgetSeparatorExtent, 0, mainwindow); 1689 1704 #endif 1690 separatorMoveTimer = new QTimer(this);1691 separatorMoveTimer->setSingleShot(true);1692 separatorMoveTimer->setInterval(0);1693 connect(separatorMoveTimer, SIGNAL(timeout()), this, SLOT(doSeparatorMove()));1694 1705 1695 1706 #ifndef QT_NO_TABWIDGET … … 1700 1711 1701 1712 #ifndef QT_NO_RUBBERBAND 1702 gapIndicator = new QRubberBand(QRubberBand::Rectangle, mainwindow);1703 1713 // For accessibility to identify this special widget. 1704 1714 gapIndicator->setObjectName(QLatin1String("qt_rubberband")); 1705 1706 1715 gapIndicator->hide(); 1707 1716 #endif … … 1709 1718 1710 1719 setObjectName(mainwindow->objectName() + QLatin1String("_layout")); 1711 widgetAnimator = new QWidgetAnimator(this);1712 connect(widgetAnimator, SIGNAL(finished(QWidget*)),1713 this, SLOT(animationFinished(QWidget*)), Qt::QueuedConnection);1714 connect(widgetAnimator, SIGNAL(finishedAll()),1715 this, SLOT(allAnimationsFinished()));1716 1720 } 1717 1721 … … 1815 1819 { 1816 1820 #ifndef QT_NO_RUBBERBAND 1817 if (widgetAnimator->animating() || currentGapPos.isEmpty()) { 1818 gapIndicator->hide(); 1819 } else { 1820 if (gapIndicator->geometry() != currentGapRect) 1821 gapIndicator->setGeometry(currentGapRect); 1822 if (!gapIndicator->isVisible()) 1823 gapIndicator->show(); 1824 } 1821 gapIndicator->setVisible(!widgetAnimator.animating() && !currentGapPos.isEmpty()); 1822 gapIndicator->setGeometry(currentGapRect); 1825 1823 #endif 1826 1824 } … … 1983 1981 } 1984 1982 1983 void QMainWindowLayout::timerEvent(QTimerEvent *e) 1984 { 1985 #ifndef QT_NO_DOCKWIDGET 1986 if (e->timerId() == separatorMoveTimer.timerId()) { 1987 //let's move the separators 1988 separatorMoveTimer.stop(); 1989 if (movingSeparator.isEmpty()) 1990 return; 1991 if (movingSeparatorOrigin == movingSeparatorPos) 1992 return; 1993 1994 //when moving the separator, we need to update the previous position 1995 parentWidget()->update(layoutState.dockAreaLayout.separatorRegion()); 1996 1997 layoutState = savedState; 1998 layoutState.dockAreaLayout.separatorMove(movingSeparator, movingSeparatorOrigin, 1999 movingSeparatorPos); 2000 movingSeparatorPos = movingSeparatorOrigin; 2001 } 2002 #endif 2003 QLayout::timerEvent(e); 2004 } 2005 2006 1985 2007 QT_END_NAMESPACE 1986 2008 -
trunk/src/gui/widgets/qmainwindowlayout_mac.mm
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. 7 8 ** 8 9 ** $QT_BEGIN_LICENSE:LGPL$ 9 ** NoCommercial Usage10 ** This file contains pre-release code and may not be distributed.11 ** You may use this file in accordance with the terms and conditions12 ** contained in the either Technology Preview License Agreement or the13 ** Beta Release License Agreement.10 ** Commercial Usage 11 ** Licensees holding valid Qt Commercial licenses may use this file in 12 ** accordance with the Qt Commercial License Agreement provided with the 13 ** Software or, alternatively, in accordance with the terms contained in 14 ** a written agreement between you and Nokia. 14 15 ** 15 16 ** GNU Lesser General Public License Usage … … 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 **40 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE41 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.42 39 ** 43 40 ****************************************************************************/ … … 330 327 { 331 328 bool useMacToolbar = layoutState.mainWindow->unifiedTitleAndToolBarOnMac(); 332 if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4) { 333 #ifndef QT_MAC_USE_COCOA 334 if (useMacToolbar) { 335 ChangeWindowAttributes(qt_mac_window_for(layoutState.mainWindow), 336 kWindowUnifiedTitleAndToolbarAttribute, 0); 337 } else { 338 ChangeWindowAttributes(qt_mac_window_for(layoutState.mainWindow), 339 0, kWindowUnifiedTitleAndToolbarAttribute); 340 } 341 #endif 342 macWindowToolbarShow(layoutState.mainWindow, useMacToolbar); 343 } 329 #ifndef QT_MAC_USE_COCOA 330 if (useMacToolbar) { 331 ChangeWindowAttributes(qt_mac_window_for(layoutState.mainWindow), 332 kWindowUnifiedTitleAndToolbarAttribute, 0); 333 } else { 334 ChangeWindowAttributes(qt_mac_window_for(layoutState.mainWindow), 335 0, kWindowUnifiedTitleAndToolbarAttribute); 336 } 337 #endif 344 338 345 339 layoutState.mainWindow->setUpdatesEnabled(false); // reduces a little bit of flicker, not all though 346 340 if (!useMacToolbar) { 347 OSWindowRef windowRef = qt_mac_window_for(parentWidget()); 348 macWindowToolbarShow(parentWidget(), false); 341 macWindowToolbarShow(layoutState.mainWindow, false); 349 342 // Move everything out of the HIToolbar into the main toolbar. 350 343 while (!qtoolbarsInUnifiedToolbarList.isEmpty()) { … … 352 345 layoutState.mainWindow->addToolBar(Qt::TopToolBarArea, qtoolbarsInUnifiedToolbarList.first()); 353 346 } 354 macWindowToolbarSet( windowRef, NULL);347 macWindowToolbarSet(qt_mac_window_for(layoutState.mainWindow), 0); 355 348 } else { 356 349 QList<QToolBar *> toolbars = layoutState.mainWindow->findChildren<QToolBar *>(); … … 362 355 } 363 356 } 357 syncUnifiedToolbarVisibility(); 364 358 } 365 359 layoutState.mainWindow->setUpdatesEnabled(true); … … 442 436 NSString *toolbarID = kQToolBarNSToolbarIdentifier; 443 437 toolbarID = [toolbarID stringByAppendingFormat:@"%p", toolbar]; 444 cocoaItemIDToToolbarHash.insert( QCFString::toQString(CFStringRef(toolbarID)), toolbar);438 cocoaItemIDToToolbarHash.insert(qt_mac_NSStringToQString(toolbarID), toolbar); 445 439 [macToolbar insertItemWithItemIdentifier:toolbarID atIndex:beforeIndex]; 446 440 #endif … … 470 464 [[qt_mac_window_for(layoutState.mainWindow->window()) toolbar] 471 465 removeItemAtIndex:toolbarItemsCopy.indexOf(item)]; 472 // In Carbon this hash and list gets emptied via events. In Cocoa, we have to do it ourselves here.473 it = unifiedToolbarHash.erase(it);474 qtoolbarsInUnifiedToolbarList.removeAll(toolbar);475 466 #endif 476 467 break; … … 490 481 void QMainWindowLayout::fixSizeInUnifiedToolbar(QToolBar *tb) const 491 482 { 483 #ifdef QT_MAC_USE_COCOA 492 484 QHash<void *, QToolBar *>::const_iterator it = unifiedToolbarHash.constBegin(); 493 485 NSToolbarItem *item = nil; … … 503 495 QWidgetItem layoutItem(tb); 504 496 QSize size = layoutItem.maximumSize(); 505 NSSize nssize = NSMakeSize(size.width(), size.height() );497 NSSize nssize = NSMakeSize(size.width(), size.height() - 2); 506 498 [item setMaxSize:nssize]; 507 499 size = layoutItem.minimumSize(); 508 500 nssize.width = size.width(); 509 nssize.height = size.height() ;501 nssize.height = size.height() - 2; 510 502 [item setMinSize:nssize]; 511 503 } 512 } 504 #else 505 Q_UNUSED(tb); 506 #endif 507 } 508 509 void QMainWindowLayout::syncUnifiedToolbarVisibility() 510 { 511 if (blockVisiblityCheck) 512 return; 513 514 Q_ASSERT(layoutState.mainWindow->unifiedTitleAndToolBarOnMac()); 515 bool show = false; 516 const int ToolBarCount = qtoolbarsInUnifiedToolbarList.count(); 517 for (int i = 0; i < ToolBarCount; ++i) { 518 if (qtoolbarsInUnifiedToolbarList.at(i)->isVisible()) { 519 show = true; 520 break; 521 } 522 } 523 macWindowToolbarShow(layoutState.mainWindow, show); 524 } 525 513 526 QT_END_NAMESPACE -
trunk/src/gui/widgets/qmainwindowlayout_p.h
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 ** … … 62 62 #include "QtCore/qvector.h" 63 63 #include "QtCore/qset.h" 64 #include "QtCore/qbasictimer.h" 64 65 #include "private/qlayoutengine_p.h" 66 #include "private/qwidgetanimator_p.h" 65 67 66 68 #include "qdockarealayout_p.h" … … 89 91 90 92 class QToolBar; 91 class QWidgetAnimator;92 93 class QRubberBand; 93 94 … … 128 129 QLayoutItem *takeAt(int index, int *x); 129 130 QList<int> indexOf(QWidget *widget) const; 130 QLayoutItem *item( QList<int>path);131 QRect itemRect( QList<int>path) const;132 QRect gapRect( QList<int>path) const; // ### get rid of this, use itemRect() instead131 QLayoutItem *item(const QList<int> &path); 132 QRect itemRect(const QList<int> &path) const; 133 QRect gapRect(const QList<int> &path) const; // ### get rid of this, use itemRect() instead 133 134 134 135 bool contains(QWidget *widget) const; … … 138 139 139 140 QList<int> gapIndex(QWidget *widget, const QPoint &pos) const; 140 bool insertGap( QList<int>path, QLayoutItem *item);141 void remove( QList<int>path);141 bool insertGap(const QList<int> &path, QLayoutItem *item); 142 void remove(const QList<int> &path); 142 143 void remove(QLayoutItem *item); 143 144 void clear(); 144 145 bool isValid() const; 145 146 146 QLayoutItem *plug( QList<int>path);147 QLayoutItem *unplug( QList<int>path, QMainWindowLayoutState *savedState = 0);147 QLayoutItem *plug(const QList<int> &path); 148 QLayoutItem *unplug(const QList<int> &path, QMainWindowLayoutState *savedState = 0); 148 149 149 150 void saveState(QDataStream &stream) const; … … 165 166 void setDockOptions(QMainWindow::DockOptions opts); 166 167 bool usesHIToolBar(QToolBar *toolbar) const; 168 169 void timerEvent(QTimerEvent *e); 167 170 168 171 // status bar … … 244 247 QList<int> movingSeparator; 245 248 QPoint movingSeparatorOrigin, movingSeparatorPos; 246 QTimer *separatorMoveTimer; 247 QVector<QLayoutStruct> separatorMoveCache; 249 QBasicTimer separatorMoveTimer; 248 250 249 251 bool startSeparatorMove(const QPoint &pos); … … 277 279 // animations 278 280 279 QWidgetAnimator *widgetAnimator;281 QWidgetAnimator widgetAnimator; 280 282 QList<int> currentGapPos; 281 283 QRect currentGapRect; … … 294 296 void restore(bool keepSavedState = false); 295 297 void updateHIToolBarStatus(); 296 297 private slots:298 298 void animationFinished(QWidget *widget); 299 void allAnimationsFinished(); 299 300 private Q_SLOTS: 300 301 #ifndef QT_NO_DOCKWIDGET 301 void doSeparatorMove();302 302 #ifndef QT_NO_TABBAR 303 303 void tabChanged(); … … 336 336 void fixSizeInUnifiedToolbar(QToolBar *tb) const; 337 337 bool useHIToolBar; 338 void syncUnifiedToolbarVisibility(); 339 bool blockVisiblityCheck; 338 340 #endif 339 341 }; … … 342 344 #endif // QT_NO_MAINWINDOW 343 345 344 QT_BEGIN_NAMESPACE345 static inline int pick(Qt::Orientation o, const QPoint &pos)346 { return o == Qt::Horizontal ? pos.x() : pos.y(); }347 348 static inline int pick(Qt::Orientation o, const QSize &size)349 { return o == Qt::Horizontal ? size.width() : size.height(); }350 351 static inline int &rpick(Qt::Orientation o, QPoint &pos)352 { return o == Qt::Horizontal ? pos.rx() : pos.ry(); }353 354 static inline int &rpick(Qt::Orientation o, QSize &size)355 { return o == Qt::Horizontal ? size.rwidth() : size.rheight(); }356 357 static inline QSizePolicy::Policy pick(Qt::Orientation o, const QSizePolicy &policy)358 { return o == Qt::Horizontal ? policy.horizontalPolicy() : policy.verticalPolicy(); }359 360 static inline int perp(Qt::Orientation o, const QPoint &pos)361 { return o == Qt::Vertical ? pos.x() : pos.y(); }362 363 static inline int perp(Qt::Orientation o, const QSize &size)364 { return o == Qt::Vertical ? size.width() : size.height(); }365 366 static inline int &rperp(Qt::Orientation o, QPoint &pos)367 { return o == Qt::Vertical ? pos.rx() : pos.ry(); }368 369 static inline int &rperp(Qt::Orientation o, QSize &size)370 { return o == Qt::Vertical ? size.rwidth() : size.rheight(); }371 372 QT_END_NAMESPACE373 374 346 #endif // QDYNAMICMAINWINDOWLAYOUT_P_H -
trunk/src/gui/widgets/qmdiarea.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 ** … … 44 44 \brief The QMdiArea widget provides an area in which MDI windows are displayed. 45 45 \since 4.3 46 \ingroup application47 \mainclass 46 \ingroup mainwindow-classes 47 48 48 49 49 QMdiArea functions, essentially, like a window manager for MDI … … 82 82 containing a list of windows, for example. 83 83 84 The subwindows are sorted by the thecurrent84 The subwindows are sorted by the current 85 85 \l{QMdiArea::}{WindowOrder}. This is used for the subWindowList() 86 86 and for activateNextSubWindow() and acivatePreviousSubWindow(). … … 801 801 Q_ASSERT(child && childWindows.indexOf(child) == -1); 802 802 803 if (child->parent() != q->viewport())804 child->setParent( q->viewport(), child->windowFlags());803 if (child->parent() != viewport) 804 child->setParent(viewport, child->windowFlags()); 805 805 childWindows.append(QPointer<QMdiSubWindow>(child)); 806 806 807 807 if (!child->testAttribute(Qt::WA_Resized) && q->isVisible()) { 808 QSize newSize(child->sizeHint().boundedTo( q->viewport()->size()));808 QSize newSize(child->sizeHint().boundedTo(viewport->size())); 809 809 child->resize(newSize.expandedTo(qSmartMinSize(child))); 810 810 } … … 842 842 843 843 QObject::connect(child, SIGNAL(aboutToActivate()), q, SLOT(_q_deactivateAllWindows())); 844 QObject::connect(child, SIGNAL(windowStateChanged(Qt::WindowStates, 845 q, SLOT(_q_processWindowStateChanged(Qt::WindowStates, 844 QObject::connect(child, SIGNAL(windowStateChanged(Qt::WindowStates,Qt::WindowStates)), 845 q, SLOT(_q_processWindowStateChanged(Qt::WindowStates,Qt::WindowStates))); 846 846 } 847 847 … … 932 932 } 933 933 934 QRect domain = q->viewport()->rect();934 QRect domain = viewport->rect(); 935 935 if (rearranger->type() == Rearranger::RegularTiler && !widgets.isEmpty()) 936 936 domain = resizeToMinimumTileSize(minSubWindowSize, widgets.count()); … … 1213 1213 QMdiSubWindow *stackUnderChild = 0; 1214 1214 if (!windowStaysOnTop(mdiChild)) { 1215 foreach (QObject *object, q_func()->viewport()->children()) {1215 foreach (QObject *object, viewport->children()) { 1216 1216 QMdiSubWindow *child = qobject_cast<QMdiSubWindow *>(object); 1217 1217 if (!child || !childWindows.contains(child)) … … 1237 1237 Q_Q(QMdiArea); 1238 1238 if (!minSubWindowSize.isValid() || subWindowCount <= 0) 1239 return q->viewport()->rect();1239 return viewport->rect(); 1240 1240 1241 1241 // Calculate minimum size. … … 1256 1256 int minAreaWidth = minWidth + left + right + 2; 1257 1257 int minAreaHeight = minHeight + top + bottom + 2; 1258 if ( q->horizontalScrollBar()->isVisible())1259 minAreaHeight += q->horizontalScrollBar()->height();1260 if ( q->verticalScrollBar()->isVisible())1261 minAreaWidth += q->verticalScrollBar()->width();1258 if (hbar->isVisible()) 1259 minAreaHeight += hbar->height(); 1260 if (vbar->isVisible()) 1261 minAreaWidth += vbar->width(); 1262 1262 if (q->style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents, 0, q)) { 1263 1263 const int frame = q->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, 0, q); … … 1269 1269 } 1270 1270 1271 QRect domain = q->viewport()->rect();1271 QRect domain = viewport->rect(); 1272 1272 1273 1273 // Adjust domain width and provide horizontal scroll bar. 1274 1274 if (domain.width() < minWidth) { 1275 1275 domain.setWidth(minWidth); 1276 if ( q->horizontalScrollBarPolicy()== Qt::ScrollBarAlwaysOff)1276 if (hbarpolicy == Qt::ScrollBarAlwaysOff) 1277 1277 q->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); 1278 else if (q->horizontalScrollBar()->value() != 0)1279 q->horizontalScrollBar()->setValue(0);1278 else 1279 hbar->setValue(0); 1280 1280 } 1281 1281 // Adjust domain height and provide vertical scroll bar. 1282 1282 if (domain.height() < minHeight) { 1283 1283 domain.setHeight(minHeight); 1284 if ( q->verticalScrollBarPolicy()== Qt::ScrollBarAlwaysOff)1284 if (vbarpolicy == Qt::ScrollBarAlwaysOff) 1285 1285 q->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); 1286 else if (q->verticalScrollBar()->value() != 0)1287 q->verticalScrollBar()->setValue(0);1286 else 1287 vbar->setValue(0); 1288 1288 } 1289 1289 return domain; … … 1854 1854 1855 1855 /*! 1856 Gives the keyboard focus to the nextwindow in the list of child1857 windows. The window s are activated in the order in which they are1858 created (CreationOrder).1859 1860 \sa activatePreviousSubWindow() 1856 Gives the keyboard focus to another window in the list of child 1857 windows. The window activated will be the next one determined 1858 by the current \l{QMdiArea::WindowOrder} {activation order}. 1859 1860 \sa activatePreviousSubWindow(), QMdiArea::WindowOrder 1861 1861 */ 1862 1862 void QMdiArea::activateNextSubWindow() … … 1872 1872 1873 1873 /*! 1874 Gives the keyboard focus to the previous window in the list of1875 child windows. The windows are activated in the order in which1876 they are created (CreationOrder).1877 1878 \sa activateNextSubWindow() 1874 Gives the keyboard focus to another window in the list of child 1875 windows. The window activated will be the previous one determined 1876 by the current \l{QMdiArea::WindowOrder} {activation order}. 1877 1878 \sa activateNextSubWindow(), QMdiArea::WindowOrder 1879 1879 */ 1880 1880 void QMdiArea::activatePreviousSubWindow() … … 1948 1948 Removes \a widget from the MDI area. The \a widget must be 1949 1949 either a QMdiSubWindow or a widget that is the internal widget of 1950 a subwindow. Note that the subwindow is not deleted by QMdiArea 1951 and that its parent is set to 0. 1950 a subwindow. Note \a widget is never actually deleted by QMdiArea. 1951 If a QMdiSubWindow is passed in its parent is set to 0 and it is 1952 removed, but if an internal widget is passed in the child widget 1953 is set to 0 but the QMdiSubWindow is not removed. 1952 1954 1953 1955 \sa addSubWindow() -
trunk/src/gui/widgets/qmdiarea.h
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 ** -
trunk/src/gui/widgets/qmdiarea_p.h
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 ** -
trunk/src/gui/widgets/qmdisubwindow.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 ** … … 45 45 QMdiArea. 46 46 \since 4.3 47 \ingroup application48 \mainclass 47 \ingroup mainwindow-classes 48 49 49 50 50 QMdiSubWindow represents a top-level window in a QMdiArea, and consists … … 1007 1007 Q_Q(QMdiSubWindow); 1008 1008 baseWidget->removeEventFilter(q); 1009 if ( QLayout *layout = q->layout())1009 if (layout) 1010 1010 layout->removeWidget(baseWidget); 1011 1011 if (baseWidget->windowTitle() == q->windowTitle()) { … … 1067 1067 actions[CloseAction]->setIcon(style->standardIcon(QStyle::SP_TitleBarCloseButton, 0, q)); 1068 1068 #if !defined(QT_NO_SHORTCUT) 1069 actions[CloseAction]->setShortcut (QKeySequence::Close);1069 actions[CloseAction]->setShortcuts(QKeySequence::Close); 1070 1070 #endif 1071 1071 updateActions(); … … 1103 1103 { 1104 1104 // No update necessary 1105 if (! q_func()->parent())1105 if (!parent) 1106 1106 return; 1107 1107 … … 1116 1116 { 1117 1117 Q_Q(QMdiSubWindow); 1118 if (! q->parent())1118 if (!parent) 1119 1119 return; 1120 1120 … … 1146 1146 q->clearMask(); 1147 1147 1148 if (! q->parent())1148 if (!parent) 1149 1149 return; 1150 1150 … … 1169 1169 Q_Q(QMdiSubWindow); 1170 1170 Q_ASSERT(currentOperation != None); 1171 Q_ASSERT( q->parent());1171 Q_ASSERT(parent); 1172 1172 1173 1173 uint cflags = operationMap.find(currentOperation).value().changeFlags; … … 1236 1236 { 1237 1237 Q_Q(QMdiSubWindow); 1238 Q_ASSERT( q->parent());1238 Q_ASSERT(parent); 1239 1239 1240 1240 ensureWindowState(Qt::WindowMinimized); … … 1264 1264 { 1265 1265 Q_Q(QMdiSubWindow); 1266 Q_ASSERT( q->parent());1266 Q_ASSERT(parent); 1267 1267 1268 1268 isShadeMode = false; … … 1335 1335 { 1336 1336 Q_Q(QMdiSubWindow); 1337 Q_ASSERT( q->parent());1337 Q_ASSERT(parent); 1338 1338 1339 1339 ensureWindowState(Qt::WindowMaximized); … … 1424 1424 { 1425 1425 Q_Q(QMdiSubWindow); 1426 if (! q->parent()|| !activationEnabled)1426 if (!parent || !activationEnabled) 1427 1427 return; 1428 1428 … … 1712 1712 { 1713 1713 Q_Q(const QMdiSubWindow); 1714 if (! q->parent()|| q->windowFlags() & Qt::FramelessWindowHint1714 if (!parent || q->windowFlags() & Qt::FramelessWindowHint 1715 1715 || (q->isMaximized() && !drawTitleBarWhenMaximized())) { 1716 1716 return 0; … … 1735 1735 Q_Q(const QMdiSubWindow); 1736 1736 Qt::WindowFlags flags = q->windowFlags(); 1737 if (! q->parent()|| flags & Qt::FramelessWindowHint) {1737 if (!parent || flags & Qt::FramelessWindowHint) { 1738 1738 *margin = 0; 1739 1739 *minWidth = 0; … … 1773 1773 return false; 1774 1774 1775 #if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC) || defined(Q_ OS_WINCE_WM)1775 #if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC) || defined(Q_WS_WINCE_WM) 1776 1776 return true; 1777 1777 #else … … 1894 1894 return; 1895 1895 Q_ASSERT(oldGeometry.isValid()); 1896 Q_ASSERT( q->parent());1896 Q_ASSERT(parent); 1897 1897 if (!rubberBand) { 1898 1898 rubberBand = new QRubberBand(QRubberBand::Rectangle, q->parentWidget()); … … 1947 1947 newPalette.setColor(QPalette::Inactive, QPalette::HighlightedText, 1948 1948 colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTIONTEXT))); 1949 if (QSysInfo::WindowsVersion != QSysInfo::WV_95 1950 && QSysInfo::WindowsVersion != QSysInfo::WV_NT) { 1951 colorsInitialized = true; 1952 BOOL hasGradient; 1953 QT_WA({ 1954 SystemParametersInfo(SPI_GETGRADIENTCAPTIONS, 0, &hasGradient, 0); 1955 } , { 1956 SystemParametersInfoA(SPI_GETGRADIENTCAPTIONS, 0, &hasGradient, 0); 1957 }); 1958 if (hasGradient) { 1959 newPalette.setColor(QPalette::Active, QPalette::Base, 1960 colorref2qrgb(GetSysColor(COLOR_GRADIENTACTIVECAPTION))); 1961 newPalette.setColor(QPalette::Inactive, QPalette::Base, 1962 colorref2qrgb(GetSysColor(COLOR_GRADIENTINACTIVECAPTION))); 1963 } else { 1964 newPalette.setColor(QPalette::Active, QPalette::Base, 1965 newPalette.color(QPalette::Active, QPalette::Highlight)); 1966 newPalette.setColor(QPalette::Inactive, QPalette::Base, 1967 newPalette.color(QPalette::Inactive, QPalette::Highlight)); 1968 } 1949 1950 colorsInitialized = true; 1951 BOOL hasGradient = false; 1952 SystemParametersInfo(SPI_GETGRADIENTCAPTIONS, 0, &hasGradient, 0); 1953 1954 if (hasGradient) { 1955 newPalette.setColor(QPalette::Active, QPalette::Base, 1956 colorref2qrgb(GetSysColor(COLOR_GRADIENTACTIVECAPTION))); 1957 newPalette.setColor(QPalette::Inactive, QPalette::Base, 1958 colorref2qrgb(GetSysColor(COLOR_GRADIENTINACTIVECAPTION))); 1959 } else { 1960 newPalette.setColor(QPalette::Active, QPalette::Base, 1961 newPalette.color(QPalette::Active, QPalette::Highlight)); 1962 newPalette.setColor(QPalette::Inactive, QPalette::Base, 1963 newPalette.color(QPalette::Inactive, QPalette::Highlight)); 1969 1964 } 1970 1965 } … … 2080 2075 { 2081 2076 Q_Q(QMdiSubWindow); 2082 if (! q->parent()) {2077 if (!parent) { 2083 2078 q->setWindowFlags(windowFlags); 2084 2079 return; … … 2165 2160 { 2166 2161 Q_Q(const QMdiSubWindow); 2167 if (! q->parent()|| q->windowFlags() & Qt::FramelessWindowHint)2162 if (!parent || q->windowFlags() & Qt::FramelessWindowHint) 2168 2163 return QSize(-1, -1); 2169 2164 return QSize(q->style()->pixelMetric(QStyle::PM_MdiSubWindowMinimizedWidth, 0, q), titleBarHeight()); … … 2181 2176 return; 2182 2177 2183 if ( q->layout() && q->layout()->indexOf(newSizeGrip) != -1)2178 if (layout && layout->indexOf(newSizeGrip) != -1) 2184 2179 return; 2185 2180 newSizeGrip->setFixedSize(newSizeGrip->sizeHint()); 2186 bool putSizeGripInLayout = q->layout()? true : false;2181 bool putSizeGripInLayout = layout ? true : false; 2187 2182 #if defined(Q_WS_MAC) && !defined(QT_NO_STYLE_MAC) 2188 2183 if (qobject_cast<QMacStyle *>(q->style())) … … 2190 2185 #endif 2191 2186 if (putSizeGripInLayout) { 2192 q->layout()->addWidget(newSizeGrip);2193 q->layout()->setAlignment(newSizeGrip, Qt::AlignBottom | Qt::AlignRight);2187 layout->addWidget(newSizeGrip); 2188 layout->setAlignment(newSizeGrip, Qt::AlignBottom | Qt::AlignRight); 2194 2189 } else { 2195 2190 newSizeGrip->setParent(q); … … 2274 2269 d->menuIcon = windowIcon(); 2275 2270 #endif 2276 connect(qApp, SIGNAL(focusChanged(QWidget *, QWidget*)),2277 this, SLOT(_q_processFocusChanged(QWidget *, QWidget*)));2271 connect(qApp, SIGNAL(focusChanged(QWidget*,QWidget*)), 2272 this, SLOT(_q_processFocusChanged(QWidget*,QWidget*))); 2278 2273 } 2279 2274 -
trunk/src/gui/widgets/qmdisubwindow.h
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 ** -
trunk/src/gui/widgets/qmdisubwindow_p.h
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 ** … … 288 288 { 289 289 Q_Q(const QMdiSubWindow); 290 if (! q->parent()|| q->windowFlags() & Qt::FramelessWindowHint290 if (!parent || q->windowFlags() & Qt::FramelessWindowHint 291 291 || (q->isMaximized() && !drawTitleBarWhenMaximized())) { 292 292 return 0; … … 309 309 { 310 310 Q_Q(QMdiSubWindow); 311 Q_ASSERT( q->parent());311 Q_ASSERT(parent); 312 312 geometry->setSize(geometry->size().expandedTo(internalMinimumSize)); 313 313 #ifndef QT_NO_RUBBERBAND -
trunk/src/gui/widgets/qmenu.cpp
r305 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 ** … … 66 66 #include "qwidgetaction.h" 67 67 #include "qtoolbutton.h" 68 #include "qpushbutton.h" 69 #include <private/qpushbutton_p.h> 68 70 #include <private/qaction_p.h> 71 #include <private/qsoftkeymanager_p.h> 69 72 #ifdef QT3_SUPPORT 70 73 #include <qmenudata.h> … … 151 154 { 152 155 Q_Q(QMenu); 153 activationRecursionGuard = false;154 156 #ifndef QT_NO_WHATSTHIS 155 157 q->setAttribute(Qt::WA_CustomWhatsThis); … … 163 165 scroll->scrollFlags = QMenuPrivate::QMenuScroller::ScrollNone; 164 166 } 167 168 #ifdef QT_SOFTKEYS_ENABLED 169 selectAction = QSoftKeyManager::createKeyedAction(QSoftKeyManager::SelectSoftKey, Qt::Key_Select, q); 170 cancelAction = QSoftKeyManager::createKeyedAction(QSoftKeyManager::CancelSoftKey, Qt::Key_Back, q); 171 selectAction->setVisible(false); // Don't show these in the menu 172 cancelAction->setVisible(false); 173 q->addAction(selectAction); 174 q->addAction(cancelAction); 175 #endif 176 } 177 178 int QMenuPrivate::scrollerHeight() const 179 { 180 Q_Q(const QMenu); 181 return qMax(QApplication::globalStrut().height(), q->style()->pixelMetric(QStyle::PM_MenuScrollerHeight, 0, q)); 182 } 183 184 // Windows, OS/2 and KDE allows menus to cover the taskbar, while GNOME and Mac don't 185 QRect QMenuPrivate::popupGeometry(const QWidget *widget) const 186 { 187 #if defined(Q_WS_WIN) || defined(Q_WS_PM) 188 return QApplication::desktop()->screenGeometry(widget); 189 #elif defined Q_WS_X11 190 if (X11->desktopEnvironment == DE_KDE) 191 return QApplication::desktop()->screenGeometry(widget); 192 else 193 return QApplication::desktop()->availableGeometry(widget); 194 #else 195 return QApplication::desktop()->availableGeometry(widget); 196 #endif 165 197 } 166 198 … … 195 227 } 196 228 197 void QMenuPrivate:: calcActionRects(QMap<QAction*, QRect> &actionRects, QList<QAction*> &actionList) const229 void QMenuPrivate::updateActionRects() const 198 230 { 199 231 Q_Q(const QMenu); 200 if (!itemsDirty) { 201 actionRects = this->actionRects; 202 actionList = this->actionList; 232 if (!itemsDirty) 203 233 return; 204 } 205 206 actionRects.clear(); 207 actionList.clear(); 208 QList<QAction*> items = filterActions(q->actions()); 234 235 q->ensurePolished(); 236 237 //let's reinitialize the buffer 238 actionRects.resize(actions.count()); 239 actionRects.fill(QRect()); 240 241 //let's try to get the last visible action 242 int lastVisibleAction = actions.count() - 1; 243 for(;lastVisibleAction >= 0; --lastVisibleAction) { 244 const QAction *action = actions.at(lastVisibleAction); 245 if (action->isVisible()) { 246 //removing trailing separators 247 if (action->isSeparator() && collapsibleSeparators) 248 continue; 249 break; 250 } 251 } 252 209 253 int max_column_width = 0, 210 dh = popupGeometry(QApplication::desktop()->screenNumber(q)).height(), 211 ncols = 1, 254 dh = popupGeometry(q).height(), 212 255 y = 0; 213 const int hmargin = q->style()->pixelMetric(QStyle::PM_MenuHMargin, 0, q), 214 vmargin = q->style()->pixelMetric(QStyle::PM_MenuVMargin, 0, q), 215 icone = q->style()->pixelMetric(QStyle::PM_SmallIconSize, 0, q); 256 QStyle *style = q->style(); 257 QStyleOption opt; 258 opt.init(q); 259 const int hmargin = style->pixelMetric(QStyle::PM_MenuHMargin, &opt, q), 260 vmargin = style->pixelMetric(QStyle::PM_MenuVMargin, &opt, q), 261 icone = style->pixelMetric(QStyle::PM_SmallIconSize, &opt, q); 262 const int fw = style->pixelMetric(QStyle::PM_MenuPanelWidth, &opt, q); 263 const int deskFw = style->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, &opt, q); 264 265 const int sfcMargin = style->sizeFromContents(QStyle::CT_Menu, &opt, QApplication::globalStrut(), q).width() - QApplication::globalStrut().width(); 266 const int min_column_width = q->minimumWidth() - (sfcMargin + leftmargin + rightmargin + 2 * (fw + hmargin)); 267 const int tearoffHeight = tearoff ? style->pixelMetric(QStyle::PM_MenuTearoffHeight, &opt, q) : 0; 216 268 217 269 //for compatability now - will have to refactor this away.. … … 219 271 maxIconWidth = 0; 220 272 hasCheckableItems = false; 221 for(int i = 0; i < items.count(); i++) { 222 QAction *action = items.at(i); 223 if (widgetItems.value(action)) 273 ncols = 1; 274 sloppyAction = 0; 275 276 for (int i = 0; i < actions.count(); ++i) { 277 QAction *action = actions.at(i); 278 if (action->isSeparator() || !action->isVisible() || widgetItems.contains(action)) 224 279 continue; 280 //..and some members 225 281 hasCheckableItems |= action->isCheckable(); 226 282 QIcon is = action->icon(); 227 283 if (!is.isNull()) { 228 uint miw = maxIconWidth; 229 maxIconWidth = qMax<uint>(miw, icone + 4); 284 maxIconWidth = qMax<uint>(maxIconWidth, icone + 4); 230 285 } 231 286 } … … 233 288 //calculate size 234 289 QFontMetrics qfm = q->fontMetrics(); 235 for(int i = 0; i < items.count(); i++) { 236 QAction *action = items.at(i); 237 238 QFontMetrics fm(action->font().resolve(q->font())); 239 QSize sz; 290 bool previousWasSeparator = true; // this is true to allow removing the leading separators 291 for(int i = 0; i <= lastVisibleAction; i++) { 292 QAction *action = actions.at(i); 293 294 if (!action->isVisible() || 295 (collapsibleSeparators && previousWasSeparator && action->isSeparator())) 296 continue; // we continue, this action will get an empty QRect 297 298 previousWasSeparator = action->isSeparator(); 240 299 241 300 //let the style modify the above size.. 242 301 QStyleOptionMenuItem opt; 243 302 q->initStyleOption(&opt, action); 244 opt.rect = q->rect(); 245 303 const QFontMetrics &fm = opt.fontMetrics; 304 305 QSize sz; 246 306 if (QWidget *w = widgetItems.value(action)) { 247 sz =w->sizeHint().expandedTo(w->minimumSize()).expandedTo(w->minimumSizeHint()).boundedTo(w->maximumSize());307 sz = w->sizeHint().expandedTo(w->minimumSize()).expandedTo(w->minimumSizeHint()).boundedTo(w->maximumSize()); 248 308 } else { 249 309 //calc what I think the size is.. … … 263 323 #endif 264 324 } 265 int w = fm.boundingRect(QRect(), Qt::TextSingleLine, s).width(); 266 w -= s.count(QLatin1Char('&')) * fm.width(QLatin1Char('&')); 267 w += s.count(QLatin1String("&&")) * fm.width(QLatin1Char('&')); 268 sz.setWidth(w); 325 sz.setWidth(fm.boundingRect(QRect(), Qt::TextSingleLine | Qt::TextShowMnemonic, s).width()); 269 326 sz.setHeight(qMax(fm.height(), qfm.height())); 270 327 … … 276 333 } 277 334 } 278 sz = q->style()->sizeFromContents(QStyle::CT_MenuItem, &opt, sz, q);335 sz = style->sizeFromContents(QStyle::CT_MenuItem, &opt, sz, q); 279 336 } 280 337 281 338 282 339 if (!sz.isEmpty()) { 283 max_column_width = qMax(m ax_column_width, sz.width());340 max_column_width = qMax(min_column_width, qMax(max_column_width, sz.width())); 284 341 //wrapping 285 342 if (!scroll && 286 y+sz.height()+vmargin > dh - ( q->style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, 0, q)* 2)) {343 y+sz.height()+vmargin > dh - (deskFw * 2)) { 287 344 ncols++; 288 345 y = vmargin; 289 346 } 290 347 y += sz.height(); 291 //append item 292 actionRects.insert(action, QRect(0, 0, sz.width(), sz.height())); 293 actionList.append(action); 294 } 295 } 296 297 if (tabWidth) 298 max_column_width += tabWidth; //finally add in the tab width 348 //update the item 349 actionRects[i] = QRect(0, 0, sz.width(), sz.height()); 350 } 351 } 352 353 max_column_width += tabWidth; //finally add in the tab width 299 354 300 355 //calculate position 301 int x = hmargin; 302 y = vmargin; 303 304 for(int i = 0; i < actionList.count(); i++) { 305 QAction *action = actionList.at(i); 306 QRect &rect = actionRects[action]; 356 const int base_y = vmargin + fw + topmargin + 357 (scroll ? scroll->scrollOffset : 0) + 358 tearoffHeight; 359 int x = hmargin + fw + leftmargin; 360 y = base_y; 361 362 for(int i = 0; i < actions.count(); i++) { 363 QRect &rect = actionRects[i]; 307 364 if (rect.isNull()) 308 365 continue; 309 366 if (!scroll && 310 y+rect.height() > dh - (q->style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, 0, q) * 2)) { 311 ncols--; 312 if (ncols < 0) 313 qWarning("QMenu: Column calculation mismatch (%d)", ncols); 367 y+rect.height() > dh - deskFw * 2) { 314 368 x += max_column_width + hmargin; 315 y = vmargin;369 y = base_y; 316 370 } 317 371 rect.translate(x, y); //move 318 372 rect.setWidth(max_column_width); //uniform width 373 374 //we need to update the widgets geometry 375 if (QWidget *widget = widgetItems.value(actions.at(i))) { 376 widget->setGeometry(rect); 377 widget->setVisible(actions.at(i)->isVisible()); 378 } 379 319 380 y += rect.height(); 320 381 } 321 }322 323 void QMenuPrivate::updateActions()324 {325 Q_Q(const QMenu);326 if (!itemsDirty)327 return;328 sloppyAction = 0;329 calcActionRects(actionRects, actionList);330 for (QHash<QAction *, QWidget *>::ConstIterator item = widgetItems.constBegin(),331 end = widgetItems.constEnd(); item != end; ++item) {332 QAction *action = item.key();333 QWidget *widget = item.value();334 widget->setGeometry(actionRect(action));335 widget->setVisible(action->isVisible());336 }337 ncols = 1;338 int last_left = q->style()->pixelMetric(QStyle::PM_MenuVMargin, 0, q);339 if (!scroll) {340 for(int i = 0; i < actionList.count(); i++) {341 int left = actionRects.value(actionList.at(i)).left();342 if (left > last_left) {343 last_left = left;344 ncols++;345 }346 }347 }348 382 itemsDirty = 0; 349 383 } 350 384 351 QList<QAction *> QMenuPrivate::filterActions(const QList<QAction *> &actions) const352 {353 QList<QAction *> visibleActions;354 int i = 0;355 while (i < actions.count()) {356 QAction *action = actions.at(i);357 if (!action->isVisible()) {358 ++i;359 continue;360 }361 if (!action->isSeparator() || !collapsibleSeparators) {362 visibleActions.append(action);363 ++i;364 continue;365 }366 367 // no leading separators368 if (!visibleActions.isEmpty())369 visibleActions.append(action);370 371 // skip double/tripple/etc. separators372 while (i < actions.count()373 && (!actions.at(i)->isVisible() || actions.at(i)->isSeparator()))374 ++i;375 }376 377 if (collapsibleSeparators) {378 // remove trailing separators379 while (!visibleActions.isEmpty() && visibleActions.last()->isSeparator())380 visibleActions.removeLast();381 }382 383 return visibleActions;384 }385 386 385 QRect QMenuPrivate::actionRect(QAction *act) const 387 386 { 388 Q_Q(const QMenu); 389 QRect ret = actionRects.value(act); 390 if (ret.isNull()) 391 return ret; 392 if (scroll) 393 ret.translate(0, scroll->scrollOffset); 394 if (tearoff) 395 ret.translate(0, q->style()->pixelMetric(QStyle::PM_MenuTearoffHeight, 0, q)); 396 const int fw = q->style()->pixelMetric(QStyle::PM_MenuPanelWidth, 0, q); 397 ret.translate(fw+leftmargin, fw+topmargin); 398 return ret; 399 } 387 int index = actions.indexOf(act); 388 if (index == -1) 389 return QRect(); 390 391 updateActionRects(); 392 393 //we found the action 394 return actionRects.at(index); 395 } 396 397 #if defined(Q_WS_MAC) 398 static const qreal MenuFadeTimeInSec = 0.150; 399 #endif 400 400 401 401 void QMenuPrivate::hideUpToMenuBar() 402 402 { 403 403 Q_Q(QMenu); 404 bool fadeMenus = q->style()->styleHint(QStyle::SH_Menu_FadeOutOnHide); 404 405 if (!tornoff) { 405 406 QWidget *caused = causedPopup.widget; … … 416 417 caused = m->d_func()->causedPopup.widget; 417 418 if (!m->d_func()->tornoff) 418 hideMenu(m); 419 m->d_func()->setCurrentAction(0); 420 } else { 421 #ifndef QT_NO_TOOLBUTTON 422 if (qobject_cast<QToolButton*>(caused) == 0) 423 #endif 424 qWarning("QMenu: Internal error"); 425 caused = 0; 419 hideMenu(m, fadeMenus); 420 if (!fadeMenus) // Mac doesn't clear the action until after hidden. 421 m->d_func()->setCurrentAction(0); 422 } else { caused = 0; 426 423 } 427 424 } 425 #if defined(Q_WS_MAC) 426 if (fadeMenus) { 427 QEventLoop eventLoop; 428 QTimer::singleShot(int(MenuFadeTimeInSec * 1000), &eventLoop, SLOT(quit())); 429 QMacWindowFader::currentFader()->performFade(); 430 eventLoop.exec(); 431 } 432 #endif 428 433 } 429 434 setCurrentAction(0); 430 435 } 431 436 432 void QMenuPrivate::hideMenu(QMenu *menu )437 void QMenuPrivate::hideMenu(QMenu *menu, bool justRegister) 433 438 { 434 439 if (!menu) 435 440 return; 436 437 441 #if !defined(QT_NO_EFFECTS) 438 442 menu->blockSignals(true); … … 440 444 // Flash item which is about to trigger (if any). 441 445 if (menu->style()->styleHint(QStyle::SH_Menu_FlashTriggeredItem) 442 && currentAction && currentAction == actionAboutToTrigger ) {443 446 && currentAction && currentAction == actionAboutToTrigger 447 && menu->actions().contains(currentAction)) { 444 448 QEventLoop eventLoop; 445 449 QAction *activeAction = currentAction; 446 450 447 // Deselect and wait 60 ms.448 451 menu->setActiveAction(0); 449 452 QTimer::singleShot(60, &eventLoop, SLOT(quit())); … … 459 462 if (menu->style()->styleHint(QStyle::SH_Menu_FadeOutOnHide)) { 460 463 // ### Qt 4.4: 461 // Should be something like: q->transitionWindow(Qt::FadeOutTransition, 150);464 // Should be something like: q->transitionWindow(Qt::FadeOutTransition, MenuFadeTimeInSec); 462 465 // Hopefully we'll integrate qt/research/windowtransitions into main before 4.4. 463 466 // Talk to Richard, Trenton or Bjoern. 464 467 #if defined(Q_WS_MAC) 465 macWindowFade(qt_mac_window_for(menu)); // FIXME - what is the default duration for view animations 466 467 // Wait for the transition to complete. 468 QEventLoop eventLoop; 469 QTimer::singleShot(150, &eventLoop, SLOT(quit())); 470 eventLoop.exec(); 468 if (justRegister) { 469 QMacWindowFader::currentFader()->setFadeDuration(MenuFadeTimeInSec); 470 QMacWindowFader::currentFader()->registerWindowToFade(menu); 471 } else { 472 macWindowFade(qt_mac_window_for(menu), MenuFadeTimeInSec); 473 } 474 471 475 #endif // Q_WS_MAC 472 476 } … … 474 478 menu->blockSignals(false); 475 479 #endif // QT_NO_EFFECTS 476 menu->hide(); 480 if (!justRegister) 481 menu->hide(); 477 482 } 478 483 … … 514 519 { 515 520 Q_Q(QMenu); 516 const int scrollerHeight = q->style()->pixelMetric(QStyle::PM_MenuScrollerHeight, 0, q); 517 for(int i = 0, saccum = 0; i < actionList.count(); i++) { 518 QAction *act = actionList[i]; 521 updateActionRects(); 522 for(int i = 0, saccum = 0; i < actions.count(); i++) { 523 const QRect &rect = actionRects.at(i); 524 if (rect.isNull()) 525 continue; 519 526 if (scroll && scroll->scrollFlags & QMenuScroller::ScrollUp) { 520 saccum -= actionRects.value(act).height();521 if (saccum > scroll->scrollOffset -scrollerHeight)527 saccum -= rect.height(); 528 if (saccum > scroll->scrollOffset - scrollerHeight()) 522 529 continue; 523 530 } 531 QAction *act = actions.at(i); 524 532 if (!act->isSeparator() && 525 533 (q->style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled, 0, q) … … 536 544 Q_Q(QMenu); 537 545 tearoffHighlighted = 0; 538 if (action == currentAction && !(action && action->menu() && action->menu() != activeMenu)) { 539 if(QMenu *menu = qobject_cast<QMenu*>(causedPopup.widget)) { 540 if(causedPopup.action && menu->d_func()->activeMenu == q) 541 menu->d_func()->setCurrentAction(causedPopup.action, 0, reason, false); 546 if (action == currentAction) { 547 if (!action || !action->menu() || action->menu() == activeMenu) { 548 if(QMenu *menu = qobject_cast<QMenu*>(causedPopup.widget)) { 549 if(causedPopup.action && menu->d_func()->activeMenu == q) 550 menu->d_func()->setCurrentAction(causedPopup.action, 0, reason, false); 551 } 542 552 } 543 553 return; … … 554 564 #endif 555 565 #ifdef QT3_SUPPORT 556 emitHighlighted = (action && action != currentAction);566 emitHighlighted = action; 557 567 #endif 558 568 currentAction = action; … … 569 579 } 570 580 q->update(actionRect(action)); 571 QWidget *widget = widgetItems.value(action);572 581 573 582 if (reason == SelectedFromKeyboard) { 583 QWidget *widget = widgetItems.value(action); 574 584 if (widget) { 575 585 if (widget->focusPolicy() != Qt::NoFocus) … … 579 589 // get the focus 580 590 // Since the menu is a pop-up, it uses the popup reason. 581 if (!q->hasFocus()) 591 if (!q->hasFocus()) { 582 592 q->setFocus(Qt::PopupFocusReason); 593 } 583 594 } 584 595 } … … 589 600 #ifndef QT_NO_STATUSTIP 590 601 } else if (previousAction) { 591 QWidget *w = causedPopup.widget; 592 while (QMenu *m = qobject_cast<QMenu*>(w)) 593 w = m->d_func()->causedPopup.widget; 594 if (w) { 595 QString empty; 596 QStatusTipEvent tip(empty); 597 QApplication::sendEvent(w, &tip); 598 } 602 previousAction->d_func()->showStatusText(topCausedWidget(), QString()); 599 603 #endif 600 604 } … … 610 614 } 611 615 616 //return the top causedPopup.widget that is not a QMenu 617 QWidget *QMenuPrivate::topCausedWidget() const 618 { 619 QWidget* top = causedPopup.widget; 620 while (QMenu* m = qobject_cast<QMenu *>(top)) 621 top = m->d_func()->causedPopup.widget; 622 return top; 623 } 624 612 625 QAction *QMenuPrivate::actionAt(QPoint p) const 613 626 { … … 615 628 return 0; 616 629 617 for(int i = 0; i < actionList.count(); i++) { 618 QAction *act = actionList[i]; 619 if (actionRect(act).contains(p)) 620 return act; 630 for(int i = 0; i < actionRects.count(); i++) { 631 if (actionRects.at(i).contains(p)) 632 return actions.at(i); 621 633 } 622 634 return 0; … … 640 652 } 641 653 654 655 void QMenuPrivate::updateLayoutDirection() 656 { 657 Q_Q(QMenu); 658 //we need to mimic the cause of the popup's layout direction 659 //to allow setting it on a mainwindow for example 660 //we call setLayoutDirection_helper to not overwrite a user-defined value 661 if (!q->testAttribute(Qt::WA_SetLayoutDirection)) { 662 if (QWidget *w = causedPopup.widget) 663 setLayoutDirection_helper(w->layoutDirection()); 664 else if (QWidget *w = q->parentWidget()) 665 setLayoutDirection_helper(w->layoutDirection()); 666 else 667 setLayoutDirection_helper(QApplication::layoutDirection()); 668 } 669 } 670 671 642 672 /*! 643 673 Returns the action associated with this menu. … … 692 722 if (!scroll || !scroll->scrollFlags) 693 723 return; 724 updateActionRects(); 694 725 int newOffset = 0; 695 const int scrollHeight = q->style()->pixelMetric(QStyle::PM_MenuScrollerHeight, 0, q); 696 const int topScroll = (scroll->scrollFlags & QMenuScroller::ScrollUp) ? scrollHeight : 0; 697 const int botScroll = (scroll->scrollFlags & QMenuScroller::ScrollDown) ? scrollHeight : 0; 726 const int topScroll = (scroll->scrollFlags & QMenuScroller::ScrollUp) ? scrollerHeight() : 0; 727 const int botScroll = (scroll->scrollFlags & QMenuScroller::ScrollDown) ? scrollerHeight() : 0; 698 728 const int vmargin = q->style()->pixelMetric(QStyle::PM_MenuVMargin, 0, q); 699 729 const int fw = q->style()->pixelMetric(QStyle::PM_MenuPanelWidth, 0, q); 700 730 701 731 if (location == QMenuScroller::ScrollTop) { 702 for(int i = 0, saccum = 0; i < actionList.count(); i++) { 703 QAction *act = actionList.at(i); 704 if (act == action) { 732 for(int i = 0, saccum = 0; i < actions.count(); i++) { 733 if (actions.at(i) == action) { 705 734 newOffset = topScroll - saccum; 706 735 break; 707 736 } 708 saccum += actionRects. value(act).height();737 saccum += actionRects.at(i).height(); 709 738 } 710 739 } else { 711 for(int i = 0, saccum = 0; i < actionList.count(); i++) { 712 QAction *act = actionList.at(i); 713 saccum += actionRects.value(act).height(); 714 if (act == action) { 740 for(int i = 0, saccum = 0; i < actions.count(); i++) { 741 saccum += actionRects.at(i).height(); 742 if (actions.at(i) == action) { 715 743 if (location == QMenuScroller::ScrollCenter) 716 744 newOffset = ((q->height() / 2) - botScroll) - (saccum - topScroll); … … 721 749 } 722 750 if(newOffset) 723 newOffset -= fw *2;751 newOffset -= fw * 2; 724 752 } 725 753 … … 729 757 newScrollFlags |= QMenuScroller::ScrollUp; 730 758 int saccum = newOffset; 731 for(int i = 0; i < action List.count(); i++) {732 saccum += actionRects. value(actionList.at(i)).height();759 for(int i = 0; i < actionRects.count(); i++) { 760 saccum += actionRects.at(i).height(); 733 761 if (saccum > q->height()) { 734 762 newScrollFlags |= QMenuScroller::ScrollDown; … … 748 776 newOffset -= vmargin; 749 777 750 QRect screen = popupGeometry( QApplication::desktop()->screenNumber(q));778 QRect screen = popupGeometry(q); 751 779 const int desktopFrame = q->style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, 0, q); 752 780 if (q->height() < screen.height()-(desktopFrame*2)-1) { … … 781 809 782 810 //actually update flags 783 scroll->scrollOffset = newOffset; 784 if (scroll->scrollOffset > 0) 785 scroll->scrollOffset = 0; 811 const int delta = qMin(0, newOffset) - scroll->scrollOffset; //make sure the new offset is always negative 812 if (!itemsDirty && delta) { 813 //we've scrolled so we need to update the action rects 814 for (int i = 0; i < actionRects.count(); ++i) { 815 QRect ¤t = actionRects[i]; 816 current.moveTop(current.top() + delta); 817 818 //we need to update the widgets geometry 819 if (QWidget *w = widgetItems.value(actions.at(i))) 820 w->setGeometry(current); 821 } 822 } 823 scroll->scrollOffset += delta; 786 824 scroll->scrollFlags = newScrollFlags; 787 825 if (active) … … 794 832 { 795 833 Q_Q(QMenu); 834 updateActionRects(); 796 835 if(location == QMenuScroller::ScrollBottom) { 797 for(int i = actionList.size()-1; i >= 0; --i) { 798 QAction *act = actionList.at(i); 836 for(int i = actions.size()-1; i >= 0; --i) { 837 QAction *act = actions.at(i); 838 if (actionRects.at(i).isNull()) 839 continue; 799 840 if (!act->isSeparator() && 800 841 (q->style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled, 0, q) … … 808 849 } 809 850 } else if(location == QMenuScroller::ScrollTop) { 810 for(int i = 0; i < actionList.size(); ++i) { 811 QAction *act = actionList.at(i); 851 for(int i = 0; i < actions.size(); ++i) { 852 QAction *act = actions.at(i); 853 if (actionRects.at(i).isNull()) 854 continue; 812 855 if (!act->isSeparator() && 813 856 (q->style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled, 0, q) … … 829 872 if (!scroll || !(scroll->scrollFlags & direction)) //not really possible... 830 873 return; 831 const int scrollHeight = q->style()->pixelMetric(QStyle::PM_MenuScrollerHeight, 0, q);832 const int topScroll = (scroll->scrollFlags & QMenuScroller::ScrollUp) ? scroll Height: 0;833 const int botScroll = (scroll->scrollFlags & QMenuScroller::ScrollDown) ? scroll Height: 0;874 updateActionRects(); 875 const int topScroll = (scroll->scrollFlags & QMenuScroller::ScrollUp) ? scrollerHeight() : 0; 876 const int botScroll = (scroll->scrollFlags & QMenuScroller::ScrollDown) ? scrollerHeight() : 0; 834 877 const int vmargin = q->style()->pixelMetric(QStyle::PM_MenuVMargin, 0, q); 835 878 const int fw = q->style()->pixelMetric(QStyle::PM_MenuPanelWidth, 0, q); 836 879 const int offset = topScroll ? topScroll-vmargin : 0; 837 880 if (direction == QMenuScroller::ScrollUp) { 838 for(int i = 0, saccum = 0; i < actionList.count(); i++) { 839 QAction *act = actionList.at(i); 840 const int iHeight = actionRects.value(act).height(); 841 saccum -= iHeight; 881 for(int i = 0, saccum = 0; i < actions.count(); i++) { 882 saccum -= actionRects.at(i).height(); 842 883 if (saccum <= scroll->scrollOffset-offset) { 843 scrollMenu(act , page ? QMenuScroller::ScrollBottom : QMenuScroller::ScrollTop, active);884 scrollMenu(actions.at(i), page ? QMenuScroller::ScrollBottom : QMenuScroller::ScrollTop, active); 844 885 break; 845 886 } … … 847 888 } else if (direction == QMenuScroller::ScrollDown) { 848 889 bool scrolled = false; 849 for(int i = 0, saccum = 0; i < actionList.count(); i++) { 850 QAction *act = actionList.at(i); 851 const int iHeight = actionRects.value(act).height(); 890 for(int i = 0, saccum = 0; i < actions.count(); i++) { 891 const int iHeight = actionRects.at(i).height(); 852 892 saccum -= iHeight; 853 893 if (saccum <= scroll->scrollOffset-offset) { 854 894 const int scrollerArea = q->height() - botScroll - fw*2; 855 895 int visible = (scroll->scrollOffset-offset) - saccum; 856 for(i++ ; i < actionList.count(); i++) { 857 act = actionList.at(i); 858 const int iHeight = actionRects.value(act).height(); 859 visible += iHeight; 896 for(i++ ; i < actions.count(); i++) { 897 visible += actionRects.at(i).height(); 860 898 if (visible > scrollerArea - topScroll) { 861 899 scrolled = true; 862 scrollMenu(act , page ? QMenuScroller::ScrollTop : QMenuScroller::ScrollBottom, active);900 scrollMenu(actions.at(i), page ? QMenuScroller::ScrollTop : QMenuScroller::ScrollBottom, active); 863 901 break; 864 902 } … … 883 921 bool isScroll = false; 884 922 if (pos.x() >= 0 && pos.x() < q->width()) { 885 const int scrollerHeight = q->style()->pixelMetric(QStyle::PM_MenuScrollerHeight, 0, q);886 923 for(int dir = QMenuScroller::ScrollUp; dir <= QMenuScroller::ScrollDown; dir = dir << 1) { 887 924 if (scroll->scrollFlags & dir) { 888 925 if (dir == QMenuScroller::ScrollUp) 889 isScroll = (pos.y() <= scrollerHeight );926 isScroll = (pos.y() <= scrollerHeight()); 890 927 else if (dir == QMenuScroller::ScrollDown) 891 isScroll = (pos.y() >= q->height() -scrollerHeight);928 isScroll = (pos.y() >= q->height() - scrollerHeight()); 892 929 if (isScroll) { 893 930 scroll->scrollDirection = dir; … … 898 935 } 899 936 if (isScroll) { 900 if (!scroll->scrollTimer) 901 scroll->scrollTimer = new QBasicTimer; 902 scroll->scrollTimer->start(50, q); 937 scroll->scrollTimer.start(50, q); 903 938 return true; 904 } else if (scroll->scrollTimer && scroll->scrollTimer->isActive()){905 scroll->scrollTimer ->stop();939 } else { 940 scroll->scrollTimer.stop(); 906 941 } 907 942 } … … 910 945 QRect tearRect(0, 0, q->width(), q->style()->pixelMetric(QStyle::PM_MenuTearoffHeight, 0, q)); 911 946 if (scroll && scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollUp) 912 tearRect.translate(0, q->style()->pixelMetric(QStyle::PM_MenuScrollerHeight, 0, q));947 tearRect.translate(0, scrollerHeight()); 913 948 q->update(tearRect); 914 949 if (tearRect.contains(pos) && hasMouseMoved(e->globalPos())) { … … 957 992 } 958 993 994 class ExceptionGuard 995 { 996 public: 997 inline ExceptionGuard(bool *w = 0) : watched(w) { Q_ASSERT(!(*watched)); *watched = true; } 998 inline ~ExceptionGuard() { *watched = false; } 999 inline operator bool() { return *watched; } 1000 private: 1001 bool *watched; 1002 }; 1003 959 1004 void QMenuPrivate::activateCausedStack(const QList<QPointer<QWidget> > &causedStack, QAction *action, QAction::ActionEvent action_e, bool self) 960 1005 { 961 Q_ASSERT(!activationRecursionGuard); 962 activationRecursionGuard = true; 1006 ExceptionGuard guard(&activationRecursionGuard); 963 1007 #ifdef QT3_SUPPORT 964 1008 const int actionId = q_func()->findIdForAction(action); … … 1005 1049 } 1006 1050 } 1007 activationRecursionGuard = false;1008 1051 } 1009 1052 … … 1035 1078 hideUpToMenuBar(); 1036 1079 } else { 1037 for(QWidget *widget = qApp->activePopupWidget(); widget; ) {1080 for(QWidget *widget = QApplication::activePopupWidget(); widget; ) { 1038 1081 if (QMenu *qmenu = qobject_cast<QMenu*>(widget)) { 1039 1082 if(qmenu == q) … … 1069 1112 } 1070 1113 #endif 1071 QWidget *w = causedPopup.widget; 1072 while (QMenu *m = qobject_cast<QMenu*>(w)) 1073 w = m->d_func()->causedPopup.widget; 1074 action->showStatusText(w); 1114 action->showStatusText(topCausedWidget()); 1075 1115 } else { 1076 1116 actionAboutToTrigger = 0; … … 1082 1122 Q_Q(QMenu); 1083 1123 if (QAction *action = qobject_cast<QAction *>(q->sender())) { 1124 QWeakPointer<QAction> actionGuard = action; 1084 1125 #ifdef QT3_SUPPORT 1085 1126 //we store it here because the action might be deleted/changed by connected slots … … 1091 1132 #endif 1092 1133 1093 if (!activationRecursionGuard ) {1134 if (!activationRecursionGuard && actionGuard) { 1094 1135 //in case the action has not been activated by the mouse 1095 1136 //we check the parent hierarchy … … 1165 1206 option->palette.setCurrentColorGroup(QPalette::Disabled); 1166 1207 1167 option->font = action->font(); 1208 option->font = action->font().resolve(font()); 1209 option->fontMetrics = QFontMetrics(option->font); 1168 1210 1169 1211 if (d->currentAction && d->currentAction == action && !d->currentAction->isSeparator()) { … … 1209 1251 bars, context menus, and other popup menus. 1210 1252 1211 \ingroup application1253 \ingroup mainwindow-classes 1212 1254 \ingroup basicwidgets 1213 \mainclass 1255 1214 1256 1215 1257 A menu widget is a selection menu. It can be either a pull-down … … 1303 1345 It is not possible to display an icon in a native menu on Windows Mobile. 1304 1346 1347 \section1 QMenu on Mac OS X with Qt build against Cocoa 1348 1349 QMenu can be inserted only once in a menu/menubar. Subsequent insertions will 1350 have no effect or will result in a disabled menu item. 1351 1305 1352 See the \l{mainwindows/menus}{Menus} example for an example of how 1306 1353 to use QMenuBar and QMenu in your application. … … 1360 1407 { 1361 1408 Q_D(QMenu); 1362 for (QHash<QAction *, QWidget *>::ConstIterator item = d->widgetItems.constBegin(), 1363 end = d->widgetItems.constEnd(); item != end; ++item) { 1364 QWidgetAction *action = static_cast<QWidgetAction *>(item.key()); 1365 QWidget *widget = item.value(); 1366 if (action && widget) 1409 QHash<QAction *, QWidget *>::iterator it = d->widgetItems.begin(); 1410 for (; it != d->widgetItems.end(); ++it) { 1411 if (QWidget *widget = it.value()) { 1412 QWidgetAction *action = static_cast<QWidgetAction *>(it.key()); 1367 1413 action->releaseWidget(widget); 1368 } 1369 d->widgetItems.clear(); 1414 *it = 0; 1415 } 1416 } 1370 1417 1371 1418 if (d->eventLoop) 1372 1419 d->eventLoop->exit(); 1373 if (d->tornPopup) 1374 d->tornPopup->close(); 1420 hideTearOffMenu(); 1375 1421 } 1376 1422 … … 1583 1629 if (d->tearoff == b) 1584 1630 return; 1585 if (!b && d->tornPopup)1586 d->tornPopup->close();1631 if (!b) 1632 hideTearOffMenu(); 1587 1633 d->tearoff = b; 1588 1634 … … 1619 1665 void QMenu::hideTearOffMenu() 1620 1666 { 1621 if ( d_func()->tornPopup)1622 d_func()->tornPopup->close();1667 if (QWidget *w = d_func()->tornPopup) 1668 w->close(); 1623 1669 } 1624 1670 … … 1718 1764 { 1719 1765 Q_D(const QMenu); 1720 ensurePolished(); 1721 QMap<QAction*, QRect> actionRects; 1722 QList<QAction*> actionList; 1723 d->calcActionRects(actionRects, actionList); 1766 d->updateActionRects(); 1724 1767 1725 1768 QSize s; 1726 QStyleOption opt(0); 1727 opt.rect = rect(); 1728 opt.palette = palette(); 1729 opt.state = QStyle::State_None; 1730 for (QMap<QAction*, QRect>::const_iterator i = actionRects.constBegin(); 1731 i != actionRects.constEnd(); ++i) { 1732 if (i.value().bottom() > s.height()) 1733 s.setHeight(i.value().y()+i.value().height()); 1734 if (i.value().right() > s.width()) 1735 s.setWidth(i.value().right()); 1736 } 1737 if (d->tearoff) 1738 s.rheight() += style()->pixelMetric(QStyle::PM_MenuTearoffHeight, &opt, this); 1739 if (const int fw = style()->pixelMetric(QStyle::PM_MenuPanelWidth, &opt, this)) { 1740 s.rwidth() += fw*2; 1741 s.rheight() += fw*2; 1769 for (int i = 0; i < d->actionRects.count(); ++i) { 1770 const QRect &rect = d->actionRects.at(i); 1771 if (rect.isNull()) 1772 continue; 1773 if (rect.bottom() >= s.height()) 1774 s.setHeight(rect.y() + rect.height()); 1775 if (rect.right() >= s.width()) 1776 s.setWidth(rect.x() + rect.width()); 1742 1777 } 1743 1778 // Note that the action rects calculated above already include 1744 1779 // the top and left margins, so we only need to add margins for 1745 1780 // the bottom and right. 1746 s.rwidth() += style()->pixelMetric(QStyle::PM_MenuHMargin, &opt, this); 1747 s.rheight() += style()->pixelMetric(QStyle::PM_MenuVMargin, &opt, this); 1748 1749 s += QSize(d->leftmargin + d->rightmargin, d->topmargin + d->bottommargin); 1781 QStyleOption opt(0); 1782 opt.init(this); 1783 const int fw = style()->pixelMetric(QStyle::PM_MenuPanelWidth, &opt, this); 1784 s.rwidth() += style()->pixelMetric(QStyle::PM_MenuHMargin, &opt, this) + fw + d->rightmargin; 1785 s.rheight() += style()->pixelMetric(QStyle::PM_MenuVMargin, &opt, this) + fw + d->bottommargin; 1750 1786 1751 1787 return style()->sizeFromContents(QStyle::CT_Menu, &opt, … … 1777 1813 d->motions = 0; 1778 1814 d->doChildEffects = true; 1815 d->updateLayoutDirection(); 1779 1816 1780 1817 #ifndef QT_NO_MENUBAR 1781 1818 // if this menu is part of a chain attached to a QMenuBar, set the 1782 1819 // _NET_WM_WINDOW_TYPE_DROPDOWN_MENU X11 window type 1783 QWidget* top = this; 1784 while (QMenu* m = qobject_cast<QMenu *>(top)) 1785 top = m->d_func()->causedPopup.widget; 1786 setAttribute(Qt::WA_X11NetWmWindowTypeDropDownMenu, qobject_cast<QMenuBar *>(top) != 0); 1820 setAttribute(Qt::WA_X11NetWmWindowTypeDropDownMenu, qobject_cast<QMenuBar *>(d->topCausedWidget()) != 0); 1787 1821 #endif 1788 1822 1789 1823 ensurePolished(); // Get the right font 1790 1824 emit aboutToShow(); 1791 d->updateActions(); 1792 QPoint pos = p; 1825 const bool actionListChanged = d->itemsDirty; 1826 d->updateActionRects(); 1827 QPoint pos; 1828 QPushButton *causedButton = qobject_cast<QPushButton*>(d->causedPopup.widget); 1829 if (actionListChanged && causedButton) 1830 pos = QPushButtonPrivate::get(causedButton)->adjustedMenuPosition(); 1831 else 1832 pos = p; 1833 1793 1834 QSize size = sizeHint(); 1794 QRect screen = d->popupGeometry(QApplication::desktop()->screenNumber(p)); 1835 QRect screen; 1836 #ifndef QT_NO_GRAPHICSVIEW 1837 bool isEmbedded = d->nearestGraphicsProxyWidget(this); 1838 if (isEmbedded) 1839 screen = d->popupGeometry(this); 1840 else 1841 #endif 1842 screen = d->popupGeometry(QApplication::desktop()->screenNumber(p)); 1843 1795 1844 const int desktopFrame = style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, 0, this); 1796 1845 bool adjustToDesktop = !window()->testAttribute(Qt::WA_DontShowOnScreen); 1846 #ifdef QT_KEYPAD_NAVIGATION 1847 if (!atAction && QApplication::keypadNavigationEnabled()) { 1848 // Try to have one item activated 1849 if (d->defaultAction && d->defaultAction->isEnabled()) { 1850 atAction = d->defaultAction; 1851 // TODO: This works for first level menus, not yet sub menus 1852 } else { 1853 foreach (QAction *action, d->actions) 1854 if (action->isEnabled()) { 1855 atAction = action; 1856 break; 1857 } 1858 } 1859 d->currentAction = atAction; 1860 } 1861 #endif 1797 1862 if (d->ncols > 1) { 1798 1863 pos.setY(screen.top()+desktopFrame); 1799 1864 } else if (atAction) { 1800 for(int i =0, above_height=0; i<(int)d->actionList.count(); i++) {1801 QAction *action = d->action List.at(i);1865 for(int i = 0, above_height = 0; i < d->actions.count(); i++) { 1866 QAction *action = d->actions.at(i); 1802 1867 if (action == atAction) { 1803 int newY = pos.y() -above_height;1868 int newY = pos.y() - above_height; 1804 1869 if (d->scroll && newY < desktopFrame) { 1805 1870 d->scroll->scrollFlags = d->scroll->scrollFlags … … 1813 1878 && !style()->styleHint(QStyle::SH_Menu_FillScreenWithScroll, 0, this)) { 1814 1879 int below_height = above_height + d->scroll->scrollOffset; 1815 for(int i2 = i; i2 < (int)d->actionList.count(); i2++)1816 below_height += d->actionRects. value(d->actionList.at(i2)).height();1880 for(int i2 = i; i2 < d->actionRects.count(); i2++) 1881 below_height += d->actionRects.at(i2).height(); 1817 1882 size.setHeight(below_height); 1818 1883 } 1819 1884 break; 1820 1885 } else { 1821 above_height += d->actionRects. value(action).height();1886 above_height += d->actionRects.at(i).height(); 1822 1887 } 1823 1888 } … … 1830 1895 if (adjustToDesktop) { 1831 1896 //handle popup falling "off screen" 1832 if ( qApp->layoutDirection() == Qt::RightToLeft) {1897 if (isRightToLeft()) { 1833 1898 if(snapToMouse) //position flowing left from the mouse 1834 1899 pos.setX(mouse.x()-size.width()); 1900 1901 #ifndef QT_NO_MENUBAR 1902 //if in a menubar, it should be right-aligned 1903 if (qobject_cast<QMenuBar*>(d->causedPopup.widget)) 1904 pos.rx() -= size.width(); 1905 #endif //QT_NO_MENUBAR 1835 1906 1836 1907 if (pos.x() < screen.left()+desktopFrame) … … 1840 1911 } else { 1841 1912 if (pos.x()+size.width()-1 > screen.right()-desktopFrame) 1842 pos.setX( qMin(p.x()+size.width(), screen.right()-desktopFrame-size.width()+1));1913 pos.setX(screen.right()-desktopFrame-size.width()+1); 1843 1914 if (pos.x() < screen.left()+desktopFrame) 1844 pos.setX( qMax(p.x(), screen.left() + desktopFrame));1915 pos.setX(screen.left() + desktopFrame); 1845 1916 } 1846 1917 if (pos.y() + size.height() - 1 > screen.bottom() - desktopFrame) { … … 1868 1939 setGeometry(QRect(pos, size)); 1869 1940 #ifndef QT_NO_EFFECTS 1870 int hGuess = qApp->layoutDirection() == Qt::RightToLeft? QEffects::LeftScroll : QEffects::RightScroll;1941 int hGuess = isRightToLeft() ? QEffects::LeftScroll : QEffects::RightScroll; 1871 1942 int vGuess = QEffects::DownScroll; 1872 if ( qApp->layoutDirection() == Qt::RightToLeft) {1943 if (isRightToLeft()) { 1873 1944 if ((snapToMouse && (pos.x() + size.width()/2 > mouse.x())) || 1874 1945 (qobject_cast<QMenu*>(d->causedPopup.widget) && pos.x() + size.width()/2 > d->causedPopup.widget->x())) … … 2026 2097 { 2027 2098 QMenu menu(parent); 2028 for(QList<QAction*>::ConstIterator it = actions.constBegin(); it != actions.constEnd(); ++it) 2029 menu.addAction((*it)); 2099 menu.addActions(actions); 2030 2100 return menu.exec(pos, at); 2031 2101 } … … 2077 2147 d->causedPopup.widget = 0; 2078 2148 d->causedPopup.action = 0; 2149 if (d->scroll) 2150 d->scroll->scrollTimer.stop(); //make sure the timer stops 2079 2151 } 2080 2152 … … 2085 2157 { 2086 2158 Q_D(QMenu); 2159 d->updateActionRects(); 2087 2160 QPainter p(this); 2088 2161 QRegion emptyArea = QRegion(rect()); … … 2097 2170 2098 2171 //draw the items that need updating.. 2099 for (int i = 0; i < d->action List.count(); ++i) {2100 QAction *action = d->action List.at(i);2101 QRect adjustedActionRect = d->actionRect (action);2172 for (int i = 0; i < d->actions.count(); ++i) { 2173 QAction *action = d->actions.at(i); 2174 QRect adjustedActionRect = d->actionRects.at(i); 2102 2175 if (!e->rect().intersects(adjustedActionRect) 2103 2176 || d->widgetItems.value(action)) … … 2117 2190 //draw the scroller regions.. 2118 2191 if (d->scroll) { 2119 const int scrollerHeight = style()->pixelMetric(QStyle::PM_MenuScrollerHeight, 0, this);2120 2192 menuOpt.menuItemType = QStyleOptionMenuItem::Scroller; 2121 2193 menuOpt.state |= QStyle::State_Enabled; 2122 2194 if (d->scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollUp) { 2123 menuOpt.rect.setRect(fw, fw, width() - (fw * 2), scrollerHeight);2195 menuOpt.rect.setRect(fw, fw, width() - (fw * 2), d->scrollerHeight()); 2124 2196 emptyArea -= QRegion(menuOpt.rect); 2125 2197 p.setClipRect(menuOpt.rect); … … 2127 2199 } 2128 2200 if (d->scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollDown) { 2129 menuOpt.rect.setRect(fw, height() - scrollerHeight- fw, width() - (fw * 2),2130 scrollerHeight);2201 menuOpt.rect.setRect(fw, height() - d->scrollerHeight() - fw, width() - (fw * 2), 2202 d->scrollerHeight()); 2131 2203 emptyArea -= QRegion(menuOpt.rect); 2132 2204 menuOpt.state |= QStyle::State_DownArrow; … … 2141 2213 style()->pixelMetric(QStyle::PM_MenuTearoffHeight, 0, this)); 2142 2214 if (d->scroll && d->scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollUp) 2143 menuOpt.rect.translate(0, style()->pixelMetric(QStyle::PM_MenuScrollerHeight, 0, this));2215 menuOpt.rect.translate(0, d->scrollerHeight()); 2144 2216 emptyArea -= QRegion(menuOpt.rect); 2145 2217 p.setClipRect(menuOpt.rect); … … 2235 2307 action->menu()->d_func()->setFirstActionActive(); 2236 2308 else { 2237 #if defined(Q_WS_WIN) && !defined(QT_NO_MENUBAR)2309 #if defined(Q_WS_WIN) 2238 2310 //On Windows only context menus can be activated with the right button 2239 bool isContextMenu = true; 2240 const QWidget *cause = d->causedPopup.widget; 2241 while (cause) { 2242 //if the popup was caused by either QMenuBar or a QToolButton, it is not a context menu 2243 if (qobject_cast<const QMenuBar *>(cause) || qobject_cast<const QToolButton *>(cause)) { 2244 isContextMenu = false; 2245 break; 2246 } else if (const QMenu *menu = qobject_cast<const QMenu *>(cause)) { 2247 cause = menu->d_func()->causedPopup.widget; 2248 } else { 2249 break; 2250 } 2251 } 2252 if (e->button() == Qt::LeftButton || (e->button() == Qt::RightButton && isContextMenu)) 2311 if (e->button() == Qt::LeftButton || d->topCausedWidget() == 0) 2253 2312 #endif 2254 2313 d->activateAction(action, QAction::Trigger); … … 2299 2358 Q_D(QMenu); 2300 2359 switch (e->type()) { 2360 case QEvent::Polish: 2361 d->updateLayoutDirection(); 2362 break; 2301 2363 case QEvent::ShortcutOverride: { 2302 2364 QKeyEvent *kev = static_cast<QKeyEvent*>(e); … … 2331 2393 } 2332 2394 d->itemsDirty = 1; 2333 d->updateAction s();2395 d->updateActionRects(); 2334 2396 break; } 2335 2397 case QEvent::Show: 2336 2398 d->mouseDown = 0; 2337 d->updateAction s();2399 d->updateActionRects(); 2338 2400 if (d->currentAction) 2339 2401 d->popupAction(d->currentAction, 0, false); … … 2371 2433 { 2372 2434 Q_D(QMenu); 2435 d->updateActionRects(); 2373 2436 int key = e->key(); 2374 2437 if (isRightToLeft()) { // in reverse mode open/close key for submenues are reversed … … 2422 2485 if (!d->currentAction) { 2423 2486 if(key == Qt::Key_Down) { 2424 for(int i = 0; i < d->actionList.size(); ++i) { 2425 QAction *act = d->actionList.at(i); 2487 for(int i = 0; i < d->actions.count(); ++i) { 2488 QAction *act = d->actions.at(i); 2489 if (d->actionRects.at(i).isNull()) 2490 continue; 2426 2491 if (!act->isSeparator() && 2427 2492 (style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled, 0, this) … … 2432 2497 } 2433 2498 } else { 2434 for(int i = d->actionList.size()-1; i >= 0; --i) { 2435 QAction *act = d->actionList.at(i); 2499 for(int i = d->actions.count()-1; i >= 0; --i) { 2500 QAction *act = d->actions.at(i); 2501 if (d->actionRects.at(i).isNull()) 2502 continue; 2436 2503 if (!act->isSeparator() && 2437 2504 (style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled, 0, this) … … 2443 2510 } 2444 2511 } else { 2445 for(int i =0, y=0; !nextAction && i < (int)d->actionList.count(); i++) {2446 QAction *act = d->action List.at(i);2512 for(int i = 0, y = 0; !nextAction && i < d->actions.count(); i++) { 2513 QAction *act = d->actions.at(i); 2447 2514 if (act == d->currentAction) { 2448 2515 if (key == Qt::Key_Up) { … … 2453 2520 if (d->scroll) 2454 2521 scroll_loc = QMenuPrivate::QMenuScroller::ScrollBottom; 2455 next_i = d->action List.count()-1;2522 next_i = d->actionRects.count()-1; 2456 2523 } 2457 QAction *next = d->action List.at(next_i);2524 QAction *next = d->actions.at(next_i); 2458 2525 if (next == d->currentAction) 2459 2526 break; 2527 if (d->actionRects.at(next_i).isNull()) 2528 continue; 2460 2529 if (next->isSeparator() || 2461 2530 (!next->isEnabled() && … … 2464 2533 nextAction = next; 2465 2534 if (d->scroll && (d->scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollUp)) { 2466 int topVisible = style()->pixelMetric(QStyle::PM_MenuScrollerHeight, 0, this);2535 int topVisible = d->scrollerHeight(); 2467 2536 if (d->tearoff) 2468 2537 topVisible += style()->pixelMetric(QStyle::PM_MenuTearoffHeight, 0, this); 2469 if (((y + d->scroll->scrollOffset) - topVisible) <= d->actionRects. value(nextAction).height())2538 if (((y + d->scroll->scrollOffset) - topVisible) <= d->actionRects.at(next_i).height()) 2470 2539 scroll_loc = QMenuPrivate::QMenuScroller::ScrollTop; 2471 2540 } … … 2475 2544 d->tearoffHighlighted = 1; 2476 2545 } else { 2477 y += d->actionRects. value(act).height();2546 y += d->actionRects.at(i).height(); 2478 2547 for(int next_i = i+1; true; next_i++) { 2479 if (next_i == d->action List.count()) {2548 if (next_i == d->actionRects.count()) { 2480 2549 if(!style()->styleHint(QStyle::SH_Menu_SelectionWrap, 0, this)) 2481 2550 break; … … 2484 2553 next_i = 0; 2485 2554 } 2486 QAction *next = d->action List.at(next_i);2555 QAction *next = d->actions.at(next_i); 2487 2556 if (next == d->currentAction) 2488 2557 break; 2558 if (d->actionRects.at(next_i).isNull()) 2559 continue; 2489 2560 if (next->isSeparator() || 2490 2561 (!next->isEnabled() && … … 2493 2564 nextAction = next; 2494 2565 if (d->scroll && (d->scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollDown)) { 2495 const int scrollerHeight = style()->pixelMetric(QStyle::PM_MenuScrollerHeight, 0, this); 2496 int bottomVisible = height()-scrollerHeight; 2566 int bottomVisible = height() - d->scrollerHeight(); 2497 2567 if (d->scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollUp) 2498 bottomVisible -= scrollerHeight;2568 bottomVisible -= d->scrollerHeight(); 2499 2569 if (d->tearoff) 2500 2570 bottomVisible -= style()->pixelMetric(QStyle::PM_MenuTearoffHeight, 0, this); 2501 if ((y + d->scroll->scrollOffset + d->actionRects. value(nextAction).height()) > bottomVisible)2571 if ((y + d->scroll->scrollOffset + d->actionRects.at(next_i).height()) > bottomVisible) 2502 2572 scroll_loc = QMenuPrivate::QMenuScroller::ScrollBottom; 2503 2573 } … … 2507 2577 break; 2508 2578 } 2509 y += d->actionRects. value(act).height();2579 y += d->actionRects.at(i).height(); 2510 2580 } 2511 2581 } 2512 2582 if (nextAction) { 2513 2583 if (d->scroll && scroll_loc != QMenuPrivate::QMenuScroller::ScrollStay) { 2514 if (d->scroll->scrollTimer) 2515 d->scroll->scrollTimer->stop(); 2584 d->scroll->scrollTimer.stop(); 2516 2585 d->scrollMenu(nextAction, scroll_loc); 2517 2586 } … … 2562 2631 d->hideMenu(this); 2563 2632 #ifndef QT_NO_MENUBAR 2564 if (QMenuBar *mb = qobject_cast<QMenuBar*>( qApp->focusWidget())) {2633 if (QMenuBar *mb = qobject_cast<QMenuBar*>(QApplication::focusWidget())) { 2565 2634 mb->d_func()->setKeyboardMode(false); 2566 2635 } … … 2635 2704 d->searchBufferTimer.start(2000, this); 2636 2705 d->searchBuffer += e->text(); 2637 for(int i = 0; i < d->action List.size(); ++i) {2706 for(int i = 0; i < d->actions.size(); ++i) { 2638 2707 int match_count = 0; 2639 register QAction *act = d->actionList.at(i); 2708 if (d->actionRects.at(i).isNull()) 2709 continue; 2710 QAction *act = d->actions.at(i); 2640 2711 const QString act_text = act->text(); 2641 2712 for(int c = 0; c < d->searchBuffer.size(); ++c) { … … 2654 2725 QAction *first = 0, *currentSelected = 0, *firstAfterCurrent = 0; 2655 2726 QChar c = e->text().at(0).toUpper(); 2656 for(int i = 0; i < d->actionList.size(); ++i) { 2657 register QAction *act = d->actionList.at(i); 2727 for(int i = 0; i < d->actions.size(); ++i) { 2728 if (d->actionRects.at(i).isNull()) 2729 continue; 2730 QAction *act = d->actions.at(i); 2658 2731 QKeySequence sequence = QKeySequence::mnemonic(act->text()); 2659 2732 int key = sequence[0] & 0xffff; … … 2690 2763 } 2691 2764 if (!key_consumed) { 2692 if (QWidget *caused = d->causedPopup.widget) {2693 while(QMenu *m = qobject_cast<QMenu*>(caused))2694 caused = m->d_func()->causedPopup.widget;2695 2765 #ifndef QT_NO_MENUBAR 2696 if (QMenuBar *mb = qobject_cast<QMenuBar*>(caused)) { 2697 QAction *oldAct = mb->d_func()->currentAction; 2698 QApplication::sendEvent(mb, e); 2699 if (mb->d_func()->currentAction != oldAct) 2700 key_consumed = true; 2701 } 2702 #endif 2766 if (QMenuBar *mb = qobject_cast<QMenuBar*>(d->topCausedWidget())) { 2767 QAction *oldAct = mb->d_func()->currentAction; 2768 QApplication::sendEvent(mb, e); 2769 if (mb->d_func()->currentAction != oldAct) 2770 key_consumed = true; 2703 2771 } 2772 #endif 2704 2773 } 2705 2774 2706 2775 #ifdef Q_OS_WIN32 2707 2776 if (key_consumed && (e->key() == Qt::Key_Control || e->key() == Qt::Key_Shift || e->key() == Qt::Key_Meta)) 2708 qApp->beep();2777 QApplication::beep(); 2709 2778 #endif // Q_OS_WIN32 2710 2779 } … … 2726 2795 if (d->motions == 0) // ignore first mouse move event (see enterEvent()) 2727 2796 return; 2728 d->hasHadMouse |=rect().contains(e->pos());2797 d->hasHadMouse = d->hasHadMouse || rect().contains(e->pos()); 2729 2798 2730 2799 QAction *action = d->actionAt(e->pos()); 2731 2800 if (!action) { 2732 if (d->hasHadMouse && !rect().contains(e->pos()))2801 if (d->hasHadMouse) 2733 2802 d->setCurrentAction(0); 2734 2803 return; 2735 } else if(e->buttons() & (Qt::LeftButton | Qt::RightButton)) {2804 } else if(e->buttons()) { 2736 2805 d->mouseDown = this; 2737 2806 } … … 2761 2830 if (!d->sloppyRegion.isEmpty()) 2762 2831 d->sloppyRegion = QRegion(); 2832 if (!d->activeMenu && d->currentAction) 2833 setActiveAction(0); 2763 2834 } 2764 2835 … … 2770 2841 { 2771 2842 Q_D(QMenu); 2772 if (d->scroll && d->scroll->scrollTimer && d->scroll->scrollTimer->timerId() == e->timerId()) {2843 if (d->scroll && d->scroll->scrollTimer.timerId() == e->timerId()) { 2773 2844 d->scrollMenu((QMenuPrivate::QMenuScroller::ScrollDirection)d->scroll->scrollDirection); 2774 2845 if (d->scroll->scrollFlags == QMenuPrivate::QMenuScroller::ScrollNone) 2775 d->scroll->scrollTimer ->stop();2846 d->scroll->scrollTimer.stop(); 2776 2847 } else if(QMenuPrivate::menuDelayTimer.timerId() == e->timerId()) { 2777 2848 QMenuPrivate::menuDelayTimer.stop(); … … 2800 2871 connect(e->action(), SIGNAL(hovered()), this, SLOT(_q_actionHovered())); 2801 2872 } 2802 2803 2873 if (QWidgetAction *wa = qobject_cast<QWidgetAction *>(e->action())) { 2804 2874 QWidget *widget = wa->requestWidget(this); … … 2807 2877 } 2808 2878 } else if (e->type() == QEvent::ActionRemoved) { 2809 d->actionRects.clear();2810 d->actionList.clear();2811 2879 e->action()->disconnect(this); 2812 2880 if (e->action() == d->currentAction) 2813 2881 d->currentAction = 0; 2814 2882 if (QWidgetAction *wa = qobject_cast<QWidgetAction *>(e->action())) { 2815 QWidget *widget = d->widgetItems.take(wa); 2816 if (widget) 2883 if (QWidget *widget = d->widgetItems.value(wa)) 2817 2884 wa->releaseWidget(widget); 2818 } else { 2819 // If this is called from the QAction destructor, the 2820 // previous call to qobject_cast will fail because the 2821 // QWidgetAction has been destroyed already. We need to 2822 // remove it from the hash anyway or it might crash later 2823 // the widget itself has been already destroyed in 2824 // ~QWidgetAction 2825 d->widgetItems.remove(e->action()); 2826 } 2885 } 2886 d->widgetItems.remove(e->action()); 2827 2887 } 2828 2888 … … 2838 2898 #endif 2839 2899 2840 #if defined(Q_ OS_WINCE) && !defined(QT_NO_MENUBAR)2900 #if defined(Q_WS_WINCE) && !defined(QT_NO_MENUBAR) 2841 2901 if (!d->wce_menu) 2842 2902 d->wce_menu = new QMenuPrivate::QWceMenuPrivate; … … 2849 2909 #endif 2850 2910 2911 #ifdef Q_WS_S60 2912 if (!d->symbian_menu) 2913 d->symbian_menu = new QMenuPrivate::QSymbianMenuPrivate; 2914 if (e->type() == QEvent::ActionAdded) 2915 d->symbian_menu->addAction(e->action(), d->symbian_menu->findAction(e->before())); 2916 else if (e->type() == QEvent::ActionRemoved) 2917 d->symbian_menu->removeAction(e->action()); 2918 else if (e->type() == QEvent::ActionChanged) 2919 d->symbian_menu->syncAction(e->action()); 2920 #endif 2851 2921 if (isVisible()) { 2852 d->updateAction s();2922 d->updateActionRects(); 2853 2923 resize(sizeHint()); 2854 2924 update(); … … 2896 2966 QMenu *caused = qobject_cast<QMenu*>(d->activeMenu->d_func()->causedPopup.widget); 2897 2967 2898 const QRect availGeometry(d->popupGeometry( QApplication::desktop()->screenNumber(caused)));2968 const QRect availGeometry(d->popupGeometry(caused)); 2899 2969 if (isRightToLeft()) { 2900 2970 pos = leftPos; … … 3028 3098 { 3029 3099 Q_D(QMenu); 3100 if (d->collapsibleSeparators == collapse) 3101 return; 3102 3030 3103 d->collapsibleSeparators = collapse; 3031 3104 d->itemsDirty = 1; 3032 3105 if (isVisible()) { 3033 d->updateAction s();3106 d->updateActionRects(); 3034 3107 update(); 3035 3108 } 3109 #ifdef Q_WS_MAC 3110 if (d->mac_menu) 3111 d->syncSeparatorsCollapsible(collapse); 3112 #endif 3036 3113 } 3037 3114 … … 3090 3167 QAction *QMenu::findActionForId(int id) const 3091 3168 { 3092 Q List<QAction *> list = actions();3093 for (int i = 0; i < list.size(); ++i) {3094 QAction *act = list.at(i);3169 Q_D(const QMenu); 3170 for (int i = 0; i < d->actions.size(); ++i) { 3171 QAction *act = d->actions.at(i); 3095 3172 if (findIdForAction(act)== id) 3096 3173 return act; -
trunk/src/gui/widgets/qmenu.h
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 ** … … 142 142 #endif 143 143 144 #ifdef Q_ OS_WINCE144 #ifdef Q_WS_WINCE 145 145 HMENU wceMenu(bool create = false); 146 146 #endif 147 148 147 149 148 bool separatorsCollapsible() const; … … 175 174 void initStyleOption(QStyleOptionMenuItem *option, const QAction *action) const; 176 175 177 #ifdef Q_ OS_WINCE176 #ifdef Q_WS_WINCE 178 177 QAction* wceCommands(uint command); 179 178 #endif -
trunk/src/gui/widgets/qmenu_mac.mm
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 ** … … 72 72 QMenu globals 73 73 *****************************************************************************/ 74 bool qt_mac_no_native_menubar = false;75 74 bool qt_mac_no_menubar_merge = false; 76 75 bool qt_mac_quit_menu_item_enabled = true; … … 144 143 } 145 144 145 static quint32 constructModifierMask(quint32 accel_key) 146 { 147 quint32 ret = 0; 148 const bool dontSwap = qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta); 149 #ifndef QT_MAC_USE_COCOA 150 if ((accel_key & Qt::ALT) == Qt::ALT) 151 ret |= kMenuOptionModifier; 152 if ((accel_key & Qt::SHIFT) == Qt::SHIFT) 153 ret |= kMenuShiftModifier; 154 if (dontSwap) { 155 if ((accel_key & Qt::META) != Qt::META) 156 ret |= kMenuNoCommandModifier; 157 if ((accel_key & Qt::CTRL) == Qt::CTRL) 158 ret |= kMenuControlModifier; 159 } else { 160 if ((accel_key & Qt::CTRL) != Qt::CTRL) 161 ret |= kMenuNoCommandModifier; 162 if ((accel_key & Qt::META) == Qt::META) 163 ret |= kMenuControlModifier; 164 } 165 #else 166 if ((accel_key & Qt::CTRL) == Qt::CTRL) 167 ret |= (dontSwap ? NSControlKeyMask : NSCommandKeyMask); 168 if ((accel_key & Qt::META) == Qt::META) 169 ret |= (dontSwap ? NSCommandKeyMask : NSControlKeyMask); 170 if ((accel_key & Qt::ALT) == Qt::ALT) 171 ret |= NSAlternateKeyMask; 172 if ((accel_key & Qt::SHIFT) == Qt::SHIFT) 173 ret |= NSShiftKeyMask; 174 #endif 175 return ret; 176 } 177 146 178 static bool actualMenuItemVisibility(const QMenuBarPrivate::QMacMenuBarPrivate *mbp, 147 179 const QMacMenuAction *action) … … 167 199 GetMenuItemProperty(menu, 0, kMenuCreatorQt, kMenuPropertyMergeList, 168 200 sizeof(list), 0, &list); 169 if (!list && qt_mac_current_menubar.qmenubar ) {201 if (!list && qt_mac_current_menubar.qmenubar && qt_mac_current_menubar.qmenubar->isNativeMenuBar()) { 170 202 MenuRef apple_menu = qt_mac_current_menubar.qmenubar->d_func()->mac_menubar->apple_menu; 171 203 GetMenuItemProperty(apple_menu, 0, kMenuCreatorQt, kMenuPropertyMergeList, sizeof(list), 0, &list); … … 427 459 int merged = 0; 428 460 const QMenuPrivate::QMacMenuPrivate *mac_menu = qmenu->d_func()->mac_menu; 429 for(int i = 0; i < mac_menu->actionItems.size(); ++i) { 461 const int ActionItemsCount = mac_menu->actionItems.size(); 462 for(int i = 0; i < ActionItemsCount; ++i) { 430 463 QMacMenuAction *action = mac_menu->actionItems.at(i); 431 464 if (action->action->isSeparator()) { … … 527 560 static void qt_mac_get_accel(quint32 accel_key, quint32 *modif, quint32 *key) { 528 561 if (modif) { 529 *modif = 0; 530 if ((accel_key & Qt::CTRL) != Qt::CTRL) 531 *modif |= kMenuNoCommandModifier; 532 if ((accel_key & Qt::META) == Qt::META) 533 *modif |= kMenuControlModifier; 534 if ((accel_key & Qt::ALT) == Qt::ALT) 535 *modif |= kMenuOptionModifier; 536 if ((accel_key & Qt::SHIFT) == Qt::SHIFT) 537 *modif |= kMenuShiftModifier; 562 *modif = constructModifierMask(accel_key); 538 563 } 539 564 … … 583 608 } 584 609 610 static inline void syncNSMenuItemEnabled(NSMenuItem *menuItem, bool enabled) 611 { 612 [menuItem setEnabled:NO]; 613 [menuItem setEnabled:YES]; 614 [menuItem setEnabled:enabled]; 615 } 616 585 617 static inline void syncMenuBarItemsVisiblity(const QMenuBarPrivate::QMacMenuBarPrivate *mac_menubar) 586 618 { … … 600 632 { 601 633 NSMenuItem *item = [[NSMenuItem alloc] 602 initWithTitle: reinterpret_cast<const NSString *>(static_cast<CFStringRef>(QCFString(title)))634 initWithTitle:qt_mac_QStringToNSString(title) 603 635 action:@selector(qtDispatcherToQAction:) keyEquivalent:@""]; 604 636 [item setTarget:getMenuLoader()]; … … 635 667 if ([item tag]) { 636 668 QAction *action = reinterpret_cast<QAction *>([item tag]); 637 [item setEnabled:action->isEnabled()];669 syncNSMenuItemEnabled(item, action->isEnabled()); 638 670 } else { 639 [item setEnabled:YES];671 syncNSMenuItemEnabled(item, YES); 640 672 } 641 673 } else { 642 [item setEnabled:NO];674 syncNSMenuItemEnabled(item, NO); 643 675 } 644 676 } … … 704 736 void qt_mac_clear_menubar() 705 737 { 738 if (QApplication::testAttribute(Qt::AA_MacPluginApplication)) 739 return; 740 706 741 #ifndef QT_MAC_USE_COCOA 707 742 MenuRef clear_menu = 0; … … 729 764 #ifdef QT_MAC_USE_COCOA 730 765 [menu release]; 731 [menuItem setTag:nil]; 766 // Update the menu item if this action still owns it. For some items 767 // (like 'Quit') ownership will be transferred between all menu bars... 768 if (action && action.data() == reinterpret_cast<QAction *>([menuItem tag])) { 769 QAction::MenuRole role = action->menuRole(); 770 // Check if the item is owned by Qt, and should be hidden to keep it from causing 771 // problems. Do it for everything but the quit menu item since that should always 772 // be visible. 773 if (role > QAction::ApplicationSpecificRole && role < QAction::QuitRole) { 774 [menuItem setHidden:YES]; 775 } else if (role == QAction::TextHeuristicRole 776 && menuItem != [getMenuLoader() quitMenuItem]) { 777 [menuItem setHidden:YES]; 778 } 779 [menuItem setTag:nil]; 780 } 732 781 [menuItem release]; 733 782 #endif … … 872 921 } 873 922 874 if ([ret tag] != 0)875 ret = 0; // already taken876 923 #endif 877 924 return ret; … … 918 965 #ifndef QT_MAC_USE_COCOA 919 966 else if (action->command == kHICommandPreferences) 920 ret = QKeySequence(Q t::CTRL+Qt::Key_Comma);967 ret = QKeySequence(QKeySequence::Preferences); 921 968 else if (action->command == kHICommandQuit) 922 ret = QKeySequence(Q t::CTRL+Qt::Key_Q);969 ret = QKeySequence(QKeySequence::Quit); 923 970 #else 924 971 else if (action->menuItem == [loader preferencesMenuItem]) 925 ret = QKeySequence(Q t::CTRL+Qt::Key_Comma);972 ret = QKeySequence(QKeySequence::Preferences); 926 973 else if (action->menuItem == [loader quitMenuItem]) 927 ret = QKeySequence(Q t::CTRL+Qt::Key_Q);974 ret = QKeySequence(QKeySequence::Quit); 928 975 #endif 929 976 return ret; … … 932 979 void Q_GUI_EXPORT qt_mac_set_menubar_icons(bool b) 933 980 { QApplication::instance()->setAttribute(Qt::AA_DontShowIconsInMenus, !b); } 934 void Q_GUI_EXPORT qt_mac_set_native_menubar(bool b) { qt_mac_no_native_menubar = !b; } 981 void Q_GUI_EXPORT qt_mac_set_native_menubar(bool b) 982 { QApplication::instance()->setAttribute(Qt::AA_DontUseNativeMenuBar, !b); } 935 983 void Q_GUI_EXPORT qt_mac_set_menubar_merge(bool b) { qt_mac_no_menubar_merge = !b; } 936 984 … … 1132 1180 if (mergedItems.contains(action->command) 1133 1181 && (testattr & kMenuItemAttrSeparator)) { 1134 1135 1136 1137 1138 1139 1140 1141 1142 1182 InsertMenuItemTextWithCFString(action->menu, 0, qMax(itemCount - 1, 0), attr, action->command); 1183 index = itemCount; 1184 } else { 1185 MenuItemIndex tmpIndex; 1186 AppendMenuItemTextWithCFString(action->menu, 0, attr, action->command, &tmpIndex); 1187 index = tmpIndex; 1188 if (mergedItems.contains(action->command)) 1189 AppendMenuItemTextWithCFString(action->menu, 0, kMenuItemAttrSeparator, 0, &tmpIndex); 1190 } 1143 1191 #else 1144 1192 [menu addItem:newItem]; … … 1209 1257 { 1210 1258 quint32 accel_key = (accel[0] & ~(Qt::MODIFIER_MASK | Qt::UNICODE_ACCEL)); 1211 unichar keyEquiv[1] = { 0 }; 1212 if (accel_key == Qt::Key_Return) 1213 keyEquiv[0] = kReturnCharCode; 1214 else if (accel_key == Qt::Key_Enter) 1215 keyEquiv[0] = kEnterCharCode; 1216 else if (accel_key == Qt::Key_Tab) 1217 keyEquiv[0] = kTabCharCode; 1218 else if (accel_key == Qt::Key_Backspace) 1219 keyEquiv[0] = kBackspaceCharCode; 1220 else if (accel_key == Qt::Key_Delete) 1221 keyEquiv[0] = NSDeleteFunctionKey; 1222 else if (accel_key == Qt::Key_Escape) 1223 keyEquiv[0] = kEscapeCharCode; 1224 else if (accel_key == Qt::Key_PageUp) 1225 keyEquiv[0] = NSPageUpFunctionKey; 1226 else if (accel_key == Qt::Key_PageDown) 1227 keyEquiv[0] = NSPageDownFunctionKey; 1228 else if (accel_key == Qt::Key_Up) 1229 keyEquiv[0] = NSUpArrowFunctionKey; 1230 else if (accel_key == Qt::Key_Down) 1231 keyEquiv[0] = NSDownArrowFunctionKey; 1232 else if (accel_key == Qt::Key_Left) 1233 keyEquiv[0] = NSLeftArrowFunctionKey; 1234 else if (accel_key == Qt::Key_Right) 1235 keyEquiv[0] = NSRightArrowFunctionKey; 1236 else if (accel_key == Qt::Key_CapsLock) 1237 keyEquiv[0] = kMenuCapsLockGlyph; // ### Cocoa has no equivalent 1238 else if (accel_key >= Qt::Key_F1 && accel_key <= Qt::Key_F15) 1239 keyEquiv[0] = (accel_key - Qt::Key_F1) + NSF1FunctionKey; 1240 else if (accel_key == Qt::Key_Home) 1241 keyEquiv[0] = NSHomeFunctionKey; 1242 else if (accel_key == Qt::Key_End) 1243 keyEquiv[0] = NSEndFunctionKey; 1244 else 1245 keyEquiv[0] = unichar(QChar(accel_key).toLower().unicode()); 1246 return [NSString stringWithCharacters:keyEquiv length:1]; 1259 extern QChar qt_macSymbolForQtKey(int key); // qkeysequence.cpp 1260 QChar keyEquiv = qt_macSymbolForQtKey(accel_key); 1261 if (keyEquiv.isNull()) { 1262 if (accel_key >= Qt::Key_F1 && accel_key <= Qt::Key_F15) 1263 keyEquiv = (accel_key - Qt::Key_F1) + NSF1FunctionKey; 1264 else 1265 keyEquiv = unichar(QChar(accel_key).toLower().unicode()); 1266 } 1267 return [NSString stringWithCharacters:&keyEquiv.unicode() length:1]; 1247 1268 } 1248 1269 … … 1250 1271 NSUInteger keySequenceModifierMask(const QKeySequence &accel) 1251 1272 { 1252 NSUInteger ret = 0; 1253 quint32 accel_key = accel[0]; 1254 if ((accel_key & Qt::CTRL) == Qt::CTRL) 1255 ret |= NSCommandKeyMask; 1256 if ((accel_key & Qt::META) == Qt::META) 1257 ret |= NSControlKeyMask; 1258 if ((accel_key & Qt::ALT) == Qt::ALT) 1259 ret |= NSAlternateKeyMask; 1260 if ((accel_key & Qt::SHIFT) == Qt::SHIFT) 1261 ret |= NSShiftKeyMask; 1262 return ret; 1273 return constructModifierMask(accel[0]); 1263 1274 } 1264 1275 … … 1340 1351 } 1341 1352 } 1353 // Show multiple key sequences as part of the menu text. 1342 1354 if (accel.count() > 1) 1343 text += QLatin1String(" ( ****)"); //just to denote a multi stroke shortcut1355 text += QLatin1String(" (") + accel.toString(QKeySequence::NativeText) + QLatin1String(")"); 1344 1356 1345 1357 QString finalString = qt_mac_removeMnemonics(text); … … 1362 1374 && action->action->isIconVisibleInMenu()) { 1363 1375 data.iconType = kMenuIconRefType; 1364 data.iconHandle = (Handle)qt_mac_create_iconref(action->action->icon().pixmap( 22, QIcon::Normal));1376 data.iconHandle = (Handle)qt_mac_create_iconref(action->action->icon().pixmap(16, QIcon::Normal)); 1365 1377 } else { 1366 1378 data.iconType = kMenuNoIcon; … … 1382 1394 if (action->action->font().resolve()) { 1383 1395 const QFont &actionFont = action->action->font(); 1384 NSFont *customMenuFont = [NSFont fontWithName: reinterpret_cast<const NSString *>(static_cast<CFStringRef>(QCFString(actionFont.family())))1396 NSFont *customMenuFont = [NSFont fontWithName:qt_mac_QStringToNSString(actionFont.family()) 1385 1397 size:actionFont.pointSize()]; 1386 1398 NSArray *keys = [NSArray arrayWithObjects:NSFontAttributeName, nil]; 1387 1399 NSArray *objects = [NSArray arrayWithObjects:customMenuFont, nil]; 1388 1400 NSDictionary *attributes = [NSDictionary dictionaryWithObjects:objects forKeys:keys]; 1389 NSAttributedString *str = [[[NSAttributedString alloc] initWithString: reinterpret_cast<const NSString *>(static_cast<CFStringRef>(QCFString(finalString)))1401 NSAttributedString *str = [[[NSAttributedString alloc] initWithString:qt_mac_QStringToNSString(finalString) 1390 1402 attributes:attributes] autorelease]; 1391 1403 [item setAttributedTitle: str]; 1392 1404 } else { 1393 [item setTitle: reinterpret_cast<const NSString *>(static_cast<CFStringRef>(QCFString(finalString)))];1394 } 1395 [item setTitle: reinterpret_cast<const NSString *>(static_cast<CFStringRef>(QCFString(qt_mac_removeMnemonics(text))))];1405 [item setTitle: qt_mac_QStringToNSString(finalString)]; 1406 } 1407 [item setTitle:qt_mac_QStringToNSString(qt_mac_removeMnemonics(text))]; 1396 1408 1397 1409 // Cocoa Enabled … … 1401 1413 NSImage *nsimage = 0; 1402 1414 if (!action->action->icon().isNull() && action->action->isIconVisibleInMenu()) { 1403 nsimage = static_cast<NSImage *>(qt_mac_create_nsimage(action->action->icon().pixmap( 22, QIcon::Normal)));1415 nsimage = static_cast<NSImage *>(qt_mac_create_nsimage(action->action->icon().pixmap(16, QIcon::Normal))); 1404 1416 } 1405 1417 [item setImage:nsimage]; … … 1415 1427 SetMenuItemProperty(data.submenuHandle, 0, kMenuCreatorQt, kMenuPropertyCausedQWidget, sizeof(caused), &caused); 1416 1428 #else 1417 [item setSubmenu:static_cast<NSMenu *>(action->action->menu()->macMenu())]; 1429 NSMenu *subMenu = static_cast<NSMenu *>(action->action->menu()->macMenu()); 1430 if ([subMenu supermenu] && [subMenu supermenu] != [item menu]) { 1431 // The menu is already a sub-menu of another one. Cocoa will throw an exception, 1432 // in such cases. For the time being, a new QMenu with same set of actions is the 1433 // only workaround. 1434 action->action->setEnabled(false); 1435 } else { 1436 [item setSubmenu:subMenu]; 1437 } 1418 1438 #endif 1419 1439 } else { //respect some other items … … 1423 1443 data.whichData |= kMenuItemDataCmdKeyModifiers; 1424 1444 data.whichData |= kMenuItemDataCmdKeyGlyph; 1425 if ( !accel.isEmpty()) {1445 if (accel.count() == 1) { 1426 1446 qt_mac_get_accel(accel[0], (quint32*)&data.cmdKeyModifiers, (quint32*)&data.cmdKeyGlyph); 1427 1447 if (data.cmdKeyGlyph == 0) … … 1430 1450 #else 1431 1451 [item setSubmenu:0]; 1432 if (!accel.isEmpty()) { 1452 // No key equivalent set for multiple key QKeySequence. 1453 if (accel.count() == 1) { 1433 1454 [item setKeyEquivalent:keySequenceToKeyEqivalent(accel)]; 1434 1455 [item setKeyEquivalentModifierMask:keySequenceModifierMask(accel)]; … … 1478 1499 #else 1479 1500 QMacCocoaAutoReleasePool pool; 1480 QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader(); 1481 if (action->menuItem == [loader quitMenuItem] || action->menuItem == [loader preferencesMenuItem]) 1482 [action->menuItem setEnabled:false]; 1483 else 1501 if (action->merged) { 1502 if (reinterpret_cast<QAction *>([action->menuItem tag]) == action->action) { 1503 QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader(); 1504 [action->menuItem setEnabled:false]; 1505 if (action->menuItem != [loader quitMenuItem] 1506 && action->menuItem != [loader preferencesMenuItem]) { 1507 [[action->menuItem menu] removeItem:action->menuItem]; 1508 } 1509 } 1510 } else { 1484 1511 [[action->menuItem menu] removeItem:action->menuItem]; 1512 } 1485 1513 #endif 1486 1514 actionItems.removeAll(action); … … 1507 1535 for(int i = 0; i < items.count(); i++) 1508 1536 mac_menu->addAction(items[i], 0, this); 1537 syncSeparatorsCollapsible(collapsibleSeparators); 1509 1538 return mac_menu->menu; 1510 1539 } 1540 1541 /*! 1542 \internal 1543 */ 1544 void 1545 QMenuPrivate::syncSeparatorsCollapsible(bool collapse) 1546 { 1547 #ifndef QT_MAC_USE_COCOA 1548 if (collapse) 1549 ChangeMenuAttributes(mac_menu->menu, kMenuAttrCondenseSeparators, 0); 1550 else 1551 ChangeMenuAttributes(mac_menu->menu, 0, kMenuAttrCondenseSeparators); 1552 #else 1553 qt_mac_menu_collapseSeparators(mac_menu->menu, collapse); 1554 #endif 1555 } 1556 1557 1511 1558 1512 1559 /*! … … 1674 1721 SetMenuItemProperty(submenu, 0, kMenuCreatorQt, kMenuPropertyCausedQWidget, sizeof(caused), &caused); 1675 1722 #else 1676 [item setSubmenu:submenu]; 1723 if ([submenu supermenu] && [submenu supermenu] != [item menu]) 1724 return; 1725 else 1726 [item setSubmenu:submenu]; 1677 1727 #endif 1678 1728 } … … 1695 1745 #else 1696 1746 [item setSubmenu: submenu]; 1697 [submenu setTitle: reinterpret_cast<const NSString *>(static_cast<CFStringRef>(QCFString(qt_mac_removeMnemonics(action->action->text()))))];1747 [submenu setTitle:qt_mac_QStringToNSString(qt_mac_removeMnemonics(action->action->text()))]; 1698 1748 syncNSMenuItemVisiblity(item, visible); 1699 1749 #endif … … 1724 1774 } 1725 1775 1776 bool QMenuBarPrivate::macWidgetHasNativeMenubar(QWidget *widget) 1777 { 1778 // This function is different from q->isNativeMenuBar(), as 1779 // it returns true only if a native menu bar is actually 1780 // _created_. 1781 if (!widget) 1782 return false; 1783 return menubars()->contains(widget->window()); 1784 } 1785 1726 1786 void 1727 1787 QMenuBarPrivate::macCreateMenuBar(QWidget *parent) 1728 1788 { 1729 1789 Q_Q(QMenuBar); 1730 static int checkEnv = -1; 1731 if (qt_mac_no_native_menubar == false && checkEnv < 0) { 1732 checkEnv = !qgetenv("QT_MAC_NO_NATIVE_MENUBAR").isEmpty(); 1733 qt_mac_no_native_menubar = checkEnv; 1734 } 1735 if (!qt_mac_no_native_menubar) { 1790 static int dontUseNativeMenuBar = -1; 1791 // We call the isNativeMenuBar function here 1792 // because that will make sure that local overrides 1793 // are dealt with correctly. q->isNativeMenuBar() will, if not 1794 // overridden, depend on the attribute Qt::AA_DontUseNativeMenuBar: 1795 bool qt_mac_no_native_menubar = !q->isNativeMenuBar(); 1796 if (qt_mac_no_native_menubar == false && dontUseNativeMenuBar < 0) { 1797 // The menubar is set to be native. Let's check (one time only 1798 // for all menubars) if this is OK with the rest of the environment. 1799 // As a result, Qt::AA_DontUseNativeMenuBar is set. NB: the application 1800 // might still choose to not respect, or change, this flag. 1801 bool isPlugin = QApplication::testAttribute(Qt::AA_MacPluginApplication); 1802 bool environmentSaysNo = !qgetenv("QT_MAC_NO_NATIVE_MENUBAR").isEmpty(); 1803 dontUseNativeMenuBar = isPlugin || environmentSaysNo; 1804 QApplication::instance()->setAttribute(Qt::AA_DontUseNativeMenuBar, dontUseNativeMenuBar); 1805 qt_mac_no_native_menubar = !q->isNativeMenuBar(); 1806 } 1807 if (qt_mac_no_native_menubar == false) { 1808 // INVARIANT: Use native menubar. 1736 1809 extern void qt_event_request_menubarupdate(); //qapplication_mac.cpp 1737 1810 qt_event_request_menubarupdate(); … … 1766 1839 { 1767 1840 Q_Q(QMenuBar); 1768 if (! mac_menubar) {1841 if (!q->isNativeMenuBar() || !mac_menubar) { 1769 1842 return 0; 1770 1843 } else if (!mac_menubar->menu) { … … 1782 1855 SetMenuItemProperty(mac_menubar->apple_menu, 0, kMenuCreatorQt, kMenuPropertyQWidget, sizeof(q), &q); 1783 1856 #else 1784 [mac_menubar->apple_menu setTitle: reinterpret_cast<const NSString *>(static_cast<CFStringRef>(QCFString(QString(QChar(0x14)))))];1857 [mac_menubar->apple_menu setTitle:qt_mac_QStringToNSString(QString(QChar(0x14)))]; 1785 1858 NSMenuItem *apple_menuItem = [[NSMenuItem alloc] init]; 1786 1859 [apple_menuItem setSubmenu:mac_menubar->menu]; … … 1825 1898 static bool qt_mac_is_ancestor(QWidget* possibleAncestor, QWidget *child) 1826 1899 { 1900 if (!possibleAncestor) 1901 return false; 1902 1827 1903 QWidget * current = child->parentWidget(); 1828 1904 while (current != 0) { … … 1843 1919 if (modalWidget == 0 || menuBar == 0) 1844 1920 return false; 1845 const Qt::WindowModality modality = modalWidget->windowModality(); 1846 if (modality == Qt::ApplicationModal) { 1847 return true; 1848 } else if (modality == Qt::WindowModal) { 1849 QWidget * parent = menuBar->parentWidget(); 1850 1851 // Special case for the global menu bar: It's not associated 1852 // with a window so don't disable it. 1853 if (parent == 0) 1854 return false; 1855 1856 // Disable menu entries in menu bars that belong to ancestors of 1857 // the modal widget, leave entries in unrelated menu bars enabled. 1858 return qt_mac_is_ancestor(parent, modalWidget); 1859 } 1860 return false; // modality == NonModal 1921 1922 // If there is an application modal window on 1923 // screen, the entries of the menubar should be disabled: 1924 QWidget *w = modalWidget; 1925 while (w) { 1926 if (w->isVisible() && w->windowModality() == Qt::ApplicationModal) 1927 return true; 1928 w = w->parentWidget(); 1929 } 1930 1931 // INVARIANT: modalWidget is window modal. Disable menu entries 1932 // if the menu bar belongs to an ancestor of modalWidget: 1933 return qt_mac_is_ancestor(menuBar->parentWidget(), modalWidget); 1861 1934 } 1862 1935 … … 1887 1960 bool QMenuBar::macUpdateMenuBar() 1888 1961 { 1889 if (qt_mac_no_native_menubar) //nothing to be done..1890 return true;1891 1892 1962 cancelAllMenuTracking(); 1893 1963 QMenuBar *mb = 0; … … 1923 1993 //now set it 1924 1994 bool ret = false; 1925 if (mb ) {1995 if (mb && mb->isNativeMenuBar()) { 1926 1996 #ifdef QT_MAC_USE_COCOA 1927 1997 QMacCocoaAutoReleasePool pool; … … 1935 2005 [NSApp setMainMenu:menu]; 1936 2006 syncMenuBarItemsVisiblity(mb->d_func()->mac_menubar); 2007 2008 if (OSMenuRef tmpMerge = QMenuPrivate::mergeMenuHash.value(menu)) { 2009 if (QMenuMergeList *mergeList 2010 = QMenuPrivate::mergeMenuItemsHash.value(tmpMerge)) { 2011 const int mergeListSize = mergeList->size(); 2012 2013 for (int i = 0; i < mergeListSize; ++i) { 2014 const QMenuMergeItem &mergeItem = mergeList->at(i); 2015 // Ideally we would call QMenuPrivate::syncAction, but that requires finding 2016 // the original QMen and likely doing more work than we need. 2017 // For example, enabled is handled below. 2018 [mergeItem.menuItem setTag:reinterpret_cast<long>( 2019 static_cast<QAction *>(mergeItem.action->action))]; 2020 [mergeItem.menuItem setHidden:!(mergeItem.action->action->isVisible())]; 2021 } 2022 } 2023 } 1937 2024 #endif 1938 2025 QWidget *modalWidget = qApp->activeModalWidget(); … … 1944 2031 qt_mac_current_menubar.modal = QApplicationPrivate::modalState(); 1945 2032 ret = true; 1946 } else if (qt_mac_current_menubar.qmenubar ) {2033 } else if (qt_mac_current_menubar.qmenubar && qt_mac_current_menubar.qmenubar->isNativeMenuBar()) { 1947 2034 const bool modal = QApplicationPrivate::modalState(); 1948 2035 if (modal != qt_mac_current_menubar.modal) { -
trunk/src/gui/widgets/qmenu_p.h
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 ** … … 62 62 #include "private/qwidget_p.h" 63 63 64 #ifdef Q_WS_S60 65 class CEikMenuPane; 66 #define QT_SYMBIAN_FIRST_MENU_ITEM 32000 67 #define QT_SYMBIAN_LAST_MENU_ITEM 41999 // 10000 items ought to be enough for anybody... 68 #endif 64 69 QT_BEGIN_NAMESPACE 65 70 66 71 #ifndef QT_NO_MENU 72 73 #ifdef Q_WS_S60 74 void qt_symbian_show_toplevel(CEikMenuPane* menuPane); 75 void qt_symbian_show_submenu(CEikMenuPane* menuPane, int id); 76 #endif // Q_WS_S60 67 77 68 78 class QTornOffMenu; … … 113 123 #endif 114 124 115 #ifdef Q_ OS_WINCE125 #ifdef Q_WS_WINCE 116 126 struct QWceMenuAction { 117 127 uint command; … … 121 131 }; 122 132 #endif 133 #ifdef Q_WS_S60 134 struct QSymbianMenuAction { 135 uint command; 136 int parent; 137 CEikMenuPane* menuPane; 138 QPointer<QAction> action; 139 QSymbianMenuAction() : command(0) {} 140 }; 141 #endif 123 142 124 143 class QMenuPrivate : public QWidgetPrivate … … 127 146 public: 128 147 QMenuPrivate() : itemsDirty(0), maxIconWidth(0), tabWidth(0), ncols(0), 129 collapsibleSeparators(true), hasHadMouse(0), aboutToHide(0), motions(0), 130 currentAction(0), scroll(0), eventLoop(0), tearoff(0), tornoff(0), tearoffHighlighted(0), 131 hasCheckableItems(0), sloppyAction(0) 148 collapsibleSeparators(true), activationRecursionGuard(false), hasHadMouse(0), aboutToHide(0), motions(0), 149 currentAction(0), 150 #ifdef QT_KEYPAD_NAVIGATION 151 selectAction(0), 152 cancelAction(0), 153 #endif 154 scroll(0), eventLoop(0), tearoff(0), tornoff(0), tearoffHighlighted(0), 155 hasCheckableItems(0), sloppyAction(0), doChildEffects(false) 132 156 #ifdef Q_WS_MAC 133 157 ,mac_menu(0) 134 158 #endif 135 #if defined(Q_ OS_WINCE) && !defined(QT_NO_MENUBAR)159 #if defined(Q_WS_WINCE) && !defined(QT_NO_MENUBAR) 136 160 ,wce_menu(0) 161 #endif 162 #ifdef Q_WS_S60 163 ,symbian_menu(0) 137 164 #endif 138 165 #ifdef QT3_SUPPORT … … 146 173 delete mac_menu; 147 174 #endif 148 #if defined(Q_ OS_WINCE) && !defined(QT_NO_MENUBAR)175 #if defined(Q_WS_WINCE) && !defined(QT_NO_MENUBAR) 149 176 delete wce_menu; 150 177 #endif 178 #ifdef Q_WS_S60 179 delete symbian_menu; 180 #endif 181 151 182 } 152 183 void init(); 184 185 static QMenuPrivate *get(QMenu *m) { return m->d_func(); } 186 int scrollerHeight() const; 153 187 154 188 //item calculations … … 156 190 mutable uint maxIconWidth, tabWidth; 157 191 QRect actionRect(QAction *) const; 158 mutable QMap<QAction*, QRect> actionRects; 159 mutable Q List<QAction*> actionList;192 193 mutable QVector<QRect> actionRects; 160 194 mutable QHash<QAction *, QWidget *> widgetItems; 161 void calcActionRects(QMap<QAction*, QRect> &actionRects, QList<QAction*> &actionList) const; 162 void updateActions(); 163 QRect popupGeometry(int screen=-1) const; 164 QList<QAction *> filterActions(const QList<QAction *> &actions) const; 165 uint ncols : 4; //4 bits is probably plenty 195 void updateActionRects() const; 196 QRect popupGeometry(const QWidget *widget) const; 197 QRect popupGeometry(int screen = -1) const; 198 mutable uint ncols : 4; //4 bits is probably plenty 166 199 uint collapsibleSeparators : 1; 167 200 168 uint activationRecursionGuard : 1;201 bool activationRecursionGuard; 169 202 170 203 //selection … … 175 208 int motions; 176 209 QAction *currentAction; 210 #ifdef QT_KEYPAD_NAVIGATION 211 QAction *selectAction; 212 QAction *cancelAction; 213 #endif 177 214 static QBasicTimer menuDelayTimer; 178 215 enum SelectionReason { … … 180 217 SelectedFromElsewhere 181 218 }; 219 QWidget *topCausedWidget() const; 182 220 QAction *actionAt(QPoint p) const; 183 221 void setFirstActionActive(); … … 192 230 uint scrollFlags : 2, scrollDirection : 2; 193 231 int scrollOffset; 194 QBasicTimer *scrollTimer;195 196 QMenuScroller() : scrollFlags(ScrollNone), scrollDirection(ScrollNone), scrollOffset(0) , scrollTimer(0){ }197 ~QMenuScroller() { delete scrollTimer;}232 QBasicTimer scrollTimer; 233 234 QMenuScroller() : scrollFlags(ScrollNone), scrollDirection(ScrollNone), scrollOffset(0) { } 235 ~QMenuScroller() { } 198 236 } *scroll; 199 237 void scrollMenu(QMenuScroller::ScrollLocation location, bool active=false); … … 209 247 QBasicTimer searchBufferTimer; 210 248 211 //passing of mouse events up the parent h eirarchy249 //passing of mouse events up the parent hierarchy 212 250 QPointer<QMenu> activeMenu; 213 251 bool mouseEventTaken(QMouseEvent *); … … 221 259 QMenuCaused causedPopup; 222 260 void hideUpToMenuBar(); 223 void hideMenu(QMenu *menu );261 void hideMenu(QMenu *menu, bool justRegister = false); 224 262 225 263 //index mappings … … 235 273 //sloppy selection 236 274 static QBasicTimer sloppyDelayTimer; 237 QAction *sloppyAction;275 mutable QAction *sloppyAction; 238 276 QRegion sloppyRegion; 239 277 … … 255 293 256 294 bool hasMouseMoved(const QPoint &globalPos); 295 296 void updateLayoutDirection(); 297 257 298 258 299 //menu fading/scrolling effects … … 285 326 OSMenuRef macMenu(OSMenuRef merge); 286 327 void setMacMenuEnabled(bool enable = true); 328 void syncSeparatorsCollapsible(bool collapsible); 287 329 static QHash<OSMenuRef, OSMenuRef> mergeMenuHash; 288 330 static QHash<OSMenuRef, QMenuMergeList*> mergeMenuItemsHash; … … 294 336 #endif 295 337 296 #if defined(Q_ OS_WINCE) && !defined(QT_NO_MENUBAR)338 #if defined(Q_WS_WINCE) && !defined(QT_NO_MENUBAR) 297 339 struct QWceMenuPrivate { 298 340 QList<QWceMenuAction*> actionItems; … … 319 361 QAction* wceCommands(uint command); 320 362 #endif 321 363 #if defined(Q_WS_S60) 364 struct QSymbianMenuPrivate { 365 QList<QSymbianMenuAction*> actionItems; 366 QSymbianMenuPrivate(); 367 ~QSymbianMenuPrivate(); 368 void addAction(QAction *, QSymbianMenuAction* =0); 369 void addAction(QSymbianMenuAction *, QSymbianMenuAction* =0); 370 void syncAction(QSymbianMenuAction *); 371 inline void syncAction(QAction *a) { syncAction(findAction(a)); } 372 void removeAction(QSymbianMenuAction *); 373 void rebuild(bool reCreate = false); 374 inline void removeAction(QAction *a) { removeAction(findAction(a)); } 375 inline QSymbianMenuAction *findAction(QAction *a) { 376 for(int i = 0; i < actionItems.size(); i++) { 377 QSymbianMenuAction *act = actionItems[i]; 378 if(a == act->action) 379 return act; 380 } 381 return 0; 382 } 383 } *symbian_menu; 384 #endif 322 385 QPointer<QWidget> noReplayFor; 323 386 }; -
trunk/src/gui/widgets/qmenubar.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 ** … … 68 68 #include "qdebug.h" 69 69 70 #ifdef Q_ OS_WINCE70 #ifdef Q_WS_WINCE 71 71 extern bool qt_wince_is_mobile(); //defined in qguifunctions_wce.cpp 72 72 #endif … … 117 117 QAction *QMenuBarPrivate::actionAt(QPoint p) const 118 118 { 119 Q_Q(const QMenuBar); 120 QList<QAction*> items = q->actions(); 121 for(int i = 0; i < items.size(); ++i) { 122 if(actionRect(items.at(i)).contains(p)) 123 return items.at(i); 119 for(int i = 0; i < actions.size(); ++i) { 120 if(actionRect(actions.at(i)).contains(p)) 121 return actions.at(i); 124 122 } 125 123 return 0; … … 135 133 136 134 if (extVisible) { 137 if (q-> layoutDirection() == Qt::RightToLeft)135 if (q->isRightToLeft()) 138 136 result.setLeft(result.left() + extension->sizeHint().width()); 139 137 else … … 143 141 if (leftWidget && leftWidget->isVisible()) { 144 142 QSize sz = leftWidget->sizeHint(); 145 if (q-> layoutDirection() == Qt::RightToLeft)143 if (q->isRightToLeft()) 146 144 result.setRight(result.right() - sz.width()); 147 145 else … … 151 149 if (rightWidget && rightWidget->isVisible()) { 152 150 QSize sz = rightWidget->sizeHint(); 153 if (q-> layoutDirection() == Qt::RightToLeft)151 if (q->isRightToLeft()) 154 152 result.setLeft(result.left() + sz.width()); 155 153 else … … 195 193 196 194 #ifdef Q_WS_MAC 197 if( mac_menubar) {//nothing to see here folks, move along..195 if(q->isNativeMenuBar()) {//nothing to see here folks, move along.. 198 196 itemsDirty = false; 199 197 return; 200 198 } 201 199 #endif 202 calcActionRects(q_width, q_start, actionRects, actionList); 203 itemsWidth = q_width; 204 itemsStart = q_start; 200 calcActionRects(q_width, q_start); 205 201 currentAction = 0; 206 202 #ifndef QT_NO_SHORTCUT … … 209 205 q->releaseShortcut(shortcutIndexMap.value(j)); 210 206 shortcutIndexMap.resize(0); // faster than clear 211 for(int i = 0; i < action List.count(); i++)212 shortcutIndexMap.append(q->grabShortcut(QKeySequence::mnemonic(action List.at(i)->text())));207 for(int i = 0; i < actions.count(); i++) 208 shortcutIndexMap.append(q->grabShortcut(QKeySequence::mnemonic(actions.at(i)->text()))); 213 209 } 214 210 #endif … … 221 217 //we try to see if the actions will fit there 222 218 bool hasHiddenActions = false; 223 foreach(QAction *action, actionList) { 224 if (!menuRect.contains(actionRect(action))) { 219 for (int i = 0; i < actions.count(); ++i) { 220 const QRect &rect = actionRects.at(i); 221 if (rect.isValid() && !menuRect.contains(rect)) { 225 222 hasHiddenActions = true; 226 223 break; … … 231 228 if (hasHiddenActions) { 232 229 menuRect = this->menuRect(true); 233 foreach(QAction *action, actionList) { 234 if (!menuRect.contains(actionRect(action))) { 235 hiddenActions.append(action); 230 for (int i = 0; i < actions.count(); ++i) { 231 const QRect &rect = actionRects.at(i); 232 if (rect.isValid() && !menuRect.contains(rect)) { 233 hiddenActions.append(actions.at(i)); 236 234 } 237 235 } … … 248 246 249 247 int vmargin = q->style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, q); 250 int x = q-> layoutDirection() == Qt::RightToLeft248 int x = q->isRightToLeft() 251 249 ? menuRect.left() - extension->sizeHint().width() + 1 252 250 : menuRect.right(); … … 258 256 q->updateGeometry(); 259 257 #ifdef QT3_SUPPORT 260 if ( q->parentWidget() != 0) {258 if (parent) { 261 259 QMenubarUpdatedEvent menubarUpdated(q); 262 QApplication::sendEvent( q->parentWidget(), &menubarUpdated);260 QApplication::sendEvent(parent, &menubarUpdated); 263 261 } 264 262 #endif … … 268 266 { 269 267 Q_Q(const QMenuBar); 270 QRect ret = actionRects.value(act); 271 const int fw = q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q); 272 ret.translate(fw, fw); 268 const int index = actions.indexOf(act); 269 if (index == -1) 270 return QRect(); 271 272 //makes sure the geometries are up-to-date 273 const_cast<QMenuBarPrivate*>(this)->updateGeometries(); 274 275 if (index >= actionRects.count()) 276 return QRect(); // that can happen in case of native menubar 277 278 QRect ret = actionRects.at(index); 273 279 return QStyle::visualRect(q->layoutDirection(), q->rect(), ret); 280 } 281 282 void QMenuBarPrivate::focusFirstAction() 283 { 284 if(!currentAction) { 285 updateGeometries(); 286 int index = 0; 287 while (index < actions.count() && actionRects.at(index).isNull()) ++index; 288 if (index < actions.count()) 289 setCurrentAction(actions.at(index)); 290 } 274 291 } 275 292 … … 283 300 keyboardState = b; 284 301 if(b) { 285 QWidget *fw = qApp->focusWidget();302 QWidget *fw = QApplication::focusWidget(); 286 303 if (fw != q) 287 304 keyboardFocusWidget = fw; 288 if(!currentAction && !actionList.isEmpty()) 289 setCurrentAction(actionList.first()); 305 focusFirstAction(); 290 306 q->setFocus(Qt::MenuBarFocusReason); 291 307 } else { … … 293 309 setCurrentAction(0); 294 310 if(keyboardFocusWidget) { 295 if ( qApp->focusWidget() == q)311 if (QApplication::focusWidget() == q) 296 312 keyboardFocusWidget->setFocus(Qt::MenuBarFocusReason); 297 313 keyboardFocusWidget = 0; … … 317 333 QSize popup_size = activeMenu->sizeHint(); 318 334 319 QRect screenRect = QApplication::desktop()->screenGeometry(pos); 335 //we put the popup menu on the screen containing the bottom-center of the action rect 336 QRect screenRect = QApplication::desktop()->screenGeometry(pos + QPoint(adjustedActionRect.width() / 2, 0)); 337 pos = QPoint(qMax(pos.x(), screenRect.x()), qMax(pos.y(), screenRect.y())); 320 338 321 339 const bool fitUp = (q->mapToGlobal(adjustedActionRect.topLeft()).y() >= popup_size.height()); 322 340 const bool fitDown = (pos.y() + popup_size.height() <= screenRect.bottom()); 341 const bool rtl = q->isRightToLeft(); 323 342 const int actionWidth = adjustedActionRect.width(); 324 343 325 344 if (!fitUp && !fitDown) { //we should shift the menu 326 bool shouldShiftToRight = ! q->isRightToLeft();327 if ( q->isRightToLeft()&& popup_size.width() > pos.x())345 bool shouldShiftToRight = !rtl; 346 if (rtl && popup_size.width() > pos.x()) 328 347 shouldShiftToRight = true; 329 348 else if (actionWidth + popup_size.width() + pos.x() > screenRect.right()) 330 349 shouldShiftToRight = false; 331 350 332 if (shouldShiftToRight) 333 pos.rx() += actionWidth; 334 else 335 pos.rx() -= popup_size.width(); 336 } else if (q->isRightToLeft()) { 337 pos.setX(pos.x()-(popup_size.width() - actionWidth)); 338 } 339 340 if(pos.x() < screenRect.x()) { 341 pos.setX(screenRect.x()); 342 } else { 343 const int off = pos.x()+popup_size.width() - screenRect.right(); 344 if(off > 0) 345 pos.setX(qMax(screenRect.x(), pos.x()-off)); 346 351 if (shouldShiftToRight) { 352 pos.rx() += actionWidth + (rtl ? popup_size.width() : 0); 353 } else { 354 //shift to left 355 if (!rtl) 356 pos.rx() -= popup_size.width(); 357 } 358 } else if (rtl) { 359 pos.rx() += actionWidth; 347 360 } 348 361 … … 399 412 } 400 413 401 void QMenuBarPrivate::calcActionRects(int max_width, int start , QMap<QAction*, QRect> &actionRects, QList<QAction*> &actionList) const414 void QMenuBarPrivate::calcActionRects(int max_width, int start) const 402 415 { 403 416 Q_Q(const QMenuBar); 404 417 405 if(!itemsDirty && itemsWidth == max_width && itemsStart == start) { 406 actionRects = actionRects; 407 actionList = actionList; 418 if(!itemsDirty) 408 419 return; 409 } 410 actionRects.clear(); 411 actionList.clear(); 412 const int itemSpacing = q->style()->pixelMetric(QStyle::PM_MenuBarItemSpacing, 0, q); 420 421 //let's reinitialize the buffer 422 actionRects.resize(actions.count()); 423 actionRects.fill(QRect()); 424 425 const QStyle *style = q->style(); 426 427 const int itemSpacing = style->pixelMetric(QStyle::PM_MenuBarItemSpacing, 0, q); 413 428 int max_item_height = 0, separator = -1, separator_start = 0, separator_len = 0; 414 QList<QAction*> items = q->actions();415 429 416 430 //calculate size 417 431 const QFontMetrics fm = q->fontMetrics(); 418 const int hmargin = q->style()->pixelMetric(QStyle::PM_MenuBarHMargin, 0, q),419 vmargin = q->style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, q),420 icone = q->style()->pixelMetric(QStyle::PM_SmallIconSize, 0, q);421 for(int i = 0; i < items.count(); i++) {422 QAction *action = items.at(i);432 const int hmargin = style->pixelMetric(QStyle::PM_MenuBarHMargin, 0, q), 433 vmargin = style->pixelMetric(QStyle::PM_MenuBarVMargin, 0, q), 434 icone = style->pixelMetric(QStyle::PM_SmallIconSize, 0, q); 435 for(int i = 0; i < actions.count(); i++) { 436 QAction *action = actions.at(i); 423 437 if(!action->isVisible()) 424 438 continue; … … 428 442 //calc what I think the size is.. 429 443 if(action->isSeparator()) { 430 if ( q->style()->styleHint(QStyle::SH_DrawMenuBarSeparator, 0, q))431 separator = actionRects.count();444 if (style->styleHint(QStyle::SH_DrawMenuBarSeparator, 0, q)) 445 separator = i; 432 446 continue; //we don't really position these! 433 447 } else { 434 QString s = action->text(); 435 if(!s.isEmpty()) { 436 int w = fm.width(s); 437 w -= s.count(QLatin1Char('&')) * fm.width(QLatin1Char('&')); 438 w += s.count(QLatin1String("&&")) * fm.width(QLatin1Char('&')); 439 sz = QSize(w, fm.height()); 440 } 441 448 const QString s = action->text(); 442 449 QIcon is = action->icon(); 443 if (!is.isNull()) { 444 QSize is_sz = QSize(icone, icone); 445 if (is_sz.height() > sz.height()) 446 sz.setHeight(is_sz.height()); 447 if (is_sz.width() > sz.width()) 448 sz.setWidth(is_sz.width()); 449 } 450 // If an icon is set, only the icon is visible 451 if (!is.isNull()) 452 sz = sz.expandedTo(QSize(icone, icone)); 453 else if (!s.isEmpty()) 454 sz = fm.size(Qt::TextShowMnemonic, s); 450 455 } 451 456 … … 457 462 if(!sz.isEmpty()) { 458 463 { //update the separator state 459 int iWidth = sz.width(); 460 iWidth += itemSpacing; 464 int iWidth = sz.width() + itemSpacing; 461 465 if(separator == -1) 462 466 separator_start += iWidth; … … 467 471 max_item_height = qMax(max_item_height, sz.height()); 468 472 //append 469 actionRects.insert(action, QRect(0, 0, sz.width(), sz.height())); 470 actionList.append(action); 473 actionRects[i] = QRect(0, 0, sz.width(), sz.height()); 471 474 } 472 475 } 473 476 474 477 //calculate position 475 int x = ((start == -1) ? hmargin : start) + itemSpacing; 476 int y = vmargin; 477 for(int i = 0; i < actionList.count(); i++) { 478 QAction *action = actionList.at(i); 479 QRect &rect = actionRects[action]; 478 const int fw = q->style()->pixelMetric(QStyle::PM_MenuBarPanelWidth, 0, q); 479 int x = fw + ((start == -1) ? hmargin : start) + itemSpacing; 480 int y = fw + vmargin; 481 for(int i = 0; i < actions.count(); i++) { 482 QRect &rect = actionRects[i]; 483 if (rect.isNull()) 484 continue; 485 480 486 //resize 481 487 rect.setHeight(max_item_height); … … 533 539 #ifndef QT_NO_ACCESSIBILITY 534 540 if (QAccessible::isActive()) { 535 QList<QAction*> actions = q->actions();536 541 int actionIndex = actions.indexOf(action); 537 542 ++actionIndex; … … 583 588 \brief The QMenuBar class provides a horizontal menu bar. 584 589 585 \ingroup application 586 \mainclass 590 \ingroup mainwindow-classes 587 591 588 592 A menu bar consists of a list of pull-down menu items. You add … … 662 666 \row \i about.* 663 667 \i Application Menu | About <application name> 664 \i If this entry is not found no About item will appear in 665 the Application Menu 668 \i The application name is fetched from the \c {Info.plist} file 669 (see note below). If this entry is not found no About item 670 will appear in the Application Menu. 666 671 \row \i config, options, setup, settings or preferences 667 672 \i Application Menu | Preferences … … 707 712 708 713 The \l{mainwindows/menus}{Menus} example shows how to use QMenuBar 709 and QMenu. The other \l{ Qt Examples#Main Windows}{main window714 and QMenu. The other \l{Main Window Examples}{main window 710 715 application examples} also provide menus using these classes. 711 716 712 717 \sa QMenu, QShortcut, QAction, 713 {http://developer.apple.com/documentation/UserExperience/Conceptual/ OSXHIGuidelines/index.html}{Introduction to Apple Human Interface Guidelines},718 {http://developer.apple.com/documentation/UserExperience/Conceptual/AppleHIGuidelines/XHIGIntro/XHIGIntro.html}{Introduction to Apple Human Interface Guidelines}, 714 719 {fowler}{GUI Design Handbook: Menu Bar}, {Menus Example} 715 720 */ … … 726 731 q->hide(); 727 732 #endif 728 #ifdef Q_ OS_WINCE733 #ifdef Q_WS_WINCE 729 734 if (qt_wince_is_mobile()) { 730 735 wceCreateMenuBar(q->parentWidget()); … … 732 737 q->hide(); 733 738 } 734 #endif 739 else { 740 QApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true); 741 } 742 #endif 743 #ifdef Q_WS_S60 744 symbianCreateMenuBar(q->parentWidget()); 745 if(symbian_menubar) 746 q->hide(); 747 #endif 748 735 749 q->setBackgroundRole(QPalette::Button); 736 750 oldWindow = oldParent = 0; … … 746 760 } 747 761 762 //Gets the next action for keyboard navigation 763 QAction *QMenuBarPrivate::getNextAction(const int _start, const int increment) const 764 { 765 Q_Q(const QMenuBar); 766 const_cast<QMenuBarPrivate*>(this)->updateGeometries(); 767 bool allowActiveAndDisabled = q->style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled, 0, q); 768 const int start = (_start == -1 && increment == -1) ? actions.count() : _start; 769 const int end = increment == -1 ? 0 : actions.count() - 1; 770 771 for (int i = start; start != end;) { 772 i += increment; 773 QAction *current = actions.at(i); 774 if (!actionRects.at(i).isNull() && (allowActiveAndDisabled || current->isEnabled())) 775 return current; 776 } 777 778 if (_start != -1) //let's try from the beginning or the end 779 return getNextAction(-1, increment); 780 781 return 0; 782 } 783 748 784 /*! 749 785 Constructs a menu bar with parent \a parent. … … 777 813 d->macDestroyMenuBar(); 778 814 #endif 779 #ifdef Q_ OS_WINCE815 #ifdef Q_WS_WINCE 780 816 Q_D(QMenuBar); 781 817 if (qt_wince_is_mobile()) 782 818 d->wceDestroyMenuBar(); 819 #endif 820 #ifdef Q_WS_S60 821 Q_D(QMenuBar); 822 d->symbianDestroyMenuBar(); 783 823 #endif 784 824 } … … 925 965 Removes all the actions from the menu bar. 926 966 967 \note On Mac OS X, menu items that have been merged to the system 968 menu bar are not removed by this function. One way to handle this 969 would be to remove the extra actions yourself. You can set the 970 \l{QAction::MenuRole}{menu role} on the different menus, so that 971 you know ahead of time which menu items get merged and which do 972 not. Then decide what to recreate or remove yourself. 973 927 974 \sa removeAction() 928 975 */ … … 978 1025 979 1026 //draw the items 980 for (int i = 0; i < d->action List.count(); ++i) {981 QAction *action = d->action List.at(i);1027 for (int i = 0; i < d->actions.count(); ++i) { 1028 QAction *action = d->actions.at(i); 982 1029 QRect adjustedActionRect = d->actionRect(action); 983 1030 if (adjustedActionRect.isEmpty() || !d->isVisible(action)) … … 1026 1073 void QMenuBar::setVisible(bool visible) 1027 1074 { 1028 #ifdef Q_WS_MAC 1029 Q_D(QMenuBar); 1030 if(d->mac_menubar) 1031 return; 1032 #endif 1033 #ifdef Q_OS_WINCE 1034 Q_D(QMenuBar); 1035 if(d->wce_menubar) 1075 #if defined(Q_WS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60) 1076 if (isNativeMenuBar()) 1036 1077 return; 1037 1078 #endif … … 1047 1088 if(e->button() != Qt::LeftButton) 1048 1089 return; 1090 1091 d->mouseDown = true; 1049 1092 1050 1093 QAction *action = d->actionAt(e->pos()); … … 1057 1100 return; 1058 1101 } 1059 1060 d->mouseDown = true;1061 1102 1062 1103 if(d->currentAction == action && d->popupState) { … … 1101 1142 { 1102 1143 Q_D(QMenuBar); 1144 d->updateGeometries(); 1103 1145 int key = e->key(); 1104 1146 if(isRightToLeft()) { // in reverse mode open/close key for submenues are reversed … … 1135 1177 case Qt::Key_Left: { 1136 1178 if(d->currentAction) { 1137 QAction *nextAction = 0; 1138 bool allowActiveAndDisabled = 1139 style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled, 0, this); 1140 1141 for(int i=0; i<(int)d->actionList.count(); i++) { 1142 if(d->actionList.at(i) == (QAction*)d->currentAction) { 1143 if (key == Qt::Key_Left) { 1144 while (i > 0) { 1145 i--; 1146 if (allowActiveAndDisabled || d->actionList[i]->isEnabled()) { 1147 nextAction = d->actionList.at(i); 1148 break; 1149 } 1150 } 1151 } else { 1152 while (i < d->actionList.count()-1) { 1153 i++; 1154 if (allowActiveAndDisabled || d->actionList[i]->isEnabled()) { 1155 nextAction = d->actionList.at(i); 1156 break; 1157 } 1158 } 1159 } 1160 break; 1161 1162 } 1163 } 1164 1165 if(!nextAction) { 1166 if (key == Qt::Key_Left) { 1167 for (int i = d->actionList.size() - 1 ; i >= 0 ; --i) { 1168 if (allowActiveAndDisabled || d->actionList[i]->isEnabled()) { 1169 nextAction = d->actionList.at(i); 1170 i--; 1171 break; 1172 } 1173 } 1174 } else { 1175 for (int i = 0 ; i < d->actionList.count() ; ++i) { 1176 if (allowActiveAndDisabled || d->actionList[i]->isEnabled()) { 1177 nextAction = d->actionList.at(i); 1178 i++; 1179 break; 1180 } 1181 } 1182 } 1183 } 1184 if(nextAction) { 1179 int index = d->actions.indexOf(d->currentAction); 1180 if (QAction *nextAction = d->getNextAction(index, key == Qt::Key_Left ? -1 : +1)) { 1185 1181 d->setCurrentAction(nextAction, d->popupState, true); 1186 1182 key_consumed = true; … … 1206 1202 { 1207 1203 QChar c = e->text()[0].toUpper(); 1208 for(int i = 0; i < d->actionList.size(); ++i) { 1209 register QAction *act = d->actionList.at(i); 1204 for(int i = 0; i < d->actions.size(); ++i) { 1205 if (d->actionRects.at(i).isNull()) 1206 continue; 1207 QAction *act = d->actions.at(i); 1210 1208 QString s = act->text(); 1211 1209 if(!s.isEmpty()) { … … 1249 1247 { 1250 1248 Q_D(QMenuBar); 1251 d->mouseDown = e->buttons() & Qt::LeftButton; 1249 if (!(e->buttons() & Qt::LeftButton)) 1250 d->mouseDown = false; 1251 bool popupState = d->popupState || d->mouseDown; 1252 1252 QAction *action = d->actionAt(e->pos()); 1253 bool popupState = d->popupState || d->mouseDown;1254 1253 if ((action && d->isVisible(action)) || !popupState) 1255 1254 d->setCurrentAction(action, popupState); … … 1262 1261 { 1263 1262 Q_D(QMenuBar); 1264 if(!hasFocus() && !d->popupState) 1263 if((!hasFocus() && !d->popupState) || 1264 (d->currentAction && d->currentAction->menu() == 0)) 1265 1265 d->setCurrentAction(0); 1266 1266 } … … 1273 1273 Q_D(QMenuBar); 1274 1274 d->itemsDirty = true; 1275 #if defined (Q_WS_MAC) || defined(Q_OS_WINCE) || defined(Q_WS_S60) 1276 if (isNativeMenuBar()) { 1275 1277 #ifdef Q_WS_MAC 1276 if(d->mac_menubar) { 1278 QMenuBarPrivate::QMacMenuBarPrivate *nativeMenuBar = d->mac_menubar; 1279 #elif defined(Q_WS_S60) 1280 QMenuBarPrivate::QSymbianMenuBarPrivate *nativeMenuBar = d->symbian_menubar; 1281 #else 1282 QMenuBarPrivate::QWceMenuBarPrivate *nativeMenuBar = d->wce_menubar; 1283 #endif 1284 if (!nativeMenuBar) 1285 return; 1277 1286 if(e->type() == QEvent::ActionAdded) 1278 d->mac_menubar->addAction(e->action(), d->mac_menubar->findAction(e->before()));1287 nativeMenuBar->addAction(e->action(), nativeMenuBar->findAction(e->before())); 1279 1288 else if(e->type() == QEvent::ActionRemoved) 1280 d->mac_menubar->removeAction(e->action());1289 nativeMenuBar->removeAction(e->action()); 1281 1290 else if(e->type() == QEvent::ActionChanged) 1282 d->mac_menubar->syncAction(e->action()); 1283 } 1284 #endif 1285 #ifdef Q_OS_WINCE 1286 if(d->wce_menubar) { 1287 if(e->type() == QEvent::ActionAdded) 1288 d->wce_menubar->addAction(e->action(), d->wce_menubar->findAction(e->before())); 1289 else if(e->type() == QEvent::ActionRemoved) 1290 d->wce_menubar->removeAction(e->action()); 1291 else if(e->type() == QEvent::ActionChanged) 1292 d->wce_menubar->syncAction(e->action()); 1293 } 1294 #endif 1291 nativeMenuBar->syncAction(e->action()); 1292 } 1293 #endif 1294 1295 1295 if(e->type() == QEvent::ActionAdded) { 1296 1296 connect(e->action(), SIGNAL(triggered()), this, SLOT(_q_actionTriggered())); … … 1311 1311 { 1312 1312 Q_D(QMenuBar); 1313 if(d->keyboardState && !d->currentAction && !d->actionList.isEmpty())1314 d-> setCurrentAction(d->actionList.first());1313 if(d->keyboardState) 1314 d->focusFirstAction(); 1315 1315 } 1316 1316 … … 1371 1371 1372 1372 #ifdef Q_WS_MAC 1373 macDestroyMenuBar(); 1374 macCreateMenuBar(newParent); 1375 #endif 1376 1377 #ifdef Q_OS_WINCE 1373 if (q->isNativeMenuBar() && !macWidgetHasNativeMenubar(newParent)) { 1374 // If the new parent got a native menubar from before, keep that 1375 // menubar rather than replace it with this one (because a parents 1376 // menubar has precedence over children menubars). 1377 macDestroyMenuBar(); 1378 macCreateMenuBar(newParent); 1379 } 1380 #endif 1381 1382 #ifdef Q_WS_WINCE 1378 1383 if (qt_wince_is_mobile() && wce_menubar) 1379 1384 wce_menubar->rebuild(); 1380 1385 #endif 1386 #ifdef Q_WS_S60 1387 if (symbian_menubar) 1388 symbian_menubar->rebuild(); 1389 #endif 1390 1381 1391 } 1382 1392 … … 1480 1490 case QEvent::ShortcutOverride: { 1481 1491 QKeyEvent *kev = static_cast<QKeyEvent*>(e); 1482 if (kev->key() == Qt::Key_Escape) { 1492 //we only filter out escape if there is a current action 1493 if (kev->key() == Qt::Key_Escape && d->currentAction) { 1483 1494 e->accept(); 1484 1495 return true; … … 1613 1624 { 1614 1625 Q_D(const QMenuBar); 1615 #ifdef Q_WS_MAC 1616 const bool as_gui_menubar = !d->mac_menubar; 1617 #elif defined (Q_OS_WINCE) 1618 const bool as_gui_menubar = !d->wce_menubar; 1626 #if defined(Q_WS_MAC) || defined(Q_WS_WINCE) || defined(Q_WS_S60) 1627 const bool as_gui_menubar = !isNativeMenuBar(); 1619 1628 #else 1620 1629 const bool as_gui_menubar = true; … … 1623 1632 ensurePolished(); 1624 1633 QSize ret(0, 0); 1634 const_cast<QMenuBarPrivate*>(d)->updateGeometries(); 1625 1635 const int hmargin = style()->pixelMetric(QStyle::PM_MenuBarHMargin, 0, this); 1626 1636 const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this); … … 1628 1638 int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this); 1629 1639 if(as_gui_menubar) { 1630 QMap<QAction*, QRect> actionRects;1631 QList<QAction*> actionList;1632 1640 int w = parentWidget() ? parentWidget()->width() : QApplication::desktop()->width(); 1633 d->calcActionRects(w - (2 * fw), 0, actionRects, actionList); 1634 if (d->actionList.count() > 0) { 1635 ret = d->actionRect(d->actionList.at(0)).size(); 1636 if (!d->extension->isHidden()) 1637 ret += QSize(d->extension->sizeHint().width(), 0); 1638 } 1641 d->calcActionRects(w - (2 * fw), 0); 1642 for (int i = 0; ret.isNull() && i < d->actions.count(); ++i) 1643 ret = d->actionRects.at(i).size(); 1644 if (!d->extension->isHidden()) 1645 ret += QSize(d->extension->sizeHint().width(), 0); 1639 1646 ret += QSize(2*fw + hmargin, 2*fw + vmargin); 1640 1647 } … … 1673 1680 { 1674 1681 Q_D(const QMenuBar); 1675 #ifdef Q_WS_MAC 1676 const bool as_gui_menubar = !d->mac_menubar; 1677 #elif defined (Q_OS_WINCE) 1678 const bool as_gui_menubar = !d->wce_menubar; 1682 #if defined(Q_WS_MAC) || defined(Q_WS_WINCE) || defined(Q_WS_S60) 1683 const bool as_gui_menubar = !isNativeMenuBar(); 1679 1684 #else 1680 1685 const bool as_gui_menubar = true; 1681 1686 #endif 1682 1687 1688 1683 1689 ensurePolished(); 1684 1690 QSize ret(0, 0); 1691 const_cast<QMenuBarPrivate*>(d)->updateGeometries(); 1685 1692 const int hmargin = style()->pixelMetric(QStyle::PM_MenuBarHMargin, 0, this); 1686 1693 const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this); … … 1688 1695 int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this); 1689 1696 if(as_gui_menubar) { 1690 QMap<QAction*, QRect> actionRects;1691 QList<QAction*> actionList;1692 1697 const int w = parentWidget() ? parentWidget()->width() : QApplication::desktop()->width(); 1693 d->calcActionRects(w - (2 * fw), 0, actionRects, actionList); 1694 for (QMap<QAction*, QRect>::const_iterator i = actionRects.constBegin(); 1695 i != actionRects.constEnd(); ++i) { 1696 QRect actionRect(i.value()); 1697 if(actionRect.x() + actionRect.width() > ret.width()) 1698 ret.setWidth(actionRect.x() + actionRect.width()); 1699 if(actionRect.y() + actionRect.height() > ret.height()) 1700 ret.setHeight(actionRect.y() + actionRect.height()); 1701 } 1702 ret += QSize(2*fw + 2*hmargin, 2*fw + 2*vmargin); 1698 d->calcActionRects(w - (2 * fw), 0); 1699 for (int i = 0; i < d->actionRects.count(); ++i) { 1700 const QRect &actionRect = d->actionRects.at(i); 1701 ret = ret.expandedTo(QSize(actionRect.x() + actionRect.width(), actionRect.y() + actionRect.height())); 1702 } 1703 //the action geometries already contain the top and left 1704 //margins. So we only need to add those from right and bottom. 1705 ret += QSize(fw + hmargin, fw + vmargin); 1703 1706 } 1704 1707 int margin = 2*vmargin + 2*fw + spaceBelowMenuBar; … … 1736 1739 { 1737 1740 Q_D(const QMenuBar); 1738 #ifdef Q_WS_MAC 1739 const bool as_gui_menubar = !d->mac_menubar; 1740 #elif defined (Q_OS_WINCE) 1741 const bool as_gui_menubar = !d->wce_menubar; 1741 #if defined(Q_WS_MAC) || defined(Q_WS_WINCE) || defined(Q_WS_S60) 1742 const bool as_gui_menubar = !isNativeMenuBar(); 1742 1743 #else 1743 1744 const bool as_gui_menubar = true; 1744 1745 #endif 1746 1747 const_cast<QMenuBarPrivate*>(d)->updateGeometries(); 1745 1748 int height = 0; 1746 1749 const int vmargin = style()->pixelMetric(QStyle::PM_MenuBarVMargin, 0, this); … … 1748 1751 int spaceBelowMenuBar = style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this); 1749 1752 if(as_gui_menubar) { 1750 if (d->actionList.count()) {1751 // assume all actionrects have the same height1752 height = d->actionRect(d->actionList.first()).height();1753 for (int i = 0; i < d->actionRects.count(); ++i) 1754 height = qMax(height, d->actionRects.at(i).height()); 1755 if (height) //there is at least one non-null item 1753 1756 height += spaceBelowMenuBar; 1754 }1755 1757 height += 2*fw; 1756 1758 height += 2*vmargin; … … 1779 1781 { 1780 1782 Q_Q(QMenuBar); 1781 QAction *act = action List.at(id);1783 QAction *act = actions.at(id); 1782 1784 setCurrentAction(act, true, true); 1783 1785 if (act && !act->menu()) { … … 1785 1787 //100 is the same as the default value in QPushButton::animateClick 1786 1788 autoReleaseTimer.start(100, q); 1789 } else if (act && q->style()->styleHint(QStyle::SH_MenuBar_AltKeyNavigation, 0, q)) { 1790 // When we open a menu using a shortcut, we should end up in keyboard state 1791 setKeyboardMode(true); 1787 1792 } 1788 1793 } … … 1857 1862 1858 1863 /*! 1864 \property QMenuBar::nativeMenuBar 1865 \brief Whether or not a menubar will be used as a native menubar on platforms that support it 1866 \since 4.6 1867 1868 This property specifies whether or not the menubar should be used as a native menubar on platforms 1869 that support it. The currently supported platforms are Mac OS X and Windows CE. On these platforms 1870 if this property is true, the menubar is used in the native menubar and is not in the window of 1871 its parent, if false the menubar remains in the window. On other platforms the value of this 1872 attribute has no effect. 1873 1874 The default is to follow whether the Qt::AA_DontUseNativeMenuBar attribute 1875 is set for the application. Explicitly settings this property overrides 1876 the presence (or abscence) of the attribute. 1877 */ 1878 1879 void QMenuBar::setNativeMenuBar(bool nativeMenuBar) 1880 { 1881 Q_D(QMenuBar); 1882 if (d->nativeMenuBar == -1 || (nativeMenuBar != bool(d->nativeMenuBar))) { 1883 d->nativeMenuBar = nativeMenuBar; 1884 #ifdef Q_WS_MAC 1885 if (!d->nativeMenuBar) { 1886 extern void qt_mac_clear_menubar(); 1887 qt_mac_clear_menubar(); 1888 d->macDestroyMenuBar(); 1889 const QList<QAction *> &menubarActions = actions(); 1890 for (int i = 0; i < menubarActions.size(); ++i) { 1891 const QAction *action = menubarActions.at(i); 1892 if (QMenu *menu = action->menu()) { 1893 delete menu->d_func()->mac_menu; 1894 menu->d_func()->mac_menu = 0; 1895 } 1896 } 1897 } else { 1898 d->macCreateMenuBar(parentWidget()); 1899 } 1900 macUpdateMenuBar(); 1901 updateGeometry(); 1902 setVisible(false); 1903 setVisible(true); 1904 #endif 1905 } 1906 } 1907 1908 bool QMenuBar::isNativeMenuBar() const 1909 { 1910 Q_D(const QMenuBar); 1911 if (d->nativeMenuBar == -1) { 1912 return !QApplication::instance()->testAttribute(Qt::AA_DontUseNativeMenuBar); 1913 } 1914 return d->nativeMenuBar; 1915 } 1916 1917 /*! 1859 1918 \since 4.4 1860 1919 … … 1870 1929 */ 1871 1930 1872 #ifdef Q_ OS_WINCE1931 #ifdef Q_WS_WINCE 1873 1932 void QMenuBar::setDefaultAction(QAction *act) 1874 1933 { … … 1876 1935 if (d->defaultAction == act) 1877 1936 return; 1878 #ifdef Q_ OS_WINCE1937 #ifdef Q_WS_WINCE 1879 1938 if (qt_wince_is_mobile()) 1880 1939 if (d->defaultAction) { 1881 1940 disconnect(d->defaultAction, SIGNAL(changed()), this, SLOT(_q_updateDefaultAction())); 1882 disconnect(d->defaultAction, SIGNAL(destroyed 1941 disconnect(d->defaultAction, SIGNAL(destroyed()), this, SLOT(_q_updateDefaultAction())); 1883 1942 } 1884 1943 #endif 1885 1944 d->defaultAction = act; 1886 #ifdef Q_ OS_WINCE1945 #ifdef Q_WS_WINCE 1887 1946 if (qt_wince_is_mobile()) 1888 1947 if (d->defaultAction) { … … 2380 2439 /*! 2381 2440 \fn int QMenuBar::margin() const 2382 Returns the wi th of thethe margin around the contents of the widget.2441 Returns the width of the margin around the contents of the widget. 2383 2442 2384 2443 Use QWidget::getContentsMargins() instead. -
trunk/src/gui/widgets/qmenubar.h
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 ** … … 65 65 66 66 Q_PROPERTY(bool defaultUp READ isDefaultUp WRITE setDefaultUp) 67 Q_PROPERTY(bool nativeMenuBar READ isNativeMenuBar WRITE setNativeMenuBar) 67 68 68 69 public: … … 111 112 #endif 112 113 113 #ifdef Q_ OS_WINCE114 #ifdef Q_WS_WINCE 114 115 void setDefaultAction(QAction *); 115 116 QAction *defaultAction() const; … … 118 119 static void wceRefresh(); 119 120 #endif 121 122 bool isNativeMenuBar() const; 123 void setNativeMenuBar(bool nativeMenuBar); 120 124 121 125 public Q_SLOTS: … … 340 344 Q_PRIVATE_SLOT(d_func(), void _q_updateLayout()) 341 345 342 #ifdef Q_ OS_WINCE346 #ifdef Q_WS_WINCE 343 347 Q_PRIVATE_SLOT(d_func(), void _q_updateDefaultAction()) 344 348 #endif -
trunk/src/gui/widgets/qmenubar_p.h
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 ** … … 58 58 #include <private/qmenu_p.h> // Mac needs what in this file! 59 59 60 #ifdef Q_ OS_WINCE60 #ifdef Q_WS_WINCE 61 61 #include "qguifunctions_wince.h" 62 #endif 63 64 #ifndef QT_NO_MENUBAR 65 #ifdef Q_WS_S60 66 class CCoeControl; 67 class CEikMenuBar; 68 #endif 62 69 #endif 63 70 … … 70 77 Q_DECLARE_PUBLIC(QMenuBar) 71 78 public: 72 QMenuBarPrivate() : itemsDirty(0), itemsWidth(0), itemsStart(-1), currentAction(0), mouseDown(0), 73 closePopupMode(0), defaultPopDown(1), popupState(0), keyboardState(0), altPressed(0) 79 QMenuBarPrivate() : itemsDirty(0), currentAction(0), mouseDown(0), 80 closePopupMode(0), defaultPopDown(1), popupState(0), keyboardState(0), altPressed(0), 81 nativeMenuBar(-1), doChildEffects(false) 82 #ifdef QT3_SUPPORT 83 , doAutoResize(false) 84 #endif 74 85 #ifdef Q_WS_MAC 75 86 , mac_menubar(0) 76 87 #endif 77 88 78 #ifdef Q_ OS_WINCE89 #ifdef Q_WS_WINCE 79 90 , wce_menubar(0), wceClassicMenu(false) 80 91 #endif 81 { } 92 #ifdef Q_WS_S60 93 , symbian_menubar(0) 94 #endif 95 96 { } 82 97 ~QMenuBarPrivate() 83 98 { … … 85 100 delete mac_menubar; 86 101 #endif 87 #ifdef Q_ OS_WINCE102 #ifdef Q_WS_WINCE 88 103 delete wce_menubar; 89 104 #endif 105 #ifdef Q_WS_S60 106 delete symbian_menubar; 107 #endif 90 108 } 91 109 92 110 void init(); 93 Q StyleOptionMenuItem getStyleOption(const QAction *action) const;111 QAction *getNextAction(const int start, const int increment) const; 94 112 95 113 //item calculations 96 114 uint itemsDirty : 1; 97 int itemsWidth, itemsStart;98 115 99 116 QVector<int> shortcutIndexMap; 100 mutable QMap<QAction*, QRect> actionRects; 101 mutable QList<QAction*> actionList; 102 void calcActionRects(int max_width, int start, QMap<QAction*, QRect> &actionRects, QList<QAction*> &actionList) const; 117 mutable QVector<QRect> actionRects; 118 void calcActionRects(int max_width, int start) const; 103 119 QRect actionRect(QAction *) const; 104 120 void updateGeometries(); … … 116 132 117 133 //keyboard mode for keyboard navigation 134 void focusFirstAction(); 118 135 void setKeyboardMode(bool); 119 136 uint keyboardState : 1, altPressed : 1; 120 137 QPointer<QWidget> keyboardFocusWidget; 121 138 139 140 int nativeMenuBar : 3; // Only has values -1, 0, and 1 122 141 //firing of events 123 142 void activateAction(QAction *, QAction::ActionEvent); … … 128 147 void _q_updateLayout(); 129 148 130 #ifdef Q_ OS_WINCE149 #ifdef Q_WS_WINCE 131 150 void _q_updateDefaultAction(); 132 151 #endif … … 178 197 } 179 198 } *mac_menubar; 199 bool macWidgetHasNativeMenubar(QWidget *widget); 180 200 void macCreateMenuBar(QWidget *); 181 201 void macDestroyMenuBar(); 182 202 OSMenuRef macMenu(); 183 203 #endif 184 #ifdef Q_ OS_WINCE204 #ifdef Q_WS_WINCE 185 205 void wceCreateMenuBar(QWidget *); 186 206 void wceDestroyMenuBar(); … … 221 241 bool wceEmitSignals(QList<QWceMenuAction*> actions, uint command); 222 242 #endif 243 #ifdef Q_WS_S60 244 void symbianCreateMenuBar(QWidget *); 245 void symbianDestroyMenuBar(); 246 struct QSymbianMenuBarPrivate { 247 QList<QSymbianMenuAction*> actionItems; 248 QMenuBarPrivate *d; 249 QSymbianMenuBarPrivate(QMenuBarPrivate *menubar); 250 ~QSymbianMenuBarPrivate(); 251 void addAction(QAction *, QSymbianMenuAction* =0); 252 void addAction(QSymbianMenuAction *, QSymbianMenuAction* =0); 253 void syncAction(QSymbianMenuAction *); 254 inline void syncAction(QAction *a) { syncAction(findAction(a)); } 255 void removeAction(QSymbianMenuAction *); 256 void rebuild(); 257 inline void removeAction(QAction *a) { removeAction(findAction(a)); } 258 inline QSymbianMenuAction *findAction(QAction *a) { 259 for(int i = 0; i < actionItems.size(); i++) { 260 QSymbianMenuAction *act = actionItems[i]; 261 if(a == act->action) 262 return act; 263 } 264 return 0; 265 } 266 void insertNativeMenuItems(const QList<QAction*> &actions); 267 268 } *symbian_menubar; 269 static int symbianCommands(int command); 270 271 #endif 223 272 }; 224 273 #endif -
trunk/src/gui/widgets/qmenudata.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 ** -
trunk/src/gui/widgets/qmenudata.h
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 ** … … 68 68 void setId(int); 69 69 void setSignalValue(int); 70 71 Q_DISABLE_COPY(QMenuItem) 70 72 }; 71 73 -
trunk/src/gui/widgets/qplaintextedit.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 ** … … 66 66 #include <qtexttable.h> 67 67 #include <qvariant.h> 68 69 68 #include <qinputcontext.h> 70 69 … … 72 71 73 72 QT_BEGIN_NAMESPACE 73 74 static inline bool shouldEnableInputMethod(QPlainTextEdit *plaintextedit) 75 { 76 return !plaintextedit->isReadOnly(); 77 } 74 78 75 79 class QPlainTextDocumentLayoutPrivate : public QAbstractTextDocumentLayoutPrivate … … 110 114 \brief The QPlainTextDocumentLayout class implements a plain text layout for QTextDocument 111 115 112 \ingroup text 113 116 \ingroup richtext-processing 114 117 115 118 A QPlainTextDocumentLayout is required for text documents that can … … 251 254 void QPlainTextDocumentLayout::requestUpdate() 252 255 { 253 emit update(QRectF(0., - 4., 1000000000., 1000000000.));256 emit update(QRectF(0., -document()->documentMargin(), 1000000000., 1000000000.)); 254 257 } 255 258 … … 346 349 347 350 if (!d->blockUpdate) 348 emit update(); // optimization potential 349 351 emit update(QRectF(0., -doc->documentMargin(), 1000000000., 1000000000.)); // optimization potential 350 352 } 351 353 … … 356 358 QTextDocument *doc = document(); 357 359 qreal margin = doc->documentMargin(); 358 QFontMetrics fm(doc->defaultFont());359 360 qreal blockMaximumWidth = 0; 360 361 361 int leading = qMax(0, fm.leading());362 362 qreal height = 0; 363 363 QTextLayout *tl = block.layout(); … … 371 371 } 372 372 tl->beginLayout(); 373 qreal availableWidth = d->width; 374 if (availableWidth <= 0) { 375 availableWidth = qreal(INT_MAX); // similar to text edit with pageSize.width == 0 376 } 377 availableWidth -= 2*margin + extraMargin; 373 378 while (1) { 374 379 QTextLine line = tl->createLine(); 375 380 if (!line.isValid()) 376 381 break; 377 line.setLineWidth(d->width - 2*margin - extraMargin); 378 379 height += leading; 382 line.setLeadingIncluded(true); 383 line.setLineWidth(availableWidth); 380 384 line.setPosition(QPointF(margin, height)); 381 385 height += line.height(); … … 440 444 { 441 445 pageUpDownLastCursorYIsValid = false; 442 } ;446 } 443 447 444 448 void QPlainTextEditPrivate::_q_verticalScrollbarActionTriggered(int action) { … … 508 512 int currentBlockNumber = topBlock; 509 513 QTextBlock currentBlock = document()->findBlockByNumber(currentBlockNumber); 514 if (!currentBlock.isValid()) 515 return -1; 516 510 517 QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(document()->documentLayout()); 511 518 Q_ASSERT(documentLayout); … … 556 563 return QRectF(); 557 564 Q_ASSERT(currentBlock.blockNumber() == currentBlockNumber); 558 QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(document()->documentLayout()); 565 QTextDocument *doc = document(); 566 QPlainTextDocumentLayout *documentLayout = qobject_cast<QPlainTextDocumentLayout*>(doc->documentLayout()); 559 567 Q_ASSERT(documentLayout); 560 568 … … 563 571 return QRectF(); 564 572 QRectF r = documentLayout->blockBoundingRect(currentBlock); 565 while (currentBlockNumber < blockNumber && offset.y() <= 2* textEdit->viewport()->height()) { 573 int maxVerticalOffset = r.height(); 574 while (currentBlockNumber < blockNumber && offset.y() - maxVerticalOffset <= 2* textEdit->viewport()->height()) { 566 575 offset.ry() += r.height(); 567 576 currentBlock = currentBlock.next(); 568 577 ++currentBlockNumber; 578 if (!currentBlock.isVisible()) { 579 currentBlock = doc->findBlockByLineNumber(currentBlock.firstLineNumber()); 580 currentBlockNumber = currentBlock.blockNumber(); 581 } 569 582 r = documentLayout->blockBoundingRect(currentBlock); 570 583 } 571 while (currentBlockNumber > blockNumber && offset.y() >= -textEdit->viewport()->height()) {584 while (currentBlockNumber > blockNumber && offset.y() + maxVerticalOffset >= -textEdit->viewport()->height()) { 572 585 currentBlock = currentBlock.previous(); 586 --currentBlockNumber; 587 while (!currentBlock.isVisible()) { 588 currentBlock = currentBlock.previous(); 589 --currentBlockNumber; 590 } 573 591 if (!currentBlock.isValid()) 574 592 break; 575 --currentBlockNumber; 593 576 594 r = documentLayout->blockBoundingRect(currentBlock); 577 595 offset.ry() -= r.height(); … … 625 643 if (viewport->updatesEnabled() && viewport->isVisible()) { 626 644 int dy = 0; 627 if (doc->findBlockBy LineNumber(control->topBlock).isValid()) {645 if (doc->findBlockByNumber(control->topBlock).isValid()) { 628 646 dy = (int)(-q->blockBoundingGeometry(block).y()) 629 647 + verticalOffset() - verticalOffset(blockNumber, lineNumber); … … 667 685 qreal h = center ? line.naturalTextRect().center().y() : line.naturalTextRect().bottom(); 668 686 687 QTextBlock previousVisibleBlock = block; 669 688 while (h < height && block.previous().isValid()) { 670 block = block.previous(); 689 previousVisibleBlock = block; 690 do { 691 block = block.previous(); 692 } while (!block.isVisible() && block.previous().isValid()); 671 693 h += q->blockBoundingRect(block).height(); 672 694 } … … 682 704 } 683 705 684 if ( block.next().isValid() &&l >= lineCount) {685 block = block.next();706 if (l >= lineCount) { 707 block = previousVisibleBlock; 686 708 l = 0; 687 709 } … … 706 728 lineWrap(QPlainTextEdit::WidgetWidth), 707 729 wordWrap(QTextOption::WrapAtWordBoundaryOrAnywhere), 708 topLine(0), pageUpDownLastCursorYIsValid(false) 730 clickCausedFocus(0),topLine(0), 731 pageUpDownLastCursorYIsValid(false) 709 732 { 710 733 showCursorOnInitialShow = true; … … 743 766 QObject::connect(control, SIGNAL(cursorPositionChanged()), q, SIGNAL(cursorPositionChanged())); 744 767 768 QObject::connect(control, SIGNAL(textChanged()), q, SLOT(updateMicroFocus())); 745 769 746 770 // set a null page size initially to avoid any relayouting until the textedit 747 771 // is shown. relayoutDocument() will take care of setting the page size to the 748 772 // viewport dimensions later. 749 doc->setTextWidth( 0);773 doc->setTextWidth(-1); 750 774 doc->documentLayout()->setPaintDevice(viewport); 751 775 doc->setDefaultFont(q->font()); … … 766 790 #ifndef QT_NO_CURSOR 767 791 viewport->setCursor(Qt::IBeamCursor); 792 #endif 793 originalOffsetY = 0; 794 #ifdef Q_WS_WIN 795 setSingleFingerPanEnabled(true); 768 796 #endif 769 797 } … … 986 1014 plain text. 987 1015 988 \ingroup text989 \mainclass 1016 \ingroup richtext-processing 1017 990 1018 991 1019 \tableofcontents … … 1000 1028 QTextEdit, but is optimized for plain text handling. 1001 1029 1002 QPlainTextEdit works on paragraphs and characters. A paragraph is a1003 formatted string which is word-wrapped to fit into the width of1030 QPlainTextEdit works on paragraphs and characters. A paragraph is 1031 a formatted string which is word-wrapped to fit into the width of 1004 1032 the widget. By default when reading plain text, one newline 1005 1033 signifies a paragraph. A document consists of zero or more 1006 paragraphs. The words in the paragraph are aligned in accordance 1007 with the paragraph's alignment. Paragraphs are separated by hard 1008 line breaks. Each character within a paragraph has its own 1009 attributes, for example, font and color. 1034 paragraphs. Paragraphs are separated by hard line breaks. Each 1035 character within a paragraph has its own attributes, for example, 1036 font and color. 1010 1037 1011 1038 The shape of the mouse cursor on a QPlainTextEdit is … … 1015 1042 \section1 Using QPlainTextEdit as a Display Widget 1016 1043 1017 The text is set or replaced using setPlainText() which deletes any 1018 existing text and replaces it with the text passed in the 1019 setPlainText() call. 1020 1021 Text itself can be inserted using the QTextCursor class or using 1022 the convenience functins insertPlainText(), appendPlainText() or 1044 The text is set or replaced using setPlainText() which deletes the 1045 existing text and replaces it with the text passed to setPlainText(). 1046 1047 Text can be inserted using the QTextCursor class or using the 1048 convenience functions insertPlainText(), appendPlainText() or 1023 1049 paste(). 1024 1050 1025 By default the text edit wraps words at whitespace to fit within1051 By default, the text edit wraps words at whitespace to fit within 1026 1052 the text edit widget. The setLineWrapMode() function is used to 1027 1053 specify the kind of line wrap you want, \l WidgetWidth or \l … … 1149 1175 1150 1176 \sa QTextDocument, QTextCursor, {Application Example}, 1151 {Syntax Highlighter Example}, {Rich Text Processing} 1177 {Code Editor Example}, {Syntax Highlighter Example}, 1178 {Rich Text Processing} 1152 1179 1153 1180 */ … … 1429 1456 } 1430 1457 #endif 1458 else if (e->type() == QEvent::Gesture) { 1459 QGestureEvent *ge = static_cast<QGestureEvent *>(e); 1460 QPanGesture *g = static_cast<QPanGesture *>(ge->gesture(Qt::PanGesture)); 1461 if (g) { 1462 QScrollBar *hBar = horizontalScrollBar(); 1463 QScrollBar *vBar = verticalScrollBar(); 1464 if (g->state() == Qt::GestureStarted) 1465 d->originalOffsetY = vBar->value(); 1466 QPointF offset = g->offset(); 1467 if (!offset.isNull()) { 1468 if (QApplication::isRightToLeft()) 1469 offset.rx() *= -1; 1470 // QPlainTextEdit scrolls by lines only in vertical direction 1471 QFontMetrics fm(document()->defaultFont()); 1472 int lineHeight = fm.height(); 1473 int newX = hBar->value() - g->delta().x(); 1474 int newY = d->originalOffsetY - offset.y()/lineHeight; 1475 hBar->setValue(newX); 1476 vBar->setValue(newY); 1477 } 1478 } 1479 return true; 1480 } 1431 1481 return QAbstractScrollArea::event(e); 1432 1482 } … … 1552 1602 #endif 1553 1603 1554 if (!(d->control->textInteractionFlags() & Qt::TextEditable)) { 1604 #ifndef QT_NO_SHORTCUT 1605 1606 Qt::TextInteractionFlags tif = d->control->textInteractionFlags(); 1607 1608 if (tif & Qt::TextSelectableByKeyboard){ 1609 if (e == QKeySequence::SelectPreviousPage) { 1610 e->accept(); 1611 d->pageUpDown(QTextCursor::Up, QTextCursor::KeepAnchor); 1612 return; 1613 } else if (e ==QKeySequence::SelectNextPage) { 1614 e->accept(); 1615 d->pageUpDown(QTextCursor::Down, QTextCursor::KeepAnchor); 1616 return; 1617 } 1618 } 1619 if (tif & (Qt::TextSelectableByKeyboard | Qt::TextEditable)) { 1620 if (e == QKeySequence::MoveToPreviousPage) { 1621 e->accept(); 1622 d->pageUpDown(QTextCursor::Up, QTextCursor::MoveAnchor); 1623 return; 1624 } else if (e == QKeySequence::MoveToNextPage) { 1625 e->accept(); 1626 d->pageUpDown(QTextCursor::Down, QTextCursor::MoveAnchor); 1627 return; 1628 } 1629 } 1630 1631 if (!(tif & Qt::TextEditable)) { 1555 1632 switch (e->key()) { 1556 1633 case Qt::Key_Space: … … 1578 1655 return; 1579 1656 } 1580 1581 #ifndef QT_NO_SHORTCUT1582 if (e == QKeySequence::MoveToPreviousPage) {1583 e->accept();1584 d->pageUpDown(QTextCursor::Up, QTextCursor::MoveAnchor);1585 return;1586 } else if (e == QKeySequence::MoveToNextPage) {1587 e->accept();1588 d->pageUpDown(QTextCursor::Down, QTextCursor::MoveAnchor);1589 return;1590 } else if (e == QKeySequence::SelectPreviousPage) {1591 e->accept();1592 d->pageUpDown(QTextCursor::Up, QTextCursor::KeepAnchor);1593 return;1594 } else if (e ==QKeySequence::SelectNextPage) {1595 e->accept();1596 d->pageUpDown(QTextCursor::Down, QTextCursor::KeepAnchor);1597 return;1598 }1599 1657 #endif // QT_NO_SHORTCUT 1600 1601 1658 1602 1659 d->sendControlEvent(e); … … 1609 1666 // Cursor position didn't change, so we want to leave 1610 1667 // these keys to change focus. 1668 e->ignore(); 1669 return; 1670 } 1671 break; 1672 case Qt::Key_Left: 1673 case Qt::Key_Right: 1674 if (QApplication::keypadNavigationEnabled() 1675 && QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) { 1676 // Same as for Key_Up and Key_Down. 1611 1677 e->ignore(); 1612 1678 return; … … 1711 1777 if (brush.style() >= Qt::LinearGradientPattern && brush.style() <= Qt::ConicalGradientPattern) { 1712 1778 if (!gradientRect.isNull()) { 1713 QTransform m; 1714 m.translate(gradientRect.left(), gradientRect.top()); 1779 QTransform m = QTransform::fromTranslate(gradientRect.left(), gradientRect.top()); 1715 1780 m.scale(gradientRect.width(), gradientRect.height()); 1716 1781 brush.setTransform(m); … … 1742 1807 QTextBlock block = firstVisibleBlock(); 1743 1808 qreal maximumWidth = document()->documentLayout()->documentSize().width(); 1744 1809 1810 // Set a brush origin so that the WaveUnderline knows where the wave started 1811 painter.setBrushOrigin(offset); 1812 1745 1813 // keep right margin clean from full-width selection 1746 1814 int maxX = offset.x() + qMax((qreal)viewportRect.width(), maximumWidth) … … 1906 1974 d->ensureCursorVisible(); 1907 1975 } 1976 1977 if (!isReadOnly() && rect().contains(e->pos())) 1978 d->handleSoftwareInputPanel(e->button(), d->clickCausedFocus); 1979 d->clickCausedFocus = 0; 1908 1980 } 1909 1981 … … 2006 2078 #endif 2007 2079 d->sendControlEvent(e); 2080 ensureCursorVisible(); 2008 2081 } 2009 2082 … … 2039 2112 { 2040 2113 Q_D(QPlainTextEdit); 2114 if (e->reason() == Qt::MouseFocusReason) { 2115 d->clickCausedFocus = 1; 2116 } 2041 2117 QAbstractScrollArea::focusInEvent(e); 2042 2118 d->sendControlEvent(e); … … 2305 2381 flags = Qt::TextEditorInteraction; 2306 2382 } 2307 setAttribute(Qt::WA_InputMethodEnabled, !ro);2383 setAttribute(Qt::WA_InputMethodEnabled, shouldEnableInputMethod(this)); 2308 2384 d->control->setTextInteractionFlags(flags); 2309 2385 } -
trunk/src/gui/widgets/qplaintextedit.h
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 ** … … 270 270 Q_PRIVATE_SLOT(d_func(), void _q_verticalScrollbarActionTriggered(int)) 271 271 Q_PRIVATE_SLOT(d_func(), void _q_cursorPositionChanged()) 272 272 273 friend class QPlainTextEditControl; 273 274 }; -
trunk/src/gui/widgets/qplaintextedit_p.h
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 ** … … 92 92 } 93 93 inline QRectF cursorRect() { return cursorRect(textCursor()); } 94 void ensureCursorVisible() { textEdit->ensureCursorVisible(); } 94 void ensureCursorVisible() { 95 textEdit->ensureCursorVisible(); 96 emit microFocusChanged(); 97 } 95 98 96 99 … … 149 152 uint centerOnScroll : 1; 150 153 uint inDrag : 1; 154 uint clickCausedFocus : 1; 151 155 152 156 int topLine; … … 172 176 173 177 void _q_cursorPositionChanged(); 178 void _q_modificationChanged(bool); 174 179 175 void _q_modificationChanged(bool);180 int originalOffsetY; 176 181 }; 177 182 -
trunk/src/gui/widgets/qprintpreviewwidget.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 ** … … 41 41 42 42 #include "qprintpreviewwidget.h" 43 #include "private/qwidget_p.h" 43 44 #include <private/qprinter_p.h> 44 45 … … 99 100 QRectF paperRect(0,0, paperSize.width(), paperSize.height()); 100 101 101 painter->setClipRect(paperRect & option->exposedRect); 102 painter->fillRect(paperRect, Qt::white); 103 if (!pagePicture) 104 return; 105 painter->drawPicture(pageRect.topLeft(), *pagePicture); 106 107 // Effect: make anything drawn in the margins look washed out. 108 QPainterPath path; 109 path.addRect(paperRect); 110 path.addRect(pageRect); 111 painter->setPen(QPen(Qt::NoPen)); 112 painter->setBrush(QColor(255, 255, 255, 180)); 113 painter->drawPath(path); 114 102 // Draw shadow 115 103 painter->setClipRect(option->exposedRect); 116 #if 0117 // Draw frame around paper.118 painter->setPen(QPen(Qt::black, 0));119 painter->setBrush(Qt::NoBrush);120 painter->drawRect(paperRect);121 #endif122 123 // Draw shadow124 104 qreal shWidth = paperRect.width()/100; 125 105 QRectF rshadow(paperRect.topRight() + QPointF(0, shWidth), … … 142 122 painter->fillRect(cshadow, QBrush(cgrad)); 143 123 124 painter->setClipRect(paperRect & option->exposedRect); 125 painter->fillRect(paperRect, Qt::white); 126 if (!pagePicture) 127 return; 128 painter->drawPicture(pageRect.topLeft(), *pagePicture); 129 130 // Effect: make anything drawn in the margins look washed out. 131 QPainterPath path; 132 path.addRect(paperRect); 133 path.addRect(pageRect); 134 painter->setPen(QPen(Qt::NoPen)); 135 painter->setBrush(QColor(255, 255, 255, 180)); 136 painter->drawPath(path); 137 138 #if 0 139 // Draw frame around paper. 140 painter->setPen(QPen(Qt::black, 0)); 141 painter->setBrush(Qt::NoBrush); 142 painter->drawRect(paperRect); 143 #endif 144 144 145 // todo: drawtext "Page N" below paper 145 146 } … … 171 172 } // anonymous namespace 172 173 173 class QPrintPreviewWidgetPrivate 174 class QPrintPreviewWidgetPrivate : public QWidgetPrivate 174 175 { 175 176 Q_DECLARE_PUBLIC(QPrintPreviewWidget) 176 177 public: 177 QPrintPreviewWidgetPrivate( QPrintPreviewWidget *q)178 : q_ptr(q),scene(0), curPage(1),178 QPrintPreviewWidgetPrivate() 179 : scene(0), curPage(1), 179 180 viewMode(QPrintPreviewWidget::SinglePageView), 180 181 zoomMode(QPrintPreviewWidget::FitInView), … … 195 196 int calcCurrentPage(); 196 197 197 QPrintPreviewWidget *q_ptr;198 198 GraphicsView *graphicsView; 199 199 QGraphicsScene *scene; … … 453 453 previewing page layouts for printer output. 454 454 455 \ingroup multimedia455 \ingroup printing 456 456 457 457 QPrintPreviewDialog uses a QPrintPreviewWidget internally, and the … … 519 519 */ 520 520 QPrintPreviewWidget::QPrintPreviewWidget(QPrinter *printer, QWidget *parent, Qt::WindowFlags flags) 521 : QWidget( parent, flags), d_ptr(new QPrintPreviewWidgetPrivate(this))521 : QWidget(*new QPrintPreviewWidgetPrivate, parent, flags) 522 522 { 523 523 Q_D(QPrintPreviewWidget); … … 535 535 */ 536 536 QPrintPreviewWidget::QPrintPreviewWidget(QWidget *parent, Qt::WindowFlags flags) 537 : QWidget( parent, flags), d_ptr(new QPrintPreviewWidgetPrivate(this))537 : QWidget(*new QPrintPreviewWidgetPrivate, parent, flags) 538 538 { 539 539 Q_D(QPrintPreviewWidget); … … 552 552 if (d->ownPrinter) 553 553 delete d->printer; 554 delete d_ptr;555 554 } 556 555 … … 665 664 666 665 /*! 666 \obsolete 667 667 Returns the number of pages in the preview. 668 \sa pageCount() 668 669 */ 669 670 int QPrintPreviewWidget::numPages() const 671 { 672 Q_D(const QPrintPreviewWidget); 673 return d->pages.size(); 674 } 675 676 /*! 677 \since 4.6 678 Returns the number of pages in the preview. 679 */ 680 int QPrintPreviewWidget::pageCount() const 670 681 { 671 682 Q_D(const QPrintPreviewWidget); -
trunk/src/gui/widgets/qprintpreviewwidget.h
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 ** … … 83 83 ZoomMode zoomMode() const; 84 84 int currentPage() const; 85 int numPages() const; 85 #ifdef QT_DEPRECATED 86 QT_DEPRECATED int numPages() const; 87 #endif 88 int pageCount() const; 86 89 void setVisible(bool visible); 87 90 … … 112 115 113 116 private: 114 QPrintPreviewWidgetPrivate *d_ptr;117 void *dummy; // ### remove in Qt 5.0 115 118 Q_PRIVATE_SLOT(d_func(), void _q_fit()) 116 119 Q_PRIVATE_SLOT(d_func(), void _q_updateCurrentPage()) -
trunk/src/gui/widgets/qprogressbar.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 ** … … 173 173 174 174 \ingroup basicwidgets 175 \mainclass 175 176 176 177 177 A progress bar is used to give the user an indication of the … … 191 191 beginning with reset(). 192 192 193 If minimum and maximum both are set to 0, the bar shows a busy indicator 194 instead of a percentage of steps. This is useful, for example, when using 195 QFtp or QHttp to download items when they are unable to determine the 196 size of the item being downloaded. 193 If minimum and maximum both are set to 0, the bar shows a busy 194 indicator instead of a percentage of steps. This is useful, for 195 example, when using QFtp or QNetworkAccessManager to download 196 items when they are unable to determine the size of the item being 197 downloaded. 197 198 198 199 \table … … 205 206 \endtable 206 207 207 \sa Q TimeLine, QProgressDialog, {fowler}{GUI Design Handbook: Progress Indicator}208 \sa QProgressDialog, {fowler}{GUI Design Handbook: Progress Indicator} 208 209 */ 209 210 … … 350 351 \brief whether the current completed percentage should be displayed 351 352 353 This property may be ignored by the style (e.g., QMacStyle never draws the text). 354 352 355 \sa textDirection 353 356 */ … … 442 445 { 443 446 Q_D(const QProgressBar); 444 if ( d->maximum == 0|| d->value < d->minimum447 if ((d->maximum == 0 && d->minimum == 0) || d->value < d->minimum 445 448 || (d->value == INT_MIN && d->minimum == INT_MIN)) 446 449 return QString(); 447 450 448 qint64 totalSteps = qint64(d->maximum) - qint64(d->minimum);451 qint64 totalSteps = qint64(d->maximum) - d->minimum; 449 452 450 453 QString result = d->format; 451 result.replace(QLatin1String("%m"), QString:: fromLatin1("%1").arg(totalSteps));452 result.replace(QLatin1String("%v"), QString:: fromLatin1("%1").arg(d->value));454 result.replace(QLatin1String("%m"), QString::number(totalSteps)); 455 result.replace(QLatin1String("%v"), QString::number(d->value)); 453 456 454 457 // If max and min are equal and we get this far, it means that the … … 456 459 // 100% here in order to avoid division by zero further down. 457 460 if (totalSteps == 0) { 458 result.replace(QLatin1String("%p"), QString:: fromLatin1("%1").arg(100));461 result.replace(QLatin1String("%p"), QString::number(100)); 459 462 return result; 460 463 } 461 464 462 int progress = int(((qreal(d->value) - qreal(d->minimum)) * 100.0) / totalSteps);463 result.replace(QLatin1String("%p"), QString:: fromLatin1("%1").arg(progress));465 int progress = (qreal(d->value) - d->minimum) * 100.0 / totalSteps; 466 result.replace(QLatin1String("%p"), QString::number(progress)); 464 467 return result; 465 468 } -
trunk/src/gui/widgets/qprogressbar.h
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 ** -
trunk/src/gui/widgets/qpushbutton.cpp
r306 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 ** … … 64 64 #endif 65 65 66 #include "private/qmenu_p.h" 66 67 #include "private/qpushbutton_p.h" 67 68 … … 74 75 75 76 \ingroup basicwidgets 76 \mainclass 77 77 78 78 79 The push button, or command button, is perhaps the most commonly … … 388 389 { 389 390 Q_D(const QPushButton); 390 if (d->sizeHint.isValid() )391 if (d->sizeHint.isValid() && d->lastAutoDefault == autoDefault()) 391 392 return d->sizeHint; 393 d->lastAutoDefault = autoDefault(); 392 394 ensurePolished(); 393 395 … … 528 530 529 531 if (menu && !d->menu) { 530 disconnect(this, SIGNAL(pressed()), this, SLOT(_q_popupPressed())); 531 connect(this, SIGNAL(pressed()), this, SLOT(_q_popupPressed())); 532 connect(this, SIGNAL(pressed()), this, SLOT(_q_popupPressed()), Qt::UniqueConnection); 532 533 } 533 534 if (d->menu) … … 576 577 577 578 menu->setNoReplayFor(q); 579 580 QPoint menuPos = adjustedMenuPosition(); 581 582 QPointer<QPushButton> guard(q); 583 QMenuPrivate::get(menu)->causedPopup.widget = guard; 584 585 //Because of a delay in menu effects, we must keep track of the 586 //menu visibility to avoid flicker on button release 587 menuOpen = true; 588 menu->exec(menuPos); 589 if (guard) { 590 menuOpen = false; 591 q->setDown(false); 592 } 593 } 594 595 QPoint QPushButtonPrivate::adjustedMenuPosition() 596 { 597 Q_Q(QPushButton); 598 578 599 bool horizontal = true; 579 600 #if !defined(QT_NO_TOOLBAR) 580 QToolBar *tb = qobject_cast<QToolBar*>( q->parentWidget());601 QToolBar *tb = qobject_cast<QToolBar*>(parent); 581 602 if (tb && tb->orientation() == Qt::Vertical) 582 603 horizontal = false; 583 604 #endif 605 584 606 QWidgetItem item(q); 585 607 QRect rect = item.geometry(); … … 591 613 int y = globalPos.y(); 592 614 if (horizontal) { 593 if (globalPos.y() + rect.height() + menuSize.height() <= qApp->desktop()->height()) {615 if (globalPos.y() + rect.height() + menuSize.height() <= QApplication::desktop()->availableGeometry(q).height()) { 594 616 y += rect.height(); 595 617 } else { … … 599 621 x += rect.width() - menuSize.width(); 600 622 } else { 601 if (globalPos.x() + rect.width() + menu->sizeHint().width() <= qApp->desktop()->width())623 if (globalPos.x() + rect.width() + menu->sizeHint().width() <= QApplication::desktop()->availableGeometry(q).width()) 602 624 x += rect.width(); 603 625 else 604 626 x -= menuSize.width(); 605 627 } 606 QPointer<QPushButton> guard(q); 607 608 //Because of a delay in menu effects, we must keep track of the 609 //menu visibility to avoid flicker on button release 610 menuOpen = true; 611 menu->exec(QPoint(x, y)); 612 if (guard) { 613 menuOpen = false; 614 // on some platforms (e.g. OS/2) QPushButton::focusOutEvent() may be called 615 // before we return from exec() above (for example, as a result of window 616 // deactivation). It will set down to false but since menuOpen won't be 617 // false yet, the button will be redrawn as sunken still. Simple setDown(false) 618 // won't do anything in this case so we need to call update() instead to make 619 // sure the button is redrawn as unsunken. 620 if (down) 621 q->setDown(false); 622 else 623 q->update(); 624 } 625 } 628 629 return QPoint(x,y); 630 } 631 626 632 #endif // QT_NO_MENU 627 633 … … 668 674 d->resetLayoutItemMargins(); 669 675 updateGeometry(); 676 } else if (e->type() == QEvent::PolishRequest) { 677 updateGeometry(); 670 678 } 671 679 return QAbstractButton::event(e); -
trunk/src/gui/widgets/qpushbutton.h
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 ** -
trunk/src/gui/widgets/qpushbutton_p.h
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 ** … … 66 66 QPushButtonPrivate() 67 67 : QAbstractButtonPrivate(QSizePolicy::PushButton), autoDefault(Auto), 68 defaultButton(false), flat(false), menuOpen(false) {}68 defaultButton(false), flat(false), menuOpen(false), lastAutoDefault(false) {} 69 69 70 70 inline void init() { resetLayoutItemMargins(); } 71 static QPushButtonPrivate* get(QPushButton *b) { return b->d_func(); } 72 #ifndef QT_NO_MENU 73 QPoint adjustedMenuPosition(); 74 #endif 71 75 void resetLayoutItemMargins(); 72 76 void _q_popupPressed(); … … 78 82 uint flat : 1; 79 83 uint menuOpen : 1; 84 mutable uint lastAutoDefault : 1; 80 85 }; 81 86 -
trunk/src/gui/widgets/qradiobutton.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 ** … … 81 81 82 82 \ingroup basicwidgets 83 \mainclass 83 84 84 85 85 A QRadioButton is an option button that can be switched on (checked) or -
trunk/src/gui/widgets/qradiobutton.h
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 ** -
trunk/src/gui/widgets/qrubberband.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 ** … … 98 98 \brief The QRubberBand class provides a rectangle or line that can 99 99 indicate a selection or a boundary. 100 101 \ingroup misc102 \mainclass103 100 104 101 A rubber band is often used to show a new bounding area (as in a -
trunk/src/gui/widgets/qrubberband.h
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 ** -
trunk/src/gui/widgets/qscrollarea.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 ** … … 62 62 63 63 \ingroup basicwidgets 64 \mainclass 64 65 65 66 66 A scroll area is used to display the contents of a child widget … … 128 128 property to one which provides constraints on the minimum and/or 129 129 maximum size of the layout (e.g., QLayout::SetMinAndMaxSize) will 130 cause the size of the thescroll area to be updated whenever the130 cause the size of the scroll area to be updated whenever the 131 131 contents of the layout changes. 132 132 -
trunk/src/gui/widgets/qscrollarea.h
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 ** -
trunk/src/gui/widgets/qscrollarea_p.h
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 ** -
trunk/src/gui/widgets/qscrollbar.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 ** … … 432 432 q->setAttribute(Qt::WA_WState_OwnSizePolicy, false); 433 433 q->setAttribute(Qt::WA_OpaquePaintEvent); 434 435 #if !defined(QT_NO_CONTEXTMENU) && defined(Q_WS_WINCE) 436 if (!q->style()->styleHint(QStyle::SH_ScrollBar_ContextMenu, 0, q)) { 437 q->setContextMenuPolicy(Qt::PreventContextMenu); 438 } 439 #endif 434 440 } 435 441 -
trunk/src/gui/widgets/qscrollbar.h
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 ** -
trunk/src/gui/widgets/qsizegrip.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 ** … … 100 100 Qt::Corner m_corner; 101 101 bool gotMousePress; 102 QWidget *tlw; 102 103 #ifdef Q_WS_MAC 103 104 void updateMacSizer(bool hide) const; … … 112 113 { 113 114 return m_corner == Qt::BottomLeftCorner || m_corner == Qt::TopLeftCorner; 115 } 116 117 void updateTopLevelWidget() 118 { 119 Q_Q(QSizeGrip); 120 QWidget *w = qt_sizegrip_topLevelWidget(q); 121 if (tlw == w) 122 return; 123 if (tlw) 124 tlw->removeEventFilter(q); 125 tlw = w; 126 if (tlw) 127 tlw->installEventFilter(q); 114 128 } 115 129 … … 122 136 Q_Q(QSizeGrip); 123 137 bool showSizeGrip = !(q->isHidden() && q->testAttribute(Qt::WA_WState_ExplicitShowHide)); 124 QWidget *tlw = qt_sizegrip_topLevelWidget(q);138 updateTopLevelWidget(); 125 139 if (tlw && showSizeGrip) { 126 140 Qt::WindowStates sizeGripNotVisibleState = Qt::WindowFullScreen; … … 140 154 { 141 155 Q_Q(const QSizeGrip); 142 if (QApplication::closingDown() || ! q->parentWidget())156 if (QApplication::closingDown() || !parent) 143 157 return; 144 158 QWidget *topLevelWindow = qt_sizegrip_topLevelWidget(const_cast<QSizeGrip *>(q)); … … 166 180 \brief The QSizeGrip class provides a resize handle for resizing top-level windows. 167 181 168 \ingroup application182 \ingroup mainwindow-classes 169 183 \ingroup basicwidgets 170 \ingroup appearance171 184 172 185 This widget works like the standard Windows resize handle. In the … … 234 247 dxMax = 0; 235 248 dyMax = 0; 249 tlw = 0; 236 250 m_corner = q->isLeftToRight() ? Qt::BottomRightCorner : Qt::BottomLeftCorner; 237 251 gotMousePress = false; … … 242 256 #endif 243 257 q->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed)); 244 QWidget *tlw = qt_sizegrip_topLevelWidget(q); 245 tlw->installEventFilter(q); 258 updateTopLevelWidget(); 246 259 } 247 260 … … 336 349 337 350 ReleaseCapture(); 338 QT_WA_INLINE(PostMessageW(tlw->winId(), WM_SYSCOMMAND, orientation, 0), 339 PostMessageA(tlw->winId(), WM_SYSCOMMAND, orientation, 0)); 351 PostMessage(tlw->winId(), WM_SYSCOMMAND, orientation, 0); 340 352 return; 341 353 } … … 527 539 bool QSizeGrip::eventFilter(QObject *o, QEvent *e) 528 540 { 541 Q_D(QSizeGrip); 529 542 if ((isHidden() && testAttribute(Qt::WA_WState_ExplicitShowHide)) 530 || e->type() != QEvent::WindowStateChange) { 543 || e->type() != QEvent::WindowStateChange 544 || o != d->tlw) { 531 545 return QWidget::eventFilter(o, e); 532 546 } 533 QWidget *tlw = qt_sizegrip_topLevelWidget(this);534 if (o != tlw)535 return QWidget::eventFilter(o, e);536 547 Qt::WindowStates sizeGripNotVisibleState = Qt::WindowFullScreen; 537 548 #ifndef Q_WS_MAC … … 539 550 #endif 540 551 // Don't show the size grip if the tlw is maximized or in full screen mode. 541 setVisible(!( tlw->windowState() & sizeGripNotVisibleState));552 setVisible(!(d->tlw->windowState() & sizeGripNotVisibleState)); 542 553 setAttribute(Qt::WA_WState_ExplicitShowHide, false); 543 554 return QWidget::eventFilter(o, e); -
trunk/src/gui/widgets/qsizegrip.h
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 ** -
trunk/src/gui/widgets/qslider.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 ** … … 63 63 QSlider::TickPosition tickPosition; 64 64 int clickOffset; 65 int snapBackPosition;66 65 void init(); 67 66 void resetLayoutItemMargins(); … … 205 204 206 205 \ingroup basicwidgets 207 \mainclass 206 208 207 209 208 The slider is the classic widget for controlling a bounded value. … … 494 493 QRect sr = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this); 495 494 d->clickOffset = d->pick(ev->pos() - sr.topLeft()); 496 d->snapBackPosition = d->position;497 495 update(sr); 498 496 setSliderDown(true); … … 514 512 QStyleOptionSlider opt; 515 513 initStyleOption(&opt); 516 int m = style()->pixelMetric(QStyle::PM_MaximumDragDistance, &opt, this);517 if (m >= 0) {518 QRect r = rect();519 r.adjust(-m, -m, m, m);520 if (!r.contains(ev->pos())) {521 newPosition = d->snapBackPosition;522 }523 }524 514 setSliderPosition(newPosition); 525 515 } -
trunk/src/gui/widgets/qslider.h
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 ** … … 115 115 inline QT3_SUPPORT TickPosition tickmarks() const { return tickPosition(); } 116 116 public Q_SLOTS: 117 inline QT_MOC_COMPAT void addStep() { triggerAction(SliderSingleStepAdd); } ;118 inline QT_MOC_COMPAT void subtractStep() { triggerAction(SliderSingleStepSub); } ;117 inline QT_MOC_COMPAT void addStep() { triggerAction(SliderSingleStepAdd); } 118 inline QT_MOC_COMPAT void subtractStep() { triggerAction(SliderSingleStepSub); } 119 119 #endif 120 120 -
trunk/src/gui/widgets/qspinbox.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 ** … … 51 51 52 52 #include <math.h> 53 #include <float.h> 53 54 54 55 QT_BEGIN_NAMESPACE … … 61 62 #endif 62 63 63 static bool isIntermediateValueHelper(qint64 num, qint64 minimum, qint64 maximum, qint64 *match = 0);64 65 64 class QSpinBoxPrivate : public QAbstractSpinBoxPrivate 66 65 { 67 66 Q_DECLARE_PUBLIC(QSpinBox) 68 67 public: 69 QSpinBoxPrivate( QWidget *parent = 0);68 QSpinBoxPrivate(); 70 69 void emitSignals(EmitPolicy ep, const QVariant &); 71 70 … … 74 73 QVariant validateAndInterpret(QString &input, int &pos, 75 74 QValidator::State &state) const; 76 bool isIntermediateValue(const QString &str) const;77 QChar thousand;78 75 79 76 inline void init() { 77 Q_Q(QSpinBox); 78 q->setInputMethodHints(Qt::ImhDigitsOnly); 80 79 setLayoutItemMargins(QStyle::SE_SpinBoxLayoutItem); 81 80 } … … 86 85 Q_DECLARE_PUBLIC(QDoubleSpinBox) 87 86 public: 88 QDoubleSpinBoxPrivate( QWidget *parent = 0);87 QDoubleSpinBoxPrivate(); 89 88 void emitSignals(EmitPolicy ep, const QVariant &); 90 bool isIntermediateValue(const QString &str) const;91 89 92 90 virtual QVariant valueFromText(const QString &n) const; … … 97 95 // variables 98 96 int decimals; 99 QChar delimiter, thousand; 97 98 inline void init() { 99 Q_Q(QDoubleSpinBox); 100 q->setInputMethodHints(Qt::ImhFormattedNumbersOnly); 101 } 100 102 }; 101 103 … … 106 108 107 109 \ingroup basicwidgets 108 \mainclass 110 109 111 110 112 QSpinBox is designed to handle integers and discrete sets of … … 198 200 199 201 QSpinBox::QSpinBox(QWidget *parent) 200 : QAbstractSpinBox(*new QSpinBoxPrivate (parent), parent)202 : QAbstractSpinBox(*new QSpinBoxPrivate, parent) 201 203 { 202 204 Q_D(QSpinBox); … … 210 212 */ 211 213 QSpinBox::QSpinBox(QWidget *parent, const char *name) 212 : QAbstractSpinBox(*new QSpinBoxPrivate (parent), parent)214 : QAbstractSpinBox(*new QSpinBoxPrivate, parent) 213 215 { 214 216 Q_D(QSpinBox); … … 222 224 */ 223 225 QSpinBox::QSpinBox(int minimum, int maximum, int step, QWidget *parent, const char *name) 224 : QAbstractSpinBox(*new QSpinBoxPrivate (parent), parent)226 : QAbstractSpinBox(*new QSpinBoxPrivate, parent) 225 227 { 226 228 Q_D(QSpinBox); … … 285 287 d->prefix = prefix; 286 288 d->updateEdit(); 289 290 d->cachedSizeHint = QSize(); 291 updateGeometry(); 287 292 } 288 293 … … 319 324 d->suffix = suffix; 320 325 d->updateEdit(); 326 327 d->cachedSizeHint = QSize(); 328 updateGeometry(); 321 329 } 322 330 … … 455 463 QString QSpinBox::textFromValue(int value) const 456 464 { 457 Q_D(const QSpinBox);458 465 QString str = locale().toString(value); 459 466 if (qAbs(value) >= 1000 || value == INT_MIN) { 460 str.remove( d->thousand);467 str.remove(locale().groupSeparator()); 461 468 } 462 469 … … 507 514 void QSpinBox::fixup(QString &input) const 508 515 { 509 Q_D(const QSpinBox); 510 511 input.remove(d->thousand); 516 input.remove(locale().groupSeparator()); 512 517 } 513 518 … … 521 526 522 527 \ingroup basicwidgets 523 \mainclass 528 524 529 525 530 QDoubleSpinBox allows the user to choose a value by clicking the … … 591 596 */ 592 597 QDoubleSpinBox::QDoubleSpinBox(QWidget *parent) 593 : QAbstractSpinBox(*new QDoubleSpinBoxPrivate(parent), parent) 594 { 598 : QAbstractSpinBox(*new QDoubleSpinBoxPrivate, parent) 599 { 600 Q_D(QDoubleSpinBox); 601 d->init(); 595 602 } 596 603 … … 818 825 interpreting doubles. 819 826 820 \warning The results might not be reliable with very high values821 for \a decimals.827 \warning The maximum value for \a decimals is DBL_MAX_10_EXP + 828 DBL_DIG (ie. 323) because of the limitations of the double type. 822 829 823 830 Note: The maximum, minimum and value might change as a result of … … 835 842 { 836 843 Q_D(QDoubleSpinBox); 837 d->decimals = q Max(0, decimals);844 d->decimals = qBound(0, decimals, DBL_MAX_10_EXP + DBL_DIG); 838 845 839 846 setRange(minimum(), maximum()); // make sure values are rounded … … 864 871 QString str = locale().toString(value, 'f', d->decimals); 865 872 if (qAbs(value) >= 1000.0) { 866 str.remove( d->thousand);873 str.remove(locale().groupSeparator()); 867 874 } 868 875 return str; … … 909 916 void QDoubleSpinBox::fixup(QString &input) const 910 917 { 911 Q_D(const QDoubleSpinBox); 912 913 input.remove(d->thousand); 918 input.remove(locale().groupSeparator()); 914 919 } 915 920 … … 921 926 */ 922 927 923 QSpinBoxPrivate::QSpinBoxPrivate( QWidget *parent)928 QSpinBoxPrivate::QSpinBoxPrivate() 924 929 { 925 930 minimum = QVariant((int)0); … … 928 933 singleStep = QVariant((int)1); 929 934 type = QVariant::Int; 930 const QString str = (parent ? parent->locale() : QLocale()).toString(4567);931 if (str.size() == 5) {932 thousand = QChar(str.at(1));933 }934 935 935 } 936 936 … … 976 976 977 977 /*! 978 \internal979 980 Return true if str can become a number which is between minimum and981 maximum or false if this is not possible.982 */983 984 bool QSpinBoxPrivate::isIntermediateValue(const QString &str) const985 {986 const int num = q_func()->locale().toInt(str, 0, 10);987 const int min = minimum.toInt();988 const int max = maximum.toInt();989 990 int numDigits = 0;991 int digits[10];992 int tmp = num;993 if (tmp == 0) {994 numDigits = 1;995 digits[0] = 0;996 } else {997 tmp = num;998 for (int i=0; tmp != 0; ++i) {999 digits[numDigits++] = qAbs(tmp % 10);1000 tmp /= 10;1001 }1002 }1003 1004 int failures = 0;1005 for (int number=min; /*number<=max*/; ++number) {1006 tmp = number;1007 for (int i=0; tmp != 0;) {1008 if (digits[i] == qAbs(tmp % 10)) {1009 if (++i == numDigits)1010 return true;1011 }1012 tmp /= 10;1013 }1014 if (failures++ == 500000) //upper bound1015 return true;1016 if (number == max) // needed for INT_MAX1017 break;1018 }1019 return false;1020 }1021 1022 /*!1023 978 \internal Multi purpose function that parses input, sets state to 1024 979 the appropriate state and returns the value it will be interpreted … … 1031 986 if (cachedText == input && !input.isEmpty()) { 1032 987 state = cachedState; 1033 QSBDEBUG() << "cachedText was " << "'" << cachedText << "'" << "state was "988 QSBDEBUG() << "cachedText was '" << cachedText << "' state was " 1034 989 << state << " and value was " << cachedValue; 1035 990 … … 1049 1004 state = QValidator::Intermediate; 1050 1005 QSBDEBUG() << __FILE__ << __LINE__<< "num is set to" << num; 1051 } else if (copy.startsWith(QLatin1 String("-")) && min >= 0) {1006 } else if (copy.startsWith(QLatin1Char('-')) && min >= 0) { 1052 1007 state = QValidator::Invalid; // special-case -0 will be interpreted as 0 and thus not be invalid with a range from 0-100 1053 1008 } else { 1054 1009 bool ok = false; 1055 bool removedThousand = false; 1056 num = q_func()->locale().toInt(copy, &ok, 10); 1057 if (!ok && copy.contains(thousand) && (max >= 1000 || min <= -1000)) { 1058 const int s = copy.size(); 1059 copy.remove(thousand); 1060 pos = qMax(0, pos - (s - copy.size())); 1061 removedThousand = true; 1062 num = q_func()->locale().toInt(copy, &ok, 10); 1010 num = locale.toInt(copy, &ok, 10); 1011 if (!ok && copy.contains(locale.groupSeparator()) && (max >= 1000 || min <= -1000)) { 1012 QString copy2 = copy; 1013 copy2.remove(locale.groupSeparator()); 1014 num = locale.toInt(copy2, &ok, 10); 1063 1015 } 1064 1016 QSBDEBUG() << __FILE__ << __LINE__<< "num is set to" << num; … … 1066 1018 state = QValidator::Invalid; 1067 1019 } else if (num >= min && num <= max) { 1068 state = removedThousand ? QValidator::Intermediate :QValidator::Acceptable;1020 state = QValidator::Acceptable; 1069 1021 } else if (max == min) { 1070 1022 state = QValidator::Invalid; … … 1074 1026 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid"; 1075 1027 } else { 1076 state = isIntermediateValue(copy) ? QValidator::Intermediate : QValidator::Invalid; 1077 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to " 1078 << (state == QValidator::Intermediate ? "Intermediate" : "Acceptable"); 1028 state = QValidator::Intermediate; 1029 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Intermediate"; 1079 1030 } 1080 1031 } … … 1099 1050 */ 1100 1051 1101 QDoubleSpinBoxPrivate::QDoubleSpinBoxPrivate( QWidget *parent)1052 QDoubleSpinBoxPrivate::QDoubleSpinBoxPrivate() 1102 1053 { 1103 1054 minimum = QVariant(0.0); … … 1107 1058 decimals = 2; 1108 1059 type = QVariant::Double; 1109 const QString str = (parent ? parent->locale() : QLocale()).toString(4567.1);1110 if (str.size() == 6) {1111 delimiter = str.at(4);1112 thousand = QChar((ushort)0);1113 } else if (str.size() == 7) {1114 thousand = str.at(1);1115 delimiter = str.at(5);1116 }1117 Q_ASSERT(!delimiter.isNull());1118 1060 } 1119 1061 … … 1136 1078 1137 1079 1138 bool QDoubleSpinBoxPrivate::isIntermediateValue(const QString &str) const1139 {1140 QSBDEBUG() << "input is" << str << minimum << maximum;1141 qint64 dec = 1;1142 for (int i=0; i<decimals; ++i)1143 dec *= 10;1144 1145 const QLatin1Char dot('.');1146 1147 // I know QString::number() uses CLocale so I use dot1148 const QString minstr = QString::number(minimum.toDouble(), 'f', decimals);1149 bool ok;1150 qint64 min_left = minstr.left(minstr.indexOf(dot)).toLongLong(&ok);1151 if (!ok)1152 return false;1153 qint64 min_right = minstr.mid(minstr.indexOf(dot) + 1).toLongLong();1154 1155 const QString maxstr = QString::number(maximum.toDouble(), 'f', decimals);1156 qint64 max_left = maxstr.left(maxstr.indexOf(dot)).toLongLong(&ok);1157 if (!ok)1158 return true;1159 qint64 max_right = maxstr.mid(maxstr.indexOf(dot) + 1).toLongLong();1160 1161 const int dotindex = str.indexOf(delimiter);1162 const bool negative = maximum.toDouble() < 0;1163 qint64 left = 0, right = 0;1164 bool doleft = true;1165 bool doright = true;1166 if (dotindex == -1) {1167 left = str.toLongLong();1168 doright = false;1169 } else if (dotindex == 0 || (dotindex == 1 && str.at(0) == QLatin1Char('+'))) {1170 if (negative) {1171 QSBDEBUG() << __FILE__ << __LINE__ << "returns false";1172 return false;1173 }1174 doleft = false;1175 right = str.mid(dotindex + 1).toLongLong();1176 } else if (dotindex == 1 && str.at(0) == QLatin1Char('-')) {1177 if (!negative) {1178 QSBDEBUG() << __FILE__ << __LINE__ << "returns false";1179 return false;1180 }1181 doleft = false;1182 right = str.mid(dotindex + 1).toLongLong();1183 } else {1184 left = str.left(dotindex).toLongLong();1185 if (dotindex == str.size() - 1) {1186 doright = false;1187 } else {1188 right = str.mid(dotindex + 1).toLongLong();1189 }1190 }1191 if ((left >= 0 && max_left < 0 && !str.startsWith(QLatin1Char('-'))) || (left < 0 && min_left >= 0)) {1192 QSBDEBUG("returns false 0");1193 return false;1194 }1195 1196 qint64 match = min_left;1197 if (doleft && !isIntermediateValueHelper(left, min_left, max_left, &match)) {1198 QSBDEBUG() << __FILE__ << __LINE__ << "returns false";1199 return false;1200 }1201 if (doright) {1202 QSBDEBUG("match %lld min_left %lld max_left %lld", match, min_left, max_left);1203 if (!doleft) {1204 if (min_left == max_left) {1205 const bool ret = isIntermediateValueHelper(qAbs(left),1206 negative ? max_right : min_right,1207 negative ? min_right : max_right);1208 QSBDEBUG() << __FILE__ << __LINE__ << "returns" << ret;1209 return ret;1210 } else if (qAbs(max_left - min_left) == 1) {1211 const bool ret = isIntermediateValueHelper(qAbs(left), min_right, negative ? 0 : dec)1212 || isIntermediateValueHelper(qAbs(left), negative ? dec : 0, max_right);1213 QSBDEBUG() << __FILE__ << __LINE__ << "returns" << ret;1214 return ret;1215 } else {1216 const bool ret = isIntermediateValueHelper(qAbs(left), 0, dec);1217 QSBDEBUG() << __FILE__ << __LINE__ << "returns" << ret;1218 return ret;1219 }1220 }1221 if (match != min_left) {1222 min_right = negative ? dec : 0;1223 }1224 if (match != max_left) {1225 max_right = negative ? 0 : dec;1226 }1227 qint64 tmpl = negative ? max_right : min_right;1228 qint64 tmpr = negative ? min_right : max_right;1229 const bool ret = isIntermediateValueHelper(right, tmpl, tmpr);1230 QSBDEBUG() << __FILE__ << __LINE__ << "returns" << ret;1231 return ret;1232 }1233 QSBDEBUG() << __FILE__ << __LINE__ << "returns true";1234 return true;1235 }1236 1237 1080 /*! 1238 1081 \internal … … 1255 1098 double QDoubleSpinBoxPrivate::round(double value) const 1256 1099 { 1257 Q_Q(const QDoubleSpinBox); 1258 const QString strDbl = q->locale().toString(value, 'f', decimals); 1259 return q->locale().toDouble(strDbl); 1100 return QString::number(value, 'f', decimals).toDouble(); 1260 1101 } 1261 1102 … … 1272 1113 if (cachedText == input && !input.isEmpty()) { 1273 1114 state = cachedState; 1274 QSBDEBUG() << "cachedText was " << "'" << cachedText << "'" << "state was "1115 QSBDEBUG() << "cachedText was '" << cachedText << "' state was " 1275 1116 << state << " and value was " << cachedValue; 1276 1117 return cachedValue; … … 1291 1132 goto end; 1292 1133 case 1: 1293 if (copy.at(0) == delimiter1134 if (copy.at(0) == locale.decimalPoint() 1294 1135 || (plus && copy.at(0) == QLatin1Char('+')) 1295 1136 || (minus && copy.at(0) == QLatin1Char('-'))) { … … 1299 1140 break; 1300 1141 case 2: 1301 if (copy.at(1) == delimiter1142 if (copy.at(1) == locale.decimalPoint() 1302 1143 && ((plus && copy.at(0) == QLatin1Char('+')) || (minus && copy.at(0) == QLatin1Char('-')))) { 1303 1144 state = QValidator::Intermediate; … … 1308 1149 } 1309 1150 1310 if (copy.at(0) == thousand) {1151 if (copy.at(0) == locale.groupSeparator()) { 1311 1152 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid"; 1312 1153 state = QValidator::Invalid; 1313 1154 goto end; 1314 1155 } else if (len > 1) { 1315 const int dec = copy.indexOf( delimiter);1156 const int dec = copy.indexOf(locale.decimalPoint()); 1316 1157 if (dec != -1) { 1317 if (dec + 1 < copy.size() && copy.at(dec + 1) == delimiter&& pos == dec + 1) {1158 if (dec + 1 < copy.size() && copy.at(dec + 1) == locale.decimalPoint() && pos == dec + 1) { 1318 1159 copy.remove(dec + 1, 1); // typing a delimiter when you are on the delimiter 1319 1160 } // should be treated as typing right arrow … … 1325 1166 } 1326 1167 for (int i=dec + 1; i<copy.size(); ++i) { 1327 if (copy.at(i).isSpace() || copy.at(i) == thousand) {1168 if (copy.at(i).isSpace() || copy.at(i) == locale.groupSeparator()) { 1328 1169 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid"; 1329 1170 state = QValidator::Invalid; … … 1334 1175 const QChar &last = copy.at(len - 1); 1335 1176 const QChar &secondLast = copy.at(len - 2); 1336 if ((last == thousand|| last.isSpace())1337 && (secondLast == thousand|| secondLast.isSpace())) {1177 if ((last == locale.groupSeparator() || last.isSpace()) 1178 && (secondLast == locale.groupSeparator() || secondLast.isSpace())) { 1338 1179 state = QValidator::Invalid; 1339 1180 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid"; 1340 1181 goto end; 1341 } else if (last.isSpace() && (! thousand.isSpace() || secondLast.isSpace())) {1182 } else if (last.isSpace() && (!locale.groupSeparator().isSpace() || secondLast.isSpace())) { 1342 1183 state = QValidator::Invalid; 1343 1184 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid"; … … 1349 1190 { 1350 1191 bool ok = false; 1351 QLocale loc(q_func()->locale()); 1352 num = loc.toDouble(copy, &ok); 1353 QSBDEBUG() << __FILE__ << __LINE__ << loc << copy << num << ok; 1354 bool notAcceptable = false; 1192 num = locale.toDouble(copy, &ok); 1193 QSBDEBUG() << __FILE__ << __LINE__ << locale << copy << num << ok; 1355 1194 1356 1195 if (!ok) { 1357 if ( thousand.isPrint()) {1358 if (max < 1000 && min > -1000 && copy.contains( thousand)) {1196 if (locale.groupSeparator().isPrint()) { 1197 if (max < 1000 && min > -1000 && copy.contains(locale.groupSeparator())) { 1359 1198 state = QValidator::Invalid; 1360 1199 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid"; … … 1364 1203 const int len = copy.size(); 1365 1204 for (int i=0; i<len- 1; ++i) { 1366 if (copy.at(i) == thousand && copy.at(i + 1) == thousand) {1205 if (copy.at(i) == locale.groupSeparator() && copy.at(i + 1) == locale.groupSeparator()) { 1367 1206 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid"; 1368 1207 state = QValidator::Invalid; … … 1371 1210 } 1372 1211 1373 const int s = copy.size(); 1374 copy.remove(thousand); 1375 pos = qMax(0, pos - (s - copy.size())); 1376 1377 1378 num = loc.toDouble(copy, &ok); 1379 QSBDEBUG() << thousand << num << copy << ok; 1212 QString copy2 = copy; 1213 copy2.remove(locale.groupSeparator()); 1214 num = locale.toDouble(copy2, &ok); 1215 QSBDEBUG() << locale.groupSeparator() << num << copy2 << ok; 1380 1216 1381 1217 if (!ok) { … … 1384 1220 goto end; 1385 1221 } 1386 notAcceptable = true;1387 1222 } 1388 1223 } … … 1392 1227 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid"; 1393 1228 } else if (num >= min && num <= max) { 1394 state = notAcceptable ? QValidator::Intermediate : QValidator::Acceptable; 1395 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to " 1396 << (state == QValidator::Intermediate ? "Intermediate" : "Acceptable"); 1229 state = QValidator::Acceptable; 1230 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Acceptable"; 1397 1231 } else if (max == min) { // when max and min is the same the only non-Invalid input is max (or min) 1398 1232 state = QValidator::Invalid; … … 1403 1237 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid"; 1404 1238 } else { 1405 state = isIntermediateValue(copy) ? QValidator::Intermediate : QValidator::Invalid; 1406 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to " 1407 << (state == QValidator::Intermediate ? "Intermediate" : "Acceptable"); 1239 state = QValidator::Intermediate; 1240 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Intermediate"; 1408 1241 } 1409 1242 } … … 1462 1295 Use minimum() instead. 1463 1296 */ 1464 1465 /*!1466 \internal Returns whether \a str is a string which value cannot be1467 parsed but still might turn into something valid.1468 */1469 1470 static bool isIntermediateValueHelper(qint64 num, qint64 min, qint64 max, qint64 *match)1471 {1472 QSBDEBUG("%lld %lld %lld", num, min, max);1473 1474 if (num >= min && num <= max) {1475 if (match)1476 *match = num;1477 QSBDEBUG("returns true 0");1478 return true;1479 }1480 qint64 tmp = num;1481 1482 int numDigits = 0;1483 int digits[10];1484 if (tmp == 0) {1485 numDigits = 1;1486 digits[0] = 0;1487 } else {1488 tmp = qAbs(num);1489 for (int i=0; tmp > 0; ++i) {1490 digits[numDigits++] = tmp % 10;1491 tmp /= 10;1492 }1493 }1494 1495 int failures = 0;1496 qint64 number;1497 for (number=max; number>=min; --number) {1498 tmp = qAbs(number);1499 for (int i=0; tmp > 0;) {1500 if (digits[i] == (tmp % 10)) {1501 if (++i == numDigits) {1502 if (match)1503 *match = number;1504 QSBDEBUG("returns true 1");1505 return true;1506 }1507 }1508 tmp /= 10;1509 }1510 if (failures++ == 500000) { //upper bound1511 if (match)1512 *match = num;1513 QSBDEBUG("returns true 2");1514 return true;1515 }1516 }1517 QSBDEBUG("returns false");1518 return false;1519 }1520 1297 1521 1298 /*! \reimp */ -
trunk/src/gui/widgets/qspinbox.h
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 ** -
trunk/src/gui/widgets/qsplashscreen.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 ** … … 72 72 \brief The QSplashScreen widget provides a splash screen that can 73 73 be shown during application startup. 74 75 \ingroup misc76 \mainclass77 74 78 75 A splash screen is a widget that is usually displayed when an -
trunk/src/gui/widgets/qsplashscreen.h
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 ** -
trunk/src/gui/widgets/qsplitter.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 ** … … 120 120 Q_D(QSplitterHandle); 121 121 d->s = parent; 122 d->hover = false;123 122 setOrientation(orientation); 124 123 } … … 270 269 { 271 270 Q_D(QSplitterHandle); 272 if (e->button() == Qt::LeftButton) 271 if (e->button() == Qt::LeftButton) { 273 272 d->mouseOffset = d->pick(e->pos()); 273 d->pressed = true; 274 update(); 275 } 274 276 } 275 277 … … 285 287 d->s->setRubberBand(-1); 286 288 moveSplitter(pos); 289 } 290 if (e->button() == Qt::LeftButton) { 291 d->pressed = false; 292 update(); 287 293 } 288 294 } … … 304 310 if (d->hover) 305 311 opt.state |= QStyle::State_MouseOver; 312 if (d->pressed) 313 opt.state |= QStyle::State_Sunken; 306 314 if (isEnabled()) 307 315 opt.state |= QStyle::State_Enabled; … … 353 361 */ 354 362 bool first = true; 363 bool allInvisible = n != 0; 355 364 for (int i = 0; i < n ; ++i) { 356 365 QSplitterLayoutStruct *s = list.at(i); 357 s->handle->setHidden(first || s->widget->isHidden()); 358 if (!s->widget->isHidden()) 366 bool widgetHidden = s->widget->isHidden(); 367 if (allInvisible && !widgetHidden && !s->collapsed) 368 allInvisible = false; 369 s->handle->setHidden(first || widgetHidden); 370 if (!widgetHidden) 359 371 first = false; 360 372 } 373 374 if (allInvisible) 375 for (int i = 0; i < n ; ++i) { 376 QSplitterLayoutStruct *s = list.at(i); 377 if (!s->widget->isHidden()) { 378 s->collapsed = false; 379 break; 380 } 381 } 361 382 362 383 int fi = 2 * q->frameWidth(); … … 390 411 391 412 if (empty) { 392 if (qobject_cast<QSplitter *>( q->parentWidget())) {413 if (qobject_cast<QSplitter *>(parent)) { 393 414 // nested splitters; be nice 394 415 maxl = maxt = 0; … … 924 945 925 946 \ingroup organizers 926 \mainclass 947 927 948 928 949 A splitter lets the user control the size of child widgets by dragging the … … 1518 1539 /*! 1519 1540 \fn int QSplitter::margin() const 1520 Returns the wi th of thethe margin around the contents of the widget.1541 Returns the width of the margin around the contents of the widget. 1521 1542 1522 1543 Use QWidget::getContentsMargins() instead. -
trunk/src/gui/widgets/qsplitter.h
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 ** -
trunk/src/gui/widgets/qsplitter_p.h
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 ** … … 132 132 Q_DECLARE_PUBLIC(QSplitterHandle) 133 133 public: 134 QSplitterHandlePrivate() : orient(Qt::Horizontal), opaq(false), s(0), mouseOffset(0) {}134 QSplitterHandlePrivate() : s(0), orient(Qt::Horizontal), mouseOffset(0), opaq(false), hover(false), pressed(false) {} 135 135 136 136 inline int pick(const QPoint &pos) const 137 137 { return orient == Qt::Horizontal ? pos.x() : pos.y(); } 138 138 139 QSplitter *s; 139 140 Qt::Orientation orient; 140 bool opaq;141 QSplitter *s;142 bool hover;143 141 int mouseOffset; 142 bool opaq : 1; 143 bool hover : 1; 144 bool pressed : 1; 144 145 }; 145 146 -
trunk/src/gui/widgets/qstackedwidget.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 ** … … 66 66 \ingroup organizers 67 67 \ingroup geomanagement 68 \ingroup appearance 69 \mainclass 68 70 69 71 70 QStackedWidget can be used to create a user interface similar to -
trunk/src/gui/widgets/qstackedwidget.h
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 ** -
trunk/src/gui/widgets/qstatusbar.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 ** … … 145 145 left = qMax(left, item->w->x() + item->w->width() + 2); 146 146 else 147 right = qMin(right, item->w->x() -1);147 right = qMin(right, item->w->x() - 2); 148 148 } 149 149 break; … … 159 159 presenting status information. 160 160 161 \ingroup application161 \ingroup mainwindow-classes 162 162 \ingroup helpsystem 163 \mainclass 163 164 164 165 165 Each status indicator falls into one of three categories: … … 729 729 if (item && item->w->isVisible() && (!haveMessage || item->p)) { 730 730 QRect ir = item->w->geometry().adjusted(-2, -1, 2, 1); 731 if (event->rect(). contains(ir)) {731 if (event->rect().intersects(ir)) { 732 732 QStyleOption opt(0); 733 733 opt.rect = ir; -
trunk/src/gui/widgets/qstatusbar.h
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 ** -
trunk/src/gui/widgets/qtabbar.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 ** … … 88 88 // TODO: test tab bar position 89 89 90 // push the black line at the bottom of the menu bar down to the client are so we can paint over it 90 OSWindowRef window = qt_mac_window_for(q); 91 92 // push base line separator down to the client are so we can paint over it (Carbon) 91 93 metrics.top = (documentMode && q->isVisible()) ? 1 : 0; 92 94 metrics.bottom = 0; 93 95 metrics.left = 0; 94 96 metrics.right = 0; 95 96 qt_mac_updateContentBorderMetricts(qt_mac_window_for(q), metrics); 97 qt_mac_updateContentBorderMetricts(window, metrics); 98 99 // hide the base line separator if the tabs have docuemnt mode enabled (Cocoa) 100 qt_mac_showBaseLineSeparator(window, !documentMode); 97 101 } 98 102 #endif … … 132 136 if (isActiveWindow()) 133 137 option->state |= QStyle::State_Active; 134 if ( option->rect == d->hoverRect)138 if (!d->dragInProgress && option->rect == d->hoverRect) 135 139 option->state |= QStyle::State_MouseOver; 136 140 option->shape = d->shape; … … 177 181 option->cornerWidgets |= QStyleOptionTab::RightCornerWidget; 178 182 } 183 #endif 179 184 180 185 QRect textRect = style()->subElementRect(QStyle::SE_TabBarTabText, option, this); 181 182 186 option->text = fontMetrics().elidedText(option->text, d->elideMode, textRect.width(), 183 187 Qt::TextShowMnemonic); 184 #endif185 188 } 186 189 … … 190 193 191 194 \ingroup basicwidgets 192 \mainclass 195 193 196 194 197 QTabBar is straightforward to use; it draws the tabs using one of … … 455 458 } 456 459 457 if (pressedIndex != -1 && movable)458 grabCache(0, tabList.count(), true);459 460 460 Q_ASSERT(tabChainIndex == tabChain.count() - 1); // add an assert just to make sure. 461 461 // Mirror our front item. … … 668 668 && movable 669 669 && QApplication::mouseButtons() == Qt::NoButton) { 670 _q_moveTabFinished(pressedIndex);670 moveTabFinished(pressedIndex); 671 671 if (!validIndex(pressedIndex)) 672 672 pressedIndex = -1; … … 1089 1089 1090 1090 /*! 1091 Returns the data dof the tab at position \a index, or a null1091 Returns the data of the tab at position \a index, or a null 1092 1092 variant if \a index is out of range. 1093 1093 */ … … 1101 1101 1102 1102 /*! 1103 Returns the visual rectangle of the of thetab at position \a1103 Returns the visual rectangle of the tab at position \a 1104 1104 index, or a null rectangle if \a index is out of range. 1105 1105 */ … … 1171 1171 update(); 1172 1172 d->makeVisible(index); 1173 d->tabList[index].lastTab = oldIndex; 1174 d->layoutWidgets(oldIndex); 1175 d->layoutWidgets(index); 1173 1176 #ifdef QT3_SUPPORT 1174 1177 emit selected(index); 1175 1178 #endif 1176 1179 emit currentChanged(index); 1177 d->tabList[index].lastTab = oldIndex;1178 d->layoutWidgets(oldIndex);1179 d->layoutWidgets(index);1180 1180 } 1181 1181 } … … 1294 1294 QSize QTabBar::tabSizeHint(int index) const 1295 1295 { 1296 //Note: this must match with the computations in QCommonStylePrivate::tabLayout 1296 1297 Q_D(const QTabBar); 1297 1298 if (const QTabBarPrivate::Tab *tab = d->at(index)) { … … 1310 1311 int widgetHeight = 0; 1311 1312 int padding = 0; 1312 if ( opt.leftButtonSize.isValid()) {1313 padding += 6 + 2;1313 if (!opt.leftButtonSize.isEmpty()) { 1314 padding += 4; 1314 1315 widgetWidth += opt.leftButtonSize.width(); 1315 1316 widgetHeight += opt.leftButtonSize.height(); 1316 1317 } 1317 if ( opt.rightButtonSize.isValid()) {1318 padding += 6 + 2;1318 if (!opt.rightButtonSize.isEmpty()) { 1319 padding += 4; 1319 1320 widgetWidth += opt.rightButtonSize.width(); 1320 1321 widgetHeight += opt.rightButtonSize.height(); 1321 1322 } 1322 if ( opt.iconSize.isValid())1323 padding += 2;1323 if (!opt.icon.isNull()) 1324 padding += 4; 1324 1325 1325 1326 QSize csz; … … 1485 1486 QStyleOptionTab cutTab; 1486 1487 selected = d->currentIndex; 1488 if (d->dragInProgress) 1489 selected = d->pressedIndex; 1487 1490 1488 1491 for (int i = 0; i < d->tabList.count(); ++i) … … 1523 1526 continue; 1524 1527 1525 if (!d->tabList[i].animatingCache.isNull() && d->paintWithOffsets) { 1526 p.drawPixmap(tab.rect, d->tabList[i].animatingCache); 1527 } else { 1528 p.drawControl(QStyle::CE_TabBarTab, tab); 1529 } 1528 p.drawControl(QStyle::CE_TabBarTab, tab); 1530 1529 } 1531 1530 … … 1540 1539 tab.rect.moveLeft(tab.rect.x() + d->tabList[selected].dragOffset); 1541 1540 } 1542 p.drawControl(QStyle::CE_TabBarTab, tab); 1541 if (!d->dragInProgress) 1542 p.drawControl(QStyle::CE_TabBarTab, tab); 1543 else { 1544 int taboverlap = style()->pixelMetric(QStyle::PM_TabBarTabOverlap, 0, this); 1545 d->movingTab->setGeometry(tab.rect.adjusted(-taboverlap, 0, taboverlap, 0)); 1546 } 1543 1547 } 1544 1548 … … 1664 1668 int postLocation = vertical ? q->tabRect(to).y() : q->tabRect(to).x(); 1665 1669 int length = postLocation - preLocation; 1666 tabList[to].makeTimeLine(q); 1667 tabList[to].dragOffset += -1 * length; 1668 tabList[to].timeLine->setFrameRange(tabList[to].dragOffset, 0); 1669 animations[tabList[to].timeLine] = to; 1670 tabList[to].timeLine->setDuration(ANIMATION_DURATION); 1671 if (tabList[to].timeLine->state() != QTimeLine::Running) 1672 tabList[to].timeLine->start(); 1673 } 1674 1675 void QTabBarPrivate::_q_moveTab(int offset) 1676 { 1677 Q_Q(QTabBar); 1678 if (QTimeLine *timeLine = qobject_cast<QTimeLine *>(q->sender())) { 1679 int index = animations[timeLine]; 1680 if (!validIndex(index)) 1681 return; 1682 tabList[index].dragOffset = offset; 1683 q->update(); 1684 } 1670 tabList[to].dragOffset -= length; 1671 tabList[to].startAnimation(this, ANIMATION_DURATION); 1672 } 1673 1674 void QTabBarPrivate::moveTab(int index, int offset) 1675 { 1676 if (!validIndex(index)) 1677 return; 1678 tabList[index].dragOffset = offset; 1679 layoutTab(index); // Make buttons follow tab 1680 q_func()->update(); 1685 1681 } 1686 1682 … … 1696 1692 // Be safe! 1697 1693 if (d->pressedIndex != -1 && d->movable) 1698 d-> _q_moveTabFinished(d->pressedIndex);1694 d->moveTabFinished(d->pressedIndex); 1699 1695 1700 1696 d->pressedIndex = d->indexAtPos(event->pos()); 1697 #ifdef Q_WS_MAC 1698 d->previousPressedIndex = d->pressedIndex; 1699 #endif 1701 1700 if (d->validIndex(d->pressedIndex)) { 1702 1701 QStyleOptionTabBarBaseV2 optTabBase; … … 1722 1721 if (d->pressedIndex != -1 1723 1722 && event->buttons() == Qt::NoButton) 1724 d-> _q_moveTabFinished(d->pressedIndex);1723 d->moveTabFinished(d->pressedIndex); 1725 1724 1726 1725 // Start drag … … 1728 1727 if ((event->pos() - d->dragStartPosition).manhattanLength() > QApplication::startDragDistance()) { 1729 1728 d->dragInProgress = true; 1730 if (d->animations.isEmpty()) 1731 d->grabCache(0, d->tabList.count(), false); 1729 d->setupMovableTab(); 1732 1730 } 1733 1731 } … … 1774 1772 d->slide(i + offset, d->pressedIndex); 1775 1773 } 1776 1777 1774 } 1778 1775 // Buttons needs to follow the dragged tab … … 1781 1778 update(); 1782 1779 } 1780 #ifdef Q_WS_MAC 1781 } else if (!d->documentMode && event->buttons() == Qt::LeftButton && d->previousPressedIndex != -1) { 1782 int newPressedIndex = d->indexAtPos(event->pos()); 1783 if (d->pressedIndex == -1 && d->previousPressedIndex == newPressedIndex) { 1784 d->pressedIndex = d->previousPressedIndex; 1785 update(tabRect(d->pressedIndex)); 1786 } else if(d->pressedIndex != newPressedIndex) { 1787 d->pressedIndex = -1; 1788 update(tabRect(d->previousPressedIndex)); 1789 } 1790 #endif 1783 1791 } 1784 1792 … … 1792 1800 } 1793 1801 1794 void QTabBarPrivate:: _q_moveTabFinished()1802 void QTabBarPrivate::setupMovableTab() 1795 1803 { 1796 1804 Q_Q(QTabBar); 1797 if (QTimeLine *timeLine = qobject_cast<QTimeLine *>(q->sender())) { 1798 int index = animations[timeLine]; 1799 animations.remove(timeLine); 1800 _q_moveTabFinished(index); 1801 } 1802 } 1803 1804 void QTabBarPrivate::grabCache(int start, int end, bool unhide) 1805 { 1806 Q_Q(QTabBar); 1807 paintWithOffsets = false; 1808 bool showButtonsAgain = rightB->isVisible(); 1809 rightB->hide(); 1810 leftB->hide(); 1811 1812 QWidget *topLevel = q->window(); 1813 QPoint topLevelOffset(q->mapTo(topLevel, QPoint())); 1814 for (int i = start; i < end; ++i) { 1815 QRect tabRect = q->tabRect(i); 1816 tabRect.translate(topLevelOffset); 1817 if (unhide) { 1818 tabList[i].unHideWidgets(); 1819 layoutWidgets(i); 1820 } 1821 tabList[i].animatingCache = QPixmap::grabWidget(topLevel, tabRect); 1822 if (i != pressedIndex) 1823 tabList[i].hideWidgets(); 1824 } 1825 if (showButtonsAgain) { 1826 rightB->show(); 1827 leftB->show(); 1828 } 1829 paintWithOffsets = true; 1830 } 1831 1832 void QTabBarPrivate::_q_moveTabFinished(int index) 1805 if (!movingTab) 1806 movingTab = new QWidget(q); 1807 1808 int taboverlap = q->style()->pixelMetric(QStyle::PM_TabBarTabOverlap, 0 ,q); 1809 QRect grabRect = q->tabRect(pressedIndex); 1810 grabRect.adjust(-taboverlap, 0, taboverlap, 0); 1811 1812 QPixmap grabImage(grabRect.size()); 1813 grabImage.fill(Qt::transparent); 1814 QStylePainter p(&grabImage, q); 1815 p.initFrom(q); 1816 1817 QStyleOptionTabV3 tab; 1818 q->initStyleOption(&tab, pressedIndex); 1819 tab.rect.moveTopLeft(QPoint(taboverlap, 0)); 1820 p.drawControl(QStyle::CE_TabBarTab, tab); 1821 p.end(); 1822 1823 QPalette pal; 1824 pal.setBrush(QPalette::All, QPalette::Window, grabImage); 1825 movingTab->setPalette(pal); 1826 movingTab->setGeometry(grabRect); 1827 movingTab->setAutoFillBackground(true); 1828 movingTab->raise(); 1829 1830 // Re-arrange widget order to avoid overlaps 1831 if (tabList[pressedIndex].leftWidget) 1832 tabList[pressedIndex].leftWidget->raise(); 1833 if (tabList[pressedIndex].rightWidget) 1834 tabList[pressedIndex].rightWidget->raise(); 1835 if (leftB) 1836 leftB->raise(); 1837 if (rightB) 1838 rightB->raise(); 1839 movingTab->setVisible(true); 1840 } 1841 1842 void QTabBarPrivate::moveTabFinished(int index) 1833 1843 { 1834 1844 Q_Q(QTabBar); 1835 1845 bool cleanup = (pressedIndex == index) || (pressedIndex == -1) || !validIndex(index); 1836 if (animations.isEmpty() && cleanup) { 1846 bool allAnimationsFinished = true; 1847 #ifndef QT_NO_ANIMATION 1848 for(int i = 0; allAnimationsFinished && i < tabList.count(); ++i) { 1849 const Tab &t = tabList.at(i); 1850 if (t.animation && t.animation->state() == QAbstractAnimation::Running) 1851 allAnimationsFinished = false; 1852 } 1853 #endif //QT_NO_ANIMATION 1854 if (allAnimationsFinished && cleanup) { 1855 if(movingTab) 1856 movingTab->setVisible(false); // We might not get a mouse release 1837 1857 for (int i = 0; i < tabList.count(); ++i) { 1838 1858 tabList[i].dragOffset = 0; 1839 tabList[i].unHideWidgets();1840 tabList[i].animatingCache = QPixmap();1841 1859 } 1842 1860 if (pressedIndex != -1 && movable) { … … 1863 1881 return; 1864 1882 } 1865 1883 #ifdef Q_WS_MAC 1884 d->previousPressedIndex = -1; 1885 #endif 1866 1886 if (d->movable && d->dragInProgress && d->validIndex(d->pressedIndex)) { 1867 1887 int length = d->tabList[d->pressedIndex].dragOffset; … … 1870 1890 : tabRect(d->pressedIndex).width(); 1871 1891 int duration = qMin(ANIMATION_DURATION, 1872 ((length < 0 ? (-1 * length) : length) * ANIMATION_DURATION) / width); 1873 if (duration > 0) { 1874 d->tabList[d->pressedIndex].makeTimeLine(this); 1875 d->tabList[d->pressedIndex].timeLine->setFrameRange(length, 0); 1876 d->animations[d->tabList[d->pressedIndex].timeLine] = d->pressedIndex; 1877 d->tabList[d->pressedIndex].timeLine->setDuration(duration); 1878 if (d->tabList[d->pressedIndex].timeLine->state() != QTimeLine::Running) 1879 d->tabList[d->pressedIndex].timeLine->start(); 1880 } else { 1881 d->_q_moveTabFinished(d->pressedIndex); 1882 } 1892 (qAbs(length) * ANIMATION_DURATION) / width); 1893 d->tabList[d->pressedIndex].startAnimation(d, duration); 1883 1894 d->dragInProgress = false; 1895 d->movingTab->setVisible(false); 1884 1896 d->dragStartPosition = QPoint(); 1885 1897 } … … 1903 1915 return; 1904 1916 } 1905 int dx = event->key() == (isRightToLeft() ? Qt::Key_Right : Qt::Key_Left) ? -1 : 1; 1906 for (int index = d->currentIndex + dx; d->validIndex(index); index += dx) { 1907 if (d->tabList.at(index).enabled) { 1908 setCurrentIndex(index); 1909 break; 1910 } 1911 } 1917 int offset = event->key() == (isRightToLeft() ? Qt::Key_Right : Qt::Key_Left) ? -1 : 1; 1918 d->setCurrentNextEnabledIndex(offset); 1912 1919 } 1913 1920 … … 1918 1925 { 1919 1926 Q_D(QTabBar); 1920 int overIndex = d->indexAtPos(event->pos()); 1921 if (overIndex != -1) { 1922 int offset = event->delta() > 0 ? -1 : 1; 1923 setCurrentIndex(currentIndex() + offset); 1924 } 1927 int offset = event->delta() > 0 ? -1 : 1; 1928 d->setCurrentNextEnabledIndex(offset); 1925 1929 QWidget::wheelEvent(event); 1926 1930 } 1927 1931 #endif //QT_NO_WHEELEVENT 1932 1933 void QTabBarPrivate::setCurrentNextEnabledIndex(int offset) 1934 { 1935 Q_Q(QTabBar); 1936 for (int index = currentIndex + offset; validIndex(index); index += offset) { 1937 if (tabList.at(index).enabled) { 1938 q->setCurrentIndex(index); 1939 break; 1940 } 1941 } 1942 } 1928 1943 1929 1944 /*!\reimp … … 1934 1949 if (event->type() == QEvent::StyleChange) { 1935 1950 d->elideMode = Qt::TextElideMode(style()->styleHint(QStyle::SH_TabBar_ElideMode, 0, this)); 1936 d->useScrollButtons = !style()->styleHint(QStyle::SH_TabBar_PreferNoArrows, 0, this); 1937 } 1938 d->refresh(); 1951 if (!d->useScrollButtonsSetByUser) 1952 d->useScrollButtons = !style()->styleHint(QStyle::SH_TabBar_PreferNoArrows, 0, this); 1953 d->refresh(); 1954 } else if (event->type() == QEvent::FontChange) { 1955 d->refresh(); 1956 } 1939 1957 QWidget::changeEvent(event); 1940 1958 } … … 1987 2005 { 1988 2006 Q_D(QTabBar); 2007 d->useScrollButtonsSetByUser = true; 1989 2008 if (d->useScrollButtons == useButtons) 1990 2009 return; … … 2204 2223 // make sure our left and right widgets stay on top 2205 2224 widget->lower(); 2225 widget->show(); 2206 2226 } 2207 2227 if (position == LeftSide) { … … 2209 2229 d->tabList[index].leftWidget->hide(); 2210 2230 d->tabList[index].leftWidget = widget; 2211 if(!d->tabList[index].hidLeft && widget)2212 widget->show();2213 2231 } else { 2214 2232 if (d->tabList[index].rightWidget) 2215 2233 d->tabList[index].rightWidget->hide(); 2216 2234 d->tabList[index].rightWidget = widget; 2217 if(!d->tabList[index].hidRight && widget)2218 widget->show();2219 2235 } 2220 2236 d->layoutTabs(); 2237 d->refresh(); 2221 2238 update(); 2222 2239 } -
trunk/src/gui/widgets/qtabbar.h
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 ** … … 216 216 Q_PRIVATE_SLOT(d_func(), void _q_scrollTabs()) 217 217 Q_PRIVATE_SLOT(d_func(), void _q_closeTab()) 218 Q_PRIVATE_SLOT(d_func(), void _q_moveTab(int))219 Q_PRIVATE_SLOT(d_func(), void _q_moveTabFinished())220 218 }; 221 219 -
trunk/src/gui/widgets/qtabbar_p.h
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 ** … … 59 59 #include <qicon.h> 60 60 #include <qtoolbutton.h> 61 #include <qtimeline.h>62 #include <qhash.h>63 61 #include <qdebug.h> 62 #include <qvariantanimation.h> 64 63 65 64 #ifndef QT_NO_TABBAR … … 70 69 71 70 QT_BEGIN_NAMESPACE 72 73 71 74 72 class QTabBarPrivate : public QWidgetPrivate … … 77 75 public: 78 76 QTabBarPrivate() 79 :currentIndex(-1), pressedIndex(-1), 80 shape(QTabBar::RoundedNorth), 81 layoutDirty(false), drawBase(true), scrollOffset(0), expanding(true), closeButtonOnTabs(false), selectionBehaviorOnRemove(QTabBar::SelectRightTab), paintWithOffsets(true), movable(false), dragInProgress(false), documentMode(false) {} 77 :currentIndex(-1), pressedIndex(-1), shape(QTabBar::RoundedNorth), layoutDirty(false), 78 drawBase(true), scrollOffset(0), useScrollButtonsSetByUser(false) , expanding(true), closeButtonOnTabs(false), 79 selectionBehaviorOnRemove(QTabBar::SelectRightTab), paintWithOffsets(true), movable(false), 80 dragInProgress(false), documentMode(false), movingTab(0) 81 #ifdef Q_WS_MAC 82 , previousPressedIndex(-1) 83 #endif 84 {} 82 85 83 86 int currentIndex; … … 90 93 struct Tab { 91 94 inline Tab(const QIcon &ico, const QString &txt) 92 : enabled(true) 93 , shortcutId(0) 94 , text(txt) 95 , icon(ico) 96 , leftWidget(0) 97 , rightWidget(0) 98 , lastTab(-1) 99 , timeLine(0) 100 , dragOffset(0) 101 , hidLeft(false) 102 , hidRight(false) 95 : enabled(true) , shortcutId(0), text(txt), icon(ico), 96 leftWidget(0), rightWidget(0), lastTab(-1), dragOffset(0) 97 #ifndef QT_NO_ANIMATION 98 , animation(0) 99 #endif //QT_NO_ANIMATION 103 100 {} 101 bool operator==(const Tab &other) const { return &other == this; } 104 102 bool enabled; 105 103 int shortcutId; … … 121 119 QWidget *rightWidget; 122 120 int lastTab; 123 124 QTimeLine *timeLine;125 121 int dragOffset; 126 QPixmap animatingCache; 127 bool hidLeft; 128 bool hidRight; 129 130 void makeTimeLine(QWidget *q) { 131 if (timeLine) 132 return; 133 timeLine = new QTimeLine(ANIMATION_DURATION, q); 134 q->connect(timeLine, SIGNAL(frameChanged(int)), q, SLOT(_q_moveTab(int))); 135 q->connect(timeLine, SIGNAL(finished()), q, SLOT(_q_moveTabFinished())); 122 123 #ifndef QT_NO_ANIMATION 124 ~Tab() { delete animation; } 125 struct TabBarAnimation : public QVariantAnimation { 126 TabBarAnimation(Tab *t, QTabBarPrivate *_priv) : tab(t), priv(_priv) 127 { setEasingCurve(QEasingCurve::InOutQuad); } 128 129 void updateCurrentValue(const QVariant ¤t) 130 { priv->moveTab(priv->tabList.indexOf(*tab), current.toInt()); } 131 132 void updateState(State, State newState) 133 { if (newState == Stopped) priv->moveTabFinished(priv->tabList.indexOf(*tab)); } 134 private: 135 //these are needed for the callbacks 136 Tab *tab; 137 QTabBarPrivate *priv; 138 } *animation; 139 140 void startAnimation(QTabBarPrivate *priv, int duration) { 141 if (!animation) 142 animation = new TabBarAnimation(this, priv); 143 animation->setStartValue(dragOffset); 144 animation->setEndValue(0); 145 animation->setDuration(duration); 146 animation->start(); 136 147 } 137 138 void hideWidgets() { 139 if (!hidRight && rightWidget) { 140 hidRight = rightWidget->isVisible(); 141 rightWidget->hide(); 142 } 143 144 if (!hidLeft && leftWidget) { 145 hidLeft = leftWidget->isVisible(); 146 leftWidget->hide(); 147 } 148 } 149 150 void unHideWidgets() { 151 if (leftWidget && hidLeft) 152 leftWidget->show(); 153 hidLeft = false; 154 if (rightWidget && hidRight) 155 rightWidget->show(); 156 hidRight = false; 157 } 158 148 #else 149 void startAnimation(QTabBarPrivate *priv, int duration) 150 { Q_UNUSED(duration); priv->moveTabFinished(priv->tabList.indexOf(*this)); } 151 #endif //QT_NO_ANIMATION 159 152 }; 160 153 QList<Tab> tabList; 161 QHash<QTimeLine*, int> animations;162 154 163 155 int calculateNewPosition(int from, int to, int index) const; … … 172 164 173 165 inline bool validIndex(int index) const { return index >= 0 && index < tabList.count(); } 166 void setCurrentNextEnabledIndex(int offset); 174 167 175 168 QSize minimumTabSizeHint(int index); … … 180 173 void _q_scrollTabs(); 181 174 void _q_closeTab(); 182 void _q_moveTab(int); 183 void _q_moveTabFinished(); 184 void _q_moveTabFinished(int offset); 175 void moveTab(int index, int offset); 176 void moveTabFinished(int index); 185 177 QRect hoverRect; 186 178 187 void grabCache(int start, int end, bool unhide);188 179 void refresh(); 189 180 void layoutTabs(); … … 191 182 void layoutTab(int index); 192 183 void updateMacBorderMetrics(); 184 void setupMovableTab(); 193 185 194 186 void makeVisible(int index); … … 196 188 Qt::TextElideMode elideMode; 197 189 bool useScrollButtons; 190 bool useScrollButtonsSetByUser; 198 191 199 192 bool expanding; … … 207 200 bool documentMode; 208 201 202 QWidget *movingTab; 203 #ifdef Q_WS_MAC 204 int previousPressedIndex; 205 #endif 209 206 // shared by tabwidget and qtabbar 210 207 static void initStyleBaseOption(QStyleOptionTabBarBaseV2 *optTabBase, QTabBar *tabbar, QSize size) -
trunk/src/gui/widgets/qtabwidget.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 ** … … 65 65 \ingroup organizers 66 66 \ingroup basicwidgets 67 \mainclass 67 68 68 69 69 A tab widget provides a tab bar (see QTabBar) and a "page area" … … 314 314 break; 315 315 } 316 316 317 option->tabBarSize = t; 318 319 if (QStyleOptionTabWidgetFrameV2 *tabframe = qstyleoption_cast<QStyleOptionTabWidgetFrameV2*>(option)) { 320 QRect tbRect = tabBar()->geometry(); 321 QRect selectedTabRect = tabBar()->tabRect(tabBar()->currentIndex()); 322 tabframe->tabBarRect = tbRect; 323 selectedTabRect.moveTopLeft(selectedTabRect.topLeft() + tbRect.topLeft()); 324 tabframe->selectedTabRect = selectedTabRect; 325 } 317 326 } 318 327 … … 505 514 506 515 /*! 507 Returns true if the thepage at position \a index is enabled; otherwise returns false.516 Returns true if the page at position \a index is enabled; otherwise returns false. 508 517 509 518 \sa setTabEnabled(), QWidget::isEnabled() … … 691 700 connect(d->tabs, SIGNAL(currentChanged(int)), 692 701 this, SLOT(_q_showTab(int))); 693 connect(d->tabs, SIGNAL(tabMoved(int, 694 this, SLOT(_q_tabMoved(int, 702 connect(d->tabs, SIGNAL(tabMoved(int,int)), 703 this, SLOT(_q_tabMoved(int,int))); 695 704 if (d->tabs->tabsClosable()) 696 705 connect(d->tabs, SIGNAL(tabCloseRequested(int)), … … 757 766 return; // nothing to do 758 767 759 QStyleOptionTabWidgetFrame option;768 QStyleOptionTabWidgetFrameV2 option; 760 769 initStyleOption(&option); 761 770 … … 1058 1067 } 1059 1068 } 1060 if (! qApp->focusWidget())1069 if (!QApplication::focusWidget()) 1061 1070 d->tabs->setFocus(); 1062 1071 } else { … … 1168 1177 { 1169 1178 Q_D(QTabWidget); 1170 QStylePainter p(this);1171 1179 if (documentMode()) { 1180 QStylePainter p(this, tabBar()); 1172 1181 if (QWidget *w = cornerWidget(Qt::TopLeftCorner)) { 1173 1182 QStyleOptionTabBarBaseV2 opt; … … 1186 1195 return; 1187 1196 } 1188 1189 QStyleOptionTabWidgetFrame opt; 1197 QStylePainter p(this); 1198 1199 QStyleOptionTabWidgetFrameV2 opt; 1190 1200 initStyleOption(&opt); 1191 1201 opt.rect = d->panelRect; -
trunk/src/gui/widgets/qtabwidget.h
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 ** -
trunk/src/gui/widgets/qtextbrowser.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 ** … … 264 264 #ifndef QT_NO_CURSOR 265 265 if (q->isVisible()) 266 qApp->setOverrideCursor(Qt::WaitCursor);266 QApplication::setOverrideCursor(Qt::WaitCursor); 267 267 #endif 268 268 textOrSourceChanged = true; … … 296 296 if (q->isVisible()) { 297 297 QString firstTag = txt.left(txt.indexOf(QLatin1Char('>')) + 1); 298 if (firstTag. left(3) == QLatin1String("<qt") && firstTag.contains(QLatin1String("type")) && firstTag.contains(QLatin1String("detail"))) {298 if (firstTag.startsWith(QLatin1String("<qt")) && firstTag.contains(QLatin1String("type")) && firstTag.contains(QLatin1String("detail"))) { 299 299 #ifndef QT_NO_CURSOR 300 qApp->restoreOverrideCursor();300 QApplication::restoreOverrideCursor(); 301 301 #endif 302 302 #ifndef QT_NO_WHATSTHIS … … 343 343 #ifndef QT_NO_CURSOR 344 344 if (q->isVisible()) 345 qApp->restoreOverrideCursor();345 QApplication::restoreOverrideCursor(); 346 346 #endif 347 347 emit q->sourceChanged(url); … … 581 581 \brief The QTextBrowser class provides a rich text browser with hypertext navigation. 582 582 583 \ingroup text583 \ingroup richtext-processing 584 584 585 585 This class extends QTextEdit (in read-only mode), adding some navigation -
trunk/src/gui/widgets/qtextbrowser.h
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 ** -
trunk/src/gui/widgets/qtextedit.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 ** … … 75 75 76 76 #ifndef QT_NO_TEXTEDIT 77 static inline bool shouldEnableInputMethod(QTextEdit *textedit) 78 { 79 return !textedit->isReadOnly(); 80 } 77 81 78 82 class QTextEditControl : public QTextControl … … 106 110 autoFormatting(QTextEdit::AutoNone), tabChangesFocus(false), 107 111 lineWrap(QTextEdit::WidgetWidth), lineWrapColumnOrWidth(0), 108 wordWrap(QTextOption::WrapAtWordBoundaryOrAnywhere), textFormat(Qt::AutoText) 112 wordWrap(QTextOption::WrapAtWordBoundaryOrAnywhere), clickCausedFocus(0), 113 textFormat(Qt::AutoText) 109 114 { 110 115 ignoreAutomaticScrollbarAdjustment = false; … … 153 158 QObject::connect(control, SIGNAL(selectionChanged()), q, SIGNAL(selectionChanged())); 154 159 QObject::connect(control, SIGNAL(cursorPositionChanged()), q, SIGNAL(cursorPositionChanged())); 160 161 QObject::connect(control, SIGNAL(textChanged()), q, SLOT(updateMicroFocus())); 155 162 156 163 QTextDocument *doc = control->document(); … … 178 185 #ifndef QT_NO_CURSOR 179 186 viewport->setCursor(Qt::IBeamCursor); 187 #endif 188 #ifdef Q_WS_WIN 189 setSingleFingerPanEnabled(true); 180 190 #endif 181 191 } … … 329 339 both plain and rich text. 330 340 331 \ingroup text332 \mainclass 341 \ingroup richtext-processing 342 333 343 334 344 \tableofcontents … … 523 533 524 534 If the text edit has another content type, it will not be replaced 525 by plain text if you call toPlainText(). 535 by plain text if you call toPlainText(). The only exception to this 536 is the non-break space, \e{nbsp;}, that will be converted into 537 standard space. 526 538 527 539 By default, for an editor with no contents, this property contains … … 1203 1215 if (e->text()[0].isPrint()) { 1204 1216 setEditFocus(true); 1217 #ifndef Q_OS_SYMBIAN 1205 1218 clear(); 1219 #endif 1206 1220 } else { 1207 1221 e->ignore(); … … 1213 1227 } 1214 1228 #endif 1215 1216 if (!(d->control->textInteractionFlags() & Qt::TextEditable)) { 1229 #ifndef QT_NO_SHORTCUT 1230 1231 Qt::TextInteractionFlags tif = d->control->textInteractionFlags(); 1232 1233 if (tif & Qt::TextSelectableByKeyboard){ 1234 if (e == QKeySequence::SelectPreviousPage) { 1235 e->accept(); 1236 d->pageUpDown(QTextCursor::Up, QTextCursor::KeepAnchor); 1237 return; 1238 } else if (e ==QKeySequence::SelectNextPage) { 1239 e->accept(); 1240 d->pageUpDown(QTextCursor::Down, QTextCursor::KeepAnchor); 1241 return; 1242 } 1243 } 1244 if (tif & (Qt::TextSelectableByKeyboard | Qt::TextEditable)) { 1245 if (e == QKeySequence::MoveToPreviousPage) { 1246 e->accept(); 1247 d->pageUpDown(QTextCursor::Up, QTextCursor::MoveAnchor); 1248 return; 1249 } else if (e == QKeySequence::MoveToNextPage) { 1250 e->accept(); 1251 d->pageUpDown(QTextCursor::Down, QTextCursor::MoveAnchor); 1252 return; 1253 } 1254 } 1255 1256 if (!(tif & Qt::TextEditable)) { 1217 1257 switch (e->key()) { 1218 1258 case Qt::Key_Space: … … 1239 1279 } 1240 1280 return; 1241 }1242 1243 #ifndef QT_NO_SHORTCUT1244 if (e == QKeySequence::MoveToPreviousPage) {1245 e->accept();1246 d->pageUpDown(QTextCursor::Up, QTextCursor::MoveAnchor);1247 return;1248 } else if (e == QKeySequence::MoveToNextPage) {1249 e->accept();1250 d->pageUpDown(QTextCursor::Down, QTextCursor::MoveAnchor);1251 return;1252 } else if (e == QKeySequence::SelectPreviousPage) {1253 e->accept();1254 d->pageUpDown(QTextCursor::Up, QTextCursor::KeepAnchor);1255 return;1256 } else if (e ==QKeySequence::SelectNextPage) {1257 e->accept();1258 d->pageUpDown(QTextCursor::Down, QTextCursor::KeepAnchor);1259 return;1260 1281 } 1261 1282 #endif // QT_NO_SHORTCUT … … 1560 1581 ensureCursorVisible(); 1561 1582 } 1583 if (!isReadOnly() && rect().contains(e->pos())) 1584 d->handleSoftwareInputPanel(e->button(), d->clickCausedFocus); 1585 d->clickCausedFocus = 0; 1562 1586 } 1563 1587 … … 1656 1680 && !hasEditFocus()) { 1657 1681 setEditFocus(true); 1682 #ifndef Q_OS_SYMBIAN 1658 1683 selectAll(); // so text is replaced rather than appended to 1684 #endif 1659 1685 } 1660 1686 #endif 1661 1687 d->sendControlEvent(e); 1688 ensureCursorVisible(); 1662 1689 } 1663 1690 … … 1695 1722 { 1696 1723 Q_D(QTextEdit); 1724 if (e->reason() == Qt::MouseFocusReason) { 1725 d->clickCausedFocus = 1; 1726 } 1697 1727 QAbstractScrollArea::focusInEvent(e); 1698 1728 d->sendControlEvent(e); … … 1879 1909 \since 4.1 1880 1910 1881 By default, this property contains a value of 80 .1911 By default, this property contains a value of 80 pixels. 1882 1912 */ 1883 1913 … … 2059 2089 flags = Qt::TextEditorInteraction; 2060 2090 } 2061 setAttribute(Qt::WA_InputMethodEnabled, !ro);2062 2091 d->control->setTextInteractionFlags(flags); 2092 setAttribute(Qt::WA_InputMethodEnabled, shouldEnableInputMethod(this)); 2063 2093 } 2064 2094 … … 2610 2640 } 2611 2641 2612 2613 2642 /*! 2614 2643 \enum QTextEdit::KeyboardAction -
trunk/src/gui/widgets/qtextedit.h
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 ** -
trunk/src/gui/widgets/qtextedit_p.h
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 72 72 class QMimeData; 73 74 73 class QTextEditPrivate : public QAbstractScrollAreaPrivate 75 74 { … … 124 123 uint showCursorOnInitialShow : 1; 125 124 uint inDrag : 1; 125 uint clickCausedFocus : 1; 126 126 127 127 // Qt3 COMPAT only, for setText -
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 -
trunk/src/gui/widgets/qtoolbar.h
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 ** … … 143 143 void iconSizeChanged(const QSize &iconSize); 144 144 void toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle); 145 void topLevelChanged(bool topLevel); 145 146 146 147 protected: … … 168 169 Q_PRIVATE_SLOT(d_func(), void _q_updateIconSize(const QSize &)) 169 170 Q_PRIVATE_SLOT(d_func(), void _q_updateToolButtonStyle(Qt::ToolButtonStyle)) 170 Q_PRIVATE_SLOT(d_func(), void _q_waitForPopup())171 171 172 172 friend class QMainWindow; -
trunk/src/gui/widgets/qtoolbar_p.h
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 ** … … 57 57 #include "QtGui/qaction.h" 58 58 #include "private/qwidget_p.h" 59 #include <QtCore/qbasictimer.h> 59 60 60 61 QT_BEGIN_NAMESPACE … … 71 72 public: 72 73 inline QToolBarPrivate() 73 : explicitIconSize(false), explicitToolButtonStyle(false), movable( false),74 : explicitIconSize(false), explicitToolButtonStyle(false), movable(true), floatable(true), 74 75 allowedAreas(Qt::AllToolBarAreas), orientation(Qt::Horizontal), 75 76 toolButtonStyle(Qt::ToolButtonIconOnly), … … 85 86 void _q_updateIconSize(const QSize &sz); 86 87 void _q_updateToolButtonStyle(Qt::ToolButtonStyle style); 87 void _q_waitForPopup();88 88 89 89 bool explicitIconSize; 90 90 bool explicitToolButtonStyle; 91 91 bool movable; 92 bool floatable; 92 93 Qt::ToolBarAreas allowedAreas; 93 94 Qt::Orientation orientation; 94 95 Qt::ToolButtonStyle toolButtonStyle; 95 96 QSize iconSize; 96 bool floatable;97 97 98 98 QAction *toggleViewAction; … … 126 126 void plug(const QRect &r); 127 127 128 Q Timer *waitForPopupTimer;128 QBasicTimer waitForPopupTimer; 129 129 }; 130 130 -
trunk/src/gui/widgets/qtoolbararealayout.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 ** … … 114 114 115 115 QSize sh = item.sizeHint(); 116 a += pick(o, sh) + item.extraSpace;116 a += item.preferredSize > 0 ? item.preferredSize : pick(o, sh); 117 117 b = qMax(b, perp(o, sh)); 118 118 } … … 157 157 continue; 158 158 159 QToolBarLayout *tblayout = qobject_cast<QToolBarLayout*>(item.widgetItem->widget()->layout()); 160 if (tblayout) 159 if (QToolBarLayout *tblayout = qobject_cast<QToolBarLayout*>(item.widgetItem->widget()->layout())) 161 160 tblayout->checkUsePopupMenu(); 162 161 163 int itemMin = pick(o, item.minimumSize());164 int itemHint = pick(o, item.sizeHint());165 //we ensure the extraspace is not too low166 item.extraSpace = qMax(itemMin - itemHint, item.extraSpace); 167 itemHint += item.extraSpace;168 int itemExtra = qMin(itemHint- itemMin, extra);169 170 item.size = itemMin + itemExtra; 171 extra -= itemExtra;162 const int itemMin = pick(o, item.minimumSize()); 163 //preferredSize is the default if it is set, otherwise, we take the sizehint 164 item.size = item.preferredSize > 0 ? item.preferredSize : pick(o, item.sizeHint()); 165 166 //the extraspace is the space above the item minimum sizehint 167 const int extraSpace = qMin(item.size - itemMin, extra); 168 item.size = itemMin + extraSpace; //that is the real size 169 170 extra -= extraSpace; 172 171 173 172 last = i; … … 396 395 void QToolBarAreaLayoutInfo::moveToolBar(QToolBar *toolbar, int pos) 397 396 { 398 if (dirty) {397 if (dirty) 399 398 fitLayout(); 400 }401 399 402 400 dirty = true; 403 401 404 if (o == Qt::Vertical) {402 if (o == Qt::Vertical) 405 403 pos -= rect.top(); 406 } 407 408 //here we actually update the extraSpace for the line containing the toolbar so that we move it 404 405 //here we actually update the preferredSize for the line containing the toolbar so that we move it 409 406 for (int j = 0; j < lines.count(); ++j) { 410 407 QToolBarAreaLayoutLine &line = lines[j]; … … 433 430 } 434 431 435 // let's update the previous extra space432 //extra is the number of pixels to add to the previous toolbar 436 433 int extra = newPos - current.pos; 437 434 438 if (qAbs(previous.extraSpace + extra) < QApplication::startDragDistance()) { 439 //we stick to the default space 440 extra = 0; 435 //we check if the previous is near its size hint 436 //in which case we try to stick to it 437 const int diff = pick(o, previous.sizeHint()) - (previous.size + extra); 438 if (qAbs(diff) < QApplication::startDragDistance()) { 439 //we stick to the default place and size 440 extra += diff; 441 441 } 442 442 443 443 //update for the current item 444 current.extraSpace -= extra; 445 //this ensures the toolbars to be pushed to the right when necessary 446 current.extraSpace = qMax(pick(o,current.minimumSize())- pick(o,current.sizeHint()), current.extraSpace); 447 444 current.extendSize(line.o, -extra); 445 448 446 if (extra >= 0) { 449 previous.extraSpace += extra; 450 447 previous.extendSize(line.o, extra); 451 448 } else { 452 449 //we need to push the toolbars on the left starting with previous … … 456 453 QToolBarAreaLayoutItem &item = line.toolBarItems[l]; 457 454 if (!item.skip()) { 458 const int min ExtraSpace = pick(o, item.minimumSize()) - pick(o, item.sizeHint());459 const int margin = item. extraSpace - minExtraSpace;455 const int minPreferredSize = pick(o, item.minimumSize()); 456 const int margin = item.size - minPreferredSize; 460 457 if (margin < extra) { 461 item. extraSpace = minExtraSpace;458 item.resize(line.o, minPreferredSize); 462 459 extra -= margin; 463 460 } else { 464 item.ext raSpace -= extra;461 item.extendSize(line.o, -extra); 465 462 extra = 0; 466 463 } … … 484 481 485 482 486 QList<int> QToolBarAreaLayoutInfo::gapIndex(const QPoint &pos ) const483 QList<int> QToolBarAreaLayoutInfo::gapIndex(const QPoint &pos, int *minDistance) const 487 484 { 488 485 int p = pick(o, pos); … … 513 510 QList<int> result; 514 511 result << j << k; 512 *minDistance = 0; //we found a perfect match 515 513 return result; 516 514 } 517 } else if (appendLineDropRect().contains(pos)) { 518 QList<int> result; 519 result << lines.count() << 0; 520 return result; 515 } else { 516 const int dist = distance(pos); 517 //it will only return a path if the minDistance is higher than the current distance 518 if (dist >= 0 && *minDistance > dist) { 519 *minDistance = dist; 520 521 QList<int> result; 522 result << lines.count() << 0; 523 return result; 524 } 521 525 } 522 526 … … 524 528 } 525 529 526 bool QToolBarAreaLayoutInfo::insertGap(QList<int> path, QLayoutItem *item) 527 { 528 int j = path.at(0); 530 bool QToolBarAreaLayoutInfo::insertGap(const QList<int> &path, QLayoutItem *item) 531 { 532 Q_ASSERT(path.count() == 2); 533 int j = path.first(); 529 534 if (j == lines.count()) 530 535 lines.append(QToolBarAreaLayoutLine(o)); … … 537 542 gap_item.widgetItem = item; 538 543 539 //update the previous item's extra space544 //update the previous item's preferred size 540 545 for(int p = k - 1 ; p >= 0; --p) { 541 546 QToolBarAreaLayoutItem &previous = line.toolBarItems[p]; 542 547 if (!previous.skip()) { 543 548 //we found the previous one 544 gap_item.extraSpace = qMax(0, previous.extraSpace - pick(o, gap_item.sizeHint())); 545 previous.extraSpace = qMin(previous.extraSpace, 0); 549 int previousSizeHint = pick(line.o, previous.sizeHint()); 550 int previousExtraSpace = previous.size - previousSizeHint; 551 552 if (previousExtraSpace > 0) { 553 //in this case we reset the space 554 previous.preferredSize = -1; 555 previous.size = previousSizeHint; 556 557 gap_item.resize(o, previousExtraSpace); 558 } 559 546 560 break; 547 561 } … … 556 570 { 557 571 lines.clear(); 558 rect = QRect(0, 0, -1, -1); 559 } 560 561 QRect QToolBarAreaLayoutInfo::itemRect(QList<int> path) const 562 { 572 rect = QRect(); 573 } 574 575 QRect QToolBarAreaLayoutInfo::itemRect(const QList<int> &path) const 576 { 577 Q_ASSERT(path.count() == 2); 563 578 int j = path.at(0); 564 579 int k = path.at(1); … … 580 595 } 581 596 582 QRect QToolBarAreaLayoutInfo::appendLineDropRect() const 583 { 584 QRect result; 585 597 int QToolBarAreaLayoutInfo::distance(const QPoint &pos) const 598 { 586 599 switch (dockPos) { 587 600 case QInternal::LeftDock: 588 result = QRect(rect.right(), rect.top(), 589 EmptyDockAreaSize, rect.height()); 590 break; 601 if (pos.y() < rect.bottom()) 602 return pos.x() - rect.right(); 591 603 case QInternal::RightDock: 592 result = QRect(rect.left() - EmptyDockAreaSize, rect.top(), 593 EmptyDockAreaSize, rect.height()); 594 break; 604 if (pos.y() < rect.bottom()) 605 return rect.left() - pos.x(); 595 606 case QInternal::TopDock: 596 result = QRect(rect.left(), rect.bottom() + 1, 597 rect.width(), EmptyDockAreaSize); 598 break; 607 if (pos.x() < rect.right()) 608 return pos.y() - rect.bottom(); 599 609 case QInternal::BottomDock: 600 result = QRect(rect.left(), rect.top() - EmptyDockAreaSize, 601 rect.width(), EmptyDockAreaSize); 602 break; 610 if (pos.x() < rect.right()) 611 return rect.top() - pos.y(); 603 612 default: 604 613 break; 605 614 } 606 607 return result; 615 return -1; 608 616 } 609 617 … … 612 620 */ 613 621 614 QToolBarAreaLayout::QToolBarAreaLayout(QMainWindow *win) 615 { 616 visible = true; 617 mainWindow = win; 622 QToolBarAreaLayout::QToolBarAreaLayout(const QMainWindow *win) : mainWindow(win), visible(true) 623 { 618 624 for (int i = 0; i < QInternal::DockCount; ++i) { 619 625 QInternal::DockPosition pos = static_cast<QInternal::DockPosition>(i); … … 771 777 for (int k = 0; k < line.toolBarItems.count(); ++k) { 772 778 QToolBarAreaLayoutItem &item = line.toolBarItems[k]; 773 delete item.widgetItem; 779 if (!item.gap) 780 delete item.widgetItem; 774 781 item.widgetItem = 0; 775 782 } … … 921 928 geo = QStyle::visualRect(dir, line.rect, geo); 922 929 923 layout->widgetAnimator ->animate(widget, geo, animate);930 layout->widgetAnimator.animate(widget, geo, animate); 924 931 } 925 932 } … … 1016 1023 } 1017 1024 1025 //this functions returns the path to the possible gapindex for the position pos 1018 1026 QList<int> QToolBarAreaLayout::gapIndex(const QPoint &pos) const 1019 1027 { 1020 1028 Qt::LayoutDirection dir = mainWindow->layoutDirection(); 1029 int minDistance = 80; // when a dock area is empty, how "wide" is it? 1030 QList<int> ret; //return value 1021 1031 for (int i = 0; i < QInternal::DockCount; ++i) { 1022 1032 QPoint p = pos; 1023 1033 if (docks[i].o == Qt::Horizontal) 1024 1034 p = QStyle::visualPos(dir, docks[i].rect, p); 1025 QList<int> result = docks[i].gapIndex(p );1035 QList<int> result = docks[i].gapIndex(p, &minDistance); 1026 1036 if (!result.isEmpty()) { 1027 1037 result.prepend(i); 1028 ret urnresult;1029 } 1030 } 1031 1032 return QList<int>();1038 ret = result; 1039 } 1040 } 1041 1042 return ret; 1033 1043 } 1034 1044 … … 1053 1063 } 1054 1064 1055 bool QToolBarAreaLayout::insertGap( QList<int>path, QLayoutItem *item)1056 { 1057 Q_ASSERT( !path.isEmpty());1058 int i = path.takeFirst();1065 bool QToolBarAreaLayout::insertGap(const QList<int> &path, QLayoutItem *item) 1066 { 1067 Q_ASSERT(path.count() == 3); 1068 const int i = path.first(); 1059 1069 Q_ASSERT(i >= 0 && i < QInternal::DockCount); 1060 return docks[i].insertGap(path, item); 1061 } 1062 1063 void QToolBarAreaLayout::remove(QList<int> path) 1064 { 1070 return docks[i].insertGap(path.mid(1), item); 1071 } 1072 1073 void QToolBarAreaLayout::remove(const QList<int> &path) 1074 { 1075 Q_ASSERT(path.count() == 3); 1065 1076 docks[path.at(0)].lines[path.at(1)].toolBarItems.removeAt(path.at(2)); 1066 1077 } … … 1090 1101 for (int i = 0; i < QInternal::DockCount; ++i) 1091 1102 docks[i].clear(); 1092 rect = QRect( 0, 0, -1, -1);1093 } 1094 1095 QToolBarAreaLayoutItem &QToolBarAreaLayout::item( QList<int>path)1103 rect = QRect(); 1104 } 1105 1106 QToolBarAreaLayoutItem &QToolBarAreaLayout::item(const QList<int> &path) 1096 1107 { 1097 1108 Q_ASSERT(path.count() == 3); … … 1105 1116 } 1106 1117 1107 QRect QToolBarAreaLayout::itemRect( QList<int>path) const1108 { 1109 int i = path.takeFirst();1110 1111 QRect r = docks[i].itemRect(path );1118 QRect QToolBarAreaLayout::itemRect(const QList<int> &path) const 1119 { 1120 const int i = path.first(); 1121 1122 QRect r = docks[i].itemRect(path.mid(1)); 1112 1123 if (docks[i].o == Qt::Horizontal) 1113 1124 r = QStyle::visualRect(mainWindow->layoutDirection(), … … 1116 1127 } 1117 1128 1118 QLayoutItem *QToolBarAreaLayout::plug( QList<int>path)1129 QLayoutItem *QToolBarAreaLayout::plug(const QList<int> &path) 1119 1130 { 1120 1131 QToolBarAreaLayoutItem &item = this->item(path); … … 1125 1136 } 1126 1137 1127 QLayoutItem *QToolBarAreaLayout::unplug( QList<int>path, QToolBarAreaLayout *other)1138 QLayoutItem *QToolBarAreaLayout::unplug(const QList<int> &path, QToolBarAreaLayout *other) 1128 1139 { 1129 1140 //other needs to be update as well 1141 Q_ASSERT(path.count() == 3); 1130 1142 QToolBarAreaLayoutItem &item = this->item(path); 1131 1143 … … 1133 1145 QToolBarAreaLayoutInfo &info = docks[path.at(0)]; 1134 1146 QToolBarAreaLayoutLine &line = info.lines[path.at(1)]; 1135 if (item.extraSpace != 0) { 1147 if (item.size != pick(line.o, item.realSizeHint())) { 1148 //the item doesn't have its default size 1149 //so we'll give this to the next item 1136 1150 int newExtraSpace = 0; 1151 //let's iterate over the siblings of the current item that pare placed before it 1152 //we need to find just the one before 1137 1153 for (int i = path.at(2) - 1; i >= 0; --i) { 1138 1154 QToolBarAreaLayoutItem &previous = line.toolBarItems[i]; 1139 1155 if (!previous.skip()) { 1156 //we need to check if it has a previous element and a next one 1157 //the previous will get its size changed 1140 1158 for (int j = path.at(2) + 1; j < line.toolBarItems.count(); ++j) { 1141 1159 const QToolBarAreaLayoutItem &next = line.toolBarItems.at(j); 1142 1160 if (!next.skip()) { 1143 newExtraSpace = previous.extraSpace = next.pos - previous.pos - pick(line.o, previous.sizeHint()); 1161 newExtraSpace = next.pos - previous.pos - pick(line.o, previous.sizeHint()); 1162 previous.resize(line.o, next.pos - previous.pos); 1163 break; 1144 1164 } 1145 break;1146 1165 } 1147 1166 break; … … 1155 1174 QToolBarAreaLayoutItem &previous = line.toolBarItems[i]; 1156 1175 if (!previous.skip()) { 1157 previous. extraSpace = newExtraSpace;1176 previous.resize(line.o, pick(line.o, previous.sizeHint()) + newExtraSpace); 1158 1177 break; 1159 1178 } … … 1162 1181 } 1163 1182 } 1164 1165 1183 1166 1184 Q_ASSERT(!item.gap); … … 1254 1272 stream << shownOrientation; 1255 1273 stream << item.pos; 1256 // if extraSpace is 0 the item has its "normal" size, so no need to store the size (we store -1)1257 stream << (item.extraSpace == 0 ? -1 : (pick(line.o, item.realSizeHint()) + item.extraSpace));1274 //we store the preferred size. If the use rdidn't resize the toolbars it will be -1 1275 stream << item.preferredSize; 1258 1276 1259 1277 uint geom0, geom1; … … 1284 1302 int lines; 1285 1303 stream >> lines; 1304 if (!testing) 1305 testing = mainWindow->unifiedTitleAndToolBarOnMac(); 1286 1306 1287 1307 for (int j = 0; j < lines; ++j) { … … 1294 1314 1295 1315 QToolBarAreaLayoutInfo &dock = docks[pos]; 1316 const bool applyingLayout = !testing && !(pos == QInternal::TopDock && mainWindow->unifiedTitleAndToolBarOnMac()); 1296 1317 QToolBarAreaLayoutLine line(dock.o); 1297 1318 … … 1334 1355 } 1335 1356 1336 if ( !testing) {1357 if (applyingLayout) { 1337 1358 item.widgetItem = new QWidgetItemV2(toolBar); 1338 1359 toolBar->setOrientation(floating ? ((shown & 2) ? Qt::Vertical : Qt::Horizontal) : dock.o); … … 1340 1361 toolBar->d_func()->setWindowState(floating, true, rect); 1341 1362 1342 //if it is -1, it means we should use the default size 1343 item.extraSpace = (item.size == -1) ? 0 : item.size - pick(line.o, item.realSizeHint()); 1344 1345 1363 item.preferredSize = item.size; 1346 1364 line.toolBarItems.append(item); 1347 1365 } 1348 1366 } 1349 1367 1350 if ( !testing) {1368 if (applyingLayout) { 1351 1369 dock.lines.append(line); 1352 1370 } -
trunk/src/gui/widgets/qtoolbararealayout_p.h
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 ** … … 59 59 60 60 QT_BEGIN_NAMESPACE 61 62 static inline int pick(Qt::Orientation o, const QPoint &pos) 63 { return o == Qt::Horizontal ? pos.x() : pos.y(); } 64 65 static inline int pick(Qt::Orientation o, const QSize &size) 66 { return o == Qt::Horizontal ? size.width() : size.height(); } 67 68 static inline int &rpick(Qt::Orientation o, QPoint &pos) 69 { return o == Qt::Horizontal ? pos.rx() : pos.ry(); } 70 71 static inline int &rpick(Qt::Orientation o, QSize &size) 72 { return o == Qt::Horizontal ? size.rwidth() : size.rheight(); } 73 74 static inline QSizePolicy::Policy pick(Qt::Orientation o, const QSizePolicy &policy) 75 { return o == Qt::Horizontal ? policy.horizontalPolicy() : policy.verticalPolicy(); } 76 77 static inline int perp(Qt::Orientation o, const QPoint &pos) 78 { return o == Qt::Vertical ? pos.x() : pos.y(); } 79 80 static inline int perp(Qt::Orientation o, const QSize &size) 81 { return o == Qt::Vertical ? size.width() : size.height(); } 82 83 static inline int &rperp(Qt::Orientation o, QPoint &pos) 84 { return o == Qt::Vertical ? pos.rx() : pos.ry(); } 85 86 static inline int &rperp(Qt::Orientation o, QSize &size) 87 { return o == Qt::Vertical ? size.rwidth() : size.rheight(); } 61 88 62 89 #ifndef QT_NO_TOOLBAR … … 71 98 public: 72 99 QToolBarAreaLayoutItem(QLayoutItem *item = 0) 73 : widgetItem(item), pos(0), size(-1), extraSpace(0), gap(false) {}100 : widgetItem(item), pos(0), size(-1), preferredSize(-1), gap(false) {} 74 101 75 102 bool skip() const; 76 103 QSize minimumSize() const; 77 104 QSize sizeHint() const; 78 QSize realSizeHint() const; 105 QSize realSizeHint() const; 106 107 void resize(Qt::Orientation o, int newSize) 108 { 109 newSize = qMax(pick(o, minimumSize()), newSize); 110 int sizeh = pick(o, sizeHint()); 111 if (newSize == sizeh) { 112 preferredSize = -1; 113 size = sizeh; 114 } else { 115 preferredSize = newSize; 116 } 117 } 118 119 void extendSize(Qt::Orientation o, int extent) 120 { 121 int newSize = qMax(pick(o, minimumSize()), (preferredSize > 0 ? preferredSize : pick(o, sizeHint())) + extent); 122 int sizeh = pick(o, sizeHint()); 123 if (newSize == sizeh) { 124 preferredSize = -1; 125 size = sizeh; 126 } else { 127 preferredSize = newSize; 128 } 129 } 79 130 80 131 QLayoutItem *widgetItem; 81 132 int pos; 82 133 int size; 83 int extraSpace;134 int preferredSize; 84 135 bool gap; 85 136 }; … … 105 156 { 106 157 public: 107 enum { EmptyDockAreaSize = 80 }; // when a dock area is empty, how "wide" is it?108 109 158 QToolBarAreaLayoutInfo(QInternal::DockPosition pos = QInternal::TopDock); 110 159 … … 123 172 void moveToolBar(QToolBar *toolbar, int pos); 124 173 125 QList<int> gapIndex(const QPoint &pos ) const;126 bool insertGap( QList<int>path, QLayoutItem *item);174 QList<int> gapIndex(const QPoint &pos, int *maxDistance) const; 175 bool insertGap(const QList<int> &path, QLayoutItem *item); 127 176 void clear(); 128 QRect itemRect( QList<int>path) const;129 QRect appendLineDropRect() const;177 QRect itemRect(const QList<int> &path) const; 178 int distance(const QPoint &pos) const; 130 179 131 180 QRect rect; … … 144 193 145 194 QRect rect; 146 QMainWindow *mainWindow;195 const QMainWindow *mainWindow; 147 196 QToolBarAreaLayoutInfo docks[4]; 148 197 bool visible; 149 198 150 QToolBarAreaLayout( QMainWindow *win);199 QToolBarAreaLayout(const QMainWindow *win); 151 200 152 201 QRect fitLayout(); … … 180 229 QList<int> gapIndex(const QPoint &pos) const; 181 230 QList<int> currentGapIndex() const; 182 bool insertGap( QList<int>path, QLayoutItem *item);183 void remove( QList<int>path);231 bool insertGap(const QList<int> &path, QLayoutItem *item); 232 void remove(const QList<int> &path); 184 233 void remove(QLayoutItem *item); 185 234 void clear(); 186 QToolBarAreaLayoutItem &item( QList<int>path);187 QRect itemRect( QList<int>path) const;188 QLayoutItem *plug( QList<int>path);189 QLayoutItem *unplug( QList<int>path, QToolBarAreaLayout *other);235 QToolBarAreaLayoutItem &item(const QList<int> &path); 236 QRect itemRect(const QList<int> &path) const; 237 QLayoutItem *plug(const QList<int> &path); 238 QLayoutItem *unplug(const QList<int> &path, QToolBarAreaLayout *other); 190 239 191 240 void saveState(QDataStream &stream) const; -
trunk/src/gui/widgets/qtoolbarextension.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 ** … … 62 62 void QToolBarExtension::setOrientation(Qt::Orientation o) 63 63 { 64 QStyleOption opt; 65 opt.init(this); 64 66 if (o == Qt::Horizontal) { 65 setIcon(style()->standardIcon(QStyle::SP_ToolBarHorizontalExtensionButton ));67 setIcon(style()->standardIcon(QStyle::SP_ToolBarHorizontalExtensionButton, &opt)); 66 68 } else { 67 setIcon(style()->standardIcon(QStyle::SP_ToolBarVerticalExtensionButton ));69 setIcon(style()->standardIcon(QStyle::SP_ToolBarVerticalExtensionButton, &opt)); 68 70 } 69 71 } -
trunk/src/gui/widgets/qtoolbarextension_p.h
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 ** … … 60 60 #ifndef QT_NO_TOOLBUTTON 61 61 62 class Q ToolBarExtension : public QToolButton62 class Q_AUTOTEST_EXPORT QToolBarExtension : public QToolButton 63 63 { 64 64 Q_OBJECT -
trunk/src/gui/widgets/qtoolbarlayout.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 ** … … 129 129 if (!set) { 130 130 QObject::connect(extension, SIGNAL(clicked(bool)), 131 this, SLOT(setExpanded(bool)) );131 this, SLOT(setExpanded(bool)), Qt::UniqueConnection); 132 132 extension->setPopupMode(QToolButton::DelayedPopup); 133 133 extension->setMenu(0); … … 335 335 if (mw->unifiedTitleAndToolBarOnMac() 336 336 && mw->toolBarArea(static_cast<QToolBar *>(parentWidget())) == Qt::TopToolBarArea) { 337 if ( that->expandFlag) {337 if (expandFlag) { 338 338 tb->setMaximumSize(0xFFFFFF, 0xFFFFFF); 339 339 } else { … … 361 361 QStyleOptionToolBar opt; 362 362 tb->initStyleOption(&opt); 363 const int handleExtent = movable()364 ? style->pixelMetric(QStyle::PM_ToolBarHandleExtent, &opt, tb) : 0;365 363 const int margin = this->margin(); 366 364 const int extensionExtent = style->pixelMetric(QStyle::PM_ToolBarExtensionExtent, &opt, tb); … … 368 366 369 367 QLayout::setGeometry(rect); 370 if (movable()) {371 if (o == Qt::Horizontal) {372 handRect = QRect(margin, margin, handleExtent, rect.height() - 2*margin);373 handRect = QStyle::visualRect(parentWidget()->layoutDirection(), rect, handRect);374 } else {375 handRect = QRect(margin, margin, rect.width() - 2*margin, handleExtent);376 }377 } else {378 handRect = QRect();379 }380 368 381 369 bool ranOutOfSpace = false; … … 667 655 return; 668 656 if (QMainWindow *win = qobject_cast<QMainWindow*>(tb->parentWidget())) { 669 animating = true;657 animating = !tb->isWindow() && win->isAnimated(); 670 658 QMainWindowLayout *layout = qobject_cast<QMainWindowLayout*>(win->layout()); 671 659 if (expanded) { … … 678 666 } 679 667 } 680 layout->layoutState.toolBarAreaLayout.apply( true);668 layout->layoutState.toolBarAreaLayout.apply(animating); 681 669 } 682 670 } … … 743 731 } 744 732 745 QRect QToolBarLayout::handleRect() const746 {747 return handRect;748 }749 750 733 QT_END_NAMESPACE 751 734 -
trunk/src/gui/widgets/qtoolbarlayout_p.h
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 ** … … 66 66 class QMenu; 67 67 68 class Q _GUI_EXPORT QToolBarItem : public QWidgetItem68 class QToolBarItem : public QWidgetItem 69 69 { 70 70 public: … … 76 76 }; 77 77 78 class Q _GUI_EXPORT QToolBarLayout : public QLayout78 class QToolBarLayout : public QLayout 79 79 { 80 80 Q_OBJECT … … 101 101 int indexOf(QWidget *widget) const { return QLayout::indexOf(widget); } 102 102 103 QRect handleRect() const;104 105 103 bool layoutActions(const QSize &size); 106 104 QSize expandedSize(const QSize &size) const; … … 114 112 bool hasExpandFlag() const; 115 113 116 public slots:114 public Q_SLOTS: 117 115 void setExpanded(bool b); 118 116 -
trunk/src/gui/widgets/qtoolbarseparator.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 ** -
trunk/src/gui/widgets/qtoolbarseparator_p.h
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 ** -
trunk/src/gui/widgets/qtoolbox.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 ** … … 253 253 \brief The QToolBox class provides a column of tabbed widget items. 254 254 255 \mainclass 255 256 256 \ingroup basicwidgets 257 257 … … 803 803 /*! 804 804 \fn int QToolBox::margin() const 805 Returns the wi th of thethe margin around the contents of the widget.805 Returns the width of the margin around the contents of the widget. 806 806 807 807 Use QWidget::getContentsMargins() instead. -
trunk/src/gui/widgets/qtoolbox.h
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 ** -
trunk/src/gui/widgets/qtoolbutton.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 ** … … 105 105 bool QToolButtonPrivate::hasMenu() const 106 106 { 107 Q_Q(const QToolButton);108 107 return ((defaultAction && defaultAction->menu()) 109 108 || (menuAction && menuAction->menu()) 110 || q->actions().size() > (defaultAction ? 1 : 0));109 || actions.size() > (defaultAction ? 1 : 0)); 111 110 } 112 111 #endif … … 118 117 119 118 \ingroup basicwidgets 120 \mainclass 119 121 120 122 121 A tool button is a special button that provides quick-access to … … 279 278 defaultAction = 0; 280 279 #ifndef QT_NO_TOOLBAR 281 if (qobject_cast<QToolBar*>( q->parentWidget()))280 if (qobject_cast<QToolBar*>(parent)) 282 281 autoRaise = true; 283 282 else … … 380 379 option->features |= QStyleOptionToolButton::HasMenu; 381 380 #endif 382 option->toolButtonStyle = d->toolButtonStyle; 381 if (d->toolButtonStyle == Qt::ToolButtonFollowStyle) { 382 option->toolButtonStyle = Qt::ToolButtonStyle(style()->styleHint(QStyle::SH_ToolButtonStyle, option, this)); 383 } else 384 option->toolButtonStyle = d->toolButtonStyle; 385 386 if (option->toolButtonStyle == Qt::ToolButtonTextBesideIcon) { 387 // If the action is not prioritized, remove the text label to save space 388 if (d->defaultAction && d->defaultAction->priority() < QAction::NormalPriority) 389 option->toolButtonStyle = Qt::ToolButtonIconOnly; 390 } 391 383 392 if (d->icon.isNull() && d->arrowType == Qt::NoArrow && !forceNoText) { 384 393 if (!d->text.isEmpty()) … … 478 487 The default is Qt::ToolButtonIconOnly. 479 488 489 To have the style of toolbuttons follow the system settings (as available 490 in GNOME and KDE desktop environments), set this property to Qt::ToolButtonFollowStyle. 491 480 492 QToolButton automatically connects this slot to the relevant 481 493 signal in the QMainWindow in which is resides. … … 860 872 if (!hasMenu()) 861 873 return; // no menu to show 862 863 if (delay > 0 && popupMode == QToolButton::DelayedPopup) 874 if (popupMode == QToolButton::MenuButtonPopup) 875 return; 876 else if (delay > 0 && !popupTimer.isActive() && popupMode == QToolButton::DelayedPopup) 864 877 popupTimer.start(delay, q); 865 878 else if (delay == 0 || popupMode == QToolButton::InstantPopup) … … 884 897 actualMenu = new QMenu(q); 885 898 mustDeleteActualMenu = true; 886 QList<QAction*> actions = q->actions();887 899 for(int i = 0; i < actions.size(); i++) 888 900 actualMenu->addAction(actions.at(i)); … … 892 904 bool horizontal = true; 893 905 #if !defined(QT_NO_TOOLBAR) 894 QToolBar *tb = qobject_cast<QToolBar*>( q->parentWidget());906 QToolBar *tb = qobject_cast<QToolBar*>(parent); 895 907 if (tb && tb->orientation() == Qt::Vertical) 896 908 horizontal = false; 897 909 #endif 898 910 QPoint p; 899 QRect screen = qApp->desktop()->availableGeometry(q);911 QRect screen = QApplication::desktop()->availableGeometry(q); 900 912 QSize sh = ((QToolButton*)(QMenu*)actualMenu)->receivers(SIGNAL(aboutToShow()))? QSize() : actualMenu->sizeHint(); 901 913 QRect rect = q->rect(); -
trunk/src/gui/widgets/qtoolbutton.h
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 ** -
trunk/src/gui/widgets/qvalidator.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 ** … … 55 55 \class QValidator 56 56 \brief The QValidator class provides validation of input text. 57 58 \ingroup misc59 \mainclass60 57 61 58 The class itself is abstract. Two subclasses, \l QIntValidator and … … 91 88 92 89 \i For an editable combobox that accepts URLs, any well-formed URL 93 is \l Acceptable, "http:// qtsoftware.com/," is \l Intermediate90 is \l Acceptable, "http://example.com/," is \l Intermediate 94 91 (it might be a cut and paste action that accidentally took in a 95 92 comma at the end), the empty string is \l Intermediate (the user … … 99 96 \i For a spin box that accepts lengths, "11cm" and "1in" are \l 100 97 Acceptable, "11" and the empty string are \l Intermediate, and 101 "http:// qtsoftware.com" and "hour" are \l Invalid.98 "http://example.com" and "hour" are \l Invalid. 102 99 103 100 \endlist … … 247 244 a string contains a valid integer within a specified range. 248 245 249 \ingroup misc250 251 246 Example of use: 252 247 … … 371 366 return 1; 372 367 return (int)log10(double(n)) + 1; 373 } ;368 } 374 369 375 370 static qlonglong pow10(int exp) … … 497 492 \brief The QDoubleValidator class provides range checking of 498 493 floating-point numbers. 499 500 \ingroup misc501 494 502 495 QDoubleValidator provides an upper bound, a lower bound, and a … … 644 637 numMode = QLocalePrivate::DoubleScientificMode; 645 638 break; 646 } ;639 } 647 640 648 641 QByteArray buff; … … 767 760 \brief The QRegExpValidator class is used to check a string 768 761 against a regular expression. 769 770 \ingroup misc771 762 772 763 QRegExpValidator uses a regular expression (regexp) to -
trunk/src/gui/widgets/qvalidator.h
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 ** … … 62 62 Q_OBJECT 63 63 public: 64 explicit QValidator(QObject * parent );64 explicit QValidator(QObject * parent = 0); 65 65 ~QValidator(); 66 66 … … 101 101 102 102 public: 103 explicit QIntValidator(QObject * parent );103 explicit QIntValidator(QObject * parent = 0); 104 104 QIntValidator(int bottom, int top, QObject * parent); 105 105 ~QIntValidator(); -
trunk/src/gui/widgets/qwidgetanimator.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 ** 40 40 ****************************************************************************/ 41 41 42 #include <QtCore/qtimer.h> 43 #include <QtCore/qdatetime.h> 42 #include <QtCore/qpropertyanimation.h> 44 43 #include <QtGui/qwidget.h> 45 #include <QtGui/qtextedit.h> 46 #include <QtGui/private/qwidget_p.h> 47 #include <qdebug.h> 44 #include <QtGui/private/qmainwindowlayout_p.h> 48 45 49 46 #include "qwidgetanimator_p.h" … … 51 48 QT_BEGIN_NAMESPACE 52 49 53 static const int g_animation_steps = 12; 54 static const int g_animation_interval = 16; 55 56 // 1000 * (x/(1 + x*x) + 0.5) on interval [-1, 1] 57 static const int g_animate_function[] = 50 QWidgetAnimator::QWidgetAnimator(QMainWindowLayout *layout) : m_mainWindowLayout(layout) 58 51 { 59 0, 1, 5, 12, 23, 38, 58, 84, 116, 155, 199, 251, 307, 368,60 433, 500, 566, 631, 692, 748, 799, 844, 883, 915, 941, 961,61 976, 987, 994, 998, 100062 };63 static const int g_animate_function_points = sizeof(g_animate_function)/sizeof(int);64 65 static inline int animateHelper(int start, int stop, int step, int steps)66 {67 if (start == stop)68 return start;69 if (step == 0)70 return start;71 if (step == steps)72 return stop;73 74 int x = g_animate_function_points*step/(steps + 1);75 return start + g_animate_function[x]*(stop - start)/1000;76 }77 78 QWidgetAnimator::QWidgetAnimator(QObject *parent)79 : QObject(parent)80 {81 m_time = new QTime();82 m_timer = new QTimer(this);83 m_timer->setInterval(g_animation_interval);84 connect(m_timer, SIGNAL(timeout()), this, SLOT(animationStep()));85 }86 87 QWidgetAnimator::~QWidgetAnimator()88 {89 delete m_time;90 52 } 91 53 92 54 void QWidgetAnimator::abort(QWidget *w) 93 55 { 94 if (m_animation_map.remove(w) == 0) 56 #ifndef QT_NO_ANIMATION 57 AnimationMap::iterator it = m_animation_map.find(w); 58 if (it == m_animation_map.end()) 95 59 return; 96 if (m_animation_map.isEmpty()) { 97 m_timer->stop(); 98 emit finishedAll(); 99 } 60 QPropertyAnimation *anim = *it; 61 m_animation_map.erase(it); 62 anim->stop(); 63 #ifndef QT_NO_MAINWINDOW 64 m_mainWindowLayout->animationFinished(w); 65 #endif 66 #else 67 Q_UNUSED(w); //there is no animation to abort 68 #endif //QT_NO_ANIMATION 100 69 } 70 71 #ifndef QT_NO_ANIMATION 72 void QWidgetAnimator::animationFinished() 73 { 74 QPropertyAnimation *anim = qobject_cast<QPropertyAnimation*>(sender()); 75 abort(static_cast<QWidget*>(anim->targetObject())); 76 } 77 #endif //QT_NO_ANIMATION 101 78 102 79 void QWidgetAnimator::animate(QWidget *widget, const QRect &_final_geometry, bool animate) 103 80 { 104 QRect final_geometry = _final_geometry;105 106 81 QRect r = widget->geometry(); 107 82 if (r.right() < 0 || r.bottom() < 0) 108 83 r = QRect(); 109 84 110 if (r.isNull() || final_geometry.isNull()) 111 animate = false; 85 animate = animate && !r.isNull() && !_final_geometry.isNull(); 112 86 87 // might make the wigdet go away by sending it to negative space 88 const QRect final_geometry = _final_geometry.isValid() || widget->isWindow() ? _final_geometry : 89 QRect(QPoint(-500 - widget->width(), -500 - widget->height()), widget->size()); 90 91 #ifndef QT_NO_ANIMATION 113 92 AnimationMap::const_iterator it = m_animation_map.constFind(widget); 114 if (it == m_animation_map.constEnd()) { 115 if (r == final_geometry) { 116 emit finished(widget); 117 return; 118 } 119 } else { 120 if ((*it).r2 == final_geometry) 121 return; 122 } 93 if (it != m_animation_map.constEnd() && (*it)->endValue().toRect() == final_geometry) 94 return; 123 95 124 if (animate) { 125 AnimationItem item(widget, r, final_geometry); 126 m_animation_map[widget] = item; 127 if (!m_timer->isActive()) { 128 m_timer->start(); 129 m_time->start(); 130 } 131 } else { 132 m_animation_map.remove(widget); 133 if (m_animation_map.isEmpty()) 134 m_timer->stop(); 135 136 if (!final_geometry.isValid() && !widget->isWindow()) { 137 // Make the wigdet go away by sending it to negative space 138 QSize s = widget->size(); 139 final_geometry = QRect(-500 - s.width(), -500 - s.height(), s.width(), s.height()); 140 } 141 widget->setGeometry(final_geometry); 142 143 emit finished(widget); 144 145 if (m_animation_map.isEmpty()) 146 emit finishedAll(); 147 148 return; 149 } 150 } 151 152 void QWidgetAnimator::animationStep() 153 { 154 int steps = (1 + m_time->restart())/g_animation_interval; 155 AnimationMap::iterator it = m_animation_map.begin(); 156 while (it != m_animation_map.end()) { 157 AnimationItem &item = *it; 158 159 item.step = qMin(item.step + steps, g_animation_steps); 160 161 int x = animateHelper(item.r1.left(), item.r2.left(), 162 item.step, g_animation_steps); 163 int y = animateHelper(item.r1.top(), item.r2.top(), 164 item.step, g_animation_steps); 165 int w = animateHelper(item.r1.width(), item.r2.width(), 166 item.step, g_animation_steps); 167 int h = animateHelper(item.r1.height(), item.r2.height(), 168 item.step, g_animation_steps); 169 170 item.widget->setGeometry(x, y, w, h); 171 172 if (item.step == g_animation_steps) { 173 emit finished(item.widget); 174 AnimationMap::iterator tmp = it; 175 ++it; 176 m_animation_map.erase(tmp); 177 } else { 178 ++it; 179 } 180 } 181 182 if (m_animation_map.isEmpty()) { 183 m_timer->stop(); 184 emit finishedAll(); 185 } 96 QPropertyAnimation *anim = new QPropertyAnimation(widget, "geometry", widget); 97 anim->setDuration(animate ? 200 : 0); 98 anim->setEasingCurve(QEasingCurve::InOutQuad); 99 anim->setEndValue(final_geometry); 100 m_animation_map[widget] = anim; 101 connect(anim, SIGNAL(finished()), SLOT(animationFinished())); 102 anim->start(QPropertyAnimation::DeleteWhenStopped); 103 #else 104 //we do it in one shot 105 widget->setGeometry(final_geometry); 106 #ifndef QT_NO_MAINWINDOW 107 m_mainWindowLayout->animationFinished(widget); 108 #endif //QT_NO_MAINWINDOW 109 #endif //QT_NO_ANIMATION 186 110 } 187 111 188 112 bool QWidgetAnimator::animating() const 189 113 { 190 return m_timer->isActive(); 191 } 192 193 bool QWidgetAnimator::animating(QWidget *widget) 194 { 195 return m_animation_map.contains(widget); 114 return !m_animation_map.isEmpty(); 196 115 } 197 116 -
trunk/src/gui/widgets/qwidgetanimator_p.h
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 ** … … 55 55 56 56 #include <qobject.h> 57 #include <qrect.h>58 57 #include <qmap.h> 59 58 … … 61 60 62 61 class QWidget; 63 class QTimer; 64 class QTime; 62 class QMainWindowLayout; 63 class QPropertyAnimation; 64 class QRect; 65 65 66 66 class QWidgetAnimator : public QObject … … 68 68 Q_OBJECT 69 69 public: 70 QWidgetAnimator(QObject *parent = 0); 71 ~QWidgetAnimator(); 70 QWidgetAnimator(QMainWindowLayout *layout); 72 71 void animate(QWidget *widget, const QRect &final_geometry, bool animate); 73 72 bool animating() const; 74 bool animating(QWidget *widget);75 73 76 74 void abort(QWidget *widget); 77 75 78 signals: 79 void finished(QWidget *widget); 80 void finishedAll(); 81 82 private slots: 83 void animationStep(); 76 #ifndef QT_NO_ANIMATION 77 private Q_SLOTS: 78 void animationFinished(); 79 #endif 84 80 85 81 private: 86 struct AnimationItem { 87 AnimationItem(QWidget *_widget = 0, const QRect &_r1 = QRect(), 88 const QRect &_r2 = QRect()) 89 : widget(_widget), r1(_r1), r2(_r2), step(0) {} 90 QWidget *widget; 91 QRect r1, r2; 92 int step; 93 }; 94 typedef QMap<QWidget*, AnimationItem> AnimationMap; 82 typedef QMap<QWidget*, QPropertyAnimation*> AnimationMap; 95 83 AnimationMap m_animation_map; 96 QTimer *m_timer; 97 QTime *m_time; 84 QMainWindowLayout *m_mainWindowLayout; 98 85 }; 99 86 -
trunk/src/gui/widgets/qwidgetresizehandler.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 ** … … 259 259 #ifdef Q_WS_X11 260 260 // Workaround for window managers which refuse to move a tool window partially offscreen. 261 QRect desktop = qApp->desktop()->availableGeometry(widget);261 QRect desktop = QApplication::desktop()->availableGeometry(widget); 262 262 pp.rx() = qMax(pp.x(), desktop.left()); 263 263 pp.ry() = qMax(pp.y(), desktop.top()); -
trunk/src/gui/widgets/qwidgetresizehandler_p.h
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 ** -
trunk/src/gui/widgets/qworkspace.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 ** … … 111 111 helpEvent->pos(), this); 112 112 if (ctrl == QStyle::SC_MdiCloseButton) 113 QToolTip::showText(helpEvent->globalPos(), QWorkspace::tr("Close") );113 QToolTip::showText(helpEvent->globalPos(), QWorkspace::tr("Close"), this); 114 114 else if (ctrl == QStyle::SC_MdiMinButton) 115 QToolTip::showText(helpEvent->globalPos(), QWorkspace::tr("Minimize") );115 QToolTip::showText(helpEvent->globalPos(), QWorkspace::tr("Minimize"), this); 116 116 else if (ctrl == QStyle::SC_MdiNormalButton) 117 QToolTip::showText(helpEvent->globalPos(), QWorkspace::tr("Restore Down") );117 QToolTip::showText(helpEvent->globalPos(), QWorkspace::tr("Restore Down"), this); 118 118 else 119 119 QToolTip::hideText(); … … 398 398 pal.setColor(QPalette::Active, QPalette::HighlightedText, colorref2qrgb(GetSysColor(COLOR_CAPTIONTEXT))); 399 399 pal.setColor(QPalette::Inactive, QPalette::HighlightedText, colorref2qrgb(GetSysColor(COLOR_INACTIVECAPTIONTEXT))); 400 if (QSysInfo::WindowsVersion != QSysInfo::WV_95 && QSysInfo::WindowsVersion != QSysInfo::WV_NT) { 401 colorsInitialized = true; 402 BOOL gradient; 403 QT_WA({ 404 SystemParametersInfo(SPI_GETGRADIENTCAPTIONS, 0, &gradient, 0); 405 } , { 406 SystemParametersInfoA(SPI_GETGRADIENTCAPTIONS, 0, &gradient, 0); 407 }); 408 if (gradient) { 409 pal.setColor(QPalette::Active, QPalette::Base, colorref2qrgb(GetSysColor(COLOR_GRADIENTACTIVECAPTION))); 410 pal.setColor(QPalette::Inactive, QPalette::Base, colorref2qrgb(GetSysColor(COLOR_GRADIENTINACTIVECAPTION))); 411 } else { 412 pal.setColor(QPalette::Active, QPalette::Base, pal.color(QPalette::Active, QPalette::Highlight)); 413 pal.setColor(QPalette::Inactive, QPalette::Base, pal.color(QPalette::Inactive, QPalette::Highlight)); 414 } 400 401 colorsInitialized = true; 402 BOOL gradient = false; 403 SystemParametersInfo(SPI_GETGRADIENTCAPTIONS, 0, &gradient, 0); 404 405 if (gradient) { 406 pal.setColor(QPalette::Active, QPalette::Base, colorref2qrgb(GetSysColor(COLOR_GRADIENTACTIVECAPTION))); 407 pal.setColor(QPalette::Inactive, QPalette::Base, colorref2qrgb(GetSysColor(COLOR_GRADIENTINACTIVECAPTION))); 408 } else { 409 pal.setColor(QPalette::Active, QPalette::Base, pal.color(QPalette::Active, QPalette::Highlight)); 410 pal.setColor(QPalette::Inactive, QPalette::Base, pal.color(QPalette::Inactive, QPalette::Highlight)); 415 411 } 416 412 } … … 839 835 \brief The QWorkspace widget provides a workspace window that can be 840 836 used in an MDI application. 841 \ingroup application842 837 843 838 This class is deprecated. Use QMdiArea instead. -
trunk/src/gui/widgets/qworkspace.h
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 ** -
trunk/src/gui/widgets/widgets.pri
r2 r561 31 31 widgets/qlineedit.h \ 32 32 widgets/qlineedit_p.h \ 33 widgets/qlinecontrol_p.h \ 33 34 widgets/qmainwindow.h \ 34 35 widgets/qmainwindowlayout_p.h \ … … 38 39 widgets/qmdisubwindow_p.h \ 39 40 widgets/qmenu.h \ 41 widgets/qmenu_p.h \ 40 42 widgets/qmenubar.h \ 43 widgets/qmenubar_p.h \ 41 44 widgets/qmenudata.h \ 42 45 widgets/qprogressbar.h \ … … 80 83 widgets/qplaintextedit_p.h \ 81 84 widgets/qprintpreviewwidget.h 82 83 85 SOURCES += \ 84 86 widgets/qabstractbutton.cpp \ … … 100 102 widgets/qlabel.cpp \ 101 103 widgets/qlcdnumber.cpp \ 104 widgets/qlineedit_p.cpp \ 102 105 widgets/qlineedit.cpp \ 106 widgets/qlinecontrol.cpp \ 103 107 widgets/qmainwindow.cpp \ 104 108 widgets/qmainwindowlayout.cpp \ … … 141 145 widgets/qprintpreviewwidget.cpp 142 146 143 144 147 !embedded:mac { 145 148 HEADERS += widgets/qmacnativewidget_mac.h \ … … 161 164 !static: QMAKE_WRITE_DEFAULT_RC = 1 162 165 } 166 167 symbian*: { 168 SOURCES += widgets/qmenu_symbian.cpp 169 }
Note:
See TracChangeset
for help on using the changeset viewer.