summaryrefslogtreecommitdiffstats
path: root/kspread/dialogs/kspread_dlg_layout.h
blob: 84b6d241a8ec64733212b0e9acac70fa41df0054 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
/* This file is part of the KDE project
   Copyright (C) 2002-2004 Ariya Hidayat <ariya@kde.org>
             (C) 2002-2003 Norbert Andres <nandres@web.de>
             (C) 2001-2003 Philipp Mueller <philipp.mueller@gmx.de>
             (C) 2002 John Dailey <dailey@vt.edu>
             (C) 1999-2002 Laurent Montel <montel@kde.org>
             (C) 1999-2002 Harri Porten <porten@kde.org>
             (C) 2000-2001 David Faure <faure@kde.org>
             (C) 1998-2000 Torben Weis <weis@kde.org>
             (C) 2000 Werner Trobin <trobin@kde.org>
             (C) 1999 Reginald Stadlbauer <reggie@kde.org>
             (C) 1998-1999 Stephan Kulow <coolo@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#ifndef __kspread_dlg_layout_h__
#define __kspread_dlg_layout_h__


#include <tqtabdialog.h>
#include <tqapplication.h>
#include <tqbuttongroup.h>
#include <tqgroupbox.h>
#include <knuminput.h>
#include <kcompletion.h>
#include "kspread_view.h"
#include "kspread_format.h"
#include "kspread_doc.h"
#include "kspread_value.h"
#include "position_cell_format.h"
#include "font_cell_format.h"
#include "protection_cell_format.h"

#include <tqpushbutton.h>
#include <tqcheckbox.h>

class KoUnitDoubleSpinBox;
class TQPixmap;
class TQRadioButton;
class TQPushButton;
class TQDate;
class TQTime;
class TQLabel;
class TQWidget;
class KLineEdit;
class TQFrame;
class TQListBox;
class TQCheckBox;
class KColorButton;
class TQComboBox;
class KComboBox;
class KoUnitDoubleSpinBox;

namespace KSpread
{
class Sheet;
class CustomStyle;
class StyleManager;
class CellFormatDialog;
class FormatManipulator;

enum BorderType
{
  BorderType_Top = 0,
  BorderType_Bottom,
  BorderType_Left,
  BorderType_Right,
  BorderType_Vertical,
  BorderType_Horizontal,
  BorderType_FallingDiagonal,
  BorderType_RisingDiagonal,
  BorderType_END
};

enum BorderShortcutType
{
  BorderShortcutType_Remove = 0,
  BorderShortcutType_All,
  BorderShortcutType_Outline,
  BorderShortcutType_END
};

class PatternSelect : public TQFrame
{
    TQ_OBJECT
  
public:
    PatternSelect( TQWidget *parent, const char *_name );

    void setPenStyle( Qt::PenStyle _pat ) { penStyle = _pat; repaint(); }
    Qt::PenStyle getPenStyle() { return penStyle; }
    void setColor( const TQColor &_col ) { penColor = _col; repaint(); }
    const TQColor& getColor() { return penColor; }
    void setPenWidth( int _w ) { penWidth = _w; repaint(); }
    int getPenWidth() { return penWidth; }

    void setPattern( const TQColor &_color, int _width, Qt::PenStyle _style );
    void setUndefined();
    void setDefined() { undefined = FALSE; repaint(); }

    bool isDefined() { return !undefined; }

signals:
    void clicked( PatternSelect *_this );

public slots:
    void slotUnselect();
    void slotSelect();

protected:
    virtual void paintEvent( TQPaintEvent *_ev );
    virtual void mousePressEvent( TQMouseEvent *_ev );

    Qt::PenStyle penStyle;
    TQColor penColor;
    int penWidth;

    bool selected;
    bool undefined;
};

class GeneralTab : public TQWidget
{
  TQ_OBJECT
  

 public:
  GeneralTab( TQWidget * parent, CellFormatDialog * _dlg );
  ~GeneralTab();

  bool apply( CustomStyle * style );

 protected slots:
  void slotNewParent( const TQString & parentName );
  void slotNameChanged();

 private:
  CellFormatDialog * m_dlg;
  KComboBox     * m_parentBox;
  KLineEdit     * m_nameEdit;

  TQString m_name;
  TQString m_parent;

  bool checkParent( const TQString & parentName );
  bool checkName();
};

/**
 */
class CellFormatPageFont : public FontTab
{
    TQ_OBJECT
  
public:
    CellFormatPageFont( TQWidget* parent, CellFormatDialog *_dlg );

    void apply( CustomStyle * style );
    void apply( FormatManipulator *_obj );

signals:
    /**
     * Connect to this to monitor the font as it as selected if you are
     * not running modal.
     */
    void fontSelected( const TQFont &font );

private slots:

    void      family_chosen_slot(const TQString & );
    void      size_chosen_slot(const TQString & );
    void      weight_chosen_slot(const TQString &);
    void      style_chosen_slot(const TQString &);
    void      underline_chosen_slot();
    void      strike_chosen_slot();
    void      display_example(const TQFont &font);
    void      slotSetTextColor( const TQColor &_color );

private:

    void setCombos();
    TQColor textColor;
    TQFont         selFont;
    bool fontChanged;
    bool bTextColorUndefined;
    CellFormatDialog *dlg;
};

/**
 * Format of numbers.
 * This widget is part of the format dialog.
 * It allows the user to cinfigure the way numbers are formatted.
 */
class CellFormatPageFloat : public TQWidget
{
    TQ_OBJECT
  
public:
    CellFormatPageFloat( TQWidget *parent, CellFormatDialog *_dlg );
    void apply( CustomStyle * style );
    void apply( FormatManipulator *_obj );

public slots:
    void slotChangeState();
    void makeformat();
    void updateFormatType();
    void init();
    void slotChangeValue(int);
    void formatChanged(int);
    void currencyChanged(const TQString &);
protected:
    TQLineEdit* postfix;
    KIntNumInput* precision;
    TQLineEdit* prefix;
    TQComboBox *format;
    TQComboBox *currency;
    TQLabel    *currencyLabel;
    TQRadioButton *generic;
    TQRadioButton *number;
    TQRadioButton *percent;
    TQRadioButton *date;
    TQRadioButton *money;
    TQRadioButton *scientific;
    TQRadioButton *fraction;
    TQRadioButton *time;
    TQRadioButton *textFormat;
    TQRadioButton *customFormat;
    TQListBox *listFormat;
    TQLineEdit* customFormatEdit;
    TQLabel *exampleLabel;
    CellFormatDialog *dlg;
    FormatType cellFormatType, newFormatType;
    //test if value changed
    bool m_bFormatTypeChanged;
    bool m_bFormatColorChanged;
};

class CellFormatPagePosition : public PositionTab
{
    TQ_OBJECT
  
public:
    CellFormatPagePosition( TQWidget *parent, CellFormatDialog *_dlg );

    void apply( CustomStyle * style );
    void apply( FormatManipulator *_obj );

    double getSizeHeight() const;
    double getSizeWidth() const;
    bool getMergedCellState() const;

public slots:
    void slotChangeHeightState();
    void slotChangeWidthState();
    void slotChangeAngle(int);
    void slotStateChanged(int);
    void slotChangeVerticalState();
    void slotChangeMultiState();

protected:
    KoUnitDoubleSpinBox *width;
    KoUnitDoubleSpinBox *height;
    KoUnitDoubleSpinBox *m_indent;
    CellFormatDialog *dlg;
    bool m_bOptionText;
};



class Border : public TQFrame
{
    TQ_OBJECT
  
public:
    Border( TQWidget *parent,const char *_name,bool _oneCol,bool _oneRow  );
signals:
    void redraw();
    void choosearea(TQMouseEvent * _ev);
protected:
    virtual void paintEvent( TQPaintEvent *_ev );
    virtual void mousePressEvent( TQMouseEvent* _ev );
    bool oneCol;
    bool oneRow;
};

class BorderButton : public TQPushButton
{
    TQ_OBJECT
  
public:
    BorderButton( TQWidget *parent, const char *_name );
    void setPenStyle( Qt::PenStyle _pat ) { penStyle = _pat;}
    Qt::PenStyle getPenStyle() { return penStyle; }
    void setColor( const TQColor &_col ) { penColor = _col; }
    const TQColor& getColor() { return penColor; }
    void setPenWidth( int _w ) { penWidth = _w; }
    int getPenWidth() { return penWidth; }
    bool isChanged() { return changed; }
    void setChanged(bool _changed ) { changed=_changed;}
    void setUndefined();
    void unselect();
 signals:
    void clicked(BorderButton *);
 protected:
    virtual void mousePressEvent( TQMouseEvent *_ev );
    Qt::PenStyle penStyle;
    TQColor penColor;
    int penWidth;
    bool changed;

};

class CellFormatPageBorder : public TQWidget
{
  TQ_OBJECT
  
public:
    CellFormatPageBorder( TQWidget *parent, CellFormatDialog *_dlg );

    void apply(FormatManipulator* obj);
    void invertState(BorderButton *_button);
    TQPixmap paintFormatPixmap(PenStyle _style);

public slots:
    void changeState(BorderButton *_this);
    void preselect( BorderButton *_this);
    void draw();
    void slotSetColorButton( const TQColor &_color );
    void slotUnselect2( PatternSelect *_select );
    void loadIcon( TQString pix,BorderButton *_button);
    void slotPressEvent(TQMouseEvent *_ev);
    void slotChangeStyle(int );
    void slotChangeStyle(const TQString & );
    void cutomize_chosen_slot();

protected:

  Sheet* sheet;
  BorderButton* borderButtons[BorderType_END];
  BorderButton* shortcutButtons[BorderShortcutType_END];
#define NUM_BORDER_PATTERNS 10

  /* the patterns to choose from */
  PatternSelect* pattern[NUM_BORDER_PATTERNS];

  /* the pattern box that is the 'preview' of what is selected above. */
  PatternSelect* preview;
  TQComboBox* size;
  TQComboBox* style;
  KColorButton* color;
  TQCheckBox* customize;
  TQColor currentColor;
  Border *area;
  CellFormatDialog *dlg;
private:

  /*some helper functions to space some tasks apart */
  void InitializeGrids();
  void InitializeBorderButtons();
  void InitializePatterns();
  void SetConnections();
  void applyTopOutline(FormatManipulator* obj);
  void applyBottomOutline(FormatManipulator* obj);
  void applyLeftOutline(FormatManipulator* obj);
  void applyRightOutline(FormatManipulator* obj);
  void applyVerticalOutline(FormatManipulator* obj);
  void applyHorizontalOutline(FormatManipulator* obj);
  void applyDiagonalOutline(FormatManipulator* obj);
};

class BrushSelect : public TQFrame
{
    TQ_OBJECT
  
public:
    BrushSelect( TQWidget *parent, const char *_name );

    void setBrushStyle( Qt::BrushStyle _pat ) { brushStyle = _pat; repaint(); }
    Qt::BrushStyle getBrushStyle() const { return brushStyle; }
    TQColor getBrushColor() const { return brushColor; }
    void setBrushColor(const TQColor &_c) { brushColor=_c;}
    void setPattern( const TQColor &_color, Qt::BrushStyle _style );

signals:
    void clicked( BrushSelect *_this );

public slots:
    void slotUnselect();
    void slotSelect();

protected:
    virtual void paintEvent( TQPaintEvent *_ev );
    virtual void mousePressEvent( TQMouseEvent *_ev );

    Qt::BrushStyle brushStyle;
    TQColor brushColor;
    bool selected;
};


class CellFormatPagePattern : public TQWidget
{
    TQ_OBJECT
  
public:
    CellFormatPagePattern( TQWidget *parent, CellFormatDialog *_dlg );

    void apply( CustomStyle * style );
    void apply( FormatManipulator *_obj );

    void init();
public slots:
    void slotUnselect2( BrushSelect *_select );
    void slotSetColorButton( const TQColor &_color );
    void slotSetBackgroundColor( const TQColor &_color );
    void slotNotAnyColor( );
protected:
    BrushSelect *selectedBrush;
    BrushSelect *brush1;
    BrushSelect *brush2;
    BrushSelect *brush3;
    BrushSelect *brush4;
    BrushSelect *brush5;
    BrushSelect *brush6;
    BrushSelect *brush7;
    BrushSelect *brush8;
    BrushSelect *brush9;
    BrushSelect *brush10;
    BrushSelect *brush11;
    BrushSelect *brush12;
    BrushSelect *brush13;
    BrushSelect *brush14;
    BrushSelect *brush15;
    BrushSelect *current;
    KColorButton* color;
    TQPushButton* notAnyColor;
    TQColor currentColor;

    TQColor bgColor;
    bool bBgColorUndefined;
    KColorButton *bgColorButton;
    bool b_notAnyColor;
    CellFormatDialog *dlg;
};

class CellFormatPageProtection : public ProtectionTab
{
  TQ_OBJECT
  

 public:
  CellFormatPageProtection( TQWidget * parent, CellFormatDialog * _dlg );
  ~CellFormatPageProtection();
  ///when protection is set through Style Manager
  void apply( CustomStyle * style );
  void apply( FormatManipulator * _obj );

 protected:
  CellFormatDialog * m_dlg;
  bool            m_isProtected;
  bool            m_hideFormula;
  bool            m_hideAll;
  bool            m_dontPrint;
};

/**
 * Dialog for the "Cell Format..." action
 */
class CellFormatDialog : public TQObject
{
    TQ_OBJECT
  
public:
    /**
     * Create a format dlg for the rectangular area in '_sheet'.
     */
    CellFormatDialog( View * _view, Sheet * _sheet );
    CellFormatDialog( View * _view, CustomStyle * _style, StyleManager * _manager,
                   Doc * doc );

    ~CellFormatDialog();

    void init();
    void initGUI();
    void initMembers();

    void initParameters(Format *_obj,int column,int row);
    void checkBorderRight(Format *obj,int x,int y);
    void checkBorderLeft(Format *obj,int x,int y);
    void checkBorderTop(Format *obj,int x,int y);
    void checkBorderBottom(Format *obj,int x,int y);
    void checkBorderVertical(Format *obj,int x,int y);
    void checkBorderHorizontal(Format *obj,int x,int y);
    /**
     * Run the dialogs event loop and return when closed.
     */
    int exec();

    Doc * getDoc() const { return m_doc; }
    Sheet * getSheet() const { return m_sheet; }
    CustomStyle * getStyle() const { return m_style; }
    StyleManager * getStyleManager() const { return m_styleManager; }

    bool isSingleCell() { return ( left == right && top == bottom ); }
    bool checkCircle( TQString const & name, TQString const & parent );

    TDELocale * locale() const { return m_pView->doc()->locale(); }


    struct CellBorderFormat
    {
      int width;
      bool bStyle;
      TQColor color;
      bool bColor;
      Qt::PenStyle style;
    };

    // The format of the selected area
    CellBorderFormat borders[BorderType_END];

    Qt::BrushStyle brushStyle;
    TQColor brushColor;

    bool oneCol;
    bool oneRow;

    TQString prefix;
    TQString postfix;
    int precision;
    Format::FloatFormat floatFormat;
    bool bFloatFormat;
    Format::FloatColor floatColor;
    Format::Currency   cCurrency;
    bool bFloatColor;
    bool bCurrency;
    TQColor textColor;
    bool bTextColor;
    bool bTextFontBold;
    bool textFontBold;
    bool bTextFontItalic;
    bool textFontItalic;
    bool bTextFontSize;
    int textFontSize;
    bool bTextFontFamily;
    TQString textFontFamily;
    bool bStrike;
    bool strike;
    bool bUnderline;
    bool underline;
    TQFont textFont;
    TQColor bgColor;
    bool bBgColor;
    TQString actionText;
    Format::Align alignX;
    Format::AlignY alignY;
    TQString styleName;
    TQString styleParent;

    bool bMultiRow;
    bool bVerticalText;

    bool bDontPrintText;
    bool bHideFormula;
    bool bHideAll;
    bool bIsProtected;

    double defaultHeightSize;
    double defaultWidthSize;
    double heightSize;
    double widthSize;

    double indent;

    TQPixmap* formatOnlyNegSignedPixmap;
    TQPixmap* formatRedOnlyNegSignedPixmap;
    TQPixmap* formatRedNeverSignedPixmap;
    TQPixmap* formatAlwaysSignedPixmap;
    TQPixmap* formatRedAlwaysSignedPixmap;

    int textRotation;
    bool bTextRotation;

    FormatType formatType;
    bool bFormatType;

    Value value;

    bool isMerged;
    bool oneCell;

    bool isRowSelected;
    bool isColumnSelected;

    // The rectangular area for which this dlg has been opened.
    int left;
    int right;
    int top;
    int bottom;


public slots:
    void slotApply();

protected:

    /**
     * Draws a pixmap showing a text consisting of two parts, @p _string1 and @p _string2 .
     * The parts' colors are given by @p _color1 and @p _color2 .
     */
    TQPixmap* paintFormatPixmap( const char *_string1, const TQColor & _color1,
				const char *_string2, const TQColor & _color2 );

    GeneralTab * generalPage;
    CellFormatPageFloat *floatPage;
    CellFormatPageBorder *borderPage;
    CellFormatPageFont *fontPage;
    CellFormatPagePosition *positionPage;
    CellFormatPagePattern *patternPage;
    CellFormatPageProtection *protectPage;
    TQTabDialog *tab;

    Doc   * m_doc;
    Sheet * m_sheet;
    View  * m_pView;
    CustomStyle * m_style;
    StyleManager * m_styleManager;

    void applyStyle();
};

} // namespace KSpread

#endif