Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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