Changeset View
Changeset View
Standalone View
Standalone View
kcm/output_identifier.cpp
Show All 18 Lines | |||||
19 | #include "../common/utils.h" | 19 | #include "../common/utils.h" | ||
20 | 20 | | |||
21 | #include <kscreen/output.h> | 21 | #include <kscreen/output.h> | ||
22 | 22 | | |||
23 | #include <QStandardPaths> | 23 | #include <QStandardPaths> | ||
24 | #include <QTimer> | 24 | #include <QTimer> | ||
25 | #include <QQuickItem> | 25 | #include <QQuickItem> | ||
26 | #include <QQuickView> | 26 | #include <QQuickView> | ||
27 | #include <PlasmaQuick/Dialog> | ||||
28 | #include <KDeclarative/kdeclarative/qmlobject.h> | ||||
romangg: Lexicographical order. Also add an empty line to differentiate include groups:
```
#include… | |||||
27 | 29 | | |||
28 | #define QML_PATH "kpackage/kcms/kcm_kscreen/contents/ui/" | 30 | #define QML_PATH "kpackage/kcms/kcm_kscreen/contents/ui/" | ||
29 | 31 | | |||
30 | OutputIdentifier::OutputIdentifier(KScreen::ConfigPtr config, QObject *parent) | 32 | OutputIdentifier::OutputIdentifier(KScreen::ConfigPtr config, QObject *parent) | ||
31 | : QObject(parent) | 33 | : QObject(parent) | ||
32 | { | 34 | { | ||
33 | 35 | | |||
34 | const QString qmlPath = | 36 | const QString qmlPath = | ||
35 | QStandardPaths::locate(QStandardPaths::GenericDataLocation, | 37 | QStandardPaths::locate(QStandardPaths::GenericDataLocation, | ||
36 | QStringLiteral(QML_PATH | 38 | QStringLiteral(QML_PATH | ||
37 | "OutputIdentifier.qml")); | 39 | "OutputIdentifier.qml")); | ||
38 | 40 | | |||
39 | for (const auto &output : config->connectedOutputs()) { | 41 | for (const auto &output : config->connectedOutputs()) { | ||
40 | if (!output->currentMode()) { | 42 | if (!output->currentMode()) { | ||
41 | continue; | 43 | continue; | ||
42 | } | 44 | } | ||
43 | 45 | | |||
44 | const KScreen::ModePtr mode = output->currentMode(); | 46 | const KScreen::ModePtr mode = output->currentMode(); | ||
45 | 47 | auto *view = new PlasmaQuick::Dialog(); | |||
46 | auto *view = new QQuickView(); | | |||
47 | 48 | | |||
48 | view->setFlags(Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint); | 49 | view->setFlags(Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint); | ||
49 | view->setResizeMode(QQuickView::SizeViewToRootObject); | 50 | auto qmlObject = new KDeclarative::QmlObject(this); | ||
50 | view->setSource(QUrl::fromLocalFile(qmlPath)); | 51 | qmlObject->setSource(QUrl::fromLocalFile(qmlPath)); | ||
52 | qmlObject->completeInitialization(); | ||||
53 | auto rootObj = qobject_cast<QQuickItem *>(qmlObject->rootObject()); | ||||
54 | view->setMainItem(rootObj); | ||||
romangg: This part could use some empty lines. | |||||
51 | view->installEventFilter(this); | 55 | view->installEventFilter(this); | ||
52 | 56 | | |||
53 | QQuickItem *rootObj = view->rootObject(); | | |||
54 | if (!rootObj) { | 57 | if (!rootObj) { | ||
55 | continue; | 58 | continue; | ||
davidedmundson: Not part of your change, but we would leak view here. | |||||
anthonyfieroni: view leaks, no? I see it's not a problem in this patch. | |||||
56 | } | 59 | } | ||
57 | 60 | | |||
58 | QSize deviceSize, logicalSize; | 61 | QSize deviceSize, logicalSize; | ||
59 | if (output->isHorizontal()) { | 62 | if (output->isHorizontal()) { | ||
60 | deviceSize = mode->size(); | 63 | deviceSize = mode->size(); | ||
61 | } else { | 64 | } else { | ||
62 | deviceSize = QSize(mode->size().height(), mode->size().width()); | 65 | deviceSize = QSize(mode->size().height(), mode->size().width()); | ||
63 | } | 66 | } | ||
64 | if (config->supportedFeatures() & KScreen::Config::Feature::PerOutputScaling) { | 67 | if (config->supportedFeatures() & KScreen::Config::Feature::PerOutputScaling) { | ||
65 | // no scale adjustment needed on Wayland | 68 | // no scale adjustment needed on Wayland, we use logicalSize | ||
66 | logicalSize = deviceSize; | 69 | logicalSize = output->logicalSize().toSize(); | ||
romangg: When you're at it correct the grammar. | |||||
romangg: You wanted to add a `.` but it became a `"` | |||||
67 | } else { | 70 | } else { | ||
68 | logicalSize = deviceSize / view->effectiveDevicePixelRatio(); | 71 | logicalSize = deviceSize / view->effectiveDevicePixelRatio(); | ||
69 | } | 72 | } | ||
70 | | ||||
71 | rootObj->setProperty("outputName", Utils::outputName(output)); | 73 | rootObj->setProperty("outputName", Utils::outputName(output)); | ||
72 | rootObj->setProperty("modeName", Utils::sizeToString(deviceSize)); | 74 | rootObj->setProperty("modeName", Utils::sizeToString(deviceSize)); | ||
73 | view->setProperty("screenSize", QRect(output->pos(), logicalSize)); | 75 | view->setProperty("screenSize", QRect(output->pos(), logicalSize)); | ||
74 | m_views << view; | 76 | m_views << view; | ||
75 | } | 77 | } | ||
76 | 78 | | |||
77 | for (auto *view : m_views) { | 79 | for (auto *view : m_views) { | ||
78 | view->show(); | 80 | view->show(); | ||
79 | } | 81 | } | ||
80 | QTimer::singleShot(2500, this, &OutputIdentifier::identifiersFinished); | 82 | QTimer::singleShot(2500, this, &OutputIdentifier::identifiersFinished); | ||
81 | } | 83 | } | ||
82 | 84 | | |||
83 | OutputIdentifier::~OutputIdentifier() | 85 | OutputIdentifier::~OutputIdentifier() | ||
84 | { | 86 | { | ||
85 | qDeleteAll(m_views); | 87 | qDeleteAll(m_views); | ||
86 | } | 88 | } | ||
87 | 89 | | |||
88 | bool OutputIdentifier::eventFilter(QObject* object, QEvent* event) | 90 | bool OutputIdentifier::eventFilter(QObject* object, QEvent* event) | ||
89 | { | 91 | { | ||
90 | if (event->type() == QEvent::Resize) { | 92 | if (event->type() == QEvent::Resize) { | ||
91 | if (m_views.contains(qobject_cast<QQuickView*>(object))) { | 93 | if (m_views.contains(qobject_cast<PlasmaQuick::Dialog*>(object))) { | ||
92 | QResizeEvent *e = static_cast<QResizeEvent*>(event); | 94 | QResizeEvent *e = static_cast<QResizeEvent*>(event); | ||
93 | const QRect screenSize = object->property("screenSize").toRect(); | 95 | const QRect screenSize = object->property("screenSize").toRect(); | ||
94 | QRect geometry(QPoint(0, 0), e->size()); | 96 | QRect geometry(QPoint(0, 0), e->size()); | ||
95 | geometry.moveCenter(screenSize.center()); | 97 | geometry.moveCenter(screenSize.center()); | ||
96 | static_cast<QQuickView*>(object)->setGeometry(geometry); | 98 | static_cast<PlasmaQuick::Dialog*>(object)->setGeometry(geometry); | ||
97 | } | 99 | } | ||
98 | } | 100 | } | ||
99 | return QObject::eventFilter(object, event); | 101 | return QObject::eventFilter(object, event); | ||
100 | } | 102 | } |
Lexicographical order. Also add an empty line to differentiate include groups: