qdirmultilineedit.cpp
00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (c) 2001-2002 Michael Goffioul <tdeprint@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., 51 Franklin Street, Fifth Floor, 00017 * Boston, MA 02110-1301, USA. 00018 **/ 00019 00020 #include "qdirmultilineedit.h" 00021 00022 #include <tqlayout.h> 00023 #include <tqheader.h> 00024 #include <tqpushbutton.h> 00025 #include <tdelistview.h> 00026 #include <tdelocale.h> 00027 #include <tdefiledialog.h> 00028 #include <kiconloader.h> 00029 00030 QDirMultiLineEdit::QDirMultiLineEdit(TQWidget *parent, const char *name) 00031 : TQWidget(parent, name) 00032 { 00033 m_view = new TDEListView(this); 00034 m_view->header()->hide(); 00035 m_view->addColumn(""); 00036 m_view->setFullWidth(true); 00037 connect(m_view, TQT_SIGNAL(selectionChanged(TQListViewItem*)), TQT_SLOT(slotSelected(TQListViewItem*))); 00038 00039 m_add = new TQPushButton(this); 00040 m_add->setPixmap(SmallIcon("folder-new")); 00041 connect(m_add, TQT_SIGNAL(clicked()), TQT_SLOT(slotAddClicked())); 00042 m_remove = new TQPushButton(this); 00043 m_remove->setPixmap(SmallIcon("edit-delete")); 00044 connect(m_remove, TQT_SIGNAL(clicked()), TQT_SLOT(slotRemoveClicked())); 00045 m_remove->setEnabled(false); 00046 00047 m_view->setFixedHeight(TQMAX(m_view->fontMetrics().lineSpacing()*3+m_view->lineWidth()*2, m_add->sizeHint().height()*2)); 00048 00049 TQHBoxLayout *l0 = new TQHBoxLayout(this, 0, 3); 00050 TQVBoxLayout *l1 = new TQVBoxLayout(0, 0, 0); 00051 l0->addWidget(m_view); 00052 l0->addLayout(l1); 00053 l1->addWidget(m_add); 00054 l1->addWidget(m_remove); 00055 l1->addStretch(1); 00056 } 00057 00058 QDirMultiLineEdit::~QDirMultiLineEdit() 00059 { 00060 } 00061 00062 void QDirMultiLineEdit::setURLs(const TQStringList& urls) 00063 { 00064 m_view->clear(); 00065 for (TQStringList::ConstIterator it=urls.begin(); it!=urls.end(); ++it) 00066 addURL(*it); 00067 } 00068 00069 TQStringList QDirMultiLineEdit::urls() 00070 { 00071 TQListViewItem *item = m_view->firstChild(); 00072 TQStringList l; 00073 while (item) 00074 { 00075 l << item->text(0); 00076 item = item->nextSibling(); 00077 } 00078 return l; 00079 } 00080 00081 void QDirMultiLineEdit::addURL(const TQString& url) 00082 { 00083 TQListViewItem *item = new TQListViewItem(m_view, url); 00084 item->setRenameEnabled(0, true); 00085 } 00086 00087 void QDirMultiLineEdit::slotAddClicked() 00088 { 00089 TQString dirname = KFileDialog::getExistingDirectory(TQString::null, this); 00090 if (!dirname.isEmpty()) 00091 addURL(dirname); 00092 } 00093 00094 void QDirMultiLineEdit::slotRemoveClicked() 00095 { 00096 TQListViewItem *item = m_view->currentItem(); 00097 if (item) 00098 { 00099 delete item; 00100 slotSelected(m_view->currentItem()); 00101 } 00102 } 00103 00104 void QDirMultiLineEdit::slotSelected(TQListViewItem *item) 00105 { 00106 m_remove->setEnabled((item != NULL)); 00107 } 00108 00109 #include "qdirmultilineedit.moc"