KDevelop API Documentation

pstringlistedit.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2003-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 "pstringlistedit.h"
00021 
00022 #include <qlineedit.h>
00023 #include <qlayout.h>
00024 #include <qdialog.h>
00025 #include <qpainter.h>
00026 
00027 #include <klocale.h>
00028 #include <kpushbutton.h>
00029 #include <keditlistbox.h>
00030 #include <kstdguiitem.h>
00031 
00032 namespace PropertyLib{
00033 
00034 PStringListEdit::PStringListEdit(MultiProperty *property, QWidget *parent, const char *name)
00035      :PropertyWidget(property, parent, name)
00036 {
00037     l = new QHBoxLayout(this);
00038 
00039     edit = new QLineEdit(this);
00040     edit->setReadOnly(true);
00041     edit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
00042     l->addWidget(edit);
00043     pbSelect = new QPushButton("...", this);
00044     pbSelect->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding);
00045     l->addWidget(pbSelect);
00046 
00047     connect(pbSelect, SIGNAL(clicked()), this, SLOT(showEditor()));
00048 }
00049 
00050 QVariant PStringListEdit::value() const
00051 {
00052     return QVariant(m_list);
00053 }
00054 
00055 void PStringListEdit::setValue(const QVariant &value, bool emitChange)
00056 {
00057     m_list = value.toStringList();
00058     edit->setText(value.toStringList().join(", "));
00059     if (emitChange)
00060         emit propertyChanged(m_property, value);
00061 }
00062 
00063 void PStringListEdit::showEditor()
00064 {
00065     QDialog* dia = new QDialog(this, "stringlist_dialog", true);
00066     QVBoxLayout *dv = new QVBoxLayout(dia, 2);
00067 
00068     KEditListBox *select = new KEditListBox(dia, "select_char");
00069     dv->addWidget(select);
00070 
00071     QHBoxLayout *dh = new QHBoxLayout(dv, 6);
00072     KPushButton *pbOk = new KPushButton(KStdGuiItem::ok(), dia);
00073     KPushButton *pbCancel = new KPushButton(KStdGuiItem::cancel(), dia);
00074     QSpacerItem *si = new QSpacerItem(30, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
00075 
00076     connect(pbOk, SIGNAL(clicked()), dia, SLOT(accept()));
00077     connect(pbCancel, SIGNAL(clicked()), dia, SLOT(reject()));
00078 
00079     dh->addItem(si);
00080     dh->addWidget(pbOk);
00081     dh->addWidget(pbCancel);
00082 
00083     select->insertStringList(m_list);
00084 
00085     if (dia->exec() == QDialog::Accepted)
00086     {
00087         m_list = select->items();
00088         edit->setText(select->items().join(", "));
00089     }
00090     delete dia;
00091 
00092     emit propertyChanged(m_property, m_list);
00093 }
00094 
00095 void PStringListEdit::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value)
00096 {
00097     p->setPen(Qt::NoPen);
00098     p->setBrush(cg.background());
00099     p->drawRect(r);
00100     p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, value.toStringList().join(", "));
00101 }
00102 
00103 }
00104 
00105 #ifndef PURE_QT
00106 #include "pstringlistedit.moc"
00107 #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