kspread

kspread_dlg_resize2.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002-2004 Ariya Hidayat <ariya@kde.org>
3 (C) 2003 Norbert Andres <nandres@web.de>
4 (C) 2001-2003 Philipp Mueller <philipp.mueller@gmx.de>
5 (C) 1999-2002 Laurent Montel <montel@kde.org>
6 (C) 2002 John Dailey <dailey@vt.edu>
7 (C) 2000 David Faure <faure@kde.org>
8 (C) 1998-1999 Torben Weis <weis@kde.org>
9
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Library General Public
12 License as published by the Free Software Foundation; either
13 version 2 of the License, or (at your option) any later version.
14
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Library General Public License for more details.
19
20 You should have received a copy of the GNU Library General Public License
21 along with this library; see the file COPYING.LIB. If not, write to
22 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
24*/
25
26#include <float.h>
27
28#include <tqlabel.h>
29#include <tqlayout.h>
30
31#include <knuminput.h>
32
33#include <KoUnit.h>
34#include <KoUnitWidgets.h>
35
36#include <kspread_canvas.h>
37#include <kspread_doc.h>
38#include <kspread_global.h>
39#include <kspread_locale.h>
40#include <kspread_sheet.h>
41#include <kspread_undo.h>
42#include <kspread_view.h>
43#include "manipulator.h"
44#include "selection.h"
45
46#include "kspread_dlg_resize2.h"
47
48using namespace KSpread;
49
50ResizeRow::ResizeRow( View* parent, const char* name )
51 : KDialogBase( parent, name, true, i18n("Resize Row"), Ok|Cancel|Default )
52{
53 m_pView = parent;
54
55 TQWidget *page = new TQWidget( this );
56 setMainWidget( page );
57
58 TQVBoxLayout *vLay = new TQVBoxLayout( page, 0, spacingHint() );
59 TQHBoxLayout *hLay = new TQHBoxLayout( vLay );
60
61 TQRect selection( m_pView->selectionInfo()->selection() );
62 RowFormat* rl = m_pView->activeSheet()->rowFormat( selection.top() );
63 rowHeight = rl->dblHeight();
64
65 TQLabel * label1 = new TQLabel( page, "label1" );
66 label1->setText( i18n( "Height:" ) );
67 hLay->addWidget( label1 );
68
69 m_pHeight = new KoUnitDoubleSpinBox( page );
70 m_pHeight->setValue( rowHeight );
71 m_pHeight->setUnit( m_pView->doc()->unit() );
72
73 hLay->addWidget( m_pHeight );
74
75 TQWidget *hSpacer = new TQWidget( page );
76 hSpacer->setMinimumSize( spacingHint(), spacingHint() );
77 hLay->addWidget( hSpacer );
78
79 TQWidget *vSpacer = new TQWidget( page );
80 vSpacer->setMinimumSize( spacingHint(), spacingHint() );
81 vLay->addWidget( vSpacer );
82
83 m_pHeight->setFocus();
84
85 //store the visible value, for later check for changes
86 rowHeight = m_pHeight->value();
87}
88
89void ResizeRow::slotOk()
90{
91 double height = m_pHeight->value();
92
93 //Don't generate a resize, when there isn't a change or the change is only a rounding issue
94 if ( fabs( height - rowHeight ) > DBL_EPSILON )
95 {
96 ResizeRowManipulator* manipulator = new ResizeRowManipulator();
97 manipulator->setSheet(m_pView->activeSheet());
98 manipulator->setSize(height);
99 // TODO Stefan:
100 manipulator->setOldSize(rowHeight);
101 manipulator->add(*m_pView->selectionInfo());
102 manipulator->execute();
103 }
104 accept();
105}
106
107void ResizeRow::slotDefault()
108{
109 Sheet* sheet = m_pView->activeSheet();
110 if (!sheet)
111 return;
112 double points = sheet->rowFormat(0)->dblHeight();
113 m_pHeight->setValue(KoUnit::toUserValue(points, m_pView->doc()->unit()));
114}
115
116ResizeColumn::ResizeColumn( View* parent, const char* name )
117 : KDialogBase( parent, name, true, i18n("Resize Column"), Ok|Cancel|Default )
118{
119 m_pView = parent;
120
121 TQWidget *page = new TQWidget( this );
122 setMainWidget(page);
123
124 TQVBoxLayout *vLay = new TQVBoxLayout( page, 0, spacingHint() );
125 TQHBoxLayout *hLay = new TQHBoxLayout( vLay );
126
127 TQRect selection( m_pView->selectionInfo()->selection() );
128 ColumnFormat* cl = m_pView->activeSheet()->columnFormat( selection.left() );
129 columnWidth = cl->dblWidth();
130
131 TQLabel * label1 = new TQLabel( page, "label1" );
132 label1->setText( i18n( "Width:" ) );
133 hLay->addWidget( label1 );
134
135 m_pWidth = new KoUnitDoubleSpinBox( page );
136 m_pWidth->setValue( columnWidth );
137 m_pWidth->setUnit( m_pView->doc()->unit() );
138
139 hLay->addWidget( m_pWidth );
140
141 TQWidget *hSpacer = new TQWidget( page );
142 hSpacer->setMinimumSize( spacingHint(), spacingHint() );
143 hLay->addWidget( hSpacer );
144
145 TQWidget *vSpacer = new TQWidget( page );
146 vSpacer->setMinimumSize( spacingHint(), spacingHint() );
147 vLay->addWidget( vSpacer );
148
149 m_pWidth->setFocus();
150
151 //store the visible value, for later check for changes
152 columnWidth = m_pWidth->value();
153}
154
155void ResizeColumn::slotOk()
156{
157 double width = m_pWidth->value();
158
159 //Don't generate a resize, when there isn't a change or the change is only a rounding issue
160 if ( fabs( width - columnWidth ) > DBL_EPSILON )
161 {
162 ResizeColumnManipulator* manipulator = new ResizeColumnManipulator();
163 manipulator->setSheet(m_pView->activeSheet());
164 manipulator->setSize(width);
165 // TODO Stefan:
166 manipulator->setOldSize(columnWidth);
167 manipulator->add(*m_pView->selectionInfo());
168 manipulator->execute();
169 }
170 accept();
171}
172
173void ResizeColumn::slotDefault()
174{
175 Sheet* sheet = m_pView->activeSheet();
176 if (!sheet)
177 return;
178 double points = sheet->columnFormat(0)->dblWidth();
179 m_pWidth->setValue(KoUnit::toUserValue(points, m_pView->doc()->unit()));
180}
181
182
183#include "kspread_dlg_resize2.moc"
Element * add(const TQPoint &point, Sheet *sheet=0)
Adds the point point to this region.
Definition region.cpp:245
The View class displays a KSpread document.
The KSpread namespace.
Definition commands.h:39