kpresenter

KPrRectProperty.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    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "KPrRectProperty.h"
00022 
00023 #include "rectpropertyui.h"
00024 #include "KPrRectPreview.h"
00025 
00026 #include <KoImageResource.h>
00027 
00028 #include <qspinbox.h>
00029 #include <qtoolbutton.h>
00030 #include <qlayout.h>
00031 
00032 KPrRectProperty::KPrRectProperty( QWidget *parent, const char *name, KPrRectValueCmd::RectValues &rectValue )
00033 : QWidget( parent, name )
00034 , m_rectValue( rectValue )
00035 {
00036     formerVerticalValue = 0;
00037     QVBoxLayout *layout = new QVBoxLayout( this );
00038     layout->addWidget( m_ui = new RectPropertyUI( this ) );
00039     KoImageResource kir;
00040     m_ui->combineButton->setPixmap(kir.chain());
00041 
00042     connect( m_ui->xRndInput, SIGNAL( valueChanged( int ) ), this, SLOT( slotRndChanged() ) );
00043     connect( m_ui->yRndInput, SIGNAL( valueChanged( int ) ), this, SLOT( slotRndChanged() ) );
00044     connect( m_ui->combineButton, SIGNAL( toggled( bool ) ), this, SLOT( combineToggled( bool ) ) );
00045 
00046     slotReset();
00047 }
00048 
00049 KPrRectProperty::~KPrRectProperty()
00050 {
00051 }
00052 
00053 
00054 int KPrRectProperty::getRectPropertyChange() const
00055 {
00056     int flags = 0;
00057 
00058     if ( getXRnd() != m_rectValue.xRnd )
00059         flags |= KPrRectValueCmd::XRnd;
00060 
00061     if ( getYRnd() != m_rectValue.yRnd )
00062         flags |= KPrRectValueCmd::YRnd;
00063 
00064     return flags;
00065 }
00066 
00067 
00068 KPrRectValueCmd::RectValues KPrRectProperty::getRectValues() const
00069 {
00070     KPrRectValueCmd::RectValues rectValue;
00071     rectValue.xRnd = getXRnd();
00072     rectValue.yRnd = getYRnd();
00073 
00074     return rectValue;
00075 }
00076 
00077 
00078 void KPrRectProperty::setRectValues( const KPrRectValueCmd::RectValues &rectValues )
00079 {
00080     m_rectValue = rectValues;
00081     slotReset();
00082 }
00083 
00084 
00085 void KPrRectProperty::apply()
00086 {
00087     int flags = getRectPropertyChange();
00088 
00089     if ( flags & KPrRectValueCmd::XRnd )
00090         m_rectValue.xRnd = getXRnd();
00091 
00092     if ( flags & KPrRectValueCmd::YRnd )
00093         m_rectValue.yRnd = getYRnd();
00094 }
00095 
00096 
00097 int KPrRectProperty::getXRnd() const
00098 {
00099     return m_ui->xRndInput->value();
00100 }
00101 
00102 
00103 int KPrRectProperty::getYRnd() const
00104 {
00105     return m_ui->yRndInput->value();
00106 }
00107 
00108 
00109 void KPrRectProperty::slotRndChanged()
00110 {
00111     m_ui->rectPreview->setRnds( getXRnd(), getYRnd() );
00112 }
00113 
00114 void KPrRectProperty::slotReset()
00115 {
00116     m_ui->xRndInput->setValue( m_rectValue.xRnd );
00117     m_ui->yRndInput->setValue( m_rectValue.yRnd );
00118     if(m_rectValue.xRnd == m_rectValue.yRnd)
00119         combineToggled(true);
00120 
00121     m_ui->rectPreview->setRnds( getXRnd(), getYRnd() );
00122 }
00123 
00124 void KPrRectProperty::combineToggled( bool on)
00125 {
00126     KoImageResource kir;
00127     if( on ) {
00128         formerVerticalValue = getYRnd();
00129         m_ui->yRndInput->setValue( getXRnd() );
00130         connect(m_ui->yRndInput, SIGNAL( valueChanged ( int ) ),
00131                 m_ui->xRndInput, SLOT( setValue ( int ) ));
00132         connect(m_ui->xRndInput, SIGNAL( valueChanged ( int ) ),
00133                 m_ui->yRndInput, SLOT( setValue ( int ) ));
00134         m_ui->combineButton->setPixmap(kir.chain());
00135     }
00136     else {
00137         disconnect(m_ui->yRndInput, SIGNAL( valueChanged ( int ) ),
00138                 m_ui->xRndInput, SLOT( setValue ( int ) ));
00139         disconnect(m_ui->xRndInput, SIGNAL( valueChanged ( int ) ),
00140                 m_ui->yRndInput, SLOT( setValue ( int ) ));
00141         if(formerVerticalValue != 0)
00142             m_ui->yRndInput->setValue( formerVerticalValue );
00143         m_ui->combineButton->setPixmap(kir.chainBroken());
00144     }
00145 }
00146 
00147 #include "KPrRectProperty.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys