~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to kword/tabledia.cc

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
   Boston, MA 02111-1307, USA.
18
18
*/
19
19
 
20
 
#include "kwdoc.h"
21
20
#include "kwcanvas.h"
22
21
#include "tabledia.h"
23
22
#include "tabledia.moc"
24
23
 
25
 
#include <qwidget.h>
26
 
#include <qlayout.h>
 
24
#include "kwtabletemplateselector.h"
 
25
#include "kwcommand.h"
 
26
#include "kwdoc.h"
 
27
#include "kwtableframeset.h"
 
28
#include "kwtabletemplate.h"
 
29
#include <kcommand.h>
 
30
 
27
31
#include <qlabel.h>
28
 
#include <qstring.h>
29
 
#include <qevent.h>
30
32
#include <qspinbox.h>
31
 
#include <qpen.h>
32
 
#include <qcolor.h>
33
 
#include <qpainter.h>
34
33
#include <qcheckbox.h>
35
34
#include <qbuttongroup.h>
36
 
#include <qlistbox.h>
37
35
#include <qcombobox.h>
38
36
 
39
 
#include <kapp.h>
40
 
#include <kcolorbtn.h>
41
 
#include <kbuttonbox.h>
42
37
#include <klocale.h>
43
38
 
44
39
#include <stdlib.h>
71
66
/* Class: KWTableDia                                              */
72
67
/******************************************************************/
73
68
 
74
 
KWTableDia::KWTableDia( QWidget* parent, const char* name, KWCanvas *_canvas, KWDocument *_doc,
75
 
                        int rows, int cols, CellSize wid, CellSize hei, bool floating )
 
69
KWTableDia::KWTableDia( QWidget* parent, const char* name, UseMode _useMode, KWCanvas *_canvas, KWDocument *_doc,
 
70
                        int rows, int cols, CellSize wid, CellSize hei, bool floating , const QString & _templateName, int format)
76
71
    : KDialogBase( Tabbed, i18n("Table Settings"), Ok | Cancel, Ok, parent, name, true)
77
72
{
 
73
    m_useMode = _useMode;
78
74
    canvas = _canvas;
79
75
    doc = _doc;
80
76
 
81
77
    setupTab1( rows, cols, wid, hei, floating );
82
 
    //setupTab2();
83
 
 
84
 
    setInitialSize( QSize(500, 400) );
 
78
    setupTab2( _templateName,format );
 
79
 
 
80
    setInitialSize( QSize(500, 480) );
 
81
 
 
82
    oldRowCount = rows;
 
83
    oldColCount = cols;
 
84
    oldTemplateName = _templateName;
 
85
    if ( m_useMode==NEW )
 
86
    {
 
87
        slotInlineTable( cbIsFloating->isChecked());
 
88
    }
85
89
}
86
90
 
87
91
void KWTableDia::setupTab1( int rows, int cols, CellSize wid, CellSize hei, bool floating )
90
94
 
91
95
    QGridLayout *grid = new QGridLayout( tab1, 9, 2, KDialog::marginHint(), KDialog::spacingHint() );
92
96
 
93
 
    lRows = new QLabel( i18n( "Number of Rows:" ), tab1 );
 
97
    lRows = new QLabel( i18n( "Number of rows:" ), tab1 );
94
98
    grid->addWidget( lRows, 0, 0 );
95
99
 
96
100
    nRows = new QSpinBox( 1, 128, 1, tab1 );
97
101
    nRows->setValue( rows );
98
102
    grid->addWidget( nRows, 1, 0 );
99
103
 
100
 
    lCols = new QLabel( i18n( "Number of Columns:" ), tab1 );
 
104
    lCols = new QLabel( i18n( "Number of columns:" ), tab1 );
101
105
    grid->addWidget( lCols, 2, 0 );
102
106
 
103
107
    nCols = new QSpinBox( 1, 128, 1, tab1 );
104
108
    nCols->setValue( cols );
105
109
    grid->addWidget( nCols, 3, 0 );
106
110
 
107
 
    lHei = new QLabel( i18n( "Cell Heights:" ), tab1 );
108
 
    grid->addWidget( lHei, 4, 0 );
109
 
 
110
 
    cHei = new QComboBox( FALSE, tab1 );
111
 
    cHei->insertItem( i18n( "Automatic" ) );
112
 
    cHei->insertItem( i18n( "Manual" ) );
113
 
    cHei->setCurrentItem( (int)hei );
114
 
    grid->addWidget( cHei, 5, 0 );
115
 
 
116
 
    lWid = new QLabel( i18n( "Cell Widths:" ), tab1 );
117
 
    grid->addWidget( lWid, 6, 0 );
118
 
 
119
 
    cWid = new QComboBox( FALSE, tab1 );
120
 
    cWid->insertItem( i18n( "Automatic" ) );
121
 
    cWid->insertItem( i18n( "Manual" ) );
122
 
    cWid->setCurrentItem( (int)wid );
123
 
    grid->addWidget( cWid, 7, 0 );
 
111
    if ( m_useMode==NEW )
 
112
    {
 
113
        lHei = new QLabel( i18n( "Cell heights:" ), tab1 );
 
114
        grid->addWidget( lHei, 4, 0 );
 
115
 
 
116
        cHei = new QComboBox( FALSE, tab1 );
 
117
        cHei->insertItem( i18n( "Automatic" ) );
 
118
        cHei->insertItem( i18n( "Manual" ) );
 
119
        cHei->setCurrentItem( (int)hei );
 
120
        grid->addWidget( cHei, 5, 0 );
 
121
 
 
122
        lWid = new QLabel( i18n( "Cell widths:" ), tab1 );
 
123
        grid->addWidget( lWid, 6, 0 );
 
124
 
 
125
        cWid = new QComboBox( FALSE, tab1 );
 
126
        cWid->insertItem( i18n( "Automatic" ) );
 
127
        cWid->insertItem( i18n( "Manual" ) );
 
128
        cWid->setCurrentItem( (int)wid );
 
129
        grid->addWidget( cWid, 7, 0 );
 
130
    }
124
131
 
125
132
    preview = new KWTablePreview( tab1, rows, cols );
126
133
    preview->setBackgroundColor( white );
127
134
    grid->addMultiCellWidget( preview, 0, 8, 1, 1 );
128
135
 
129
 
    // Checkbox for floating/fixed location. The default is floating (aka inline).
130
 
    cbIsFloating = new QCheckBox( i18n( "The table is inline" ), tab1 );
131
 
    //cbIsFloating->setEnabled(false);
132
 
    cbIsFloating->setChecked( floating );
133
 
 
134
 
    grid->addMultiCellWidget( cbIsFloating, 9, 9, 0, 2 );
 
136
    if ( m_useMode==NEW )
 
137
    {
 
138
        // Checkbox for floating/fixed location. The default is floating (aka inline).
 
139
        cbIsFloating = new QCheckBox( i18n( "The table is &inline" ), tab1 );
 
140
        //cbIsFloating->setEnabled(false);
 
141
        cbIsFloating->setChecked( floating );
 
142
 
 
143
        grid->addMultiCellWidget( cbIsFloating, 9, 9, 0, 2 );
 
144
        connect( cbIsFloating, SIGNAL( toggled ( bool )  ), this, SLOT( slotInlineTable( bool ) ) );
 
145
    }
 
146
    else
 
147
    if (m_useMode==EDIT)
 
148
    {
 
149
        cbReapplyTemplate1 = new QCheckBox( i18n("Reapply template to table"), tab1 );
 
150
        grid->addMultiCellWidget( cbReapplyTemplate1, 9, 9, 0, 2);
 
151
 
 
152
        connect( cbReapplyTemplate1, SIGNAL( toggled ( bool )  ), this, SLOT( slotSetReapply( bool ) ) );
 
153
    }
135
154
 
136
155
    grid->addRowSpacing( 0, lRows->height() );
137
156
    grid->addRowSpacing( 1, nRows->height() );
138
157
    grid->addRowSpacing( 2, lCols->height() );
139
158
    grid->addRowSpacing( 3, nCols->height() );
140
 
    grid->addRowSpacing( 4, lHei->height() );
141
 
    grid->addRowSpacing( 5, cHei->height() );
142
 
    grid->addRowSpacing( 6, lWid->height() );
143
 
    grid->addRowSpacing( 7, cWid->height() );
 
159
    if ( m_useMode==NEW )
 
160
    {
 
161
        grid->addRowSpacing( 4, lHei->height() );
 
162
        grid->addRowSpacing( 5, cHei->height() );
 
163
        grid->addRowSpacing( 6, lWid->height() );
 
164
        grid->addRowSpacing( 7, cWid->height() );
 
165
    }
144
166
    grid->addRowSpacing( 8, 150 - ( lRows->height() + nRows->height() + lCols->height() + nCols->height() ) );
145
 
    grid->addRowSpacing( 9, cbIsFloating->height() );
 
167
    if ( m_useMode==NEW )
 
168
        grid->addRowSpacing( 9, cbIsFloating->height() );
146
169
    grid->setRowStretch( 0, 0 );
147
170
    grid->setRowStretch( 1, 0 );
148
171
    grid->setRowStretch( 2, 0 );
158
181
    grid->addColSpacing( 0, nRows->width() );
159
182
    grid->addColSpacing( 0, lCols->width() );
160
183
    grid->addColSpacing( 0, nCols->width() );
161
 
    grid->addColSpacing( 0, lHei->width() );
162
 
    grid->addColSpacing( 0, cHei->width() );
163
 
    grid->addColSpacing( 0, lWid->width() );
164
 
    grid->addColSpacing( 0, cWid->width() );
 
184
    if ( m_useMode==NEW )
 
185
    {
 
186
        grid->addColSpacing( 0, lHei->width() );
 
187
        grid->addColSpacing( 0, cHei->width() );
 
188
        grid->addColSpacing( 0, lWid->width() );
 
189
        grid->addColSpacing( 0, cWid->width() );
 
190
    }
165
191
    grid->addColSpacing( 1, 150 );
166
192
    grid->setColStretch( 0, 0 );
167
193
    grid->setColStretch( 1, 1 );
172
198
    connect( nCols, SIGNAL( valueChanged( int ) ), this, SLOT( colsChanged( int ) ) );
173
199
}
174
200
 
175
 
void KWTableDia::setupTab2()
 
201
void KWTableDia::setupTab2(const QString & _templateName, int format )
176
202
{
177
 
    readTableStyles();
178
 
 
179
 
    tab2 = addPage( i18n("Properties"));
180
 
    QGridLayout *grid = new QGridLayout( tab2, 4, 3, KDialog::marginHint(), KDialog::spacingHint() );
181
 
 
182
 
    lStyles = new QLabel( i18n( "Styles" ), tab2 );
183
 
    grid->addWidget( lStyles, 0, 0 );
184
 
 
185
 
    lbStyles = new QListBox( tab2 );
186
 
    grid->addWidget( lbStyles, 1, 0 );
187
 
 
188
 
    preview2 = new QWidget( tab2 );
189
 
    preview2->setBackgroundColor( white );
190
 
    grid->addMultiCellWidget( preview2, 1, 1, 1, 2 );
191
 
 
192
 
    bgHeader = new QButtonGroup( i18n( "Apply for Header" ), tab2 );
193
 
    grid->addWidget( bgHeader, 2, 0 );
194
 
 
195
 
    bgFirstCol = new QButtonGroup( i18n( "Apply for First Column" ), tab2 );
196
 
    grid->addWidget( bgFirstCol, 2, 1 );
197
 
 
198
 
    bgBody = new QButtonGroup( i18n( "Apply for Body" ), tab2 );
199
 
    grid->addWidget( bgBody, 2, 2 );
200
 
 
201
 
    cbHeaderOnAllPages = new QCheckBox( i18n( "When a table flows over multiple pages, "
202
 
                                              "copy header to the top of each page." ), tab2 );
203
 
    grid->addMultiCellWidget( cbHeaderOnAllPages, 3, 3, 0, 2 );
204
 
 
205
 
    grid->addRowSpacing( 0, lStyles->height() );
206
 
    grid->addRowSpacing( 1, lbStyles->height() );
207
 
    grid->addRowSpacing( 1, 200 );
208
 
    grid->addRowSpacing( 2, bgHeader->height() );
209
 
    grid->addRowSpacing( 2, bgFirstCol->height() );
210
 
    grid->addRowSpacing( 2, bgBody->height() );
211
 
    grid->addRowSpacing( 3, cbHeaderOnAllPages->height() );
212
 
    grid->setRowStretch( 0, 0 );
213
 
    grid->setRowStretch( 1, 1 );
214
 
    grid->setRowStretch( 2, 0 );
215
 
    grid->setRowStretch( 3, 0 );
216
 
 
217
 
    grid->addColSpacing( 0, lStyles->width() );
218
 
    grid->addColSpacing( 0, lbStyles->width() );
219
 
    grid->addColSpacing( 0, bgHeader->width() );
220
 
    grid->addColSpacing( 1, 100 );
221
 
    grid->addColSpacing( 1, bgFirstCol->width() );
222
 
    grid->addColSpacing( 2, 100 );
223
 
    grid->addColSpacing( 2, bgBody->width() );
224
 
    grid->setColStretch( 0, 1 );
225
 
    grid->setColStretch( 1, 1 );
226
 
    grid->setColStretch( 2, 1 );
227
 
 
 
203
    QWidget *tab2 = addPage( i18n("Templates"));
 
204
 
 
205
    QGridLayout *grid = new QGridLayout( tab2, 2, 1, KDialog::marginHint(), KDialog::spacingHint() );
 
206
 
 
207
    tableTemplateSelector = new KWTableTemplateSelector( doc, tab2, _templateName,format );
 
208
    grid->addWidget(tableTemplateSelector, 0, 0);
 
209
 
 
210
    if (m_useMode==EDIT)
 
211
    {
 
212
        cbReapplyTemplate2 = new QCheckBox( i18n("Reapply template to table"), tab2 );
 
213
        grid->addWidget( cbReapplyTemplate2, 1, 0);
 
214
 
 
215
        grid->setRowStretch( 0, 1);
 
216
        grid->setRowStretch( 1, 0);
 
217
 
 
218
        connect( cbReapplyTemplate2, SIGNAL( toggled ( bool )  ), this, SLOT( slotSetReapply( bool ) ) );
 
219
    }
228
220
    grid->activate();
229
221
}
230
222
 
231
 
void KWTableDia::readTableStyles()
232
 
{
233
 
#ifdef __GNUC__
234
 
#warning TODO
235
 
#endif
236
 
}
237
 
 
238
223
void KWTableDia::slotOk()
239
224
{
240
 
    canvas->createTable( nRows->value(), nCols->value(),
241
 
                         cWid->currentItem(),
242
 
                         cHei->currentItem(),
243
 
                         cbIsFloating->isChecked() );
 
225
    if ( m_useMode==NEW )
 
226
        /// ###### This should be done AFTER this dialog is closed.
 
227
        // Otherwise we have two modal dialogs fighting each other
 
228
        canvas->createTable( nRows->value(), nCols->value(),
 
229
                             cWid->currentItem(),
 
230
                             cHei->currentItem(),
 
231
                             cbIsFloating->isChecked(),
 
232
                             tableTemplateSelector->getTableTemplate(),
 
233
                             tableTemplateSelector->getFormatType());
 
234
    else
 
235
    {
 
236
        KWTableFrameSet *table = canvas->getCurrentTable();
 
237
        if ( table )
 
238
        {
 
239
            KMacroCommand *macroCmd = 0L;
 
240
            KCommand *cmd = 0L;
 
241
 
 
242
            // Add or delete rows
 
243
            int rowsDiff = nRows->value()-oldRowCount;
 
244
            if ( rowsDiff!=0 )
 
245
            {
 
246
                macroCmd = new KMacroCommand( (rowsDiff>0 ) ? i18n("Add New Rows to Table") : i18n("Remove Rows From Table") );
 
247
                for ( int i = 0 ; i < abs( rowsDiff ) ; i++ )
 
248
                {
 
249
                    if ( rowsDiff < 0 )
 
250
                        cmd = new KWRemoveRowCommand( i18n("Remove Row"), table, oldRowCount-i-1 );
 
251
                    else
 
252
                    {
 
253
                        cmd = new KWInsertRowCommand( i18n("Insert Row"), table, oldRowCount+i );
 
254
                    }
 
255
 
 
256
                    if (cmd)
 
257
                        macroCmd->addCommand( cmd );
 
258
                }
 
259
                canvas->setTableRows( nRows->value() );
 
260
            }
 
261
 
 
262
            // Add or delete cols
 
263
            int colsDiff = nCols->value()-oldColCount;
 
264
            if ( colsDiff!=0 )
 
265
            {
 
266
                double maxRightOffset;
 
267
                if (table->isFloating())
 
268
                    // inline table: max offset of containing frame
 
269
                    maxRightOffset = table->anchorFrameset()->frame(0)->right();
 
270
                else
 
271
                    // non inline table: max offset of the page
 
272
                    maxRightOffset = doc->ptPaperWidth() - doc->ptRightBorder();
 
273
                if ( !macroCmd )
 
274
                    macroCmd = new KMacroCommand( (colsDiff>0 ) ? i18n("Add New Columns to Table") : i18n("Remove Columns From Table") );
 
275
                cmd = 0L;
 
276
                for ( int i = 0 ; i < abs( colsDiff ) ; i++ )
 
277
                {
 
278
                    if ( colsDiff < 0 )
 
279
                        cmd = new KWRemoveColumnCommand( i18n("Remove Column"), table, oldColCount-i-1 );
 
280
                    else
 
281
                    {
 
282
                        cmd = new KWInsertColumnCommand( i18n("Insert Column"), table, oldColCount+i,  maxRightOffset);
 
283
                    }
 
284
 
 
285
                    if (cmd)
 
286
                        macroCmd->addCommand( cmd );
 
287
                }
 
288
                canvas->setTableCols( nCols->value() );
 
289
            }
 
290
 
 
291
            // Apply template
 
292
            if ( tableTemplateSelector->getTableTemplate() && (( oldTemplateName!=tableTemplateSelector->getTableTemplate()->name() ) || (cbReapplyTemplate1->isChecked()) ))
 
293
            {
 
294
                if ( !macroCmd )
 
295
                    macroCmd = new KMacroCommand( i18n("Apply Template to Table") );
 
296
                KWTableTemplateCommand *ttCmd=new KWTableTemplateCommand( i18n("Apply Template to Table"), table, tableTemplateSelector->getTableTemplate() );
 
297
                macroCmd->addCommand( ttCmd );
 
298
                canvas->setTableTemplateName( tableTemplateSelector->getTableTemplate()->name() );
 
299
            }
 
300
            if ( macroCmd )
 
301
            {
 
302
                macroCmd->execute();
 
303
                doc->addCommand( macroCmd );
 
304
            }
 
305
        }
 
306
    }
244
307
    KDialogBase::slotOk();
245
308
}
246
309
 
253
316
{
254
317
    preview->setCols( _cols );
255
318
}
 
319
 
 
320
void KWTableDia::slotSetReapply( bool _reapply )
 
321
{
 
322
    if ( cbReapplyTemplate1->isChecked()!=_reapply ) cbReapplyTemplate1->setChecked( _reapply );
 
323
    if ( cbReapplyTemplate2->isChecked()!=_reapply ) cbReapplyTemplate2->setChecked( _reapply );
 
324
}
 
325
 
 
326
void KWTableDia::slotInlineTable( bool state)
 
327
{
 
328
    if ( m_useMode==NEW )
 
329
    {
 
330
        lWid->setEnabled( !state );
 
331
        lHei->setEnabled( !state );
 
332
        cHei->setEnabled( !state );
 
333
        cWid->setEnabled( !state );
 
334
    }
 
335
}