karbon

vpolygontool.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 
00021 #include <qlabel.h>
00022 #include <qgroupbox.h>
00023 
00024 #include <kdialogbase.h>
00025 #include <klocale.h>
00026 #include <KoUnitWidgets.h>
00027 
00028 #include <karbon_view.h>
00029 #include <karbon_part.h>
00030 #include <shapes/vstar.h>
00031 #include "vpolygontool.h"
00032 
00033 VPolygonTool::VPolygonOptionsWidget::VPolygonOptionsWidget( KarbonView *view, QWidget* parent, const char* name )
00034     : KDialogBase( parent, name, true, i18n( "Insert Polygon" ), Ok | Cancel ), m_view(view)
00035 {
00036     QGroupBox *group = new QGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), this );
00037 
00038     new QLabel( i18n( "Radius:" ), group );
00039     m_radius = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 50.0, KoUnit::U_MM );
00040     refreshUnit();
00041     new QLabel( i18n( "Edges:" ), group );
00042     m_edges = new KIntSpinBox( group );
00043     m_edges->setMinValue( 3 );
00044 
00045     group->setInsideMargin( 4 );
00046     group->setInsideSpacing( 2 );
00047 
00048     setMainWidget( group );
00049     //setFixedSize( baseSize() );
00050 }
00051 
00052 double
00053 VPolygonTool::VPolygonOptionsWidget::radius() const
00054 {
00055     return m_radius->value();
00056 }
00057 
00058 uint
00059 VPolygonTool::VPolygonOptionsWidget::edges() const
00060 {
00061     return m_edges->value();
00062 }
00063 
00064 void
00065 VPolygonTool::VPolygonOptionsWidget::setRadius( double value )
00066 {
00067     m_radius->changeValue( value );
00068 }
00069 
00070 void
00071 VPolygonTool::VPolygonOptionsWidget::setEdges( uint value )
00072 {
00073     m_edges->setValue( value );
00074 }
00075 
00076 void
00077 VPolygonTool::VPolygonOptionsWidget::refreshUnit()
00078 {
00079     m_radius->setUnit( m_view->part()->unit() );
00080 }
00081 
00082 VPolygonTool::VPolygonTool( KarbonView *view )
00083     : VShapeTool( view, "tool_polygon", true )
00084 {
00085     // create config dialog:
00086     m_optionsWidget = new VPolygonOptionsWidget( view );
00087     m_optionsWidget->setEdges( 5 );
00088     registerTool( this );
00089 }
00090 
00091 VPolygonTool::~VPolygonTool()
00092 {
00093     delete( m_optionsWidget );
00094 }
00095 
00096 void
00097 VPolygonTool::refreshUnit()
00098 {
00099     m_optionsWidget->refreshUnit();
00100 }
00101 
00102 void
00103 VPolygonTool::arrowKeyReleased( Qt::Key key )
00104 {
00105     int change = 0;
00106     if( key == Qt::Key_Up )
00107         change = 1;
00108     else if( key == Qt::Key_Down )
00109         change = -1;
00110 
00111     if( change != 0 )
00112     {
00113         draw();
00114 
00115         m_optionsWidget->setEdges( m_optionsWidget->edges() + change );
00116 
00117         draw();
00118     }
00119 }
00120 
00121 VPath*
00122 VPolygonTool::shape( bool interactive ) const
00123 {
00124     if( interactive )
00125     {
00126         return
00127             new VStar(
00128                 0L,
00129                 m_p,
00130                 m_optionsWidget->radius(),
00131                 m_optionsWidget->radius(),
00132                 m_optionsWidget->edges(), 0, 0, 0, VStar::polygon );
00133     }
00134     else
00135         return
00136             new VStar(
00137                 0L,
00138                 m_p,
00139                 m_d1, m_d1,
00140                 m_optionsWidget->edges(),
00141                 m_d2, 0, 0, VStar::polygon );
00142 }
00143 
00144 bool
00145 VPolygonTool::showDialog() const
00146 {
00147     return m_optionsWidget->exec() == QDialog::Accepted;
00148 }
00149 
00150 void
00151 VPolygonTool::setup( KActionCollection *collection )
00152 {
00153     m_action = static_cast<KRadioAction *>(collection -> action( name() ) );
00154 
00155     if( m_action == 0 )
00156     {
00157         KShortcut shortcut( Qt::Key_Plus );
00158         shortcut.append(KShortcut( Qt::Key_F9 ) );
00159         m_action = new KRadioAction( i18n( "Polygon Tool" ), "14_polygon", shortcut, this, SLOT( activate() ), collection, name() );
00160         m_action->setToolTip( i18n( "Polygon" ) );
00161         m_action->setExclusiveGroup( "shapes" );
00162         //m_ownAction = true;
00163     }
00164 }
00165 
KDE Home | KDE Accessibility Home | Description of Access Keys