lib/widgets/propeditor/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
#include <qlineedit.h>
00020
#include <qpushbutton.h>
00021
#include <qlayout.h>
00022
00023
#ifndef PURE_QT
00024
#include <kcharselect.h>
00025
#include <qdialog.h>
00026
#include <klocale.h>
00027
#include <kpushbutton.h>
00028
#include <kstdguiitem.h>
00029
#endif
00030
00031
#include "psymbolcombo.h"
00032
#include "propertyeditor.h"
00033
00034 PSymbolCombo::PSymbolCombo(
const PropertyEditor *editor,
const QString pname,
const QVariant value,
QWidget *parent,
const char *name):
00035
QWidget(parent, name)
00036 {
00037
l =
new QHBoxLayout(
this);
00038
00039
edit =
new QLineEdit(
this);
00040
edit->setMaxLength(1);
00041
l->addWidget(
edit);
00042
pbSelect =
new QPushButton(
"...",
this);
00043
l->addWidget(
pbSelect);
00044
00045
#ifdef PURE_QT
00046
pbSelect->hide();
00047
#endif
00048
00049 connect(
pbSelect, SIGNAL(clicked()),
this, SLOT(
selectChar()));
00050
setValue(value);
00051 setPName(pname);
00052 connect(
edit, SIGNAL(textChanged(
const QString&)),
this, SLOT(
updateProperty(
const QString&)));
00053 connect(
this, SIGNAL(
propertyChanged(
QString,
QVariant)), editor, SLOT(emitPropertyChange(
QString,
QVariant)));
00054 }
00055
00056 QVariant PSymbolCombo::value()
const
00057
{
00058
if (!(
edit->text().isNull()))
00059
return QVariant(
QString(
"%1").arg(
edit->text().at(0).unicode()));
00060
else
00061
return QVariant(0);
00062 }
00063
00064 void PSymbolCombo::setValue(
const QVariant value,
bool emitChange)
00065 {
00066
#if QT_VERSION >= 0x030100
00067
if (!(value.isNull()))
00068
#else
00069
if (value.canCast(QVariant::Int))
00070
00071
#endif
00072
{
00073
edit->setText(
QChar(value.toInt()));
00074
if (emitChange)
00075 emit
propertyChanged(
pname(), value);
00076 }
00077 }
00078
00079 void PSymbolCombo::selectChar()
00080 {
00081
#ifndef PURE_QT
00082
QDialog* dia =
new QDialog(
this,
"select_dialog",
true);
00083
QVBoxLayout *dv =
new QVBoxLayout(dia, 2);
00084
00085
KCharSelect *select =
new KCharSelect(dia,
"select_char");
00086 dv->addWidget(select);
00087
00088
QHBoxLayout *dh =
new QHBoxLayout(dv, 6);
00089
KPushButton *pbOk =
new KPushButton(KStdGuiItem::ok(), dia);
00090 KPushButton *pbCancel =
new KPushButton(KStdGuiItem::cancel(), dia);
00091
QSpacerItem *si =
new QSpacerItem(30, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
00092
00093 connect(pbOk, SIGNAL(clicked()), dia, SLOT(accept()));
00094 connect(pbCancel, SIGNAL(clicked()), dia, SLOT(reject()));
00095
00096 dh->addItem(si);
00097 dh->addWidget(pbOk);
00098 dh->addWidget(pbCancel);
00099
00100
if (!(
edit->text().isNull()))
00101 select->
setChar(
edit->text().at(0));
00102
00103
if (dia->exec() == QDialog::Accepted)
00104 {
00105
edit->setText(select->
chr());
00106 }
00107
delete dia;
00108
#endif
00109
}
00110
00111 void PSymbolCombo::updateProperty(
const QString& val)
00112 {
00113 emit
propertyChanged(
pname(),
QVariant(val));
00114 }
00115
00116
#ifndef PURE_QT
00117
#include "psymbolcombo.moc"
00118
#endif
This file is part of the documentation for KDevelop Version 3.0.4.