karbon

vroundrecttool.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 
00024 #include <knuminput.h>
00025 
00026 #include <karbon_view.h>
00027 #include <karbon_part.h>
00028 #include <shapes/vrectangle.h>
00029 #include "vroundrecttool.h"
00030 #include "KoUnitWidgets.h"
00031 
00032 #include <kgenericfactory.h>
00033 
00034 VRoundRectTool::VRoundRectOptionsWidget::VRoundRectOptionsWidget( KarbonPart *part, QWidget* parent, const char* name )
00035     : KDialogBase( parent, name, true, i18n( "Insert Round Rect" ), Ok | Cancel ), m_part( part )
00036 {
00037     QGroupBox *group = new QGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), this );
00038     new QLabel( i18n( "Width:" ), group );
00039     
00040     KoUnit::Unit unit = KoUnit::U_CM;
00041     m_width = new KoUnitDoubleSpinBox( group, 0.0, KoUnit::fromUserValue( 1000.0, unit ), KoUnit::fromUserValue( 0.5, unit ), KoUnit::fromUserValue( 10.0, unit ), unit );
00042 
00043     new QLabel( i18n( "Height (%1):" ).arg(KoUnit::unitName( m_part->unit() )), group );
00044     m_height = new KoUnitDoubleSpinBox( group, 0.0, KoUnit::fromUserValue( 1000.0, unit ), KoUnit::fromUserValue( 0.5, unit ), KoUnit::fromUserValue( 10.0, unit ), unit );
00045 
00046     new QLabel( i18n( "Edge radius X:" ), group );
00047     m_roundx = new KoUnitDoubleSpinBox( group, 0.0, KoUnit::fromUserValue( 100.0, unit ), KoUnit::fromUserValue( 0.1, unit ), KoUnit::fromUserValue( 1.0, unit ), unit );
00048 
00049     new QLabel( i18n( "Edge radius Y:" ), group );
00050     m_roundy = new KoUnitDoubleSpinBox( group, 0.0, KoUnit::fromUserValue( 100.0, unit ), KoUnit::fromUserValue( 0.1, unit ), KoUnit::fromUserValue( 1.0, unit ), unit );
00051 
00052     group->setInsideMargin( 4 );
00053     group->setInsideSpacing( 2 );
00054 
00055     setMainWidget( group );
00056     setFixedSize( baseSize() );
00057 }
00058 
00059 double
00060 VRoundRectTool::VRoundRectOptionsWidget::width() const
00061 {
00062     return m_width->value();
00063 }
00064 
00065 double
00066 VRoundRectTool::VRoundRectOptionsWidget::height() const
00067 {
00068     return m_height->value();
00069 }
00070 
00071 double
00072 VRoundRectTool::VRoundRectOptionsWidget::roundx() const
00073 {
00074     return m_roundx->value();
00075 }
00076 
00077 double
00078 VRoundRectTool::VRoundRectOptionsWidget::roundy() const
00079 {
00080     return m_roundy->value();
00081 }
00082 
00083 void
00084 VRoundRectTool::VRoundRectOptionsWidget::setWidth( double value )
00085 {
00086     m_width->changeValue( value );
00087 }
00088 
00089 void
00090 VRoundRectTool::VRoundRectOptionsWidget::setHeight( double value )
00091 {
00092     m_height->changeValue( value );
00093 }
00094 
00095 void
00096 VRoundRectTool::VRoundRectOptionsWidget::setRoundX( double value )
00097 {
00098     m_roundx->changeValue( value );
00099 }
00100 
00101 void
00102 VRoundRectTool::VRoundRectOptionsWidget::setRoundY( double value )
00103 {
00104     m_roundy->changeValue( value );
00105 }
00106 
00107 void
00108 VRoundRectTool::VRoundRectOptionsWidget::refreshUnit ()
00109 {
00110     m_width->setUnit( m_part->unit() );
00111     m_height->setUnit( m_part->unit() );
00112     m_roundx->setUnit( m_part->unit() );
00113     m_roundy->setUnit( m_part->unit() );
00114 }
00115 
00116 VRoundRectTool::VRoundRectTool( KarbonView *view )
00117         : VShapeTool( view, "tool_round_rectangle" )
00118 {
00119     // Create config dialog:
00120     m_optionsWidget = new VRoundRectOptionsWidget( view->part() );
00121     registerTool( this );
00122 }
00123 
00124 VRoundRectTool::~VRoundRectTool()
00125 {
00126     delete( m_optionsWidget );
00127 }
00128 
00129 void VRoundRectTool::refreshUnit()
00130 {
00131     m_optionsWidget->refreshUnit();
00132 }
00133 
00134 VPath*
00135 VRoundRectTool::shape( bool interactive ) const
00136 {
00137     if( interactive )
00138     {
00139         return
00140             new VRectangle(
00141                 0L,
00142                 m_p,
00143                 m_optionsWidget->width(),
00144                 m_optionsWidget->height(),
00145                 m_optionsWidget->roundx(),
00146                 m_optionsWidget->roundy() );
00147     }
00148     else {
00149         return
00150             new VRectangle(
00151                 0L,
00152                 m_p,
00153                 m_d1,
00154                 m_d2,
00155                 m_optionsWidget->roundx(),
00156                 m_optionsWidget->roundy() );
00157     }
00158 }
00159 
00160 bool
00161 VRoundRectTool::showDialog() const
00162 {
00163     return m_optionsWidget->exec() == QDialog::Accepted;
00164 }
00165 
00166 void
00167 VRoundRectTool::setup( KActionCollection *collection )
00168 {
00169     m_action = static_cast<KRadioAction *>(collection -> action( name() ) );
00170 
00171     if( m_action == 0 )
00172     {
00173         m_action = new KRadioAction( i18n( "Round Rectangle Tool" ), "14_roundrect", Qt::SHIFT+Qt::Key_H, this, SLOT( activate() ), collection, name() );
00174         m_action->setToolTip( i18n( "Round Rectangle" ) );
00175         m_action->setExclusiveGroup( "shapes" );
00176         //m_ownAction = true;
00177     }
00178 }
00179 
KDE Home | KDE Accessibility Home | Description of Access Keys