Skip to content

Commit 348519e

Browse files
Merge pull request #48 from trikset/directCommands
Direct commands
2 parents 63c7b70 + e04f9af commit 348519e

File tree

28 files changed

+482
-332
lines changed

28 files changed

+482
-332
lines changed

global.pri

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# Build settings common to all projects in TrikRuntime.
1616
# Provides:
1717
# CONFIGURATION_SUFFIX variable that shall be consistently used in TARGET and LIBS variables in all projects.
18+
# copyToDestdir function to copy arbitrary files and directories to DESTDIR
19+
# uses function to automatically add a library to INCLUDEPATH and LIBS.
1820

1921
CROSS_COMPILE = $$(CROSS_COMPILE)
2022

@@ -38,6 +40,11 @@ CONFIG(debug, debug | release) {
3840

3941
DESTDIR = $$PWD/bin/$$CONFIGURATION
4042

43+
PROJECT_BASENAME = $$basename(_PRO_FILE_)
44+
PROJECT_NAME = $$section(PROJECT_BASENAME, ".", 0, 0)
45+
46+
TARGET = $$PROJECT_NAME$$CONFIGURATION_SUFFIX
47+
4148
equals(TEMPLATE, app) {
4249
!macx {
4350
QMAKE_LFLAGS += -Wl,-O1,-rpath,.
@@ -50,11 +57,16 @@ MOC_DIR = .build/$$CONFIGURATION/.moc
5057
RCC_DIR = .build/$$CONFIGURATION/.rcc
5158
UI_DIR = .build/$$CONFIGURATION/.ui
5259

60+
INCLUDEPATH += $$_PRO_FILE_PWD_ \
61+
$$_PRO_FILE_PWD_/include/$$PROJECT_NAME \
62+
5363
unix {
5464
target.path = $$[INSTALL_ROOT]/
5565
INSTALLS += target
5666
}
5767

68+
GLOBAL_PWD = $$PWD
69+
5870
# Useful function to copy additional files to destination,
5971
# from http://stackoverflow.com/questions/3984104/qmake-how-to-copy-a-file-to-the-output
6072
defineTest(copyToDestdir) {
@@ -77,3 +89,16 @@ defineTest(copyToDestdir) {
7789

7890
export(QMAKE_POST_LINK)
7991
}
92+
93+
defineTest(uses) {
94+
LIBS += -L$$DESTDIR
95+
PROJECTS = $$1
96+
97+
for(PROJECT, PROJECTS) {
98+
LIBS += -l$$PROJECT$$CONFIGURATION_SUFFIX
99+
INCLUDEPATH += $$GLOBAL_PWD/$$PROJECT/include
100+
}
101+
102+
export(LIBS)
103+
export(INCLUDEPATH)
104+
}

trikCommunicator/trikCommunicator.pro

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,25 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
TRIKKERNEL_DIR = ../trikKernel/
16-
TRIKCONTROL_DIR = ../trikControl/
17-
TRIKSCRIPTRUNNER_DIR = ../trikScriptRunner/
18-
19-
TEMPLATE = lib
20-
21-
QT += network
22-
23-
DEFINES += TRIKCOMMUNICATOR_LIBRARY
24-
2515
include(../global.pri)
2616

27-
TARGET = trikCommunicator$$CONFIGURATION_SUFFIX
28-
29-
INCLUDEPATH = \
30-
$$PWD \
31-
$$PWD/include/trikCommunicator \
32-
$$TRIKSCRIPTRUNNER_DIR/include \
33-
$$TRIKCONTROL_DIR/include \
34-
$$TRIKKERNEL_DIR/include \
35-
36-
LIBS += -L$$DESTDIR -ltrikScriptRunner$$CONFIGURATION_SUFFIX -ltrikKernel$$CONFIGURATION_SUFFIX
37-
3817
HEADERS += \
3918
$$PWD/include/trikCommunicator/trikCommunicator.h \
4019
$$PWD/src/connection.h \
4120

4221
SOURCES += \
4322
$$PWD/src/trikCommunicator.cpp \
4423
$$PWD/src/connection.cpp \
24+
25+
TEMPLATE = lib
26+
27+
QT += network
28+
29+
DEFINES += TRIKCOMMUNICATOR_LIBRARY
30+
31+
uses(trikScriptRunner trikControl trikKernel)
32+
33+
INCLUDEPATH += \
34+
../trikScriptRunner/include/ \
35+
../trikControl/include/ \
36+
../trikKernel/include/ \

trikControl/include/trikControl/sensor3d.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515
#pragma once
1616

1717
#include <QtCore/QObject>
18-
#include <QtCore/QSocketNotifier>
19-
#include <QtCore/QSharedPointer>
18+
#include <QtCore/QScopedPointer>
19+
#include <QtCore/QThread>
2020
#include <QtCore/QVector>
2121

2222
#include "declSpec.h"
2323

2424
namespace trikControl {
2525

26+
class Sensor3dWorker;
27+
2628
/// Sensor that returns 3d vector.
2729
class TRIKCONTROL_EXPORT Sensor3d : public QObject
2830
{
@@ -35,20 +37,15 @@ class TRIKCONTROL_EXPORT Sensor3d : public QObject
3537
/// @param deviceFile - device file for this sensor.
3638
Sensor3d(int min, int max, QString const &deviceFile);
3739

40+
~Sensor3d();
41+
3842
public slots:
3943
/// Returns current raw reading of a sensor in a form of vector with 3 coordinates.
40-
QVector<int> const &read() const;
41-
42-
private slots:
43-
/// Updates current reading when new value is ready.
44-
void readFile();
44+
QVector<int> read() const;
4545

4646
private:
47-
QSharedPointer<QSocketNotifier> mSocketNotifier;
48-
QVector<int> mReading;
49-
int mDeviceFileDescriptor;
50-
int mMax;
51-
int mMin;
47+
QScopedPointer<Sensor3dWorker> mSensor3dWorker;
48+
QThread mWorkerThread;
5249
};
5350

5451
}

trikControl/src/display.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Display::Display(QThread &guiThread, const QString &startDirPath)
3333
, mGuiWorker(new GuiWorker())
3434
{
3535
mGuiWorker->moveToThread(&guiThread);
36+
QMetaObject::invokeMethod(mGuiWorker, "init");
3637
}
3738

3839
Display::~Display()

trikControl/src/guiWorker.cpp

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -30,46 +30,54 @@
3030
using namespace trikControl;
3131

3232
GuiWorker::GuiWorker()
33-
: mFontMetrics(mImageWidget.font())
3433
{
34+
35+
}
36+
37+
void GuiWorker::init()
38+
{
39+
mImageLabel.reset(new QLabel());
40+
mImageWidget.reset(new GraphicsWidget());
41+
mFontMetrics.reset(new QFontMetrics(mImageWidget->font()));
42+
3543
QHBoxLayout * const layout = new QHBoxLayout();
36-
mImageLabel.setScaledContents(true);
37-
layout->addWidget(&mImageLabel);
38-
mImageWidget.setLayout(layout);
39-
mImageWidget.setWindowState(Qt::WindowFullScreen);
40-
mImageWidget.setWindowFlags(mImageWidget.windowFlags() | Qt::WindowStaysOnTopHint);
44+
mImageLabel->setScaledContents(true);
45+
layout->addWidget(mImageLabel.data());
46+
mImageWidget->setLayout(layout);
47+
mImageWidget->setWindowState(Qt::WindowFullScreen);
48+
mImageWidget->setWindowFlags(mImageWidget->windowFlags() | Qt::WindowStaysOnTopHint);
4149
resetBackground();
4250
}
4351

4452
void GuiWorker::showImage(QString const &fileName)
4553
{
4654
if (!mImagesCache.contains(fileName)) {
4755
QPixmap pixmap(fileName);
48-
pixmap = pixmap.scaled(mImageWidget.size() - QSize(20, 20), Qt::KeepAspectRatio);
56+
pixmap = pixmap.scaled(mImageWidget->size() - QSize(20, 20), Qt::KeepAspectRatio);
4957
mImagesCache.insert(fileName, pixmap);
5058
}
5159

52-
mImageLabel.setPixmap(mImagesCache.value(fileName));
53-
mImageWidget.show();
60+
mImageLabel->setPixmap(mImagesCache.value(fileName));
61+
mImageWidget->show();
5462
}
5563

5664
void GuiWorker::addLabel(QString const &text, int x, int y)
5765
{
5866
QLabel *label = findLabel(x, y);
59-
label = label ? label : new QLabel(&mImageWidget);
67+
label = label ? label : new QLabel(mImageWidget.data());
6068
label->setText(text);
61-
label->setStyleSheet(QString("color: %1").arg(mImageWidget.currentPenColor().name()));
69+
label->setStyleSheet(QString("color: %1").arg(mImageWidget->currentPenColor().name()));
6270

6371
// There is no layout for the label, so its size cannot be set automatically. We set
6472
// it with QFontMetrics.
65-
label->setGeometry(x, y, mFontMetrics.width(text), mFontMetrics.height());
73+
label->setGeometry(x, y, mFontMetrics->width(text), mFontMetrics->height());
6674

6775
label->show();
6876
if (!mLabels.contains(x ^ y, label)) {
6977
mLabels.insertMulti(x ^ y, label);
7078
}
7179

72-
mImageWidget.show();
80+
mImageWidget->show();
7381
}
7482

7583
void GuiWorker::removeLabels()
@@ -89,7 +97,7 @@ void GuiWorker::deleteWorker()
8997

9098
void GuiWorker::setBackground(QString const &color)
9199
{
92-
QPalette palette = mImageWidget.palette();
100+
QPalette palette = mImageWidget->palette();
93101

94102
if (color == tr("white")) {
95103
palette.setColor(QPalette::Window, Qt::white);
@@ -129,41 +137,41 @@ void GuiWorker::setBackground(QString const &color)
129137
palette.setColor(QPalette::Window, QColor(color));
130138
}
131139

132-
mImageWidget.setPalette(palette);
133-
mImageWidget.show();
140+
mImageWidget->setPalette(palette);
141+
mImageWidget->show();
134142
}
135143

136144
void GuiWorker::resetBackground()
137145
{
138-
QPalette palette = mImageWidget.palette();
146+
QPalette palette = mImageWidget->palette();
139147
palette.setColor(QPalette::Window, Qt::lightGray);
140-
mImageWidget.setPalette(palette);
148+
mImageWidget->setPalette(palette);
141149
}
142150

143151
void GuiWorker::setPainterColor(QString const &color)
144152
{
145-
mImageWidget.setPainterColor(color);
153+
mImageWidget->setPainterColor(color);
146154
}
147155

148156
void GuiWorker::setPainterWidth(int penWidth)
149157
{
150-
mImageWidget.setPainterWidth(penWidth);
158+
mImageWidget->setPainterWidth(penWidth);
151159
}
152160

153161
void GuiWorker::clear()
154162
{
155-
mImageWidget.deleteAllItems();
156-
mImageWidget.setPainterColor("black");
157-
mImageWidget.setPainterWidth(0);
158-
mImageWidget.hide();
163+
mImageWidget->deleteAllItems();
164+
mImageWidget->setPainterColor("black");
165+
mImageWidget->setPainterWidth(1);
166+
mImageWidget->hide();
159167
removeLabels();
160-
mImageLabel.setPixmap(QPixmap());
168+
mImageLabel->setPixmap(QPixmap());
161169
resetBackground();
162170
}
163171

164172
void GuiWorker::hide()
165173
{
166-
mImageWidget.hide();
174+
mImageWidget->hide();
167175
}
168176

169177
QLabel *GuiWorker::findLabel(int x, int y) const
@@ -179,35 +187,35 @@ QLabel *GuiWorker::findLabel(int x, int y) const
179187

180188
void GuiWorker::drawPoint(int x, int y)
181189
{
182-
mImageWidget.drawPoint(x, y);
183-
mImageWidget.update();
184-
mImageWidget.show();
190+
mImageWidget->drawPoint(x, y);
191+
mImageWidget->update();
192+
mImageWidget->show();
185193
}
186194

187195
void GuiWorker::drawLine(int x1, int y1, int x2, int y2)
188196
{
189-
mImageWidget.drawLine(x1, y1, x2, y2);
190-
mImageWidget.update();
191-
mImageWidget.show();
197+
mImageWidget->drawLine(x1, y1, x2, y2);
198+
mImageWidget->update();
199+
mImageWidget->show();
192200
}
193201

194202
void GuiWorker::drawRect(int x, int y, int width, int height)
195203
{
196-
mImageWidget.drawRect(x, y, width, height);
197-
mImageWidget.update();
198-
mImageWidget.show();
204+
mImageWidget->drawRect(x, y, width, height);
205+
mImageWidget->update();
206+
mImageWidget->show();
199207
}
200208

201209
void GuiWorker::drawEllipse(int x, int y, int width, int height)
202210
{
203-
mImageWidget.drawEllipse(x, y, width, height);
204-
mImageWidget.update();
205-
mImageWidget.show();
211+
mImageWidget->drawEllipse(x, y, width, height);
212+
mImageWidget->update();
213+
mImageWidget->show();
206214
}
207215

208216
void GuiWorker::drawArc(int x, int y, int width, int height, int startAngle, int spanAngle)
209217
{
210-
mImageWidget.drawArc(x, y, width, height, startAngle, spanAngle);
211-
mImageWidget.update();
212-
mImageWidget.show();
218+
mImageWidget->drawArc(x, y, width, height, startAngle, spanAngle);
219+
mImageWidget->update();
220+
mImageWidget->show();
213221
}

trikControl/src/guiWorker.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <QtCore/qglobal.h>
1818
#include <QtCore/QMultiHash>
1919
#include <QtCore/QList>
20+
#include <QtCore/QScopedPointer>
2021
#include <QtGui/QPixmap>
2122
#include <QtGui/QFontMetrics>
2223

@@ -109,17 +110,20 @@ public slots:
109110
/// @param spanAngle - end andle.
110111
void drawArc(int x, int y, int width, int height, int startAngle, int spanAngle);
111112

113+
/// Initializes widget. Shall be called when widget is moved to correct thread. Not supposed to be called from .qts.
114+
void init();
115+
112116
private:
113117
void resetBackground();
114118

115119
/// Returns existing label with given coordinates or NULL if no such label exists.
116120
QLabel *findLabel(int x, int y) const;
117121

118-
GraphicsWidget mImageWidget;
119-
QLabel mImageLabel;
122+
QScopedPointer<GraphicsWidget> mImageWidget;
123+
QScopedPointer<QLabel> mImageLabel;
120124
QHash<QString, QPixmap> mImagesCache;
121125
QMultiHash<int, QLabel *> mLabels; // Has ownership.
122-
QFontMetrics mFontMetrics;
126+
QScopedPointer<QFontMetrics> mFontMetrics;
123127
};
124128

125129
}

0 commit comments

Comments
 (0)