Developer Documentation
viewModeWidget.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 
51 
52 
53 #include "viewModeWidget.hh"
55 
57 viewModeWidget::viewModeWidget(const QVector< ViewMode* >& _modes, QWidget *_parent)
58  : QDialog(_parent),
59  modes_(_modes)
60 {
61  setupUi(this);
62 
63 
64  connect(viewModeList, SIGNAL(itemSelectionChanged()), this, SLOT(slotSetAllWidgets()));
65 
66 
67 
68 
69 
70  connect(viewModeList, SIGNAL(currentTextChanged (QString)), this, SLOT(slotModeChanged(QString)) );
71  connect(viewModeList, SIGNAL(clicked (QModelIndex)), this, SLOT(slotModeClicked(QModelIndex)) );
72 
73 
74 
75  // View Mode buttons
76  connect(removeButton, SIGNAL(clicked()), this, SLOT(slotRemoveMode()));
77  connect(copyButton, SIGNAL(clicked()), this, SLOT(slotCopyMode()));
78  connect(addButton, SIGNAL(clicked()), this, SLOT(slotAddMode()));
79 
80  // View Mode List context Menu
81  viewModeList->setContextMenuPolicy(Qt::CustomContextMenu);
82  connect(viewModeList ,SIGNAL(customContextMenuRequested ( const QPoint & ) ),
83  this ,SLOT(slotModeContextMenu ( const QPoint & ) ));
84 
85 
86  // Context Menus for Toolbars
87  toolbarList->setContextMenuPolicy(Qt::CustomContextMenu);
88  availableToolbars->setContextMenuPolicy(Qt::CustomContextMenu);
89  connect(toolbarList ,SIGNAL(customContextMenuRequested ( const QPoint & ) ),
90  this ,SLOT(slotUsedToolbarContextMenu ( const QPoint & ) ));
91  connect(availableToolbars ,SIGNAL(customContextMenuRequested ( const QPoint & ) ),
92  this ,SLOT(slotAvailableToolbarContextMenu ( const QPoint & ) ));
93 
94 
95  // Context Menus for Toolboxes
96  toolboxList->setContextMenuPolicy(Qt::CustomContextMenu);
97  availableToolboxes->setContextMenuPolicy(Qt::CustomContextMenu);
98  connect(toolboxList ,SIGNAL(customContextMenuRequested ( const QPoint & ) ),
99  this ,SLOT(slotUsedToolboxContextMenu ( const QPoint & ) ));
100  connect(availableToolboxes ,SIGNAL(customContextMenuRequested ( const QPoint & ) ),
101  this ,SLOT(slotAvailableToolboxContextMenu ( const QPoint & ) ));
102 
103 
104  // Context Menus for Context Menus
105  contextMenuList->setContextMenuPolicy(Qt::CustomContextMenu);
106  availableContextMenus->setContextMenuPolicy(Qt::CustomContextMenu);
107  connect(contextMenuList ,SIGNAL(customContextMenuRequested ( const QPoint & ) ),
108  this ,SLOT(slotUsedContextMenuContextMenu ( const QPoint & ) ));
109  connect(availableContextMenus ,SIGNAL(customContextMenuRequested ( const QPoint & ) ),
110  this ,SLOT(slotAvailableContextMenuContextMenu ( const QPoint & ) ));
111 
112 
113  // Toolbar Buttons to add and remove toolbars in the given Mode
114  connect(rightArrowToolbar, SIGNAL(clicked()), this, SLOT(slotRightArrowToolbar()) );
115  rightArrowToolbar->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "arrow-right.png" ) );
116  connect(leftArrowToolbar, SIGNAL(clicked()), this, SLOT(slotLeftArrowToolbar()) );
117  leftArrowToolbar->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "arrow-left.png" ) );
118 
119 
120  // Toolbox Buttons to add, remove and order toolboxes in the given Mode
121  connect(rightArrowToolbox, SIGNAL(clicked()), this, SLOT(slotRightArrowToolbox()) );
122  rightArrowToolbox->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "arrow-right.png" ) );
123  connect(leftArrowToolbox, SIGNAL(clicked()), this, SLOT(slotLeftArrowToolbox()) );
124  leftArrowToolbox->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "arrow-left.png" ) );
125 
126  connect(upButtonToolbox, SIGNAL(clicked()), this, SLOT(slotMoveToolboxUp()) );
127  upButtonToolbox->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "arrow-up.png" ) );
128  connect(downButtonToolbox, SIGNAL(clicked()), this, SLOT(slotMoveToolboxDown()) );
129  downButtonToolbox->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "arrow-down.png" ) );
130 
131 
132  // ContextMenu Buttons to add, remove and order ContextMenus in the given Mode
133  connect(rightArrowContextMenu, SIGNAL(clicked()), this, SLOT(slotRightArrowContextMenu()) );
134  rightArrowContextMenu->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "arrow-right.png" ) );
135  connect(leftArrowContextMenu, SIGNAL(clicked()), this, SLOT(slotLeftArrowContextMenu()) );
136  leftArrowContextMenu->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "arrow-left.png" ) );
137 
138  connect(upButtonContextMenu, SIGNAL(clicked()), this, SLOT(slotMoveContextMenuUp()) );
139  upButtonContextMenu->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "arrow-up.png" ) );
140  connect(downButtonContextMenu, SIGNAL(clicked()), this, SLOT(slotMoveContextMenuDown()) );
141  downButtonContextMenu->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "arrow-down.png" ) );
142 
143 
144 
145  // General Buttons
146  // Apply currently configured Mode
147  connect(okButton, SIGNAL(clicked()), this, SLOT(slotChangeView()));
148  connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));
149  connect(saveButton, SIGNAL(clicked()), this, SLOT(slotSaveMode()));
150 }
151 
152 
153 // =======================================================================================================
154 // View Mode button slots
155 // =======================================================================================================
157  emit removeMode( viewModeList->currentItem()->text() );
158  QListWidgetItem* item = viewModeList->takeItem( viewModeList->currentRow() );
159  delete item;
160 }
161 
163  // Find currently selected Mode
164  // Search for current mode
165  int id = -1;
166  if ( viewModeList->selectedItems().count() > 0)
167  for (int i=0; i < modes_.size(); i++)
168  if (modes_[i]->name == viewModeList->currentItem()->text()){
169  id = i;
170  break;
171  }
172 
173  if ( id == -1 ) {
174  std::cerr << "Currently selected Mode not found?!" << std::endl;
175  return;
176  }
177 
178  //ask for a name for the new viewmode as it is not a custom one
179  bool ok;
180  QString name = QInputDialog::getText(this, tr("Copy View Mode"),
181  tr("Please enter a name for the new View Mode"), QLineEdit::Normal,
182  "", &ok);
183 
184  // Check if valid
185  if (!ok || name.isEmpty()) {
186  QMessageBox::warning(this, tr("Copy View Mode"), tr("Please enter a Name"), QMessageBox::Ok);
187  return;
188  }
189 
190  //check if name already exists
191  for (int i=0; i < modes_.size(); i++)
192  if (modes_[i]->name == name){
193  QMessageBox::warning(this, tr("Copy View Mode"), tr("Cannot Copy ViewMode. \nNew Name already in use for a different mode."), QMessageBox::Ok);
194  return;
195  }
196 
197  emit saveMode(name, true, modes_[id]->visibleToolboxes, modes_[id]->visibleToolbars, modes_[id]->visibleContextMenus);
198 
199  QListWidgetItem *item = new QListWidgetItem(viewModeList);
200  item->setTextAlignment(Qt::AlignHCenter);
201  item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
202  item->setIcon(QIcon(OpenFlipper::Options::iconDirStr() + QDir::separator () + "Unknown.png"));
203  item->setText(name);
204 
205  item->setForeground( QBrush(QColor(0,0,150) ) );
206 
207  show(name);
208 }
209 
211 
212  //ask for a name for the new viewmode as it is not a custom one
213  bool ok;
214  QString name = QInputDialog::getText(this, tr("Add View Mode"),
215  tr("Please enter a name for the new View Mode"), QLineEdit::Normal,
216  "", &ok);
217 
218  // Check if valid
219  if (!ok || name.isEmpty()) {
220  QMessageBox::warning(this, tr("Add View Mode"), tr("Please enter a Name"), QMessageBox::Ok);
221  return;
222  }
223 
224  //check if name already exists
225  for (int i=0; i < modes_.size(); i++)
226  if (modes_[i]->name == name){
227  QMessageBox::warning(this, tr("Add View Mode"), tr("Cannot Add ViewMode. \nNew Name already in use for a different mode."), QMessageBox::Ok);
228  return;
229  }
230 
231  emit saveMode(name, true, QStringList(), QStringList(), modes_[0]->visibleContextMenus);
232 
233  QListWidgetItem *item = new QListWidgetItem(viewModeList);
234  item->setTextAlignment(Qt::AlignHCenter);
235  item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
236  item->setIcon(QIcon(OpenFlipper::Options::iconDirStr() + QDir::separator () + "Unknown.png"));
237  item->setText(name);
238 
239  item->setForeground( QBrush(QColor(0,0,150) ) );
240 
241  show(name);
242 }
243 
244 // =======================================================================================================
245 // View Mode Context Menu
246 // =======================================================================================================
247 void viewModeWidget::slotModeContextMenu ( const QPoint & _pos ){
248 
249  if (viewModeList->itemAt(_pos)){
250 
251  QMenu menu(0);
252 
253  menu.addAction(tr("Remove Mode"), this, SLOT ( slotRemoveMode() ));
254  menu.addAction(tr("Copy Mode"), this, SLOT ( slotCopyMode() ));
255  menu.addAction(tr("Change Icon"), this, SLOT ( slotSetIcon() ));
256 
257  //check if mode is custom e.g. that it can be removed
258  for (int i=0; i < modes_.size(); i++)
259  if (modes_[i]->name == viewModeList->currentItem()->text()){
260  menu.actions()[0]->setEnabled(modes_[i]->custom);
261  menu.actions()[2]->setEnabled(modes_[i]->custom);
262  break;
263  }
264 
265  menu.exec(viewModeList->mapToGlobal( _pos) );
266  }
267 }
268 
270  // Get the correct mode
271  int id = -1;
272  for (int i=0; i < modes_.size(); i++)
273  if (modes_[i]->name == viewModeList->currentItem()->text()){
274  id = i;
275  break;
276  }
277 
278  if ( id == -1) {
279  std::cerr << "Unable to find Mode viewModeWidget::slotSetIcon()" << std::endl;
280  return;
281  }
282 
283  // Get the filename from the user
284  QString fileName = QFileDialog::getOpenFileName ( this, tr("Select Image for view Mode ( best size : 150x150px )"), QString(), tr("Images (*.png *.xpm *.jpg)") );
285 
286  QFile file(fileName);
287  QFileInfo fileInfo(file);
288 
289  if ( ! file.exists() )
290  return;
291 
292 
293  file.copy(OpenFlipper::Options::configDirStr() + QDir::separator() + "Icons" + QDir::separator() + "viewMode_" + fileInfo.fileName() );
294 
295  modes_[id]->icon = "viewMode_" + fileInfo.fileName();
296 
297  show(modes_[id]->name);
298 }
299 
300 // =======================================================================================================
301 // ToolBox, ToolBar and ContextMenu Lists update functions
302 // =======================================================================================================
304  toolboxList->clear();
305  toolbarList->clear();
306  contextMenuList->clear();
307  availableToolboxes->clear();
308  availableToolbars->clear();
309  availableContextMenus->clear();
310 
311  QStringList toolboxes;
312  QStringList toolbars;
313  QStringList contextmenus;
314 
315  //iterate over all selected modes
316  for (int m=0; m < viewModeList->selectedItems().size(); m++) {
317 
318  // find mode in modeVector modes_
319  for (int i=0; i < modes_.size(); i++) {
320  if ( modes_[i]->name == (viewModeList->selectedItems()[m])->text() ) {
321  toolboxes = modes_[i]->visibleToolboxes;
322  toolbars = modes_[i]->visibleToolbars;
323  contextmenus = modes_[i]->visibleContextMenus;
324  if (contextmenus.contains("ALL_THAT_EXIST"))
325  contextmenus = modes_[0]->visibleContextMenus;
326  toolboxList->addItems(toolboxes); //add corresponding widgets
327  toolbarList->addItems(toolbars);
328  contextMenuList->addItems(contextmenus);
329  break;
330  }
331  }
332  }
333 
334 
335  if ( !modes_.empty() ) {
336  QStringList allToolboxes = modes_[0]->visibleToolboxes;
337  QStringList allToolbars = modes_[0]->visibleToolbars;
338  QStringList allContextMenus = modes_[0]->visibleContextMenus;
339 
340  QStringList availableToolboxList;
341  QStringList availableToolbarList;
342  QStringList availableContextMenuList;
343 
344  for ( int i = 0; i < allToolboxes.size(); ++i ) {
345  if ( ! toolboxes.contains(allToolboxes[i]) )
346  availableToolboxList.push_back(allToolboxes[i]);
347  }
348 
349  for ( int i = 0; i < allToolbars.size(); ++i ) {
350  if ( ! toolbars.contains(allToolbars[i]) )
351  availableToolbarList.push_back(allToolbars[i]);
352  }
353 
354  for ( int i = 0; i < allContextMenus.size(); ++i ) {
355  if ( ! contextmenus.contains(allContextMenus[i]) )
356  availableContextMenuList.push_back(allContextMenus[i]);
357  }
358 
359  availableToolboxes->addItems(availableToolboxList);
360  availableToolbars->addItems(availableToolbarList);
361  availableContextMenus->addItems(availableContextMenuList);
362 
363  } else {
364  std::cerr << "Mode not found!" << std::endl;
365  }
366 
367 }
368 
369 
370 // =======================================================================================================
371 // ToolBar Context Menus Buttons
372 // =======================================================================================================
373 
375 void viewModeWidget::slotUsedToolbarContextMenu ( const QPoint & _pos ){
376 
377  if (toolboxList->itemAt(_pos)){
378 
379  QMenu menu(0);
380 
381  if ( toolbarList->selectedItems().count() != 0 )
382  menu.addAction(tr("Remove"), this, SLOT ( slotRightArrowToolbar() ));
383 
384  menu.exec(toolbarList->mapToGlobal( _pos) );
385  }
386 }
387 
390 
391  if (availableToolbars->itemAt(_pos)){
392 
393  QMenu menu(0);
394 
395  if ( availableToolbars->selectedItems().count() != 0 )
396  menu.addAction(tr("Add"), this, SLOT ( slotLeftArrowToolbar() ));
397 
398  menu.exec(availableToolbars->mapToGlobal( _pos) );
399  }
400 }
401 
402 // =======================================================================================================
403 // ToolBox Context Menus Buttons
404 // =======================================================================================================
405 
407 void viewModeWidget::slotUsedToolboxContextMenu ( const QPoint & _pos ){
408 
409  if (toolboxList->itemAt(_pos)){
410 
411  QMenu menu(0);
412 
413  if (toolboxList->selectedItems().count() == 1){
414  menu.addAction(tr("Move up"), this, SLOT ( slotMoveToolboxUp() ));
415  menu.addAction(tr("Move down"), this, SLOT ( slotMoveToolboxDown() ));
416  menu.addSeparator();
417  }
418 
419  if ( toolboxList->selectedItems().count() != 0 )
420  menu.addAction(tr("Remove"), this, SLOT ( slotRightArrowToolbox() ));
421 
422  menu.exec(toolboxList->mapToGlobal( _pos) );
423  }
424 }
425 
428 
429  if (availableToolboxes->itemAt(_pos)){
430 
431  QMenu menu(0);
432 
433  if ( availableToolboxes->selectedItems().count() != 0 )
434  menu.addAction(tr("Add"), this, SLOT ( slotLeftArrowToolbox() ));
435 
436  menu.exec(availableToolboxes->mapToGlobal( _pos) );
437  }
438 }
439 
440 // =======================================================================================================
441 // ContextMenu Context Menus Buttons
442 // =======================================================================================================
443 
446 
447  if (contextMenuList->itemAt(_pos)){
448 
449  QMenu menu(0);
450 
451  if (contextMenuList->selectedItems().count() == 1){
452  menu.addAction(tr("Move up"), this, SLOT ( slotMoveContextMenuUp() ));
453  menu.addAction(tr("Move down"), this, SLOT ( slotMoveContextMenuDown() ));
454  menu.addSeparator();
455  }
456 
457  if ( contextMenuList->selectedItems().count() != 0 )
458  menu.addAction(tr("Remove"), this, SLOT ( slotRightArrowContextMenu() ));
459 
460  menu.exec(contextMenuList->mapToGlobal( _pos) );
461  }
462 }
463 
466 
467  if (availableContextMenus->itemAt(_pos)){
468 
469  QMenu menu(0);
470 
471  if ( availableContextMenus->selectedItems().count() != 0 )
472  menu.addAction(tr("Add"), this, SLOT ( slotLeftArrowContextMenu() ));
473 
474  menu.exec(availableContextMenus->mapToGlobal( _pos) );
475  }
476 }
477 
478 // =======================================================================================================
479 // ToolBar Buttons
480 // =======================================================================================================
481 
483  QList<QListWidgetItem *> selectedItems = toolbarList->selectedItems ();
484  for ( int i = 0 ; i < selectedItems.size(); ++i )
485  availableToolbars->addItem(selectedItems[i]->text());
486 
487  qDeleteAll(selectedItems);
488 }
489 
491  QList<QListWidgetItem *> selectedItems = availableToolbars->selectedItems ();
492  for ( int i = 0 ; i < selectedItems.size(); ++i )
493  toolbarList->addItem(selectedItems[i]->text());
494 
495  qDeleteAll(selectedItems);
496 }
497 
498 // =======================================================================================================
499 // ToolBox Buttons
500 // =======================================================================================================
501 
503  QList<QListWidgetItem *> selectedItems = toolboxList->selectedItems ();
504  for ( int i = 0 ; i < selectedItems.size(); ++i )
505  availableToolboxes->addItem(selectedItems[i]->text());
506 
507  qDeleteAll(selectedItems);
508 }
509 
511  QList<QListWidgetItem *> selectedItems = availableToolboxes->selectedItems ();
512  for ( int i = 0 ; i < selectedItems.size(); ++i )
513  toolboxList->addItem(selectedItems[i]->text());
514 
515  qDeleteAll(selectedItems);
516 }
517 
518 
521  if (toolboxList->selectedItems().count() == 1){
522  if (toolboxList->currentRow() == 0) return;
523  //extract a list of all items
524  QString item = toolboxList->currentItem()->text();
525  int oldRow = toolboxList->currentRow();
526  QStringList widgets;
527  for (int i=0; i < toolboxList->count(); i++)
528  widgets << toolboxList->item(i)->text();
529 
530  //reorder items
531  QString last = widgets[0];
532  for (int i=1; i < widgets.size(); i++){
533  if (widgets[i] == item){
534  widgets[i] = last;
535  widgets[i-1] = item;
536  }
537  last = widgets[i];
538  }
539  // set new list as elements for the toolboxList
540  toolboxList->clear();
541  toolboxList->addItems(widgets);
542  //highlight active item
543  toolboxList->setCurrentRow(oldRow-1);
544  }
545 }
546 
549  if (toolboxList->selectedItems().count() == 1){
550  if (toolboxList->currentRow() == toolboxList->count()-1) return;
551  //extract a list of all items
552  QString item = toolboxList->currentItem()->text();
553  int oldRow = toolboxList->currentRow();
554  QStringList widgets;
555  for (int i=0; i < toolboxList->count(); i++)
556  widgets << toolboxList->item(i)->text();
557 
558  //reorder items
559  QString last = widgets[widgets.size()-1];
560  for (int i=widgets.size()-2; i >= 0; i--){
561  if (widgets[i] == item){
562  widgets[i] = last;
563  widgets[i+1] = item;
564  }
565  last = widgets[i];
566  }
567  // set new list as elements for the toolboxList
568  toolboxList->clear();
569  toolboxList->addItems(widgets);
570  //highlight active item
571  toolboxList->setCurrentRow(oldRow+1);
572  }
573 }
574 
575 // =======================================================================================================
576 // ContextMenu Buttons
577 // =======================================================================================================
578 
580  QList<QListWidgetItem *> selectedItems = contextMenuList->selectedItems ();
581  for ( int i = 0 ; i < selectedItems.size(); ++i )
582  availableContextMenus->addItem(selectedItems[i]->text());
583 
584  qDeleteAll(selectedItems);
585 }
586 
588  QList<QListWidgetItem *> selectedItems = availableContextMenus->selectedItems ();
589  for ( int i = 0 ; i < selectedItems.size(); ++i )
590  contextMenuList->addItem(selectedItems[i]->text());
591 
592  qDeleteAll(selectedItems);
593 }
594 
595 
598  if (contextMenuList->selectedItems().count() == 1){
599  if (contextMenuList->currentRow() == 0) return;
600  //extract a list of all items
601  QString item = contextMenuList->currentItem()->text();
602  int oldRow = contextMenuList->currentRow();
603  QStringList widgets;
604  for (int i=0; i < contextMenuList->count(); i++)
605  widgets << contextMenuList->item(i)->text();
606 
607  //reorder items
608  QString last = widgets[0];
609  for (int i=1; i < widgets.size(); i++){
610  if (widgets[i] == item){
611  widgets[i] = last;
612  widgets[i-1] = item;
613  }
614  last = widgets[i];
615  }
616  // set new list as elements for the toolboxList
617  contextMenuList->clear();
618  contextMenuList->addItems(widgets);
619  //highlight active item
620  contextMenuList->setCurrentRow(oldRow-1);
621  }
622 }
623 
626  if (contextMenuList->selectedItems().count() == 1){
627  if (contextMenuList->currentRow() == contextMenuList->count()-1) return;
628  //extract a list of all items
629  QString item = contextMenuList->currentItem()->text();
630  int oldRow = contextMenuList->currentRow();
631  QStringList widgets;
632  for (int i=0; i < contextMenuList->count(); i++)
633  widgets << contextMenuList->item(i)->text();
634 
635  //reorder items
636  QString last = widgets[widgets.size()-1];
637  for (int i=widgets.size()-2; i >= 0; i--){
638  if (widgets[i] == item){
639  widgets[i] = last;
640  widgets[i+1] = item;
641  }
642  last = widgets[i];
643  }
644  // set new list as elements for the toolboxList
645  contextMenuList->clear();
646  contextMenuList->addItems(widgets);
647  //highlight active item
648  contextMenuList->setCurrentRow(oldRow+1);
649  }
650 }
651 
652 
653 
654 // =======================================================================================================
655 // External communication
656 // =======================================================================================================
657 
660  //get toolboxes
661  QStringList toolboxes;
662  for (int i=0; i < toolboxList->count(); i++)
663  toolboxes << toolboxList->item(i)->text();
664 
665  //get toolbars
666  QStringList toolbars;
667  for (int i=0; i < toolbarList->count(); i++)
668  toolbars << toolbarList->item(i)->text();
669 
670  //get context menus
671  QStringList contextmenus;
672  for (int i=0; i < contextMenuList->count(); i++)
673  contextmenus << contextMenuList->item(i)->text();
674 
675  //get mode
676  QString mode = "";
677  if (viewModeList->selectedItems().size() > 0)
678  mode = viewModeList->selectedItems()[0]->text();
679 
680 
681  // Check current configuration if it is a changed view mode
682 
683  // Search for current mode
684  int id = -1;
685  if ( viewModeList->selectedItems().count() > 0)
686  for (int i=0; i < modes_.size(); i++)
687  if (modes_[i]->name == viewModeList->currentItem()->text()){
688  id = i;
689  break;
690  }
691 
692  if ( id == -1 ) {
693  std::cerr << "Currently selected Mode not found?!" << std::endl;
694  return;
695  }
696 
697  bool matching = true;
698  // Check if toolbox list matches:
699  if ( modes_[id]->visibleToolboxes.size() == toolboxes.size() ) {
700  for ( int i = 0 ; i < modes_[id]->visibleToolboxes.size(); ++i )
701  if ( modes_[id]->visibleToolboxes[i] != toolboxes[i] )
702  matching = false;
703  } else {
704  matching = false;
705  }
706 
707  // Check if toolbar list matches:
708  if ( modes_[id]->visibleToolbars.size() == toolbars.size() ) {
709  for ( int i = 0 ; i < modes_[id]->visibleToolbars.size(); ++i )
710  if ( modes_[id]->visibleToolbars[i] != toolbars[i] )
711  matching = false;
712  } else {
713  matching = false;
714  }
715 
716  // Check if context menu list matches:
717  if ( modes_[id]->visibleContextMenus.size() == contextmenus.size() ) {
718  for ( int i = 0 ; i < modes_[id]->visibleContextMenus.size(); ++i )
719  if ( modes_[id]->visibleContextMenus[i] != contextmenus[i] )
720  matching = false;
721  } else {
722  matching = false;
723  }
724 
725  if ( !matching ) {
726  int ret = QMessageBox::warning(this,
727  tr("Mode has been changed!"),
728  tr("You changed the view mode configuration. Do you want to save it?"),
729  QMessageBox::Yes|QMessageBox::No,
730  QMessageBox::No);
731  if (ret == QMessageBox::Yes)
732  slotSaveMode();
733 
734  }
735 
736  emit changeView(mode,toolboxes,toolbars,contextmenus);
737  close();
738 }
739 
742  // Search for current mode vector
743  int id = -1;
744  if ( viewModeList->selectedItems().count() > 0)
745  for (int i=0; i < modes_.size(); i++)
746  if (modes_[i]->name == viewModeList->currentItem()->text()){
747  id = i;
748  break;
749  }
750 
751  if ( id == -1 ) {
752  std::cerr << "Mode Not found in slotSaveMode" << std::endl;
753  return;
754  }
755 
756  // Get Toolboxes
757  QStringList toolboxes;
758  for (int i=0; i < toolboxList->count(); i++)
759  toolboxes << toolboxList->item(i)->text();
760 
761  // Get Toolbars
762  QStringList toolbars;
763  for (int i=0; i < toolbarList->count(); i++)
764  toolbars << toolbarList->item(i)->text();
765 
766  // Get Context Menus
767  QStringList contextmenus;
768  for (int i=0; i < contextMenuList->count(); i++)
769  contextmenus << contextMenuList->item(i)->text();
770 
771  bool createNewMode = false;
772 
773  QString message = tr("You cannot change predefined modes.\n"
774  "Please enter a new Name for the mode.");
775 
776  // Check if we want to create a new node.
777  if ( ! modes_[id]->custom ) {
778  createNewMode = true;
779 
780  } else {
781  int ret = QMessageBox::warning(this,
782  tr("View Mode exists"),
783  tr("View Mode already exists. Do you want to overwrite it?"),
784  QMessageBox::Yes|QMessageBox::No,
785  QMessageBox::No);
786  if (ret == QMessageBox::No) {
787  message = tr("New name for view mode:");
788  createNewMode = true;
789  }
790  }
791 
792 
793  if ( createNewMode ) {
794 
795  //ask for a name for the new viewmode as it is not a custom one
796  bool ok;
797  QString name = QInputDialog::getText(this, tr("Save view Mode"),
798  message, QLineEdit::Normal,
799  "", &ok);
800 
801  //Remove Spaces from name
802  if (!ok || name.isEmpty()) {
803  std::cerr << "Illegal or no name given!" << std::endl;
804  return;
805  }
806 
807  //check if name already exists
808  for (int i=0; i < modes_.size(); i++)
809  if (modes_[i]->name == name){
810  QMessageBox::warning(this, tr("Save View Mode"), tr("Cannot Save ViewMode.\nName already taken by a different mode."), QMessageBox::Ok);
811  return;
812  }
813 
814  emit saveMode(name, true, toolboxes, toolbars, contextmenus);
815  show(name);
816  } else {
817  emit saveMode(modes_[id]->name, true, toolboxes, toolbars, contextmenus);
818  show(modes_[id]->name);
819  }
820 
821  slotModeChanged(QString());
822 }
823 
824 
825 
826 
827 
828 
829 
830 
831 
832 
833 
834 
835 
836 
837 
838 
839 
840 
841 
843 void viewModeWidget::show(QString _lastMode){
844  QDialog::show();
845 
846  //fill viewModeList
847  viewModeList->clear();
848  for (int i=0; i < modes_.size(); i++){
849  QListWidgetItem *item = new QListWidgetItem(viewModeList);
850  item->setTextAlignment(Qt::AlignHCenter);
851  item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
852 
853  QFile iconFile( OpenFlipper::Options::iconDirStr() + QDir::separator () + modes_[i]->icon );
854 
855  if ( iconFile.exists() )
856  item->setIcon( QIcon(iconFile.fileName()) );
857  else {
858  iconFile.setFileName( OpenFlipper::Options::configDirStr() + QDir::separator() + "Icons" + QDir::separator() + modes_[i]->icon );
859  if ( iconFile.exists() )
860  item->setIcon( QIcon(iconFile.fileName()) );
861  else {
862  item->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + QDir::separator () + "Unknown.png") );
863  std::cerr << "Unable to find icon file! " << iconFile.fileName().toStdString() << std::endl;
864  }
865  }
866 
867  item->setText(modes_[i]->name);
868 
869  if (modes_[i]->custom)
870  viewModeList->item(i)->setForeground( QBrush(QColor(0,0,150) ) );
871  else
872  viewModeList->item(i)->setForeground( QBrush(QColor(0,0,0) ) );
873  }
874 
875  //select given mode
876  viewModeList->setCurrentRow(0);
877 
878  for (int i=0; i < viewModeList->count(); i++)
879  if (viewModeList->item(i)->text() == _lastMode)
880  viewModeList->setCurrentRow(i);
881 
882  removeButton->setEnabled(false);
883 }
884 
885 
887 void viewModeWidget::slotModeClicked(QModelIndex /*_id*/){
888  slotModeChanged(QString());
889 }
890 
892 void viewModeWidget::slotModeChanged(QString /*_mode*/){
893  //check if mode is custom e.g. that it can be removed
894  if (viewModeList->selectedItems().count() > 0){
895  for (int i=0; i < modes_.size(); i++)
896  if (modes_[i]->name == viewModeList->currentItem()->text()){
897  removeButton->setEnabled(modes_[i]->custom);
898  break;
899  }
900  }
901 }
902 
903 
904 
905 
906 
907 
908 
909 
910 
911 
912 
913 
914 
915 
916 
917 
918 
void slotMoveToolboxUp()
Move Toolbox up.
void slotUsedToolbarContextMenu(const QPoint &_pos)
Context Menu Used Toolbars.
void slotMoveToolboxDown()
Move Toolbox down.
viewModeWidget(const QVector< ViewMode * > &_modes, QWidget *parent=0)
Constructor.
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:87
void show(QString _lastMode)
overloaded show function
void slotSetIcon()
Context menu slot to change the icon for a view mode.
void slotCopyMode()
Button slot to copy the selected view mode.
void slotRightArrowToolbox()
remove Toolboxes from Mode
void slotAvailableContextMenuContextMenu(const QPoint &_pos)
Context Menu Available ContextMenus.
void slotModeContextMenu(const QPoint &_pos)
Context Menu View Modes.
void slotModeClicked(QModelIndex _id)
Slot for updating removeButton when new mode is selected.
void slotRightArrowContextMenu()
remove ContextMenu from Mode
void slotAvailableToolboxContextMenu(const QPoint &_pos)
Context Menu Available Toolboxes.
void slotSetAllWidgets()
Update list views.
void slotChangeView()
Slot for changing the current view to currently configured one.
void slotRightArrowToolbar()
remove Toolbars from Mode
void slotMoveContextMenuUp()
Move ContextMenu up.
void saveMode(QString _name, bool _custom, QStringList _toolboxWidgets, QStringList _toolbars, QStringList _contextmenus)
saves the given mode
void changeView(QString _mode, QStringList _toolboxWidgets, QStringList _toolbars, QStringList _contextmenus)
Changes the view mode to the currently configured one.
void slotAvailableToolbarContextMenu(const QPoint &_pos)
Context Menu Available Toolbars.
void slotModeChanged(QString _mode)
Slot for updating removeButton when new mode is selected.
void slotMoveContextMenuDown()
Move Toolbox down.
void slotUsedContextMenuContextMenu(const QPoint &_pos)
Context Menu Used ContextMenus.
void slotLeftArrowToolbar()
add Toolbars to Mode
void slotLeftArrowContextMenu()
add ContextMenu to Mode
void slotLeftArrowToolbox()
add Toolboxes to Mode
void slotSaveMode()
Save the current view mode configuration.
void slotUsedToolboxContextMenu(const QPoint &_pos)
Context Menu Used Toolboxes.
void removeMode(QString _name)
This signal is emitted to remove a mode.
void slotRemoveMode()
Button slot to remove the selected view mode.
void slotAddMode()
Button slot to add a new empty mode.