diff options
author | Ken Moore <moorekou@gmail.com> | 2015-10-09 15:22:56 -0400 |
---|---|---|
committer | Ken Moore <moorekou@gmail.com> | 2015-10-09 15:22:56 -0400 |
commit | d209bd5116f97650f9260ccdb62acbb5a89916c5 (patch) | |
tree | 8010f643c9ad357190f8ac638f67f231bc578454 /lumina-desktop/desktop-plugins/applauncher | |
parent | Split up the desktop-plugin source files into a separate desktop-plugins.pri ... (diff) | |
download | lumina-d209bd5116f97650f9260ccdb62acbb5a89916c5.tar.gz lumina-d209bd5116f97650f9260ccdb62acbb5a89916c5.tar.bz2 lumina-d209bd5116f97650f9260ccdb62acbb5a89916c5.zip |
Convert the applauncher deskto plugin to automatically use outlined fonts for any text. This still needs a bit of tweaking, but overall seems to work quite well.
Diffstat (limited to 'lumina-desktop/desktop-plugins/applauncher')
-rw-r--r-- | lumina-desktop/desktop-plugins/applauncher/OutlineToolButton.h | 61 |
1 files changed, 39 insertions, 22 deletions
diff --git a/lumina-desktop/desktop-plugins/applauncher/OutlineToolButton.h b/lumina-desktop/desktop-plugins/applauncher/OutlineToolButton.h index 1e71658d..65a2edec 100644 --- a/lumina-desktop/desktop-plugins/applauncher/OutlineToolButton.h +++ b/lumina-desktop/desktop-plugins/applauncher/OutlineToolButton.h @@ -17,41 +17,58 @@ #include <QStyleOption> #include <QStylePainter> #include <QFont> +#include <QDebug> + class OutlineToolButton : public QToolButton{ Q_OBJECT public: OutlineToolButton(QWidget *parent=0) : QToolButton(parent){ - QFont font = this->font(); - font.setStyleStrategy(QFont::ForceOutline);// | QFont::PreferQuality); - this->setFont(font); } ~OutlineToolButton(){} protected: void paintEvent(QPaintEvent*){ - - //QPainter painter(this); - //QPainterPath path; - //QPen pen; - //pen.setWidth(2); - //pen.setColor(Qt::red); - //painter.setFont(this->font()); - //painter.setPen(pen); - //path.addText(10 , 60, this->font(), this->text()); //Adjust the position - //painter.drawPath(path); - QFont font = this->font(); - font.setStyleStrategy(QFont::ForceOutline);// | QFont::PreferQuality); - //This is what a QToolButton performs + /* NOTE: This is what a standard QToolButton performs (peeked at Qt source code for this tidbit) + QStylePainter p(this); + QStyleOptionToolButton opt; + initStyleOption(&opt); + p.drawComplexControl(QStyle::CC_ToolButton, opt); + */ + + //Modify the standard QToolButton routine to paint the text differently QStylePainter p(this); - //p.setPen(pen); QStyleOptionToolButton opt; initStyleOption(&opt); - opt.font = font; //Use the font which forces outlines - //p.style()->drawControl(QStyle::CE_ToolButtonLabel, &opt, &p, this); //this does the outline underneath - p.drawComplexControl(QStyle::CC_ToolButton, opt); //This does the normal painting on top - //Now do the normal paint event over the top - //QToolButton::paintEvent(ev); + opt.font.setStyleStrategy(QFont::PreferAntialias); //Always set the font strategy (just in case it starts working down the road) + opt.font.setWeight(2*opt.font.weight()); //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 + QRect box = p.style()->itemTextRect(opt.fontMetrics, opt.rect, Qt::AlignHCenter | Qt::AlignBottom, true, this->text()); + //Get the QColors for the outline/text + /*QColor textC = opt.palette.text().color().toHsl(); //need the lightness value in a moment + QColor outC; + qDebug() << "Font Color Values:" << textC << textC.lightness() << textC.lightnessF(); + if(textC.lightnessF() > 0.5){ outC = textC.darker(1000); } //1000% darker + else{ outC = textC.lighter(1000); } //1000% lighter + qDebug() << "Outline Color Values:" << outC;*/ + //Now generate a QPainterPath for the text + QPainterPath path; + QStringList txt = this->text().split("\n"); //need each line independently, the newline actually gets painted otherwise + for(int i=0; i<txt.length(); i++){ + path.addText(box.center().x() - (opt.fontMetrics.width(txt[i])/2), box.y()+((i+1)*(box.height()/txt.length()))-opt.fontMetrics.descent(), opt.font, txt[i] ); + } + path.setFillRule(Qt::WindingFill); + //Now paint them + p.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); + p.strokePath(path, QPen(QColor(Qt::white)));//outC)) ); //This will be the outline - 1pixel thick + p.fillPath(path, QBrush(Qt::black));//textC)); //this will be the inside/text color + + + /*opt.font.setWeight(50); //reset back to the normal text size + opt.palette = QPalette(Qt::white); + p.drawControl(QStyle::CE_ToolButtonLabel, opt); //don't do the full background on top again - just the labels (icon/text)*/ } }; |