spring.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
3 Copyright (C) 2005 Jaroslaw Staniek <js@iidea.pl>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include <tqsizepolicy.h>
22#include <tqpainter.h>
23#include <tqdom.h>
24#include <tqvariant.h>
25
26#include <kdebug.h>
27
28#include "objecttree.h"
29#include "container.h"
30#include "form.h"
31#include "formIO.h"
32#include "widgetlibrary.h"
33
34#include "spring.h"
35
36Spring::Spring(TQWidget *parent, const char *name)
37 : TQWidget(parent, name)
38{
39 m_edit = true;
40 m_orient =TQt::Horizontal;
41 setSizeType((SizeType)TQSizePolicy::Expanding);
42}
43
44void
45Spring::setOrientation(TQt::Orientation orient)
46{
47 SizeType type = sizeType();
48 m_orient = orient;
49 setSizeType(type);
50 repaint();
51}
52
53Spring::SizeType
54Spring::sizeType() const
55{
56 if(m_orient ==TQt::Vertical)
57 return (SizeType)sizePolicy().verData();
58 else
59 return (SizeType)sizePolicy().horData();
60}
61
62void
63Spring::setSizeType(SizeType size)
64{
65 if(m_orient ==TQt::Vertical)
66 setSizePolicy(TQSizePolicy::Minimum, (TQSizePolicy::SizeType)size);
67 else
68 setSizePolicy( (TQSizePolicy::SizeType)size, TQSizePolicy::Minimum);
69}
70
71void
72Spring::paintEvent(TQPaintEvent *ev)
73{
74 if(!m_edit)
75 return;
76
77 TQPainter p(this);
78 if(!ev->erased())
79 p.eraseRect(0,0,width(), height());
80 p.setPen(TQPen(TQt::white, 1));
81 p.setRasterOp(TQt::XorROP);
82 TQPointArray pa(4);
83 if(m_orient ==TQt::Vertical) {
84 uint part = (height()+16) / 16;
85 if (part<3)
86 part=3;
87 uint w = width()-1;
88 uint offset = 0;
89 for (uint i=0; i<4; i++, offset+=(part*4)) {
90 pa.putPoints(0, 4,
91 w/2,offset, w,offset+part, w,offset+part, w/2,offset+part*2);
92 p.drawCubicBezier(pa, 0);
93 pa.putPoints(0, 4,
94 w/2,offset+part*2, 0,offset+part*3, 0,offset+part*3, w/2,offset+part*4);
95 p.drawCubicBezier(pa, 0);
96 }
97 }
98 else {
99 uint part = (width()+16) / 16;
100 if (part<3)
101 part=3;
102 uint h = height()-1;
103 uint offset = 0;
104 for (uint i=0; i<4; i++, offset+=(part*4)) {
105 pa.putPoints(0, 4,
106 offset,h/2, offset+part,0, offset+part,0, offset+part*2,h/2);
107 p.drawCubicBezier(pa, 0);
108 pa.putPoints(0, 4,
109 offset+part*2,h/2, offset+part*3,h, offset+part*3,h, offset+part*4,h/2);
110 p.drawCubicBezier(pa, 0);
111 }
112 }
113}
114
115bool
116Spring::isPropertyVisible(const TQCString &name)
117{
118 if((name == "name") || (name == "sizeType") || (name == "orientation") || (name == "geometry"))
119 return true;
120
121 return false;
122}
123
124
125void
126Spring::saveSpring(KFormDesigner::ObjectTreeItem *item, TQDomElement &parentNode, TQDomDocument &domDoc, bool insideGridLayout)
127{
128 TQDomElement tclass = domDoc.createElement("spacer");
129 parentNode.appendChild(tclass);
130
131 if(insideGridLayout)
132 {
133 tclass.setAttribute("row", item->gridRow());
134 tclass.setAttribute("column", item->gridCol());
135 if(item->spanMultipleCells())
136 {
137 tclass.setAttribute("rowspan", item->gridRowSpan());
138 tclass.setAttribute("colspan", item->gridColSpan());
139 }
140 }
141
142 KFormDesigner::FormIO::savePropertyValue(tclass, domDoc, "name", item->widget()->property("name"), item->widget());
143
144 if(parentNode.tagName() == "widget")
145 KFormDesigner::FormIO::savePropertyValue(tclass, domDoc, "geometry", item->widget()->property("geometry"), item->widget());
146
147 if(!item->widget()->sizeHint().isValid())
148 KFormDesigner::FormIO::savePropertyValue(tclass, domDoc, "sizeHint", item->widget()->property("size"), item->widget());
149 else
150 KFormDesigner::FormIO::savePropertyValue(tclass, domDoc, "sizeHint", item->widget()->property("sizeHint"), item->widget());
151
152 KFormDesigner::FormIO::savePropertyValue(tclass, domDoc, "orientation", item->widget()->property("orientation"), item->widget());
153 KFormDesigner::FormIO::savePropertyValue(tclass, domDoc, "sizeType", item->widget()->property("sizeType"), item->widget());
154}
155
156
157#include "spring.moc"
158
An item representing a widget Holds the properties of a widget (classname, name, parent,...
Definition objecttree.h:59