Back to index

salome-gui  6.5.0
LightApp_AboutDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // File:      LightApp_AboutDlg.cxx
00024 // Created:   03.06.2005 13:52:45
00025 // Author:    Sergey TELKOV
00026 //
00027 #include "LightApp_AboutDlg.h"
00028 #include "LightApp_Application.h"
00029 
00030 #include <SUIT_Session.h>
00031 #include <SUIT_ResourceMgr.h>
00032 
00033 #include <QtxGridBox.h>
00034 
00035 #include <QLabel>
00036 #include <QVBoxLayout>
00037 #include <QPixmap>
00038 #include <QIcon>
00039 #include <QGroupBox>
00040 #include <QTabWidget>
00041 #include <QPushButton>
00042 
00044 LightApp_AboutDlg::LightApp_AboutDlg( const QString& defName, const QString& defVer, QWidget* parent )
00045 : QtxDialog( parent, true, false, None )
00046 {
00047   setObjectName( "salome_about_dialog" );
00048 
00049   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00050 
00051   QPixmap ico = resMgr->loadPixmap( "LightApp", tr( "ICO_ABOUT" ), false );
00052   if ( !ico.isNull() )
00053     setWindowIcon( ico );
00054 
00055   QPalette pal = palette();
00056 
00057   pal.setBrush( QPalette::Active, QPalette::WindowText, QBrush( Qt::darkBlue ) );
00058   pal.setBrush( QPalette::Active, QPalette::Window,     QBrush( Qt::white ) );
00059 
00060   pal.setBrush( QPalette::Inactive, QPalette::WindowText, QBrush( Qt::darkBlue ) );
00061   pal.setBrush( QPalette::Inactive, QPalette::Window,     QBrush( Qt::white ) );
00062 
00063 
00064   pal.setBrush( QPalette::Disabled, QPalette::WindowText, QBrush( Qt::darkBlue ) );
00065   pal.setBrush( QPalette::Disabled, QPalette::Window,     QBrush( Qt::white ) );
00066 
00067 
00068 
00069   setPalette(pal);
00070 
00071   QTabWidget* tw = new QTabWidget( mainFrame() );
00072   
00073   QGridLayout* main = new QGridLayout( mainFrame() );
00074   main->addWidget( tw, 0, 0, 1, 3 );
00075   
00076   QtxGridBox* base = new QtxGridBox( 1, Qt::Horizontal, tw, 0, 0 );
00077   base->setInsideMargin( 0 );
00078 
00079   tw->addTab(base, tr("ABOUT_BASE") );
00080 
00081   tw->addTab(getModulesInfoWidget(tw), tr("ABOUT_MODULE_INFOS") );
00082 
00083   QPushButton * btn = new QPushButton( tr("ABOUT_CLOSE"), mainFrame() );
00084 
00085   main->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), 1, 0, 1, 1);
00086 
00087   main->addWidget( btn, 1, 1, 1, 1);
00088 
00089   main->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), 1, 2, 1, 1);
00090 
00091   connect(btn, SIGNAL( clicked() ), this, SLOT( accept()) );
00092 
00093 
00094   QLabel* screen = new QLabel( base );
00095   screen->setScaledContents( true );
00096   screen->setAlignment( Qt::AlignCenter );
00097   screen->setFrameStyle( QFrame::Box | QFrame::Plain );
00098 
00099   QLabel* title = new QLabel( base );
00100   title->setAlignment( Qt::AlignCenter );
00101   changeFont( title, true, false, false, 5 );
00102 
00103   QLabel* version = new QLabel( base );
00104   version->setAlignment( Qt::AlignCenter );
00105   changeFont( version, false, true, false, 2 );
00106   
00107   QLabel* copyright = new QLabel( base );
00108   copyright->setAlignment( Qt::AlignCenter );
00109   changeFont( copyright, false, false, false, 1 );
00110 
00111   QLabel* license = new QLabel( base );
00112   license->setAlignment( Qt::AlignCenter );
00113   changeFont( license, false, false, false, 1 );
00114 
00115   screen->setPixmap( resMgr->loadPixmap( "LightApp", tr( "ABOUT" ), false ) );
00116   checkLabel( screen );
00117 
00118   QString titleText = tr( "ABOUT_TITLE" );
00119   if ( titleText == "ABOUT_TITLE" )
00120     titleText = defName;
00121   title->setText( titleText );
00122   checkLabel( title );
00123 
00124   QString verText = tr( "ABOUT_VERSION" );
00125   if ( verText.contains( "%1" ) )
00126     verText = verText.arg( defVer );
00127   version->setText( verText );
00128   checkLabel( version );
00129 
00130   copyright->setText( tr( "ABOUT_COPYRIGHT" ) );
00131   checkLabel( copyright );
00132 
00133   license->setText( tr( "ABOUT_LICENSE" ) );
00134   checkLabel( license );
00135 
00136   QString capText = tr( "ABOUT_CAPTION" );
00137   if ( capText.contains( "%1" ) )
00138     capText = capText.arg( defName );
00139   setWindowTitle( capText );
00140 
00141   setSizeGripEnabled( false );
00142 }
00143 
00145 LightApp_AboutDlg::~LightApp_AboutDlg()
00146 {
00148 }
00149 
00157 void LightApp_AboutDlg::changeFont( QWidget* wid, const bool bold, const bool italic,
00158                                      const bool underline, const int inc ) const
00159 {
00160   if ( !wid )
00161     return;
00162 
00163   QFont widFont = wid->font();
00164   widFont.setBold( bold );
00165   widFont.setItalic( italic );
00166   widFont.setUnderline( underline );
00167   widFont.setPointSize( widFont.pointSize() + inc );
00168 }
00169 
00171 void LightApp_AboutDlg::checkLabel( QLabel* lab ) const
00172 {
00173   if ( !lab )
00174     return;
00175 
00176   bool vis = !lab->text().trimmed().isEmpty() ||
00177              ( lab->pixmap() && !lab->pixmap()->isNull() );
00178   vis ? lab->show() : lab->hide();
00179 }
00180 
00182 QWidget* LightApp_AboutDlg::getModulesInfoWidget(QWidget* parent) const {
00183 
00184   QWidget* modulesInfo = new QWidget(parent);
00185   QGridLayout* gridLayout = new QGridLayout(modulesInfo);
00186 
00187   LightApp_Application* app = dynamic_cast<LightApp_Application*>(SUIT_Session::session()->activeApplication());
00188   if(app) {
00189 
00190     CAM_Application::ModuleShortInfoList info = app->getVersionInfo();
00191     
00192     CAM_Application::ModuleShortInfoList::const_iterator it = info.constBegin();
00193     int i = 0;
00194     
00195     QString unknownVersion = tr("ABOUT_UNKNOWN_VERSION");
00196 
00197     while (it != info.constEnd()) {
00198       QLabel * name = new QLabel( "<h4>" + (*it).name + ":</h4>", modulesInfo);
00199       QString v = (*it).version.isEmpty() ?  unknownVersion : (*it).version;
00200       QLabel * version = new QLabel("<h4>" + v + "</h4>",modulesInfo);
00201       gridLayout->addWidget(name , i, 0);
00202       gridLayout->addWidget(version , i, 1);
00203       gridLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum), i, 2);
00204       it++;
00205       i++;
00206     }
00207     gridLayout->addItem(new QSpacerItem(0, 0,  QSizePolicy::Minimum, QSizePolicy::Expanding), i, 0);
00208     gridLayout->addItem(new QSpacerItem(0, 0,  QSizePolicy::Minimum, QSizePolicy::Expanding), i, 1);
00209   }  
00210   return modulesInfo;
00211 }