kdeprint Library API Documentation

editlist.cpp

00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License version 2 as published by the Free Software Foundation. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Library General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Library General Public License 00015 * along with this library; see the file COPYING.LIB. If not, write to 00016 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 * Boston, MA 02111-1307, USA. 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"
KDE Logo
This file is part of the documentation for kdeprint Library Version 3.3.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Oct 17 11:32:32 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003