summaryrefslogtreecommitdiffstats
path: root/kpresenter/KPrMarginWidget.cpp
blob: 6be911e9b756dac98143d57efe1ddafd2d2f3c34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* This file is part of the KDE project
   Copyright (C) 2005 Thorsten Zachmann <zachmann@kde.org>

   The code is mostly a copy from kword/framedia.cpp

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#include "KPrMarginWidget.h"

#include <tqgroupbox.h>
#include <tqcheckbox.h>
#include <tqlayout.h>

#include <tdelocale.h>
#include <knuminput.h>

#include "marginui.h"
#include <KoUnitWidgets.h>//for KoUnitDoubleSpinBox

KPrMarginWidget::KPrMarginWidget( TQWidget *parent, const char *name, const KoUnit::Unit unit )
: TQWidget( parent, name )
, m_unit( unit )
, m_changed( false )
, m_noSignal( false )
{
    TQVBoxLayout *layout = new TQVBoxLayout( this );

    m_ui = new MarginUI( this );
    layout->addWidget( m_ui );

    TQSpacerItem *spacer = new TQSpacerItem( 20, 20, TQSizePolicy::Expanding, TQSizePolicy::Expanding );
    layout->addItem( spacer );

    m_ui->margins->setTitle( i18n( "Margins" ) );

    double dStep = KoUnit::fromUserValue( 0.5, unit );
    double dMax = KoUnit::fromUserValue( 9999, unit );
    m_ui->leftInput->setUnit( unit );
    m_ui->leftInput->setMinMaxStep( 0, dMax, dStep );

    m_ui->rightInput->setUnit( unit );
    m_ui->rightInput->setMinMaxStep( 0, dMax, dStep );

    m_ui->topInput->setUnit( unit );
    m_ui->topInput->setMinMaxStep( 0, dMax, dStep );

    m_ui->bottomInput->setUnit( unit );
    m_ui->bottomInput->setMinMaxStep( 0, dMax, dStep );

    connect( m_ui->leftInput, TQ_SIGNAL( valueChanged( double ) ),
             this, TQ_SLOT( slotValueChanged( double ) ) );
    connect( m_ui->rightInput, TQ_SIGNAL( valueChanged( double ) ),
             this, TQ_SLOT( slotValueChanged( double ) ) );
    connect( m_ui->topInput, TQ_SIGNAL( valueChanged( double ) ),
             this, TQ_SLOT( slotValueChanged( double ) ) );
    connect( m_ui->bottomInput, TQ_SIGNAL( valueChanged( double ) ),
             this, TQ_SLOT( slotValueChanged( double ) ) );
}


KPrMarginWidget::~KPrMarginWidget()
{
}


void KPrMarginWidget::setValues( double left, double right, double top, double bottom )
{
    m_ui->leftInput->changeValue( left );
    m_ui->rightInput->changeValue( right );
    m_ui->topInput->changeValue( top );
    m_ui->bottomInput->changeValue( bottom );
}


double KPrMarginWidget::leftValue() const
{
    return m_ui->leftInput->value();
}


double KPrMarginWidget::rightValue() const
{
    return m_ui->rightInput->value();
}


double KPrMarginWidget::topValue() const
{
    return m_ui->topInput->value();
}


double KPrMarginWidget::bottomValue() const
{
    return m_ui->bottomInput->value();
}


void KPrMarginWidget::slotValueChanged( double val )
{
    m_changed = true;
    if ( m_ui->synchronize->isChecked() && !m_noSignal )
    {
        m_noSignal = true;
        m_ui->leftInput->setValue( val );
        m_ui->bottomInput->setValue( val );
        m_ui->rightInput->setValue( val );
        m_ui->topInput->setValue( val );
        m_noSignal = false;
    }
}


#include "KPrMarginWidget.moc"