From 36f8cf92d254a3e44737a682696efcde23836996 Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 7 Oct 2008 05:12:31 +0000 Subject: [PATCH] Merging GUI_SRC module with the BR_HDF_dev_merged branch, which has been merged with the BR_V5_DEV branch. --- src/STD/STD.h | 16 +-- src/SUIT/SUIT.h | 22 +-- src/SUIT/SUIT.pro | 2 +- src/SUIT/SUIT_Application.cxx | 80 ++++++++--- src/SUIT/SUIT_Application.h | 11 +- src/SUIT/SUIT_ExceptionHandler.cxx | 9 ++ src/SUIT/SUIT_LicenseDlg.cxx | 215 +++++++++++++++++++++++++++++ src/SUIT/SUIT_LicenseDlg.h | 51 +++++++ src/SUIT/SUIT_Operation.cxx | 2 +- src/SUIT/SUIT_Operation.h | 2 +- src/SUIT/SUIT_ResourceMgr.h | 2 +- src/SUIT/SUIT_SelectionMgr.cxx | 3 +- src/SUIT/SUIT_SelectionMgr.h | 4 +- src/SUIT/SUIT_Session.cxx | 32 +++-- src/SUIT/SUIT_Session.h | 6 +- src/SUIT/SUIT_Study.cxx | 24 ++-- src/SUIT/SUIT_Study.h | 12 +- src/SUIT/SUIT_ViewManager.cxx | 6 + src/SUIT/SUIT_ViewManager.h | 2 + src/SUIT/SUIT_ViewWindow.cxx | 208 ++++++++++++++++------------ src/SUIT/SUIT_ViewWindow.h | 10 +- 21 files changed, 549 insertions(+), 170 deletions(-) create mode 100755 src/SUIT/SUIT_LicenseDlg.cxx create mode 100755 src/SUIT/SUIT_LicenseDlg.h diff --git a/src/STD/STD.h b/src/STD/STD.h index 404cf9adf..e974b5255 100755 --- a/src/STD/STD.h +++ b/src/STD/STD.h @@ -19,18 +19,14 @@ #ifndef STD_H #define STD_H -#if defined STD_EXPORTS #if defined WIN32 -#define STD_EXPORT __declspec( dllexport ) +# if defined STD_EXPORTS +# define STD_EXPORT __declspec( dllexport ) +# else +# define STD_EXPORT __declspec( dllimport ) +# endif #else -#define STD_EXPORT -#endif -#else -#if defined WIN32 -#define STD_EXPORT __declspec( dllimport ) -#else -#define STD_EXPORT -#endif +# define STD_EXPORT #endif #if defined SOLARIS diff --git a/src/SUIT/SUIT.h b/src/SUIT/SUIT.h index 151fba4d1..62c205b68 100755 --- a/src/SUIT/SUIT.h +++ b/src/SUIT/SUIT.h @@ -16,21 +16,21 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +// File : SUIT.h +// Author : +// + #ifndef SUIT_H #define SUIT_H -#if defined SUIT_EXPORTS -#if defined WIN32 -#define SUIT_EXPORT __declspec( dllexport ) -#else -#define SUIT_EXPORT -#endif -#else #if defined WIN32 -#define SUIT_EXPORT __declspec( dllimport ) +# if defined SUIT_EXPORTS +# define SUIT_EXPORT __declspec( dllexport ) +# else +# define SUIT_EXPORT __declspec( dllimport ) +# endif #else -#define SUIT_EXPORT -#endif +# define SUIT_EXPORT #endif #if defined SOLARIS @@ -52,4 +52,4 @@ #define SUIT_ASSERT(x) #endif -#endif +#endif // SUIT_H diff --git a/src/SUIT/SUIT.pro b/src/SUIT/SUIT.pro index 61c6078e6..da3b3a035 100644 --- a/src/SUIT/SUIT.pro +++ b/src/SUIT/SUIT.pro @@ -16,7 +16,7 @@ CONFIG -= debug release debug_and_release CONFIG += qt thread debug dll shared win32:DEFINES += WNT WIN32 -DEFINES += SUIT_EXPORTS +DEFINES += SUIT_EXPORTS DISABLE_TESTRECORDER HEADERS = *.h diff --git a/src/SUIT/SUIT_Application.cxx b/src/SUIT/SUIT_Application.cxx index a5e545230..ead59e4c4 100755 --- a/src/SUIT/SUIT_Application.cxx +++ b/src/SUIT/SUIT_Application.cxx @@ -26,19 +26,33 @@ #include #include #include +#include +#include #include #include #include +/*! + \class StatusLabel + \brief Status bar customization label. Used to workaroubd desktop resizing bug. + \internal +*/ +class StatusLabel : public QLabel +{ +public: + StatusLabel( QWidget* parent ) : QLabel( parent ) {} + QSize minimumSizeHint () const { return QSize( 0, QLabel::minimumSizeHint().height() ); } +}; + /*! Default constructor */ SUIT_Application::SUIT_Application() : QObject( 0 ), -myStudy( 0 ), -myDesktop( 0 ), -myStatusLabel( 0 ) + myStudy( 0 ), + myDesktop( 0 ), + myStatusLabel( 0 ) { if ( SUIT_Session::session() ) SUIT_Session::session()->insertApplication( this ); @@ -49,8 +63,9 @@ myStatusLabel( 0 ) */ SUIT_Application::~SUIT_Application() { - delete myStudy; - myStudy = 0; + SUIT_Study* s = myStudy; + setActiveStudy( 0 ); + delete s; setDesktop( 0 ); } @@ -67,7 +82,7 @@ SUIT_Desktop* SUIT_Application::desktop() \return FALSE if application can not be closed (because of non saved data for example). This method called by SUIT_Session whin closing of application was requested. */ -bool SUIT_Application::isPossibleToClose( bool& closePermanently ) +bool SUIT_Application::isPossibleToClose( bool& ) { return true; } @@ -94,7 +109,7 @@ SUIT_Study* SUIT_Application::activeStudy() const */ QString SUIT_Application::applicationVersion() const { - return QString::null; + return QString(); } /*! @@ -126,15 +141,6 @@ bool SUIT_Application::useFile( const QString& theFileName ) return status; } -/*! - Opens other study into active Study. If Study is empty - creates it. - \param theName - name of study -*/ -bool SUIT_Application::useStudy( const QString& /*theName*/ ) -{ - return false; -} - /*! Creates new empty Study if active Study = 0 */ @@ -178,7 +184,7 @@ void SUIT_Application::putInfo( const QString& msg, const int msec ) if ( !myStatusLabel ) { - myStatusLabel = new QLabel( desktop()->statusBar() ); + myStatusLabel = new StatusLabel( desktop()->statusBar() ); desktop()->statusBar()->addWidget( myStatusLabel, 1 ); myStatusLabel->show(); } @@ -204,7 +210,14 @@ void SUIT_Application::onInfoClear() bool changed = !myStatusLabel->text().isEmpty(); myStatusLabel->clear(); if ( changed ) - emit infoChanged( QString::null ); + emit infoChanged( QString() ); +} + +/*! + Update status of the registerd actions +*/ +void SUIT_Application::updateCommandsStatus() +{ } /*! @@ -243,8 +256,11 @@ void SUIT_Application::setDesktop( SUIT_Desktop* desk ) delete myDesktop; myDesktop = desk; - if ( myDesktop ) + if ( myDesktop ) { connect( myDesktop, SIGNAL( activated() ), this, SLOT( onDesktopActivated() ) ); + // Force desktop activation (NPAL16628) + QApplication::postEvent(myDesktop, new QEvent(QEvent::WindowActivate)); + } } /*! @@ -266,6 +282,13 @@ void SUIT_Application::setActiveStudy( SUIT_Study* study ) if ( myStudy == study ) return; + if ( myStudy ) + disconnect( myStudy, SIGNAL( studyModified( SUIT_Study* ) ), + this, SLOT( updateCommandsStatus() ) ); + if ( study ) + connect( study, SIGNAL( studyModified( SUIT_Study* ) ), + this, SLOT( updateCommandsStatus() ) ); + myStudy = study; } @@ -557,6 +580,16 @@ int SUIT_Application::actionId( const QAction* a ) const return id; } +QList SUIT_Application::actions() const +{ + return myActionMap.values(); +} + +QList SUIT_Application::actionIds() const +{ + return myActionMap.keys(); +} + /*! Creates action and registers it both in menu manager and tool manager \return new instance of action @@ -630,3 +663,12 @@ void SUIT_Application::onDesktopActivated() { emit activated( this ); } + +/*! + SLOT: is used for Help browsing +*/ +void SUIT_Application::onHelpContextModule( const QString& /*theComponentName*/, + const QString& /*theFileName*/, + const QString& /*theContext*/ ) +{ +} diff --git a/src/SUIT/SUIT_Application.h b/src/SUIT/SUIT_Application.h index 710d3b2d5..f20dc5633 100755 --- a/src/SUIT/SUIT_Application.h +++ b/src/SUIT/SUIT_Application.h @@ -84,9 +84,6 @@ public: //! Opens document into active Study. If Study is empty - creates it. virtual bool useFile( const QString& theFileName); - //! Loads document into active Study. If Study is empty - creates it. - virtual bool useStudy( const QString& theName); - //! Creates new empty Study if active Study = 0 virtual void createEmptyStudy(); @@ -111,6 +108,10 @@ signals: void activated( SUIT_Application* ); void infoChanged( QString ); +public slots: + virtual void updateCommandsStatus(); + virtual void onHelpContextModule( const QString&, const QString&, const QString& = QString() ); + private slots: void onInfoClear(); @@ -152,6 +153,10 @@ protected: static QAction* separator(); QAction* action( const int ) const; int actionId( const QAction* ) const; + + QList actions() const; + QList actionIds() const; + int registerAction( const int, QAction* ); QAction* createAction( const int, const QString&, const QIcon&, const QString&, const QString&, const int, QObject* = 0, diff --git a/src/SUIT/SUIT_ExceptionHandler.cxx b/src/SUIT/SUIT_ExceptionHandler.cxx index 861fdcf2c..babe67e69 100755 --- a/src/SUIT/SUIT_ExceptionHandler.cxx +++ b/src/SUIT/SUIT_ExceptionHandler.cxx @@ -20,6 +20,10 @@ #include "SUIT_MessageBox.h" +#ifndef DISABLE_TESTRECORDER + #include +#endif + #include /*!\class SUIT_ExceptionHandler @@ -39,7 +43,12 @@ bool SUIT_ExceptionHandler::handle( QObject* o, QEvent* e ) */ bool SUIT_ExceptionHandler::internalHandle( QObject* o, QEvent* e ) { +#ifndef DISABLE_TESTRECORDER + TestApplication* aTApp = qobject_cast(qApp); + return aTApp ? aTApp->TestApplication::notify( o, e ) : false; +#else return qApp ? qApp->QApplication::notify( o, e ) : false; +#endif } /*! diff --git a/src/SUIT/SUIT_LicenseDlg.cxx b/src/SUIT/SUIT_LicenseDlg.cxx new file mode 100755 index 000000000..4faafba13 --- /dev/null +++ b/src/SUIT/SUIT_LicenseDlg.cxx @@ -0,0 +1,215 @@ +// 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 +// + +#include "SUIT_LicenseDlg.h" + +#include +#include +#include +#include +#include +#include +#include +//#include +#include +#include + +#include + +#ifdef WIN32 +#include +#endif + + +/*! + Constructor + Construct a dialog with specified parent and name. + \param modal define modal status of dialog (default modal dialog created). +*/ +SUIT_LicenseDlg::SUIT_LicenseDlg( bool firstShow, QWidget* parent, const char* name, bool modal ) + : QDialog( parent ) +{ + setObjectName( name ); + setModal( modal ); + QString env; + if ( ::getenv( "TRIPOLI_ROOT_DIR" ) ) + env = ::getenv( "TRIPOLI_ROOT_DIR" ); + + QFile file( env + "/share/salome/resources/License.txt" ); // Read the text from a file + + if ( !file.exists() || !file.open( QIODevice::ReadOnly ) ) + return; + + setWindowTitle( tr( "License" ) ); + + // Create text editor + myTextEdit = new QTextEdit( this ); + QTextStream stream( &file ); + myTextEdit->setText( stream.readAll() ); + file.close(); + myTextEdit->setReadOnly( true ); + //myTextEdit->ensureVisible(0, 0); + + // Create buttons + QPushButton* anAgreeBtn = new QPushButton( tr( "Agree" ), this ); + if (firstShow) { + anAgreeBtn->setAutoDefault( true ); + anAgreeBtn->setFocus(); + } + else + anAgreeBtn->hide(); + + QPushButton* aCancelBtn = new QPushButton( this ); + aCancelBtn->setText( firstShow ? tr( "Cancel" ) : tr( "Close" ) ); + if ( !firstShow ) + aCancelBtn->setFocus(); + + QPushButton* aPrintBtn = new QPushButton( tr( "Print..." ), this ); + + // Layouting + QVBoxLayout* aBaseLayout = new QVBoxLayout( this ); + aBaseLayout->setMargin( 5 ); + aBaseLayout->setSpacing( 5 ); + aBaseLayout->addWidget( myTextEdit ); + + QHBoxLayout* aButtonsLayout = new QHBoxLayout(); + aBaseLayout->addLayout( aButtonsLayout ); + if (firstShow) + aButtonsLayout->addWidget( anAgreeBtn ); + + aButtonsLayout->addWidget( aCancelBtn ); + aButtonsLayout->addStretch(); + aButtonsLayout->addWidget( aPrintBtn ); + + // Connections + connect( anAgreeBtn, SIGNAL( clicked() ), this, SLOT( onAgree( ) ) ); + connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( onCancel( ) ) ); + connect( aPrintBtn, SIGNAL( clicked() ), this, SLOT( onPrint( ) ) ); + + resize( 640, 480 ); +} + +/*! + Name: ~SUIT_LicenseDlg [public] + Desc: Destructor +*/ + +SUIT_LicenseDlg::~SUIT_LicenseDlg() +{ +} + +void SUIT_LicenseDlg::onAgree() +{ + QString env; +#ifdef WIN32 + DWORD aLen=1024; + char aStr[1024]; + HANDLE aToken=0; + HANDLE hProcess = GetCurrentProcess(); + OpenProcessToken(hProcess,TOKEN_QUERY,&aToken); + if( ! GetUserProfileDirectory( aToken, aStr, &aLen ) ) + reject(); + + env = aStr; +#else + if( ! ::getenv( "HOME" ) ) + reject(); + env = ::getenv( "HOME" ); +#endif + + QFile file( env + "/ReadLicense.log" ); // Read the text from a file + + file.open( QIODevice::WriteOnly ); + + QTextStream ts( &file ); + ts << "OK" << endl; + //file.writeBlock( "OK", (Q_ULONG)qstrlen( "OK" ) ); + file.close(); + + accept(); +} + +void SUIT_LicenseDlg::onCancel() +{ + reject(); +} + +void SUIT_LicenseDlg::onPrint() +{ + QPrinter aPrinter( QPrinter::HighResolution ); + aPrinter.setFullPage(true); + + if ( true /*aPrinter.pageSetup( this )*/ ) { + QPainter aPainter( &aPrinter ); + if( !aPainter.isActive() ) // starting printing failed + return; + + // define fonts + QFont aBodyFont = myTextEdit->currentFont(); + QFont aFooterFont = aBodyFont; + + // calculate margin + QPaintDevice* aMetrics(aPainter.device()); + int aDpiY = aMetrics->logicalDpiY(); + int aMargin = (int) ( (2/2.54)*aDpiY ); // 2 cm margins + + QRect aBody( aMargin, aMargin, aMetrics->width() - 2*aMargin, aMetrics->height() - 2*aMargin ); + + // convert text to rich text format + QString aFormattedText = Qt::convertFromPlainText( myTextEdit->toPlainText() ); + + QTextDocument aRichText( aFormattedText ); + aRichText.setDefaultFont( aBodyFont ); + + + /*QSimpleRichText aRichText( aFormattedText, + aBodyFont, + myTextEdit->context(), + myTextEdit->styleSheet(), + myTextEdit->mimeSourceFactory(), + aBody.height() ); + */ + aRichText.setPageSize( QSize( aBody.width(), aRichText.pageSize().height() ) ); + //aRichText.setWidth( &aPainter, aBody.width() ); + + QRect aView( aBody ); + + int aPageIndex = 1; + + do { + // print page text + aRichText.drawContents( &aPainter, aView ); + //aRichText.draw( &aPainter, aBody.left(), aBody.top(), aView, colorGroup() ); + aView.translate( 0, aBody.height() ); + aPainter.translate( 0 , -aBody.height() ); + + // print page number + aPainter.setPen(Qt::gray); + aPainter.setFont(aFooterFont); + QString aFooter = QString("Page ") + QString::number(aPageIndex); + aPainter.drawText( aView.right() - aPainter.fontMetrics().width( aFooter ), + aView.bottom() + aPainter.fontMetrics().ascent() + 5, aFooter ); + + if ( aView.top() >= aRichText.size().height() ) + break; + aPrinter.newPage(); + aPageIndex++; + } while (true); + } +} diff --git a/src/SUIT/SUIT_LicenseDlg.h b/src/SUIT/SUIT_LicenseDlg.h new file mode 100755 index 000000000..d0e2e739f --- /dev/null +++ b/src/SUIT/SUIT_LicenseDlg.h @@ -0,0 +1,51 @@ +// 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 + +#ifndef SUIT_LICENSEDLG_H +#define SUIT_LICENSEDLG_H + +#include "SUIT.h" + +#include +class QTextEdit; + +#ifdef WIN32 +#pragma warning( disable:4251 ) +#endif + +class SUIT_EXPORT SUIT_LicenseDlg :public QDialog +{ + Q_OBJECT +public: + SUIT_LicenseDlg( bool firstShow = true, QWidget* = 0, const char* = 0, bool = true ); + virtual ~SUIT_LicenseDlg(); + +private slots: + void onAgree(); + void onCancel(); + void onPrint(); + +private: + QTextEdit* myTextEdit; +}; + +#ifdef WIN32 +#pragma warning( default:4251 ) +#endif + +#endif diff --git a/src/SUIT/SUIT_Operation.cxx b/src/SUIT/SUIT_Operation.cxx index 31ff40f8f..73ab85cc2 100755 --- a/src/SUIT/SUIT_Operation.cxx +++ b/src/SUIT/SUIT_Operation.cxx @@ -154,7 +154,7 @@ bool SUIT_Operation::testFlags( const int f ) const */ QString SUIT_Operation::operationName() const { - return QString::null; + return QString(); } /*! diff --git a/src/SUIT/SUIT_Operation.h b/src/SUIT/SUIT_Operation.h index 6a1785e2a..cf29007d7 100755 --- a/src/SUIT/SUIT_Operation.h +++ b/src/SUIT/SUIT_Operation.h @@ -140,7 +140,7 @@ protected: virtual bool openTransaction(); virtual bool abortTransaction(); virtual bool hasTransaction() const; - virtual bool commitTransaction( const QString& = QString::null ); + virtual bool commitTransaction( const QString& = QString() ); void setExecStatus( const int ); diff --git a/src/SUIT/SUIT_ResourceMgr.h b/src/SUIT/SUIT_ResourceMgr.h index db0eda711..2717de2c4 100755 --- a/src/SUIT/SUIT_ResourceMgr.h +++ b/src/SUIT/SUIT_ResourceMgr.h @@ -26,7 +26,7 @@ class SUIT_EXPORT SUIT_ResourceMgr : public QtxResourceMgr { public: - SUIT_ResourceMgr( const QString&, const QString& = QString::null ); + SUIT_ResourceMgr( const QString&, const QString& = QString() ); virtual ~SUIT_ResourceMgr(); virtual QString version() const; diff --git a/src/SUIT/SUIT_SelectionMgr.cxx b/src/SUIT/SUIT_SelectionMgr.cxx index 21d02eadc..a3f8a8e81 100755 --- a/src/SUIT/SUIT_SelectionMgr.cxx +++ b/src/SUIT/SUIT_SelectionMgr.cxx @@ -148,7 +148,8 @@ void SUIT_SelectionMgr::selectionChanged( SUIT_Selector* sel ) { for ( SelectorList::iterator it = mySelectors.begin(); it != mySelectors.end(); ++it ) { - if ( *it != sel ) + // Temporary action(to avoid selection of the objects which don't pass the filters): + //if ( *it != sel ) (*it)->setSelected( newOwners ); } } diff --git a/src/SUIT/SUIT_SelectionMgr.h b/src/SUIT/SUIT_SelectionMgr.h index 7f3082737..ec2ecb9fa 100755 --- a/src/SUIT/SUIT_SelectionMgr.h +++ b/src/SUIT/SUIT_SelectionMgr.h @@ -40,14 +40,14 @@ public: virtual ~SUIT_SelectionMgr(); void clearSelected(); - virtual void selected( SUIT_DataOwnerPtrList&, const QString& = QString::null ) const; + virtual void selected( SUIT_DataOwnerPtrList&, const QString& = QString() ) const; virtual void setSelected( const SUIT_DataOwnerPtrList&, const bool = false ); void selectors( QList& ) const; void selectors( const QString&, QList& ) const; - void setEnabled( const bool, const QString& = QString::null ); + void setEnabled( const bool, const QString& = QString() ); bool hasSelectionMode( const int ) const; diff --git a/src/SUIT/SUIT_Session.cxx b/src/SUIT/SUIT_Session.cxx index 891c20b8f..a11ea26a6 100755 --- a/src/SUIT/SUIT_Session.cxx +++ b/src/SUIT/SUIT_Session.cxx @@ -38,10 +38,11 @@ SUIT_Session* SUIT_Session::mySession = 0; SUIT_Session::SUIT_Session() : QObject(), -myResMgr( 0 ), -myActiveApp( 0 ), -myHandler( 0 ), -myExitStatus( FROM_GUI ) + myResMgr( 0 ), + myActiveApp( 0 ), + myHandler( 0 ), + myExitStatus( NORMAL ), + myExitFlags ( 0 ) { SUIT_ASSERT( !mySession ) @@ -229,7 +230,7 @@ void SUIT_Session::onApplicationClosed( SUIT_Application* theApp ) if ( myAppList.isEmpty() ) { - printf( "Calling QApplication::exit() with exit code = %d\n", myExitStatus ); + //printf( "Calling QApplication::exit() with exit code = %d\n", myExitStatus ); QApplication::instance()->exit( myExitStatus ); } } @@ -237,7 +238,7 @@ void SUIT_Session::onApplicationClosed( SUIT_Application* theApp ) /*! Destroys session by closing all applications. */ -void SUIT_Session::closeSession( int mode ) +void SUIT_Session::closeSession( int mode, int flags ) { AppList apps = myAppList; for ( AppList::const_iterator it = apps.begin(); it != apps.end(); ++it ) @@ -254,12 +255,27 @@ void SUIT_Session::closeSession( int mode ) } else if ( mode == DONT_SAVE ) { - myExitStatus = FROM_CORBA_SESSION; - //.... + myExitStatus = FORCED; } app->closeApplication(); } + + myExitFlags = flags; +} + +/*! + Get session exit flags. + + By default, exit flags are set to 0. You can use pass any flags to the + closeSession() method if you need to process them later on application + quiting. + + \return exit flags +*/ +int SUIT_Session::exitFlags() const +{ + return myExitFlags; } /*! \retval return myHandler*/ diff --git a/src/SUIT/SUIT_Session.h b/src/SUIT/SUIT_Session.h index f62d697c1..e6ece73e3 100755 --- a/src/SUIT/SUIT_Session.h +++ b/src/SUIT/SUIT_Session.h @@ -56,7 +56,7 @@ public: typedef LIB_HANDLE AppLib; enum { ASK = 0, SAVE, DONT_SAVE } CloseMode; - enum { FROM_GUI = 0, FROM_CORBA_SESSION } ExitStatus; + enum { NORMAL = 0, FORCED } ExitStatus; public: SUIT_Session(); @@ -71,7 +71,8 @@ public: SUIT_ResourceMgr* resourceMgr() const; - void closeSession( int mode = ASK ); + void closeSession( int mode = ASK, int flags = 0 ); + int exitFlags() const; SUIT_ExceptionHandler* handler() const; @@ -106,6 +107,7 @@ private: static SUIT_Session* mySession; int myExitStatus; + int myExitFlags; }; #endif diff --git a/src/SUIT/SUIT_Study.cxx b/src/SUIT/SUIT_Study.cxx index 8fc4f71ce..fec0b6a4f 100755 --- a/src/SUIT/SUIT_Study.cxx +++ b/src/SUIT/SUIT_Study.cxx @@ -198,6 +198,15 @@ void SUIT_Study::setIsModified( const bool on ) myIsModified = on; } +/*! + Set study modified to \a on. + */ +void SUIT_Study::Modified() +{ + setIsModified( true ); + sendChangesNotification(); +} + /*! Set root object. */ @@ -237,8 +246,9 @@ SUIT_Operation* SUIT_Study::blockingOperation( SUIT_Operation* theOp ) const return 0; Operations tmpOps( myOperations ); - for ( Operations::const_iterator it = tmpOps.end(); it != tmpOps.begin(); --it ) + for ( Operations::const_iterator it = tmpOps.end(); it != tmpOps.begin(); ) { + it--; SUIT_Operation* anOp = *it; if ( anOp != 0 && anOp!= theOp && !anOp->isValid( theOp ) ) return anOp; @@ -512,16 +522,8 @@ bool SUIT_Study::hasTransaction() const } /*! - * \brief Stores the study state -*/ -int SUIT_Study::storeState() -{ - return -1; -} - -/*! - * \brief Restores the study state -*/ + * \brief Restores the study state. + */ void SUIT_Study::restoreState(int /*savePoint*/) { } diff --git a/src/SUIT/SUIT_Study.h b/src/SUIT/SUIT_Study.h index 6ebf2bcad..4128bd7fe 100755 --- a/src/SUIT/SUIT_Study.h +++ b/src/SUIT/SUIT_Study.h @@ -48,6 +48,7 @@ public: virtual bool isSaved() const; virtual bool isModified() const; + virtual void Modified(); virtual void closeDocument( bool = true ); virtual bool openDocument( const QString& ); @@ -73,7 +74,6 @@ public: bool suspend( SUIT_Operation* ); bool resume( SUIT_Operation* ); - virtual int storeState(); virtual void restoreState(int savePoint); signals: @@ -85,15 +85,15 @@ protected: virtual void setRoot( SUIT_DataObject* ); virtual void setStudyName( const QString& ); - virtual void operationStarted( SUIT_Operation* ); - virtual void operationAborted( SUIT_Operation* ); - virtual void operationStopped( SUIT_Operation* ); - virtual void operationCommited( SUIT_Operation* ); + virtual void operationStarted( SUIT_Operation* ); + virtual void operationAborted( SUIT_Operation* ); + virtual void operationStopped( SUIT_Operation* ); + virtual void operationCommited( SUIT_Operation* ); virtual bool openTransaction(); virtual bool abortTransaction(); virtual bool hasTransaction() const; - virtual bool commitTransaction( const QString& = QString::null ); + virtual bool commitTransaction( const QString& = QString() ); private: typedef QList Operations; diff --git a/src/SUIT/SUIT_ViewManager.cxx b/src/SUIT/SUIT_ViewManager.cxx index 61db632b6..34ee0c10c 100755 --- a/src/SUIT/SUIT_ViewManager.cxx +++ b/src/SUIT/SUIT_ViewManager.cxx @@ -165,6 +165,12 @@ SUIT_ViewWindow* SUIT_ViewManager::createViewWindow() return aView; } +/*! Get identifier */ +int SUIT_ViewManager::getId() const +{ + return myId; +} + /*!Create view window.*/ void SUIT_ViewManager::createView() { diff --git a/src/SUIT/SUIT_ViewManager.h b/src/SUIT/SUIT_ViewManager.h index cc6735d07..220c824f5 100755 --- a/src/SUIT/SUIT_ViewManager.h +++ b/src/SUIT/SUIT_ViewManager.h @@ -77,6 +77,8 @@ public: virtual void setShown( const bool ); virtual void setDestructiveClose( const bool ); + int getId() const; + public slots: void createView(); void closeAllViews(); diff --git a/src/SUIT/SUIT_ViewWindow.cxx b/src/SUIT/SUIT_ViewWindow.cxx index ca584e2a8..03c9e9d31 100755 --- a/src/SUIT/SUIT_ViewWindow.cxx +++ b/src/SUIT/SUIT_ViewWindow.cxx @@ -27,17 +27,16 @@ #include "SUIT_MessageBox.h" #include "SUIT_Application.h" #include "SUIT_ViewManager.h" - +#include "QtxActionToolMgr.h" #include "Qtx.h" #include #include #include #include -#include -#include #include - +#include +#include /*!\class SUIT_ViewWindow * Class provide view window. @@ -48,13 +47,15 @@ const int DUMP_EVENT = QEvent::User + 123; /*! Constructor.*/ SUIT_ViewWindow::SUIT_ViewWindow( SUIT_Desktop* theDesktop ) -: QMainWindow( theDesktop ), myManager( 0 ) +: QMainWindow( theDesktop ) { myDesktop = theDesktop; setWindowIcon( myDesktop->windowIcon() ); setAttribute( Qt::WA_DeleteOnClose ); + + myToolMgr = new QtxActionToolMgr( this ); } /*! Destructor.*/ @@ -120,6 +121,97 @@ bool SUIT_ViewWindow::dumpViewToFormat( const QString& fileName, const QString& return dumpViewToFormat( dumpView(), fileName, format ); } +/*! + Prints given image + \param theImage - the image to print +*/ +void SUIT_ViewWindow::printImage( const QImage& theImage, QWidget* theWidget ) +{ + if ( theImage.isNull() ) + return; + +#if !defined(WIN32) && !defined(QT_NO_CUPS) +#if QT_VERSION < 0x040303 + if ( !Qtx::hasAnyPrinters() ) { + SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ), + tr( "WRN_NO_PRINTERS" ) ); + return; + } +#endif +#endif + + // stored settings for further starts + static QString aPrinterName; + static int anOrientation = -1; + + QPrinter aPrinter; + + // restore settinds from previous launching + + // printer name + if ( !aPrinterName.isEmpty() ) + aPrinter.setPrinterName( aPrinterName ); + else + { + // Nothing to do for the first printing. aPrinter contains default printer name by default + } + + if ( anOrientation >= 0 ) + aPrinter.setOrientation( (QPrinter::Orientation)anOrientation ); + else + aPrinter.setOrientation( QPrinter::Landscape ); + + + QPrintDialog printDlg( &aPrinter, theWidget ); + printDlg.setPrintRange( QAbstractPrintDialog::AllPages ); + if ( printDlg.exec() != QDialog::Accepted ) + return; + + // store printer settings for further starts + aPrinterName = aPrinter.printerName(); + anOrientation = aPrinter.orientation(); + + int W, H; + QPainter aPainter; + + // work arround for printing on real printer + if ( aPrinter.outputFileName().isEmpty() && aPrinter.orientation() == QPrinter::Landscape ) + { + aPrinter.setFullPage( true ); + // set paper orientation and rotate painter + aPrinter.setOrientation( QPrinter::Portrait ); + + W = aPrinter.height(); + H = aPrinter.width(); + + int wBorder = aPrinter.paperRect().height() - W; + int hBorder = aPrinter.paperRect().width() - H; + + aPainter.begin( &aPrinter ); + aPainter.translate( QPoint( H + hBorder, wBorder ) ); + aPainter.rotate( 90 ); + } + else + { + aPrinter.setFullPage( false ); + aPainter.begin( &aPrinter ); + W = aPrinter.width(); + H = aPrinter.height(); + } + + QImage anImage = theImage; + if ( anImage.width() > W || anImage.height() > H ) + anImage = anImage.scaled( W, H, Qt::KeepAspectRatio, Qt::SmoothTransformation ); + + // place image in the center of page + int offsetW = ( W - anImage.width() ) / 2; + int offsetH = ( H - anImage.height() ) / 2; + + aPainter.drawImage( offsetW, offsetH, anImage ); + + aPainter.end(); +} + /*! Set or clear flag Qt::WDestructiveClose */ @@ -138,8 +230,15 @@ void SUIT_ViewWindow::closeEvent( QCloseEvent* e ) /*! Context menu requested for event \a e. */ -void SUIT_ViewWindow::contextMenuEvent ( QContextMenuEvent * e ) +void SUIT_ViewWindow::contextMenuEvent( QContextMenuEvent* e ) { + e->ignore(); + + QMainWindow::contextMenuEvent( e ); + + if ( e->isAccepted() ) + return; + if ( e->reason() != QContextMenuEvent::Mouse ) emit contextMenuRequested( e ); } @@ -173,7 +272,7 @@ bool SUIT_ViewWindow::event( QEvent* e ) // get file name SUIT_Application* app = myManager->study()->application(); - QString fileName = app->getFileName( false, QString::null, filter(), tr( "TLT_DUMP_VIEW" ), 0 ); + QString fileName = app->getFileName( false, QString(), filter(), tr( "TLT_DUMP_VIEW" ), 0 ); if ( !fileName.isEmpty() ) { QString fmt = SUIT_Tools::extension( fileName ).toUpper(); @@ -221,92 +320,17 @@ void SUIT_ViewWindow::setVisualParameters( const QString& /*parameters*/ ) } /*! - Prints given image - \param theImage - the image to print + \return associated tool bar manager */ -void SUIT_ViewWindow::printImage( const QImage& theImage, QWidget* theWidget ) +QtxActionToolMgr* SUIT_ViewWindow::toolMgr() const { - if ( theImage.isNull() ) - return; - -#if !defined(WIN32) && !defined(QT_NO_CUPS) -#if QT_VERSION < 0x040303 - if ( !Qtx::hasAnyPrinters() ) { - SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ), - tr( "WRN_NO_PRINTERS" ) ); - return; - } -#endif -#endif - - // stored settings for further starts - static QString aPrinterName; - static int anOrientation = -1; - - QPrinter aPrinter; - - // restore settinds from previous launching - - // printer name - if ( !aPrinterName.isEmpty() ) - aPrinter.setPrinterName( aPrinterName ); - else - { - // Nothing to do for the first printing. aPrinter contains default printer name by default - } - - if ( anOrientation >= 0 ) - aPrinter.setOrientation( (QPrinter::Orientation)anOrientation ); - else - aPrinter.setOrientation( QPrinter::Landscape ); - - - QPrintDialog printDlg( &aPrinter, theWidget ); - printDlg.setPrintRange( QAbstractPrintDialog::AllPages ); - if ( printDlg.exec() != QDialog::Accepted ) - return; - - // store printer settings for further starts - aPrinterName = aPrinter.printerName(); - anOrientation = aPrinter.orientation(); - - int W, H; - QPainter aPainter; - - // work arround for printing on real printer - if ( aPrinter.outputFileName().isEmpty() && aPrinter.orientation() == QPrinter::Landscape ) - { - aPrinter.setFullPage( true ); - // set paper orientation and rotate painter - aPrinter.setOrientation( QPrinter::Portrait ); - - W = aPrinter.height(); - H = aPrinter.width(); - - int wBorder = aPrinter.paperRect().height() - W; - int hBorder = aPrinter.paperRect().width() - H; - - aPainter.begin( &aPrinter ); - aPainter.translate( QPoint( H + hBorder, wBorder ) ); - aPainter.rotate( 90 ); - } - else - { - aPrinter.setFullPage( false ); - aPainter.begin( &aPrinter ); - W = aPrinter.width(); - H = aPrinter.height(); - } - - QImage anImage = theImage; - if ( anImage.width() > W || anImage.height() > H ) - anImage = anImage.scaled( W, H, Qt::KeepAspectRatio, Qt::SmoothTransformation ); - - // place image in the center of page - int offsetW = ( W - anImage.width() ) / 2; - int offsetH = ( H - anImage.height() ) / 2; - - aPainter.drawImage( offsetW, offsetH, anImage ); + return myToolMgr; +} - aPainter.end(); +/*! + \return window unique identifier +*/ +int SUIT_ViewWindow::getId() const +{ + return int(long(this)); } diff --git a/src/SUIT/SUIT_ViewWindow.h b/src/SUIT/SUIT_ViewWindow.h index 944c9d5fa..60ee0c434 100755 --- a/src/SUIT/SUIT_ViewWindow.h +++ b/src/SUIT/SUIT_ViewWindow.h @@ -25,10 +25,11 @@ #include "SUIT.h" #include -#include class SUIT_Desktop; class SUIT_ViewManager; +class QtxActionToolMgr; +class QImage; class SUIT_EXPORT SUIT_ViewWindow: public QMainWindow { @@ -52,6 +53,10 @@ public: virtual void setVisualParameters( const QString& parameters ); void setDestructiveClose( const bool ); + + int getId() const; + + QtxActionToolMgr* toolMgr() const; public slots: virtual void onDumpView(); @@ -76,6 +81,9 @@ protected: SUIT_Desktop* myDesktop; SUIT_ViewManager* myManager; + +private: + QtxActionToolMgr* myToolMgr; }; #endif // !defined(AFX_SUIT_VIEWWINDOW_H__82C3D51A_6F10_45B0_BCFE_3CB3EF596A4D__INCLUDED_) -- 2.39.2