trikRuntime
guiWorker.h
Go to the documentation of this file.
1 /* Copyright 2013 - 2014 Yurii Litvinov, Smirnov Mikhail, Kogutich Denis
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License. */
14 
15 #pragma once
16 
17 #include <QtCore/qglobal.h>
18 #include <QtCore/QMultiHash>
19 #include <QtCore/QList>
20 #include <QtCore/QScopedPointer>
21 #include <QtGui/QPixmap>
22 #include <QtGui/QFontMetrics>
23 
24 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
25  #include <QtGui/QWidget>
26  #include <QtGui/QLabel>
27 #else
28  #include <QtWidgets/QWidget>
29  #include <QtWidgets/QLabel>
30 #endif
31 
32 #include "graphicsWidget.h"
33 #include "shapes/shape.h"
34 
35 namespace trikControl {
36 
38 class GuiWorker : public QObject
39 {
40  Q_OBJECT
41 
42 public:
43  GuiWorker();
44 
47 
48 public slots:
51  void showImage(const QString &fileName);
52 
54  void show(const QVector<int32_t> &array, int width, int height, const QString &format);
55 
61  void addLabel(const QString &text, int x, int y);
62 
64  void removeLabels();
65 
67  void hide();
68 
71  void setBackground(const QString &color);
72 
74  void setPainterWidth(int penWidth);
75 
77  void setPainterColor(const QString &color);
78 
80  void clear();
81 
83  void reset();
84 
88  void drawPoint(int x, int y);
89 
95  void drawLine(int x1, int y1, int x2, int y2);
96 
102  void drawRect(int x, int y, int width, int height, bool filled = false);
103 
109  void drawEllipse(int x, int y, int width, int height, bool filled = false);
110 
118  void drawArc(int x, int y, int width, int height, int startAngle, int spanAngle);
119 
121  void init();
122 
125  void redraw();
126 
127 private:
128  void resetBackground();
129 
130  void repaintGraphicsWidget();
131 
132  static QColor colorByName(const QString &name);
133 
134  QScopedPointer<GraphicsWidget> mImageWidget;
135  QHash<QString, QPixmap> mImagesCache;
136 };
137 
138 }
void setPainterColor(const QString &color)
Set painter color.
Definition: guiWorker.cpp:130
void drawLine(int x1, int y1, int x2, int y2)
Draw line on the widget without redrawing it.
Definition: guiWorker.cpp:166
void clear()
Clear everything painted with this object.
Definition: guiWorker.cpp:140
void addLabel(const QString &text, int x, int y)
Add a label to the specific position of the screen without redrawing it.
Definition: guiWorker.cpp:104
DisplayWidgetInterface & graphicsWidget()
Returns a widget on which everything is drawn.
Definition: guiWorker.cpp:47
void showImage(const QString &fileName)
Shows image with given filename on display.
Definition: guiWorker.cpp:52
Interface for widget on which Brick draws its graphics. Can notify when it shows or hides itself...
Definition: displayWidgetInterface.h:30
void removeLabels()
Remove all labels from the screen and redraws it.
Definition: guiWorker.cpp:109
void setBackground(const QString &color)
Sets background for a picture.
Definition: guiWorker.cpp:115
void redraw()
Updates painted picture on the robot`s screen.
Definition: guiWorker.cpp:186
void drawArc(int x, int y, int width, int height, int startAngle, int spanAngle)
Draw arc on the widget without redrawing it.
Definition: guiWorker.cpp:181
void hide()
Hides image widget.
Definition: guiWorker.cpp:156
void show(const QVector< int32_t > &array, int width, int height, const QString &format)
Shows image from array data according to format. Image is scaled to fill the screen.
Definition: guiWorker.cpp:64
void drawEllipse(int x, int y, int width, int height, bool filled=false)
Draw ellipse without redrawing the screen.
Definition: guiWorker.cpp:176
void reset()
Returns a display in a blank state.
Definition: guiWorker.cpp:149
Definition: trikCommunicator.h:27
void init()
Initializes widget. Shall be called when widget is moved to correct thread. Not supposed to be called...
Definition: guiWorker.cpp:37
GuiWorker()
Definition: guiWorker.cpp:33
void drawRect(int x, int y, int width, int height, bool filled=false)
Draw rect on the widget without redrawing it.
Definition: guiWorker.cpp:171
void setPainterWidth(int penWidth)
Set painter width.
Definition: guiWorker.cpp:135
void drawPoint(int x, int y)
Draw point on the widget without redrawing it.
Definition: guiWorker.cpp:161
Works in GUI thread and is responsible for all output to display.
Definition: guiWorker.h:38
var x
Definition: file-test.js:2
var y
Definition: file-test.js:5