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

« back to all changes in this revision

Viewing changes to karbon/dockers/vstrokedocker.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
   Made by Tomislav Lukman (tomislav.lukman@ck.tel.hr)
 
3
   Copyright (C) 2002, The Karbon Developers
 
4
 
 
5
   This library is free software; you can redistribute it and/or
 
6
   modify it under the terms of the GNU Library General Public
 
7
   License as published by the Free Software Foundation; either
 
8
   version 2 of the License, or (at your option) any later version.
 
9
 
 
10
   This library is distributed in the hope that it will be useful,
 
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
   Library General Public License for more details.
 
14
 
 
15
   You should have received a copy of the GNU Library General Public License
 
16
   along with this library; see the file COPYING.LIB.  If not, write to
 
17
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
18
   Boston, MA 02111-1307, USA.
 
19
*/
 
20
 
 
21
#include <qhbuttongroup.h>
 
22
#include <qlabel.h>
 
23
#include <qlayout.h>
 
24
#include <qpushbutton.h>
 
25
#include <qwidget.h>
 
26
 
 
27
#include <kiconloader.h>
 
28
#include <klocale.h>
 
29
#include <koMainWindow.h>
 
30
 
 
31
#include "koUnitWidgets.h"
 
32
 
 
33
#include "karbon_part.h"
 
34
#include "karbon_view.h"
 
35
#include "vstroke.h"
 
36
#include "vcolorslider.h"
 
37
#include "vselection.h"
 
38
#include "vstrokecmd.h"
 
39
 
 
40
#include "vstrokedocker.h"
 
41
 
 
42
VStrokeDocker::VStrokeDocker( KarbonPart* part, KarbonView* parent, const char* /*name*/ )
 
43
        : VDocker( parent->shell() ), m_part ( part ), m_view( parent )
 
44
{
 
45
        setCaption( i18n( "Stroke Properties" ) );
 
46
 
 
47
        QPushButton *button;
 
48
        mainWidget = new QWidget( this );
 
49
        QGridLayout *mainLayout = new QGridLayout( mainWidget, 4, 2 );
 
50
        
 
51
        QLabel* widthLabel = new QLabel( i18n ( "Width:" ), mainWidget );
 
52
        mainLayout->addWidget( widthLabel, 0, 0 );
 
53
        m_setLineWidth = new KoUnitDoubleSpinBox( mainWidget, 0.0, 1000.0, 0.5, 1.0, KoUnit::U_PT, 1 );
 
54
        mainLayout->addWidget ( m_setLineWidth, 0, 1 );
 
55
        connect( m_setLineWidth, SIGNAL( valueChanged( double ) ), this, SLOT( widthChanged() ) ); 
 
56
        
 
57
        QLabel* capLabel = new QLabel( i18n ( "Cap:" ), mainWidget );
 
58
        mainLayout->addWidget( capLabel, 1, 0 );
 
59
        m_capGroup = new QHButtonGroup( mainWidget );
 
60
        m_capGroup->setFrameShape( NoFrame );
 
61
        m_capGroup->setInsideMargin( 1 );
 
62
        m_capGroup->setExclusive( true );
 
63
        button = new QPushButton( "", m_capGroup );
 
64
        button->setPixmap( SmallIcon( "cap_butt" ) );
 
65
        button->setToggleButton( true );
 
66
        m_capGroup->insert( button );
 
67
        button = new QPushButton( "", m_capGroup );
 
68
        button->setPixmap( SmallIcon( "cap_round" ) );
 
69
        button->setToggleButton( true );
 
70
        m_capGroup->insert( button );
 
71
        button = new QPushButton( "", m_capGroup );
 
72
        button->setPixmap( SmallIcon( "cap_square" ) );
 
73
        button->setToggleButton( true );
 
74
        m_capGroup->insert( button );
 
75
        mainLayout->addWidget( m_capGroup, 1, 1 );
 
76
        connect( m_capGroup, SIGNAL( clicked( int ) ), this, SLOT( slotCapChanged( int ) ) );
 
77
        
 
78
        QLabel* joinLabel = new QLabel( i18n ( "Join:" ), mainWidget );
 
79
        mainLayout->addWidget( joinLabel, 2, 0 );
 
80
        
 
81
        m_joinGroup = new QHButtonGroup( mainWidget );
 
82
        m_joinGroup->setFrameShape( NoFrame );
 
83
        m_joinGroup->setInsideMargin( 1 );
 
84
        m_joinGroup->setExclusive( true );
 
85
        button = new QPushButton( "", m_joinGroup );
 
86
        button->setPixmap( SmallIcon( "join_miter" ) );
 
87
        button->setToggleButton( true );
 
88
        m_joinGroup->insert( button );
 
89
        button = new QPushButton( "", m_joinGroup );
 
90
        button->setPixmap( SmallIcon( "join_round" ) );
 
91
        button->setToggleButton( true );
 
92
        m_joinGroup->insert( button );
 
93
        button = new QPushButton( "", m_joinGroup );
 
94
        button->setPixmap( SmallIcon( "join_bevel" ) );
 
95
        button->setToggleButton( true );
 
96
        m_joinGroup->insert( button );
 
97
        mainLayout->addWidget( m_joinGroup, 2, 1 );
 
98
        connect( m_joinGroup, SIGNAL( clicked( int ) ), this, SLOT( slotJoinChanged( int ) ) );
 
99
 
 
100
        mainLayout->activate();
 
101
        setWidget( mainWidget );
 
102
 
 
103
        updateDocker();
 
104
}
 
105
 
 
106
void VStrokeDocker::updateCanvas()
 
107
{
 
108
        if( m_part && m_part->document().selection()->objects().count() > 0 )
 
109
                m_part->addCommand( new VStrokeCmd( &m_part->document(), &m_stroke ), true );
 
110
}
 
111
 
 
112
void VStrokeDocker::slotCapChanged( int ID )
 
113
{
 
114
        switch( ID )
 
115
        {
 
116
                case 1:
 
117
                        m_stroke.setLineCap( VStroke::capRound ); break;
 
118
                case 2:
 
119
                        m_stroke.setLineCap( VStroke::capSquare ); break;
 
120
                default:
 
121
                        m_stroke.setLineCap( VStroke::capButt );
 
122
        }
 
123
        updateCanvas();
 
124
}
 
125
 
 
126
void VStrokeDocker::slotJoinChanged( int ID )
 
127
{
 
128
        switch( ID )
 
129
        {
 
130
                case 1:
 
131
                        m_stroke.setLineJoin( VStroke::joinRound ); break;
 
132
                case 2:
 
133
                        m_stroke.setLineJoin( VStroke::joinBevel ); break;
 
134
                default:
 
135
                        m_stroke.setLineJoin( VStroke::joinMiter );
 
136
        }
 
137
        updateCanvas();
 
138
}
 
139
 
 
140
void VStrokeDocker::updateDocker()
 
141
{
 
142
        disconnect( m_setLineWidth, SIGNAL( valueChanged( double ) ), this, SLOT( widthChanged() ) ); 
 
143
        disconnect( m_capGroup, SIGNAL( clicked( int ) ), this, SLOT( slotCapChanged( int ) ) );
 
144
        disconnect( m_joinGroup, SIGNAL( clicked( int ) ), this, SLOT( slotJoinChanged( int ) ) );
 
145
 
 
146
        switch( m_stroke.lineCap() )
 
147
        {
 
148
                case VStroke::capRound:
 
149
                        m_capGroup->setButton( 1 ); break;
 
150
                case VStroke::capSquare:
 
151
                        m_capGroup->setButton( 2 ); break;
 
152
                default:
 
153
                        m_capGroup->setButton( 0 );
 
154
        }
 
155
 
 
156
        switch( m_stroke.lineJoin() )
 
157
        {
 
158
                case VStroke::joinRound:
 
159
                        m_joinGroup->setButton( 1 ); break;
 
160
                case VStroke::joinBevel:
 
161
                        m_joinGroup->setButton( 2 ); break;
 
162
                default:
 
163
                        m_joinGroup->setButton( 0 );
 
164
        }
 
165
        
 
166
        m_setLineWidth->setValue( m_stroke.lineWidth() );
 
167
        
 
168
        connect( m_setLineWidth, SIGNAL( valueChanged( double ) ), this, SLOT( widthChanged() ) ); 
 
169
        connect( m_capGroup, SIGNAL( clicked( int ) ), this, SLOT( slotCapChanged( int ) ) );
 
170
        connect( m_joinGroup, SIGNAL( clicked( int ) ), this, SLOT( slotJoinChanged( int ) ) );
 
171
}
 
172
 
 
173
void VStrokeDocker::widthChanged()
 
174
{
 
175
        m_stroke.setLineWidth( m_setLineWidth->value() );
 
176
        updateCanvas();
 
177
}
 
178
 
 
179
void VStrokeDocker::setStroke( const VStroke &stroke )
 
180
{
 
181
        m_stroke = stroke;
 
182
        updateDocker();
 
183
}
 
184
 
 
185
#include "vstrokedocker.moc"
 
186