71
66
/* Class: KWTableDia */
72
67
/******************************************************************/
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)
81
77
setupTab1( rows, cols, wid, hei, floating );
84
setInitialSize( QSize(500, 400) );
78
setupTab2( _templateName,format );
80
setInitialSize( QSize(500, 480) );
84
oldTemplateName = _templateName;
87
slotInlineTable( cbIsFloating->isChecked());
87
91
void KWTableDia::setupTab1( int rows, int cols, CellSize wid, CellSize hei, bool floating )
91
95
QGridLayout *grid = new QGridLayout( tab1, 9, 2, KDialog::marginHint(), KDialog::spacingHint() );
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 );
96
100
nRows = new QSpinBox( 1, 128, 1, tab1 );
97
101
nRows->setValue( rows );
98
102
grid->addWidget( nRows, 1, 0 );
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 );
103
107
nCols = new QSpinBox( 1, 128, 1, tab1 );
104
108
nCols->setValue( cols );
105
109
grid->addWidget( nCols, 3, 0 );
107
lHei = new QLabel( i18n( "Cell Heights:" ), tab1 );
108
grid->addWidget( lHei, 4, 0 );
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 );
116
lWid = new QLabel( i18n( "Cell Widths:" ), tab1 );
117
grid->addWidget( lWid, 6, 0 );
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 )
113
lHei = new QLabel( i18n( "Cell heights:" ), tab1 );
114
grid->addWidget( lHei, 4, 0 );
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 );
122
lWid = new QLabel( i18n( "Cell widths:" ), tab1 );
123
grid->addWidget( lWid, 6, 0 );
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 );
125
132
preview = new KWTablePreview( tab1, rows, cols );
126
133
preview->setBackgroundColor( white );
127
134
grid->addMultiCellWidget( preview, 0, 8, 1, 1 );
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 );
134
grid->addMultiCellWidget( cbIsFloating, 9, 9, 0, 2 );
136
if ( m_useMode==NEW )
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 );
143
grid->addMultiCellWidget( cbIsFloating, 9, 9, 0, 2 );
144
connect( cbIsFloating, SIGNAL( toggled ( bool ) ), this, SLOT( slotInlineTable( bool ) ) );
149
cbReapplyTemplate1 = new QCheckBox( i18n("Reapply template to table"), tab1 );
150
grid->addMultiCellWidget( cbReapplyTemplate1, 9, 9, 0, 2);
152
connect( cbReapplyTemplate1, SIGNAL( toggled ( bool ) ), this, SLOT( slotSetReapply( bool ) ) );
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 )
161
grid->addRowSpacing( 4, lHei->height() );
162
grid->addRowSpacing( 5, cHei->height() );
163
grid->addRowSpacing( 6, lWid->height() );
164
grid->addRowSpacing( 7, cWid->height() );
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 );
172
198
connect( nCols, SIGNAL( valueChanged( int ) ), this, SLOT( colsChanged( int ) ) );
175
void KWTableDia::setupTab2()
201
void KWTableDia::setupTab2(const QString & _templateName, int format )
179
tab2 = addPage( i18n("Properties"));
180
QGridLayout *grid = new QGridLayout( tab2, 4, 3, KDialog::marginHint(), KDialog::spacingHint() );
182
lStyles = new QLabel( i18n( "Styles" ), tab2 );
183
grid->addWidget( lStyles, 0, 0 );
185
lbStyles = new QListBox( tab2 );
186
grid->addWidget( lbStyles, 1, 0 );
188
preview2 = new QWidget( tab2 );
189
preview2->setBackgroundColor( white );
190
grid->addMultiCellWidget( preview2, 1, 1, 1, 2 );
192
bgHeader = new QButtonGroup( i18n( "Apply for Header" ), tab2 );
193
grid->addWidget( bgHeader, 2, 0 );
195
bgFirstCol = new QButtonGroup( i18n( "Apply for First Column" ), tab2 );
196
grid->addWidget( bgFirstCol, 2, 1 );
198
bgBody = new QButtonGroup( i18n( "Apply for Body" ), tab2 );
199
grid->addWidget( bgBody, 2, 2 );
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 );
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 );
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 );
203
QWidget *tab2 = addPage( i18n("Templates"));
205
QGridLayout *grid = new QGridLayout( tab2, 2, 1, KDialog::marginHint(), KDialog::spacingHint() );
207
tableTemplateSelector = new KWTableTemplateSelector( doc, tab2, _templateName,format );
208
grid->addWidget(tableTemplateSelector, 0, 0);
212
cbReapplyTemplate2 = new QCheckBox( i18n("Reapply template to table"), tab2 );
213
grid->addWidget( cbReapplyTemplate2, 1, 0);
215
grid->setRowStretch( 0, 1);
216
grid->setRowStretch( 1, 0);
218
connect( cbReapplyTemplate2, SIGNAL( toggled ( bool ) ), this, SLOT( slotSetReapply( bool ) ) );
228
220
grid->activate();
231
void KWTableDia::readTableStyles()
238
223
void KWTableDia::slotOk()
240
canvas->createTable( nRows->value(), nCols->value(),
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(),
231
cbIsFloating->isChecked(),
232
tableTemplateSelector->getTableTemplate(),
233
tableTemplateSelector->getFormatType());
236
KWTableFrameSet *table = canvas->getCurrentTable();
239
KMacroCommand *macroCmd = 0L;
242
// Add or delete rows
243
int rowsDiff = nRows->value()-oldRowCount;
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++ )
250
cmd = new KWRemoveRowCommand( i18n("Remove Row"), table, oldRowCount-i-1 );
253
cmd = new KWInsertRowCommand( i18n("Insert Row"), table, oldRowCount+i );
257
macroCmd->addCommand( cmd );
259
canvas->setTableRows( nRows->value() );
262
// Add or delete cols
263
int colsDiff = nCols->value()-oldColCount;
266
double maxRightOffset;
267
if (table->isFloating())
268
// inline table: max offset of containing frame
269
maxRightOffset = table->anchorFrameset()->frame(0)->right();
271
// non inline table: max offset of the page
272
maxRightOffset = doc->ptPaperWidth() - doc->ptRightBorder();
274
macroCmd = new KMacroCommand( (colsDiff>0 ) ? i18n("Add New Columns to Table") : i18n("Remove Columns From Table") );
276
for ( int i = 0 ; i < abs( colsDiff ) ; i++ )
279
cmd = new KWRemoveColumnCommand( i18n("Remove Column"), table, oldColCount-i-1 );
282
cmd = new KWInsertColumnCommand( i18n("Insert Column"), table, oldColCount+i, maxRightOffset);
286
macroCmd->addCommand( cmd );
288
canvas->setTableCols( nCols->value() );
292
if ( tableTemplateSelector->getTableTemplate() && (( oldTemplateName!=tableTemplateSelector->getTableTemplate()->name() ) || (cbReapplyTemplate1->isChecked()) ))
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() );
303
doc->addCommand( macroCmd );
244
307
KDialogBase::slotOk();