From: vsr Date: Tue, 15 May 2007 06:59:49 +0000 (+0000) Subject: Porting to Qt4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5b244e3980355be565eff44522dfba41fde9f956;p=modules%2Fgui.git Porting to Qt4 --- diff --git a/src/Qtx/QtxDirListEditor.cxx b/src/Qtx/QtxDirListEditor.cxx index cd4bb9fcf..770cc58a0 100644 --- a/src/Qtx/QtxDirListEditor.cxx +++ b/src/Qtx/QtxDirListEditor.cxx @@ -242,7 +242,7 @@ bool QtxDirListEditor::validate( const bool quietMode ) { QString dirPath = QFileInfo( myEdit->text().stripWhiteSpace() ).filePath(); /* -#ifndef WNT +#ifndef WIN32 if ( dirPath.startsWith( "~") ) { dirPath = dirPath.remove(0,1); QString user; diff --git a/src/Qtx/QtxDockWindow.cxx b/src/Qtx/QtxDockWindow.cxx deleted file mode 100644 index da6f5cc55..000000000 --- a/src/Qtx/QtxDockWindow.cxx +++ /dev/null @@ -1,412 +0,0 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// -// File: QtxDockWindow.cxx -// Author: Sergey TELKOV - -#include "QtxDockWindow.h" - -#include -#include -#include -#include -#include - -/*! - \class QtxDockWindow::Watcher [Internal] - Internal object with event filter. -*/ -class QtxDockWindow::Watcher : public QObject -{ -public: - Watcher( QtxDockWindow* ); - - void shown( QtxDockWindow* ); - void hided( QtxDockWindow* ); - - virtual bool eventFilter( QObject*, QEvent* ); - -protected: - virtual void customEvent( QCustomEvent* ); - -private: - void installFilters(); - - void showContainer(); - void hideContainer(); - - void updateIcon(); - void updateCaption(); - void updateVisibility(); - -private: - QtxDockWindow* myCont; - bool myState; - bool myEmpty; - bool myVisible; -}; - -/*! - Constructor -*/ -QtxDockWindow::Watcher::Watcher( QtxDockWindow* cont ) -: QObject( cont ), myCont( cont ), -myState( true ), -myEmpty( true ) -{ - if ( myCont->mainWindow() ) - myState = myCont->mainWindow()->appropriate( myCont ); - - myCont->installEventFilter( this ); - myVisible = myCont->isVisibleTo( myCont->parentWidget() ); - - installFilters(); -} - -/*! - Custom event filter -*/ -bool QtxDockWindow::Watcher::eventFilter( QObject* o, QEvent* e ) -{ - if ( o == myCont && - ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent || - e->type() == QEvent::Hide || e->type() == QEvent::HideToParent || - e->type() == QEvent::ChildInserted ) ) - QApplication::postEvent( this, new QCustomEvent( QEvent::User ) ); - - if ( o != myCont && e->type() == QEvent::IconChange ) - updateIcon(); - - if ( o != myCont && e->type() == QEvent::CaptionChange ) - updateCaption(); - - if ( ( o != myCont && ( e->type() == QEvent::Hide || e->type() == QEvent::HideToParent ) ) || - ( o == myCont && ( e->type() == QEvent::ChildRemoved ) ) || - ( e->type() == QEvent::Show || e->type() == QEvent::ShowToParent ) ) - updateVisibility(); - - return false; -} - -/*! - Sets internal status to shown -*/ -void QtxDockWindow::Watcher::shown( QtxDockWindow* dw ) -{ - if ( dw != myCont ) - return; - - myVisible = true; -} - -/*! - Sets internal status to hidden -*/ -void QtxDockWindow::Watcher::hided( QtxDockWindow* dw ) -{ - if ( dw != myCont ) - return; - - myVisible = false; -} - -/*! - Shows corresponding dock window -*/ -void QtxDockWindow::Watcher::showContainer() -{ - if ( !myCont ) - return; - - QtxDockWindow* cont = myCont; - myCont = 0; - cont->show(); - myCont = cont; -} - -/*! - Hides corresponding dock window -*/ -void QtxDockWindow::Watcher::hideContainer() -{ - if ( !myCont ) - return; - - QtxDockWindow* cont = myCont; - myCont = 0; - cont->hide(); - myCont = cont; -} - -/*! - Event filter of custom events -*/ -void QtxDockWindow::Watcher::customEvent( QCustomEvent* e ) -{ - installFilters(); - - updateIcon(); - updateCaption(); - updateVisibility(); -} - -/*! - Installs this object as event filter to all widgets inside corresponding main window -*/ -void QtxDockWindow::Watcher::installFilters() -{ - if ( !myCont ) - return; - - QBoxLayout* bl = myCont->boxLayout(); - if ( !bl ) - return; - - for ( QLayoutIterator it = bl->iterator(); it.current(); ++it ) - { - if ( it.current()->widget() ) - it.current()->widget()->installEventFilter( this ); - } -} - -/*! - Updates visibility of all widgets inside corresponding main window -*/ -void QtxDockWindow::Watcher::updateVisibility() -{ - if ( !myCont ) - return; - - QBoxLayout* bl = myCont->boxLayout(); - if ( !bl ) - return; - - bool vis = false; - for ( QLayoutIterator it = bl->iterator(); it.current() && !vis; ++it ) - vis = it.current()->widget() && it.current()->widget()->isVisibleTo( myCont ); - - QMainWindow* mw = myCont->mainWindow(); - if ( mw && myEmpty == vis ) - { - myEmpty = !vis; - if ( !myEmpty ) - mw->setAppropriate( myCont, myState ); - else - { - myState = mw->appropriate( myCont ); - mw->setAppropriate( myCont, false ); - } - } - - vis = !myEmpty && myVisible; - if ( vis != myCont->isVisibleTo( myCont->parentWidget() ) ) - vis ? showContainer() : hideContainer(); -} - -/*! - Updates icon of corresponding main window -*/ -void QtxDockWindow::Watcher::updateIcon() -{ - if ( !myCont || !myCont->widget() ) - return; - - const QPixmap* ico = myCont->widget()->icon(); - myCont->setIcon( ico ? *ico : QPixmap() ); -} - -/*! - Updates caption of corresponding main window -*/ -void QtxDockWindow::Watcher::updateCaption() -{ - if ( myCont && myCont->widget() && !myCont->widget()->caption().isNull() ) - myCont->setCaption( myCont->widget()->caption() ); -} - -/*! - Constructor -*/ -QtxDockWindow::QtxDockWindow( Place p, QWidget* parent, const char* name, WFlags f ) -: QDockWindow( p, parent, name, f ), -myWatcher( 0 ), -myStretch( false ) -{ -} - -/*! - Constructor -*/ -QtxDockWindow::QtxDockWindow( const bool watch, QWidget* parent, const char* name, WFlags f ) -: QDockWindow( InDock, parent, name, f ), -myWatcher( 0 ), -myStretch( false ) -{ - if ( watch ) - myWatcher = new Watcher( this ); -} - -/*! - Constructor -*/ -QtxDockWindow::QtxDockWindow( QWidget* parent, const char* name, WFlags f ) -: QDockWindow( InDock, parent, name, f ), -myWatcher( 0 ), -myStretch( false ) -{ -} - -/*! - Destructor -*/ -QtxDockWindow::~QtxDockWindow() -{ -} - -/*! - Sets the dock window's main widget - \param wid - new main widget -*/ -void QtxDockWindow::setWidget( QWidget* wid ) -{ - if ( wid ) - { - if ( wid->parentWidget() != this ) - wid->reparent( this, QPoint( 0, 0 ), wid->isVisibleTo( wid->parentWidget() ) ); - if ( myWatcher ) - { - setCaption( wid->caption() ); - if ( wid->icon() ) - setIcon( *wid->icon() ); - } - } - - QDockWindow::setWidget( wid ); -} - -/*! - \return true if the dock window is stretchable -*/ -bool QtxDockWindow::isStretchable() const -{ - return myStretch; -} - -/*! - Sets the dock window "stretchable" state - \param on - new state -*/ -void QtxDockWindow::setStretchable( const bool on ) -{ - if ( myStretch == on ) - return; - - myStretch = on; - - boxLayout()->setStretchFactor( widget(), myStretch ? 1 : 0 ); - - if ( myStretch != isHorizontalStretchable() || - myStretch != isVerticalStretchable() ) - { - if ( orientation() == Horizontal ) - setHorizontalStretchable( myStretch ); - else - setVerticalStretchable( myStretch ); - } -} - -/*! - \return the recommended size for the widget -*/ -QSize QtxDockWindow::sizeHint() const -{ - QSize sz = QDockWindow::sizeHint(); - - if ( place() == InDock && isStretchable() && area() ) - { - if ( orientation() == Horizontal ) - sz.setWidth( area()->width() ); - else - sz.setHeight( area()->height() ); - } - - return sz; -} - -/*! - \return the recommended minimum size for the widget -*/ -QSize QtxDockWindow::minimumSizeHint() const -{ - QSize sz = QDockWindow::minimumSizeHint(); - - if ( orientation() == Horizontal ) - sz = QSize( 0, QDockWindow::minimumSizeHint().height() ); - else - sz = QSize( QDockWindow::minimumSizeHint().width(), 0 ); - - if ( place() == InDock && isStretchable() && area() ) - { - if ( orientation() == Horizontal ) - sz.setWidth( area()->width() ); - else - sz.setHeight( area()->height() ); - } - - return sz; -} - -/*! - \return corresponding main window -*/ -QMainWindow* QtxDockWindow::mainWindow() const -{ - QMainWindow* mw = 0; - - QWidget* wid = parentWidget(); - while ( !mw && wid ) - { - if ( wid->inherits( "QMainWindow" ) ) - mw = (QMainWindow*)wid; - wid = wid->parentWidget(); - } - - return mw; -} - -/*! - Shows window -*/ -void QtxDockWindow::show() -{ - if ( myWatcher ) - myWatcher->shown( this ); - - QDockWindow::show(); -} - -/*! - Hides window -*/ -void QtxDockWindow::hide() -{ - if ( myWatcher ) - myWatcher->hided( this ); - - QDockWindow::hide(); -} diff --git a/src/Qtx/QtxDockWindow.h b/src/Qtx/QtxDockWindow.h deleted file mode 100644 index 6aa0190e3..000000000 --- a/src/Qtx/QtxDockWindow.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// -// File: QtxDockWindow.h -// Author: Sergey TELKOV - -#include "Qtx.h" - -#include - -class QTX_EXPORT QtxDockWindow : public QDockWindow -{ - Q_OBJECT - - class Watcher; - -public: - QtxDockWindow( Place = InDock, QWidget* = 0, const char* = 0, WFlags = 0 ); - QtxDockWindow( const bool, QWidget*, const char* = 0, WFlags = 0 ); - QtxDockWindow( QWidget*, const char* = 0, WFlags = 0 ); - virtual ~QtxDockWindow(); - - virtual void setWidget( QWidget* ); - - bool isStretchable() const; - virtual void setStretchable( const bool ); - - virtual QSize sizeHint() const; - virtual QSize minimumSizeHint() const; - - QMainWindow* mainWindow() const; - -public slots: - virtual void show(); - virtual void hide(); - -private: - Watcher* myWatcher; - bool myStretch; -}; diff --git a/src/Qtx/QtxWorkstack.cxx b/src/Qtx/QtxWorkstack.cxx index 7c6f234d9..4884ceaa1 100644 --- a/src/Qtx/QtxWorkstack.cxx +++ b/src/Qtx/QtxWorkstack.cxx @@ -61,37 +61,6 @@ private: \brief Workstack drag object */ -class QtxWorkstackDrag : public QObject -{ - Q_OBJECT - -public: - QtxWorkstackDrag( QtxWorkstack*, QtxWorkstackChild* ); - virtual ~QtxWorkstackDrag(); - - virtual bool eventFilter( QObject*, QEvent* ); - -private: - void dropWidget(); - - void updateTarget( const QPoint& ); - QtxWorkstackArea* detectTarget( const QPoint&, int& ) const; - void setTarget( QtxWorkstackArea*, const int ); - - void drawRect(); - void endDrawRect(); - void startDrawRect(); - -private: - QtxWorkstack* myWS; //!< parent workstack - QtxWorkstackChild* myChild; //!< workstack child widget container - - int myTab; //!< workarea tab page index - QtxWorkstackArea* myArea; //!< workarea - QRubberBand* myTabRect; //!< tab bar rubber band - QRubberBand* myAreaRect; //!< workarea rubber band -}; - /*! \brief Constructor. \param ws parent workstack diff --git a/src/Qtx/QtxWorkstack.h b/src/Qtx/QtxWorkstack.h index ad5cf59e4..6d472325e 100644 --- a/src/Qtx/QtxWorkstack.h +++ b/src/Qtx/QtxWorkstack.h @@ -34,6 +34,7 @@ class QAction; class QSplitter; class QPushButton; class QStackedWidget; +class QRubberBand; class QtxWorkstackArea; class QtxWorkstackDrag; @@ -327,6 +328,37 @@ private: bool myActive; //!< "active" status }; +class QtxWorkstackDrag : public QObject +{ + Q_OBJECT + +public: + QtxWorkstackDrag( QtxWorkstack*, QtxWorkstackChild* ); + virtual ~QtxWorkstackDrag(); + + virtual bool eventFilter( QObject*, QEvent* ); + +private: + void dropWidget(); + + void updateTarget( const QPoint& ); + QtxWorkstackArea* detectTarget( const QPoint&, int& ) const; + void setTarget( QtxWorkstackArea*, const int ); + + void drawRect(); + void endDrawRect(); + void startDrawRect(); + +private: + QtxWorkstack* myWS; //!< parent workstack + QtxWorkstackChild* myChild; //!< workstack child widget container + + int myTab; //!< workarea tab page index + QtxWorkstackArea* myArea; //!< workarea + QRubberBand* myTabRect; //!< tab bar rubber band + QRubberBand* myAreaRect; //!< workarea rubber band +}; + #ifdef WIN32 #pragma warning( default:4251 ) #endif