diff options
author | Ken Moore <moorekou@gmail.com> | 2015-10-12 08:28:50 -0400 |
---|---|---|
committer | Ken Moore <moorekou@gmail.com> | 2015-10-12 08:28:50 -0400 |
commit | a36ff0e157d98953da50b47fd0e532f47a47b828 (patch) | |
tree | dc3596ad6cbab6dfeeee9080f7ab7d96696db786 /lumina-desktop/desktop-plugins | |
parent | Tweak the desktop icon font outlines a bit - make them slightly easier to read. (diff) | |
download | lumina-a36ff0e157d98953da50b47fd0e532f47a47b828.tar.gz lumina-a36ff0e157d98953da50b47fd0e532f47a47b828.tar.bz2 lumina-a36ff0e157d98953da50b47fd0e532f47a47b828.zip |
A few more tweaks for the applauncher outlines. Now they are much more readable in all situations/backgrounds, as well as accounting for the change in thickness to ensure that the text is not cut off at the edge of the box.
Diffstat (limited to 'lumina-desktop/desktop-plugins')
-rw-r--r-- | lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp | 10 | ||||
-rw-r--r-- | lumina-desktop/desktop-plugins/applauncher/OutlineToolButton.h | 13 |
2 files changed, 15 insertions, 8 deletions
diff --git a/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp b/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp index 0335b650..cf7f84d4 100644 --- a/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp +++ b/lumina-desktop/desktop-plugins/applauncher/AppLauncherPlugin.cpp @@ -2,6 +2,8 @@ #include "../../LSession.h" #include "OutlineToolButton.h" +#define OUTMARGIN 8 //special margin for fonts due to the outlining effect from the OutlineToolbutton + AppLauncherPlugin::AppLauncherPlugin(QWidget* parent, QString ID) : LDPlugin(parent, ID){ QVBoxLayout *lay = new QVBoxLayout(); this->setLayout(lay); @@ -92,7 +94,7 @@ void AppLauncherPlugin::loadButton(){ //this->setFixedSize(bwid, icosize+qRound(2.5*button->fontMetrics().height()) ); //make sure to adjust the button on first show. //if(onchange){ this->adjustSize( bwid+4, icosize+8+qRound(2.5*button->fontMetrics().height())); } //qDebug() << "Initial Button Text:" << txt << icosize; - if(button->fontMetrics().width(txt) > (button->width()-2) ){ + if(button->fontMetrics().width(txt) > (button->width()-OUTMARGIN) ){ //int dash = this->fontMetrics().width("-"); //Text too long, try to show it on two lines txt = txt.section(" ",0,2).replace(" ","\n"); //First take care of any natural breaks @@ -101,13 +103,13 @@ void AppLauncherPlugin::loadButton(){ QStringList txtL = txt.split("\n"); for(int i=0; i<txtL.length(); i++){ if(i>1){ txtL.removeAt(i); i--; } //Only take the first two lines - else{ txtL[i] = button->fontMetrics().elidedText(txtL[i], Qt::ElideRight, (button->width()-2) ); } + else{ txtL[i] = button->fontMetrics().elidedText(txtL[i], Qt::ElideRight, (button->width()-OUTMARGIN) ); } } txt = txtL.join("\n"); }else{ - txt = this->fontMetrics().elidedText(txt,Qt::ElideRight, 2*button->width() -4); + txt = this->fontMetrics().elidedText(txt,Qt::ElideRight, 2*(button->width()-OUTMARGIN)); //Now split the line in half for the two lines - txt.insert( (txt.count()/2), "\n"); + txt.insert( ((txt.count()-2)/2), "\n"); } } if(!txt.contains("\n")){ txt.append("\n "); } //always use two lines diff --git a/lumina-desktop/desktop-plugins/applauncher/OutlineToolButton.h b/lumina-desktop/desktop-plugins/applauncher/OutlineToolButton.h index ecec3ea6..7a0f28cf 100644 --- a/lumina-desktop/desktop-plugins/applauncher/OutlineToolButton.h +++ b/lumina-desktop/desktop-plugins/applauncher/OutlineToolButton.h @@ -24,6 +24,11 @@ class OutlineToolButton : public QToolButton{ Q_OBJECT public: OutlineToolButton(QWidget *parent=0) : QToolButton(parent){ + //This button needs slightly different font settings - do this in the constructor so that other widgets can take it into account. + QFont font = this->font(); + font.setStyleStrategy(QFont::PreferAntialias); //Always set the font strategy (just in case it starts working down the road) + font.setWeight(70); //need a slightly heavier weight due to outlining later + this->setFont(font); } ~OutlineToolButton(){} @@ -41,7 +46,7 @@ protected: QStyleOptionToolButton opt; initStyleOption(&opt); opt.font.setStyleStrategy(QFont::PreferAntialias); //Always set the font strategy (just in case it starts working down the road) - opt.font.setWeight(2.5*opt.font.weight()); //need a slightly heavier weight due to outlining later + opt.font.setWeight(65); //need a slightly heavier weight due to outlining later opt.text.clear(); //Don't paint the text yet - just the background/icon p.drawComplexControl(QStyle::CC_ToolButton, opt); //This does all the normal QToolButton stuff - just not text //Now get the text rectangle for the widget @@ -50,8 +55,8 @@ protected: QColor textC = opt.palette.text().color().toHsl(); //need the lightness value in a moment QColor outC = textC; //qDebug() << "Font Color Values:" << textC << textC.lightness() << textC.lightnessF(); - if(textC.lightnessF() > 0.5){ outC.setHsl(textC.hue(), textC.hslSaturation(), 0); } - else{outC.setHsl(textC.hue(), textC.hslSaturation(), 255); } //1000% lighter + if(textC.lightnessF() > 0.5){ outC.setHsl(textC.hue(), textC.hslSaturation(), 0, 80); } + else{outC.setHsl(textC.hue(), textC.hslSaturation(), 255, 80); } //qDebug() << "Outline Color Values:" << outC; //Now generate a QPainterPath for the text QPainterPath path; @@ -62,7 +67,7 @@ protected: path.setFillRule(Qt::WindingFill); //Now paint the text p.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); //need antialiasing for this to work well (sub-pixel painting) - p.strokePath(path, QPen(outC) ); //This will be the outline - 1pixel thick + p.strokePath(path, QPen(QBrush(outC),1.8, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin) ); //This will be the outline - 1pixel thick, semi-transparent p.fillPath(path, QBrush(textC)); //this will be the inside/text color } |