mirror of
https://github.com/gamecreature/QtAwesome.git
synced 2024-11-15 13:35:44 +08:00
Added support for different glyphs per icon-mode, via the configuration options text-*.
This commit is contained in:
parent
214301c788
commit
fe2b3e2002
@ -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();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
12
README.md
12
README.md
@ -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
|
||||||
-------
|
-------
|
||||||
|
Loading…
Reference in New Issue
Block a user