kexi

spring.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
00003    Copyright (C) 2005 Jaroslaw Staniek <js@iidea.pl>
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 <qsizepolicy.h>
00022 #include <qpainter.h>
00023 #include <qdom.h>
00024 #include <qvariant.h>
00025 
00026 #include <kdebug.h>
00027 
00028 #include "objecttree.h"
00029 #include "container.h"
00030 #include "form.h"
00031 #include "formIO.h"
00032 #include "widgetlibrary.h"
00033 
00034 #include "spring.h"
00035 
00036 Spring::Spring(QWidget *parent, const char *name)
00037   : QWidget(parent, name)
00038 {
00039     m_edit = true;
00040     m_orient = Horizontal;
00041     setSizeType((SizeType)QSizePolicy::Expanding);
00042 }
00043 
00044 void
00045 Spring::setOrientation(Orientation orient)
00046 {
00047     SizeType type = sizeType();
00048     m_orient = orient;
00049     setSizeType(type);
00050     repaint();
00051 }
00052 
00053 Spring::SizeType
00054 Spring::sizeType() const
00055 {
00056     if(m_orient == Vertical)
00057         return (SizeType)sizePolicy().verData();
00058     else
00059         return (SizeType)sizePolicy().horData();
00060 }
00061 
00062 void
00063 Spring::setSizeType(SizeType size)
00064 {
00065     if(m_orient == Vertical)
00066         setSizePolicy(QSizePolicy::Minimum, (QSizePolicy::SizeType)size);
00067     else
00068         setSizePolicy( (QSizePolicy::SizeType)size, QSizePolicy::Minimum);
00069 }
00070 
00071 void
00072 Spring::paintEvent(QPaintEvent *ev)
00073 {
00074     if(!m_edit)
00075         return;
00076 
00077     QPainter p(this);
00078     if(!ev->erased())
00079         p.eraseRect(0,0,width(), height());
00080     p.setPen(QPen(Qt::white, 1));
00081     p.setRasterOp(Qt::XorROP);
00082     QPointArray pa(4);
00083     if(m_orient == Vertical) {
00084         uint part = (height()+16) / 16;
00085         if (part<3)
00086             part=3;
00087         uint w = width()-1;
00088         uint offset = 0;
00089         for (uint i=0; i<4; i++, offset+=(part*4)) {
00090             pa.putPoints(0, 4,
00091                 w/2,offset, w,offset+part, w,offset+part, w/2,offset+part*2);
00092             p.drawCubicBezier(pa, 0);
00093             pa.putPoints(0, 4,
00094                 w/2,offset+part*2, 0,offset+part*3, 0,offset+part*3, w/2,offset+part*4);
00095             p.drawCubicBezier(pa, 0);
00096         }
00097     }
00098     else {
00099         uint part = (width()+16) / 16;
00100         if (part<3)
00101             part=3;
00102         uint h = height()-1;
00103         uint offset = 0;
00104         for (uint i=0; i<4; i++, offset+=(part*4)) {
00105             pa.putPoints(0, 4,
00106                 offset,h/2, offset+part,0, offset+part,0, offset+part*2,h/2);
00107             p.drawCubicBezier(pa, 0);
00108             pa.putPoints(0, 4,
00109                 offset+part*2,h/2, offset+part*3,h, offset+part*3,h, offset+part*4,h/2);
00110             p.drawCubicBezier(pa, 0);
00111         }
00112     }
00113 }
00114 
00115 bool
00116 Spring::isPropertyVisible(const QCString &name)
00117 {
00118     if((name == "name") || (name == "sizeType") || (name == "orientation") || (name == "geometry"))
00119         return true;
00120 
00121     return false;
00122 }
00123 
00124 
00125 void
00126 Spring::saveSpring(KFormDesigner::ObjectTreeItem *item, QDomElement &parentNode, QDomDocument &domDoc, bool insideGridLayout)
00127 {
00128     QDomElement tclass = domDoc.createElement("spacer");
00129     parentNode.appendChild(tclass);
00130 
00131     if(insideGridLayout)
00132     {
00133         tclass.setAttribute("row", item->gridRow());
00134         tclass.setAttribute("column", item->gridCol());
00135         if(item->spanMultipleCells())
00136         {
00137             tclass.setAttribute("rowspan", item->gridRowSpan());
00138             tclass.setAttribute("colspan", item->gridColSpan());
00139         }
00140     }
00141 
00142     KFormDesigner::FormIO::savePropertyValue(tclass, domDoc, "name", item->widget()->property("name"), item->widget());
00143 
00144     if(parentNode.tagName() == "widget")
00145         KFormDesigner::FormIO::savePropertyValue(tclass, domDoc, "geometry", item->widget()->property("geometry"), item->widget());
00146 
00147     if(!item->widget()->sizeHint().isValid())
00148         KFormDesigner::FormIO::savePropertyValue(tclass, domDoc, "sizeHint", item->widget()->property("size"), item->widget());
00149     else
00150         KFormDesigner::FormIO::savePropertyValue(tclass, domDoc, "sizeHint", item->widget()->property("sizeHint"), item->widget());
00151 
00152     KFormDesigner::FormIO::savePropertyValue(tclass, domDoc, "orientation", item->widget()->property("orientation"), item->widget());
00153     KFormDesigner::FormIO::savePropertyValue(tclass, domDoc, "sizeType", item->widget()->property("sizeType"), item->widget());
00154 }
00155 
00156 
00157 #include "spring.moc"
00158 
KDE Home | KDE Accessibility Home | Description of Access Keys