src/gui/widgets/qsizegrip.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    97     int d;
    97     int d;
    98     int dxMax;
    98     int dxMax;
    99     int dyMax;
    99     int dyMax;
   100     Qt::Corner m_corner;
   100     Qt::Corner m_corner;
   101     bool gotMousePress;
   101     bool gotMousePress;
       
   102     QWidget *tlw;
   102 #ifdef Q_WS_MAC
   103 #ifdef Q_WS_MAC
   103     void updateMacSizer(bool hide) const;
   104     void updateMacSizer(bool hide) const;
   104 #endif
   105 #endif
   105     Qt::Corner corner() const;
   106     Qt::Corner corner() const;
   106     inline bool atBottom() const
   107     inline bool atBottom() const
   109     }
   110     }
   110 
   111 
   111     inline bool atLeft() const
   112     inline bool atLeft() const
   112     {
   113     {
   113         return m_corner == Qt::BottomLeftCorner || m_corner == Qt::TopLeftCorner;
   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 
   116     // This slot is invoked by QLayout when the size grip is added to
   130     // This slot is invoked by QLayout when the size grip is added to
   117     // a layout or reparented after the tlw is shown. This re-implementation is basically
   131     // a layout or reparented after the tlw is shown. This re-implementation is basically
   118     // the same as QWidgetPrivate::_q_showIfNotHidden except that it checks
   132     // the same as QWidgetPrivate::_q_showIfNotHidden except that it checks
   119     // for Qt::WindowFullScreen and Qt::WindowMaximized as well.
   133     // for Qt::WindowFullScreen and Qt::WindowMaximized as well.
   120     void _q_showIfNotHidden()
   134     void _q_showIfNotHidden()
   121     {
   135     {
   122         Q_Q(QSizeGrip);
   136         Q_Q(QSizeGrip);
   123         bool showSizeGrip = !(q->isHidden() && q->testAttribute(Qt::WA_WState_ExplicitShowHide));
   137         bool showSizeGrip = !(q->isHidden() && q->testAttribute(Qt::WA_WState_ExplicitShowHide));
   124         QWidget *tlw = qt_sizegrip_topLevelWidget(q);
   138         updateTopLevelWidget();
   125         if (tlw && showSizeGrip) {
   139         if (tlw && showSizeGrip) {
   126             Qt::WindowStates sizeGripNotVisibleState = Qt::WindowFullScreen;
   140             Qt::WindowStates sizeGripNotVisibleState = Qt::WindowFullScreen;
   127 #ifndef Q_WS_MAC
   141 #ifndef Q_WS_MAC
   128             sizeGripNotVisibleState |= Qt::WindowMaximized;
   142             sizeGripNotVisibleState |= Qt::WindowMaximized;
   129 #endif
   143 #endif
   230 void QSizeGripPrivate::init()
   244 void QSizeGripPrivate::init()
   231 {
   245 {
   232     Q_Q(QSizeGrip);
   246     Q_Q(QSizeGrip);
   233     dxMax = 0;
   247     dxMax = 0;
   234     dyMax = 0;
   248     dyMax = 0;
       
   249     tlw = 0;
   235     m_corner = q->isLeftToRight() ? Qt::BottomRightCorner : Qt::BottomLeftCorner;
   250     m_corner = q->isLeftToRight() ? Qt::BottomRightCorner : Qt::BottomLeftCorner;
   236     gotMousePress = false;
   251     gotMousePress = false;
   237 
   252 
   238 #if !defined(QT_NO_CURSOR) && !defined(Q_WS_MAC)
   253 #if !defined(QT_NO_CURSOR) && !defined(Q_WS_MAC)
   239     q->setCursor(m_corner == Qt::TopLeftCorner || m_corner == Qt::BottomRightCorner
   254     q->setCursor(m_corner == Qt::TopLeftCorner || m_corner == Qt::BottomRightCorner
   240                  ? Qt::SizeFDiagCursor : Qt::SizeBDiagCursor);
   255                  ? Qt::SizeFDiagCursor : Qt::SizeBDiagCursor);
   241 #endif
   256 #endif
   242     q->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed));
   257     q->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed));
   243     QWidget *tlw = qt_sizegrip_topLevelWidget(q);
   258     updateTopLevelWidget();
   244     tlw->installEventFilter(q);
       
   245 }
   259 }
   246 
   260 
   247 
   261 
   248 /*!
   262 /*!
   249     Destroys this size grip.
   263     Destroys this size grip.
   522 }
   536 }
   523 
   537 
   524 /*! \reimp */
   538 /*! \reimp */
   525 bool QSizeGrip::eventFilter(QObject *o, QEvent *e)
   539 bool QSizeGrip::eventFilter(QObject *o, QEvent *e)
   526 {
   540 {
       
   541     Q_D(QSizeGrip);
   527     if ((isHidden() && testAttribute(Qt::WA_WState_ExplicitShowHide))
   542     if ((isHidden() && testAttribute(Qt::WA_WState_ExplicitShowHide))
   528         || e->type() != QEvent::WindowStateChange) {
   543         || e->type() != QEvent::WindowStateChange
       
   544 		|| o != d->tlw) {
   529         return QWidget::eventFilter(o, e);
   545         return QWidget::eventFilter(o, e);
   530     }
   546     }
   531     QWidget *tlw = qt_sizegrip_topLevelWidget(this);
       
   532     if (o != tlw)
       
   533         return QWidget::eventFilter(o, e);
       
   534     Qt::WindowStates sizeGripNotVisibleState = Qt::WindowFullScreen;
   547     Qt::WindowStates sizeGripNotVisibleState = Qt::WindowFullScreen;
   535 #ifndef Q_WS_MAC
   548 #ifndef Q_WS_MAC
   536     sizeGripNotVisibleState |= Qt::WindowMaximized;
   549     sizeGripNotVisibleState |= Qt::WindowMaximized;
   537 #endif
   550 #endif
   538     // Don't show the size grip if the tlw is maximized or in full screen mode.
   551     // Don't show the size grip if the tlw is maximized or in full screen mode.
   539     setVisible(!(tlw->windowState() & sizeGripNotVisibleState));
   552     setVisible(!(d->tlw->windowState() & sizeGripNotVisibleState));
   540     setAttribute(Qt::WA_WState_ExplicitShowHide, false);
   553     setAttribute(Qt::WA_WState_ExplicitShowHide, false);
   541     return QWidget::eventFilter(o, e);
   554     return QWidget::eventFilter(o, e);
   542 }
   555 }
   543 
   556 
   544 /*!
   557 /*!