kword

KWResizeTableDia.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2002 Montel Laurent <lmontel@mandrakesoft.com>
3 Copyright (C) 2005 Thomas Zander <zander@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include "KWDocument.h"
22#include "KWResizeTableDia.h"
23#include "KWTableFrameSet.h"
24#include "KWCommand.h"
25
26#include <KoUnitWidgets.h>
27#include <tdelocale.h>
28#include <tqlabel.h>
29#include <tqvbox.h>
30
31KWResizeTableDia::KWResizeTableDia( TQWidget *parent, KWTableFrameSet *table, KWDocument *doc, int resizeColumn )
32 : KDialogBase( parent, "resize column dialog" , true, "", Ok | Cancel | User1 | Apply )
33{
34 setButtonText( KDialogBase::User1, i18n("Reset") );
35 setCaption( i18n( "Resize Column" ) );
36
37 m_table = table;
38 m_doc = doc;
39
40 setupTab1(resizeColumn);
41}
42
43void KWResizeTableDia::setupTab1(int resizeColumn) {
44 TQVBox *page = makeVBoxMainWidget();
45 TQLabel *rc = new TQLabel( i18n( "Column:" ), page );
46 rc->resize( rc->sizeHint() );
47 rc->setAlignment( AlignLeft | AlignBottom );
48 m_value = new TQSpinBox( 1, m_table->getColumns(), 1, page );
49 m_value->resize( m_value->sizeHint() );
50 m_value->setValue( resizeColumn );
51
52 rc = new TQLabel( i18n( "Width:" ), page );
53 m_position= new KoUnitDoubleSpinBox( page, 0.01, m_table->anchorFrameset()->isFloating() ? m_table->anchorFrameset()->frame(0)->width(): 9999, 1, 0.0, m_doc->unit(), m_doc->unit() );
54 slotValueChanged( m_value->value());
55 connect( m_value, TQ_SIGNAL( valueChanged ( int )), this, TQ_SLOT( slotValueChanged( int )));
56}
57
58bool KWResizeTableDia::doResize()
59{
60 unsigned int resize= m_value->value() - 1;
61 KWFrame *frm = m_table->cell( 0, resize )->frame(0);
62 if (frm) {
63 FrameIndex index( frm );
64 KoRect newRect( frm->normalize() );
65 newRect.setWidth( m_position->value() );
66 FrameResizeStruct resizeStruct( frm->normalize(), frm->minimumFrameHeight(), newRect );
67 KWFrameResizeCommand * cmd =new KWFrameResizeCommand( i18n("Resize Column"), index, resizeStruct );
68 cmd->execute();
69 m_doc->addCommand( cmd );
70 }
71 return true;
72}
73
74void KWResizeTableDia::slotValueChanged( int pos)
75{
76 KWFrame *frm = m_table->cell( 0, pos-1 )->frame(0);
77 if (frm) {
78 m_position->setValue( KoUnit::toUserValue( TQMAX(0.00, frm->normalize().width()), m_doc->unit() ) );
79 m_resetValue = m_position->value();
80 }
81}
82
83void KWResizeTableDia::slotUser1()
84{
85 m_position->setValue( KoUnit::toUserValue(m_resetValue, m_doc->unit() ) );
86 doResize();
87}
88
89void KWResizeTableDia::slotApply()
90{
91 doResize();
92}
93
94void KWResizeTableDia::slotOk()
95{
96 if (doResize())
97 {
98 KDialogBase::slotOk();
99 }
100}
101
102#include "KWResizeTableDia.moc"
Command created when a frame is resized (or "moved and resized" as for KWPartFrameSet)
Definition KWCommand.h:228
bool isFloating() const
Return true if this frameset is floating (inline), false if it's fixed.
Definition KWFrameSet.h:372
KWTextFrameSet * anchorFrameset() const
Return the frameset in which our anchor is - assuming isFloating()
Definition KWFrameSet.h:374
KWFrame * frame(unsigned int _num) const
get a frame by number
This class represents a single frame.
Definition KWFrame.h:68
double minimumFrameHeight(void) const
Definition KWFrame.h:284
KWResizeTableDia(TQWidget *parent, KWTableFrameSet *table, KWDocument *doc, int resizeColumn)
Constructor.
This class implements tables by acting as the manager for the frame(set)s which make up the table cel...
unsigned int getColumns() const
returns the number of columns
Identifies a frame.
Definition KWCommand.h:98