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