1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
/***************************************************************************
wlabel.cpp - description
-------------------
begin : Wed Jan 5 2005
copyright : (C) 2003 by Tue Haste Andersen
email : haste@diku.dk
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "widget/wlabel.h"
#include <QFont>
#include "widget/wskincolor.h"
WLabel::WLabel(QWidget* pParent)
: QLabel(pParent),
WBaseWidget(this),
m_skinText(),
m_longText() {
}
WLabel::~WLabel() {
}
void WLabel::setup(QDomNode node, const SkinContext& context) {
// Colors
QPalette pal = palette(); //we have to copy out the palette to edit it since it's const (probably for threadsafety)
if (context.hasNode(node, "BgColor")) {
m_qBgColor.setNamedColor(context.selectString(node, "BgColor"));
pal.setColor(this->backgroundRole(), WSkinColor::getCorrectColor(m_qBgColor));
setAutoFillBackground(true);
}
m_qFgColor.setNamedColor(context.selectString(node, "FgColor"));
pal.setColor(this->foregroundRole(), WSkinColor::getCorrectColor(m_qFgColor));
setPalette(pal);
// Text
if (context.hasNode(node, "Text")) {
m_skinText = context.selectString(node, "Text");
setText(m_skinText);
}
// Font size
if (context.hasNode(node, "FontSize")) {
int fontsize = context.selectString(node, "FontSize").toInt();
setFont(QFont("Helvetica", fontsize, QFont::Normal));
}
// Alignment
if (context.hasNode(node, "Alignment")) {
if (context.selectString(node, "Alignment").toLower() == "right") {
setAlignment(Qt::AlignRight | Qt::AlignVCenter);
} else if (context.selectString(node, "Alignment").toLower() == "center") {
setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
} else if (context.selectString(node, "Alignment").toLower() == "left") {
setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
}
}
}
QString WLabel::text() const {
return m_longText;
}
void WLabel::setText(const QString& text) {
m_longText = text;
QFontMetrics metrics(font());
QString elidedText = metrics.elidedText(m_longText, Qt::ElideRight, width());
QLabel::setText(elidedText);
}
bool WLabel::event(QEvent* pEvent) {
if (pEvent->type() == QEvent::ToolTip) {
updateTooltip();
}
return QLabel::event(pEvent);
}
void WLabel::resizeEvent(QResizeEvent* event) {
QLabel::resizeEvent(event);
setText(m_longText);
}
void WLabel::fillDebugTooltip(QStringList* debug) {
WBaseWidget::fillDebugTooltip(debug);
*debug << QString("Text: \"%1\"").arg(text());
}
|