summaryrefslogtreecommitdiff
path: root/noncore/applets/keyhelper/keyhelperapplet/extension/MenuTitle.cpp
blob: d8fd2a393bcfe7b6a70c09d71ce8f1a386413c03 (plain)
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
#include "MenuTitle.h"

MenuTitle::MenuTitle(const QString& s, const QFont& f, const QString& k)
{
	font = f;
	kind = k;

	ConfigEx& cfg = ConfigEx::getInstance("keyhelper");

	const QString curGroup = cfg.getGroup();
	cfg.setGroup("Style");

	caption = cfg.readEntry("Caption_" + k, s);
	cfg.setGroup(curGroup);
}

bool MenuTitle::fullSpan() const
{
	return(true);
}

bool MenuTitle::isSeparator() const
{
	return(true);
}

void MenuTitle::paint(QPainter* p, const QColorGroup& cg, bool /*act*/,
		bool /*enabled*/, int x, int y, int w, int h)
{
	ConfigEx& cfg = ConfigEx::getInstance("keyhelper");
	const QString& curGroup = cfg.getGroup();

	cfg.setGroup("Style");

	QString name;
	QColor color;

	p->setFont(font);

	/* set fontcolor */
	name = cfg.readEntry("FontColor_" + kind, QString::null);
	if(name != QString::null){
		color.setNamedColor(name);
		if(color.isValid()){
			p->setPen(color);
		}
	}

	/* set bgcolor */
	name = cfg.readEntry("BgColor_" + kind, QString::null);
	if(name != QString::null){
		color.setNamedColor(name);
		if(color.isValid() == false){
			color = cg.mid();
		}
	} else {
		color = cg.mid();
	}
	p->fillRect(x, y, w, h, QBrush(color));
	p->drawText(x, y, w, h, AlignCenter, caption);
	cfg.setGroup(curGroup);
}

QSize MenuTitle::sizeHint()
{
	return(QFontMetrics(font).size(AlignCenter, caption));
}