Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / LightApp / LightApp_AboutDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File:      LightApp_AboutDlg.cxx
23 // Created:   03.06.2005 13:52:45
24 // Author:    Sergey TELKOV
25 //
26 #include "LightApp_AboutDlg.h"
27
28 #include <SUIT_Session.h>
29 #include <SUIT_ResourceMgr.h>
30
31 #include <QtxGridBox.h>
32
33 #include <QLabel>
34 #include <QVBoxLayout>
35 #include <QPixmap>
36 #include <QIcon>
37 #include <QGroupBox>
38
39 /*!Constructor.*/
40 LightApp_AboutDlg::LightApp_AboutDlg( const QString& defName, const QString& defVer, QWidget* parent )
41 : QtxDialog( parent, true, false, None )
42 {
43   setObjectName( "salome_about_dialog" );
44
45   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
46
47   QPixmap ico = resMgr->loadPixmap( "LightApp", tr( "ICO_ABOUT" ), false );
48   if ( !ico.isNull() )
49     setWindowIcon( ico );
50
51   QPalette pal = palette();
52
53   pal.setBrush( QPalette::Active, QPalette::WindowText, QBrush( Qt::darkBlue ) );
54   pal.setBrush( QPalette::Active, QPalette::Window,     QBrush( Qt::white ) );
55
56   pal.setBrush( QPalette::Inactive, QPalette::WindowText, QBrush( Qt::darkBlue ) );
57   pal.setBrush( QPalette::Inactive, QPalette::Window,     QBrush( Qt::white ) );
58
59   pal.setBrush( QPalette::Disabled, QPalette::WindowText, QBrush( Qt::darkBlue ) );
60   pal.setBrush( QPalette::Disabled, QPalette::Window,     QBrush( Qt::white ) );
61
62   setPalette(pal);
63
64   QVBoxLayout* main = new QVBoxLayout( mainFrame() );
65   QtxGridBox* base = new QtxGridBox( 1, Qt::Horizontal, mainFrame(), 0, 0 );
66   base->setInsideMargin( 0 );
67   main->addWidget( base );
68
69   QLabel* screen = new QLabel( base );
70   screen->setScaledContents( true );
71   screen->setAlignment( Qt::AlignCenter );
72   screen->setFrameStyle( QFrame::Box | QFrame::Plain );
73
74   QLabel* title = new QLabel( base );
75   title->setAlignment( Qt::AlignCenter );
76   changeFont( title, true, false, false, 5 );
77
78   QLabel* version = new QLabel( base );
79   version->setAlignment( Qt::AlignCenter );
80   changeFont( version, false, true, false, 2 );
81   
82   QLabel* copyright = new QLabel( base );
83   copyright->setAlignment( Qt::AlignCenter );
84   changeFont( copyright, false, false, false, 1 );
85
86   QLabel* license = new QLabel( base );
87   license->setAlignment( Qt::AlignCenter );
88   changeFont( license, false, false, false, 1 );
89
90   screen->setPixmap( resMgr->loadPixmap( "LightApp", tr( "ABOUT" ), false ) );
91   checkLabel( screen );
92
93   QString titleText = tr( "ABOUT_TITLE" );
94   if ( titleText == "ABOUT_TITLE" )
95     titleText = defName;
96   title->setText( titleText );
97   checkLabel( title );
98
99   QString verText = tr( "ABOUT_VERSION" );
100   if ( verText.contains( "%1" ) )
101     verText = verText.arg( defVer );
102   version->setText( verText );
103   checkLabel( version );
104
105   copyright->setText( tr( "ABOUT_COPYRIGHT" ) );
106   checkLabel( copyright );
107
108   license->setText( tr( "ABOUT_LICENSE" ) );
109   checkLabel( license );
110
111   QString capText = tr( "ABOUT_CAPTION" );
112   if ( capText.contains( "%1" ) )
113     capText = capText.arg( defName );
114   setWindowTitle( capText );
115
116   setSizeGripEnabled( false );
117 }
118
119 /*!Destructor.*/
120 LightApp_AboutDlg::~LightApp_AboutDlg()
121 {
122   //! Do nothing.
123 }
124
125 /*!On mouse press event.*/
126 void LightApp_AboutDlg::mousePressEvent( QMouseEvent* )
127 {
128   accept();
129 }
130
131 /*!Change font of widget \a wid.
132  *\param wid - QWidget
133  *\param bold - boolean value
134  *\param italic - boolean value
135  *\param underline - boolean value
136  *\param inc - integer increment for font point size.
137  */
138 void LightApp_AboutDlg::changeFont( QWidget* wid, const bool bold, const bool italic,
139                                      const bool underline, const int inc ) const
140 {
141   if ( !wid )
142     return;
143
144   QFont widFont = wid->font();
145   widFont.setBold( bold );
146   widFont.setItalic( italic );
147   widFont.setUnderline( underline );
148   widFont.setPointSize( widFont.pointSize() + inc );
149 }
150
151 /*!Check lable \a lab.*/
152 void LightApp_AboutDlg::checkLabel( QLabel* lab ) const
153 {
154   if ( !lab )
155     return;
156
157   bool vis = !lab->text().trimmed().isEmpty() ||
158              ( lab->pixmap() && !lab->pixmap()->isNull() );
159   vis ? lab->show() : lab->hide();
160 }