kspread

kspread_dlg_layout.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
00003              (C) 2004 Tomas Mecir <mecirt@gmail.com>
00004              (C) 2002-2004 Ariya Hidayat <ariya@kde.org>
00005              (C) 2002-2003 Norbert Andres <nandres@web.de>
00006              (C) 2001-2003 Philipp Mueller <philipp.mueller@gmx.de>
00007              (C) 2002 John Dailey <dailey@vt.edu>
00008              (C) 1999-2002 Laurent Montel <montel@kde.org>
00009              (C) 1999-2002 Harri Porten <porten@kde.org>
00010              (C) 2000-2001 David Faure <faure@kde.org>
00011              (C) 1998-2000 Torben Weis <weis@kde.org>
00012              (C) 2000 Werner Trobin <trobin@kde.org>
00013              (C) 1999 Reginald Stadlbauer <reggie@kde.org>
00014              (C) 1998-1999 Stephan Kulow <coolo@kde.org>
00015 
00016    This library is free software; you can redistribute it and/or
00017    modify it under the terms of the GNU Library General Public
00018    License as published by the Free Software Foundation; either
00019    version 2 of the License, or (at your option) any later version.
00020 
00021    This library is distributed in the hope that it will be useful,
00022    but WITHOUT ANY WARRANTY; without even the implied warranty of
00023    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00024    Library General Public License for more details.
00025 
00026    You should have received a copy of the GNU Library General Public License
00027    along with this library; see the file COPYING.LIB.  If not, write to
00028    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00029  * Boston, MA 02110-1301, USA.
00030 */
00031 
00032 #include <stdlib.h>
00033 #include <math.h>
00034 
00035 #include <qbitmap.h>
00036 #include <qcheckbox.h>
00037 #include <qframe.h>
00038 #include <qlabel.h>
00039 #include <qlayout.h>
00040 #include <qlistbox.h>
00041 #include <qfontdatabase.h>
00042 #include <qradiobutton.h>
00043 #include <qslider.h>
00044 #include <qwhatsthis.h>
00045 
00046 #include <kcolorbutton.h>
00047 #include <kcombobox.h>
00048 #include <kdebug.h>
00049 #include <kdialog.h>
00050 #include <klineedit.h>
00051 #include <kmessagebox.h>
00052 #include <knumvalidator.h>
00053 
00054 #include <KoUnitWidgets.h>
00055 
00056 #include "kspread_canvas.h"
00057 #include "kspread_dlg_layout.h"
00058 #include "kspread_locale.h"
00059 #include "kspread_sheet.h"
00060 #include "kspread_style.h"
00061 #include "kspread_style_manager.h"
00062 #include "kspread_undo.h"
00063 #include "kspread_util.h"
00064 #include "manipulator.h"
00065 #include "selection.h"
00066 #include "valueformatter.h"
00067 
00068 using namespace KSpread;
00069 
00070 /***************************************************************************
00071  *
00072  * PatternSelect
00073  *
00074  ***************************************************************************/
00075 
00076 PatternSelect::PatternSelect( QWidget *parent, const char * )
00077   : QFrame( parent )
00078 {
00079     penStyle = NoPen;
00080     penWidth = 1;
00081     penColor = colorGroup().text();
00082     selected = false;
00083     undefined = false;
00084 }
00085 
00086 void PatternSelect::setPattern( const QColor &_color, int _width, PenStyle _style )
00087 {
00088     penStyle = _style;
00089     penColor = _color;
00090     penWidth = _width;
00091     repaint();
00092 }
00093 
00094 void PatternSelect::setUndefined()
00095 {
00096     undefined = true;
00097 }
00098 
00099 void PatternSelect::paintEvent( QPaintEvent *_ev )
00100 {
00101     QFrame::paintEvent( _ev );
00102 
00103     QPainter painter( this );
00104 
00105     if ( !undefined )
00106     {
00107         QPen pen( penColor, penWidth, penStyle);
00108         painter.setPen( pen );
00109         painter.drawLine( 6, height()/2, width() - 6,height()/2  );
00110     }
00111     else
00112     {
00113         painter.fillRect( 2, 2, width() - 4, height() - 4, BDiagPattern );
00114     }
00115 }
00116 
00117 void PatternSelect::mousePressEvent( QMouseEvent * )
00118 {
00119     slotSelect();
00120 
00121     emit clicked( this );
00122 }
00123 
00124 void PatternSelect::slotUnselect()
00125 {
00126     selected = false;
00127 
00128     setLineWidth( 1 );
00129     setFrameStyle( QFrame::Panel | QFrame::Sunken );
00130     repaint();
00131 }
00132 
00133 void PatternSelect::slotSelect()
00134 {
00135     selected = true;
00136 
00137     setLineWidth( 2 );
00138     setFrameStyle( QFrame::Panel | QFrame::Plain );
00139     repaint();
00140 }
00141 
00142 
00143 
00144 /***************************************************************************
00145  *
00146  * GeneralTab
00147  *
00148  ***************************************************************************/
00149 
00150 GeneralTab::GeneralTab( QWidget* parent, CellFormatDialog * dlg )
00151   : QWidget( parent ),
00152     m_dlg( dlg )
00153 {
00154   QGridLayout * layout = new QGridLayout( this, 1, 1, KDialog::marginHint(), KDialog::spacingHint(), "layout");
00155 
00156   QGroupBox * groupBox = new QGroupBox( this, "groupBox1" );
00157   groupBox->setColumnLayout(0, Qt::Vertical );
00158   groupBox->setTitle( i18n( "Style" ) );
00159   groupBox->layout()->setSpacing( KDialog::spacingHint() );
00160   groupBox->layout()->setMargin( KDialog::marginHint() );
00161 
00162   QGridLayout * groupBoxLayout = new QGridLayout( groupBox->layout() );
00163   groupBoxLayout->setAlignment( Qt::AlignTop );
00164 
00165   QLabel * label1 = new QLabel( groupBox, "label1" );
00166   label1->setText( i18n( "Name:" ) );
00167   groupBoxLayout->addWidget( label1, 0, 0 );
00168 
00169   m_nameEdit = new KLineEdit( groupBox, "m_nameEdit" );
00170   m_nameEdit->setText( m_dlg->styleName );
00171   groupBoxLayout->addWidget( m_nameEdit, 0, 1 );
00172 
00173   QLabel * label2 = new QLabel( groupBox, "label2" );
00174   label2->setText( i18n( "Inherit style:" ) );
00175   groupBoxLayout->addWidget( label2, 1, 0 );
00176 
00177   m_parentBox = new KComboBox( false, groupBox, "m_parentBox" );
00178   m_parentBox->clear();
00179   m_parentBox->insertItem( i18n( "<None>" ) );
00180   QStringList tmp = m_dlg->getStyleManager()->styleNames();
00181   tmp.remove( m_dlg->styleName );
00182   m_parentBox->insertStringList( tmp );
00183 
00184   if ( m_dlg->getStyle()->parent() )
00185     m_parentBox->setCurrentText( m_dlg->getStyle()->parentName() );
00186   else
00187   {
00188     m_parentBox->setCurrentText( i18n( "<None>" ) );
00189 
00190     if ( m_dlg->getStyle()->definesAll() )
00191       m_parentBox->setEnabled( false );
00192   }
00193 
00194   connect( m_parentBox, SIGNAL( textChanged( const QString & ) ), this, SLOT( slotNewParent( const QString & ) ) );
00195   connect( m_nameEdit, SIGNAL( lostFocus() ), this, SLOT( slotNameChanged() ) );
00196 
00197   groupBoxLayout->addWidget( m_parentBox, 1, 1 );
00198 
00199   QSpacerItem * spacer = new QSpacerItem( 20, 260, QSizePolicy::Minimum, QSizePolicy::Expanding );
00200 
00201   layout->addWidget( groupBox, 0, 0 );
00202   layout->addItem( spacer, 1, 0 );
00203 
00204   if ( m_dlg->getStyle()->type() == Style::BUILTIN )
00205   {
00206     m_nameEdit->setEnabled( false );
00207     m_parentBox->setEnabled( false );
00208   }
00209 
00210   resize( QSize( 534, 447 ).expandedTo(minimumSizeHint()) );
00211 }
00212 
00213 GeneralTab::~GeneralTab()
00214 {
00215 }
00216 
00217 void GeneralTab::slotNameChanged()
00218 {
00219   checkName();
00220 }
00221 
00222 void GeneralTab::slotNewParent( const QString & parentName )
00223 {
00224   kdDebug() << "New Parent" << endl;
00225   if ( !checkParent( parentName ) )
00226     return;
00227 
00228   if ( parentName.isEmpty() || parentName == i18n( "<None>" ) )
00229     m_dlg->getStyle()->setParent( 0 );
00230   else
00231     m_dlg->getStyle()->setParent( m_dlg->getStyleManager()->style( parentName ) );
00232 
00233   // Set difference to new parent, set GUI to parent values, add changes made before
00234   //  m_dlg->initGUI();
00235 }
00236 
00237 bool GeneralTab::checkName()
00238 {
00239   if ( m_nameEdit->isEnabled() )
00240   {
00241     if ( !m_dlg->getStyleManager()->validateStyleName( m_nameEdit->text(), m_dlg->getStyle() ) )
00242     {
00243       KMessageBox::sorry( this, i18n( "A style with this name already exists." ) );
00244       return false;
00245     }
00246   }
00247 
00248   return true;
00249 }
00250 
00251 bool GeneralTab::checkParent( const QString & parentName )
00252 {
00253   if ( m_dlg->getStyle()->parentName() != parentName
00254        && m_parentBox->isEnabled() && parentName != i18n( "<None>" ) && !parentName.isEmpty() )
00255   {
00256     if ( m_nameEdit->text() == parentName )
00257     {
00258       KMessageBox::sorry( this, i18n( "A style cannot inherit from itself." ) );
00259       return false;
00260     }
00261     if ( !m_dlg->checkCircle( m_nameEdit->text(), parentName ) )
00262     {
00263       KMessageBox::sorry( this,
00264                           i18n( "The style cannot inherit from '%1' because of recursive references." )
00265                           .arg( m_parentBox->currentText() ) );
00266       return false;
00267     }
00268 
00269     CustomStyle * p = m_dlg->getStyleManager()->style( parentName );
00270 
00271     if ( !p )
00272     {
00273       KMessageBox::sorry( this, i18n( "The parent style does not exist." ) );
00274       return false;
00275     }
00276   }
00277 
00278   return true;
00279 }
00280 
00281 bool GeneralTab::apply( CustomStyle * style )
00282 {
00283   if ( !checkParent( m_parentBox->currentText() ) )
00284     return false;
00285 
00286   if ( !checkName() )
00287     return false;
00288 
00289   if ( m_nameEdit->isEnabled() )
00290   {
00291     if ( style->type() != Style::BUILTIN )
00292     {
00293       QString name( style->name() );
00294       style->setName( m_nameEdit->text() );
00295       if ( m_parentBox->isEnabled() )
00296       {
00297         if ( m_parentBox->currentText() == i18n( "None" ) || m_parentBox->currentText().isEmpty() )
00298           style->setParent( 0 );
00299         else
00300           style->setParent( m_dlg->getStyleManager()->style( m_parentBox->currentText() ) );
00301       }
00302       m_dlg->getStyleManager()->changeName( name, m_nameEdit->text() );
00303     }
00304   }
00305 
00306   if ( style->type() == Style::TENTATIVE )
00307     style->setType( Style::CUSTOM );
00308 
00309   return true;
00310 }
00311 
00312 
00313 
00314 /***************************************************************************
00315  *
00316  * CellFormatDialog
00317  *
00318  ***************************************************************************/
00319 
00320 CellFormatDialog::CellFormatDialog( View * _view, Sheet * _sheet )
00321   : QObject(),
00322     m_doc( _sheet->doc() ),
00323     m_sheet( _sheet ),
00324     m_pView( _view ),
00325     m_style( 0 )
00326 {
00327   initMembers();
00328 
00329   //We need both conditions quite often, so store the condition here too
00330   isRowSelected    = _view->selectionInfo()->isRowSelected();
00331   isColumnSelected = _view->selectionInfo()->isColumnSelected();
00332 
00333   QRect range = _view->selectionInfo()->selection();
00334   left = range.left();
00335   top = range.top();
00336   right = range.right();
00337   bottom = range.bottom();
00338 
00339   if ( left == right )
00340     oneCol = true;
00341   else
00342     oneCol = false;
00343 
00344   if ( top == bottom )
00345     oneRow = true;
00346   else
00347     oneRow = false;
00348 
00349   Cell* obj = m_sheet->cellAt( left, top );
00350   oneCell = (left == right && top == bottom &&
00351              !obj->doesMergeCells());
00352 
00353   isMerged = ((obj->doesMergeCells() &&
00354                left + obj->extraXCells() >= right &&
00355                top + obj->extraYCells() >= bottom));
00356 
00357   // Initialize with the upper left object.
00358   borders[BorderType_Left].style = obj->format()->leftBorderStyle( left, top );
00359   borders[BorderType_Left].width = obj->format()->leftBorderWidth( left, top );
00360   borders[BorderType_Left].color = obj->format()->leftBorderColor( left, top );
00361   borders[BorderType_Top].style = obj->format()->topBorderStyle( left, top );
00362   borders[BorderType_Top].width = obj->format()->topBorderWidth( left, top );
00363   borders[BorderType_Top].color = obj->format()->topBorderColor( left, top );
00364   borders[BorderType_FallingDiagonal].style =
00365       obj->format()->fallDiagonalStyle( left, top );
00366   borders[BorderType_FallingDiagonal].width =
00367       obj->format()->fallDiagonalWidth( left, top );
00368   borders[BorderType_FallingDiagonal].color =
00369       obj->format()->fallDiagonalColor( left, top );
00370   borders[BorderType_RisingDiagonal].style =
00371       obj->format()->goUpDiagonalStyle( left, top );
00372   borders[BorderType_RisingDiagonal].width =
00373       obj->format()->goUpDiagonalWidth( left, top );
00374   borders[BorderType_RisingDiagonal].color =
00375       obj->format()->goUpDiagonalColor( left, top );
00376 
00377   // Look at the upper right one for the right border.
00378   obj = m_sheet->cellAt( right, top );
00379   borders[BorderType_Right].style = obj->format()->rightBorderStyle( right, top );
00380   borders[BorderType_Right].width = obj->format()->rightBorderWidth( right, top );
00381   borders[BorderType_Right].color = obj->format()->rightBorderColor( right, top );
00382 
00383   // Look at the bottom left cell for the bottom border.
00384   obj = m_sheet->cellAt( left, bottom );
00385   borders[BorderType_Bottom].style = obj->format()->bottomBorderStyle( left, bottom );
00386   borders[BorderType_Bottom].width = obj->format()->bottomBorderWidth( left, bottom );
00387   borders[BorderType_Bottom].color = obj->format()->bottomBorderColor( left, bottom );
00388 
00389   // Just an assumption
00390   obj = m_sheet->cellAt( right, top );
00391   if ( obj->isPartOfMerged() )
00392   {
00393     obj = obj->obscuringCells().first();
00394     int moveX  = obj->column();
00395     int moveY  = top;
00396     int moveX2 = right;
00397     int moveY2 = obj->row();
00398     borders[BorderType_Vertical].style = obj->format()->leftBorderStyle( moveX, moveY );
00399     borders[BorderType_Vertical].width = obj->format()->leftBorderWidth( moveX, moveY );
00400     borders[BorderType_Vertical].color = obj->format()->leftBorderColor( moveX, moveY );
00401 
00402     obj = m_sheet->cellAt( moveX2,  moveY2 );
00403     borders[BorderType_Horizontal].style = obj->format()->topBorderStyle( moveX2, moveY2 );
00404     borders[BorderType_Horizontal].width = obj->format()->topBorderWidth( moveX2, moveY2 );
00405     borders[BorderType_Horizontal].color = obj->format()->topBorderColor( moveX2, moveY2 );
00406   }
00407   else
00408   {
00409     borders[BorderType_Vertical].style = obj->format()->leftBorderStyle( right, top );
00410     borders[BorderType_Vertical].width = obj->format()->leftBorderWidth( right, top );
00411     borders[BorderType_Vertical].color = obj->format()->leftBorderColor( right, top );
00412     borders[BorderType_Horizontal].style = obj->format()->topBorderStyle(right, bottom);
00413     borders[BorderType_Horizontal].width = obj->format()->topBorderWidth(right, bottom);
00414     borders[BorderType_Horizontal].color = obj->format()->topBorderColor(right, bottom);
00415   }
00416 
00417   obj = m_sheet->cellAt( left, top );
00418   prefix = obj->format()->prefix( left, top );
00419   postfix = obj->format()->postfix( left, top );
00420   precision = obj->format()->precision( left, top );
00421   floatFormat = obj->format()->floatFormat( left, top );
00422   floatColor = obj->format()->floatColor( left, top );
00423   alignX = obj->format()->align( left, top );
00424   alignY = obj->format()->alignY( left, top );
00425   textColor = obj->format()->textColor( left, top );
00426   bgColor = obj->bgColor( left, top );
00427   textFontSize = obj->format()->textFontSize( left, top );
00428   textFontFamily = obj->format()->textFontFamily( left, top );
00429   textFontBold = obj->format()->textFontBold( left, top );
00430   textFontItalic = obj->format()->textFontItalic( left, top );
00431   strike=obj->format()->textFontStrike( left, top );
00432   underline = obj->format()->textFontUnderline( left, top );
00433   // Needed to initialize the font correctly ( bug in Qt )
00434   textFont = obj->format()->textFont( left, top );
00435   obj->format()->currencyInfo( cCurrency );
00436 
00437   brushColor = obj->format()->backGroundBrushColor( left, top );
00438   brushStyle = obj->format()->backGroundBrushStyle( left,top );
00439 
00440   bMultiRow = obj->format()->multiRow( left, top );
00441   bVerticalText = obj->format()->verticalText( left, top );
00442   textRotation = obj->format()->getAngle(left, top);
00443   formatType = obj->format()->getFormatType(left, top);
00444 
00445   bDontPrintText = obj->format()->getDontprintText( left, top );
00446   bHideFormula   = obj->format()->isHideFormula( left, top );
00447   bHideAll       = obj->format()->isHideAll( left, top );
00448   bIsProtected   = !obj->format()->notProtected( left, top );
00449 
00450   indent = obj->format()->getIndent(left, top);
00451 
00452   value = obj->value();
00453 
00454   RowFormat *rl;
00455   ColumnFormat *cl;
00456   widthSize = 0.0;
00457   heightSize = 0.0;
00458 
00459   if ( !isRowSelected )
00460   {
00461     for ( int x = left; x <= right; x++ )
00462     {
00463       cl = m_pView->activeSheet()->columnFormat( x );
00464       widthSize = QMAX( cl->dblWidth(), widthSize );
00465     }
00466   }
00467 
00468   if ( !isColumnSelected )
00469   {
00470     for ( int y = top; y <= bottom; y++ )
00471     {
00472       rl = m_pView->activeSheet()->rowFormat(y);
00473       heightSize = QMAX( rl->dblHeight(), heightSize );
00474     }
00475   }
00476 
00477   //select column(s)
00478   if ( isColumnSelected )
00479   {
00480     int y = 1;
00481     Cell* cell = NULL;
00482     for (int x = left;x <= right; x++)
00483     {
00484       ColumnFormat *obj = m_sheet->nonDefaultColumnFormat(x);
00485       initParameters( obj,x,y);
00486 
00487       for (cell = m_sheet->getFirstCellColumn(x); cell != NULL;
00488            cell = m_sheet->getNextCellDown(cell->column(), cell->row()))
00489       {
00490         initParameters( cell->format(), x, cell->row());
00491       }
00492     }
00493 
00494   }
00495   else if ( isRowSelected )
00496   {
00497     int x = 1;
00498     Cell* c = NULL;
00499     for ( int y = top;y<=bottom;y++)
00500     {
00501       RowFormat *obj = m_sheet->nonDefaultRowFormat(y);
00502       initParameters( obj,x,y);
00503 
00504       for (c = m_sheet->getFirstCellRow(y); c != NULL;
00505            c = m_sheet->getNextCellRight(c->column(), c->row()) )
00506       {
00507         initParameters( c->format(), c->column(), c->row());
00508       }
00509       }
00510   }
00511   else
00512   {
00513     // Do the other objects have the same values ?
00514     for ( int x = left; x <= right; x++ )
00515     {
00516       for ( int y = top; y <= bottom; y++ )
00517       {
00518         Cell *obj = m_sheet->cellAt( x, y );
00519 
00520         if ( obj->isPartOfMerged() )
00521           continue;
00522 
00523         initParameters( obj->format(),x,y);
00524       }
00525     }
00526   }
00527   if ( !bTextRotation )
00528     textRotation = 0;
00529 
00530   if ( isColumnSelected )
00531   {
00532     int y=1;
00533     ColumnFormat *obj=m_sheet->nonDefaultColumnFormat(left);
00534     checkBorderLeft( obj,left, y);
00535 
00536     Cell* c = NULL;
00537     for (c = m_sheet->getFirstCellColumn(left); c != NULL;
00538          c = m_sheet->getNextCellDown(c->column(), c->row()) )
00539     {
00540       checkBorderLeft(c->format(), c->column(), c->row());
00541     }
00542 
00543 
00544     obj=m_sheet->nonDefaultColumnFormat(right);
00545     checkBorderRight(obj,right,y);
00546     c = NULL;
00547     for (c = m_sheet->getFirstCellColumn(right); c != NULL;
00548          c = m_sheet->getNextCellDown(c->column(), c->row()) )
00549     {
00550       checkBorderRight(c->format(), c->column(), c->row());
00551     }
00552 
00553     for ( int x = left; x <= right; x++ )
00554     {
00555       Cell *obj = m_sheet->cellAt( x, top );
00556       checkBorderTop(obj->format(),x, top);
00557       obj = m_sheet->cellAt( x, bottom );
00558       checkBorderBottom(obj->format(),x, bottom);
00559       if ( x > left )
00560       {
00561         ColumnFormat *obj = m_sheet->nonDefaultColumnFormat(x);
00562         checkBorderHorizontal(obj,x, y);
00563         checkBorderVertical(obj,x, y);
00564       }
00565     }
00566   }
00567   else if ( isRowSelected )
00568   {
00569     int x=1;
00570     for ( int y = top; y <= bottom; y++ )
00571     {
00572       Cell *obj = m_sheet->cellAt( right, y );
00573       checkBorderRight(obj->format(),right,y);
00574       obj = m_sheet->cellAt( left, y );
00575       checkBorderLeft( obj->format(),left, y);
00576       if ( y > top )
00577       {
00578         RowFormat* obj = m_sheet->nonDefaultRowFormat(y);
00579         checkBorderHorizontal(obj,x, y);
00580         checkBorderVertical(obj,x, y);
00581       }
00582     }
00583 
00584     RowFormat *obj=m_sheet->nonDefaultRowFormat(top);
00585     checkBorderTop(obj,x, top);
00586     obj=m_sheet->nonDefaultRowFormat(bottom);
00587     checkBorderBottom(obj,x, bottom);
00588   }
00589   else
00590   {
00591     for ( int y = top; y <= bottom; y++ )
00592     {
00593       Cell *obj = m_sheet->cellAt( left, y );
00594       checkBorderLeft( obj->format(),left, y);
00595       obj = m_sheet->cellAt( right, y );
00596       checkBorderRight(obj->format(),right,y);
00597     }
00598 
00599     for ( int x = left; x <= right; x++ )
00600     {
00601       Cell *obj = m_sheet->cellAt( x, top );
00602       checkBorderTop( obj->format(), x, top );
00603       obj = m_sheet->cellAt( x, bottom );
00604       checkBorderBottom( obj->format(), x, bottom );
00605     }
00606 
00607     // Look for the Outline
00608     for ( int x = left; x <= right; x++ )
00609     {
00610       for ( int y = top+1; y <= bottom; y++ )
00611       {
00612         Cell *obj = m_sheet->cellAt( x, y );
00613         checkBorderHorizontal(obj->format(),x, y);
00614       }
00615     }
00616 
00617     for ( int x = left+1; x <= right; x++ )
00618     {
00619       for ( int y = top; y <= bottom; y++ )
00620       {
00621         Cell *obj = m_sheet->cellAt( x, y );
00622         checkBorderVertical(obj->format(),x,y);
00623       }
00624     }
00625   }
00626 
00627   init();
00628 }
00629 
00630 CellFormatDialog::CellFormatDialog( View * _view, CustomStyle * _style,
00631                               StyleManager * _manager, Doc * doc )
00632   : QObject(),
00633     m_doc( doc ),
00634     m_sheet( 0 ),
00635     m_pView( _view ),
00636     m_style( _style ),
00637     m_styleManager( _manager )
00638 {
00639   initMembers();
00640   initGUI();
00641   init();
00642 }
00643 
00644 void CellFormatDialog::initGUI()
00645 {
00646   isRowSelected    = false;
00647   isColumnSelected = false;
00648   styleName = m_style->name();
00649 
00650   borders[BorderType_Left].style = m_style->leftBorderPen().style();
00651   borders[BorderType_Left].width = m_style->leftBorderPen().width();
00652   borders[BorderType_Left].color = m_style->leftBorderPen().color();
00653 
00654   borders[BorderType_Top].style  = m_style->topBorderPen().style();
00655   borders[BorderType_Top].width  = m_style->topBorderPen().width();
00656   borders[BorderType_Top].color  = m_style->topBorderPen().color();
00657 
00658   borders[BorderType_Right].style = m_style->rightBorderPen().style();
00659   borders[BorderType_Right].width = m_style->rightBorderPen().width();
00660   borders[BorderType_Right].color = m_style->rightBorderPen().color();
00661 
00662   borders[BorderType_Bottom].style = m_style->bottomBorderPen().style();
00663   borders[BorderType_Bottom].width = m_style->bottomBorderPen().width();
00664   borders[BorderType_Bottom].color = m_style->bottomBorderPen().color();
00665 
00666   borders[BorderType_FallingDiagonal].style = m_style->fallDiagonalPen().style();
00667   borders[BorderType_FallingDiagonal].width = m_style->fallDiagonalPen().width();
00668   borders[BorderType_FallingDiagonal].color = m_style->fallDiagonalPen().color();
00669 
00670   borders[BorderType_RisingDiagonal].style  = m_style->goUpDiagonalPen().style();
00671   borders[BorderType_RisingDiagonal].width  = m_style->goUpDiagonalPen().width();
00672   borders[BorderType_RisingDiagonal].color  = m_style->goUpDiagonalPen().color();
00673 
00674   borders[BorderType_Vertical].style = m_style->leftBorderPen().style();
00675   borders[BorderType_Vertical].width = m_style->leftBorderPen().width();
00676   borders[BorderType_Vertical].color = m_style->leftBorderPen().color();
00677   borders[BorderType_Horizontal].style = m_style->topBorderPen().style();
00678   borders[BorderType_Horizontal].width = m_style->topBorderPen().width();
00679   borders[BorderType_Horizontal].color = m_style->topBorderPen().color();
00680 
00681   prefix         = m_style->prefix();
00682   postfix        = m_style->postfix();
00683   precision      = m_style->precision();
00684   floatFormat    = m_style->floatFormat();
00685   floatColor     = m_style->floatColor();
00686   alignX         = m_style->alignX();
00687   alignY         = m_style->alignY();
00688   textColor      = m_style->pen().color();
00689   bgColor        = m_style->bgColor();
00690   textFontSize   = m_style->fontSize();
00691   textFontFamily = m_style->fontFamily();
00692 
00693   uint flags     = m_style->fontFlags();
00694   textFontBold   = ( flags & (uint) Style::FBold );
00695   textFontItalic = ( flags & (uint) Style::FItalic );
00696   strike         = ( flags & (uint) Style::FStrike );
00697   underline      = ( flags & (uint) Style::FUnderline );
00698 
00699   // Needed to initialize the font correctly ( bug in Qt )
00700   textFont   = m_style->font();
00701   cCurrency  = m_style->currency();
00702   brushColor = m_style->backGroundBrush().color();
00703   brushStyle = m_style->backGroundBrush().style();
00704 
00705   bMultiRow     = m_style->hasProperty( Style::PMultiRow );
00706   bVerticalText = m_style->hasProperty( Style::PVerticalText );
00707   textRotation  = m_style->rotateAngle();
00708   formatType    = m_style->formatType();
00709   indent        = m_style->indent();
00710 
00711   bDontPrintText = m_style->hasProperty( Style::PDontPrintText );
00712   bHideFormula   = m_style->hasProperty( Style::PHideFormula );
00713   bHideAll       = m_style->hasProperty( Style::PHideAll );
00714   bIsProtected   = !m_style->hasProperty( Style::PNotProtected );
00715 
00716   widthSize  = defaultWidthSize;
00717   heightSize = defaultHeightSize;
00718 }
00719 
00720 CellFormatDialog::~CellFormatDialog()
00721 {
00722   delete formatOnlyNegSignedPixmap;
00723   delete formatRedOnlyNegSignedPixmap;
00724   delete formatRedNeverSignedPixmap;
00725   delete formatAlwaysSignedPixmap;
00726   delete formatRedAlwaysSignedPixmap;
00727 }
00728 
00729 void CellFormatDialog::initMembers()
00730 {
00731   formatOnlyNegSignedPixmap    = 0L;
00732   formatRedOnlyNegSignedPixmap = 0L;
00733   formatRedNeverSignedPixmap   = 0L;
00734   formatAlwaysSignedPixmap     = 0L;
00735   formatRedAlwaysSignedPixmap  = 0L;
00736 
00737   // We assume, that all other objects have the same values
00738   for ( int i = 0; i < BorderType_END; ++i )
00739   {
00740     borders[i].bStyle = true;
00741     borders[i].bColor = true;
00742   }
00743   bFloatFormat    = true;
00744   bFloatColor     = true;
00745   bTextColor      = true;
00746   bBgColor        = true;
00747   bTextFontFamily = true;
00748   bTextFontSize   = true;
00749   bTextFontBold   = true;
00750   bTextFontItalic = true;
00751   bStrike         = true;
00752   bUnderline      = true;
00753   bTextRotation   = true;
00754   bFormatType     = true;
00755   bCurrency       = true;
00756   bDontPrintText  = false;
00757   bHideFormula    = false;
00758   bHideAll        = false;
00759   bIsProtected    = true;
00760 
00761   cCurrency.symbol = locale()->currencySymbol();
00762   cCurrency.type   = 0;
00763 
00764   Sheet* sheet = m_pView->activeSheet();
00765   defaultWidthSize  = sheet ? sheet->columnFormat(0)->dblWidth() : 0;
00766   defaultHeightSize = sheet ? sheet->rowFormat(0)->dblHeight() : 0;
00767 }
00768 
00769 bool CellFormatDialog::checkCircle( QString const & name, QString const & parent )
00770 {
00771   return m_styleManager->checkCircle( name, parent );
00772 }
00773 
00774 void CellFormatDialog::checkBorderRight(Format *obj,int x,int y)
00775 {
00776   if ( borders[BorderType_Right].style != obj->rightBorderStyle( x, y ) ||
00777        borders[BorderType_Right].width != obj->rightBorderWidth( x, y ) )
00778     borders[BorderType_Right].bStyle = false;
00779   if ( borders[BorderType_Right].color != obj->rightBorderColor( x, y ) )
00780     borders[BorderType_Right].bColor = false;
00781 }
00782 
00783 void CellFormatDialog::checkBorderLeft(Format *obj,int x,int y)
00784 {
00785   if ( borders[BorderType_Left].style != obj->leftBorderStyle( x, y ) ||
00786        borders[BorderType_Left].width != obj->leftBorderWidth( x, y ) )
00787     borders[BorderType_Left].bStyle = false;
00788   if ( borders[BorderType_Left].color != obj->leftBorderColor( x, y ) )
00789     borders[BorderType_Left].bColor = false;
00790 }
00791 
00792 void CellFormatDialog::checkBorderTop(Format *obj,int x,int y)
00793 {
00794   if ( borders[BorderType_Top].style != obj->topBorderStyle( x, y ) ||
00795        borders[BorderType_Top].width != obj->topBorderWidth( x, y ) )
00796     borders[BorderType_Top].bStyle = false;
00797   if ( borders[BorderType_Top].color != obj->topBorderColor( x, y ) )
00798     borders[BorderType_Top].bColor = false;
00799 }
00800 
00801 void CellFormatDialog::checkBorderBottom(Format *obj,int x,int y)
00802 {
00803   if ( borders[BorderType_Bottom].style != obj->bottomBorderStyle( x, y ) ||
00804        borders[BorderType_Bottom].width != obj->bottomBorderWidth( x, y ) )
00805     borders[BorderType_Bottom].bStyle = false;
00806   if ( borders[BorderType_Bottom].color != obj->bottomBorderColor( x, y ) )
00807     borders[BorderType_Bottom].bColor = false;
00808 }
00809 
00810 void CellFormatDialog::checkBorderVertical(Format *obj,int x,int y)
00811 {
00812   if (borders[BorderType_Vertical].style != obj->leftBorderStyle( x, y ) ||
00813       borders[BorderType_Vertical].width != obj->leftBorderWidth( x, y ))
00814     borders[BorderType_Vertical].bStyle = false;
00815   if ( borders[BorderType_Vertical].color != obj->leftBorderColor( x, y ) )
00816     borders[BorderType_Vertical].bColor = false;
00817 }
00818 
00819 void CellFormatDialog::checkBorderHorizontal(Format *obj,int x,int y)
00820 {
00821   if ( borders[BorderType_Horizontal].style != obj->topBorderStyle( x, y ) ||
00822        borders[BorderType_Horizontal].width != obj->topBorderWidth( x, y ) )
00823     borders[BorderType_Horizontal].bStyle = false;
00824   if ( borders[BorderType_Horizontal].color != obj->topBorderColor( x, y ) )
00825     borders[BorderType_Horizontal].bColor = false;
00826 }
00827 
00828 
00829 void CellFormatDialog::initParameters(Format *obj,int x,int y)
00830 {
00831   if (borders[BorderType_FallingDiagonal].style != obj->fallDiagonalStyle( x, y ))
00832     borders[BorderType_FallingDiagonal].bStyle = false;
00833   if (borders[BorderType_FallingDiagonal].width != obj->fallDiagonalWidth( x, y ))
00834     borders[BorderType_FallingDiagonal].bStyle = false;
00835   if (borders[BorderType_FallingDiagonal].color != obj->fallDiagonalColor( x, y ))
00836     borders[BorderType_FallingDiagonal].bColor = false;
00837 
00838   if (borders[BorderType_RisingDiagonal].style != obj->goUpDiagonalStyle( x, y ))
00839     borders[BorderType_RisingDiagonal].bStyle = false;
00840   if (borders[BorderType_RisingDiagonal].width != obj->goUpDiagonalWidth( x, y ))
00841     borders[BorderType_RisingDiagonal].bStyle = false;
00842   if (borders[BorderType_RisingDiagonal].color != obj->goUpDiagonalColor( x, y ))
00843     borders[BorderType_RisingDiagonal].bColor = false;
00844   if ( strike != obj->textFontStrike( x, y ) )
00845     bStrike = false;
00846   if ( underline != obj->textFontUnderline( x, y ) )
00847     bUnderline = false;
00848   if ( prefix != obj->prefix( x, y ) )
00849     prefix = QString::null;
00850   if ( postfix != obj->postfix( x, y ) )
00851     postfix = QString::null;
00852   if ( floatFormat != obj->floatFormat( x, y ) )
00853     bFloatFormat = false;
00854   if ( floatColor != obj->floatColor( x, y ) )
00855     bFloatColor = false;
00856   if ( textColor != obj->textColor( x, y ) )
00857     bTextColor = false;
00858   if ( textFontFamily != obj->textFontFamily( x, y ) )
00859     bTextFontFamily = false;
00860   if ( textFontSize != obj->textFontSize( x, y ) )
00861     bTextFontSize = false;
00862   if ( textFontBold != obj->textFontBold( x, y ) )
00863     bTextFontBold = false;
00864   if ( textFontItalic != obj->textFontItalic( x, y ) )
00865     bTextFontItalic = false;
00866   if ( bgColor != obj->bgColor( x, y ) )
00867     bBgColor = false;
00868   if ( textRotation != obj->getAngle(left, top) )
00869     bTextRotation = false;
00870   if ( formatType != obj->getFormatType(left, top) )
00871     bFormatType = false;
00872   if ( bMultiRow != obj->multiRow( left, top ) )
00873     bMultiRow = false;
00874   if ( bVerticalText!=obj->verticalText( left, top ) )
00875     bVerticalText = false;
00876   if (  bDontPrintText!=obj->getDontprintText( left, top ) )
00877     bDontPrintText= false;
00878 
00879   Format::Currency cur;
00880   if (!obj->currencyInfo(cur))
00881     bCurrency = false;
00882   else
00883     if (cur.symbol != cCurrency.symbol)
00884       bCurrency = false;
00885 }
00886 
00887 void CellFormatDialog::init()
00888 {
00889   QColorGroup colorGroup = QApplication::palette().active();
00890 
00891   // Did we initialize the bitmaps ?
00892   if ( formatOnlyNegSignedPixmap == 0L )
00893   {
00894     QColor black = colorGroup.text(); // not necessarily black :)
00895     formatOnlyNegSignedPixmap    = paintFormatPixmap( "123.456", black, "-123.456", black );
00896     formatRedOnlyNegSignedPixmap = paintFormatPixmap( "123.456", black, "-123.456", Qt::red );
00897     formatRedNeverSignedPixmap   = paintFormatPixmap( "123.456", black, "123.456", Qt::red );
00898     formatAlwaysSignedPixmap     = paintFormatPixmap( "+123.456", black, "-123.456", black );
00899     formatRedAlwaysSignedPixmap  = paintFormatPixmap( "+123.456", black, "-123.456", Qt::red );
00900   }
00901 
00902   tab = new QTabDialog( (QWidget*)m_pView, 0L, true );
00903   //tab->setGeometry( tab->x(), tab->y(), 420, 400 );
00904 
00905   if ( m_style )
00906   {
00907     generalPage = new GeneralTab( tab, this );
00908     tab->addTab( generalPage, i18n( "&General" ) );
00909   }
00910 
00911   floatPage = new CellFormatPageFloat( tab, this );
00912   tab->addTab( floatPage, i18n("&Data Format") );
00913 
00914   fontPage = new CellFormatPageFont( tab, this );
00915   tab->addTab( fontPage, i18n("&Font") );
00916 
00917   //  miscPage = new CellFormatPageMisc( tab, this );
00918   //  tab->addTab( miscPage, i18n("&Misc") );
00919 
00920   positionPage = new CellFormatPagePosition( tab, this);
00921   tab->addTab( positionPage, i18n("&Position") );
00922 
00923   borderPage = new CellFormatPageBorder( tab, this );
00924   tab->addTab( borderPage, i18n("&Border") );
00925 
00926   patternPage=new CellFormatPagePattern(tab,this);
00927   tab->addTab( patternPage,i18n("Back&ground"));
00928 
00929   protectPage = new CellFormatPageProtection( tab, this );
00930   tab->addTab( protectPage, i18n("&Cell Protection") );
00931 
00932   tab->setCancelButton( i18n( "&Cancel" ) );
00933   tab->setOkButton( i18n( "&OK" ) );
00934 
00935   tab->setCaption( i18n( "Cell Format" ) );
00936 
00937   tab->adjustSize();
00938 
00939   connect( tab, SIGNAL( applyButtonPressed() ), this, SLOT( slotApply() ) );
00940 
00941   tab->exec();
00942 }
00943 
00944 QPixmap * CellFormatDialog::paintFormatPixmap( const char * _string1, const QColor & _color1,
00945                                             const char *_string2, const QColor & _color2 )
00946 {
00947   QPixmap * pixmap = new QPixmap( 150, 14 );
00948 
00949   QPainter painter;
00950   painter.begin( pixmap );
00951   painter.fillRect( 0, 0, 150, 14, QApplication::palette().active().base() );
00952   painter.setPen( _color1 );
00953   painter.drawText( 2, 11, _string1 );
00954   painter.setPen( _color2 );
00955   painter.drawText( 75, 11, _string2 );
00956   painter.end();
00957 
00958   QBitmap bm( pixmap->size() );
00959   bm.fill( color0 );
00960   painter.begin( &bm );
00961   painter.setPen( color1 );
00962   painter.drawText( 2, 11, _string1 );
00963   painter.drawText( 75, 11, _string2 );
00964   painter.end();
00965   pixmap->setMask( bm );
00966 
00967   return pixmap;
00968 }
00969 
00970 int CellFormatDialog::exec()
00971 {
00972   return ( tab->exec() );
00973 }
00974 
00975 void CellFormatDialog::applyStyle()
00976 {
00977   generalPage->apply( m_style );
00978 
00979   borderPage->apply(0);
00980   floatPage->apply( m_style );
00981   // miscPage->apply( m_style );
00982   fontPage->apply( m_style );
00983   positionPage->apply( m_style );
00984   patternPage->apply( m_style );
00985   protectPage->apply( m_style );
00986 }
00987 
00988 void CellFormatDialog::slotApply()
00989 {
00990   if ( m_style )
00991   {
00992     applyStyle();
00993     return;
00994   }
00995 
00996   // (Tomas) TODO: this will be slow !!!
00997   // We need to create a manipulator that would act as KMacroCommand,
00998   // but which would also ensure that updates are not painted until everything
00999   // is updated properly ...
01000   KMacroCommand* macroCommand = new KMacroCommand( i18n("Change Format") );
01001 
01002   if ( isMerged != positionPage->getMergedCellState() )
01003   {
01004     if ( positionPage->getMergedCellState() )
01005     {
01006       Manipulator* manipulator = new MergeManipulator();
01007       manipulator->setSheet(m_pView->activeSheet());
01008       manipulator->setRegisterUndo(false);
01009       manipulator->add(*m_pView->selectionInfo());
01010       macroCommand->addCommand( manipulator );
01011     }
01012     else
01013     {
01014       //dissociate cells
01015       Manipulator* manipulator = new MergeManipulator();
01016       manipulator->setSheet(m_pView->activeSheet());
01017       manipulator->setReverse(true);
01018       manipulator->setRegisterUndo(false);
01019       manipulator->add(*m_pView->selectionInfo());
01020       macroCommand->addCommand( manipulator );
01021     }
01022   }
01023 
01024   FormatManipulator* manipulator = new FormatManipulator();
01025   manipulator->setSheet(m_pView->activeSheet());
01026   manipulator->setRegisterUndo(false);
01027   manipulator->add(*m_pView->selectionInfo());
01028   borderPage->apply(manipulator);
01029   floatPage->apply(manipulator);
01030   fontPage->apply(manipulator);
01031   positionPage->apply(manipulator);
01032   patternPage->apply(manipulator);
01033   protectPage->apply(manipulator);
01034 
01035   if (!manipulator->isEmpty())
01036   {
01037     macroCommand->addCommand( manipulator );
01038   }
01039   else
01040   {
01041     delete manipulator;
01042   }
01043 
01044   if ( int( positionPage->getSizeHeight() ) != int( heightSize ) )
01045   {
01046     ResizeRowManipulator* manipulator = new ResizeRowManipulator();
01047     manipulator->setSheet(m_pView->activeSheet());
01048     manipulator->setSize(positionPage->getSizeHeight());
01049     // TODO Stefan:
01050     manipulator->setOldSize(heightSize);
01051     manipulator->add(*m_pView->selectionInfo());
01052     macroCommand->addCommand( manipulator );
01053   }
01054   if ( int( positionPage->getSizeWidth() ) != int( widthSize ) )
01055   {
01056     ResizeColumnManipulator* manipulator = new ResizeColumnManipulator();
01057     manipulator->setSheet(m_pView->activeSheet());
01058     manipulator->setSize(positionPage->getSizeWidth());
01059     // TODO Stefan:
01060     manipulator->setOldSize(widthSize);
01061     manipulator->add(*m_pView->selectionInfo());
01062     macroCommand->addCommand( manipulator );
01063   }
01064 
01065   macroCommand->execute();
01066   m_doc->addCommand( macroCommand );
01067 
01068   // Update the toolbar (bold/italic/font...)
01069   m_pView->updateEditWidget();
01070 }
01071 
01072 
01073 
01074 /***************************************************************************
01075  *
01076  * CellFormatPageFloat
01077  *
01078  ***************************************************************************/
01079 
01080 CellFormatPageFloat::CellFormatPageFloat( QWidget* parent, CellFormatDialog *_dlg )
01081   : QWidget ( parent ),
01082     dlg( _dlg )
01083 {
01084     QVBoxLayout* layout = new QVBoxLayout( this, 6,10 );
01085 
01086     QButtonGroup *grp = new QButtonGroup( i18n("Format"),this);
01087     QGridLayout *grid = new QGridLayout(grp,11,2,KDialog::marginHint(), KDialog::spacingHint());
01088 
01089     int fHeight = grp->fontMetrics().height();
01090     grid->addRowSpacing( 0, fHeight/2 ); // groupbox title
01091 
01092     grp->setRadioButtonExclusive( true );
01093     generic=new QRadioButton(i18n("Generic"),grp);
01094     QWhatsThis::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." ) );
01095     grid->addWidget(generic,1,0);
01096 
01097     number=new QRadioButton(i18n("Number"),grp);
01098     QWhatsThis::add(number, i18n( "The number notation uses the notation you globally choose in KControl -> Regional & Accessibility -> Numbers tab. Numbers are right justified by default." ) );
01099     grid->addWidget(number,2,0);
01100 
01101     percent=new QRadioButton(i18n("Percent"),grp);
01102     QWhatsThis::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." ) );
01103     grid->addWidget(percent,3,0);
01104 
01105     money=new QRadioButton(i18n("Money"),grp);
01106     QWhatsThis::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." ) );
01107     grid->addWidget(money,4,0);
01108 
01109     scientific=new QRadioButton(i18n("Scientific"),grp);
01110     QWhatsThis::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." ) );
01111     grid->addWidget(scientific,5,0);
01112 
01113     fraction=new QRadioButton(i18n("Fraction"),grp);
01114     QWhatsThis::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." ) );
01115     grid->addWidget(fraction,6,0);
01116 
01117     date=new QRadioButton(i18n("Date format"),grp);
01118     QWhatsThis::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." ) );
01119     grid->addWidget(date,7,0);
01120 
01121     time=new QRadioButton(i18n("Time format"),grp);
01122     QWhatsThis::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." ) );
01123     grid->addWidget(time,8,0);
01124 
01125     textFormat=new QRadioButton(i18n("Text"),grp);
01126     QWhatsThis::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." ) );
01127     grid->addWidget(textFormat,9,0);
01128 
01129     customFormat=new QRadioButton(i18n("Custom"),grp);
01130     QWhatsThis::add(customFormat, i18n( "The custom format does not work yet. To be enabled in the next release." ) );
01131     grid->addWidget(customFormat,10,0);
01132     customFormat->setEnabled( false );
01133 
01134     QGroupBox *box2 = new QGroupBox( grp, "Box");
01135     box2->setTitle(i18n("Preview"));
01136     QGridLayout *grid3 = new QGridLayout(box2,1,3,KDialog::marginHint(), KDialog::spacingHint());
01137 
01138     exampleLabel=new QLabel(box2);
01139     QWhatsThis::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." ) );
01140     grid3->addWidget(exampleLabel,0,1);
01141 
01142     grid->addMultiCellWidget(box2,9,10,1,1);
01143 
01144     customFormatEdit = new QLineEdit( grp );
01145     grid->addMultiCellWidget( customFormatEdit, 1, 1, 1, 1 );
01146     customFormatEdit->setHidden( true );
01147 
01148     listFormat=new QListBox(grp);
01149     grid->addMultiCellWidget(listFormat,2,7,1,1);
01150     QWhatsThis::add(listFormat, i18n( "Displays choices of format for the fraction, date or time formats." ) );
01151     layout->addWidget(grp);
01152 
01153     /* *** */
01154 
01155     QGroupBox *box = new QGroupBox( this, "Box");
01156 
01157     grid = new QGridLayout(box,3,4,KDialog::marginHint(), KDialog::spacingHint());
01158 
01159     postfix = new QLineEdit( box, "LineEdit_1" );
01160     QWhatsThis::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." ) );
01161     grid->addWidget(postfix,2,1);
01162     precision = new KIntNumInput( dlg->precision, box, 10 );
01163     precision->setSpecialValueText(i18n("variable"));
01164     precision->setRange(-1,10,1,false);
01165     QWhatsThis::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. " ) );
01166     grid->addWidget(precision,1,1);
01167 
01168     prefix = new QLineEdit( box, "LineEdit_3" );
01169     QWhatsThis::add(prefix, i18n( "You can add here a Prefix such as a $ symbol at the start of each cell content in the checked format." ) );
01170     grid->addWidget(prefix,0,1);
01171 
01172     format = new QComboBox( box, "ListBox_1" );
01173     QWhatsThis::add(format, i18n( "You can choose whether positive values are displayed with a leading + sign and whether negative values are shown in red." ) );
01174     grid->addWidget(format,0,3);
01175 
01176     QLabel* tmpQLabel;
01177     tmpQLabel = new QLabel( box, "Label_1" );
01178     grid->addWidget(tmpQLabel,2,0);
01179     tmpQLabel->setText( i18n("Postfix:") );
01180 
01181     postfix->setText( dlg->postfix );
01182 
01183     tmpQLabel = new QLabel( box, "Label_2" );
01184     grid->addWidget(tmpQLabel,0,0);
01185 
01186     tmpQLabel->setText( i18n("Prefix:") );
01187     tmpQLabel = new QLabel( box, "Label_3" );
01188     grid->addWidget(tmpQLabel,1,0);
01189     tmpQLabel->setText( i18n("Precision:") );
01190 
01191     prefix->setText( dlg->prefix );
01192 
01193     format->insertItem( *_dlg->formatOnlyNegSignedPixmap, 0 );
01194     format->insertItem( *_dlg->formatRedOnlyNegSignedPixmap, 1 );
01195     format->insertItem( *_dlg->formatRedNeverSignedPixmap, 2 );
01196     format->insertItem( *_dlg->formatAlwaysSignedPixmap, 3 );
01197     format->insertItem( *_dlg->formatRedAlwaysSignedPixmap, 4 );
01198 
01199     tmpQLabel = new QLabel( box, "Label_4" );
01200     grid->addWidget(tmpQLabel, 0, 2);
01201     tmpQLabel->setText( i18n("Format:") );
01202 
01203     currencyLabel = new QLabel( box, "LabelCurrency" );
01204     grid->addWidget(currencyLabel, 1, 2);
01205     currencyLabel->setText( i18n("Currency:") );
01206 
01207     currency = new QComboBox( box, "ComboCurrency" );
01208     grid->addWidget(currency, 1, 3);
01209 
01210     currency->insertItem( i18n("Automatic") );
01211 
01212     int index = 2; //ignore first two in the list
01213     bool ok = true;
01214     QString text;
01215 
01216     while ( ok )
01217     {
01218       text = Currency::getChooseString( index, ok );
01219       if ( ok )
01220       {
01221         currency->insertItem( text );
01222       }
01223       else
01224       {
01225         break;
01226       }
01227 
01228       ++index;
01229     }
01230 
01231     currency->setCurrentItem( 0 );
01232     currency->hide();
01233     currencyLabel->hide();
01234 
01235     if ( !dlg->bFloatFormat || !dlg->bFloatColor )
01236         format->setCurrentItem( 5 );
01237     else if ( dlg->floatFormat == Format::OnlyNegSigned && dlg->floatColor == Format::AllBlack )
01238         format->setCurrentItem( 0 );
01239     else if ( dlg->floatFormat == Format::OnlyNegSigned && dlg->floatColor == Format::NegRed )
01240         format->setCurrentItem( 1 );
01241     else if ( dlg->floatFormat == Format::AlwaysUnsigned && dlg->floatColor == Format::NegRed )
01242         format->setCurrentItem( 2 );
01243     else if ( dlg->floatFormat == Format::AlwaysSigned && dlg->floatColor == Format::AllBlack )
01244         format->setCurrentItem( 3 );
01245     else if ( dlg->floatFormat == Format::AlwaysSigned && dlg->floatColor == Format::NegRed )
01246         format->setCurrentItem( 4 );
01247     layout->addWidget(box);
01248 
01249     cellFormatType=dlg->formatType;
01250     newFormatType = cellFormatType;
01251 
01252     if (!cellFormatType)
01253           generic->setChecked(true);
01254     else
01255     {
01256         if (cellFormatType==Number_format)
01257                 number->setChecked(true);
01258         else if (cellFormatType==Percentage_format)
01259                 percent->setChecked(true);
01260         else if (cellFormatType==Money_format)
01261         {
01262                 money->setChecked(true);
01263                 currencyLabel->show();
01264                 currency->show();
01265                 if (dlg->bCurrency)
01266                 {
01267                   QString tmp;
01268                   if (dlg->cCurrency.type != 1)
01269                   {
01270                     Currency curr(dlg->cCurrency.type);
01271                     bool ok = true;
01272                     tmp = Currency::getChooseString(dlg->cCurrency.type, ok);
01273                     if ( !ok )
01274                       tmp = dlg->cCurrency.symbol;
01275                   }
01276                   else
01277                     tmp = dlg->cCurrency.symbol;
01278                   currency->setCurrentText( tmp );
01279                 }
01280         }
01281         else if ( cellFormatType == Scientific_format )
01282           scientific->setChecked(true);
01283         else if ( formatIsDate (cellFormatType) )
01284                 date->setChecked(true);
01285         else if ( formatIsTime (cellFormatType) )
01286           time->setChecked(true);
01287         else if ( formatIsFraction (cellFormatType) )
01288           fraction->setChecked(true);
01289     else if (cellFormatType == Text_format)
01290       textFormat->setChecked(true);
01291     else if (cellFormatType == Custom_format)
01292       customFormat->setChecked(true);
01293         }
01294 
01295     connect(generic,SIGNAL(clicked ()),this,SLOT(slotChangeState()));
01296     connect(fraction,SIGNAL(clicked ()),this,SLOT(slotChangeState()));
01297     connect(money,SIGNAL(clicked ()),this,SLOT(slotChangeState()));
01298     connect(date,SIGNAL(clicked ()),this,SLOT(slotChangeState()));
01299     connect(scientific,SIGNAL(clicked ()),this,SLOT(slotChangeState()));
01300     connect(number,SIGNAL(clicked ()),this,SLOT(slotChangeState()));
01301     connect(percent,SIGNAL(clicked ()),this,SLOT(slotChangeState()));
01302     connect(time,SIGNAL(clicked ()),this,SLOT(slotChangeState()));
01303     connect(textFormat,SIGNAL(clicked()),this,SLOT(slotChangeState()));
01304     connect(customFormat,SIGNAL(clicked()),this,SLOT(slotChangeState()));
01305 
01306     connect(listFormat,SIGNAL(selectionChanged ()),this,SLOT(makeformat()));
01307     connect(precision,SIGNAL(valueChanged(int)),this,SLOT(slotChangeValue(int)));
01308     connect(prefix,SIGNAL(textChanged ( const QString & ) ),this,SLOT(makeformat()));
01309     connect(postfix,SIGNAL(textChanged ( const QString & ) ),this,SLOT(makeformat()));
01310     connect(currency,SIGNAL(activated ( const QString & ) ),this, SLOT(currencyChanged(const QString &)));
01311     connect(format,SIGNAL(activated ( int ) ),this,SLOT(formatChanged(int)));
01312     connect(format, SIGNAL(activated(int)), this, SLOT(makeformat()));
01313     slotChangeState();
01314     m_bFormatColorChanged=false;
01315     m_bFormatTypeChanged=false;
01316     this->resize( 400, 400 );
01317 }
01318 
01319 void CellFormatPageFloat::formatChanged(int)
01320 {
01321     m_bFormatColorChanged=true;
01322 }
01323 
01324 void CellFormatPageFloat::slotChangeValue(int)
01325 {
01326     makeformat();
01327 }
01328 void CellFormatPageFloat::slotChangeState()
01329 {
01330     QStringList list;
01331     listFormat->clear();
01332     currency->hide();
01333     currencyLabel->hide();
01334 
01335     // start with enabled, they get disabled when inappropriate further down
01336     precision->setEnabled(true);
01337     prefix->setEnabled(true);
01338     postfix->setEnabled(true);
01339     format->setEnabled(true);
01340 
01341     if (generic->isChecked() || number->isChecked() || percent->isChecked() ||
01342         scientific->isChecked() || textFormat->isChecked())
01343       listFormat->setEnabled(false);
01344     else if (money->isChecked())
01345     {
01346         listFormat->setEnabled(false);
01347         precision->setValue(2);
01348         currency->show();
01349         currencyLabel->show();
01350     }
01351     else if (date->isChecked())
01352         {
01353             format->setEnabled(false);
01354             precision->setEnabled(false);
01355             prefix->setEnabled(false);
01356             postfix->setEnabled(false);
01357             listFormat->setEnabled(true);
01358             init();
01359         }
01360     else if (fraction->isChecked())
01361         {
01362             precision->setEnabled(false);
01363             listFormat->setEnabled(true);
01364             list+=i18n("Halves 1/2");
01365             list+=i18n("Quarters 1/4");
01366             list+=i18n("Eighths 1/8");
01367             list+=i18n("Sixteenths 1/16");
01368             list+=i18n("Tenths 1/10");
01369             list+=i18n("Hundredths 1/100");
01370             list+=i18n("One digit 5/9");
01371             list+=i18n("Two digits 15/22");
01372             list+=i18n("Three digits 153/652");
01373             listFormat->insertStringList(list);
01374             if (cellFormatType == fraction_half)
01375                 listFormat->setCurrentItem(0);
01376             else if (cellFormatType == fraction_quarter)
01377                 listFormat->setCurrentItem(1);
01378             else if (cellFormatType == fraction_eighth )
01379                 listFormat->setCurrentItem(2);
01380             else if (cellFormatType == fraction_sixteenth )
01381                 listFormat->setCurrentItem(3);
01382             else if (cellFormatType == fraction_tenth )
01383                 listFormat->setCurrentItem(4);
01384             else if (cellFormatType == fraction_hundredth )
01385                 listFormat->setCurrentItem(5);
01386             else if (cellFormatType == fraction_one_digit )
01387                 listFormat->setCurrentItem(6);
01388             else if (cellFormatType == fraction_two_digits )
01389                 listFormat->setCurrentItem(7);
01390             else if (cellFormatType == fraction_three_digits )
01391                 listFormat->setCurrentItem(8);
01392             else
01393                 listFormat->setCurrentItem(0);
01394         }
01395     else if (time->isChecked())
01396         {
01397             precision->setEnabled(false);
01398             prefix->setEnabled(false);
01399             postfix->setEnabled(false);
01400             format->setEnabled(false);
01401             listFormat->setEnabled(true);
01402 
01403 
01404             list+=i18n("System: ")+dlg->locale()->formatTime(QTime::currentTime(),false);
01405             list+=i18n("System: ")+dlg->locale()->formatTime(QTime::currentTime(),true);
01406             QDateTime tmpTime (QDate (1, 1, 1900), QTime (10, 35, 25));
01407 
01408 
01409             ValueFormatter *fmt = dlg->getDoc()->formatter();
01410             list+= fmt->timeFormat(tmpTime, Time_format1);
01411             list+= fmt->timeFormat(tmpTime, Time_format2);
01412             list+= fmt->timeFormat(tmpTime, Time_format3);
01413             list+= fmt->timeFormat(tmpTime, Time_format4);
01414             list+= fmt->timeFormat(tmpTime, Time_format5);
01415             list+= ( fmt->timeFormat(tmpTime, Time_format6) + i18n(" (=[mm]::ss)") );
01416             list+= ( fmt->timeFormat(tmpTime, Time_format7) + i18n(" (=[hh]::mm::ss)") );
01417             list+= ( fmt->timeFormat(tmpTime, Time_format8) + i18n(" (=[hh]::mm)") );
01418             listFormat->insertStringList(list);
01419 
01420             if ( cellFormatType == Time_format )
01421                 listFormat->setCurrentItem(0);
01422             else if (cellFormatType == SecondeTime_format)
01423                 listFormat->setCurrentItem(1);
01424             else if (cellFormatType == Time_format1)
01425                 listFormat->setCurrentItem(2);
01426             else if (cellFormatType == Time_format2)
01427                 listFormat->setCurrentItem(3);
01428             else if (cellFormatType == Time_format3)
01429                 listFormat->setCurrentItem(4);
01430             else if (cellFormatType == Time_format4)
01431                 listFormat->setCurrentItem(5);
01432             else if (cellFormatType == Time_format5)
01433                 listFormat->setCurrentItem(6);
01434             else if (cellFormatType == Time_format6)
01435                 listFormat->setCurrentItem(7);
01436             else if (cellFormatType == Time_format7)
01437                 listFormat->setCurrentItem(8);
01438             else if (cellFormatType == Time_format8)
01439                 listFormat->setCurrentItem(9);
01440             else
01441                 listFormat->setCurrentItem(0);
01442         }
01443 
01444     if (customFormat->isChecked())
01445     {
01446       customFormatEdit->setHidden( false );
01447       precision->setEnabled(false);
01448       prefix->setEnabled(false);
01449       postfix->setEnabled(false);
01450       format->setEnabled(false);
01451       listFormat->setEnabled(true);
01452     }
01453     else
01454       customFormatEdit->setHidden( true );
01455 
01456     m_bFormatTypeChanged=true;
01457 
01458     makeformat();
01459 }
01460 
01461 void CellFormatPageFloat::init()
01462 {
01463     QStringList list;
01464     QString tmp;
01465     QString tmp2;
01466     QDate tmpDate( 2000,2,18);
01467     list+=i18n("System: ")+dlg->locale()->formatDate (QDate::currentDate(), true);
01468     list+=i18n("System: ")+dlg->locale()->formatDate (QDate::currentDate(), false);
01469 
01470     ValueFormatter *fmt = dlg->getDoc()->formatter();
01471 
01472     /*18-Feb-00*/
01473     list+=fmt->dateFormat( tmpDate, date_format1);
01474     /*18-Feb-1999*/
01475     list+=fmt->dateFormat( tmpDate, date_format2);
01476     /*18-Feb*/
01477     list+=fmt->dateFormat( tmpDate, date_format3);
01478     /*18-2*/
01479     list+=fmt->dateFormat( tmpDate, date_format4);
01480     /*18/2/00*/
01481     list+=fmt->dateFormat( tmpDate, date_format5);
01482     /*18/5/1999*/
01483     list+=fmt->dateFormat( tmpDate, date_format6);
01484     /*Feb-99*/
01485     list+=fmt->dateFormat( tmpDate, date_format7);
01486     /*February-99*/
01487     list+=fmt->dateFormat( tmpDate, date_format8);
01488     /*February-1999*/
01489     list+=fmt->dateFormat( tmpDate, date_format9);
01490     /*F-99*/
01491     list+=fmt->dateFormat( tmpDate, date_format10);
01492     /*18/Feb*/
01493     list+=fmt->dateFormat( tmpDate, date_format11);
01494     /*18/2*/
01495     list+=fmt->dateFormat( tmpDate, date_format12);
01496     /*18/Feb/1999*/
01497     list+=fmt->dateFormat( tmpDate, date_format13);
01498     /*2000/Feb/18*/
01499     list+=fmt->dateFormat( tmpDate, date_format14);
01500     /*2000-Feb-18*/
01501     list+=fmt->dateFormat( tmpDate, date_format15);
01502     /*2000-2-18*/
01503     list+=fmt->dateFormat( tmpDate, date_format16);
01504     /*2 february 2000*/
01505     list+=fmt->dateFormat( tmpDate, date_format17);
01506     list+=fmt->dateFormat( tmpDate, date_format18);
01507     list+=fmt->dateFormat( tmpDate, date_format19);
01508     list+=fmt->dateFormat( tmpDate, date_format20);
01509     list+=fmt->dateFormat( tmpDate, date_format21);
01510     list+=fmt->dateFormat( tmpDate, date_format22);
01511     list+=fmt->dateFormat( tmpDate, date_format23);
01512     list+=fmt->dateFormat( tmpDate, date_format24);
01513     list+=fmt->dateFormat( tmpDate, date_format25);
01514     list+=fmt->dateFormat( tmpDate, date_format26);
01515 
01516     listFormat->insertStringList(list);
01517     if ( cellFormatType == ShortDate_format )
01518         listFormat->setCurrentItem(0);
01519     else if (cellFormatType == TextDate_format)
01520         listFormat->setCurrentItem(1);
01521     else if (cellFormatType == date_format1)
01522         listFormat->setCurrentItem(2);
01523     else if (cellFormatType == date_format2)
01524         listFormat->setCurrentItem(3);
01525     else if (cellFormatType == date_format3)
01526         listFormat->setCurrentItem(4);
01527     else if (cellFormatType == date_format4)
01528         listFormat->setCurrentItem(5);
01529     else if (cellFormatType == date_format5)
01530         listFormat->setCurrentItem(6);
01531     else if (cellFormatType == date_format6)
01532         listFormat->setCurrentItem(7);
01533     else if (cellFormatType == date_format7)
01534         listFormat->setCurrentItem(8);
01535     else if (cellFormatType == date_format8)
01536         listFormat->setCurrentItem(9);
01537     else if (cellFormatType == date_format9)
01538         listFormat->setCurrentItem(10);
01539     else if (cellFormatType == date_format10)
01540         listFormat->setCurrentItem(11);
01541     else if (cellFormatType == date_format11)
01542         listFormat->setCurrentItem(12);
01543     else if (cellFormatType == date_format12)
01544         listFormat->setCurrentItem(13);
01545     else if (cellFormatType == date_format13)
01546         listFormat->setCurrentItem(14);
01547     else if (cellFormatType == date_format14)
01548         listFormat->setCurrentItem(15);
01549     else if (cellFormatType == date_format15)
01550         listFormat->setCurrentItem(16);
01551     else if (cellFormatType == date_format16)
01552         listFormat->setCurrentItem(17);
01553     else if (cellFormatType == date_format17)
01554         listFormat->setCurrentItem(18);
01555     else if (cellFormatType == date_format18)
01556         listFormat->setCurrentItem(19);
01557     else if (cellFormatType == date_format19)
01558         listFormat->setCurrentItem(20);
01559     else if (cellFormatType == date_format20)
01560         listFormat->setCurrentItem(21);
01561     else if (cellFormatType == date_format21)
01562         listFormat->setCurrentItem(22);
01563     else if (cellFormatType == date_format22)
01564         listFormat->setCurrentItem(23);
01565     else if (cellFormatType == date_format23)
01566         listFormat->setCurrentItem(24);
01567     else if (cellFormatType == date_format24)
01568         listFormat->setCurrentItem(25);
01569     else if (cellFormatType == date_format25)
01570         listFormat->setCurrentItem(26);
01571     else if (cellFormatType == date_format26)
01572         listFormat->setCurrentItem(27);
01573     else
01574         listFormat->setCurrentItem(0);
01575 
01576 }
01577 
01578 void CellFormatPageFloat::currencyChanged(const QString &)
01579 {
01580   int index = currency->currentItem();
01581   if (index > 0)
01582     ++index;
01583   dlg->cCurrency.symbol = Currency::getDisplaySymbol(index);
01584   dlg->cCurrency.type   = index;
01585 
01586   makeformat();
01587 }
01588 
01589 void CellFormatPageFloat::updateFormatType ()
01590 {
01591   if (generic->isChecked())
01592     newFormatType = Generic_format;
01593   else if (number->isChecked())
01594     newFormatType = Number_format;
01595   else if (percent->isChecked())
01596     newFormatType = Percentage_format;
01597   else if (date->isChecked())
01598   {
01599     newFormatType=ShortDate_format;
01600     switch (listFormat->currentItem())
01601     {
01602       case 0: newFormatType=ShortDate_format; break;
01603       case 1: newFormatType=TextDate_format; break;
01604       case 2: newFormatType=date_format1; break; /*18-Feb-99*/
01605       case 3: newFormatType=date_format2; break; /*18-Feb-1999*/
01606       case 4: newFormatType=date_format3; break; /*18-Feb*/
01607       case 5: newFormatType=date_format4; break; /*18-05*/
01608       case 6: newFormatType=date_format5; break; /*18/05/00*/
01609       case 7: newFormatType=date_format6; break; /*18/05/1999*/
01610       case 8: newFormatType=date_format7; break;/*Feb-99*/
01611       case 9: newFormatType=date_format8; break; /*February-99*/
01612       case 10: newFormatType=date_format9; break; /*February-1999*/
01613       case 11: newFormatType=date_format10; break; /*F-99*/
01614       case 12: newFormatType=date_format11; break; /*18/Feb*/
01615       case 13: newFormatType=date_format12; break; /*18/02*/
01616       case 14: newFormatType=date_format13; break; /*18/Feb/1999*/
01617       case 15: newFormatType=date_format14; break; /*2000/Feb/18*/
01618       case 16: newFormatType=date_format15; break;/*2000-Feb-18*/
01619       case 17: newFormatType=date_format16; break;/*2000-02-18*/
01620       case 18: newFormatType=date_format17; break; /*2000-02-18*/
01621       case 19: newFormatType=date_format18; break;
01622       case 20: newFormatType=date_format19; break;
01623       case 21: newFormatType=date_format20; break;
01624       case 22: newFormatType=date_format21; break;
01625       case 23: newFormatType=date_format22; break;
01626       case 24: newFormatType=date_format23; break;
01627       case 25: newFormatType=date_format24; break;
01628       case 26: newFormatType=date_format25; break;
01629       case 27: newFormatType=date_format26; break;
01630     }
01631   }
01632   else if (money->isChecked())
01633     newFormatType = Money_format;
01634   else if (scientific->isChecked())
01635     newFormatType = Scientific_format;
01636   else if (fraction->isChecked())
01637   {
01638     newFormatType=fraction_half;
01639     switch (listFormat->currentItem())
01640     {
01641       case 0: newFormatType=fraction_half; break;
01642       case 1: newFormatType=fraction_quarter; break;
01643       case 2: newFormatType=fraction_eighth; break;
01644       case 3: newFormatType=fraction_sixteenth; break;
01645       case 4: newFormatType=fraction_tenth; break;
01646       case 5: newFormatType=fraction_hundredth; break;
01647       case 6: newFormatType=fraction_one_digit; break;
01648       case 7: newFormatType=fraction_two_digits; break;
01649       case 8: newFormatType=fraction_three_digits; break;
01650     }
01651   }
01652   else if (time->isChecked())
01653   {
01654     newFormatType=Time_format;
01655     switch (listFormat->currentItem())
01656     {
01657       case 0: newFormatType=Time_format; break;
01658       case 1: newFormatType=SecondeTime_format; break;
01659       case 2: newFormatType=Time_format1; break;
01660       case 3: newFormatType=Time_format2; break;
01661       case 4: newFormatType=Time_format3; break;
01662       case 5: newFormatType=Time_format4; break;
01663       case 6: newFormatType=Time_format5; break;
01664       case 7: newFormatType=Time_format6; break;
01665       case 8: newFormatType=Time_format7; break;
01666       case 9: newFormatType=Time_format8; break;
01667     }
01668   }
01669   else if (textFormat->isChecked())
01670     newFormatType = Text_format;
01671   else if (customFormat->isChecked())
01672     newFormatType = Custom_format;
01673 }
01674 
01675 void CellFormatPageFloat::makeformat()
01676 {
01677   m_bFormatTypeChanged=true;
01678   QString tmp;
01679 
01680   updateFormatType();
01681   QColor color;
01682   Format::FloatFormat floatFormat;
01683   switch( format->currentItem() )
01684   {
01685     case 0:
01686       floatFormat = Format::OnlyNegSigned;
01687       color = black;
01688       break;
01689     case 1:
01690       floatFormat =  Format::OnlyNegSigned;
01691       color = Qt::red;
01692       break;
01693     case 2:
01694       floatFormat =  Format::AlwaysUnsigned;
01695       color = Qt::red;
01696       break;
01697     case 3:
01698       floatFormat =  Format::AlwaysSigned;
01699       color = black;
01700       break;
01701     case 4:
01702       floatFormat =  Format::AlwaysSigned;
01703       color = Qt::red;
01704       break;
01705   }
01706   if (!dlg->value.isNumber() || dlg->value.asFloat() >= 0 || !format->isEnabled())
01707   {
01708     color = black;
01709   }
01710   ValueFormatter *fmt = dlg->getDoc()->formatter();
01711   tmp = fmt->formatText(dlg->value, newFormatType, precision->value(),
01712                         floatFormat,
01713                         prefix->isEnabled() ? prefix->text() : QString::null,
01714                         postfix->isEnabled() ? postfix->text() : QString::null,
01715                         newFormatType == Money_format ? dlg->cCurrency.symbol : QString::null);
01716   if (tmp.length() > 50)
01717     tmp = tmp.left (50);
01718   exampleLabel->setText(tmp.prepend("<font color=" + color.name() + ">").append("</font>"));
01719 }
01720 
01721 void CellFormatPageFloat::apply( CustomStyle * style )
01722 {
01723   if ( postfix->text() != dlg->postfix )
01724   {
01725       if ( postfix->isEnabled())
01726         style->changePostfix( postfix->text() );
01727       else
01728         style->changePostfix( "" );
01729   }
01730   if ( prefix->text() != dlg->prefix )
01731   {
01732       if (prefix->isEnabled())
01733         style->changePrefix( prefix->text() );
01734       else
01735         style->changePrefix( "" );
01736   }
01737 
01738   if ( dlg->precision != precision->value() )
01739     style->changePrecision( precision->value() );
01740 
01741   if ( m_bFormatColorChanged )
01742   {
01743     switch( format->currentItem() )
01744     {
01745      case 0:
01746       style->changeFloatFormat( Format::OnlyNegSigned );
01747       style->changeFloatColor( Format::AllBlack );
01748       break;
01749      case 1:
01750       style->changeFloatFormat( Format::OnlyNegSigned );
01751       style->changeFloatColor( Format::NegRed );
01752       break;
01753      case 2:
01754       style->changeFloatFormat( Format::AlwaysUnsigned );
01755       style->changeFloatColor( Format::NegRed );
01756       break;
01757      case 3:
01758       style->changeFloatFormat( Format::AlwaysSigned );
01759       style->changeFloatColor( Format::AllBlack );
01760       break;
01761      case 4:
01762       style->changeFloatFormat( Format::AlwaysSigned );
01763       style->changeFloatColor( Format::NegRed );
01764       break;
01765     }
01766   }
01767   if ( m_bFormatTypeChanged )
01768   {
01769     style->changeFormatType (newFormatType);
01770     if ( money->isChecked() )
01771     {
01772       Format::Currency cur;
01773       int index = currency->currentItem();
01774       if (index == 0)
01775       {
01776         if ( currency->currentText() == i18n( "Automatic" ) )
01777         {
01778           cur.symbol = dlg->locale()->currencySymbol();
01779           cur.type   = 0;
01780         }
01781         else
01782         {
01783           cur.type   = 1;
01784           cur.symbol = currency->currentText();
01785         }
01786       }
01787       else
01788       {
01789         cur.type   = ++index;
01790         cur.symbol = Currency::getDisplaySymbol( index );
01791       }
01792 
01793       style->changeCurrency( cur );
01794     }
01795   }
01796 }
01797 
01798 void CellFormatPageFloat::apply(FormatManipulator* _obj)
01799 {
01800   if ( postfix->text() != dlg->postfix )
01801     if ( postfix->isEnabled())
01802     {
01803       // If we are in here it *never* can be disabled - FIXME (Werner)!
01804       if ( postfix->isEnabled())
01805         _obj->setPostfix( postfix->text() );
01806       else
01807         _obj->setPostfix( "" );
01808     }
01809   if ( prefix->text() != dlg->prefix )
01810       if (prefix->isEnabled())
01811         _obj->setPrefix( prefix->text() );
01812       else
01813         _obj->setPrefix( "" );
01814 
01815   if ( dlg->precision != precision->value() )
01816       _obj->setPrecision( precision->value() );
01817 
01818   if (m_bFormatColorChanged)
01819   {
01820     switch( format->currentItem() )
01821       {
01822       case 0:
01823         _obj->setFloatFormat( Format::OnlyNegSigned );
01824         _obj->setFloatColor( Format::AllBlack );
01825         break;
01826       case 1:
01827         _obj->setFloatFormat( Format::OnlyNegSigned );
01828         _obj->setFloatColor( Format::NegRed );
01829         break;
01830       case 2:
01831         _obj->setFloatFormat( Format::AlwaysUnsigned );
01832         _obj->setFloatColor( Format::NegRed );
01833         break;
01834       case 3:
01835         _obj->setFloatFormat( Format::AlwaysSigned );
01836         _obj->setFloatColor( Format::AllBlack );
01837         break;
01838       case 4:
01839         _obj->setFloatFormat( Format::AlwaysSigned );
01840         _obj->setFloatColor( Format::NegRed );
01841         break;
01842       }
01843   }
01844   if (m_bFormatTypeChanged)
01845   {
01846     _obj->setFormatType (newFormatType);
01847     if (money->isChecked())
01848     {
01849       Format::Currency cur;
01850       int index = currency->currentItem();
01851       if (index == 0)
01852       {
01853         if ( currency->currentText() == i18n( "Automatic" ) )
01854         {
01855           cur.symbol = dlg->locale()->currencySymbol();
01856           cur.type   = 0;
01857         }
01858         else
01859         {
01860           cur.type   = 1;
01861           cur.symbol = currency->currentText();
01862         }
01863       }
01864       else
01865       {
01866         cur.type   = ++index;
01867         cur.symbol = Currency::getDisplaySymbol( index );
01868       }
01869 
01870       _obj->setCurrency( cur.type, cur.symbol );
01871     }
01872   }
01873 }
01874 
01875 
01876 
01877 /***************************************************************************
01878  *
01879  * CellFormatPageProtection
01880  *
01881  ***************************************************************************/
01882 
01883 CellFormatPageProtection::CellFormatPageProtection( QWidget* parent, CellFormatDialog * _dlg )
01884   : ProtectionTab( parent ),
01885     m_dlg( _dlg )
01886 {
01887   m_bDontPrint->setChecked( m_dlg->bDontPrintText );
01888   m_bHideAll->setChecked( m_dlg->bHideAll );
01889   m_bHideFormula->setChecked( m_dlg->bHideFormula );
01890   m_bIsProtected->setChecked( m_dlg->bIsProtected );
01891 }
01892 
01893 CellFormatPageProtection::~CellFormatPageProtection()
01894 {
01895 }
01896 
01897 void CellFormatPageProtection::apply( CustomStyle * style )
01898 {
01899   if ( m_dlg->bDontPrintText != m_bDontPrint->isChecked() )
01900   {
01901     if ( m_bDontPrint->isChecked() )
01902       style->addProperty( Style::PDontPrintText );
01903     else
01904       style->removeProperty( Style::PDontPrintText );
01905   }
01906 
01907   if ( m_dlg->bIsProtected != m_bIsProtected->isChecked() )
01908   {
01909     if ( !m_bIsProtected->isChecked() )
01910       style->addProperty( Style::PNotProtected );
01911     else
01912       style->removeProperty( Style::PNotProtected );
01913   }
01914 
01915   if ( m_dlg->bHideAll != m_bHideAll->isChecked() )
01916   {
01917     if ( m_bHideAll->isChecked() )
01918       style->addProperty( Style::PHideAll );
01919     else
01920       style->removeProperty( Style::PHideAll );
01921   }
01922 
01923   if ( m_dlg->bHideFormula != m_bHideFormula->isChecked() )
01924   {
01925     if ( m_bHideFormula->isChecked() )
01926       style->addProperty( Style::PHideFormula );
01927     else
01928       style->removeProperty( Style::PHideFormula );
01929   }
01930 }
01931 
01932 void CellFormatPageProtection::apply(FormatManipulator* _obj)
01933 {
01934   if ( m_dlg->bDontPrintText != m_bDontPrint->isChecked())
01935     _obj->setDontPrintText( m_bDontPrint->isChecked() );
01936 
01937   if ( m_dlg->bIsProtected != m_bIsProtected->isChecked())
01938     _obj->setNotProtected( !m_bIsProtected->isChecked() );
01939 
01940   if ( m_dlg->bHideAll != m_bHideAll->isChecked())
01941     _obj->setHideAll( m_bHideAll->isChecked() );
01942 
01943   if ( m_dlg->bHideFormula != m_bHideFormula->isChecked())
01944     _obj->setHideFormula( m_bHideFormula->isChecked() );
01945 }
01946 
01947 
01948 
01949 /***************************************************************************
01950  *
01951  * CellFormatPageFont
01952  *
01953  ***************************************************************************/
01954 
01955 CellFormatPageFont::CellFormatPageFont( QWidget* parent, CellFormatDialog *_dlg ) : FontTab( parent )
01956 {
01957   dlg = _dlg;
01958 
01959   bTextColorUndefined = !dlg->bTextColor;
01960 
01961   connect( textColorButton, SIGNAL( changed( const QColor & ) ),
01962              this, SLOT( slotSetTextColor( const QColor & ) ) );
01963 
01964 
01965   QStringList tmpListFont;
01966   QFontDatabase *fontDataBase = new QFontDatabase();
01967   tmpListFont = fontDataBase->families();
01968   delete fontDataBase;
01969 
01970   family_combo->insertStringList( tmpListFont);
01971   selFont = dlg->textFont;
01972 
01973    if ( dlg->bTextFontFamily )
01974    {
01975         selFont.setFamily( dlg->textFontFamily );
01976         kdDebug(36001) << "Family = " << dlg->textFontFamily << endl;
01977 
01978         if ( !family_combo->findItem(dlg->textFontFamily))
01979                 {
01980                 family_combo->insertItem("",0);
01981                 family_combo->setCurrentItem(0);
01982                 }
01983         else
01984                 family_combo->setCurrentItem(family_combo->index(family_combo->findItem(dlg->textFontFamily)));
01985    }
01986    else
01987    {
01988         family_combo->insertItem("",0);
01989         family_combo->setCurrentItem(0);
01990    }
01991 
01992   connect( family_combo, SIGNAL(highlighted(const QString &)),
01993            SLOT(family_chosen_slot(const QString &)) );
01994 
01995   QStringList lst;
01996   lst.append("");
01997   for ( unsigned int i = 1; i < 100; ++i )
01998         lst.append( QString( "%1" ).arg( i ) );
01999 
02000   size_combo->insertStringList( lst );
02001 
02002 
02003   size_combo->setInsertionPolicy(QComboBox::NoInsertion);
02004 
02005   connect( size_combo, SIGNAL(activated(const QString &)),
02006            SLOT(size_chosen_slot(const QString &)) );
02007   connect( size_combo ,SIGNAL( textChanged(const QString &)),
02008         this,SLOT(size_chosen_slot(const QString &)));
02009 
02010   connect( weight_combo, SIGNAL(activated(const QString &)),
02011            SLOT(weight_chosen_slot(const QString &)) );
02012 
02013   connect( style_combo, SIGNAL(activated(const QString &)),
02014            SLOT(style_chosen_slot(const QString &)) );
02015 
02016   strike->setChecked(dlg->strike);
02017   connect( strike, SIGNAL( clicked()),
02018            SLOT(strike_chosen_slot()) );
02019 
02020   underline->setChecked(dlg->underline);
02021   connect( underline, SIGNAL( clicked()),
02022            SLOT(underline_chosen_slot()) );
02023 
02024   example_label->setText(i18n("Dolor Ipse"));
02025 
02026   connect(this,SIGNAL(fontSelected( const QFont&  )),
02027           this,SLOT(display_example( const QFont&)));
02028 
02029   setCombos();
02030   display_example( selFont );
02031   fontChanged=false;
02032   this->resize( 400, 400 );
02033 }
02034 
02035 void CellFormatPageFont::slotSetTextColor( const QColor &_color )
02036 {
02037   textColor = _color;
02038   bTextColorUndefined = false;
02039 }
02040 
02041 void CellFormatPageFont::apply( CustomStyle * style )
02042 {
02043   if ( !bTextColorUndefined && textColor != dlg->textColor )
02044     style->changeTextColor( textColor );
02045 
02046   if ( ( size_combo->currentItem() != 0 )
02047        && ( dlg->textFontSize != selFont.pointSize() ) )
02048     style->changeFontSize( selFont.pointSize() );
02049 
02050   if ( ( selFont.family() != dlg->textFontFamily )
02051        && !family_combo->currentText().isEmpty() )
02052     style->changeFontFamily( selFont.family() );
02053 
02054   uint flags = 0;
02055 
02056   if ( weight_combo->currentItem() != 0 && selFont.bold() )
02057     flags |= Style::FBold;
02058   else
02059     flags &= ~(uint) Style::FBold;
02060 
02061   if ( style_combo->currentItem() != 0 && selFont.italic() )
02062     flags |= Style::FItalic;
02063   else
02064     flags &= ~(uint) Style::FItalic;
02065 
02066   if ( strike->isChecked() )
02067     flags |= Style::FStrike;
02068   else
02069     flags &= ~(uint) Style::FStrike;
02070 
02071   if ( underline->isChecked() )
02072     flags |= Style::FUnderline;
02073   else
02074     flags &= ~(uint) Style::FUnderline;
02075 
02076   style->changeFontFlags( flags );
02077 }
02078 
02079 void CellFormatPageFont::apply(FormatManipulator* _obj)
02080 {
02081   if ( !bTextColorUndefined && textColor != dlg->textColor )
02082     _obj->setTextColor( textColor );
02083   if (fontChanged)
02084   {
02085     if ( ( size_combo->currentItem() != 0 )
02086          && ( dlg->textFontSize != selFont.pointSize() ) )
02087       _obj->setFontSize( selFont.pointSize() );
02088     if ( ( selFont.family() != dlg->textFontFamily ) && ( !family_combo->currentText().isEmpty() ) )
02089       _obj->setFontFamily( selFont.family() );
02090     if ( weight_combo->currentItem() != 0 )
02091       _obj->setFontBold( selFont.bold() );
02092     if ( style_combo->currentItem() != 0 )
02093       _obj->setFontItalic( selFont.italic() );
02094     _obj->setFontStrike( strike->isChecked() );
02095     _obj->setFontUnderline(underline->isChecked() );
02096   }
02097 }
02098 
02099 void CellFormatPageFont::underline_chosen_slot()
02100 {
02101    selFont.setUnderline( underline->isChecked() );
02102    emit fontSelected(selFont);
02103 }
02104 
02105 void CellFormatPageFont::strike_chosen_slot()
02106 {
02107    selFont.setStrikeOut( strike->isChecked() );
02108    emit fontSelected(selFont);
02109 }
02110 
02111 void CellFormatPageFont::family_chosen_slot(const QString & family)
02112 {
02113   selFont.setFamily(family);
02114   emit fontSelected(selFont);
02115 }
02116 
02117 void CellFormatPageFont::size_chosen_slot(const QString & size)
02118 {
02119   QString size_string = size;
02120 
02121   selFont.setPointSize(size_string.toInt());
02122   emit fontSelected(selFont);
02123 }
02124 
02125 void CellFormatPageFont::weight_chosen_slot(const QString & weight)
02126 {
02127   QString weight_string = weight;
02128 
02129   if ( weight_string == i18n("Normal"))
02130     selFont.setBold(false);
02131   if ( weight_string == i18n("Bold"))
02132     selFont.setBold(true);
02133   emit fontSelected(selFont);
02134 }
02135 
02136 void CellFormatPageFont::style_chosen_slot(const QString & style)
02137 {
02138   QString style_string = style;
02139 
02140   if ( style_string == i18n("Roman"))
02141     selFont.setItalic(false);
02142   if ( style_string == i18n("Italic"))
02143     selFont.setItalic(true);
02144   emit fontSelected(selFont);
02145 }
02146 
02147 
02148 void CellFormatPageFont::display_example(const QFont& font)
02149 {
02150   QString string;
02151   fontChanged=true;
02152   example_label->setFont(font);
02153   example_label->repaint();
02154 }
02155 
02156 void CellFormatPageFont::setCombos()
02157 {
02158  QString string;
02159  QComboBox* combo;
02160  int number_of_entries;
02161  bool found;
02162 
02163  if ( dlg->bTextColor )
02164    textColor = dlg->textColor;
02165  else
02166    textColor = colorGroup().text();
02167 
02168  if ( !textColor.isValid() )
02169    textColor =colorGroup().text();
02170 
02171  textColorButton->setColor( textColor );
02172 
02173 
02174  combo = size_combo;
02175  if ( dlg->bTextFontSize )
02176  {
02177      kdDebug(36001) << "SIZE=" << dlg->textFontSize << endl;
02178      selFont.setPointSize( dlg->textFontSize );
02179      number_of_entries = size_combo->count();
02180      string.setNum( dlg->textFontSize );
02181      found = false;
02182 
02183      for (int i = 0; i < number_of_entries ; i++){
02184          if ( string == (QString) combo->text(i)){
02185              combo->setCurrentItem(i);
02186              found = true;
02187              // kdDebug(36001) << "Found Size " << string.data() << " setting to item " i << endl;
02188              break;
02189          }
02190      }
02191  }
02192  else
02193      combo->setCurrentItem( 0 );
02194 
02195  if ( !dlg->bTextFontBold )
02196      weight_combo->setCurrentItem(0);
02197  else if ( dlg->textFontBold )
02198  {
02199      selFont.setBold( dlg->textFontBold );
02200      weight_combo->setCurrentItem(2);
02201  }
02202  else
02203  {
02204      selFont.setBold( dlg->textFontBold );
02205      weight_combo->setCurrentItem(1);
02206  }
02207 
02208  if ( !dlg->bTextFontItalic )
02209      weight_combo->setCurrentItem(0);
02210  else if ( dlg->textFontItalic )
02211  {
02212      selFont.setItalic( dlg->textFontItalic );
02213      style_combo->setCurrentItem(2);
02214  }
02215  else
02216  {
02217      selFont.setItalic( dlg->textFontItalic );
02218      style_combo->setCurrentItem(1);
02219  }
02220 }
02221 
02222 
02223 
02224 /***************************************************************************
02225  *
02226  * CellFormatPagePosition
02227  *
02228  ***************************************************************************/
02229 
02230 CellFormatPagePosition::CellFormatPagePosition( QWidget* parent, CellFormatDialog *_dlg )
02231   : PositionTab(parent ),
02232     dlg( _dlg )
02233 {
02234     if ( dlg->alignX == Format::Left )
02235         left->setChecked( true );
02236     else if ( dlg->alignX == Format::Center )
02237         center->setChecked( true );
02238     else if ( dlg->alignX == Format::Right )
02239         right->setChecked( true );
02240     else if ( dlg->alignX == Format::Undefined )
02241         standard->setChecked( true );
02242 
02243     connect(horizontalGroup,  SIGNAL(clicked(int)), this, SLOT(slotStateChanged(int)));
02244 
02245     if ( dlg->alignY ==Format::Top )
02246         top->setChecked( true );
02247     else if ( dlg->alignY ==Format::Middle )
02248         middle->setChecked(true );
02249     else if ( dlg->alignY ==Format::Bottom )
02250         bottom->setChecked( true );
02251 
02252     multi->setChecked(dlg->bMultiRow);
02253 
02254     vertical->setChecked(dlg->bVerticalText);
02255 
02256     angleRotation->setValue(-dlg->textRotation);//annma
02257     spinBox3->setValue(-dlg->textRotation);
02258     if ( dlg->textRotation != 0 )
02259     {
02260         multi->setEnabled(false );
02261         vertical->setEnabled(false);
02262     }
02263 
02264     mergeCell->setChecked(dlg->isMerged);
02265     mergeCell->setEnabled(!dlg->oneCell && ((!dlg->isRowSelected) && (!dlg->isColumnSelected)));
02266 
02267     QGridLayout *grid2 = new QGridLayout(indentGroup, 1, 1, KDialog::marginHint(), KDialog::spacingHint());
02268     grid2->addRowSpacing( 0, indentGroup->fontMetrics().height()/8 ); // groupbox title
02269     m_indent = new KoUnitDoubleSpinBox( indentGroup, 0.0,  400.0, 10.0,dlg->indent,dlg->getDoc()->unit() );
02270     grid2->addWidget(m_indent, 0, 0);
02271 
02272     width = new KoUnitDoubleSpinBox( m_widthPanel );
02273     QGridLayout *gridWidth = new QGridLayout(m_widthPanel, 1, 1, 0, 0);
02274     gridWidth->addWidget(width, 0, 0);
02275     width->setValue ( dlg->widthSize );
02276     width->setUnit( dlg->getDoc()->unit() );
02277     //to ensure, that we don't get rounding problems, we store the displayed value (for later check for changes)
02278     dlg->widthSize = width->value();
02279 
02280     if ( dlg->isRowSelected )
02281         width->setEnabled(false);
02282 
02283     defaultWidth->setText(i18n("Default width (%1 %2)").arg(KoUnit::toUserValue(dlg->defaultWidthSize, dlg->getDoc()->unit()), 0, 'f', 2).arg(dlg->getDoc()->unitName()));
02284     if ( dlg->isRowSelected )
02285         defaultWidth->setEnabled(false);
02286 
02287     height=new KoUnitDoubleSpinBox( m_heightPanel );
02288     QGridLayout *gridHeight = new QGridLayout(m_heightPanel, 1, 1, 0, 0);
02289     gridHeight->addWidget(height, 0, 0);
02290     height->setValue( dlg->heightSize );
02291     height->setUnit(  dlg->getDoc()->unit() );
02292     //to ensure, that we don't get rounding problems, we store the displayed value (for later check for changes)
02293     dlg->heightSize = height->value();
02294 
02295     if ( dlg->isColumnSelected )
02296         height->setEnabled(false);
02297 
02298     defaultHeight->setText(i18n("Default height (%1 %2)").arg(KoUnit::toUserValue(dlg->defaultHeightSize, dlg->getDoc()->unit()), 0, 'f', 2).arg(dlg->getDoc()->unitName())); //annma
02299     if ( dlg->isColumnSelected )
02300         defaultHeight->setEnabled(false);
02301 
02302     // in case we're editing a style, we disable the cell size settings
02303     if (dlg->getStyle())
02304     {
02305       sizeCellGroup->setEnabled(false);
02306     }
02307 
02308     connect(defaultWidth , SIGNAL(clicked() ),this, SLOT(slotChangeWidthState()));
02309     connect(defaultHeight , SIGNAL(clicked() ),this, SLOT(slotChangeHeightState()));
02310     connect(vertical , SIGNAL(clicked() ),this, SLOT(slotChangeVerticalState()));
02311     connect(multi , SIGNAL(clicked() ), this, SLOT(slotChangeMultiState()));
02312     connect(angleRotation, SIGNAL(valueChanged(int)), this, SLOT(slotChangeAngle(int)));
02313 
02314     slotStateChanged( 0 );
02315     m_bOptionText = false;
02316     this->resize( 400, 400 );
02317 }
02318 
02319 void CellFormatPagePosition::slotChangeMultiState()
02320 {
02321     m_bOptionText = true;
02322     if (vertical->isChecked())
02323     {
02324         vertical->setChecked(false);
02325     }
02326 }
02327 
02328 void CellFormatPagePosition::slotChangeVerticalState()
02329 {
02330     m_bOptionText=true;
02331     if (multi->isChecked())
02332     {
02333         multi->setChecked(false);
02334     }
02335 
02336 }
02337 
02338 void CellFormatPagePosition::slotStateChanged(int)
02339 {
02340     if (right->isChecked() || center->isChecked())
02341         m_indent->setEnabled(false);
02342     else
02343         m_indent->setEnabled(true);
02344 }
02345 
02346 bool CellFormatPagePosition::getMergedCellState() const
02347 {
02348     return  mergeCell->isChecked();
02349 }
02350 
02351 void CellFormatPagePosition::slotChangeWidthState()
02352 {
02353     if ( defaultWidth->isChecked())
02354         width->setEnabled(false);
02355     else
02356         width->setEnabled(true);
02357 }
02358 
02359 void CellFormatPagePosition::slotChangeHeightState()
02360 {
02361     if ( defaultHeight->isChecked())
02362         height->setEnabled(false);
02363     else
02364         height->setEnabled(true);
02365 }
02366 
02367 void CellFormatPagePosition::slotChangeAngle(int _angle)
02368 {
02369   if ( _angle == 0 )
02370   {
02371     multi->setEnabled( true );
02372     vertical->setEnabled( true );
02373   }
02374   else
02375   {
02376     multi->setEnabled( false );
02377     vertical->setEnabled( false );
02378   }
02379 }
02380 
02381 void CellFormatPagePosition::apply( CustomStyle * style )
02382 {
02383   if ( top->isChecked() && dlg->alignY != Format::Top )
02384     style->changeAlignY( Format::Top );
02385   else if ( bottom->isChecked() && dlg->alignY != Format::Bottom )
02386     style->changeAlignY( Format::Bottom );
02387   else if ( middle->isChecked() && dlg->alignY != Format::Middle )
02388     style->changeAlignY( Format::Middle );
02389 
02390   if ( left->isChecked() && dlg->alignX != Format::Left )
02391     style->changeAlignX( Format::Left );
02392   else if ( right->isChecked() && dlg->alignX != Format::Right )
02393     style->changeAlignX( Format::Right );
02394   else if ( center->isChecked() && dlg->alignX != Format::Center )
02395     style->changeAlignX( Format::Center );
02396   else if ( standard->isChecked() && dlg->alignX != Format::Undefined )
02397     style->changeAlignX( Format::Undefined );
02398 
02399   if ( m_bOptionText )
02400   {
02401     if ( multi->isEnabled() )
02402     {
02403       if ( multi->isChecked() )
02404         style->addProperty( Style::PMultiRow );
02405       else
02406         style->removeProperty( Style::PMultiRow );
02407     }
02408   }
02409 
02410   if ( m_bOptionText )
02411   {
02412     if ( vertical->isEnabled() )
02413     {
02414       if ( vertical->isChecked() )
02415         style->addProperty( Style::PVerticalText );
02416       else
02417         style->removeProperty( Style::PVerticalText );
02418     }
02419   }
02420 
02421   if ( dlg->textRotation != angleRotation->value() )
02422     style->changeRotateAngle( (-angleRotation->value()) );
02423 
02424   if ( m_indent->isEnabled()
02425        && dlg->indent != m_indent->value() )
02426     style->changeIndent( m_indent->value() );
02427 }
02428 
02429 void CellFormatPagePosition::apply(FormatManipulator* _obj)
02430 {
02431   Format::Align  ax;
02432   Format::AlignY ay;
02433 
02434   if ( top->isChecked() )
02435     ay = Format::Top;
02436   else if ( bottom->isChecked() )
02437     ay = Format::Bottom;
02438   else if ( middle->isChecked() )
02439     ay = Format::Middle;
02440   else
02441     ay = Format::Middle; // Default, just in case
02442 
02443   if ( left->isChecked() )
02444     ax = Format::Left;
02445   else if ( right->isChecked() )
02446     ax = Format::Right;
02447   else if ( center->isChecked() )
02448     ax = Format::Center;
02449   else if ( standard->isChecked() )
02450     ax = Format::Undefined;
02451   else
02452     ax = Format::Undefined; //Default, just in case
02453 
02454   if ( top->isChecked() && ay != dlg->alignY )
02455     _obj->setVerticalAlignment( Format::Top );
02456   else if ( bottom->isChecked() && ay != dlg->alignY )
02457     _obj->setVerticalAlignment( Format::Bottom );
02458   else if ( middle->isChecked() && ay != dlg->alignY )
02459     _obj->setVerticalAlignment( Format::Middle );
02460 
02461   if ( left->isChecked() && ax != dlg->alignX )
02462     _obj->setHorizontalAlignment( Format::Left );
02463   else if ( right->isChecked() && ax != dlg->alignX )
02464     _obj->setHorizontalAlignment( Format::Right );
02465   else if ( center->isChecked() && ax != dlg->alignX )
02466     _obj->setHorizontalAlignment( Format::Center );
02467   else if ( standard->isChecked() && ax != dlg->alignX )
02468     _obj->setHorizontalAlignment( Format::Undefined );
02469 
02470   if ( m_bOptionText )
02471   {
02472     if ( multi->isEnabled() )
02473       _obj->setMultiRow( multi->isChecked() );
02474     else
02475       _obj->setMultiRow( false );
02476   }
02477 
02478   if ( m_bOptionText )
02479   {
02480     if ( vertical->isEnabled() )
02481       _obj->setVerticalText( vertical->isChecked() );
02482     else
02483       _obj->setVerticalText( false );
02484   }
02485 
02486   if ( dlg->textRotation!=angleRotation->value() )
02487     _obj->setAngle( (-angleRotation->value() ) );
02488   if ( m_indent->isEnabled()
02489        && dlg->indent != m_indent->value() )
02490     _obj->setIndent( m_indent->value() );
02491 }
02492 
02493 double CellFormatPagePosition::getSizeHeight() const
02494 {
02495   if ( defaultHeight->isChecked() )
02496     return dlg->defaultHeightSize; // guess who calls this!
02497   else
02498       return height->value();
02499 }
02500 
02501 double CellFormatPagePosition::getSizeWidth() const
02502 {
02503   if ( defaultWidth->isChecked() )
02504     return dlg->defaultWidthSize; // guess who calls this!
02505   else
02506         return width->value();
02507 }
02508 
02509 
02510 
02511 /***************************************************************************
02512  *
02513  * BorderButton
02514  *
02515  ***************************************************************************/
02516 
02517 BorderButton::BorderButton( QWidget *parent, const char *_name ) : QPushButton(parent,_name)
02518 {
02519   penStyle = Qt::NoPen;
02520   penWidth = 1;
02521   penColor = colorGroup().text();
02522   setToggleButton( true );
02523   setOn( false);
02524   setChanged(false);
02525 }
02526 void BorderButton::mousePressEvent( QMouseEvent * )
02527 {
02528 
02529   this->setOn(!isOn());
02530   emit clicked( this );
02531 }
02532 
02533 void BorderButton::setUndefined()
02534 {
02535  setPenStyle(SolidLine );
02536  setPenWidth(1);
02537  setColor(colorGroup().midlight());
02538 }
02539 
02540 
02541 void BorderButton::unselect()
02542 {
02543   setOn(false);
02544   setPenWidth(1);
02545   setPenStyle(Qt::NoPen);
02546   setColor( colorGroup().text() );
02547   setChanged(true);
02548 }
02549 
02550 
02551 
02552 /***************************************************************************
02553  *
02554  * Border
02555  *
02556  ***************************************************************************/
02557 
02558 Border::Border( QWidget *parent, const char *_name,bool _oneCol, bool _oneRow )
02559     : QFrame( parent, _name )
02560 {
02561   oneCol=_oneCol;
02562   oneRow=_oneRow;
02563 }
02564 
02565 
02566 #define OFFSETX 5
02567 #define OFFSETY 5
02568 void Border::paintEvent( QPaintEvent *_ev )
02569 {
02570   QFrame::paintEvent( _ev );
02571   QPen pen;
02572   QPainter painter;
02573   painter.begin( this );
02574   pen=QPen( colorGroup().midlight(),2,SolidLine);
02575   painter.setPen( pen );
02576 
02577   painter.drawLine( OFFSETX-5, OFFSETY, OFFSETX , OFFSETY );
02578   painter.drawLine( OFFSETX, OFFSETY-5, OFFSETX , OFFSETY );
02579   painter.drawLine( width()-OFFSETX, OFFSETY, width() , OFFSETY );
02580   painter.drawLine( width()-OFFSETX, OFFSETY-5, width()-OFFSETX , OFFSETY );
02581 
02582   painter.drawLine( OFFSETX, height()-OFFSETY, OFFSETX , height() );
02583   painter.drawLine( OFFSETX-5, height()-OFFSETY, OFFSETX , height()-OFFSETY );
02584 
02585   painter.drawLine( width()-OFFSETX, height()-OFFSETY, width() , height()-OFFSETY );
02586   painter.drawLine( width()-OFFSETX, height()-OFFSETY, width()-OFFSETX , height() );
02587   if (oneCol==false)
02588   {
02589         painter.drawLine( width()/2, OFFSETY-5, width()/2 , OFFSETY );
02590         painter.drawLine( width()/2-5, OFFSETY, width()/2+5 , OFFSETY );
02591         painter.drawLine( width()/2, height()-OFFSETY, width()/2 , height() );
02592         painter.drawLine( width()/2-5, height()-OFFSETY, width()/2+5 , height()-OFFSETY );
02593   }
02594   if (oneRow==false)
02595   {
02596         painter.drawLine( OFFSETX-5, height()/2, OFFSETX , height()/2 );
02597         painter.drawLine( OFFSETX, height()/2-5, OFFSETX , height()/2+5 );
02598         painter.drawLine( width()-OFFSETX, height()/2, width(), height()/2 );
02599         painter.drawLine( width()-OFFSETX, height()/2-5, width()-OFFSETX , height()/2+5 );
02600   }
02601   painter.end();
02602   emit redraw();
02603 }
02604 
02605 void Border::mousePressEvent( QMouseEvent* _ev )
02606 {
02607   emit choosearea(_ev);
02608 }
02609 
02610 
02611 
02612 /***************************************************************************
02613  *
02614  * CellFormatPageBorder
02615  *
02616  ***************************************************************************/
02617 
02618 CellFormatPageBorder::CellFormatPageBorder( QWidget* parent, CellFormatDialog *_dlg )
02619   : QWidget( parent ),
02620     dlg( _dlg )
02621 {
02622   sheet = dlg->getSheet();
02623 
02624   InitializeGrids();
02625   InitializeBorderButtons();
02626   InitializePatterns();
02627   SetConnections();
02628 
02629   preview->slotSelect();
02630   pattern[2]->slotSelect();
02631 
02632   style->setEnabled(false);
02633   size->setEnabled(false);
02634   preview->setPattern( black , 1, SolidLine );
02635   this->resize( 400, 400 );
02636 }
02637 
02638 void CellFormatPageBorder::InitializeGrids()
02639 {
02640   QGridLayout *grid = new QGridLayout(this,5,2,KDialog::marginHint(), KDialog::spacingHint());
02641   QGridLayout *grid2 = NULL;
02642   QGroupBox* tmpQGroupBox = NULL;
02643 
02644   /***********************/
02645   /* here is the data to initialize all the border buttons with */
02646   const char borderButtonNames[BorderType_END][20] =
02647     {"top", "bottom", "left", "right", "vertical", "fall", "go", "horizontal"};
02648 
02649   const char shortcutButtonNames[BorderShortcutType_END][20] =
02650     {"remove", "all", "outline"};
02651 
02652   QString borderButtonIconNames[BorderType_END] =
02653     {"border_top", "border_bottom", "border_left", "border_right",
02654      "border_vertical", "border_horizontal", "border_fall", "border_up"};
02655 
02656   QString shortcutButtonIconNames[BorderShortcutType_END] =
02657     { "border_remove", "", "border_outline"};
02658 
02659   int borderButtonPositions[BorderType_END][2] =
02660     {{0,2}, {4,2}, {2,0}, {2,4}, {4,4}, {4,0}, {0,0}, {0,4}};
02661 
02662   int shortcutButtonPositions[BorderShortcutType_END][2] =
02663     { {0,0}, {0,1},{0,2} };
02664   /***********************/
02665 
02666   /* set up a layout box for most of the border setting buttons */
02667   tmpQGroupBox = new QGroupBox( this, "GroupBox_1" );
02668   tmpQGroupBox->setFrameStyle( QFrame::Box | QFrame::Sunken );
02669   tmpQGroupBox->setTitle( i18n("Border") );
02670   tmpQGroupBox->setAlignment( AlignLeft );
02671   grid2 = new QGridLayout(tmpQGroupBox,6,5,KDialog::marginHint(), KDialog::spacingHint());
02672   int fHeight = tmpQGroupBox->fontMetrics().height();
02673   grid2->addRowSpacing( 0, fHeight/2 ); // groupbox title
02674 
02675   area=new Border(tmpQGroupBox,"area",dlg->oneCol,dlg->oneRow);
02676   grid2->addMultiCellWidget(area,2,4,1,3);
02677   area->setBackgroundColor( colorGroup().base() );
02678 
02679   /* initailize the buttons that are in this box */
02680   for (int i=BorderType_Top; i < BorderType_END; i++)
02681   {
02682     borderButtons[i] = new BorderButton(tmpQGroupBox,
02683                                                borderButtonNames[i]);
02684     loadIcon(borderButtonIconNames[i], borderButtons[i]);
02685     grid2->addWidget(borderButtons[i], borderButtonPositions[i][0] + 1,
02686                      borderButtonPositions[i][1]);
02687   }
02688 
02689   grid->addMultiCellWidget(tmpQGroupBox,0,2,0,0);
02690 
02691   /* the remove, all, and outline border buttons are in a second box down
02692      below.*/
02693 
02694   tmpQGroupBox = new QGroupBox( this, "GroupBox_3" );
02695   tmpQGroupBox->setFrameStyle( QFrame::Box | QFrame::Sunken );
02696   tmpQGroupBox->setTitle( i18n("Preselect") );
02697   tmpQGroupBox->setAlignment( AlignLeft );
02698 
02699   grid2 = new QGridLayout(tmpQGroupBox,1,3,KDialog::marginHint(), KDialog::spacingHint());
02700 
02701   /* the "all" button is different depending on what kind of region is currently
02702      selected */
02703   if ((dlg->oneRow==true)&&(dlg->oneCol==false))
02704   {
02705     shortcutButtonIconNames[BorderShortcutType_All] = "border_vertical";
02706   }
02707   else if ((dlg->oneRow==false)&&(dlg->oneCol==true))
02708   {
02709     shortcutButtonIconNames[BorderShortcutType_All] = "border_horizontal";
02710   }
02711   else
02712   {
02713     shortcutButtonIconNames[BorderShortcutType_All] = "border_inside";
02714   }
02715 
02716   for (int i=BorderShortcutType_Remove; i < BorderShortcutType_END; i++)
02717   {
02718     shortcutButtons[i] = new BorderButton(tmpQGroupBox,
02719                                                  shortcutButtonNames[i]);
02720     loadIcon(shortcutButtonIconNames[i], shortcutButtons[i]);
02721     grid2->addWidget(shortcutButtons[i], shortcutButtonPositions[i][0],
02722                      shortcutButtonPositions[i][1]);
02723   }
02724 
02725   if (dlg->oneRow && dlg->oneCol)
02726   {
02727     shortcutButtons[BorderShortcutType_All]->setEnabled(false);
02728   }
02729 
02730   grid->addMultiCellWidget(tmpQGroupBox,3,4,0,0);
02731 
02732   /* now set up the group box with the pattern selector */
02733   tmpQGroupBox = new QGroupBox( this, "GroupBox_10" );
02734   tmpQGroupBox->setFrameStyle( QFrame::Box | QFrame::Sunken );
02735   tmpQGroupBox->setTitle( i18n("Pattern") );
02736   tmpQGroupBox->setAlignment( AlignLeft );
02737 
02738   grid2 = new QGridLayout(tmpQGroupBox,7,2,KDialog::marginHint(), KDialog::spacingHint());
02739   fHeight = tmpQGroupBox->fontMetrics().height();
02740   grid2->addRowSpacing( 0, fHeight/2 ); // groupbox title
02741 
02742   char name[] = "PatternXX";
02743   Q_ASSERT(NUM_BORDER_PATTERNS < 100);
02744 
02745   for (int i=0; i < NUM_BORDER_PATTERNS; i++)
02746   {
02747     name[7] = '0' + (i+1) / 10;
02748     name[8] = '0' + (i+1) % 10;
02749     pattern[i] = new PatternSelect( tmpQGroupBox, name );
02750     pattern[i]->setFrameStyle( QFrame::Panel | QFrame::Sunken );
02751     grid2->addWidget(pattern[i], i % 5 + 1, i / 5);
02752     /* this puts them in the pattern:
02753        1  6
02754        2  7
02755        3  8
02756        4  9
02757        5  10
02758     */
02759   }
02760 
02761   color = new KColorButton (tmpQGroupBox, "PushButton_1" );
02762   grid2->addWidget(color,7,1);
02763 
02764   QLabel *tmpQLabel = new QLabel( tmpQGroupBox, "Label_6" );
02765   tmpQLabel->setText( i18n("Color:") );
02766   grid2->addWidget(tmpQLabel,7,0);
02767 
02768   /* tack on the 'customize' border pattern selector */
02769   QGridLayout *grid3 = new QGridLayout( this, 2, 2, KDialog::marginHint(), KDialog::spacingHint() );
02770   customize  = new QCheckBox(i18n("Customize"),tmpQGroupBox);
02771   grid3->addWidget(customize,0,0);
02772   connect( customize, SIGNAL( clicked()), SLOT(cutomize_chosen_slot()) );
02773 
02774   size=new QComboBox(true,tmpQGroupBox);
02775   grid3->addWidget(size,1,1);
02776   size->setValidator(new KIntValidator( size ));
02777   QString tmp;
02778   for ( int i=0;i<10;i++)
02779   {
02780     tmp=tmp.setNum(i);
02781     size->insertItem(tmp);
02782   }
02783   size->setCurrentItem(1);
02784 
02785   style=new QComboBox(tmpQGroupBox);
02786   grid3->addWidget(style,1,0);
02787   style->insertItem(paintFormatPixmap(DotLine),0 );
02788   style->insertItem(paintFormatPixmap(DashLine) ,1);
02789   style->insertItem(paintFormatPixmap(DashDotLine),2 );
02790   style->insertItem(paintFormatPixmap(DashDotDotLine),3  );
02791   style->insertItem(paintFormatPixmap(SolidLine),4);
02792   style->setBackgroundColor( colorGroup().background() );
02793 
02794   grid2->addMultiCell(grid3,6,6,0,1);
02795   grid->addMultiCellWidget(tmpQGroupBox,0,3,1,1);
02796 
02797   /* Now the preview box is put together */
02798   tmpQGroupBox = new QGroupBox(this, "GroupBox_4" );
02799   tmpQGroupBox->setFrameStyle( QFrame::Box | QFrame::Sunken );
02800   tmpQGroupBox->setTitle( i18n("Preview") );
02801   tmpQGroupBox->setAlignment( AlignLeft );
02802 
02803   grid2 = new QGridLayout(tmpQGroupBox,1,1,KDialog::marginHint(), KDialog::spacingHint());
02804   fHeight = tmpQGroupBox->fontMetrics().height();
02805   grid2->addRowSpacing( 0, fHeight/2 ); // groupbox title
02806 
02807   preview = new PatternSelect( tmpQGroupBox, "Pattern_preview" );
02808   preview->setFrameStyle( QFrame::Panel | QFrame::Sunken );
02809   grid2->addWidget(preview,1,0);
02810 
02811   grid->addWidget(tmpQGroupBox,4,1);
02812 }
02813 
02814 void CellFormatPageBorder::InitializeBorderButtons()
02815 {
02816   for (int i=BorderType_Top; i < BorderType_END; i++)
02817   {
02818     if (dlg->borders[i].style != Qt::NoPen ||
02819        !dlg->borders[i].bStyle )
02820     {
02821       /* the horozontil and vertical buttons might be disabled depending on what
02822          kind of area is selected so check that first. */
02823       if ((dlg->oneRow == true && i == BorderType_Horizontal) ||
02824           (dlg->oneCol == true && i == BorderType_Vertical))
02825       {
02826         borderButtons[i]->setEnabled(false);
02827       }
02828       else if ( dlg->borders[i].bColor && dlg->borders[i].bStyle  )
02829       {
02830         borderButtons[i]->setPenStyle(dlg->borders[i].style );
02831         borderButtons[i]->setPenWidth(dlg->borders[i].width);
02832         borderButtons[i]->setColor(dlg->borders[i].color);
02833         borderButtons[i]->setOn(true);
02834       }
02835       else
02836       {
02837         borderButtons[i]->setUndefined();
02838       }
02839     }
02840   }
02841 
02842 
02843 }
02844 
02845 void CellFormatPageBorder::InitializePatterns()
02846 {
02847   pattern[0]->setPattern( black, 1, DotLine );
02848   pattern[1]->setPattern( black, 1, DashLine );
02849   pattern[2]->setPattern( black, 1, SolidLine );
02850   pattern[3]->setPattern( black, 1, DashDotLine );
02851   pattern[4]->setPattern( black, 1, DashDotDotLine );
02852   pattern[5]->setPattern( black, 2, SolidLine );
02853   pattern[6]->setPattern( black, 3, SolidLine );
02854   pattern[7]->setPattern( black, 4, SolidLine );
02855   pattern[8]->setPattern( black, 5, SolidLine );
02856   pattern[9]->setPattern( black, 1, NoPen );
02857 
02858   slotSetColorButton( black );
02859 }
02860 
02861 void CellFormatPageBorder::SetConnections()
02862 {
02863   connect( color, SIGNAL( changed( const QColor & ) ),
02864            this, SLOT( slotSetColorButton( const QColor & ) ) );
02865 
02866   for (int i=0; i < NUM_BORDER_PATTERNS; i++)
02867   {
02868     connect( pattern[i], SIGNAL( clicked( PatternSelect* ) ),
02869              this, SLOT( slotUnselect2( PatternSelect* ) ) );
02870   }
02871 
02872   for (int i = BorderType_Top; i < BorderType_END; i++)
02873   {
02874     connect( borderButtons[i], SIGNAL( clicked (BorderButton *) ),
02875              this, SLOT( changeState( BorderButton *) ) );
02876   }
02877 
02878   for (int i = BorderShortcutType_Remove; i < BorderShortcutType_END; i++)
02879   {
02880     connect( shortcutButtons[i], SIGNAL( clicked(BorderButton *) ),
02881              this, SLOT( preselect(BorderButton *) ) );
02882   }
02883 
02884   connect( area ,SIGNAL( redraw()),this,SLOT(draw()));
02885   connect( area ,SIGNAL( choosearea(QMouseEvent * )),
02886            this,SLOT( slotPressEvent(QMouseEvent *)));
02887 
02888   connect( style, SIGNAL( activated(int)), this, SLOT(slotChangeStyle(int)));
02889   connect( size, SIGNAL( textChanged(const QString &)),
02890            this, SLOT(slotChangeStyle(const QString &)));
02891   connect( size ,SIGNAL( activated(int)), this, SLOT(slotChangeStyle(int)));
02892 }
02893 
02894 void CellFormatPageBorder::cutomize_chosen_slot()
02895 {
02896   if ( customize->isChecked() )
02897   {
02898     style->setEnabled( true );
02899     size->setEnabled( true );
02900     slotUnselect2( preview );
02901   }
02902   else
02903   {
02904     style->setEnabled( false );
02905     size->setEnabled( false );
02906     pattern[2]->slotSelect();
02907     preview->setPattern( black , 1, SolidLine );
02908   }
02909 }
02910 
02911 void CellFormatPageBorder::slotChangeStyle(const QString &)
02912 {
02913   /* if they try putting text in the size box, then erase the line */
02914   slotChangeStyle(0);
02915 }
02916 
02917 void CellFormatPageBorder::slotChangeStyle(int)
02918 {
02919   int index = style->currentItem();
02920   QString tmp;
02921   int penSize = size->currentText().toInt();
02922   if ( !penSize)
02923   {
02924     preview->setPattern( preview->getColor(), penSize, NoPen );
02925   }
02926   else
02927   {
02928     switch(index)
02929     {
02930     case 0:
02931       preview->setPattern( preview->getColor(), penSize, DotLine );
02932       break;
02933     case 1:
02934       preview->setPattern( preview->getColor(), penSize, DashLine );
02935       break;
02936     case 2:
02937       preview->setPattern( preview->getColor(), penSize, DashDotLine );
02938       break;
02939     case 3:
02940       preview->setPattern( preview->getColor(), penSize, DashDotDotLine );
02941       break;
02942     case 4:
02943       preview->setPattern( preview->getColor(), penSize, SolidLine );
02944       break;
02945     default:
02946       kdDebug(36001)<<"Error in combobox\n";
02947       break;
02948     }
02949   }
02950   slotUnselect2(preview);
02951 }
02952 
02953 QPixmap CellFormatPageBorder::paintFormatPixmap(PenStyle _style)
02954 {
02955   QPixmap pixmap( style->width(), 14 );
02956   QPainter painter;
02957   QPen pen;
02958   pen=QPen( colorGroup().text(),1,_style);
02959   painter.begin( &pixmap );
02960   painter.fillRect( 0, 0, style->width(), 14, colorGroup().background() );
02961   painter.setPen( pen );
02962   painter.drawLine( 0, 7, style->width(), 7 );
02963   painter.end();
02964   return pixmap;
02965 }
02966 
02967 void CellFormatPageBorder::loadIcon( QString _pix, BorderButton *_button)
02968 {
02969   _button->setPixmap( QPixmap( KSBarIcon(_pix) ) );
02970 }
02971 
02972 void CellFormatPageBorder::apply(FormatManipulator* obj)
02973 {
02974   if (borderButtons[BorderType_Horizontal]->isChanged())
02975     applyHorizontalOutline(obj);
02976 
02977   if (borderButtons[BorderType_Vertical]->isChanged())
02978     applyVerticalOutline(obj);
02979 
02980   if ( borderButtons[BorderType_Left]->isChanged() )
02981     applyLeftOutline(obj);
02982 
02983   if ( borderButtons[BorderType_Right]->isChanged() )
02984     applyRightOutline(obj);
02985 
02986   if ( borderButtons[BorderType_Top]->isChanged() )
02987     applyTopOutline(obj);
02988 
02989   if ( borderButtons[BorderType_Bottom]->isChanged() )
02990     applyBottomOutline(obj);
02991 
02992   if ( borderButtons[BorderType_RisingDiagonal]->isChanged() ||
02993        borderButtons[BorderType_FallingDiagonal]->isChanged() )
02994     applyDiagonalOutline(obj);
02995 }
02996 
02997 void CellFormatPageBorder::applyTopOutline(FormatManipulator* obj)
02998 {
02999   BorderButton * top = borderButtons[BorderType_Top];
03000 
03001   QPen tmpPen( top->getColor(), top->getPenWidth(), top->getPenStyle());
03002 
03003   if ( dlg->getStyle() )
03004   {
03005     dlg->getStyle()->changeTopBorderPen( tmpPen );
03006   }
03007   else
03008   {
03009     if (borderButtons[BorderType_Top]->isChanged())
03010       obj->setTopBorderPen( tmpPen );
03011   }
03012 }
03013 
03014 void CellFormatPageBorder::applyBottomOutline(FormatManipulator* obj)
03015 {
03016   BorderButton * bottom = borderButtons[BorderType_Bottom];
03017 
03018   QPen tmpPen( bottom->getColor(), bottom->getPenWidth(), bottom->getPenStyle() );
03019 
03020   if ( dlg->getStyle() )
03021   {
03022     dlg->getStyle()->changeBottomBorderPen( tmpPen );
03023   }
03024   else
03025   {
03026     if (borderButtons[BorderType_Bottom]->isChanged())
03027       obj->setBottomBorderPen( tmpPen );
03028   }
03029 }
03030 
03031 void CellFormatPageBorder::applyLeftOutline(FormatManipulator* obj)
03032 {
03033   BorderButton * left = borderButtons[BorderType_Left];
03034   QPen tmpPen( left->getColor(), left->getPenWidth(), left->getPenStyle() );
03035 
03036   if ( dlg->getStyle() )
03037   {
03038     dlg->getStyle()->changeLeftBorderPen( tmpPen );
03039   }
03040   else
03041   {
03042     if (borderButtons[BorderType_Left]->isChanged())
03043       obj->setLeftBorderPen( tmpPen );
03044   }
03045 }
03046 
03047 void CellFormatPageBorder::applyRightOutline(FormatManipulator* obj)
03048 {
03049   BorderButton* right = borderButtons[BorderType_Right];
03050   QPen tmpPen( right->getColor(), right->getPenWidth(), right->getPenStyle() );
03051 
03052   if ( dlg->getStyle() )
03053   {
03054     dlg->getStyle()->changeRightBorderPen( tmpPen );
03055   }
03056   else
03057   {
03058     if (borderButtons[BorderType_Right]->isChanged())
03059       obj->setRightBorderPen( tmpPen );
03060   }
03061 }
03062 
03063 void CellFormatPageBorder::applyDiagonalOutline(FormatManipulator* obj)
03064 {
03065   BorderButton * fallDiagonal = borderButtons[BorderType_FallingDiagonal];
03066   BorderButton * goUpDiagonal = borderButtons[BorderType_RisingDiagonal];
03067   QPen tmpPenFall( fallDiagonal->getColor(), fallDiagonal->getPenWidth(),
03068                    fallDiagonal->getPenStyle());
03069   QPen tmpPenGoUp( goUpDiagonal->getColor(), goUpDiagonal->getPenWidth(),
03070                    goUpDiagonal->getPenStyle());
03071 
03072   if ( dlg->getStyle() )
03073   {
03074     if ( fallDiagonal->isChanged() )
03075       dlg->getStyle()->changeFallBorderPen( tmpPenFall );
03076     if ( goUpDiagonal->isChanged() )
03077       dlg->getStyle()->changeGoUpBorderPen( tmpPenGoUp );
03078   }
03079   else
03080   {
03081     if ( fallDiagonal->isChanged() )
03082       obj->setFallDiagonalPen( tmpPenFall );
03083     if ( goUpDiagonal->isChanged() )
03084       obj->setGoUpDiagonalPen( tmpPenGoUp );
03085   }
03086 }
03087 
03088 void CellFormatPageBorder::applyHorizontalOutline(FormatManipulator* obj)
03089 {
03090   QPen tmpPen( borderButtons[BorderType_Horizontal]->getColor(),
03091                borderButtons[BorderType_Horizontal]->getPenWidth(),
03092                borderButtons[BorderType_Horizontal]->getPenStyle());
03093 
03094   if ( dlg->getStyle() )
03095   {
03096     dlg->getStyle()->changeTopBorderPen( tmpPen );
03097   }
03098   else
03099   {
03100     if (borderButtons[BorderType_Horizontal]->isChanged())
03101       obj->setHorizontalPen( tmpPen );
03102   }
03103 }
03104 
03105 void CellFormatPageBorder::applyVerticalOutline(FormatManipulator* obj)
03106 {
03107   BorderButton* vertical = borderButtons[BorderType_Vertical];
03108   QPen tmpPen( vertical->getColor(), vertical->getPenWidth(),
03109                vertical->getPenStyle());
03110 
03111   if ( dlg->getStyle() )
03112   {
03113     dlg->getStyle()->changeLeftBorderPen( tmpPen );
03114   }
03115   else
03116   {
03117     if (borderButtons[BorderType_Vertical]->isChanged())
03118       obj->setVerticalPen( tmpPen );
03119   }
03120 }
03121 
03122 
03123 void CellFormatPageBorder::slotSetColorButton( const QColor &_color )
03124 {
03125     currentColor = _color;
03126 
03127     for ( int i = 0; i < NUM_BORDER_PATTERNS; ++i )
03128     {
03129       pattern[i]->setColor( currentColor );
03130     }
03131     preview->setColor( currentColor );
03132 }
03133 
03134 void CellFormatPageBorder::slotUnselect2( PatternSelect *_p )
03135 {
03136     for ( int i = 0; i < NUM_BORDER_PATTERNS; ++i )
03137     {
03138       if ( pattern[i] != _p )
03139       {
03140         pattern[i]->slotUnselect();
03141       }
03142     }
03143     preview->setPattern( _p->getColor(), _p->getPenWidth(), _p->getPenStyle() );
03144 }
03145 
03146 void CellFormatPageBorder::preselect( BorderButton *_p )
03147 {
03148   BorderButton* top = borderButtons[BorderType_Top];
03149   BorderButton* bottom = borderButtons[BorderType_Bottom];
03150   BorderButton* left = borderButtons[BorderType_Left];
03151   BorderButton* right = borderButtons[BorderType_Right];
03152   BorderButton* vertical = borderButtons[BorderType_Vertical];
03153   BorderButton* horizontal = borderButtons[BorderType_Horizontal];
03154   BorderButton* remove = shortcutButtons[BorderShortcutType_Remove];
03155   BorderButton* outline = shortcutButtons[BorderShortcutType_Outline];
03156   BorderButton* all = shortcutButtons[BorderShortcutType_All];
03157 
03158   _p->setOn(false);
03159   if (_p == remove)
03160   {
03161     for (int i=BorderType_Top; i < BorderType_END; i++)
03162     {
03163       if (borderButtons[i]->isOn())
03164       {
03165         borderButtons[i]->unselect();
03166       }
03167     }
03168   }
03169   if (_p==outline)
03170   {
03171     top->setOn(true);
03172     top->setPenWidth(preview->getPenWidth());
03173     top->setPenStyle(preview->getPenStyle());
03174     top->setColor( currentColor );
03175     top->setChanged(true);
03176     bottom->setOn(true);
03177     bottom->setPenWidth(preview->getPenWidth());
03178     bottom->setPenStyle(preview->getPenStyle());
03179     bottom->setColor( currentColor );
03180     bottom->setChanged(true);
03181     left->setOn(true);
03182     left->setPenWidth(preview->getPenWidth());
03183     left->setPenStyle(preview->getPenStyle());
03184     left->setColor( currentColor );
03185     left->setChanged(true);
03186     right->setOn(true);
03187     right->setPenWidth(preview->getPenWidth());
03188     right->setPenStyle(preview->getPenStyle());
03189     right->setColor( currentColor );
03190     right->setChanged(true);
03191   }
03192   if (_p==all)
03193   {
03194     if (dlg->oneRow==false)
03195     {
03196       horizontal->setOn(true);
03197       horizontal->setPenWidth(preview->getPenWidth());
03198       horizontal->setPenStyle(preview->getPenStyle());
03199       horizontal->setColor( currentColor );
03200       horizontal->setChanged(true);
03201     }
03202     if (dlg->oneCol==false)
03203     {
03204       vertical->setOn(true);
03205       vertical->setPenWidth(preview->getPenWidth());
03206       vertical->setPenStyle(preview->getPenStyle());
03207       vertical->setColor( currentColor );
03208       vertical->setChanged(true);
03209     }
03210   }
03211   area->repaint();
03212 }
03213 
03214 void CellFormatPageBorder::changeState( BorderButton *_p)
03215 {
03216   _p->setChanged(true);
03217 
03218   if (_p->isOn())
03219   {
03220     _p->setPenWidth(preview->getPenWidth());
03221     _p->setPenStyle(preview->getPenStyle());
03222     _p->setColor( currentColor );
03223   }
03224   else
03225   {
03226     _p->setPenWidth(1);
03227     _p->setPenStyle(Qt::NoPen);
03228     _p->setColor( colorGroup().text() );
03229   }
03230 
03231  area->repaint();
03232 }
03233 
03234 void CellFormatPageBorder::draw()
03235 {
03236   BorderButton* top = borderButtons[BorderType_Top];
03237   BorderButton* bottom = borderButtons[BorderType_Bottom];
03238   BorderButton* left = borderButtons[BorderType_Left];
03239   BorderButton* right = borderButtons[BorderType_Right];
03240   BorderButton* risingDiagonal = borderButtons[BorderType_RisingDiagonal];
03241   BorderButton* fallingDiagonal = borderButtons[BorderType_FallingDiagonal];
03242   BorderButton* vertical = borderButtons[BorderType_Vertical];
03243   BorderButton* horizontal = borderButtons[BorderType_Horizontal];
03244   QPen pen;
03245   QPainter painter;
03246   painter.begin( area );
03247 
03248   if ((bottom->getPenStyle())!=Qt::NoPen)
03249   {
03250     pen=QPen( bottom->getColor(), bottom->getPenWidth(),bottom->getPenStyle());
03251     painter.setPen( pen );
03252     painter.drawLine( OFFSETX, area->height()-OFFSETY, area->width()-OFFSETX , area->height()-OFFSETY );
03253   }
03254   if ((top->getPenStyle())!=Qt::NoPen)
03255   {
03256     pen=QPen( top->getColor(), top->getPenWidth(),top->getPenStyle());
03257     painter.setPen( pen );
03258     painter.drawLine( OFFSETX, OFFSETY, area->width() -OFFSETX, OFFSETY );
03259   }
03260  if ((left->getPenStyle())!=Qt::NoPen)
03261  {
03262    pen=QPen( left->getColor(), left->getPenWidth(),left->getPenStyle());
03263    painter.setPen( pen );
03264    painter.drawLine( OFFSETX, OFFSETY, OFFSETX , area->height()-OFFSETY );
03265  }
03266  if ((right->getPenStyle())!=Qt::NoPen)
03267  {
03268    pen=QPen( right->getColor(), right->getPenWidth(),right->getPenStyle());
03269    painter.setPen( pen );
03270    painter.drawLine( area->width()-OFFSETX, OFFSETY, area->width()-OFFSETX,
03271                      area->height()-OFFSETY );
03272 
03273  }
03274  if ((fallingDiagonal->getPenStyle())!=Qt::NoPen)
03275  {
03276    pen=QPen( fallingDiagonal->getColor(), fallingDiagonal->getPenWidth(),
03277              fallingDiagonal->getPenStyle());
03278    painter.setPen( pen );
03279    painter.drawLine( OFFSETX, OFFSETY, area->width()-OFFSETX,
03280                      area->height()-OFFSETY );
03281    if (dlg->oneCol==false&& dlg->oneRow==false)
03282    {
03283      painter.drawLine( area->width()/2, OFFSETY, area->width()-OFFSETX,
03284                        area->height()/2 );
03285      painter.drawLine( OFFSETX,area->height()/2 , area->width()/2,
03286                        area->height()-OFFSETY );
03287    }
03288  }
03289  if ((risingDiagonal->getPenStyle())!=Qt::NoPen)
03290  {
03291    pen=QPen( risingDiagonal->getColor(), risingDiagonal->getPenWidth(),
03292              risingDiagonal->getPenStyle());
03293    painter.setPen( pen );
03294    painter.drawLine( OFFSETX, area->height()-OFFSETY , area->width()-OFFSETX ,
03295                      OFFSETY );
03296    if (dlg->oneCol==false&& dlg->oneRow==false)
03297    {
03298      painter.drawLine( area->width()/2, OFFSETY, OFFSETX, area->height()/2 );
03299      painter.drawLine( area->width()/2,area->height()-OFFSETY ,
03300                        area->width()-OFFSETX, area->height()/2 );
03301    }
03302 
03303  }
03304  if ((vertical->getPenStyle())!=Qt::NoPen)
03305     {
03306       pen=QPen( vertical->getColor(), vertical->getPenWidth(),
03307                 vertical->getPenStyle());
03308       painter.setPen( pen );
03309       painter.drawLine( area->width()/2, 5 , area->width()/2 , area->height()-5 );
03310     }
03311  if ((horizontal->getPenStyle())!=Qt::NoPen)
03312  {
03313    pen=QPen( horizontal->getColor(), horizontal->getPenWidth(),
03314              horizontal->getPenStyle());
03315    painter.setPen( pen );
03316    painter.drawLine( OFFSETX,area->height()/2,area->width()-OFFSETX,
03317                      area->height()/2 );
03318  }
03319  painter.end();
03320 }
03321 
03322 void CellFormatPageBorder::invertState(BorderButton *_p)
03323 {
03324   if (_p->isOn())
03325   {
03326     _p->unselect();
03327   }
03328   else
03329   {
03330     _p->setOn(true);
03331     _p->setPenWidth(preview->getPenWidth());
03332     _p->setPenStyle(preview->getPenStyle());
03333     _p->setColor( currentColor );
03334     _p->setChanged(true);
03335   }
03336 }
03337 
03338 void CellFormatPageBorder::slotPressEvent(QMouseEvent *_ev)
03339 {
03340   BorderButton* top = borderButtons[BorderType_Top];
03341   BorderButton* bottom = borderButtons[BorderType_Bottom];
03342   BorderButton* left = borderButtons[BorderType_Left];
03343   BorderButton* right = borderButtons[BorderType_Right];
03344   BorderButton* vertical = borderButtons[BorderType_Vertical];
03345   BorderButton* horizontal = borderButtons[BorderType_Horizontal];
03346 
03347 
03348   QRect rect(OFFSETX,OFFSETY-8,area->width()-OFFSETX,OFFSETY+8);
03349   if (rect.contains(QPoint(_ev->x(),_ev->y())))
03350   {
03351     if (((top->getPenWidth()!=preview->getPenWidth()) ||
03352         (top->getColor()!=currentColor) ||
03353         (top->getPenStyle()!=preview->getPenStyle()))
03354        && top->isOn())
03355     {
03356       top->setPenWidth(preview->getPenWidth());
03357       top->setPenStyle(preview->getPenStyle());
03358       top->setColor( currentColor );
03359       top->setChanged(true);
03360     }
03361     else
03362       invertState(top);
03363   }
03364   rect.setCoords(OFFSETX,area->height()-OFFSETY-8,area->width()-OFFSETX,
03365                  area->height()-OFFSETY+8);
03366   if (rect.contains(QPoint(_ev->x(),_ev->y())))
03367   {
03368     if (((bottom->getPenWidth()!=preview->getPenWidth()) ||
03369         (bottom->getColor()!=currentColor) ||
03370         (bottom->getPenStyle()!=preview->getPenStyle()))
03371        && bottom->isOn())
03372     {
03373       bottom->setPenWidth(preview->getPenWidth());
03374       bottom->setPenStyle(preview->getPenStyle());
03375       bottom->setColor( currentColor );
03376       bottom->setChanged(true);
03377     }
03378     else
03379       invertState(bottom);
03380   }
03381 
03382   rect.setCoords(OFFSETX-8,OFFSETY,OFFSETX+8,area->height()-OFFSETY);
03383   if (rect.contains(QPoint(_ev->x(),_ev->y())))
03384   {
03385     if (((left->getPenWidth()!=preview->getPenWidth()) ||
03386         (left->getColor()!=currentColor) ||
03387         (left->getPenStyle()!=preview->getPenStyle()))
03388        && left->isOn())
03389     {
03390       left->setPenWidth(preview->getPenWidth());
03391       left->setPenStyle(preview->getPenStyle());
03392       left->setColor( currentColor );
03393                 left->setChanged(true);
03394     }
03395     else
03396       invertState(left);
03397   }
03398   rect.setCoords(area->width()-OFFSETX-8,OFFSETY,area->width()-OFFSETX+8,
03399                  area->height()-OFFSETY);
03400   if (rect.contains(QPoint(_ev->x(),_ev->y())))
03401   {
03402     if (((right->getPenWidth()!=preview->getPenWidth()) ||
03403         (right->getColor()!=currentColor) ||
03404         (right->getPenStyle()!=preview->getPenStyle()))
03405        && right->isOn())
03406     {
03407       right->setPenWidth(preview->getPenWidth());
03408       right->setPenStyle(preview->getPenStyle());
03409       right->setColor( currentColor );
03410       right->setChanged(true);
03411     }
03412     else
03413       invertState(right);
03414   }
03415 
03416 //don't work because I don't know how create a rectangle
03417 //for diagonal
03418 /*rect.setCoords(OFFSETX,OFFSETY,XLEN-OFFSETX,YHEI-OFFSETY);
03419 if (rect.contains(QPoint(_ev->x(),_ev->y())))
03420         {
03421          invertState(fallDiagonal);
03422         }
03423 rect.setCoords(OFFSETX,YHEI-OFFSETY,XLEN-OFFSETX,OFFSETY);
03424 if (rect.contains(QPoint(_ev->x(),_ev->y())))
03425         {
03426          invertState(goUpDiagonal);
03427         } */
03428 
03429   if (dlg->oneCol==false)
03430   {
03431     rect.setCoords(area->width()/2-8,OFFSETY,area->width()/2+8,
03432                    area->height()-OFFSETY);
03433 
03434     if (rect.contains(QPoint(_ev->x(),_ev->y())))
03435     {
03436       if (((vertical->getPenWidth()!=preview->getPenWidth()) ||
03437           (vertical->getColor()!=currentColor) ||
03438           (vertical->getPenStyle()!=preview->getPenStyle()))
03439          && vertical->isOn())
03440       {
03441         vertical->setPenWidth(preview->getPenWidth());
03442         vertical->setPenStyle(preview->getPenStyle());
03443         vertical->setColor( currentColor );
03444         vertical->setChanged(true);
03445       }
03446       else
03447         invertState(vertical);
03448     }
03449   }
03450   if (dlg->oneRow==false)
03451   {
03452     rect.setCoords(OFFSETX,area->height()/2-8,area->width()-OFFSETX,
03453                    area->height()/2+8);
03454     if (rect.contains(QPoint(_ev->x(),_ev->y())))
03455     {
03456       if (((horizontal->getPenWidth()!=preview->getPenWidth()) ||
03457           (horizontal->getColor()!=currentColor) ||
03458           (horizontal->getPenStyle()!=preview->getPenStyle()))
03459          && horizontal->isOn())
03460       {
03461         horizontal->setPenWidth(preview->getPenWidth());
03462         horizontal->setPenStyle(preview->getPenStyle());
03463         horizontal->setColor( currentColor );
03464         horizontal->setChanged(true);
03465       }
03466       else
03467         invertState(horizontal);
03468     }
03469   }
03470 
03471   area->repaint();
03472 }
03473 
03474 
03475 
03476 /***************************************************************************
03477  *
03478  * BrushSelect
03479  *
03480  ***************************************************************************/
03481 
03482 BrushSelect::BrushSelect( QWidget *parent, const char * ) : QFrame( parent )
03483 {
03484     brushStyle = Qt::NoBrush;
03485     brushColor = Qt::red;
03486     selected = false;
03487 }
03488 
03489 void BrushSelect::setPattern( const QColor &_color,BrushStyle _style )
03490 {
03491     brushStyle = _style;
03492     brushColor = _color;
03493     repaint();
03494 }
03495 
03496 
03497 void BrushSelect::paintEvent( QPaintEvent *_ev )
03498 {
03499     QFrame::paintEvent( _ev );
03500 
03501     QPainter painter;
03502     QBrush brush(brushColor,brushStyle);
03503     painter.begin( this );
03504     painter.setPen( Qt::NoPen );
03505     painter.setBrush( brush);
03506     painter.drawRect( 2, 2, width()-4, height()-4);
03507     painter.end();
03508 }
03509 
03510 void BrushSelect::mousePressEvent( QMouseEvent * )
03511 {
03512     slotSelect();
03513 
03514     emit clicked( this );
03515 }
03516 
03517 void BrushSelect::slotUnselect()
03518 {
03519     selected = false;
03520 
03521     setLineWidth( 1 );
03522     setFrameStyle( QFrame::Panel | QFrame::Sunken );
03523     repaint();
03524 }
03525 
03526 void BrushSelect::slotSelect()
03527 {
03528     selected = true;
03529 
03530     setLineWidth( 2 );
03531     setFrameStyle( QFrame::Panel | QFrame::Plain );
03532     repaint();
03533 }
03534 
03535 
03536 
03537 /***************************************************************************
03538  *
03539  * CellFormatPagePattern
03540  *
03541  ***************************************************************************/
03542 
03543 CellFormatPagePattern::CellFormatPagePattern( QWidget* parent, CellFormatDialog *_dlg ) : QWidget( parent )
03544 {
03545     dlg = _dlg;
03546 
03547     bBgColorUndefined = !dlg->bBgColor;
03548 
03549     QGridLayout *grid = new QGridLayout(this,5,2,KDialog::marginHint(), KDialog::spacingHint());
03550 
03551     QGroupBox* tmpQGroupBox;
03552     tmpQGroupBox = new QGroupBox( this, "GroupBox_20" );
03553     tmpQGroupBox->setFrameStyle( QFrame::Box | QFrame::Sunken );
03554     tmpQGroupBox->setTitle( i18n("Pattern") );
03555     tmpQGroupBox->setAlignment( AlignLeft );
03556 
03557     QGridLayout *grid2 = new QGridLayout(tmpQGroupBox,8,3,KDialog::marginHint(), KDialog::spacingHint());
03558     int fHeight = tmpQGroupBox->fontMetrics().height();
03559     grid2->addRowSpacing( 0, fHeight/2 ); // groupbox title
03560 
03561 
03562     brush1 = new BrushSelect( tmpQGroupBox, "Frame_1" );
03563     brush1->setFrameStyle( QFrame::Panel | QFrame::Sunken );
03564     grid2->addWidget(brush1,1,0);
03565 
03566     brush2 = new BrushSelect( tmpQGroupBox, "Frame_2" );
03567     brush2->setFrameStyle( QFrame::Panel | QFrame::Sunken );
03568     grid2->addWidget(brush2,1,1);
03569 
03570     brush3 = new BrushSelect( tmpQGroupBox, "Frame_3" );
03571     brush3->setFrameStyle( QFrame::Panel | QFrame::Sunken );
03572     grid2->addWidget(brush3,1,2);
03573 
03574     brush4 = new BrushSelect( tmpQGroupBox, "Frame_4" );
03575     brush4->setFrameStyle( QFrame::Panel | QFrame::Sunken );
03576     grid2->addWidget(brush4,2,0);
03577 
03578     brush5 = new BrushSelect( tmpQGroupBox, "Frame_5" );
03579     brush5->setFrameStyle( QFrame::Panel | QFrame::Sunken );
03580     grid2->addWidget(brush5,2,1);
03581 
03582     brush6 = new BrushSelect( tmpQGroupBox, "Frame_6" );
03583     brush6->setFrameStyle( QFrame::Panel | QFrame::Sunken );
03584     grid2->addWidget(brush6,2,2);
03585 
03586     brush7 = new BrushSelect( tmpQGroupBox, "Frame_7" );
03587     brush7->setFrameStyle( QFrame::Panel | QFrame::Sunken );
03588     grid2->addWidget(brush7,3,0);
03589 
03590     brush8 = new BrushSelect( tmpQGroupBox, "Frame_8" );
03591     brush8->setFrameStyle( QFrame::Panel | QFrame::Sunken );
03592     grid2->addWidget(brush8,3,1);
03593 
03594     brush9 = new BrushSelect( tmpQGroupBox, "Frame_9" );
03595     brush9->setFrameStyle( QFrame::Panel | QFrame::Sunken );
03596     grid2->addWidget(brush9,3,2);
03597 
03598     brush10 = new BrushSelect( tmpQGroupBox, "Frame_10" );
03599     brush10->setFrameStyle( QFrame::Panel | QFrame::Sunken );
03600     grid2->addWidget(brush10,4,0);
03601 
03602     brush11 = new BrushSelect( tmpQGroupBox, "Frame_11" );
03603     brush11->setFrameStyle( QFrame::Panel | QFrame::Sunken );
03604     grid2->addWidget(brush11,4,1);
03605 
03606     brush12 = new BrushSelect( tmpQGroupBox, "Frame_12" );
03607     brush12->setFrameStyle( QFrame::Panel | QFrame::Sunken );
03608     grid2->addWidget(brush12,4,2);
03609 
03610     brush13 = new BrushSelect( tmpQGroupBox, "Frame_13" );
03611     brush13->setFrameStyle( QFrame::Panel | QFrame::Sunken );
03612     grid2->addWidget(brush13,5,0);
03613 
03614     brush14 = new BrushSelect( tmpQGroupBox, "Frame_14" );
03615     brush14->setFrameStyle( QFrame::Panel | QFrame::Sunken );
03616     grid2->addWidget(brush14,5,1);
03617 
03618     brush15 = new BrushSelect( tmpQGroupBox, "Frame_15" );
03619     brush15->setFrameStyle( QFrame::Panel | QFrame::Sunken );
03620     grid2->addWidget(brush15,5,2);
03621 
03622     QGridLayout *grid3 = new QGridLayout( 1, 2 );
03623     color = new KColorButton (tmpQGroupBox, "ColorButton_1" );
03624     grid3->addWidget(color,0,1);
03625 
03626     QLabel *tmpQLabel = new QLabel( tmpQGroupBox, "Label_1" );
03627     tmpQLabel->setText( i18n("Color:") );
03628     grid3->addWidget(tmpQLabel,0,0);
03629 
03630     grid2->addMultiCell(grid3,6,6,0,2);
03631 
03632     grid3 = new QGridLayout( 1, 3 );
03633     grid3->setSpacing(KDialog::spacingHint());
03634 
03635     tmpQLabel = new QLabel( tmpQGroupBox, "Label_2" );
03636     grid3->addWidget(tmpQLabel,0,0);
03637     tmpQLabel->setText( i18n("Background color:") );
03638 
03639     bgColorButton = new KColorButton( tmpQGroupBox, "ColorButton" );
03640     grid3->addWidget(bgColorButton,0,1);
03641     if ( dlg->bBgColor )
03642         bgColor = dlg->bgColor;
03643     else
03644         bgColor = colorGroup().base();
03645 
03646     if (!bgColor.isValid())
03647         bgColor = colorGroup().base();
03648 
03649     bgColorButton->setColor( bgColor );
03650     connect( bgColorButton, SIGNAL( changed( const QColor & ) ),
03651              this, SLOT( slotSetBackgroundColor( const QColor & ) ) );
03652 
03653     notAnyColor=new QPushButton(i18n("No Color"),tmpQGroupBox);
03654     grid3->addWidget(notAnyColor,0,2);
03655     connect( notAnyColor, SIGNAL( clicked( ) ),
03656              this, SLOT( slotNotAnyColor(  ) ) );
03657     b_notAnyColor=false;
03658 
03659     grid2->addMultiCell(grid3,7,7,0,2);
03660 
03661     grid->addMultiCellWidget(tmpQGroupBox,0,3,0,0);
03662 
03663     tmpQGroupBox = new QGroupBox( this, "GroupBox1" );
03664     tmpQGroupBox->setTitle( i18n("Preview") );
03665     tmpQGroupBox->setFrameStyle( QFrame::Box | QFrame::Sunken );
03666     tmpQGroupBox->setAlignment( AlignLeft );
03667 
03668     grid2 = new QGridLayout(tmpQGroupBox,2,1,KDialog::marginHint(), KDialog::spacingHint());
03669     fHeight = tmpQGroupBox->fontMetrics().height();
03670     grid2->addRowSpacing( 0, fHeight/2 ); // groupbox title
03671 
03672     current = new BrushSelect( tmpQGroupBox, "Current" );
03673     current->setFrameStyle( QFrame::Panel | QFrame::Sunken );
03674     grid2->addWidget(current,1,0);
03675     grid->addWidget( tmpQGroupBox,4,0);
03676 
03677     connect( brush1, SIGNAL( clicked( BrushSelect* ) ),
03678              this, SLOT( slotUnselect2( BrushSelect* ) ) );
03679     connect( brush2, SIGNAL( clicked( BrushSelect* ) ),
03680              this, SLOT( slotUnselect2( BrushSelect* ) ) );
03681     connect( brush3, SIGNAL( clicked( BrushSelect* ) ),
03682              this, SLOT( slotUnselect2( BrushSelect* ) ) );
03683     connect( brush4, SIGNAL( clicked( BrushSelect* ) ),
03684              this, SLOT( slotUnselect2( BrushSelect* ) ) );
03685     connect( brush5, SIGNAL( clicked( BrushSelect* ) ),
03686              this, SLOT( slotUnselect2( BrushSelect* ) ) );
03687     connect( brush6, SIGNAL( clicked( BrushSelect* ) ),
03688              this, SLOT( slotUnselect2( BrushSelect* ) ) );
03689     connect( brush7, SIGNAL( clicked( BrushSelect* ) ),
03690              this, SLOT( slotUnselect2( BrushSelect* ) ) );
03691     connect( brush8, SIGNAL( clicked( BrushSelect* ) ),
03692              this, SLOT( slotUnselect2( BrushSelect* ) ) );
03693     connect( brush9, SIGNAL( clicked( BrushSelect* ) ),
03694              this, SLOT( slotUnselect2( BrushSelect* ) ) );
03695     connect( brush10, SIGNAL( clicked( BrushSelect* ) ),
03696              this, SLOT( slotUnselect2( BrushSelect* ) ) );
03697     connect( brush11, SIGNAL( clicked( BrushSelect* ) ),
03698              this, SLOT( slotUnselect2( BrushSelect* ) ) );
03699     connect( brush12, SIGNAL( clicked( BrushSelect* ) ),
03700              this, SLOT( slotUnselect2( BrushSelect* ) ) );
03701     connect( brush13, SIGNAL( clicked( BrushSelect* ) ),
03702              this, SLOT( slotUnselect2( BrushSelect* ) ) );
03703     connect( brush14, SIGNAL( clicked( BrushSelect* ) ),
03704              this, SLOT( slotUnselect2( BrushSelect* ) ) );
03705     connect( brush15, SIGNAL( clicked( BrushSelect* ) ),
03706              this, SLOT( slotUnselect2( BrushSelect* ) ) );
03707 
03708     brush1->setPattern( Qt::red, Qt::VerPattern );
03709     brush2->setPattern( Qt::red,Qt::HorPattern );
03710     brush3->setPattern( Qt::red,Qt::Dense1Pattern );
03711     brush4->setPattern( Qt::red,Qt::Dense2Pattern );
03712     brush5->setPattern( Qt::red,Qt::Dense3Pattern );
03713     brush6->setPattern( Qt::red,Qt::Dense4Pattern );
03714     brush7->setPattern( Qt::red,Qt::Dense5Pattern );
03715     brush8->setPattern( Qt::red,Qt::Dense6Pattern );
03716     brush9->setPattern(  Qt::red,Qt::Dense7Pattern );
03717     brush10->setPattern(  Qt::red,Qt::CrossPattern );
03718     brush11->setPattern( Qt::red,Qt::BDiagPattern );
03719     brush12->setPattern( Qt::red,Qt::FDiagPattern );
03720     brush13->setPattern( Qt::red,Qt::VerPattern );
03721     brush14->setPattern( Qt::red,Qt::DiagCrossPattern );
03722     brush15->setPattern( Qt::red,Qt::NoBrush );
03723 
03724     current->setPattern(dlg->brushColor,dlg->brushStyle);
03725     current->slotSelect();
03726     selectedBrush=current;
03727     color->setColor(dlg->brushColor);
03728     current->setBackgroundColor( bgColor );
03729 
03730     connect( color, SIGNAL( changed( const QColor & ) ),
03731              this, SLOT( slotSetColorButton( const QColor & ) ) );
03732 
03733     slotSetColorButton( dlg->brushColor );
03734     init();
03735     this->resize( 400, 400 );
03736 }
03737 
03738 void CellFormatPagePattern::slotNotAnyColor()
03739 {
03740   b_notAnyColor = true;
03741   bgColorButton->setColor( colorGroup().base() );
03742   current->setBackgroundColor( colorGroup().base() );
03743 }
03744 
03745 void CellFormatPagePattern::slotSetBackgroundColor( const QColor &_color )
03746 {
03747   bgColor =_color;
03748   current->setBackgroundColor( bgColor );
03749   bBgColorUndefined = false;
03750   b_notAnyColor = false;
03751 }
03752 
03753 void CellFormatPagePattern::init()
03754 {
03755   if (dlg->brushStyle == Qt::VerPattern)
03756   {
03757     brush1->slotSelect();
03758   }
03759   else if (dlg->brushStyle == Qt::HorPattern)
03760   {
03761     brush2->slotSelect();
03762   }
03763   else if (dlg->brushStyle == Qt::Dense1Pattern)
03764   {
03765     brush3->slotSelect();
03766   }
03767   else if (dlg->brushStyle == Qt::Dense2Pattern)
03768   {
03769     brush4->slotSelect();
03770   }
03771   else if (dlg->brushStyle == Qt::Dense3Pattern)
03772   {
03773     brush5->slotSelect();
03774   }
03775   else if (dlg->brushStyle == Qt::Dense4Pattern)
03776   {
03777     brush6->slotSelect();
03778   }
03779   else if (dlg->brushStyle == Qt::Dense5Pattern)
03780   {
03781     brush7->slotSelect();
03782   }
03783   else if (dlg->brushStyle == Qt::Dense6Pattern)
03784   {
03785     brush8->slotSelect();
03786   }
03787   else if (dlg->brushStyle == Qt::Dense7Pattern)
03788   {
03789     brush9->slotSelect();
03790   }
03791   else if (dlg->brushStyle == Qt::CrossPattern)
03792   {
03793     brush10->slotSelect();
03794   }
03795   else if (dlg->brushStyle == Qt::BDiagPattern)
03796   {
03797     brush11->slotSelect();
03798   }
03799   else if (dlg->brushStyle == Qt::FDiagPattern)
03800   {
03801     brush12->slotSelect();
03802   }
03803   else if (dlg->brushStyle == Qt::VerPattern)
03804   {
03805     brush13->slotSelect();
03806   }
03807   else if (dlg->brushStyle == Qt::DiagCrossPattern)
03808   {
03809     brush14->slotSelect();
03810   }
03811   else if (dlg->brushStyle == Qt::NoBrush)
03812   {
03813     brush15->slotSelect();
03814   }
03815   else
03816     kdDebug(36001) << "Error in brushStyle" << endl;
03817 }
03818 
03819 void CellFormatPagePattern::slotSetColorButton( const QColor &_color )
03820 {
03821     currentColor = _color;
03822 
03823     brush1->setBrushColor( currentColor );
03824     brush2->setBrushColor( currentColor );
03825     brush3->setBrushColor( currentColor );
03826     brush4->setBrushColor( currentColor );
03827     brush5->setBrushColor( currentColor );
03828     brush6->setBrushColor( currentColor );
03829     brush7->setBrushColor( currentColor );
03830     brush8->setBrushColor( currentColor );
03831     brush9->setBrushColor( currentColor );
03832     brush10->setBrushColor( currentColor );
03833     brush11->setBrushColor( currentColor );
03834     brush12->setBrushColor( currentColor );
03835     brush13->setBrushColor( currentColor );
03836     brush14->setBrushColor( currentColor );
03837     brush15->setBrushColor( currentColor );
03838     current->setBrushColor( currentColor );
03839 }
03840 
03841 void CellFormatPagePattern::slotUnselect2( BrushSelect *_p )
03842 {
03843     selectedBrush = _p;
03844 
03845     if ( brush1 != _p )
03846         brush1->slotUnselect();
03847     if ( brush2 != _p )
03848         brush2->slotUnselect();
03849     if ( brush3 != _p )
03850         brush3->slotUnselect();
03851     if ( brush4 != _p )
03852         brush4->slotUnselect();
03853     if ( brush5 != _p )
03854         brush5->slotUnselect();
03855     if ( brush6 != _p )
03856         brush6->slotUnselect();
03857     if ( brush7 != _p )
03858         brush7->slotUnselect();
03859     if ( brush8 != _p )
03860         brush8->slotUnselect();
03861     if ( brush9 != _p )
03862         brush9->slotUnselect();
03863     if ( brush10 != _p )
03864         brush10->slotUnselect();
03865     if ( brush11 != _p )
03866         brush11->slotUnselect();
03867     if ( brush12 != _p )
03868         brush12->slotUnselect();
03869     if ( brush13 != _p )
03870         brush13->slotUnselect();
03871     if ( brush14 != _p )
03872         brush14->slotUnselect();
03873     if ( brush15 != _p )
03874         brush15->slotUnselect();
03875 
03876     current->setBrushStyle( selectedBrush->getBrushStyle() );
03877 }
03878 
03879 void CellFormatPagePattern::apply( CustomStyle * style )
03880 {
03881   if ( selectedBrush != 0L
03882     && ( dlg->brushStyle != selectedBrush->getBrushStyle()
03883          || dlg->brushColor != selectedBrush->getBrushColor() ) )
03884     style->changeBackGroundBrush( QBrush( selectedBrush->getBrushColor(), selectedBrush->getBrushStyle() ) );
03885 
03886   /*
03887     TODO: check...
03888   if ( b_notAnyColor)
03889     style->changeBgColor( QColor() );
03890   else
03891   */
03892   if ( bgColor != dlg->getStyle()->bgColor() )
03893     style->changeBgColor( bgColor );
03894 }
03895 
03896 void CellFormatPagePattern::apply(FormatManipulator *_obj)
03897 {
03898   if ( selectedBrush != 0L
03899        && ( dlg->brushStyle != selectedBrush->getBrushStyle()
03900             || dlg->brushColor != selectedBrush->getBrushColor() ) )
03901     _obj->setBackgroundBrush( QBrush( selectedBrush->getBrushColor(), selectedBrush->getBrushStyle() ) );
03902 
03903   if ( bgColor == dlg->bgColor )
03904     return;
03905 
03906   if ( b_notAnyColor)
03907     _obj->setBackgroundColor( QColor() );
03908   else if ( !bBgColorUndefined )
03909     _obj->setBackgroundColor( bgColor );
03910 }
03911 
03912 #include "kspread_dlg_layout.moc"
03913 
KDE Home | KDE Accessibility Home | Description of Access Keys