symbolcombo.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 <tqlineedit.h>
22#include <tqpushbutton.h>
23#include <tqlayout.h>
24#include <tqpainter.h>
25#include <tqvariant.h>
26
27#include <kcharselect.h>
28#include <tdelocale.h>
29#include <kdialogbase.h>
30
31#include "symbolcombo.h"
32
33using namespace KoProperty;
34
35SymbolCombo::SymbolCombo(Property *property, TQWidget *parent, const char *name)
36 : Widget(property, parent, name)
37{
38 setHasBorders(false);
39 TQHBoxLayout *l = new TQHBoxLayout(this);
40
41 m_edit = new TQLineEdit(this);
42 m_edit->setLineWidth(0);
43 m_edit->setReadOnly(true);
44 m_edit->setSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Expanding);
45 m_edit->setMinimumHeight(5);
46 m_edit->setMaxLength(1);
47 l->addWidget(m_edit);
48 m_select = new TQPushButton("...", this);
49 m_select->setSizePolicy(TQSizePolicy::Maximum, TQSizePolicy::MinimumExpanding);
50 m_select->setMinimumHeight(5);
51 l->addWidget(m_select);
52
53 connect(m_select, TQ_SIGNAL(clicked()), this, TQ_SLOT(selectChar()));
54 connect(m_edit, TQ_SIGNAL(textChanged(const TQString&)), this, TQ_SLOT(slotValueChanged(const TQString&)));
55}
56
57SymbolCombo::~SymbolCombo()
58{}
59
60TQVariant
61SymbolCombo::value() const
62{
63 if (!(m_edit->text().isNull()))
64 return m_edit->text().at(0).unicode();
65 else
66 return 0;
67}
68
69void
70SymbolCombo::setValue(const TQVariant &value, bool emitChange)
71{
72 if (!(value.isNull()))
73 {
74 m_edit->blockSignals(true);
75 m_edit->setText(TQChar(value.toInt()));
76 m_edit->blockSignals(false);
77 if (emitChange)
78 emit valueChanged(this);
79 }
80}
81
82void
83SymbolCombo::drawViewer(TQPainter *p, const TQColorGroup &cg, const TQRect &r, const TQVariant &value)
84{
85// p->eraseRect(r);
86// p->drawText(r, TQt::AlignLeft | TQt::AlignVCenter | TQt::SingleLine, TQChar(value.toInt()));
87 Widget::drawViewer(p, cg, r, TQString( TQChar(value.toInt()) ));
88}
89
90void
91SymbolCombo::selectChar()
92{
93 KDialogBase dialog(this->topLevelWidget(), "charselect_dialog", true, i18n("Select Char"),
95
96 KCharSelect *select = new KCharSelect(&dialog, "select_char");
97 dialog.setMainWidget(select);
98
99 if (!(m_edit->text().isNull()))
100 select->setChar(m_edit->text().at(0));
101
102 if (dialog.exec() == TQDialog::Accepted)
103 m_edit->setText(select->chr());
104}
105
106void
107SymbolCombo::slotValueChanged(const TQString&)
108{
109 emit valueChanged(this);
110}
111
112void
113SymbolCombo::setReadOnlyInternal(bool readOnly)
114{
115 m_select->setEnabled(!readOnly);
116}
117
118#include "symbolcombo.moc"
virtual TQChar chr() const
virtual void setChar(const TQChar &chr)
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.