kspread

kspread_dlg_layout.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
3 (C) 2004 Tomas Mecir <mecirt@gmail.com>
4 (C) 2002-2004 Ariya Hidayat <ariya@kde.org>
5 (C) 2002-2003 Norbert Andres <nandres@web.de>
6 (C) 2001-2003 Philipp Mueller <philipp.mueller@gmx.de>
7 (C) 2002 John Dailey <dailey@vt.edu>
8 (C) 1999-2002 Laurent Montel <montel@kde.org>
9 (C) 1999-2002 Harri Porten <porten@kde.org>
10 (C) 2000-2001 David Faure <faure@kde.org>
11 (C) 1998-2000 Torben Weis <weis@kde.org>
12 (C) 2000 Werner Trobin <trobin@kde.org>
13 (C) 1999 Reginald Stadlbauer <reggie@kde.org>
14 (C) 1998-1999 Stephan Kulow <coolo@kde.org>
15
16 This library is free software; you can redistribute it and/or
17 modify it under the terms of the GNU Library General Public
18 License as published by the Free Software Foundation; either
19 version 2 of the License, or (at your option) any later version.
20
21 This library is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 Library General Public License for more details.
25
26 You should have received a copy of the GNU Library General Public License
27 along with this library; see the file COPYING.LIB. If not, write to
28 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29 * Boston, MA 02110-1301, USA.
30*/
31
32#include <stdlib.h>
33#include <math.h>
34
35#include <tqbitmap.h>
36#include <tqcheckbox.h>
37#include <tqframe.h>
38#include <tqlabel.h>
39#include <tqlayout.h>
40#include <tqlistbox.h>
41#include <tqfontdatabase.h>
42#include <tqradiobutton.h>
43#include <tqslider.h>
44#include <tqwhatsthis.h>
45
46#include <kcolorbutton.h>
47#include <kcombobox.h>
48#include <kdebug.h>
49#include <kdialog.h>
50#include <klineedit.h>
51#include <tdemessagebox.h>
52#include <knumvalidator.h>
53
54#include <KoUnitWidgets.h>
55
56#include "kspread_canvas.h"
57#include "kspread_dlg_layout.h"
58#include "kspread_locale.h"
59#include "kspread_sheet.h"
60#include "kspread_style.h"
61#include "kspread_style_manager.h"
62#include "kspread_undo.h"
63#include "kspread_util.h"
64#include "manipulator.h"
65#include "selection.h"
66#include "valueformatter.h"
67
68using namespace KSpread;
69
70/***************************************************************************
71 *
72 * PatternSelect
73 *
74 ***************************************************************************/
75
76PatternSelect::PatternSelect( TQWidget *parent, const char * )
77 : TQFrame( parent )
78{
79 penStyle = TQt::NoPen;
80 penWidth = 1;
81 penColor = colorGroup().text();
82 selected = false;
83 undefined = false;
84}
85
86void PatternSelect::setPattern( const TQColor &_color, int _width, TQt::PenStyle _style )
87{
88 penStyle = _style;
89 penColor = _color;
90 penWidth = _width;
91 repaint();
92}
93
94void PatternSelect::setUndefined()
95{
96 undefined = true;
97}
98
99void PatternSelect::paintEvent( TQPaintEvent *_ev )
100{
101 TQFrame::paintEvent( _ev );
102
103 TQPainter painter( this );
104
105 if ( !undefined )
106 {
107 TQPen pen( penColor, penWidth, penStyle);
108 painter.setPen( pen );
109 painter.drawLine( 6, height()/2, width() - 6,height()/2 );
110 }
111 else
112 {
113 painter.fillRect( 2, 2, width() - 4, height() - 4, BDiagPattern );
114 }
115}
116
117void PatternSelect::mousePressEvent( TQMouseEvent * )
118{
119 slotSelect();
120
121 emit clicked( this );
122}
123
124void PatternSelect::slotUnselect()
125{
126 selected = false;
127
128 setLineWidth( 1 );
129 setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
130 repaint();
131}
132
133void PatternSelect::slotSelect()
134{
135 selected = true;
136
137 setLineWidth( 2 );
138 setFrameStyle( TQFrame::Panel | TQFrame::Plain );
139 repaint();
140}
141
142
143
144/***************************************************************************
145 *
146 * GeneralTab
147 *
148 ***************************************************************************/
149
150GeneralTab::GeneralTab( TQWidget* parent, CellFormatDialog * dlg )
151 : TQWidget( parent ),
152 m_dlg( dlg )
153{
154 TQGridLayout * layout = new TQGridLayout( this, 1, 1, KDialog::marginHint(), KDialog::spacingHint(), "layout");
155
156 TQGroupBox * groupBox = new TQGroupBox( this, "groupBox1" );
157 groupBox->setColumnLayout(0, TQt::Vertical );
158 groupBox->setTitle( i18n( "Style" ) );
159 groupBox->layout()->setSpacing( KDialog::spacingHint() );
160 groupBox->layout()->setMargin( KDialog::marginHint() );
161
162 TQGridLayout * groupBoxLayout = new TQGridLayout( groupBox->layout() );
163 groupBoxLayout->setAlignment( TQt::AlignTop );
164
165 TQLabel * label1 = new TQLabel( groupBox, "label1" );
166 label1->setText( i18n( "Name:" ) );
167 groupBoxLayout->addWidget( label1, 0, 0 );
168
169 m_nameEdit = new KLineEdit( groupBox, "m_nameEdit" );
170 m_nameEdit->setText( m_dlg->styleName );
171 groupBoxLayout->addWidget( m_nameEdit, 0, 1 );
172
173 TQLabel * label2 = new TQLabel( groupBox, "label2" );
174 label2->setText( i18n( "Inherit style:" ) );
175 groupBoxLayout->addWidget( label2, 1, 0 );
176
177 m_parentBox = new KComboBox( false, groupBox, "m_parentBox" );
178 m_parentBox->clear();
179 m_parentBox->insertItem( i18n( "<None>" ) );
180 TQStringList tmp = m_dlg->getStyleManager()->styleNames();
181 tmp.remove( m_dlg->styleName );
182 m_parentBox->insertStringList( tmp );
183
184 if ( m_dlg->getStyle()->parent() )
185 m_parentBox->setCurrentText( m_dlg->getStyle()->parentName() );
186 else
187 {
188 m_parentBox->setCurrentText( i18n( "<None>" ) );
189
190 if ( m_dlg->getStyle()->definesAll() )
191 m_parentBox->setEnabled( false );
192 }
193
194 connect( m_parentBox, TQ_SIGNAL( textChanged( const TQString & ) ), this, TQ_SLOT( slotNewParent( const TQString & ) ) );
195 connect( m_nameEdit, TQ_SIGNAL( lostFocus() ), this, TQ_SLOT( slotNameChanged() ) );
196
197 groupBoxLayout->addWidget( m_parentBox, 1, 1 );
198
199 TQSpacerItem * spacer = new TQSpacerItem( 20, 260, TQSizePolicy::Minimum, TQSizePolicy::Expanding );
200
201 layout->addWidget( groupBox, 0, 0 );
202 layout->addItem( spacer, 1, 0 );
203
204 if ( m_dlg->getStyle()->type() == Style::BUILTIN )
205 {
206 m_nameEdit->setEnabled( false );
207 m_parentBox->setEnabled( false );
208 }
209
210 resize( TQSize( 534, 447 ).expandedTo(minimumSizeHint()) );
211}
212
213GeneralTab::~GeneralTab()
214{
215}
216
217void GeneralTab::slotNameChanged()
218{
219 checkName();
220}
221
222void GeneralTab::slotNewParent( const TQString & parentName )
223{
224 kdDebug() << "New Parent" << endl;
225 if ( !checkParent( parentName ) )
226 return;
227
228 if ( parentName.isEmpty() || parentName == i18n( "<None>" ) )
229 m_dlg->getStyle()->setParent( 0 );
230 else
231 m_dlg->getStyle()->setParent( m_dlg->getStyleManager()->style( parentName ) );
232
233 // Set difference to new parent, set GUI to parent values, add changes made before
234 // m_dlg->initGUI();
235}
236
237bool GeneralTab::checkName()
238{
239 if ( m_nameEdit->isEnabled() )
240 {
241 if ( !m_dlg->getStyleManager()->validateStyleName( m_nameEdit->text(), m_dlg->getStyle() ) )
242 {
243 KMessageBox::sorry( this, i18n( "A style with this name already exists." ) );
244 return false;
245 }
246 }
247
248 return true;
249}
250
251bool GeneralTab::checkParent( const TQString & parentName )
252{
253 if ( m_dlg->getStyle()->parentName() != parentName
254 && m_parentBox->isEnabled() && parentName != i18n( "<None>" ) && !parentName.isEmpty() )
255 {
256 if ( m_nameEdit->text() == parentName )
257 {
258 KMessageBox::sorry( this, i18n( "A style cannot inherit from itself." ) );
259 return false;
260 }
261 if ( !m_dlg->checkCircle( m_nameEdit->text(), parentName ) )
262 {
263 KMessageBox::sorry( this,
264 i18n( "The style cannot inherit from '%1' because of recursive references." )
265 .arg( m_parentBox->currentText() ) );
266 return false;
267 }
268
269 CustomStyle * p = m_dlg->getStyleManager()->style( parentName );
270
271 if ( !p )
272 {
273 KMessageBox::sorry( this, i18n( "The parent style does not exist." ) );
274 return false;
275 }
276 }
277
278 return true;
279}
280
281bool GeneralTab::apply( CustomStyle * style )
282{
283 if ( !checkParent( m_parentBox->currentText() ) )
284 return false;
285
286 if ( !checkName() )
287 return false;
288
289 if ( m_nameEdit->isEnabled() )
290 {
291 if ( style->type() != Style::BUILTIN )
292 {
293 TQString name( style->name() );
294 style->setName( m_nameEdit->text() );
295 if ( m_parentBox->isEnabled() )
296 {
297 if ( m_parentBox->currentText() == i18n( "None" ) || m_parentBox->currentText().isEmpty() )
298 style->setParent( 0 );
299 else
300 style->setParent( m_dlg->getStyleManager()->style( m_parentBox->currentText() ) );
301 }
302 m_dlg->getStyleManager()->changeName( name, m_nameEdit->text() );
303 }
304 }
305
306 if ( style->type() == Style::TENTATIVE )
307 style->setType( Style::CUSTOM );
308
309 return true;
310}
311
312
313
314/***************************************************************************
315 *
316 * CellFormatDialog
317 *
318 ***************************************************************************/
319
320CellFormatDialog::CellFormatDialog( View * _view, Sheet * _sheet )
321 : TQObject(),
322 m_doc( _sheet->doc() ),
323 m_sheet( _sheet ),
324 m_pView( _view ),
325 m_style( 0 )
326{
327 initMembers();
328
329 //We need both conditions quite often, so store the condition here too
330 isRowSelected = _view->selectionInfo()->isRowSelected();
331 isColumnSelected = _view->selectionInfo()->isColumnSelected();
332
333 TQRect range = _view->selectionInfo()->selection();
334 left = range.left();
335 top = range.top();
336 right = range.right();
337 bottom = range.bottom();
338
339 if ( left == right )
340 oneCol = true;
341 else
342 oneCol = false;
343
344 if ( top == bottom )
345 oneRow = true;
346 else
347 oneRow = false;
348
349 Cell* obj = m_sheet->cellAt( left, top );
350 oneCell = (left == right && top == bottom &&
351 !obj->doesMergeCells());
352
353 isMerged = ((obj->doesMergeCells() &&
354 left + obj->extraXCells() >= right &&
355 top + obj->extraYCells() >= bottom));
356
357 // Initialize with the upper left object.
358 borders[BorderType_Left].style = obj->format()->leftBorderStyle( left, top );
359 borders[BorderType_Left].width = obj->format()->leftBorderWidth( left, top );
360 borders[BorderType_Left].color = obj->format()->leftBorderColor( left, top );
361 borders[BorderType_Top].style = obj->format()->topBorderStyle( left, top );
362 borders[BorderType_Top].width = obj->format()->topBorderWidth( left, top );
363 borders[BorderType_Top].color = obj->format()->topBorderColor( left, top );
364 borders[BorderType_FallingDiagonal].style =
365 obj->format()->fallDiagonalStyle( left, top );
366 borders[BorderType_FallingDiagonal].width =
367 obj->format()->fallDiagonalWidth( left, top );
368 borders[BorderType_FallingDiagonal].color =
369 obj->format()->fallDiagonalColor( left, top );
370 borders[BorderType_RisingDiagonal].style =
371 obj->format()->goUpDiagonalStyle( left, top );
372 borders[BorderType_RisingDiagonal].width =
373 obj->format()->goUpDiagonalWidth( left, top );
374 borders[BorderType_RisingDiagonal].color =
375 obj->format()->goUpDiagonalColor( left, top );
376
377 // Look at the upper right one for the right border.
378 obj = m_sheet->cellAt( right, top );
379 borders[BorderType_Right].style = obj->format()->rightBorderStyle( right, top );
380 borders[BorderType_Right].width = obj->format()->rightBorderWidth( right, top );
381 borders[BorderType_Right].color = obj->format()->rightBorderColor( right, top );
382
383 // Look at the bottom left cell for the bottom border.
384 obj = m_sheet->cellAt( left, bottom );
385 borders[BorderType_Bottom].style = obj->format()->bottomBorderStyle( left, bottom );
386 borders[BorderType_Bottom].width = obj->format()->bottomBorderWidth( left, bottom );
387 borders[BorderType_Bottom].color = obj->format()->bottomBorderColor( left, bottom );
388
389 // Just an assumption
390 obj = m_sheet->cellAt( right, top );
391 if ( obj->isPartOfMerged() )
392 {
393 obj = obj->obscuringCells().first();
394 int moveX = obj->column();
395 int moveY = top;
396 int moveX2 = right;
397 int moveY2 = obj->row();
398 borders[BorderType_Vertical].style = obj->format()->leftBorderStyle( moveX, moveY );
399 borders[BorderType_Vertical].width = obj->format()->leftBorderWidth( moveX, moveY );
400 borders[BorderType_Vertical].color = obj->format()->leftBorderColor( moveX, moveY );
401
402 obj = m_sheet->cellAt( moveX2, moveY2 );
403 borders[BorderType_Horizontal].style = obj->format()->topBorderStyle( moveX2, moveY2 );
404 borders[BorderType_Horizontal].width = obj->format()->topBorderWidth( moveX2, moveY2 );
405 borders[BorderType_Horizontal].color = obj->format()->topBorderColor( moveX2, moveY2 );
406 }
407 else
408 {
409 borders[BorderType_Vertical].style = obj->format()->leftBorderStyle( right, top );
410 borders[BorderType_Vertical].width = obj->format()->leftBorderWidth( right, top );
411 borders[BorderType_Vertical].color = obj->format()->leftBorderColor( right, top );
412 borders[BorderType_Horizontal].style = obj->format()->topBorderStyle(right, bottom);
413 borders[BorderType_Horizontal].width = obj->format()->topBorderWidth(right, bottom);
414 borders[BorderType_Horizontal].color = obj->format()->topBorderColor(right, bottom);
415 }
416
417 obj = m_sheet->cellAt( left, top );
418 prefix = obj->format()->prefix( left, top );
419 postfix = obj->format()->postfix( left, top );
420 precision = obj->format()->precision( left, top );
421 floatFormat = obj->format()->floatFormat( left, top );
422 floatColor = obj->format()->floatColor( left, top );
423 alignX = obj->format()->align( left, top );
424 alignY = obj->format()->alignY( left, top );
425 textColor = obj->format()->textColor( left, top );
426 bgColor = obj->bgColor( left, top );
427 textFontSize = obj->format()->textFontSize( left, top );
428 textFontFamily = obj->format()->textFontFamily( left, top );
429 textFontBold = obj->format()->textFontBold( left, top );
430 textFontItalic = obj->format()->textFontItalic( left, top );
431 strike=obj->format()->textFontStrike( left, top );
432 underline = obj->format()->textFontUnderline( left, top );
433 // Needed to initialize the font correctly ( bug in TQt )
434 textFont = obj->format()->textFont( left, top );
435 obj->format()->currencyInfo( cCurrency );
436
437 brushColor = obj->format()->backGroundBrushColor( left, top );
438 brushStyle = obj->format()->backGroundBrushStyle( left,top );
439
440 bMultiRow = obj->format()->multiRow( left, top );
441 bVerticalText = obj->format()->verticalText( left, top );
442 textRotation = obj->format()->getAngle(left, top);
443 formatType = obj->format()->getFormatType(left, top);
444
445 bDontPrintText = obj->format()->getDontprintText( left, top );
446 bHideFormula = obj->format()->isHideFormula( left, top );
447 bHideAll = obj->format()->isHideAll( left, top );
448 bIsProtected = !obj->format()->notProtected( left, top );
449
450 indent = obj->format()->getIndent(left, top);
451
452 value = obj->value();
453
454 RowFormat *rl;
455 ColumnFormat *cl;
456 widthSize = 0.0;
457 heightSize = 0.0;
458
459 if ( !isRowSelected )
460 {
461 for ( int x = left; x <= right; x++ )
462 {
463 cl = m_pView->activeSheet()->columnFormat( x );
464 widthSize = TQMAX( cl->dblWidth(), widthSize );
465 }
466 }
467
468 if ( !isColumnSelected )
469 {
470 for ( int y = top; y <= bottom; y++ )
471 {
472 rl = m_pView->activeSheet()->rowFormat(y);
473 heightSize = TQMAX( rl->dblHeight(), heightSize );
474 }
475 }
476
477 //select column(s)
478 if ( isColumnSelected )
479 {
480 int y = 1;
481 Cell* cell = NULL;
482 for (int x = left;x <= right; x++)
483 {
484 ColumnFormat *obj = m_sheet->nonDefaultColumnFormat(x);
485 initParameters( obj,x,y);
486
487 for (cell = m_sheet->getFirstCellColumn(x); cell != NULL;
488 cell = m_sheet->getNextCellDown(cell->column(), cell->row()))
489 {
490 initParameters( cell->format(), x, cell->row());
491 }
492 }
493
494 }
495 else if ( isRowSelected )
496 {
497 int x = 1;
498 Cell* c = NULL;
499 for ( int y = top;y<=bottom;y++)
500 {
501 RowFormat *obj = m_sheet->nonDefaultRowFormat(y);
502 initParameters( obj,x,y);
503
504 for (c = m_sheet->getFirstCellRow(y); c != NULL;
505 c = m_sheet->getNextCellRight(c->column(), c->row()) )
506 {
507 initParameters( c->format(), c->column(), c->row());
508 }
509 }
510 }
511 else
512 {
513 // Do the other objects have the same values ?
514 for ( int x = left; x <= right; x++ )
515 {
516 for ( int y = top; y <= bottom; y++ )
517 {
518 Cell *obj = m_sheet->cellAt( x, y );
519
520 if ( obj->isPartOfMerged() )
521 continue;
522
523 initParameters( obj->format(),x,y);
524 }
525 }
526 }
527 if ( !bTextRotation )
528 textRotation = 0;
529
530 if ( isColumnSelected )
531 {
532 int y=1;
533 ColumnFormat *obj=m_sheet->nonDefaultColumnFormat(left);
534 checkBorderLeft( obj,left, y);
535
536 Cell* c = NULL;
537 for (c = m_sheet->getFirstCellColumn(left); c != NULL;
538 c = m_sheet->getNextCellDown(c->column(), c->row()) )
539 {
540 checkBorderLeft(c->format(), c->column(), c->row());
541 }
542
543
544 obj=m_sheet->nonDefaultColumnFormat(right);
545 checkBorderRight(obj,right,y);
546 c = NULL;
547 for (c = m_sheet->getFirstCellColumn(right); c != NULL;
548 c = m_sheet->getNextCellDown(c->column(), c->row()) )
549 {
550 checkBorderRight(c->format(), c->column(), c->row());
551 }
552
553 for ( int x = left; x <= right; x++ )
554 {
555 Cell *obj = m_sheet->cellAt( x, top );
556 checkBorderTop(obj->format(),x, top);
557 obj = m_sheet->cellAt( x, bottom );
558 checkBorderBottom(obj->format(),x, bottom);
559 if ( x > left )
560 {
561 ColumnFormat *obj = m_sheet->nonDefaultColumnFormat(x);
562 checkBorderHorizontal(obj,x, y);
563 checkBorderVertical(obj,x, y);
564 }
565 }
566 }
567 else if ( isRowSelected )
568 {
569 int x=1;
570 for ( int y = top; y <= bottom; y++ )
571 {
572 Cell *obj = m_sheet->cellAt( right, y );
573 checkBorderRight(obj->format(),right,y);
574 obj = m_sheet->cellAt( left, y );
575 checkBorderLeft( obj->format(),left, y);
576 if ( y > top )
577 {
578 RowFormat* obj = m_sheet->nonDefaultRowFormat(y);
579 checkBorderHorizontal(obj,x, y);
580 checkBorderVertical(obj,x, y);
581 }
582 }
583
584 RowFormat *obj=m_sheet->nonDefaultRowFormat(top);
585 checkBorderTop(obj,x, top);
586 obj=m_sheet->nonDefaultRowFormat(bottom);
587 checkBorderBottom(obj,x, bottom);
588 }
589 else
590 {
591 for ( int y = top; y <= bottom; y++ )
592 {
593 Cell *obj = m_sheet->cellAt( left, y );
594 checkBorderLeft( obj->format(),left, y);
595 obj = m_sheet->cellAt( right, y );
596 checkBorderRight(obj->format(),right,y);
597 }
598
599 for ( int x = left; x <= right; x++ )
600 {
601 Cell *obj = m_sheet->cellAt( x, top );
602 checkBorderTop( obj->format(), x, top );
603 obj = m_sheet->cellAt( x, bottom );
604 checkBorderBottom( obj->format(), x, bottom );
605 }
606
607 // Look for the Outline
608 for ( int x = left; x <= right; x++ )
609 {
610 for ( int y = top+1; y <= bottom; y++ )
611 {
612 Cell *obj = m_sheet->cellAt( x, y );
613 checkBorderHorizontal(obj->format(),x, y);
614 }
615 }
616
617 for ( int x = left+1; x <= right; x++ )
618 {
619 for ( int y = top; y <= bottom; y++ )
620 {
621 Cell *obj = m_sheet->cellAt( x, y );
622 checkBorderVertical(obj->format(),x,y);
623 }
624 }
625 }
626
627 init();
628}
629
631 StyleManager * _manager, Doc * doc )
632 : TQObject(),
633 m_doc( doc ),
634 m_sheet( 0 ),
635 m_pView( _view ),
636 m_style( _style ),
637 m_styleManager( _manager )
638{
639 initMembers();
640 initGUI();
641 init();
642}
643
644void CellFormatDialog::initGUI()
645{
646 isRowSelected = false;
647 isColumnSelected = false;
648 styleName = m_style->name();
649
650 borders[BorderType_Left].style = m_style->leftBorderPen().style();
651 borders[BorderType_Left].width = m_style->leftBorderPen().width();
652 borders[BorderType_Left].color = m_style->leftBorderPen().color();
653
654 borders[BorderType_Top].style = m_style->topBorderPen().style();
655 borders[BorderType_Top].width = m_style->topBorderPen().width();
656 borders[BorderType_Top].color = m_style->topBorderPen().color();
657
658 borders[BorderType_Right].style = m_style->rightBorderPen().style();
659 borders[BorderType_Right].width = m_style->rightBorderPen().width();
660 borders[BorderType_Right].color = m_style->rightBorderPen().color();
661
662 borders[BorderType_Bottom].style = m_style->bottomBorderPen().style();
663 borders[BorderType_Bottom].width = m_style->bottomBorderPen().width();
664 borders[BorderType_Bottom].color = m_style->bottomBorderPen().color();
665
666 borders[BorderType_FallingDiagonal].style = m_style->fallDiagonalPen().style();
667 borders[BorderType_FallingDiagonal].width = m_style->fallDiagonalPen().width();
668 borders[BorderType_FallingDiagonal].color = m_style->fallDiagonalPen().color();
669
670 borders[BorderType_RisingDiagonal].style = m_style->goUpDiagonalPen().style();
671 borders[BorderType_RisingDiagonal].width = m_style->goUpDiagonalPen().width();
672 borders[BorderType_RisingDiagonal].color = m_style->goUpDiagonalPen().color();
673
674 borders[BorderType_Vertical].style = m_style->leftBorderPen().style();
675 borders[BorderType_Vertical].width = m_style->leftBorderPen().width();
676 borders[BorderType_Vertical].color = m_style->leftBorderPen().color();
677 borders[BorderType_Horizontal].style = m_style->topBorderPen().style();
678 borders[BorderType_Horizontal].width = m_style->topBorderPen().width();
679 borders[BorderType_Horizontal].color = m_style->topBorderPen().color();
680
681 prefix = m_style->prefix();
682 postfix = m_style->postfix();
683 precision = m_style->precision();
684 floatFormat = m_style->floatFormat();
685 floatColor = m_style->floatColor();
686 alignX = m_style->alignX();
687 alignY = m_style->alignY();
688 textColor = m_style->pen().color();
689 bgColor = m_style->bgColor();
690 textFontSize = m_style->fontSize();
691 textFontFamily = m_style->fontFamily();
692
693 uint flags = m_style->fontFlags();
694 textFontBold = ( flags & (uint) Style::FBold );
695 textFontItalic = ( flags & (uint) Style::FItalic );
696 strike = ( flags & (uint) Style::FStrike );
697 underline = ( flags & (uint) Style::FUnderline );
698
699 // Needed to initialize the font correctly ( bug in TQt )
700 textFont = m_style->font();
701 cCurrency = m_style->currency();
702 brushColor = m_style->backGroundBrush().color();
703 brushStyle = m_style->backGroundBrush().style();
704
705 bMultiRow = m_style->hasProperty( Style::PMultiRow );
706 bVerticalText = m_style->hasProperty( Style::PVerticalText );
707 textRotation = m_style->rotateAngle();
708 formatType = m_style->formatType();
709 indent = m_style->indent();
710
711 bDontPrintText = m_style->hasProperty( Style::PDontPrintText );
712 bHideFormula = m_style->hasProperty( Style::PHideFormula );
713 bHideAll = m_style->hasProperty( Style::PHideAll );
714 bIsProtected = !m_style->hasProperty( Style::PNotProtected );
715
716 widthSize = defaultWidthSize;
717 heightSize = defaultHeightSize;
718}
719
720CellFormatDialog::~CellFormatDialog()
721{
722 delete formatOnlyNegSignedPixmap;
723 delete formatRedOnlyNegSignedPixmap;
724 delete formatRedNeverSignedPixmap;
725 delete formatAlwaysSignedPixmap;
726 delete formatRedAlwaysSignedPixmap;
727}
728
729void CellFormatDialog::initMembers()
730{
731 formatOnlyNegSignedPixmap = 0L;
732 formatRedOnlyNegSignedPixmap = 0L;
733 formatRedNeverSignedPixmap = 0L;
734 formatAlwaysSignedPixmap = 0L;
735 formatRedAlwaysSignedPixmap = 0L;
736
737 // We assume, that all other objects have the same values
738 for ( int i = 0; i < BorderType_END; ++i )
739 {
740 borders[i].bStyle = true;
741 borders[i].bColor = true;
742 }
743 bFloatFormat = true;
744 bFloatColor = true;
745 bTextColor = true;
746 bBgColor = true;
747 bTextFontFamily = true;
748 bTextFontSize = true;
749 bTextFontBold = true;
750 bTextFontItalic = true;
751 bStrike = true;
752 bUnderline = true;
753 bTextRotation = true;
754 bFormatType = true;
755 bCurrency = true;
756 bDontPrintText = false;
757 bHideFormula = false;
758 bHideAll = false;
759 bIsProtected = true;
760
761 cCurrency.symbol = locale()->currencySymbol();
762 cCurrency.type = 0;
763
764 Sheet* sheet = m_pView->activeSheet();
765 defaultWidthSize = sheet ? sheet->columnFormat(0)->dblWidth() : 0;
766 defaultHeightSize = sheet ? sheet->rowFormat(0)->dblHeight() : 0;
767}
768
769bool CellFormatDialog::checkCircle( TQString const & name, TQString const & parent )
770{
771 return m_styleManager->checkCircle( name, parent );
772}
773
774void CellFormatDialog::checkBorderRight(Format *obj,int x,int y)
775{
776 if ( borders[BorderType_Right].style != obj->rightBorderStyle( x, y ) ||
777 borders[BorderType_Right].width != obj->rightBorderWidth( x, y ) )
778 borders[BorderType_Right].bStyle = false;
779 if ( borders[BorderType_Right].color != obj->rightBorderColor( x, y ) )
780 borders[BorderType_Right].bColor = false;
781}
782
783void CellFormatDialog::checkBorderLeft(Format *obj,int x,int y)
784{
785 if ( borders[BorderType_Left].style != obj->leftBorderStyle( x, y ) ||
786 borders[BorderType_Left].width != obj->leftBorderWidth( x, y ) )
787 borders[BorderType_Left].bStyle = false;
788 if ( borders[BorderType_Left].color != obj->leftBorderColor( x, y ) )
789 borders[BorderType_Left].bColor = false;
790}
791
792void CellFormatDialog::checkBorderTop(Format *obj,int x,int y)
793{
794 if ( borders[BorderType_Top].style != obj->topBorderStyle( x, y ) ||
795 borders[BorderType_Top].width != obj->topBorderWidth( x, y ) )
796 borders[BorderType_Top].bStyle = false;
797 if ( borders[BorderType_Top].color != obj->topBorderColor( x, y ) )
798 borders[BorderType_Top].bColor = false;
799}
800
801void CellFormatDialog::checkBorderBottom(Format *obj,int x,int y)
802{
803 if ( borders[BorderType_Bottom].style != obj->bottomBorderStyle( x, y ) ||
804 borders[BorderType_Bottom].width != obj->bottomBorderWidth( x, y ) )
805 borders[BorderType_Bottom].bStyle = false;
806 if ( borders[BorderType_Bottom].color != obj->bottomBorderColor( x, y ) )
807 borders[BorderType_Bottom].bColor = false;
808}
809
810void CellFormatDialog::checkBorderVertical(Format *obj,int x,int y)
811{
812 if (borders[BorderType_Vertical].style != obj->leftBorderStyle( x, y ) ||
813 borders[BorderType_Vertical].width != obj->leftBorderWidth( x, y ))
814 borders[BorderType_Vertical].bStyle = false;
815 if ( borders[BorderType_Vertical].color != obj->leftBorderColor( x, y ) )
816 borders[BorderType_Vertical].bColor = false;
817}
818
819void CellFormatDialog::checkBorderHorizontal(Format *obj,int x,int y)
820{
821 if ( borders[BorderType_Horizontal].style != obj->topBorderStyle( x, y ) ||
822 borders[BorderType_Horizontal].width != obj->topBorderWidth( x, y ) )
823 borders[BorderType_Horizontal].bStyle = false;
824 if ( borders[BorderType_Horizontal].color != obj->topBorderColor( x, y ) )
825 borders[BorderType_Horizontal].bColor = false;
826}
827
828
829void CellFormatDialog::initParameters(Format *obj,int x,int y)
830{
831 if (borders[BorderType_FallingDiagonal].style != obj->fallDiagonalStyle( x, y ))
832 borders[BorderType_FallingDiagonal].bStyle = false;
833 if (borders[BorderType_FallingDiagonal].width != obj->fallDiagonalWidth( x, y ))
834 borders[BorderType_FallingDiagonal].bStyle = false;
835 if (borders[BorderType_FallingDiagonal].color != obj->fallDiagonalColor( x, y ))
836 borders[BorderType_FallingDiagonal].bColor = false;
837
838 if (borders[BorderType_RisingDiagonal].style != obj->goUpDiagonalStyle( x, y ))
839 borders[BorderType_RisingDiagonal].bStyle = false;
840 if (borders[BorderType_RisingDiagonal].width != obj->goUpDiagonalWidth( x, y ))
841 borders[BorderType_RisingDiagonal].bStyle = false;
842 if (borders[BorderType_RisingDiagonal].color != obj->goUpDiagonalColor( x, y ))
843 borders[BorderType_RisingDiagonal].bColor = false;
844 if ( strike != obj->textFontStrike( x, y ) )
845 bStrike = false;
846 if ( underline != obj->textFontUnderline( x, y ) )
847 bUnderline = false;
848 if ( prefix != obj->prefix( x, y ) )
849 prefix = TQString();
850 if ( postfix != obj->postfix( x, y ) )
851 postfix = TQString();
852 if ( floatFormat != obj->floatFormat( x, y ) )
853 bFloatFormat = false;
854 if ( floatColor != obj->floatColor( x, y ) )
855 bFloatColor = false;
856 if ( textColor != obj->textColor( x, y ) )
857 bTextColor = false;
858 if ( textFontFamily != obj->textFontFamily( x, y ) )
859 bTextFontFamily = false;
860 if ( textFontSize != obj->textFontSize( x, y ) )
861 bTextFontSize = false;
862 if ( textFontBold != obj->textFontBold( x, y ) )
863 bTextFontBold = false;
864 if ( textFontItalic != obj->textFontItalic( x, y ) )
865 bTextFontItalic = false;
866 if ( bgColor != obj->bgColor( x, y ) )
867 bBgColor = false;
868 if ( textRotation != obj->getAngle(left, top) )
869 bTextRotation = false;
870 if ( formatType != obj->getFormatType(left, top) )
871 bFormatType = false;
872 if ( bMultiRow != obj->multiRow( left, top ) )
873 bMultiRow = false;
874 if ( bVerticalText!=obj->verticalText( left, top ) )
875 bVerticalText = false;
876 if ( bDontPrintText!=obj->getDontprintText( left, top ) )
877 bDontPrintText= false;
878
879 Format::Currency cur;
880 if (!obj->currencyInfo(cur))
881 bCurrency = false;
882 else
883 if (cur.symbol != cCurrency.symbol)
884 bCurrency = false;
885}
886
887void CellFormatDialog::init()
888{
889 TQColorGroup colorGroup = TQApplication::palette().active();
890
891 // Did we initialize the bitmaps ?
892 if ( formatOnlyNegSignedPixmap == 0L )
893 {
894 TQColor black = colorGroup.text(); // not necessarily black :)
895 formatOnlyNegSignedPixmap = paintFormatPixmap( "123.456", black, "-123.456", black );
896 formatRedOnlyNegSignedPixmap = paintFormatPixmap( "123.456", black, "-123.456", TQt::red );
897 formatRedNeverSignedPixmap = paintFormatPixmap( "123.456", black, "123.456", TQt::red );
898 formatAlwaysSignedPixmap = paintFormatPixmap( "+123.456", black, "-123.456", black );
899 formatRedAlwaysSignedPixmap = paintFormatPixmap( "+123.456", black, "-123.456", TQt::red );
900 }
901
902 tab = new TQTabDialog( (TQWidget*)m_pView, 0L, true );
903 //tab->setGeometry( tab->x(), tab->y(), 420, 400 );
904
905 if ( m_style )
906 {
907 generalPage = new GeneralTab( tab, this );
908 tab->addTab( generalPage, i18n( "&General" ) );
909 }
910
911 floatPage = new CellFormatPageFloat( tab, this );
912 tab->addTab( floatPage, i18n("&Data Format") );
913
914 fontPage = new CellFormatPageFont( tab, this );
915 tab->addTab( fontPage, i18n("&Font") );
916
917 // miscPage = new CellFormatPageMisc( tab, this );
918 // tab->addTab( miscPage, i18n("&Misc") );
919
920 positionPage = new CellFormatPagePosition( tab, this);
921 tab->addTab( positionPage, i18n("&Position") );
922
923 borderPage = new CellFormatPageBorder( tab, this );
924 tab->addTab( borderPage, i18n("&Border") );
925
926 patternPage=new CellFormatPagePattern(tab,this);
927 tab->addTab( patternPage,i18n("Back&ground"));
928
929 protectPage = new CellFormatPageProtection( tab, this );
930 tab->addTab( protectPage, i18n("&Cell Protection") );
931
932 tab->setCancelButton( i18n( "&Cancel" ) );
933 tab->setOkButton( i18n( "&OK" ) );
934
935 tab->setCaption( i18n( "Cell Format" ) );
936
937 tab->adjustSize();
938
939 connect( tab, TQ_SIGNAL( applyButtonPressed() ), this, TQ_SLOT( slotApply() ) );
940
941 tab->exec();
942}
943
944TQPixmap * CellFormatDialog::paintFormatPixmap( const char * _string1, const TQColor & _color1,
945 const char *_string2, const TQColor & _color2 )
946{
947 TQPixmap * pixmap = new TQPixmap( 150, 14 );
948
949 TQPainter painter;
950 painter.begin( pixmap );
951 painter.fillRect( 0, 0, 150, 14, TQApplication::palette().active().base() );
952 painter.setPen( _color1 );
953 painter.drawText( 2, 11, TQString(_string1) );
954 painter.setPen( _color2 );
955 painter.drawText( 75, 11, TQString(_string2) );
956 painter.end();
957
958 TQBitmap bm( pixmap->size() );
959 bm.fill( color0 );
960 painter.begin( &bm );
961 painter.setPen( color1 );
962 painter.drawText( 2, 11, TQString(_string1) );
963 painter.drawText( 75, 11, TQString(_string2) );
964 painter.end();
965 pixmap->setMask( bm );
966
967 return pixmap;
968}
969
971{
972 return ( tab->exec() );
973}
974
975void CellFormatDialog::applyStyle()
976{
977 generalPage->apply( m_style );
978
979 borderPage->apply(0);
980 floatPage->apply( m_style );
981 // miscPage->apply( m_style );
982 fontPage->apply( m_style );
983 positionPage->apply( m_style );
984 patternPage->apply( m_style );
985 protectPage->apply( m_style );
986 m_pView->refreshView();
987}
988
989void CellFormatDialog::slotApply()
990{
991 if ( m_style )
992 {
993 applyStyle();
994 return;
995 }
996
997 // (Tomas) TODO: this will be slow !!!
998 // We need to create a manipulator that would act as KMacroCommand,
999 // but which would also ensure that updates are not painted until everything
1000 // is updated properly ...
1001 KMacroCommand* macroCommand = new KMacroCommand( i18n("Change Format") );
1002
1003 if ( isMerged != positionPage->getMergedCellState() )
1004 {
1005 if ( positionPage->getMergedCellState() )
1006 {
1007 Manipulator* manipulator = new MergeManipulator();
1008 manipulator->setSheet(m_pView->activeSheet());
1009 manipulator->setRegisterUndo(false);
1010 manipulator->add(*m_pView->selectionInfo());
1011 macroCommand->addCommand( manipulator );
1012 }
1013 else
1014 {
1015 //dissociate cells
1016 Manipulator* manipulator = new MergeManipulator();
1017 manipulator->setSheet(m_pView->activeSheet());
1018 manipulator->setReverse(true);
1019 manipulator->setRegisterUndo(false);
1020 manipulator->add(*m_pView->selectionInfo());
1021 macroCommand->addCommand( manipulator );
1022 }
1023 }
1024
1025 FormatManipulator* manipulator = new FormatManipulator();
1026 manipulator->setSheet(m_pView->activeSheet());
1027 manipulator->setRegisterUndo(false);
1028 manipulator->add(*m_pView->selectionInfo());
1029 borderPage->apply(manipulator);
1030 floatPage->apply(manipulator);
1031 fontPage->apply(manipulator);
1032 positionPage->apply(manipulator);
1033 patternPage->apply(manipulator);
1034 protectPage->apply(manipulator);
1035
1036 if (!manipulator->isEmpty())
1037 {
1038 macroCommand->addCommand( manipulator );
1039 }
1040 else
1041 {
1042 delete manipulator;
1043 }
1044
1045 if ( int( positionPage->getSizeHeight() ) != int( heightSize ) )
1046 {
1047 ResizeRowManipulator* manipulator = new ResizeRowManipulator();
1048 manipulator->setSheet(m_pView->activeSheet());
1049 manipulator->setSize(positionPage->getSizeHeight());
1050 // TODO Stefan:
1051 manipulator->setOldSize(heightSize);
1052 manipulator->add(*m_pView->selectionInfo());
1053 macroCommand->addCommand( manipulator );
1054 }
1055 if ( int( positionPage->getSizeWidth() ) != int( widthSize ) )
1056 {
1057 ResizeColumnManipulator* manipulator = new ResizeColumnManipulator();
1058 manipulator->setSheet(m_pView->activeSheet());
1059 manipulator->setSize(positionPage->getSizeWidth());
1060 // TODO Stefan:
1061 manipulator->setOldSize(widthSize);
1062 manipulator->add(*m_pView->selectionInfo());
1063 macroCommand->addCommand( manipulator );
1064 }
1065
1066 macroCommand->execute();
1067 m_doc->addCommand( macroCommand );
1068
1069 // Update the toolbar (bold/italic/font...)
1070 m_pView->updateEditWidget();
1071}
1072
1073
1074
1075/***************************************************************************
1076 *
1077 * CellFormatPageFloat
1078 *
1079 ***************************************************************************/
1080
1081CellFormatPageFloat::CellFormatPageFloat( TQWidget* parent, CellFormatDialog *_dlg )
1082 : TQWidget ( parent ),
1083 dlg( _dlg )
1084{
1085 TQVBoxLayout* layout = new TQVBoxLayout( this, 6,10 );
1086
1087 TQButtonGroup *grp = new TQButtonGroup( i18n("Format"),this);
1088 TQGridLayout *grid = new TQGridLayout(grp,11,2,KDialog::marginHint(), KDialog::spacingHint());
1089
1090 int fHeight = grp->fontMetrics().height();
1091 grid->addRowSpacing( 0, fHeight/2 ); // groupbox title
1092
1093 grp->setRadioButtonExclusive( true );
1094 generic=new TQRadioButton(i18n("Generic"),grp);
1095 TQWhatsThis::add(generic, i18n( "This is the default format and KSpread autodetects the actual data type depending on the current cell data. By default, KSpread right justifies numbers, dates and times within a cell and left justifies anything else." ) );
1096 grid->addWidget(generic,1,0);
1097
1098 number=new TQRadioButton(i18n("Number"),grp);
1099 TQWhatsThis::add(number, i18n( "The number notation uses the notation you globally choose in KControl -> Regional & Accessibility -> Numbers tab. Numbers are right justified by default." ) );
1100 grid->addWidget(number,2,0);
1101
1102 percent=new TQRadioButton(i18n("Percent"),grp);
1103 TQWhatsThis::add(percent, i18n( "When you have a number in the current cell and you switch from the dcell format from Generic to Percent, the current cell number will be multiplied by 100%.\nFor example if you enter 12 and set the cell format to Percent, the number will then be 1,200 %. Switching back to Generic cell format will bring it back to 12.\nYou can also use the Percent icon in the Format Toolbar." ) );
1104 grid->addWidget(percent,3,0);
1105
1106 money=new TQRadioButton(i18n("Money"),grp);
1107 TQWhatsThis::add(money, i18n( "The Money format converts your number into money notation using the settings globally fixed in KControl in Regional & Accessibility -> Money. The currency symbol will be displayed and the precision will be the one set in KControl.\nYou can also use the Currency icon in the Format Toolbar to set the cell formatting to look like your current currency." ) );
1108 grid->addWidget(money,4,0);
1109
1110 scientific=new TQRadioButton(i18n("Scientific"),grp);
1111 TQWhatsThis::add(scientific, i18n( "The scientific format changes your number using the scientific notation. For example, 0.0012 will be changed to 1.2E-03. Going back using Generic cell format will display 0.0012 again." ) );
1112 grid->addWidget(scientific,5,0);
1113
1114 fraction=new TQRadioButton(i18n("Fraction"),grp);
1115 TQWhatsThis::add(fraction, i18n( "The fraction format changes your number into a fraction. For example, 0.1 can be changed to 1/8, 2/16, 1/10, etc. You define the type of fraction by choosing it in the field on the right. If the exact fraction is not possible in the fraction mode you choose, the nearest closest match is chosen.\n For example: when we have 1.5 as number, we choose Fraction and Sixteenths 1/16 the text displayed into cell is \"1 8/16\" which is an exact fraction. If you have 1.4 as number in your cell and you choose Fraction and Sixteenths 1/16 then the cell will display \"1 6/16\" which is the nearest closest Sixteenth fraction." ) );
1116 grid->addWidget(fraction,6,0);
1117
1118 date=new TQRadioButton(i18n("Date format"),grp);
1119 TQWhatsThis::add(date, i18n( "To enter a date, you should enter it in one of the formats set in KControl in Regional & Accessibility ->Time & Dates. There are two formats set here: the date format and the short date format.\nJust like you can drag down numbers you can also drag down dates and the next cells will also get dates." ) );
1120 grid->addWidget(date,7,0);
1121
1122 time=new TQRadioButton(i18n("Time format"),grp);
1123 TQWhatsThis::add(time, i18n( "This formats your cell content as a time. To enter a time, you should enter it in the Time format set in KControl in Regional & Accessibility ->Time & Dates. In the Cell Format dialog box you can set how the time should be displayed by choosing one of the available time format options. The default format is the system format set in KControl. When the number in the cell does not make sense as a time, KSpread will display 00:00 in the global format you have in KControl." ) );
1124 grid->addWidget(time,8,0);
1125
1126 textFormat=new TQRadioButton(i18n("Text"),grp);
1127 TQWhatsThis::add(textFormat, i18n( "This formats your cell content as text. This can be useful if you want a number treated as text instead as a number, for example for a ZIP code. Setting a number as text format will left justify it. When numbers are formatted as text, they cannot be used in calculations or formulas. It also change the way the cell is justified." ) );
1128 grid->addWidget(textFormat,9,0);
1129
1130 customFormat=new TQRadioButton(i18n("Custom"),grp);
1131 TQWhatsThis::add(customFormat, i18n( "The custom format does not work yet. To be enabled in the next release." ) );
1132 grid->addWidget(customFormat,10,0);
1133 customFormat->setEnabled( false );
1134
1135 TQGroupBox *box2 = new TQGroupBox( grp, "Box");
1136 box2->setTitle(i18n("Preview"));
1137 TQGridLayout *grid3 = new TQGridLayout(box2,1,3,KDialog::marginHint(), KDialog::spacingHint());
1138
1139 exampleLabel=new TQLabel(box2);
1140 TQWhatsThis::add(exampleLabel, i18n( "This will display a preview of your choice so you can know what it does before clicking the OK button to validate it." ) );
1141 grid3->addWidget(exampleLabel,0,1);
1142
1143 grid->addMultiCellWidget(box2,9,10,1,1);
1144
1145 customFormatEdit = new TQLineEdit( grp );
1146 grid->addMultiCellWidget( customFormatEdit, 1, 1, 1, 1 );
1147 customFormatEdit->setHidden( true );
1148
1149 listFormat=new TQListBox(grp);
1150 grid->addMultiCellWidget(listFormat,2,7,1,1);
1151 TQWhatsThis::add(listFormat, i18n( "Displays choices of format for the fraction, date or time formats." ) );
1152 layout->addWidget(grp);
1153
1154 /* *** */
1155
1156 TQGroupBox *box = new TQGroupBox( this, "Box");
1157
1158 grid = new TQGridLayout(box,3,4,KDialog::marginHint(), KDialog::spacingHint());
1159
1160 postfix = new TQLineEdit( box, "LineEdit_1" );
1161 TQWhatsThis::add(postfix, i18n( "You can add here a Postfix such as a $HK symbol to the end of each cell content in the checked format." ) );
1162 grid->addWidget(postfix,2,1);
1163 precision = new KIntNumInput( dlg->precision, box, 10 );
1164 precision->setSpecialValueText(i18n("variable"));
1165 precision->setRange(-1,10,1,false);
1166 TQWhatsThis::add(precision, i18n( "You can control how many digits are displayed after the decimal point for numeric values. This can also be changed using the Increase precision or Decrease precision icons in the Format toolbar. " ) );
1167 grid->addWidget(precision,1,1);
1168
1169 prefix = new TQLineEdit( box, "LineEdit_3" );
1170 TQWhatsThis::add(prefix, i18n( "You can add here a Prefix such as a $ symbol at the start of each cell content in the checked format." ) );
1171 grid->addWidget(prefix,0,1);
1172
1173 format = new TQComboBox( box, "ListBox_1" );
1174 TQWhatsThis::add(format, i18n( "You can choose whether positive values are displayed with a leading + sign and whether negative values are shown in red." ) );
1175 grid->addWidget(format,0,3);
1176
1177 TQLabel* tmpTQLabel;
1178 tmpTQLabel = new TQLabel( box, "Label_1" );
1179 grid->addWidget(tmpTQLabel,2,0);
1180 tmpTQLabel->setText( i18n("Postfix:") );
1181
1182 postfix->setText( dlg->postfix );
1183
1184 tmpTQLabel = new TQLabel( box, "Label_2" );
1185 grid->addWidget(tmpTQLabel,0,0);
1186
1187 tmpTQLabel->setText( i18n("Prefix:") );
1188 tmpTQLabel = new TQLabel( box, "Label_3" );
1189 grid->addWidget(tmpTQLabel,1,0);
1190 tmpTQLabel->setText( i18n("Precision:") );
1191
1192 prefix->setText( dlg->prefix );
1193
1194 format->insertItem( *_dlg->formatOnlyNegSignedPixmap, 0 );
1195 format->insertItem( *_dlg->formatRedOnlyNegSignedPixmap, 1 );
1196 format->insertItem( *_dlg->formatRedNeverSignedPixmap, 2 );
1197 format->insertItem( *_dlg->formatAlwaysSignedPixmap, 3 );
1198 format->insertItem( *_dlg->formatRedAlwaysSignedPixmap, 4 );
1199
1200 tmpTQLabel = new TQLabel( box, "Label_4" );
1201 grid->addWidget(tmpTQLabel, 0, 2);
1202 tmpTQLabel->setText( i18n("Format:") );
1203
1204 currencyLabel = new TQLabel( box, "LabelCurrency" );
1205 grid->addWidget(currencyLabel, 1, 2);
1206 currencyLabel->setText( i18n("Currency:") );
1207
1208 currency = new TQComboBox( box, "ComboCurrency" );
1209 grid->addWidget(currency, 1, 3);
1210
1211 currency->insertItem( i18n("Automatic") );
1212
1213 int index = 2; //ignore first two in the list
1214 bool ok = true;
1215 TQString text;
1216
1217 while ( ok )
1218 {
1219 text = Currency::getChooseString( index, ok );
1220 if ( ok )
1221 {
1222 currency->insertItem( text );
1223 }
1224 else
1225 {
1226 break;
1227 }
1228
1229 ++index;
1230 }
1231
1232 currency->setCurrentItem( 0 );
1233 currency->hide();
1234 currencyLabel->hide();
1235
1236 if ( !dlg->bFloatFormat || !dlg->bFloatColor )
1237 format->setCurrentItem( 5 );
1238 else if ( dlg->floatFormat == Format::OnlyNegSigned && dlg->floatColor == Format::AllBlack )
1239 format->setCurrentItem( 0 );
1240 else if ( dlg->floatFormat == Format::OnlyNegSigned && dlg->floatColor == Format::NegRed )
1241 format->setCurrentItem( 1 );
1242 else if ( dlg->floatFormat == Format::AlwaysUnsigned && dlg->floatColor == Format::NegRed )
1243 format->setCurrentItem( 2 );
1244 else if ( dlg->floatFormat == Format::AlwaysSigned && dlg->floatColor == Format::AllBlack )
1245 format->setCurrentItem( 3 );
1246 else if ( dlg->floatFormat == Format::AlwaysSigned && dlg->floatColor == Format::NegRed )
1247 format->setCurrentItem( 4 );
1248 layout->addWidget(box);
1249
1250 cellFormatType=dlg->formatType;
1251 newFormatType = cellFormatType;
1252
1253 if (!cellFormatType)
1254 generic->setChecked(true);
1255 else
1256 {
1257 if (cellFormatType==Number_format)
1258 number->setChecked(true);
1259 else if (cellFormatType==Percentage_format)
1260 percent->setChecked(true);
1261 else if (cellFormatType==Money_format)
1262 {
1263 money->setChecked(true);
1264 currencyLabel->show();
1265 currency->show();
1266 if (dlg->bCurrency)
1267 {
1268 TQString tmp;
1269 if (dlg->cCurrency.type != 1)
1270 {
1271 Currency curr(dlg->cCurrency.type);
1272 bool ok = true;
1273 tmp = Currency::getChooseString(dlg->cCurrency.type, ok);
1274 if ( !ok )
1275 tmp = dlg->cCurrency.symbol;
1276 }
1277 else
1278 tmp = dlg->cCurrency.symbol;
1279 currency->setCurrentText( tmp );
1280 }
1281 }
1282 else if ( cellFormatType == Scientific_format )
1283 scientific->setChecked(true);
1284 else if ( formatIsDate (cellFormatType) )
1285 date->setChecked(true);
1286 else if ( formatIsTime (cellFormatType) )
1287 time->setChecked(true);
1288 else if ( formatIsFraction (cellFormatType) )
1289 fraction->setChecked(true);
1290 else if (cellFormatType == Text_format)
1291 textFormat->setChecked(true);
1292 else if (cellFormatType == Custom_format)
1293 customFormat->setChecked(true);
1294 }
1295
1296 connect(generic,TQ_SIGNAL(clicked ()),this,TQ_SLOT(slotChangeState()));
1297 connect(fraction,TQ_SIGNAL(clicked ()),this,TQ_SLOT(slotChangeState()));
1298 connect(money,TQ_SIGNAL(clicked ()),this,TQ_SLOT(slotChangeState()));
1299 connect(date,TQ_SIGNAL(clicked ()),this,TQ_SLOT(slotChangeState()));
1300 connect(scientific,TQ_SIGNAL(clicked ()),this,TQ_SLOT(slotChangeState()));
1301 connect(number,TQ_SIGNAL(clicked ()),this,TQ_SLOT(slotChangeState()));
1302 connect(percent,TQ_SIGNAL(clicked ()),this,TQ_SLOT(slotChangeState()));
1303 connect(time,TQ_SIGNAL(clicked ()),this,TQ_SLOT(slotChangeState()));
1304 connect(textFormat,TQ_SIGNAL(clicked()),this,TQ_SLOT(slotChangeState()));
1305 connect(customFormat,TQ_SIGNAL(clicked()),this,TQ_SLOT(slotChangeState()));
1306
1307 connect(listFormat,TQ_SIGNAL(selectionChanged ()),this,TQ_SLOT(makeformat()));
1308 connect(precision,TQ_SIGNAL(valueChanged(int)),this,TQ_SLOT(slotChangeValue(int)));
1309 connect(prefix,TQ_SIGNAL(textChanged ( const TQString & ) ),this,TQ_SLOT(makeformat()));
1310 connect(postfix,TQ_SIGNAL(textChanged ( const TQString & ) ),this,TQ_SLOT(makeformat()));
1311 connect(currency,TQ_SIGNAL(activated ( const TQString & ) ),this, TQ_SLOT(currencyChanged(const TQString &)));
1312 connect(format,TQ_SIGNAL(activated ( int ) ),this,TQ_SLOT(formatChanged(int)));
1313 connect(format, TQ_SIGNAL(activated(int)), this, TQ_SLOT(makeformat()));
1314 slotChangeState();
1315 m_bFormatColorChanged=false;
1316 m_bFormatTypeChanged=false;
1317 this->resize( 400, 400 );
1318}
1319
1320void CellFormatPageFloat::formatChanged(int)
1321{
1322 m_bFormatColorChanged=true;
1323}
1324
1325void CellFormatPageFloat::slotChangeValue(int)
1326{
1327 makeformat();
1328}
1329void CellFormatPageFloat::slotChangeState()
1330{
1331 TQStringList list;
1332 listFormat->clear();
1333 currency->hide();
1334 currencyLabel->hide();
1335
1336 // start with enabled, they get disabled when inappropriate further down
1337 precision->setEnabled(true);
1338 prefix->setEnabled(true);
1339 postfix->setEnabled(true);
1340 format->setEnabled(true);
1341
1342 if (generic->isChecked() || number->isChecked() || percent->isChecked() ||
1343 scientific->isChecked() || textFormat->isChecked())
1344 listFormat->setEnabled(false);
1345 else if (money->isChecked())
1346 {
1347 listFormat->setEnabled(false);
1348 precision->setValue(2);
1349 currency->show();
1350 currencyLabel->show();
1351 }
1352 else if (date->isChecked())
1353 {
1354 format->setEnabled(false);
1355 precision->setEnabled(false);
1356 prefix->setEnabled(false);
1357 postfix->setEnabled(false);
1358 listFormat->setEnabled(true);
1359 init();
1360 }
1361 else if (fraction->isChecked())
1362 {
1363 precision->setEnabled(false);
1364 listFormat->setEnabled(true);
1365 list+=i18n("Halves 1/2");
1366 list+=i18n("Quarters 1/4");
1367 list+=i18n("Eighths 1/8");
1368 list+=i18n("Sixteenths 1/16");
1369 list+=i18n("Tenths 1/10");
1370 list+=i18n("Hundredths 1/100");
1371 list+=i18n("One digit 5/9");
1372 list+=i18n("Two digits 15/22");
1373 list+=i18n("Three digits 153/652");
1374 listFormat->insertStringList(list);
1375 if (cellFormatType == fraction_half)
1376 listFormat->setCurrentItem(0);
1377 else if (cellFormatType == fraction_quarter)
1378 listFormat->setCurrentItem(1);
1379 else if (cellFormatType == fraction_eighth )
1380 listFormat->setCurrentItem(2);
1381 else if (cellFormatType == fraction_sixteenth )
1382 listFormat->setCurrentItem(3);
1383 else if (cellFormatType == fraction_tenth )
1384 listFormat->setCurrentItem(4);
1385 else if (cellFormatType == fraction_hundredth )
1386 listFormat->setCurrentItem(5);
1387 else if (cellFormatType == fraction_one_digit )
1388 listFormat->setCurrentItem(6);
1389 else if (cellFormatType == fraction_two_digits )
1390 listFormat->setCurrentItem(7);
1391 else if (cellFormatType == fraction_three_digits )
1392 listFormat->setCurrentItem(8);
1393 else
1394 listFormat->setCurrentItem(0);
1395 }
1396 else if (time->isChecked())
1397 {
1398 precision->setEnabled(false);
1399 prefix->setEnabled(false);
1400 postfix->setEnabled(false);
1401 format->setEnabled(false);
1402 listFormat->setEnabled(true);
1403
1404
1405 list+=i18n("System: ")+dlg->locale()->formatTime(TQTime::currentTime(),false);
1406 list+=i18n("System: ")+dlg->locale()->formatTime(TQTime::currentTime(),true);
1407 TQDateTime tmpTime (TQDate (1, 1, 1900), TQTime (10, 35, 25));
1408
1409
1410 ValueFormatter *fmt = dlg->getDoc()->formatter();
1411 list+= fmt->timeFormat(tmpTime, Time_format1);
1412 list+= fmt->timeFormat(tmpTime, Time_format2);
1413 list+= fmt->timeFormat(tmpTime, Time_format3);
1414 list+= fmt->timeFormat(tmpTime, Time_format4);
1415 list+= fmt->timeFormat(tmpTime, Time_format5);
1416 list+= ( fmt->timeFormat(tmpTime, Time_format6) + i18n(" (=[mm]::ss)") );
1417 list+= ( fmt->timeFormat(tmpTime, Time_format7) + i18n(" (=[hh]::mm::ss)") );
1418 list+= ( fmt->timeFormat(tmpTime, Time_format8) + i18n(" (=[hh]::mm)") );
1419 listFormat->insertStringList(list);
1420
1421 if ( cellFormatType == Time_format )
1422 listFormat->setCurrentItem(0);
1423 else if (cellFormatType == SecondeTime_format)
1424 listFormat->setCurrentItem(1);
1425 else if (cellFormatType == Time_format1)
1426 listFormat->setCurrentItem(2);
1427 else if (cellFormatType == Time_format2)
1428 listFormat->setCurrentItem(3);
1429 else if (cellFormatType == Time_format3)
1430 listFormat->setCurrentItem(4);
1431 else if (cellFormatType == Time_format4)
1432 listFormat->setCurrentItem(5);
1433 else if (cellFormatType == Time_format5)
1434 listFormat->setCurrentItem(6);
1435 else if (cellFormatType == Time_format6)
1436 listFormat->setCurrentItem(7);
1437 else if (cellFormatType == Time_format7)
1438 listFormat->setCurrentItem(8);
1439 else if (cellFormatType == Time_format8)
1440 listFormat->setCurrentItem(9);
1441 else
1442 listFormat->setCurrentItem(0);
1443 }
1444
1445 if (customFormat->isChecked())
1446 {
1447 customFormatEdit->setHidden( false );
1448 precision->setEnabled(false);
1449 prefix->setEnabled(false);
1450 postfix->setEnabled(false);
1451 format->setEnabled(false);
1452 listFormat->setEnabled(true);
1453 }
1454 else
1455 customFormatEdit->setHidden( true );
1456
1457 m_bFormatTypeChanged=true;
1458
1459 makeformat();
1460}
1461
1462void CellFormatPageFloat::init()
1463{
1464 TQStringList list;
1465 TQString tmp;
1466 TQString tmp2;
1467 TQDate tmpDate( 2000,2,18);
1468 list+=i18n("System: ")+dlg->locale()->formatDate (TQDate::currentDate(), true);
1469 list+=i18n("System: ")+dlg->locale()->formatDate (TQDate::currentDate(), false);
1470
1471 ValueFormatter *fmt = dlg->getDoc()->formatter();
1472
1473 /*18-Feb-00*/
1474 list+=fmt->dateFormat( tmpDate, date_format1);
1475 /*18-Feb-1999*/
1476 list+=fmt->dateFormat( tmpDate, date_format2);
1477 /*18-Feb*/
1478 list+=fmt->dateFormat( tmpDate, date_format3);
1479 /*18-2*/
1480 list+=fmt->dateFormat( tmpDate, date_format4);
1481 /*18/2/00*/
1482 list+=fmt->dateFormat( tmpDate, date_format5);
1483 /*18/5/1999*/
1484 list+=fmt->dateFormat( tmpDate, date_format6);
1485 /*Feb-99*/
1486 list+=fmt->dateFormat( tmpDate, date_format7);
1487 /*February-99*/
1488 list+=fmt->dateFormat( tmpDate, date_format8);
1489 /*February-1999*/
1490 list+=fmt->dateFormat( tmpDate, date_format9);
1491 /*F-99*/
1492 list+=fmt->dateFormat( tmpDate, date_format10);
1493 /*18/Feb*/
1494 list+=fmt->dateFormat( tmpDate, date_format11);
1495 /*18/2*/
1496 list+=fmt->dateFormat( tmpDate, date_format12);
1497 /*18/Feb/1999*/
1498 list+=fmt->dateFormat( tmpDate, date_format13);
1499 /*2000/Feb/18*/
1500 list+=fmt->dateFormat( tmpDate, date_format14);
1501 /*2000-Feb-18*/
1502 list+=fmt->dateFormat( tmpDate, date_format15);
1503 /*2000-2-18*/
1504 list+=fmt->dateFormat( tmpDate, date_format16);
1505 /*2 february 2000*/
1506 list+=fmt->dateFormat( tmpDate, date_format17);
1507 list+=fmt->dateFormat( tmpDate, date_format18);
1508 list+=fmt->dateFormat( tmpDate, date_format19);
1509 list+=fmt->dateFormat( tmpDate, date_format20);
1510 list+=fmt->dateFormat( tmpDate, date_format21);
1511 list+=fmt->dateFormat( tmpDate, date_format22);
1512 list+=fmt->dateFormat( tmpDate, date_format23);
1513 list+=fmt->dateFormat( tmpDate, date_format24);
1514 list+=fmt->dateFormat( tmpDate, date_format25);
1515 list+=fmt->dateFormat( tmpDate, date_format26);
1516
1517 listFormat->insertStringList(list);
1518 if ( cellFormatType == ShortDate_format )
1519 listFormat->setCurrentItem(0);
1520 else if (cellFormatType == TextDate_format)
1521 listFormat->setCurrentItem(1);
1522 else if (cellFormatType == date_format1)
1523 listFormat->setCurrentItem(2);
1524 else if (cellFormatType == date_format2)
1525 listFormat->setCurrentItem(3);
1526 else if (cellFormatType == date_format3)
1527 listFormat->setCurrentItem(4);
1528 else if (cellFormatType == date_format4)
1529 listFormat->setCurrentItem(5);
1530 else if (cellFormatType == date_format5)
1531 listFormat->setCurrentItem(6);
1532 else if (cellFormatType == date_format6)
1533 listFormat->setCurrentItem(7);
1534 else if (cellFormatType == date_format7)
1535 listFormat->setCurrentItem(8);
1536 else if (cellFormatType == date_format8)
1537 listFormat->setCurrentItem(9);
1538 else if (cellFormatType == date_format9)
1539 listFormat->setCurrentItem(10);
1540 else if (cellFormatType == date_format10)
1541 listFormat->setCurrentItem(11);
1542 else if (cellFormatType == date_format11)
1543 listFormat->setCurrentItem(12);
1544 else if (cellFormatType == date_format12)
1545 listFormat->setCurrentItem(13);
1546 else if (cellFormatType == date_format13)
1547 listFormat->setCurrentItem(14);
1548 else if (cellFormatType == date_format14)
1549 listFormat->setCurrentItem(15);
1550 else if (cellFormatType == date_format15)
1551 listFormat->setCurrentItem(16);
1552 else if (cellFormatType == date_format16)
1553 listFormat->setCurrentItem(17);
1554 else if (cellFormatType == date_format17)
1555 listFormat->setCurrentItem(18);
1556 else if (cellFormatType == date_format18)
1557 listFormat->setCurrentItem(19);
1558 else if (cellFormatType == date_format19)
1559 listFormat->setCurrentItem(20);
1560 else if (cellFormatType == date_format20)
1561 listFormat->setCurrentItem(21);
1562 else if (cellFormatType == date_format21)
1563 listFormat->setCurrentItem(22);
1564 else if (cellFormatType == date_format22)
1565 listFormat->setCurrentItem(23);
1566 else if (cellFormatType == date_format23)
1567 listFormat->setCurrentItem(24);
1568 else if (cellFormatType == date_format24)
1569 listFormat->setCurrentItem(25);
1570 else if (cellFormatType == date_format25)
1571 listFormat->setCurrentItem(26);
1572 else if (cellFormatType == date_format26)
1573 listFormat->setCurrentItem(27);
1574 else
1575 listFormat->setCurrentItem(0);
1576
1577}
1578
1579void CellFormatPageFloat::currencyChanged(const TQString &)
1580{
1581 int index = currency->currentItem();
1582 if (index > 0)
1583 ++index;
1584 dlg->cCurrency.symbol = Currency::getDisplaySymbol(index);
1585 dlg->cCurrency.type = index;
1586
1587 makeformat();
1588}
1589
1590void CellFormatPageFloat::updateFormatType ()
1591{
1592 if (generic->isChecked())
1593 newFormatType = Generic_format;
1594 else if (number->isChecked())
1595 newFormatType = Number_format;
1596 else if (percent->isChecked())
1597 newFormatType = Percentage_format;
1598 else if (date->isChecked())
1599 {
1600 newFormatType=ShortDate_format;
1601 switch (listFormat->currentItem())
1602 {
1603 case 0: newFormatType=ShortDate_format; break;
1604 case 1: newFormatType=TextDate_format; break;
1605 case 2: newFormatType=date_format1; break; /*18-Feb-99*/
1606 case 3: newFormatType=date_format2; break; /*18-Feb-1999*/
1607 case 4: newFormatType=date_format3; break; /*18-Feb*/
1608 case 5: newFormatType=date_format4; break; /*18-05*/
1609 case 6: newFormatType=date_format5; break; /*18/05/00*/
1610 case 7: newFormatType=date_format6; break; /*18/05/1999*/
1611 case 8: newFormatType=date_format7; break;/*Feb-99*/
1612 case 9: newFormatType=date_format8; break; /*February-99*/
1613 case 10: newFormatType=date_format9; break; /*February-1999*/
1614 case 11: newFormatType=date_format10; break; /*F-99*/
1615 case 12: newFormatType=date_format11; break; /*18/Feb*/
1616 case 13: newFormatType=date_format12; break; /*18/02*/
1617 case 14: newFormatType=date_format13; break; /*18/Feb/1999*/
1618 case 15: newFormatType=date_format14; break; /*2000/Feb/18*/
1619 case 16: newFormatType=date_format15; break;/*2000-Feb-18*/
1620 case 17: newFormatType=date_format16; break;/*2000-02-18*/
1621 case 18: newFormatType=date_format17; break; /*2000-02-18*/
1622 case 19: newFormatType=date_format18; break;
1623 case 20: newFormatType=date_format19; break;
1624 case 21: newFormatType=date_format20; break;
1625 case 22: newFormatType=date_format21; break;
1626 case 23: newFormatType=date_format22; break;
1627 case 24: newFormatType=date_format23; break;
1628 case 25: newFormatType=date_format24; break;
1629 case 26: newFormatType=date_format25; break;
1630 case 27: newFormatType=date_format26; break;
1631 }
1632 }
1633 else if (money->isChecked())
1634 newFormatType = Money_format;
1635 else if (scientific->isChecked())
1636 newFormatType = Scientific_format;
1637 else if (fraction->isChecked())
1638 {
1639 newFormatType=fraction_half;
1640 switch (listFormat->currentItem())
1641 {
1642 case 0: newFormatType=fraction_half; break;
1643 case 1: newFormatType=fraction_quarter; break;
1644 case 2: newFormatType=fraction_eighth; break;
1645 case 3: newFormatType=fraction_sixteenth; break;
1646 case 4: newFormatType=fraction_tenth; break;
1647 case 5: newFormatType=fraction_hundredth; break;
1648 case 6: newFormatType=fraction_one_digit; break;
1649 case 7: newFormatType=fraction_two_digits; break;
1650 case 8: newFormatType=fraction_three_digits; break;
1651 }
1652 }
1653 else if (time->isChecked())
1654 {
1655 newFormatType=Time_format;
1656 switch (listFormat->currentItem())
1657 {
1658 case 0: newFormatType=Time_format; break;
1659 case 1: newFormatType=SecondeTime_format; break;
1660 case 2: newFormatType=Time_format1; break;
1661 case 3: newFormatType=Time_format2; break;
1662 case 4: newFormatType=Time_format3; break;
1663 case 5: newFormatType=Time_format4; break;
1664 case 6: newFormatType=Time_format5; break;
1665 case 7: newFormatType=Time_format6; break;
1666 case 8: newFormatType=Time_format7; break;
1667 case 9: newFormatType=Time_format8; break;
1668 }
1669 }
1670 else if (textFormat->isChecked())
1671 newFormatType = Text_format;
1672 else if (customFormat->isChecked())
1673 newFormatType = Custom_format;
1674}
1675
1676void CellFormatPageFloat::makeformat()
1677{
1678 m_bFormatTypeChanged=true;
1679 TQString tmp;
1680
1681 updateFormatType();
1682 TQColor color;
1683 Format::FloatFormat floatFormat = Format::OnlyNegSigned;
1684 switch( format->currentItem() )
1685 {
1686 case 0:
1687 floatFormat = Format::OnlyNegSigned;
1688 color = black;
1689 break;
1690 case 1:
1691 floatFormat = Format::OnlyNegSigned;
1692 color = TQt::red;
1693 break;
1694 case 2:
1695 floatFormat = Format::AlwaysUnsigned;
1696 color = TQt::red;
1697 break;
1698 case 3:
1699 floatFormat = Format::AlwaysSigned;
1700 color = black;
1701 break;
1702 case 4:
1703 floatFormat = Format::AlwaysSigned;
1704 color = TQt::red;
1705 break;
1706 }
1707 if (!dlg->value.isNumber() || dlg->value.asFloat() >= 0 || !format->isEnabled())
1708 {
1709 color = black;
1710 }
1711 ValueFormatter *fmt = dlg->getDoc()->formatter();
1712 tmp = fmt->formatText(dlg->value, newFormatType, precision->value(),
1713 floatFormat,
1714 prefix->isEnabled() ? prefix->text() : TQString(),
1715 postfix->isEnabled() ? postfix->text() : TQString(),
1716 newFormatType == Money_format ? dlg->cCurrency.symbol : TQString());
1717 if (tmp.length() > 50)
1718 tmp = tmp.left (50);
1719 exampleLabel->setText(tmp.prepend("<font color=" + color.name() + ">").append("</font>"));
1720}
1721
1722void CellFormatPageFloat::apply( CustomStyle * style )
1723{
1724 if ( postfix->text() != dlg->postfix )
1725 {
1726 if ( postfix->isEnabled())
1727 style->changePostfix( postfix->text() );
1728 else
1729 style->changePostfix( "" );
1730 }
1731 if ( prefix->text() != dlg->prefix )
1732 {
1733 if (prefix->isEnabled())
1734 style->changePrefix( prefix->text() );
1735 else
1736 style->changePrefix( "" );
1737 }
1738
1739 if ( dlg->precision != precision->value() )
1740 style->changePrecision( precision->value() );
1741
1742 if ( m_bFormatColorChanged )
1743 {
1744 switch( format->currentItem() )
1745 {
1746 case 0:
1747 style->changeFloatFormat( Format::OnlyNegSigned );
1748 style->changeFloatColor( Format::AllBlack );
1749 break;
1750 case 1:
1751 style->changeFloatFormat( Format::OnlyNegSigned );
1752 style->changeFloatColor( Format::NegRed );
1753 break;
1754 case 2:
1755 style->changeFloatFormat( Format::AlwaysUnsigned );
1756 style->changeFloatColor( Format::NegRed );
1757 break;
1758 case 3:
1759 style->changeFloatFormat( Format::AlwaysSigned );
1760 style->changeFloatColor( Format::AllBlack );
1761 break;
1762 case 4:
1763 style->changeFloatFormat( Format::AlwaysSigned );
1764 style->changeFloatColor( Format::NegRed );
1765 break;
1766 }
1767 }
1768 if ( m_bFormatTypeChanged )
1769 {
1770 style->changeFormatType (newFormatType);
1771 if ( money->isChecked() )
1772 {
1773 Format::Currency cur;
1774 int index = currency->currentItem();
1775 if (index == 0)
1776 {
1777 if ( currency->currentText() == i18n( "Automatic" ) )
1778 {
1779 cur.symbol = dlg->locale()->currencySymbol();
1780 cur.type = 0;
1781 }
1782 else
1783 {
1784 cur.type = 1;
1785 cur.symbol = currency->currentText();
1786 }
1787 }
1788 else
1789 {
1790 cur.type = ++index;
1791 cur.symbol = Currency::getDisplaySymbol( index );
1792 }
1793
1794 style->changeCurrency( cur );
1795 }
1796 }
1797}
1798
1799void CellFormatPageFloat::apply(FormatManipulator* _obj)
1800{
1801 if ( postfix->text() != dlg->postfix )
1802 if ( postfix->isEnabled())
1803 {
1804 // If we are in here it *never* can be disabled - FIXME (Werner)!
1805 if ( postfix->isEnabled())
1806 _obj->setPostfix( postfix->text() );
1807 else
1808 _obj->setPostfix( "" );
1809 }
1810 if ( prefix->text() != dlg->prefix )
1811 if (prefix->isEnabled())
1812 _obj->setPrefix( prefix->text() );
1813 else
1814 _obj->setPrefix( "" );
1815
1816 if ( dlg->precision != precision->value() )
1817 _obj->setPrecision( precision->value() );
1818
1819 if (m_bFormatColorChanged)
1820 {
1821 switch( format->currentItem() )
1822 {
1823 case 0:
1824 _obj->setFloatFormat( Format::OnlyNegSigned );
1825 _obj->setFloatColor( Format::AllBlack );
1826 break;
1827 case 1:
1828 _obj->setFloatFormat( Format::OnlyNegSigned );
1829 _obj->setFloatColor( Format::NegRed );
1830 break;
1831 case 2:
1832 _obj->setFloatFormat( Format::AlwaysUnsigned );
1833 _obj->setFloatColor( Format::NegRed );
1834 break;
1835 case 3:
1836 _obj->setFloatFormat( Format::AlwaysSigned );
1837 _obj->setFloatColor( Format::AllBlack );
1838 break;
1839 case 4:
1840 _obj->setFloatFormat( Format::AlwaysSigned );
1841 _obj->setFloatColor( Format::NegRed );
1842 break;
1843 }
1844 }
1845 if (m_bFormatTypeChanged)
1846 {
1847 _obj->setFormatType (newFormatType);
1848 if (money->isChecked())
1849 {
1850 Format::Currency cur;
1851 int index = currency->currentItem();
1852 if (index == 0)
1853 {
1854 if ( currency->currentText() == i18n( "Automatic" ) )
1855 {
1856 cur.symbol = dlg->locale()->currencySymbol();
1857 cur.type = 0;
1858 }
1859 else
1860 {
1861 cur.type = 1;
1862 cur.symbol = currency->currentText();
1863 }
1864 }
1865 else
1866 {
1867 cur.type = ++index;
1868 cur.symbol = Currency::getDisplaySymbol( index );
1869 }
1870
1871 _obj->setCurrency( cur.type, cur.symbol );
1872 }
1873 }
1874}
1875
1876
1877
1878/***************************************************************************
1879 *
1880 * CellFormatPageProtection
1881 *
1882 ***************************************************************************/
1883
1884CellFormatPageProtection::CellFormatPageProtection( TQWidget* parent, CellFormatDialog * _dlg )
1885 : ProtectionTab( parent ),
1886 m_dlg( _dlg )
1887{
1888 m_bDontPrint->setChecked( m_dlg->bDontPrintText );
1889 m_bHideAll->setChecked( m_dlg->bHideAll );
1890 m_bHideFormula->setChecked( m_dlg->bHideFormula );
1891 m_bIsProtected->setChecked( m_dlg->bIsProtected );
1892}
1893
1894CellFormatPageProtection::~CellFormatPageProtection()
1895{
1896}
1897
1898void CellFormatPageProtection::apply( CustomStyle * style )
1899{
1900 if ( m_dlg->bDontPrintText != m_bDontPrint->isChecked() )
1901 {
1902 if ( m_bDontPrint->isChecked() )
1903 style->addProperty( Style::PDontPrintText );
1904 else
1905 style->removeProperty( Style::PDontPrintText );
1906 }
1907
1908 if ( m_dlg->bIsProtected != m_bIsProtected->isChecked() )
1909 {
1910 if ( !m_bIsProtected->isChecked() )
1911 style->addProperty( Style::PNotProtected );
1912 else
1913 style->removeProperty( Style::PNotProtected );
1914 }
1915
1916 if ( m_dlg->bHideAll != m_bHideAll->isChecked() )
1917 {
1918 if ( m_bHideAll->isChecked() )
1919 style->addProperty( Style::PHideAll );
1920 else
1921 style->removeProperty( Style::PHideAll );
1922 }
1923
1924 if ( m_dlg->bHideFormula != m_bHideFormula->isChecked() )
1925 {
1926 if ( m_bHideFormula->isChecked() )
1927 style->addProperty( Style::PHideFormula );
1928 else
1929 style->removeProperty( Style::PHideFormula );
1930 }
1931}
1932
1933void CellFormatPageProtection::apply(FormatManipulator* _obj)
1934{
1935 if ( m_dlg->bDontPrintText != m_bDontPrint->isChecked())
1936 _obj->setDontPrintText( m_bDontPrint->isChecked() );
1937
1938 if ( m_dlg->bIsProtected != m_bIsProtected->isChecked())
1939 _obj->setNotProtected( !m_bIsProtected->isChecked() );
1940
1941 if ( m_dlg->bHideAll != m_bHideAll->isChecked())
1942 _obj->setHideAll( m_bHideAll->isChecked() );
1943
1944 if ( m_dlg->bHideFormula != m_bHideFormula->isChecked())
1945 _obj->setHideFormula( m_bHideFormula->isChecked() );
1946}
1947
1948
1949
1950/***************************************************************************
1951 *
1952 * CellFormatPageFont
1953 *
1954 ***************************************************************************/
1955
1956CellFormatPageFont::CellFormatPageFont( TQWidget* parent, CellFormatDialog *_dlg ) : FontTab( parent )
1957{
1958 dlg = _dlg;
1959
1960 bTextColorUndefined = !dlg->bTextColor;
1961
1962 connect( textColorButton, TQ_SIGNAL( changed( const TQColor & ) ),
1963 this, TQ_SLOT( slotSetTextColor( const TQColor & ) ) );
1964
1965
1966 TQStringList tmpListFont;
1967 TQFontDatabase *fontDataBase = new TQFontDatabase();
1968 tmpListFont = fontDataBase->families();
1969 delete fontDataBase;
1970
1971 family_combo->insertStringList( tmpListFont);
1972 selFont = dlg->textFont;
1973
1974 if ( dlg->bTextFontFamily )
1975 {
1976 selFont.setFamily( dlg->textFontFamily );
1977 kdDebug(36001) << "Family = " << dlg->textFontFamily << endl;
1978
1979 if ( !family_combo->findItem(dlg->textFontFamily))
1980 {
1981 family_combo->insertItem("",0);
1982 family_combo->setCurrentItem(0);
1983 }
1984 else
1985 family_combo->setCurrentItem(family_combo->index(family_combo->findItem(dlg->textFontFamily)));
1986 }
1987 else
1988 {
1989 family_combo->insertItem("",0);
1990 family_combo->setCurrentItem(0);
1991 }
1992
1993 connect( family_combo, TQ_SIGNAL(highlighted(const TQString &)),
1994 TQ_SLOT(family_chosen_slot(const TQString &)) );
1995
1996 TQStringList lst;
1997 lst.append("");
1998 for ( unsigned int i = 1; i < 100; ++i )
1999 lst.append( TQString( "%1" ).arg( i ) );
2000
2001 size_combo->insertStringList( lst );
2002
2003
2004 size_combo->setInsertionPolicy(TQComboBox::NoInsertion);
2005
2006 connect( size_combo, TQ_SIGNAL(activated(const TQString &)),
2007 TQ_SLOT(size_chosen_slot(const TQString &)) );
2008 connect( size_combo ,TQ_SIGNAL( textChanged(const TQString &)),
2009 this,TQ_SLOT(size_chosen_slot(const TQString &)));
2010
2011 connect( weight_combo, TQ_SIGNAL(activated(const TQString &)),
2012 TQ_SLOT(weight_chosen_slot(const TQString &)) );
2013
2014 connect( style_combo, TQ_SIGNAL(activated(const TQString &)),
2015 TQ_SLOT(style_chosen_slot(const TQString &)) );
2016
2017 strike->setChecked(dlg->strike);
2018 connect( strike, TQ_SIGNAL( clicked()),
2019 TQ_SLOT(strike_chosen_slot()) );
2020
2021 underline->setChecked(dlg->underline);
2022 connect( underline, TQ_SIGNAL( clicked()),
2023 TQ_SLOT(underline_chosen_slot()) );
2024
2025 example_label->setText(i18n("Dolor Ipse"));
2026
2027 connect(this,TQ_SIGNAL(fontSelected( const TQFont& )),
2028 this,TQ_SLOT(display_example( const TQFont&)));
2029
2030 setCombos();
2031 display_example( selFont );
2032 fontChanged=false;
2033 this->resize( 400, 400 );
2034}
2035
2036void CellFormatPageFont::slotSetTextColor( const TQColor &_color )
2037{
2038 textColor = _color;
2039 bTextColorUndefined = false;
2040}
2041
2042void CellFormatPageFont::apply( CustomStyle * style )
2043{
2044 if ( !bTextColorUndefined && textColor != dlg->textColor )
2045 style->changeTextColor( textColor );
2046
2047 if ( ( size_combo->currentItem() != 0 )
2048 && ( dlg->textFontSize != selFont.pointSize() ) )
2049 style->changeFontSize( selFont.pointSize() );
2050
2051 if ( ( selFont.family() != dlg->textFontFamily )
2052 && !family_combo->currentText().isEmpty() )
2053 style->changeFontFamily( selFont.family() );
2054
2055 uint flags = 0;
2056
2057 if ( weight_combo->currentItem() != 0 && selFont.bold() )
2058 flags |= Style::FBold;
2059 else
2060 flags &= ~(uint) Style::FBold;
2061
2062 if ( style_combo->currentItem() != 0 && selFont.italic() )
2063 flags |= Style::FItalic;
2064 else
2065 flags &= ~(uint) Style::FItalic;
2066
2067 if ( strike->isChecked() )
2068 flags |= Style::FStrike;
2069 else
2070 flags &= ~(uint) Style::FStrike;
2071
2072 if ( underline->isChecked() )
2073 flags |= Style::FUnderline;
2074 else
2075 flags &= ~(uint) Style::FUnderline;
2076
2077 style->changeFontFlags( flags );
2078}
2079
2080void CellFormatPageFont::apply(FormatManipulator* _obj)
2081{
2082 if ( !bTextColorUndefined && textColor != dlg->textColor )
2083 _obj->setTextColor( textColor );
2084 if (fontChanged)
2085 {
2086 if ( ( size_combo->currentItem() != 0 )
2087 && ( dlg->textFontSize != selFont.pointSize() ) )
2088 _obj->setFontSize( selFont.pointSize() );
2089 if ( ( selFont.family() != dlg->textFontFamily ) && ( !family_combo->currentText().isEmpty() ) )
2090 _obj->setFontFamily( selFont.family() );
2091 if ( weight_combo->currentItem() != 0 )
2092 _obj->setFontBold( selFont.bold() );
2093 if ( style_combo->currentItem() != 0 )
2094 _obj->setFontItalic( selFont.italic() );
2095 _obj->setFontStrike( strike->isChecked() );
2096 _obj->setFontUnderline(underline->isChecked() );
2097 }
2098}
2099
2100void CellFormatPageFont::underline_chosen_slot()
2101{
2102 selFont.setUnderline( underline->isChecked() );
2103 emit fontSelected(selFont);
2104}
2105
2106void CellFormatPageFont::strike_chosen_slot()
2107{
2108 selFont.setStrikeOut( strike->isChecked() );
2109 emit fontSelected(selFont);
2110}
2111
2112void CellFormatPageFont::family_chosen_slot(const TQString & family)
2113{
2114 selFont.setFamily(family);
2115 emit fontSelected(selFont);
2116}
2117
2118void CellFormatPageFont::size_chosen_slot(const TQString & size)
2119{
2120 TQString size_string = size;
2121
2122 selFont.setPointSize(size_string.toInt());
2123 emit fontSelected(selFont);
2124}
2125
2126void CellFormatPageFont::weight_chosen_slot(const TQString & weight)
2127{
2128 TQString weight_string = weight;
2129
2130 if ( weight_string == i18n("Normal"))
2131 selFont.setBold(false);
2132 if ( weight_string == i18n("Bold"))
2133 selFont.setBold(true);
2134 emit fontSelected(selFont);
2135}
2136
2137void CellFormatPageFont::style_chosen_slot(const TQString & style)
2138{
2139 TQString style_string = style;
2140
2141 if ( style_string == i18n("Roman"))
2142 selFont.setItalic(false);
2143 if ( style_string == i18n("Italic"))
2144 selFont.setItalic(true);
2145 emit fontSelected(selFont);
2146}
2147
2148
2149void CellFormatPageFont::display_example(const TQFont& font)
2150{
2151 TQString string;
2152 fontChanged=true;
2153 example_label->setFont(font);
2154 example_label->repaint();
2155}
2156
2157void CellFormatPageFont::setCombos()
2158{
2159 TQString string;
2160 TQComboBox* combo;
2161 int number_of_entries;
2162 bool found;
2163
2164 if ( dlg->bTextColor )
2165 textColor = dlg->textColor;
2166 else
2167 textColor = colorGroup().text();
2168
2169 if ( !textColor.isValid() )
2170 textColor =colorGroup().text();
2171
2172 textColorButton->setColor( textColor );
2173
2174
2175 combo = size_combo;
2176 if ( dlg->bTextFontSize )
2177 {
2178 kdDebug(36001) << "SIZE=" << dlg->textFontSize << endl;
2179 selFont.setPointSize( dlg->textFontSize );
2180 number_of_entries = size_combo->count();
2181 string.setNum( dlg->textFontSize );
2182 found = false;
2183
2184 for (int i = 0; i < number_of_entries ; i++){
2185 if ( string == (TQString) combo->text(i)){
2186 combo->setCurrentItem(i);
2187 found = true;
2188 // kdDebug(36001) << "Found Size " << string.data() << " setting to item " i << endl;
2189 break;
2190 }
2191 }
2192 }
2193 else
2194 combo->setCurrentItem( 0 );
2195
2196 if ( !dlg->bTextFontBold )
2197 weight_combo->setCurrentItem(0);
2198 else if ( dlg->textFontBold )
2199 {
2200 selFont.setBold( dlg->textFontBold );
2201 weight_combo->setCurrentItem(2);
2202 }
2203 else
2204 {
2205 selFont.setBold( dlg->textFontBold );
2206 weight_combo->setCurrentItem(1);
2207 }
2208
2209 if ( !dlg->bTextFontItalic )
2210 weight_combo->setCurrentItem(0);
2211 else if ( dlg->textFontItalic )
2212 {
2213 selFont.setItalic( dlg->textFontItalic );
2214 style_combo->setCurrentItem(2);
2215 }
2216 else
2217 {
2218 selFont.setItalic( dlg->textFontItalic );
2219 style_combo->setCurrentItem(1);
2220 }
2221}
2222
2223
2224
2225/***************************************************************************
2226 *
2227 * CellFormatPagePosition
2228 *
2229 ***************************************************************************/
2230
2231CellFormatPagePosition::CellFormatPagePosition( TQWidget* parent, CellFormatDialog *_dlg )
2232 : PositionTab(parent ),
2233 dlg( _dlg )
2234{
2235 if ( dlg->alignX == Format::Left )
2236 left->setChecked( true );
2237 else if ( dlg->alignX == Format::Center )
2238 center->setChecked( true );
2239 else if ( dlg->alignX == Format::Right )
2240 right->setChecked( true );
2241 else if ( dlg->alignX == Format::Undefined )
2242 standard->setChecked( true );
2243
2244 connect(horizontalGroup, TQ_SIGNAL(clicked(int)), this, TQ_SLOT(slotStateChanged(int)));
2245
2246 if ( dlg->alignY ==Format::Top )
2247 top->setChecked( true );
2248 else if ( dlg->alignY ==Format::Middle )
2249 middle->setChecked(true );
2250 else if ( dlg->alignY ==Format::Bottom )
2251 bottom->setChecked( true );
2252
2253 multi->setChecked(dlg->bMultiRow);
2254
2255 vertical->setChecked(dlg->bVerticalText);
2256
2257 angleRotation->setValue(-dlg->textRotation);//annma
2258 spinBox3->setValue(-dlg->textRotation);
2259 if ( dlg->textRotation != 0 )
2260 {
2261 multi->setEnabled(false );
2262 vertical->setEnabled(false);
2263 }
2264
2265 mergeCell->setChecked(dlg->isMerged);
2266 mergeCell->setEnabled(!dlg->oneCell && ((!dlg->isRowSelected) && (!dlg->isColumnSelected)));
2267
2268 TQGridLayout *grid2 = new TQGridLayout(indentGroup, 1, 1, KDialog::marginHint(), KDialog::spacingHint());
2269 grid2->addRowSpacing( 0, indentGroup->fontMetrics().height()/8 ); // groupbox title
2270 m_indent = new KoUnitDoubleSpinBox( indentGroup, 0.0, 400.0, 10.0,dlg->indent,dlg->getDoc()->unit() );
2271 grid2->addWidget(m_indent, 0, 0);
2272
2273 width = new KoUnitDoubleSpinBox( m_widthPanel );
2274 TQGridLayout *gridWidth = new TQGridLayout(m_widthPanel, 1, 1, 0, 0);
2275 gridWidth->addWidget(width, 0, 0);
2276 width->setValue ( dlg->widthSize );
2277 width->setUnit( dlg->getDoc()->unit() );
2278 //to ensure, that we don't get rounding problems, we store the displayed value (for later check for changes)
2279 dlg->widthSize = width->value();
2280
2281 if ( dlg->isRowSelected )
2282 width->setEnabled(false);
2283
2284 defaultWidth->setText(i18n("Default width (%1 %2)").arg(KoUnit::toUserValue(dlg->defaultWidthSize, dlg->getDoc()->unit()), 0, 'f', 2).arg(dlg->getDoc()->unitName()));
2285 if ( dlg->isRowSelected )
2286 defaultWidth->setEnabled(false);
2287
2288 height=new KoUnitDoubleSpinBox( m_heightPanel );
2289 TQGridLayout *gridHeight = new TQGridLayout(m_heightPanel, 1, 1, 0, 0);
2290 gridHeight->addWidget(height, 0, 0);
2291 height->setValue( dlg->heightSize );
2292 height->setUnit( dlg->getDoc()->unit() );
2293 //to ensure, that we don't get rounding problems, we store the displayed value (for later check for changes)
2294 dlg->heightSize = height->value();
2295
2296 if ( dlg->isColumnSelected )
2297 height->setEnabled(false);
2298
2299 defaultHeight->setText(i18n("Default height (%1 %2)").arg(KoUnit::toUserValue(dlg->defaultHeightSize, dlg->getDoc()->unit()), 0, 'f', 2).arg(dlg->getDoc()->unitName())); //annma
2300 if ( dlg->isColumnSelected )
2301 defaultHeight->setEnabled(false);
2302
2303 // in case we're editing a style, we disable the cell size settings
2304 if (dlg->getStyle())
2305 {
2306 defaultHeight->setEnabled(false);
2307 defaultWidth->setEnabled(false);
2308 }
2309
2310 connect(defaultWidth , TQ_SIGNAL(clicked() ),this, TQ_SLOT(slotChangeWidthState()));
2311 connect(defaultHeight , TQ_SIGNAL(clicked() ),this, TQ_SLOT(slotChangeHeightState()));
2312 connect(vertical , TQ_SIGNAL(clicked() ),this, TQ_SLOT(slotChangeVerticalState()));
2313 connect(multi , TQ_SIGNAL(clicked() ), this, TQ_SLOT(slotChangeMultiState()));
2314 connect(angleRotation, TQ_SIGNAL(valueChanged(int)), this, TQ_SLOT(slotChangeAngle(int)));
2315
2316 slotStateChanged( 0 );
2317 m_bOptionText = false;
2318 this->resize( 400, 400 );
2319}
2320
2321void CellFormatPagePosition::slotChangeMultiState()
2322{
2323 m_bOptionText = true;
2324 if (vertical->isChecked())
2325 {
2326 vertical->setChecked(false);
2327 }
2328}
2329
2330void CellFormatPagePosition::slotChangeVerticalState()
2331{
2332 m_bOptionText=true;
2333 if (multi->isChecked())
2334 {
2335 multi->setChecked(false);
2336 }
2337
2338}
2339
2340void CellFormatPagePosition::slotStateChanged(int)
2341{
2342 if (right->isChecked() || center->isChecked())
2343 m_indent->setEnabled(false);
2344 else
2345 m_indent->setEnabled(true);
2346}
2347
2348bool CellFormatPagePosition::getMergedCellState() const
2349{
2350 return mergeCell->isChecked();
2351}
2352
2353void CellFormatPagePosition::slotChangeWidthState()
2354{
2355 if ( defaultWidth->isChecked())
2356 width->setEnabled(false);
2357 else
2358 width->setEnabled(true);
2359}
2360
2361void CellFormatPagePosition::slotChangeHeightState()
2362{
2363 if ( defaultHeight->isChecked())
2364 height->setEnabled(false);
2365 else
2366 height->setEnabled(true);
2367}
2368
2369void CellFormatPagePosition::slotChangeAngle(int _angle)
2370{
2371 if ( _angle == 0 )
2372 {
2373 multi->setEnabled( true );
2374 vertical->setEnabled( true );
2375 }
2376 else
2377 {
2378 multi->setEnabled( false );
2379 vertical->setEnabled( false );
2380 }
2381}
2382
2383void CellFormatPagePosition::apply( CustomStyle * style )
2384{
2385 if ( top->isChecked() && dlg->alignY != Format::Top )
2386 style->changeAlignY( Format::Top );
2387 else if ( bottom->isChecked() && dlg->alignY != Format::Bottom )
2388 style->changeAlignY( Format::Bottom );
2389 else if ( middle->isChecked() && dlg->alignY != Format::Middle )
2390 style->changeAlignY( Format::Middle );
2391
2392 if ( left->isChecked() && dlg->alignX != Format::Left )
2393 style->changeAlignX( Format::Left );
2394 else if ( right->isChecked() && dlg->alignX != Format::Right )
2395 style->changeAlignX( Format::Right );
2396 else if ( center->isChecked() && dlg->alignX != Format::Center )
2397 style->changeAlignX( Format::Center );
2398 else if ( standard->isChecked() && dlg->alignX != Format::Undefined )
2399 style->changeAlignX( Format::Undefined );
2400
2401 if ( m_bOptionText )
2402 {
2403 if ( multi->isEnabled() )
2404 {
2405 if ( multi->isChecked() )
2406 style->addProperty( Style::PMultiRow );
2407 else
2408 style->removeProperty( Style::PMultiRow );
2409 }
2410 }
2411
2412 if ( m_bOptionText )
2413 {
2414 if ( vertical->isEnabled() )
2415 {
2416 if ( vertical->isChecked() )
2417 style->addProperty( Style::PVerticalText );
2418 else
2419 style->removeProperty( Style::PVerticalText );
2420 }
2421 }
2422
2423 if ( dlg->textRotation != angleRotation->value() )
2424 style->changeRotateAngle( (-angleRotation->value()) );
2425
2426 if ( m_indent->isEnabled()
2427 && dlg->indent != m_indent->value() )
2428 style->changeIndent( m_indent->value() );
2429
2430 // setting the default column width and row height
2431 if ( dlg->getStyle()->type() == Style::BUILTIN && dlg->getStyle()->name() == "Default" )
2432 {
2433 if ( (int) height->value() != (int) dlg->heightSize )
2434 {
2435 Format::setGlobalRowHeight( height->value() );
2436 }
2437 if ( (int) width->value() != (int) dlg->widthSize )
2438 {
2439 Format::setGlobalColWidth( width->value() );
2440 }
2441 }
2442}
2443
2444void CellFormatPagePosition::apply(FormatManipulator* _obj)
2445{
2446 Format::Align ax;
2447 Format::AlignY ay;
2448
2449 if ( top->isChecked() )
2450 ay = Format::Top;
2451 else if ( bottom->isChecked() )
2452 ay = Format::Bottom;
2453 else if ( middle->isChecked() )
2454 ay = Format::Middle;
2455 else
2456 ay = Format::Middle; // Default, just in case
2457
2458 if ( left->isChecked() )
2459 ax = Format::Left;
2460 else if ( right->isChecked() )
2461 ax = Format::Right;
2462 else if ( center->isChecked() )
2463 ax = Format::Center;
2464 else if ( standard->isChecked() )
2465 ax = Format::Undefined;
2466 else
2467 ax = Format::Undefined; //Default, just in case
2468
2469 if ( top->isChecked() && ay != dlg->alignY )
2470 _obj->setVerticalAlignment( Format::Top );
2471 else if ( bottom->isChecked() && ay != dlg->alignY )
2472 _obj->setVerticalAlignment( Format::Bottom );
2473 else if ( middle->isChecked() && ay != dlg->alignY )
2474 _obj->setVerticalAlignment( Format::Middle );
2475
2476 if ( left->isChecked() && ax != dlg->alignX )
2477 _obj->setHorizontalAlignment( Format::Left );
2478 else if ( right->isChecked() && ax != dlg->alignX )
2479 _obj->setHorizontalAlignment( Format::Right );
2480 else if ( center->isChecked() && ax != dlg->alignX )
2481 _obj->setHorizontalAlignment( Format::Center );
2482 else if ( standard->isChecked() && ax != dlg->alignX )
2483 _obj->setHorizontalAlignment( Format::Undefined );
2484
2485 if ( m_bOptionText )
2486 {
2487 if ( multi->isEnabled() )
2488 _obj->setMultiRow( multi->isChecked() );
2489 else
2490 _obj->setMultiRow( false );
2491 }
2492
2493 if ( m_bOptionText )
2494 {
2495 if ( vertical->isEnabled() )
2496 _obj->setVerticalText( vertical->isChecked() );
2497 else
2498 _obj->setVerticalText( false );
2499 }
2500
2501 if ( dlg->textRotation!=angleRotation->value() )
2502 _obj->setAngle( (-angleRotation->value() ) );
2503 if ( m_indent->isEnabled()
2504 && dlg->indent != m_indent->value() )
2505 _obj->setIndent( m_indent->value() );
2506}
2507
2508double CellFormatPagePosition::getSizeHeight() const
2509{
2510 if ( defaultHeight->isChecked() )
2511 return dlg->defaultHeightSize; // guess who calls this!
2512 else
2513 return height->value();
2514}
2515
2516double CellFormatPagePosition::getSizeWidth() const
2517{
2518 if ( defaultWidth->isChecked() )
2519 return dlg->defaultWidthSize; // guess who calls this!
2520 else
2521 return width->value();
2522}
2523
2524
2525
2526/***************************************************************************
2527 *
2528 * BorderButton
2529 *
2530 ***************************************************************************/
2531
2532BorderButton::BorderButton( TQWidget *parent, const char *_name ) : TQPushButton(parent,_name)
2533{
2534 penStyle = TQt::NoPen;
2535 penWidth = 1;
2536 penColor = colorGroup().text();
2537 setToggleButton( true );
2538 setOn( false);
2539 setChanged(false);
2540}
2541void BorderButton::mousePressEvent( TQMouseEvent * )
2542{
2543
2544 this->setOn(!isOn());
2545 emit clicked( this );
2546}
2547
2548void BorderButton::setUndefined()
2549{
2550 setPenStyle(TQt::SolidLine );
2551 setPenWidth(1);
2552 setColor(colorGroup().midlight());
2553}
2554
2555
2556void BorderButton::unselect()
2557{
2558 setOn(false);
2559 setPenWidth(1);
2560 setPenStyle(TQt::NoPen);
2561 setColor( colorGroup().text() );
2562 setChanged(true);
2563}
2564
2565
2566
2567/***************************************************************************
2568 *
2569 * Border
2570 *
2571 ***************************************************************************/
2572
2573Border::Border( TQWidget *parent, const char *_name,bool _oneCol, bool _oneRow )
2574 : TQFrame( parent, _name )
2575{
2576 oneCol=_oneCol;
2577 oneRow=_oneRow;
2578}
2579
2580
2581#define OFFSETX 5
2582#define OFFSETY 5
2583void Border::paintEvent( TQPaintEvent *_ev )
2584{
2585 TQFrame::paintEvent( _ev );
2586 TQPen pen;
2587 TQPainter painter;
2588 painter.begin( this );
2589 pen=TQPen( colorGroup().midlight(),2,SolidLine);
2590 painter.setPen( pen );
2591
2592 painter.drawLine( OFFSETX-5, OFFSETY, OFFSETX , OFFSETY );
2593 painter.drawLine( OFFSETX, OFFSETY-5, OFFSETX , OFFSETY );
2594 painter.drawLine( width()-OFFSETX, OFFSETY, width() , OFFSETY );
2595 painter.drawLine( width()-OFFSETX, OFFSETY-5, width()-OFFSETX , OFFSETY );
2596
2597 painter.drawLine( OFFSETX, height()-OFFSETY, OFFSETX , height() );
2598 painter.drawLine( OFFSETX-5, height()-OFFSETY, OFFSETX , height()-OFFSETY );
2599
2600 painter.drawLine( width()-OFFSETX, height()-OFFSETY, width() , height()-OFFSETY );
2601 painter.drawLine( width()-OFFSETX, height()-OFFSETY, width()-OFFSETX , height() );
2602 if (oneCol==false)
2603 {
2604 painter.drawLine( width()/2, OFFSETY-5, width()/2 , OFFSETY );
2605 painter.drawLine( width()/2-5, OFFSETY, width()/2+5 , OFFSETY );
2606 painter.drawLine( width()/2, height()-OFFSETY, width()/2 , height() );
2607 painter.drawLine( width()/2-5, height()-OFFSETY, width()/2+5 , height()-OFFSETY );
2608 }
2609 if (oneRow==false)
2610 {
2611 painter.drawLine( OFFSETX-5, height()/2, OFFSETX , height()/2 );
2612 painter.drawLine( OFFSETX, height()/2-5, OFFSETX , height()/2+5 );
2613 painter.drawLine( width()-OFFSETX, height()/2, width(), height()/2 );
2614 painter.drawLine( width()-OFFSETX, height()/2-5, width()-OFFSETX , height()/2+5 );
2615 }
2616 painter.end();
2617 emit redraw();
2618}
2619
2620void Border::mousePressEvent( TQMouseEvent* _ev )
2621{
2622 emit choosearea(_ev);
2623}
2624
2625
2626
2627/***************************************************************************
2628 *
2629 * CellFormatPageBorder
2630 *
2631 ***************************************************************************/
2632
2633CellFormatPageBorder::CellFormatPageBorder( TQWidget* parent, CellFormatDialog *_dlg )
2634 : TQWidget( parent ),
2635 dlg( _dlg )
2636{
2637 sheet = dlg->getSheet();
2638
2639 InitializeGrids();
2640 InitializeBorderButtons();
2641 InitializePatterns();
2642 SetConnections();
2643
2644 preview->slotSelect();
2645 pattern[2]->slotSelect();
2646
2647 style->setEnabled(false);
2648 size->setEnabled(false);
2649 preview->setPattern( black , 1, TQt::SolidLine );
2650 this->resize( 400, 400 );
2651}
2652
2653void CellFormatPageBorder::InitializeGrids()
2654{
2655 TQGridLayout *grid = new TQGridLayout(this,5,2,KDialog::marginHint(), KDialog::spacingHint());
2656 TQGridLayout *grid2 = NULL;
2657 TQGroupBox* tmpTQGroupBox = NULL;
2658
2659 /***********************/
2660 /* here is the data to initialize all the border buttons with */
2661 const char borderButtonNames[BorderType_END][20] =
2662 {"top", "bottom", "left", "right", "vertical", "fall", "go", "horizontal"};
2663
2664 const char shortcutButtonNames[BorderShortcutType_END][20] =
2665 {"remove", "all", "outline"};
2666
2667 TQString borderButtonIconNames[BorderType_END] =
2668 {"border_top", "border_bottom", "border_left", "border_right",
2669 "border_vertical", "border_horizontal", "border_fall", "border_up"};
2670
2671 TQString shortcutButtonIconNames[BorderShortcutType_END] =
2672 { "border_remove", "", "border_outline"};
2673
2674 int borderButtonPositions[BorderType_END][2] =
2675 {{0,2}, {4,2}, {2,0}, {2,4}, {4,4}, {4,0}, {0,0}, {0,4}};
2676
2677 int shortcutButtonPositions[BorderShortcutType_END][2] =
2678 { {0,0}, {0,1},{0,2} };
2679 /***********************/
2680
2681 /* set up a layout box for most of the border setting buttons */
2682 tmpTQGroupBox = new TQGroupBox( this, "GroupBox_1" );
2683 tmpTQGroupBox->setFrameStyle( TQFrame::Box | TQFrame::Sunken );
2684 tmpTQGroupBox->setTitle( i18n("Border") );
2685 tmpTQGroupBox->setAlignment( AlignLeft );
2686 grid2 = new TQGridLayout(tmpTQGroupBox,6,5,KDialog::marginHint(), KDialog::spacingHint());
2687 int fHeight = tmpTQGroupBox->fontMetrics().height();
2688 grid2->addRowSpacing( 0, fHeight/2 ); // groupbox title
2689
2690 area=new Border(tmpTQGroupBox,"area",dlg->oneCol,dlg->oneRow);
2691 grid2->addMultiCellWidget(area,2,4,1,3);
2692 area->setBackgroundColor( colorGroup().base() );
2693
2694 /* initailize the buttons that are in this box */
2695 for (int i=BorderType_Top; i < BorderType_END; i++)
2696 {
2697 borderButtons[i] = new BorderButton(tmpTQGroupBox,
2698 borderButtonNames[i]);
2699 loadIcon(borderButtonIconNames[i], borderButtons[i]);
2700 grid2->addWidget(borderButtons[i], borderButtonPositions[i][0] + 1,
2701 borderButtonPositions[i][1]);
2702 }
2703
2704 grid->addMultiCellWidget(tmpTQGroupBox,0,2,0,0);
2705
2706 /* the remove, all, and outline border buttons are in a second box down
2707 below.*/
2708
2709 tmpTQGroupBox = new TQGroupBox( this, "GroupBox_3" );
2710 tmpTQGroupBox->setFrameStyle( TQFrame::Box | TQFrame::Sunken );
2711 tmpTQGroupBox->setTitle( i18n("Preselect") );
2712 tmpTQGroupBox->setAlignment( AlignLeft );
2713
2714 grid2 = new TQGridLayout(tmpTQGroupBox,1,3,KDialog::marginHint(), KDialog::spacingHint());
2715
2716 /* the "all" button is different depending on what kind of region is currently
2717 selected */
2718 if ((dlg->oneRow==true)&&(dlg->oneCol==false))
2719 {
2720 shortcutButtonIconNames[BorderShortcutType_All] = "border_vertical";
2721 }
2722 else if ((dlg->oneRow==false)&&(dlg->oneCol==true))
2723 {
2724 shortcutButtonIconNames[BorderShortcutType_All] = "border_horizontal";
2725 }
2726 else
2727 {
2728 shortcutButtonIconNames[BorderShortcutType_All] = "border_inside";
2729 }
2730
2731 for (int i=BorderShortcutType_Remove; i < BorderShortcutType_END; i++)
2732 {
2733 shortcutButtons[i] = new BorderButton(tmpTQGroupBox,
2734 shortcutButtonNames[i]);
2735 loadIcon(shortcutButtonIconNames[i], shortcutButtons[i]);
2736 grid2->addWidget(shortcutButtons[i], shortcutButtonPositions[i][0],
2737 shortcutButtonPositions[i][1]);
2738 }
2739
2740 if (dlg->oneRow && dlg->oneCol)
2741 {
2742 shortcutButtons[BorderShortcutType_All]->setEnabled(false);
2743 }
2744
2745 grid->addMultiCellWidget(tmpTQGroupBox,3,4,0,0);
2746
2747 /* now set up the group box with the pattern selector */
2748 tmpTQGroupBox = new TQGroupBox( this, "GroupBox_10" );
2749 tmpTQGroupBox->setFrameStyle( TQFrame::Box | TQFrame::Sunken );
2750 tmpTQGroupBox->setTitle( i18n("Pattern") );
2751 tmpTQGroupBox->setAlignment( AlignLeft );
2752
2753 grid2 = new TQGridLayout(tmpTQGroupBox,7,2,KDialog::marginHint(), KDialog::spacingHint());
2754 fHeight = tmpTQGroupBox->fontMetrics().height();
2755 grid2->addRowSpacing( 0, fHeight/2 ); // groupbox title
2756
2757 char name[] = "PatternXX";
2758 Q_ASSERT(NUM_BORDER_PATTERNS < 100);
2759
2760 for (int i=0; i < NUM_BORDER_PATTERNS; i++)
2761 {
2762 name[7] = '0' + (i+1) / 10;
2763 name[8] = '0' + (i+1) % 10;
2764 pattern[i] = new PatternSelect( tmpTQGroupBox, name );
2765 pattern[i]->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
2766 grid2->addWidget(pattern[i], i % 5 + 1, i / 5);
2767 /* this puts them in the pattern:
2768 1 6
2769 2 7
2770 3 8
2771 4 9
2772 5 10
2773 */
2774 }
2775
2776 color = new KColorButton (tmpTQGroupBox, "PushButton_1" );
2777 grid2->addWidget(color,7,1);
2778
2779 TQLabel *tmpTQLabel = new TQLabel( tmpTQGroupBox, "Label_6" );
2780 tmpTQLabel->setText( i18n("Color:") );
2781 grid2->addWidget(tmpTQLabel,7,0);
2782
2783 /* tack on the 'customize' border pattern selector */
2784 TQGridLayout *grid3 = new TQGridLayout( this, 2, 2, KDialog::marginHint(), KDialog::spacingHint() );
2785 customize = new TQCheckBox(i18n("Customize"),tmpTQGroupBox);
2786 grid3->addWidget(customize,0,0);
2787 connect( customize, TQ_SIGNAL( clicked()), TQ_SLOT(cutomize_chosen_slot()) );
2788
2789 size=new TQComboBox(true,tmpTQGroupBox);
2790 grid3->addWidget(size,1,1);
2791 size->setValidator(new KIntValidator( size ));
2792 TQString tmp;
2793 for ( int i=0;i<10;i++)
2794 {
2795 tmp=tmp.setNum(i);
2796 size->insertItem(tmp);
2797 }
2798 size->setCurrentItem(1);
2799
2800 style=new TQComboBox(tmpTQGroupBox);
2801 grid3->addWidget(style,1,0);
2802 style->insertItem(paintFormatPixmap(DotLine),0 );
2803 style->insertItem(paintFormatPixmap(DashLine) ,1);
2804 style->insertItem(paintFormatPixmap(DashDotLine),2 );
2805 style->insertItem(paintFormatPixmap(DashDotDotLine),3 );
2806 style->insertItem(paintFormatPixmap(SolidLine),4);
2807 style->setBackgroundColor( colorGroup().background() );
2808
2809 grid2->addMultiCell(grid3,6,6,0,1);
2810 grid->addMultiCellWidget(tmpTQGroupBox,0,3,1,1);
2811
2812 /* Now the preview box is put together */
2813 tmpTQGroupBox = new TQGroupBox(this, "GroupBox_4" );
2814 tmpTQGroupBox->setFrameStyle( TQFrame::Box | TQFrame::Sunken );
2815 tmpTQGroupBox->setTitle( i18n("Preview") );
2816 tmpTQGroupBox->setAlignment( AlignLeft );
2817
2818 grid2 = new TQGridLayout(tmpTQGroupBox,1,1,KDialog::marginHint(), KDialog::spacingHint());
2819 fHeight = tmpTQGroupBox->fontMetrics().height();
2820 grid2->addRowSpacing( 0, fHeight/2 ); // groupbox title
2821
2822 preview = new PatternSelect( tmpTQGroupBox, "Pattern_preview" );
2823 preview->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
2824 grid2->addWidget(preview,1,0);
2825
2826 grid->addWidget(tmpTQGroupBox,4,1);
2827}
2828
2829void CellFormatPageBorder::InitializeBorderButtons()
2830{
2831 for (int i=BorderType_Top; i < BorderType_END; i++)
2832 {
2833 if (dlg->borders[i].style != TQt::NoPen ||
2834 !dlg->borders[i].bStyle )
2835 {
2836 /* the horozontil and vertical buttons might be disabled depending on what
2837 kind of area is selected so check that first. */
2838 if ((dlg->oneRow == true && i == BorderType_Horizontal) ||
2839 (dlg->oneCol == true && i == BorderType_Vertical))
2840 {
2841 borderButtons[i]->setEnabled(false);
2842 }
2843 else if ( dlg->borders[i].bColor && dlg->borders[i].bStyle )
2844 {
2845 borderButtons[i]->setPenStyle(dlg->borders[i].style );
2846 borderButtons[i]->setPenWidth(dlg->borders[i].width);
2847 borderButtons[i]->setColor(dlg->borders[i].color);
2848 borderButtons[i]->setOn(true);
2849 }
2850 else
2851 {
2852 borderButtons[i]->setUndefined();
2853 }
2854 }
2855 }
2856
2857
2858}
2859
2860void CellFormatPageBorder::InitializePatterns()
2861{
2862 pattern[0]->setPattern( black, 1, TQt::DotLine );
2863 pattern[1]->setPattern( black, 1, TQt::DashLine );
2864 pattern[2]->setPattern( black, 1, TQt::SolidLine );
2865 pattern[3]->setPattern( black, 1, TQt::DashDotLine );
2866 pattern[4]->setPattern( black, 1, TQt::DashDotDotLine );
2867 pattern[5]->setPattern( black, 2, TQt::SolidLine );
2868 pattern[6]->setPattern( black, 3, TQt::SolidLine );
2869 pattern[7]->setPattern( black, 4, TQt::SolidLine );
2870 pattern[8]->setPattern( black, 5, TQt::SolidLine );
2871 pattern[9]->setPattern( black, 1, TQt::NoPen );
2872
2873 slotSetColorButton( black );
2874}
2875
2876void CellFormatPageBorder::SetConnections()
2877{
2878 connect( color, TQ_SIGNAL( changed( const TQColor & ) ),
2879 this, TQ_SLOT( slotSetColorButton( const TQColor & ) ) );
2880
2881 for (int i=0; i < NUM_BORDER_PATTERNS; i++)
2882 {
2883 connect( pattern[i], TQ_SIGNAL( clicked( PatternSelect* ) ),
2884 this, TQ_SLOT( slotUnselect2( PatternSelect* ) ) );
2885 }
2886
2887 for (int i = BorderType_Top; i < BorderType_END; i++)
2888 {
2889 connect( borderButtons[i], TQ_SIGNAL( clicked (BorderButton *) ),
2890 this, TQ_SLOT( changeState( BorderButton *) ) );
2891 }
2892
2893 for (int i = BorderShortcutType_Remove; i < BorderShortcutType_END; i++)
2894 {
2895 connect( shortcutButtons[i], TQ_SIGNAL( clicked(BorderButton *) ),
2896 this, TQ_SLOT( preselect(BorderButton *) ) );
2897 }
2898
2899 connect( area ,TQ_SIGNAL( redraw()),this,TQ_SLOT(draw()));
2900 connect( area ,TQ_SIGNAL( choosearea(TQMouseEvent * )),
2901 this,TQ_SLOT( slotPressEvent(TQMouseEvent *)));
2902
2903 connect( style, TQ_SIGNAL( activated(int)), this, TQ_SLOT(slotChangeStyle(int)));
2904 connect( size, TQ_SIGNAL( textChanged(const TQString &)),
2905 this, TQ_SLOT(slotChangeStyle(const TQString &)));
2906 connect( size ,TQ_SIGNAL( activated(int)), this, TQ_SLOT(slotChangeStyle(int)));
2907}
2908
2909void CellFormatPageBorder::cutomize_chosen_slot()
2910{
2911 if ( customize->isChecked() )
2912 {
2913 style->setEnabled( true );
2914 size->setEnabled( true );
2915 slotUnselect2( preview );
2916 }
2917 else
2918 {
2919 style->setEnabled( false );
2920 size->setEnabled( false );
2921 pattern[2]->slotSelect();
2922 preview->setPattern( black , 1, TQt::SolidLine );
2923 }
2924}
2925
2926void CellFormatPageBorder::slotChangeStyle(const TQString &)
2927{
2928 /* if they try putting text in the size box, then erase the line */
2929 slotChangeStyle(0);
2930}
2931
2932void CellFormatPageBorder::slotChangeStyle(int)
2933{
2934 int index = style->currentItem();
2935 TQString tmp;
2936 int penSize = size->currentText().toInt();
2937 if ( !penSize)
2938 {
2939 preview->setPattern( preview->getColor(), penSize, TQt::NoPen );
2940 }
2941 else
2942 {
2943 switch(index)
2944 {
2945 case 0:
2946 preview->setPattern( preview->getColor(), penSize, TQt::DotLine );
2947 break;
2948 case 1:
2949 preview->setPattern( preview->getColor(), penSize, TQt::DashLine );
2950 break;
2951 case 2:
2952 preview->setPattern( preview->getColor(), penSize, TQt::DashDotLine );
2953 break;
2954 case 3:
2955 preview->setPattern( preview->getColor(), penSize, TQt::DashDotDotLine );
2956 break;
2957 case 4:
2958 preview->setPattern( preview->getColor(), penSize, TQt::SolidLine );
2959 break;
2960 default:
2961 kdDebug(36001)<<"Error in combobox\n";
2962 break;
2963 }
2964 }
2965 slotUnselect2(preview);
2966}
2967
2968TQPixmap CellFormatPageBorder::paintFormatPixmap(PenStyle _style)
2969{
2970 TQPixmap pixmap( style->width(), 14 );
2971 TQPainter painter;
2972 TQPen pen;
2973 pen=TQPen( colorGroup().text(),1,_style);
2974 painter.begin( &pixmap );
2975 painter.fillRect( 0, 0, style->width(), 14, colorGroup().background() );
2976 painter.setPen( pen );
2977 painter.drawLine( 0, 7, style->width(), 7 );
2978 painter.end();
2979 return pixmap;
2980}
2981
2982void CellFormatPageBorder::loadIcon( TQString _pix, BorderButton *_button)
2983{
2984 _button->setPixmap( TQPixmap( BarIcon(_pix, Factory::global()) ) );
2985}
2986
2987void CellFormatPageBorder::apply(FormatManipulator* obj)
2988{
2989 if (borderButtons[BorderType_Horizontal]->isChanged())
2990 applyHorizontalOutline(obj);
2991
2992 if (borderButtons[BorderType_Vertical]->isChanged())
2993 applyVerticalOutline(obj);
2994
2995 if ( borderButtons[BorderType_Left]->isChanged() )
2996 applyLeftOutline(obj);
2997
2998 if ( borderButtons[BorderType_Right]->isChanged() )
2999 applyRightOutline(obj);
3000
3001 if ( borderButtons[BorderType_Top]->isChanged() )
3002 applyTopOutline(obj);
3003
3004 if ( borderButtons[BorderType_Bottom]->isChanged() )
3005 applyBottomOutline(obj);
3006
3007 if ( borderButtons[BorderType_RisingDiagonal]->isChanged() ||
3008 borderButtons[BorderType_FallingDiagonal]->isChanged() )
3009 applyDiagonalOutline(obj);
3010}
3011
3012void CellFormatPageBorder::applyTopOutline(FormatManipulator* obj)
3013{
3014 BorderButton * top = borderButtons[BorderType_Top];
3015
3016 TQPen tmpPen( top->getColor(), top->getPenWidth(), top->getPenStyle());
3017
3018 if ( dlg->getStyle() )
3019 {
3020 dlg->getStyle()->changeTopBorderPen( tmpPen );
3021 }
3022 else
3023 {
3024 if (borderButtons[BorderType_Top]->isChanged())
3025 obj->setTopBorderPen( tmpPen );
3026 }
3027}
3028
3029void CellFormatPageBorder::applyBottomOutline(FormatManipulator* obj)
3030{
3031 BorderButton * bottom = borderButtons[BorderType_Bottom];
3032
3033 TQPen tmpPen( bottom->getColor(), bottom->getPenWidth(), bottom->getPenStyle() );
3034
3035 if ( dlg->getStyle() )
3036 {
3037 dlg->getStyle()->changeBottomBorderPen( tmpPen );
3038 }
3039 else
3040 {
3041 if (borderButtons[BorderType_Bottom]->isChanged())
3042 obj->setBottomBorderPen( tmpPen );
3043 }
3044}
3045
3046void CellFormatPageBorder::applyLeftOutline(FormatManipulator* obj)
3047{
3048 BorderButton * left = borderButtons[BorderType_Left];
3049 TQPen tmpPen( left->getColor(), left->getPenWidth(), left->getPenStyle() );
3050
3051 if ( dlg->getStyle() )
3052 {
3053 dlg->getStyle()->changeLeftBorderPen( tmpPen );
3054 }
3055 else
3056 {
3057 if (borderButtons[BorderType_Left]->isChanged())
3058 obj->setLeftBorderPen( tmpPen );
3059 }
3060}
3061
3062void CellFormatPageBorder::applyRightOutline(FormatManipulator* obj)
3063{
3064 BorderButton* right = borderButtons[BorderType_Right];
3065 TQPen tmpPen( right->getColor(), right->getPenWidth(), right->getPenStyle() );
3066
3067 if ( dlg->getStyle() )
3068 {
3069 dlg->getStyle()->changeRightBorderPen( tmpPen );
3070 }
3071 else
3072 {
3073 if (borderButtons[BorderType_Right]->isChanged())
3074 obj->setRightBorderPen( tmpPen );
3075 }
3076}
3077
3078void CellFormatPageBorder::applyDiagonalOutline(FormatManipulator* obj)
3079{
3080 BorderButton * fallDiagonal = borderButtons[BorderType_FallingDiagonal];
3081 BorderButton * goUpDiagonal = borderButtons[BorderType_RisingDiagonal];
3082 TQPen tmpPenFall( fallDiagonal->getColor(), fallDiagonal->getPenWidth(),
3083 fallDiagonal->getPenStyle());
3084 TQPen tmpPenGoUp( goUpDiagonal->getColor(), goUpDiagonal->getPenWidth(),
3085 goUpDiagonal->getPenStyle());
3086
3087 if ( dlg->getStyle() )
3088 {
3089 if ( fallDiagonal->isChanged() )
3090 dlg->getStyle()->changeFallBorderPen( tmpPenFall );
3091 if ( goUpDiagonal->isChanged() )
3092 dlg->getStyle()->changeGoUpBorderPen( tmpPenGoUp );
3093 }
3094 else
3095 {
3096 if ( fallDiagonal->isChanged() )
3097 obj->setFallDiagonalPen( tmpPenFall );
3098 if ( goUpDiagonal->isChanged() )
3099 obj->setGoUpDiagonalPen( tmpPenGoUp );
3100 }
3101}
3102
3103void CellFormatPageBorder::applyHorizontalOutline(FormatManipulator* obj)
3104{
3105 TQPen tmpPen( borderButtons[BorderType_Horizontal]->getColor(),
3106 borderButtons[BorderType_Horizontal]->getPenWidth(),
3107 borderButtons[BorderType_Horizontal]->getPenStyle());
3108
3109 if ( dlg->getStyle() )
3110 {
3111 dlg->getStyle()->changeTopBorderPen( tmpPen );
3112 }
3113 else
3114 {
3115 if (borderButtons[BorderType_Horizontal]->isChanged())
3116 obj->setHorizontalPen( tmpPen );
3117 }
3118}
3119
3120void CellFormatPageBorder::applyVerticalOutline(FormatManipulator* obj)
3121{
3122 BorderButton* vertical = borderButtons[BorderType_Vertical];
3123 TQPen tmpPen( vertical->getColor(), vertical->getPenWidth(),
3124 vertical->getPenStyle());
3125
3126 if ( dlg->getStyle() )
3127 {
3128 dlg->getStyle()->changeLeftBorderPen( tmpPen );
3129 }
3130 else
3131 {
3132 if (borderButtons[BorderType_Vertical]->isChanged())
3133 obj->setVerticalPen( tmpPen );
3134 }
3135}
3136
3137
3138void CellFormatPageBorder::slotSetColorButton( const TQColor &_color )
3139{
3140 currentColor = _color;
3141
3142 for ( int i = 0; i < NUM_BORDER_PATTERNS; ++i )
3143 {
3144 pattern[i]->setColor( currentColor );
3145 }
3146 preview->setColor( currentColor );
3147}
3148
3149void CellFormatPageBorder::slotUnselect2( PatternSelect *_p )
3150{
3151 for ( int i = 0; i < NUM_BORDER_PATTERNS; ++i )
3152 {
3153 if ( pattern[i] != _p )
3154 {
3155 pattern[i]->slotUnselect();
3156 }
3157 }
3158 preview->setPattern( _p->getColor(), _p->getPenWidth(), _p->getPenStyle() );
3159}
3160
3161void CellFormatPageBorder::preselect( BorderButton *_p )
3162{
3163 BorderButton* top = borderButtons[BorderType_Top];
3164 BorderButton* bottom = borderButtons[BorderType_Bottom];
3165 BorderButton* left = borderButtons[BorderType_Left];
3166 BorderButton* right = borderButtons[BorderType_Right];
3167 BorderButton* vertical = borderButtons[BorderType_Vertical];
3168 BorderButton* horizontal = borderButtons[BorderType_Horizontal];
3169 BorderButton* remove = shortcutButtons[BorderShortcutType_Remove];
3170 BorderButton* outline = shortcutButtons[BorderShortcutType_Outline];
3171 BorderButton* all = shortcutButtons[BorderShortcutType_All];
3172
3173 _p->setOn(false);
3174 if (_p == remove)
3175 {
3176 for (int i=BorderType_Top; i < BorderType_END; i++)
3177 {
3178 if (borderButtons[i]->isOn())
3179 {
3180 borderButtons[i]->unselect();
3181 }
3182 }
3183 }
3184 if (_p==outline)
3185 {
3186 top->setOn(true);
3187 top->setPenWidth(preview->getPenWidth());
3188 top->setPenStyle(preview->getPenStyle());
3189 top->setColor( currentColor );
3190 top->setChanged(true);
3191 bottom->setOn(true);
3192 bottom->setPenWidth(preview->getPenWidth());
3193 bottom->setPenStyle(preview->getPenStyle());
3194 bottom->setColor( currentColor );
3195 bottom->setChanged(true);
3196 left->setOn(true);
3197 left->setPenWidth(preview->getPenWidth());
3198 left->setPenStyle(preview->getPenStyle());
3199 left->setColor( currentColor );
3200 left->setChanged(true);
3201 right->setOn(true);
3202 right->setPenWidth(preview->getPenWidth());
3203 right->setPenStyle(preview->getPenStyle());
3204 right->setColor( currentColor );
3205 right->setChanged(true);
3206 }
3207 if (_p==all)
3208 {
3209 if (dlg->oneRow==false)
3210 {
3211 horizontal->setOn(true);
3212 horizontal->setPenWidth(preview->getPenWidth());
3213 horizontal->setPenStyle(preview->getPenStyle());
3214 horizontal->setColor( currentColor );
3215 horizontal->setChanged(true);
3216 }
3217 if (dlg->oneCol==false)
3218 {
3219 vertical->setOn(true);
3220 vertical->setPenWidth(preview->getPenWidth());
3221 vertical->setPenStyle(preview->getPenStyle());
3222 vertical->setColor( currentColor );
3223 vertical->setChanged(true);
3224 }
3225 }
3226 area->repaint();
3227}
3228
3229void CellFormatPageBorder::changeState( BorderButton *_p)
3230{
3231 _p->setChanged(true);
3232
3233 if (_p->isOn())
3234 {
3235 _p->setPenWidth(preview->getPenWidth());
3236 _p->setPenStyle(preview->getPenStyle());
3237 _p->setColor( currentColor );
3238 }
3239 else
3240 {
3241 _p->setPenWidth(1);
3242 _p->setPenStyle(TQt::NoPen);
3243 _p->setColor( colorGroup().text() );
3244 }
3245
3246 area->repaint();
3247}
3248
3249void CellFormatPageBorder::draw()
3250{
3251 BorderButton* top = borderButtons[BorderType_Top];
3252 BorderButton* bottom = borderButtons[BorderType_Bottom];
3253 BorderButton* left = borderButtons[BorderType_Left];
3254 BorderButton* right = borderButtons[BorderType_Right];
3255 BorderButton* risingDiagonal = borderButtons[BorderType_RisingDiagonal];
3256 BorderButton* fallingDiagonal = borderButtons[BorderType_FallingDiagonal];
3257 BorderButton* vertical = borderButtons[BorderType_Vertical];
3258 BorderButton* horizontal = borderButtons[BorderType_Horizontal];
3259 TQPen pen;
3260 TQPainter painter;
3261 painter.begin( area );
3262
3263 if ((bottom->getPenStyle())!=TQt::NoPen)
3264 {
3265 pen=TQPen( bottom->getColor(), bottom->getPenWidth(),bottom->getPenStyle());
3266 painter.setPen( pen );
3267 painter.drawLine( OFFSETX, area->height()-OFFSETY, area->width()-OFFSETX , area->height()-OFFSETY );
3268 }
3269 if ((top->getPenStyle())!=TQt::NoPen)
3270 {
3271 pen=TQPen( top->getColor(), top->getPenWidth(),top->getPenStyle());
3272 painter.setPen( pen );
3273 painter.drawLine( OFFSETX, OFFSETY, area->width() -OFFSETX, OFFSETY );
3274 }
3275 if ((left->getPenStyle())!=TQt::NoPen)
3276 {
3277 pen=TQPen( left->getColor(), left->getPenWidth(),left->getPenStyle());
3278 painter.setPen( pen );
3279 painter.drawLine( OFFSETX, OFFSETY, OFFSETX , area->height()-OFFSETY );
3280 }
3281 if ((right->getPenStyle())!=TQt::NoPen)
3282 {
3283 pen=TQPen( right->getColor(), right->getPenWidth(),right->getPenStyle());
3284 painter.setPen( pen );
3285 painter.drawLine( area->width()-OFFSETX, OFFSETY, area->width()-OFFSETX,
3286 area->height()-OFFSETY );
3287
3288 }
3289 if ((fallingDiagonal->getPenStyle())!=TQt::NoPen)
3290 {
3291 pen=TQPen( fallingDiagonal->getColor(), fallingDiagonal->getPenWidth(),
3292 fallingDiagonal->getPenStyle());
3293 painter.setPen( pen );
3294 painter.drawLine( OFFSETX, OFFSETY, area->width()-OFFSETX,
3295 area->height()-OFFSETY );
3296 if (dlg->oneCol==false&& dlg->oneRow==false)
3297 {
3298 painter.drawLine( area->width()/2, OFFSETY, area->width()-OFFSETX,
3299 area->height()/2 );
3300 painter.drawLine( OFFSETX,area->height()/2 , area->width()/2,
3301 area->height()-OFFSETY );
3302 }
3303 }
3304 if ((risingDiagonal->getPenStyle())!=TQt::NoPen)
3305 {
3306 pen=TQPen( risingDiagonal->getColor(), risingDiagonal->getPenWidth(),
3307 risingDiagonal->getPenStyle());
3308 painter.setPen( pen );
3309 painter.drawLine( OFFSETX, area->height()-OFFSETY , area->width()-OFFSETX ,
3310 OFFSETY );
3311 if (dlg->oneCol==false&& dlg->oneRow==false)
3312 {
3313 painter.drawLine( area->width()/2, OFFSETY, OFFSETX, area->height()/2 );
3314 painter.drawLine( area->width()/2,area->height()-OFFSETY ,
3315 area->width()-OFFSETX, area->height()/2 );
3316 }
3317
3318 }
3319 if ((vertical->getPenStyle())!=TQt::NoPen)
3320 {
3321 pen=TQPen( vertical->getColor(), vertical->getPenWidth(),
3322 vertical->getPenStyle());
3323 painter.setPen( pen );
3324 painter.drawLine( area->width()/2, 5 , area->width()/2 , area->height()-5 );
3325 }
3326 if ((horizontal->getPenStyle())!=TQt::NoPen)
3327 {
3328 pen=TQPen( horizontal->getColor(), horizontal->getPenWidth(),
3329 horizontal->getPenStyle());
3330 painter.setPen( pen );
3331 painter.drawLine( OFFSETX,area->height()/2,area->width()-OFFSETX,
3332 area->height()/2 );
3333 }
3334 painter.end();
3335}
3336
3337void CellFormatPageBorder::invertState(BorderButton *_p)
3338{
3339 if (_p->isOn())
3340 {
3341 _p->unselect();
3342 }
3343 else
3344 {
3345 _p->setOn(true);
3346 _p->setPenWidth(preview->getPenWidth());
3347 _p->setPenStyle(preview->getPenStyle());
3348 _p->setColor( currentColor );
3349 _p->setChanged(true);
3350 }
3351}
3352
3353void CellFormatPageBorder::slotPressEvent(TQMouseEvent *_ev)
3354{
3355 BorderButton* top = borderButtons[BorderType_Top];
3356 BorderButton* bottom = borderButtons[BorderType_Bottom];
3357 BorderButton* left = borderButtons[BorderType_Left];
3358 BorderButton* right = borderButtons[BorderType_Right];
3359 BorderButton* vertical = borderButtons[BorderType_Vertical];
3360 BorderButton* horizontal = borderButtons[BorderType_Horizontal];
3361
3362
3363 TQRect rect(OFFSETX,OFFSETY-8,area->width()-OFFSETX,OFFSETY+8);
3364 if (rect.contains(TQPoint(_ev->x(),_ev->y())))
3365 {
3366 if (((top->getPenWidth()!=preview->getPenWidth()) ||
3367 (top->getColor()!=currentColor) ||
3368 (top->getPenStyle()!=preview->getPenStyle()))
3369 && top->isOn())
3370 {
3371 top->setPenWidth(preview->getPenWidth());
3372 top->setPenStyle(preview->getPenStyle());
3373 top->setColor( currentColor );
3374 top->setChanged(true);
3375 }
3376 else
3377 invertState(top);
3378 }
3379 rect.setCoords(OFFSETX,area->height()-OFFSETY-8,area->width()-OFFSETX,
3380 area->height()-OFFSETY+8);
3381 if (rect.contains(TQPoint(_ev->x(),_ev->y())))
3382 {
3383 if (((bottom->getPenWidth()!=preview->getPenWidth()) ||
3384 (bottom->getColor()!=currentColor) ||
3385 (bottom->getPenStyle()!=preview->getPenStyle()))
3386 && bottom->isOn())
3387 {
3388 bottom->setPenWidth(preview->getPenWidth());
3389 bottom->setPenStyle(preview->getPenStyle());
3390 bottom->setColor( currentColor );
3391 bottom->setChanged(true);
3392 }
3393 else
3394 invertState(bottom);
3395 }
3396
3397 rect.setCoords(OFFSETX-8,OFFSETY,OFFSETX+8,area->height()-OFFSETY);
3398 if (rect.contains(TQPoint(_ev->x(),_ev->y())))
3399 {
3400 if (((left->getPenWidth()!=preview->getPenWidth()) ||
3401 (left->getColor()!=currentColor) ||
3402 (left->getPenStyle()!=preview->getPenStyle()))
3403 && left->isOn())
3404 {
3405 left->setPenWidth(preview->getPenWidth());
3406 left->setPenStyle(preview->getPenStyle());
3407 left->setColor( currentColor );
3408 left->setChanged(true);
3409 }
3410 else
3411 invertState(left);
3412 }
3413 rect.setCoords(area->width()-OFFSETX-8,OFFSETY,area->width()-OFFSETX+8,
3414 area->height()-OFFSETY);
3415 if (rect.contains(TQPoint(_ev->x(),_ev->y())))
3416 {
3417 if (((right->getPenWidth()!=preview->getPenWidth()) ||
3418 (right->getColor()!=currentColor) ||
3419 (right->getPenStyle()!=preview->getPenStyle()))
3420 && right->isOn())
3421 {
3422 right->setPenWidth(preview->getPenWidth());
3423 right->setPenStyle(preview->getPenStyle());
3424 right->setColor( currentColor );
3425 right->setChanged(true);
3426 }
3427 else
3428 invertState(right);
3429 }
3430
3431//don't work because I don't know how create a rectangle
3432//for diagonal
3433/*rect.setCoords(OFFSETX,OFFSETY,XLEN-OFFSETX,YHEI-OFFSETY);
3434if (rect.contains(TQPoint(_ev->x(),_ev->y())))
3435 {
3436 invertState(fallDiagonal);
3437 }
3438rect.setCoords(OFFSETX,YHEI-OFFSETY,XLEN-OFFSETX,OFFSETY);
3439if (rect.contains(TQPoint(_ev->x(),_ev->y())))
3440 {
3441 invertState(goUpDiagonal);
3442 } */
3443
3444 if (dlg->oneCol==false)
3445 {
3446 rect.setCoords(area->width()/2-8,OFFSETY,area->width()/2+8,
3447 area->height()-OFFSETY);
3448
3449 if (rect.contains(TQPoint(_ev->x(),_ev->y())))
3450 {
3451 if (((vertical->getPenWidth()!=preview->getPenWidth()) ||
3452 (vertical->getColor()!=currentColor) ||
3453 (vertical->getPenStyle()!=preview->getPenStyle()))
3454 && vertical->isOn())
3455 {
3456 vertical->setPenWidth(preview->getPenWidth());
3457 vertical->setPenStyle(preview->getPenStyle());
3458 vertical->setColor( currentColor );
3459 vertical->setChanged(true);
3460 }
3461 else
3462 invertState(vertical);
3463 }
3464 }
3465 if (dlg->oneRow==false)
3466 {
3467 rect.setCoords(OFFSETX,area->height()/2-8,area->width()-OFFSETX,
3468 area->height()/2+8);
3469 if (rect.contains(TQPoint(_ev->x(),_ev->y())))
3470 {
3471 if (((horizontal->getPenWidth()!=preview->getPenWidth()) ||
3472 (horizontal->getColor()!=currentColor) ||
3473 (horizontal->getPenStyle()!=preview->getPenStyle()))
3474 && horizontal->isOn())
3475 {
3476 horizontal->setPenWidth(preview->getPenWidth());
3477 horizontal->setPenStyle(preview->getPenStyle());
3478 horizontal->setColor( currentColor );
3479 horizontal->setChanged(true);
3480 }
3481 else
3482 invertState(horizontal);
3483 }
3484 }
3485
3486 area->repaint();
3487}
3488
3489
3490
3491/***************************************************************************
3492 *
3493 * BrushSelect
3494 *
3495 ***************************************************************************/
3496
3497BrushSelect::BrushSelect( TQWidget *parent, const char * ) : TQFrame( parent )
3498{
3499 brushStyle = TQt::NoBrush;
3500 brushColor = TQt::red;
3501 selected = false;
3502}
3503
3504void BrushSelect::setPattern( const TQColor &_color,TQt::BrushStyle _style )
3505{
3506 brushStyle = _style;
3507 brushColor = _color;
3508 repaint();
3509}
3510
3511
3512void BrushSelect::paintEvent( TQPaintEvent *_ev )
3513{
3514 TQFrame::paintEvent( _ev );
3515
3516 TQPainter painter;
3517 TQBrush brush(brushColor,brushStyle);
3518 painter.begin( this );
3519 painter.setPen( TQt::NoPen );
3520 painter.setBrush( brush);
3521 painter.drawRect( 2, 2, width()-4, height()-4);
3522 painter.end();
3523}
3524
3525void BrushSelect::mousePressEvent( TQMouseEvent * )
3526{
3527 slotSelect();
3528
3529 emit clicked( this );
3530}
3531
3532void BrushSelect::slotUnselect()
3533{
3534 selected = false;
3535
3536 setLineWidth( 1 );
3537 setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
3538 repaint();
3539}
3540
3541void BrushSelect::slotSelect()
3542{
3543 selected = true;
3544
3545 setLineWidth( 2 );
3546 setFrameStyle( TQFrame::Panel | TQFrame::Plain );
3547 repaint();
3548}
3549
3550
3551
3552/***************************************************************************
3553 *
3554 * CellFormatPagePattern
3555 *
3556 ***************************************************************************/
3557
3558CellFormatPagePattern::CellFormatPagePattern( TQWidget* parent, CellFormatDialog *_dlg ) : TQWidget( parent )
3559{
3560 dlg = _dlg;
3561
3562 bBgColorUndefined = !dlg->bBgColor;
3563
3564 TQGridLayout *grid = new TQGridLayout(this,5,2,KDialog::marginHint(), KDialog::spacingHint());
3565
3566 TQGroupBox* tmpTQGroupBox;
3567 tmpTQGroupBox = new TQGroupBox( this, "GroupBox_20" );
3568 tmpTQGroupBox->setFrameStyle( TQFrame::Box | TQFrame::Sunken );
3569 tmpTQGroupBox->setTitle( i18n("Pattern") );
3570 tmpTQGroupBox->setAlignment( AlignLeft );
3571
3572 TQGridLayout *grid2 = new TQGridLayout(tmpTQGroupBox,8,3,KDialog::marginHint(), KDialog::spacingHint());
3573 int fHeight = tmpTQGroupBox->fontMetrics().height();
3574 grid2->addRowSpacing( 0, fHeight/2 ); // groupbox title
3575
3576
3577 brush1 = new BrushSelect( tmpTQGroupBox, "Frame_1" );
3578 brush1->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
3579 grid2->addWidget(brush1,1,0);
3580
3581 brush2 = new BrushSelect( tmpTQGroupBox, "Frame_2" );
3582 brush2->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
3583 grid2->addWidget(brush2,1,1);
3584
3585 brush3 = new BrushSelect( tmpTQGroupBox, "Frame_3" );
3586 brush3->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
3587 grid2->addWidget(brush3,1,2);
3588
3589 brush4 = new BrushSelect( tmpTQGroupBox, "Frame_4" );
3590 brush4->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
3591 grid2->addWidget(brush4,2,0);
3592
3593 brush5 = new BrushSelect( tmpTQGroupBox, "Frame_5" );
3594 brush5->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
3595 grid2->addWidget(brush5,2,1);
3596
3597 brush6 = new BrushSelect( tmpTQGroupBox, "Frame_6" );
3598 brush6->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
3599 grid2->addWidget(brush6,2,2);
3600
3601 brush7 = new BrushSelect( tmpTQGroupBox, "Frame_7" );
3602 brush7->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
3603 grid2->addWidget(brush7,3,0);
3604
3605 brush8 = new BrushSelect( tmpTQGroupBox, "Frame_8" );
3606 brush8->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
3607 grid2->addWidget(brush8,3,1);
3608
3609 brush9 = new BrushSelect( tmpTQGroupBox, "Frame_9" );
3610 brush9->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
3611 grid2->addWidget(brush9,3,2);
3612
3613 brush10 = new BrushSelect( tmpTQGroupBox, "Frame_10" );
3614 brush10->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
3615 grid2->addWidget(brush10,4,0);
3616
3617 brush11 = new BrushSelect( tmpTQGroupBox, "Frame_11" );
3618 brush11->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
3619 grid2->addWidget(brush11,4,1);
3620
3621 brush12 = new BrushSelect( tmpTQGroupBox, "Frame_12" );
3622 brush12->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
3623 grid2->addWidget(brush12,4,2);
3624
3625 brush13 = new BrushSelect( tmpTQGroupBox, "Frame_13" );
3626 brush13->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
3627 grid2->addWidget(brush13,5,0);
3628
3629 brush14 = new BrushSelect( tmpTQGroupBox, "Frame_14" );
3630 brush14->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
3631 grid2->addWidget(brush14,5,1);
3632
3633 brush15 = new BrushSelect( tmpTQGroupBox, "Frame_15" );
3634 brush15->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
3635 grid2->addWidget(brush15,5,2);
3636
3637 TQGridLayout *grid3 = new TQGridLayout( 1, 2 );
3638 color = new KColorButton (tmpTQGroupBox, "ColorButton_1" );
3639 grid3->addWidget(color,0,1);
3640
3641 TQLabel *tmpTQLabel = new TQLabel( tmpTQGroupBox, "Label_1" );
3642 tmpTQLabel->setText( i18n("Color:") );
3643 grid3->addWidget(tmpTQLabel,0,0);
3644
3645 grid2->addMultiCell(grid3,6,6,0,2);
3646
3647 grid3 = new TQGridLayout( 1, 3 );
3648 grid3->setSpacing(KDialog::spacingHint());
3649
3650 tmpTQLabel = new TQLabel( tmpTQGroupBox, "Label_2" );
3651 grid3->addWidget(tmpTQLabel,0,0);
3652 tmpTQLabel->setText( i18n("Background color:") );
3653
3654 bgColorButton = new KColorButton( tmpTQGroupBox, "ColorButton" );
3655 grid3->addWidget(bgColorButton,0,1);
3656 if ( dlg->bBgColor )
3657 bgColor = dlg->bgColor;
3658 else
3659 bgColor = colorGroup().base();
3660
3661 if (!bgColor.isValid())
3662 bgColor = colorGroup().base();
3663
3664 bgColorButton->setColor( bgColor );
3665 connect( bgColorButton, TQ_SIGNAL( changed( const TQColor & ) ),
3666 this, TQ_SLOT( slotSetBackgroundColor( const TQColor & ) ) );
3667
3668 notAnyColor=new TQPushButton(i18n("No Color"),tmpTQGroupBox);
3669 grid3->addWidget(notAnyColor,0,2);
3670 connect( notAnyColor, TQ_SIGNAL( clicked( ) ),
3671 this, TQ_SLOT( slotNotAnyColor( ) ) );
3672 b_notAnyColor=false;
3673
3674 grid2->addMultiCell(grid3,7,7,0,2);
3675
3676 grid->addMultiCellWidget(tmpTQGroupBox,0,3,0,0);
3677
3678 tmpTQGroupBox = new TQGroupBox( this, "GroupBox1" );
3679 tmpTQGroupBox->setTitle( i18n("Preview") );
3680 tmpTQGroupBox->setFrameStyle( TQFrame::Box | TQFrame::Sunken );
3681 tmpTQGroupBox->setAlignment( AlignLeft );
3682
3683 grid2 = new TQGridLayout(tmpTQGroupBox,2,1,KDialog::marginHint(), KDialog::spacingHint());
3684 fHeight = tmpTQGroupBox->fontMetrics().height();
3685 grid2->addRowSpacing( 0, fHeight/2 ); // groupbox title
3686
3687 current = new BrushSelect( tmpTQGroupBox, "Current" );
3688 current->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
3689 grid2->addWidget(current,1,0);
3690 grid->addWidget( tmpTQGroupBox,4,0);
3691
3692 connect( brush1, TQ_SIGNAL( clicked( BrushSelect* ) ),
3693 this, TQ_SLOT( slotUnselect2( BrushSelect* ) ) );
3694 connect( brush2, TQ_SIGNAL( clicked( BrushSelect* ) ),
3695 this, TQ_SLOT( slotUnselect2( BrushSelect* ) ) );
3696 connect( brush3, TQ_SIGNAL( clicked( BrushSelect* ) ),
3697 this, TQ_SLOT( slotUnselect2( BrushSelect* ) ) );
3698 connect( brush4, TQ_SIGNAL( clicked( BrushSelect* ) ),
3699 this, TQ_SLOT( slotUnselect2( BrushSelect* ) ) );
3700 connect( brush5, TQ_SIGNAL( clicked( BrushSelect* ) ),
3701 this, TQ_SLOT( slotUnselect2( BrushSelect* ) ) );
3702 connect( brush6, TQ_SIGNAL( clicked( BrushSelect* ) ),
3703 this, TQ_SLOT( slotUnselect2( BrushSelect* ) ) );
3704 connect( brush7, TQ_SIGNAL( clicked( BrushSelect* ) ),
3705 this, TQ_SLOT( slotUnselect2( BrushSelect* ) ) );
3706 connect( brush8, TQ_SIGNAL( clicked( BrushSelect* ) ),
3707 this, TQ_SLOT( slotUnselect2( BrushSelect* ) ) );
3708 connect( brush9, TQ_SIGNAL( clicked( BrushSelect* ) ),
3709 this, TQ_SLOT( slotUnselect2( BrushSelect* ) ) );
3710 connect( brush10, TQ_SIGNAL( clicked( BrushSelect* ) ),
3711 this, TQ_SLOT( slotUnselect2( BrushSelect* ) ) );
3712 connect( brush11, TQ_SIGNAL( clicked( BrushSelect* ) ),
3713 this, TQ_SLOT( slotUnselect2( BrushSelect* ) ) );
3714 connect( brush12, TQ_SIGNAL( clicked( BrushSelect* ) ),
3715 this, TQ_SLOT( slotUnselect2( BrushSelect* ) ) );
3716 connect( brush13, TQ_SIGNAL( clicked( BrushSelect* ) ),
3717 this, TQ_SLOT( slotUnselect2( BrushSelect* ) ) );
3718 connect( brush14, TQ_SIGNAL( clicked( BrushSelect* ) ),
3719 this, TQ_SLOT( slotUnselect2( BrushSelect* ) ) );
3720 connect( brush15, TQ_SIGNAL( clicked( BrushSelect* ) ),
3721 this, TQ_SLOT( slotUnselect2( BrushSelect* ) ) );
3722
3723 brush1->setPattern( TQt::red,TQt::VerPattern );
3724 brush2->setPattern( TQt::red,TQt::HorPattern );
3725 brush3->setPattern( TQt::red,TQt::Dense1Pattern );
3726 brush4->setPattern( TQt::red,TQt::Dense2Pattern );
3727 brush5->setPattern( TQt::red,TQt::Dense3Pattern );
3728 brush6->setPattern( TQt::red,TQt::Dense4Pattern );
3729 brush7->setPattern( TQt::red,TQt::Dense5Pattern );
3730 brush8->setPattern( TQt::red,TQt::Dense6Pattern );
3731 brush9->setPattern( TQt::red,TQt::Dense7Pattern );
3732 brush10->setPattern( TQt::red,TQt::CrossPattern );
3733 brush11->setPattern( TQt::red,TQt::BDiagPattern );
3734 brush12->setPattern( TQt::red,TQt::FDiagPattern );
3735 brush13->setPattern( TQt::red,TQt::VerPattern );
3736 brush14->setPattern( TQt::red,TQt::DiagCrossPattern );
3737 brush15->setPattern( TQt::red,TQt::NoBrush );
3738
3739 current->setPattern(dlg->brushColor,dlg->brushStyle);
3740 current->slotSelect();
3741 selectedBrush=current;
3742 color->setColor(dlg->brushColor);
3743 current->setBackgroundColor( bgColor );
3744
3745 connect( color, TQ_SIGNAL( changed( const TQColor & ) ),
3746 this, TQ_SLOT( slotSetColorButton( const TQColor & ) ) );
3747
3748 slotSetColorButton( dlg->brushColor );
3749 init();
3750 this->resize( 400, 400 );
3751}
3752
3753void CellFormatPagePattern::slotNotAnyColor()
3754{
3755 b_notAnyColor = true;
3756 bgColorButton->setColor( colorGroup().base() );
3757 current->setBackgroundColor( colorGroup().base() );
3758}
3759
3760void CellFormatPagePattern::slotSetBackgroundColor( const TQColor &_color )
3761{
3762 bgColor =_color;
3763 current->setBackgroundColor( bgColor );
3764 bBgColorUndefined = false;
3765 b_notAnyColor = false;
3766}
3767
3768void CellFormatPagePattern::init()
3769{
3770 if (dlg->brushStyle == TQt::VerPattern)
3771 {
3772 brush1->slotSelect();
3773 }
3774 else if (dlg->brushStyle == TQt::HorPattern)
3775 {
3776 brush2->slotSelect();
3777 }
3778 else if (dlg->brushStyle == TQt::Dense1Pattern)
3779 {
3780 brush3->slotSelect();
3781 }
3782 else if (dlg->brushStyle == TQt::Dense2Pattern)
3783 {
3784 brush4->slotSelect();
3785 }
3786 else if (dlg->brushStyle == TQt::Dense3Pattern)
3787 {
3788 brush5->slotSelect();
3789 }
3790 else if (dlg->brushStyle == TQt::Dense4Pattern)
3791 {
3792 brush6->slotSelect();
3793 }
3794 else if (dlg->brushStyle == TQt::Dense5Pattern)
3795 {
3796 brush7->slotSelect();
3797 }
3798 else if (dlg->brushStyle == TQt::Dense6Pattern)
3799 {
3800 brush8->slotSelect();
3801 }
3802 else if (dlg->brushStyle == TQt::Dense7Pattern)
3803 {
3804 brush9->slotSelect();
3805 }
3806 else if (dlg->brushStyle == TQt::CrossPattern)
3807 {
3808 brush10->slotSelect();
3809 }
3810 else if (dlg->brushStyle == TQt::BDiagPattern)
3811 {
3812 brush11->slotSelect();
3813 }
3814 else if (dlg->brushStyle == TQt::FDiagPattern)
3815 {
3816 brush12->slotSelect();
3817 }
3818 else if (dlg->brushStyle == TQt::VerPattern)
3819 {
3820 brush13->slotSelect();
3821 }
3822 else if (dlg->brushStyle == TQt::DiagCrossPattern)
3823 {
3824 brush14->slotSelect();
3825 }
3826 else if (dlg->brushStyle == TQt::NoBrush)
3827 {
3828 brush15->slotSelect();
3829 }
3830 else
3831 kdDebug(36001) << "Error in brushStyle" << endl;
3832}
3833
3834void CellFormatPagePattern::slotSetColorButton( const TQColor &_color )
3835{
3836 currentColor = _color;
3837
3838 brush1->setBrushColor( currentColor );
3839 brush2->setBrushColor( currentColor );
3840 brush3->setBrushColor( currentColor );
3841 brush4->setBrushColor( currentColor );
3842 brush5->setBrushColor( currentColor );
3843 brush6->setBrushColor( currentColor );
3844 brush7->setBrushColor( currentColor );
3845 brush8->setBrushColor( currentColor );
3846 brush9->setBrushColor( currentColor );
3847 brush10->setBrushColor( currentColor );
3848 brush11->setBrushColor( currentColor );
3849 brush12->setBrushColor( currentColor );
3850 brush13->setBrushColor( currentColor );
3851 brush14->setBrushColor( currentColor );
3852 brush15->setBrushColor( currentColor );
3853 current->setBrushColor( currentColor );
3854}
3855
3856void CellFormatPagePattern::slotUnselect2( BrushSelect *_p )
3857{
3858 selectedBrush = _p;
3859
3860 if ( brush1 != _p )
3861 brush1->slotUnselect();
3862 if ( brush2 != _p )
3863 brush2->slotUnselect();
3864 if ( brush3 != _p )
3865 brush3->slotUnselect();
3866 if ( brush4 != _p )
3867 brush4->slotUnselect();
3868 if ( brush5 != _p )
3869 brush5->slotUnselect();
3870 if ( brush6 != _p )
3871 brush6->slotUnselect();
3872 if ( brush7 != _p )
3873 brush7->slotUnselect();
3874 if ( brush8 != _p )
3875 brush8->slotUnselect();
3876 if ( brush9 != _p )
3877 brush9->slotUnselect();
3878 if ( brush10 != _p )
3879 brush10->slotUnselect();
3880 if ( brush11 != _p )
3881 brush11->slotUnselect();
3882 if ( brush12 != _p )
3883 brush12->slotUnselect();
3884 if ( brush13 != _p )
3885 brush13->slotUnselect();
3886 if ( brush14 != _p )
3887 brush14->slotUnselect();
3888 if ( brush15 != _p )
3889 brush15->slotUnselect();
3890
3891 current->setBrushStyle( selectedBrush->getBrushStyle() );
3892}
3893
3894void CellFormatPagePattern::apply( CustomStyle * style )
3895{
3896 if ( selectedBrush != 0L
3897 && ( dlg->brushStyle != selectedBrush->getBrushStyle()
3898 || dlg->brushColor != selectedBrush->getBrushColor() ) )
3899 style->changeBackGroundBrush( TQBrush( selectedBrush->getBrushColor(), selectedBrush->getBrushStyle() ) );
3900
3901 /*
3902 TODO: check...
3903 if ( b_notAnyColor)
3904 style->changeBgColor( TQColor() );
3905 else
3906 */
3907 if ( bgColor != dlg->getStyle()->bgColor() )
3908 style->changeBgColor( bgColor );
3909}
3910
3911void CellFormatPagePattern::apply(FormatManipulator *_obj)
3912{
3913 if ( selectedBrush != 0L
3914 && ( dlg->brushStyle != selectedBrush->getBrushStyle()
3915 || dlg->brushColor != selectedBrush->getBrushColor() ) )
3916 _obj->setBackgroundBrush( TQBrush( selectedBrush->getBrushColor(), selectedBrush->getBrushStyle() ) );
3917
3918 if ( bgColor == dlg->bgColor )
3919 return;
3920
3921 if ( b_notAnyColor)
3922 _obj->setBackgroundColor( TQColor() );
3923 else if ( !bBgColorUndefined )
3924 _obj->setBackgroundColor( bgColor );
3925}
3926
3927#include "kspread_dlg_layout.moc"
3928
Dialog for the "Cell Format..." action.
CellFormatDialog(View *_view, Sheet *_sheet)
Create a format dlg for the rectangular area in '_sheet'.
int exec()
Run the dialogs event loop and return when closed.
TQPixmap * paintFormatPixmap(const char *_string1, const TQColor &_color1, const char *_string2, const TQColor &_color2)
Draws a pixmap showing a text consisting of two parts, _string1 and _string2 .
For every cell in the spread sheet there is a Cell object.
int row() const
Returns the cell's row.
const Value value() const
Returns the value that this cell holds.
TQValueList< Cell * > obscuringCells() const
bool doesMergeCells() const
int column() const
Returns the cell's column.
int extraXCells() const
int extraYCells() const
Format * format() const
Returns the format object of this cell.
const TQColor & bgColor(int col, int row) const
bool isPartOfMerged() const
If this cell is part of a merged cell, then the marker may never reside on this cell.
Built-in or custom style defined in StyleManager dialog.
This class holds the data that makes up a spreadsheet.
Definition kspread_doc.h:98
TQString unitName() const
Returns the name of the unit used to display margins.
FormatManipulator.
Element * add(const TQPoint &point, Sheet *sheet=0)
Adds the point point to this region.
Definition region.cpp:245
bool isRowSelected(uint row=0) const
Definition region.cpp:541
bool isColumnSelected(uint col=0) const
Definition region.cpp:525
@ BUILTIN
built-in style (the default style)
@ CUSTOM
custom style (defined in the StyleManager dialog)
TQString timeFormat(const TQDateTime &_time, FormatType fmtType)
create a time format
TQString dateFormat(const TQDate &_date, FormatType fmtType)
create a date format
TQString formatText(Cell *cell, FormatType fmtType)
create a text representation of data in this cell
The View class displays a KSpread document.
void refreshView()
refresh view when you hide/show vertical scrollbar
The KSpread namespace.
Definition commands.h:39