Changeset 561 for trunk/src/gui/widgets/qdockwidget.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/gui/widgets/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
Note:
See TracChangeset
for help on using the changeset viewer.