2022-04-01 13:56:16 +02:00
|
|
|
/******************************************************************************
|
2024-01-17 14:31:45 +01:00
|
|
|
* QSkinny - Copyright (C) The authors
|
2023-04-06 09:23:37 +02:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2022-04-01 13:56:16 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "SkinnyNamespace.h"
|
|
|
|
|
|
|
|
#include <QskSkinManager.h>
|
2024-02-19 15:51:55 +01:00
|
|
|
#include <QskFontRole.h>
|
2022-04-01 13:56:16 +02:00
|
|
|
#include <QskSkin.h>
|
|
|
|
|
|
|
|
#include <QGuiApplication>
|
2022-07-14 11:52:25 +02:00
|
|
|
#include <QByteArray>
|
2024-02-20 16:20:43 +01:00
|
|
|
#include <QDir>
|
2024-01-30 10:43:27 +01:00
|
|
|
#include <QFont>
|
2024-01-30 10:58:04 +01:00
|
|
|
#include <QDebug>
|
2022-04-01 13:56:16 +02:00
|
|
|
|
2022-07-14 11:52:25 +02:00
|
|
|
#if defined( PLUGIN_PATH )
|
|
|
|
|
|
|
|
#define STRINGIFY(x) #x
|
|
|
|
#define STRING(x) STRINGIFY(x)
|
|
|
|
|
|
|
|
static int initPluginPath()
|
|
|
|
{
|
|
|
|
const char env[] = "QT_PLUGIN_PATH";
|
|
|
|
|
|
|
|
QByteArray value = qgetenv( env );
|
|
|
|
if ( !value.isEmpty() )
|
|
|
|
{
|
|
|
|
if ( QChar( value.at( value.size() - 1 ) ) != QDir::listSeparator() )
|
|
|
|
value += QDir::listSeparator().toLatin1();
|
|
|
|
}
|
|
|
|
|
|
|
|
value += STRING( PLUGIN_PATH );
|
|
|
|
|
|
|
|
qputenv( env, value );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// some plugins are loaded before entering QCoreApplication
|
|
|
|
static bool pluginPath = initPluginPath();
|
|
|
|
|
|
|
|
#endif // PLUGIN_PATH
|
|
|
|
|
2022-04-01 13:56:16 +02:00
|
|
|
#if defined( ENSURE_SKINS )
|
|
|
|
|
2022-07-05 08:36:25 +02:00
|
|
|
#include <material3/QskMaterial3SkinFactory.h>
|
2023-06-17 12:23:34 +02:00
|
|
|
#include <fluent2/QskFluent2SkinFactory.h>
|
2024-01-24 17:42:32 +01:00
|
|
|
#include <fusion/QskFusionSkinFactory.h>
|
2022-04-01 13:56:16 +02:00
|
|
|
|
|
|
|
static void initSkins()
|
|
|
|
{
|
2023-06-20 09:20:51 +02:00
|
|
|
auto skinNames = qskSkinManager->skinNames();
|
|
|
|
|
|
|
|
if ( skinNames.isEmpty() )
|
2022-04-01 13:56:16 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
To avoid having problems with not finding the skin plugins
|
|
|
|
we manually add them here.
|
|
|
|
*/
|
|
|
|
|
2022-07-05 08:36:25 +02:00
|
|
|
qskSkinManager->registerFactory( "Material3Factory", new QskMaterial3SkinFactory() );
|
2023-06-17 12:23:34 +02:00
|
|
|
qskSkinManager->registerFactory( "Fluent2Factory", new QskFluent2SkinFactory() );
|
2024-01-24 17:42:32 +01:00
|
|
|
qskSkinManager->registerFactory( "FusionFactory", new QskFusionSkinFactory() );
|
2022-04-01 13:56:16 +02:00
|
|
|
|
|
|
|
qWarning() << "Couldn't find skin plugins, adding some manually.";
|
2023-06-20 09:20:51 +02:00
|
|
|
|
|
|
|
skinNames = qskSkinManager->skinNames();
|
2022-04-01 13:56:16 +02:00
|
|
|
}
|
2022-07-11 21:10:29 +02:00
|
|
|
|
2023-06-20 09:20:51 +02:00
|
|
|
if ( !skinNames.isEmpty() )
|
2024-01-30 10:43:27 +01:00
|
|
|
qskSkinManager->setSkin( skinNames[0] );
|
2022-04-01 13:56:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Q_COREAPP_STARTUP_FUNCTION( initSkins )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined( ENSURE_FONTS )
|
|
|
|
|
2024-02-20 16:20:43 +01:00
|
|
|
#include <QFontDatabase>
|
2022-04-01 13:56:16 +02:00
|
|
|
|
2024-02-20 16:20:43 +01:00
|
|
|
static void initFonts()
|
2023-02-28 16:58:08 +01:00
|
|
|
{
|
2024-02-20 16:20:43 +01:00
|
|
|
const QString path = QStringLiteral( ":/fonts/" );
|
2022-04-01 13:56:16 +02:00
|
|
|
|
2024-02-20 16:20:43 +01:00
|
|
|
QDir dir( path );
|
|
|
|
const auto fontFiles = dir.entryList();
|
2022-04-01 13:56:16 +02:00
|
|
|
|
2024-02-20 16:20:43 +01:00
|
|
|
for ( const auto& file : fontFiles )
|
2022-04-01 13:56:16 +02:00
|
|
|
{
|
2024-02-20 16:20:43 +01:00
|
|
|
const auto fontPath = path + file;
|
|
|
|
if ( QFontDatabase::addApplicationFont( fontPath ) < 0 )
|
|
|
|
qWarning() << "couldn't load font file:" << fontPath;
|
2022-04-01 13:56:16 +02:00
|
|
|
}
|
2023-02-28 16:58:08 +01:00
|
|
|
}
|
|
|
|
|
2024-02-20 16:20:43 +01:00
|
|
|
Q_COREAPP_STARTUP_FUNCTION( initFonts )
|
2022-04-01 13:56:16 +02:00
|
|
|
|
2024-02-20 16:20:43 +01:00
|
|
|
#endif
|
2022-04-01 13:56:16 +02:00
|
|
|
|
2024-01-30 16:46:01 +01:00
|
|
|
void Skinny::changeSkin()
|
2023-05-16 11:12:11 +02:00
|
|
|
{
|
|
|
|
const auto names = qskSkinManager->skinNames();
|
|
|
|
if ( names.size() > 1 )
|
|
|
|
{
|
2024-01-30 10:43:27 +01:00
|
|
|
auto index = names.indexOf( qskSkinManager->skinName() );
|
2023-05-16 11:12:11 +02:00
|
|
|
index = ( index + 1 ) % names.size();
|
|
|
|
|
2024-01-30 16:46:01 +01:00
|
|
|
qskSkinManager->setSkin( names[ index ] );
|
2023-05-16 11:12:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-30 16:46:01 +01:00
|
|
|
void Skinny::changeColorScheme()
|
2022-04-01 13:56:16 +02:00
|
|
|
{
|
2024-01-30 16:46:01 +01:00
|
|
|
if ( auto skin = qskSkinManager->skin() )
|
2022-04-01 13:56:16 +02:00
|
|
|
{
|
2024-01-30 16:46:01 +01:00
|
|
|
const auto colorScheme = ( skin->colorScheme() == QskSkin::LightScheme )
|
|
|
|
? QskSkin::DarkScheme : QskSkin::LightScheme;
|
2022-04-01 13:56:16 +02:00
|
|
|
|
2024-01-30 16:46:01 +01:00
|
|
|
skin->setColorScheme( colorScheme );
|
|
|
|
}
|
2024-01-30 14:52:40 +01:00
|
|
|
}
|
|
|
|
|
2022-04-01 13:56:16 +02:00
|
|
|
void Skinny::changeFonts( int increment )
|
2023-02-28 15:49:42 +01:00
|
|
|
{
|
2024-01-30 10:43:27 +01:00
|
|
|
auto skin = qskSkinManager->skin();
|
2023-02-28 15:49:42 +01:00
|
|
|
|
2024-02-19 15:51:55 +01:00
|
|
|
const auto table = skin->fontTable();
|
2023-02-28 15:49:42 +01:00
|
|
|
|
2024-02-19 15:51:55 +01:00
|
|
|
for ( auto it = table.constBegin(); it != table.constEnd(); ++it )
|
2023-02-28 15:49:42 +01:00
|
|
|
{
|
2024-01-30 13:04:38 +01:00
|
|
|
auto role = it.key();
|
|
|
|
auto font = it.value();
|
2023-02-28 15:49:42 +01:00
|
|
|
|
2022-04-01 13:56:16 +02:00
|
|
|
if ( font.pixelSize() > 0 )
|
2023-02-28 15:49:42 +01:00
|
|
|
{
|
2022-04-01 13:56:16 +02:00
|
|
|
const auto newSize = font.pixelSize() + increment;
|
|
|
|
if ( newSize > 0 )
|
|
|
|
font.setPixelSize( newSize );
|
|
|
|
}
|
|
|
|
else
|
2023-02-28 15:49:42 +01:00
|
|
|
{
|
2022-04-01 13:56:16 +02:00
|
|
|
const auto newSize = font.pointSizeF() + increment;
|
|
|
|
if ( newSize > 0 )
|
|
|
|
font.setPointSizeF( font.pointSizeF() + increment );
|
|
|
|
}
|
2023-02-28 15:49:42 +01:00
|
|
|
|
2022-04-01 13:56:16 +02:00
|
|
|
skin->setFont( role, font );
|
|
|
|
}
|
2023-02-28 15:49:42 +01:00
|
|
|
|
2024-01-30 10:43:27 +01:00
|
|
|
Q_EMIT qskSkinManager->skinChanged( skin );
|
2022-04-01 13:56:16 +02:00
|
|
|
}
|
2022-04-12 14:13:59 +02:00
|
|
|
|
|
|
|
void Skinny::init()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
a dummy call - has no reason beside, that applications can load
|
|
|
|
the lib and all initializaion take place
|
|
|
|
*/
|
|
|
|
}
|