summaryrefslogtreecommitdiffstats
path: root/kregexpeditor/KMultiFormListBox/tdemultiformlistbox-windowed.cpp
blob: a366ad150d13e2486c753e0d1007d8abefc79974 (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
/*
 *  Copyright (c) 2002-2003 Jesper K. Pedersen <[email protected]>
 *
 *  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.
 **/
#ifdef TQT_ONLY
  #include "compat.h"
#else
  #include <tdemessagebox.h>
  #include <kpushbutton.h>
  #include <kstdguiitem.h>
  #include "tdemultiformlistbox-windowed.moc"
#endif

#include "widgetwindow.h"
#include "windowlistboxitem.h"

KMultiFormListBoxWindowed::KMultiFormListBoxWindowed(KMultiFormListBoxFactory *factory, TQWidget *parent,
																	 bool showUpDownButtons, bool showHelpButton,
																	 TQString addButtonText,const char *name)
  : TQWidget( parent, name )
{
  _layout = new TQVBoxLayout(this);

	TQHBoxLayout *innerLayout = new TQHBoxLayout();
	_layout->addLayout(innerLayout);

  _listbox = new TDEListBox(this,"listbox");
  _listbox->setSelectionMode(TQListBox::Single);
  innerLayout->addWidget(_listbox);

  TQVBoxLayout *buttons = new TQVBoxLayout();
  innerLayout->addLayout(buttons);

  TQPushButton *but = new TQPushButton(addButtonText, this,"Add Button");
  buttons->addWidget(but,0);
  connect(but, TQ_SIGNAL(clicked()), this, TQ_SLOT(addNewElement()));

  but = new TQPushButton(i18n("Edit"), this,"Edit Button");
  buttons->addWidget(but,0);
  connect(but,TQ_SIGNAL(clicked()), this, TQ_SLOT(slotEditSelected()));
  connect(_listbox, TQ_SIGNAL(doubleClicked(TQListBoxItem *)), this, TQ_SLOT(slotEditSelected(TQListBoxItem *)));
	_buttonList.append(but);

  but = new TQPushButton(i18n("Delete"), this, "Delete Button");
  buttons->addWidget(but,0);
  connect(but, TQ_SIGNAL(clicked()), this, TQ_SLOT(slotDeleteEntry()));
	_buttonList.append(but);

  but = new TQPushButton(i18n("Copy"), this, "Copy Button");
  buttons->addWidget(but,0);
  connect(but, TQ_SIGNAL(clicked()), this, TQ_SLOT(slotCopySelected()));
	_buttonList.append(but);

	if (showUpDownButtons) {
		but = new TQPushButton(i18n("Up"), this, "Up Button");
		buttons->addWidget(but, 0);
		connect(but, TQ_SIGNAL(clicked()), this, TQ_SLOT(slotMoveItemUp()));
		_buttonList.append(but);

		but = new TQPushButton(i18n("Down"), this, "Down Button");
		buttons->addWidget(but, 0);
		connect(but, TQ_SIGNAL(clicked()), this, TQ_SLOT(slotMoveItemDown()));
		_buttonList.append(but);
	}

	if (showHelpButton) {
		but = new KPushButton(KStdGuiItem::help(), this, "Help Button");
		buttons->addWidget(but, 0);
		connect(but, TQ_SIGNAL(clicked()), this, TQ_SIGNAL(showHelp()));
	}

  buttons->addStretch(1);
  _factory = factory;
	slotUpdateButtonState();

}

KMultiFormListBoxEntryList KMultiFormListBoxWindowed::elements()
{
  KMultiFormListBoxEntryList list;
  for (unsigned int i=0; i < _listbox->count(); i++) {
    WindowListboxItem *item = (WindowListboxItem *) _listbox->item(i);
    list.append(item->entry());
  }
  return list;
}

void KMultiFormListBoxWindowed::delElement(TQWidget */*elm*/)
{
    // kdDebug() << "KMultiFormListBoxWindowed::delElement NOT YET IMPLEMENTED"<<endl;
	// TODO
}

void KMultiFormListBoxWindowed::delAnElement()
{
    // kdDebug() << "KMultiFormListBoxWindowed::delAnElement NOT YET IMPLEMENTED"<<endl;
  // TODO
}


void KMultiFormListBoxWindowed::append(KMultiFormListBoxEntry *elm)
{
  (void) new WidgetWindow(_factory, elm, _listbox);
	slotUpdateButtonState();
}

void KMultiFormListBoxWindowed::addNewElement()
{
	// kdDebug() << "addNewElement " << _factory << "," << _listbox << endl;

  TQWidget *widget = new WidgetWindow(_factory, _listbox);
	widget->show();
	connect(widget, TQ_SIGNAL(finished()), this, TQ_SLOT(slotUpdateButtonState()));
}

void KMultiFormListBoxWindowed::addElement()
{
  new WidgetWindow(_factory, _listbox);
	slotUpdateButtonState();
}

void KMultiFormListBoxWindowed::slotEditSelected(TQListBoxItem *item)
{
  ((WindowListboxItem *) item)->displayWidget();
}

void KMultiFormListBoxWindowed::slotEditSelected()
{
  WindowListboxItem *item = selected();
  if (item) {
    slotEditSelected(item);
  }
}

void KMultiFormListBoxWindowed::slotDeleteEntry()
{
  WindowListboxItem *item = selected();
  if (item) {
		int answer =
			KMessageBox::warningContinueCancel(0, i18n("Delete item \"%1\"?").arg(item->text()),i18n("Delete Item"),KStdGuiItem::del());
		if (answer == KMessageBox::Continue) {
			delete item;
			slotUpdateButtonState();
		}
  }
}

void KMultiFormListBoxWindowed::slotCopySelected()
{
  WindowListboxItem *item = selected();
  if (item) {
    item->clone();
  }
}

WindowListboxItem *KMultiFormListBoxWindowed::selected()
{
  int i = _listbox->currentItem();
  if (i == -1) {
    return 0;
  } else {
    return (WindowListboxItem *) _listbox->item(i);
  }
}

void KMultiFormListBoxWindowed::slotMoveItemUp()
{
	WindowListboxItem *item = selected();
	if (item == 0)
		return;

	int index = _listbox->index(item);
	if (index != 0) {
		_listbox->takeItem(item);
		_listbox->insertItem(item, index-1);
		_listbox->setCurrentItem(item);
	}
}

void KMultiFormListBoxWindowed::slotMoveItemDown()
{
	WindowListboxItem *item = selected();
	if (item == 0)
		return;

	unsigned int index = _listbox->index(item);
	if (index < _listbox->count()) {
		_listbox->takeItem(item);
		_listbox->insertItem(item, index+1);
		_listbox->setCurrentItem(item);
	}
}

void KMultiFormListBoxWindowed::slotUpdateButtonState()
{
	bool on = (_listbox->count() != 0);
	for (unsigned int i=0; i<_buttonList.count(); i++) {
		_buttonList.at(i)->setEnabled(on);
	}
}