kpresenter

KPrMarginWidget.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005 Thorsten Zachmann <zachmann@kde.org>
3
4 The code is mostly a copy from kword/framedia.cpp
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20*/
21
22#include "KPrMarginWidget.h"
23
24#include <tqgroupbox.h>
25#include <tqcheckbox.h>
26#include <tqlayout.h>
27
28#include <tdelocale.h>
29#include <knuminput.h>
30
31#include "marginui.h"
32#include <KoUnitWidgets.h>//for KoUnitDoubleSpinBox
33
34KPrMarginWidget::KPrMarginWidget( TQWidget *parent, const char *name, const KoUnit::Unit unit )
35: TQWidget( parent, name )
36, m_unit( unit )
37, m_changed( false )
38, m_noSignal( false )
39{
40 TQVBoxLayout *layout = new TQVBoxLayout( this );
41
42 m_ui = new MarginUI( this );
43 layout->addWidget( m_ui );
44
45 TQSpacerItem *spacer = new TQSpacerItem( 20, 20, TQSizePolicy::Expanding, TQSizePolicy::Expanding );
46 layout->addItem( spacer );
47
48 m_ui->margins->setTitle( i18n( "Margins" ) );
49
50 double dStep = KoUnit::fromUserValue( 0.5, unit );
51 double dMax = KoUnit::fromUserValue( 9999, unit );
52 m_ui->leftInput->setUnit( unit );
53 m_ui->leftInput->setMinMaxStep( 0, dMax, dStep );
54
55 m_ui->rightInput->setUnit( unit );
56 m_ui->rightInput->setMinMaxStep( 0, dMax, dStep );
57
58 m_ui->topInput->setUnit( unit );
59 m_ui->topInput->setMinMaxStep( 0, dMax, dStep );
60
61 m_ui->bottomInput->setUnit( unit );
62 m_ui->bottomInput->setMinMaxStep( 0, dMax, dStep );
63
64 connect( m_ui->leftInput, TQ_SIGNAL( valueChanged( double ) ),
65 this, TQ_SLOT( slotValueChanged( double ) ) );
66 connect( m_ui->rightInput, TQ_SIGNAL( valueChanged( double ) ),
67 this, TQ_SLOT( slotValueChanged( double ) ) );
68 connect( m_ui->topInput, TQ_SIGNAL( valueChanged( double ) ),
69 this, TQ_SLOT( slotValueChanged( double ) ) );
70 connect( m_ui->bottomInput, TQ_SIGNAL( valueChanged( double ) ),
71 this, TQ_SLOT( slotValueChanged( double ) ) );
72}
73
74
75KPrMarginWidget::~KPrMarginWidget()
76{
77}
78
79
80void KPrMarginWidget::setValues( double left, double right, double top, double bottom )
81{
82 m_ui->leftInput->changeValue( left );
83 m_ui->rightInput->changeValue( right );
84 m_ui->topInput->changeValue( top );
85 m_ui->bottomInput->changeValue( bottom );
86}
87
88
89double KPrMarginWidget::leftValue() const
90{
91 return m_ui->leftInput->value();
92}
93
94
95double KPrMarginWidget::rightValue() const
96{
97 return m_ui->rightInput->value();
98}
99
100
101double KPrMarginWidget::topValue() const
102{
103 return m_ui->topInput->value();
104}
105
106
107double KPrMarginWidget::bottomValue() const
108{
109 return m_ui->bottomInput->value();
110}
111
112
113void KPrMarginWidget::slotValueChanged( double val )
114{
115 m_changed = true;
116 if ( m_ui->synchronize->isChecked() && !m_noSignal )
117 {
118 m_noSignal = true;
119 m_ui->leftInput->setValue( val );
120 m_ui->bottomInput->setValue( val );
121 m_ui->rightInput->setValue( val );
122 m_ui->topInput->setValue( val );
123 m_noSignal = false;
124 }
125}
126
127
128#include "KPrMarginWidget.moc"