qskinny/examples/gallery/label/LabelPage.cpp

98 lines
2.6 KiB
C++
Raw Normal View History

2020-08-11 17:56:53 +02:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
2023-04-06 09:23:37 +02:00
* SPDX-License-Identifier: BSD-3-Clause
2020-08-11 17:56:53 +02:00
*****************************************************************************/
#include "LabelPage.h"
#include <QskTextLabel.h>
#include <QskGraphicLabel.h>
#include <QskSeparator.h>
#include <QskRgbValue.h>
2022-04-01 14:43:22 +02:00
#include <QskSkin.h>
2020-08-11 17:56:53 +02:00
namespace
{
2022-04-01 14:43:22 +02:00
class TextLabel : public QskTextLabel
2020-08-11 17:56:53 +02:00
{
public:
2022-04-01 14:43:22 +02:00
TextLabel( int role, QQuickItem* parent = nullptr )
: QskTextLabel( parent )
2020-08-11 17:56:53 +02:00
{
2022-04-01 14:43:22 +02:00
setText( textFromRole( role ) );
setFontRole( role );
2020-08-11 17:56:53 +02:00
2022-04-01 14:43:22 +02:00
setSizePolicy( Qt::Horizontal, QskSizePolicy::Ignored );
}
2020-08-11 17:56:53 +02:00
2022-04-01 14:43:22 +02:00
private:
QString textFromRole( int role ) const
{
static QMetaEnum metaEnum;
2020-08-11 17:56:53 +02:00
2022-04-01 14:43:22 +02:00
if ( !metaEnum.isValid() )
{
const auto& mo = QskSkin::staticMetaObject;
metaEnum = mo.enumerator( mo.indexOfEnumerator( "SkinFontRole" ) );
2020-08-11 17:56:53 +02:00
}
2022-04-01 14:43:22 +02:00
QString s( metaEnum.valueToKey( role ) );
s.remove( QStringLiteral( "Font" ) );
return s;
}
};
class TextBox : public QskLinearBox
{
public:
TextBox( QQuickItem* parent = nullptr )
: QskLinearBox( Qt::Horizontal, 3, parent )
{
setMargins( 10 );
setDefaultAlignment( Qt::AlignCenter );
for ( int i = 0; i <= QskSkin::HugeFont; i++ )
( void ) new TextLabel( i, this );
2020-08-11 17:56:53 +02:00
}
};
class IconBox : public QskLinearBox
{
public:
IconBox( QQuickItem* parent = nullptr )
: QskLinearBox( Qt::Horizontal, 3, parent )
{
setMargins( 10 );
setSpacing( 20 );
const char* icons[] =
{
"rectangle/royalblue",
"triangleright/thistle",
"ellipse/khaki",
"ring/sandybrown",
"star/darkviolet",
"hexagon/darkslategray"
};
const auto prefix = QStringLiteral( "image://shapes/" );
for ( const auto icon : icons )
{
auto label = new QskGraphicLabel( prefix + icon, this );
label->setAlignment( Qt::AlignCenter );
}
}
};
}
LabelPage::LabelPage( QQuickItem* parent )
: Page( Qt::Vertical, parent )
{
setSpacing( 40 );
(void) new TextBox( this );
(void) new QskSeparator( this );
(void) new IconBox( this );
}