Skip to content

Commit c2294fe

Browse files
committed
Re-structure Qt projects
1 parent b612155 commit c2294fe

21 files changed

+402
-126
lines changed

GreeRemote.pro

+8-78
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,12 @@
1-
#-------------------------------------------------
2-
#
3-
# Project created by QtCreator 2017-09-18T14:29:43
4-
#
5-
#-------------------------------------------------
1+
TEMPLATE = subdirs
62

7-
QT += core gui network
3+
SUBDIRS = \
4+
GreeLib \
5+
GreeRemoteGuiQt
86

9-
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
7+
lib.subdir = GreeLib
108

11-
TARGET = GreeRemote
12-
TEMPLATE = app
9+
app.subdir = GreeRemoteGuiQt
10+
app.depends = lib
1311

14-
CONFIG += c++14
15-
16-
# The following define makes your compiler emit warnings if you use
17-
# any feature of Qt which has been marked as deprecated (the exact warnings
18-
# depend on your compiler). Please consult the documentation of the
19-
# deprecated API in order to know how to port your code away from it.
20-
DEFINES += QT_DEPRECATED_WARNINGS
21-
22-
# You can also make your code fail to compile if you use deprecated APIs.
23-
# In order to do so, uncomment the following line.
24-
# You can also select to disable deprecated APIs only up to a certain version of Qt.
25-
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
26-
27-
SOURCES += \
28-
src/main.cpp \
29-
src/mainwindow.cpp \
30-
src/deviceviewmodel.cpp \
31-
src/deviceitem.cpp
32-
33-
HEADERS += \
34-
src/mainwindow.h \
35-
src/deviceviewmodel.h \
36-
src/deviceitem.h
37-
38-
FORMS += \
39-
src/mainwindow.ui
40-
41-
RESOURCES += \
42-
resources/res.qrc
43-
44-
INCLUDEPATH += \
45-
$$PWD/GreeLib/include
46-
47-
LIBS += \
48-
-L$$PWD/lib \
49-
-L$$PWD/3rdparty/cryptopp \
50-
-lcryptopp
51-
52-
CONFIG(debug, debug|release) {
53-
message(Debug build)
54-
55-
DESTDIR = $$PWD/bin
56-
TARGET = $$join(TARGET,,,d)
57-
58-
LIBS += \
59-
-lGreeLibd
60-
} else {
61-
message(Release build)
62-
63-
DESTDIR = $$PWD/bin
64-
65-
LIBS += \
66-
-lGreeLib
67-
}
68-
69-
macx {
70-
message(Building for macOS)
71-
72-
QT += macextras
73-
QMAKE_INFO_PLIST = Info.plist
74-
LIBS += -framework AppKit
75-
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9
76-
77-
SOURCES += \
78-
src/mac/macnativelabel.mm
79-
80-
HEADERS += \
81-
src/mac/macnativelabel.h
82-
}
12+
CONFIG += ordered

GreeRemoteGuiQt/GreeRemoteGuiQt.pro

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#-------------------------------------------------
2+
#
3+
# Project created by QtCreator 2017-09-18T14:29:43
4+
#
5+
#-------------------------------------------------
6+
7+
QT += core gui network
8+
9+
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10+
11+
TARGET = GreeRemote
12+
TEMPLATE = app
13+
14+
CONFIG += c++14
15+
16+
# The following define makes your compiler emit warnings if you use
17+
# any feature of Qt which has been marked as deprecated (the exact warnings
18+
# depend on your compiler). Please consult the documentation of the
19+
# deprecated API in order to know how to port your code away from it.
20+
DEFINES += QT_DEPRECATED_WARNINGS
21+
22+
# You can also make your code fail to compile if you use deprecated APIs.
23+
# In order to do so, uncomment the following line.
24+
# You can also select to disable deprecated APIs only up to a certain version of Qt.
25+
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
26+
27+
SOURCES += \
28+
src/main.cpp \
29+
src/mainwindow.cpp \
30+
src/deviceviewmodel.cpp \
31+
src/deviceitem.cpp
32+
33+
HEADERS += \
34+
src/mainwindow.h \
35+
src/deviceviewmodel.h \
36+
src/deviceitem.h
37+
38+
FORMS += \
39+
src/mainwindow.ui
40+
41+
RESOURCES += \
42+
resources/res.qrc
43+
44+
INCLUDEPATH += \
45+
$$PWD/../GreeLib/include
46+
47+
LIBS += \
48+
-L$$PWD/../lib \
49+
-L$$PWD/../3rdparty/cryptopp \
50+
-lcryptopp
51+
52+
CONFIG(debug, debug|release) {
53+
message(Debug build)
54+
55+
DESTDIR = $$PWD/bin
56+
TARGET = $$join(TARGET,,,d)
57+
58+
LIBS += \
59+
-lGreeLibd
60+
} else {
61+
message(Release build)
62+
63+
DESTDIR = $$PWD/bin
64+
65+
LIBS += \
66+
-lGreeLib
67+
}
68+
69+
macx {
70+
message(Building for macOS)
71+
72+
QT += macextras
73+
QMAKE_INFO_PLIST = Info.plist
74+
LIBS += -framework AppKit
75+
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9
76+
77+
SOURCES += \
78+
src/mac/macnativelabel.mm
79+
80+
HEADERS += \
81+
src/mac/macnativelabel.h
82+
}
File renamed without changes.
1.04 KB
Loading
1.99 KB
Loading
11.7 KB
Loading

GreeRemoteGuiQt/resources/fan-3.png

2.22 KB
Loading
File renamed without changes.

GreeRemoteGuiQt/src/deviceitem.cpp

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#include "deviceitem.h"
2+
#ifdef Q_OS_MAC
3+
#include "mac/macnativelabel.h"
4+
#endif
5+
6+
#include <QEvent>
7+
#include <QDebug>
8+
#include <QGridLayout>
9+
#include <QLabel>
10+
#include <QPushButton>
11+
#include <QSlider>
12+
13+
DeviceItem::DeviceItem(const QPointer<Device> &device, QObject *parent)
14+
: QWidgetAction(parent)
15+
, m_device(device)
16+
{
17+
// installEventFilter(this);
18+
19+
// startTimer(100);
20+
}
21+
22+
QWidget *DeviceItem::createWidget(QWidget *parent)
23+
{
24+
if (m_widget)
25+
return m_widget;
26+
27+
parent->installEventFilter(this);
28+
29+
// auto&& contextMenu = m_trayIcon->contextMenu();
30+
// contextMenu->addSeparator();
31+
32+
// auto&& deviceMenu = new QMenu(contextMenu);
33+
// deviceMenu->setTitle(device->descritptor().name);
34+
// contextMenu->addMenu(deviceMenu);
35+
// deviceMenu->addAction("Power on", []{});
36+
// deviceMenu->addAction("Power off", []{});
37+
38+
m_widget = new QWidget(parent);
39+
auto l = new QVBoxLayout;
40+
41+
l->setSpacing(0);
42+
l->setContentsMargins(20, 0, 20, 0);
43+
44+
m_widget->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
45+
m_widget->setLayout(l);
46+
47+
auto buttonLayout = new QHBoxLayout;
48+
buttonLayout->setContentsMargins(0, 0, 0, 0);
49+
buttonLayout->setSpacing(8);
50+
auto slider = new QSlider(Qt::Horizontal, m_widget);
51+
slider->setMinimum(16);
52+
slider->setMaximum(30);
53+
slider->setMinimumWidth(100);
54+
55+
#ifdef Q_OS_MAC
56+
// We must use a native label (NSTextField) since QLabel's text color doesn't change
57+
// when Dark theme is selected
58+
auto&& label = new MacNativeLabel(m_widget);
59+
#else
60+
auto&& label = new QLabel(m_widget);
61+
#endif
62+
63+
label->setMinimumWidth(30);
64+
connect(slider, &QSlider::valueChanged, [label](int value) {
65+
label->setText(QString{ "%1 C" }.arg(value));
66+
});
67+
68+
buttonLayout->addWidget(slider);
69+
buttonLayout->addWidget(label);
70+
71+
l->addLayout(buttonLayout);
72+
73+
return m_widget;
74+
75+
// auto action = new QWidgetAction(contextMenu);
76+
// action->setDefaultWidget(w);
77+
// m_trayIcon->contextMenu()->addAction(action);
78+
}
79+
80+
bool DeviceItem::event(QEvent* e)
81+
{
82+
qInfo() << "DeviceItem::event:" << e->type();
83+
84+
// if (e->type() == QEvent::Timer)
85+
// m_widget->update();
86+
87+
return QWidgetAction::event(e);
88+
}
89+
90+
bool DeviceItem::eventFilter(QObject* o, QEvent* e)
91+
{
92+
qInfo() << "DeviceItem::eventFilter::event:" << e->type();
93+
94+
return QWidgetAction::eventFilter(o, e);
95+
}

GreeRemoteGuiQt/src/deviceitem.h

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef DEVICEITEM_H
2+
#define DEVICEITEM_H
3+
4+
#include <QPalette>
5+
#include <QPointer>
6+
#include <QWidgetAction>
7+
8+
class Device;
9+
10+
class DeviceItem : public QWidgetAction
11+
{
12+
public:
13+
DeviceItem(const QPointer<Device>& device, QObject* parent = nullptr);
14+
15+
QWidget* createWidget(QWidget* parent) override;
16+
17+
protected:
18+
bool event(QEvent *e) override;
19+
bool eventFilter(QObject* o, QEvent* e) override;
20+
21+
private:
22+
QWidget* m_widget = nullptr;
23+
const QPointer<Device> m_device;
24+
};
25+
26+
#endif // DEVICEITEM_H
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "deviceviewmodel.h"
2+
3+
DeviceViewModel::DeviceViewModel(const QPointer<Device>&, QObject *parent)
4+
: QObject(parent)
5+
{
6+
7+
}

GreeRemoteGuiQt/src/deviceviewmodel.h

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef DEVICEVIEWMODEL_H
2+
#define DEVICEVIEWMODEL_H
3+
4+
#include <QObject>
5+
#include <QPointer>
6+
7+
class Device;
8+
9+
class DeviceViewModel : public QObject
10+
{
11+
Q_OBJECT
12+
13+
public:
14+
DeviceViewModel(const QPointer<Device>& device, QObject *parent = nullptr);
15+
16+
signals:
17+
18+
public slots:
19+
20+
private:
21+
QPointer<Device> m_device;
22+
};
23+
24+
#endif // DEVICEVIEWMODEL_H
File renamed without changes.
File renamed without changes.

src/main.cpp GreeRemoteGuiQt/src/main.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
#include "devicefinder.h"
21
#include "mainwindow.h"
32

3+
#include <devicefinder.h>
4+
45
#include <QApplication>
56
#include <QLoggingCategory>
67
#include <QObject>
@@ -12,9 +13,12 @@ int main(int argc, char *argv[])
1213
{
1314
QApplication a(argc, argv);
1415

16+
a.setAttribute(Qt::AA_EnableHighDpiScaling);
17+
1518
qCInfo(MainLog) << "initializing";
1619

1720
MainWindow w;
21+
// w.show();
1822

1923
DeviceFinder dh;
2024

@@ -23,6 +27,11 @@ int main(int argc, char *argv[])
2327
});
2428
QObject::connect(&w, &MainWindow::scanInitiated, &dh, &DeviceFinder::scan);
2529
QObject::connect(&dh, &DeviceFinder::scanFinshed, &w, &MainWindow::onScanFinished);
30+
QObject::connect(&dh, &DeviceFinder::deviceBound, [&w, &dh](const DeviceDescriptor& descriptor) {
31+
w.addDevice(dh.getDevice(descriptor));
32+
});
33+
34+
dh.scan();
2635

2736
auto exitCode = a.exec();
2837

0 commit comments

Comments
 (0)