karbon

vsinustool.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 <qgroupbox.h>
00022 #include <qlabel.h>
00023 #include <qlayout.h>
00024 
00025 #include <klocale.h>
00026 #include <knuminput.h>
00027 
00028 #include <karbon_view.h>
00029 #include <karbon_part.h>
00030 #include <shapes/vsinus.h>
00031 #include "vsinustool.h"
00032 #include "KoUnitWidgets.h"
00033 
00034 
00035 VSinusTool::VSinusOptionsWidget::VSinusOptionsWidget( KarbonPart *part, QWidget* parent, const char* name )
00036     : KDialogBase( parent, name, true, i18n( "Insert Sinus" ), Ok | Cancel ), m_part( part )
00037 {
00038     QGroupBox *group = new QGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), this );
00039 
00040     // add width/height-input:
00041     m_widthLabel = new QLabel( i18n( "Width:" ), group );
00042     m_width = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 100.0, KoUnit::U_MM );
00043     m_heightLabel = new QLabel( i18n( "Height:" ), group );
00044     m_height = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 100.0, KoUnit::U_MM );
00045 
00046     refreshUnit();
00047 
00048     new QLabel( i18n( "Periods:" ), group );
00049     m_periods = new KIntSpinBox( group );
00050     m_periods->setMinValue( 1 );
00051 
00052     group->setInsideMargin( 4 );
00053     group->setInsideSpacing( 2 );
00054 
00055     setMainWidget( group );
00056     setFixedSize( baseSize() );
00057 }
00058 
00059 double
00060 VSinusTool::VSinusOptionsWidget::width() const
00061 {
00062     return m_width->value();
00063 }
00064 
00065 double
00066 VSinusTool::VSinusOptionsWidget::height() const
00067 {
00068     return m_height->value();
00069 }
00070 
00071 uint
00072 VSinusTool::VSinusOptionsWidget::periods() const
00073 {
00074     return m_periods->value();
00075 }
00076 
00077 void
00078 VSinusTool::VSinusOptionsWidget::setWidth( double value )
00079 {
00080     m_width->changeValue( value );
00081 }
00082 
00083 void
00084 VSinusTool::VSinusOptionsWidget::setHeight( double value )
00085 {
00086     m_height->changeValue( value );
00087 }
00088 
00089 void
00090 VSinusTool::VSinusOptionsWidget::setPeriods( uint value )
00091 {
00092     m_periods->setValue( value );
00093 }
00094 
00095 void
00096 VSinusTool::VSinusOptionsWidget::refreshUnit ()
00097 {
00098     m_width->setUnit( m_part->unit() );
00099     m_height->setUnit( m_part->unit() );
00100 }
00101 
00102 VSinusTool::VSinusTool( KarbonView *view )
00103     : VShapeTool( view, "tool_sinus" )
00104 {
00105     // create config widget:
00106     m_optionsWidget = new VSinusOptionsWidget( view->part() );
00107     m_optionsWidget->setPeriods( 1 );
00108     registerTool( this );
00109 }
00110 
00111 VSinusTool::~VSinusTool()
00112 {
00113     delete( m_optionsWidget );
00114 }
00115 
00116 void
00117 VSinusTool::refreshUnit()
00118 {
00119     m_optionsWidget->refreshUnit();
00120 }
00121 
00122 VPath*
00123 VSinusTool::shape( bool interactive ) const
00124 {
00125     if( interactive )
00126         return
00127             new VSinus(
00128                 0L,
00129                 m_p,
00130                 m_optionsWidget->width(),
00131                 m_optionsWidget->height(),
00132                 m_optionsWidget->periods() );
00133     else
00134         return
00135             new VSinus(
00136                 0L,
00137                 m_p,
00138                 m_d1,
00139                 m_d2,
00140                 m_optionsWidget->periods() );
00141 }
00142 
00143 bool
00144 VSinusTool::showDialog() const
00145 {
00146     return m_optionsWidget->exec() == QDialog::Accepted;
00147 }
00148 
00149 void
00150 VSinusTool::setup( KActionCollection *collection )
00151 {
00152     m_action = static_cast<KRadioAction *>(collection -> action( name() ) );
00153 
00154     if( m_action == 0 )
00155     {
00156         m_action = new KRadioAction( i18n( "Sinus Tool" ), "14_sinus", Qt::SHIFT+Qt::Key_S, this, SLOT( activate() ), collection, name() );
00157         m_action->setToolTip( i18n( "Sinus" ) );
00158         m_action->setExclusiveGroup( "shapes" );
00159         //m_ownAction = true;
00160     }
00161 }
00162 
KDE Home | KDE Accessibility Home | Description of Access Keys