19#include "KPrGeneralProperty.h"
21#include <tqcheckbox.h>
22#include <tqgroupbox.h>
25#include <tqlineedit.h>
29#include <KoUnitWidgets.h>
31#include <KoGeneralPropertyUi.h>
33KPrGeneralProperty::KPrGeneralProperty( TQWidget *parent,
const char *name, GeneralValue &generalValue, KoUnit::Unit unit )
34: TQWidget( parent, name )
36, m_generalValue( generalValue )
39 TQVBoxLayout *layout =
new TQVBoxLayout(
this );
40 layout->addWidget( m_ui =
new KoGeneralPropertyUI(
this ) );
42 TQSpacerItem* spacer =
new TQSpacerItem( 20, 20, TQSizePolicy::Minimum, TQSizePolicy::Expanding );
43 layout->addItem( spacer );
45 if ( m_generalValue.m_name.isNull() )
47 m_ui->nameLabel->setEnabled(
false );
48 m_ui->nameInput->setEnabled(
false );
52 m_ui->nameInput->setText( m_generalValue.m_name );
55 m_ui->positionGroup->setTitle( i18n(
"Position" ) );
57 connect( m_ui->protect, TQ_SIGNAL( toggled(
bool ) ),
this, TQ_SLOT( slotProtectToggled(
bool ) ) );
58 connect( m_ui->keepRatio, TQ_SIGNAL( toggled(
bool ) ),
this, TQ_SLOT( slotKeepRatioToggled(
bool ) ) );
60 double dStep = KoUnit::fromUserValue( 0.5, m_unit );
61 double dMax = KoUnit::fromUserValue( 9999, m_unit );
62 m_ui->xInput->setUnit( m_unit );
63 m_ui->xInput->setMinMaxStep( 0, dMax, dStep );
65 m_ui->yInput->setUnit( m_unit );
66 m_ui->yInput->setMinMaxStep( 0, dMax, dStep );
68 m_ui->widthInput->setUnit( m_unit );
69 m_ui->widthInput->setMinMaxStep( 0, dMax, dStep );
70 connect( m_ui->widthInput, TQ_SIGNAL( valueChanged(
double ) ),
this, TQ_SLOT( slotWidthChanged(
double ) ) );
72 m_ui->heightInput->setUnit( m_unit );
73 m_ui->heightInput->setMinMaxStep( 0, dMax, dStep );
74 connect( m_ui->heightInput, TQ_SIGNAL( valueChanged(
double ) ),
this, TQ_SLOT( slotHeightChanged(
double ) ) );
79KPrGeneralProperty::~KPrGeneralProperty()
84int KPrGeneralProperty::getGeneralPropertyChange()
const
88 if ( !m_generalValue.m_name.isNull() && m_generalValue.m_name != m_ui->nameInput->text() )
91 if ( m_ui->protect->state() != TQButton::NoChange )
93 if ( ( m_ui->protect->isOn() ? STATE_ON : STATE_OFF ) != m_generalValue.m_protect )
96 if ( !m_ui->protect->isOn() )
98 KoRect rect = getRect();
99 if ( m_generalValue.m_rect.left() != rect.left() )
101 if ( m_generalValue.m_rect.top() != rect.top() )
104 if ( TQABS( m_generalValue.m_rect.width() - rect.width() ) > 1e-6 )
106 if ( TQABS( m_generalValue.m_rect.height() - rect.height() ) > 1e-6 )
111 if ( m_ui->keepRatio->state() != TQButton::NoChange
112 && ( m_ui->keepRatio->isOn() ? STATE_ON : STATE_OFF ) != m_generalValue.m_keepRatio )
121KPrGeneralProperty::GeneralValue KPrGeneralProperty::getGeneralValue()
const
123 GeneralValue generalValue;
124 generalValue.m_name = m_ui->nameInput->isEnabled() ? m_ui->nameInput->text() : TQString();
125 generalValue.m_protect = m_ui->protect->isOn() ? STATE_ON : STATE_OFF;
126 generalValue.m_keepRatio = m_ui->keepRatio->isOn() ? STATE_ON : STATE_OFF;
127 generalValue.m_rect = getRect();
132void KPrGeneralProperty::apply()
134 int flags = getGeneralPropertyChange();
137 m_generalValue.m_name = m_ui->nameInput->text();
139 if ( flags & Protect )
140 m_generalValue.m_protect = m_ui->protect->isOn() ? STATE_ON : STATE_OFF;
142 if ( flags & KeepRatio )
143 m_generalValue.m_keepRatio = m_ui->keepRatio->isOn() ? STATE_ON : STATE_OFF;
146 m_generalValue.m_rect = getRect();
150KoRect KPrGeneralProperty::getRect()
const
152 double x = TQMAX( 0, m_ui->xInput->value() );
153 double y = TQMAX( 0, m_ui->yInput->value() );
154 double w = TQMAX( 0, m_ui->widthInput->value() );
155 double h = TQMAX( 0, m_ui->heightInput->value() );
157 KoRect rect( x, y, w, h );
162void KPrGeneralProperty::setRect( KoRect &rect )
164 m_ui->xInput->changeValue( TQMAX( 0.00, rect.left() ) );
165 m_ui->yInput->changeValue( TQMAX( 0.00, rect.top() ) );
166 m_ui->widthInput->changeValue( TQMAX( 0.00, rect.width() ) );
167 m_ui->heightInput->changeValue( TQMAX( 0.00, rect.height() ) );
171void KPrGeneralProperty::slotReset()
173 switch ( m_generalValue.m_protect )
176 m_ui->protect->setChecked(
true );
179 m_ui->protect->setChecked(
false );
182 m_ui->protect->setTristate(
true );
183 m_ui->protect->setNoChange();
186 m_ui->protect->setChecked(
false );
190 switch ( m_generalValue.m_keepRatio )
193 m_ui->keepRatio->setChecked(
true );
196 m_ui->keepRatio->setChecked(
false );
199 m_ui->keepRatio->setTristate(
true );
200 m_ui->keepRatio->setNoChange();
203 m_ui->keepRatio->setChecked(
false );
207 setRect( m_generalValue.m_rect );
209 m_generalValue.m_rect = getRect();
213void KPrGeneralProperty::slotProtectToggled(
bool state )
215 m_ui->positionGroup->setEnabled( !state );
219void KPrGeneralProperty::slotKeepRatioToggled(
bool state )
223 if ( m_ui->widthInput->value() == 0 )
229 m_ratio = m_ui->heightInput->value() / m_ui->widthInput->value();
235void KPrGeneralProperty::slotWidthChanged(
double value )
237 if ( m_ui->keepRatio->isChecked() )
239 m_ui->heightInput->setValue( value * m_ratio );
244void KPrGeneralProperty::slotHeightChanged(
double value )
246 if ( m_ui->keepRatio->isChecked() && m_ratio != 0 )
248 m_ui->widthInput->setValue( value / m_ratio );
253#include "KPrGeneralProperty.moc"