~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to lib/widgets/propeditor/pstringlistedit.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2003-2004 by Alexander Dymo                             *
3
 
 *   cloudtemple@mskat.net                                                 *
4
 
 *                                                                         *
5
 
 *   This program is free software; you can redistribute it and/or modify  *
6
 
 *   it under the terms of the GNU Library General Public License as       *
7
 
 *   published by the Free Software Foundation; either version 2 of the    *
8
 
 *   License, or (at your option) any later version.                       *
9
 
 *                                                                         *
10
 
 *   This program 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         *
13
 
 *   GNU General Public License for more details.                          *
14
 
 *                                                                         *
15
 
 *   You should have received a copy of the GNU Library General Public     *
16
 
 *   License along with this program; if not, write to the                 *
17
 
 *   Free Software Foundation, Inc.,                                       *
18
 
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19
 
 ***************************************************************************/
20
 
#include "pstringlistedit.h"
21
 
 
22
 
#include <qlayout.h>
23
 
#include <qdialog.h>
24
 
#include <qpainter.h>
25
 
#include <klineedit.h>
26
 
 
27
 
#ifndef PURE_QT
28
 
#include <keditlistbox.h>
29
 
#include <kpushbutton.h>
30
 
#include <kstdguiitem.h>
31
 
#else
32
 
#include "qeditlistbox.h"
33
 
#include <qpushbutton.h>
34
 
#include "compat_tools.h"
35
 
#endif
36
 
 
37
 
namespace PropertyLib{
38
 
 
39
 
PStringListEdit::PStringListEdit(MultiProperty *property, QWidget *parent, const char *name)
40
 
     :PropertyWidget(property, parent, name)
41
 
{
42
 
    l = new QHBoxLayout(this);
43
 
 
44
 
    edit = new KLineEdit(this);
45
 
    edit->setReadOnly(true);
46
 
    edit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
47
 
    l->addWidget(edit);
48
 
    pbSelect = new QPushButton("...", this);
49
 
    pbSelect->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding);
50
 
    l->addWidget(pbSelect);
51
 
 
52
 
    connect(pbSelect, SIGNAL(clicked()), this, SLOT(showEditor()));
53
 
}
54
 
 
55
 
QVariant PStringListEdit::value() const
56
 
{
57
 
    return QVariant(m_list);
58
 
}
59
 
 
60
 
void PStringListEdit::setValue(const QVariant &value, bool emitChange)
61
 
{
62
 
    m_list = value.toStringList();
63
 
    edit->setText(value.toStringList().join(", "));
64
 
    if (emitChange)
65
 
        emit propertyChanged(m_property, value);
66
 
}
67
 
 
68
 
void PStringListEdit::showEditor()
69
 
{
70
 
    QDialog* dia = new QDialog(this, "stringlist_dialog", true);
71
 
    QVBoxLayout *dv = new QVBoxLayout(dia, 2);
72
 
 
73
 
#ifdef PURE_QT
74
 
    QEditListBox *select = new QEditListBox(dia, "select_char");
75
 
#else
76
 
    KEditListBox *select = new KEditListBox(dia, "select_char");
77
 
#endif
78
 
    dv->addWidget(select);
79
 
 
80
 
    QHBoxLayout *dh = new QHBoxLayout(dv, 6);
81
 
#ifndef PURE_QT
82
 
    KPushButton *pbOk = new KPushButton(KStdGuiItem::ok(), dia);
83
 
    KPushButton *pbCancel = new KPushButton(KStdGuiItem::cancel(), dia);
84
 
#else
85
 
    QPushButton *pbOk = new QPushButton(i18n("Ok"), dia);
86
 
    QPushButton *pbCancel = new QPushButton(i18n("Cancel"), dia);
87
 
#endif
88
 
    QSpacerItem *si = new QSpacerItem(30, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
89
 
 
90
 
    connect(pbOk, SIGNAL(clicked()), dia, SLOT(accept()));
91
 
    connect(pbCancel, SIGNAL(clicked()), dia, SLOT(reject()));
92
 
 
93
 
    dh->addItem(si);
94
 
    dh->addWidget(pbOk);
95
 
    dh->addWidget(pbCancel);
96
 
 
97
 
    select->insertStringList(m_list);
98
 
 
99
 
    if (dia->exec() == QDialog::Accepted)
100
 
    {
101
 
        m_list = select->items();
102
 
        edit->setText(select->items().join(", "));
103
 
    }
104
 
    delete dia;
105
 
 
106
 
    emit propertyChanged(m_property, m_list);
107
 
}
108
 
 
109
 
void PStringListEdit::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value)
110
 
{
111
 
    p->setPen(Qt::NoPen);
112
 
    p->setBrush(cg.background());
113
 
    p->drawRect(r);
114
 
    p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, value.toStringList().join(", "));
115
 
}
116
 
 
117
 
}
118
 
 
119
 
#ifndef PURE_QT
120
 
#include "pstringlistedit.moc"
121
 
#endif