KDevelop API Documentation

psymbolcombo.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2002-2004 by Alexander Dymo                             *
00003  *   cloudtemple@mskat.net                                                 *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Library General Public License as       *
00007  *   published by the Free Software Foundation; either version 2 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  *   This program 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         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU Library General Public     *
00016  *   License along with this program; if not, write to the                 *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
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
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:22:37 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003