Changeset View
Changeset View
Standalone View
Standalone View
kcm/src/widget.cpp
Show All 13 Lines | |||||
14 | * You should have received a copy of the GNU General Public License along | 14 | * You should have received a copy of the GNU General Public License along | ||
15 | * with this program; if not, write to the Free Software Foundation, Inc., | 15 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
17 | * | 17 | * | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "widget.h" | 20 | #include "widget.h" | ||
21 | #include "controlpanel.h" | 21 | #include "controlpanel.h" | ||
22 | #ifdef WITH_PROFILES | | |||
23 | #include "profilesmodel.h" | | |||
24 | #endif | | |||
25 | 22 | | |||
26 | #include <QVBoxLayout> | 23 | #include <QVBoxLayout> | ||
27 | #include <QSplitter> | 24 | #include <QSplitter> | ||
28 | #include <QLabel> | 25 | #include <QLabel> | ||
29 | #include <QTimer> | 26 | #include <QTimer> | ||
30 | #include <QtGlobal> | 27 | #include <QtGlobal> | ||
31 | 28 | | |||
32 | #include "declarative/qmloutput.h" | 29 | #include "declarative/qmloutput.h" | ||
Show All 26 Lines | |||||
59 | { | 56 | { | ||
60 | qRegisterMetaType<QQuickView*>(); | 57 | qRegisterMetaType<QQuickView*>(); | ||
61 | 58 | | |||
62 | ui->setupUi(this); | 59 | ui->setupUi(this); | ||
63 | ui->quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView); | 60 | ui->quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView); | ||
64 | connect(ui->primaryCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), | 61 | connect(ui->primaryCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), | ||
65 | this, &Widget::primaryOutputSelected); | 62 | this, &Widget::primaryOutputSelected); | ||
66 | 63 | | |||
67 | #ifdef WITH_PROFILES | | |||
68 | mProfilesModel = new ProfilesModel(this); | | |||
69 | | ||||
70 | connect(mProfilesModel, &ProfilesModel::modelUpdated()), | | |||
71 | this, &Widget::slotProfilesUpdated); | | |||
72 | mProfilesCombo = new QComboBox(this); | | |||
73 | mProfilesCombo->setModel(mProfilesModel); | | |||
74 | mProfilesCombo->setSizeAdjustPolicy(QComboBox::AdjustToContents); | | |||
75 | hbox->addWidget(new QLabel(i18n("Active profile"))); | | |||
76 | hbox->addWidget(mProfilesCombo); | | |||
77 | #endif | | |||
78 | | ||||
79 | mControlPanel = new ControlPanel(this); | 64 | mControlPanel = new ControlPanel(this); | ||
80 | connect(mControlPanel, &ControlPanel::changed, | 65 | connect(mControlPanel, &ControlPanel::changed, | ||
81 | this, &Widget::changed); | 66 | this, &Widget::changed); | ||
82 | ui->controlPanelLayout->addWidget(mControlPanel); | 67 | ui->controlPanelLayout->addWidget(mControlPanel); | ||
83 | 68 | | |||
84 | connect(ui->unifyButton, &QPushButton::released, | 69 | connect(ui->unifyButton, &QPushButton::released, | ||
85 | [this]{ | 70 | [this]{ | ||
86 | slotUnifyOutputs(); | 71 | slotUnifyOutputs(); | ||
▲ Show 20 Lines • Show All 231 Lines • ▼ Show 20 Line(s) | 267 | } else { | |||
318 | ui->primaryCombo->setEnabled(false); | 303 | ui->primaryCombo->setEnabled(false); | ||
319 | mControlPanel->setUnifiedOutput(base->outputPtr()); | 304 | mControlPanel->setUnifiedOutput(base->outputPtr()); | ||
320 | ui->unifyButton->setText(i18n("Break Unified Outputs")); | 305 | ui->unifyButton->setText(i18n("Break Unified Outputs")); | ||
321 | } | 306 | } | ||
322 | 307 | | |||
323 | Q_EMIT changed(); | 308 | Q_EMIT changed(); | ||
324 | } | 309 | } | ||
325 | 310 | | |||
326 | void Widget::slotProfileChanged(int index) | | |||
327 | { | | |||
328 | #ifdef WITH_PROFILES | | |||
329 | const QVariantMap profile = mProfilesCombo->itemData(index, ProfilesModel::ProfileRole).toMap(); | | |||
330 | const QVariantList outputs = profile[QLatin1String("outputs")].toList(); | | |||
331 | | ||||
332 | // FIXME: Copy-pasted from KDED's Serializer::config() | | |||
333 | KScreen::Config *config = KScreen::Config::current(); | | |||
334 | KScreen::OutputList outputList = config->outputs(); | | |||
335 | for (KScreen::Output: output, outputList) { | | |||
336 | if (!output->isConnected() && output->isEnabled()) { | | |||
337 | output->setEnabled(false); | | |||
338 | } | | |||
339 | } | | |||
340 | | ||||
341 | KScreen::Config *outputsConfig = config->clone(); | | |||
342 | Q_FOREACH(const QVariant & info, outputs) { | | |||
343 | KScreen::Output *output = findOutput(outputsConfig, info.toMap()); | | |||
344 | if (!output) { | | |||
345 | continue; | | |||
346 | } | | |||
347 | | ||||
348 | delete outputList.take(output->id()); | | |||
349 | outputList.insert(output->id(), output); | | |||
350 | } | | |||
351 | | ||||
352 | config->setOutputs(outputList); | | |||
353 | | ||||
354 | setConfig(config); | | |||
355 | #else | | |||
356 | Q_UNUSED(index) | | |||
357 | #endif | | |||
358 | } | | |||
359 | | ||||
360 | // FIXME: Copy-pasted from KDED's Serializer::findOutput() | 311 | // FIXME: Copy-pasted from KDED's Serializer::findOutput() | ||
361 | KScreen::OutputPtr Widget::findOutput(const KScreen::ConfigPtr &config, const QVariantMap &info) | 312 | KScreen::OutputPtr Widget::findOutput(const KScreen::ConfigPtr &config, const QVariantMap &info) | ||
362 | { | 313 | { | ||
363 | KScreen::OutputList outputs = config->outputs(); | 314 | KScreen::OutputList outputs = config->outputs(); | ||
364 | Q_FOREACH(const KScreen::OutputPtr &output, outputs) { | 315 | Q_FOREACH(const KScreen::OutputPtr &output, outputs) { | ||
365 | if (!output->isConnected()) { | 316 | if (!output->isConnected()) { | ||
366 | continue; | 317 | continue; | ||
367 | } | 318 | } | ||
Show All 27 Lines | 337 | Q_FOREACH(const KScreen::ModePtr &mode, modes) { | |||
395 | break; | 346 | break; | ||
396 | } | 347 | } | ||
397 | return output; | 348 | return output; | ||
398 | } | 349 | } | ||
399 | 350 | | |||
400 | return KScreen::OutputPtr(); | 351 | return KScreen::OutputPtr(); | ||
401 | } | 352 | } | ||
402 | 353 | | |||
403 | void Widget::slotProfilesAboutToUpdate() | | |||
404 | { | | |||
405 | #ifdef WITH_PROFILES | | |||
406 | disconnect(mProfilesCombo, &QComboBox::currentIndexChanged, | | |||
407 | this, &Widget::slotProfileChanged); | | |||
408 | #endif | | |||
409 | } | | |||
410 | | ||||
411 | void Widget::slotProfilesUpdated() | | |||
412 | { | | |||
413 | #ifdef WITH_PROFILES | | |||
414 | connect(mProfilesCombo, &QComboBox::currentIndexChanged, | | |||
415 | this, &Widget::slotProfileChanged); | | |||
416 | | ||||
417 | const int index = mProfilesModel->activeProfileIndex(); | | |||
418 | mProfilesCombo->setCurrentIndex(index); | | |||
419 | #endif | | |||
420 | } | | |||
421 | | ||||
422 | | ||||
423 | void Widget::clearOutputIdentifiers() | 354 | void Widget::clearOutputIdentifiers() | ||
424 | { | 355 | { | ||
425 | mOutputTimer->stop(); | 356 | mOutputTimer->stop(); | ||
426 | qDeleteAll(mOutputIdentifiers); | 357 | qDeleteAll(mOutputIdentifiers); | ||
427 | mOutputIdentifiers.clear(); | 358 | mOutputIdentifiers.clear(); | ||
428 | } | 359 | } | ||
429 | 360 | | |||
430 | void Widget::outputAdded(const KScreen::OutputPtr &output) | 361 | void Widget::outputAdded(const KScreen::OutputPtr &output) | ||
▲ Show 20 Lines • Show All 124 Lines • Show Last 20 Lines |