lib
symbolcombo.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qlineedit.h>
00022 #include <qpushbutton.h>
00023 #include <qlayout.h>
00024 #include <qpainter.h>
00025 #include <qvariant.h>
00026
00027 #ifndef QT_ONLY
00028 #include <kcharselect.h>
00029 #include <klocale.h>
00030 #include <kdialogbase.h>
00031 #endif
00032
00033 #include "symbolcombo.h"
00034
00035 using namespace KoProperty;
00036
00037 SymbolCombo::SymbolCombo(Property *property, QWidget *parent, const char *name)
00038 : Widget(property, parent, name)
00039 {
00040 setHasBorders(false);
00041 QHBoxLayout *l = new QHBoxLayout(this);
00042
00043 m_edit = new QLineEdit(this);
00044 m_edit->setLineWidth(0);
00045 m_edit->setReadOnly(true);
00046 m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
00047 m_edit->setMinimumHeight(5);
00048 m_edit->setMaxLength(1);
00049 l->addWidget(m_edit);
00050 m_select = new QPushButton("...", this);
00051 m_select->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding);
00052 m_select->setMinimumHeight(5);
00053 l->addWidget(m_select);
00054
00055 #ifdef QT_ONLY
00056 m_select->hide();
00057 #endif
00058
00059 connect(m_select, SIGNAL(clicked()), this, SLOT(selectChar()));
00060 connect(m_edit, SIGNAL(textChanged(const QString&)), this, SLOT(slotValueChanged(const QString&)));
00061 }
00062
00063 SymbolCombo::~SymbolCombo()
00064 {}
00065
00066 QVariant
00067 SymbolCombo::value() const
00068 {
00069 if (!(m_edit->text().isNull()))
00070 return m_edit->text().at(0).unicode();
00071 else
00072 return 0;
00073 }
00074
00075 void
00076 SymbolCombo::setValue(const QVariant &value, bool emitChange)
00077 {
00078 #if QT_VERSION >= 0x030100
00079 if (!(value.isNull()))
00080 #else
00081 if (value.canCast(QVariant::Int))
00082 #endif
00083 {
00084 m_edit->blockSignals(true);
00085 m_edit->setText(QChar(value.toInt()));
00086 m_edit->blockSignals(false);
00087 if (emitChange)
00088 emit valueChanged(this);
00089 }
00090 }
00091
00092 void
00093 SymbolCombo::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value)
00094 {
00095
00096
00097 Widget::drawViewer(p, cg, r, QString( QChar(value.toInt()) ));
00098 }
00099
00100 void
00101 SymbolCombo::selectChar()
00102 {
00103 #ifndef QT_ONLY
00104 KDialogBase dialog(this->topLevelWidget(), "charselect_dialog", true, i18n("Select Char"),
00105 KDialogBase::Ok|KDialogBase::Cancel, KDialogBase::Ok, false);
00106
00107 KCharSelect *select = new KCharSelect(&dialog, "select_char");
00108 dialog.setMainWidget(select);
00109
00110 if (!(m_edit->text().isNull()))
00111 select->setChar(m_edit->text().at(0));
00112
00113 if (dialog.exec() == QDialog::Accepted)
00114 m_edit->setText(select->chr());
00115 #endif
00116 }
00117
00118 void
00119 SymbolCombo::slotValueChanged(const QString&)
00120 {
00121 emit valueChanged(this);
00122 }
00123
00124 void
00125 SymbolCombo::setReadOnlyInternal(bool readOnly)
00126 {
00127 m_select->setEnabled(!readOnly);
00128 }
00129
00130 #include "symbolcombo.moc"
|