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