1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "SUIT_LicenseDlg.h"
24 #include <QApplication>
27 #include <QPushButton>
28 #include <QTextStream>
31 //#include <QSimpleRichText>
32 #include <QTextDocument>
44 Construct a dialog with specified parent and name.
45 \param modal define modal status of dialog (default modal dialog created).
47 SUIT_LicenseDlg::SUIT_LicenseDlg( bool firstShow, QWidget* parent, const char* name, bool modal )
50 setObjectName( name );
53 if ( ::getenv( "TRIPOLI_ROOT_DIR" ) )
54 env = ::getenv( "TRIPOLI_ROOT_DIR" );
56 QFile file( env + "/share/salome/resources/License.txt" ); // Read the text from a file
58 if ( !file.exists() || !file.open( QIODevice::ReadOnly ) )
61 setWindowTitle( tr( "License" ) );
64 myTextEdit = new QTextEdit( this );
65 QTextStream stream( &file );
66 myTextEdit->setText( stream.readAll() );
68 myTextEdit->setReadOnly( true );
69 //myTextEdit->ensureVisible(0, 0);
72 QPushButton* anAgreeBtn = new QPushButton( tr( "Agree" ), this );
74 anAgreeBtn->setAutoDefault( true );
75 anAgreeBtn->setFocus();
80 QPushButton* aCancelBtn = new QPushButton( this );
81 aCancelBtn->setText( firstShow ? tr( "Cancel" ) : tr( "Close" ) );
83 aCancelBtn->setFocus();
85 QPushButton* aPrintBtn = new QPushButton( tr( "Print..." ), this );
88 QVBoxLayout* aBaseLayout = new QVBoxLayout( this );
89 aBaseLayout->setMargin( 5 );
90 aBaseLayout->setSpacing( 5 );
91 aBaseLayout->addWidget( myTextEdit );
93 QHBoxLayout* aButtonsLayout = new QHBoxLayout();
94 aBaseLayout->addLayout( aButtonsLayout );
96 aButtonsLayout->addWidget( anAgreeBtn );
98 aButtonsLayout->addWidget( aCancelBtn );
99 aButtonsLayout->addStretch();
100 aButtonsLayout->addWidget( aPrintBtn );
103 connect( anAgreeBtn, SIGNAL( clicked() ), this, SLOT( onAgree( ) ) );
104 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( onCancel( ) ) );
105 connect( aPrintBtn, SIGNAL( clicked() ), this, SLOT( onPrint( ) ) );
111 Name: ~SUIT_LicenseDlg [public]
115 SUIT_LicenseDlg::~SUIT_LicenseDlg()
119 void SUIT_LicenseDlg::onAgree()
126 HANDLE hProcess = GetCurrentProcess();
127 OpenProcessToken(hProcess,TOKEN_QUERY,&aToken);
128 if( ! GetUserProfileDirectory( aToken, aStr, &aLen ) )
133 if( ! ::getenv( "HOME" ) )
135 env = ::getenv( "HOME" );
138 QFile file( env + "/ReadLicense.log" ); // Read the text from a file
140 file.open( QIODevice::WriteOnly );
142 QTextStream ts( &file );
144 //file.writeBlock( "OK", (Q_ULONG)qstrlen( "OK" ) );
150 void SUIT_LicenseDlg::onCancel()
155 void SUIT_LicenseDlg::onPrint()
157 QPrinter aPrinter( QPrinter::HighResolution );
158 aPrinter.setFullPage(true);
160 if ( true /*aPrinter.pageSetup( this )*/ ) {
161 QPainter aPainter( &aPrinter );
162 if( !aPainter.isActive() ) // starting printing failed
166 QFont aBodyFont = myTextEdit->currentFont();
167 QFont aFooterFont = aBodyFont;
170 QPaintDevice* aMetrics = aPainter.device();
171 int aDpiY = aMetrics->logicalDpiY();
172 int aMargin = (int) ( (2/2.54)*aDpiY ); // 2 cm margins
174 QRect aBody( aMargin, aMargin, aMetrics->width() - 2*aMargin, aMetrics->height() - 2*aMargin );
176 // convert text to rich text format
177 QString aFormattedText = Qt::convertFromPlainText( myTextEdit->toPlainText() );
179 QTextDocument aRichText( aFormattedText );
180 aRichText.setDefaultFont( aBodyFont );
183 /*QSimpleRichText aRichText( aFormattedText,
185 myTextEdit->context(),
186 myTextEdit->styleSheet(),
187 myTextEdit->mimeSourceFactory(),
190 aRichText.setPageSize( QSize( aBody.width(), aRichText.pageSize().height() ) );
191 //aRichText.setWidth( &aPainter, aBody.width() );
193 QRect aView( aBody );
199 aRichText.drawContents( &aPainter, aView );
200 //aRichText.draw( &aPainter, aBody.left(), aBody.top(), aView, colorGroup() );
201 aView.translate( 0, aBody.height() );
202 aPainter.translate( 0 , -aBody.height() );
205 aPainter.setPen(Qt::gray);
206 aPainter.setFont(aFooterFont);
207 QString aFooter = QString("Page ") + QString::number(aPageIndex);
208 aPainter.drawText( aView.right() - aPainter.fontMetrics().width( aFooter ),
209 aView.bottom() + aPainter.fontMetrics().ascent() + 5, aFooter );
211 if ( aView.top() >= aRichText.size().height() )