1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
/***************************************************************************
* Copyright (C) 2005 by David Saxton *
* david@bluehaze.org *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "solidshape.h"
#include "libraryitem.h"
#include "resizeoverlay.h"
#include <cmath>
#include <kiconloader.h>
#include <klocale.h>
#include <qpainter.h>
//BEGIN class DPRectangle
Item * DPRectangle::construct( ItemDocument *itemDocument, bool newItem, const char *id )
{
return new DPRectangle( itemDocument, newItem, id );
}
LibraryItem* DPRectangle::libraryItem()
{
return new LibraryItem(
QString("dp/rectangle"),
i18n("Rectangle"),
i18n("Other"),
KGlobal::iconLoader()->loadIcon( "text", KIcon::Small ),
LibraryItem::lit_drawpart,
DPRectangle::construct );
}
DPRectangle::DPRectangle( ItemDocument *itemDocument, bool newItem, const char *id )
: DrawPart( itemDocument, newItem, id ? id : "rectangle" )
{
m_pRectangularOverlay = new RectangularOverlay(this);
m_name = i18n("Rectangle");
createProperty( "background", Variant::Type::Bool );
property("background")->setValue(false);
property("background")->setCaption( i18n("Display Background") );
property("background")->setAdvanced(true);
createProperty( "background-color", Variant::Type::Color );
property("background-color")->setValue(Qt::white);
property("background-color")->setCaption( i18n("Background Color") );
property("background-color")->setAdvanced(true);
createProperty( "line-color", Variant::Type::Color );
property("line-color")->setValue(Qt::black);
property("line-color")->setCaption( i18n("Line Color") );
property("line-color")->setAdvanced(true);
createProperty( "line-width", Variant::Type::Int );
property("line-width")->setCaption( i18n("Line Width") );
property("line-width")->setMinValue(1);
property("line-width")->setMaxValue(1000);
property("line-width")->setValue(1);
property("line-width")->setAdvanced(true);
createProperty( "line-style", Variant::Type::PenStyle );
property("line-style")->setAdvanced(true);
setDataPenStyle( "line-style", Qt::SolidLine );
}
DPRectangle::~DPRectangle()
{
}
void DPRectangle::setSelected( bool yes )
{
if ( yes == isSelected() )
return;
DrawPart::setSelected(yes);
m_pRectangularOverlay->showResizeHandles(yes);
}
void DPRectangle::dataChanged()
{
bool displayBackground = dataBool("background");
QColor line_color = dataColor("line-color");
unsigned width = unsigned( dataInt("line-width") );
Qt::PenStyle style = getDataPenStyle("line-style");
setPen( QPen( line_color, width, style ) );
if (displayBackground)
setBrush( dataColor("background-color") );
else
setBrush( Qt::NoBrush );
postResize();
update();
}
QSize DPRectangle::minimumSize() const
{
int side = QMAX(16, pen().width()+2);
return QSize( side, side );
}
void DPRectangle::postResize()
{
setItemPoints( m_sizeRect, false );
}
QRect DPRectangle::drawRect() const
{
int lw = pen().width();
if ( lw > m_sizeRect.width() )
lw = m_sizeRect.width();
if ( lw > m_sizeRect.height() )
lw = m_sizeRect.height();
return QRect( int(x() + m_sizeRect.x()+lw/2), int(y() + m_sizeRect.y()+lw/2),
m_sizeRect.width()-lw, m_sizeRect.height()-lw );
}
void DPRectangle::drawShape( QPainter & p )
{
p.drawRect(drawRect());
}
//END class DPRectangle
//BEGIN class DPEllipse
Item * DPEllipse::construct( ItemDocument *itemDocument, bool newItem, const char *id )
{
return new DPEllipse( itemDocument, newItem, id );
}
LibraryItem* DPEllipse::libraryItem()
{
return new LibraryItem(
QString("dp/ellipse"),
i18n("Ellipse"),
i18n("Other"),
KGlobal::iconLoader()->loadIcon( "text", KIcon::Small ),
LibraryItem::lit_drawpart,
DPEllipse::construct );
}
DPEllipse::DPEllipse( ItemDocument *itemDocument, bool newItem, const char *id )
: DPRectangle( itemDocument, newItem, id ? id : "ellipse" )
{
m_name = i18n("Ellipse");
}
DPEllipse::~DPEllipse()
{
}
void DPEllipse::postResize()
{
QRect br = m_sizeRect;
// Make octagon that roughly covers ellipse
QPointArray pa(8);
pa[0] = QPoint( br.x() + br.width()/4, br.y() );
pa[1] = QPoint( br.x() + 3*br.width()/4, br.y() );
pa[2] = QPoint( br.x() + br.width(), br.y() + br.height()/4 );
pa[3] = QPoint( br.x() + br.width(), br.y() + 3*br.height()/4 );
pa[4] = QPoint( br.x() + 3*br.width()/4, br.y() + br.height() );
pa[5] = QPoint( br.x() + br.width()/4, br.y() + br.height() );
pa[6] = QPoint( br.x(), br.y() + 3*br.height()/4 );
pa[7] = QPoint( br.x(), br.y() + br.height()/4 );
setItemPoints( pa, false );
}
void DPEllipse::drawShape( QPainter & p )
{
p.drawEllipse(drawRect());
}
//END class SolidShape
|