kpresenter

KPrRectProperty.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005 Thorsten Zachmann <zachmann@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "KPrRectProperty.h"
21
22#include "rectpropertyui.h"
23#include "KPrRectPreview.h"
24
25#include <KoImageResource.h>
26
27#include <tqspinbox.h>
28#include <tqtoolbutton.h>
29#include <tqlayout.h>
30
31KPrRectProperty::KPrRectProperty( TQWidget *parent, const char *name, KPrRectValueCmd::RectValues &rectValue )
32: TQWidget( parent, name )
33, m_rectValue( rectValue )
34{
35 formerVerticalValue = 0;
36 TQVBoxLayout *layout = new TQVBoxLayout( this );
37 layout->addWidget( m_ui = new RectPropertyUI( this ) );
38 KoImageResource kir;
39 m_ui->combineButton->setPixmap(kir.chain());
40
41 connect( m_ui->xRndInput, TQ_SIGNAL( valueChanged( int ) ), this, TQ_SLOT( slotRndChanged() ) );
42 connect( m_ui->yRndInput, TQ_SIGNAL( valueChanged( int ) ), this, TQ_SLOT( slotRndChanged() ) );
43 connect( m_ui->combineButton, TQ_SIGNAL( toggled( bool ) ), this, TQ_SLOT( combineToggled( bool ) ) );
44
45 slotReset();
46}
47
48KPrRectProperty::~KPrRectProperty()
49{
50}
51
52
53int KPrRectProperty::getRectPropertyChange() const
54{
55 int flags = 0;
56
57 if ( getXRnd() != m_rectValue.xRnd )
58 flags |= KPrRectValueCmd::XRnd;
59
60 if ( getYRnd() != m_rectValue.yRnd )
61 flags |= KPrRectValueCmd::YRnd;
62
63 return flags;
64}
65
66
67KPrRectValueCmd::RectValues KPrRectProperty::getRectValues() const
68{
69 KPrRectValueCmd::RectValues rectValue;
70 rectValue.xRnd = getXRnd();
71 rectValue.yRnd = getYRnd();
72
73 return rectValue;
74}
75
76
77void KPrRectProperty::setRectValues( const KPrRectValueCmd::RectValues &rectValues )
78{
79 m_rectValue = rectValues;
80 slotReset();
81}
82
83
84void KPrRectProperty::apply()
85{
86 int flags = getRectPropertyChange();
87
88 if ( flags & KPrRectValueCmd::XRnd )
89 m_rectValue.xRnd = getXRnd();
90
91 if ( flags & KPrRectValueCmd::YRnd )
92 m_rectValue.yRnd = getYRnd();
93}
94
95
96int KPrRectProperty::getXRnd() const
97{
98 return m_ui->xRndInput->value();
99}
100
101
102int KPrRectProperty::getYRnd() const
103{
104 return m_ui->yRndInput->value();
105}
106
107
108void KPrRectProperty::slotRndChanged()
109{
110 m_ui->rectPreview->setRnds( getXRnd(), getYRnd() );
111}
112
113void KPrRectProperty::slotReset()
114{
115 m_ui->xRndInput->setValue( m_rectValue.xRnd );
116 m_ui->yRndInput->setValue( m_rectValue.yRnd );
117 if(m_rectValue.xRnd == m_rectValue.yRnd)
118 combineToggled(true);
119
120 m_ui->rectPreview->setRnds( getXRnd(), getYRnd() );
121}
122
123void KPrRectProperty::combineToggled( bool on)
124{
125 KoImageResource kir;
126 if( on ) {
127 formerVerticalValue = getYRnd();
128 m_ui->yRndInput->setValue( getXRnd() );
129 connect(m_ui->yRndInput, TQ_SIGNAL( valueChanged ( int ) ),
130 m_ui->xRndInput, TQ_SLOT( setValue ( int ) ));
131 connect(m_ui->xRndInput, TQ_SIGNAL( valueChanged ( int ) ),
132 m_ui->yRndInput, TQ_SLOT( setValue ( int ) ));
133 m_ui->combineButton->setPixmap(kir.chain());
134 }
135 else {
136 disconnect(m_ui->yRndInput, TQ_SIGNAL( valueChanged ( int ) ),
137 m_ui->xRndInput, TQ_SLOT( setValue ( int ) ));
138 disconnect(m_ui->xRndInput, TQ_SIGNAL( valueChanged ( int ) ),
139 m_ui->yRndInput, TQ_SLOT( setValue ( int ) ));
140 if(formerVerticalValue != 0)
141 m_ui->yRndInput->setValue( formerVerticalValue );
142 m_ui->combineButton->setPixmap(kir.chainBroken());
143 }
144}
145
146#include "KPrRectProperty.moc"