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
51viewModeWidget::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// =======================================================================================================
241void 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
319 if (contextmenus.contains("ALL_THAT_EXIST"))
320 contextmenus = modes_[0]->visibleContextMenus;
321
322 //add corresponding widgets
323 for (int j = 0; j < toolboxes.size(); j++)
324 {
325 QListWidgetItem* toolbox = new QListWidgetItem(modes_[0]->toolboxIconMap[toolboxes[j]], toolboxes[j]);
326 toolboxList->addItem(toolbox);
327 }
328
329 toolbarList->addItems(toolbars);
330 contextMenuList->addItems(contextmenus);
331 break;
332 }
333 }
334 }
335
336
337 if ( !modes_.empty() ) {
338 QStringList allToolboxes = modes_[0]->visibleToolboxes;
339 QStringList allToolbars = modes_[0]->visibleToolbars;
340 QStringList allContextMenus = modes_[0]->visibleContextMenus;
341
342 QStringList availableToolboxList;
343 QStringList availableToolbarList;
344 QStringList availableContextMenuList;
345
346 for ( int i = 0; i < allToolboxes.size(); ++i ) {
347 if ( ! toolboxes.contains(allToolboxes[i]) )
348 availableToolboxList.push_back(allToolboxes[i]);
349 }
350
351 for ( int i = 0; i < allToolbars.size(); ++i ) {
352 if ( ! toolbars.contains(allToolbars[i]) )
353 availableToolbarList.push_back(allToolbars[i]);
354 }
355
356 for ( int i = 0; i < allContextMenus.size(); ++i ) {
357 if ( ! contextmenus.contains(allContextMenus[i]) )
358 availableContextMenuList.push_back(allContextMenus[i]);
359 }
360
361 for (int i = 0; i < availableToolboxList.size(); i++)
362 {
363 QListWidgetItem* availableToolbox = new QListWidgetItem(modes_[0]->toolboxIconMap[availableToolboxList[i]], availableToolboxList[i]);
364 availableToolboxes->addItem(availableToolbox);
365 }
366
367 availableToolbars->addItems(availableToolbarList);
368 availableContextMenus->addItems(availableContextMenuList);
369
370 } else {
371 std::cerr << "Mode not found!" << std::endl;
372 }
373
374}
375
376
377// =======================================================================================================
378// ToolBar Context Menus Buttons
379// =======================================================================================================
380
383
384 if (toolboxList->itemAt(_pos)){
385
386 QMenu menu(0);
387
388 if ( toolbarList->selectedItems().count() != 0 )
389 menu.addAction(tr("Remove"), this, SLOT ( slotRightArrowToolbar() ));
390
391 menu.exec(toolbarList->mapToGlobal( _pos) );
392 }
393}
394
397
398 if (availableToolbars->itemAt(_pos)){
399
400 QMenu menu(0);
401
402 if ( availableToolbars->selectedItems().count() != 0 )
403 menu.addAction(tr("Add"), this, SLOT ( slotLeftArrowToolbar() ));
404
405 menu.exec(availableToolbars->mapToGlobal( _pos) );
406 }
407}
408
409// =======================================================================================================
410// ToolBox Context Menus Buttons
411// =======================================================================================================
412
415
416 if (toolboxList->itemAt(_pos)){
417
418 QMenu menu(0);
419
420 if (toolboxList->selectedItems().count() == 1){
421 menu.addAction(tr("Move up"), this, SLOT ( slotMoveToolboxUp() ));
422 menu.addAction(tr("Move down"), this, SLOT ( slotMoveToolboxDown() ));
423 menu.addSeparator();
424 }
425
426 if ( toolboxList->selectedItems().count() != 0 )
427 menu.addAction(tr("Remove"), this, SLOT ( slotRightArrowToolbox() ));
428
429 menu.exec(toolboxList->mapToGlobal( _pos) );
430 }
431}
432
435
436 if (availableToolboxes->itemAt(_pos)){
437
438 QMenu menu(0);
439
440 if ( availableToolboxes->selectedItems().count() != 0 )
441 menu.addAction(tr("Add"), this, SLOT ( slotLeftArrowToolbox() ));
442
443 menu.exec(availableToolboxes->mapToGlobal( _pos) );
444 }
445}
446
447// =======================================================================================================
448// ContextMenu Context Menus Buttons
449// =======================================================================================================
450
453
454 if (contextMenuList->itemAt(_pos)){
455
456 QMenu menu(0);
457
458 if (contextMenuList->selectedItems().count() == 1){
459 menu.addAction(tr("Move up"), this, SLOT ( slotMoveContextMenuUp() ));
460 menu.addAction(tr("Move down"), this, SLOT ( slotMoveContextMenuDown() ));
461 menu.addSeparator();
462 }
463
464 if ( contextMenuList->selectedItems().count() != 0 )
465 menu.addAction(tr("Remove"), this, SLOT ( slotRightArrowContextMenu() ));
466
467 menu.exec(contextMenuList->mapToGlobal( _pos) );
468 }
469}
470
473
474 if (availableContextMenus->itemAt(_pos)){
475
476 QMenu menu(0);
477
478 if ( availableContextMenus->selectedItems().count() != 0 )
479 menu.addAction(tr("Add"), this, SLOT ( slotLeftArrowContextMenu() ));
480
481 menu.exec(availableContextMenus->mapToGlobal( _pos) );
482 }
483}
484
485// =======================================================================================================
486// ToolBar Buttons
487// =======================================================================================================
488
490 QList<QListWidgetItem *> selectedItems = toolbarList->selectedItems ();
491 for ( int i = 0 ; i < selectedItems.size(); ++i )
492 availableToolbars->addItem(selectedItems[i]->text());
493
494 qDeleteAll(selectedItems);
495}
496
498 QList<QListWidgetItem *> selectedItems = availableToolbars->selectedItems ();
499 for ( int i = 0 ; i < selectedItems.size(); ++i )
500 toolbarList->addItem(selectedItems[i]->text());
501
502 qDeleteAll(selectedItems);
503}
504
505// =======================================================================================================
506// ToolBox Buttons
507// =======================================================================================================
508
510 QList<QListWidgetItem *> selectedItems = toolboxList->selectedItems ();
511 for ( int i = 0 ; i < selectedItems.size(); ++i )
512 availableToolboxes->addItem(selectedItems[i]->text());
513
514 qDeleteAll(selectedItems);
515}
516
518 QList<QListWidgetItem *> selectedItems = availableToolboxes->selectedItems ();
519 for ( int i = 0 ; i < selectedItems.size(); ++i )
520 toolboxList->addItem(selectedItems[i]->text());
521
522 qDeleteAll(selectedItems);
523}
524
525
528 if (toolboxList->selectedItems().count() == 1){
529 if (toolboxList->currentRow() == 0) return;
530 //extract a list of all items
531 QString item = toolboxList->currentItem()->text();
532 int oldRow = toolboxList->currentRow();
533 QStringList widgets;
534 for (int i=0; i < toolboxList->count(); i++)
535 widgets << toolboxList->item(i)->text();
536
537 //reorder items
538 QString last = widgets[0];
539 for (int i=1; i < widgets.size(); i++){
540 if (widgets[i] == item){
541 widgets[i] = last;
542 widgets[i-1] = item;
543 }
544 last = widgets[i];
545 }
546 // set new list as elements for the toolboxList
547 toolboxList->clear();
548 toolboxList->addItems(widgets);
549 //highlight active item
550 toolboxList->setCurrentRow(oldRow-1);
551 }
552}
553
556 if (toolboxList->selectedItems().count() == 1){
557 if (toolboxList->currentRow() == toolboxList->count()-1) return;
558 //extract a list of all items
559 QString item = toolboxList->currentItem()->text();
560 int oldRow = toolboxList->currentRow();
561 QStringList widgets;
562 for (int i=0; i < toolboxList->count(); i++)
563 widgets << toolboxList->item(i)->text();
564
565 //reorder items
566 QString last = widgets[widgets.size()-1];
567 for (int i=widgets.size()-2; i >= 0; i--){
568 if (widgets[i] == item){
569 widgets[i] = last;
570 widgets[i+1] = item;
571 }
572 last = widgets[i];
573 }
574 // set new list as elements for the toolboxList
575 toolboxList->clear();
576 toolboxList->addItems(widgets);
577 //highlight active item
578 toolboxList->setCurrentRow(oldRow+1);
579 }
580}
581
582// =======================================================================================================
583// ContextMenu Buttons
584// =======================================================================================================
585
587 QList<QListWidgetItem *> selectedItems = contextMenuList->selectedItems ();
588 for ( int i = 0 ; i < selectedItems.size(); ++i )
589 availableContextMenus->addItem(selectedItems[i]->text());
590
591 qDeleteAll(selectedItems);
592}
593
595 QList<QListWidgetItem *> selectedItems = availableContextMenus->selectedItems ();
596 for ( int i = 0 ; i < selectedItems.size(); ++i )
597 contextMenuList->addItem(selectedItems[i]->text());
598
599 qDeleteAll(selectedItems);
600}
601
602
605 if (contextMenuList->selectedItems().count() == 1){
606 if (contextMenuList->currentRow() == 0) return;
607 //extract a list of all items
608 QString item = contextMenuList->currentItem()->text();
609 int oldRow = contextMenuList->currentRow();
610 QStringList widgets;
611 for (int i=0; i < contextMenuList->count(); i++)
612 widgets << contextMenuList->item(i)->text();
613
614 //reorder items
615 QString last = widgets[0];
616 for (int i=1; i < widgets.size(); i++){
617 if (widgets[i] == item){
618 widgets[i] = last;
619 widgets[i-1] = item;
620 }
621 last = widgets[i];
622 }
623 // set new list as elements for the toolboxList
624 contextMenuList->clear();
625 contextMenuList->addItems(widgets);
626 //highlight active item
627 contextMenuList->setCurrentRow(oldRow-1);
628 }
629}
630
633 if (contextMenuList->selectedItems().count() == 1){
634 if (contextMenuList->currentRow() == contextMenuList->count()-1) return;
635 //extract a list of all items
636 QString item = contextMenuList->currentItem()->text();
637 int oldRow = contextMenuList->currentRow();
638 QStringList widgets;
639 for (int i=0; i < contextMenuList->count(); i++)
640 widgets << contextMenuList->item(i)->text();
641
642 //reorder items
643 QString last = widgets[widgets.size()-1];
644 for (int i=widgets.size()-2; i >= 0; i--){
645 if (widgets[i] == item){
646 widgets[i] = last;
647 widgets[i+1] = item;
648 }
649 last = widgets[i];
650 }
651 // set new list as elements for the toolboxList
652 contextMenuList->clear();
653 contextMenuList->addItems(widgets);
654 //highlight active item
655 contextMenuList->setCurrentRow(oldRow+1);
656 }
657}
658
659
660
661// =======================================================================================================
662// External communication
663// =======================================================================================================
664
667 //get toolboxes
668 QStringList toolboxes;
669 for (int i=0; i < toolboxList->count(); i++)
670 toolboxes << toolboxList->item(i)->text();
671
672 //get toolbars
673 QStringList toolbars;
674 for (int i=0; i < toolbarList->count(); i++)
675 toolbars << toolbarList->item(i)->text();
676
677 //get context menus
678 QStringList contextmenus;
679 for (int i=0; i < contextMenuList->count(); i++)
680 contextmenus << contextMenuList->item(i)->text();
681
682 //get mode
683 QString mode = "";
684 if (viewModeList->selectedItems().size() > 0)
685 mode = viewModeList->selectedItems()[0]->text();
686
687
688 // Check current configuration if it is a changed view mode
689
690 // Search for current mode
691 int id = -1;
692 if ( viewModeList->selectedItems().count() > 0)
693 for (int i=0; i < modes_.size(); i++)
694 if (modes_[i]->name == viewModeList->currentItem()->text()){
695 id = i;
696 break;
697 }
698
699 if ( id == -1 ) {
700 std::cerr << "Currently selected Mode not found?!" << std::endl;
701 return;
702 }
703
704 bool matching = true;
705 // Check if toolbox list matches:
706 if ( modes_[id]->visibleToolboxes.size() == toolboxes.size() ) {
707 for ( int i = 0 ; i < modes_[id]->visibleToolboxes.size(); ++i )
708 if ( modes_[id]->visibleToolboxes[i] != toolboxes[i] )
709 matching = false;
710 } else {
711 matching = false;
712 }
713
714 // Check if toolbar list matches:
715 if ( modes_[id]->visibleToolbars.size() == toolbars.size() ) {
716 for ( int i = 0 ; i < modes_[id]->visibleToolbars.size(); ++i )
717 if ( modes_[id]->visibleToolbars[i] != toolbars[i] )
718 matching = false;
719 } else {
720 matching = false;
721 }
722
723 // Check if context menu list matches:
724 if ( modes_[id]->visibleContextMenus.size() == contextmenus.size() ) {
725 for ( int i = 0 ; i < modes_[id]->visibleContextMenus.size(); ++i )
726 if ( modes_[id]->visibleContextMenus[i] != contextmenus[i] )
727 matching = false;
728 } else {
729 matching = false;
730 }
731
732 if ( !matching ) {
733 int ret = QMessageBox::warning(this,
734 tr("Mode has been changed!"),
735 tr("You changed the view mode configuration. Do you want to save it?"),
736 QMessageBox::Yes|QMessageBox::No,
737 QMessageBox::No);
738 if (ret == QMessageBox::Yes)
739 slotSaveMode();
740
741 }
742
743 emit changeView(mode,toolboxes,toolbars,contextmenus);
744 close();
745}
746
749 // Search for current mode vector
750 int id = -1;
751 if ( viewModeList->selectedItems().count() > 0)
752 for (int i=0; i < modes_.size(); i++)
753 if (modes_[i]->name == viewModeList->currentItem()->text()){
754 id = i;
755 break;
756 }
757
758 if ( id == -1 ) {
759 std::cerr << "Mode Not found in slotSaveMode" << std::endl;
760 return;
761 }
762
763 // Get Toolboxes
764 QStringList toolboxes;
765 for (int i=0; i < toolboxList->count(); i++)
766 toolboxes << toolboxList->item(i)->text();
767
768 // Get Toolbars
769 QStringList toolbars;
770 for (int i=0; i < toolbarList->count(); i++)
771 toolbars << toolbarList->item(i)->text();
772
773 // Get Context Menus
774 QStringList contextmenus;
775 for (int i=0; i < contextMenuList->count(); i++)
776 contextmenus << contextMenuList->item(i)->text();
777
778 bool createNewMode = false;
779
780 QString message = tr("You cannot change predefined modes.\n"
781 "Please enter a new Name for the mode.");
782
783 // Check if we want to create a new node.
784 if ( ! modes_[id]->custom ) {
785 createNewMode = true;
786
787 } else {
788 int ret = QMessageBox::warning(this,
789 tr("View Mode exists"),
790 tr("View Mode already exists. Do you want to overwrite it?"),
791 QMessageBox::Yes|QMessageBox::No,
792 QMessageBox::No);
793 if (ret == QMessageBox::No) {
794 message = tr("New name for view mode:");
795 createNewMode = true;
796 }
797 }
798
799
800 if ( createNewMode ) {
801
802 //ask for a name for the new viewmode as it is not a custom one
803 bool ok;
804 QString name = QInputDialog::getText(this, tr("Save view Mode"),
805 message, QLineEdit::Normal,
806 "", &ok);
807
808 //Remove Spaces from name
809 if (!ok || name.isEmpty()) {
810 std::cerr << "Illegal or no name given!" << std::endl;
811 return;
812 }
813
814 //check if name already exists
815 for (int i=0; i < modes_.size(); i++)
816 if (modes_[i]->name == name){
817 QMessageBox::warning(this, tr("Save View Mode"), tr("Cannot Save ViewMode.\nName already taken by a different mode."), QMessageBox::Ok);
818 return;
819 }
820
821 emit saveMode(name, true, toolboxes, toolbars, contextmenus);
822 show(name);
823 } else {
824 emit saveMode(modes_[id]->name, true, toolboxes, toolbars, contextmenus);
825 show(modes_[id]->name);
826 }
827
828 slotModeChanged(QString());
829}
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
850void viewModeWidget::show(const QString& _lastMode){
851 QDialog::show();
852
853 //fill viewModeList
854 viewModeList->clear();
855 for (int i=0; i < modes_.size(); i++){
856 QListWidgetItem *item = new QListWidgetItem(viewModeList);
857 item->setTextAlignment(Qt::AlignHCenter);
858 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
859
860 QFile iconFile( OpenFlipper::Options::iconDirStr() + QDir::separator () + modes_[i]->icon );
861
862 if ( iconFile.exists() )
863 item->setIcon( QIcon(iconFile.fileName()) );
864 else {
865 iconFile.setFileName( OpenFlipper::Options::configDirStr() + QDir::separator() + "Icons" + QDir::separator() + modes_[i]->icon );
866 if ( iconFile.exists() )
867 item->setIcon( QIcon(iconFile.fileName()) );
868 else {
869 item->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + QDir::separator () + "Unknown.png") );
870 std::cerr << "Unable to find icon file! " << iconFile.fileName().toStdString() << std::endl;
871 }
872 }
873
874 item->setText(modes_[i]->name);
875
876 if (modes_[i]->custom)
877 viewModeList->item(i)->setForeground( QBrush(QColor(0,0,150) ) );
878 else
879 viewModeList->item(i)->setForeground( QBrush(QColor(0,0,0) ) );
880 }
881
882 //select given mode
883 viewModeList->setCurrentRow(0);
884
885 for (int i=0; i < viewModeList->count(); i++)
886 if (viewModeList->item(i)->text() == _lastMode)
887 viewModeList->setCurrentRow(i);
888
889 removeButton->setEnabled(false);
890}
891
892
894void viewModeWidget::slotModeClicked(QModelIndex /*_id*/){
895 slotModeChanged(QString());
896}
897
899void viewModeWidget::slotModeChanged(QString /*_mode*/){
900 //check if mode is custom e.g. that it can be removed
901 if (viewModeList->selectedItems().count() > 0){
902 for (int i=0; i < modes_.size(); i++)
903 if (modes_[i]->name == viewModeList->currentItem()->text()){
904 removeButton->setEnabled(modes_[i]->custom);
905 break;
906 }
907 }
908}
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
void slotChangeView()
Slot for changing the current view to currently configured one.
void slotMoveToolboxDown()
Move Toolbox down.
viewModeWidget(const QVector< ViewMode * > &_modes, QWidget *parent=0)
Constructor.
void slotAddMode()
Button slot to add a new empty mode.
void slotLeftArrowToolbox()
add Toolboxes to Mode
void slotUsedToolbarContextMenu(const QPoint &_pos)
Context Menu Used Toolbars.
void slotRightArrowContextMenu()
remove ContextMenu from Mode
void slotSaveMode()
Save the current view mode configuration.
void removeMode(QString _name)
This signal is emitted to remove a mode.
void slotSetIcon()
Context menu slot to change the icon for a view mode.
void slotAvailableToolbarContextMenu(const QPoint &_pos)
Context Menu Available Toolbars.
void slotUsedContextMenuContextMenu(const QPoint &_pos)
Context Menu Used ContextMenus.
void slotCopyMode()
Button slot to copy the selected view mode.
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 slotModeChanged(QString _mode)
Slot for updating removeButton when new mode is selected.
void slotLeftArrowToolbar()
add Toolbars to Mode
void slotAvailableContextMenuContextMenu(const QPoint &_pos)
Context Menu Available ContextMenus.
void slotRightArrowToolbox()
remove Toolboxes from Mode
void slotRemoveMode()
Button slot to remove the selected view mode.
void slotModeClicked(QModelIndex _id)
Slot for updating removeButton when new mode is selected.
void slotMoveContextMenuUp()
Move ContextMenu up.
void show(const QString &_lastMode)
overloaded show function
void slotRightArrowToolbar()
remove Toolbars from Mode
void slotLeftArrowContextMenu()
add ContextMenu to Mode
void slotModeContextMenu(const QPoint &_pos)
Context Menu View Modes.
void slotUsedToolboxContextMenu(const QPoint &_pos)
Context Menu Used Toolboxes.
void slotMoveContextMenuDown()
Move Toolbox down.
void slotMoveToolboxUp()
Move Toolbox up.
void slotAvailableToolboxContextMenu(const QPoint &_pos)
Context Menu Available Toolboxes.
void slotSetAllWidgets()
Update list views.