F:/KPlato/koffice/libs/koproperty/editors/linestyledit.cpp

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
00003    Copyright (C) 2004  Alexander Dymo <cloudtemple@mskat.net>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library 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 GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "linestyleedit.h"
00022 #include "editoritem.h"
00023 
00024 #include <QPainter>
00025 #include <QPixmap>
00026 #include <QComboBox>
00027 #include <QLayout>
00028 #include <QVariant>
00029 #include <QHBoxLayout>
00030 
00031 using namespace KoProperty;
00032 
00034     static const char *nopen[]={
00035     "48 16 1 1",
00036     ". c None",
00037     "................................................",
00038     "................................................",
00039     "................................................",
00040     "................................................",
00041     "................................................",
00042     "................................................",
00043     "................................................",
00044     "................................................",
00045     "................................................",
00046     "................................................",
00047     "................................................",
00048     "................................................",
00049     "................................................",
00050     "................................................",
00051     "................................................",
00052     "................................................"};
00054     static const char *solid[]={
00055     "48 16 2 1",
00056     ". c None",
00057     "# c #000000",
00058     "................................................",
00059     "................................................",
00060     "................................................",
00061     "................................................",
00062     "................................................",
00063     "................................................",
00064     "................................................",
00065     ".###########################################....",
00066     ".###########################################....",
00067     "................................................",
00068     "................................................",
00069     "................................................",
00070     "................................................",
00071     "................................................",
00072     "................................................",
00073     "................................................"};
00075     static const char *dash[]={
00076     "48 16 2 1",
00077     ". c None",
00078     "# c #000000",
00079     "................................................",
00080     "................................................",
00081     "................................................",
00082     "................................................",
00083     "................................................",
00084     "................................................",
00085     "................................................",
00086     ".#########..#########..#########..##########....",
00087     ".#########..#########..#########..##########....",
00088     "................................................",
00089     "................................................",
00090     "................................................",
00091     "................................................",
00092     "................................................",
00093     "................................................",
00094     "................................................"};
00096     static const char *dashdot[]={
00097     "48 16 2 1",
00098     ". c None",
00099     "# c #000000",
00100     "................................................",
00101     "................................................",
00102     "................................................",
00103     "................................................",
00104     "................................................",
00105     "................................................",
00106     "................................................",
00107     ".#########..##..#########..##..#########..##....",
00108     ".#########..##..#########..##..#########..##....",
00109     "................................................",
00110     "................................................",
00111     "................................................",
00112     "................................................",
00113     "................................................",
00114     "................................................",
00115     "................................................"};
00117     static const char *dashdotdot[]={
00118     "48 16 2 1",
00119     ". c None",
00120     "# c #000000",
00121     "................................................",
00122     "................................................",
00123     "................................................",
00124     "................................................",
00125     "................................................",
00126     "................................................",
00127     "................................................",
00128     ".#########..##..##..#########..##..##..#####....",
00129     ".#########..##..##..#########..##..##..#####....",
00130     "................................................",
00131     "................................................",
00132     "................................................",
00133     "................................................",
00134     "................................................",
00135     "................................................",
00136     "................................................"};
00137 
00138 
00139 LineStyleEdit::LineStyleEdit(Property *property, QWidget *parent)
00140  : Widget(property, parent)
00141 {
00142         QHBoxLayout *l = new QHBoxLayout(this);
00143         l->setMargin(0);
00144         l->setSpacing(0);
00145 
00146         m_edit = new QComboBox(this);
00147         m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
00148         m_edit->setMinimumHeight(5);
00149         l->addWidget(m_edit);
00150 
00151         m_edit->addItem(QIcon(QPixmap(nopen)), "");
00152         m_edit->addItem(QIcon(QPixmap(solid)), "");
00153         m_edit->addItem(QIcon(QPixmap(dash)), "");
00154         m_edit->addItem(QIcon(QPixmap(dashdot)), "");
00155         m_edit->addItem(QIcon(QPixmap(dashdotdot)), "");
00156 
00157         setLeavesTheSpaceForRevertButton(true);
00158         setFocusWidget(m_edit);
00159         connect(m_edit, SIGNAL(activated(int)), this, SLOT(slotValueChanged(int)));
00160 }
00161 
00162 LineStyleEdit::~LineStyleEdit()
00163 {}
00164 
00165 QVariant
00166 LineStyleEdit::value() const
00167 {
00168         return m_edit->currentIndex();
00169 }
00170 
00171 void
00172 LineStyleEdit::setValue(const QVariant &value, bool emitChange)
00173 {
00174         if (!value.canConvert(QVariant::Int))
00175                 return;
00176         if ((value.toInt() > 5) || (value.toInt() < 0))
00177                 return;
00178 
00179         m_edit->blockSignals(true);
00180         m_edit->setCurrentIndex(value.toInt());
00181         m_edit->blockSignals(false);
00182         if (emitChange)
00183                 emit valueChanged(this);
00184 }
00185 
00186 void
00187 LineStyleEdit::drawViewer(QPainter *p, const QColorGroup &, const QRect &r, const QVariant &value)
00188 {
00189         p->eraseRect(r);
00190 
00191         if (!value.canConvert(QVariant::Int))
00192                 return;
00193 
00194         QPixmap px;
00195         switch (value.toInt()) {
00196         case 0:
00197                 px = QPixmap(nopen);
00198                 break;
00199         case 1:
00200                 px = QPixmap(solid);
00201                 break;
00202         case 2:
00203                 px = QPixmap(dash);
00204                 break;
00205         case 3:
00206                 px = QPixmap(dashdot);
00207                 break;
00208         case 4:
00209                 px = QPixmap(dashdotdot);
00210                 break;
00211         default:
00212                 return;
00213         }
00214         p->drawPixmap(r.left()+KPROPEDITOR_ITEM_MARGIN, r.top()+(r.height()-px.height())/2, px);
00215 }
00216 
00217 void
00218 LineStyleEdit::slotValueChanged(int)
00219 {
00220         emit valueChanged(this);
00221 }
00222 
00223 void
00224 LineStyleEdit::setReadOnlyInternal(bool readOnly)
00225 {
00226         setVisibleFlag(!readOnly);
00227 }
00228 
00229 #include "linestyleedit.moc"

Généré le Wed Nov 22 23:41:06 2006 pour KPlato par  doxygen 1.5.1-p1