Make use of the proposed new KColorScheme API

Make use of new API proposed in frameworks/kcolorscheme!12
This commit is contained in:
James Graham
2024-09-01 14:17:41 +00:00
parent cbc2e65856
commit 05a2f03c18
6 changed files with 7 additions and 41 deletions

View File

@@ -14,7 +14,7 @@ set(RELEASE_SERVICE_VERSION "${RELEASE_SERVICE_VERSION_MAJOR}.${RELEASE_SERVICE_
project(NeoChat VERSION ${RELEASE_SERVICE_VERSION})
set(KF_MIN_VERSION "6.4")
set(KF_MIN_VERSION "6.6")
set(QT_MIN_VERSION "6.5")
find_package(ECM ${KF_MIN_VERSION} REQUIRED NO_MODULE)

View File

@@ -26,23 +26,9 @@ void ColorSchemer::apply(int idx)
c->activateScheme(c->model()->index(idx, 0));
}
void ColorSchemer::apply(const QString &name)
int ColorSchemer::indexForCurrentScheme()
{
c->activateScheme(c->indexForScheme(name));
}
int ColorSchemer::indexForScheme(const QString &name) const
{
auto index = c->indexForScheme(name).row();
if (index == -1) {
index = 0;
}
return index;
}
QString ColorSchemer::nameForIndex(int index) const
{
return c->model()->data(c->model()->index(index, 0), Qt::DisplayRole).toString();
return c->indexForSchemeId(c->activeSchemeId()).row();
}
#include "moc_colorschemer.cpp"

View File

@@ -44,21 +44,11 @@ public:
Q_INVOKABLE void apply(int idx);
/**
* @brief Activates the KColorScheme with the given name.
* @brief Get the row for the current color scheme.
*
* @sa KColorScheme
*/
Q_INVOKABLE void apply(const QString &name);
/**
* @brief Returns the index for the scheme with the given name.
*/
Q_INVOKABLE int indexForScheme(const QString &name) const;
/**
* @brief Returns the name for the scheme with the given index.
*/
Q_INVOKABLE QString nameForIndex(int index) const;
Q_INVOKABLE int indexForCurrentScheme();
private:
KColorSchemeManager *c;

View File

@@ -185,9 +185,6 @@ int main(int argc, char *argv[])
#endif
ColorSchemer colorScheme;
if (!NeoChatConfig::self()->colorScheme().isEmpty()) {
colorScheme.apply(NeoChatConfig::self()->colorScheme());
}
QCommandLineParser parser;
parser.setApplicationDescription(i18n("Client for the matrix communication protocol"));

View File

@@ -15,9 +15,6 @@
<entry name="OpenRoom" type="String">
<label>Latest opened room</label>
</entry>
<entry name="ColorScheme" type="String">
<label>Color scheme</label>
</entry>
<entry name="Blur" type="bool">
<label>Make NeoChat blurry</label>
<default>false</default>

View File

@@ -15,10 +15,6 @@ FormCard.FormComboBoxDelegate {
textRole: "display"
valueRole: "display"
model: ColorSchemer.model
Component.onCompleted: currentIndex = ColorSchemer.indexForScheme(NeoChatConfig.colorScheme)
onCurrentValueChanged: {
ColorSchemer.apply(currentIndex);
NeoChatConfig.colorScheme = ColorSchemer.nameForIndex(currentIndex);
NeoChatConfig.save();
}
Component.onCompleted: currentIndex = ColorSchemer.indexForCurrentScheme()
onCurrentValueChanged: ColorSchemer.apply(currentIndex);
}