lib

symbolcombo.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
00003    Copyright (C) 2004  Alexander Dymo <cloudtemple@mskat.net>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include <qlineedit.h>
00022 #include <qpushbutton.h>
00023 #include <qlayout.h>
00024 #include <qpainter.h>
00025 #include <qvariant.h>
00026 
00027 #include <kcharselect.h>
00028 #include <klocale.h>
00029 #include <kdialogbase.h>
00030 
00031 #include "symbolcombo.h"
00032 
00033 using namespace KoProperty;
00034 
00035 SymbolCombo::SymbolCombo(Property *property, QWidget *parent, const char *name)
00036  : Widget(property, parent, name)
00037 {
00038     setHasBorders(false);
00039     QHBoxLayout *l = new QHBoxLayout(this);
00040 
00041     m_edit = new QLineEdit(this);
00042     m_edit->setLineWidth(0);
00043     m_edit->setReadOnly(true);
00044     m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
00045     m_edit->setMinimumHeight(5);
00046     m_edit->setMaxLength(1);
00047     l->addWidget(m_edit);
00048     m_select = new QPushButton("...", this);
00049     m_select->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding);
00050     m_select->setMinimumHeight(5);
00051     l->addWidget(m_select);
00052 
00053     connect(m_select, SIGNAL(clicked()), this, SLOT(selectChar()));
00054     connect(m_edit, SIGNAL(textChanged(const QString&)), this, SLOT(slotValueChanged(const QString&)));
00055 }
00056 
00057 SymbolCombo::~SymbolCombo()
00058 {}
00059 
00060 QVariant
00061 SymbolCombo::value() const
00062 {
00063     if (!(m_edit->text().isNull()))
00064         return m_edit->text().at(0).unicode();
00065     else
00066         return 0;
00067 }
00068 
00069 void
00070 SymbolCombo::setValue(const QVariant &value, bool emitChange)
00071 {
00072 #if QT_VERSION >= 0x030100
00073     if (!(value.isNull()))
00074 #else
00075     if (value.canCast(QVariant::Int))
00076 #endif
00077     {
00078         m_edit->blockSignals(true);
00079         m_edit->setText(QChar(value.toInt()));
00080         m_edit->blockSignals(false);
00081         if (emitChange)
00082             emit valueChanged(this);
00083     }
00084 }
00085 
00086 void
00087 SymbolCombo::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value)
00088 {
00089 //  p->eraseRect(r);
00090 //  p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, QChar(value.toInt()));
00091     Widget::drawViewer(p, cg, r, QString( QChar(value.toInt()) ));
00092 }
00093 
00094 void
00095 SymbolCombo::selectChar()
00096 {
00097     KDialogBase dialog(this->topLevelWidget(), "charselect_dialog", true, i18n("Select Char"),
00098         KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, false);
00099 
00100     KCharSelect *select = new KCharSelect(&dialog, "select_char");
00101     dialog.setMainWidget(select);
00102 
00103     if (!(m_edit->text().isNull()))
00104         select->setChar(m_edit->text().at(0));
00105 
00106     if (dialog.exec() == QDialog::Accepted)
00107         m_edit->setText(select->chr());
00108 }
00109 
00110 void
00111 SymbolCombo::slotValueChanged(const QString&)
00112 {
00113     emit valueChanged(this);
00114 }
00115 
00116 void
00117 SymbolCombo::setReadOnlyInternal(bool readOnly)
00118 {
00119     m_select->setEnabled(!readOnly);
00120 }
00121 
00122 #include "symbolcombo.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys