File indexing completed on 2024-05-12 16:35:25

0001 /* This file is part of the KDE project
0002    Copyright (C) 2002-2004 Ariya Hidayat <ariya@kde.org>
0003              (C) 2003 Norbert Andres <nandres@web.de>
0004              (C) 2001-2003 Philipp Mueller <philipp.mueller@gmx.de>
0005              (C) 1999-2002 Laurent Montel <montel@kde.org>
0006              (C) 2002 John Dailey <dailey@vt.edu>
0007              (C) 2000 David Faure <faure@kde.org>
0008              (C) 1998-1999 Torben Weis <weis@kde.org>
0009 
0010    This library is free software; you can redistribute it and/or
0011    modify it under the terms of the GNU Library General Public
0012    License as published by the Free Software Foundation; either
0013    version 2 of the License, or (at your option) any later version.
0014 
0015    This library is distributed in the hope that it will be useful,
0016    but WITHOUT ANY WARRANTY; without even the implied warranty of
0017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0018    Library General Public License for more details.
0019 
0020    You should have received a copy of the GNU Library General Public License
0021    along with this library; see the file COPYING.LIB.  If not, write to
0022    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0023    Boston, MA 02110-1301, USA.
0024 */
0025 
0026 // Local
0027 #include "Resize2Dialog.h"
0028 
0029 #include <float.h>
0030 
0031 // Qt
0032 #include <QGridLayout>
0033 #include <QLabel>
0034 
0035 // Calligra
0036 #include <KoCanvasBase.h>
0037 #include <KoUnit.h>
0038 #include <KoUnitDoubleSpinBox.h>
0039 
0040 // Sheets
0041 #include <Global.h>
0042 #include <Localization.h>
0043 #include "Map.h"
0044 #include "RowColumnFormat.h"
0045 #include "RowFormatStorage.h"
0046 #include "ui/Selection.h"
0047 #include <Sheet.h>
0048 
0049 // commands
0050 #include "commands/RowColumnManipulators.h"
0051 
0052 using namespace Calligra::Sheets;
0053 
0054 ResizeRow::ResizeRow(QWidget* parent, Selection* selection)
0055         : KoDialog(parent)
0056 {
0057     setCaption(i18n("Resize Row"));
0058     setModal(true);
0059     setButtons(Ok | Cancel | Default);
0060     m_selection = selection;
0061 
0062     rowHeight = m_selection->activeSheet()->rowFormats()->rowHeight(m_selection->lastRange().top());
0063 
0064     QWidget *page = new QWidget();
0065     setMainWidget(page);
0066 
0067     QGridLayout* gridLayout = new QGridLayout(page);
0068     gridLayout->setColumnStretch(1, 1);
0069 
0070     QLabel * label1 = new QLabel(page);
0071     label1->setText(i18n("Height:"));
0072     gridLayout->addWidget(label1, 0, 0);
0073 
0074     m_pHeight = new KoUnitDoubleSpinBox(page);
0075     m_pHeight->setValue(rowHeight);
0076     m_pHeight->setUnit(m_selection->canvas()->unit());
0077     gridLayout->addWidget(m_pHeight, 0, 1);
0078 
0079     m_pHeight->setFocus();
0080 
0081     //store the visible value, for later check for changes
0082     rowHeight = m_pHeight->value();
0083     connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
0084     connect(this, SIGNAL(defaultClicked()), this, SLOT(slotDefault()));
0085 }
0086 
0087 void ResizeRow::slotOk()
0088 {
0089     double height = m_pHeight->value();
0090 
0091     //Don't generate a resize, when there isn't a change or the change is only a rounding issue
0092     if (fabs(height - rowHeight) > DBL_EPSILON) {
0093         ResizeRowManipulator* manipulator = new ResizeRowManipulator();
0094         manipulator->setSheet(m_selection->activeSheet());
0095         manipulator->setSize(height);
0096         manipulator->add(*m_selection);
0097         manipulator->execute(m_selection->canvas());
0098     }
0099     accept();
0100 }
0101 
0102 void ResizeRow::slotDefault()
0103 {
0104     Sheet* sheet = m_selection->activeSheet();
0105     if (!sheet)
0106         return;
0107     double points = sheet->map()->defaultRowFormat()->height();
0108     m_pHeight->setValue(m_selection->canvas()->unit().toUserValue(points));
0109 }
0110 
0111 ResizeColumn::ResizeColumn(QWidget* parent, Selection* selection)
0112         : KoDialog(parent)
0113 {
0114     setCaption(i18n("Resize Column"));
0115     setModal(true);
0116     setButtons(Ok | Cancel | Default);
0117     m_selection = selection;
0118 
0119     const ColumnFormat* cl = m_selection->activeSheet()->columnFormat(selection->lastRange().left());
0120     columnWidth = cl->width();
0121 
0122     QWidget *page = new QWidget();
0123     setMainWidget(page);
0124 
0125     QGridLayout* gridLayout = new QGridLayout(page);
0126     gridLayout->setColumnStretch(1, 1);
0127 
0128     QLabel * label1 = new QLabel(page);
0129     label1->setText(i18n("Width:"));
0130     gridLayout->addWidget(label1, 0, 0);
0131 
0132     m_pWidth = new KoUnitDoubleSpinBox(page);
0133     m_pWidth->setValue(columnWidth);
0134     m_pWidth->setUnit(m_selection->canvas()->unit());
0135     gridLayout->addWidget(m_pWidth, 0, 1);
0136 
0137     m_pWidth->setFocus();
0138 
0139     //store the visible value, for later check for changes
0140     columnWidth = m_pWidth->value();
0141     connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
0142     connect(this, SIGNAL(defaultClicked()), this, SLOT(slotDefault()));
0143 
0144 }
0145 
0146 void ResizeColumn::slotOk()
0147 {
0148     double width = m_pWidth->value();
0149 
0150     //Don't generate a resize, when there isn't a change or the change is only a rounding issue
0151     if (fabs(width - columnWidth) > DBL_EPSILON) {
0152         ResizeColumnManipulator* manipulator = new ResizeColumnManipulator();
0153         manipulator->setSheet(m_selection->activeSheet());
0154         manipulator->setSize(width);
0155         manipulator->add(*m_selection);
0156         manipulator->execute(m_selection->canvas());
0157     }
0158     accept();
0159 }
0160 
0161 void ResizeColumn::slotDefault()
0162 {
0163     Sheet* sheet = m_selection->activeSheet();
0164     if (!sheet)
0165         return;
0166     double points = sheet->map()->defaultColumnFormat()->width();
0167     m_pWidth->setValue(m_selection->canvas()->unit().toUserValue(points));
0168 }