141 lines
3.7 KiB
C++
141 lines
3.7 KiB
C++
/******************************************************************************
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
* This file may be used under the terms of the 3-clause BSD License
|
|
*****************************************************************************/
|
|
|
|
#include "SkinnyNamespace.h"
|
|
|
|
#include <QskSetup.h>
|
|
#include <QskSkinManager.h>
|
|
#include <QskSkin.h>
|
|
#include <QskSkinTransition.h>
|
|
#include <QskAnimationHint.h>
|
|
|
|
#include <QGuiApplication>
|
|
#include <QDebug>
|
|
|
|
#define STRINGIFY(x) #x
|
|
#define STRING(x) STRINGIFY(x)
|
|
|
|
#if defined( ENSURE_SKINS )
|
|
|
|
#include <squiek/QskSquiekSkinFactory.h>
|
|
#include <material/QskMaterialSkinFactory.h>
|
|
|
|
static void initSkins()
|
|
{
|
|
if ( qskSkinManager->skinNames().isEmpty() )
|
|
{
|
|
/*
|
|
To avoid having problems with not finding the skin plugins
|
|
we manually add them here.
|
|
*/
|
|
|
|
qskSkinManager->registerFactory( "SquiekFactory", new QskSquiekSkinFactory() );
|
|
qskSkinManager->registerFactory( "MaterialFactory", new QskMaterialSkinFactory() );
|
|
|
|
qWarning() << "Couldn't find skin plugins, adding some manually.";
|
|
}
|
|
}
|
|
|
|
Q_COREAPP_STARTUP_FUNCTION( initSkins )
|
|
|
|
#endif
|
|
|
|
#define ENSURE_FONTS
|
|
|
|
#if defined( ENSURE_FONTS )
|
|
|
|
#include <QFontDatabase>
|
|
#include <QElapsedTimer>
|
|
|
|
static void initFonts()
|
|
{
|
|
#ifdef FONTCONFIG_FILE
|
|
const char env[] = "FONTCONFIG_FILE";
|
|
if ( !qEnvironmentVariableIsSet( env ) )
|
|
qputenv( env, STRING( FONTCONFIG_FILE ) );
|
|
#endif
|
|
|
|
QElapsedTimer timer;
|
|
timer.start();
|
|
|
|
QFontDatabase();
|
|
|
|
const auto elapsed = timer.elapsed();
|
|
|
|
if ( elapsed > 20 )
|
|
{
|
|
qWarning() << "Loading fonts needed" << elapsed << "ms"
|
|
<< "- usually because of creating a font cache.";
|
|
}
|
|
|
|
/*
|
|
The default initialization in QskSkin sets up its font table
|
|
with using the application font for the default font role.
|
|
*/
|
|
QGuiApplication::setFont( QFont( "DejaVuSans", 12 ) );
|
|
}
|
|
#endif
|
|
|
|
Q_COREAPP_STARTUP_FUNCTION( initFonts )
|
|
|
|
void Skinny::changeSkin( QskAnimationHint hint )
|
|
{
|
|
const auto names = qskSkinManager->skinNames();
|
|
if ( names.size() <= 1 )
|
|
return;
|
|
|
|
int index = names.indexOf( qskSetup->skinName() );
|
|
index = ( index + 1 ) % names.size();
|
|
|
|
auto oldSkin = qskSetup->skin();
|
|
if ( oldSkin->parent() == qskSetup )
|
|
oldSkin->setParent( nullptr ); // otherwise setSkin deletes it
|
|
|
|
if ( auto newSkin = qskSetup->setSkin( names[ index ] ) )
|
|
{
|
|
QskSkinTransition transition;
|
|
|
|
//transition.setMask( QskAspect::Color ); // Metrics are flickering -> TODO
|
|
transition.setSourceSkin( oldSkin );
|
|
transition.setTargetSkin( newSkin );
|
|
transition.setAnimation( hint );
|
|
|
|
transition.process();
|
|
|
|
if ( oldSkin->parent() == nullptr )
|
|
delete oldSkin;
|
|
}
|
|
}
|
|
|
|
void Skinny::changeFonts( int increment )
|
|
{
|
|
auto skin = qskSetup->skin();
|
|
|
|
const auto fonts = skin->fonts();
|
|
|
|
for ( auto it = fonts.begin(); it != fonts.end(); ++it )
|
|
{
|
|
auto role = it->first;
|
|
auto font = it->second;
|
|
|
|
if ( font.pixelSize() > 0 )
|
|
{
|
|
const auto newSize = font.pixelSize() + increment;
|
|
if ( newSize > 0 )
|
|
font.setPixelSize( newSize );
|
|
}
|
|
else
|
|
{
|
|
const auto newSize = font.pointSizeF() + increment;
|
|
if ( newSize > 0 )
|
|
font.setPointSizeF( font.pointSizeF() + increment );
|
|
}
|
|
|
|
skin->setFont( role, font );
|
|
}
|
|
|
|
Q_EMIT qskSetup->skinChanged( skin );
|
|
}
|