viewModeWidget.cc 21.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
 *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
 *                           www.openflipper.org                             *
 *                                                                           *
 *---------------------------------------------------------------------------*
 *  This file is part of OpenFlipper.                                        *
 *                                                                           *
 *  OpenFlipper is free software: you can redistribute it and/or modify      *
 *  it under the terms of the GNU Lesser General Public License as           *
 *  published by the Free Software Foundation, either version 3 of           *
 *  the License, or (at your option) any later version with the              *
 *  following exceptions:                                                    *
 *                                                                           *
 *  If other files instantiate templates or use macros                       *
 *  or inline functions from this file, or you compile this file and         *
 *  link it with other files to produce an executable, this file does        *
 *  not by itself cause the resulting executable to be covered by the        *
 *  GNU Lesser General Public License. This exception does not however       *
 *  invalidate any other reasons why the executable file might be            *
 *  covered by the GNU Lesser General Public License.                        *
 *                                                                           *
 *  OpenFlipper is distributed in the hope that it will be useful,           *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *  GNU Lesser General Public License for more details.                      *
 *                                                                           *
 *  You should have received a copy of the GNU LesserGeneral Public          *
 *  License along with OpenFlipper. If not,                                  *
 *  see <http://www.gnu.org/licenses/>.                                      *
 *                                                                           *
\*===========================================================================*/

/*===========================================================================*\
 *                                                                           *
 *   $Revision$                                                         *
 *   $Author$                                                      *
 *   $Date$                   *
 *                                                                           *
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60




#include "viewModeWidget.hh"
#include <OpenFlipper/widgets/coreWidget/CoreWidget.hh>
#include <OpenFlipper/common/GlobalOptions.hh>

#include <QInputDialog>
#include <QMessageBox>

/// Constructor
viewModeWidget::viewModeWidget(const QVector< ViewMode* >& _modes, QWidget *_parent)
  : QDialog(_parent),
    modes_(_modes)
{
  setupUi(this);


61
  connect(viewModeList, SIGNAL(itemSelectionChanged()), this, SLOT(slotSetToolWidgets()));
Jan Möbius's avatar
 
Jan Möbius committed
62

63
  
Jan Möbius's avatar
Jan Möbius committed
64
65
66
  
  
  
67
68
  connect(viewModeList, SIGNAL(currentTextChanged (QString)), this, SLOT(slotModeChanged(QString)) );
  connect(viewModeList, SIGNAL(clicked (QModelIndex)), this, SLOT(slotModeClicked(QModelIndex)) );
Jan Möbius's avatar
 
Jan Möbius committed
69

70
71
  
  
Jan Möbius's avatar
Jan Möbius committed
72
73
74
75
  // View Mode buttons
  connect(removeButton, SIGNAL(clicked()), this, SLOT(slotRemoveMode()));
  connect(copyButton, SIGNAL(clicked()), this, SLOT(slotCopyMode()));
  connect(addButton, SIGNAL(clicked()), this, SLOT(slotAddMode()));
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
  
  // View Mode List context Menu
  viewModeList->setContextMenuPolicy(Qt::CustomContextMenu);
  connect(viewModeList ,SIGNAL(customContextMenuRequested ( const QPoint &  )  ),
          this         ,SLOT(slotModeContextMenu ( const QPoint & ) ));
  
  
  // Context Menus Toolbars
  toolbarList->setContextMenuPolicy(Qt::CustomContextMenu);
  availableToolbars->setContextMenuPolicy(Qt::CustomContextMenu);
  connect(toolbarList ,SIGNAL(customContextMenuRequested ( const QPoint &  )  ),
          this        ,SLOT(slotUsedToolbarContextMenu ( const QPoint & ) )); 
  connect(availableToolbars ,SIGNAL(customContextMenuRequested ( const QPoint &  )  ),
          this        ,SLOT(slotAvailableToolbarContextMenu ( const QPoint & ) )); 
  
  
  // Context Menus Toolboxes
  toolboxList->setContextMenuPolicy(Qt::CustomContextMenu);
  availableToolboxes->setContextMenuPolicy(Qt::CustomContextMenu);
  connect(toolboxList ,SIGNAL(customContextMenuRequested ( const QPoint &  )  ),
          this        ,SLOT(slotUsedToolboxContextMenu ( const QPoint & ) )); 
  connect(availableToolboxes ,SIGNAL(customContextMenuRequested ( const QPoint &  )  ),
          this        ,SLOT(slotAvailableToolboxContextMenu ( const QPoint & ) )); 
          
  
  // Toolbar Buttons to add remove toolbars to the given Mode
  connect(rightArrowToolbar, SIGNAL(clicked()), this, SLOT(slotRightArrowToolbar()) );
  rightArrowToolbar->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "arrow-right.png" ) );
  connect(leftArrowToolbar, SIGNAL(clicked()), this, SLOT(slotLeftArrowToolbar()) );
  leftArrowToolbar->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "arrow-left.png" ) );
  
  
  // Toolbar Buttons to add remove toolbars to the given Mode
  connect(rightArrowToolbox, SIGNAL(clicked()), this, SLOT(slotRightArrowToolbox()) );
  rightArrowToolbox->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "arrow-right.png" ) );
  connect(leftArrowToolbox, SIGNAL(clicked()), this, SLOT(slotLeftArrowToolbox()) );
  leftArrowToolbox->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "arrow-left.png" ) );  
  
  connect(upButton, SIGNAL(clicked()), this, SLOT(slotMoveUp()) );
Jan Möbius's avatar
 
Jan Möbius committed
115
  upButton->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "arrow-up.png" ) );
116
  connect(downButton, SIGNAL(clicked()), this, SLOT(slotMoveDown()) );
Jan Möbius's avatar
 
Jan Möbius committed
117
  downButton->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "arrow-down.png" ) );
118
119
  
  
Jan Möbius's avatar
Jan Möbius committed
120
  // General Buttons
121
122
  // Apply currently configured Mode
  connect(okButton, SIGNAL(clicked()), this, SLOT(slotChangeView()));
Jan Möbius's avatar
Jan Möbius committed
123
124
  connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));
  connect(saveButton, SIGNAL(clicked()), this, SLOT(slotSaveMode()));
125
126
127
128
129
130
131
132
133
134
135
136
}


// =======================================================================================================
// View Mode button slots
// =======================================================================================================
void viewModeWidget::slotRemoveMode(){
  emit removeMode( viewModeList->currentItem()->text() );
  QListWidgetItem* item =  viewModeList->takeItem( viewModeList->currentRow() );
  delete item;
}

Jan Möbius's avatar
Jan Möbius committed
137
138
139
140
141
142
143
144
void viewModeWidget::slotCopyMode(){
  std::cerr << "Todo: Copy Mode" << std::endl;
}

void viewModeWidget::slotAddMode(){
  std::cerr << "Todo: Add Mode" << std::endl;
}

145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// =======================================================================================================
// View Mode Context Menu
// =======================================================================================================
void viewModeWidget::slotModeContextMenu ( const QPoint & _pos ){
  
  if (viewModeList->itemAt(_pos)){
    
    QMenu menu(0);
    
    menu.addAction(tr("Remove Mode"), this, SLOT ( slotRemoveMode() ));
    
    //check if mode is custom e.g. that it can be removed
    for (int i=0; i < modes_.size(); i++)
      if (modes_[i]->name == viewModeList->currentItem()->text()){
        menu.actions()[0]->setEnabled(modes_[i]->custom);
        break;
      }
      
    menu.exec(viewModeList->mapToGlobal( _pos) );
  }
}

// =======================================================================================================
// ToolBox and ToolBar Lists update functions
// =======================================================================================================
void viewModeWidget::slotSetToolWidgets(){
  toolboxList->clear();
  toolbarList->clear();
  availableToolboxes->clear();
  availableToolbars->clear();
  
  QStringList toolboxes;
  QStringList toolbars;
  
  //iterate over all selected modes
  for (int m=0; m < viewModeList->selectedItems().size(); m++)
    
    // find mode in modeVector modes_
    for (int i=0; i < modes_.size(); i++)
      if ( modes_[i]->name == (viewModeList->selectedItems()[m])->text() ) {
        toolboxes = modes_[i]->visibleToolboxes;
        toolbars = modes_[i]->visibleToolbars;
        toolboxList->addItems(toolboxes); //add corresponding widgets
        toolbarList->addItems(toolbars);
        break;
      }
      
      
      if ( !modes_.empty() ) {
        QStringList allToolboxes = modes_[0]->visibleToolboxes;
        QStringList allToolbars  = modes_[0]->visibleToolbars;
        
        QStringList availableToolboxList;
        QStringList availableToolbarList;
        
        for ( int i = 0; i < allToolboxes.size(); ++i ) {
          if ( ! toolboxes.contains(allToolboxes[i]) ) 
            availableToolboxList.push_back(allToolboxes[i]);
        }
        
        for ( int i = 0; i < allToolbars.size(); ++i ) {
          if ( ! toolbars.contains(allToolbars[i]) ) 
            availableToolbarList.push_back(allToolbars[i]);
        }
        
        availableToolboxes->addItems(availableToolboxList);
        availableToolbars->addItems(availableToolbarList);
        
      } else {
        std::cerr << "Mode not found!" << std::endl;
      }
      
Jan Möbius's avatar
 
Jan Möbius committed
217
218
}

219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331

// =======================================================================================================
// ToolBar Context Menus Buttons
// =======================================================================================================

/// opens custom context menu in used toolbox-List
void viewModeWidget::slotUsedToolbarContextMenu ( const QPoint & _pos ){
  
  if (toolboxList->itemAt(_pos)){
    
    QMenu menu(0);
    
    if ( toolbarList->selectedItems().count() != 0 )
      menu.addAction(tr("Remove"), this, SLOT ( slotRightArrowToolbar() ));
    
    menu.exec(toolbarList->mapToGlobal( _pos) );
  }
}

/// opens custom context menu in available toolbox-List
void viewModeWidget::slotAvailableToolbarContextMenu ( const QPoint & _pos ){
  
  if (availableToolbars->itemAt(_pos)){
    
    QMenu menu(0);
    
    if ( availableToolbars->selectedItems().count() != 0 )
      menu.addAction(tr("Add"), this, SLOT ( slotLeftArrowToolbar() ));
    
    menu.exec(availableToolbars->mapToGlobal( _pos) );
  }
}

// =======================================================================================================
// ToolBox Context Menus Buttons
// =======================================================================================================

/// opens custom context menu in used toolbox-List
void viewModeWidget::slotUsedToolboxContextMenu ( const QPoint & _pos ){
  
  if (toolboxList->itemAt(_pos)){
    
    QMenu menu(0);
    
    if (toolboxList->selectedItems().count() == 1){
      menu.addAction(tr("Move up"), this, SLOT ( slotMoveUp() ));
      menu.addAction(tr("Move down"), this, SLOT ( slotMoveDown() ));
      menu.addSeparator();
    }
    
    if ( toolboxList->selectedItems().count() != 0 )
      menu.addAction(tr("Remove"), this, SLOT ( slotRightArrowToolbox() ));
    
    menu.exec(toolboxList->mapToGlobal( _pos) );
  }
}

/// opens custom context menu in available toolbox-List
void viewModeWidget::slotAvailableToolboxContextMenu ( const QPoint & _pos ){
  
  if (availableToolboxes->itemAt(_pos)){
    
    QMenu menu(0);
    
    if ( availableToolboxes->selectedItems().count() != 0 )
      menu.addAction(tr("Add"), this, SLOT ( slotLeftArrowToolbox() ));
    
    menu.exec(availableToolboxes->mapToGlobal( _pos) );
  }
}


// =======================================================================================================
// ToolBar Buttons
// =======================================================================================================

void viewModeWidget::slotRightArrowToolbar() {
  QList<QListWidgetItem *> selectedItems = toolbarList->selectedItems ();
  for ( int i = 0 ; i < selectedItems.size(); ++i ) 
    availableToolbars->addItem(selectedItems[i]->text());

  qDeleteAll(selectedItems);
}

void viewModeWidget::slotLeftArrowToolbar() {
  QList<QListWidgetItem *> selectedItems = availableToolbars->selectedItems ();
  for ( int i = 0 ; i < selectedItems.size(); ++i ) 
    toolbarList->addItem(selectedItems[i]->text());
  
  qDeleteAll(selectedItems);
}

// =======================================================================================================
// ToolBox Buttons
// =======================================================================================================

void viewModeWidget::slotRightArrowToolbox() {
  QList<QListWidgetItem *> selectedItems = toolboxList->selectedItems ();
  for ( int i = 0 ; i < selectedItems.size(); ++i ) 
    availableToolboxes->addItem(selectedItems[i]->text());
  
  qDeleteAll(selectedItems);
}

void viewModeWidget::slotLeftArrowToolbox() {
  QList<QListWidgetItem *> selectedItems = availableToolboxes->selectedItems ();
  for ( int i = 0 ; i < selectedItems.size(); ++i ) 
    toolboxList->addItem(selectedItems[i]->text());
  
  qDeleteAll(selectedItems);
}


Jan Möbius's avatar
 
Jan Möbius committed
332
333
/// Move Widget up in the list
void viewModeWidget::slotMoveUp(){
334
335
  if (toolboxList->selectedItems().count() == 1){
    if (toolboxList->currentRow() == 0) return;
Jan Möbius's avatar
 
Jan Möbius committed
336
    //extract a list of all items
337
338
    QString item = toolboxList->currentItem()->text();
    int oldRow = toolboxList->currentRow();
Jan Möbius's avatar
 
Jan Möbius committed
339
    QStringList widgets;
340
341
    for (int i=0; i < toolboxList->count(); i++)
      widgets << toolboxList->item(i)->text();
342
    
Jan Möbius's avatar
 
Jan Möbius committed
343
344
345
346
347
348
349
350
351
    //reorder items
    QString last = widgets[0];
    for (int i=1; i < widgets.size(); i++){
      if (widgets[i] == item){
        widgets[i] = last;
        widgets[i-1] = item;
      }
      last = widgets[i];
    }
352
353
354
    // set new list as elements for the toolboxList
    toolboxList->clear();
    toolboxList->addItems(widgets);
Jan Möbius's avatar
 
Jan Möbius committed
355
    //highlight active item
356
    toolboxList->setCurrentRow(oldRow-1);
Jan Möbius's avatar
 
Jan Möbius committed
357
358
359
360
361
  }
}

/// Move widget do in the list
void viewModeWidget::slotMoveDown(){
362
363
  if (toolboxList->selectedItems().count() == 1){
    if (toolboxList->currentRow() == toolboxList->count()-1) return;
Jan Möbius's avatar
 
Jan Möbius committed
364
    //extract a list of all items
365
366
    QString item = toolboxList->currentItem()->text();
    int oldRow = toolboxList->currentRow();
Jan Möbius's avatar
 
Jan Möbius committed
367
    QStringList widgets;
368
369
    for (int i=0; i < toolboxList->count(); i++)
      widgets << toolboxList->item(i)->text();
370
    
Jan Möbius's avatar
 
Jan Möbius committed
371
372
373
374
375
376
377
378
379
    //reorder items
    QString last = widgets[widgets.size()-1];
    for (int i=widgets.size()-2; i >= 0; i--){
      if (widgets[i] == item){
        widgets[i] = last;
        widgets[i+1] = item;
      }
      last = widgets[i];
    }
380
381
382
    // set new list as elements for the toolboxList
    toolboxList->clear();
    toolboxList->addItems(widgets);
Jan Möbius's avatar
 
Jan Möbius committed
383
    //highlight active item
384
    toolboxList->setCurrentRow(oldRow+1);
Jan Möbius's avatar
 
Jan Möbius committed
385
386
387
388
  }
}


389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410

// =======================================================================================================
// External communication
// =======================================================================================================

/// Slot for changing View and closing widget
void viewModeWidget::slotChangeView(){
  //get toolboxes
  QStringList toolboxes;
  for (int i=0; i < toolboxList->count(); i++)
    toolboxes << toolboxList->item(i)->text();
  
  //get toolbars
  QStringList toolbars;
  for (int i=0; i < toolbarList->count(); i++)
    toolbars << toolbarList->item(i)->text();
  
  //get mode
  QString mode = "";
  if (viewModeList->selectedItems().size() > 0)
    mode = viewModeList->selectedItems()[0]->text();
  
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
  
  // Check current configuration if it is a changed view mode
  
  // Search for current mode 
  int id = -1;
  if ( viewModeList->selectedItems().count() > 0) 
    for (int i=0; i < modes_.size(); i++)
      if (modes_[i]->name == viewModeList->currentItem()->text()){
        id = i;
        break;
      }
      
  if ( id == -1 ) {
    std::cerr << "Currently selected Mode not found?!" << std::endl; 
    return;
  }
  
  bool matching = true;
  // Check if toolbox list matches:
  if ( modes_[id]->visibleToolboxes.size() == toolboxes.size() ) {
    for ( int i = 0 ; i < modes_[id]->visibleToolboxes.size(); ++i  ) 
      if ( modes_[id]->visibleToolboxes[i] != toolboxes[i] )
        matching = false;
  } else {
      matching = false;
  }
  
  // Check if toolbar list matches:
  if ( modes_[id]->visibleToolbars.size() == toolbars.size() ) {
    for ( int i = 0 ; i < modes_[id]->visibleToolbars.size(); ++i  ) 
      if ( modes_[id]->visibleToolbars[i] != toolbars[i] )
        matching = false;
  } else {
    matching = false;
  }
  
  if ( !matching ) {
    int ret = QMessageBox::warning(this, 
                                   tr("Mode has been changed!"),
                                   tr("You changed the view mode configuration. Do you want to save it?"),
                                   QMessageBox::Yes|QMessageBox::No,
                                   QMessageBox::No);
    if (ret == QMessageBox::Yes) 
      slotSaveMode();
    
  }
  
458
459
  emit changeView(mode,toolboxes,toolbars);
  close();
Jan Möbius's avatar
 
Jan Möbius committed
460
461
}

462
463
464
465
466
/// Slot for saving current List of Widgets as custom mode
void viewModeWidget::slotSaveMode(){
  // Search for current mode vector
  int id = -1;
  if ( viewModeList->selectedItems().count() > 0) 
Jan Möbius's avatar
 
Jan Möbius committed
467
    for (int i=0; i < modes_.size(); i++)
468
      if (modes_[i]->name == viewModeList->currentItem()->text()){
469
        id = i;
Jan Möbius's avatar
 
Jan Möbius committed
470
471
        break;
      }
472
473
  
  if ( id == -1 ) {
474
    std::cerr << "Mode Not found in slotSaveMode" << std::endl;
475
    return;
Jan Möbius's avatar
 
Jan Möbius committed
476
  }
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
  
  // Get Toolboxes
  QStringList toolboxes;
  for (int i=0; i < toolboxList->count(); i++)
    toolboxes << toolboxList->item(i)->text();
  
  // Get Toolbars
  QStringList toolbars;
  for (int i=0; i < toolbarList->count(); i++)
    toolbars << toolbarList->item(i)->text();
   
  bool  createNewMode = false;

  QString message = tr("You cannot change predefined modes.\n"
                       "Please enter a new Name for the mode.");
  
  // Check if we want to create a new node.
  if ( ! modes_[id]->custom ) {
    createNewMode = true;
    
  } else {
    int ret = QMessageBox::warning(this, 
                                   tr("View Mode exists"),
                                   tr("View Mode already exists. Do you want to overwrite it?"),
                                   QMessageBox::Yes|QMessageBox::No,
                                   QMessageBox::No);
    if (ret == QMessageBox::No) {
      message = tr("New name for view mode:");
      createNewMode = true;
    }
  }
  
  
  if ( createNewMode ) {
    
    //ask for a name for the new viewmode as it is not a custom one
    bool ok;
    QString name = QInputDialog::getText(this, tr("Save view Mode"),
                                               message, QLineEdit::Normal,
                                                  "", &ok);
                                                    
    //Remove Spaces from name
    if (!ok || name.isEmpty()) {
      std::cerr << "Illegal or no name given!" << std::endl;
      return; 
    }
    
    //check if name already exists
    for (int i=0; i < modes_.size(); i++)
      if (modes_[i]->name == name){
        QMessageBox::warning(this, tr("Save View Mode"), tr("Cannot Save ViewMode. Name already taken by a different mode."), QMessageBox::Ok);
        return;
      }
      
    emit saveMode(name, true, toolboxes, toolbars);
    show(name);      
  } else {
    emit saveMode(modes_[id]->name, true, toolboxes, toolbars);
    show(modes_[id]->name);    
  }
  
}  

Jan Möbius's avatar
 
Jan Möbius committed
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560


















/// overloaded show function
void viewModeWidget::show(QString _lastMode){
  QDialog::show();
561
  
562
563
  //fill viewModeList
  viewModeList->clear();
Jan Möbius's avatar
 
Jan Möbius committed
564
  for (int i=0; i < modes_.size(); i++){
565
566
567
    QListWidgetItem *item = new QListWidgetItem(viewModeList);
    item->setTextAlignment(Qt::AlignHCenter);
    item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
Jan Möbius's avatar
Jan Möbius committed
568
569
    item->setIcon(QIcon(OpenFlipper::Options::iconDirStr() + QDir::separator () + modes_[i]->icon));
    
570
    item->setText(modes_[i]->name);
571
    
Jan Möbius's avatar
 
Jan Möbius committed
572
    if (modes_[i]->custom)
573
      viewModeList->item(i)->setForeground( QBrush(QColor(0,0,150) ) );
Jan Möbius's avatar
 
Jan Möbius committed
574
    else
575
      viewModeList->item(i)->setForeground( QBrush(QColor(0,0,0) ) );
Jan Möbius's avatar
 
Jan Möbius committed
576
  }
577
  
Jan Möbius's avatar
 
Jan Möbius committed
578
  //select given mode
579
  viewModeList->setCurrentRow(0);
580
  
581
582
583
  for (int i=0; i < viewModeList->count(); i++)
    if (viewModeList->item(i)->text() == _lastMode)
      viewModeList->setCurrentRow(i);
584
585
586
587
    
    removeButton->setEnabled(false);
}

Jan Möbius's avatar
 
Jan Möbius committed
588

589
590
591
/// Slot for updating removeButton when new mode is selected
void viewModeWidget::slotModeClicked(QModelIndex /*_id*/){
  slotModeChanged(QString());
Jan Möbius's avatar
 
Jan Möbius committed
592
593
}

594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
/// Slot for updating removeButton when new mode is selected
void viewModeWidget::slotModeChanged(QString /*_mode*/){
  //check if mode is custom e.g. that it can be removed
  if (viewModeList->selectedItems().count() > 0){
    for (int i=0; i < modes_.size(); i++)
      if (modes_[i]->name == viewModeList->currentItem()->text()){
        removeButton->setEnabled(modes_[i]->custom);
        break;
      }
  }
}