19#include "kspread_generalProperty.h"
21#include <tqcheckbox.h>
22#include <tqgroupbox.h>
25#include <tqlineedit.h>
29#include <KoGeneralPropertyUi.h>
30#include <KoUnitWidgets.h>
34GeneralProperty::GeneralProperty( TQWidget *parent,
const char *name, GeneralValue &generalValue, KoUnit::Unit unit )
35: TQWidget( parent, name )
37, m_generalValue( generalValue )
40 TQVBoxLayout *layout =
new TQVBoxLayout(
this );
41 layout->addWidget( m_ui =
new KoGeneralPropertyUI(
this ) );
43 TQSpacerItem* spacer =
new TQSpacerItem( 20, 20, TQSizePolicy::Minimum, TQSizePolicy::Expanding );
44 layout->addItem( spacer );
46 if ( m_generalValue.m_name.isNull() )
48 m_ui->nameLabel->setEnabled(
false );
49 m_ui->nameInput->setEnabled(
false );
53 m_ui->nameInput->setText( m_generalValue.m_name );
56 m_ui->positionGroup->setTitle( i18n(
"Position" ) );
58 connect( m_ui->protect, TQ_SIGNAL( toggled(
bool ) ),
this, TQ_SLOT( slotProtectToggled(
bool ) ) );
59 connect( m_ui->keepRatio, TQ_SIGNAL( toggled(
bool ) ),
this, TQ_SLOT( slotKeepRatioToggled(
bool ) ) );
61 double dStep = KoUnit::fromUserValue( 0.5, m_unit );
62 double dMax = KoUnit::fromUserValue( 9999, m_unit );
63 m_ui->xInput->setUnit( m_unit );
64 m_ui->xInput->setMinMaxStep( 0, dMax, dStep );
66 m_ui->yInput->setUnit( m_unit );
67 m_ui->yInput->setMinMaxStep( 0, dMax, dStep );
69 m_ui->widthInput->setUnit( m_unit );
70 m_ui->widthInput->setMinMaxStep( 0, dMax, dStep );
71 connect( m_ui->widthInput, TQ_SIGNAL( valueChanged(
double ) ),
this, TQ_SLOT( slotWidthChanged(
double ) ) );
73 m_ui->heightInput->setUnit( m_unit );
74 m_ui->heightInput->setMinMaxStep( 0, dMax, dStep );
75 connect( m_ui->heightInput, TQ_SIGNAL( valueChanged(
double ) ),
this, TQ_SLOT( slotHeightChanged(
double ) ) );
80GeneralProperty::~GeneralProperty()
85int GeneralProperty::getGeneralPropertyChange()
const
89 if ( !m_generalValue.m_name.isNull() && m_generalValue.m_name != m_ui->nameInput->text() )
92 if ( m_ui->protect->state() != TQButton::NoChange )
94 if ( ( m_ui->protect->isOn() ? STATE_ON : STATE_OFF ) != m_generalValue.m_protect )
97 if ( !m_ui->protect->isOn() )
99 KoRect rect = getRect();
100 if ( m_generalValue.m_rect.left() != rect.left() )
102 if ( m_generalValue.m_rect.top() != rect.top() )
105 if ( TQABS( m_generalValue.m_rect.width() - rect.width() ) > 1e-6 )
107 if ( TQABS( m_generalValue.m_rect.height() - rect.height() ) > 1e-6 )
112 if ( m_ui->keepRatio->state() != TQButton::NoChange
113 && ( m_ui->keepRatio->isOn() ? STATE_ON : STATE_OFF ) != m_generalValue.m_keepRatio )
122GeneralProperty::GeneralValue GeneralProperty::getGeneralValue()
const
124 GeneralValue generalValue;
125 generalValue.m_name = m_ui->nameInput->isEnabled() ? m_ui->nameInput->text() : TQString();
126 generalValue.m_protect = m_ui->protect->isOn() ? STATE_ON : STATE_OFF;
127 generalValue.m_keepRatio = m_ui->keepRatio->isOn() ? STATE_ON : STATE_OFF;
128 generalValue.m_rect = getRect();
133void GeneralProperty::apply()
135 int flags = getGeneralPropertyChange();
138 m_generalValue.m_name = m_ui->nameInput->text();
140 if ( flags & Protect )
141 m_generalValue.m_protect = m_ui->protect->isOn() ? STATE_ON : STATE_OFF;
143 if ( flags & KeepRatio )
144 m_generalValue.m_keepRatio = m_ui->keepRatio->isOn() ? STATE_ON : STATE_OFF;
147 m_generalValue.m_rect = getRect();
151KoRect GeneralProperty::getRect()
const
153 double x = TQMAX( 0, m_ui->xInput->value() );
154 double y = TQMAX( 0, m_ui->yInput->value() );
155 double w = TQMAX( 0, m_ui->widthInput->value() );
156 double h = TQMAX( 0, m_ui->heightInput->value() );
158 KoRect rect( x, y, w, h );
163void GeneralProperty::setRect( KoRect &rect )
165 m_ui->xInput->changeValue( TQMAX( 0.00, rect.left() ) );
166 m_ui->yInput->changeValue( TQMAX( 0.00, rect.top() ) );
167 m_ui->widthInput->changeValue( TQMAX( 0.00, rect.width() ) );
168 m_ui->heightInput->changeValue( TQMAX( 0.00, rect.height() ) );
172void GeneralProperty::slotReset()
174 switch ( m_generalValue.m_protect )
177 m_ui->protect->setChecked(
true );
180 m_ui->protect->setChecked(
false );
183 m_ui->protect->setTristate(
true );
184 m_ui->protect->setNoChange();
187 m_ui->protect->setChecked(
false );
191 switch ( m_generalValue.m_keepRatio )
194 m_ui->keepRatio->setChecked(
true );
197 m_ui->keepRatio->setChecked(
false );
200 m_ui->keepRatio->setTristate(
true );
201 m_ui->keepRatio->setNoChange();
204 m_ui->keepRatio->setChecked(
false );
208 setRect( m_generalValue.m_rect );
210 m_generalValue.m_rect = getRect();
214void GeneralProperty::slotProtectToggled(
bool state )
216 m_ui->positionGroup->setEnabled( !state );
220void GeneralProperty::slotKeepRatioToggled(
bool state )
224 if ( m_ui->widthInput->value() == 0 )
230 m_ratio = m_ui->heightInput->value() / m_ui->widthInput->value();
236void GeneralProperty::slotWidthChanged(
double value )
238 if ( m_ui->keepRatio->isChecked() )
240 m_ui->heightInput->setValue( value * m_ratio );
245void GeneralProperty::slotHeightChanged(
double value )
247 if ( m_ui->keepRatio->isChecked() && m_ratio != 0 )
249 m_ui->widthInput->setValue( value / m_ratio );
254#include "kspread_generalProperty.moc"