lib

stringlistedit.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
00003    Copyright (C) 2004  Alexander Dymo <cloudtemple@mskat.net>
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 as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "stringlistedit.h"
00022 
00023 #include <qlineedit.h>
00024 #include <qlayout.h>
00025 #include <qdialog.h>
00026 #include <qpainter.h>
00027 #include <qvariant.h>
00028 #include <qpushbutton.h>
00029 
00030 #include <keditlistbox.h>
00031 #include <kdialogbase.h>
00032 #include <kstdguiitem.h>
00033 #include <klocale.h>
00034 #include <kdebug.h>
00035 
00036 #include "property.h"
00037 
00038 using namespace KoProperty;
00039 
00040 StringListEdit::StringListEdit(Property *property, QWidget *parent, const char *name)
00041  : Widget(property, parent, name)
00042 {
00043     setHasBorders(false);
00044     QHBoxLayout *l = new QHBoxLayout(this, 0, 0);
00045 
00046     m_edit = new QLineEdit(this);
00047     m_edit->setLineWidth(0);
00048     m_edit->setReadOnly(true);
00049     m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
00050     m_edit->setMinimumHeight(5);
00051     l->addWidget(m_edit);
00052 
00053     m_selectButton = new QPushButton("...", this);
00054     m_selectButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
00055     l->addWidget(m_selectButton);
00056     setFocusWidget(m_selectButton);
00057 
00058     connect(m_selectButton, SIGNAL(clicked()), this, SLOT(showEditor()));
00059 }
00060 
00061 StringListEdit::~StringListEdit()
00062 {}
00063 
00064 QVariant
00065 StringListEdit::value() const
00066 {
00067     return m_list;
00068 }
00069 
00070 void
00071 StringListEdit::setValue(const QVariant &value, bool emitChange)
00072 {
00073     m_list = value.toStringList();
00074     m_edit->setText(value.toStringList().join(", "));
00075     if(emitChange)
00076         emit valueChanged(this);
00077 }
00078 
00079 void
00080 StringListEdit::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value)
00081 {
00082 //  p->eraseRect(r);
00083 //  p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, value.toStringList().join(", "));
00084     Widget::drawViewer(p, cg, r, value.toStringList().join(", "));
00085 }
00086 
00087 void
00088 StringListEdit::showEditor()
00089 {
00090     KDialogBase dialog(this->topLevelWidget(), "stringlist_dialog", true, i18n("Edit List of Items"),
00091         KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, false);
00092 
00093     KEditListBox *edit = new KEditListBox(i18n("Contents of %1").arg(property()->caption()), &dialog, "editlist");
00094     dialog.setMainWidget(edit);
00095     edit->insertStringList(m_list);
00096 
00097     if(dialog.exec() == QDialog::Accepted)
00098     {
00099         m_list = edit->items();
00100         m_edit->setText(m_list.join(", "));
00101         emit valueChanged(this);
00102     }
00103 }
00104 
00105 void
00106 StringListEdit::setReadOnlyInternal(bool readOnly)
00107 {
00108     m_selectButton->setEnabled(!readOnly);
00109 }
00110 
00111 #include "stringlistedit.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys