karbon

vrectangletool.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 <knuminput.h>
00025 
00026 #include <karbon_view.h>
00027 #include <karbon_part.h>
00028 #include <shapes/vrectangle.h>
00029 #include "vrectangletool.h"
00030 #include <KoUnitWidgets.h>
00031 
00032 
00033 VRectangleTool::VRectangleOptionsWidget::VRectangleOptionsWidget( KarbonPart *part, QWidget* parent, const char* name )
00034     : KDialogBase( parent, name, true, i18n( "Insert Rectangle" ), Ok | Cancel ), m_part( part )
00035 {
00036     QGroupBox *group = new QGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), this );
00037     // add width/height-input:
00038     m_widthLabel = new QLabel( i18n( "object width", "Width:" ), group );
00039     m_width = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 100.0, KoUnit::U_MM );
00040 
00041     m_heightLabel = new QLabel( i18n( "Height:" ), group );
00042     m_height = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 100.0, KoUnit::U_MM );
00043 
00044     refreshUnit();
00045 
00046     group->setInsideMargin( 4 );
00047     group->setInsideSpacing( 2 );
00048 
00049     setMainWidget( group );
00050     //setFixedSize( baseSize() );
00051 }
00052 
00053 double
00054 VRectangleTool::VRectangleOptionsWidget::width() const
00055 {
00056     return m_width->value();
00057 }
00058 
00059 double
00060 VRectangleTool::VRectangleOptionsWidget::height() const
00061 {
00062     return m_height->value();
00063 }
00064 
00065 void
00066 VRectangleTool::VRectangleOptionsWidget::setWidth( double value )
00067 {
00068     m_width->setValue( value );
00069 }
00070 
00071 void
00072 VRectangleTool::VRectangleOptionsWidget::setHeight( double value )
00073 {
00074     m_height->setValue( value );
00075 }
00076 
00077 void
00078 VRectangleTool::VRectangleOptionsWidget::refreshUnit()
00079 {
00080     m_width->setUnit( m_part->unit() );
00081     m_height->setUnit( m_part->unit() );
00082 }
00083 
00084 VRectangleTool::VRectangleTool( KarbonView *view )
00085     : VShapeTool( view, "tool_rectangle" )
00086 {
00087     // Create config dialog:
00088     m_optionWidget = new VRectangleOptionsWidget( view->part() );
00089     registerTool( this );
00090 }
00091 
00092 VRectangleTool::~VRectangleTool()
00093 {
00094     delete( m_optionWidget );
00095 }
00096 
00097 void
00098 VRectangleTool::refreshUnit()
00099 {
00100     m_optionWidget->refreshUnit();
00101 }
00102 
00103 VPath *
00104 VRectangleTool::shape( bool interactive ) const
00105 {
00106     if( interactive )
00107     {
00108         return
00109             new VRectangle(
00110                 0L,
00111                 m_p,
00112                 m_optionWidget->width(),
00113                 m_optionWidget->height() );
00114     }
00115     else
00116         return
00117             new VRectangle(
00118                 0L,
00119                 m_p,
00120                 m_d1,
00121                 m_d2 );
00122 }
00123 
00124 bool
00125 VRectangleTool::showDialog() const
00126 {
00127     return m_optionWidget->exec() == QDialog::Accepted;
00128 }
00129 
00130 void
00131 VRectangleTool::setup( KActionCollection *collection )
00132 {
00133     m_action = static_cast<KRadioAction *>(collection -> action( name() ) );
00134 
00135     if( m_action == 0 )
00136     {
00137         m_action = new KRadioAction( i18n( "Rectangle Tool" ), "14_rectangle", Qt::Key_Plus+Qt::Key_F9, this, SLOT( activate() ), collection, name() );
00138         m_action->setToolTip( i18n( "Rectangle" ) );
00139         m_action->setExclusiveGroup( "shapes" );
00140         //m_ownAction = true;
00141     }
00142 }
00143 
KDE Home | KDE Accessibility Home | Description of Access Keys