stringlistedit.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
3 Copyright (C) 2004 Alexander Dymo <cloudtemple@mskat.net>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include "stringlistedit.h"
22
23#include <tqlineedit.h>
24#include <tqlayout.h>
25#include <tqdialog.h>
26#include <tqpainter.h>
27#include <tqvariant.h>
28#include <tqpushbutton.h>
29
30#include <keditlistbox.h>
31#include <kdialogbase.h>
32#include <kstdguiitem.h>
33#include <tdelocale.h>
34#include <kdebug.h>
35
36#include "property.h"
37
38using namespace KoProperty;
39
40StringListEdit::StringListEdit(Property *property, TQWidget *parent, const char *name)
41 : Widget(property, parent, name)
42{
43 setHasBorders(false);
44 TQHBoxLayout *l = new TQHBoxLayout(this, 0, 0);
45
46 m_edit = new TQLineEdit(this);
47 m_edit->setLineWidth(0);
48 m_edit->setReadOnly(true);
49 m_edit->setSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Expanding);
50 m_edit->setMinimumHeight(5);
51 l->addWidget(m_edit);
52
53 m_selectButton = new TQPushButton("...", this);
54 m_selectButton->setSizePolicy(TQSizePolicy::Minimum, TQSizePolicy::Expanding);
55 l->addWidget(m_selectButton);
56 setFocusWidget(m_selectButton);
57
58 connect(m_selectButton, TQ_SIGNAL(clicked()), this, TQ_SLOT(showEditor()));
59}
60
61StringListEdit::~StringListEdit()
62{}
63
64TQVariant
65StringListEdit::value() const
66{
67 return m_list;
68}
69
70void
71StringListEdit::setValue(const TQVariant &value, bool emitChange)
72{
73 m_list = value.toStringList();
74 m_edit->setText(value.toStringList().join(", "));
75 if(emitChange)
76 emit valueChanged(this);
77}
78
79void
80StringListEdit::drawViewer(TQPainter *p, const TQColorGroup &cg, const TQRect &r, const TQVariant &value)
81{
82// p->eraseRect(r);
83// p->drawText(r, TQt::AlignLeft | TQt::AlignVCenter | TQt::SingleLine, value.toStringList().join(", "));
84 Widget::drawViewer(p, cg, r, value.toStringList().join(", "));
85}
86
87void
88StringListEdit::showEditor()
89{
90 KDialogBase dialog(this->topLevelWidget(), "stringlist_dialog", true, i18n("Edit List of Items"),
92
93 KEditListBox *edit = new KEditListBox(i18n("Contents of %1").arg(property()->caption()), &dialog, "editlist");
94 dialog.setMainWidget(edit);
95 edit->insertStringList(m_list);
96
97 if(dialog.exec() == TQDialog::Accepted)
98 {
99 m_list = edit->items();
100 m_edit->setText(m_list.join(", "));
101 emit valueChanged(this);
102 }
103}
104
105void
106StringListEdit::setReadOnlyInternal(bool readOnly)
107{
108 m_selectButton->setEnabled(!readOnly);
109}
110
111#include "stringlistedit.moc"
void insertStringList(const TQStringList &list, int index=-1)
TQStringList items() const
The base class representing a single property.
Definition property.h:177
The base class for all item editors used in Editor.
Definition widget.h:37
virtual void drawViewer(TQPainter *p, const TQColorGroup &cg, const TQRect &r, const TQVariant &value)
Definition widget.cpp:88
const char * name(StdAction id)
Namespace for a set of classes implementing generic properties framework.