~ubuntu-branches/ubuntu/edgy/koffice/edgy-updates

« back to all changes in this revision

Viewing changes to karbon/tools/vgradienttool.cc

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040509113300-xi5t1z4yxe7n03x7
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2001, 2002, 2003 The Karbon Developers
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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.
 
18
*/
 
19
 
 
20
#include <qcursor.h>
 
21
#include <qlabel.h>
 
22
 
 
23
#include <klocale.h>
 
24
 
 
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>
 
36
 
 
37
#include <kdebug.h>
 
38
 
 
39
VGradientTool::VGradientOptionsWidget::VGradientOptionsWidget( VGradient *gradient )
 
40
        : KDialogBase( 0L, "", true, i18n( "Edit Gradient" ), Ok | Cancel )
 
41
{
 
42
        m_gradientWidget = new VGradientTabWidget( *gradient, KarbonFactory::rServer(), this );
 
43
        setMainWidget( m_gradientWidget );
 
44
        setFixedSize( baseSize() );
 
45
}
 
46
 
 
47
VGradientTool::VGradientTool( KarbonPart *part, const char *name )
 
48
        : VTool( part, name )
 
49
{
 
50
        m_optionsWidget = new VGradientOptionsWidget( &m_gradient );
 
51
        registerTool( this );
 
52
}
 
53
 
 
54
VGradientTool::~VGradientTool()
 
55
{
 
56
        delete m_optionsWidget;
 
57
}
 
58
 
 
59
void
 
60
VGradientTool::activate()
 
61
{
 
62
        view()->statusMessage()->setText( i18n( "Gradient" ) );
 
63
        view()->setCursor( QCursor( Qt::crossCursor ) );
 
64
}
 
65
 
 
66
QString 
 
67
VGradientTool::contextHelp()
 
68
{
 
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>" );
 
75
        return s;
 
76
}
 
77
 
 
78
void
 
79
VGradientTool::draw()
 
80
{
 
81
        VPainter *painter = view()->painterFactory()->editpainter();
 
82
        painter->setRasterOp( Qt::NotROP );
 
83
 
 
84
        painter->setPen( Qt::DotLine );
 
85
        painter->newPath();
 
86
        painter->moveTo( first() );
 
87
        painter->lineTo( m_current );
 
88
        painter->strokePath();
 
89
}
 
90
 
 
91
void
 
92
VGradientTool::mouseDrag()
 
93
{
 
94
        // undo old line
 
95
        draw();
 
96
 
 
97
        m_current = last();
 
98
 
 
99
        draw();
 
100
}
 
101
 
 
102
void
 
103
VGradientTool::mouseButtonPress()
 
104
{
 
105
        m_current = first();
 
106
}
 
107
 
 
108
void
 
109
VGradientTool::mouseButtonRelease()
 
110
{
 
111
        if( view()->part()->document().selection()->objects().count() == 0 ) return;
 
112
        m_gradient.setOrigin( first() );
 
113
        KoPoint p = last();
 
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 );
 
117
 
 
118
        if( m_optionsWidget->gradientWidget()->target() == VGradientTabWidget::FILL )
 
119
        {
 
120
                VFill 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 );
 
125
        }
 
126
        else
 
127
        {
 
128
                VStroke stroke;
 
129
                stroke.gradient() = m_gradient;
 
130
                stroke.setType( VStroke::grad );
 
131
                view()->part()->addCommand(
 
132
                        new VStrokeCmd( &view()->part()->document(), &stroke, "14_gradient" ), true );
 
133
        }
 
134
}
 
135
 
 
136
void
 
137
VGradientTool::mouseDragRelease()
 
138
{
 
139
        if( view()->part()->document().selection()->objects().count() == 0 )
 
140
        {
 
141
                draw();
 
142
                return;
 
143
        }
 
144
        // Y mirroring
 
145
        KoPoint fp = first();
 
146
        //fp.setY( -fp.y() + view()->canvasWidget()->viewport()->height() );
 
147
        KoPoint lp = last();
 
148
        //lp.setY( -lp.y() + view()->canvasWidget()->viewport()->height() );
 
149
        m_gradient.setOrigin( fp );
 
150
        m_gradient.setFocalPoint( fp );
 
151
        m_gradient.setVector( lp );
 
152
 
 
153
        if( m_optionsWidget->gradientWidget()->target() == VGradientTabWidget::FILL )
 
154
        {
 
155
                VFill 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 );
 
163
        }
 
164
        else
 
165
                view()->part()->addCommand(
 
166
                        new VStrokeCmd( &view()->part()->document(), &m_gradient ), true );
 
167
}
 
168
 
 
169
void
 
170
VGradientTool::cancel()
 
171
{
 
172
        // Erase old object:
 
173
        if( isDragging() )
 
174
                draw();
 
175
}
 
176
 
 
177
bool
 
178
VGradientTool::showDialog() const
 
179
{
 
180
        return m_optionsWidget->exec() == QDialog::Accepted;
 
181
}
 
182