1
/* This file is part of the KDE project
2
Copyright (C) 2001, 2002, 2003 The Karbon Developers
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License as published by the Free Software Foundation; either
7
version 2 of the License, or (at your option) any later version.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
Library General Public License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to
16
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
Boston, MA 02111-1307, USA.
25
#include <karbon_part.h>
26
#include <karbon_view.h>
27
#include <karbon_factory.h>
28
#include <render/vpainter.h>
29
#include <render/vpainterfactory.h>
30
#include "vgradienttool.h"
31
#include <widgets/vgradienttabwidget.h>
32
#include <commands/vfillcmd.h>
33
#include <commands/vstrokecmd.h>
34
#include <core/vstroke.h>
35
#include <core/vselection.h>
39
VGradientTool::VGradientOptionsWidget::VGradientOptionsWidget( VGradient *gradient )
40
: KDialogBase( 0L, "", true, i18n( "Edit Gradient" ), Ok | Cancel )
42
m_gradientWidget = new VGradientTabWidget( *gradient, KarbonFactory::rServer(), this );
43
setMainWidget( m_gradientWidget );
44
setFixedSize( baseSize() );
47
VGradientTool::VGradientTool( KarbonPart *part, const char *name )
50
m_optionsWidget = new VGradientOptionsWidget( &m_gradient );
54
VGradientTool::~VGradientTool()
56
delete m_optionsWidget;
60
VGradientTool::activate()
62
view()->statusMessage()->setText( i18n( "Gradient" ) );
63
view()->setCursor( QCursor( Qt::crossCursor ) );
67
VGradientTool::contextHelp()
69
QString s = i18n( "<qt><b>Gradient tool:</b><br>" );
70
s += i18n( "<i>Click and drag</i> to choose the gradient vector.<br>" );
71
s += i18n( "<br><b>Gradient editing:</b><br>" );
72
s += i18n( "<i>Click and drag</i> to move points.<br>" );
73
s += i18n( "<i>Double click</i> on a color point to edit it.<br>" );
74
s += i18n( "<i>Right click</i> on a color point to remove it.</qt>" );
81
VPainter *painter = view()->painterFactory()->editpainter();
82
painter->setRasterOp( Qt::NotROP );
84
painter->setPen( Qt::DotLine );
86
painter->moveTo( first() );
87
painter->lineTo( m_current );
88
painter->strokePath();
92
VGradientTool::mouseDrag()
103
VGradientTool::mouseButtonPress()
109
VGradientTool::mouseButtonRelease()
111
if( view()->part()->document().selection()->objects().count() == 0 ) return;
112
m_gradient.setOrigin( first() );
114
if( first().x() == last().x() && first().y() == last().y() ) // workaround for a libart 2.3.10 bug
115
p.setX( first().x() + 1 );
116
m_gradient.setVector( p );
118
if( m_optionsWidget->gradientWidget()->target() == VGradientTabWidget::FILL )
121
fill.gradient() = m_gradient;
122
fill.setType( VFill::grad );
123
view()->part()->addCommand(
124
new VFillCmd( &view()->part()->document(), fill, "14_gradient" ), true );
129
stroke.gradient() = m_gradient;
130
stroke.setType( VStroke::grad );
131
view()->part()->addCommand(
132
new VStrokeCmd( &view()->part()->document(), &stroke, "14_gradient" ), true );
137
VGradientTool::mouseDragRelease()
139
if( view()->part()->document().selection()->objects().count() == 0 )
145
KoPoint fp = first();
146
//fp.setY( -fp.y() + view()->canvasWidget()->viewport()->height() );
148
//lp.setY( -lp.y() + view()->canvasWidget()->viewport()->height() );
149
m_gradient.setOrigin( fp );
150
m_gradient.setFocalPoint( fp );
151
m_gradient.setVector( lp );
153
if( m_optionsWidget->gradientWidget()->target() == VGradientTabWidget::FILL )
156
fill.gradient() = m_gradient;
157
fill.setType( VFill::grad );
158
VColor c = fill.color();
159
c.setOpacity( m_optionsWidget->gradientWidget()->opacity() );
160
fill.setColor( c, false );
161
view()->part()->addCommand(
162
new VFillCmd( &view()->part()->document(), fill, "14_gradient" ), true );
165
view()->part()->addCommand(
166
new VStrokeCmd( &view()->part()->document(), &m_gradient ), true );
170
VGradientTool::cancel()
178
VGradientTool::showDialog() const
180
return m_optionsWidget->exec() == QDialog::Accepted;