Salome HOME
Copyright update 2022
[modules/gui.git] / src / LightApp / LightApp_AboutDlg.cxx
1 // Copyright (C) 2007-2022  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, or (at your option) any later version.
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
23 // File:      LightApp_AboutDlg.cxx
24 // Created:   03.06.2005 13:52:45
25 // Author:    Sergey TELKOV
26 //
27 #include "LightApp_AboutDlg.h"
28 #include "LightApp_Application.h"
29
30 #include <SUIT_Session.h>
31 #include <SUIT_ResourceMgr.h>
32
33 #include <QtxGridBox.h>
34
35 #include <QLabel>
36 #include <QVBoxLayout>
37 #include <QPixmap>
38 #include <QIcon>
39 #include <QGroupBox>
40 #include <QTabWidget>
41 #include <QPushButton>
42
43 /*!Constructor.*/
44 LightApp_AboutDlg::LightApp_AboutDlg( const QString& defName, const QString& defVer, QWidget* parent )
45 : QtxDialog( parent, true, false, None )
46 {
47   setObjectName( "salome_about_dialog" );
48
49   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
50
51   QPixmap ico = resMgr->loadPixmap( "LightApp", tr( "ICO_ABOUT" ), false );
52   if ( !ico.isNull() )
53     setWindowIcon( ico );
54
55   QPalette pal = palette();
56
57   pal.setBrush( QPalette::Active, QPalette::WindowText, QBrush( Qt::darkBlue ) );
58   pal.setBrush( QPalette::Active, QPalette::Window,     QBrush( Qt::white ) );
59
60   pal.setBrush( QPalette::Inactive, QPalette::WindowText, QBrush( Qt::darkBlue ) );
61   pal.setBrush( QPalette::Inactive, QPalette::Window,     QBrush( Qt::white ) );
62
63
64   pal.setBrush( QPalette::Disabled, QPalette::WindowText, QBrush( Qt::darkBlue ) );
65   pal.setBrush( QPalette::Disabled, QPalette::Window,     QBrush( Qt::white ) );
66
67
68
69   setPalette(pal);
70
71   QTabWidget* tw = new QTabWidget( mainFrame() );
72   
73   QGridLayout* main = new QGridLayout( mainFrame() );
74   main->addWidget( tw, 0, 0, 1, 3 );
75   
76   QtxGridBox* base = new QtxGridBox( 1, Qt::Horizontal, tw, 0, 0 );
77   base->setInsideMargin( 0 );
78
79   tw->addTab(base, tr("ABOUT_BASE") );
80
81   tw->addTab(getModulesInfoWidget(tw), tr("ABOUT_MODULE_INFOS") );
82
83   QPushButton * btn = new QPushButton( tr("ABOUT_CLOSE"), mainFrame() );
84
85   main->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), 1, 0, 1, 1);
86
87   main->addWidget( btn, 1, 1, 1, 1);
88
89   main->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), 1, 2, 1, 1);
90
91   connect(btn, SIGNAL( clicked() ), this, SLOT( accept()) );
92
93
94   QLabel* screen = new QLabel( base );
95   screen->setScaledContents( true );
96   screen->setAlignment( Qt::AlignCenter );
97   screen->setFrameStyle( QFrame::Box | QFrame::Plain );
98
99   QLabel* title = new QLabel( base );
100   title->setAlignment( Qt::AlignCenter );
101   changeFont( title, true, false, false, 5 );
102
103   QLabel* version = new QLabel( base );
104   version->setAlignment( Qt::AlignCenter );
105   changeFont( version, false, true, false, 2 );
106   
107   QLabel* copyright = new QLabel( base );
108   copyright->setAlignment( Qt::AlignCenter );
109   changeFont( copyright, false, false, false, 1 );
110
111   QLabel* license = new QLabel( base );
112   license->setAlignment( Qt::AlignCenter );
113   changeFont( license, false, false, false, 1 );
114
115   screen->setPixmap( resMgr->loadPixmap( "LightApp", tr( "ABOUT" ), false ) );
116   checkLabel( screen );
117
118   QString titleText = tr( "ABOUT_TITLE" );
119   if ( titleText == "ABOUT_TITLE" )
120     titleText = defName;
121   title->setText( titleText );
122   checkLabel( title );
123
124   QString verText = tr( "ABOUT_VERSION" );
125   if ( verText.contains( "%1" ) )
126     verText = verText.arg( defVer );
127   version->setText( verText );
128   checkLabel( version );
129
130   copyright->setText( tr( "ABOUT_COPYRIGHT" ) );
131   checkLabel( copyright );
132
133   license->setText( tr( "ABOUT_LICENSE" ) );
134   checkLabel( license );
135
136   QString capText = tr( "ABOUT_CAPTION" );
137   if ( capText.contains( "%1" ) )
138     capText = capText.arg( defName );
139   setWindowTitle( capText );
140
141   setSizeGripEnabled( false );
142 }
143
144 /*!Destructor.*/
145 LightApp_AboutDlg::~LightApp_AboutDlg()
146 {
147   //! Do nothing.
148 }
149
150 /*!Change font of widget \a wid.
151  *\param wid - QWidget
152  *\param bold - boolean value
153  *\param italic - boolean value
154  *\param underline - boolean value
155  *\param inc - integer increment for font point size.
156  */
157 void LightApp_AboutDlg::changeFont( QWidget* wid, const bool bold, const bool italic,
158                                      const bool underline, const int inc ) const
159 {
160   if ( !wid )
161     return;
162
163   QFont widFont = wid->font();
164   widFont.setBold( bold );
165   widFont.setItalic( italic );
166   widFont.setUnderline( underline );
167   widFont.setPointSize( widFont.pointSize() + inc );
168 }
169
170 /*!Check lable \a lab.*/
171 void LightApp_AboutDlg::checkLabel( QLabel* lab ) const
172 {
173   if ( !lab )
174     return;
175
176   bool vis = !lab->text().trimmed().isEmpty() ||
177              ( lab->pixmap() && !lab->pixmap()->isNull() );
178   vis ? lab->show() : lab->hide();
179 }
180
181 /*! Return widget with info about versions of modules */
182 QWidget* LightApp_AboutDlg::getModulesInfoWidget(QWidget* parent) const {
183
184   QWidget* modulesInfo = new QWidget(parent);
185   QGridLayout* gridLayout = new QGridLayout(modulesInfo);
186
187   LightApp_Application* app = dynamic_cast<LightApp_Application*>(SUIT_Session::session()->activeApplication());
188   if(app) {
189
190     CAM_Application::ModuleShortInfoList info = app->getVersionInfo();
191     
192     CAM_Application::ModuleShortInfoList::const_iterator it = info.constBegin();
193     int i = 0;
194     
195     QString unknownVersion = tr("ABOUT_UNKNOWN_VERSION");
196
197     while (it != info.constEnd()) {
198       QLabel * name = new QLabel( "<h4>" + (*it).name + ":</h4>", modulesInfo);
199       QString v = (*it).version.isEmpty() ?  unknownVersion : (*it).version;
200       QLabel * version = new QLabel("<h4>" + v + "</h4>",modulesInfo);
201       gridLayout->addWidget(name , i, 0);
202       gridLayout->addWidget(version , i, 1);
203       gridLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), i, 2);
204       it++;
205       i++;
206     }
207     gridLayout->addItem(new QSpacerItem(0, 0,  QSizePolicy::Minimum, QSizePolicy::Expanding), i, 0);
208     gridLayout->addItem(new QSpacerItem(0, 0,  QSizePolicy::Minimum, QSizePolicy::Expanding), i, 1);
209   }  
210   return modulesInfo;
211 }