Salome HOME
Added slots for Copy and Paste operations
[modules/gui.git] / src / SalomeApp / SalomeApp_ModuleDlg.cxx
1 //  SALOME SALOMEGUI : implementation of desktop and GUI kernel
2 //
3 //  Copyright (C) 2005  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : SalomeApp_ModuleDlg.cxx
8 //  Author : Michael Zorin (mzn)
9 //  Module : SALOME
10
11 #include "SalomeApp_ModuleDlg.h"
12
13 #include <qframe.h>
14 #include <qlabel.h>
15 #include <qpushbutton.h>
16 #include <qlayout.h>
17 #include <qpixmap.h>
18 using namespace std;
19
20 static const char* const default_icon[] = { 
21 "48 48 17 1",
22 ". c None",
23 "# c #161e4c",
24 "b c #1d3638",
25 "e c #2f585b",
26 "i c #345b5e",
27 "c c #386266",
28 "g c #3f7477",
29 "d c #4d8589",
30 "m c #519099",
31 "o c #6abbc1",
32 "a c #70c9d3",
33 "f c #79ddea",
34 "n c #7adff2",
35 "k c #7ce2f4",
36 "j c #993550",
37 "h c #d84b71",
38 "l c #ef537d",
39 "................................................",
40 "................................................",
41 "................................................",
42 "................................................",
43 "................................................",
44 "................########.########.########......",
45 "...............#aaaaaa###aaaaaa###aaaaaa##......",
46 "..............#aaaaaa#b#aaaaaa#b#aaaaaa#c#......",
47 ".............########b########b########cc#......",
48 ".............#dddddd#b#dddddd#b#dddddd#cc#......",
49 "...........########d########d########d#cc#......",
50 "..........#aaaaaa###aaaaaa###aaaaaa##d#cc#......",
51 ".........#aaaaaa#b#aaaaaa#b#aaaaaa#c#d#cc#......",
52 "........########b########e########cc#d#c#.......",
53 "........#dddddd#b#dddddd#e#ffffff#cc#d####......",
54 "......########d########d########f#cc###g##......",
55 ".....#aaaaaa###aaaaaa###hhhhhh##f#cc#gg#c#......",
56 "....#aaaaaa#b#aaaaaa#i#hhhhhh#j#f#cc###cc#......",
57 "...########b########i########jj#f#c#gg#cc#......",
58 "...#kkkkkk#b#kkkkkk#i#llllll#jj#f####g#cc#......",
59 "...#kkkkkk#b#kkkkkk#i#llllll#jj###m##g#cc#......",
60 "...#knnkkk#b#kkkkkk#i#llllll#jj#mm#c#g#cc#......",
61 "...#knnkkk#b#kkkkkk#i#llllll#jj###cc#g#c#.......",
62 "...#kkkkkk#b#kkkkkk#i#llllll#j#dd#cc#g####......",
63 "...#kkkkkk###kkkkkk###llllll####d#cc###g##......",
64 "...########g########g########o##d#cc#gg#c#......",
65 "....#gggggg#b#gggggg#b#oooooo#c#d#cc###cc#......",
66 "...########b########b########cc#d#c#gg#cc#......",
67 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#d####g#cc#......",
68 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc###g##g#cc#......",
69 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#gg#c#g#cc#......",
70 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc###cc#g#c#.......",
71 "...#kkkkkk#b#kkkkkk#b#kkkkkk#c#gg#cc#g##........",
72 "...#kkkkkk###kkkkkk###kkkkkk####g#cc###.........",
73 "...########g########g########g##g#cc#...........",
74 "....#gggggg#b#gggggg#b#gggggg#c#g#cc#...........",
75 "...########b########b########cc#g#c#............",
76 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#g##.............",
77 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc###..............",
78 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#................",
79 "...#kkkkkk#b#kkkkkk#b#kkkkkk#cc#................",
80 "...#kkkkkk#b#kkkkkk#b#kkkkkk#c#.................",
81 "...#kkkkkk###kkkkkk###kkkkkk##..................",
82 "...########.########.########...................",
83 "................................................",
84 "................................................",
85 "................................................",
86 "................................................"};
87
88 //==============================================================================================================================
89 /*!
90  *  SalomeApp_ModuleDlg::SalomeApp_ModuleDlg
91  *
92  *  Constructor
93  */
94 //==============================================================================================================================
95 SalomeApp_ModuleDlg::SalomeApp_ModuleDlg ( QWidget * parent, const QString& component, const QPixmap icon )
96      : QDialog ( parent, "ActivateModuleDlg", true,  WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
97 {
98   QPixmap defaultIcon( ( const char** ) default_icon );
99   setCaption( tr( "CAPTION" ) );
100   setSizeGripEnabled( TRUE );
101   
102   QGridLayout* ActivateModuleDlgLayout = new QGridLayout( this ); 
103   ActivateModuleDlgLayout->setMargin( 11 ); ActivateModuleDlgLayout->setSpacing( 6 );
104
105   // Module's name and icon
106   myComponentFrame = new QFrame( this, "myComponentFrame" );
107   myComponentFrame->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Expanding ) );
108   myComponentFrame->setMinimumHeight( 100 );
109   myComponentFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
110   
111   QGridLayout* myComponentFrameLayout = new QGridLayout( myComponentFrame ); 
112   myComponentFrameLayout->setMargin( 11 ); myComponentFrameLayout->setSpacing( 6 );
113
114   // --> icon
115   myComponentIcon = new QLabel( myComponentFrame, "myComponentIcon" );
116   myComponentIcon->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
117   myComponentIcon->setPixmap( !icon.isNull() ? icon : defaultIcon );
118   myComponentIcon->setScaledContents( false );
119   myComponentIcon->setAlignment( AlignCenter );
120   // --> name
121   myComponentLab = new QLabel( component, myComponentFrame, "myComponentLab" );
122   QFont fnt = myComponentLab->font(); fnt.setBold( TRUE ); myComponentLab->setFont( fnt ); 
123   myComponentLab->setAlignment( AlignCenter );
124
125   myComponentFrameLayout->addWidget( myComponentIcon, 0, 0 );
126   myComponentFrameLayout->addWidget( myComponentLab,  0, 1 );
127
128   // Info
129   QVBoxLayout* infoLayout = new QVBoxLayout();
130   infoLayout->setMargin( 0 ); infoLayout->setSpacing( 6 );
131   
132   // --> top line
133   QFrame* myLine1 = new QFrame( this, "myLine1" );
134   myLine1->setFrameStyle( QFrame::HLine | QFrame::Plain );
135   // --> info label  
136   myInfoLabel = new QLabel( tr ("ActivateComponent_DESCRIPTION"), this, "myInfoLabel" );
137   myInfoLabel->setAlignment( AlignCenter );
138   // --> bottom line
139   QFrame*  myLine2 = new QFrame( this, "myLine2" );
140   myLine2->setFrameStyle( QFrame::HLine | QFrame::Plain );
141   
142   infoLayout->addStretch();
143   infoLayout->addWidget( myLine1 );
144   infoLayout->addWidget( myInfoLabel );
145   infoLayout->addWidget( myLine2 );
146   infoLayout->addStretch();
147   
148   // Buttons
149   QHBoxLayout* btnLayout = new QHBoxLayout(); 
150   btnLayout->setMargin( 0 ); btnLayout->setSpacing( 6 );
151   
152   // --> New
153   myNewBtn = new QPushButton( tr( "NEW" ), this, "myNewBtn" );
154   myNewBtn->setDefault( true ); myNewBtn->setAutoDefault( true );
155   // --> Open
156   myOpenBtn = new QPushButton( tr( "OPEN" ), this, "myOpenBtn" );
157   myOpenBtn->setAutoDefault( true );
158   // --> Load
159   myLoadBtn = new QPushButton( tr( "LOAD" ), this, "myLoadBtn" );
160   myLoadBtn->setAutoDefault( true );
161   // --> Cancel
162   myCancelBtn = new QPushButton( tr( "CANCEL" ), this, "myCancelBtn" );
163   myCancelBtn->setAutoDefault( true );
164   
165   btnLayout->addWidget( myNewBtn );
166   btnLayout->addWidget( myOpenBtn );
167   btnLayout->addWidget( myLoadBtn );
168   btnLayout->addStretch();
169   btnLayout->addSpacing( 70 );
170   btnLayout->addStretch();
171   btnLayout->addWidget( myCancelBtn );
172
173   ActivateModuleDlgLayout->addWidget(          myComponentFrame, 0,    0    );
174   ActivateModuleDlgLayout->addLayout(          infoLayout,       0,    1    );
175   ActivateModuleDlgLayout->addMultiCellLayout( btnLayout,        1, 1, 0, 1 );
176
177   // signals and slots connections
178   connect( myNewBtn,    SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) );
179   connect( myOpenBtn,   SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) );
180   connect( myLoadBtn,   SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) );
181   connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
182 }
183
184 //==============================================================================================================================
185 /*!
186  *  SalomeApp_ModuleDlg::onButtonClicked
187  *
188  *  Buttons slot
189  */
190 //==============================================================================================================================
191 void SalomeApp_ModuleDlg::onButtonClicked()
192 {
193   QPushButton* btn = ( QPushButton* )sender();
194   if ( btn == myNewBtn )
195     done( 1 );
196   if ( btn == myOpenBtn )
197     done( 2 );
198   if ( btn == myLoadBtn )
199     done( 3 );
200 }