introducing high level APIs for setting of font and graphic roles for
Text/Graphic-Label
This commit is contained in:
parent
3c40903ea9
commit
a57915c6f0
|
@ -12,6 +12,8 @@ public:
|
|||
IndicatorLabel( QQuickItem* parentItem = nullptr ):
|
||||
QskGraphicLabel( parentItem )
|
||||
{
|
||||
// so the skins are able to colorize them
|
||||
setGraphicRole( SkinFactory::Indicator );
|
||||
}
|
||||
|
||||
virtual QskAspect::Subcontrol effectiveSubcontrol(
|
||||
|
@ -43,9 +45,6 @@ void ButtonBar::addIndicator( const char* name )
|
|||
{
|
||||
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
|
||||
according to its aspect ratio.
|
||||
|
|
|
@ -30,9 +30,8 @@ public:
|
|||
QskTextLabel( text, parent )
|
||||
{
|
||||
setBackgroundColor( Qt::black );
|
||||
setColor( QskTextLabel::Text, Qt::white );
|
||||
|
||||
setFontRole( Text, QskSkin::MediumFont );
|
||||
setTextColor( Qt::white );
|
||||
setFontRole( QskSkin::MediumFont );
|
||||
|
||||
QskTextOptions textOptions;
|
||||
textOptions.setWrapMode( QskTextOptions::WordWrap );
|
||||
|
|
|
@ -42,19 +42,18 @@ public:
|
|||
{
|
||||
using namespace QskAspect;
|
||||
|
||||
const QskAspect::Aspect aspectRole = QskGraphicLabel::Graphic | GraphicRole;
|
||||
const int oldRole = graphicRole( aspectRole );
|
||||
const int oldRole = graphicRole();
|
||||
|
||||
QColor color;
|
||||
if ( on )
|
||||
{
|
||||
color.setRgb( 40, 40, 40 );
|
||||
setGraphicRole( aspectRole, Inverted );
|
||||
setGraphicRole( Inverted );
|
||||
}
|
||||
else
|
||||
{
|
||||
color.setRgb( 255, 228, 181 );
|
||||
setGraphicRole( aspectRole, Normal );
|
||||
setGraphicRole( Normal );
|
||||
}
|
||||
|
||||
const int duration = 500;
|
||||
|
@ -68,7 +67,8 @@ public:
|
|||
startTransition( aspectColor, duration, oldColor, color );
|
||||
}
|
||||
|
||||
startTransition( aspectRole, duration, oldRole, graphicRole( aspectRole ) );
|
||||
const QskAspect::Aspect aspectRole = QskGraphicLabel::Graphic | GraphicRole;
|
||||
startTransition( aspectRole, duration, oldRole, graphicRole() );
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -25,9 +25,8 @@ public:
|
|||
Label( const QString& text, QQuickItem* parent = nullptr ):
|
||||
QskTextLabel( text, parent )
|
||||
{
|
||||
setColor( Text, Qt::darkRed );
|
||||
|
||||
setFontRole( Text, QskSkin::LargeFont );
|
||||
setTextColor( Qt::darkRed );
|
||||
setFontRole( QskSkin::LargeFont );
|
||||
setAlignment( Qt::AlignCenter );
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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[] )
|
||||
{
|
||||
#ifdef ITEM_STATISTICS
|
||||
|
@ -123,20 +140,10 @@ int main( int argc, char* argv[] )
|
|||
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->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;
|
||||
window.resize( 600, 600 );
|
||||
window.setColor( "SteelBlue" );
|
||||
|
|
|
@ -6,16 +6,12 @@
|
|||
#include <SkinnyFont.h>
|
||||
#include <SkinnyShortcut.h>
|
||||
|
||||
#include <QskAspect.h>
|
||||
#include <QskModule.h>
|
||||
#include <QskObjectCounter.h>
|
||||
#include <QskSkin.h>
|
||||
#include <QskLinearBox.h>
|
||||
#include <QskTextLabel.h>
|
||||
#include <QskWindow.h>
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QFont>
|
||||
|
||||
class TextBox: public QskLinearBox
|
||||
{
|
||||
|
@ -29,7 +25,7 @@ public:
|
|||
for ( int i = 0; i < texts.size(); i++ )
|
||||
{
|
||||
auto label = new QskTextLabel( texts[i] + " Font", this );
|
||||
label->setFontRole( QskTextLabel::Text, i );
|
||||
label->setFontRole( i );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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
|
||||
{
|
||||
// can be removed once we can store a filter inidividually
|
||||
|
|
|
@ -22,6 +22,9 @@ class QSK_EXPORT QskGraphicLabel : public QskControl
|
|||
Q_PROPERTY( QSize sourceSize READ sourceSize
|
||||
WRITE setSourceSize RESET resetSourceSize NOTIFY sourceSizeChanged )
|
||||
|
||||
Q_PROPERTY( int graphicRole READ graphicRole
|
||||
WRITE setGraphicRole NOTIFY graphicRoleChanged )
|
||||
|
||||
Q_PROPERTY( Qt::Alignment alignment READ alignment
|
||||
WRITE setAlignment NOTIFY alignmentChanged )
|
||||
|
||||
|
@ -80,10 +83,14 @@ public:
|
|||
|
||||
bool isEmpty() const;
|
||||
|
||||
void setGraphicRole( int role );
|
||||
int graphicRole() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void sourceChanged();
|
||||
void mirrorChanged();
|
||||
void sourceSizeChanged();
|
||||
void graphicRoleChanged();
|
||||
void alignmentChanged();
|
||||
void fillModeChanged();
|
||||
|
||||
|
|
|
@ -173,11 +173,6 @@ QColor QskSkin::color( QskAspect::Aspect aspect ) const
|
|||
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 )
|
||||
{
|
||||
setSkinHint( aspect | QskAspect::Metric, metric );
|
||||
|
|
|
@ -61,7 +61,6 @@ public:
|
|||
void setColor( QskAspect::Aspect, const QColor& );
|
||||
|
||||
QColor color( QskAspect::Aspect ) const;
|
||||
QColor baseColor() const;
|
||||
|
||||
void setMetric( QskAspect::Aspect, qreal metric );
|
||||
qreal metric( QskAspect::Aspect ) const;
|
||||
|
|
|
@ -93,6 +93,44 @@ QskTextOptions QskTextLabel::textOptions() const
|
|||
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
|
||||
{
|
||||
return flagHint< Qt::Alignment >(
|
||||
|
|
|
@ -16,6 +16,12 @@ class QSK_EXPORT QskTextLabel : public QskControl
|
|||
|
||||
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
|
||||
WRITE setTextOptions NOTIFY textOptionsChanged )
|
||||
|
||||
|
@ -34,6 +40,12 @@ public:
|
|||
|
||||
QString text() const;
|
||||
|
||||
void setFontRole( int role );
|
||||
int fontRole() const;
|
||||
|
||||
void setTextColor( const QColor& );
|
||||
QColor textColor() const;
|
||||
|
||||
void setTextOptions( const QskTextOptions& );
|
||||
QskTextOptions textOptions() const;
|
||||
|
||||
|
@ -51,7 +63,9 @@ public:
|
|||
|
||||
Q_SIGNALS:
|
||||
void textChanged( const QString& );
|
||||
void textColorChanged();
|
||||
void textOptionsChanged();
|
||||
void fontRoleChanged();
|
||||
void alignmentChanged();
|
||||
|
||||
public Q_SLOTS:
|
||||
|
|
Loading…
Reference in New Issue