karbon

vspiraltool.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001, 2002, 2003 The Karbon Developers
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include <qlabel.h>
00021 #include <qgroupbox.h>
00022 
00023 #include <klocale.h>
00024 #include <kcombobox.h>
00025 #include <knuminput.h>
00026 
00027 #include <karbon_view.h>
00028 #include <karbon_part.h>
00029 #include <shapes/vspiral.h>
00030 #include "vspiraltool.h"
00031 #include "KoUnitWidgets.h"
00032 
00033 
00034 VSpiralTool::VSpiralOptionsWidget::VSpiralOptionsWidget( KarbonPart *part, QWidget* parent, const char* name )
00035     : KDialogBase( parent, name, true, i18n( "Insert Spiral" ), Ok | Cancel ), m_part( part )
00036 {
00037     QGroupBox *group = new QGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), this );
00038 
00039     new QLabel( i18n( "Type:" ), group );
00040     m_type = new KComboBox( false, group );
00041     m_type->insertItem( i18n( "Round" ), 0 );
00042     m_type->insertItem( i18n( "Rectangular" ), 1 );
00043 
00044     new QLabel( i18n( "Radius:" ), group );
00045     m_radius = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 50.0, KoUnit::U_MM );
00046     refreshUnit();
00047     new QLabel( i18n( "Segments:" ), group );
00048     m_segments = new KIntSpinBox( group );
00049     m_segments->setMinValue( 1 );
00050     new QLabel( i18n( "Fade:" ), group );
00051     m_fade = new KDoubleNumInput( group );
00052     m_fade->setRange( 0.0, 1.0, 0.05 );
00053 
00054     new QLabel( i18n( "Orientation:" ), group );
00055     m_clockwise = new KComboBox( false, group );
00056     m_clockwise->insertItem( i18n( "Clockwise" ), 0 );
00057     m_clockwise->insertItem( i18n( "Counter Clockwise" ), 1 );
00058 
00059     group->setInsideMargin( 4 );
00060     group->setInsideSpacing( 2 );
00061 
00062     setMainWidget( group );
00063     //setFixedSize( baseSize() );
00064 }
00065 
00066 double
00067 VSpiralTool::VSpiralOptionsWidget::radius() const
00068 {
00069     return m_radius->value();
00070 }
00071 
00072 uint
00073 VSpiralTool::VSpiralOptionsWidget::segments() const
00074 {
00075     return m_segments->value();
00076 }
00077 
00078 double
00079 VSpiralTool::VSpiralOptionsWidget::fade() const
00080 {
00081     return m_fade->value();
00082 }
00083 
00084 bool
00085 VSpiralTool::VSpiralOptionsWidget::clockwise() const
00086 {
00087     return m_clockwise->currentItem() == 0;
00088 }
00089 
00090 uint
00091 VSpiralTool::VSpiralOptionsWidget::type() const
00092 {
00093     return m_type->currentItem();
00094 }
00095 
00096 void
00097 VSpiralTool::VSpiralOptionsWidget::setRadius( double value )
00098 {
00099     m_radius->changeValue( value );
00100 }
00101 
00102 void
00103 VSpiralTool::VSpiralOptionsWidget::setSegments( uint value )
00104 {
00105     m_segments->setValue( value );
00106 }
00107 
00108 void
00109 VSpiralTool::VSpiralOptionsWidget::setFade( double value )
00110 {
00111     m_fade->setValue( value );
00112 }
00113 
00114 void
00115 VSpiralTool::VSpiralOptionsWidget::setClockwise( bool value )
00116 {
00117     m_clockwise->setCurrentItem( value ? 0 : 1 );
00118 }
00119 
00120 void
00121 VSpiralTool::VSpiralOptionsWidget::refreshUnit()
00122 {
00123     m_radius->setUnit( m_part->unit() );
00124 }
00125 
00126 VSpiralTool::VSpiralTool( KarbonView *view )
00127     : VShapeTool( view, "tool_spiral", true )
00128 {
00129     // create config dialog:
00130     m_optionsWidget = new VSpiralOptionsWidget( view->part() );
00131     m_optionsWidget->setSegments( 8 );
00132     m_optionsWidget->setFade( 0.8 );
00133     m_optionsWidget->setClockwise( true );
00134     registerTool( this );
00135 }
00136 
00137 void
00138 VSpiralTool::arrowKeyReleased( Qt::Key key )
00139 {
00140     int change = 0;
00141     if( key == Qt::Key_Up )
00142         change = 1;
00143     else if( key == Qt::Key_Down )
00144         change = -1;
00145 
00146     if( change != 0 )
00147     {
00148         draw();
00149 
00150         m_optionsWidget->setSegments( m_optionsWidget->segments() + change );
00151 
00152         draw();
00153     }
00154 }
00155 
00156 VSpiralTool::~VSpiralTool()
00157 {
00158     delete( m_optionsWidget );
00159 }
00160 
00161 void
00162 VSpiralTool::refreshUnit()
00163 {
00164     m_optionsWidget->refreshUnit();
00165 }
00166 
00167 VPath*
00168 VSpiralTool::shape( bool interactive ) const
00169 {
00170     if( interactive )
00171     {
00172         return
00173             new VSpiral(
00174                 0L,
00175                 m_p,
00176                 m_optionsWidget->radius(),
00177                 m_optionsWidget->segments(),
00178                 m_optionsWidget->fade(),
00179                 m_optionsWidget->clockwise(),
00180                 m_d2, (VSpiral::VSpiralType)m_optionsWidget->type() );
00181     }
00182     else
00183         return
00184             new VSpiral(
00185                 0L,
00186                 m_p,
00187                 m_d1,
00188                 m_optionsWidget->segments(),
00189                 m_optionsWidget->fade(),
00190                 m_optionsWidget->clockwise(),
00191                 m_d2, (VSpiral::VSpiralType)m_optionsWidget->type() );
00192 }
00193 
00194 bool
00195 VSpiralTool::showDialog() const
00196 {
00197     return m_optionsWidget->exec() == QDialog::Accepted;
00198 }
00199 
00200 void
00201 VSpiralTool::setup( KActionCollection *collection )
00202 {
00203     m_action = static_cast<KRadioAction *>(collection -> action( name() ) );
00204 
00205     if( m_action == 0 )
00206     {
00207         m_action = new KRadioAction( i18n( "Spiral Tool" ), "14_spiral", Qt::SHIFT+Qt::Key_H, this, SLOT( activate() ), collection, name() );
00208         m_action->setToolTip( i18n( "Spiral" ) );
00209         m_action->setExclusiveGroup( "shapes" );
00210         //m_ownAction = true;
00211     }
00212 }
00213 
KDE Home | KDE Accessibility Home | Description of Access Keys