kspread Library API Documentation

kspread_dlg_resize2.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002-2004 Ariya Hidayat <ariya@kde.org>
00003              (C) 2003 Norbert Andres <nandres@web.de>
00004              (C) 2001-2003 Philipp Mueller <philipp.mueller@gmx.de>
00005              (C) 1999-2002 Laurent Montel <montel@kde.org>
00006              (C) 2002 John Dailey <dailey@vt.edu>
00007              (C) 2000 David Faure <faure@kde.org>
00008              (C) 1998-1999 Torben Weis <weis@kde.org>
00009 
00010    This library is free software; you can redistribute it and/or
00011    modify it under the terms of the GNU Library General Public
00012    License as published by the Free Software Foundation; either
00013    version 2 of the License, or (at your option) any later version.
00014 
00015    This library is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018    Library General Public License for more details.
00019 
00020    You should have received a copy of the GNU Library General Public License
00021    along with this library; see the file COPYING.LIB.  If not, write to
00022    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00023    Boston, MA 02111-1307, USA.
00024 */
00025 
00026 #include <float.h>
00027 #include <qlayout.h>
00028 
00029 #include <knuminput.h>
00030 
00031 #include <koUnit.h>
00032 
00033 #include "kspread_dlg_resize2.h"
00034 #include <kspread_global.h>
00035 #include <kspread_canvas.h>
00036 #include <kspread_sheet.h>
00037 #include <kspread_doc.h>
00038 #include <kspread_locale.h>
00039 #include <kspread_undo.h>
00040 #include <kspread_view.h>
00041 
00042 #include <qlabel.h>
00043 
00044 KSpreadResizeRow::KSpreadResizeRow( KSpreadView* parent, const char* name )
00045     : KDialogBase( parent, name, true, i18n("Resize Row"), Ok|Cancel|Default )
00046 {
00047     m_pView = parent;
00048 
00049     QWidget *page = new QWidget( this );
00050     setMainWidget( page );
00051 
00052     QVBoxLayout *vLay = new QVBoxLayout( page, 0, spacingHint() );
00053     QHBoxLayout *hLay = new QHBoxLayout( vLay );
00054 
00055     QRect selection( m_pView->selection() );
00056     RowFormat* rl = m_pView->activeSheet()->rowFormat( selection.top() );
00057     rowHeight = rl->dblHeight();
00058 
00059     QLabel * label1 = new QLabel( page, "label1" );
00060     label1->setText( i18n( "Height:" ) );
00061     hLay->addWidget( label1 );
00062 
00063     m_pHeight = new KDoubleNumInput( page );
00064     m_pHeight->setPrecision( 2 );
00065     m_pHeight->setValue( KoUnit::toUserValue( rowHeight,
00066                                            m_pView->doc()->getUnit() ) );
00067     m_pHeight->setSuffix( m_pView->doc()->getUnitName() );
00068     hLay->addWidget( m_pHeight );
00069 
00070     QWidget *hSpacer = new QWidget( page );
00071     hSpacer->setMinimumSize( spacingHint(), spacingHint() );
00072     hLay->addWidget( hSpacer );
00073 
00074     QWidget *vSpacer = new QWidget( page );
00075     vSpacer->setMinimumSize( spacingHint(), spacingHint() );
00076     vLay->addWidget( vSpacer );
00077 
00078     m_pHeight->setFocus();
00079 
00080     //store the visible value, for later check for changes
00081     rowHeight = KoUnit::fromUserValue( m_pHeight->value(), m_pView->doc()->getUnit() );
00082 }
00083 
00084 void KSpreadResizeRow::slotOk()
00085 {
00086     m_pView->doc()->emitBeginOperation( false );
00087     double height = KoUnit::fromUserValue( m_pHeight->value(), m_pView->doc()->getUnit() );
00088 
00089     //Don't generate a resize, when there isn't a change or the change is only a rounding issue
00090     if ( fabs( height - rowHeight ) > DBL_EPSILON )
00091     {
00092         QRect selection( m_pView->selection() );
00093 
00094         if ( !m_pView->doc()->undoLocked() )
00095         {
00096             KSpreadUndoResizeColRow *undo = new KSpreadUndoResizeColRow( m_pView->doc(), m_pView->activeSheet(), selection );
00097             m_pView->doc()->addCommand( undo );
00098         }
00099 
00100         for( int i=selection.top(); i <= selection.bottom(); i++ )
00101             m_pView->vBorderWidget()->resizeRow( height, i, false );
00102     }
00103 
00104     m_pView->slotUpdateView( m_pView->activeSheet() );
00105     accept();
00106 }
00107 
00108 void KSpreadResizeRow::slotDefault()
00109 {
00110     double height = KoUnit::toUserValue( heightOfRow,m_pView->doc()->getUnit() );
00111     m_pHeight->setValue( height );
00112 }
00113 
00114 KSpreadResizeColumn::KSpreadResizeColumn( KSpreadView* parent, const char* name )
00115     : KDialogBase( parent, name, true, i18n("Resize Column"), Ok|Cancel|Default )
00116 {
00117     m_pView = parent;
00118 
00119     QWidget *page = new QWidget( this );
00120     setMainWidget(page);
00121 
00122     QVBoxLayout *vLay = new QVBoxLayout( page, 0, spacingHint() );
00123     QHBoxLayout *hLay = new QHBoxLayout( vLay );
00124 
00125     QRect selection( m_pView->selection() );
00126     ColumnFormat* cl = m_pView->activeSheet()->columnFormat( selection.left() );
00127     columnWidth = cl->dblWidth();
00128 
00129     QLabel * label1 = new QLabel( page, "label1" );
00130     label1->setText( i18n( "Width:" ) );
00131     hLay->addWidget( label1 );
00132 
00133     m_pWidth = new KDoubleNumInput( page );
00134     m_pWidth->setPrecision( 2 );
00135     m_pWidth->setValue( KoUnit::toUserValue( columnWidth, m_pView->doc()->getUnit() ) );
00136     m_pWidth->setSuffix( m_pView->doc()->getUnitName() );
00137     hLay->addWidget( m_pWidth );
00138 
00139     QWidget *hSpacer = new QWidget( page );
00140     hSpacer->setMinimumSize( spacingHint(), spacingHint() );
00141     hLay->addWidget( hSpacer );
00142 
00143     QWidget *vSpacer = new QWidget( page );
00144     vSpacer->setMinimumSize( spacingHint(), spacingHint() );
00145     vLay->addWidget( vSpacer );
00146 
00147     m_pWidth->setFocus();
00148 
00149     //store the visible value, for later check for changes
00150     columnWidth = KoUnit::fromUserValue( m_pWidth->value(), m_pView->doc()->getUnit() );
00151 }
00152 
00153 void KSpreadResizeColumn::slotOk()
00154 {
00155     m_pView->doc()->emitBeginOperation( false );
00156     double width = KoUnit::fromUserValue( m_pWidth->value(), m_pView->doc()->getUnit() );
00157 
00158     //Don't generate a resize, when there isn't a change or the change is only a rounding issue
00159     if ( fabs( width - columnWidth ) > DBL_EPSILON )
00160     {
00161         QRect selection( m_pView->selection() );
00162 
00163         if ( !m_pView->doc()->undoLocked() )
00164         {
00165             KSpreadUndoResizeColRow *undo = new KSpreadUndoResizeColRow( m_pView->doc(), m_pView->activeSheet(), selection );
00166             m_pView->doc()->addCommand( undo );
00167         }
00168 
00169         for( int i = selection.left(); i <= selection.right(); i++ )
00170             m_pView->hBorderWidget()->resizeColumn( width, i, false );
00171 
00172     }
00173 
00174     m_pView->slotUpdateView( m_pView->activeSheet() );
00175     accept();
00176 }
00177 
00178 void KSpreadResizeColumn::slotDefault()
00179 {
00180     double width = KoUnit::toUserValue( colWidth, m_pView->doc()->getUnit() );
00181     m_pWidth->setValue( width );
00182 }
00183 
00184 
00185 #include "kspread_dlg_resize2.moc"
KDE Logo
This file is part of the documentation for kspread Library Version 1.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Feb 13 09:43:02 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003