From: vsr Date: Wed, 13 Apr 2011 07:24:07 +0000 (+0000) Subject: 0021219: [CEA 463] Add a preference to setOpaqueResize X-Git-Tag: V6_3_0a1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=875028ef371f5d6f5eef7a7d05ffe220d9e13a7f;p=modules%2Fgui.git 0021219: [CEA 463] Add a preference to setOpaqueResize --- diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index b30c2719a..cf22f0702 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -2633,6 +2633,7 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString if ( opaqueResize ) dopts |= QMainWindow::AnimatedDocks; else dopts &= ~QMainWindow::AnimatedDocks; desktop()->setDockOptions( dopts ); + desktop()->setOpaqueResize( opaqueResize ); if ( dynamic_cast( desktop() ) ) dynamic_cast( desktop() )->workstack()->setOpaqueResize( opaqueResize ); } @@ -2691,6 +2692,7 @@ void LightApp_Application::loadPreferences() if ( opaqueResize ) dopts |= QMainWindow::AnimatedDocks; else dopts &= ~QMainWindow::AnimatedDocks; desktop()->setDockOptions( dopts ); + desktop()->setOpaqueResize( opaqueResize ); if ( dynamic_cast( desktop() ) ) dynamic_cast( desktop() )->workstack()->setOpaqueResize( opaqueResize ); } diff --git a/src/Qtx/QtxMainWindow.cxx b/src/Qtx/QtxMainWindow.cxx index d3cb76621..8546d9668 100644 --- a/src/Qtx/QtxMainWindow.cxx +++ b/src/Qtx/QtxMainWindow.cxx @@ -19,18 +19,21 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +// File: QtxMainWindow.cxx +// Author: Sergey TELKOV -// File: QtxMainWindow.cxx -// Author: Sergey TELKOV -// #include "QtxMainWindow.h" #include "QtxToolBar.h" -#include "QtxResourceMgr.h" #include +#include +#include +#include #include #include +#include +#include #include #include @@ -93,6 +96,131 @@ bool QtxMainWindow::Filter::eventFilter( QObject* o, QEvent* e ) return QObject::eventFilter( o, e ); } +/*! + \class QtxMainWindow::Resizer + \internal + \brief Internal object used to resize dock widgets. +*/ + +class QtxMainWindow::Resizer : public QObject +{ +public: + Resizer( const QPoint&, const Qt::Orientation, QtxMainWindow* ); + virtual ~Resizer(); + + QMouseEvent* finalEvent() const; + void setFinalEvent( QMouseEvent* ); + + void setPosition( const QPoint& ); + virtual bool eventFilter( QObject*, QEvent* ); + +private: + void setFilters( bool ); + +private: + QPoint myPos; + QMainWindow* myMain; + QRubberBand* myRubber; + Qt::Orientation myOrient; + QMouseEvent* myFinEvent; +}; + +/*! + \brief Constructor. + \param mw parent main window +*/ +QtxMainWindow::Resizer::Resizer( const QPoint& p, const Qt::Orientation o, QtxMainWindow* mw ) +: QObject( mw ), + myMain( mw ), + myOrient( o ), + myFinEvent( 0 ) +{ + setFilters( true ); + + myRubber = new QRubberBand( QRubberBand::Line, 0 ); + + setPosition( p ); + + myRubber->show(); +}; + +/*! + \brief Destructor. +*/ +QtxMainWindow::Resizer::~Resizer() +{ + delete myRubber; + + setFilters( false ); +} + +void QtxMainWindow::Resizer::setPosition( const QPoint& pos ) +{ + myPos = pos; + if ( myRubber ) { + QRect r; + QPoint min = myMain->mapToGlobal( myMain->rect().topLeft() ); + QPoint max = myMain->mapToGlobal( myMain->rect().bottomRight() ); + if ( myOrient == Qt::Horizontal ) { + int p = qMax( qMin( myPos.y(), max.y() ), min.y() ); + r = QRect( myMain->mapToGlobal( QPoint( 0, 0 ) ).x(), p - 1, myMain->width(), 3 ); + } + else { + int p = qMax( qMin( myPos.x(), max.x() ), min.x() ); + r = QRect( p - 1, myMain->mapToGlobal( QPoint( 0, 0 ) ).y(), 3, myMain->height() ); + } + myRubber->setGeometry( r ); + } +} + +QMouseEvent* QtxMainWindow::Resizer::finalEvent() const +{ + return myFinEvent; +} + +void QtxMainWindow::Resizer::setFinalEvent( QMouseEvent* e ) +{ + myFinEvent = e; +} + +/*! + \brief Event filter. + + \param o recevier object + \param e event +*/ +bool QtxMainWindow::Resizer::eventFilter( QObject* o, QEvent* e ) +{ + if ( e->type() == QEvent::Timer ) { + if ( !finalEvent() ) + return true; + + setFilters( false ); + QApplication::postEvent( myMain, finalEvent() ); + myFinEvent = 0; + deleteLater(); + } + + return QObject::eventFilter( o, e ); +} + +void QtxMainWindow::Resizer::setFilters( bool on ) +{ + if ( myMain ) { + if ( on ) + myMain->layout()->installEventFilter( this ); + else + myMain->layout()->removeEventFilter( this ); + } + + QTimer* t = qFindChild( myMain->layout() ); + if ( t ) { + if ( on ) + t->installEventFilter( this ); + else + t->removeEventFilter( this ); + } +} /*! \class QtxMainWindow @@ -108,11 +236,14 @@ bool QtxMainWindow::Filter::eventFilter( QObject* o, QEvent* e ) QtxMainWindow::QtxMainWindow( QWidget* parent, Qt::WindowFlags f ) : QMainWindow( parent, f ), myMenuBar( 0 ), - myStatusBar( 0 ) + myStatusBar( 0 ), + myOpaque( true ), + myResizer( 0 ), + myMouseMove( 0 ) { - //rnv: Enables tooltips for inactive windows. - //rnv: For details see http://bugtracker.opencascade.com/show_bug.cgi?id=20893 - setAttribute(Qt::WA_AlwaysShowToolTips); + //rnv: Enables tooltips for inactive windows. + //rnv: For details see http://bugtracker.opencascade.com/show_bug.cgi?id=20893 + setAttribute(Qt::WA_AlwaysShowToolTips); } /*! @@ -220,6 +351,16 @@ void QtxMainWindow::setDockableStatusBar( const bool on ) } } +bool QtxMainWindow::isOpaqueResize() const +{ + return myOpaque; +} + +void QtxMainWindow::setOpaqueResize( bool on ) +{ + myOpaque = on; +} + /*! \brief Dump main window geometry to the string. \return string represenation of the window geometry @@ -313,7 +454,7 @@ void QtxMainWindow::retrieveGeometry( const QString& str ) if ( xOk ) { if ( xp ) - x = screen.width() * qMax( qMin( x, 100 ), 0 ) / 100; + x = screen.width() * qMax( qMin( x, 100 ), 0 ) / 100; x = ( xs > 0 ? x : screen.right() - x - rect.width() ) + frameGeometry().x() - geometry().x(); } @@ -324,7 +465,7 @@ void QtxMainWindow::retrieveGeometry( const QString& str ) if ( yOk ) { if ( yp ) - y = screen.height() * qMax( qMin( y, 100 ), 0 ) / 100; + y = screen.height() * qMax( qMin( y, 100 ), 0 ) / 100; y = ( ys > 0 ? y : screen.bottom() - y - rect.height() ) + frameGeometry().y() - geometry().y(); } @@ -417,3 +558,53 @@ void QtxMainWindow::onDestroyed( QObject* obj ) } } +bool QtxMainWindow::event( QEvent* e ) +{ + if ( myResizer && e->type() == QEvent::MouseButtonRelease ) { + if ( myMouseMove ) { + QMainWindow::event( myMouseMove ); + delete myMouseMove; + myMouseMove = 0; + } + + QMouseEvent* me = static_cast( e ); + myResizer->setFinalEvent( new QMouseEvent( me->type(), me->pos(), me->globalPos(), + me->button(), me->buttons(), me->modifiers() ) ); + myResizer = 0; + return true; + } + + if ( myResizer && e->type() == QEvent::MouseMove ) { + QMouseEvent* me = static_cast( e ); + myMouseMove = new QMouseEvent( me->type(), me->pos(), me->globalPos(), + me->button(), me->buttons(), me->modifiers() ); + myResizer->setPosition( me->globalPos() ); + } + + bool ok = QMainWindow::event( e ); + + if ( e->type() == QEvent::MouseButtonPress ) { + if ( !isOpaqueResize() && ok && testAttribute( Qt::WA_SetCursor ) ) { + bool status = true; + Qt::Orientation o; + switch ( cursor().shape() ) + { + case Qt::SplitHCursor: + o = Qt::Vertical; + break; + case Qt::SplitVCursor: + o = Qt::Horizontal; + break; + default: + status = false; + break; + } + if ( status ) { + QMouseEvent* me = static_cast( e ); + myResizer = new Resizer( me->globalPos(), o, this ); + } + } + } + + return ok; +} diff --git a/src/Qtx/QtxMainWindow.h b/src/Qtx/QtxMainWindow.h index 305e519c4..79fcda482 100644 --- a/src/Qtx/QtxMainWindow.h +++ b/src/Qtx/QtxMainWindow.h @@ -19,10 +19,9 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +// File: QtxMainWindow.h +// Author: Sergey TELKOV -// File: QtxMainWindow.h -// Author: Sergey TELKOV -// #ifndef QTXMAINWINDOW_H #define QTXMAINWINDOW_H @@ -37,11 +36,15 @@ class QTX_EXPORT QtxMainWindow : public QMainWindow Q_OBJECT class Filter; + class Resizer; public: QtxMainWindow( QWidget* = 0, Qt::WindowFlags = 0 ); virtual ~QtxMainWindow(); + bool isOpaqueResize() const; + void setOpaqueResize( bool ); + bool isDockableMenuBar() const; void setDockableMenuBar( const bool ); @@ -51,6 +54,9 @@ public: QString storeGeometry() const; void retrieveGeometry( const QString& ); +protected: + virtual bool event( QEvent* ); + private slots: void onDestroyed( QObject* ); @@ -60,6 +66,10 @@ private: private: QToolBar* myMenuBar; //!< dockable menu bar QToolBar* myStatusBar; //!< dockable status bar + + bool myOpaque; + Resizer* myResizer; + QMouseEvent* myMouseMove; }; #endif // QTXMAINWINDOW_H diff --git a/src/SUIT/SUIT_Desktop.cxx b/src/SUIT/SUIT_Desktop.cxx index ad4b310b5..2719e2ab5 100755 --- a/src/SUIT/SUIT_Desktop.cxx +++ b/src/SUIT/SUIT_Desktop.cxx @@ -88,7 +88,7 @@ bool SUIT_Desktop::event( QEvent* e ) break; } - return QMainWindow::event( e ); + return QtxMainWindow::event( e ); } /*!