summaryrefslogtreecommitdiffstats
path: root/kword/KWSplitCellDia.cpp
blob: c753f4df734b42fd70fdac86d14c37a1020eae95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* This file is part of the KDE project
   Copyright (C) 2001 Thomas Zander <zander@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#include "KWSplitCellDia.h"
#include "KWSplitCellDia.moc"
#include "KWTableDia.h"

#include <tqlayout.h>
#include <tqlabel.h>
#include <tqspinbox.h>

#include <klocale.h>

KWSplitCellDia::KWSplitCellDia( TQWidget* tqparent, const char* name, unsigned int columns, unsigned int rows)
    : KDialogBase( Plain, i18n("Split Cell"), Ok | Cancel, Ok, tqparent, name, true)
{
    m_cols = columns;
    m_rows = rows;

    setInitialSize( TQSize(400, 300) );

    TQWidget *page = plainPage();
    TQGridLayout *grid = new TQGridLayout( page, 4, 2, KDialog::marginHint(), KDialog::spacingHint() );

    TQLabel *lRows = new TQLabel( i18n( "Number of rows:" ), page );
    grid->addWidget( lRows, 0, 0 );

    nRows = new TQSpinBox( 1, 128, 1, page );
    nRows->setValue( m_rows );
    grid->addWidget( nRows, 1, 0 );

    TQLabel *lCols = new TQLabel( i18n( "Number of columns:" ), page );
    grid->addWidget( lCols, 2, 0 );

    nCols = new TQSpinBox( 1, 128, 1, page );
    nCols->setValue( m_cols );
    grid->addWidget( nCols, 3, 0 );

    preview = new KWTablePreview( page, m_rows, m_cols );
    preview->setBackgroundColor( white );
    grid->addMultiCellWidget( preview, 0, 4, 1, 1 );

    grid->addRowSpacing( 0, lRows->height() );
    grid->addRowSpacing( 1, nRows->height() );
    grid->addRowSpacing( 2, lCols->height() );
    grid->addRowSpacing( 3, nCols->height() );
    grid->addRowSpacing( 4, 150 - ( lRows->height() + nRows->height() + lCols->height() + nCols->height() ) );
    grid->setRowStretch( 0, 0 );
    grid->setRowStretch( 1, 0 );
    grid->setRowStretch( 2, 0 );
    grid->setRowStretch( 3, 0 );
    grid->setRowStretch( 4, 1 );

    grid->addColSpacing( 0, lRows->width() );
    grid->addColSpacing( 0, nRows->width() );
    grid->addColSpacing( 0, lCols->width() );
    grid->addColSpacing( 0, nCols->width() );
    grid->addColSpacing( 1, 150 );
    grid->setColStretch( 0, 0 );
    grid->setColStretch( 1, 1 );

    grid->activate();
    enableButtonOK( !(m_rows==1 && m_cols==1) );

    connect( nRows, TQT_SIGNAL( valueChanged( int ) ), this, TQT_SLOT( rowsChanged( int ) ) );
    connect( nCols, TQT_SIGNAL( valueChanged( int ) ), this, TQT_SLOT( colsChanged( int ) ) );
    setFocus();
}

void KWSplitCellDia::rowsChanged( int rows ) {
    m_rows=rows;
    preview->setRows( m_rows );
    enableButtonOK( !(m_rows==1 && m_cols==1) );
}

void KWSplitCellDia::colsChanged( int cols ) {
    m_cols=cols;
    preview->setCols( m_cols );
    enableButtonOK( !(m_rows==1 && m_cols==1) );
}