karbon

vstrokedocker.cpp
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., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include <tqhbuttongroup.h>
22#include <tqlabel.h>
23#include <tqlayout.h>
24#include <tqpushbutton.h>
25#include <tqwidget.h>
26#include <tqtooltip.h>
27
28#include <kiconloader.h>
29#include <tdelocale.h>
30#include <KoMainWindow.h>
31
32#include "KoUnitWidgets.h"
33
34#include "karbon_part.h"
35#include "karbon_view.h"
36#include "vstroke.h"
37#include "vselection.h"
38#include "vstrokecmd.h"
39
40#include "vstrokedocker.h"
41
42VStrokeDocker::VStrokeDocker( KarbonPart* part, KarbonView* parent, const char* /*name*/ )
43 : TQWidget(), m_part ( part ), m_view( parent )
44{
45 setCaption( i18n( "Stroke Properties" ) );
46
47 TQPushButton *button;
48
49 TQGridLayout *mainLayout = new TQGridLayout( this, 4, 2 );
50
51 TQLabel* widthLabel = new TQLabel( i18n ( "stroke width", "Width:" ), this );
52 mainLayout->addWidget( widthLabel, 0, 0 );
53 // set min/max/step and value in points, then set actual unit
54 m_setLineWidth = new KoUnitDoubleSpinBox( this, 0.0, 1000.0, 0.5, 1.0, KoUnit::U_PT, 2 );
55 m_setLineWidth->setUnit( part->unit() );
56 TQToolTip::add( m_setLineWidth, i18n( "Set line width of actual selection" ) );
57 mainLayout->addWidget ( m_setLineWidth, 0, 1 );
58 connect( m_setLineWidth, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( widthChanged() ) );
59
60 TQLabel* capLabel = new TQLabel( i18n ( "Cap:" ), this );
61 mainLayout->addWidget( capLabel, 1, 0 );
62 m_capGroup = new TQHButtonGroup( this );
63 m_capGroup->setFrameShape( TQFrame::NoFrame );
64 m_capGroup->setInsideMargin( 1 );
65 m_capGroup->setExclusive( true );
66 button = new TQPushButton( "", m_capGroup );
67 button->setPixmap( SmallIcon( "cap_butt" ) );
68 button->setToggleButton( true );
69 TQToolTip::add( button, i18n( "Butt cap" ) );
70 m_capGroup->insert( button );
71 button = new TQPushButton( "", m_capGroup );
72 button->setPixmap( SmallIcon( "cap_round" ) );
73 button->setToggleButton( true );
74 TQToolTip::add( button, i18n( "Round cap" ) );
75 m_capGroup->insert( button );
76 button = new TQPushButton( "", m_capGroup );
77 button->setPixmap( SmallIcon( "cap_square" ) );
78 button->setToggleButton( true );
79 TQToolTip::add( button, i18n( "Square cap" ) );
80 m_capGroup->insert( button );
81 mainLayout->addWidget( m_capGroup, 1, 1 );
82 connect( m_capGroup, TQ_SIGNAL( clicked( int ) ), this, TQ_SLOT( slotCapChanged( int ) ) );
83
84 TQLabel* joinLabel = new TQLabel( i18n ( "Join:" ), this );
85 mainLayout->addWidget( joinLabel, 2, 0 );
86
87 m_joinGroup = new TQHButtonGroup( this );
88 m_joinGroup->setFrameShape( TQFrame::NoFrame );
89 m_joinGroup->setInsideMargin( 1 );
90 m_joinGroup->setExclusive( true );
91 button = new TQPushButton( "", m_joinGroup );
92 button->setPixmap( SmallIcon( "join_miter" ) );
93 button->setToggleButton( true );
94 TQToolTip::add( button, i18n( "Miter join" ) );
95 m_joinGroup->insert( button );
96 button = new TQPushButton( "", m_joinGroup );
97 button->setPixmap( SmallIcon( "join_round" ) );
98 button->setToggleButton( true );
99 TQToolTip::add( button, i18n( "Round join" ) );
100 m_joinGroup->insert( button );
101 button = new TQPushButton( "", m_joinGroup );
102 button->setPixmap( SmallIcon( "join_bevel" ) );
103 button->setToggleButton( true );
104 TQToolTip::add( button, i18n( "Bevel join" ) );
105 m_joinGroup->insert( button );
106 mainLayout->addWidget( m_joinGroup, 2, 1 );
107 connect( m_joinGroup, TQ_SIGNAL( clicked( int ) ), this, TQ_SLOT( slotJoinChanged( int ) ) );
108
109 mainLayout->setRowStretch( 3, 1 );
110 mainLayout->setColStretch( 1, 1 );
111 mainLayout->activate();
112
113 updateDocker();
114}
115
116void VStrokeDocker::updateCanvas()
117{
118 if( m_part && m_part->document().selection()->objects().count() > 0 )
119 m_part->addCommand( new VStrokeCmd( &m_part->document(), &m_stroke ), true );
120}
121
122void VStrokeDocker::slotCapChanged( int ID )
123{
124 switch( ID )
125 {
126 case 1:
127 m_stroke.setLineCap( VStroke::capRound ); break;
128 case 2:
129 m_stroke.setLineCap( VStroke::capSquare ); break;
130 default:
131 m_stroke.setLineCap( VStroke::capButt );
132 }
133 updateCanvas();
134}
135
136void VStrokeDocker::slotJoinChanged( int ID )
137{
138 switch( ID )
139 {
140 case 1:
141 m_stroke.setLineJoin( VStroke::joinRound ); break;
142 case 2:
143 m_stroke.setLineJoin( VStroke::joinBevel ); break;
144 default:
145 m_stroke.setLineJoin( VStroke::joinMiter );
146 }
147 updateCanvas();
148}
149
150void VStrokeDocker::updateDocker()
151{
152 disconnect( m_setLineWidth, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( widthChanged() ) );
153 disconnect( m_capGroup, TQ_SIGNAL( clicked( int ) ), this, TQ_SLOT( slotCapChanged( int ) ) );
154 disconnect( m_joinGroup, TQ_SIGNAL( clicked( int ) ), this, TQ_SLOT( slotJoinChanged( int ) ) );
155
156 switch( m_stroke.lineCap() )
157 {
158 case VStroke::capRound:
159 m_capGroup->setButton( 1 ); break;
160 case VStroke::capSquare:
161 m_capGroup->setButton( 2 ); break;
162 default:
163 m_capGroup->setButton( 0 );
164 }
165
166 switch( m_stroke.lineJoin() )
167 {
168 case VStroke::joinRound:
169 m_joinGroup->setButton( 1 ); break;
170 case VStroke::joinBevel:
171 m_joinGroup->setButton( 2 ); break;
172 default:
173 m_joinGroup->setButton( 0 );
174 }
175
176 m_setLineWidth->changeValue( m_stroke.lineWidth() );
177
178 connect( m_setLineWidth, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( widthChanged() ) );
179 connect( m_capGroup, TQ_SIGNAL( clicked( int ) ), this, TQ_SLOT( slotCapChanged( int ) ) );
180 connect( m_joinGroup, TQ_SIGNAL( clicked( int ) ), this, TQ_SLOT( slotJoinChanged( int ) ) );
181}
182
183void VStrokeDocker::widthChanged()
184{
185 m_stroke.setLineWidth( m_setLineWidth->value() );
186 updateCanvas();
187}
188
189void VStrokeDocker::setStroke( const VStroke &stroke )
190{
191 if( &stroke )
192 m_stroke = stroke;
193 else
194 m_stroke = VStroke();
195 updateDocker();
196}
197
198void VStrokeDocker::setUnit( KoUnit::Unit unit )
199{
200 disconnect( m_setLineWidth, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( widthChanged() ) );
201 disconnect( m_capGroup, TQ_SIGNAL( clicked( int ) ), this, TQ_SLOT( slotCapChanged( int ) ) );
202 disconnect( m_joinGroup, TQ_SIGNAL( clicked( int ) ), this, TQ_SLOT( slotJoinChanged( int ) ) );
203
204 m_setLineWidth->setUnit( unit );
205
206 connect( m_setLineWidth, TQ_SIGNAL( valueChanged( double ) ), this, TQ_SLOT( widthChanged() ) );
207 connect( m_capGroup, TQ_SIGNAL( clicked( int ) ), this, TQ_SLOT( slotCapChanged( int ) ) );
208 connect( m_joinGroup, TQ_SIGNAL( clicked( int ) ), this, TQ_SLOT( slotJoinChanged( int ) ) );
209}
210#include "vstrokedocker.moc"
211
Keeps track of visual per document properties.
Definition karbon_part.h:46
Manages stroke properties.
Definition vstroke.h:49