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