Moka Ihm Qt
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
select-bar.qt.cc
Go to the documentation of this file.
1 /*
2  * Moka : Un modeleur de 3-G-cartes.
3  * Copyright (C) 2004, Moka Team, Université de Poitiers, Laboratoire SIC
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * Copyright (C) 2009, Guillaume Damiand, CNRS, LIRIS,
6  * guillaume.damiand@liris.cnrs.fr, http://liris.cnrs.fr/
7  *
8  * This file is part of Moka
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #include "select-bar.qt.hh"
25 #include "window.qt.hh"
26 #include "HtmlEntities.hh"
27 
28 #include <QtGui/QVBoxLayout>
29 #include <QtGui/QToolTip>
30 
31 #define NB_SELECTION_BOUTONS 16
32 
33 //*****************************
34 // Constantes
35 //*****************************
36 static const char * const mokaLabels [ NB_SELECTION_BOUTONS ] =
37 {
38  "B",
39  "0", "1", "2", "3",
40  "01*", "02*", "03*",
41  "12", "13", "23",
42  "S", "A*", "F*", "V*", "C"
43 } ;
44 
45 static const TOrbit mokaOrbit [ NB_SELECTION_BOUTONS ] =
46 {
47  ORBIT_SELF,
48  ORBIT_0, ORBIT_1, ORBIT_2, ORBIT_3,
49  ORBIT_01 , ORBIT_02 , ORBIT_03,
50  ORBIT_12 , ORBIT_13 , ORBIT_23,
51  ORBIT_123, ORBIT_023, ORBIT_013, ORBIT_012, ORBIT_0123
52 } ;
53 
54 static const char * const mokaTooltips [ NB_SELECTION_BOUTONS ] =
55 {
56  "[----: Brin]",
57  "[0---]", "[-1--]", "[--2-]", "[---3]",
58  "[01--: Face/Volume (ou demi-face)]",
59  "[0-2-: Ar&ecirc;te/Volume]",
60  "[0--3: Ar&ecirc;te/Face (ou demi-ar&ecirc;te)]",
61  "[-12-: Sommet/Volume]", "[-1-3: Sommet/Face]",
62  "[--23: Sommet/Ar&ecirc;te (ou demi-sommet)]",
63  "[-123: Sommet]", "[0-23: Ar&ecirc;te]", "[01-3: Face]",
64  "[012-: Volume]",
65  "[0123: Composante connexe]"
66 } ;
67 
68 //******************************
69 // Constructeur
70 //******************************
71 
73  :
74  QToolBar(*HTML::decode("S&eacute;lection") , parent),
75  FControler(parent -> getControler()),
76  FParent(parent)
77 {
78  setAllowedAreas(Qt::LeftToolBarArea | Qt::RightToolBarArea);
79 
80  // Mise en place d'un layout
81  //--------------------------
82  QWidget * total = new QWidget(this) ;
83  QVBoxLayout * bl = new QVBoxLayout(total) ;
84  bl -> setSpacing(0);
85 
86  // Creation des boutons
87  //---------------------
88  FGroupe = new QGroupBox(total) ;
89  QVBoxLayout * gpl = new QVBoxLayout(FGroupe) ;
91 
92  for (int i = 0 ; i < NB_SELECTION_BOUTONS ; i++)
93  {
94  rb_tab[i] = new IdRadioButton(i, mokaLabels[i]) ;
95  gpl -> addWidget(rb_tab[i]);
96 
97  connect(rb_tab[i], SIGNAL(clicked(int)),
98  this, SLOT(callBackClic(int))) ;
99  }
100 
101  rb_tab[0] -> setChecked(true);
102 
103  // Mise en place des tooltips
104  for (int i = 0 ; i < NB_SELECTION_BOUTONS ; i++)
105  rb_tab[i] -> setToolTip(*HTML::decode(mokaTooltips [ i ])) ;
106 
107  // Boutons de niveau de selection (1, 2 ou 3)
108  //-------------------------------------------
109 
110  // Disposition
111  QWidget * sel = new QWidget ;
112  sel -> setToolTip(*HTML::decode("Niveau de s&eacute;lection")) ;
113 
114  QHBoxLayout * bh = new QHBoxLayout(sel) ;
115  bh -> setSpacing(0);
116 
117  // Allocation
118  int nb_selection_lev = FControler -> getNbSelectionLevels();
119  FNiveaux = new IdPushButton * [ nb_selection_lev ] ;
120 
121  // Creation
122  for (int i = 0;i < nb_selection_lev;i++)
123  {
124  FNiveaux [ i ] = new IdPushButton(i, QString::number(i + 1)) ;
125  bh -> addWidget(FNiveaux [ i ]) ;
126 
127  connect(FNiveaux[i], SIGNAL(clicked(int)),
128  this, SLOT(callbackSelectionLevel(int))) ;
129  }
130 
131  FNiveaux [ 0 ] -> setEnabled(false) ;
132 
133  // Le bouton block
134  FBlock = new QPushButton("Block");
135  FBlock->setCheckable(true);
136  connect(FBlock, SIGNAL(toggled(bool)), this,
137  SLOT(callbackToggleBlock(bool)));
138 
139  // Le bouton Simplif
140  FSimplif = new QPushButton("Simplif");
141  FSimplif->setCheckable(true);
142  connect(FSimplif, SIGNAL(toggled(bool)), this,
143  SLOT(callbackToggleSimplificationMode(bool)));
144 
145  // Ajout au layout principal
146  bl -> addWidget(FGroupe) ;
147  bl -> addWidget(sel) ;
148  bl -> addWidget(FBlock) ;
149  bl -> addWidget(FSimplif) ;
150 
151  total -> setMaximumWidth(90);
152  addWidget(total);
153 }
154 
155 //**********************************
156 // Destructeur
157 //**********************************
159 //*********************************
160 // Slot
161 //*********************************
162 void SelectBar::callBackClic(int ind)
163 {
164  FControler->setSelectionOrbit(mokaOrbit [ ind ]) ;
165  FParent->repaint() ;
166 }
167 
168 static bool freezed = false ;
169 
170 void SelectBar::callbackSelectionLevel(int id)
171 {
172  if ( !freezed )
173  setSelectionLevel(id) ;
174 }
175 
176 void SelectBar :: setSelectionLevel(int L , bool freeze)
177 {
178  if (! freeze)
179  {
180  FControler -> setSelectionLevel(L) ;
181  FParent -> repaint() ;
182  }
183 
184  freezed = true;
185 
186  for (int i = 0 ; i < FControler -> getNbSelectionLevels() ; i++)
187  {
188  if (FControler -> getSelectionLevel() == i)
189  FNiveaux [ i ] -> setEnabled(false) ;
190  else
191  FNiveaux [ i ] -> setEnabled(true) ;
192  }
193 
194  freezed = false;
195 }
196 
198 {
199  for (int i = 0 ; i < FControler -> getNbSelectionLevels() ; i++)
200  {
201  if (! FNiveaux [ i ] -> isEnabled())
202  {
203  setSelectionLevel((i + 1) % FControler->getNbSelectionLevels()) ;
204  return ;
205  }
206  }
207 }
208 
209 void SelectBar::callbackToggleBlock( bool ABlock )
210 {
211  FControler->toggleModelBlocked();
212  if ( !ABlock ) FParent->repaint();
213 }
214 
215 void SelectBar::callbackToggleSimplificationMode( bool ABlock )
216 {
217  FControler->toggleModeSimplification();
218  if ( !ABlock ) FParent->repaint();
219 }
220 
221 
222 
223