File indexing completed on 2024-05-12 16:35:22

0001 /* This file is part of the KDE project
0002    Copyright (C) 2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
0003              (C) 2004 Tomas Mecir <mecirt@gmail.com>
0004              (C) 2002-2004 Ariya Hidayat <ariya@kde.org>
0005              (C) 2002-2003 Norbert Andres <nandres@web.de>
0006              (C) 2001-2003 Philipp Mueller <philipp.mueller@gmx.de>
0007              (C) 2002 John Dailey <dailey@vt.edu>
0008              (C) 1999-2002 Laurent Montel <montel@kde.org>
0009              (C) 1999-2002 Harri Porten <porten@kde.org>
0010              (C) 2000-2001 David Faure <faure@kde.org>
0011              (C) 1998-2000 Torben Weis <weis@kde.org>
0012              (C) 2000 Werner Trobin <trobin@kde.org>
0013              (C) 1999 Reginald Stadlbauer <reggie@kde.org>
0014              (C) 1998-1999 Stephan Kulow <coolo@kde.org>
0015 
0016    This library is free software; you can redistribute it and/or
0017    modify it under the terms of the GNU Library General Public
0018    License as published by the Free Software Foundation; either
0019    version 2 of the License, or (at your option) any later version.
0020 
0021    This library is distributed in the hope that it will be useful,
0022    but WITHOUT ANY WARRANTY; without even the implied warranty of
0023    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0024    Library General Public License for more details.
0025 
0026    You should have received a copy of the GNU Library General Public License
0027    along with this library; see the file COPYING.LIB.  If not, write to
0028    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0029    Boston, MA 02110-1301, USA.
0030 */
0031 
0032 // Local
0033 #include "LayoutDialog.h"
0034 
0035 #include <stdlib.h>
0036 #include <math.h>
0037 
0038 #include <QIntValidator>
0039 #include <QButtonGroup>
0040 #include <QCheckBox>
0041 #include <QFrame>
0042 #include <QLabel>
0043 #include <QListWidget>
0044 #include <QFontDatabase>
0045 #include <QPainter>
0046 #include <QRadioButton>
0047 #include <QPaintEvent>
0048 #include <QMouseEvent>
0049 #include <QVBoxLayout>
0050 #include <QGridLayout>
0051 #include <QPixmap>
0052 #include <QSpinBox>
0053 
0054 #include <kcolorbutton.h>
0055 #include <kcombobox.h>
0056 #include <klineedit.h>
0057 
0058 #include <KoIcon.h>
0059 #include <KoCanvasBase.h>
0060 #include <KoUnitDoubleSpinBox.h>
0061 #include <KoUnit.h>
0062 
0063 #include "SheetsDebug.h"
0064 #include "CalculationSettings.h"
0065 #include "Cell.h"
0066 #include "CellStorage.h"
0067 #include "Localization.h"
0068 #include "Map.h"
0069 #include "RowFormatStorage.h"
0070 #include "ui/Selection.h"
0071 #include "Sheet.h"
0072 #include "Style.h"
0073 #include "StyleManager.h"
0074 #include "StyleStorage.h"
0075 #include "ValueFormatter.h"
0076 
0077 #include "commands/MergeCommand.h"
0078 #include "commands/StyleCommand.h"
0079 #include "commands/RowColumnManipulators.h"
0080 
0081 using namespace Calligra::Sheets;
0082 
0083 /***************************************************************************
0084  *
0085  * PatternSelect
0086  *
0087  ***************************************************************************/
0088 
0089 PatternSelect::PatternSelect(QWidget *parent, const char *)
0090         : QFrame(parent)
0091 {
0092     penStyle = Qt::NoPen;
0093     penWidth = 1;
0094     penColor = palette().text().color();
0095     selected = false;
0096     undefined = false;
0097 }
0098 
0099 void PatternSelect::setPattern(const QColor &_color, int _width, Qt::PenStyle _style)
0100 {
0101     penStyle = _style;
0102     penColor = _color;
0103     penWidth = _width;
0104     repaint();
0105 }
0106 
0107 void PatternSelect::setUndefined()
0108 {
0109     undefined = true;
0110 }
0111 
0112 void PatternSelect::paintEvent(QPaintEvent *_ev)
0113 {
0114     QFrame::paintEvent(_ev);
0115 
0116     QPainter painter(this);
0117 
0118     if (!undefined) {
0119         QPen pen(penColor, penWidth, penStyle);
0120         painter.setPen(pen);
0121         painter.drawLine(6, height() / 2, width() - 6, height() / 2);
0122     } else {
0123         painter.fillRect(2, 2, width() - 4, height() - 4, Qt::BDiagPattern);
0124     }
0125 }
0126 
0127 void PatternSelect::mousePressEvent(QMouseEvent *)
0128 {
0129     slotSelect();
0130 
0131     emit clicked(this);
0132 }
0133 
0134 void PatternSelect::slotUnselect()
0135 {
0136     selected = false;
0137 
0138     setLineWidth(1);
0139     setFrameStyle(QFrame::Panel | QFrame::Sunken);
0140     repaint();
0141 }
0142 
0143 void PatternSelect::slotSelect()
0144 {
0145     selected = true;
0146 
0147     setLineWidth(2);
0148     setFrameStyle(QFrame::Panel | QFrame::Plain);
0149     repaint();
0150 }
0151 
0152 
0153 
0154 /***************************************************************************
0155  *
0156  * GeneralTab
0157  *
0158  ***************************************************************************/
0159 
0160 GeneralTab::GeneralTab(QWidget* parent, CellFormatDialog * dlg)
0161         : QWidget(parent),
0162         m_dlg(dlg)
0163 {
0164     QGridLayout * layout = new QGridLayout(this);
0165 
0166     QGroupBox * groupBox = new QGroupBox(this);
0167     groupBox->setTitle(i18n("Style"));
0168 
0169     QGridLayout * groupBoxLayout = new QGridLayout(groupBox);
0170     groupBoxLayout->setAlignment(Qt::AlignTop);
0171 
0172     QLabel * label1 = new QLabel(groupBox);
0173     label1->setText(i18nc("Name of the style", "Name:"));
0174     groupBoxLayout->addWidget(label1, 0, 0);
0175 
0176     m_nameEdit = new KLineEdit(groupBox);
0177     m_nameEdit->setText(m_dlg->styleName);
0178     groupBoxLayout->addWidget(m_nameEdit, 0, 1);
0179 
0180     m_nameStatus = new QLabel(groupBox);
0181     m_nameStatus->hide();
0182     groupBoxLayout->addWidget(m_nameStatus, 1, 1);
0183 
0184     QLabel * label2 = new QLabel(groupBox);
0185     label2->setText(i18n("Inherit style:"));
0186     groupBoxLayout->addWidget(label2, 2, 0);
0187 
0188     m_parentBox = new KComboBox(false, groupBox);
0189     m_parentBox->clear();
0190     QStringList tmp = m_dlg->getStyleManager()->styleNames();
0191     tmp.removeAll(m_dlg->styleName);
0192     // place the default style first
0193     tmp.removeAll(i18n("Default"));
0194     m_parentBox->insertItem(0, i18n("Default"));
0195     m_parentBox->insertItems(1, tmp);
0196 
0197     if (!m_dlg->getStyle()->parentName().isNull())
0198         m_parentBox->setCurrentIndex(m_parentBox->findText(m_dlg->getStyle()->parentName()));
0199     else
0200         m_parentBox->setCurrentIndex(m_parentBox->findText(i18n("Default")));
0201 
0202     connect(m_parentBox, SIGNAL(activated(QString)),
0203             this, SLOT(parentChanged(QString)));
0204     connect(m_nameEdit, SIGNAL(textChanged(QString)),
0205             this, SLOT(styleNameChanged(QString)));
0206 
0207     groupBoxLayout->addWidget(m_parentBox, 2, 1);
0208 
0209     m_parentStatus = new QLabel(groupBox);
0210     m_parentStatus->hide();
0211     groupBoxLayout->addWidget(m_parentStatus, 3, 1);
0212 
0213     QSpacerItem * spacer = new QSpacerItem(20, 260, QSizePolicy::Minimum, QSizePolicy::Expanding);
0214 
0215     layout->addWidget(groupBox, 0, 0);
0216     layout->addItem(spacer, 1, 0);
0217 
0218     if (m_dlg->getStyle()->type() == Style::BUILTIN) {
0219         m_nameEdit->setEnabled(false);
0220         m_parentBox->setEnabled(false);
0221     }
0222 
0223     resize(QSize(534, 447).expandedTo(minimumSizeHint()));
0224 }
0225 
0226 GeneralTab::~GeneralTab()
0227 {
0228 }
0229 
0230 void GeneralTab::styleNameChanged(const QString& name)
0231 {
0232     if (!m_dlg->getStyleManager()->validateStyleName(name, m_dlg->getStyle())) {
0233         m_nameStatus->setText(i18n("A style with this name already exists."));
0234         m_nameStatus->show();
0235         m_dlg->setOkButtonEnabled(false);
0236     } else if (name.isEmpty()) {
0237         m_nameStatus->setText(i18n("The style name can not be empty."));
0238         m_nameStatus->show();
0239         m_dlg->setOkButtonEnabled(false);
0240     } else {
0241         m_nameStatus->hide();
0242         m_dlg->setOkButtonEnabled(true);
0243     }
0244 }
0245 
0246 void GeneralTab::parentChanged(const QString& parentName)
0247 {
0248     if (m_nameEdit->text() == parentName) {
0249         m_parentStatus->setText(i18n("A style cannot inherit from itself."));
0250         m_parentStatus->show();
0251         m_dlg->setOkButtonEnabled(false);
0252     } else if (!m_dlg->checkCircle(m_nameEdit->text(), parentName)) {
0253         m_parentStatus->setText(i18n("The style cannot inherit from '%1' because of recursive references.",
0254                                      m_parentBox->currentText()));
0255         m_parentStatus->show();
0256         m_dlg->setOkButtonEnabled(false);
0257     } else {
0258         m_parentStatus->hide();
0259         m_dlg->setOkButtonEnabled(true);
0260     }
0261 
0262     if (parentName.isEmpty() || parentName == i18n("Default"))
0263         m_dlg->getStyle()->clearAttribute(Style::NamedStyleKey);
0264     else
0265         m_dlg->getStyle()->setParentName(parentName);
0266 
0267     // Set difference to new parent, set GUI to parent values, add changes made before
0268     //  m_dlg->initGUI();
0269 }
0270 
0271 bool GeneralTab::apply(CustomStyle * style)
0272 {
0273     if (m_nameEdit->isEnabled()) {
0274         if (style->type() != Style::BUILTIN) {
0275             QString name(style->name());
0276             style->setName(m_nameEdit->text());
0277             if (m_parentBox->isEnabled()) {
0278                 if (m_parentBox->currentText() == i18n("Default") || m_parentBox->currentText().isEmpty())
0279                     style->clearAttribute(Style::NamedStyleKey);
0280                 else
0281                     style->setParentName(m_parentBox->currentText());
0282             }
0283             m_dlg->getStyleManager()->changeName(name, m_nameEdit->text());
0284         }
0285     }
0286 
0287     if (style->type() == Style::TENTATIVE)
0288         style->setType(Style::CUSTOM);
0289 
0290     return true;
0291 }
0292 
0293 
0294 
0295 /***************************************************************************
0296  *
0297  * CellFormatDialog
0298  *
0299  ***************************************************************************/
0300 
0301 CellFormatDialog::CellFormatDialog(QWidget* parent, Selection* selection)
0302         : KPageDialog(parent)
0303         , m_sheet(selection->activeSheet())
0304         , m_selection(selection)
0305         , m_style(0)
0306         , m_styleManager(0)
0307 {
0308     initMembers();
0309 
0310     //We need both conditions quite often, so store the condition here too
0311     isRowSelected    = m_selection->isRowSelected();
0312     isColumnSelected = m_selection->isColumnSelected();
0313 
0314     QRect range = m_selection->lastRange();
0315     left = range.left();
0316     top = range.top();
0317     right = range.right();
0318     bottom = range.bottom();
0319 
0320     if (left == right)
0321         oneCol = true;
0322     else
0323         oneCol = false;
0324 
0325     if (top == bottom)
0326         oneRow = true;
0327     else
0328         oneRow = false;
0329 
0330     Cell cell = Cell(m_sheet, left, top);
0331     oneCell = (left == right && top == bottom &&
0332                !cell.doesMergeCells());
0333 
0334     isMerged = ((cell.doesMergeCells() &&
0335                  left + cell.mergedXCells() >= right &&
0336                  top + cell.mergedYCells() >= bottom));
0337 
0338     // Initialize with the upper left object.
0339     const Style styleTopLeft = cell.style();
0340     borders[BorderType_Left].style = styleTopLeft.leftBorderPen().style();
0341     borders[BorderType_Left].width = styleTopLeft.leftBorderPen().width();
0342     borders[BorderType_Left].color = styleTopLeft.leftBorderPen().color();
0343     borders[BorderType_Top].style = styleTopLeft.topBorderPen().style();
0344     borders[BorderType_Top].width = styleTopLeft.topBorderPen().width();
0345     borders[BorderType_Top].color = styleTopLeft.topBorderPen().color();
0346     borders[BorderType_FallingDiagonal].style = styleTopLeft.fallDiagonalPen().style();
0347     borders[BorderType_FallingDiagonal].width = styleTopLeft.fallDiagonalPen().width();
0348     borders[BorderType_FallingDiagonal].color = styleTopLeft.fallDiagonalPen().color();
0349     borders[BorderType_RisingDiagonal].style = styleTopLeft.goUpDiagonalPen().style();
0350     borders[BorderType_RisingDiagonal].width = styleTopLeft.goUpDiagonalPen().width();
0351     borders[BorderType_RisingDiagonal].color = styleTopLeft.goUpDiagonalPen().color();
0352 
0353     // Look at the upper right one for the right border.
0354     const Style styleTopRight = Cell(m_sheet, right, top).style();
0355     borders[BorderType_Right].style = styleTopRight.rightBorderPen().style();
0356     borders[BorderType_Right].width = styleTopRight.rightBorderPen().width();
0357     borders[BorderType_Right].color = styleTopRight.rightBorderPen().color();
0358 
0359     // Look at the bottom left cell for the bottom border.
0360     const Style styleBottomLeft = Cell(m_sheet, left, bottom).style();
0361     borders[BorderType_Bottom].style = styleBottomLeft.bottomBorderPen().style();
0362     borders[BorderType_Bottom].width = styleBottomLeft.bottomBorderPen().width();
0363     borders[BorderType_Bottom].color = styleBottomLeft.bottomBorderPen().color();
0364 
0365     // Just an assumption
0366     cell = Cell(m_sheet, right, top);
0367     if (cell.isPartOfMerged()) {
0368         cell = cell.masterCell();
0369 
0370         const Style styleMove1 = Cell(m_sheet, cell.column(), top).style();
0371         borders[BorderType_Vertical].style = styleMove1.leftBorderPen().style();
0372         borders[BorderType_Vertical].width = styleMove1.leftBorderPen().width();
0373         borders[BorderType_Vertical].color = styleMove1.leftBorderPen().color();
0374 
0375         const Style styleMove2 = Cell(m_sheet, right, cell.row()).style();
0376         borders[BorderType_Horizontal].style = styleMove2.topBorderPen().style();
0377         borders[BorderType_Horizontal].width = styleMove2.topBorderPen().width();
0378         borders[BorderType_Horizontal].color = styleMove2.topBorderPen().color();
0379     } else {
0380         borders[BorderType_Vertical].style = styleTopRight.leftBorderPen().style();
0381         borders[BorderType_Vertical].width = styleTopRight.leftBorderPen().width();
0382         borders[BorderType_Vertical].color = styleTopRight.leftBorderPen().color();
0383         const Style styleBottomRight = Cell(m_sheet, right, bottom).style();
0384         borders[BorderType_Horizontal].style = styleBottomRight.topBorderPen().style();
0385         borders[BorderType_Horizontal].width = styleBottomRight.topBorderPen().width();
0386         borders[BorderType_Horizontal].color = styleBottomRight.topBorderPen().color();
0387     }
0388 
0389     cell = Cell(m_sheet, left, top);
0390     prefix = styleTopLeft.prefix();
0391     postfix = styleTopLeft.postfix();
0392     precision = styleTopLeft.precision();
0393     floatFormat = styleTopLeft.floatFormat();
0394     floatColor = styleTopLeft.floatColor();
0395     alignX = styleTopLeft.halign();
0396     alignY = styleTopLeft.valign();
0397     textColor = styleTopLeft.fontColor();
0398     bgColor = styleTopLeft.backgroundColor();
0399     fontSize = styleTopLeft.fontSize();
0400     fontFamily = styleTopLeft.fontFamily();
0401     fontBold = styleTopLeft.bold();
0402     fontItalic = styleTopLeft.italic();
0403     strike = styleTopLeft.strikeOut();
0404     underline = styleTopLeft.underline();
0405     // Needed to initialize the font correctly ( bug in Qt )
0406     font = styleTopLeft.font();
0407     m_currency = styleTopLeft.currency();
0408 
0409     brushColor = styleTopLeft.backgroundBrush().color();
0410     brushStyle = styleTopLeft.backgroundBrush().style();
0411 
0412     bMultiRow = styleTopLeft.wrapText();
0413     bVerticalText = styleTopLeft.verticalText();
0414     bShrinkToFit = styleTopLeft.shrinkToFit();
0415     textRotation = styleTopLeft.angle();
0416     formatType = styleTopLeft.formatType();
0417 
0418     bDontPrintText = !styleTopLeft.printText();
0419     bHideFormula   = styleTopLeft.hideFormula();
0420     bHideAll       = styleTopLeft.hideAll();
0421     bIsProtected   = !styleTopLeft.notProtected();
0422 
0423     indent = styleTopLeft.indentation();
0424 
0425     value = cell.value();
0426 
0427     const ColumnFormat *cl;
0428     widthSize = 0.0;
0429     heightSize = 0.0;
0430 
0431     Selection::ConstIterator end(m_selection->constEnd());
0432     for (Selection::ConstIterator it(m_selection->constBegin()); it != end; ++it) {
0433         QRect range = (*it)->rect();
0434         Style style = m_sheet->cellStorage()->style(range);   // FIXME merge
0435         initParameters(style);
0436 
0437         // left border
0438         range.setWidth(1);
0439         checkBorderLeft(m_sheet->cellStorage()->style(range));
0440         // right border
0441         range = (*it)->rect();
0442         range.setLeft(range.right());
0443         checkBorderRight(m_sheet->cellStorage()->style(range));
0444         // inner borders
0445         range = (*it)->rect();
0446         range = range.adjusted(1, 1, -1, -1);
0447         style = m_sheet->cellStorage()->style(range);
0448         checkBorderHorizontal(style);
0449         checkBorderVertical(style);
0450         // top border
0451         range = (*it)->rect();
0452         range.setHeight(1);
0453         checkBorderTop(style);
0454         // bottom border
0455         range = (*it)->rect();
0456         range.setBottom(range.top());
0457         checkBorderBottom(m_sheet->cellStorage()->style(range));
0458     }
0459 
0460     // column width
0461     if (!isRowSelected) {
0462         for (int x = left; x <= right; x++) {
0463             cl = m_sheet->columnFormat(x);
0464             widthSize = qMax(cl->width(), widthSize);
0465         }
0466     }
0467 
0468     // row height
0469     if (!isColumnSelected) {
0470         for (int y = top; y <= bottom; y++) {
0471             heightSize = qMax(m_sheet->rowFormats()->rowHeight(y), static_cast<qreal>(heightSize) );
0472         }
0473     }
0474 
0475     if (!bTextRotation)
0476         textRotation = 0;
0477 
0478     init();
0479 }
0480 
0481 CellFormatDialog::CellFormatDialog(QWidget* parent, Selection* selection,
0482                                    CustomStyle* style, StyleManager* manager)
0483         : KPageDialog(parent)
0484         , m_sheet(selection->activeSheet())
0485         , m_selection(selection)
0486         , m_style(style)
0487         , m_styleManager(manager)
0488 {
0489     initMembers();
0490     initGUI();
0491     init();
0492 }
0493 
0494 void CellFormatDialog::initGUI()
0495 {
0496     isRowSelected    = false;
0497     isColumnSelected = false;
0498     styleName = m_style->name();
0499 
0500     borders[BorderType_Left].style = m_style->leftBorderPen().style();
0501     borders[BorderType_Left].width = m_style->leftBorderPen().width();
0502     borders[BorderType_Left].color = m_style->leftBorderPen().color();
0503 
0504     borders[BorderType_Top].style  = m_style->topBorderPen().style();
0505     borders[BorderType_Top].width  = m_style->topBorderPen().width();
0506     borders[BorderType_Top].color  = m_style->topBorderPen().color();
0507 
0508     borders[BorderType_Right].style = m_style->rightBorderPen().style();
0509     borders[BorderType_Right].width = m_style->rightBorderPen().width();
0510     borders[BorderType_Right].color = m_style->rightBorderPen().color();
0511 
0512     borders[BorderType_Bottom].style = m_style->bottomBorderPen().style();
0513     borders[BorderType_Bottom].width = m_style->bottomBorderPen().width();
0514     borders[BorderType_Bottom].color = m_style->bottomBorderPen().color();
0515 
0516     borders[BorderType_FallingDiagonal].style = m_style->fallDiagonalPen().style();
0517     borders[BorderType_FallingDiagonal].width = m_style->fallDiagonalPen().width();
0518     borders[BorderType_FallingDiagonal].color = m_style->fallDiagonalPen().color();
0519 
0520     borders[BorderType_RisingDiagonal].style  = m_style->goUpDiagonalPen().style();
0521     borders[BorderType_RisingDiagonal].width  = m_style->goUpDiagonalPen().width();
0522     borders[BorderType_RisingDiagonal].color  = m_style->goUpDiagonalPen().color();
0523 
0524     borders[BorderType_Vertical].style = m_style->leftBorderPen().style();
0525     borders[BorderType_Vertical].width = m_style->leftBorderPen().width();
0526     borders[BorderType_Vertical].color = m_style->leftBorderPen().color();
0527     borders[BorderType_Horizontal].style = m_style->topBorderPen().style();
0528     borders[BorderType_Horizontal].width = m_style->topBorderPen().width();
0529     borders[BorderType_Horizontal].color = m_style->topBorderPen().color();
0530 
0531     prefix         = m_style->prefix();
0532     postfix        = m_style->postfix();
0533     precision      = m_style->precision();
0534     floatFormat    = m_style->floatFormat();
0535     floatColor     = m_style->floatColor();
0536     alignX         = m_style->halign();
0537     alignY         = m_style->valign();
0538     textColor      = m_style->fontColor();
0539     bgColor        = m_style->backgroundColor();
0540     fontSize       = m_style->fontSize();
0541     fontFamily     = m_style->fontFamily();
0542 
0543     fontBold       = m_style->bold();
0544     fontItalic     = m_style->italic();
0545     strike         = m_style->strikeOut();
0546     underline      = m_style->underline();
0547 
0548     // Needed to initialize the font correctly ( bug in Qt )
0549     font           = m_style->font();
0550     m_currency     = m_style->currency();
0551     brushColor     = m_style->backgroundBrush().color();
0552     brushStyle     = m_style->backgroundBrush().style();
0553 
0554     bMultiRow      = m_style->wrapText();
0555     bVerticalText  = m_style->verticalText();
0556     bShrinkToFit   = m_style->shrinkToFit();
0557     textRotation   = m_style->angle();
0558     formatType     = m_style->formatType();
0559     indent         = m_style->indentation();
0560 
0561     bDontPrintText = !m_style->printText();
0562     bHideFormula   = m_style->hideFormula();
0563     bHideAll       = m_style->hideAll();
0564     bIsProtected   = !m_style->notProtected();
0565 
0566     widthSize      = defaultWidthSize;
0567     heightSize     = defaultHeightSize;
0568 }
0569 
0570 CellFormatDialog::~CellFormatDialog()
0571 {
0572     delete formatOnlyNegSignedPixmap;
0573     delete formatRedOnlyNegSignedPixmap;
0574     delete formatRedNeverSignedPixmap;
0575     delete formatAlwaysSignedPixmap;
0576     delete formatRedAlwaysSignedPixmap;
0577 }
0578 
0579 void CellFormatDialog::initMembers()
0580 {
0581     formatOnlyNegSignedPixmap    = 0;
0582     formatRedOnlyNegSignedPixmap = 0;
0583     formatRedNeverSignedPixmap   = 0;
0584     formatAlwaysSignedPixmap     = 0;
0585     formatRedAlwaysSignedPixmap  = 0;
0586 
0587     // We assume, that all other objects have the same values
0588     for (int i = 0; i < BorderType_END; ++i) {
0589         borders[i].bStyle = true;
0590         borders[i].bColor = true;
0591     }
0592     bFloatFormat    = true;
0593     bFloatColor     = true;
0594     bTextColor      = true;
0595     bBgColor        = true;
0596     bTextFontFamily = true;
0597     bTextFontSize   = true;
0598     bTextFontBold   = true;
0599     bTextFontItalic = true;
0600     bStrike         = true;
0601     bUnderline      = true;
0602     bTextRotation   = true;
0603     bFormatType     = true;
0604     bCurrency       = true;
0605     bDontPrintText  = false;
0606     bHideFormula    = false;
0607     bHideAll        = false;
0608     bIsProtected    = true;
0609 
0610     m_currency      = Currency(); // locale default
0611 
0612     Sheet* sheet = m_sheet;
0613     defaultWidthSize  = sheet ? sheet->map()->defaultColumnFormat()->width() : 0;
0614     defaultHeightSize = sheet ? sheet->map()->defaultRowFormat()->height() : 0;
0615 }
0616 
0617 bool CellFormatDialog::checkCircle(QString const & name, QString const & parent)
0618 {
0619     return m_styleManager->checkCircle(name, parent);
0620 }
0621 
0622 KLocale* CellFormatDialog::locale() const
0623 {
0624     return m_sheet->map()->calculationSettings()->locale();
0625 }
0626 
0627 void CellFormatDialog::setOkButtonEnabled(bool enabled)
0628 {
0629     buttonBox()->button(QDialogButtonBox::Ok)->setEnabled(enabled);
0630 }
0631 
0632 
0633 void CellFormatDialog::checkBorderRight(const Style& style)
0634 {
0635     if (borders[BorderType_Right].style != style.rightBorderPen().style() ||
0636             borders[BorderType_Right].width != style.rightBorderPen().width())
0637         borders[BorderType_Right].bStyle = false;
0638     if (borders[BorderType_Right].color != style.rightBorderPen().color())
0639         borders[BorderType_Right].bColor = false;
0640 }
0641 
0642 void CellFormatDialog::checkBorderLeft(const Style& style)
0643 {
0644     if (borders[BorderType_Left].style != style.leftBorderPen().style() ||
0645             borders[BorderType_Left].width != style.leftBorderPen().width())
0646         borders[BorderType_Left].bStyle = false;
0647     if (borders[BorderType_Left].color != style.leftBorderPen().color())
0648         borders[BorderType_Left].bColor = false;
0649 }
0650 
0651 void CellFormatDialog::checkBorderTop(const Style& style)
0652 {
0653     if (borders[BorderType_Top].style != style.topBorderPen().style() ||
0654             borders[BorderType_Top].width != style.topBorderPen().width())
0655         borders[BorderType_Top].bStyle = false;
0656     if (borders[BorderType_Top].color != style.topBorderPen().color())
0657         borders[BorderType_Top].bColor = false;
0658 }
0659 
0660 void CellFormatDialog::checkBorderBottom(const Style& style)
0661 {
0662     if (borders[BorderType_Bottom].style != style.bottomBorderPen().style() ||
0663             borders[BorderType_Bottom].width != style.bottomBorderPen().width())
0664         borders[BorderType_Bottom].bStyle = false;
0665     if (borders[BorderType_Bottom].color != style.bottomBorderPen().color())
0666         borders[BorderType_Bottom].bColor = false;
0667 }
0668 
0669 void CellFormatDialog::checkBorderVertical(const Style& style)
0670 {
0671     if (borders[BorderType_Vertical].style != style.leftBorderPen().style() ||
0672             borders[BorderType_Vertical].width != style.leftBorderPen().width())
0673         borders[BorderType_Vertical].bStyle = false;
0674     if (borders[BorderType_Vertical].color != style.leftBorderPen().color())
0675         borders[BorderType_Vertical].bColor = false;
0676 }
0677 
0678 void CellFormatDialog::checkBorderHorizontal(const Style& style)
0679 {
0680     if (borders[BorderType_Horizontal].style != style.topBorderPen().style() ||
0681             borders[BorderType_Horizontal].width != style.topBorderPen().width())
0682         borders[BorderType_Horizontal].bStyle = false;
0683     if (borders[BorderType_Horizontal].color != style.topBorderPen().color())
0684         borders[BorderType_Horizontal].bColor = false;
0685 }
0686 
0687 
0688 void CellFormatDialog::initParameters(const Style& style)
0689 {
0690     if (borders[BorderType_FallingDiagonal].style != style.fallDiagonalPen().style())
0691         borders[BorderType_FallingDiagonal].bStyle = false;
0692     if (borders[BorderType_FallingDiagonal].width != style.fallDiagonalPen().width())
0693         borders[BorderType_FallingDiagonal].bStyle = false;
0694     if (borders[BorderType_FallingDiagonal].color != style.fallDiagonalPen().color())
0695         borders[BorderType_FallingDiagonal].bColor = false;
0696 
0697     if (borders[BorderType_RisingDiagonal].style != style.goUpDiagonalPen().style())
0698         borders[BorderType_RisingDiagonal].bStyle = false;
0699     if (borders[BorderType_RisingDiagonal].width != style.goUpDiagonalPen().width())
0700         borders[BorderType_RisingDiagonal].bStyle = false;
0701     if (borders[BorderType_RisingDiagonal].color != style.goUpDiagonalPen().color())
0702         borders[BorderType_RisingDiagonal].bColor = false;
0703     if (strike != style.strikeOut())
0704         bStrike = false;
0705     if (underline != style.underline())
0706         bUnderline = false;
0707     if (prefix != style.prefix())
0708         prefix.clear();
0709     if (postfix != style.postfix())
0710         postfix.clear();
0711     if (floatFormat != style.floatFormat())
0712         bFloatFormat = false;
0713     if (floatColor != style.floatColor())
0714         bFloatColor = false;
0715     if (textColor != style.fontColor())
0716         bTextColor = false;
0717     if (fontFamily != style.fontFamily())
0718         bTextFontFamily = false;
0719     if (fontSize != style.fontSize())
0720         bTextFontSize = false;
0721     if (fontBold != style.bold())
0722         bTextFontBold = false;
0723     if (fontItalic != style.italic())
0724         bTextFontItalic = false;
0725     if (bgColor != style.backgroundColor())
0726         bBgColor = false;
0727     if (textRotation != style.angle())
0728         bTextRotation = false;
0729     if (formatType != style.formatType())
0730         bFormatType = false;
0731     if (bMultiRow != style.wrapText())
0732         bMultiRow = false;
0733     if (bVerticalText != style.verticalText())
0734         bVerticalText = false;
0735     if (bShrinkToFit != style.shrinkToFit())
0736         bShrinkToFit = false;
0737     if (!bDontPrintText != style.printText())
0738         bDontPrintText = false;
0739 
0740     Currency currency = style.currency();
0741     if (currency != m_currency)
0742         bCurrency = false;
0743 }
0744 
0745 void CellFormatDialog::init()
0746 {
0747     // Did we initialize the bitmaps ?
0748     if (formatOnlyNegSignedPixmap == 0) {
0749         formatOnlyNegSignedPixmap    = paintFormatPixmap("123.456", Qt::black, "-123.456", Qt::black);
0750         formatRedOnlyNegSignedPixmap = paintFormatPixmap("123.456", Qt::black, "-123.456", Qt::red);
0751         formatRedNeverSignedPixmap   = paintFormatPixmap("123.456", Qt::black, "123.456", Qt::red);
0752         formatAlwaysSignedPixmap     = paintFormatPixmap("+123.456", Qt::black, "-123.456", Qt::black);
0753         formatRedAlwaysSignedPixmap  = paintFormatPixmap("+123.456", Qt::black, "-123.456", Qt::red);
0754     }
0755 
0756     setWindowTitle(i18n("Cell Format"));
0757     setFaceType(KPageDialog::Tabbed);
0758     setMinimumWidth(600);
0759     setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
0760 
0761     if (m_style) {
0762         generalPage = new GeneralTab(this, this);
0763 
0764         KPageWidgetItem* generalitem = addPage(generalPage, i18n("&General"));
0765         //generalitem->setHeader( i18n( "&General" ) );
0766         Q_UNUSED(generalitem);
0767     }
0768 
0769     floatPage = new CellFormatPageFloat(this, this);
0770     addPage(floatPage, i18n("&Data Format"));
0771 
0772     fontPage = new CellFormatPageFont(this, this);
0773     addPage(fontPage, i18n("&Font"));
0774 
0775     //  miscPage = new CellFormatPageMisc( tab, this );
0776     //  tab->addTab( miscPage, i18n("&Misc") );
0777 
0778     positionPage = new CellFormatPagePosition(this, this);
0779     addPage(positionPage, i18n("&Position"));
0780 
0781     borderPage = new CellFormatPageBorder(this, this);
0782     addPage(borderPage, i18n("&Border"));
0783 
0784     patternPage = new CellFormatPagePattern(this, this);
0785     addPage(patternPage, i18n("Back&ground"));
0786 
0787     protectPage = new CellFormatPageProtection(this, this);
0788     addPage(protectPage, i18n("&Cell Protection"));
0789 
0790     connect(this, SIGNAL(accepted()), this, SLOT(slotApply()));
0791 }
0792 
0793 QPixmap * CellFormatDialog::paintFormatPixmap(const char * _string1, const QColor & _color1,
0794         const char *_string2, const QColor & _color2)
0795 {
0796     QPixmap * pixmap = new QPixmap(150, 14);
0797     pixmap->fill(Qt::transparent);
0798 
0799     QPainter painter;
0800     painter.begin(pixmap);
0801     painter.setPen(_color1);
0802     painter.drawText(2, 11, _string1);
0803     painter.setPen(_color2);
0804     painter.drawText(75, 11, _string2);
0805     painter.end();
0806 
0807     return pixmap;
0808 }
0809 
0810 void CellFormatDialog::applyStyle()
0811 {
0812     generalPage->apply(m_style);
0813 
0814     borderPage->apply(0);
0815     floatPage->apply(m_style);
0816     // miscPage->apply( m_style );
0817     fontPage->apply(m_style);
0818     positionPage->apply(m_style);
0819     patternPage->apply(m_style);
0820     protectPage->apply(m_style);
0821 }
0822 
0823 void CellFormatDialog::slotApply()
0824 {
0825     if (m_style) {
0826         applyStyle();
0827         return;
0828     }
0829 
0830     // (Tomas) TODO: this will be slow !!!
0831     // We need to create a command that would act as macro,
0832     // but which would also ensure that updates are not painted until everything
0833     // is updated properly ...
0834     KUndo2Command* macroCommand = new KUndo2Command(kundo2_i18n("Change Format"));
0835 
0836     if (isMerged != positionPage->getMergedCellState()) {
0837         MergeCommand* command = new MergeCommand(macroCommand);
0838         command->setSheet(m_sheet);
0839         command->setSelection(m_selection);
0840         if (!positionPage->getMergedCellState())
0841             //dissociate cells
0842             command->setReverse(true);
0843         command->add(*m_selection);
0844     }
0845 
0846     StyleCommand* command = new StyleCommand(macroCommand);
0847     command->setSheet(m_sheet);
0848     command->add(*m_selection);
0849     borderPage->apply(command);
0850     floatPage->apply(command);
0851     fontPage->apply(command);
0852     positionPage->apply(command);
0853     patternPage->apply(command);
0854     protectPage->apply(command);
0855 
0856     if (int(positionPage->getSizeHeight()) != int(heightSize)) {
0857         ResizeRowManipulator* command = new ResizeRowManipulator(macroCommand);
0858         command->setSheet(m_sheet);
0859         command->setSize(positionPage->getSizeHeight());
0860         command->add(*m_selection);
0861     }
0862     if (int(positionPage->getSizeWidth()) != int(widthSize)) {
0863         ResizeColumnManipulator* command = new ResizeColumnManipulator(macroCommand);
0864         command->setSheet(m_sheet);
0865         command->setSize(positionPage->getSizeWidth());
0866         command->add(*m_selection);
0867     }
0868 
0869     m_selection->canvas()->addCommand(macroCommand);
0870 }
0871 
0872 
0873 
0874 /***************************************************************************
0875  *
0876  * CellFormatPageFloat
0877  *
0878  ***************************************************************************/
0879 
0880 CellFormatPageFloat::CellFormatPageFloat(QWidget* parent, CellFormatDialog *_dlg)
0881         : QWidget(parent),
0882         dlg(_dlg)
0883 {
0884     QVBoxLayout* layout = new QVBoxLayout(this);
0885 
0886     QGroupBox *grp = new QGroupBox(i18n("Format"), this);
0887     QGridLayout *grid = new QGridLayout(grp);
0888 
0889     int fHeight = grp->fontMetrics().height();
0890     grid->addItem(new QSpacerItem(0, fHeight / 2), 0, 0);  // groupbox title
0891 
0892     generic = new QRadioButton(i18n("Generic"), grp);
0893     generic->setWhatsThis(i18n("This is the default format and Calligra Sheets autodetects the actual data type depending on the current cell data. By default, Calligra Sheets right justifies numbers, dates and times within a cell and left justifies anything else."));
0894     grid->addWidget(generic, 1, 0);
0895 
0896     number = new QRadioButton(i18n("Number"), grp);
0897     number->setWhatsThis(i18n("The number notation uses the notation you globally choose in System Settings -> Common Appearance and Behavior -> Locale -> Country/Region & Language -> Numbers tab. Numbers are right justified by default."));
0898     grid->addWidget(number, 2, 0);
0899 
0900     percent = new QRadioButton(i18n("Percent"), grp);
0901     percent->setWhatsThis(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."));
0902     grid->addWidget(percent, 3, 0);
0903 
0904     money = new QRadioButton(i18n("Money"), grp);
0905     money->setWhatsThis(i18n("The Money format converts your number into money notation using the settings globally fixed in System Settings -> Common Appearance and Behavior -> Locale -> Country/Region & Language -> Money. The currency symbol will be displayed and the precision will be the one set in System Settings.\nYou can also use the Currency icon in the Format Toolbar to set the cell formatting to look like your current currency."));
0906     grid->addWidget(money, 4, 0);
0907 
0908     scientific = new QRadioButton(i18n("Scientific"), grp);
0909     scientific->setWhatsThis(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."));
0910     grid->addWidget(scientific, 5, 0);
0911 
0912     fraction = new QRadioButton(i18n("Fraction"), grp);
0913     fraction->setWhatsThis(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."));
0914     grid->addWidget(fraction, 6, 0);
0915 
0916     date = new QRadioButton(i18n("Date"), grp);
0917     date->setWhatsThis(i18n("To enter a date, you should enter it in one of the formats set in System Settings -> Common Appearance and Behavior -> Locale -> Country/Region & Language -> 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."));
0918     grid->addWidget(date, 7, 0);
0919 
0920     time = new QRadioButton(i18n("Time"), grp);
0921     time->setWhatsThis(i18n("This formats your cell content as a time. To enter a time, you should enter it in the Time format set in System Settings -> Common Appearance and Behavior -> Locale -> Country/Region & Language -> Date & Time. 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 System Settings. When the number in the cell does not make sense as a time, Calligra Sheets will display 00:00 in the global format you have in System Settings."));
0922     grid->addWidget(time, 8, 0);
0923 
0924     datetime = new QRadioButton(i18n("Date and Time"), grp);
0925     datetime->setWhatsThis(i18n("This formats your cell content as date and time. To enter a date and a time, you should enter it in the Time format set in System Settings -> Common Appearance and Behavior -> Locale -> Country/Region & Language -> Time & Dates. In the Cell Format dialog box you can set how the time should be displayed by choosing one of the available date format options. The default format is the system format set in System Settings. When the number in the cell does not make sense as a date and time, Calligra Sheets will display 00:00 in the global format you have in System Settings."));
0926     grid->addWidget(datetime, 9, 0);
0927 
0928     textFormat = new QRadioButton(i18n("Text"), grp);
0929     textFormat->setWhatsThis(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."));
0930     grid->addWidget(textFormat, 10, 0);
0931 
0932     customFormat = new QRadioButton(i18n("Custom"), grp);
0933     customFormat->setWhatsThis(i18n("The custom format does not work yet. To be enabled in the next release."));
0934     grid->addWidget(customFormat, 11, 0);
0935     customFormat->setEnabled(false);
0936 
0937     QGroupBox *box2 = new QGroupBox(grp);
0938     box2->setTitle(i18n("Preview"));
0939     QGridLayout *grid3 = new QGridLayout(box2);
0940 
0941     exampleLabel = new QLabel(box2);
0942     exampleLabel->setWhatsThis(i18n("This will display a preview of your choice so you can know what it does before clicking the OK button to validate it."));
0943     grid3->addWidget(exampleLabel, 0, 1);
0944 
0945     grid->addWidget(box2, 9, 1, 3, 1);
0946 
0947     customFormatEdit = new KLineEdit(grp);
0948     grid->addWidget(customFormatEdit, 0, 1);
0949     customFormatEdit->setHidden(true);
0950 
0951     listFormat = new QListWidget(grp);
0952     grid->addWidget(listFormat, 1, 1, 8, 1);
0953     listFormat->setWhatsThis(i18n("Displays choices of format for the fraction, date or time formats."));
0954     layout->addWidget(grp);
0955 
0956     /* *** */
0957 
0958     QGroupBox *box = new QGroupBox(this);
0959 
0960     grid = new QGridLayout(box);
0961 
0962     postfix = new KLineEdit(box);
0963     postfix->setWhatsThis(i18n("You can add here a Postfix such as a $HK symbol to the end of each cell content in the checked format."));
0964     grid->addWidget(postfix, 2, 1);
0965     precision = new QSpinBox(box);
0966     precision->setValue(dlg->precision);
0967     precision->setSpecialValueText(i18n("variable"));
0968     precision->setRange(-1, 10);
0969     precision->setSingleStep(1);
0970     precision->setWhatsThis(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. "));
0971     grid->addWidget(precision, 1, 1);
0972 
0973     prefix = new KLineEdit(box);
0974     prefix->setWhatsThis(i18n("You can add here a Prefix such as a $ symbol at the start of each cell content in the checked format."));
0975     grid->addWidget(prefix, 0, 1);
0976 
0977     format = new KComboBox(box);
0978     format->setWhatsThis(i18n("You can choose whether positive values are displayed with a leading + sign and whether negative values are shown in red."));
0979     grid->addWidget(format, 0, 3);
0980 
0981     QLabel* tmpQLabel;
0982     tmpQLabel = new QLabel(box);
0983     grid->addWidget(tmpQLabel, 2, 0);
0984     tmpQLabel->setText(i18n("Postfix:"));
0985 
0986     postfix->setText(dlg->postfix);
0987 
0988     tmpQLabel = new QLabel(box);
0989     grid->addWidget(tmpQLabel, 0, 0);
0990     tmpQLabel->setText(i18n("Prefix:"));
0991 
0992     tmpQLabel = new QLabel(box);
0993     grid->addWidget(tmpQLabel, 1, 0);
0994     tmpQLabel->setText(i18n("Precision:"));
0995 
0996     prefix->setText(dlg->prefix);
0997 
0998     format->setIconSize(QSize(150, 14));
0999     format->insertItem(0, *_dlg->formatOnlyNegSignedPixmap, "");
1000     format->insertItem(1, *_dlg->formatRedOnlyNegSignedPixmap, "");
1001     format->insertItem(2, *_dlg->formatRedNeverSignedPixmap, "");
1002     format->insertItem(3, *_dlg->formatAlwaysSignedPixmap, "");
1003     format->insertItem(4, *_dlg->formatRedAlwaysSignedPixmap, "");
1004 
1005     tmpQLabel = new QLabel(box);
1006     grid->addWidget(tmpQLabel, 0, 2);
1007     tmpQLabel->setText(i18n("Format:"));
1008 
1009     currencyLabel = new QLabel(box);
1010     grid->addWidget(currencyLabel, 1, 2);
1011     currencyLabel->setText(i18n("Currency:"));
1012 
1013     currency = new KComboBox(box);
1014     grid->addWidget(currency, 1, 3);
1015 
1016     // fill the currency combo box
1017     currency->insertItem(0, i18n("Automatic"));
1018     int index = 2; //ignore first two in the list
1019     bool ok = true;
1020     QString text;
1021     while (ok) {
1022         text = Currency::chooseString(index, ok);
1023         if (ok)
1024             currency->insertItem(index - 1, text);
1025         else
1026             break;
1027         ++index;
1028     }
1029     currency->setCurrentIndex(0);
1030     currency->hide();
1031     currencyLabel->hide();
1032 
1033     if (!dlg->bFloatFormat || !dlg->bFloatColor)
1034         format->setCurrentIndex(5);
1035     else if (dlg->floatFormat == Style::OnlyNegSigned && dlg->floatColor == Style::AllBlack)
1036         format->setCurrentIndex(0);
1037     else if (dlg->floatFormat == Style::OnlyNegSigned && dlg->floatColor == Style::NegRed)
1038         format->setCurrentIndex(1);
1039     else if (dlg->floatFormat == Style::AlwaysUnsigned && dlg->floatColor == Style::NegRed)
1040         format->setCurrentIndex(2);
1041     else if (dlg->floatFormat == Style::AlwaysSigned && dlg->floatColor == Style::AllBlack)
1042         format->setCurrentIndex(3);
1043     else if (dlg->floatFormat == Style::AlwaysSigned && dlg->floatColor == Style::NegRed)
1044         format->setCurrentIndex(4);
1045     layout->addWidget(box);
1046 
1047     cellFormatType = dlg->formatType;
1048     newFormatType = cellFormatType;
1049 
1050     if (!cellFormatType)
1051         generic->setChecked(true);
1052     else {
1053         if (cellFormatType == Format::Number)
1054             number->setChecked(true);
1055         else if (cellFormatType == Format::Percentage)
1056             percent->setChecked(true);
1057         else if (cellFormatType == Format::Money) {
1058             money->setChecked(true);
1059             currencyLabel->show();
1060             currency->show();
1061             if (dlg->bCurrency) {
1062                 QString tmp;
1063                 if (dlg->m_currency.index() == 1)   // custom currency unit
1064                     tmp = dlg->m_currency.symbol();
1065                 else {
1066                     bool ok = true;
1067                     tmp = Currency::chooseString(dlg->m_currency.index(), ok);
1068                     if (!ok)
1069                         tmp = dlg->m_currency.symbol();
1070                 }
1071                 currency->setCurrentIndex(currency->findText(tmp));
1072             }
1073         } else if (cellFormatType == Format::Scientific)
1074             scientific->setChecked(true);
1075         else if (Format::isDate(cellFormatType))
1076             date->setChecked(true);
1077         else if (Format::isTime(cellFormatType))
1078             time->setChecked(true);
1079         else if (Format::isFraction(cellFormatType))
1080             fraction->setChecked(true);
1081         else if (cellFormatType == Format::Text)
1082             textFormat->setChecked(true);
1083         else if (cellFormatType == Format::Custom)
1084             customFormat->setChecked(true);
1085     }
1086 
1087     connect(generic, SIGNAL(clicked()), this, SLOT(slotChangeState()));
1088     connect(fraction, SIGNAL(clicked()), this, SLOT(slotChangeState()));
1089     connect(money, SIGNAL(clicked()), this, SLOT(slotChangeState()));
1090     connect(date, SIGNAL(clicked()), this, SLOT(slotChangeState()));
1091     connect(datetime, SIGNAL(clicked()), this, SLOT(slotChangeState()));
1092     connect(scientific, SIGNAL(clicked()), this, SLOT(slotChangeState()));
1093     connect(number, SIGNAL(clicked()), this, SLOT(slotChangeState()));
1094     connect(percent, SIGNAL(clicked()), this, SLOT(slotChangeState()));
1095     connect(time, SIGNAL(clicked()), this, SLOT(slotChangeState()));
1096     connect(textFormat, SIGNAL(clicked()), this, SLOT(slotChangeState()));
1097     connect(customFormat, SIGNAL(clicked()), this, SLOT(slotChangeState()));
1098 
1099     connect(listFormat, SIGNAL(itemSelectionChanged()), this, SLOT(makeformat()));
1100     connect(precision, SIGNAL(valueChanged(int)), this, SLOT(slotChangeValue(int)));
1101     connect(prefix, SIGNAL(textChanged(QString)), this, SLOT(makeformat()));
1102     connect(postfix, SIGNAL(textChanged(QString)), this, SLOT(makeformat()));
1103     connect(currency, SIGNAL(activated(QString)), this, SLOT(currencyChanged(QString)));
1104     connect(format, SIGNAL(activated(int)), this, SLOT(formatChanged(int)));
1105     connect(format, SIGNAL(activated(int)), this, SLOT(makeformat()));
1106     slotChangeState();
1107     m_bFormatColorChanged = false;
1108     m_bFormatTypeChanged = false;
1109     this->resize(400, 400);
1110 }
1111 
1112 void CellFormatPageFloat::formatChanged(int)
1113 {
1114     m_bFormatColorChanged = true;
1115 }
1116 
1117 void CellFormatPageFloat::slotChangeValue(int)
1118 {
1119     makeformat();
1120 }
1121 void CellFormatPageFloat::slotChangeState()
1122 {
1123     QStringList list;
1124     listFormat->clear();
1125     currency->hide();
1126     currencyLabel->hide();
1127 
1128     // start with enabled, they get disabled when inappropriate further down
1129     precision->setEnabled(true);
1130     prefix->setEnabled(true);
1131     postfix->setEnabled(true);
1132     format->setEnabled(true);
1133     if (generic->isChecked() || number->isChecked() || percent->isChecked() ||
1134             scientific->isChecked() || textFormat->isChecked())
1135         listFormat->setEnabled(false);
1136     else if (money->isChecked()) {
1137         listFormat->setEnabled(false);
1138         precision->setValue(2);
1139         currency->show();
1140         currencyLabel->show();
1141     } else if (date->isChecked()) {
1142         format->setEnabled(false);
1143         precision->setEnabled(false);
1144         prefix->setEnabled(false);
1145         postfix->setEnabled(false);
1146         listFormat->setEnabled(true);
1147         init();
1148     } else if (datetime->isChecked()) {
1149         format->setEnabled(false);
1150         precision->setEnabled(false);
1151         prefix->setEnabled(false);
1152         postfix->setEnabled(false);
1153         listFormat->setEnabled(true);
1154         datetimeInit();
1155     } else if (fraction->isChecked()) {
1156         precision->setEnabled(false);
1157         listFormat->setEnabled(true);
1158         list += i18n("Halves 1/2");
1159         list += i18n("Quarters 1/4");
1160         list += i18n("Eighths 1/8");
1161         list += i18n("Sixteenths 1/16");
1162         list += i18n("Tenths 1/10");
1163         list += i18n("Hundredths 1/100");
1164         list += i18n("One digit 5/9");
1165         list += i18n("Two digits 15/22");
1166         list += i18n("Three digits 153/652");
1167         listFormat->addItems(list);
1168         if (cellFormatType == Format::fraction_half)
1169             listFormat->setCurrentRow(0);
1170         else if (cellFormatType == Format::fraction_quarter)
1171             listFormat->setCurrentRow(1);
1172         else if (cellFormatType == Format::fraction_eighth)
1173             listFormat->setCurrentRow(2);
1174         else if (cellFormatType == Format::fraction_sixteenth)
1175             listFormat->setCurrentRow(3);
1176         else if (cellFormatType == Format::fraction_tenth)
1177             listFormat->setCurrentRow(4);
1178         else if (cellFormatType == Format::fraction_hundredth)
1179             listFormat->setCurrentRow(5);
1180         else if (cellFormatType == Format::fraction_one_digit)
1181             listFormat->setCurrentRow(6);
1182         else if (cellFormatType == Format::fraction_two_digits)
1183             listFormat->setCurrentRow(7);
1184         else if (cellFormatType == Format::fraction_three_digits)
1185             listFormat->setCurrentRow(8);
1186         else
1187             listFormat->setCurrentRow(0);
1188     } else if (time->isChecked()) {
1189         precision->setEnabled(false);
1190         prefix->setEnabled(false);
1191         postfix->setEnabled(false);
1192         format->setEnabled(false);
1193         listFormat->setEnabled(true);
1194 
1195 
1196         list += i18n("System: ") + dlg->locale()->formatTime(QTime::currentTime(), false);
1197         list += i18n("System: ") + dlg->locale()->formatTime(QTime::currentTime(), true);
1198         QDateTime tmpTime(QDate(1, 1, 1900), QTime(10, 35, 25), Qt::UTC);
1199 
1200 
1201         ValueFormatter *fmt = dlg->getSheet()->map()->formatter();
1202         list += fmt->timeFormat(tmpTime, Format::Time1);
1203         list += fmt->timeFormat(tmpTime, Format::Time2);
1204         list += fmt->timeFormat(tmpTime, Format::Time3);
1205         list += fmt->timeFormat(tmpTime, Format::Time4);
1206         list += fmt->timeFormat(tmpTime, Format::Time5);
1207         list += (fmt->timeFormat(tmpTime, Format::Time6) + i18n(" (=[mm]:ss)"));
1208         list += (fmt->timeFormat(tmpTime, Format::Time7) + i18n(" (=[hh]:mm:ss)"));
1209         list += (fmt->timeFormat(tmpTime, Format::Time8) + i18n(" (=[hh]:mm)"));
1210         listFormat->addItems(list);
1211 
1212         if (cellFormatType == Format::Time)
1213             listFormat->setCurrentRow(0);
1214         else if (cellFormatType == Format::SecondeTime)
1215             listFormat->setCurrentRow(1);
1216         else if (cellFormatType == Format::Time1)
1217             listFormat->setCurrentRow(2);
1218         else if (cellFormatType == Format::Time2)
1219             listFormat->setCurrentRow(3);
1220         else if (cellFormatType == Format::Time3)
1221             listFormat->setCurrentRow(4);
1222         else if (cellFormatType == Format::Time4)
1223             listFormat->setCurrentRow(5);
1224         else if (cellFormatType == Format::Time5)
1225             listFormat->setCurrentRow(6);
1226         else if (cellFormatType == Format::Time6)
1227             listFormat->setCurrentRow(7);
1228         else if (cellFormatType == Format::Time7)
1229             listFormat->setCurrentRow(8);
1230         else if (cellFormatType == Format::Time8)
1231             listFormat->setCurrentRow(9);
1232         else
1233             listFormat->setCurrentRow(0);
1234     }
1235 
1236     if (customFormat->isChecked()) {
1237         customFormatEdit->setHidden(false);
1238         precision->setEnabled(false);
1239         prefix->setEnabled(false);
1240         postfix->setEnabled(false);
1241         format->setEnabled(false);
1242         listFormat->setEnabled(true);
1243     } else
1244         customFormatEdit->setHidden(true);
1245 
1246     m_bFormatTypeChanged = true;
1247 
1248     makeformat();
1249 }
1250 
1251 void CellFormatPageFloat::init()
1252 {
1253     QStringList list;
1254     QString tmp;
1255     QString tmp2;
1256     QDate tmpDate(2000, 2, 18);
1257     list += i18n("System: ") + dlg->locale()->formatDate(QDate::currentDate(), KLocale::ShortDate);
1258     list += i18n("System: ") + dlg->locale()->formatDate(QDate::currentDate(), KLocale::LongDate);
1259 
1260     ValueFormatter *fmt = dlg->getSheet()->map()->formatter();
1261 
1262     /*18-Feb-00*/
1263     list += fmt->dateFormat(tmpDate, Format::Date1);
1264     /*18-Feb-1999*/
1265     list += fmt->dateFormat(tmpDate, Format::Date2);
1266     /*18-Feb*/
1267     list += fmt->dateFormat(tmpDate, Format::Date3);
1268     /*18-2*/
1269     list += fmt->dateFormat(tmpDate, Format::Date4);
1270     /*18/2/00*/
1271     list += fmt->dateFormat(tmpDate, Format::Date5);
1272     /*18/5/1999*/
1273     list += fmt->dateFormat(tmpDate, Format::Date6);
1274     /*Feb-99*/
1275     list += fmt->dateFormat(tmpDate, Format::Date7);
1276     /*February-99*/
1277     list += fmt->dateFormat(tmpDate, Format::Date8);
1278     /*February-1999*/
1279     list += fmt->dateFormat(tmpDate, Format::Date9);
1280     /*F-99*/
1281     list += fmt->dateFormat(tmpDate, Format::Date10);
1282     /*18/Feb*/
1283     list += fmt->dateFormat(tmpDate, Format::Date11);
1284     /*18/2*/
1285     list += fmt->dateFormat(tmpDate, Format::Date12);
1286     /*18/Feb/1999*/
1287     list += fmt->dateFormat(tmpDate, Format::Date13);
1288     /*2000/Feb/18*/
1289     list += fmt->dateFormat(tmpDate, Format::Date14);
1290     /*2000-Feb-18*/
1291     list += fmt->dateFormat(tmpDate, Format::Date15);
1292     /*2000-2-18*/
1293     list += fmt->dateFormat(tmpDate, Format::Date16);
1294     /*2 february 2000*/
1295     list += fmt->dateFormat(tmpDate, Format::Date17);
1296     list += fmt->dateFormat(tmpDate, Format::Date18);
1297     list += fmt->dateFormat(tmpDate, Format::Date19);
1298     list += fmt->dateFormat(tmpDate, Format::Date20);
1299     list += fmt->dateFormat(tmpDate, Format::Date21);
1300     list += fmt->dateFormat(tmpDate, Format::Date22);
1301     list += fmt->dateFormat(tmpDate, Format::Date23);
1302     list += fmt->dateFormat(tmpDate, Format::Date24);
1303     list += fmt->dateFormat(tmpDate, Format::Date25);
1304     list += fmt->dateFormat(tmpDate, Format::Date26);
1305     list += fmt->dateFormat(tmpDate, Format::Date27);
1306     list += fmt->dateFormat(tmpDate, Format::Date28);
1307     list += fmt->dateFormat(tmpDate, Format::Date29);
1308     list += fmt->dateFormat(tmpDate, Format::Date30);
1309     list += fmt->dateFormat(tmpDate, Format::Date31);
1310     list += fmt->dateFormat(tmpDate, Format::Date32);
1311     list += fmt->dateFormat(tmpDate, Format::Date33);
1312     list += fmt->dateFormat(tmpDate, Format::Date34);
1313     list += fmt->dateFormat(tmpDate, Format::Date35);
1314 
1315     listFormat->addItems(list);
1316     if (cellFormatType == Format::ShortDate)
1317         listFormat->setCurrentRow(0);
1318     else if (cellFormatType == Format::TextDate)
1319         listFormat->setCurrentRow(1);
1320     else if (cellFormatType == Format::Date1)
1321         listFormat->setCurrentRow(2);
1322     else if (cellFormatType == Format::Date2)
1323         listFormat->setCurrentRow(3);
1324     else if (cellFormatType == Format::Date3)
1325         listFormat->setCurrentRow(4);
1326     else if (cellFormatType == Format::Date4)
1327         listFormat->setCurrentRow(5);
1328     else if (cellFormatType == Format::Date5)
1329         listFormat->setCurrentRow(6);
1330     else if (cellFormatType == Format::Date6)
1331         listFormat->setCurrentRow(7);
1332     else if (cellFormatType == Format::Date7)
1333         listFormat->setCurrentRow(8);
1334     else if (cellFormatType == Format::Date8)
1335         listFormat->setCurrentRow(9);
1336     else if (cellFormatType == Format::Date9)
1337         listFormat->setCurrentRow(10);
1338     else if (cellFormatType == Format::Date10)
1339         listFormat->setCurrentRow(11);
1340     else if (cellFormatType == Format::Date11)
1341         listFormat->setCurrentRow(12);
1342     else if (cellFormatType == Format::Date12)
1343         listFormat->setCurrentRow(13);
1344     else if (cellFormatType == Format::Date13)
1345         listFormat->setCurrentRow(14);
1346     else if (cellFormatType == Format::Date14)
1347         listFormat->setCurrentRow(15);
1348     else if (cellFormatType == Format::Date15)
1349         listFormat->setCurrentRow(16);
1350     else if (cellFormatType == Format::Date16)
1351         listFormat->setCurrentRow(17);
1352     else if (cellFormatType == Format::Date17)
1353         listFormat->setCurrentRow(18);
1354     else if (cellFormatType == Format::Date18)
1355         listFormat->setCurrentRow(19);
1356     else if (cellFormatType == Format::Date19)
1357         listFormat->setCurrentRow(20);
1358     else if (cellFormatType == Format::Date20)
1359         listFormat->setCurrentRow(21);
1360     else if (cellFormatType == Format::Date21)
1361         listFormat->setCurrentRow(22);
1362     else if (cellFormatType == Format::Date22)
1363         listFormat->setCurrentRow(23);
1364     else if (cellFormatType == Format::Date23)
1365         listFormat->setCurrentRow(24);
1366     else if (cellFormatType == Format::Date24)
1367         listFormat->setCurrentRow(25);
1368     else if (cellFormatType == Format::Date25)
1369         listFormat->setCurrentRow(26);
1370     else if (cellFormatType == Format::Date26)
1371         listFormat->setCurrentRow(27);
1372     else if (cellFormatType == Format::Date27)
1373         listFormat->setCurrentRow(28);
1374     else if (cellFormatType == Format::Date28)
1375         listFormat->setCurrentRow(29);
1376     else if (cellFormatType == Format::Date29)
1377         listFormat->setCurrentRow(30);
1378     else if (cellFormatType == Format::Date30)
1379         listFormat->setCurrentRow(31);
1380     else if (cellFormatType == Format::Date31)
1381         listFormat->setCurrentRow(32);
1382     else if (cellFormatType == Format::Date32)
1383         listFormat->setCurrentRow(33);
1384     else if (cellFormatType == Format::Date33)
1385         listFormat->setCurrentRow(34);
1386     else if (cellFormatType == Format::Date34)
1387         listFormat->setCurrentRow(35);
1388     else if (cellFormatType == Format::Date35)
1389         listFormat->setCurrentRow(36);
1390     else
1391         listFormat->setCurrentRow(0);
1392 }
1393 
1394 void CellFormatPageFloat::datetimeInit()
1395 {
1396     QStringList list;
1397     list += i18n("System: ") + dlg->locale()->formatDateTime(QDateTime::currentDateTime(), KLocale::ShortDate);
1398     list += i18n("System: ") + dlg->locale()->formatDateTime(QDateTime::currentDateTime(), KLocale::LongDate);
1399     listFormat->addItems(list);
1400 }
1401 
1402 void CellFormatPageFloat::currencyChanged(const QString &)
1403 {
1404     int index = currency->currentIndex();
1405     if (index > 0)
1406         ++index;
1407     dlg->m_currency = Currency(index);
1408 
1409     makeformat();
1410 }
1411 
1412 void CellFormatPageFloat::updateFormatType()
1413 {
1414     if (generic->isChecked())
1415         newFormatType = Format::Generic;
1416     else if (number->isChecked())
1417         newFormatType = Format::Number;
1418     else if (percent->isChecked())
1419         newFormatType = Format::Percentage;
1420     else if (date->isChecked()) {
1421         newFormatType = Format::ShortDate;
1422         switch (listFormat->currentRow()) {
1423         case 0: newFormatType = Format::ShortDate; break;
1424         case 1: newFormatType = Format::TextDate; break;
1425         case 2: newFormatType = Format::Date1; break; /*18-Feb-99*/
1426         case 3: newFormatType = Format::Date2; break; /*18-Feb-1999*/
1427         case 4: newFormatType = Format::Date3; break; /*18-Feb*/
1428         case 5: newFormatType = Format::Date4; break; /*18-05*/
1429         case 6: newFormatType = Format::Date5; break; /*18/05/00*/
1430         case 7: newFormatType = Format::Date6; break; /*18/05/1999*/
1431         case 8: newFormatType = Format::Date7; break;/*Feb-99*/
1432         case 9: newFormatType = Format::Date8; break; /*February-99*/
1433         case 10: newFormatType = Format::Date9; break; /*February-1999*/
1434         case 11: newFormatType = Format::Date10; break; /*F-99*/
1435         case 12: newFormatType = Format::Date11; break; /*18/Feb*/
1436         case 13: newFormatType = Format::Date12; break; /*18/02*/
1437         case 14: newFormatType = Format::Date13; break; /*18/Feb/1999*/
1438         case 15: newFormatType = Format::Date14; break; /*2000/Feb/18*/
1439         case 16: newFormatType = Format::Date15; break;/*2000-Feb-18*/
1440         case 17: newFormatType = Format::Date16; break;/*2000-02-18*/
1441         case 18: newFormatType = Format::Date17; break; /*2000-02-18*/
1442         case 19: newFormatType = Format::Date18; break;
1443         case 20: newFormatType = Format::Date19; break;
1444         case 21: newFormatType = Format::Date20; break;
1445         case 22: newFormatType = Format::Date21; break;
1446         case 23: newFormatType = Format::Date22; break;
1447         case 24: newFormatType = Format::Date23; break;
1448         case 25: newFormatType = Format::Date24; break;
1449         case 26: newFormatType = Format::Date25; break;
1450         case 27: newFormatType = Format::Date26; break;
1451         case 28: newFormatType = Format::Date27; break;
1452         case 29: newFormatType = Format::Date28; break;
1453         case 30: newFormatType = Format::Date29; break;
1454         case 31: newFormatType = Format::Date30; break;
1455         case 32: newFormatType = Format::Date31; break;
1456         case 33: newFormatType = Format::Date32; break;
1457         case 34: newFormatType = Format::Date33; break;
1458         case 35: newFormatType = Format::Date34; break;
1459         case 36: newFormatType = Format::Date35; break;
1460         }
1461     } else if (money->isChecked())
1462         newFormatType = Format::Money;
1463     else if (scientific->isChecked())
1464         newFormatType = Format::Scientific;
1465     else if (fraction->isChecked()) {
1466         newFormatType = Format::fraction_half;
1467         switch (listFormat->currentRow()) {
1468         case 0: newFormatType = Format::fraction_half; break;
1469         case 1: newFormatType = Format::fraction_quarter; break;
1470         case 2: newFormatType = Format::fraction_eighth; break;
1471         case 3: newFormatType = Format::fraction_sixteenth; break;
1472         case 4: newFormatType = Format::fraction_tenth; break;
1473         case 5: newFormatType = Format::fraction_hundredth; break;
1474         case 6: newFormatType = Format::fraction_one_digit; break;
1475         case 7: newFormatType = Format::fraction_two_digits; break;
1476         case 8: newFormatType = Format::fraction_three_digits; break;
1477         }
1478     } else if (time->isChecked()) {
1479         newFormatType = Format::Time;
1480         switch (listFormat->currentRow()) {
1481         case 0: newFormatType = Format::Time; break;
1482         case 1: newFormatType = Format::SecondeTime; break;
1483         case 2: newFormatType = Format::Time1; break;
1484         case 3: newFormatType = Format::Time2; break;
1485         case 4: newFormatType = Format::Time3; break;
1486         case 5: newFormatType = Format::Time4; break;
1487         case 6: newFormatType = Format::Time5; break;
1488         case 7: newFormatType = Format::Time6; break;
1489         case 8: newFormatType = Format::Time7; break;
1490         case 9: newFormatType = Format::Time8; break;
1491         }
1492     } else if (textFormat->isChecked())
1493         newFormatType = Format::Text;
1494     else if (customFormat->isChecked())
1495         newFormatType = Format::Custom;
1496 }
1497 
1498 void CellFormatPageFloat::makeformat()
1499 {
1500     m_bFormatTypeChanged = true;
1501     QString tmp;
1502 
1503     updateFormatType();
1504     QColor color;
1505     Style::FloatFormat floatFormat = Style::OnlyNegSigned;
1506     switch (format->currentIndex()) {
1507     case 0:
1508         floatFormat = Style::OnlyNegSigned;
1509         color = Qt::black;
1510         break;
1511     case 1:
1512         floatFormat =  Style::OnlyNegSigned;
1513         color = Qt::red;
1514         break;
1515     case 2:
1516         floatFormat =  Style::AlwaysUnsigned;
1517         color = Qt::red;
1518         break;
1519     case 3:
1520         floatFormat =  Style::AlwaysSigned;
1521         color = Qt::black;
1522         break;
1523     case 4:
1524         floatFormat =  Style::AlwaysSigned;
1525         color = Qt::red;
1526         break;
1527     }
1528     if (!dlg->value.isNumber() || dlg->value.asFloat() >= 0 || !format->isEnabled()) {
1529         color = Qt::black;
1530     }
1531     ValueFormatter *fmt = dlg->getSheet()->map()->formatter();
1532     tmp = fmt->formatText(dlg->value, newFormatType, precision->value(),
1533                           floatFormat,
1534                           prefix->isEnabled() ? prefix->text() : QString(),
1535                           postfix->isEnabled() ? postfix->text() : QString(),
1536                           newFormatType == Format::Money ? dlg->m_currency.symbol() : QString()).asString();
1537     if (tmp.length() > 50)
1538         tmp = tmp.left(50);
1539     exampleLabel->setText(tmp.prepend("<font color=" + color.name() + '>').append("</font>"));
1540 }
1541 
1542 void CellFormatPageFloat::apply(CustomStyle * style)
1543 {
1544     if (postfix->text() != dlg->postfix) {
1545         if (postfix->isEnabled())
1546             style->setPostfix(postfix->text());
1547         else
1548             style->setPostfix("");
1549     }
1550     if (prefix->text() != dlg->prefix) {
1551         if (prefix->isEnabled())
1552             style->setPrefix(prefix->text());
1553         else
1554             style->setPrefix("");
1555     }
1556 
1557     if (dlg->precision != precision->value())
1558         style->setPrecision(precision->value());
1559 
1560     if (m_bFormatColorChanged) {
1561         switch (format->currentIndex()) {
1562         case 0:
1563             style->setFloatFormat(Style::OnlyNegSigned);
1564             style->setFloatColor(Style::AllBlack);
1565             break;
1566         case 1:
1567             style->setFloatFormat(Style::OnlyNegSigned);
1568             style->setFloatColor(Style::NegRed);
1569             break;
1570         case 2:
1571             style->setFloatFormat(Style::AlwaysUnsigned);
1572             style->setFloatColor(Style::NegRed);
1573             break;
1574         case 3:
1575             style->setFloatFormat(Style::AlwaysSigned);
1576             style->setFloatColor(Style::AllBlack);
1577             break;
1578         case 4:
1579             style->setFloatFormat(Style::AlwaysSigned);
1580             style->setFloatColor(Style::NegRed);
1581             break;
1582         }
1583     }
1584     if (m_bFormatTypeChanged) {
1585         style->setFormatType(newFormatType);
1586         if (money->isChecked()) {
1587             Currency currency;
1588             int index = this->currency->currentIndex();
1589             if (index == 0) {
1590                 if (this->currency->currentText() == i18n("Automatic"))
1591                     currency = Currency();
1592                 else
1593                     currency = Currency(this->currency->currentText());
1594             } else {
1595                 currency = Currency(++index);
1596             }
1597             style->setCurrency(currency);
1598         }
1599     }
1600 }
1601 
1602 void CellFormatPageFloat::apply(StyleCommand* _obj)
1603 {
1604     if (postfix->text() != dlg->postfix)
1605         if (postfix->isEnabled()) {
1606             // If we are in here it *never* can be disabled - FIXME (Werner)!
1607             if (postfix->isEnabled())
1608                 _obj->setPostfix(postfix->text());
1609             else
1610                 _obj->setPostfix("");
1611         }
1612     if (prefix->text() != dlg->prefix) {
1613         if (prefix->isEnabled())
1614             _obj->setPrefix(prefix->text());
1615         else
1616             _obj->setPrefix("");
1617     }
1618 
1619     if (dlg->precision != precision->value())
1620         _obj->setPrecision(precision->value());
1621 
1622     if (m_bFormatColorChanged) {
1623         switch (format->currentIndex()) {
1624         case 0:
1625             _obj->setFloatFormat(Style::OnlyNegSigned);
1626             _obj->setFloatColor(Style::AllBlack);
1627             break;
1628         case 1:
1629             _obj->setFloatFormat(Style::OnlyNegSigned);
1630             _obj->setFloatColor(Style::NegRed);
1631             break;
1632         case 2:
1633             _obj->setFloatFormat(Style::AlwaysUnsigned);
1634             _obj->setFloatColor(Style::NegRed);
1635             break;
1636         case 3:
1637             _obj->setFloatFormat(Style::AlwaysSigned);
1638             _obj->setFloatColor(Style::AllBlack);
1639             break;
1640         case 4:
1641             _obj->setFloatFormat(Style::AlwaysSigned);
1642             _obj->setFloatColor(Style::NegRed);
1643             break;
1644         }
1645     }
1646     if (m_bFormatTypeChanged) {
1647         _obj->setFormatType(newFormatType);
1648         if (money->isChecked()) {
1649             Currency currency;
1650             int index = this->currency->currentIndex();
1651             if (index == 0) {
1652                 if (this->currency->currentText() == i18n("Automatic"))
1653                     currency = Currency();
1654                 else
1655                     currency = Currency(this->currency->currentText());
1656             } else {
1657                 currency = Currency(++index);
1658             }
1659             _obj->setCurrency(currency);
1660         }
1661     }
1662     if (newFormatType == Format::Scientific) {
1663         // FIXME: temporary fix to at least get precision to work
1664         // TODO: Add min-exponent-digits to dialog
1665         // Custom format overrides precision, so create a proper one
1666         QString format = "0.";
1667         if (precision->value() > 0) {
1668             for (int i = 0; i < precision->value(); ++i)
1669                 format.append('0');
1670         }
1671         format.append("E+00");
1672         _obj->setCustomFormat(format);
1673     } else {
1674         // nothing else needs custom format
1675         _obj->setCustomFormat(QString());
1676     }
1677 }
1678 
1679 
1680 
1681 /***************************************************************************
1682  *
1683  * CellFormatPageProtection
1684  *
1685  ***************************************************************************/
1686 
1687 CellFormatPageProtection::CellFormatPageProtection(QWidget* parent, CellFormatDialog * _dlg)
1688         : QWidget(parent),
1689         m_dlg(_dlg)
1690 {
1691     setupUi(this);
1692     connect(m_bHideAll, SIGNAL(toggled(bool)), m_bIsProtected, SLOT(setDisabled(bool)));
1693     connect(m_bHideAll, SIGNAL(toggled(bool)), m_bHideFormula, SLOT(setDisabled(bool)));
1694 
1695     m_bDontPrint->setChecked(m_dlg->bDontPrintText);
1696     m_bHideAll->setChecked(m_dlg->bHideAll);
1697     m_bHideFormula->setChecked(m_dlg->bHideFormula);
1698     m_bIsProtected->setChecked(m_dlg->bIsProtected);
1699 }
1700 
1701 CellFormatPageProtection::~CellFormatPageProtection()
1702 {
1703 }
1704 
1705 void CellFormatPageProtection::apply(CustomStyle * style)
1706 {
1707     if (m_dlg->bDontPrintText != m_bDontPrint->isChecked()) {
1708         style->setDontPrintText(m_bDontPrint->isChecked());
1709     }
1710 
1711     if (m_dlg->bIsProtected != m_bIsProtected->isChecked()) {
1712         style->setNotProtected(!m_bIsProtected->isChecked());
1713     }
1714 
1715     if (m_dlg->bHideAll != m_bHideAll->isChecked()) {
1716         style->setHideAll(m_bHideAll->isChecked());
1717     }
1718 
1719     if (m_dlg->bHideFormula != m_bHideFormula->isChecked()) {
1720         style->setHideFormula(m_bHideFormula->isChecked());
1721     }
1722 }
1723 
1724 void CellFormatPageProtection::apply(StyleCommand* _obj)
1725 {
1726     if (m_dlg->bDontPrintText != m_bDontPrint->isChecked())
1727         _obj->setDontPrintText(m_bDontPrint->isChecked());
1728 
1729     if (m_dlg->bIsProtected != m_bIsProtected->isChecked())
1730         _obj->setNotProtected(!m_bIsProtected->isChecked());
1731 
1732     if (m_dlg->bHideAll != m_bHideAll->isChecked())
1733         _obj->setHideAll(m_bHideAll->isChecked());
1734 
1735     if (m_dlg->bHideFormula != m_bHideFormula->isChecked())
1736         _obj->setHideFormula(m_bHideFormula->isChecked());
1737 }
1738 
1739 
1740 
1741 /***************************************************************************
1742  *
1743  * CellFormatPageFont
1744  *
1745  ***************************************************************************/
1746 
1747 CellFormatPageFont::CellFormatPageFont(QWidget* parent, CellFormatDialog *_dlg)
1748         : QWidget(parent)
1749 {
1750     setupUi(this);
1751 
1752     dlg = _dlg;
1753 
1754     bTextColorUndefined = !dlg->bTextColor;
1755 
1756     connect(textColorButton, SIGNAL(changed(QColor)),
1757             this, SLOT(slotSetTextColor(QColor)));
1758 
1759 
1760     QStringList tmpListFont;
1761     QFontDatabase *fontDataBase = new QFontDatabase();
1762     tmpListFont = fontDataBase->families();
1763     delete fontDataBase;
1764 
1765     family_combo->addItems(tmpListFont);
1766     selFont = dlg->font;
1767 
1768     if (dlg->bTextFontFamily) {
1769         selFont.setFamily(dlg->fontFamily);
1770         // debugSheets <<"Family =" << dlg->fontFamily;
1771 
1772         if (family_combo->findItems(dlg->fontFamily, Qt::MatchExactly).size() == 0) {
1773             family_combo->insertItem(0, "");
1774             family_combo->setCurrentRow(0);
1775         } else
1776             family_combo->setCurrentItem(family_combo->findItems(dlg->fontFamily, Qt::MatchExactly)[0]);
1777     } else {
1778         family_combo->insertItem(0, "");
1779         family_combo->setCurrentRow(0);
1780     }
1781 
1782     connect(family_combo, SIGNAL(currentTextChanged(QString)),
1783             SLOT(family_chosen_slot(QString)));
1784 
1785     QStringList lst;
1786     lst.append("");
1787     for (unsigned int i = 1; i < 100; ++i)
1788         lst.append(QString("%1").arg(i));
1789 
1790     size_combo->insertItems(0, lst);
1791 
1792 
1793     size_combo->setInsertPolicy(KComboBox::NoInsert);
1794 
1795     connect(size_combo, SIGNAL(activated(QString)),
1796             SLOT(size_chosen_slot(QString)));
1797     connect(size_combo , SIGNAL(editTextChanged(QString)),
1798             this, SLOT(size_chosen_slot(QString)));
1799 
1800     connect(weight_combo, SIGNAL(activated(QString)),
1801             SLOT(weight_chosen_slot(QString)));
1802 
1803     connect(style_combo, SIGNAL(activated(QString)),
1804             SLOT(style_chosen_slot(QString)));
1805 
1806     strike->setChecked(dlg->strike);
1807     connect(strike, SIGNAL(clicked()),
1808             SLOT(strike_chosen_slot()));
1809 
1810     underline->setChecked(dlg->underline);
1811     connect(underline, SIGNAL(clicked()),
1812             SLOT(underline_chosen_slot()));
1813 
1814     example_label->setText(i18n("Dolor Ipse"));
1815 
1816     connect(this, SIGNAL(fontSelected(QFont)),
1817             this, SLOT(display_example(QFont)));
1818 
1819     setCombos();
1820     display_example(selFont);
1821     fontChanged = false;
1822     this->resize(400, 400);
1823 }
1824 
1825 void CellFormatPageFont::slotSetTextColor(const QColor &_color)
1826 {
1827     textColor = _color;
1828     bTextColorUndefined = false;
1829 }
1830 
1831 void CellFormatPageFont::apply(CustomStyle * style)
1832 {
1833     if (!bTextColorUndefined && textColor != dlg->textColor)
1834         style->setFontColor(textColor);
1835 
1836     if ((size_combo->currentIndex() != 0)
1837             && (dlg->fontSize != selFont.pointSize()))
1838         style->setFontSize(selFont.pointSize());
1839 
1840     if ((selFont.family() != dlg->fontFamily)
1841             && family_combo->currentItem() != 0 && !family_combo->currentItem()->text().isEmpty())
1842         style->setFontFamily(selFont.family());
1843 
1844     style->setFontBold(weight_combo->currentIndex() != 0 && selFont.bold());
1845     style->setFontItalic(style_combo->currentIndex() != 0 && selFont.italic());
1846     style->setFontStrikeOut(strike->isChecked());
1847     style->setFontUnderline(underline->isChecked());
1848 }
1849 
1850 void CellFormatPageFont::apply(StyleCommand* _obj)
1851 {
1852     if (!bTextColorUndefined && textColor != dlg->textColor)
1853         _obj->setFontColor(textColor);
1854     if (fontChanged) {
1855         if ((size_combo->currentIndex() != 0)
1856                 && (dlg->fontSize != selFont.pointSize()))
1857             _obj->setFontSize(selFont.pointSize());
1858         if ((selFont.family() != dlg->fontFamily) && (family_combo->currentItem() != 0 && !family_combo->currentItem()->text().isEmpty()))
1859             _obj->setFontFamily(selFont.family());
1860         if (weight_combo->currentIndex() != 0)
1861             _obj->setFontBold(selFont.bold());
1862         if (style_combo->currentIndex() != 0)
1863             _obj->setFontItalic(selFont.italic());
1864         _obj->setFontStrike(strike->isChecked());
1865         _obj->setFontUnderline(underline->isChecked());
1866     }
1867 }
1868 
1869 void CellFormatPageFont::underline_chosen_slot()
1870 {
1871     selFont.setUnderline(underline->isChecked());
1872     emit fontSelected(selFont);
1873 }
1874 
1875 void CellFormatPageFont::strike_chosen_slot()
1876 {
1877     selFont.setStrikeOut(strike->isChecked());
1878     emit fontSelected(selFont);
1879 }
1880 
1881 void CellFormatPageFont::family_chosen_slot(const QString & family)
1882 {
1883     selFont.setFamily(family);
1884     emit fontSelected(selFont);
1885 }
1886 
1887 void CellFormatPageFont::size_chosen_slot(const QString & size)
1888 {
1889     QString size_string = size;
1890 
1891     if (size_string.toInt() > 0) selFont.setPointSize(size_string.toInt());
1892     emit fontSelected(selFont);
1893 }
1894 
1895 void CellFormatPageFont::weight_chosen_slot(const QString & weight)
1896 {
1897     QString weight_string = weight;
1898 
1899     if (weight_string == i18n("Normal"))
1900         selFont.setBold(false);
1901     if (weight_string == i18n("Bold"))
1902         selFont.setBold(true);
1903     emit fontSelected(selFont);
1904 }
1905 
1906 void CellFormatPageFont::style_chosen_slot(const QString & style)
1907 {
1908     QString style_string = style;
1909 
1910     if (style_string == i18n("Roman"))
1911         selFont.setItalic(false);
1912     if (style_string == i18n("Italic"))
1913         selFont.setItalic(true);
1914     emit fontSelected(selFont);
1915 }
1916 
1917 
1918 void CellFormatPageFont::display_example(const QFont& font)
1919 {
1920     QString string;
1921     fontChanged = true;
1922     example_label->setFont(font);
1923     example_label->repaint();
1924 }
1925 
1926 void CellFormatPageFont::setCombos()
1927 {
1928     QString string;
1929     KComboBox* combo;
1930     int number_of_entries;
1931 
1932     if (dlg->bTextColor)
1933         textColor = dlg->textColor;
1934     else
1935         textColor = palette().text().color();
1936 
1937     if (!textColor.isValid())
1938         textColor = palette().text().color();
1939 
1940     textColorButton->setColor(textColor);
1941 
1942 
1943     combo = size_combo;
1944     if (dlg->bTextFontSize) {
1945 //      debugSheets <<"SIZE=" << dlg->fontSize;
1946         selFont.setPointSize(dlg->fontSize);
1947         number_of_entries = size_combo->count();
1948         string.setNum(dlg->fontSize);
1949 
1950         for (int i = 0; i < number_of_entries ; i++) {
1951             if (string == (QString) combo->itemText(i)) {
1952                 combo->setCurrentIndex(i);
1953                 // debugSheets <<"Found Size" << string.data() <<" setting to item" i;
1954                 break;
1955             }
1956         }
1957     } else
1958         combo->setCurrentIndex(0);
1959 
1960     if (!dlg->bTextFontBold)
1961         weight_combo->setCurrentIndex(0);
1962     else if (dlg->fontBold) {
1963         selFont.setBold(dlg->fontBold);
1964         weight_combo->setCurrentIndex(2);
1965     } else {
1966         selFont.setBold(dlg->fontBold);
1967         weight_combo->setCurrentIndex(1);
1968     }
1969 
1970     if (!dlg->bTextFontItalic)
1971         weight_combo->setCurrentIndex(0);
1972     else if (dlg->fontItalic) {
1973         selFont.setItalic(dlg->fontItalic);
1974         style_combo->setCurrentIndex(2);
1975     } else {
1976         selFont.setItalic(dlg->fontItalic);
1977         style_combo->setCurrentIndex(1);
1978     }
1979 }
1980 
1981 
1982 
1983 /***************************************************************************
1984  *
1985  * CellFormatPagePosition
1986  *
1987  ***************************************************************************/
1988 
1989 CellFormatPagePosition::CellFormatPagePosition(QWidget* parent, CellFormatDialog *_dlg)
1990         : QWidget(parent),
1991         dlg(_dlg)
1992 {
1993     setupUi(this);
1994     connect(angleRotation, SIGNAL(valueChanged(int)), spinBox3, SLOT(setValue(int)));
1995     connect(spinBox3, SIGNAL(valueChanged(int)), angleRotation, SLOT(setValue(int)));
1996 
1997     if (dlg->alignX == Style::Left)
1998         left->setChecked(true);
1999     else if (dlg->alignX == Style::Center)
2000         center->setChecked(true);
2001     else if (dlg->alignX == Style::Right)
2002         right->setChecked(true);
2003     else if (dlg->alignX == Style::HAlignUndefined)
2004         standard->setChecked(true);
2005 
2006     QButtonGroup* horizontalGroup = new QButtonGroup(this);
2007     horizontalGroup->addButton(left);
2008     horizontalGroup->addButton(center);
2009     horizontalGroup->addButton(right);
2010     horizontalGroup->addButton(standard);
2011     connect(horizontalGroup, SIGNAL(buttonClicked(int)), this, SLOT(slotStateChanged(int)));
2012 
2013     if (dlg->alignY == Style::Top)
2014         top->setChecked(true);
2015     else if (dlg->alignY == Style::Middle)
2016         middle->setChecked(true);
2017     else if (dlg->alignY == Style::Bottom)
2018         bottom->setChecked(true);
2019 
2020     multi->setChecked(dlg->bMultiRow);
2021 
2022     vertical->setChecked(dlg->bVerticalText);
2023     
2024     shrinkToFit->setChecked(dlg->bShrinkToFit);
2025 
2026     angleRotation->setValue(-dlg->textRotation);//annma
2027     spinBox3->setValue(-dlg->textRotation);
2028     if (dlg->textRotation != 0) {
2029         multi->setEnabled(false);
2030         vertical->setEnabled(false);
2031         shrinkToFit->setEnabled(false);
2032     }
2033 
2034     mergeCell->setChecked(dlg->isMerged);
2035     mergeCell->setEnabled(!dlg->oneCell && ((!dlg->isRowSelected) && (!dlg->isColumnSelected)));
2036 
2037     QGridLayout *grid2 = new QGridLayout(indentGroup);
2038     grid2->addItem(new QSpacerItem(0, indentGroup->fontMetrics().height() / 8), 0, 0);  // groupbox title
2039     m_indent = new KoUnitDoubleSpinBox(indentGroup);
2040     m_indent->setMinimum(0.0);
2041     m_indent->setMaximum(400.0);
2042     m_indent->setLineStepPt(10.0);
2043     m_indent->setUnit(dlg->selection()->canvas()->unit());
2044     m_indent->changeValue(dlg->indent);
2045     grid2->addWidget(m_indent, 0, 0);
2046 
2047     width = new KoUnitDoubleSpinBox(m_widthPanel);
2048     QGridLayout *gridWidth = new QGridLayout(m_widthPanel);
2049     gridWidth->setMargin(0);
2050     gridWidth->setSpacing(0);
2051     gridWidth->addWidget(width, 0, 0);
2052     width->setValue(dlg->widthSize);
2053     width->setUnit(dlg->selection()->canvas()->unit());
2054     //to ensure, that we don't get rounding problems, we store the displayed value (for later check for changes)
2055     dlg->widthSize = width->value();
2056 
2057     if (dlg->isRowSelected)
2058         width->setEnabled(false);
2059 
2060     double dw = dlg->selection()->canvas()->unit().toUserValue(dlg->defaultWidthSize);
2061     defaultWidth->setText(i18n("Default width (%1 %2)", dw, dlg->selection()->canvas()->unit().symbol()));
2062     if (dlg->isRowSelected)
2063         defaultWidth->setEnabled(false);
2064 
2065     height = new KoUnitDoubleSpinBox(m_heightPanel);
2066     QGridLayout *gridHeight = new QGridLayout(m_heightPanel);
2067     gridHeight->setMargin(0);
2068     gridHeight->setSpacing(0);
2069     gridHeight->addWidget(height, 0, 0);
2070     height->setValue(dlg->heightSize);
2071     height->setUnit(dlg->selection()->canvas()->unit());
2072     //to ensure, that we don't get rounding problems, we store the displayed value (for later check for changes)
2073     dlg->heightSize = height->value();
2074 
2075     if (dlg->isColumnSelected)
2076         height->setEnabled(false);
2077 
2078     double dh =  dlg->selection()->canvas()->unit().toUserValue(dlg->defaultHeightSize);
2079     defaultHeight->setText(i18n("Default height (%1 %2)", dh, dlg->selection()->canvas()->unit().symbol()));
2080     if (dlg->isColumnSelected)
2081         defaultHeight->setEnabled(false);
2082 
2083     // in case we're editing a style, we disable the cell size settings
2084     if (dlg->getStyle()) {
2085         defaultHeight->setEnabled(false);
2086         defaultWidth->setEnabled(false);
2087     }
2088 
2089     connect(defaultWidth , SIGNAL(clicked()), this, SLOT(slotChangeWidthState()));
2090     connect(defaultHeight , SIGNAL(clicked()), this, SLOT(slotChangeHeightState()));
2091     connect(vertical , SIGNAL(clicked()), this, SLOT(slotChangeVerticalState()));
2092     connect(shrinkToFit, SIGNAL(clicked()), this, SLOT(slotChangeShrinkToFitState()));
2093     connect(multi , SIGNAL(clicked()), this, SLOT(slotChangeMultiState()));
2094     connect(angleRotation, SIGNAL(valueChanged(int)), this, SLOT(slotChangeAngle(int)));
2095 
2096     slotStateChanged(0);
2097     m_bOptionText = false;
2098     this->resize(400, 400);
2099 }
2100 
2101 void CellFormatPagePosition::slotChangeMultiState()
2102 {
2103     m_bOptionText = true;
2104     if (vertical->isChecked()) {
2105         vertical->setChecked(false);
2106     }
2107 }
2108 
2109 void CellFormatPagePosition::slotChangeVerticalState()
2110 {
2111     m_bOptionText = true;
2112     if (multi->isChecked()) {
2113         multi->setChecked(false);
2114     }
2115     if (shrinkToFit->isChecked()) {
2116         shrinkToFit->setChecked(false);
2117     }
2118 }
2119 
2120 
2121 void CellFormatPagePosition::slotChangeShrinkToFitState()
2122 {
2123     m_bOptionText = true;
2124     if (vertical->isChecked()) {
2125         vertical->setChecked(false);
2126     }
2127     if (multi->isChecked()) {
2128         multi->setChecked(false);
2129     }
2130 }
2131 
2132 void CellFormatPagePosition::slotStateChanged(int)
2133 {
2134     if (right->isChecked() || center->isChecked())
2135         m_indent->setEnabled(false);
2136     else
2137         m_indent->setEnabled(true);
2138 }
2139 
2140 bool CellFormatPagePosition::getMergedCellState() const
2141 {
2142     return  mergeCell->isChecked();
2143 }
2144 
2145 void CellFormatPagePosition::slotChangeWidthState()
2146 {
2147     if (defaultWidth->isChecked())
2148         width->setEnabled(false);
2149     else
2150         width->setEnabled(true);
2151 }
2152 
2153 void CellFormatPagePosition::slotChangeHeightState()
2154 {
2155     if (defaultHeight->isChecked())
2156         height->setEnabled(false);
2157     else
2158         height->setEnabled(true);
2159 }
2160 
2161 void CellFormatPagePosition::slotChangeAngle(int _angle)
2162 {
2163     if (_angle == 0) {
2164         multi->setEnabled(true);
2165         vertical->setEnabled(true);
2166     } else {
2167         multi->setEnabled(false);
2168         vertical->setEnabled(false);
2169     }
2170 }
2171 
2172 void CellFormatPagePosition::apply(CustomStyle * style)
2173 {
2174     if (top->isChecked() && dlg->alignY != Style::Top)
2175         style->setVAlign(Style::Top);
2176     else if (bottom->isChecked() && dlg->alignY != Style::Bottom)
2177         style->setVAlign(Style::Bottom);
2178     else if (middle->isChecked() && dlg->alignY != Style::Middle)
2179         style->setVAlign(Style::Middle);
2180 
2181     if (left->isChecked() && dlg->alignX != Style::Left)
2182         style->setHAlign(Style::Left);
2183     else if (right->isChecked() && dlg->alignX != Style::Right)
2184         style->setHAlign(Style::Right);
2185     else if (center->isChecked() && dlg->alignX != Style::Center)
2186         style->setHAlign(Style::Center);
2187     else if (standard->isChecked() && dlg->alignX != Style::HAlignUndefined)
2188         style->setHAlign(Style::HAlignUndefined);
2189 
2190     if (m_bOptionText) {
2191         if (multi->isEnabled()) {
2192             style->setWrapText(multi->isChecked());
2193         }
2194         if (vertical->isEnabled()) {
2195             style->setVerticalText(vertical->isChecked());
2196         }
2197         if (shrinkToFit->isEnabled()) {
2198             style->setShrinkToFit(shrinkToFit->isChecked());
2199         }
2200     }
2201 
2202     if (dlg->textRotation != angleRotation->value())
2203         style->setAngle((-angleRotation->value()));
2204 
2205     if (m_indent->isEnabled()
2206             && dlg->indent != m_indent->value())
2207         style->setIndentation(m_indent->value());
2208 
2209     // setting the default column width and row height
2210     if (dlg->getStyle()->type() == Style::BUILTIN && dlg->getStyle()->name() == "Default") {
2211         if ((int) height->value() != (int) dlg->heightSize) {
2212             dlg->getSheet()->map()->setDefaultRowHeight(height->value());
2213         }
2214         if ((int) width->value() != (int) dlg->widthSize) {
2215             dlg->getSheet()->map()->setDefaultColumnWidth(width->value());
2216         }
2217     }
2218 }
2219 
2220 void CellFormatPagePosition::apply(StyleCommand* _obj)
2221 {
2222     Style::HAlign  ax;
2223     Style::VAlign ay;
2224 
2225     if (top->isChecked())
2226         ay = Style::Top;
2227     else if (bottom->isChecked())
2228         ay = Style::Bottom;
2229     else if (middle->isChecked())
2230         ay = Style::Middle;
2231     else
2232         ay = Style::Middle; // Default, just in case
2233 
2234     if (left->isChecked())
2235         ax = Style::Left;
2236     else if (right->isChecked())
2237         ax = Style::Right;
2238     else if (center->isChecked())
2239         ax = Style::Center;
2240     else if (standard->isChecked())
2241         ax = Style::HAlignUndefined;
2242     else
2243         ax = Style::HAlignUndefined; //Default, just in case
2244 
2245     if (top->isChecked() && ay != dlg->alignY)
2246         _obj->setVerticalAlignment(Style::Top);
2247     else if (bottom->isChecked() && ay != dlg->alignY)
2248         _obj->setVerticalAlignment(Style::Bottom);
2249     else if (middle->isChecked() && ay != dlg->alignY)
2250         _obj->setVerticalAlignment(Style::Middle);
2251 
2252     if (left->isChecked() && ax != dlg->alignX)
2253         _obj->setHorizontalAlignment(Style::Left);
2254     else if (right->isChecked() && ax != dlg->alignX)
2255         _obj->setHorizontalAlignment(Style::Right);
2256     else if (center->isChecked() && ax != dlg->alignX)
2257         _obj->setHorizontalAlignment(Style::Center);
2258     else if (standard->isChecked() && ax != dlg->alignX)
2259         _obj->setHorizontalAlignment(Style::HAlignUndefined);
2260 
2261     if (m_bOptionText) {
2262         if (multi->isEnabled())
2263             _obj->setMultiRow(multi->isChecked());
2264         else
2265             _obj->setMultiRow(false);
2266     }
2267 
2268     if (m_bOptionText) {
2269         if (vertical->isEnabled())
2270             _obj->setVerticalText(vertical->isChecked());
2271         else
2272             _obj->setVerticalText(false);
2273     }
2274 
2275     if (m_bOptionText) {
2276         if (shrinkToFit->isEnabled())
2277             _obj->setShrinkToFit(shrinkToFit->isChecked());
2278         else
2279             _obj->setShrinkToFit(false);
2280     }
2281 
2282     if (dlg->textRotation != angleRotation->value())
2283         _obj->setAngle((-angleRotation->value()));
2284     if (m_indent->isEnabled()
2285             && dlg->indent != m_indent->value())
2286         _obj->setIndentation(m_indent->value());
2287 }
2288 
2289 double CellFormatPagePosition::getSizeHeight() const
2290 {
2291     if (defaultHeight->isChecked())
2292         return dlg->defaultHeightSize; // guess who calls this!
2293     else
2294         return height->value();
2295 }
2296 
2297 double CellFormatPagePosition::getSizeWidth() const
2298 {
2299     if (defaultWidth->isChecked())
2300         return dlg->defaultWidthSize; // guess who calls this!
2301     else
2302         return width->value();
2303 }
2304 
2305 
2306 
2307 /***************************************************************************
2308  *
2309  * BorderButton
2310  *
2311  ***************************************************************************/
2312 
2313 BorderButton::BorderButton(QWidget *parent, const char * /*_name*/) : QPushButton(parent)
2314 {
2315     penStyle = Qt::NoPen;
2316     penWidth = 1;
2317     penColor = palette().text().color();
2318     setCheckable(true);
2319     setChecked(false);
2320     setChanged(false);
2321 }
2322 void BorderButton::mousePressEvent(QMouseEvent *)
2323 {
2324 
2325     this->setChecked(!isChecked());
2326     emit clicked(this);
2327 }
2328 
2329 void BorderButton::setUndefined()
2330 {
2331     setPenStyle(Qt::SolidLine);
2332     setPenWidth(1);
2333     setColor(palette().midlight().color());
2334 }
2335 
2336 
2337 void BorderButton::unselect()
2338 {
2339     setChecked(false);
2340     setPenWidth(1);
2341     setPenStyle(Qt::NoPen);
2342     setColor(palette().text().color());
2343     setChanged(true);
2344 }
2345 
2346 
2347 
2348 /***************************************************************************
2349  *
2350  * Border
2351  *
2352  ***************************************************************************/
2353 
2354 Border::Border(QWidget *parent, const char * /*_name*/, bool _oneCol, bool _oneRow)
2355         : QFrame(parent)
2356 {
2357     setAutoFillBackground(true);
2358 
2359     oneCol = _oneCol;
2360     oneRow = _oneRow;
2361 }
2362 
2363 
2364 #define OFFSETX 5
2365 #define OFFSETY 5
2366 void Border::paintEvent(QPaintEvent *_ev)
2367 {
2368     QFrame::paintEvent(_ev);
2369     QPen pen;
2370     QPainter painter;
2371     painter.begin(this);
2372     pen = QPen(palette().midlight(), 2, Qt::SolidLine).color();
2373     painter.setPen(pen);
2374 
2375     painter.drawLine(OFFSETX - 5, OFFSETY, OFFSETX , OFFSETY);
2376     painter.drawLine(OFFSETX, OFFSETY - 5, OFFSETX , OFFSETY);
2377     painter.drawLine(width() - OFFSETX, OFFSETY, width() , OFFSETY);
2378     painter.drawLine(width() - OFFSETX, OFFSETY - 5, width() - OFFSETX , OFFSETY);
2379 
2380     painter.drawLine(OFFSETX, height() - OFFSETY, OFFSETX , height());
2381     painter.drawLine(OFFSETX - 5, height() - OFFSETY, OFFSETX , height() - OFFSETY);
2382 
2383     painter.drawLine(width() - OFFSETX, height() - OFFSETY, width() , height() - OFFSETY);
2384     painter.drawLine(width() - OFFSETX, height() - OFFSETY, width() - OFFSETX , height());
2385     if (oneCol == false) {
2386         painter.drawLine(width() / 2, OFFSETY - 5, width() / 2 , OFFSETY);
2387         painter.drawLine(width() / 2 - 5, OFFSETY, width() / 2 + 5 , OFFSETY);
2388         painter.drawLine(width() / 2, height() - OFFSETY, width() / 2 , height());
2389         painter.drawLine(width() / 2 - 5, height() - OFFSETY, width() / 2 + 5 , height() - OFFSETY);
2390     }
2391     if (oneRow == false) {
2392         painter.drawLine(OFFSETX - 5, height() / 2, OFFSETX , height() / 2);
2393         painter.drawLine(OFFSETX, height() / 2 - 5, OFFSETX , height() / 2 + 5);
2394         painter.drawLine(width() - OFFSETX, height() / 2, width(), height() / 2);
2395         painter.drawLine(width() - OFFSETX, height() / 2 - 5, width() - OFFSETX , height() / 2 + 5);
2396     }
2397     painter.end();
2398     emit redraw();
2399 }
2400 
2401 void Border::mousePressEvent(QMouseEvent* _ev)
2402 {
2403     emit choosearea(_ev);
2404 }
2405 
2406 
2407 
2408 /***************************************************************************
2409  *
2410  * CellFormatPageBorder
2411  *
2412  ***************************************************************************/
2413 
2414 CellFormatPageBorder::CellFormatPageBorder(QWidget* parent, CellFormatDialog *_dlg)
2415         : QWidget(parent),
2416         dlg(_dlg)
2417 {
2418     sheet = dlg->getSheet();
2419 
2420     InitializeGrids();
2421     InitializeBorderButtons();
2422     InitializePatterns();
2423     SetConnections();
2424 
2425     preview->slotSelect();
2426     pattern[2]->slotSelect();
2427 
2428     style->setEnabled(false);
2429     size->setEnabled(false);
2430     preview->setPattern(Qt::black , 1, Qt::SolidLine);
2431     this->resize(400, 400);
2432 }
2433 
2434 void CellFormatPageBorder::InitializeGrids()
2435 {
2436     QGridLayout *grid = new QGridLayout(this);
2437     QGridLayout *grid2 = 0;
2438     QGroupBox* tmpQGroupBox = 0;
2439 
2440     /***********************/
2441     /* here is the data to initialize all the border buttons with */
2442     const char borderButtonNames[BorderType_END][20] = {"top", "bottom", "left", "right", "vertical", "fall", "go", "horizontal"};
2443 
2444     const char shortcutButtonNames[BorderShortcutType_END][20] = {"remove", "all", "outline"};
2445 
2446     QString borderButtonIconNames[BorderType_END] = {
2447         koIconName("format-border-set-top"), koIconName("format-border-set-bottom"),
2448         koIconName("format-border-set-left"), koIconName("format-border-set-right"),
2449         koIconName("format-border-set-internal-vertical"), koIconName("format-border-set-internal-horizontal"),
2450         koIconName("format-border-set-diagonal-tl-br"), koIconName("format-border-set-diagonal-bl-tr")
2451     };
2452 
2453     QString shortcutButtonIconNames[BorderShortcutType_END] = {
2454         koIconName("format-border-set-none"), QString(), koIconName("format-border-set-external")
2455     };
2456 
2457     int borderButtonPositions[BorderType_END][2] = {{0, 2}, {4, 2}, {2, 0}, {2, 4}, {4, 4}, {4, 0}, {0, 0}, {0, 4}};
2458 
2459     int shortcutButtonPositions[BorderShortcutType_END][2] = { {0, 0}, {0, 1}, {0, 2} };
2460     /***********************/
2461 
2462     /* set up a layout box for most of the border setting buttons */
2463     tmpQGroupBox = new QGroupBox(this);
2464     tmpQGroupBox->setTitle(i18n("Border"));
2465     tmpQGroupBox->setAlignment(Qt::AlignLeft);
2466     grid2 = new QGridLayout(tmpQGroupBox);
2467     int fHeight = tmpQGroupBox->fontMetrics().height();
2468     grid2->addItem(new QSpacerItem(0, fHeight / 2), 0, 0);  // groupbox title
2469 
2470     area = new Border(tmpQGroupBox, "area", dlg->oneCol, dlg->oneRow);
2471     grid2->addWidget(area, 2, 1, 3, 3);
2472     QPalette palette = area->palette();
2473     palette.setColor(area->backgroundRole(), this->palette().base().color());
2474     area->setPalette(palette);
2475 
2476     /* initialize the buttons that are in this box */
2477     for (int i = BorderType_Top; i < BorderType_END; i++) {
2478         borderButtons[i] = new BorderButton(tmpQGroupBox,
2479                                             borderButtonNames[i]);
2480         loadIcon(borderButtonIconNames[i], borderButtons[i]);
2481         grid2->addWidget(borderButtons[i], borderButtonPositions[i][0] + 1,
2482                          borderButtonPositions[i][1]);
2483     }
2484 
2485     grid->addWidget(tmpQGroupBox, 0, 0, 3, 1);
2486 
2487     /* the remove, all, and outline border buttons are in a second box down
2488        below.*/
2489 
2490     tmpQGroupBox = new QGroupBox(this);
2491     tmpQGroupBox->setTitle(i18n("Preselect"));
2492     tmpQGroupBox->setAlignment(Qt::AlignLeft);
2493 
2494     grid2 = new QGridLayout(tmpQGroupBox);
2495 
2496     /* the "all" button is different depending on what kind of region is currently
2497        selected */
2498     if ((dlg->oneRow == true) && (dlg->oneCol == false)) {
2499         shortcutButtonIconNames[BorderShortcutType_All] = koIconName("format-border-set-internal-vertical");
2500     } else if ((dlg->oneRow == false) && (dlg->oneCol == true)) {
2501         shortcutButtonIconNames[BorderShortcutType_All] = koIconName("format-border-set-internal-horizontal");
2502     } else {
2503         shortcutButtonIconNames[BorderShortcutType_All] = koIconName("format-border-set-internal");
2504     }
2505 
2506     for (int i = BorderShortcutType_Remove; i < BorderShortcutType_END; i++) {
2507         shortcutButtons[i] = new BorderButton(tmpQGroupBox,
2508                                               shortcutButtonNames[i]);
2509         loadIcon(shortcutButtonIconNames[i], shortcutButtons[i]);
2510         grid2->addWidget(shortcutButtons[i], shortcutButtonPositions[i][0],
2511                          shortcutButtonPositions[i][1]);
2512     }
2513 
2514     if (dlg->oneRow && dlg->oneCol) {
2515         shortcutButtons[BorderShortcutType_All]->setEnabled(false);
2516     }
2517 
2518     grid->addWidget(tmpQGroupBox, 3, 0, 2, 1);
2519 
2520     /* now set up the group box with the pattern selector */
2521     tmpQGroupBox = new QGroupBox(this);
2522     tmpQGroupBox->setTitle(i18n("Pattern"));
2523     tmpQGroupBox->setAlignment(Qt::AlignLeft);
2524 
2525     grid2 = new QGridLayout(tmpQGroupBox);
2526     fHeight = tmpQGroupBox->fontMetrics().height();
2527     grid2->addItem(new QSpacerItem(0, fHeight / 2), 0, 0);  // groupbox title
2528 
2529     char name[] = "PatternXX";
2530     Q_ASSERT(NUM_BORDER_PATTERNS < 100);
2531 
2532     for (int i = 0; i < NUM_BORDER_PATTERNS; i++) {
2533         name[7] = '0' + (i + 1) / 10;
2534         name[8] = '0' + (i + 1) % 10;
2535         pattern[i] = new PatternSelect(tmpQGroupBox, name);
2536         pattern[i]->setFrameStyle(QFrame::Panel | QFrame::Sunken);
2537         grid2->addWidget(pattern[i], i % 5, i / 5);
2538         /* this puts them in the pattern:
2539            1  6
2540            2  7
2541            3  8
2542            4  9
2543            5  10
2544         */
2545     }
2546 
2547     color = new KColorButton(tmpQGroupBox);
2548     grid2->addWidget(color, 8, 1);
2549 
2550     QLabel *tmpQLabel = new QLabel(tmpQGroupBox);
2551     tmpQLabel->setText(i18n("Color:"));
2552     grid2->addWidget(tmpQLabel, 8, 0);
2553 
2554     /* tack on the 'customize' border pattern selector */
2555     customize  = new QCheckBox(i18n("Customize"), tmpQGroupBox);
2556     grid2->addWidget(customize, 6, 0);
2557     connect(customize, SIGNAL(clicked()), SLOT(cutomize_chosen_slot()));
2558 
2559     size = new KComboBox(tmpQGroupBox);
2560     size->setEditable(true);
2561     grid2->addWidget(size, 7, 1);
2562     size->setValidator(new QIntValidator(size));
2563     QString tmp;
2564     for (int i = 0; i < 10; i++) {
2565         tmp = tmp.setNum(i);
2566         size->insertItem(i, tmp);
2567     }
2568     size->setCurrentIndex(1);
2569 
2570     style = new KComboBox(tmpQGroupBox);
2571     grid2->addWidget(style, 7, 0);
2572     style->setIconSize(QSize(100, 14));
2573     style->insertItem(0, paintFormatPixmap(Qt::DotLine), "");
2574     style->insertItem(1, paintFormatPixmap(Qt::DashLine), "");
2575     style->insertItem(2, paintFormatPixmap(Qt::DashDotLine), "");
2576     style->insertItem(3, paintFormatPixmap(Qt::DashDotDotLine), "");
2577     style->insertItem(4, paintFormatPixmap(Qt::SolidLine), "");
2578     palette = style->palette();
2579     palette.setColor(style->backgroundRole(), this->palette().window().color());
2580     style->setPalette(palette);
2581 
2582     grid->addWidget(tmpQGroupBox, 0, 1, 4, 1);
2583 
2584     /* Now the preview box is put together */
2585     tmpQGroupBox = new QGroupBox(this);
2586     tmpQGroupBox->setTitle(i18n("Preview"));
2587     tmpQGroupBox->setAlignment(Qt::AlignLeft);
2588 
2589     grid2 = new QGridLayout(tmpQGroupBox);
2590     fHeight = tmpQGroupBox->fontMetrics().height();
2591     grid2->addItem(new QSpacerItem(0, fHeight / 2), 0, 0);  // groupbox title
2592 
2593     preview = new PatternSelect(tmpQGroupBox, "Pattern_preview");
2594     preview->setFrameStyle(QFrame::Panel | QFrame::Sunken);
2595     grid2->addWidget(preview, 1, 0);
2596 
2597     grid->addWidget(tmpQGroupBox, 4, 1);
2598 }
2599 
2600 void CellFormatPageBorder::InitializeBorderButtons()
2601 {
2602     for (int i = BorderType_Top; i < BorderType_END; i++) {
2603         if (dlg->borders[i].style != Qt::NoPen ||
2604                 !dlg->borders[i].bStyle) {
2605             /* the horizontal and vertical buttons might be disabled depending on what
2606                kind of area is selected so check that first. */
2607             if ((dlg->oneRow == true && i == BorderType_Horizontal) ||
2608                     (dlg->oneCol == true && i == BorderType_Vertical)) {
2609                 borderButtons[i]->setEnabled(false);
2610             } else if (dlg->borders[i].bColor && dlg->borders[i].bStyle) {
2611                 borderButtons[i]->setPenStyle(dlg->borders[i].style);
2612                 borderButtons[i]->setPenWidth(dlg->borders[i].width);
2613                 borderButtons[i]->setColor(dlg->borders[i].color);
2614                 borderButtons[i]->setChecked(true);
2615             } else {
2616                 borderButtons[i]->setUndefined();
2617             }
2618         }
2619     }
2620 
2621 
2622 }
2623 
2624 void CellFormatPageBorder::InitializePatterns()
2625 {
2626     pattern[0]->setPattern(Qt::black, 1, Qt::DotLine);
2627     pattern[1]->setPattern(Qt::black, 1, Qt::DashLine);
2628     pattern[2]->setPattern(Qt::black, 1, Qt::SolidLine);
2629     pattern[3]->setPattern(Qt::black, 1, Qt::DashDotLine);
2630     pattern[4]->setPattern(Qt::black, 1, Qt::DashDotDotLine);
2631     pattern[5]->setPattern(Qt::black, 2, Qt::SolidLine);
2632     pattern[6]->setPattern(Qt::black, 3, Qt::SolidLine);
2633     pattern[7]->setPattern(Qt::black, 4, Qt::SolidLine);
2634     pattern[8]->setPattern(Qt::black, 5, Qt::SolidLine);
2635     pattern[9]->setPattern(Qt::black, 1, Qt::NoPen);
2636 
2637     slotSetColorButton(Qt::black);
2638 }
2639 
2640 void CellFormatPageBorder::SetConnections()
2641 {
2642     connect(color, SIGNAL(changed(QColor)),
2643             this, SLOT(slotSetColorButton(QColor)));
2644 
2645     for (int i = 0; i < NUM_BORDER_PATTERNS; i++) {
2646         connect(pattern[i], SIGNAL(clicked(PatternSelect*)),
2647                 this, SLOT(slotUnselect2(PatternSelect*)));
2648     }
2649 
2650     for (int i = BorderType_Top; i < BorderType_END; i++) {
2651         connect(borderButtons[i], SIGNAL(clicked(BorderButton*)),
2652                 this, SLOT(changeState(BorderButton*)));
2653     }
2654 
2655     for (int i = BorderShortcutType_Remove; i < BorderShortcutType_END; i++) {
2656         connect(shortcutButtons[i], SIGNAL(clicked(BorderButton*)),
2657                 this, SLOT(preselect(BorderButton*)));
2658     }
2659 
2660     connect(area , SIGNAL(redraw()), this, SLOT(draw()));
2661     connect(area , SIGNAL(choosearea(QMouseEvent*)),
2662             this, SLOT(slotPressEvent(QMouseEvent*)));
2663 
2664     connect(style, SIGNAL(activated(int)), this, SLOT(slotChangeStyle(int)));
2665     connect(size, SIGNAL(editTextChanged(QString)),
2666             this, SLOT(slotChangeStyle(QString)));
2667     connect(size , SIGNAL(activated(int)), this, SLOT(slotChangeStyle(int)));
2668 }
2669 
2670 void CellFormatPageBorder::cutomize_chosen_slot()
2671 {
2672     if (customize->isChecked()) {
2673         style->setEnabled(true);
2674         size->setEnabled(true);
2675         slotUnselect2(preview);
2676     } else {
2677         style->setEnabled(false);
2678         size->setEnabled(false);
2679         pattern[2]->slotSelect();
2680         preview->setPattern(Qt::black , 1, Qt::SolidLine);
2681     }
2682 }
2683 
2684 void CellFormatPageBorder::slotChangeStyle(const QString &)
2685 {
2686     /* if they try putting text in the size box, then erase the line */
2687     slotChangeStyle(0);
2688 }
2689 
2690 void CellFormatPageBorder::slotChangeStyle(int)
2691 {
2692     int index = style->currentIndex();
2693     QString tmp;
2694     int penSize = size->currentText().toInt();
2695     if (!penSize) {
2696         preview->setPattern(preview->getColor(), penSize, Qt::NoPen);
2697     } else {
2698         switch (index) {
2699         case 0:
2700             preview->setPattern(preview->getColor(), penSize, Qt::DotLine);
2701             break;
2702         case 1:
2703             preview->setPattern(preview->getColor(), penSize, Qt::DashLine);
2704             break;
2705         case 2:
2706             preview->setPattern(preview->getColor(), penSize, Qt::DashDotLine);
2707             break;
2708         case 3:
2709             preview->setPattern(preview->getColor(), penSize, Qt::DashDotDotLine);
2710             break;
2711         case 4:
2712             preview->setPattern(preview->getColor(), penSize, Qt::SolidLine);
2713             break;
2714         default:
2715             debugSheets << "Error in combobox";
2716             break;
2717         }
2718     }
2719     slotUnselect2(preview);
2720 }
2721 
2722 QPixmap CellFormatPageBorder::paintFormatPixmap(Qt::PenStyle _style)
2723 {
2724     QPixmap pixmap(100, 14);
2725     pixmap.fill(Qt::transparent);
2726     QPainter painter;
2727     painter.begin(&pixmap);
2728     painter.setPen(QPen(palette().text().color(), 5, _style));
2729     painter.drawLine(0, 7, 100, 7);
2730     painter.end();
2731     return pixmap;
2732 }
2733 
2734 void CellFormatPageBorder::loadIcon(const QString &iconName, BorderButton *_button)
2735 {
2736     _button->setIcon(QIcon::fromTheme(iconName));
2737 }
2738 
2739 void CellFormatPageBorder::apply(StyleCommand* obj)
2740 {
2741     if (borderButtons[BorderType_Horizontal]->isChanged())
2742         applyHorizontalOutline(obj);
2743 
2744     if (borderButtons[BorderType_Vertical]->isChanged())
2745         applyVerticalOutline(obj);
2746 
2747     if (borderButtons[BorderType_Left]->isChanged())
2748         applyLeftOutline(obj);
2749 
2750     if (borderButtons[BorderType_Right]->isChanged())
2751         applyRightOutline(obj);
2752 
2753     if (borderButtons[BorderType_Top]->isChanged())
2754         applyTopOutline(obj);
2755 
2756     if (borderButtons[BorderType_Bottom]->isChanged())
2757         applyBottomOutline(obj);
2758 
2759     if (borderButtons[BorderType_RisingDiagonal]->isChanged() ||
2760             borderButtons[BorderType_FallingDiagonal]->isChanged())
2761         applyDiagonalOutline(obj);
2762 }
2763 
2764 void CellFormatPageBorder::applyTopOutline(StyleCommand* obj)
2765 {
2766     BorderButton * top = borderButtons[BorderType_Top];
2767 
2768     QPen tmpPen(top->getColor(), top->getPenWidth(), top->getPenStyle());
2769 
2770     if (dlg->getStyle()) {
2771         dlg->getStyle()->setTopBorderPen(tmpPen);
2772     } else {
2773         if (borderButtons[BorderType_Top]->isChanged())
2774             obj->setTopBorderPen(tmpPen);
2775     }
2776 }
2777 
2778 void CellFormatPageBorder::applyBottomOutline(StyleCommand* obj)
2779 {
2780     BorderButton * bottom = borderButtons[BorderType_Bottom];
2781 
2782     QPen tmpPen(bottom->getColor(), bottom->getPenWidth(), bottom->getPenStyle());
2783 
2784     if (dlg->getStyle()) {
2785         dlg->getStyle()->setBottomBorderPen(tmpPen);
2786     } else {
2787         if (borderButtons[BorderType_Bottom]->isChanged())
2788             obj->setBottomBorderPen(tmpPen);
2789     }
2790 }
2791 
2792 void CellFormatPageBorder::applyLeftOutline(StyleCommand* obj)
2793 {
2794     BorderButton * left = borderButtons[BorderType_Left];
2795     QPen tmpPen(left->getColor(), left->getPenWidth(), left->getPenStyle());
2796 
2797     if (dlg->getStyle()) {
2798         dlg->getStyle()->setLeftBorderPen(tmpPen);
2799     } else {
2800         if (borderButtons[BorderType_Left]->isChanged())
2801             obj->setLeftBorderPen(tmpPen);
2802     }
2803 }
2804 
2805 void CellFormatPageBorder::applyRightOutline(StyleCommand* obj)
2806 {
2807     BorderButton* right = borderButtons[BorderType_Right];
2808     QPen tmpPen(right->getColor(), right->getPenWidth(), right->getPenStyle());
2809 
2810     if (dlg->getStyle()) {
2811         dlg->getStyle()->setRightBorderPen(tmpPen);
2812     } else {
2813         if (borderButtons[BorderType_Right]->isChanged())
2814             obj->setRightBorderPen(tmpPen);
2815     }
2816 }
2817 
2818 void CellFormatPageBorder::applyDiagonalOutline(StyleCommand* obj)
2819 {
2820     BorderButton * fallDiagonal = borderButtons[BorderType_FallingDiagonal];
2821     BorderButton * goUpDiagonal = borderButtons[BorderType_RisingDiagonal];
2822     QPen tmpPenFall(fallDiagonal->getColor(), fallDiagonal->getPenWidth(),
2823                     fallDiagonal->getPenStyle());
2824     QPen tmpPenGoUp(goUpDiagonal->getColor(), goUpDiagonal->getPenWidth(),
2825                     goUpDiagonal->getPenStyle());
2826 
2827     if (dlg->getStyle()) {
2828         if (fallDiagonal->isChanged())
2829             dlg->getStyle()->setFallDiagonalPen(tmpPenFall);
2830         if (goUpDiagonal->isChanged())
2831             dlg->getStyle()->setGoUpDiagonalPen(tmpPenGoUp);
2832     } else {
2833         if (fallDiagonal->isChanged())
2834             obj->setFallDiagonalPen(tmpPenFall);
2835         if (goUpDiagonal->isChanged())
2836             obj->setGoUpDiagonalPen(tmpPenGoUp);
2837     }
2838 }
2839 
2840 void CellFormatPageBorder::applyHorizontalOutline(StyleCommand* obj)
2841 {
2842     QPen tmpPen(borderButtons[BorderType_Horizontal]->getColor(),
2843                 borderButtons[BorderType_Horizontal]->getPenWidth(),
2844                 borderButtons[BorderType_Horizontal]->getPenStyle());
2845 
2846     if (dlg->getStyle()) {
2847         dlg->getStyle()->setTopBorderPen(tmpPen);
2848     } else {
2849         if (borderButtons[BorderType_Horizontal]->isChanged())
2850             obj->setHorizontalPen(tmpPen);
2851     }
2852 }
2853 
2854 void CellFormatPageBorder::applyVerticalOutline(StyleCommand* obj)
2855 {
2856     BorderButton* vertical = borderButtons[BorderType_Vertical];
2857     QPen tmpPen(vertical->getColor(), vertical->getPenWidth(),
2858                 vertical->getPenStyle());
2859 
2860     if (dlg->getStyle()) {
2861         dlg->getStyle()->setLeftBorderPen(tmpPen);
2862     } else {
2863         if (borderButtons[BorderType_Vertical]->isChanged())
2864             obj->setVerticalPen(tmpPen);
2865     }
2866 }
2867 
2868 
2869 void CellFormatPageBorder::slotSetColorButton(const QColor &_color)
2870 {
2871     currentColor = _color;
2872 
2873     for (int i = 0; i < NUM_BORDER_PATTERNS; ++i) {
2874         pattern[i]->setColor(currentColor);
2875     }
2876     preview->setColor(currentColor);
2877 }
2878 
2879 void CellFormatPageBorder::slotUnselect2(PatternSelect *_p)
2880 {
2881     for (int i = 0; i < NUM_BORDER_PATTERNS; ++i) {
2882         if (pattern[i] != _p) {
2883             pattern[i]->slotUnselect();
2884         }
2885     }
2886     preview->setPattern(_p->getColor(), _p->getPenWidth(), _p->getPenStyle());
2887 }
2888 
2889 void CellFormatPageBorder::preselect(BorderButton *_p)
2890 {
2891     BorderButton* top = borderButtons[BorderType_Top];
2892     BorderButton* bottom = borderButtons[BorderType_Bottom];
2893     BorderButton* left = borderButtons[BorderType_Left];
2894     BorderButton* right = borderButtons[BorderType_Right];
2895     BorderButton* vertical = borderButtons[BorderType_Vertical];
2896     BorderButton* horizontal = borderButtons[BorderType_Horizontal];
2897     BorderButton* remove = shortcutButtons[BorderShortcutType_Remove];
2898     BorderButton* outline = shortcutButtons[BorderShortcutType_Outline];
2899     BorderButton* all = shortcutButtons[BorderShortcutType_All];
2900 
2901     _p->setChecked(false);
2902     if (_p == remove) {
2903         for (int i = BorderType_Top; i < BorderType_END; i++) {
2904             if (borderButtons[i]->isChecked()) {
2905                 borderButtons[i]->unselect();
2906             }
2907         }
2908     }
2909     if (_p == outline) {
2910         top->setChecked(true);
2911         top->setPenWidth(preview->getPenWidth());
2912         top->setPenStyle(preview->getPenStyle());
2913         top->setColor(currentColor);
2914         top->setChanged(true);
2915         bottom->setChecked(true);
2916         bottom->setPenWidth(preview->getPenWidth());
2917         bottom->setPenStyle(preview->getPenStyle());
2918         bottom->setColor(currentColor);
2919         bottom->setChanged(true);
2920         left->setChecked(true);
2921         left->setPenWidth(preview->getPenWidth());
2922         left->setPenStyle(preview->getPenStyle());
2923         left->setColor(currentColor);
2924         left->setChanged(true);
2925         right->setChecked(true);
2926         right->setPenWidth(preview->getPenWidth());
2927         right->setPenStyle(preview->getPenStyle());
2928         right->setColor(currentColor);
2929         right->setChanged(true);
2930     }
2931     if (_p == all) {
2932         if (dlg->oneRow == false) {
2933             horizontal->setChecked(true);
2934             horizontal->setPenWidth(preview->getPenWidth());
2935             horizontal->setPenStyle(preview->getPenStyle());
2936             horizontal->setColor(currentColor);
2937             horizontal->setChanged(true);
2938         }
2939         if (dlg->oneCol == false) {
2940             vertical->setChecked(true);
2941             vertical->setPenWidth(preview->getPenWidth());
2942             vertical->setPenStyle(preview->getPenStyle());
2943             vertical->setColor(currentColor);
2944             vertical->setChanged(true);
2945         }
2946     }
2947     area->repaint();
2948 }
2949 
2950 void CellFormatPageBorder::changeState(BorderButton *_p)
2951 {
2952     _p->setChanged(true);
2953 
2954     if (_p->isChecked()) {
2955         _p->setPenWidth(preview->getPenWidth());
2956         _p->setPenStyle(preview->getPenStyle());
2957         _p->setColor(currentColor);
2958     } else {
2959         _p->setPenWidth(1);
2960         _p->setPenStyle(Qt::NoPen);
2961         _p->setColor(palette().text().color());
2962     }
2963 
2964     area->repaint();
2965 }
2966 
2967 void CellFormatPageBorder::draw()
2968 {
2969     BorderButton* top = borderButtons[BorderType_Top];
2970     BorderButton* bottom = borderButtons[BorderType_Bottom];
2971     BorderButton* left = borderButtons[BorderType_Left];
2972     BorderButton* right = borderButtons[BorderType_Right];
2973     BorderButton* risingDiagonal = borderButtons[BorderType_RisingDiagonal];
2974     BorderButton* fallingDiagonal = borderButtons[BorderType_FallingDiagonal];
2975     BorderButton* vertical = borderButtons[BorderType_Vertical];
2976     BorderButton* horizontal = borderButtons[BorderType_Horizontal];
2977     QPen pen;
2978     QPainter painter;
2979     painter.begin(area);
2980 
2981     if ((bottom->getPenStyle()) != Qt::NoPen) {
2982         pen = QPen(bottom->getColor(), bottom->getPenWidth(), bottom->getPenStyle());
2983         painter.setPen(pen);
2984         painter.drawLine(OFFSETX, area->height() - OFFSETY, area->width() - OFFSETX , area->height() - OFFSETY);
2985     }
2986     if ((top->getPenStyle()) != Qt::NoPen) {
2987         pen = QPen(top->getColor(), top->getPenWidth(), top->getPenStyle());
2988         painter.setPen(pen);
2989         painter.drawLine(OFFSETX, OFFSETY, area->width() - OFFSETX, OFFSETY);
2990     }
2991     if ((left->getPenStyle()) != Qt::NoPen) {
2992         pen = QPen(left->getColor(), left->getPenWidth(), left->getPenStyle());
2993         painter.setPen(pen);
2994         painter.drawLine(OFFSETX, OFFSETY, OFFSETX , area->height() - OFFSETY);
2995     }
2996     if ((right->getPenStyle()) != Qt::NoPen) {
2997         pen = QPen(right->getColor(), right->getPenWidth(), right->getPenStyle());
2998         painter.setPen(pen);
2999         painter.drawLine(area->width() - OFFSETX, OFFSETY, area->width() - OFFSETX,
3000                          area->height() - OFFSETY);
3001 
3002     }
3003     if ((fallingDiagonal->getPenStyle()) != Qt::NoPen) {
3004         pen = QPen(fallingDiagonal->getColor(), fallingDiagonal->getPenWidth(),
3005                    fallingDiagonal->getPenStyle());
3006         painter.setPen(pen);
3007         painter.drawLine(OFFSETX, OFFSETY, area->width() - OFFSETX,
3008                          area->height() - OFFSETY);
3009         if (dlg->oneCol == false && dlg->oneRow == false) {
3010             painter.drawLine(area->width() / 2, OFFSETY, area->width() - OFFSETX,
3011                              area->height() / 2);
3012             painter.drawLine(OFFSETX, area->height() / 2 , area->width() / 2,
3013                              area->height() - OFFSETY);
3014         }
3015     }
3016     if ((risingDiagonal->getPenStyle()) != Qt::NoPen) {
3017         pen = QPen(risingDiagonal->getColor(), risingDiagonal->getPenWidth(),
3018                    risingDiagonal->getPenStyle());
3019         painter.setPen(pen);
3020         painter.drawLine(OFFSETX, area->height() - OFFSETY , area->width() - OFFSETX ,
3021                          OFFSETY);
3022         if (dlg->oneCol == false && dlg->oneRow == false) {
3023             painter.drawLine(area->width() / 2, OFFSETY, OFFSETX, area->height() / 2);
3024             painter.drawLine(area->width() / 2, area->height() - OFFSETY ,
3025                              area->width() - OFFSETX, area->height() / 2);
3026         }
3027 
3028     }
3029     if ((vertical->getPenStyle()) != Qt::NoPen) {
3030         pen = QPen(vertical->getColor(), vertical->getPenWidth(),
3031                    vertical->getPenStyle());
3032         painter.setPen(pen);
3033         painter.drawLine(area->width() / 2, 5 , area->width() / 2 , area->height() - 5);
3034     }
3035     if ((horizontal->getPenStyle()) != Qt::NoPen) {
3036         pen = QPen(horizontal->getColor(), horizontal->getPenWidth(),
3037                    horizontal->getPenStyle());
3038         painter.setPen(pen);
3039         painter.drawLine(OFFSETX, area->height() / 2, area->width() - OFFSETX,
3040                          area->height() / 2);
3041     }
3042     painter.end();
3043 }
3044 
3045 void CellFormatPageBorder::invertState(BorderButton *_p)
3046 {
3047     if (_p->isChecked()) {
3048         _p->unselect();
3049     } else {
3050         _p->setChecked(true);
3051         _p->setPenWidth(preview->getPenWidth());
3052         _p->setPenStyle(preview->getPenStyle());
3053         _p->setColor(currentColor);
3054         _p->setChanged(true);
3055     }
3056 }
3057 
3058 void CellFormatPageBorder::slotPressEvent(QMouseEvent *_ev)
3059 {
3060     BorderButton* top = borderButtons[BorderType_Top];
3061     BorderButton* bottom = borderButtons[BorderType_Bottom];
3062     BorderButton* left = borderButtons[BorderType_Left];
3063     BorderButton* right = borderButtons[BorderType_Right];
3064     BorderButton* vertical = borderButtons[BorderType_Vertical];
3065     BorderButton* horizontal = borderButtons[BorderType_Horizontal];
3066 
3067 
3068     QRect rect(OFFSETX, OFFSETY - 8, area->width() - OFFSETX, OFFSETY + 8);
3069     if (rect.contains(QPoint(_ev->x(), _ev->y()))) {
3070         if (((top->getPenWidth() != preview->getPenWidth()) ||
3071                 (top->getColor() != currentColor) ||
3072                 (top->getPenStyle() != preview->getPenStyle()))
3073                 && top->isChecked()) {
3074             top->setPenWidth(preview->getPenWidth());
3075             top->setPenStyle(preview->getPenStyle());
3076             top->setColor(currentColor);
3077             top->setChanged(true);
3078         } else
3079             invertState(top);
3080     }
3081     rect.setCoords(OFFSETX, area->height() - OFFSETY - 8, area->width() - OFFSETX,
3082                    area->height() - OFFSETY + 8);
3083     if (rect.contains(QPoint(_ev->x(), _ev->y()))) {
3084         if (((bottom->getPenWidth() != preview->getPenWidth()) ||
3085                 (bottom->getColor() != currentColor) ||
3086                 (bottom->getPenStyle() != preview->getPenStyle()))
3087                 && bottom->isChecked()) {
3088             bottom->setPenWidth(preview->getPenWidth());
3089             bottom->setPenStyle(preview->getPenStyle());
3090             bottom->setColor(currentColor);
3091             bottom->setChanged(true);
3092         } else
3093             invertState(bottom);
3094     }
3095 
3096     rect.setCoords(OFFSETX - 8, OFFSETY, OFFSETX + 8, area->height() - OFFSETY);
3097     if (rect.contains(QPoint(_ev->x(), _ev->y()))) {
3098         if (((left->getPenWidth() != preview->getPenWidth()) ||
3099                 (left->getColor() != currentColor) ||
3100                 (left->getPenStyle() != preview->getPenStyle()))
3101                 && left->isChecked()) {
3102             left->setPenWidth(preview->getPenWidth());
3103             left->setPenStyle(preview->getPenStyle());
3104             left->setColor(currentColor);
3105             left->setChanged(true);
3106         } else
3107             invertState(left);
3108     }
3109     rect.setCoords(area->width() - OFFSETX - 8, OFFSETY, area->width() - OFFSETX + 8,
3110                    area->height() - OFFSETY);
3111     if (rect.contains(QPoint(_ev->x(), _ev->y()))) {
3112         if (((right->getPenWidth() != preview->getPenWidth()) ||
3113                 (right->getColor() != currentColor) ||
3114                 (right->getPenStyle() != preview->getPenStyle()))
3115                 && right->isChecked()) {
3116             right->setPenWidth(preview->getPenWidth());
3117             right->setPenStyle(preview->getPenStyle());
3118             right->setColor(currentColor);
3119             right->setChanged(true);
3120         } else
3121             invertState(right);
3122     }
3123 
3124 //don't work because I don't know how create a rectangle
3125 //for diagonal
3126     /*rect.setCoords(OFFSETX,OFFSETY,XLEN-OFFSETX,YHEI-OFFSETY);
3127     if (rect.contains(QPoint(_ev->x(),_ev->y())))
3128             {
3129              invertState(fallDiagonal);
3130             }
3131     rect.setCoords(OFFSETX,YHEI-OFFSETY,XLEN-OFFSETX,OFFSETY);
3132     if (rect.contains(QPoint(_ev->x(),_ev->y())))
3133             {
3134              invertState(goUpDiagonal);
3135             } */
3136 
3137     if (dlg->oneCol == false) {
3138         rect.setCoords(area->width() / 2 - 8, OFFSETY, area->width() / 2 + 8,
3139                        area->height() - OFFSETY);
3140 
3141         if (rect.contains(QPoint(_ev->x(), _ev->y()))) {
3142             if (((vertical->getPenWidth() != preview->getPenWidth()) ||
3143                     (vertical->getColor() != currentColor) ||
3144                     (vertical->getPenStyle() != preview->getPenStyle()))
3145                     && vertical->isChecked()) {
3146                 vertical->setPenWidth(preview->getPenWidth());
3147                 vertical->setPenStyle(preview->getPenStyle());
3148                 vertical->setColor(currentColor);
3149                 vertical->setChanged(true);
3150             } else
3151                 invertState(vertical);
3152         }
3153     }
3154     if (dlg->oneRow == false) {
3155         rect.setCoords(OFFSETX, area->height() / 2 - 8, area->width() - OFFSETX,
3156                        area->height() / 2 + 8);
3157         if (rect.contains(QPoint(_ev->x(), _ev->y()))) {
3158             if (((horizontal->getPenWidth() != preview->getPenWidth()) ||
3159                     (horizontal->getColor() != currentColor) ||
3160                     (horizontal->getPenStyle() != preview->getPenStyle()))
3161                     && horizontal->isChecked()) {
3162                 horizontal->setPenWidth(preview->getPenWidth());
3163                 horizontal->setPenStyle(preview->getPenStyle());
3164                 horizontal->setColor(currentColor);
3165                 horizontal->setChanged(true);
3166             } else
3167                 invertState(horizontal);
3168         }
3169     }
3170 
3171     area->repaint();
3172 }
3173 
3174 
3175 
3176 /***************************************************************************
3177  *
3178  * BrushSelect
3179  *
3180  ***************************************************************************/
3181 
3182 BrushSelect::BrushSelect(QWidget *parent, const char *) : QFrame(parent)
3183 {
3184     brushStyle = Qt::NoBrush;
3185     brushColor = Qt::red;
3186     selected = false;
3187 }
3188 
3189 void BrushSelect::setPattern(const QColor &_color, Qt::BrushStyle _style)
3190 {
3191     brushStyle = _style;
3192     brushColor = _color;
3193     repaint();
3194 }
3195 
3196 
3197 void BrushSelect::paintEvent(QPaintEvent *_ev)
3198 {
3199     QFrame::paintEvent(_ev);
3200 
3201     QPainter painter;
3202     QBrush brush(brushColor, brushStyle);
3203     painter.begin(this);
3204     painter.setPen(Qt::NoPen);
3205     painter.setBrush(brush);
3206     painter.drawRect(2, 2, width() - 4, height() - 4);
3207     painter.end();
3208 }
3209 
3210 void BrushSelect::mousePressEvent(QMouseEvent *)
3211 {
3212     slotSelect();
3213 
3214     emit clicked(this);
3215 }
3216 
3217 void BrushSelect::slotUnselect()
3218 {
3219     selected = false;
3220 
3221     setLineWidth(1);
3222     setFrameStyle(QFrame::Panel | QFrame::Sunken);
3223     repaint();
3224 }
3225 
3226 void BrushSelect::slotSelect()
3227 {
3228     selected = true;
3229 
3230     setLineWidth(2);
3231     setFrameStyle(QFrame::Panel | QFrame::Plain);
3232     repaint();
3233 }
3234 
3235 
3236 
3237 /***************************************************************************
3238  *
3239  * CellFormatPagePattern
3240  *
3241  ***************************************************************************/
3242 
3243 CellFormatPagePattern::CellFormatPagePattern(QWidget* parent, CellFormatDialog *_dlg) : QWidget(parent)
3244 {
3245     dlg = _dlg;
3246 
3247     QGridLayout *grid = new QGridLayout(this);
3248 
3249     QGroupBox* tmpQGroupBox;
3250     tmpQGroupBox = new QGroupBox(this);
3251     tmpQGroupBox->setTitle(i18n("Pattern"));
3252     tmpQGroupBox->setAlignment(Qt::AlignLeft);
3253 
3254     QGridLayout *grid2 = new QGridLayout(tmpQGroupBox);
3255     int fHeight = tmpQGroupBox->fontMetrics().height();
3256     grid2->addItem(new QSpacerItem(0, fHeight / 2), 0, 0);  // groupbox title
3257 
3258 
3259     brush1 = new BrushSelect(tmpQGroupBox, "Frame_1");
3260     brush1->setFrameStyle(QFrame::Panel | QFrame::Sunken);
3261     grid2->addWidget(brush1, 1, 0);
3262 
3263     brush2 = new BrushSelect(tmpQGroupBox, "Frame_2");
3264     brush2->setFrameStyle(QFrame::Panel | QFrame::Sunken);
3265     grid2->addWidget(brush2, 1, 1);
3266 
3267     brush3 = new BrushSelect(tmpQGroupBox, "Frame_3");
3268     brush3->setFrameStyle(QFrame::Panel | QFrame::Sunken);
3269     grid2->addWidget(brush3, 1, 2);
3270 
3271     brush4 = new BrushSelect(tmpQGroupBox, "Frame_4");
3272     brush4->setFrameStyle(QFrame::Panel | QFrame::Sunken);
3273     grid2->addWidget(brush4, 2, 0);
3274 
3275     brush5 = new BrushSelect(tmpQGroupBox, "Frame_5");
3276     brush5->setFrameStyle(QFrame::Panel | QFrame::Sunken);
3277     grid2->addWidget(brush5, 2, 1);
3278 
3279     brush6 = new BrushSelect(tmpQGroupBox, "Frame_6");
3280     brush6->setFrameStyle(QFrame::Panel | QFrame::Sunken);
3281     grid2->addWidget(brush6, 2, 2);
3282 
3283     brush7 = new BrushSelect(tmpQGroupBox, "Frame_7");
3284     brush7->setFrameStyle(QFrame::Panel | QFrame::Sunken);
3285     grid2->addWidget(brush7, 3, 0);
3286 
3287     brush8 = new BrushSelect(tmpQGroupBox, "Frame_8");
3288     brush8->setFrameStyle(QFrame::Panel | QFrame::Sunken);
3289     grid2->addWidget(brush8, 3, 1);
3290 
3291     brush9 = new BrushSelect(tmpQGroupBox, "Frame_9");
3292     brush9->setFrameStyle(QFrame::Panel | QFrame::Sunken);
3293     grid2->addWidget(brush9, 3, 2);
3294 
3295     brush10 = new BrushSelect(tmpQGroupBox, "Frame_10");
3296     brush10->setFrameStyle(QFrame::Panel | QFrame::Sunken);
3297     grid2->addWidget(brush10, 4, 0);
3298 
3299     brush11 = new BrushSelect(tmpQGroupBox, "Frame_11");
3300     brush11->setFrameStyle(QFrame::Panel | QFrame::Sunken);
3301     grid2->addWidget(brush11, 4, 1);
3302 
3303     brush12 = new BrushSelect(tmpQGroupBox, "Frame_12");
3304     brush12->setFrameStyle(QFrame::Panel | QFrame::Sunken);
3305     grid2->addWidget(brush12, 4, 2);
3306 
3307     brush13 = new BrushSelect(tmpQGroupBox, "Frame_13");
3308     brush13->setFrameStyle(QFrame::Panel | QFrame::Sunken);
3309     grid2->addWidget(brush13, 5, 0);
3310 
3311     brush14 = new BrushSelect(tmpQGroupBox, "Frame_14");
3312     brush14->setFrameStyle(QFrame::Panel | QFrame::Sunken);
3313     grid2->addWidget(brush14, 5, 1);
3314 
3315     brush15 = new BrushSelect(tmpQGroupBox, "Frame_15");
3316     brush15->setFrameStyle(QFrame::Panel | QFrame::Sunken);
3317     grid2->addWidget(brush15, 5, 2);
3318 
3319     QGridLayout *grid3 = new QGridLayout();
3320     color = new KColorButton(tmpQGroupBox);
3321     grid3->addWidget(color, 0, 1);
3322 
3323     QLabel *tmpQLabel = new QLabel(tmpQGroupBox);
3324     tmpQLabel->setText(i18n("Color:"));
3325     grid3->addWidget(tmpQLabel, 0, 0);
3326 
3327     grid2->addItem(grid3, 6, 0, 1, 3);
3328 
3329     grid3 = new QGridLayout();
3330 
3331     tmpQLabel = new QLabel(tmpQGroupBox);
3332     grid3->addWidget(tmpQLabel, 0, 0);
3333     tmpQLabel->setText(i18n("Background color:"));
3334 
3335     bgColorButton = new KColorButton(tmpQGroupBox);
3336     grid3->addWidget(bgColorButton, 0, 1);
3337     if (dlg->bBgColor)
3338         bgColor = dlg->bgColor;
3339     else
3340         bgColor = palette().base().color();
3341 
3342     if (!bgColor.isValid())
3343         bgColor = palette().base().color();
3344 
3345     bgColorButton->setColor(bgColor);
3346     connect(bgColorButton, SIGNAL(changed(QColor)),
3347             this, SLOT(slotSetBackgroundColor(QColor)));
3348 
3349     notAnyColor = new QPushButton(i18n("No Color"), tmpQGroupBox);
3350     grid3->addWidget(notAnyColor, 0, 2);
3351     connect(notAnyColor, SIGNAL(clicked()),
3352             this, SLOT(slotNotAnyColor()));
3353     b_notAnyColor = true;
3354 
3355     grid2->addItem(grid3, 7, 0, 1, 3);
3356 
3357     grid->addWidget(tmpQGroupBox, 0, 0, 4, 1);
3358 
3359     tmpQGroupBox = new QGroupBox(this);
3360     tmpQGroupBox->setTitle(i18n("Preview"));
3361     tmpQGroupBox->setAlignment(Qt::AlignLeft);
3362 
3363     grid2 = new QGridLayout(tmpQGroupBox);
3364     fHeight = tmpQGroupBox->fontMetrics().height();
3365     grid2->addItem(new QSpacerItem(0, fHeight / 2), 0, 0);  // groupbox title
3366 
3367     current = new BrushSelect(tmpQGroupBox, "Current");
3368     current->setFrameStyle(QFrame::Panel | QFrame::Sunken);
3369     grid2->addWidget(current, 1, 0);
3370     grid->addWidget(tmpQGroupBox, 4, 0);
3371 
3372     connect(brush1, SIGNAL(clicked(BrushSelect*)),
3373             this, SLOT(slotUnselect2(BrushSelect*)));
3374     connect(brush2, SIGNAL(clicked(BrushSelect*)),
3375             this, SLOT(slotUnselect2(BrushSelect*)));
3376     connect(brush3, SIGNAL(clicked(BrushSelect*)),
3377             this, SLOT(slotUnselect2(BrushSelect*)));
3378     connect(brush4, SIGNAL(clicked(BrushSelect*)),
3379             this, SLOT(slotUnselect2(BrushSelect*)));
3380     connect(brush5, SIGNAL(clicked(BrushSelect*)),
3381             this, SLOT(slotUnselect2(BrushSelect*)));
3382     connect(brush6, SIGNAL(clicked(BrushSelect*)),
3383             this, SLOT(slotUnselect2(BrushSelect*)));
3384     connect(brush7, SIGNAL(clicked(BrushSelect*)),
3385             this, SLOT(slotUnselect2(BrushSelect*)));
3386     connect(brush8, SIGNAL(clicked(BrushSelect*)),
3387             this, SLOT(slotUnselect2(BrushSelect*)));
3388     connect(brush9, SIGNAL(clicked(BrushSelect*)),
3389             this, SLOT(slotUnselect2(BrushSelect*)));
3390     connect(brush10, SIGNAL(clicked(BrushSelect*)),
3391             this, SLOT(slotUnselect2(BrushSelect*)));
3392     connect(brush11, SIGNAL(clicked(BrushSelect*)),
3393             this, SLOT(slotUnselect2(BrushSelect*)));
3394     connect(brush12, SIGNAL(clicked(BrushSelect*)),
3395             this, SLOT(slotUnselect2(BrushSelect*)));
3396     connect(brush13, SIGNAL(clicked(BrushSelect*)),
3397             this, SLOT(slotUnselect2(BrushSelect*)));
3398     connect(brush14, SIGNAL(clicked(BrushSelect*)),
3399             this, SLOT(slotUnselect2(BrushSelect*)));
3400     connect(brush15, SIGNAL(clicked(BrushSelect*)),
3401             this, SLOT(slotUnselect2(BrushSelect*)));
3402 
3403     brush1->setPattern(Qt::red, Qt::VerPattern);
3404     brush2->setPattern(Qt::red, Qt::HorPattern);
3405     brush3->setPattern(Qt::red, Qt::Dense1Pattern);
3406     brush4->setPattern(Qt::red, Qt::Dense2Pattern);
3407     brush5->setPattern(Qt::red, Qt::Dense3Pattern);
3408     brush6->setPattern(Qt::red, Qt::Dense4Pattern);
3409     brush7->setPattern(Qt::red, Qt::Dense5Pattern);
3410     brush8->setPattern(Qt::red, Qt::Dense6Pattern);
3411     brush9->setPattern(Qt::red, Qt::Dense7Pattern);
3412     brush10->setPattern(Qt::red, Qt::CrossPattern);
3413     brush11->setPattern(Qt::red, Qt::BDiagPattern);
3414     brush12->setPattern(Qt::red, Qt::FDiagPattern);
3415     brush13->setPattern(Qt::red, Qt::DiagCrossPattern);
3416     brush14->setPattern(Qt::red, Qt::SolidPattern);
3417     brush15->setPattern(Qt::red, Qt::NoBrush);
3418 
3419     current->setPattern(dlg->brushColor, dlg->brushStyle);
3420     current->slotSelect();
3421     selectedBrush = current;
3422     color->setColor(dlg->brushColor);
3423     QPalette palette = current->palette();
3424     palette.setColor(current->backgroundRole(), bgColor);
3425     current->setPalette(palette);
3426 
3427     connect(color, SIGNAL(changed(QColor)),
3428             this, SLOT(slotSetColorButton(QColor)));
3429 
3430     slotSetColorButton(dlg->brushColor);
3431     init();
3432     this->resize(400, 400);
3433 }
3434 
3435 void CellFormatPagePattern::slotNotAnyColor()
3436 {
3437     b_notAnyColor = true;
3438     bgColorButton->setColor(palette().base().color());
3439     QPalette palette = current->palette();
3440     palette.setColor(current->backgroundRole(), this->palette().base().color());
3441     current->setPalette(palette);
3442 }
3443 
3444 void CellFormatPagePattern::slotSetBackgroundColor(const QColor &_color)
3445 {
3446     bgColor = _color;
3447     QPalette palette = current->palette();
3448     palette.setColor(current->backgroundRole(), bgColor);
3449     current->setPalette(palette);
3450     b_notAnyColor = false;
3451 }
3452 
3453 void CellFormatPagePattern::init()
3454 {
3455     if (dlg->brushStyle == Qt::VerPattern) {
3456         brush1->slotSelect();
3457     } else if (dlg->brushStyle == Qt::HorPattern) {
3458         brush2->slotSelect();
3459     } else if (dlg->brushStyle == Qt::Dense1Pattern) {
3460         brush3->slotSelect();
3461     } else if (dlg->brushStyle == Qt::Dense2Pattern) {
3462         brush4->slotSelect();
3463     } else if (dlg->brushStyle == Qt::Dense3Pattern) {
3464         brush5->slotSelect();
3465     } else if (dlg->brushStyle == Qt::Dense4Pattern) {
3466         brush6->slotSelect();
3467     } else if (dlg->brushStyle == Qt::Dense5Pattern) {
3468         brush7->slotSelect();
3469     } else if (dlg->brushStyle == Qt::Dense6Pattern) {
3470         brush8->slotSelect();
3471     } else if (dlg->brushStyle == Qt::Dense7Pattern) {
3472         brush9->slotSelect();
3473     } else if (dlg->brushStyle == Qt::CrossPattern) {
3474         brush10->slotSelect();
3475     } else if (dlg->brushStyle == Qt::BDiagPattern) {
3476         brush11->slotSelect();
3477     } else if (dlg->brushStyle == Qt::FDiagPattern) {
3478         brush12->slotSelect();
3479     } else if (dlg->brushStyle == Qt::DiagCrossPattern) {
3480         brush13->slotSelect();
3481     } else if (dlg->brushStyle == Qt::SolidPattern) {
3482         brush14->slotSelect();
3483     } else if (dlg->brushStyle == Qt::NoBrush) {
3484         brush15->slotSelect();
3485     } else
3486         debugSheets << "Error in brushStyle";
3487 }
3488 
3489 void CellFormatPagePattern::slotSetColorButton(const QColor &_color)
3490 {
3491     currentColor = _color;
3492 
3493     brush1->setBrushColor(currentColor);
3494     brush2->setBrushColor(currentColor);
3495     brush3->setBrushColor(currentColor);
3496     brush4->setBrushColor(currentColor);
3497     brush5->setBrushColor(currentColor);
3498     brush6->setBrushColor(currentColor);
3499     brush7->setBrushColor(currentColor);
3500     brush8->setBrushColor(currentColor);
3501     brush9->setBrushColor(currentColor);
3502     brush10->setBrushColor(currentColor);
3503     brush11->setBrushColor(currentColor);
3504     brush12->setBrushColor(currentColor);
3505     brush13->setBrushColor(currentColor);
3506     brush14->setBrushColor(currentColor);
3507     brush15->setBrushColor(currentColor);
3508     current->setBrushColor(currentColor);
3509 }
3510 
3511 void CellFormatPagePattern::slotUnselect2(BrushSelect *_p)
3512 {
3513     selectedBrush = _p;
3514 
3515     if (brush1 != _p)
3516         brush1->slotUnselect();
3517     if (brush2 != _p)
3518         brush2->slotUnselect();
3519     if (brush3 != _p)
3520         brush3->slotUnselect();
3521     if (brush4 != _p)
3522         brush4->slotUnselect();
3523     if (brush5 != _p)
3524         brush5->slotUnselect();
3525     if (brush6 != _p)
3526         brush6->slotUnselect();
3527     if (brush7 != _p)
3528         brush7->slotUnselect();
3529     if (brush8 != _p)
3530         brush8->slotUnselect();
3531     if (brush9 != _p)
3532         brush9->slotUnselect();
3533     if (brush10 != _p)
3534         brush10->slotUnselect();
3535     if (brush11 != _p)
3536         brush11->slotUnselect();
3537     if (brush12 != _p)
3538         brush12->slotUnselect();
3539     if (brush13 != _p)
3540         brush13->slotUnselect();
3541     if (brush14 != _p)
3542         brush14->slotUnselect();
3543     if (brush15 != _p)
3544         brush15->slotUnselect();
3545 
3546     current->setBrushStyle(selectedBrush->getBrushStyle());
3547 }
3548 
3549 void CellFormatPagePattern::apply(CustomStyle * style)
3550 {
3551     if (selectedBrush != 0
3552             && (dlg->brushStyle != selectedBrush->getBrushStyle()
3553                 || dlg->brushColor != selectedBrush->getBrushColor()))
3554         style->setBackgroundBrush(QBrush(selectedBrush->getBrushColor(), selectedBrush->getBrushStyle()));
3555 
3556     if (!b_notAnyColor && bgColor != dlg->getStyle()->backgroundColor())
3557         style->setBackgroundColor(bgColor);
3558 }
3559 
3560 void CellFormatPagePattern::apply(StyleCommand *_obj)
3561 {
3562     if (selectedBrush != 0
3563             && (dlg->brushStyle != selectedBrush->getBrushStyle()
3564                 || dlg->brushColor != selectedBrush->getBrushColor()))
3565         _obj->setBackgroundBrush(QBrush(selectedBrush->getBrushColor(), selectedBrush->getBrushStyle()));
3566 
3567     if (bgColor == dlg->bgColor)
3568         return;
3569 
3570     if (!b_notAnyColor)
3571         _obj->setBackgroundColor(bgColor);
3572 }