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.
283 lines
8.6 KiB
283 lines
8.6 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Made by Tomislav Lukman (tomislav.lukman@ck.t-com.hr)
|
||
|
Copyright (C) 2005, The Karbon Developers
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library 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
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
4 years ago
|
/* vsmallpreview.cpp */
|
||
14 years ago
|
#include <tqcolor.h>
|
||
|
#include <tqframe.h>
|
||
|
#include <tqlabel.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
14 years ago
|
#include <tqpixmap.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
#include <KoPoint.h>
|
||
|
|
||
|
#include "vcolor.h"
|
||
|
#include "vfill.h"
|
||
|
#include "vgradient.h"
|
||
|
#include "vkopainter.h"
|
||
|
#include "vpattern.h"
|
||
|
#include "vstroke.h"
|
||
|
|
||
|
#include "vsmallpreview.h"
|
||
|
|
||
|
#define FRAMEWIDTH 40
|
||
|
|
||
13 years ago
|
VSmallPreview::VSmallPreview( TQWidget* parent, const char* name )
|
||
|
: TQWidget( parent, name )
|
||
15 years ago
|
{
|
||
13 years ago
|
/* Create widget layout */
|
||
|
TQHBoxLayout *layout = new TQHBoxLayout( this, 4 );
|
||
14 years ago
|
m_strokeLabel = new TQLabel( i18n( "Stroke: None" ), this );
|
||
13 years ago
|
layout->addWidget( m_strokeLabel );
|
||
14 years ago
|
m_strokeFrame = new TQFrame( this );
|
||
15 years ago
|
m_strokeFrame->setFixedWidth ( FRAMEWIDTH );
|
||
14 years ago
|
m_strokeFrame->setFrameStyle( TQFrame::GroupBoxPanel | TQFrame::Plain );
|
||
13 years ago
|
layout->addWidget( m_strokeFrame );
|
||
14 years ago
|
m_fillLabel = new TQLabel( i18n( "Fill: None" ), this );
|
||
13 years ago
|
layout->addWidget( m_fillLabel );
|
||
14 years ago
|
m_fillFrame = new TQFrame( this );
|
||
15 years ago
|
m_fillFrame->setFixedWidth ( FRAMEWIDTH );
|
||
14 years ago
|
m_fillFrame->setFrameStyle( TQFrame::GroupBoxPanel | TQFrame::Plain );
|
||
13 years ago
|
layout->addWidget( m_fillFrame );
|
||
|
layout->activate();
|
||
15 years ago
|
|
||
|
m_fill = VFill();
|
||
|
m_stroke = VStroke();
|
||
|
}
|
||
|
|
||
|
VSmallPreview::~VSmallPreview()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void
|
||
|
VSmallPreview::update( const VStroke &s, const VFill &f )
|
||
|
{
|
||
|
if( &f )
|
||
|
m_fill = f;
|
||
|
else
|
||
|
m_fill = VFill();
|
||
|
if( &s )
|
||
|
m_stroke = s;
|
||
|
else
|
||
|
m_stroke = VStroke();
|
||
|
|
||
|
drawStroke( m_stroke );
|
||
|
drawFill( m_fill );
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VSmallPreview::paintEvent( TQPaintEvent* /*event*/ )
|
||
15 years ago
|
{
|
||
|
drawStroke( m_stroke );
|
||
|
drawFill( m_fill );
|
||
|
}
|
||
|
|
||
|
void
|
||
|
VSmallPreview::drawFill( const VFill &f )
|
||
|
{
|
||
|
VFill fill;
|
||
|
VStroke stroke;
|
||
|
|
||
14 years ago
|
TQPixmap m_pixmap;
|
||
15 years ago
|
m_pixmap.resize( m_fillFrame->width(), m_fillFrame->height() );
|
||
14 years ago
|
VKoPainter* m_painter = new VKoPainter( TQT_TQPAINTDEVICE(&m_pixmap), m_fillFrame->width(), m_fillFrame->height() );
|
||
15 years ago
|
|
||
|
m_painter->begin();
|
||
14 years ago
|
m_painter->setPen( TQt::NoPen );
|
||
|
fill.setColor( TQt::white );
|
||
15 years ago
|
m_painter->setBrush( fill );
|
||
|
m_painter->drawRect( KoRect( 0, 0, m_fillFrame->width(), m_fillFrame->height() ) );
|
||
|
|
||
|
switch ( f.type() )
|
||
|
{
|
||
|
case VFill::solid:
|
||
|
{
|
||
|
switch ( f.color().colorSpace() )
|
||
|
{
|
||
|
case VColor::rgb:
|
||
|
m_fillLabel->setText( i18n( "Fill: RGB") ); break;
|
||
|
case VColor::cmyk:
|
||
|
m_fillLabel->setText( i18n( "Fill: CMYK") ); break;
|
||
|
case VColor::hsb:
|
||
|
m_fillLabel->setText( i18n( "Fill: HSB") ); break;
|
||
|
case VColor::gray:
|
||
|
m_fillLabel->setText( i18n( "Fill: Grayscale") ); break;
|
||
|
default:
|
||
|
m_fillLabel->setText( i18n( "Fill: Color") );
|
||
|
}
|
||
|
fill.setColor( f.color() );
|
||
|
break;
|
||
|
}
|
||
|
case VFill::grad:
|
||
|
{
|
||
|
fill.gradient() = f.gradient();
|
||
|
fill.setType( VFill::grad );
|
||
|
m_fillLabel->setText( i18n( "Fill: Gradient") );
|
||
|
if( f.gradient().type() == VGradient::linear )
|
||
|
{
|
||
|
fill.gradient().setOrigin( KoPoint( m_fillFrame->width() * 0.5, 0 ) );
|
||
|
fill.gradient().setVector( KoPoint( m_fillFrame->width() * 0.5, m_fillFrame->height() ) );
|
||
|
}
|
||
|
else if( f.gradient().type() == VGradient::radial ||
|
||
|
f.gradient().type() == VGradient::conic )
|
||
|
{
|
||
|
fill.gradient().setOrigin( KoPoint( m_fillFrame->width() * 0.5, m_fillFrame->height() * 0.5 ) );
|
||
|
fill.gradient().setFocalPoint( KoPoint( m_fillFrame->width() * 0.5, m_fillFrame->height() * 0.5 ) );
|
||
|
fill.gradient().setVector( KoPoint( m_fillFrame->width() * 0.5, m_fillFrame->height() ) );
|
||
|
}
|
||
|
break;
|
||
|
|
||
|
}
|
||
|
case VFill::patt:
|
||
|
{
|
||
|
fill.pattern() = f.pattern();
|
||
|
fill.pattern().setOrigin( KoPoint( 0, 0 ) );
|
||
|
fill.pattern().setVector( KoPoint( m_fillFrame->width() * 0.5, 0 ) );
|
||
|
fill.setType( VFill::patt );
|
||
|
m_fillLabel->setText( i18n( "Fill: Pattern") );
|
||
|
break;
|
||
|
}
|
||
|
default: //None or unknown
|
||
|
{
|
||
|
m_fillLabel->setText( i18n( "Fill: None") );
|
||
14 years ago
|
fill.setColor( TQt::white );
|
||
15 years ago
|
m_painter->setBrush( fill );
|
||
|
m_painter->drawRect( KoRect( 0, 0, m_fillFrame->width(), m_fillFrame->height() ) );
|
||
14 years ago
|
stroke.setColor( TQt::red );
|
||
15 years ago
|
stroke.setLineWidth( 2.0 );
|
||
|
m_painter->setPen( stroke );
|
||
|
m_painter->newPath();
|
||
|
m_painter->moveTo( KoPoint( 4, m_fillFrame->height() - 4 ) );
|
||
|
m_painter->lineTo( KoPoint( m_fillFrame->width() - 4, 4 ) );
|
||
|
m_painter->strokePath();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if( f.type() != VFill::none )
|
||
|
{
|
||
|
m_painter->setPen( stroke );
|
||
|
m_painter->setBrush( fill );
|
||
|
m_painter->drawRect( KoRect( 0, 0, m_fillFrame->width(), m_fillFrame->height() ) );
|
||
|
}
|
||
|
|
||
|
m_painter->end();
|
||
|
|
||
|
bitBlt( m_fillFrame, m_fillFrame->frameWidth(), m_fillFrame->frameWidth(), &m_pixmap, m_fillFrame->frameWidth(), m_fillFrame->frameWidth(), m_fillFrame->width() - m_fillFrame->frameWidth(), m_fillFrame->height() - m_fillFrame->frameWidth(), CopyROP );
|
||
|
|
||
|
delete ( m_painter );
|
||
|
}
|
||
|
|
||
|
void
|
||
|
VSmallPreview::drawStroke( const VStroke &s )
|
||
|
{
|
||
|
VFill fill;
|
||
|
VStroke stroke;
|
||
|
|
||
14 years ago
|
TQPixmap m_pixmap;
|
||
15 years ago
|
m_pixmap.resize( m_fillFrame->width(), m_fillFrame->height() );
|
||
14 years ago
|
VKoPainter* m_painter = new VKoPainter( TQT_TQPAINTDEVICE(&m_pixmap), m_fillFrame->width(), m_fillFrame->height() );
|
||
15 years ago
|
|
||
|
m_painter->begin();
|
||
14 years ago
|
m_painter->setPen( TQt::NoPen );
|
||
|
fill.setColor( TQt::white );
|
||
15 years ago
|
m_painter->setBrush( fill );
|
||
|
m_painter->drawRect( KoRect( 0, 0, m_strokeFrame->width(), m_strokeFrame->height() ) );
|
||
|
|
||
|
switch ( s.type() )
|
||
|
{
|
||
|
case VStroke::solid:
|
||
|
{
|
||
|
switch ( s.color().colorSpace() )
|
||
|
{
|
||
|
case VColor::rgb:
|
||
|
m_strokeLabel->setText( i18n( "Stroke: RGB") ); break;
|
||
|
case VColor::cmyk:
|
||
|
m_strokeLabel->setText( i18n( "Stroke: CMYK") ); break;
|
||
|
case VColor::hsb:
|
||
|
m_strokeLabel->setText( i18n( "Stroke: HSB") ); break;
|
||
|
case VColor::gray:
|
||
|
m_strokeLabel->setText( i18n( "Stroke: Grayscale") ); break;
|
||
|
default:
|
||
|
m_strokeLabel->setText( i18n( "Stroke: Color") );
|
||
|
}
|
||
|
fill.setColor( s.color() );
|
||
|
break;
|
||
|
}
|
||
|
case VStroke::grad:
|
||
|
{
|
||
|
fill.gradient() = s.gradient();
|
||
|
fill.setType( VFill::grad );
|
||
|
m_strokeLabel->setText( i18n( "Stroke: Gradient") );
|
||
|
if( s.gradient().type() == VGradient::linear )
|
||
|
{
|
||
|
fill.gradient().setOrigin( KoPoint( m_strokeFrame->width() * 0.5, 0 ) );
|
||
|
fill.gradient().setVector( KoPoint( m_strokeFrame->width() * 0.5, m_strokeFrame->height() ) );
|
||
|
}
|
||
|
else if( s.gradient().type() == VGradient::radial ||
|
||
|
s.gradient().type() == VGradient::conic )
|
||
|
{
|
||
|
fill.gradient().setOrigin( KoPoint( m_strokeFrame->width() * 0.5, m_strokeFrame->height() * 0.5 ) );
|
||
|
fill.gradient().setFocalPoint( KoPoint( m_strokeFrame->width() * 0.5, m_strokeFrame->height() * 0.5 ) );
|
||
|
fill.gradient().setVector( KoPoint( m_strokeFrame->width() * 0.5, m_strokeFrame->height() ) );
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
case VStroke::patt:
|
||
|
{
|
||
|
fill.pattern() = s.pattern();
|
||
|
fill.pattern().setOrigin( KoPoint( 0, 0 ) );
|
||
|
fill.pattern().setVector( KoPoint( m_strokeFrame->width() * 0.5, 0 ) );
|
||
|
fill.setType( VFill::patt );
|
||
|
m_strokeLabel->setText( i18n( "Stroke: Pattern") );
|
||
|
break;
|
||
|
}
|
||
|
default: //None or unknown
|
||
|
{
|
||
|
m_strokeLabel->setText( i18n( "Stroke: None") );
|
||
14 years ago
|
fill.setColor( TQt::white );
|
||
15 years ago
|
m_painter->setBrush( fill );
|
||
|
m_painter->drawRect( KoRect( 0, 0, m_strokeFrame->width(), m_strokeFrame->height() ) );
|
||
14 years ago
|
stroke.setColor( TQt::red );
|
||
15 years ago
|
stroke.setLineWidth( 2.0 );
|
||
|
m_painter->setPen( stroke );
|
||
|
m_painter->newPath();
|
||
|
m_painter->moveTo( KoPoint( 4, m_strokeFrame->height() - 4 ) );
|
||
|
m_painter->lineTo( KoPoint( m_strokeFrame->width() - 4, 4 ) );
|
||
|
m_painter->strokePath();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if( s.type() != VStroke::none )
|
||
|
{
|
||
|
m_painter->setPen( stroke );
|
||
|
m_painter->setBrush( fill );
|
||
|
m_painter->drawRect( KoRect( 0, 0, m_strokeFrame->width(), m_strokeFrame->height() ) );
|
||
|
}
|
||
|
|
||
|
m_painter->end();
|
||
|
|
||
|
bitBlt( m_strokeFrame, m_strokeFrame->frameWidth(), m_strokeFrame->frameWidth(), &m_pixmap, m_strokeFrame->frameWidth(), m_strokeFrame->frameWidth(), m_strokeFrame->width() - m_strokeFrame->frameWidth(), m_strokeFrame->height() - m_strokeFrame->frameWidth(), CopyROP );
|
||
|
|
||
|
delete ( m_painter );
|
||
|
}
|
||
|
|
||
|
#include "vsmallpreview.moc"
|
||
|
|