Draft: Big overhaul of the settings

This commit is contained in:
Carl Schwan
2021-06-04 23:46:31 +02:00
parent d9eaa95b9d
commit 23bd73c499
11 changed files with 467 additions and 69 deletions

View File

@@ -43,7 +43,9 @@ ecm_add_app_icon(NEOCHAT_ICON ICONS ${CMAKE_SOURCE_DIR}/128-logo.png)
target_sources(neochat PRIVATE ${NEOCHAT_ICON})
if(NOT ANDROID)
target_sources(neochat PRIVATE trayicon.cpp)
target_sources(neochat PRIVATE trayicon.cpp colorschemer.cpp)
target_link_libraries(neochat PRIVATE KF5::ConfigWidgets)
target_compile_definitions(neochat PRIVATE -DHAVE_COLORSCHEME)
endif()
target_include_directories(neochat PRIVATE ${CMAKE_BINARY_DIR})

39
src/colorschemer.cpp Normal file
View File

@@ -0,0 +1,39 @@
#include <KColorSchemeManager>
#include <QAbstractItemModel>
#include "colorschemer.h"
ColorSchemer::ColorSchemer(QObject* parent)
: QObject(parent)
, c(new KColorSchemeManager(this))
{
}
ColorSchemer::~ColorSchemer()
{
}
QAbstractItemModel *ColorSchemer::model() const
{
return c->model();
}
void ColorSchemer::apply(int idx)
{
c->activateScheme(c->model()->index(idx, 0));
}
void ColorSchemer::apply(const QString &name)
{
c->activateScheme(c->indexForScheme(name));
}
int ColorSchemer::indexForScheme(const QString &name) const
{
return c->indexForScheme(name).row();
}
QString ColorSchemer::nameForIndex(int index) const
{
return c->model()->data(c->model()->index(index, 0), Qt::DisplayRole).toString();
}

26
src/colorschemer.h Normal file
View File

@@ -0,0 +1,26 @@
#pragma once
#include <QObject>
#include <QIdentityProxyModel>
class QAbstractItemModel;
class KColorSchemeManager;
class ColorSchemer : public QObject
{
Q_OBJECT
Q_PROPERTY(QAbstractItemModel *model READ model CONSTANT)
public:
ColorSchemer(QObject* parent = nullptr);
~ColorSchemer();
QAbstractItemModel* model() const;
Q_INVOKABLE void apply(int idx);
Q_INVOKABLE void apply(const QString &name);
Q_INVOKABLE int indexForScheme(const QString &name) const;
Q_INVOKABLE QString nameForIndex(int index) const;
private:
KColorSchemeManager* c;
};

View File

@@ -57,6 +57,9 @@
#include "userdirectorylistmodel.h"
#include "userlistmodel.h"
#include "webshortcutmodel.h"
#ifdef HAVE_COLORSCHEME
#include "colorschemer.h"
#endif
using namespace Quotient;
@@ -137,6 +140,14 @@ int main(int argc, char *argv[])
Login *login = new Login();
ChatBoxHelper chatBoxHelper;
#ifdef HAVE_COLORSCHEME
ColorSchemer colorScheme;
qmlRegisterSingletonInstance<ColorSchemer>("org.kde.neochat", 1, 0, "ColorSchemer", &colorScheme);
if (!config->colorScheme().isEmpty()) {
colorScheme.apply(config->colorScheme());
}
#endif
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "Controller", &Controller::instance());
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "Clipboard", &clipboard);
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "Config", config);

View File

@@ -14,6 +14,9 @@
<entry name="ActiveConnection" type="String">
<label>Latest active connection</label>
</entry>
<entry name="ColorScheme" type="String">
<label>Color scheme</label>
</entry>
<entry name="ShowNotifications" type="bool">
<label>Show notifications</label>
<default>true</default>
@@ -36,6 +39,10 @@
<label>Show avatar in the timeline</label>
<default>true</default>
</entry>
<entry name="CompactLayout" type="bool">
<label>Use a compact layout</label>
<default>false</default>
</entry>
<entry name="ShowRename" type="bool">
<label>Show rename events in the timeline</label>
<default>true</default>