kspread

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., 51 Franklin Street, Fifth Floor,
00023  * Boston, MA 02110-1301, USA.
00024 */
00025 
00026 #include <float.h>
00027 
00028 #include <qlabel.h>
00029 #include <qlayout.h>
00030 
00031 #include <knuminput.h>
00032 
00033 #include <KoUnit.h>
00034 #include <KoUnitWidgets.h>
00035 
00036 #include <kspread_canvas.h>
00037 #include <kspread_doc.h>
00038 #include <kspread_global.h>
00039 #include <kspread_locale.h>
00040 #include <kspread_sheet.h>
00041 #include <kspread_undo.h>
00042 #include <kspread_view.h>
00043 #include "manipulator.h"
00044 #include "selection.h"
00045 
00046 #include "kspread_dlg_resize2.h"
00047 
00048 using namespace KSpread;
00049 
00050 ResizeRow::ResizeRow( View* parent, const char* name )
00051     : KDialogBase( parent, name, true, i18n("Resize Row"), Ok|Cancel|Default )
00052 {
00053     m_pView = parent;
00054 
00055     QWidget *page = new QWidget( this );
00056     setMainWidget( page );
00057 
00058     QVBoxLayout *vLay = new QVBoxLayout( page, 0, spacingHint() );
00059     QHBoxLayout *hLay = new QHBoxLayout( vLay );
00060 
00061     QRect selection( m_pView->selectionInfo()->selection() );
00062     RowFormat* rl = m_pView->activeSheet()->rowFormat( selection.top() );
00063     rowHeight = rl->dblHeight();
00064 
00065     QLabel * label1 = new QLabel( page, "label1" );
00066     label1->setText( i18n( "Height:" ) );
00067     hLay->addWidget( label1 );
00068 
00069     m_pHeight = new KoUnitDoubleSpinBox( page );
00070     m_pHeight->setValue( rowHeight );
00071     m_pHeight->setUnit( m_pView->doc()->unit() );
00072 
00073     hLay->addWidget( m_pHeight );
00074 
00075     QWidget *hSpacer = new QWidget( page );
00076     hSpacer->setMinimumSize( spacingHint(), spacingHint() );
00077     hLay->addWidget( hSpacer );
00078 
00079     QWidget *vSpacer = new QWidget( page );
00080     vSpacer->setMinimumSize( spacingHint(), spacingHint() );
00081     vLay->addWidget( vSpacer );
00082 
00083     m_pHeight->setFocus();
00084 
00085     //store the visible value, for later check for changes
00086     rowHeight = m_pHeight->value();
00087 }
00088 
00089 void ResizeRow::slotOk()
00090 {
00091   double height = m_pHeight->value();
00092 
00093   //Don't generate a resize, when there isn't a change or the change is only a rounding issue
00094   if ( fabs( height - rowHeight ) > DBL_EPSILON )
00095   {
00096     ResizeRowManipulator* manipulator = new ResizeRowManipulator();
00097     manipulator->setSheet(m_pView->activeSheet());
00098     manipulator->setSize(height);
00099     // TODO Stefan:
00100     manipulator->setOldSize(rowHeight);
00101     manipulator->add(*m_pView->selectionInfo());
00102     manipulator->execute();
00103   }
00104   accept();
00105 }
00106 
00107 void ResizeRow::slotDefault()
00108 {
00109     m_pHeight->setValue( POINT_TO_MM( heightOfRow ) );
00110 }
00111 
00112 ResizeColumn::ResizeColumn( View* parent, const char* name )
00113     : KDialogBase( parent, name, true, i18n("Resize Column"), Ok|Cancel|Default )
00114 {
00115     m_pView = parent;
00116 
00117     QWidget *page = new QWidget( this );
00118     setMainWidget(page);
00119 
00120     QVBoxLayout *vLay = new QVBoxLayout( page, 0, spacingHint() );
00121     QHBoxLayout *hLay = new QHBoxLayout( vLay );
00122 
00123     QRect selection( m_pView->selectionInfo()->selection() );
00124     ColumnFormat* cl = m_pView->activeSheet()->columnFormat( selection.left() );
00125     columnWidth = cl->dblWidth();
00126 
00127     QLabel * label1 = new QLabel( page, "label1" );
00128     label1->setText( i18n( "Width:" ) );
00129     hLay->addWidget( label1 );
00130 
00131     m_pWidth = new KoUnitDoubleSpinBox( page );
00132     m_pWidth->setValue( columnWidth );
00133     m_pWidth->setUnit( m_pView->doc()->unit() );
00134 
00135     hLay->addWidget( m_pWidth );
00136 
00137     QWidget *hSpacer = new QWidget( page );
00138     hSpacer->setMinimumSize( spacingHint(), spacingHint() );
00139     hLay->addWidget( hSpacer );
00140 
00141     QWidget *vSpacer = new QWidget( page );
00142     vSpacer->setMinimumSize( spacingHint(), spacingHint() );
00143     vLay->addWidget( vSpacer );
00144 
00145     m_pWidth->setFocus();
00146 
00147     //store the visible value, for later check for changes
00148     columnWidth = m_pWidth->value();
00149 }
00150 
00151 void ResizeColumn::slotOk()
00152 {
00153   double width = m_pWidth->value();
00154 
00155   //Don't generate a resize, when there isn't a change or the change is only a rounding issue
00156   if ( fabs( width - columnWidth ) > DBL_EPSILON )
00157   {
00158     ResizeColumnManipulator* manipulator = new ResizeColumnManipulator();
00159     manipulator->setSheet(m_pView->activeSheet());
00160     manipulator->setSize(width);
00161     // TODO Stefan:
00162     manipulator->setOldSize(columnWidth);
00163     manipulator->add(*m_pView->selectionInfo());
00164     manipulator->execute();
00165   }
00166   accept();
00167 }
00168 
00169 void ResizeColumn::slotDefault()
00170 {
00171     m_pWidth->setValue( POINT_TO_MM(colWidth ) );
00172 }
00173 
00174 
00175 #include "kspread_dlg_resize2.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys