Developer Documentation
rendererWidget.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: 15910 $ *
45 * $LastChangedBy: moeller $ *
46 * $Date: 2012-12-05 12:53:39 +0100 (Mi, 05 Dez 2012) $ *
47 * *
48 \*===========================================================================*/
49 
50 #include "rendererWidget.hh"
51 
52 #if QT_VERSION >= 0x050000
53  #include <QtWidgets>
54 #else
55  #include <QtGui>
56 #endif
57 
60 
61 
62 RendererDialog::RendererDialog(QWidget *parent)
63  : QDialog(parent)
64 {
65  setupUi(this);
66 
67  list->setContextMenuPolicy(Qt::CustomContextMenu);
68 
69  connect(closeButton, SIGNAL(clicked()), this, SLOT(accept()));
70  connect(list,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(slotContextMenu(const QPoint&)));
71 
72  //set icons
73  QString iconPath = OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator();
74 
75  closeButton->setIcon( QIcon(iconPath + "window-close.png"));
76 
77 }
78 
79 void RendererDialog::closeEvent(QCloseEvent *event)
80 {
81  event->accept();
82  accept();
83 }
84 
85 
86 void RendererDialog::showEvent ( QShowEvent * ) {
87  update();
88 }
89 
90 void RendererDialog::update()
91 {
92 
93  list->clear();
94 
95  for ( unsigned int i = 0 ; i < renderManager().available() ; ++i) {
96 
97  // Get and check post processor
98  RendererInfo* renderer = renderManager()[i];
99  if ( ! renderer )
100  continue;
101 
102  QFrame* frame = new QFrame();
103  QHBoxLayout* hlayout = new QHBoxLayout;
104 
105  QLabel* name = new QLabel( renderer->name );
106  QFont font;
107  font.setBold(true);
108  font.setPointSize(10);
109  name->setFont(font);
110  QLabel* version = new QLabel( renderer->version );
111  hlayout->addWidget(name);
112  hlayout->addStretch();
113  hlayout->addWidget(version);
114 
115  QVBoxLayout* vlayout = new QVBoxLayout;
116 
117  QLabel* description = new QLabel( renderer->description );
118  descriptions_.push_back(description);
119 
120  vlayout->addLayout(hlayout,20);
121  vlayout->addWidget(description);
122  frame->setLayout(vlayout);
123 
124  QListWidgetItem *item = new QListWidgetItem("");
125  frames_.push_back(frame);
126  item->setSizeHint( QSize (100,50) );
127 
128  list->addItem(item);
129  list->setItemWidget(item, frame);
130 
131  if ( renderManager().activeId(PluginFunctions::activeExaminer()) == i )
132  item->setBackground( Qt::green );
133  }
134 
135 }
136 
138  for (int i=0; i < list->selectedItems().size(); ++i)
139  {
140  QListWidgetItem* widget = list->selectedItems()[i];
141 
142  renderManager().setActive( list->row( widget ), PluginFunctions::activeExaminer());
143  }
144 
145  update();
146 }
147 
148 
149 void RendererDialog::slotContextMenu(const QPoint& _point)
150 {
151  if (!list->count())
152  return;
153 
154  QMenu *menu = new QMenu(list);
155  QAction* action = 0;
156 
157  action = menu->addAction(tr("Activate"));
158  connect(action,SIGNAL(triggered(bool)),this,SLOT(slotActivateRenderer()));
159 
160 
161  menu->exec(list->mapToGlobal(_point),0);
162 
163 }
QString description
Description of the plugin ( requested from the plugin on load)
Definition: RendererInfo.hh:83
unsigned int available()
number of available renderers
void slotActivateRenderer()
Activates the renderer (triggered via the context menu)
unsigned int activeExaminer()
Get the id of the examiner which got the last mouse events.
QString version
Version of the plugin ( requested from the plugin on load)
Definition: RendererInfo.hh:80
void slotContextMenu(const QPoint &_point)
Show the custom context menu.
void setActive(unsigned int _active, int _id)
set the active renderer
QString name
Name of the plugin ( requested from the plugin on load)
Definition: RendererInfo.hh:77