Developer Documentation
viewModeChangeWidget.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 "viewModeChangeWidget.hh"
49 
51 viewModeChangeWidget::viewModeChangeWidget(const QVector< ViewMode* >& _modes, QWidget *_parent)
52  : QWidget(_parent, Qt::Window | Qt::CustomizeWindowHint),
53  modes_(_modes)
54 {
55  setupUi(this);
56 
57  connect(viewModeList, SIGNAL(clicked (QModelIndex)), this, SLOT(slotModeClicked(QModelIndex)) );
58 }
59 
60 // =======================================================================================================
61 // External communication
62 // =======================================================================================================
63 
65 void viewModeChangeWidget::slotModeClicked(QModelIndex /*_idx*/ ){
66 
67  // Search for current mode
68  int id = -1;
69  if ( viewModeList->selectedItems().count() > 0)
70  for (int i=0; i < modes_.size(); i++)
71  if (modes_[i]->name == viewModeList->currentItem()->text()){
72  id = i;
73  break;
74  }
75 
76  if ( id == -1 ) {
77  std::cerr << "Currently selected Mode not found?!" << std::endl;
78  return;
79  }
80 
81  emit changeView(modes_[id]->name,modes_[id]->visibleToolboxes,modes_[id]->visibleToolbars,modes_[id]->visibleContextMenus);
82  emit wantClose();
83 }
84 
85 void viewModeChangeWidget::slot_update(){
86  update(OpenFlipper::Options::currentViewMode());
87 };
88 
89 void viewModeChangeWidget::showEvent(QShowEvent *event) {
90  slot_update();
91  QWidget::showEvent(event);
92  //QMenu *parentMenu = qobject_cast<QMenu*>(parent());
93 }
94 
96 void viewModeChangeWidget::update(QString _lastMode){
97 
98  //fill viewModeList
99  viewModeList->clear();
100  for (int i=0; i < modes_.size(); i++){
101  QListWidgetItem *item = new QListWidgetItem(viewModeList);
102  item->setTextAlignment(Qt::AlignHCenter);
103  item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
104 
105  QFile iconFile( OpenFlipper::Options::iconDirStr() + QDir::separator () + modes_[i]->icon );
106 
107  if ( iconFile.exists() )
108  item->setIcon( QIcon(iconFile.fileName()) );
109  else {
110  iconFile.setFileName( OpenFlipper::Options::configDirStr() + QDir::separator() + "Icons" + QDir::separator() + modes_[i]->icon );
111  if ( iconFile.exists() )
112  item->setIcon( QIcon(iconFile.fileName()) );
113  else {
114  item->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + QDir::separator () + "Unknown.png") );
115  std::cerr << "Unable to find icon file! " << iconFile.fileName().toStdString() << std::endl;
116  }
117  }
118 
119  item->setText(modes_[i]->name);
120 
121  if (modes_[i]->custom)
122  viewModeList->item(i)->setForeground( QBrush(QColor(0,0,150) ) );
123  else
124  viewModeList->item(i)->setForeground( QBrush(QColor(0,0,0) ) );
125  }
126 
127  //select given mode
128  viewModeList->setCurrentRow(0);
129 
130  for (int i=0; i < viewModeList->count(); i++)
131  if (viewModeList->item(i)->text() == _lastMode)
132  viewModeList->setCurrentRow(i);
133 
134 }
135 
void update(QString _lastMode)
overloaded show function
void changeView(QString _mode, QStringList _toolboxWidgets, QStringList _toolbars, QStringList _contextmenus)
Changes the view mode to the currently configured one.
void slotModeClicked(QModelIndex _id)
Slot for changing View and closing widget.
viewModeChangeWidget(const QVector< ViewMode * > &_modes, QWidget *parent=0)
Constructor.