1
/***************************************************************************
2
* Copyright (C) 2002-2004 by Alexander Dymo *
3
* cloudtemple@mskat.net *
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. *
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. *
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>
28
#include <kcharselect.h>
30
#include <kpushbutton.h>
31
#include <kstdguiitem.h>
34
#include "psymbolcombo.h"
36
namespace PropertyLib{
38
PSymbolCombo::PSymbolCombo(MultiProperty *property, QWidget *parent, const char *name)
39
:PropertyWidget(property, parent, name)
41
l = new QHBoxLayout(this);
43
m_edit = new QLineEdit(this);
44
m_edit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
45
m_edit->setMaxLength(1);
47
m_select = new QPushButton("...", this);
48
m_select->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding);
49
l->addWidget(m_select);
55
connect(m_select, SIGNAL(clicked()), this, SLOT(selectChar()));
56
connect(m_edit, SIGNAL(textChanged(const QString&)), this, SLOT(updateProperty(const QString&)));
59
QVariant PSymbolCombo::value() const
61
if (!(m_edit->text().isNull()))
62
return QVariant(QString("%1").arg(m_edit->text().at(0).unicode()));
67
void PSymbolCombo::setValue(const QVariant &value, bool emitChange)
69
#if QT_VERSION >= 0x030100
70
if (!(value.isNull()))
72
if (value.canCast(QVariant::Int))
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&)));
79
emit propertyChanged(m_property, value);
83
void PSymbolCombo::selectChar()
86
QDialog* dia = new QDialog(this, "select_dialog", true);
87
QVBoxLayout *dv = new QVBoxLayout(dia, 2);
89
KCharSelect *select = new KCharSelect(dia, "select_char");
90
dv->addWidget(select);
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);
97
connect(pbOk, SIGNAL(clicked()), dia, SLOT(accept()));
98
connect(pbCancel, SIGNAL(clicked()), dia, SLOT(reject()));
102
dh->addWidget(pbCancel);
104
if (!(m_edit->text().isNull()))
105
select->setChar(m_edit->text().at(0));
107
if (dia->exec() == QDialog::Accepted)
109
m_edit->setText(select->chr());
115
void PSymbolCombo::updateProperty(const QString& val)
117
emit propertyChanged(m_property, QVariant(QString("%1").arg(val.at(0).unicode())));
120
void PSymbolCombo::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value)
122
p->setBrush(cg.background());
123
p->setPen(Qt::NoPen);
125
p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, QChar(value.toInt()));
131
#include "psymbolcombo.moc"