kpresenter

KPrMarginWidget.cpp

00001 // -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4; -*-
00002 /* This file is part of the KDE project
00003    Copyright (C) 2005 Thorsten Zachmann <zachmann@kde.org>
00004 
00005    The code is mostly a copy from kword/framedia.cc
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020  * Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #include "KPrMarginWidget.h"
00024 
00025 #include <qgroupbox.h>
00026 #include <qcheckbox.h>
00027 #include <qlayout.h>
00028 
00029 #include <klocale.h>
00030 #include <knuminput.h>
00031 
00032 #include "marginui.h"
00033 #include <KoUnitWidgets.h>//for KoUnitDoubleSpinBox
00034 
00035 KPrMarginWidget::KPrMarginWidget( QWidget *parent, const char *name, const KoUnit::Unit unit )
00036 : QWidget( parent, name )
00037 , m_unit( unit )
00038 , m_changed( false )
00039 , m_noSignal( false )
00040 {
00041     QVBoxLayout *layout = new QVBoxLayout( this );
00042 
00043     m_ui = new MarginUI( this );
00044     layout->addWidget( m_ui );
00045 
00046     QSpacerItem *spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Expanding );
00047     layout->addItem( spacer );
00048 
00049     m_ui->margins->setTitle( i18n( "Margins" ) );
00050 
00051     double dStep = KoUnit::fromUserValue( 0.5, unit );
00052     double dMax = KoUnit::fromUserValue( 9999, unit );
00053     m_ui->leftInput->setUnit( unit );
00054     m_ui->leftInput->setMinMaxStep( 0, dMax, dStep );
00055 
00056     m_ui->rightInput->setUnit( unit );
00057     m_ui->rightInput->setMinMaxStep( 0, dMax, dStep );
00058 
00059     m_ui->topInput->setUnit( unit );
00060     m_ui->topInput->setMinMaxStep( 0, dMax, dStep );
00061 
00062     m_ui->bottomInput->setUnit( unit );
00063     m_ui->bottomInput->setMinMaxStep( 0, dMax, dStep );
00064 
00065     connect( m_ui->leftInput, SIGNAL( valueChanged( double ) ),
00066              this, SLOT( slotValueChanged( double ) ) );
00067     connect( m_ui->rightInput, SIGNAL( valueChanged( double ) ),
00068              this, SLOT( slotValueChanged( double ) ) );
00069     connect( m_ui->topInput, SIGNAL( valueChanged( double ) ),
00070              this, SLOT( slotValueChanged( double ) ) );
00071     connect( m_ui->bottomInput, SIGNAL( valueChanged( double ) ),
00072              this, SLOT( slotValueChanged( double ) ) );
00073 }
00074 
00075 
00076 KPrMarginWidget::~KPrMarginWidget()
00077 {
00078 }
00079 
00080 
00081 void KPrMarginWidget::setValues( double left, double right, double top, double bottom )
00082 {
00083     m_ui->leftInput->changeValue( left );
00084     m_ui->rightInput->changeValue( right );
00085     m_ui->topInput->changeValue( top );
00086     m_ui->bottomInput->changeValue( bottom );
00087 }
00088 
00089 
00090 double KPrMarginWidget::leftValue() const
00091 {
00092     return m_ui->leftInput->value();
00093 }
00094 
00095 
00096 double KPrMarginWidget::rightValue() const
00097 {
00098     return m_ui->rightInput->value();
00099 }
00100 
00101 
00102 double KPrMarginWidget::topValue() const
00103 {
00104     return m_ui->topInput->value();
00105 }
00106 
00107 
00108 double KPrMarginWidget::bottomValue() const
00109 {
00110     return m_ui->bottomInput->value();
00111 }
00112 
00113 
00114 void KPrMarginWidget::slotValueChanged( double val )
00115 {
00116     m_changed = true;
00117     if ( m_ui->synchronize->isChecked() && !m_noSignal )
00118     {
00119         m_noSignal = true;
00120         m_ui->leftInput->setValue( val );
00121         m_ui->bottomInput->setValue( val );
00122         m_ui->rightInput->setValue( val );
00123         m_ui->topInput->setValue( val );
00124         m_noSignal = false;
00125     }
00126 }
00127 
00128 
00129 #include "KPrMarginWidget.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys