linestyledit.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
3 Copyright (C) 2004 Alexander Dymo <cloudtemple@mskat.net>
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 "linestyleedit.h"
22#include "editoritem.h"
23
24#include <tqpainter.h>
25#include <tqpixmap.h>
26#include <tqcombobox.h>
27#include <tqlayout.h>
28#include <tqvariant.h>
29
30using namespace KoProperty;
31
33 static const char *nopen[]={
34 "48 16 1 1",
35 ". c None",
36 "................................................",
37 "................................................",
38 "................................................",
39 "................................................",
40 "................................................",
41 "................................................",
42 "................................................",
43 "................................................",
44 "................................................",
45 "................................................",
46 "................................................",
47 "................................................",
48 "................................................",
49 "................................................",
50 "................................................",
51 "................................................"};
53 static const char *solid[]={
54 "48 16 2 1",
55 ". c None",
56 "# c #000000",
57 "................................................",
58 "................................................",
59 "................................................",
60 "................................................",
61 "................................................",
62 "................................................",
63 "................................................",
64 ".###########################################....",
65 ".###########################################....",
66 "................................................",
67 "................................................",
68 "................................................",
69 "................................................",
70 "................................................",
71 "................................................",
72 "................................................"};
74 static const char *dash[]={
75 "48 16 2 1",
76 ". c None",
77 "# c #000000",
78 "................................................",
79 "................................................",
80 "................................................",
81 "................................................",
82 "................................................",
83 "................................................",
84 "................................................",
85 ".#########..#########..#########..##########....",
86 ".#########..#########..#########..##########....",
87 "................................................",
88 "................................................",
89 "................................................",
90 "................................................",
91 "................................................",
92 "................................................",
93 "................................................"};
95 static const char *dashdot[]={
96 "48 16 2 1",
97 ". c None",
98 "# c #000000",
99 "................................................",
100 "................................................",
101 "................................................",
102 "................................................",
103 "................................................",
104 "................................................",
105 "................................................",
106 ".#########..##..#########..##..#########..##....",
107 ".#########..##..#########..##..#########..##....",
108 "................................................",
109 "................................................",
110 "................................................",
111 "................................................",
112 "................................................",
113 "................................................",
114 "................................................"};
116 static const char *dashdotdot[]={
117 "48 16 2 1",
118 ". c None",
119 "# c #000000",
120 "................................................",
121 "................................................",
122 "................................................",
123 "................................................",
124 "................................................",
125 "................................................",
126 "................................................",
127 ".#########..##..##..#########..##..##..#####....",
128 ".#########..##..##..#########..##..##..#####....",
129 "................................................",
130 "................................................",
131 "................................................",
132 "................................................",
133 "................................................",
134 "................................................",
135 "................................................"};
136
137
138LineStyleEdit::LineStyleEdit(Property *property, TQWidget *parent, const char *name)
139 : Widget(property, parent, name)
140{
141 TQHBoxLayout *l = new TQHBoxLayout(this, 0, 0);
142 m_edit = new TQComboBox(this);
143 m_edit->setSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Expanding);
144 m_edit->setMinimumHeight(5);
145 l->addWidget(m_edit);
146
147 m_edit->insertItem(TQPixmap(nopen));
148 m_edit->insertItem(TQPixmap(solid));
149 m_edit->insertItem(TQPixmap(dash));
150 m_edit->insertItem(TQPixmap(dashdot));
151 m_edit->insertItem(TQPixmap(dashdotdot));
152
153 setLeavesTheSpaceForRevertButton(true);
154 setFocusWidget(m_edit);
155 connect(m_edit, TQ_SIGNAL(activated(int)), this, TQ_SLOT(slotValueChanged(int)));
156}
157
158LineStyleEdit::~LineStyleEdit()
159{}
160
161TQVariant
162LineStyleEdit::value() const
163{
164 return m_edit->currentItem();
165}
166
167void
168LineStyleEdit::setValue(const TQVariant &value, bool emitChange)
169{
170 if (!value.canCast(TQVariant::Int))
171 return;
172 if ((value.toInt() > 5) || (value.toInt() < 0))
173 return;
174
175 m_edit->blockSignals(true);
176 m_edit->setCurrentItem(value.toInt());
177 m_edit->blockSignals(false);
178 if (emitChange)
179 emit valueChanged(this);
180}
181
182void
183LineStyleEdit::drawViewer(TQPainter *p, const TQColorGroup &, const TQRect &r, const TQVariant &value)
184{
185 p->eraseRect(r);
186
187 if (!value.canCast(TQVariant::Int))
188 return;
189
190 TQPixmap px;
191 switch (value.toInt()) {
192 case 0:
193 px = TQPixmap(nopen);
194 break;
195 case 1:
196 px = TQPixmap(solid);
197 break;
198 case 2:
199 px = TQPixmap(dash);
200 break;
201 case 3:
202 px = TQPixmap(dashdot);
203 break;
204 case 4:
205 px = TQPixmap(dashdotdot);
206 break;
207 default:
208 return;
209 }
210 p->drawPixmap(r.left()+KPROPEDITOR_ITEM_MARGIN, r.top()+(r.height()-px.height())/2, px);
211}
212
213void
214LineStyleEdit::slotValueChanged(int)
215{
216 emit valueChanged(this);
217}
218
219void
220LineStyleEdit::setReadOnlyInternal(bool readOnly)
221{
222 setVisibleFlag(!readOnly);
223}
224
225#include "linestyleedit.moc"
The base class representing a single property.
Definition property.h:177
The base class for all item editors used in Editor.
Definition widget.h:37
const char * name(StdAction id)
Namespace for a set of classes implementing generic properties framework.