summaryrefslogtreecommitdiffstats
path: root/src/kvirc/ui/kvi_listview.cpp
blob: 7665287e248eb3aa6a1f616a6cdde9c74d834526 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
///////////////////////////////////////////////////////////////////////////////
//
//   File : kvi_listview.cpp
//   Creation date : 19  Jan 2006 GMT by Alexey Uzhva
//
//   This toolbar is part of the KVirc irc client distribution
//   Copyright (C) 2006 Alexey Uzhva
//   Copyright (C) 2006 Szymon Stefanek (pragma at kvirc dot net)
//
//   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 opinion) 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. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
///////////////////////////////////////////////////////////////////////////////

#define __KVIRC__

#include "kvi_listview.h"

#include <tqpainter.h>
#include <tqpixmap.h>

#include "kvi_doublebuffer.h"

KviListView::KviListView( TQWidget * tqparent, const char * name)
:KviTalListView(tqparent)
{
	m_pBackgroundOverlayPixmap=0;
	m_iBackgroundOverlayAlignment=TQt::AlignAuto;
}

KviListView::~KviListView()
{
	if(m_pBackgroundOverlayPixmap)
		delete m_pBackgroundOverlayPixmap;
}

void KviListView::setBackgroundOverlayPixmap(TQPixmap * pix,int iAlignmentFlags)
{
	setStaticBackground(TRUE);
#ifdef COMPILE_USE_QT4
	viewport()->setAutoFillBackground(false);
#else
	viewport()->setBackgroundMode(TQWidget::NoBackground);
#endif
	m_pBackgroundOverlayPixmap=new TQPixmap(*pix);
	m_iBackgroundOverlayAlignment= TQt::AlignRight | TQt::AlignBottom;
	tqrepaintContents();
}



void KviListView::drawContentsOffset(TQPainter * p,int ox,int oy,int cx,int cy,int cw,int ch)
{
	if(!m_pBackgroundOverlayPixmap)
	{
		KviTalListView::drawContentsOffset(p,ox,oy,cx,cy,cw,ch);
		return;
	}

	if(cw <= 0)return; // this does happen
	if(ch <= 0)return; // this does happen

	KviDoubleBuffer pix(viewport()->width(),viewport()->height());

	TQPixmap * pMemPixmap = pix.pixmap();

	TQPainter pa(pMemPixmap);

	int xx = cx - ox;
	int yy = cy - oy;

	pa.fillRect(TQRect(xx,yy,cw,ch),viewport()->backgroundColor());

	//KviTalListView::paintEmptyArea(&pa,);

	// compute the pixmap position
	int x,y;
	if(m_iBackgroundOverlayAlignment == TQt::AlignAuto)
		x=y=0;
	else {
		if(m_iBackgroundOverlayAlignment & TQt::AlignLeft)
			x=0;
		else if ( m_iBackgroundOverlayAlignment & TQt::AlignRight )
			x=viewport()->width() - m_pBackgroundOverlayPixmap->width();
		else if( m_iBackgroundOverlayAlignment & TQt::AlignHCenter )
			x=(viewport()->width() - m_pBackgroundOverlayPixmap->width())/2;
		else
			x=0;
		
		if( m_iBackgroundOverlayAlignment & TQt::AlignTop )
			y=0;
		else if ( m_iBackgroundOverlayAlignment & TQt::AlignBottom )
			y=viewport()->height() - m_pBackgroundOverlayPixmap->height();
		else if ( m_iBackgroundOverlayAlignment & TQt::AlignVCenter )
			y=(viewport()->height() - m_pBackgroundOverlayPixmap->height())/2;
		else
			y=0;
	}

	pa.drawPixmap(xx,yy,*m_pBackgroundOverlayPixmap,xx-x,yy-y,cw,ch);

	// TQt's auto double buffering is buggy and can't be disabled... too bad :/
	//
	// The TQt source for the listview painting is also totally unreadable
	// (maybe that's why they have thrown this cool widget away in TQt4: unmantainable)
	//
	// Anyway, I've noticed that when double buffering is choosen (and
	// TQt seems to have a really complex logic to choose when to enable it
	// and when not) then the painter passed to paintCell() of the
	// list view items is NOT this painter. It's the internal painter
	// of the TQSharedDoubleBuffer private TQt class. It's screwed
	// because of the multiple coordinate translations. With this
	// widget we screw it even more just because our paintEmptyArea()
	// does nothing and we do double buffering ourselves.
	
	KviTalListView::drawContentsOffset(&pa,ox,oy,cx,cy,cw,ch);

	p->drawPixmap(xx,yy,*pMemPixmap,xx,yy,cw,ch);

	//p->drawPixmap(cx-ox,cy-oy,*pMemPixmap,0,0,cw,ch);
	//KviTalListView::drawContentsOffset(p,ox,oy,cx,cy,cw,ch);
}


void KviListView::paintEmptyArea(TQPainter * p,const TQRect & rect)
{
	if(!m_pBackgroundOverlayPixmap)
	{
		KviTalListView::paintEmptyArea(p,rect);
		return;
	}

	// otherwise just do nothing (we're filling the background in drawContentsOffset)

	/*
	KviDoubleBuffer pix(rect.right()+1,rect.bottom()+1);

	TQPixmap * pMemPixmap = pix.pixmap();

	TQPainter pa(pMemPixmap);

	pa.fillRect(rect,viewport()->backgroundColor());

	KviTalListView::paintEmptyArea(&pa,rect);
	
	TQPoint realTopLeft = p->xForm(rect.topLeft());

	// compute the pixmap position
	int x,y;
	if(m_iBackgroundOverlayAlignment == TQt::AlignAuto)
		x=y=0;
	else {
		if(m_iBackgroundOverlayAlignment & TQt::AlignLeft)
			x=0;
		else if ( m_iBackgroundOverlayAlignment & TQt::AlignRight )
			x=viewport()->width() - m_pBackgroundOverlayPixmap->width();
		else if( m_iBackgroundOverlayAlignment & TQt::AlignHCenter )
			x=(viewport()->width() - m_pBackgroundOverlayPixmap->width())/2;
		else
			x=0;
		
		if( m_iBackgroundOverlayAlignment & TQt::AlignTop )
			y=0;
		else if ( m_iBackgroundOverlayAlignment & TQt::AlignBottom )
			y=viewport()->height() - m_pBackgroundOverlayPixmap->height();
		else if ( m_iBackgroundOverlayAlignment & TQt::AlignVCenter )
			y=(viewport()->height() - m_pBackgroundOverlayPixmap->height())/2;
		else
			y=0;
	}

	pa.drawPixmap(rect.x(),rect.y(),*m_pBackgroundOverlayPixmap,realTopLeft.x()-x,realTopLeft.y()-y,rect.width(),rect.height());

	p->drawPixmap(rect.x(),rect.y(),*pMemPixmap,rect.x(),rect.y(),rect.width(),rect.height());
	*/
}

void KviListView::resizeEvent(TQResizeEvent * e)
{
	KviTalListView::resizeEvent(e);
	if(m_pBackgroundOverlayPixmap)
	tqrepaintContents(); // force a full tqrepaint (otherwise qt does not honor static background here)
}

#ifdef COMPILE_ON_WINDOWS

void KviListView::focusInEvent(TQFocusEvent * e)
{
	KviTalListView::focusInEvent(e);
	if(m_pBackgroundOverlayPixmap)
		tqrepaintContents(); 
}

void KviListView::focusOutEvent(TQFocusEvent * e)
{
	KviTalListView::focusOutEvent(e);
	if(m_pBackgroundOverlayPixmap)
		tqrepaintContents(); 
}

#endif