00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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
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
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
00141 }
00142 }
00143