KDevelop API Documentation

lib/widgets/propeditor/psymbolcombo.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project 00002 Copyright (C) 2002 Alexander Dymo <cloudtemple@mksat.net> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 Boston, MA 02111-1307, USA. 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
KDE Logo
This file is part of the documentation for KDevelop Version 3.0.4.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Oct 6 17:39:09 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003