minor refactor
Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
0924aeb51f
commit
8a1dcfb808
|
@ -25,7 +25,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "framelesshelpercore_global.h"
|
#include "framelesshelpercore_global.h"
|
||||||
#include <QtCore/qvariant.h>
|
|
||||||
|
|
||||||
FRAMELESSHELPER_BEGIN_NAMESPACE
|
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
@ -47,18 +46,6 @@ public:
|
||||||
|
|
||||||
static void setLoadFromEnvironmentVariablesDisabled(const bool on = true);
|
static void setLoadFromEnvironmentVariablesDisabled(const bool on = true);
|
||||||
static void setLoadFromConfigurationFileDisabled(const bool on = true);
|
static void setLoadFromConfigurationFileDisabled(const bool on = true);
|
||||||
|
|
||||||
Q_NODISCARD QVariant setInternal(const QString &key, const QVariant &value);
|
|
||||||
Q_NODISCARD QVariant getInternal(const QString &key) const;
|
|
||||||
template<typename T>
|
|
||||||
Q_NODISCARD std::optional<T> getInternal(const QString &key) const
|
|
||||||
{
|
|
||||||
const QVariant var = getInternal(key);
|
|
||||||
if (var.isValid()) {
|
|
||||||
return qvariant_cast<T>(var);
|
|
||||||
}
|
|
||||||
return std::nullopt;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
FRAMELESSHELPER_END_NAMESPACE
|
FRAMELESSHELPER_END_NAMESPACE
|
||||||
|
|
|
@ -199,9 +199,6 @@ elseif(UNIX)
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
if(GTK3_FOUND)
|
if(GTK3_FOUND)
|
||||||
#target_include_directories(${SUB_PROJ_NAME} PRIVATE
|
|
||||||
# ${GTK3_INCLUDE_DIRS}
|
|
||||||
#)
|
|
||||||
target_link_libraries(${SUB_PROJ_NAME} PRIVATE
|
target_link_libraries(${SUB_PROJ_NAME} PRIVATE
|
||||||
PkgConfig::GTK3
|
PkgConfig::GTK3
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <QtCore/qdir.h>
|
#include <QtCore/qdir.h>
|
||||||
#include <QtCore/qsettings.h>
|
#include <QtCore/qsettings.h>
|
||||||
#include <QtCore/qcoreapplication.h>
|
#include <QtCore/qcoreapplication.h>
|
||||||
|
#include <QtCore/qtimer.h>
|
||||||
|
|
||||||
FRAMELESSHELPER_BEGIN_NAMESPACE
|
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
@ -89,6 +90,28 @@ Q_GLOBAL_STATIC(ConfigData, g_data)
|
||||||
|
|
||||||
Q_GLOBAL_STATIC(FramelessConfig, g_config)
|
Q_GLOBAL_STATIC(FramelessConfig, g_config)
|
||||||
|
|
||||||
|
static inline void warnInappropriateOptions()
|
||||||
|
{
|
||||||
|
const FramelessConfig * const cfg = FramelessConfig::instance();
|
||||||
|
#ifndef Q_OS_WINDOWS
|
||||||
|
if (cfg->isSet(Option::UseCrossPlatformQtImplementation)) {
|
||||||
|
WARNING << "Option::UseCrossPlatformQtImplementation is default on non-Windows platforms.";
|
||||||
|
}
|
||||||
|
if (cfg->isSet(Option::ForceHideWindowFrameBorder)) {
|
||||||
|
WARNING << "Option::ForceHideWindowFrameBorder is only available on Windows.";
|
||||||
|
}
|
||||||
|
if (cfg->isSet(Option::ForceShowWindowFrameBorder)) {
|
||||||
|
WARNING << "Option::ForceShowWindowFrameBorder is only available on Windows.";
|
||||||
|
}
|
||||||
|
if (cfg->isSet(Option::DisableWindowsSnapLayout)) {
|
||||||
|
WARNING << "Option::DisableWindowsSnapLayout is only available on Windows.";
|
||||||
|
}
|
||||||
|
#endif // Q_OS_WINDOWS
|
||||||
|
if (cfg->isSet(Option::WindowUseRoundCorners)) {
|
||||||
|
WARNING << "Option::WindowUseRoundCorners has not been implemented yet.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FramelessConfig::FramelessConfig(QObject *parent) : QObject(parent)
|
FramelessConfig::FramelessConfig(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
reload();
|
reload();
|
||||||
|
@ -123,6 +146,8 @@ void FramelessConfig::reload(const bool force)
|
||||||
g_data()->options[i] = (envVar || cfgFile);
|
g_data()->options[i] = (envVar || cfgFile);
|
||||||
}
|
}
|
||||||
g_data()->loaded = true;
|
g_data()->loaded = true;
|
||||||
|
|
||||||
|
QTimer::singleShot(0, qApp, [](){ warnInappropriateOptions(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void FramelessConfig::set(const Option option, const bool on)
|
void FramelessConfig::set(const Option option, const bool on)
|
||||||
|
@ -149,34 +174,4 @@ void FramelessConfig::setLoadFromConfigurationFileDisabled(const bool on)
|
||||||
g_data()->disableCfgFile = on;
|
g_data()->disableCfgFile = on;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant FramelessConfig::setInternal(const QString &key, const QVariant &value)
|
|
||||||
{
|
|
||||||
Q_ASSERT(!key.isEmpty());
|
|
||||||
Q_ASSERT(value.isValid());
|
|
||||||
if (key.isEmpty() || !value.isValid()) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
QVariant previous = {};
|
|
||||||
const QMutexLocker locker(&g_data()->mutex);
|
|
||||||
if (g_data()->internals.contains(key)) {
|
|
||||||
previous = g_data()->internals.value(key);
|
|
||||||
g_data()->internals.remove(key);
|
|
||||||
}
|
|
||||||
g_data()->internals.insert(key, value);
|
|
||||||
return previous;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant FramelessConfig::getInternal(const QString &key) const
|
|
||||||
{
|
|
||||||
Q_ASSERT(!key.isEmpty());
|
|
||||||
if (key.isEmpty()) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
const QMutexLocker locker(&g_data()->mutex);
|
|
||||||
if (g_data()->internals.contains(key)) {
|
|
||||||
return g_data()->internals.value(key);
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
FRAMELESSHELPER_END_NAMESPACE
|
FRAMELESSHELPER_END_NAMESPACE
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "framelessmanager.h"
|
#include "framelessmanager.h"
|
||||||
#include "framelessmanager_p.h"
|
#include "framelessmanager_p.h"
|
||||||
#include <QtCore/qmutex.h>
|
#include <QtCore/qmutex.h>
|
||||||
|
#include <QtCore/qvariant.h>
|
||||||
#include <QtCore/qcoreapplication.h>
|
#include <QtCore/qcoreapplication.h>
|
||||||
#include <QtGui/qfontdatabase.h>
|
#include <QtGui/qfontdatabase.h>
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0))
|
||||||
|
|
Loading…
Reference in New Issue