28
28
Label::Label(QGraphicsWidget *parent)
29
29
: QGraphicsWidget(parent)
31
setMinimumHeight(QFontMetrics(font()).lineSpacing() + 4);
32
setMaximumHeight(QFontMetrics(font()).lineSpacing() + 4);
31
QFontMetrics fm(font());
32
setMinimumHeight(fm.height() + 4);
33
setMaximumHeight(fm.height() + 4);
33
34
setCacheMode(DeviceCoordinateCache);
67
const QString text = QFontMetrics(font()).elidedText(m_text, Qt::ElideMiddle, contentsRect().width());
72
shadowColor = Qt::transparent;
73
shadowOffset = QPoint();
74
} else if (qGray(palette().color(QPalette::Text).rgb()) > 192) {
75
shadowColor = Qt::black;
76
shadowOffset = QPoint(1, 1);
78
shadowColor = Qt::white;
79
shadowOffset = QPoint();
82
QPixmap titlePixmap = Plasma::PaintUtils::shadowText(text, palette().color(QPalette::Text),
83
shadowColor, shadowOffset);
84
painter->drawPixmap(contentsRect().topLeft(), titlePixmap);
86
int width = contentsRect().width();
89
if (m_divider.width() != width) {
90
qreal fw = 1.0 / width * 20.0;
91
m_divider = QPixmap(width, 2);
92
m_divider.fill(Qt::transparent);
93
QLinearGradient g(0, 0, width, 0);
94
g.setColorAt(0, Qt::transparent);
95
g.setColorAt(fw, Qt::black);
96
g.setColorAt(1 - fw, Qt::black);
97
g.setColorAt(1, Qt::transparent);
98
QPainter p(&m_divider);
99
p.setCompositionMode(QPainter::CompositionMode_Source);
100
p.fillRect(0, 0, width, 1, QColor(0, 0, 0, 64));
101
p.fillRect(0, 1, width, 1, QColor(255, 255, 255, 64));
102
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
103
p.fillRect(m_divider.rect(), g);
105
painter->drawPixmap(0, contentsRect().height() - 2, m_divider);
68
QColor color = palette().color(QPalette::Text);
71
QFontMetrics fm(font());
72
const QString text = fm.elidedText(m_text, Qt::ElideMiddle, contentsRect().width());
75
painter->setFont(font());
76
painter->setPen(color);
77
painter->drawText(contentsRect(), Qt::AlignCenter, text);
108
81
#include "label.moc"