Added support for different glyphs per icon-mode, via the configuration options text-*.

This commit is contained in:
Rick Blommers 2013-06-07 14:52:42 +02:00
parent 214301c788
commit fe2b3e2002
2 changed files with 32 additions and 1 deletions

View File

@ -28,12 +28,26 @@ public:
// set the correct color // set the correct color
QColor color = options.value("color").value<QColor>(); QColor color = options.value("color").value<QColor>();
QString text = options.value("text").toString();
if( mode == QIcon::Disabled ) { if( mode == QIcon::Disabled ) {
color = options.value("color-disabled").value<QColor>(); color = options.value("color-disabled").value<QColor>();
QVariant alt = options.value("text-disabled");
if( alt.isValid() ) {
text = alt.toString();
}
} else if( mode == QIcon::Active ) { } else if( mode == QIcon::Active ) {
color = options.value("color-active").value<QColor>(); color = options.value("color-active").value<QColor>();
QVariant alt = options.value("text-active");
if( alt.isValid() ) {
text = alt.toString();
}
} else if( mode == QIcon::Selected ) { } else if( mode == QIcon::Selected ) {
color = options.value("color-selected").value<QColor>(); color = options.value("color-selected").value<QColor>();
QVariant alt = options.value("text-selected");
if( alt.isValid() ) {
text = alt.toString();
}
} }
painter->setPen(color); painter->setPen(color);
@ -41,7 +55,7 @@ public:
int drawSize = qRound(rect.height()*options.value("scale-factor").toFloat()); int drawSize = qRound(rect.height()*options.value("scale-factor").toFloat());
painter->setFont( awesome->font(drawSize) ); painter->setFont( awesome->font(drawSize) );
painter->drawText( rect, options.value("text").toString(), QTextOption( Qt::AlignCenter|Qt::AlignVCenter ) ); painter->drawText( rect, text, QTextOption( Qt::AlignCenter|Qt::AlignVCenter ) );
painter->restore(); painter->restore();
} }
@ -111,6 +125,11 @@ QtAwesome::QtAwesome( QObject* parent )
setDefaultOption( "color-selected", QColor(10,10,10)); setDefaultOption( "color-selected", QColor(10,10,10));
setDefaultOption( "scale-factor", 0.9 ); setDefaultOption( "scale-factor", 0.9 );
setDefaultOption( "text", QVariant() );
setDefaultOption( "text-disabled", QVariant() );
setDefaultOption( "text-active", QVariant() );
setDefaultOption( "text-selected", QVariant() );
fontIconPainter_ = new QtAwesomeCharIconPainter(); fontIconPainter_ = new QtAwesomeCharIconPainter();
} }

View File

@ -108,12 +108,24 @@ setDefaultOption( "color", QColor(50,50,50) );
setDefaultOption( "color-disabled", QColor(70,70,70,60)); setDefaultOption( "color-disabled", QColor(70,70,70,60));
setDefaultOption( "color-active", QColor(10,10,10)); setDefaultOption( "color-active", QColor(10,10,10));
setDefaultOption( "color-selected", QColor(10,10,10)); setDefaultOption( "color-selected", QColor(10,10,10));
setDefaultOption( "text", QString() ); // internal option
setDefaultOption( "text-disabled", QString() );
setDefaultOption( "text-active", QString() );
setDefaultOption( "text-selected", QString() );
setDefaultOption( "scale-factor", 0.9 ); setDefaultOption( "scale-factor", 0.9 );
``` ```
When creating an icon, it first populates the options-map with the default options from the QtAwesome object. When creating an icon, it first populates the options-map with the default options from the QtAwesome object.
After that the options are expanded/overwritten by the options supplied to the icon. After that the options are expanded/overwritten by the options supplied to the icon.
It is possible to use another glyph per icon-state. For example to make an icon-unlock symbol switch to locked when selected,
you could supply the following option.
```c++
options.insert("text-selected", QString( icon_lock ) );
```
License License
------- -------