summaryrefslogtreecommitdiffstats
path: root/kregexpeditor/KMultiFormListBox/kmultiformlistbox.cpp
blob: 58b82dadf9902994293627b826bcad8234489663 (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
/*
 *  Copyright (c) 2002-2003 Jesper K. Pedersen <blackie@kde.org>
 *
 *  This library 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 library 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
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 **/
#ifndef TQT_ONLY
  #include "kmultiformlistbox.moc"
#endif

#include "kmultiformlistbox-multivisible.h"
#include "kmultiformlistbox-windowed.h"

KMultiFormListBox::KMultiFormListBox( KMultiFormListBoxFactory *factory, KMultiFormListBoxType tp, TQWidget *parent,
																		  bool showUpDownButtons, bool showHelpButton, TQString addButtonText,
																		  const char *name )  : TQWidget( parent, name )
{
	switch ( tp ) {

	case MultiVisible:
    theWidget = new KMultiFormListBoxMultiVisible( factory, this, "KMultiFormListBox Widget" );
		break;

	case Windowed:
    theWidget = new KMultiFormListBoxWindowed( factory, this, showUpDownButtons,
																							 showHelpButton, addButtonText, "KMultiFormListBox Widget" );
		break;
	}

  TQWidget *widget = theWidget->qWidget();

  TQHBoxLayout *layout = new TQHBoxLayout( this );
	_factory = factory;
  layout->addWidget( widget );
}

void KMultiFormListBox::append( KMultiFormListBoxEntry *element )
{
  theWidget->append( element );
}

void KMultiFormListBox::addElement()
{
  theWidget->addElement();
}

KMultiFormListBoxEntryList KMultiFormListBox::elements()
{
  return theWidget->elements();
}

const KMultiFormListBoxEntryList KMultiFormListBox::elements() const
{
  return const_cast<KMultiFormListBox*>(this)->elements();
}

void KMultiFormListBox::slotChangeFace( KMultiFormListBoxType /*newFace*/ )
{
	// TODO
	// kdDebug() << "It's not possible yet to change the face on the fly." << endl
	//					<< "Please let me (blackie@kde.org) know that you need it, and I'll work on it" << endl;
}

void KMultiFormListBox::toStream( TQDataStream& stream ) const
{
  const KMultiFormListBoxEntryList elms = elements();
  stream << elms.count();
  for ( TQPtrListIterator<KMultiFormListBoxEntry> it(elms); *it; ++it)
    _factory->toStream( TQT_TQOBJECT(*it), stream );
}

void KMultiFormListBox::fromStream( TQDataStream& stream )
{
  unsigned int fromCount, toCount;
  stream >> fromCount;

  toCount = elements().count();

  // adds/remove elements in the to list, to make it have the correct length.
  for (unsigned int j=toCount; j< fromCount; ++j) {
    addElement();
  }
  for (unsigned int k=fromCount; k < toCount; ++k) {
    theWidget->delAnElement();
  }

  KMultiFormListBoxEntryList elms = elements();
  for (TQPtrListIterator<KMultiFormListBoxEntry> it(elms); *it; ++it)
    _factory->fromStream( stream, TQT_TQOBJECT(*it) );
}