dptext.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2003-2005 by David Saxton                               *
00003  *   david@bluehaze.org                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  ***************************************************************************/
00010 
00011 #include "dptext.h"
00012 #include "itemdocument.h"
00013 #include "libraryitem.h"
00014 #include "resizeoverlay.h"
00015 
00016 #include <kiconloader.h>
00017 #include <klocale.h>
00018 #include <qpainter.h>
00019 
00020 Item* DPText::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00021 {
00022         return new DPText( itemDocument, newItem, id );
00023 }
00024 
00025 LibraryItem* DPText::libraryItem()
00026 {
00027         QStringList idList;
00028         idList << "dp/text" << "dp/canvas_text" << "canvas_text";
00029         
00030         return new LibraryItem(
00031                 idList,
00032                 i18n("Canvas Text"),
00033                 i18n("Other"),
00034                 KGlobal::iconLoader()->loadIcon( "text", KIcon::Small ),
00035                 LibraryItem::lit_drawpart,
00036                 DPText::construct );
00037 }
00038 
00039 DPText::DPText( ItemDocument *itemDocument, bool newItem, const char *id )
00040         : DrawPart( itemDocument, newItem, (id) ? id : "canvas_text" )
00041 {
00042         m_rectangularOverlay = new RectangularOverlay(this);
00043         m_name = i18n("Text");
00044         m_desc = i18n("Doubleclick the Text Item to set the text");
00045         
00046         createProperty( "text", Variant::Type::Multiline );
00047         property("text")->setValue( i18n("Text") );
00048         
00049         createProperty( "background", Variant::Type::Bool );
00050         property("background")->setValue(false);
00051         property("background")->setCaption( i18n("Display Background") );
00052         property("background")->setAdvanced(true);
00053         
00054         createProperty( "background-color", Variant::Type::Color );
00055         property("background-color")->setValue(Qt::white);
00056         property("background-color")->setCaption( i18n("Background Color") );
00057         property("background-color")->setAdvanced(true);
00058         
00059         createProperty( "frame-color", Variant::Type::Color );
00060         property("frame-color")->setValue(Qt::black);
00061         property("frame-color")->setCaption( i18n("Frame Color") );
00062         property("frame-color")->setAdvanced(true);
00063         
00064         createProperty( "text-color", Variant::Type::Color );
00065         property("text-color")->setValue(Qt::black);
00066         property("text-color")->setCaption( i18n("Text Color") );
00067 }
00068 
00069 DPText::~DPText()
00070 {
00071 }
00072 
00073 void DPText::setSelected( bool yes )
00074 {
00075         if ( yes == isSelected() )
00076                 return;
00077         
00078         DrawPart::setSelected(yes);
00079         m_rectangularOverlay->showResizeHandles(yes);
00080 }
00081 
00082 
00083 void DPText::dataChanged()
00084 {
00085         m_caption = dataString("text");
00086         b_displayBackground = dataBool("background");
00087         m_backgroundColor = dataColor("background-color");
00088         m_textColor = dataColor("text-color");
00089         m_frameColor = dataColor("frame-color");
00090         update();
00091 }
00092 
00093 
00094 void DPText::postResize()
00095 {
00096         setItemPoints( QPointArray(m_sizeRect), false );
00097 }
00098 
00099 
00100 QSize DPText::minimumSize() const
00101 {
00102         return QSize( 48, 24 );
00103 }
00104 
00105 
00106 void DPText::drawShape( QPainter &p )
00107 {
00108         QRect bound = m_sizeRect;
00109         bound.setWidth( bound.width()-2 );
00110         bound.setHeight( bound.height()-2 );
00111         bound.moveBy( int(x()+1), int(y()+1) );
00112         
00113         if (b_displayBackground)
00114         {
00115                 p.save();
00116                 p.setPen( QPen( m_frameColor, 1, Qt::DotLine) );
00117                 p.setBrush(m_backgroundColor);
00118                 p.drawRect(bound);
00119                 p.restore();
00120         }
00121         
00122         const int pad = 6;
00123         
00124         bound.setLeft( bound.left()+pad );
00125         bound.setTop( bound.top()+pad );
00126         bound.setRight( bound.right()-pad );
00127         bound.setBottom( bound.bottom()-pad );
00128         
00129         p.setPen(m_textColor);
00130         p.setFont( font() );
00131         p.drawText( bound, (Qt::WordBreak | Qt::AlignHCenter | Qt::AlignVCenter), m_caption );
00132 }
00133 

Generated on Tue May 8 17:05:29 2007 for KTechLab by  doxygen 1.5.1