summaryrefslogtreecommitdiffstats
path: root/src/kbfxplasmacanvasgroup.cpp
blob: fe48427cc6adfdab621e7fa530d19dbd3c8ac0cf (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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/*
 *   Copyright (C) 2006
 *   Siraj Razick <[email protected]>
 *   PhobosK <[email protected]>
 *   see Also AUTHORS
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License version 2 as
 *   published by the Free Software Foundation
 *
 *   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 Library 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.
 */

#include "kbfxplasmacanvasgroup.h"

KbfxPlasmaCanvasGroup::KbfxPlasmaCanvasGroup ()
{

	m_height = 0;
	m_id = 0;
// m_count = 0;
	m_name = TQString ( "Unknown" );
//  bool m_visible = true;
	m_shaded = false;
}

KbfxPlasmaCanvasGroup::~KbfxPlasmaCanvasGroup ()
{
	for ( ItemListIter it ( m_itemList ); *it; ++it )
	{
//qDebug("Trying to delete Item from Rgoup================");
//	if(*it)
//		delete (*it);
//	      itemListMap ().remove (*it);
		if ( ( *it ) != 0 )
			if ( deleteItem ( ( *it ) ) == false )
			{
				qDebug ( "Deleting failed" );
			}
	}


}

KbfxPlasmaCanvasGroup::ItemListMap & KbfxPlasmaCanvasGroup::itemListMap ()
{
	static ItemListMap *
	map = 0;
	if ( !map )
		map = new ItemListMap ();
	return *map;
}

bool
KbfxPlasmaCanvasGroup::deleteItem ( KbfxPlasmaCanvasAbstractItem * it )
{
//qDebug("Removing Item from Group");
// itemListMap ().remove (it);
	//delete it;
//return true;
	for ( ItemListIter iti ( m_itemList ); *iti; ++iti )
	{
		if ( iti == it )
		{
			itemListMap ().remove ( *iti );
			if ( m_itemList.removeRef ( it ) )
			{
				if ( m_itemList.isEmpty () )
					delete this;
				return true;
			}
			else
			{
				qDebug ( "deleting Item failed" );
				return false;
			}
		}
	}
	return false;
}

bool
KbfxPlasmaCanvasGroup::addItem ( KbfxPlasmaCanvasAbstractItem * it )
{

	if ( it->name().isEmpty() )
	{
		qDebug ( "Adding Failed bcos Name Missing" );
		return false;
	}
	ItemListMap::ConstIterator itn = itemListMap ().find ( it );
	if ( itn != itemListMap ().end () )
	{
		qDebug ( "Adding Failed Due to Item not end" );
		return false;
	}
	for ( ItemListIter itr ( m_itemList ); *itr; ++itr )
	{
		if ( ( *itr )->lookup ( it->name() ) == true )
		{
			qDebug ( "Adding Failed Due to Item already exisits" );
			return false;
		}
	}


	int _x = 0;
	int _y = this->boundingRect ().height ();
	KbfxPlasmaCanvasGroup *&group = itemListMap () [it];
	if ( group )
	{
		if ( group == this )
			return true;
		group->m_itemList.removeRef ( it );
		if ( group->m_itemList.isEmpty () )
			delete group;
	}
	m_itemList.prepend ( it );
	m_height += it->height();
	m_width = it->width();
	it->move ( _x, _y );
	group = this;

	if ( it->type() == KbfxPlasmaCanvasAbstractItem::SEPARATOR )
		m_sepheight  = it->height();
	m_count++;
	return true;
}


void
KbfxPlasmaCanvasGroup::move ( int x, int y )
{

	for ( ItemListIter it ( m_itemList ); *it; ++it )
	{
		( *it )->move ( ( *it )->x () + x, ( *it )->y () + y );
	}


}

void
KbfxPlasmaCanvasGroup::moveBy ( int x, int y )
{

	for ( ItemListIter it ( m_itemList ); *it; ++it )
	{
		( *it )->move ( x, y );
	}
}

void
KbfxPlasmaCanvasGroup::hide()
{

	for ( ItemListIter it ( m_itemList ); *it; ++it )
	{
//	if(*it)
		( *it )->hide();
	}
	m_visible = false;


}

void
KbfxPlasmaCanvasGroup::setGroupName ( TQString name )
{
	m_name = name;
// 	delete [] name;
}

TQString
KbfxPlasmaCanvasGroup::name()
{
	return m_name;
}

void
KbfxPlasmaCanvasGroup::showAll()
{
	for ( ItemListIter it ( m_itemList ); *it; ++it )
	{
		if ( ( *it )->type() == KbfxPlasmaCanvasAbstractItem::SEPARATOR || m_shaded == false )
			( *it )->show();
	}

}

void
KbfxPlasmaCanvasGroup::show()
{
	for ( ItemListIter it ( m_itemList ); *it; ++it )
	{
		if ( ( *it )->type() == KbfxPlasmaCanvasAbstractItem::SEPARATOR || m_shaded == false )
			( *it )->show();
	}
	m_visible = true;
}

void
KbfxPlasmaCanvasGroup::shade ()
{
	if ( m_shaded == false )
	{
		emit this->groupShade ( this->groupID() );

		for ( ItemListIter it ( m_itemList ); *it; ++it )
		{
			//  (*it)->move ((*it)->x (), 0);
			if ( ( *it )->type() != KbfxPlasmaCanvasAbstractItem::SEPARATOR )
				( *it )->hide();
		}
		m_shaded = true;
		return;
	}
	else if ( m_shaded == true )
	{
		int _shadeby = 0;
		int _firstItemHeight=0;

		emit this->groupUnShade ( this->groupID() );

		for ( ItemListIter it ( m_itemList ); *it; ++it )
		{
			if ( ( *it )->type() != KbfxPlasmaCanvasAbstractItem::SEPARATOR )
			{
//	      (*it)->move ((*it)->x (), _shadeby);
				( *it )->show();
				_shadeby += ( *it )->height ();
			}
			else
			{
				_shadeby = ( *it )->height ();
				_firstItemHeight = _shadeby;

			}
		}
		m_shaded = false;
	}
}

void
KbfxPlasmaCanvasGroup::moveUp ( int y )
{

	for ( ItemListIter it ( m_itemList ); *it; ++it )
	{
		( *it )->move ( ( *it )->x (), ( ( *it )->y () +m_sepheight ) - y );
	}


}

void
KbfxPlasmaCanvasGroup::moveDown ( int y )
{

	for ( ItemListIter it ( m_itemList ); *it; ++it )
	{
		( *it )->move ( ( *it )->x (), ( ( *it )->y () - m_sepheight ) + y );
	}
}

TQRect
KbfxPlasmaCanvasGroup::boundingRect ()
{
	if ( this->count () == 0 )
		return TQRect ( 0, 0, 0, 0 );

	TQRect r;
	for ( ItemListIter it ( m_itemList ); *it; ++it )
		r |= ( *it )->boundingRect ();
	return r;
}

int
KbfxPlasmaCanvasGroup::count ()
{

	return m_itemList.count();
}

int
KbfxPlasmaCanvasGroup::height ()
{

	return   m_height ;
}

int
KbfxPlasmaCanvasGroup::width ()
{

	return m_width;
}


KbfxPlasmaCanvasGroup *
KbfxPlasmaCanvasGroup::groupContaining ( KbfxPlasmaCanvasAbstractItem * item )
{
	ItemListMap::ConstIterator it = itemListMap ().find ( item );
	if ( it == itemListMap ().end () )
		return 0;
	else
		return *it;
}

uint
KbfxPlasmaCanvasGroup::groupID()
{
	return m_id;
}


void KbfxPlasmaCanvasGroup::setGroupID ( uint e_id )
{
	m_id = e_id;
}

#include "kbfxplasmacanvasgroup.moc"