Changeset View
Changeset View
Standalone View
Standalone View
common/control.cpp
Show First 20 Lines • Show All 271 Lines • ▼ Show 20 Line(s) | 258 | { | |||
---|---|---|---|---|---|
272 | // no entry yet, create one | 272 | // no entry yet, create one | ||
273 | auto outputInfo = createOutputInfo(outputId, outputName); | 273 | auto outputInfo = createOutputInfo(outputId, outputName); | ||
274 | outputInfo[QStringLiteral("retention")] = (int)value; | 274 | outputInfo[QStringLiteral("retention")] = (int)value; | ||
275 | 275 | | |||
276 | outputsInfo << outputInfo; | 276 | outputsInfo << outputInfo; | ||
277 | setOutputs(outputsInfo); | 277 | setOutputs(outputsInfo); | ||
278 | } | 278 | } | ||
279 | 279 | | |||
280 | qreal ControlConfig::getScale(const KScreen::OutputPtr &output) const | ||||
281 | { | ||||
282 | return getScale(output->hashMd5(), output->name()); | ||||
283 | } | ||||
284 | | ||||
285 | qreal ControlConfig::getScale(const QString &outputId, const QString &outputName) const | ||||
286 | { | ||||
287 | const auto retention = getOutputRetention(outputId, outputName); | ||||
288 | if (retention == OutputRetention::Individual) { | ||||
289 | const QVariantList outputsInfo = getOutputs(); | ||||
290 | for (const auto variantInfo : outputsInfo) { | ||||
291 | const QVariantMap info = variantInfo.toMap(); | ||||
292 | if (!infoIsOutput(info, outputId, outputName)) { | ||||
293 | continue; | ||||
294 | } | ||||
295 | const auto val = info[QStringLiteral("scale")]; | ||||
296 | return val.canConvert<qreal>() ? val.toReal() : -1; | ||||
297 | } | ||||
298 | } | ||||
299 | // Retention is global or info for output not in config control file. | ||||
300 | if (auto *outputControl = getOutputControl(outputId, outputName)) { | ||||
301 | return outputControl->getScale(); | ||||
302 | } | ||||
303 | | ||||
304 | // Info for output not found. | ||||
305 | return -1; | ||||
306 | } | ||||
307 | | ||||
308 | void ControlConfig::setScale(const KScreen::OutputPtr &output, qreal value) | ||||
309 | { | ||||
310 | setScale(output->hashMd5(), output->name(), value); | ||||
311 | } | ||||
312 | | ||||
313 | // TODO: combine methods (templated functions) | ||||
314 | void ControlConfig::setScale(const QString &outputId, const QString &outputName, qreal value) | ||||
315 | { | ||||
316 | QList<QVariant>::iterator it; | ||||
317 | QVariantList outputsInfo = getOutputs(); | ||||
318 | | ||||
319 | auto setOutputScale = [&outputId, &outputName, value, this]() { | ||||
320 | if (auto *control = getOutputControl(outputId, outputName)) { | ||||
321 | control->setScale(value); | ||||
322 | } | ||||
323 | | ||||
324 | }; | ||||
325 | | ||||
326 | for (it = outputsInfo.begin(); it != outputsInfo.end(); ++it) { | ||||
327 | QVariantMap outputInfo = (*it).toMap(); | ||||
328 | if (!infoIsOutput(outputInfo, outputId, outputName)) { | ||||
329 | continue; | ||||
330 | } | ||||
331 | outputInfo[QStringLiteral("scale")] = value; | ||||
332 | *it = outputInfo; | ||||
333 | setOutputs(outputsInfo); | ||||
334 | setOutputScale(); | ||||
335 | return; | ||||
336 | } | ||||
337 | // no entry yet, create one | ||||
338 | auto outputInfo = createOutputInfo(outputId, outputName); | ||||
339 | outputInfo[QStringLiteral("scale")] = value; | ||||
340 | | ||||
341 | outputsInfo << outputInfo; | ||||
342 | setOutputs(outputsInfo); | ||||
343 | setOutputScale(); | ||||
344 | } | ||||
345 | | ||||
280 | bool ControlConfig::getAutoRotate(const KScreen::OutputPtr &output) const | 346 | bool ControlConfig::getAutoRotate(const KScreen::OutputPtr &output) const | ||
281 | { | 347 | { | ||
282 | return getAutoRotate(output->hashMd5(), output->name()); | 348 | return getAutoRotate(output->hashMd5(), output->name()); | ||
283 | } | 349 | } | ||
284 | 350 | | |||
285 | bool ControlConfig::getAutoRotate(const QString &outputId, const QString &outputName) const | 351 | bool ControlConfig::getAutoRotate(const QString &outputId, const QString &outputName) const | ||
286 | { | 352 | { | ||
287 | const auto retention = getOutputRetention(outputId, outputName); | 353 | const auto retention = getOutputRetention(outputId, outputName); | ||
▲ Show 20 Lines • Show All 172 Lines • ▼ Show 20 Line(s) | |||||
460 | QString ControlOutput::filePath() const | 526 | QString ControlOutput::filePath() const | ||
461 | { | 527 | { | ||
462 | if (!m_output) { | 528 | if (!m_output) { | ||
463 | return QString(); | 529 | return QString(); | ||
464 | } | 530 | } | ||
465 | return filePathFromHash(m_output->hashMd5()); | 531 | return filePathFromHash(m_output->hashMd5()); | ||
466 | } | 532 | } | ||
467 | 533 | | |||
534 | qreal ControlOutput::getScale() const | ||||
535 | { | ||||
536 | const auto val = constInfo()[QStringLiteral("scale")]; | ||||
537 | return val.canConvert<qreal>() ? val.toReal() : -1; | ||||
538 | } | ||||
539 | | ||||
540 | void ControlOutput::setScale(qreal value) | ||||
541 | { | ||||
542 | auto &infoMap = info(); | ||||
543 | if (infoMap.isEmpty()) { | ||||
544 | infoMap = createOutputInfo(m_output->hashMd5(), m_output->name()); | ||||
545 | } | ||||
546 | infoMap[QStringLiteral("scale")] = value; | ||||
547 | } | ||||
548 | | ||||
468 | bool ControlOutput::getAutoRotate() const | 549 | bool ControlOutput::getAutoRotate() const | ||
469 | { | 550 | { | ||
470 | const auto val = constInfo()[QStringLiteral("autorotate")]; | 551 | const auto val = constInfo()[QStringLiteral("autorotate")]; | ||
471 | return !val.canConvert<bool>() || val.toBool(); | 552 | return !val.canConvert<bool>() || val.toBool(); | ||
472 | } | 553 | } | ||
473 | 554 | | |||
474 | void ControlOutput::setAutoRotate(bool value) | 555 | void ControlOutput::setAutoRotate(bool value) | ||
475 | { | 556 | { | ||
476 | auto &infoMap = info(); | 557 | auto &infoMap = info(); | ||
477 | if (infoMap.isEmpty()) { | 558 | if (infoMap.isEmpty()) { | ||
478 | infoMap = createOutputInfo(m_output->hashMd5(), m_output->name()); | 559 | infoMap = createOutputInfo(m_output->hashMd5(), m_output->name()); | ||
479 | } | 560 | } | ||
480 | infoMap[QStringLiteral("autorotate")] = value; | 561 | infoMap[QStringLiteral("autorotate")] = value; | ||
481 | } | 562 | } |