1 /***************************************************************************
2  *   copyright       : (C) 2003-2017 by Pascal Brachet                     *
3  *   http://www.xm1math.net/texmaker/                                      *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  ***************************************************************************/
11 
12 
13 #include <QPainter>
14 #include <QFont>
15 #include <QApplication>
16 #include "dropshadowlabel.h"
17 
DropShadowLabel(const QString & text,QWidget * parent)18 DropShadowLabel::DropShadowLabel(const QString &text,QWidget* parent) :
19 	QLabel(text,parent)
20 {
21     setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
22 
23     setFont(QFont("DejaVu Sans Condensed",qApp->font().pointSize()));
24 }
25 
drawText(QPainter * painter,QPoint offset)26 void DropShadowLabel::drawText(QPainter *painter,
27 								 QPoint offset)
28 {
29 	Q_ASSERT(painter != 0);
30 
31 	// Draw shadow.
32 	painter->setPen(QPen(textColor));
33 	painter->drawText(rect().translated(offset),
34 					  alignment(), text());
35 }
drawTextEffect(QPainter * painter,QPoint offset)36 void DropShadowLabel::drawTextEffect(QPainter *painter,
37 								 QPoint offset)
38 {
39 	Q_ASSERT(painter != 0);
40 
41 	// Draw shadow.
42 	painter->setPen(QPen(dropShadowColor));
43 	painter->drawText(rect().translated(offset),
44 					  alignment(), text());
45 }
46 
paintEvent(QPaintEvent * event)47 void DropShadowLabel::paintEvent(QPaintEvent *event)
48 {
49 	Q_UNUSED(event);
50 
51 	QPainter painter(this);
52 	painter.setFont(font());
53 #ifndef Q_OS_MAC
54 	drawTextEffect(&painter, QPoint(contentsMargins().left(), 1));
55 #endif
56 	drawText(&painter, QPoint(contentsMargins().left(), 0));
57 }
58 
setColor(const QColor & color)59 void DropShadowLabel::setColor(const QColor & color)
60 {
61 	textColor = color;
62 }
63 
setDropShadowColor(const QColor & color)64 void DropShadowLabel::setDropShadowColor(const QColor & color)
65 {
66 	dropShadowColor = color;
67 }
68