Changeset View
Changeset View
Standalone View
Standalone View
kded/osd.cpp
Show First 20 Lines • Show All 110 Lines • ▼ Show 20 Line(s) | 98 | { | |||
---|---|---|---|---|---|
111 | rootObject->setProperty("itemSource", QStringLiteral("OutputIdentifier.qml")); | 111 | rootObject->setProperty("itemSource", QStringLiteral("OutputIdentifier.qml")); | ||
112 | rootObject->setProperty("modeName", Utils::sizeToString(realSize)); | 112 | rootObject->setProperty("modeName", Utils::sizeToString(realSize)); | ||
113 | rootObject->setProperty("outputName", Utils::outputName(output)); | 113 | rootObject->setProperty("outputName", Utils::outputName(output)); | ||
114 | showOsd(); | 114 | showOsd(); | ||
115 | } | 115 | } | ||
116 | 116 | | |||
117 | void Osd::showActionSelector() | 117 | void Osd::showActionSelector() | ||
118 | { | 118 | { | ||
119 | if (!initOsd()) { | 119 | if (!m_osdActionSelector) { | ||
zzag: Please delete reference. Compilers can eliminate unnecessary copying, so there is no need to do… | |||||
zzag: s/expansion/extension/ | |||||
Good point. I copied this from the original instantiation, will fix both. gladhorn: Good point. I copied this from the original instantiation, will fix both. | |||||
davidedmundson: This will reconnect on the second invocation | |||||
120 | const QString osdPath = QStandardPaths::locate(QStandardPaths::QStandardPaths::GenericDataLocation, QStringLiteral("kded_kscreen/qml/OsdSelector.qml")); | ||||
121 | if (osdPath.isEmpty()) { | ||||
122 | qCWarning(KSCREEN_KDED) << "Failed to find action selector OSD QML file" << osdPath; | ||||
120 | return; | 123 | return; | ||
121 | } | 124 | } | ||
125 | m_osdActionSelector = new KDeclarative::QmlObject(this); | ||||
Should we use QmlObjectSharedEngine here? (could be done separately later) broulik: Should we use `QmlObjectSharedEngine` here? (could be done separately later) | |||||
I think the whole OSD class is constantly being deleted/re-created (after 5 seconds of not being used iirc) so for now this is moot. gladhorn: I think the whole OSD class is constantly being deleted/re-created (after 5 seconds of not… | |||||
126 | m_osdActionSelector->setSource(QUrl::fromLocalFile(osdPath)); | ||||
122 | 127 | | |||
123 | m_outputGeometry = m_output->geometry(); | 128 | if (m_osdActionSelector->status() != QQmlComponent::Ready) { | ||
124 | auto *rootObject = m_osdObject->rootObject(); | 129 | qCWarning(KSCREEN_KDED) << "Failed to load OSD QML file" << osdPath; | ||
125 | rootObject->setProperty("itemSource", QStringLiteral("OsdSelector.qml")); | 130 | delete m_osdActionSelector; | ||
126 | rootObject->setProperty("timeout", 0); | 131 | m_osdActionSelector = nullptr; | ||
127 | rootObject->setProperty("outputOnly", false); | 132 | return; | ||
128 | auto osdItem = rootObject->property("osdItem").value<QObject*>(); | 133 | } | ||
129 | connect(osdItem, SIGNAL(clicked(int)), | | |||
130 | this, SLOT(onOsdActionSelected(int))); | | |||
131 | m_timeout = 0; // no timeout for this one | | |||
132 | 134 | | |||
133 | showOsd(); | 135 | auto *rootObject = m_osdActionSelector->rootObject(); | ||
136 | connect(rootObject, SIGNAL(clicked(int)), | ||||
137 | this, SLOT(onOsdActionSelected(int))); | ||||
138 | } | ||||
139 | Q_ASSERT(m_osdActionSelector); | ||||
This assert can never be hit, you *always* create the object or return early and never end up here broulik: This assert can never be hit, you *always* create the object or return early and never end up… | |||||
gladhorn: That is correct. Do you prefer not to have the assert? | |||||
140 | if (auto *rootObject = m_osdActionSelector->rootObject()) { | ||||
141 | rootObject->setProperty("visible", true); | ||||
142 | } else { | ||||
143 | qCWarning(KSCREEN_KDED) << "Could not get root object for action selector."; | ||||
144 | } | ||||
134 | } | 145 | } | ||
135 | 146 | | |||
136 | void Osd::onOsdActionSelected(int action) | 147 | void Osd::onOsdActionSelected(int action) | ||
137 | { | 148 | { | ||
138 | Q_EMIT osdActionSelected(static_cast<OsdAction::Action>(action)); | 149 | Q_EMIT osdActionSelected(static_cast<OsdAction::Action>(action)); | ||
139 | hideOsd(); | 150 | hideOsd(); | ||
I don't understand how this hideOsd() will work, it only updates m_osdObject which is the other OSD. davidedmundson: I don't understand how this hideOsd() will work, it only updates m_osdObject which is the other… | |||||
Ouch, there you saved me :) osdtest works since it exits, with the real osd through kded it doesn't work at all. gladhorn: Ouch, there you saved me :) osdtest works since it exits, with the real osd through kded it… | |||||
140 | } | 151 | } | ||
141 | 152 | | |||
142 | void Osd::onOutputAvailabilityChanged() | 153 | void Osd::onOutputAvailabilityChanged() | ||
143 | { | 154 | { | ||
144 | if (!m_output || !m_output->isConnected() || !m_output->isEnabled() || !m_output->currentMode()) { | 155 | if (!m_output || !m_output->isConnected() || !m_output->isEnabled() || !m_output->currentMode()) { | ||
145 | hideOsd(); | 156 | hideOsd(); | ||
146 | } | 157 | } | ||
147 | } | 158 | } | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 185 | { | |||
194 | QTimer::singleShot(0, this, &Osd::updatePosition); | 205 | QTimer::singleShot(0, this, &Osd::updatePosition); | ||
195 | if (m_timeout > 0) { | 206 | if (m_timeout > 0) { | ||
196 | m_osdTimer->start(m_timeout); | 207 | m_osdTimer->start(m_timeout); | ||
197 | } | 208 | } | ||
198 | } | 209 | } | ||
199 | 210 | | |||
200 | void Osd::hideOsd() | 211 | void Osd::hideOsd() | ||
201 | { | 212 | { | ||
202 | if (!initOsd()) { | 213 | if (m_osdActionSelector) { | ||
203 | return; | 214 | if (auto *rootObject = m_osdActionSelector->rootObject()) { | ||
215 | rootObject->setProperty("visible", false); | ||||
204 | } | 216 | } | ||
205 | | ||||
206 | auto *rootObject = m_osdObject->rootObject(); | | |||
207 | if (!rootObject) { | | |||
208 | return; | | |||
209 | } | 217 | } | ||
218 | if (m_osdObject) { | ||||
219 | if (auto *rootObject = m_osdObject->rootObject()) { | ||||
210 | rootObject->setProperty("visible", false); | 220 | rootObject->setProperty("visible", false); | ||
211 | } | 221 | } | ||
212 | 222 | } | |||
223 | } |
Please delete reference. Compilers can eliminate unnecessary copying, so there is no need to do the lifetime expansion.