KProperty

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 <QLineEdit>
24#include <QDialog>
25#include <QPainter>
26#include <QVariant>
27#include <QPushButton>
28#include <QHBoxLayout>
29
30#include "KProperty.h"
31
32class Q_DECL_HIDDEN KPropertyStringListEditor::Private
33{
34public:
35 Private() {
36 }
37 QLineEdit *edit;
39 QPushButton *selectButton;
40};
41
42KPropertyStringListEditor::KPropertyStringListEditor(KProperty *property, QWidget *parent)
43 : Widget(property, parent), d(new Private)
44{
45 setHasBorders(false);
46 QHBoxLayout *l = new QHBoxLayout(this);
47 l->setMargin(0);
48 l->setSpacing(0);
49
50 d->edit = new QLineEdit(this);
51 d->edit->setReadOnly(true);
52 d->edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
53 d->edit->setMinimumHeight(5);
54 l->addWidget(d->edit);
55
56 d->selectButton = new QPushButton(this);
57 Utils::setupDotDotDotButton(d->selectButton, tr("Select item"),
58 tr("Selects one item"));
59
60 d->selectButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
61 l->addWidget(d->selectButton);
62 setFocusWidget(d->selectButton);
63
64 connect(d->selectButton, SIGNAL(clicked()), this, SLOT(showEditor()));
65}
66
67KPropertyStringListEditor::~KPropertyStringListEditor()
68{
69 delete d;
70}
71
73KPropertyStringListEditor::value() const
74{
75 return d->list;
76}
77
78void
79KPropertyStringListEditor::setValue(const QVariant &value, bool emitChange)
80{
81 d->list = value.toStringList();
82 d->edit->setText(value.toStringList().join(", "));
83 if (emitChange)
84 emit valueChanged(this);
85}
86
87void
88KPropertyStringListEditor::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value)
89{
90 Widget::drawViewer(p, cg, r, value.toStringList().join(", "));
91}
92
93void
94KPropertyStringListEditor::showEditor()
95{
96 QDialog dialog(this->topLevelWidget());
97 dialog.setWindowTitle(tr("Edit List of Items", "Window title"));
98 dialog.setObjectName("stringlist_dialog");
99 dialog.setButtons(QDialog::Ok | QDialog::Cancel);
100 dialog.setDefaultButton(QDialog::Ok);
101 dialog.setModal(false);
102 KEditListBox *edit = new KEditListBox(tr("Contents of %1").arg(property()->captionOrName()),
103 &dialog, "editlist");
104 // PORTING: Verify that widget was added to mainLayout: dialog.setMainWidget(edit);
105 // Add mainLayout->addWidget(edit); if necessary
106 edit->insertStringList(d->list);
107
108 if (dialog.exec() == QDialog::Accepted) {
109 d->list = edit->items();
110 d->edit->setText(d->list.join(", "));
111 emit valueChanged(this);
112 }
113}
114
115void
116KPropertyStringListEditor::setReadOnlyInternal(bool readOnly)
117{
118 d->selectButton->setEnabled(!readOnly);
119}
The base class representing a single property.
Definition KProperty.h:96
KIOCORE_EXPORT QStringList list(const QString &fileClass)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void setSpacing(int spacing)
void setMargin(int margin)
void setText(const QString &)
QString join(const QString &separator) const const
QStringList toStringList() const const
void setEnabled(bool)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:41:55 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.