Changeset View
Changeset View
Standalone View
Standalone View
src/Gui/SettingsDialog/BackendOptionsPage.cpp
- This file was added.
1 | #include "BackendOptionsPage.h" | ||||
---|---|---|---|---|---|
2 | | ||||
3 | #include "BackendInterfaces/ScreenshotInterface.h" | ||||
4 | #include "SpectacleConfig.h" | ||||
5 | | ||||
6 | #include <KLocalizedString> | ||||
7 | #include <KTitleWidget> | ||||
8 | | ||||
9 | #include <QApplication> | ||||
10 | #include <QGraphicsDropShadowEffect> | ||||
11 | #include <QLabel> | ||||
12 | #include <QString> | ||||
13 | #include <QPushButton> | ||||
14 | | ||||
15 | BackendOptionsPage::BackendOptionsPage(QWidget *parent) | ||||
16 | : SettingsPage {parent}, | ||||
17 | layout {new QVBoxLayout {}}, | ||||
18 | activateButtonGroup {new QButtonGroup {this}} | ||||
19 | { | ||||
20 | KTitleWidget* screenshotBackendLabel = new KTitleWidget {}; | ||||
21 | screenshotBackendLabel->setText(i18n("Screenshot Backend")); | ||||
22 | screenshotBackendLabel->setLevel(2); | ||||
23 | layout->addWidget(screenshotBackendLabel); | ||||
24 | | ||||
25 | initalizeModel(); | ||||
26 | setScreenshotViewLayout(); | ||||
27 | | ||||
28 | layout->addStretch(); | ||||
29 | | ||||
30 | setLayout(layout); | ||||
31 | } | ||||
32 | | ||||
33 | void BackendOptionsPage::initalizeModel() | ||||
34 | { | ||||
35 | QJsonValue backendName; | ||||
36 | QJsonArray backendPlatforms; | ||||
37 | PluginState pluginState; | ||||
38 | | ||||
39 | auto spectacleConfig = SpectacleConfig::instance(); | ||||
40 | | ||||
41 | for(const auto& screenshotPlugin: spectacleConfig->screenshotPlugins()) { | ||||
42 | backendName = screenshotPlugin.metaData[QStringLiteral("Name")]; | ||||
43 | backendPlatforms = screenshotPlugin.metaData[QStringLiteral("Platforms")].toArray(); | ||||
44 | | ||||
45 | auto platformIt = std::find(backendPlatforms.begin(), backendPlatforms.end(), QJsonValue(spectacleConfig->platform())); | ||||
46 | | ||||
47 | if(platformIt == backendPlatforms.end()) { | ||||
48 | pluginState = PluginState::Disabled; | ||||
49 | } else { | ||||
50 | if(screenshotPlugin.backend) { | ||||
51 | pluginState = PluginState::InUse; | ||||
52 | } else { | ||||
53 | pluginState = PluginState::NotInUse; | ||||
54 | } | ||||
55 | } | ||||
56 | | ||||
57 | model.push_back(std::make_tuple(backendName, backendPlatforms, pluginState)); | ||||
58 | } | ||||
59 | } | ||||
60 | | ||||
61 | void BackendOptionsPage::setScreenshotViewLayout() | ||||
62 | { | ||||
63 | QVBoxLayout* screenshotView = new QVBoxLayout {}; | ||||
64 | screenshotView->setSpacing(10); | ||||
65 | | ||||
66 | for(size_t i = 0; i < model.size(); ++i) { | ||||
67 | QWidget* rowWidget = new QWidget {}; | ||||
68 | QHBoxLayout* rowWidgetLayout = new QHBoxLayout {}; | ||||
69 | rowWidget->setLayout(rowWidgetLayout); | ||||
70 | | ||||
71 | QPalette pal = QApplication::palette(); | ||||
72 | pal.setColor(QPalette::Background, pal.color(QPalette::Mid)); | ||||
73 | rowWidget->setAutoFillBackground(true); | ||||
74 | rowWidget->setPalette(pal); | ||||
75 | | ||||
76 | QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect; | ||||
77 | effect->setXOffset(3); | ||||
78 | effect->setYOffset(3); | ||||
79 | effect->setColor(pal.color(QPalette::Dark)); | ||||
80 | rowWidget->setGraphicsEffect(effect); | ||||
81 | | ||||
82 | QLabel* backendName = new QLabel { std::get<0>(model[i]).toString() }; | ||||
83 | | ||||
84 | QString backendList; | ||||
85 | for(const QJsonValue& value: std::get<1>(model[i])) { | ||||
86 | backendList += value.toString(); | ||||
87 | backendList += QStringLiteral(","); | ||||
88 | } | ||||
89 | backendList.remove(backendList.size() - 1, 1); | ||||
90 | QLabel *backendPlatform = new QLabel { backendList }; | ||||
91 | | ||||
92 | QPushButton* activateButton = new QPushButton {}; | ||||
93 | activateButton->setCheckable(true); | ||||
94 | activateButton->setFocusPolicy(Qt::NoFocus); | ||||
95 | activateButton->setProperty("pluginName", std::get<0>(model[i])); | ||||
96 | | ||||
97 | activateButtonGroup->addButton(activateButton); | ||||
98 | connect(activateButtonGroup, QOverload<QAbstractButton*, bool>::of(&QButtonGroup::buttonToggled), [=](QAbstractButton *button, bool checked) { | ||||
99 | if(checked) { | ||||
100 | std::get<2>(model[i]) = PluginState::InUse; | ||||
101 | button->setText(QStringLiteral("In Use")); | ||||
102 | } else { | ||||
103 | std::get<2>(model[i]) = PluginState::NotInUse; | ||||
104 | button->setText(QStringLiteral("Activate")); | ||||
105 | } | ||||
106 | }); | ||||
107 | | ||||
108 | switch(std::get<2>(model[i])) { | ||||
109 | case PluginState::InUse: activateButton->setText(QStringLiteral("In Use")); activateButton->setChecked(true); break; | ||||
110 | case PluginState::NotInUse: activateButton->setText(QStringLiteral("Activate")); break; | ||||
111 | case PluginState::Disabled: activateButton->setText(QStringLiteral("Activate")); activateButton->setEnabled(false); break; | ||||
112 | } | ||||
113 | | ||||
114 | rowWidgetLayout->addWidget(backendName); | ||||
115 | rowWidgetLayout->addStretch(); | ||||
116 | rowWidgetLayout->addWidget(backendPlatform); | ||||
117 | rowWidgetLayout->addStretch(); | ||||
118 | rowWidgetLayout->addWidget(activateButton); | ||||
119 | | ||||
120 | screenshotView->addWidget(rowWidget); | ||||
121 | } | ||||
122 | | ||||
123 | layout->addLayout(screenshotView); | ||||
124 | } | ||||
125 | | ||||
126 | void BackendOptionsPage::saveChanges() | ||||
127 | { | ||||
128 | auto spectacleConfig = SpectacleConfig::instance(); | ||||
129 | | ||||
130 | if(!activateButtonGroup->checkedButton()) { | ||||
131 | return; | ||||
132 | } | ||||
133 | | ||||
134 | spectacleConfig->findScreenshotBackend(activateButtonGroup->checkedButton()->property("pluginName").toString()); | ||||
135 | } | ||||
136 | | ||||
137 | void BackendOptionsPage::resetChanges() | ||||
138 | { | ||||
139 | //Not sure yet | ||||
140 | } | ||||
141 | No newline at end of file |