From 727cd29732182a067498350759a1fd4afc44e28c Mon Sep 17 00:00:00 2001 From: nds Date: Mon, 6 Oct 2008 10:06:05 +0000 Subject: [PATCH] Merging with the BR_V5_DEV branch. --- src/SUIT/SUIT.pro | 2 +- src/SUIT/SUIT_Application.cxx | 15 +- src/SUIT/SUIT_ExceptionHandler.cxx | 9 ++ src/SUIT/SUIT_FileDlg.cxx | 9 ++ src/SUIT/SUIT_FileDlg.h | 6 +- src/SUIT/SUIT_LicenseDlg.cxx | 215 +++++++++++++++++++++++++++++ src/SUIT/SUIT_LicenseDlg.h | 51 +++++++ src/SUIT/SUIT_Session.cxx | 2 +- 8 files changed, 304 insertions(+), 5 deletions(-) create mode 100755 src/SUIT/SUIT_LicenseDlg.cxx create mode 100755 src/SUIT/SUIT_LicenseDlg.h diff --git a/src/SUIT/SUIT.pro b/src/SUIT/SUIT.pro index 63f66e07a..3548b214a 100644 --- a/src/SUIT/SUIT.pro +++ b/src/SUIT/SUIT.pro @@ -11,7 +11,7 @@ CONFIG -= debug release debug_and_release CONFIG += qt thread debug dll shared win32:DEFINES += 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 19a68e935..ead59e4c4 100755 --- a/src/SUIT/SUIT_Application.cxx +++ b/src/SUIT/SUIT_Application.cxx @@ -27,11 +27,24 @@ #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 */ @@ -171,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(); } 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_FileDlg.cxx b/src/SUIT/SUIT_FileDlg.cxx index 1a026be1b..7572fba75 100755 --- a/src/SUIT/SUIT_FileDlg.cxx +++ b/src/SUIT/SUIT_FileDlg.cxx @@ -954,6 +954,15 @@ QString SUIT_FileDlg::getExistingDirectory( QWidget* parent, const QString& init return dirname; } +/*! + \brief Get last visited path + \return last visited path +*/ +QString SUIT_FileDlg::getLastVisitedPath() +{ + return myLastVisitedPath; +} + /*! \brief Selects current file diff --git a/src/SUIT/SUIT_FileDlg.h b/src/SUIT/SUIT_FileDlg.h index 5405baa6e..76309c67a 100755 --- a/src/SUIT/SUIT_FileDlg.h +++ b/src/SUIT/SUIT_FileDlg.h @@ -54,9 +54,9 @@ public: QStringList selectedFiles() const; QString selectedFile() const; - static QString getLastVisitedDirectory(); + void selectFile( const QString& ); - void selectFile( const QString& ); + static QString getLastVisitedDirectory(); static QString getFileName( QWidget*, const QString&, @@ -92,6 +92,8 @@ public: const bool = true, SUIT_FileValidator* = 0 ); + static QString getLastVisitedPath(); + protected: virtual bool event( QEvent* ); QLineEdit* lineEdit() const; 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_Session.cxx b/src/SUIT/SUIT_Session.cxx index 6ca03d964..a11ea26a6 100755 --- a/src/SUIT/SUIT_Session.cxx +++ b/src/SUIT/SUIT_Session.cxx @@ -230,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 ); } } -- 2.39.2