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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2006-05-23 18:39:42 UTC
  • Revision ID: james.westby@ubuntu.com-20060523183942-hucifbvh68k2bwz7
Tags: upstream-3.3.2
Import upstream version 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2002-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 <qlineedit.h>
 
21
#include <qpushbutton.h>
 
22
#include <qlayout.h>
 
23
#include <qpainter.h>
 
24
 
 
25
#ifndef PURE_QT
 
26
#include <qdialog.h>
 
27
 
 
28
#include <kcharselect.h>
 
29
#include <klocale.h>
 
30
#include <kpushbutton.h>
 
31
#include <kstdguiitem.h>
 
32
#endif
 
33
 
 
34
#include "psymbolcombo.h"
 
35
 
 
36
namespace PropertyLib{
 
37
 
 
38
PSymbolCombo::PSymbolCombo(MultiProperty *property, QWidget *parent, const char *name)
 
39
    :PropertyWidget(property, parent, name)
 
40
{
 
41
    l = new QHBoxLayout(this);
 
42
 
 
43
    m_edit = new QLineEdit(this);
 
44
    m_edit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
 
45
    m_edit->setMaxLength(1);
 
46
    l->addWidget(m_edit);
 
47
    m_select = new QPushButton("...", this);
 
48
    m_select->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding);
 
49
    l->addWidget(m_select);
 
50
 
 
51
#ifdef PURE_QT
 
52
    m_select->hide();
 
53
#endif
 
54
 
 
55
    connect(m_select, SIGNAL(clicked()), this, SLOT(selectChar()));
 
56
    connect(m_edit, SIGNAL(textChanged(const QString&)), this, SLOT(updateProperty(const QString&)));
 
57
}
 
58
 
 
59
QVariant PSymbolCombo::value() const
 
60
{
 
61
    if (!(m_edit->text().isNull()))
 
62
        return QVariant(QString("%1").arg(m_edit->text().at(0).unicode()));
 
63
    else
 
64
        return QVariant(0);
 
65
}
 
66
 
 
67
void PSymbolCombo::setValue(const QVariant &value, bool emitChange)
 
68
{
 
69
#if QT_VERSION >= 0x030100
 
70
    if (!(value.isNull()))
 
71
#else
 
72
    if (value.canCast(QVariant::Int))
 
73
#endif
 
74
    {
 
75
        disconnect(m_edit, SIGNAL(textChanged(const QString&)), this, SLOT(updateProperty(const QString&)));
 
76
        m_edit->setText(QChar(value.toInt()));
 
77
        connect(m_edit, SIGNAL(textChanged(const QString&)), this, SLOT(updateProperty(const QString&)));
 
78
        if (emitChange)
 
79
            emit propertyChanged(m_property, value);
 
80
    }
 
81
}
 
82
 
 
83
void PSymbolCombo::selectChar()
 
84
{
 
85
#ifndef PURE_QT
 
86
    QDialog* dia = new QDialog(this, "select_dialog", true);
 
87
    QVBoxLayout *dv = new QVBoxLayout(dia, 2);
 
88
 
 
89
    KCharSelect *select = new KCharSelect(dia, "select_char");
 
90
    dv->addWidget(select);
 
91
 
 
92
    QHBoxLayout *dh = new QHBoxLayout(dv, 6);
 
93
    KPushButton *pbOk = new KPushButton(KStdGuiItem::ok(), dia);
 
94
    KPushButton *pbCancel = new KPushButton(KStdGuiItem::cancel(), dia);
 
95
    QSpacerItem *si = new QSpacerItem(30, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
 
96
 
 
97
    connect(pbOk, SIGNAL(clicked()), dia, SLOT(accept()));
 
98
    connect(pbCancel, SIGNAL(clicked()), dia, SLOT(reject()));
 
99
 
 
100
    dh->addItem(si);
 
101
    dh->addWidget(pbOk);
 
102
    dh->addWidget(pbCancel);
 
103
 
 
104
    if (!(m_edit->text().isNull()))
 
105
        select->setChar(m_edit->text().at(0));
 
106
 
 
107
    if (dia->exec() == QDialog::Accepted)
 
108
    {
 
109
        m_edit->setText(select->chr());
 
110
    }
 
111
    delete dia;
 
112
#endif
 
113
}
 
114
 
 
115
void PSymbolCombo::updateProperty(const QString& val)
 
116
{
 
117
    emit propertyChanged(m_property, QVariant(QString("%1").arg(val.at(0).unicode())));
 
118
}
 
119
 
 
120
void PSymbolCombo::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value)
 
121
{
 
122
    p->setBrush(cg.background());
 
123
    p->setPen(Qt::NoPen);
 
124
    p->drawRect(r);
 
125
    p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, QChar(value.toInt()));
 
126
}
 
127
 
 
128
}
 
129
 
 
130
#ifndef PURE_QT
 
131
#include "psymbolcombo.moc"
 
132
#endif