-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
74 lines (60 loc) · 2.64 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QThread>
#include <qqmlcontext.h>
#include "ddcutilController.h"
#include "displaylistitemmodel.h"
static QList<QObject*> displayList;
static DDCutilController* brightnessController;
static QQmlApplicationEngine* engine;
class QDetectThread: public QThread {
private slots:
void onFinishedInternal() {
if (displayList.count() > 0) {
engine->rootContext()->setContextProperty("displayListItemModel", QVariant::fromValue(displayList));
engine->rootContext()->setContextProperty("tabViewIndex", 1);
} else {
engine->rootContext()->setContextProperty("tabViewIndex", 2);
}
}
private:
virtual void run() {
// This is a hack to migrate to the main thread context
QObject::connect(this, &QThread::finished, this, &QDetectThread::onFinishedInternal);
brightnessController->detect();
for (unsigned int iDisp=0; iDisp<brightnessController->monitorNumber(); iDisp++)
{
long bmax = brightnessController->brightnessMax(iDisp);
displayListItemModel* displayInstance= new displayListItemModel(
brightnessController->nameForDisplay(iDisp),
brightnessController->brightness(iDisp),
0, bmax, bmax * 0.05,
QStringList(brightnessController->whitePointList(iDisp))
);
//New connect syntax, see https://wiki.qt.io/New_Signal_Slot_Syntax
QObject::connect(displayInstance, &displayListItemModel::brightnessChanged, [=](const long newBrightness)
{
brightnessController->setBrightness(iDisp, newBrightness);
});
QObject::connect(displayInstance, &displayListItemModel::whitepointSelectedChanged, [=](const QString newWhitePoint)
{
brightnessController->setWhitepoint(iDisp, newWhitePoint);
});
displayInstance->moveToThread(engine->thread());
displayList.append(displayInstance);
}
}
};
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QDetectThread detectThread;
engine = new QQmlApplicationEngine();
brightnessController = new DDCutilController();
engine->rootContext()->setContextProperty("displayListItemModel", QVariant::fromValue(displayList));
engine->rootContext()->setContextProperty("tabViewIndex", 0);
engine->load(QUrl(QStringLiteral("qrc:/main.qml")));
detectThread.start();
qDebug() << "main thread: " << QObject().thread()->currentThreadId();
return app.exec();
}