kword

KWResizeTableDia.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C)  2002 Montel Laurent <lmontel@mandrakesoft.com>
00003    Copyright (C)  2005 Thomas Zander <zander@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "KWDocument.h"
00022 #include "KWResizeTableDia.h"
00023 #include "KWTableFrameSet.h"
00024 #include "KWCommand.h"
00025 
00026 #include <KoUnitWidgets.h>
00027 #include <klocale.h>
00028 #include <qlabel.h>
00029 #include <qvbox.h>
00030 
00031 KWResizeTableDia::KWResizeTableDia( QWidget *parent, KWTableFrameSet *table, KWDocument *doc, int resizeColumn )
00032     : KDialogBase( parent, "resize column dialog" , true, "", Ok | Cancel | User1 | Apply )
00033 {
00034     setButtonText( KDialogBase::User1, i18n("Reset") );
00035     setCaption( i18n( "Resize Column" ) );
00036 
00037     m_table = table;
00038     m_doc = doc;
00039 
00040     setupTab1(resizeColumn);
00041 }
00042 
00043 void KWResizeTableDia::setupTab1(int resizeColumn) {
00044     QVBox *page = makeVBoxMainWidget();
00045     QLabel *rc = new QLabel( i18n( "Column:" ), page );
00046     rc->resize( rc->sizeHint() );
00047     rc->setAlignment( AlignLeft | AlignBottom );
00048     m_value = new QSpinBox( 1, m_table->getColumns(), 1, page );
00049     m_value->resize( m_value->sizeHint() );
00050     m_value->setValue( resizeColumn );
00051 
00052     rc = new QLabel( i18n( "Width:" ), page );
00053     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() );
00054     slotValueChanged( m_value->value());
00055     connect( m_value, SIGNAL( valueChanged ( int )), this, SLOT( slotValueChanged( int )));
00056 }
00057 
00058 bool KWResizeTableDia::doResize()
00059 {
00060     unsigned int resize= m_value->value() - 1;
00061     KWFrame *frm = m_table->cell( 0, resize )->frame(0);
00062     if (frm) {
00063         FrameIndex index( frm );
00064         KoRect newRect( frm->normalize() );
00065         newRect.setWidth( m_position->value() );
00066         FrameResizeStruct resizeStruct( frm->normalize(), frm->minimumFrameHeight(), newRect );
00067         KWFrameResizeCommand * cmd =new KWFrameResizeCommand( i18n("Resize Column"), index, resizeStruct );
00068         cmd->execute();
00069         m_doc->addCommand( cmd );
00070     }
00071     return true;
00072 }
00073 
00074 void KWResizeTableDia::slotValueChanged( int pos)
00075 {
00076     KWFrame *frm = m_table->cell( 0, pos-1 )->frame(0);
00077     if (frm) {
00078         m_position->setValue( KoUnit::toUserValue( QMAX(0.00, frm->normalize().width()), m_doc->unit() ) );
00079         m_resetValue = m_position->value();
00080     }
00081 }
00082 
00083 void KWResizeTableDia::slotUser1()
00084 {
00085     m_position->setValue( KoUnit::toUserValue(m_resetValue, m_doc->unit() ) );
00086     doResize();
00087 }
00088 
00089 void KWResizeTableDia::slotApply()
00090 {
00091     doResize();
00092 }
00093 
00094 void KWResizeTableDia::slotOk()
00095 {
00096    if (doResize())
00097    {
00098       KDialogBase::slotOk();
00099    }
00100 }
00101 
00102 #include "KWResizeTableDia.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys