psymbolcombo.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <qlineedit.h>
00021 #include <qpushbutton.h>
00022 #include <qlayout.h>
00023 #include <qpainter.h>
00024
00025 #ifndef PURE_QT
00026 #include <qdialog.h>
00027
00028 #include <kcharselect.h>
00029 #include <klocale.h>
00030 #include <kpushbutton.h>
00031 #include <kstdguiitem.h>
00032 #endif
00033
00034 #include "psymbolcombo.h"
00035
00036 namespace PropertyLib{
00037
00038 PSymbolCombo::PSymbolCombo(MultiProperty *property, QWidget *parent, const char *name)
00039 :PropertyWidget(property, parent, name)
00040 {
00041 l = new QHBoxLayout(this);
00042
00043 m_edit = new QLineEdit(this);
00044 m_edit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
00045 m_edit->setMaxLength(1);
00046 l->addWidget(m_edit);
00047 m_select = new QPushButton("...", this);
00048 m_select->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding);
00049 l->addWidget(m_select);
00050
00051 #ifdef PURE_QT
00052 m_select->hide();
00053 #endif
00054
00055 connect(m_select, SIGNAL(clicked()), this, SLOT(selectChar()));
00056 connect(m_edit, SIGNAL(textChanged(const QString&)), this, SLOT(updateProperty(const QString&)));
00057 }
00058
00059 QVariant PSymbolCombo::value() const
00060 {
00061 if (!(m_edit->text().isNull()))
00062 return QVariant(QString("%1").arg(m_edit->text().at(0).unicode()));
00063 else
00064 return QVariant(0);
00065 }
00066
00067 void PSymbolCombo::setValue(const QVariant &value, bool emitChange)
00068 {
00069 #if QT_VERSION >= 0x030100
00070 if (!(value.isNull()))
00071 #else
00072 if (value.canCast(QVariant::Int))
00073 #endif
00074 {
00075 disconnect(m_edit, SIGNAL(textChanged(const QString&)), this, SLOT(updateProperty(const QString&)));
00076 m_edit->setText(QChar(value.toInt()));
00077 connect(m_edit, SIGNAL(textChanged(const QString&)), this, SLOT(updateProperty(const QString&)));
00078 if (emitChange)
00079 emit propertyChanged(m_property, value);
00080 }
00081 }
00082
00083 void PSymbolCombo::selectChar()
00084 {
00085 #ifndef PURE_QT
00086 QDialog* dia = new QDialog(this, "select_dialog", true);
00087 QVBoxLayout *dv = new QVBoxLayout(dia, 2);
00088
00089 KCharSelect *select = new KCharSelect(dia, "select_char");
00090 dv->addWidget(select);
00091
00092 QHBoxLayout *dh = new QHBoxLayout(dv, 6);
00093 KPushButton *pbOk = new KPushButton(KStdGuiItem::ok(), dia);
00094 KPushButton *pbCancel = new KPushButton(KStdGuiItem::cancel(), dia);
00095 QSpacerItem *si = new QSpacerItem(30, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
00096
00097 connect(pbOk, SIGNAL(clicked()), dia, SLOT(accept()));
00098 connect(pbCancel, SIGNAL(clicked()), dia, SLOT(reject()));
00099
00100 dh->addItem(si);
00101 dh->addWidget(pbOk);
00102 dh->addWidget(pbCancel);
00103
00104 if (!(m_edit->text().isNull()))
00105 select->setChar(m_edit->text().at(0));
00106
00107 if (dia->exec() == QDialog::Accepted)
00108 {
00109 m_edit->setText(select->chr());
00110 }
00111 delete dia;
00112 #endif
00113 }
00114
00115 void PSymbolCombo::updateProperty(const QString& val)
00116 {
00117 emit propertyChanged(m_property, QVariant(QString("%1").arg(val.at(0).unicode())));
00118 }
00119
00120 void PSymbolCombo::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value)
00121 {
00122 p->setBrush(cg.background());
00123 p->setPen(Qt::NoPen);
00124 p->drawRect(r);
00125 p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, QChar(value.toInt()));
00126 }
00127
00128 }
00129
00130 #ifndef PURE_QT
00131 #include "psymbolcombo.moc"
00132 #endif
This file is part of the documentation for KDevelop Version 3.1.2.