diff --git a/QtAwesome/QtAwesome.cpp b/QtAwesome/QtAwesome.cpp index 1dbfea8..d82fdf2 100644 --- a/QtAwesome/QtAwesome.cpp +++ b/QtAwesome/QtAwesome.cpp @@ -28,12 +28,26 @@ public: // set the correct color QColor color = options.value("color").value(); + QString text = options.value("text").toString(); + if( mode == QIcon::Disabled ) { color = options.value("color-disabled").value(); + QVariant alt = options.value("text-disabled"); + if( alt.isValid() ) { + text = alt.toString(); + } } else if( mode == QIcon::Active ) { color = options.value("color-active").value(); + QVariant alt = options.value("text-active"); + if( alt.isValid() ) { + text = alt.toString(); + } } else if( mode == QIcon::Selected ) { color = options.value("color-selected").value(); + QVariant alt = options.value("text-selected"); + if( alt.isValid() ) { + text = alt.toString(); + } } painter->setPen(color); @@ -41,7 +55,7 @@ public: int drawSize = qRound(rect.height()*options.value("scale-factor").toFloat()); 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(); } @@ -111,6 +125,11 @@ QtAwesome::QtAwesome( QObject* parent ) setDefaultOption( "color-selected", QColor(10,10,10)); setDefaultOption( "scale-factor", 0.9 ); + setDefaultOption( "text", QVariant() ); + setDefaultOption( "text-disabled", QVariant() ); + setDefaultOption( "text-active", QVariant() ); + setDefaultOption( "text-selected", QVariant() ); + fontIconPainter_ = new QtAwesomeCharIconPainter(); } diff --git a/README.md b/README.md index 9a9b902..9eaa5f3 100644 --- a/README.md +++ b/README.md @@ -108,12 +108,24 @@ setDefaultOption( "color", QColor(50,50,50) ); setDefaultOption( "color-disabled", QColor(70,70,70,60)); setDefaultOption( "color-active", 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 ); ``` 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. + + 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 -------