21 #include <tqstringlist.h>
22 #include <tqpushbutton.h>
24 #include <tqgroupbox.h>
25 #include <tqlistbox.h>
26 #include <tqwhatsthis.h>
29 #include <kcombobox.h>
32 #include <klineedit.h>
34 #include <tdeapplication.h>
35 #include <knotifyclient.h>
37 #include "keditlistbox.h"
41 class KEditListBoxPrivate
44 bool m_checkAtEntering;
49 bool checkAtEntering,
int buttons )
50 :TQGroupBox(parent, name ), d(new KEditListBoxPrivate)
52 init( checkAtEntering, buttons );
56 const char *name,
bool checkAtEntering,
int buttons)
57 :TQGroupBox(title, parent, name ), d(new KEditListBoxPrivate)
59 init( checkAtEntering, buttons );
63 TQWidget *parent,
const char *name,
64 bool checkAtEntering,
int buttons)
65 :TQGroupBox(title, parent, name ), d(new KEditListBoxPrivate)
67 m_lineEdit = custom.lineEdit();
68 init( checkAtEntering, buttons, custom.representationWidget() );
71 KEditListBox::~KEditListBox()
76 void KEditListBox::init(
bool checkAtEntering,
int buttons,
77 TQWidget *representationWidget )
79 d->m_checkAtEntering = checkAtEntering;
81 servNewButton = servRemoveButton = servUpButton = servDownButton = 0L;
82 setSizePolicy(TQSizePolicy(TQSizePolicy::MinimumExpanding,
83 TQSizePolicy::MinimumExpanding));
85 TQGridLayout * grid =
new TQGridLayout(
this, 7, 2,
88 grid->addRowSpacing(0, fontMetrics().lineSpacing());
89 grid->setRowStretch( 6, 1 );
93 if ( representationWidget )
94 representationWidget->reparent(
this, TQPoint(0,0) );
98 m_listBox =
new TQListBox(
this);
100 TQWidget *editingWidget = representationWidget ?
101 representationWidget : m_lineEdit;
102 grid->addMultiCellWidget(editingWidget,1,1,0,1);
103 grid->addMultiCellWidget(m_listBox, 2, 6, 0, 0);
108 connect(m_lineEdit,TQT_SIGNAL(textChanged(
const TQString&)),
this,TQT_SLOT(typedSomething(
const TQString&)));
110 connect(m_lineEdit,TQT_SIGNAL(returnPressed()),
this,TQT_SLOT(addItem()));
111 connect(m_listBox, TQT_SIGNAL(highlighted(
int)), TQT_SLOT(enableMoveButtons(
int)));
114 typedSomething( m_lineEdit->text() );
119 if ( d->buttons == buttons )
122 TQGridLayout* grid =
static_cast<TQGridLayout *
>( layout() );
123 if ( ( buttons & Add ) && !servNewButton ) {
124 servNewButton =
new TQPushButton(i18n(
"&Add"),
this);
125 servNewButton->setEnabled(
false);
126 servNewButton->show();
127 connect(servNewButton, TQT_SIGNAL(clicked()), TQT_SLOT(addItem()));
129 grid->addWidget(servNewButton, 2, 1);
130 }
else if ( ( buttons & Add ) == 0 && servNewButton ) {
131 delete servNewButton;
135 if ( ( buttons & Remove ) && !servRemoveButton ) {
136 servRemoveButton =
new TQPushButton(i18n(
"&Remove"),
this);
137 servRemoveButton->setEnabled(
false);
138 servRemoveButton->show();
139 connect(servRemoveButton, TQT_SIGNAL(clicked()), TQT_SLOT(removeItem()));
141 grid->addWidget(servRemoveButton, 3, 1);
142 }
else if ( ( buttons & Remove ) == 0 && servRemoveButton ) {
143 delete servRemoveButton;
144 servRemoveButton = 0;
147 if ( ( buttons & UpDown ) && !servUpButton ) {
148 servUpButton =
new TQPushButton(i18n(
"Move &Up"),
this);
149 servUpButton->setEnabled(
false);
150 servUpButton->show();
151 connect(servUpButton, TQT_SIGNAL(clicked()), TQT_SLOT(moveItemUp()));
153 servDownButton =
new TQPushButton(i18n(
"Move &Down"),
this);
154 servDownButton->setEnabled(
false);
155 servDownButton->show();
156 connect(servDownButton, TQT_SIGNAL(clicked()), TQT_SLOT(moveItemDown()));
158 grid->addWidget(servUpButton, 4, 1);
159 grid->addWidget(servDownButton, 5, 1);
160 }
else if ( ( buttons & UpDown ) == 0 && servUpButton ) {
161 delete servUpButton; servUpButton = 0;
162 delete servDownButton; servDownButton = 0;
168 void KEditListBox::typedSomething(
const TQString& text)
176 bool block = m_listBox->signalsBlocked();
177 m_listBox->blockSignals(
true );
179 m_listBox->blockSignals( block );
184 if ( !servNewButton )
187 if (!d->m_checkAtEntering)
188 servNewButton->setEnabled(!text.isEmpty());
193 servNewButton->setEnabled(
false);
197 StringComparisonMode mode = (StringComparisonMode) (ExactMatch |
CaseSensitive );
198 bool enable = (!m_listBox->findItem( text, mode ));
199 servNewButton->setEnabled( enable );
204 void KEditListBox::moveItemUp()
206 if (!m_listBox->isEnabled())
212 const unsigned int selIndex = m_listBox->currentItem();
219 TQListBoxItem *selItem = m_listBox->item(selIndex);
220 m_listBox->takeItem(selItem);
221 m_listBox->insertItem(selItem, selIndex-1);
222 m_listBox->setCurrentItem(selIndex - 1);
227 void KEditListBox::moveItemDown()
229 if (!m_listBox->isEnabled())
235 unsigned int selIndex = m_listBox->currentItem();
236 if (selIndex == m_listBox->count() - 1)
242 TQListBoxItem *selItem = m_listBox->item(selIndex);
243 m_listBox->takeItem(selItem);
244 m_listBox->insertItem(selItem, selIndex+1);
245 m_listBox->setCurrentItem(selIndex + 1);
250 void KEditListBox::addItem()
255 if ( !servNewButton || !servNewButton->isEnabled() )
258 const TQString& currentTextLE=m_lineEdit->text();
259 bool alreadyInList(
false);
261 if (!d->m_checkAtEntering)
264 if ( m_listBox->currentText() == currentTextLE )
265 alreadyInList =
true;
268 StringComparisonMode mode = (StringComparisonMode) (ExactMatch |
CaseSensitive );
269 alreadyInList =(m_listBox->findItem(currentTextLE, mode) );
274 servNewButton->setEnabled(
false);
276 bool block = m_lineEdit->signalsBlocked();
277 m_lineEdit->blockSignals(
true);
279 m_lineEdit->blockSignals(block);
285 block = m_listBox->signalsBlocked();
286 m_listBox->blockSignals(
true );
287 m_listBox->insertItem(currentTextLE);
288 m_listBox->blockSignals( block );
290 emit
added( currentTextLE );
296 int nr = m_listBox->currentItem();
297 if(nr >= 0 && !m_listBox->item(nr)->isSelected())
return -1;
301 void KEditListBox::removeItem()
303 int selected = m_listBox->currentItem();
307 TQString removedText = m_listBox->currentText();
309 m_listBox->removeItem( selected );
311 m_listBox->setSelected( TQMIN( selected,
count() - 1 ),
true );
317 if ( servRemoveButton && m_listBox->currentItem() == -1 )
318 servRemoveButton->setEnabled(
false);
321 void KEditListBox::enableMoveButtons(
int index)
327 bool moveEnabled = servUpButton && servDownButton;
331 if (m_listBox->count() <= 1)
333 servUpButton->setEnabled(
false);
334 servDownButton->setEnabled(
false);
336 else if ((uint) index == (m_listBox->count() - 1))
338 servUpButton->setEnabled(
true);
339 servDownButton->setEnabled(
false);
343 servUpButton->setEnabled(
false);
344 servDownButton->setEnabled(
true);
348 servUpButton->setEnabled(
true);
349 servDownButton->setEnabled(
true);
353 if ( servRemoveButton )
354 servRemoveButton->setEnabled(
true);
366 m_listBox->insertStringList(list,index);
371 m_listBox->insertStrList(list,index);
376 m_listBox->insertStrList(list,index);
381 m_listBox->insertStrList(list,numStrings,index);
387 for (TQListBoxItem
const * i = m_listBox->firstItem(); i != 0; i = i->next() )
388 list.append( i->text());
396 m_listBox->insertStringList(items, 0);
404 void KEditListBox::virtual_hook(
int,
void* )
411 KEditListBox::CustomEditor::CustomEditor(
KComboBox *combo )
413 m_representationWidget = combo;
414 m_lineEdit = tqt_dynamic_cast<
KLineEdit*>( combo->lineEdit() );
415 assert( m_lineEdit );
418 #include "keditlistbox.moc"
static int marginHint()
Return the number of pixels you shall use between a dialog edge and the outermost widget(s) according...
int currentItem() const
See TQListBox::currentItem()
void beep(const TQString &reason=TQString::null)
virtual void clear()
Reimplemented to workaround a buggy TQLineEdit::clear() (changing the clipboard to the text we just h...
void insertStringList(const TQStringList &list, int index=-1)
See TQListBox::insertStringList()
TQString currentText() const
See TQListBox::currentText()
void removed(const TQString &text)
This signal is emitted when the user removes a string from the list, the parameter is the removed str...
void added(const TQString &text)
This signal is emitted when the user adds a new string to the list, the parameter is the added string...
static int spacingHint()
Return the number of pixels you shall use between widgets inside a dialog according to the KDE standa...
int count() const
See TQListBox::count()
void setButtons(uint buttons)
Specifies which buttons should be visible.
void insertStrList(const TQStrList *list, int index=-1)
See TQListBox::insertStringList()
void setTrapReturnKey(bool trap)
By default, KLineEdit recognizes Key_Return and Key_Enter and emits the returnPressed() signals...
KEditListBox(TQWidget *parent=0, const char *name=0, bool checkAtEntering=false, int buttons=All)
Create an editable listbox.
int buttons() const
Returns which buttons are visible.
void setItems(const TQStringList &items)
Clears the listbox and sets the contents to items.
An enhanced TQLineEdit widget for inputting text.
void clear()
Clears both the listbox and the line edit.
TQStringList items() const
virtual void setText(const TQString &)
Re-implemented to enable text squeezing.