You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
205 lines
5.0 KiB
205 lines
5.0 KiB
15 years ago
|
// Copyright (C) 2003 Dominique Devriese <devriese@kde.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.
|
||
|
|
||
|
// This program is distributed in the hope that it will be useful,
|
||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
// GNU General Public License for more details.
|
||
|
|
||
|
// You should have received a copy of the GNU General Public License
|
||
|
// along with this program; if not, write to the Free Software
|
||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||
|
// 02110-1301, USA.
|
||
|
|
||
|
#include "object_drawer.h"
|
||
|
|
||
|
#include "object_imp.h"
|
||
|
#include "../misc/kigpainter.h"
|
||
|
|
||
15 years ago
|
#include <tqpen.h>
|
||
|
#include <tqnamespace.h>
|
||
15 years ago
|
#include <cassert>
|
||
|
|
||
|
#include <kdebug.h>
|
||
|
|
||
|
void ObjectDrawer::draw( const ObjectImp& imp, KigPainter& p, bool sel ) const
|
||
|
{
|
||
|
bool nv = p.getNightVision( );
|
||
|
if ( mshown || nv )
|
||
|
{
|
||
|
p.setBrushStyle( Qt::NoBrush );
|
||
14 years ago
|
p.setBrushColor( sel ? TQt::red : ( mshown?mcolor:TQt::gray ) );
|
||
|
p.setPen( TQPen ( sel ? TQt::red : ( mshown?mcolor:TQt::gray ), 1) );
|
||
15 years ago
|
p.setWidth( mwidth );
|
||
|
p.setStyle( mstyle );
|
||
|
p.setPointStyle( mpointstyle );
|
||
|
imp.draw( p );
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
bool ObjectDrawer::contains( const ObjectImp& imp, const Coordinate& pt, const KigWidget& w, bool nv ) const
|
||
15 years ago
|
{
|
||
|
bool shownornv = mshown || nv;
|
||
14 years ago
|
return shownornv && imp.contains( pt, mwidth, w );
|
||
15 years ago
|
}
|
||
|
|
||
|
bool ObjectDrawer::shown( ) const
|
||
|
{
|
||
|
return mshown;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQColor ObjectDrawer::color() const
|
||
15 years ago
|
{
|
||
|
return mcolor;
|
||
|
}
|
||
|
|
||
|
ObjectDrawer* ObjectDrawer::getCopyShown( bool s ) const
|
||
|
{
|
||
|
ObjectDrawer* ret = new ObjectDrawer;
|
||
|
ret->mcolor = mcolor;
|
||
|
ret->mshown = s;
|
||
|
ret->mwidth = mwidth;
|
||
|
ret->mstyle = mstyle;
|
||
|
ret->mpointstyle = mpointstyle;
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
15 years ago
|
ObjectDrawer* ObjectDrawer::getCopyColor( const TQColor& c ) const
|
||
15 years ago
|
{
|
||
|
ObjectDrawer* ret = new ObjectDrawer;
|
||
|
ret->mcolor = c;
|
||
|
ret->mshown = mshown;
|
||
|
ret->mwidth = mwidth;
|
||
|
ret->mstyle = mstyle;
|
||
|
ret->mpointstyle = mpointstyle;
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
ObjectDrawer* ObjectDrawer::getCopyWidth( int w ) const
|
||
|
{
|
||
|
ObjectDrawer* ret = new ObjectDrawer;
|
||
|
ret->mcolor = mcolor;
|
||
|
ret->mshown = mshown;
|
||
|
ret->mwidth = w;
|
||
|
ret->mstyle = mstyle;
|
||
|
ret->mpointstyle = mpointstyle;
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
ObjectDrawer* ObjectDrawer::getCopyStyle( Qt::PenStyle s ) const
|
||
|
{
|
||
|
ObjectDrawer* ret = new ObjectDrawer;
|
||
|
ret->mcolor = mcolor;
|
||
|
ret->mshown = mshown;
|
||
|
ret->mwidth = mwidth;
|
||
|
ret->mstyle = s;
|
||
|
ret->mpointstyle = mpointstyle;
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
ObjectDrawer* ObjectDrawer::getCopyPointStyle( int p ) const
|
||
|
{
|
||
|
ObjectDrawer* ret = new ObjectDrawer;
|
||
|
ret->mcolor = mcolor;
|
||
|
ret->mshown = mshown;
|
||
|
ret->mwidth = mwidth;
|
||
|
ret->mstyle = mstyle;
|
||
|
ret->mpointstyle = p;
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
int ObjectDrawer::width() const
|
||
|
{
|
||
|
return mwidth;
|
||
|
}
|
||
|
|
||
|
Qt::PenStyle ObjectDrawer::style() const
|
||
|
{
|
||
|
return mstyle;
|
||
|
}
|
||
|
|
||
|
int ObjectDrawer::pointStyle() const
|
||
|
{
|
||
|
return mpointstyle;
|
||
|
}
|
||
|
|
||
15 years ago
|
ObjectDrawer::ObjectDrawer( const TQColor& color, int width, bool shown, Qt::PenStyle style, int pointStyle )
|
||
15 years ago
|
: mcolor( color ), mshown( shown ), mwidth( width ), mstyle( style ), mpointstyle( pointStyle )
|
||
|
{
|
||
|
}
|
||
|
|
||
|
ObjectDrawer::ObjectDrawer()
|
||
14 years ago
|
: mcolor( TQt::blue ), mshown( true ), mwidth( -1 ), mstyle( Qt::SolidLine ), mpointstyle( 0 )
|
||
15 years ago
|
{
|
||
|
}
|
||
|
|
||
|
bool ObjectDrawer::inRect( const ObjectImp& imp, const Rect& r, const KigWidget& w ) const
|
||
|
{
|
||
|
return mshown && imp.inRect( r, mwidth, w );
|
||
|
}
|
||
|
|
||
15 years ago
|
int ObjectDrawer::pointStyleFromString( const TQString& style )
|
||
15 years ago
|
{
|
||
|
if ( style == "Round" )
|
||
|
return 0;
|
||
|
else if ( style == "RoundEmpty" )
|
||
|
return 1;
|
||
|
else if ( style == "Rectangular" )
|
||
|
return 2;
|
||
|
else if ( style == "RectangularEmpty" )
|
||
|
return 3;
|
||
|
else if ( style == "Cross" )
|
||
|
return 4;
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString ObjectDrawer::pointStyleToString() const
|
||
15 years ago
|
{
|
||
|
if ( mpointstyle == 0 )
|
||
|
return "Round";
|
||
|
else if ( mpointstyle == 1 )
|
||
|
return "RoundEmpty";
|
||
|
else if ( mpointstyle == 2 )
|
||
|
return "Rectangular";
|
||
|
else if ( mpointstyle == 3 )
|
||
|
return "RectangularEmpty";
|
||
|
else if ( mpointstyle == 4 )
|
||
|
return "Cross";
|
||
|
assert( false );
|
||
14 years ago
|
return TQString();
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
Qt::PenStyle ObjectDrawer::styleFromString( const TQString& style )
|
||
15 years ago
|
{
|
||
|
if ( style == "SolidLine" )
|
||
|
return Qt::SolidLine;
|
||
|
else if ( style == "DashLine" )
|
||
|
return Qt::DashLine;
|
||
|
else if ( style == "DotLine" )
|
||
|
return Qt::DotLine;
|
||
|
else if ( style == "DashDotLine" )
|
||
|
return Qt::DashDotLine;
|
||
|
else if ( style == "DashDotDotLine" )
|
||
|
return Qt::DashDotDotLine;
|
||
|
else return Qt::SolidLine;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString ObjectDrawer::styleToString() const
|
||
15 years ago
|
{
|
||
14 years ago
|
if ( mstyle == TQt::SolidLine )
|
||
15 years ago
|
return "SolidLine";
|
||
14 years ago
|
else if ( mstyle == TQt::DashLine )
|
||
15 years ago
|
return "DashLine";
|
||
14 years ago
|
else if ( mstyle == TQt::DotLine )
|
||
15 years ago
|
return "DotLine";
|
||
14 years ago
|
else if ( mstyle == TQt::DashDotLine )
|
||
15 years ago
|
return "DashDotLine";
|
||
14 years ago
|
else if ( mstyle == TQt::DashDotDotLine )
|
||
15 years ago
|
return "DashDotDotLine";
|
||
|
return "SolidLine";
|
||
|
}
|