Developer Documentation
functionDisplay.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 //== INCLUDES =================================================================
45 #include <QWidget>
46 #include <QPainter>
47 #include <QGraphicsLinearLayout>
48 #include <QGraphicsProxyWidget>
49 #include <QGraphicsGridLayout>
50 
51 #include "baseWidget.hh"
52 
53 #include "functionDisplay.hh"
54 #include "elementFunction.hh"
55 #include "text.hh"
56 #include "button.hh"
57 
58 #include "../parser/function.hh"
59 #include "../parser/element.hh"
60 
61 #define BACKGROUND_RED 0x0
62 #define BACKGROUND_GREEN 0x0
63 #define BACKGROUND_BLUE 0x0
64 #define BACKGROUND_ALPHA 0xff
65 
66 
67 //== NAMESPACES ===============================================================
68 namespace VSI {
69 
70 //=============================================================================
71 //
72 // CLASS VSI::FunctionDisplay - IMPLEMENTATION
73 //
74 //=============================================================================
75 
78  scene_ (_scene)
79 {
80  QGraphicsGridLayout *tL = new QGraphicsGridLayout;
81 
82  // If the scene belongs to a function, then display its name and add the "Go back" button
83  if (scene_->function ())
84  {
85 
86  Text *f = new Text (scene_->function ()->function ()->element ()->shortDescription (), this);
87  Text *fn = new Text (scene_->function ()->function ()->shortDescription (), this);
88  Button *goBack = new Button (tr("Go back"), this);
89 
90  f->setBackground (true, false);
91  f->setBrush (Qt::black);
92  f->setBackgroundBrush (Qt::gray);
93  fn->setBackground (true, false);
94  fn->setBrush (Qt::black);
95  fn->setBackgroundBrush (Qt::white);
96  goBack->setBrush (Qt::black);
97  goBack->setBackgroundBrush (Qt::lightGray);
98  goBack->setBackground (true, true);
99 
100  connect (goBack, SIGNAL (pressed ()), BaseWidget::getBaseWidget(), SLOT (popScene ()));
101 
102  QFont font = f->font ();
103  fn->setFont (font);
104  font.setBold (true);
105  f->setFont (font);
106 
107 
108  tL->addItem (f, 0, 0, Qt::AlignVCenter | Qt::AlignLeft);
109  tL->addItem (fn, 0, 1, Qt::AlignVCenter | Qt::AlignLeft);
110  tL->addItem (goBack, 0, 2, Qt::AlignVCenter | Qt::AlignLeft);
111  }
112  // Scene is the main scene
113  else
114  {
115  Text *f = new Text (tr("Main"), this);
116  f->setBackground (true, true);
117  f->setBrush (Qt::black);
118  f->setBackgroundBrush (Qt::white);
119 
120  tL->addItem (f, 0, 0);
121 
122  QFont font = f->font ();
123  font.setBold (true);
124  f->setFont (font);
125  }
126 
127  tL->setHorizontalSpacing (1);
128  tL->setContentsMargins (3, 3, 3, 3);
129  setLayout (tL);
130 
131  setMinimumWidth (tL->preferredWidth());
132 }
133 
134 //------------------------------------------------------------------------------
135 
138 {
139 }
140 
141 //------------------------------------------------------------------------------
142 
144 void FunctionDisplay::paint (QPainter *_painter, const QStyleOptionGraphicsItem *_option, QWidget *_widget)
145 {
146  int w = geometry().width();
147  int h = geometry().height();
148 
149  _painter->setRenderHint(QPainter::Antialiasing, true);
150 
151  _painter->setBrush(QBrush(QColor(BACKGROUND_RED,
152  BACKGROUND_GREEN,
153  BACKGROUND_BLUE,
154  BACKGROUND_ALPHA)));
155 
156  _painter->setPen(QColor(BACKGROUND_RED,
157  BACKGROUND_GREEN,
158  BACKGROUND_BLUE,
159  BACKGROUND_ALPHA));
160 
161  QPainterPath path;
162  path.moveTo (0, 0);
163  path.lineTo (0, h);
164  path.lineTo (w - 10, h);
165  path.arcTo (w - 20, h - 20, 20, 20, -90, 90);
166  path.lineTo (w, 0);
167  path.lineTo (0, 0);
168  _painter->drawPath (path);
169 
170 
171  QLinearGradient lG;
172  QRadialGradient rG;
173 
174  _painter->setPen (Qt::NoPen);
175 
176  lG.setStart (w - 5, 0);
177  lG.setFinalStop(w, 0);
178  lG.setColorAt(0, Qt::transparent);
179  lG.setColorAt(1, QColor (255, 255, 255, 128));
180  _painter->setBrush (lG);
181  _painter->drawRect (w - 5, 0, 5, h - 10);
182 
183  lG.setStart (0, h - 5);
184  lG.setFinalStop (0, h);
185  _painter->setBrush (lG);
186  _painter->drawRect (0, h - 5, w - 10, 5);
187 
188  path = QPainterPath ();
189  path.moveTo (w - 10, h);
190  path.arcTo (w - 20, h - 20, 20, 20, -90, 90);
191  path.lineTo (w - 10, h - 10);
192  path.lineTo (w - 10, h);
193  rG.setCenter (w - 10, h - 10);
194  rG.setFocalPoint(w -10, h - 10);
195  rG.setRadius (10);
196  rG.setColorAt (0, Qt::transparent);
197  rG.setColorAt (0.5, Qt::transparent);
198  rG.setColorAt (1, QColor (255, 255, 255, 128));
199  _painter->setBrush (rG);
200  _painter->drawPath(path);
201 
202  QGraphicsWidget::paint (_painter, _option, _widget);
203 }
204 
205 //------------------------------------------------------------------------------
206 }
207 
const QString & shortDescription() const
Short description.
Definition: function.hh:84
virtual void setBackgroundBrush(QBrush _brush)
Sets the background brush.
Definition: text.cc:379
ElementFunction * function()
Associated function.
void setBackground(bool _leftOut, bool _rightOut)
Enables background painting.
Definition: text.cc:300
Element * element() const
Element that this function belongs to.
Definition: function.hh:78
static BaseWidget * getBaseWidget()
Returns singleton.
Definition: baseWidget.cc:465
Function * function()
Function class.
void paint(QPainter *_painter, const QStyleOptionGraphicsItem *_option, QWidget *_widget=0)
Paints the background.
FunctionDisplay(GraphicsScene *_scene)
Constructor.
const QString & shortDescription() const
Short description.
Definition: element.hh:88
~FunctionDisplay()
Destructor.