00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include "editlist.h"
00021
00022
#include <klistbox.h>
00023
#include <kpushbutton.h>
00024
#include <qlayout.h>
00025
#include <klocale.h>
00026
#include <kiconloader.h>
00027
#include <kguiitem.h>
00028
00029 EditList::EditList(
QWidget *parent,
const char *name)
00030 :
QWidget(parent, name)
00031 {
00032 list_ =
new KListBox(
this);
00033 addbtn_ =
new KPushButton(KGuiItem(i18n(
"Add..."),
"filenew"),
this);
00034 editbtn_ =
new KPushButton(KGuiItem(i18n(
"Edit..."),
"edit"),
this);
00035 delbtn_ =
new KPushButton(KGuiItem(i18n(
"Delete"),
"editdelete"),
this);
00036 defbtn_ =
new KPushButton(KGuiItem(i18n(
"Default List"),
"history"),
this);
00037
00038
QGridLayout *m1 =
new QGridLayout(
this, 4, 2, 0, 0);
00039 m1->
setColStretch(0, 1);
00040 m1->
addMultiCellWidget(list_, 0, 3, 0, 1);
00041 m1->
addWidget(addbtn_, 0, 1);
00042 m1->
addWidget(editbtn_, 1, 1);
00043 m1->
addWidget(delbtn_, 2, 1);
00044 m1->
addWidget(defbtn_, 3, 1);
00045
00046 connect(addbtn_, SIGNAL(clicked()), SIGNAL(add()));
00047 connect(editbtn_, SIGNAL(clicked()), SLOT(slotEdit()));
00048 connect(delbtn_, SIGNAL(clicked()), SLOT(slotDelete()));
00049 connect(defbtn_, SIGNAL(clicked()), SIGNAL(defaultList()));
00050 connect(list_, SIGNAL(highlighted(
int)), SLOT(slotSelected(
int)));
00051 slotSelected(-1);
00052 }
00053
00054
void EditList::slotEdit()
00055 {
00056
int index = list_->currentItem();
00057
if (index >= 0)
00058 emit edit(index);
00059 }
00060
00061
void EditList::slotDelete()
00062 {
00063
int index = list_->currentItem();
00064 list_->removeItem(index);
00065 slotSelected((list_->count() > 0 ? list_->currentItem() : -1));
00066 emit deleted(index);
00067 }
00068
00069
void EditList::slotSelected(
int index)
00070 {
00071 editbtn_->setEnabled(index >= 0);
00072 delbtn_->setEnabled(index >= 0);
00073 }
00074
00075
QString EditList::text(
int index)
00076 {
00077
return list_->text(index);
00078 }
00079
00080
void EditList::setText(
int index,
const QString& s)
00081 {
00082
if (list_->text(index) != s)
00083 {
00084
QListBoxItem *it = list_->findItem(s, Qt::ExactMatch);
00085
if (!it)
00086 list_->changeItem(s, index);
00087
else
00088 list_->removeItem(index);
00089 }
00090 }
00091
00092
void EditList::clear()
00093 {
00094 list_->clear();
00095 slotSelected(-1);
00096 }
00097
00098
void EditList::insertItem(
const QString& s)
00099 {
00100
if (!list_->findItem(s, Qt::ExactMatch))
00101 list_->insertItem(s);
00102 }
00103
00104
void EditList::insertItem(
const QPixmap& icon,
const QString& s)
00105 {
00106
if (!list_->findItem(s, Qt::ExactMatch))
00107 list_->insertItem(icon, s);
00108 }
00109
00110
void EditList::insertItems(
const QStringList& l)
00111 {
00112
for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it)
00113 insertItem(*it);
00114 }
00115
00116
QStringList EditList::items()
00117 {
00118
QStringList l;
00119
for (uint i=0; i<list_->count(); i++)
00120 l << list_->text(i);
00121
return l;
00122 }
00123
00124
#include "editlist.moc"