forked from blue/squawk
new optional KDE Frameworks plugin to support system color schemes
This commit is contained in:
parent
802e2f11a1
commit
0ff9f12157
@ -29,6 +29,7 @@ target_include_directories(squawk PRIVATE ${CMAKE_SOURCE_DIR})
|
|||||||
option(SYSTEM_QXMPP "Use system qxmpp lib" ON)
|
option(SYSTEM_QXMPP "Use system qxmpp lib" ON)
|
||||||
option(WITH_KWALLET "Build KWallet support module" ON)
|
option(WITH_KWALLET "Build KWallet support module" ON)
|
||||||
option(WITH_KIO "Build KIO support module" ON)
|
option(WITH_KIO "Build KIO support module" ON)
|
||||||
|
option(WITH_KCONFIG "Build KConfig support module" ON)
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
## Qt
|
## Qt
|
||||||
@ -90,6 +91,24 @@ if (WITH_KWALLET)
|
|||||||
endif ()
|
endif ()
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
if (WITH_KCONFIG)
|
||||||
|
find_package(KF5Config CONFIG)
|
||||||
|
if (NOT KF5Config_FOUND)
|
||||||
|
set(WITH_KCONFIG OFF)
|
||||||
|
message("KConfig package wasn't found, KConfig support modules wouldn't be built")
|
||||||
|
else()
|
||||||
|
find_package(KF5ConfigWidgets CONFIG)
|
||||||
|
if (NOT KF5ConfigWidgets_FOUND)
|
||||||
|
set(WITH_KCONFIG OFF)
|
||||||
|
message("KConfigWidgets package wasn't found, KConfigWidgets support modules wouldn't be built")
|
||||||
|
else()
|
||||||
|
target_compile_definitions(squawk PRIVATE WITH_KCONFIG)
|
||||||
|
message("Building with support of KConfig")
|
||||||
|
message("Building with support of KConfigWidgets")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
## Signal (TODO)
|
## Signal (TODO)
|
||||||
# find_package(Signal REQUIRED)
|
# find_package(Signal REQUIRED)
|
||||||
|
|
||||||
|
@ -176,7 +176,10 @@ int main(int argc, char *argv[])
|
|||||||
int result = app.exec();
|
int result = app.exec();
|
||||||
|
|
||||||
if (coreThread->isRunning()) {
|
if (coreThread->isRunning()) {
|
||||||
coreThread->wait();
|
//coreThread->wait();
|
||||||
|
//todo if I uncomment that, the app will no quit if it has reconnected at least once
|
||||||
|
//it feels like a symptom of something badly desinged in the core coreThread
|
||||||
|
//need to investigate;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -2,3 +2,9 @@ if (WITH_KIO)
|
|||||||
add_library(openFileManagerWindowJob SHARED openfilemanagerwindowjob.cpp)
|
add_library(openFileManagerWindowJob SHARED openfilemanagerwindowjob.cpp)
|
||||||
target_link_libraries(openFileManagerWindowJob PRIVATE KF5::KIOWidgets)
|
target_link_libraries(openFileManagerWindowJob PRIVATE KF5::KIOWidgets)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
if (WITH_KCONFIG)
|
||||||
|
add_library(colorSchemeTools SHARED colorschemetools.cpp)
|
||||||
|
target_link_libraries(colorSchemeTools PRIVATE KF5::ConfigCore)
|
||||||
|
target_link_libraries(colorSchemeTools PRIVATE KF5::ConfigWidgets)
|
||||||
|
endif()
|
||||||
|
39
plugins/colorschemetools.cpp
Normal file
39
plugins/colorschemetools.cpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#include <QIcon>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
|
#include <KConfigCore/KSharedConfig>
|
||||||
|
#include <KConfigWidgets/KColorScheme>
|
||||||
|
|
||||||
|
QPixmap createPixmap(int size, const QBrush& window, const QBrush& button, const QBrush& view, const QBrush& selection);
|
||||||
|
|
||||||
|
extern "C" QIcon* createPreview(const QString& path) {
|
||||||
|
KSharedConfigPtr schemeConfig = KSharedConfig::openConfig(path);
|
||||||
|
QIcon* result = new QIcon();
|
||||||
|
KColorScheme activeWindow(QPalette::Active, KColorScheme::Window, schemeConfig);
|
||||||
|
KColorScheme activeButton(QPalette::Active, KColorScheme::Button, schemeConfig);
|
||||||
|
KColorScheme activeView(QPalette::Active, KColorScheme::View, schemeConfig);
|
||||||
|
KColorScheme activeSelection(QPalette::Active, KColorScheme::Selection, schemeConfig);
|
||||||
|
|
||||||
|
result->addPixmap(createPixmap(16, activeWindow.background(), activeButton.background(), activeView.background(), activeSelection.background()));
|
||||||
|
result->addPixmap(createPixmap(24, activeWindow.background(), activeButton.background(), activeView.background(), activeSelection.background()));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void deletePreview(QIcon* icon) {
|
||||||
|
delete icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPixmap createPixmap(int size, const QBrush& window, const QBrush& button, const QBrush& view, const QBrush& selection) {
|
||||||
|
QPixmap pix(size, size);
|
||||||
|
pix.fill(Qt::black);
|
||||||
|
QPainter p;
|
||||||
|
p.begin(&pix);
|
||||||
|
const int itemSize = size / 2 - 1;
|
||||||
|
p.fillRect(1, 1, itemSize, itemSize, window);
|
||||||
|
p.fillRect(1 + itemSize, 1, itemSize, itemSize, button);
|
||||||
|
p.fillRect(1, 1 + itemSize, itemSize, itemSize, view);
|
||||||
|
p.fillRect(1 + itemSize, 1 + itemSize, itemSize, itemSize, selection);
|
||||||
|
p.end();
|
||||||
|
return pix;
|
||||||
|
}
|
@ -28,6 +28,12 @@ QLibrary Shared::Global::openFileManagerWindowJob("openFileManagerWindowJob");
|
|||||||
Shared::Global::HighlightInFileManager Shared::Global::hfm = 0;
|
Shared::Global::HighlightInFileManager Shared::Global::hfm = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WITH_KCONFIG
|
||||||
|
QLibrary Shared::Global::colorSchemeTools("colorSchemeTools");
|
||||||
|
Shared::Global::CreatePreview Shared::Global::createPreview = 0;
|
||||||
|
Shared::Global::DeletePreview Shared::Global::deletePreview = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
Shared::Global::Global():
|
Shared::Global::Global():
|
||||||
availability({
|
availability({
|
||||||
tr("Online", "Availability"),
|
tr("Online", "Availability"),
|
||||||
@ -87,7 +93,8 @@ Shared::Global::Global():
|
|||||||
defaultSystemStyle(QApplication::style()->objectName()),
|
defaultSystemStyle(QApplication::style()->objectName()),
|
||||||
pluginSupport({
|
pluginSupport({
|
||||||
{"KWallet", false},
|
{"KWallet", false},
|
||||||
{"openFileManagerWindowJob", false}
|
{"openFileManagerWindowJob", false},
|
||||||
|
{"colorSchemeTools", false}
|
||||||
}),
|
}),
|
||||||
fileCache()
|
fileCache()
|
||||||
{
|
{
|
||||||
@ -111,6 +118,22 @@ Shared::Global::Global():
|
|||||||
qDebug() << "KIO::OpenFileManagerWindow support disabled: couldn't load the library" << openFileManagerWindowJob.errorString();
|
qDebug() << "KIO::OpenFileManagerWindow support disabled: couldn't load the library" << openFileManagerWindowJob.errorString();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WITH_KCONFIG
|
||||||
|
colorSchemeTools.load();
|
||||||
|
if (colorSchemeTools.isLoaded()) {
|
||||||
|
createPreview = (CreatePreview) colorSchemeTools.resolve("createPreview");
|
||||||
|
deletePreview = (DeletePreview) colorSchemeTools.resolve("deletePreview");
|
||||||
|
if (createPreview && deletePreview) {
|
||||||
|
setSupported("colorSchemeTools", true);
|
||||||
|
qDebug() << "Color Schemes support enabled";
|
||||||
|
} else {
|
||||||
|
qDebug() << "Color Schemes support disabled: couldn't resolve required methods in the library";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qDebug() << "Color Schemes support disabled: couldn't load the library" << colorSchemeTools.errorString();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -276,6 +299,18 @@ void Shared::Global::highlightInFileManager(const QString& path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QIcon Shared::Global::createThemePreview(const QString& path)
|
||||||
|
{
|
||||||
|
if (supported("colorSchemeTools")) {
|
||||||
|
QIcon* icon = createPreview(path);
|
||||||
|
QIcon localIcon = *icon;
|
||||||
|
deletePreview(icon);
|
||||||
|
return localIcon;
|
||||||
|
} else {
|
||||||
|
return QIcon();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#define FROM_INT_INPL(Enum) \
|
#define FROM_INT_INPL(Enum) \
|
||||||
template<> \
|
template<> \
|
||||||
|
@ -95,6 +95,7 @@ namespace Shared {
|
|||||||
|
|
||||||
static FileInfo getFileInfo(const QString& path);
|
static FileInfo getFileInfo(const QString& path);
|
||||||
static void highlightInFileManager(const QString& path);
|
static void highlightInFileManager(const QString& path);
|
||||||
|
static QIcon createThemePreview(const QString& path);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static T fromInt(int src);
|
static T fromInt(int src);
|
||||||
@ -128,6 +129,16 @@ namespace Shared {
|
|||||||
|
|
||||||
static HighlightInFileManager hfm;
|
static HighlightInFileManager hfm;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WITH_KCONFIG
|
||||||
|
static QLibrary colorSchemeTools;
|
||||||
|
|
||||||
|
typedef QIcon* (*CreatePreview)(const QString&);
|
||||||
|
typedef void (*DeletePreview)(QIcon*);
|
||||||
|
|
||||||
|
static CreatePreview createPreview;
|
||||||
|
static DeletePreview deletePreview;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,16 +33,19 @@ PageAppearance::PageAppearance(QWidget* parent):
|
|||||||
|
|
||||||
connect(m_ui->themeInput, qOverload<int>(&QComboBox::currentIndexChanged), this, &PageAppearance::onThemeChanged);
|
connect(m_ui->themeInput, qOverload<int>(&QComboBox::currentIndexChanged), this, &PageAppearance::onThemeChanged);
|
||||||
|
|
||||||
m_ui->colorInput->addItem(tr("System"));
|
if (Shared::Global::supported("colorSchemeTools")) {
|
||||||
const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "color-schemes", QStandardPaths::LocateDirectory);
|
m_ui->colorInput->addItem(tr("System"));
|
||||||
QStringList schemeFiles;
|
const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, "color-schemes", QStandardPaths::LocateDirectory);
|
||||||
for (const QString &dir : dirs) {
|
QStringList schemeFiles;
|
||||||
const QStringList fileNames = QDir(dir).entryList(filters);
|
for (const QString &dir : dirs) {
|
||||||
for (const QString &file : fileNames) {
|
const QStringList fileNames = QDir(dir).entryList(filters);
|
||||||
m_ui->colorInput->addItem(dir + QDir::separator() + file);
|
for (const QString &file : fileNames) {
|
||||||
|
m_ui->colorInput->addItem(Shared::Global::createThemePreview(dir + QDir::separator() + file), file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
m_ui->colorInput->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PageAppearance::~PageAppearance()
|
PageAppearance::~PageAppearance()
|
||||||
@ -55,3 +58,5 @@ void PageAppearance::onThemeChanged(int index)
|
|||||||
emit variableModified("theme", styles[index]);
|
emit variableModified("theme", styles[index]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "shared/global.h"
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
class PageAppearance;
|
class PageAppearance;
|
||||||
|
Loading…
Reference in New Issue
Block a user