00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "solidshape.h"
00012 #include "libraryitem.h"
00013 #include "resizeoverlay.h"
00014
00015 #include <cmath>
00016 #include <kiconloader.h>
00017 #include <klocale.h>
00018 #include <qpainter.h>
00019
00020
00021
00022 Item * DPRectangle::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00023 {
00024 return new DPRectangle( itemDocument, newItem, id );
00025 }
00026
00027 LibraryItem* DPRectangle::libraryItem()
00028 {
00029 return new LibraryItem(
00030 QString("dp/rectangle"),
00031 i18n("Rectangle"),
00032 i18n("Other"),
00033 KGlobal::iconLoader()->loadIcon( "text", KIcon::Small ),
00034 LibraryItem::lit_drawpart,
00035 DPRectangle::construct );
00036 }
00037
00038 DPRectangle::DPRectangle( ItemDocument *itemDocument, bool newItem, const char *id )
00039 : DrawPart( itemDocument, newItem, id ? id : "rectangle" )
00040 {
00041 m_pRectangularOverlay = new RectangularOverlay(this);
00042 m_name = i18n("Rectangle");
00043
00044 createProperty( "background", Variant::Type::Bool );
00045 property("background")->setValue(false);
00046 property("background")->setCaption( i18n("Display Background") );
00047 property("background")->setAdvanced(true);
00048
00049 createProperty( "background-color", Variant::Type::Color );
00050 property("background-color")->setValue(Qt::white);
00051 property("background-color")->setCaption( i18n("Background Color") );
00052 property("background-color")->setAdvanced(true);
00053
00054 createProperty( "line-color", Variant::Type::Color );
00055 property("line-color")->setValue(Qt::black);
00056 property("line-color")->setCaption( i18n("Line Color") );
00057 property("line-color")->setAdvanced(true);
00058
00059 createProperty( "line-width", Variant::Type::Int );
00060 property("line-width")->setCaption( i18n("Line Width") );
00061 property("line-width")->setMinValue(1);
00062 property("line-width")->setMaxValue(1000);
00063 property("line-width")->setValue(1);
00064 property("line-width")->setAdvanced(true);
00065
00066 createProperty( "line-style", Variant::Type::PenStyle );
00067 property("line-style")->setAdvanced(true);
00068 setDataPenStyle( "line-style", Qt::SolidLine );
00069 }
00070
00071 DPRectangle::~DPRectangle()
00072 {
00073 }
00074
00075 void DPRectangle::setSelected( bool yes )
00076 {
00077 if ( yes == isSelected() )
00078 return;
00079
00080 DrawPart::setSelected(yes);
00081 m_pRectangularOverlay->showResizeHandles(yes);
00082 }
00083
00084
00085 void DPRectangle::dataChanged()
00086 {
00087 bool displayBackground = dataBool("background");
00088 QColor line_color = dataColor("line-color");
00089 unsigned width = unsigned( dataInt("line-width") );
00090 Qt::PenStyle style = getDataPenStyle("line-style");
00091
00092 setPen( QPen( line_color, width, style ) );
00093
00094 if (displayBackground)
00095 setBrush( dataColor("background-color") );
00096 else
00097 setBrush( Qt::NoBrush );
00098
00099 postResize();
00100 update();
00101 }
00102
00103
00104 QSize DPRectangle::minimumSize() const
00105 {
00106 int side = QMAX(16, pen().width()+2);
00107 return QSize( side, side );
00108 }
00109
00110
00111 void DPRectangle::postResize()
00112 {
00113 setItemPoints( m_sizeRect, false );
00114 }
00115
00116
00117 QRect DPRectangle::drawRect() const
00118 {
00119 int lw = pen().width();
00120
00121 if ( lw > m_sizeRect.width() )
00122 lw = m_sizeRect.width();
00123
00124 if ( lw > m_sizeRect.height() )
00125 lw = m_sizeRect.height();
00126
00127 return QRect( int(x() + m_sizeRect.x()+lw/2), int(y() + m_sizeRect.y()+lw/2),
00128 m_sizeRect.width()-lw, m_sizeRect.height()-lw );
00129 }
00130
00131
00132 void DPRectangle::drawShape( QPainter & p )
00133 {
00134 p.drawRect(drawRect());
00135 }
00136
00137
00138
00139
00140 Item * DPEllipse::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00141 {
00142 return new DPEllipse( itemDocument, newItem, id );
00143 }
00144
00145 LibraryItem* DPEllipse::libraryItem()
00146 {
00147 return new LibraryItem(
00148 QString("dp/ellipse"),
00149 i18n("Ellipse"),
00150 i18n("Other"),
00151 KGlobal::iconLoader()->loadIcon( "text", KIcon::Small ),
00152 LibraryItem::lit_drawpart,
00153 DPEllipse::construct );
00154 }
00155
00156 DPEllipse::DPEllipse( ItemDocument *itemDocument, bool newItem, const char *id )
00157 : DPRectangle( itemDocument, newItem, id ? id : "ellipse" )
00158 {
00159 m_name = i18n("Ellipse");
00160 }
00161
00162 DPEllipse::~DPEllipse()
00163 {
00164 }
00165
00166
00167 void DPEllipse::postResize()
00168 {
00169 QRect br = m_sizeRect;
00170
00171
00172 QPointArray pa(8);
00173 pa[0] = QPoint( br.x() + br.width()/4, br.y() );
00174 pa[1] = QPoint( br.x() + 3*br.width()/4, br.y() );
00175 pa[2] = QPoint( br.x() + br.width(), br.y() + br.height()/4 );
00176 pa[3] = QPoint( br.x() + br.width(), br.y() + 3*br.height()/4 );
00177 pa[4] = QPoint( br.x() + 3*br.width()/4, br.y() + br.height() );
00178 pa[5] = QPoint( br.x() + br.width()/4, br.y() + br.height() );
00179 pa[6] = QPoint( br.x(), br.y() + 3*br.height()/4 );
00180 pa[7] = QPoint( br.x(), br.y() + br.height()/4 );
00181
00182 setItemPoints( pa, false );
00183 }
00184
00185
00186 void DPEllipse::drawShape( QPainter & p )
00187 {
00188 p.drawEllipse(drawRect());
00189 }
00190
00191
00192