Changeset View
Changeset View
Standalone View
Standalone View
src/kcolorschememanager.cpp
Show First 20 Lines • Show All 160 Lines • ▼ Show 20 Line(s) | 155 | { | |||
---|---|---|---|---|---|
161 | } | 161 | } | ||
162 | return QModelIndex(); | 162 | return QModelIndex(); | ||
163 | } | 163 | } | ||
164 | 164 | | |||
165 | KActionMenu *KColorSchemeManager::createSchemeSelectionMenu(const QIcon &icon, const QString &name, const QString &selectedSchemeName, QObject *parent) | 165 | KActionMenu *KColorSchemeManager::createSchemeSelectionMenu(const QIcon &icon, const QString &name, const QString &selectedSchemeName, QObject *parent) | ||
166 | { | 166 | { | ||
167 | KActionMenu *menu = new KActionMenu(icon, name, parent); | 167 | KActionMenu *menu = new KActionMenu(icon, name, parent); | ||
168 | QActionGroup *group = new QActionGroup(menu); | 168 | QActionGroup *group = new QActionGroup(menu); | ||
169 | connect(group, &QActionGroup::triggered, [](QAction * action) { | 169 | connect(group, &QActionGroup::triggered,this, [this](QAction * action) { | ||
170 | // hint for the style to synchronize the color scheme with the window manager/compositor | 170 | // hint for the style to synchronize the color scheme with the window manager/compositor | ||
171 | qApp->setProperty("KDE_COLOR_SCHEME_PATH", action->data()); | 171 | activateScheme(d->model->index(action->data().toInt())); | ||
172 | qApp->setPalette(KColorScheme::createApplicationPalette(KSharedConfig::openConfig(action->data().toString()))); | | |||
173 | }); | 172 | }); | ||
174 | for (int i = 0; i < d->model->rowCount(); ++i) { | 173 | for (int i = 0; i < d->model->rowCount(); ++i) { | ||
175 | QModelIndex index = d->model->index(i); | 174 | QModelIndex index = d->model->index(i); | ||
176 | QAction *action = new QAction(index.data(Qt::DisplayRole).toString(), menu); | 175 | QAction *action = new QAction(index.data(Qt::DisplayRole).toString(), menu); | ||
177 | action->setData(index.data(Qt::UserRole)); | 176 | action->setData(index.row()); | ||
178 | action->setActionGroup(group); | 177 | action->setActionGroup(group); | ||
179 | action->setCheckable(true); | 178 | action->setCheckable(true); | ||
180 | if (index.data().toString() == selectedSchemeName) { | 179 | if (index.data().toString() == selectedSchemeName) { | ||
181 | action->setChecked(true); | 180 | action->setChecked(true); | ||
182 | } | 181 | } | ||
183 | menu->addAction(action); | 182 | menu->addAction(action); | ||
184 | } | 183 | } | ||
185 | 184 | | |||
186 | connect(menu->menu(), &QMenu::aboutToShow, group, [this, group] { | 185 | connect(menu->menu(), &QMenu::aboutToShow, group, [this, group] { | ||
187 | const auto actions = group->actions(); | 186 | const auto actions = group->actions(); | ||
188 | for (QAction *action : actions) { | 187 | for (QAction *action : actions) { | ||
189 | if (action->icon().isNull()) { | 188 | if (action->icon().isNull()) { | ||
190 | action->setIcon(d->model->createPreview(action->data().toString())); | 189 | action->setIcon(d->model->createPreview(d->model->index(action->data().toInt()).data(Qt::UserRole).toString())); | ||
191 | } | 190 | } | ||
192 | } | 191 | } | ||
193 | }); | 192 | }); | ||
194 | 193 | | |||
195 | return menu; | 194 | return menu; | ||
196 | } | 195 | } | ||
197 | 196 | | |||
198 | KActionMenu *KColorSchemeManager::createSchemeSelectionMenu(const QString &text, const QString &selectedSchemeName, QObject *parent) | 197 | KActionMenu *KColorSchemeManager::createSchemeSelectionMenu(const QString &text, const QString &selectedSchemeName, QObject *parent) | ||
Show All 9 Lines | |||||
208 | void KColorSchemeManager::activateScheme(const QModelIndex &index) | 207 | void KColorSchemeManager::activateScheme(const QModelIndex &index) | ||
209 | { | 208 | { | ||
210 | if (!index.isValid()) { | 209 | if (!index.isValid()) { | ||
211 | return; | 210 | return; | ||
212 | } | 211 | } | ||
213 | if (index.model() != d->model.data()) { | 212 | if (index.model() != d->model.data()) { | ||
214 | return; | 213 | return; | ||
215 | } | 214 | } | ||
215 | disconnect(qApp, &QApplication::paletteChanged, this, nullptr); | ||||
216 | d->activeSchemeIndex = index.row(); | ||||
216 | // hint for the style to synchronize the color scheme with the window manager/compositor | 217 | // hint for the style to synchronize the color scheme with the window manager/compositor | ||
217 | qApp->setProperty("KDE_COLOR_SCHEME_PATH", index.data(Qt::UserRole)); | 218 | qApp->setProperty("KDE_COLOR_SCHEME_PATH", index.data(Qt::UserRole)); | ||
218 | qApp->setPalette(KColorScheme::createApplicationPalette(KSharedConfig::openConfig(index.data(Qt::UserRole).toString()))); | 219 | qApp->setPalette(KColorScheme::createApplicationPalette(KSharedConfig::openConfig(index.data(Qt::UserRole).toString()))); | ||
220 | connect(qApp, &QApplication::paletteChanged, this, [this] { | ||||
221 | activateScheme(d->model->index(d->activeSchemeIndex)); | ||||
222 | }); | ||||
219 | } | 223 | } |