Back to index

salome-gui  6.5.0
LightApp_ModuleDlg.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_ModuleDlg.cxx
00024 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
00025 //
00026 #include "LightApp_ModuleDlg.h"
00027 
00028 #include <QLabel>
00029 #include <QPushButton>
00030 #include <QGridLayout>
00031 #include <QHBoxLayout>
00032 
00037 static const char* const default_icon[] = { 
00038 "48 48 17 1",
00039 ". c None",
00040 "# c #161e4c",
00041 "b c #1d3638",
00042 "e c #2f585b",
00043 "i c #345b5e",
00044 "c c #386266",
00045 "g c #3f7477",
00046 "d c #4d8589",
00047 "m c #519099",
00048 "o c #6abbc1",
00049 "a c #70c9d3",
00050 "f c #79ddea",
00051 "n c #7adff2",
00052 "k c #7ce2f4",
00053 "j c #993550",
00054 "h c #d84b71",
00055 "l c #ef537d",
00056 "................................................",
00057 "................................................",
00058 "................................................",
00059 "................................................",
00060 "................................................",
00061 "................########.########.########......",
00062 "...............#aaaaaa###aaaaaa###aaaaaa##......",
00063 "..............#aaaaaa#b#aaaaaa#b#aaaaaa#c#......",
00064 ".............########b########b########cc#......",
00065 ".............#dddddd#b#dddddd#b#dddddd#cc#......",
00066 "...........########d########d########d#cc#......",
00067 "..........#aaaaaa###aaaaaa###aaaaaa##d#cc#......",
00068 ".........#aaaaaa#b#aaaaaa#b#aaaaaa#c#d#cc#......",
00069 "........########b########e########cc#d#c#.......",
00070 "........#dddddd#b#dddddd#e#ffffff#cc#d####......",
00071 "......########d########d########f#cc###g##......",
00072 ".....#aaaaaa###aaaaaa###hhhhhh##f#cc#gg#c#......",
00073 "....#aaaaaa#b#aaaaaa#i#hhhhhh#j#f#cc###cc#......",
00074 "...########b########i########jj#f#c#gg#cc#......",
00075 "...#kkkkkk#b#kkkkkk#i#llllll#jj#f####g#cc#......",
00076 "...#kkkkkk#b#kkkkkk#i#llllll#jj###m##g#cc#......",
00077 "...#knnkkk#b#kkkkkk#i#llllll#jj#mm#c#g#cc#......",
00078 "...#knnkkk#b#kkkkkk#i#llllll#jj###cc#g#c#.......",
00079 "...#kkkkkk#b#kkkkkk#i#llllll#j#dd#cc#g####......",
00080 "...#kkkkkk###kkkkkk###llllll####d#cc###g##......",
00081 "...########g########g########o##d#cc#gg#c#......",
00082 "....#gggggg#b#gggggg#b#oooooo#c#d#cc###cc#......",
00083 "...########b########b########cc#d#c#gg#cc#......",
00084 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#d####g#cc#......",
00085 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc###g##g#cc#......",
00086 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#gg#c#g#cc#......",
00087 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc###cc#g#c#.......",
00088 "...#kkkkkk#b#kkkkkk#b#kkkkkk#c#gg#cc#g##........",
00089 "...#kkkkkk###kkkkkk###kkkkkk####g#cc###.........",
00090 "...########g########g########g##g#cc#...........",
00091 "....#gggggg#b#gggggg#b#gggggg#c#g#cc#...........",
00092 "...########b########b########cc#g#c#............",
00093 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#g##.............",
00094 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc###..............",
00095 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#................",
00096 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#................",
00097 "...#kkkkkk#b#kkkkkk#b#kkkkkk#c#.................",
00098 "...#kkkkkk###kkkkkk###kkkkkk##..................",
00099 "...########.########.########...................",
00100 "................................................",
00101 "................................................",
00102 "................................................",
00103 "................................................"};
00104 
00151 LightApp_ModuleDlg::LightApp_ModuleDlg( QWidget*       parent, 
00152                                         const QString& component, 
00153                                         const QPixmap& icon )
00154 : QDialog ( parent )
00155 {
00156   setModal( true );
00157 
00158   QPixmap defaultIcon( default_icon );
00159   setWindowTitle( tr( "CAPTION" ) );
00160   
00161   // icon
00162   QLabel* iconLab = new QLabel( this );
00163   iconLab->setFrameStyle( QFrame::Box | QFrame::Sunken );
00164   iconLab->setMinimumSize( 70, 70 );
00165   iconLab->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
00166   iconLab->setPixmap( !icon.isNull() ? icon : defaultIcon );
00167   iconLab->setScaledContents( false );
00168   iconLab->setAlignment( Qt::AlignCenter );
00169 
00170   // info message
00171   QLabel* infoLab = new QLabel( tr ( "DESCRIPTION" ).arg( component ), this );
00172   infoLab->setTextFormat( Qt::RichText );
00173   infoLab->setAlignment( Qt::AlignCenter );
00174   
00175   // Buttons
00176   myButtonLayout = new QHBoxLayout(); 
00177   myButtonLayout->setMargin( 0 ); 
00178   myButtonLayout->setSpacing( 6 );
00179 
00180   // <Cancel>
00181   QPushButton* cancelBtn = new QPushButton( tr( "CANCEL" ), this );
00182   cancelBtn->setAutoDefault( true );
00183 
00184   myButtonLayout->addSpacing( 70 );
00185   myButtonLayout->addStretch();
00186   myButtonLayout->addWidget( cancelBtn );
00187 
00188   QGridLayout* layout = new QGridLayout( this ); 
00189   layout->setMargin( 11 );
00190   layout->setSpacing( 6 );
00191 
00192   layout->addWidget( iconLab, 0, 0 );
00193   layout->addWidget( infoLab, 0, 1 );
00194   layout->addLayout( myButtonLayout, 1, 0, 1, 2 );
00195 
00196   // signals and slots connections
00197   connect( cancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
00198 }
00199 
00203 LightApp_ModuleDlg::~LightApp_ModuleDlg()
00204 {
00205 }
00206 
00217 int LightApp_ModuleDlg::addButton( const QString& button, const int id )
00218 {
00219   static int lastId = 0;
00220   int bid = id == -1 ? --lastId : id;
00221 
00222   QPushButton* b = findButton( bid );
00223   if ( b ) {
00224     myButtons.remove( b );
00225     delete b;
00226   }
00227 
00228   QPushButton* newButton = new QPushButton( button, this );
00229   newButton->setAutoDefault( true );
00230 
00231   if ( myButtons.empty() ) {
00232        newButton->setDefault( true );
00233        newButton->setFocus();
00234   }
00235 
00236   myButtons.insert( newButton, bid );
00237   myButtonLayout->insertWidget( myButtonLayout->count()-3, newButton );
00238   connect( newButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
00239 
00240   return bid;
00241 }
00242 
00248 QPushButton* LightApp_ModuleDlg::findButton( const int id ) const
00249 {
00250   QPushButton* btn = 0;
00251   for ( ButtonMap::ConstIterator it = myButtons.begin(); 
00252         it != myButtons.end() && !btn; ++it ) {
00253     if ( it.value() == id )
00254       btn = it.key();
00255   }
00256   return btn;
00257 }
00258 
00266 void LightApp_ModuleDlg::accept()
00267 {
00268   QPushButton* btn = ( QPushButton* )sender();
00269   done( myButtons[ btn ] );
00270 }