summaryrefslogtreecommitdiffstats
path: root/src/arkollon/headerlistitem.cpp
blob: 0c30b390d27138d7f6dbaae8a7a161fc88533101 (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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/***************************************************************************
 *   Copyright (C) 2004 by David Sansome                                   *
 *   [email protected]                                                   *
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "headerlistitem.h"

#include <tqfontmetrics.h>
#include <tqpainter.h>
#include <tqapplication.h>

#include "uninstallwizard.h"
#include "wizard.h"

HeaderListItem::HeaderListItem(TQListView* parent)
 : TQListViewItem(parent)
{
}

int HeaderListItem::compare(TQListViewItem* i, int col, bool ascending) const
{
	switch (i->rtti())
	{
		case 1001: // Component
		{
			ComponentListItem* item = (ComponentListItem*) i;
			if (section > item->section)
				return 1;
			return -1;
		}
		
		case 1003: // App
		{
			AppListItem* item = (AppListItem*) i;
			if (section > item->section)
				return 1;
			return -1;
		}
		
		case 1002: // Header
		{
			HeaderListItem* item = (HeaderListItem*) i;
			if (section > item->section)
				return 1;
			if (section < item->section)
				return -1;
			return 0;
		}
	}
	return 0;
}

void HeaderListItem::paintCell(TQPainter* p, const TQColorGroup& cg, int column, int width, int align)
{
	p->fillRect(0, 0, width, height(), cg.base());
	
	TQFont boldFont = p->font();
	boldFont.setBold(true);
	p->setFont(boldFont);
	p->drawText(listView()->itemMargin(), listView()->itemMargin(), width, TQFontMetrics(boldFont).height(), TQt::AlignLeft, text(0));
	
	int textWidth = TQFontMetrics(boldFont).width(text(0));
	p->fillRect(0, height() - 4 - listView()->itemMargin(), textWidth-10, 4, cg.highlight());
	
	TQColor ca = cg.highlight();
	TQColor cb = cg.base();
	// Taken from KPixmapEffect::gradient
	int rDiff, gDiff, bDiff;
	int rca, gca, bca /*, rcb, gcb, bcb*/;
	
	register int x, y;
	
	rDiff = (/*rcb = */ cb.red())   - (rca = ca.red());
	gDiff = (/*gcb = */ cb.green()) - (gca = ca.green());
	bDiff = (/*bcb = */ cb.blue())  - (bca = ca.blue());
	
	register int rl = rca << 16;
	register int gl = gca << 16;
	register int bl = bca << 16;
	
	int rcdelta = ((1<<16) / 20) * rDiff;
	int gcdelta = ((1<<16) / 20) * gDiff;
	int bcdelta = ((1<<16) / 20) * bDiff;
	for( int x = textWidth-10; x < textWidth+10; x++)
	{
		rl += rcdelta;
		gl += gcdelta;
		bl += bcdelta;
	
		p->setPen(TQColor(rl>>16, gl>>16, bl>>16));
		p->drawLine(x, height() - 4 - listView()->itemMargin(), x, height() - listView()->itemMargin() - 1);
	}
}

void HeaderListItem::paintFocus(TQPainter* p, const TQColorGroup& cg, const TQRect& r)
{
}

int HeaderListItem::width(const TQFontMetrics& fm, const TQListView* lv, int c) const
{
	TQFont boldFont = tqApp->font();
	boldFont.setBold(true);
	TQFontMetrics metrics(boldFont);
	return metrics.width(text(0)) + lv->itemMargin() + 10;
}

void HeaderListItem::setup()
{
	setHeight(tqApp->fontMetrics().height() + listView()->itemMargin()*3 + 4);
}