From d209bd5116f97650f9260ccdb62acbb5a89916c5 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Fri, 9 Oct 2015 15:22:56 -0400 Subject: 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. --- .../applauncher/OutlineToolButton.h | 61 ++++++++++++++-------- 1 file changed, 39 insertions(+), 22 deletions(-) (limited to 'lumina-desktop/desktop-plugins/applauncher') 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 #include #include +#include + 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