lib

linestyledit.cpp

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.h>
00025 #include <qpixmap.h>
00026 #include <qcombobox.h>
00027 #include <qlayout.h>
00028 #include <qvariant.h>
00029 
00030 using namespace KoProperty;
00031 
00033     static const char *nopen[]={
00034     "48 16 1 1",
00035     ". c None",
00036     "................................................",
00037     "................................................",
00038     "................................................",
00039     "................................................",
00040     "................................................",
00041     "................................................",
00042     "................................................",
00043     "................................................",
00044     "................................................",
00045     "................................................",
00046     "................................................",
00047     "................................................",
00048     "................................................",
00049     "................................................",
00050     "................................................",
00051     "................................................"};
00053     static const char *solid[]={
00054     "48 16 2 1",
00055     ". c None",
00056     "# c #000000",
00057     "................................................",
00058     "................................................",
00059     "................................................",
00060     "................................................",
00061     "................................................",
00062     "................................................",
00063     "................................................",
00064     ".###########################################....",
00065     ".###########################################....",
00066     "................................................",
00067     "................................................",
00068     "................................................",
00069     "................................................",
00070     "................................................",
00071     "................................................",
00072     "................................................"};
00074     static const char *dash[]={
00075     "48 16 2 1",
00076     ". c None",
00077     "# c #000000",
00078     "................................................",
00079     "................................................",
00080     "................................................",
00081     "................................................",
00082     "................................................",
00083     "................................................",
00084     "................................................",
00085     ".#########..#########..#########..##########....",
00086     ".#########..#########..#########..##########....",
00087     "................................................",
00088     "................................................",
00089     "................................................",
00090     "................................................",
00091     "................................................",
00092     "................................................",
00093     "................................................"};
00095     static const char *dashdot[]={
00096     "48 16 2 1",
00097     ". c None",
00098     "# c #000000",
00099     "................................................",
00100     "................................................",
00101     "................................................",
00102     "................................................",
00103     "................................................",
00104     "................................................",
00105     "................................................",
00106     ".#########..##..#########..##..#########..##....",
00107     ".#########..##..#########..##..#########..##....",
00108     "................................................",
00109     "................................................",
00110     "................................................",
00111     "................................................",
00112     "................................................",
00113     "................................................",
00114     "................................................"};
00116     static const char *dashdotdot[]={
00117     "48 16 2 1",
00118     ". c None",
00119     "# c #000000",
00120     "................................................",
00121     "................................................",
00122     "................................................",
00123     "................................................",
00124     "................................................",
00125     "................................................",
00126     "................................................",
00127     ".#########..##..##..#########..##..##..#####....",
00128     ".#########..##..##..#########..##..##..#####....",
00129     "................................................",
00130     "................................................",
00131     "................................................",
00132     "................................................",
00133     "................................................",
00134     "................................................",
00135     "................................................"};
00136 
00137 
00138 LineStyleEdit::LineStyleEdit(Property *property, QWidget *parent, const char *name)
00139  : Widget(property, parent, name)
00140 {
00141     QHBoxLayout *l = new QHBoxLayout(this, 0, 0);
00142     m_edit = new QComboBox(this);
00143     m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
00144     m_edit->setMinimumHeight(5);
00145     l->addWidget(m_edit);
00146 
00147     m_edit->insertItem(QPixmap(nopen));
00148     m_edit->insertItem(QPixmap(solid));
00149     m_edit->insertItem(QPixmap(dash));
00150     m_edit->insertItem(QPixmap(dashdot));
00151     m_edit->insertItem(QPixmap(dashdotdot));
00152 
00153     setLeavesTheSpaceForRevertButton(true);
00154     setFocusWidget(m_edit);
00155     connect(m_edit, SIGNAL(activated(int)), this, SLOT(slotValueChanged(int)));
00156 }
00157 
00158 LineStyleEdit::~LineStyleEdit()
00159 {}
00160 
00161 QVariant
00162 LineStyleEdit::value() const
00163 {
00164     return m_edit->currentItem();
00165 }
00166 
00167 void
00168 LineStyleEdit::setValue(const QVariant &value, bool emitChange)
00169 {
00170     if (!value.canCast(QVariant::Int))
00171         return;
00172     if ((value.toInt() > 5) || (value.toInt() < 0))
00173         return;
00174 
00175     m_edit->blockSignals(true);
00176     m_edit->setCurrentItem(value.toInt());
00177     m_edit->blockSignals(false);
00178     if (emitChange)
00179         emit valueChanged(this);
00180 }
00181 
00182 void
00183 LineStyleEdit::drawViewer(QPainter *p, const QColorGroup &, const QRect &r, const QVariant &value)
00184 {
00185     p->eraseRect(r);
00186 
00187     if (!value.canCast(QVariant::Int))
00188         return;
00189 
00190     QPixmap px;
00191     switch (value.toInt()) {
00192     case 0:
00193         px = QPixmap(nopen);
00194         break;
00195     case 1:
00196         px = QPixmap(solid);
00197         break;
00198     case 2:
00199         px = QPixmap(dash);
00200         break;
00201     case 3:
00202         px = QPixmap(dashdot);
00203         break;
00204     case 4:
00205         px = QPixmap(dashdotdot);
00206         break;
00207     default:
00208         return;
00209     }
00210     p->drawPixmap(r.left()+KPROPEDITOR_ITEM_MARGIN, r.top()+(r.height()-px.height())/2, px);
00211 }
00212 
00213 void
00214 LineStyleEdit::slotValueChanged(int)
00215 {
00216     emit valueChanged(this);
00217 }
00218 
00219 void
00220 LineStyleEdit::setReadOnlyInternal(bool readOnly)
00221 {
00222     setVisibleFlag(!readOnly);
00223 }
00224 
00225 #include "linestyleedit.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys