introducing high level APIs for setting of font and graphic roles for

Text/Graphic-Label
This commit is contained in:
Uwe Rathmann 2017-08-22 20:15:11 +02:00
parent 3c40903ea9
commit a57915c6f0
12 changed files with 107 additions and 36 deletions

View File

@ -12,6 +12,8 @@ public:
IndicatorLabel( QQuickItem* parentItem = nullptr ): IndicatorLabel( QQuickItem* parentItem = nullptr ):
QskGraphicLabel( parentItem ) QskGraphicLabel( parentItem )
{ {
// so the skins are able to colorize them
setGraphicRole( SkinFactory::Indicator );
} }
virtual QskAspect::Subcontrol effectiveSubcontrol( virtual QskAspect::Subcontrol effectiveSubcontrol(
@ -43,9 +45,6 @@ void ButtonBar::addIndicator( const char* name )
{ {
auto* label = new IndicatorLabel( this ); auto* label = new IndicatorLabel( this );
// so the skins are able to colorize them
label->setGraphicRole( QskGraphicLabel::Graphic, SkinFactory::Indicator );
/* /*
The label should adjust vertically and be stretched horizontally The label should adjust vertically and be stretched horizontally
according to its aspect ratio. according to its aspect ratio.

View File

@ -30,9 +30,8 @@ public:
QskTextLabel( text, parent ) QskTextLabel( text, parent )
{ {
setBackgroundColor( Qt::black ); setBackgroundColor( Qt::black );
setColor( QskTextLabel::Text, Qt::white ); setTextColor( Qt::white );
setFontRole( QskSkin::MediumFont );
setFontRole( Text, QskSkin::MediumFont );
QskTextOptions textOptions; QskTextOptions textOptions;
textOptions.setWrapMode( QskTextOptions::WordWrap ); textOptions.setWrapMode( QskTextOptions::WordWrap );

View File

@ -42,19 +42,18 @@ public:
{ {
using namespace QskAspect; using namespace QskAspect;
const QskAspect::Aspect aspectRole = QskGraphicLabel::Graphic | GraphicRole; const int oldRole = graphicRole();
const int oldRole = graphicRole( aspectRole );
QColor color; QColor color;
if ( on ) if ( on )
{ {
color.setRgb( 40, 40, 40 ); color.setRgb( 40, 40, 40 );
setGraphicRole( aspectRole, Inverted ); setGraphicRole( Inverted );
} }
else else
{ {
color.setRgb( 255, 228, 181 ); color.setRgb( 255, 228, 181 );
setGraphicRole( aspectRole, Normal ); setGraphicRole( Normal );
} }
const int duration = 500; const int duration = 500;
@ -68,7 +67,8 @@ public:
startTransition( aspectColor, duration, oldColor, color ); startTransition( aspectColor, duration, oldColor, color );
} }
startTransition( aspectRole, duration, oldRole, graphicRole( aspectRole ) ); const QskAspect::Aspect aspectRole = QskGraphicLabel::Graphic | GraphicRole;
startTransition( aspectRole, duration, oldRole, graphicRole() );
} }
}; };

View File

@ -25,9 +25,8 @@ public:
Label( const QString& text, QQuickItem* parent = nullptr ): Label( const QString& text, QQuickItem* parent = nullptr ):
QskTextLabel( text, parent ) QskTextLabel( text, parent )
{ {
setColor( Text, Qt::darkRed ); setTextColor( Qt::darkRed );
setFontRole( QskSkin::LargeFont );
setFontRole( Text, QskSkin::LargeFont );
setAlignment( Qt::AlignCenter ); setAlignment( Qt::AlignCenter );
} }
}; };

View File

@ -101,6 +101,23 @@ public:
} }
}; };
class ScrollArea : public QskScrollArea
{
public:
ScrollArea( QQuickItem* parentItem = nullptr ) :
QskScrollArea( parentItem )
{
using namespace QskAspect;
// settings usually done in the skins
setMetric( Viewport | Radius, 20 );
setMetric( VerticalScrollBar | Size, 20 );
setMetric( VerticalScrollHandle | Radius, 8 );
setMetric( HorizontalScrollBar | Size, 20 );
setMetric( HorizontalScrollHandle | Radius, 0 );
}
};
int main( int argc, char* argv[] ) int main( int argc, char* argv[] )
{ {
#ifdef ITEM_STATISTICS #ifdef ITEM_STATISTICS
@ -123,20 +140,10 @@ int main( int argc, char* argv[] )
But here we only want to demonstrate how QskScrollArea works. But here we only want to demonstrate how QskScrollArea works.
*/ */
auto scrollArea = new QskScrollArea(); auto scrollArea = new ScrollArea();
scrollArea->setMargins( QMarginsF( 25, 25, 5, 5 ) ); scrollArea->setMargins( QMarginsF( 25, 25, 5, 5 ) );
scrollArea->setScrolledItem( new IconGrid() ); scrollArea->setScrolledItem( new IconGrid() );
#if 1
// settings that are usually done in the skins
scrollArea->setMetric( QskScrollView::Viewport | QskAspect::Radius, 20 );
scrollArea->setMetric( QskScrollView::VerticalScrollBar | QskAspect::Size, 20 );
scrollArea->setMetric( QskScrollView::VerticalScrollHandle | QskAspect::Radius, 8 );
scrollArea->setMetric( QskScrollView::HorizontalScrollBar | QskAspect::Size, 20 );
scrollArea->setMetric( QskScrollView::HorizontalScrollHandle | QskAspect::Radius, 0 );
#endif
QskWindow window; QskWindow window;
window.resize( 600, 600 ); window.resize( 600, 600 );
window.setColor( "SteelBlue" ); window.setColor( "SteelBlue" );

View File

@ -6,16 +6,12 @@
#include <SkinnyFont.h> #include <SkinnyFont.h>
#include <SkinnyShortcut.h> #include <SkinnyShortcut.h>
#include <QskAspect.h>
#include <QskModule.h>
#include <QskObjectCounter.h> #include <QskObjectCounter.h>
#include <QskSkin.h>
#include <QskLinearBox.h> #include <QskLinearBox.h>
#include <QskTextLabel.h> #include <QskTextLabel.h>
#include <QskWindow.h> #include <QskWindow.h>
#include <QGuiApplication> #include <QGuiApplication>
#include <QFont>
class TextBox: public QskLinearBox class TextBox: public QskLinearBox
{ {
@ -29,7 +25,7 @@ public:
for ( int i = 0; i < texts.size(); i++ ) for ( int i = 0; i < texts.size(); i++ )
{ {
auto label = new QskTextLabel( texts[i] + " Font", this ); auto label = new QskTextLabel( texts[i] + " Font", this );
label->setFontRole( QskTextLabel::Text, i ); label->setFontRole( i );
} }
} }
}; };

View File

@ -121,6 +121,24 @@ void QskGraphicLabel::setGraphic( const QskGraphic& graphic )
} }
} }
void QskGraphicLabel::setGraphicRole( int role )
{
const int oldRole = graphicRole();
QskSkinnable::setGraphicRole( effectiveSubcontrol( Graphic ), role );
if ( role != oldRole )
{
update();
Q_EMIT graphicRoleChanged();
}
}
int QskGraphicLabel::graphicRole() const
{
return QskSkinnable::graphicRole( Graphic );
}
QskColorFilter QskGraphicLabel::graphicFilter() const QskColorFilter QskGraphicLabel::graphicFilter() const
{ {
// can be removed once we can store a filter inidividually // can be removed once we can store a filter inidividually

View File

@ -22,6 +22,9 @@ class QSK_EXPORT QskGraphicLabel : public QskControl
Q_PROPERTY( QSize sourceSize READ sourceSize Q_PROPERTY( QSize sourceSize READ sourceSize
WRITE setSourceSize RESET resetSourceSize NOTIFY sourceSizeChanged ) WRITE setSourceSize RESET resetSourceSize NOTIFY sourceSizeChanged )
Q_PROPERTY( int graphicRole READ graphicRole
WRITE setGraphicRole NOTIFY graphicRoleChanged )
Q_PROPERTY( Qt::Alignment alignment READ alignment Q_PROPERTY( Qt::Alignment alignment READ alignment
WRITE setAlignment NOTIFY alignmentChanged ) WRITE setAlignment NOTIFY alignmentChanged )
@ -80,10 +83,14 @@ public:
bool isEmpty() const; bool isEmpty() const;
void setGraphicRole( int role );
int graphicRole() const;
Q_SIGNALS: Q_SIGNALS:
void sourceChanged(); void sourceChanged();
void mirrorChanged(); void mirrorChanged();
void sourceSizeChanged(); void sourceSizeChanged();
void graphicRoleChanged();
void alignmentChanged(); void alignmentChanged();
void fillModeChanged(); void fillModeChanged();

View File

@ -173,11 +173,6 @@ QColor QskSkin::color( QskAspect::Aspect aspect ) const
return skinHint( aspect | QskAspect::Color ).value<QColor>(); return skinHint( aspect | QskAspect::Color ).value<QColor>();
} }
QColor QskSkin::baseColor() const
{
return color( QskAspect::Control | QskAspect::Color );
}
void QskSkin::setMetric( QskAspect::Aspect aspect, qreal metric ) void QskSkin::setMetric( QskAspect::Aspect aspect, qreal metric )
{ {
setSkinHint( aspect | QskAspect::Metric, metric ); setSkinHint( aspect | QskAspect::Metric, metric );

View File

@ -61,7 +61,6 @@ public:
void setColor( QskAspect::Aspect, const QColor& ); void setColor( QskAspect::Aspect, const QColor& );
QColor color( QskAspect::Aspect ) const; QColor color( QskAspect::Aspect ) const;
QColor baseColor() const;
void setMetric( QskAspect::Aspect, qreal metric ); void setMetric( QskAspect::Aspect, qreal metric );
qreal metric( QskAspect::Aspect ) const; qreal metric( QskAspect::Aspect ) const;

View File

@ -93,6 +93,44 @@ QskTextOptions QskTextLabel::textOptions() const
return m_data->textOptions; return m_data->textOptions;
} }
void QskTextLabel::setFontRole( int role )
{
const int oldRole = fontRole();
QskSkinnable::setFontRole( effectiveSubcontrol( Text ), role );
if ( oldRole != role )
{
resetImplicitSize();
update();
Q_EMIT fontRoleChanged();
}
}
int QskTextLabel::fontRole() const
{
return QskSkinnable::fontRole( Text );
}
void QskTextLabel::setTextColor( const QColor& color )
{
const QColor oldColor = textColor();
QskSkinnable::setColor( effectiveSubcontrol( Text ), color );
if ( oldColor != color )
{
update();
Q_EMIT textColorChanged();
}
}
QColor QskTextLabel::textColor() const
{
return QskSkinnable::color( Text );
}
Qt::Alignment QskTextLabel::alignment() const Qt::Alignment QskTextLabel::alignment() const
{ {
return flagHint< Qt::Alignment >( return flagHint< Qt::Alignment >(

View File

@ -16,6 +16,12 @@ class QSK_EXPORT QskTextLabel : public QskControl
Q_PROPERTY( QString text READ text WRITE setText NOTIFY textChanged ) Q_PROPERTY( QString text READ text WRITE setText NOTIFY textChanged )
Q_PROPERTY( int fontRole READ fontRole
WRITE setFontRole NOTIFY fontRoleChanged )
Q_PROPERTY( QColor textColor READ textColor
WRITE setTextColor NOTIFY textColorChanged )
Q_PROPERTY( QskTextOptions textOptions READ textOptions Q_PROPERTY( QskTextOptions textOptions READ textOptions
WRITE setTextOptions NOTIFY textOptionsChanged ) WRITE setTextOptions NOTIFY textOptionsChanged )
@ -34,6 +40,12 @@ public:
QString text() const; QString text() const;
void setFontRole( int role );
int fontRole() const;
void setTextColor( const QColor& );
QColor textColor() const;
void setTextOptions( const QskTextOptions& ); void setTextOptions( const QskTextOptions& );
QskTextOptions textOptions() const; QskTextOptions textOptions() const;
@ -51,7 +63,9 @@ public:
Q_SIGNALS: Q_SIGNALS:
void textChanged( const QString& ); void textChanged( const QString& );
void textColorChanged();
void textOptionsChanged(); void textOptionsChanged();
void fontRoleChanged();
void alignmentChanged(); void alignmentChanged();
public Q_SLOTS: public Q_SLOTS: