karbon

vstrokedlg.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001, The Karbon Developers
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 <tqcombobox.h>
22#include <tqlabel.h>
23#include <tqlayout.h>
24#include <tqtabwidget.h>
25#include <tqradiobutton.h>
26#include <tqvbuttongroup.h>
27
28#include <kiconloader.h>
29#include <tdelocale.h>
30#include <kstandarddirs.h>
31
32#include "KoUnitWidgets.h"
33
34#include "karbon_part.h"
35#include "vcolor.h"
36#include "vselection.h"
37#include "vstrokecmd.h"
38#include "vstroke.h"
39#include "vstrokedlg.h"
40#include "vcolortab.h"
41
42VStrokeDlg::VStrokeDlg( KarbonPart* part, TQWidget* parent, const char* name )
43 : KDialogBase ( parent, name, true, i18n( "Stroke" ), Ok | Cancel ), m_part( part )
44{
45 enableButtonSeparator( true );
46 TQTabWidget *mainWidget = new TQTabWidget( this, "strokemain" );
47 TQHBoxLayout *mainLayout = new TQHBoxLayout (mainWidget, 3);
48
49 TQVBoxLayout *leftLayout = new TQVBoxLayout( mainLayout, 4 );
50
51 TQLabel* widthLabel = new TQLabel( i18n ( "stroke width", "Width:" ), mainWidget );
52 leftLayout->addWidget ( widthLabel );
53 m_setLineWidth = new KoUnitDoubleSpinBox( mainWidget, 0.0, 1000.0, 0.5, 1.0, KoUnit::U_PT, 1 );
54 leftLayout->addWidget ( m_setLineWidth );
55
56 //Dashing ->
57 TQLabel* styleLabel = new TQLabel( i18n ( "Style:" ), mainWidget );
58 leftLayout->addWidget ( styleLabel );
59 m_styleCombo = new TQComboBox( mainWidget );
60 m_styleCombo->setEnabled ( false );
61 leftLayout->addWidget ( m_styleCombo );
62 // <- Dashing - reserved for later
63
64 TQRadioButton* button;
65 m_typeOption = new TQVButtonGroup ( mainWidget );
66 button = new TQRadioButton ( i18n( "None" ), m_typeOption );
67 m_typeOption->insert( button );
68 button = new TQRadioButton ( i18n( "Stroke" ), m_typeOption );
69 m_typeOption->insert( button );
70 button = new TQRadioButton ( i18n( "Gradient" ), m_typeOption );
71 m_typeOption->insert( button );
72 m_typeOption->setTitle( i18n( "Type" ) );
73 mainLayout->addWidget( m_typeOption );
74 connect( m_typeOption, TQ_SIGNAL( clicked( int ) ), this, TQ_SLOT( slotTypeChanged( int ) ) );
75
76 m_capOption = new TQVButtonGroup ( mainWidget );
77 //button = new TQRadioButton ( i18n( "Butt" ), m_capOption );
78 button = new TQRadioButton ( m_capOption );
79 button->setPixmap( DesktopIcon( "cap_butt" ) );
80 m_capOption->insert( button );
81 button = new TQRadioButton ( m_capOption );
82 button->setPixmap( DesktopIcon( "cap_round" ) );
83 m_capOption->insert( button );
84 button = new TQRadioButton ( m_capOption );
85 button->setPixmap( DesktopIcon( "cap_square" ) );
86 m_capOption->insert( button );
87 m_capOption->setTitle( i18n( "Cap" ) );
88 mainLayout->addWidget( m_capOption );
89 connect( m_capOption, TQ_SIGNAL( clicked( int ) ), this, TQ_SLOT( slotCapChanged( int ) ) );
90
91 m_joinOption = new TQVButtonGroup ( mainWidget );
92 button = new TQRadioButton ( m_joinOption );
93 button->setPixmap( DesktopIcon( "join_miter" ) );
94 m_joinOption->insert( button );
95 button = new TQRadioButton ( m_joinOption );
96 button->setPixmap( DesktopIcon( "join_round" ) );
97 m_joinOption->insert( button );
98 button = new TQRadioButton ( m_joinOption );
99 button->setPixmap( DesktopIcon( "join_bevel" ) );
100 m_joinOption->insert( button );
101 m_joinOption->setTitle( i18n( "Join" ) );
102 mainLayout->addWidget( m_joinOption );
103 connect( m_joinOption, TQ_SIGNAL( clicked( int ) ), this, TQ_SLOT( slotJoinChanged( int ) ) );
104
105 VSelection *sel = part->document().selection();
106 if( sel && sel->objects().count() > 0 ) // there is a selection, so take the stroke of first selected object
107 {
108 m_stroke.setType ( sel->objects().getFirst()->stroke()->type() );
109 m_stroke.setColor ( sel->objects().getFirst()->stroke()->color() );
110 m_stroke.setLineWidth ( sel->objects().getFirst()->stroke()->lineWidth() );
111 m_stroke.setLineCap ( sel->objects().getFirst()->stroke()->lineCap() );
112 m_stroke.setLineJoin ( sel->objects().getFirst()->stroke()->lineJoin() );
113 m_stroke.setMiterLimit ( sel->objects().getFirst()->stroke()->miterLimit() );
114 }
115
116 slotUpdateDialog(); //Put the values of selected objects (or default)
117 mainLayout->activate();
118
119 //setMainWidget( mainWidget );
120
121 m_colortab = new VColorTab( sel->objects().count() == 0 ? sel->stroke()->color() :
122 sel->objects().getFirst()->stroke()->color(), this);
123 m_colortab->insertTab( mainWidget, i18n("Stroke"), 0 );
124 m_colortab->setCurrentPage( 0 );
125
126 setMainWidget( m_colortab );
127
128 disableResize();
129 connect (this, TQ_SIGNAL( okClicked( void ) ), this, TQ_SLOT( slotOKClicked ( void ) ) );
130}
131
132void VStrokeDlg::slotTypeChanged( int ID )
133{
134 switch ( ID ) {
135 case 1:
136 m_stroke.setType ( VStroke::solid ); break;
137 case 2:
138 m_stroke.setType ( VStroke::grad ); break;
139 default:
140 m_stroke.setType ( VStroke::none );
141 }
142}
143
144void VStrokeDlg::slotCapChanged( int ID )
145{
146 switch ( ID ) {
147 case 1:
148 m_stroke.setLineCap ( VStroke::capRound ); break;
149 case 2:
150 m_stroke.setLineCap ( VStroke::capSquare ); break;
151 default:
152 m_stroke.setLineCap ( VStroke::capButt );
153 }
154}
155
156void VStrokeDlg::slotJoinChanged( int ID )
157{
158 switch ( ID ) {
159 case 1:
160 m_stroke.setLineJoin ( VStroke::joinRound ); break;
161 case 2:
162 m_stroke.setLineJoin ( VStroke::joinBevel ); break;
163 default:
164 m_stroke.setLineJoin ( VStroke::joinMiter );
165 }
166}
167
168void VStrokeDlg::slotOKClicked()
169{
170 m_stroke.setLineWidth ( m_setLineWidth->value() );
171
172 m_stroke.setColor( m_colortab->Color() );
173
174 if( m_part && m_part->document().selection()->objects().count() > 0 )
175 m_part->addCommand( new VStrokeCmd( &m_part->document(), &m_stroke ), true );
176
177 emit strokeChanged( VStroke( m_stroke ) );
178}
179
180void VStrokeDlg::slotUpdateDialog()
181{
182 switch( m_stroke.type() )
183 {
184 case VStroke::solid:
185 m_typeOption->setButton( 1 ); break;
186 case VStroke::grad:
187 m_typeOption->setButton( 2 ); break;
188 default:
189 m_typeOption->setButton( 0 );
190 }
191
192 switch( m_stroke.lineCap() )
193 {
194 case VStroke::capRound:
195 m_capOption->setButton( 1 ); break;
196 case VStroke::capSquare:
197 m_capOption->setButton( 2 ); break;
198 default:
199 m_capOption->setButton( 0 );
200 }
201
202 switch( m_stroke.lineJoin() )
203 {
204 case VStroke::joinRound:
205 m_joinOption->setButton( 1 ); break;
206 case VStroke::joinBevel:
207 m_joinOption->setButton( 2 ); break;
208 default:
209 m_joinOption->setButton( 0 );
210 }
211
212 m_setLineWidth->setValue( m_stroke.lineWidth() );
213}
214
215#include "vstrokedlg.moc"
216
Keeps track of visual per document properties.
Definition karbon_part.h:46
VSelection * selection() const
Returns a pointer to the selection.
Definition vdocument.h:238
virtual VStroke * stroke() const
Gets the object's actual stroke.
Definition vobject.h:170
VSelection manages a set of selected vobjects.
Definition vselection.h:62
const VObjectList & objects() const
Read only access to the selected objects.
Definition vselection.h:136
@ grad
solid stroke
Definition vstroke.h:55
@ solid
no stroke at all
Definition vstroke.h:54