qskinny/playground/levelingsensor/SkinFactory.cpp

171 lines
5.2 KiB
C++
Raw Normal View History

2023-07-17 10:50:36 +00:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* SPDX-License-Identifier: BSD-3-Clause
*****************************************************************************/
#include "SkinFactory.h"
#include <QskBoxBorderColors.h>
#include <QskGradient.h>
#include <QskGradientStop.h>
#include <QskPlatform.h>
#include <QskRgbValue.h>
#include <QskSkin.h>
#include <QskSkinHintTableEditor.h>
#include <QskTextLabel.h>
2023-07-25 11:05:15 +00:00
#include <QskLevelingSensor.h>
#include <QskLevelingSensorSkinlet.h>
2023-07-17 10:50:36 +00:00
#include <QskSlider.h>
#include <QskSliderSkinlet.h>
#include <QskTextLabel.h>
#include <QskTextLabelSkinlet.h>
namespace
{
class Skin : public QskSkin
{
template< typename T >
void style( QskSkinHintTableEditor& editor );
template< typename Skinnable, typename Skinlet >
2023-07-25 13:08:00 +00:00
void declareSkinlet()
2023-07-17 10:50:36 +00:00
{
QskSkin::declareSkinlet< Skinnable, Skinlet >();
}
2023-07-25 13:08:00 +00:00
2023-07-17 10:50:36 +00:00
template< typename Skinnable, typename Skinlet >
void declareSkinlet( QskSkinHintTableEditor& editor )
{
QskSkin::declareSkinlet< Skinnable, Skinlet >();
style< Skinnable >( editor );
}
2023-08-02 15:07:44 +00:00
public:
Skin()
2023-07-17 10:50:36 +00:00
{
2023-08-02 15:07:44 +00:00
QskSkinHintTableEditor editor( &hintTable() );
declareSkinlet< QskSlider, QskSliderSkinlet >( editor );
declareSkinlet< QskTextLabel, QskTextLabelSkinlet >();
declareSkinlet< QskLevelingSensor, QskLevelingSensorSkinlet >( editor );
}
};
template<>
void Skin::style< QskSlider >( QskSkinHintTableEditor& editor )
{
using A = QskAspect;
using Q = QskSlider;
2023-07-17 10:50:36 +00:00
2023-08-02 15:07:44 +00:00
const qreal extent = 40;
2023-07-17 10:50:36 +00:00
2023-08-02 15:07:44 +00:00
// Panel
2023-07-17 10:50:36 +00:00
2023-08-02 15:07:44 +00:00
for ( auto variation : { A::Horizontal, A::Vertical } )
{
const auto aspect = Q::Panel | variation;
2023-07-17 10:50:36 +00:00
2023-08-02 15:07:44 +00:00
editor.setMetric( aspect | A::Size, extent );
editor.setBoxBorderMetrics( aspect, 0 );
editor.setBoxShape( aspect, 0 );
editor.setGradient( aspect, QskGradient() );
}
2023-07-17 10:50:36 +00:00
2023-08-02 15:07:44 +00:00
// Groove, Fill
2023-07-17 10:50:36 +00:00
2023-08-02 15:07:44 +00:00
for ( auto variation : { A::Horizontal, A::Vertical } )
{
for ( auto subControl : { Q::Groove, Q::Fill } )
2023-07-17 10:50:36 +00:00
{
2023-08-02 15:07:44 +00:00
const auto aspect = subControl | variation;
2023-07-17 10:50:36 +00:00
2023-08-02 15:07:44 +00:00
editor.setMetric( aspect | A::Size, 0.3 * extent );
2023-07-17 10:50:36 +00:00
2023-08-02 15:07:44 +00:00
editor.setBoxBorderMetrics( aspect, 0 );
editor.setBoxShape( aspect, 0.1 * extent );
2023-07-17 10:50:36 +00:00
}
2023-08-02 15:07:44 +00:00
editor.setGradient( Q::Groove | variation, Qt::lightGray );
editor.setGradient( Q::Fill | variation, Qt::darkGray );
}
2023-07-17 10:50:36 +00:00
2023-08-02 15:07:44 +00:00
// Handle
2023-07-17 10:50:36 +00:00
2023-08-02 15:07:44 +00:00
for ( auto variation : { A::Horizontal, A::Vertical } )
{
const auto aspect = Q::Handle | variation;
editor.setColor( aspect, Qt::black );
2023-07-17 10:50:36 +00:00
2023-08-02 15:07:44 +00:00
editor.setBoxShape( aspect, 20.0, Qt::RelativeSize );
2023-07-17 10:50:36 +00:00
2023-08-02 15:07:44 +00:00
const qreal sz = 0.75 * extent;
editor.setStrutSize( aspect, sz, sz );
}
}
2023-07-17 10:50:36 +00:00
2023-08-02 15:07:44 +00:00
template<>
void Skin::style< QskLevelingSensor >( QskSkinHintTableEditor& editor )
{
using Q = QskLevelingSensor;
2023-07-17 10:50:36 +00:00
2023-08-02 15:07:44 +00:00
static constexpr auto r1 = 0.9;
static constexpr auto r2 = 1.0;
2023-07-17 10:50:36 +00:00
2023-08-02 15:07:44 +00:00
QskGradient gradient{ {
{ 0.5, Qt::lightGray },
{ 0.5, Qt::lightGray },
{ 0.5, Qt::darkGray },
{ 1.0, Qt::darkGray },
} };
gradient.setLinearDirection( Qt::Vertical );
2023-07-17 10:50:36 +00:00
2023-08-02 15:07:44 +00:00
editor.setColor( Q::Background, "dimgray" );
2023-07-17 10:50:36 +00:00
2023-08-02 15:07:44 +00:00
editor.setStrutSize( Q::OuterDisk, { r2, r2 } );
editor.setColor( Q::OuterDisk, Qt::white );
2023-07-17 10:50:36 +00:00
2023-08-02 15:07:44 +00:00
editor.setGradient( Q::Horizon, gradient );
editor.setStrutSize( Q::Horizon, { r1, r1 } );
2023-07-17 10:50:36 +00:00
2023-08-02 15:07:44 +00:00
editor.setColor( Q::TickmarksX, Qt::black );
editor.setStrutSize( Q::TickmarksX, { r1, 0.2 } ); // w %, h %
editor.setHint( Q::TickmarksX, QVector3D{ 0.50, 0.75, 1.0 } ); // %
editor.setAlignment( Q::TickmarksX, Qt::AlignCenter );
2023-07-17 10:50:36 +00:00
2023-08-02 15:07:44 +00:00
editor.setStrutSize( Q::TickmarksXLabels, { r1, 0.15 } ); // w %, h %
editor.setAlignment( Q::TickmarksXLabels, Qt::AlignTop | Qt::AlignHCenter );
2023-07-17 10:50:36 +00:00
2023-08-02 15:07:44 +00:00
editor.setColor( Q::TickmarksY, Qt::black );
editor.setStrutSize( Q::TickmarksY, { 0.1, r1 } ); // w %, h %
editor.setHint( Q::TickmarksY, QVector3D{ 0.50, 0.75, 1.00 } ); // %
editor.setAlignment( Q::TickmarksY, Qt::AlignCenter );
2023-07-17 10:50:36 +00:00
2023-08-02 15:07:44 +00:00
editor.setStrutSize( Q::TickmarksYLabels, { 0.15, r1 } ); // w %, h %
editor.setAlignment( Q::TickmarksYLabels, Qt::AlignCenter );
2023-07-17 10:50:36 +00:00
2023-08-02 15:07:44 +00:00
editor.setColor( Q::TickmarksZ, "silver" );
editor.setStrutSize( Q::TickmarksZ, { 0.90, 0.95 } );
editor.setHint( Q::TickmarksZ, QVector3D{ 0.50, 0.75, 1.00 } ); // %
2023-07-17 10:50:36 +00:00
2023-08-02 15:07:44 +00:00
editor.setStrutSize( Q::TickmarksZLabels, { 0.9, 0.0 } ); // r1 %, r2 %
editor.setAlignment( Q::TickmarksZLabels, Qt::AlignCenter );
}
2023-07-17 10:50:36 +00:00
}
QStringList SkinFactory::skinNames() const
{
return { "Skin" };
}
QskSkin* SkinFactory::createSkin( const QString& skinName )
{
if ( skinName == "Skin" )
return new Skin();
return nullptr;
}
#include "moc_SkinFactory.cpp"