Changeset View
Changeset View
Standalone View
Standalone View
faces/SensorFace.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright (C) 2020 Marco Martin <mart@kde.org> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Library General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2 of the License, or (at your option) any later version. | ||||
8 | | ||||
9 | This library is distributed in the hope that it will be useful, | ||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | Library General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU Library General Public License | ||||
15 | along with this library; see the file COPYING.LIB. If not, write to | ||||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
17 | Boston, MA 02110-1301, USA. | ||||
18 | */ | ||||
19 | | ||||
20 | #include "SensorFace_p.h" | ||||
21 | #include "SensorFaceController.h" | ||||
22 | | ||||
23 | #include <QDebug> | ||||
24 | | ||||
25 | using namespace KSysGuard; | ||||
26 | | ||||
27 | class SensorFace::Private { | ||||
28 | public: | ||||
29 | QPointer<QQuickItem> contentItem; | ||||
30 | SensorFaceController *controller = nullptr; | ||||
31 | FormFactor formFactor = Planar; | ||||
32 | }; | ||||
33 | | ||||
34 | SensorFace::SensorFace(QQuickItem *parent) | ||||
35 | : QQuickItem(parent), | ||||
36 | d(std::make_unique<Private>()) | ||||
37 | { | ||||
38 | | ||||
39 | } | ||||
40 | | ||||
41 | SensorFace::~SensorFace() | ||||
42 | { | ||||
43 | } | ||||
44 | | ||||
45 | SensorFaceController *SensorFace::controller() const | ||||
46 | { | ||||
47 | return d->controller; | ||||
48 | } | ||||
49 | | ||||
50 | // Not writable from QML | ||||
51 | void SensorFace::setController(SensorFaceController *controller) | ||||
52 | { | ||||
53 | d->controller = controller; | ||||
54 | } | ||||
55 | | ||||
56 | SensorFace::FormFactor SensorFace::formFactor() const | ||||
57 | { | ||||
58 | return d->formFactor; | ||||
59 | } | ||||
60 | | ||||
61 | void SensorFace::setFormFactor(SensorFace::FormFactor formFactor) | ||||
62 | { | ||||
63 | if (d->formFactor == formFactor) { | ||||
64 | return; | ||||
65 | } | ||||
66 | | ||||
67 | d->formFactor = formFactor; | ||||
68 | emit formFactorChanged(); | ||||
69 | } | ||||
70 | | ||||
71 | QQuickItem * SensorFace::contentItem() const | ||||
72 | { | ||||
73 | return d->contentItem; | ||||
74 | } | ||||
75 | | ||||
76 | void SensorFace::setContentItem(QQuickItem *item) | ||||
77 | { | ||||
78 | if (d->contentItem == item) { | ||||
79 | return; | ||||
80 | } | ||||
81 | d->contentItem = item; | ||||
82 | | ||||
83 | if (d->contentItem) { | ||||
84 | d->contentItem->setParentItem(this); | ||||
85 | d->contentItem->setX(0); | ||||
86 | d->contentItem->setY(0); | ||||
87 | d->contentItem->setSize(size()); | ||||
88 | } | ||||
89 | | ||||
90 | emit contentItemChanged(); | ||||
91 | } | ||||
92 | | ||||
93 | void SensorFace::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) | ||||
94 | { | ||||
95 | if (d->contentItem) { | ||||
96 | d->contentItem->setX(0); | ||||
97 | d->contentItem->setY(0); | ||||
98 | d->contentItem->setSize(newGeometry.size()); | ||||
99 | } | ||||
100 | | ||||
101 | QQuickItem::geometryChanged(newGeometry, oldGeometry); | ||||
102 | } | ||||
103 | | ||||
104 | #include "moc_SensorFace_p.cpp" |