File indexing completed on 2024-05-12 16:35:23
0001 /* This file is part of the KDE project 0002 Copyright (C) 2002-2004 Ariya Hidayat <ariya@kde.org> 0003 (C) 2002-2003 Norbert Andres <nandres@web.de> 0004 (C) 2001-2003 Philipp Mueller <philipp.mueller@gmx.de> 0005 (C) 2002 John Dailey <dailey@vt.edu> 0006 (C) 1999-2002 Laurent Montel <montel@kde.org> 0007 (C) 1999-2002 Harri Porten <porten@kde.org> 0008 (C) 2000-2001 David Faure <faure@kde.org> 0009 (C) 1998-2000 Torben Weis <weis@kde.org> 0010 (C) 2000 Werner Trobin <trobin@kde.org> 0011 (C) 1999 Reginald Stadlbauer <reggie@kde.org> 0012 (C) 1998-1999 Stephan Kulow <coolo@kde.org> 0013 0014 This library is free software; you can redistribute it and/or 0015 modify it under the terms of the GNU Library General Public 0016 License as published by the Free Software Foundation; either 0017 version 2 of the License, or (at your option) any later version. 0018 0019 This library is distributed in the hope that it will be useful, 0020 but WITHOUT ANY WARRANTY; without even the implied warranty of 0021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0022 Library General Public License for more details. 0023 0024 You should have received a copy of the GNU Library General Public License 0025 along with this library; see the file COPYING.LIB. If not, write to 0026 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0027 Boston, MA 02110-1301, USA. 0028 */ 0029 0030 #ifndef CALLIGRA_SHEETS_LAYOUT_DIALOG 0031 #define CALLIGRA_SHEETS_LAYOUT_DIALOG 0032 0033 #include <QCheckBox> 0034 #include <QFrame> 0035 #include <QLabel> 0036 #include <QMouseEvent> 0037 #include <QPixmap> 0038 #include <QPaintEvent> 0039 #include <QPushButton> 0040 0041 #include <kpagedialog.h> 0042 0043 #include "RowColumnFormat.h" 0044 #include "Style.h" 0045 #include "Value.h" 0046 0047 #include "ui_FontWidget.h" 0048 #include "ui_PositionWidget.h" 0049 #include "ui_ProtectionWidget.h" 0050 0051 class KoUnitDoubleSpinBox; 0052 class QSpinBox; 0053 class QPixmap; 0054 class QRadioButton; 0055 class QPushButton; 0056 class QLabel; 0057 class QWidget; 0058 class KLineEdit; 0059 class QFrame; 0060 class QListWidget; 0061 class QCheckBox; 0062 class KColorButton; 0063 class KComboBox; 0064 class KLocale; 0065 0066 namespace Calligra 0067 { 0068 namespace Sheets 0069 { 0070 class Sheet; 0071 class CustomStyle; 0072 class StyleManager; 0073 class CellFormatDialog; 0074 class Selection; 0075 class StyleCommand; 0076 0077 enum BorderType { 0078 BorderType_Top = 0, 0079 BorderType_Bottom, 0080 BorderType_Left, 0081 BorderType_Right, 0082 BorderType_Vertical, 0083 BorderType_Horizontal, 0084 BorderType_FallingDiagonal, 0085 BorderType_RisingDiagonal, 0086 BorderType_END 0087 }; 0088 0089 enum BorderShortcutType { 0090 BorderShortcutType_Remove = 0, 0091 BorderShortcutType_All, 0092 BorderShortcutType_Outline, 0093 BorderShortcutType_END 0094 }; 0095 0096 /** 0097 * \ingroup UI 0098 * Widget to select a background pattern. 0099 */ 0100 class PatternSelect : public QFrame 0101 { 0102 Q_OBJECT 0103 public: 0104 PatternSelect(QWidget *parent, const char *_name); 0105 0106 void setPenStyle(Qt::PenStyle _pat) { 0107 penStyle = _pat; repaint(); 0108 } 0109 Qt::PenStyle getPenStyle() { 0110 return penStyle; 0111 } 0112 void setColor(const QColor &_col) { 0113 penColor = _col; repaint(); 0114 } 0115 const QColor& getColor() { 0116 return penColor; 0117 } 0118 void setPenWidth(int _w) { 0119 penWidth = _w; repaint(); 0120 } 0121 int getPenWidth() { 0122 return penWidth; 0123 } 0124 0125 void setPattern(const QColor &_color, int _width, Qt::PenStyle _style); 0126 void setUndefined(); 0127 void setDefined() { 0128 undefined = false; repaint(); 0129 } 0130 0131 bool isDefined() { 0132 return !undefined; 0133 } 0134 0135 Q_SIGNALS: 0136 void clicked(PatternSelect *_this); 0137 0138 public Q_SLOTS: 0139 void slotUnselect(); 0140 void slotSelect(); 0141 0142 protected: 0143 void paintEvent(QPaintEvent *_ev) override; 0144 void mousePressEvent(QMouseEvent *_ev) override; 0145 0146 Qt::PenStyle penStyle; 0147 QColor penColor; 0148 int penWidth; 0149 0150 bool selected; 0151 bool undefined; 0152 }; 0153 0154 /** 0155 * \ingroup UI 0156 * Dialog page to select the cell style inheritance. 0157 * Only shown when modifying a named cell style. 0158 */ 0159 class GeneralTab : public QWidget 0160 { 0161 Q_OBJECT 0162 0163 public: 0164 GeneralTab(QWidget * parent, CellFormatDialog * _dlg); 0165 ~GeneralTab() override; 0166 0167 bool apply(CustomStyle * style); 0168 0169 protected Q_SLOTS: 0170 void parentChanged(const QString&); 0171 void styleNameChanged(const QString&); 0172 0173 private: 0174 CellFormatDialog * m_dlg; 0175 KComboBox * m_parentBox; 0176 KLineEdit * m_nameEdit; 0177 QLabel * m_nameStatus; 0178 QLabel * m_parentStatus; 0179 0180 QString m_name; 0181 QString m_parent; 0182 0183 bool checkParent(const QString & parentName); 0184 bool checkName(); 0185 }; 0186 0187 /** 0188 * \ingroup UI 0189 * Dialog page to choose the used font. 0190 */ 0191 class CellFormatPageFont : public QWidget, public Ui::FontWidget 0192 { 0193 Q_OBJECT 0194 public: 0195 CellFormatPageFont(QWidget* parent, CellFormatDialog *_dlg); 0196 0197 void apply(CustomStyle * style); 0198 void apply(StyleCommand *_obj); 0199 0200 Q_SIGNALS: 0201 /** 0202 * Connect to this to monitor the font as it as selected if you are 0203 * not running modal. 0204 */ 0205 void fontSelected(const QFont &font); 0206 0207 private Q_SLOTS: 0208 0209 void family_chosen_slot(const QString &); 0210 void size_chosen_slot(const QString &); 0211 void weight_chosen_slot(const QString &); 0212 void style_chosen_slot(const QString &); 0213 void underline_chosen_slot(); 0214 void strike_chosen_slot(); 0215 void display_example(const QFont &font); 0216 void slotSetTextColor(const QColor &_color); 0217 0218 private: 0219 0220 void setCombos(); 0221 QColor textColor; 0222 QFont selFont; 0223 bool fontChanged; 0224 bool bTextColorUndefined; 0225 CellFormatDialog *dlg; 0226 }; 0227 0228 /** 0229 * \ingroup UI 0230 * Dialog page to select the value formatting. 0231 */ 0232 class CellFormatPageFloat : public QWidget 0233 { 0234 Q_OBJECT 0235 public: 0236 CellFormatPageFloat(QWidget *parent, CellFormatDialog *_dlg); 0237 void apply(CustomStyle * style); 0238 void apply(StyleCommand *_obj); 0239 0240 public Q_SLOTS: 0241 void slotChangeState(); 0242 void makeformat(); 0243 void updateFormatType(); 0244 void init(); 0245 void datetimeInit(); 0246 void slotChangeValue(int); 0247 void formatChanged(int); 0248 void currencyChanged(const QString &); 0249 protected: 0250 KLineEdit* postfix; 0251 QSpinBox* precision; 0252 KLineEdit* prefix; 0253 KComboBox *format; 0254 KComboBox *currency; 0255 QLabel *currencyLabel; 0256 QRadioButton *generic; 0257 QRadioButton *number; 0258 QRadioButton *percent; 0259 QRadioButton *date; 0260 QRadioButton *datetime; 0261 QRadioButton *money; 0262 QRadioButton *scientific; 0263 QRadioButton *fraction; 0264 QRadioButton *time; 0265 QRadioButton *textFormat; 0266 QRadioButton *customFormat; 0267 QListWidget *listFormat; 0268 KLineEdit* customFormatEdit; 0269 QLabel *exampleLabel; 0270 CellFormatDialog *dlg; 0271 Format::Type cellFormatType, newFormatType; 0272 //test if value changed 0273 bool m_bFormatTypeChanged; 0274 bool m_bFormatColorChanged; 0275 }; 0276 0277 /** 0278 * \ingroup UI 0279 * Dialog page to set up the cell dimension, value alignment, etc. 0280 */ 0281 class CellFormatPagePosition : public QWidget, public Ui::PositionWidget 0282 { 0283 Q_OBJECT 0284 public: 0285 CellFormatPagePosition(QWidget *parent, CellFormatDialog *_dlg); 0286 0287 void apply(CustomStyle * style); 0288 void apply(StyleCommand *_obj); 0289 0290 double getSizeHeight() const; 0291 double getSizeWidth() const; 0292 bool getMergedCellState() const; 0293 0294 public Q_SLOTS: 0295 void slotChangeHeightState(); 0296 void slotChangeWidthState(); 0297 void slotChangeAngle(int); 0298 void slotStateChanged(int); 0299 void slotChangeVerticalState(); 0300 void slotChangeMultiState(); 0301 void slotChangeShrinkToFitState(); 0302 0303 protected: 0304 KoUnitDoubleSpinBox *width; 0305 KoUnitDoubleSpinBox *height; 0306 KoUnitDoubleSpinBox *m_indent; 0307 CellFormatDialog *dlg; 0308 bool m_bOptionText; 0309 }; 0310 0311 0312 0313 /** 0314 * \ingroup UI 0315 * The cell border preview. 0316 */ 0317 class Border : public QFrame 0318 { 0319 Q_OBJECT 0320 public: 0321 Border(QWidget *parent, const char *_name, bool _oneCol, bool _oneRow); 0322 Q_SIGNALS: 0323 void redraw(); 0324 void choosearea(QMouseEvent * _ev); 0325 protected: 0326 void paintEvent(QPaintEvent *_ev) override; 0327 void mousePressEvent(QMouseEvent* _ev) override; 0328 bool oneCol; 0329 bool oneRow; 0330 }; 0331 0332 /** 0333 * \ingroup UI 0334 * A button to set/unset a cell border. 0335 */ 0336 class BorderButton : public QPushButton 0337 { 0338 Q_OBJECT 0339 public: 0340 BorderButton(QWidget *parent, const char *_name); 0341 void setPenStyle(Qt::PenStyle _pat) { 0342 penStyle = _pat; 0343 } 0344 Qt::PenStyle getPenStyle() { 0345 return penStyle; 0346 } 0347 void setColor(const QColor &_col) { 0348 penColor = _col; 0349 } 0350 const QColor& getColor() { 0351 return penColor; 0352 } 0353 void setPenWidth(int _w) { 0354 penWidth = _w; 0355 } 0356 int getPenWidth() { 0357 return penWidth; 0358 } 0359 bool isChanged() { 0360 return changed; 0361 } 0362 void setChanged(bool _changed) { 0363 changed = _changed; 0364 } 0365 void setUndefined(); 0366 void unselect(); 0367 Q_SIGNALS: 0368 void clicked(BorderButton *); 0369 protected: 0370 void mousePressEvent(QMouseEvent *_ev) override; 0371 Qt::PenStyle penStyle; 0372 QColor penColor; 0373 int penWidth; 0374 bool changed; 0375 0376 }; 0377 0378 /** 0379 * \ingroup UI 0380 * Dialog page to select the cell borders. 0381 */ 0382 class CellFormatPageBorder : public QWidget 0383 { 0384 Q_OBJECT 0385 public: 0386 CellFormatPageBorder(QWidget *parent, CellFormatDialog *_dlg); 0387 0388 void apply(StyleCommand* obj); 0389 void invertState(BorderButton *_button); 0390 QPixmap paintFormatPixmap(Qt::PenStyle _style); 0391 0392 public Q_SLOTS: 0393 void changeState(BorderButton *_this); 0394 void preselect(BorderButton *_this); 0395 void draw(); 0396 void slotSetColorButton(const QColor &_color); 0397 void slotUnselect2(PatternSelect *_select); 0398 void loadIcon(const QString &iconName, BorderButton *_button); 0399 void slotPressEvent(QMouseEvent *_ev); 0400 void slotChangeStyle(int); 0401 void slotChangeStyle(const QString &); 0402 void cutomize_chosen_slot(); 0403 0404 protected: 0405 0406 Sheet* sheet; 0407 BorderButton* borderButtons[BorderType_END]; 0408 BorderButton* shortcutButtons[BorderShortcutType_END]; 0409 #define NUM_BORDER_PATTERNS 10 0410 0411 /* the patterns to choose from */ 0412 PatternSelect* pattern[NUM_BORDER_PATTERNS]; 0413 0414 /* the pattern box that is the 'preview' of what is selected above. */ 0415 PatternSelect* preview; 0416 KComboBox* size; 0417 KComboBox* style; 0418 KColorButton* color; 0419 QCheckBox* customize; 0420 QColor currentColor; 0421 Border *area; 0422 CellFormatDialog *dlg; 0423 private: 0424 0425 /*some helper functions to space some tasks apart */ 0426 void InitializeGrids(); 0427 void InitializeBorderButtons(); 0428 void InitializePatterns(); 0429 void SetConnections(); 0430 void applyTopOutline(StyleCommand* obj); 0431 void applyBottomOutline(StyleCommand* obj); 0432 void applyLeftOutline(StyleCommand* obj); 0433 void applyRightOutline(StyleCommand* obj); 0434 void applyVerticalOutline(StyleCommand* obj); 0435 void applyHorizontalOutline(StyleCommand* obj); 0436 void applyDiagonalOutline(StyleCommand* obj); 0437 }; 0438 0439 /** 0440 * \ingroup UI 0441 * Widget to preview a background brush. 0442 */ 0443 class BrushSelect : public QFrame 0444 { 0445 Q_OBJECT 0446 public: 0447 BrushSelect(QWidget *parent, const char *_name); 0448 0449 void setBrushStyle(Qt::BrushStyle _pat) { 0450 brushStyle = _pat; repaint(); 0451 } 0452 Qt::BrushStyle getBrushStyle() const { 0453 return brushStyle; 0454 } 0455 QColor getBrushColor() const { 0456 return brushColor; 0457 } 0458 void setBrushColor(const QColor &_c) { 0459 brushColor = _c; 0460 } 0461 void setPattern(const QColor &_color, Qt::BrushStyle _style); 0462 0463 Q_SIGNALS: 0464 void clicked(BrushSelect *_this); 0465 0466 public Q_SLOTS: 0467 void slotUnselect(); 0468 void slotSelect(); 0469 0470 protected: 0471 void paintEvent(QPaintEvent *_ev) override; 0472 void mousePressEvent(QMouseEvent *_ev) override; 0473 0474 Qt::BrushStyle brushStyle; 0475 QColor brushColor; 0476 bool selected; 0477 }; 0478 0479 0480 /** 0481 * \ingroup UI 0482 * Dialog page to set the cell background. 0483 */ 0484 class CellFormatPagePattern : public QWidget 0485 { 0486 Q_OBJECT 0487 public: 0488 CellFormatPagePattern(QWidget *parent, CellFormatDialog *_dlg); 0489 0490 void apply(CustomStyle * style); 0491 void apply(StyleCommand *_obj); 0492 0493 void init(); 0494 public Q_SLOTS: 0495 void slotUnselect2(BrushSelect *_select); 0496 void slotSetColorButton(const QColor &_color); 0497 void slotSetBackgroundColor(const QColor &_color); 0498 void slotNotAnyColor(); 0499 protected: 0500 BrushSelect *selectedBrush; 0501 BrushSelect *brush1; 0502 BrushSelect *brush2; 0503 BrushSelect *brush3; 0504 BrushSelect *brush4; 0505 BrushSelect *brush5; 0506 BrushSelect *brush6; 0507 BrushSelect *brush7; 0508 BrushSelect *brush8; 0509 BrushSelect *brush9; 0510 BrushSelect *brush10; 0511 BrushSelect *brush11; 0512 BrushSelect *brush12; 0513 BrushSelect *brush13; 0514 BrushSelect *brush14; 0515 BrushSelect *brush15; 0516 BrushSelect *current; 0517 KColorButton* color; 0518 QPushButton* notAnyColor; 0519 QColor currentColor; 0520 0521 QColor bgColor; 0522 KColorButton *bgColorButton; 0523 bool b_notAnyColor; 0524 CellFormatDialog *dlg; 0525 }; 0526 0527 0528 /** 0529 * \ingroup UI 0530 * Dialog page to set up cell protection. 0531 */ 0532 class CellFormatPageProtection : public QWidget, public Ui::ProtectionWidget 0533 { 0534 Q_OBJECT 0535 0536 public: 0537 CellFormatPageProtection(QWidget * parent, CellFormatDialog * _dlg); 0538 ~CellFormatPageProtection() override; 0539 ///when protection is set through Style Manager 0540 void apply(CustomStyle * style); 0541 void apply(StyleCommand * _obj); 0542 0543 protected: 0544 CellFormatDialog * m_dlg; 0545 bool m_isProtected; 0546 bool m_hideFormula; 0547 bool m_hideAll; 0548 bool m_dontPrint; 0549 }; 0550 0551 /** 0552 * \ingroup UI 0553 * Dialog to set the cell style. 0554 */ 0555 class CellFormatDialog : public KPageDialog 0556 { 0557 Q_OBJECT 0558 public: 0559 /** 0560 * Create a format dlg for the rectangular area in '_sheet'. 0561 */ 0562 CellFormatDialog(QWidget* parent, Selection* selection); 0563 CellFormatDialog(QWidget* parent, Selection* selection, CustomStyle* style, StyleManager* manager); 0564 0565 ~CellFormatDialog() override; 0566 0567 void init(); 0568 void initGUI(); 0569 void initMembers(); 0570 0571 void initParameters(const Style& _obj); 0572 void checkBorderRight(const Style& obj); 0573 void checkBorderLeft(const Style& obj); 0574 void checkBorderTop(const Style& obj); 0575 void checkBorderBottom(const Style& obj); 0576 void checkBorderVertical(const Style& obj); 0577 void checkBorderHorizontal(const Style& obj); 0578 0579 Sheet * getSheet() const { 0580 return m_sheet; 0581 } 0582 Selection* selection() const { 0583 return m_selection; 0584 } 0585 CustomStyle * getStyle() const { 0586 return m_style; 0587 } 0588 StyleManager * getStyleManager() const { 0589 return m_styleManager; 0590 } 0591 0592 bool isSingleCell() { 0593 return (left == right && top == bottom); 0594 } 0595 bool checkCircle(QString const & name, QString const & parent); 0596 0597 KLocale * locale() const; 0598 0599 void setOkButtonEnabled(bool enabled); 0600 0601 struct CellBorderFormat { 0602 int width; 0603 bool bStyle; 0604 QColor color; 0605 bool bColor; 0606 Qt::PenStyle style; 0607 }; 0608 0609 // The format of the selected area 0610 CellBorderFormat borders[BorderType_END]; 0611 0612 Qt::BrushStyle brushStyle; 0613 QColor brushColor; 0614 0615 bool oneCol; 0616 bool oneRow; 0617 0618 QString prefix; 0619 QString postfix; 0620 int precision; 0621 Style::FloatFormat floatFormat; 0622 bool bFloatFormat; 0623 Style::FloatColor floatColor; 0624 Currency m_currency; 0625 bool bFloatColor; 0626 bool bCurrency; 0627 QColor textColor; 0628 bool bTextColor; 0629 bool bTextFontBold; 0630 bool fontBold; 0631 bool bTextFontItalic; 0632 bool fontItalic; 0633 bool bTextFontSize; 0634 int fontSize; 0635 bool bTextFontFamily; 0636 QString fontFamily; 0637 bool bStrike; 0638 bool strike; 0639 bool bUnderline; 0640 bool underline; 0641 QFont font; 0642 QColor bgColor; 0643 bool bBgColor; 0644 QString actionText; 0645 Style::HAlign alignX; 0646 Style::VAlign alignY; 0647 QString styleName; 0648 QString styleParent; 0649 0650 bool bMultiRow; 0651 bool bVerticalText; 0652 bool bShrinkToFit; 0653 0654 bool bDontPrintText; 0655 bool bHideFormula; 0656 bool bHideAll; 0657 bool bIsProtected; 0658 0659 double defaultHeightSize; 0660 double defaultWidthSize; 0661 double heightSize; 0662 double widthSize; 0663 0664 double indent; 0665 0666 QPixmap* formatOnlyNegSignedPixmap; 0667 QPixmap* formatRedOnlyNegSignedPixmap; 0668 QPixmap* formatRedNeverSignedPixmap; 0669 QPixmap* formatAlwaysSignedPixmap; 0670 QPixmap* formatRedAlwaysSignedPixmap; 0671 0672 int textRotation; 0673 bool bTextRotation; 0674 0675 Format::Type formatType; 0676 bool bFormatType; 0677 0678 Value value; 0679 0680 bool isMerged; 0681 bool oneCell; 0682 0683 bool isRowSelected; 0684 bool isColumnSelected; 0685 0686 // The rectangular area for which this dlg has been opened. 0687 int left; 0688 int right; 0689 int top; 0690 int bottom; 0691 0692 0693 public Q_SLOTS: 0694 void slotApply(); 0695 0696 protected: 0697 0698 /** 0699 * Draws a pixmap showing a text consisting of two parts, @p _string1 and @p _string2 . 0700 * The parts' colors are given by @p _color1 and @p _color2 . 0701 */ 0702 QPixmap* paintFormatPixmap(const char *_string1, const QColor & _color1, 0703 const char *_string2, const QColor & _color2); 0704 0705 GeneralTab * generalPage; 0706 CellFormatPageFloat *floatPage; 0707 CellFormatPageBorder *borderPage; 0708 CellFormatPageFont *fontPage; 0709 CellFormatPagePosition *positionPage; 0710 CellFormatPagePattern *patternPage; 0711 CellFormatPageProtection *protectPage; 0712 0713 Sheet * m_sheet; 0714 Selection * m_selection; 0715 CustomStyle * m_style; 0716 StyleManager * m_styleManager; 0717 0718 void applyStyle(); 0719 }; 0720 0721 } // namespace Sheets 0722 } // namespace Calligra 0723 0724 #endif // CALLIGRA_SHEETS_LAYOUT_DIALOG