Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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