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
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
|
/*
Copyright (c) 2003,2004,2005 Clarence Dang <dang@kde.org>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef KP_MAIN_WINDOW_H
#define KP_MAIN_WINDOW_H
#define DEBUG_KP_MAIN_WINDOW 0
#include <tqpoint.h>
#include <tqptrlist.h>
#include <tqsize.h>
#include <tqvaluevector.h>
#include <kmainwindow.h>
#include <kurl.h>
#include <kpdefs.h>
#include <kpdocumentsaveoptions.h>
#include <kppixmapfx.h>
class TQPainter;
class TQPoint;
class TQPopupMenu;
class TQRect;
class TQSize;
class TQStringList;
class TDEAction;
class TDEFontAction;
class TDEFontSizeAction;
class TDESelectAction;
class TDEToggleAction;
class TDEToolBar;
class KPrinter;
class TDERecentFilesAction;
class KScanDialog;
class TDEToggleFullScreenAction;
class kpColor;
class kpColorToolBar;
class kpCommand;
class kpCommandHistory;
class kpDocument;
class kpDocumentMetaInfo;
class kpDocumentSaveOptions;
class kpViewManager;
class kpViewScrollableContainer;
class kpSelection;
class kpSelectionTransparency;
class kpSingleKeyTriggersAction;
class kpSqueezedTextLabel;
class kpTextStyle;
class kpThumbnail;
class kpThumbnailView;
class kpTool;
class kpToolText;
class kpToolToolBar;
class kpZoomedView;
class kpMainWindow : public TDEMainWindow
{
Q_OBJECT
public:
// Opens a new window with a blank document.
kpMainWindow ();
// Opens a new window with the document specified by <url>
// or creates a blank document if <url> could not be opened.
kpMainWindow (const KURL &url);
// Opens a new window with the document <newDoc>
// (<newDoc> can be 0 although this would result in a new
// window without a document at all).
kpMainWindow (kpDocument *newDoc);
public:
double configColorSimilarity () const;
void configSetColorSimilarity (double val);
private:
bool m_configFirstTime;
bool m_configShowGrid;
bool m_configShowPath;
double m_configColorSimilarity;
bool m_configThumbnailShown;
TQRect m_configThumbnailGeometry;
bool m_configZoomedThumbnail;
void readGeneralSettings ();
void readThumbnailSettings ();
void init ();
// (only called for restoring a previous session e.g. starting KDE with
// a previously saved session; it's not called on normal KolourPaint
// startup)
virtual void readProperties (TDEConfig *cfg);
// (only called for saving the current session e.g. logging out of KDE
// with the KolourPaint window open; it's not called on normal KolourPaint
// exit)
virtual void saveProperties (TDEConfig *cfg);
public:
~kpMainWindow ();
private:
bool m_isFullyConstructed;
public:
kpDocument *document () const;
kpViewManager *viewManager () const;
kpColorToolBar *colorToolBar () const;
kpToolToolBar *toolToolBar () const;
kpCommandHistory *commandHistory () const;
private:
kpViewScrollableContainer *m_scrollView;
kpZoomedView *m_mainView;
kpThumbnail *m_thumbnail;
kpThumbnailView *m_thumbnailView;
kpDocument *m_document;
kpViewManager *m_viewManager;
kpColorToolBar *m_colorToolBar;
kpToolToolBar *m_toolToolBar;
kpCommandHistory *m_commandHistory;
private:
void setupActions ();
void enableDocumentActions (bool enable = true);
public:
bool actionsSingleKeyTriggersEnabled () const;
void enableActionsSingleKeyTriggers (bool enable = true);
private:
void setDocument (kpDocument *newDoc);
virtual bool queryClose ();
virtual void dragEnterEvent (TQDragEnterEvent *e);
virtual void dropEvent (TQDropEvent *e);
private slots:
void slotScrollViewAboutToScroll ();
void slotScrollViewAfterScroll ();
private:
virtual void moveEvent (TQMoveEvent *e);
private slots:
void slotUpdateCaption ();
void slotDocumentRestored ();
/*
* Tools
*/
private:
void setupToolActions ();
void createToolBox ();
void enableToolsDocumentActions (bool enable = true);
private slots:
void updateToolOptionPrevNextActionsEnabled ();
private:
kpTool *m_toolAirSpray, *m_toolBrush, *m_toolColorPicker,
*m_toolColorWasher, *m_toolCurve, *m_toolEllipse,
*m_toolEllipticalSelection, *m_toolEraser,
*m_toolFloodFill, *m_toolFreeFormSelection,
*m_toolLine, *m_toolPen, *m_toolPolygon,
*m_toolPolyline, *m_toolRectangle, *m_toolRectSelection,
*m_toolRoundedRectangle;
kpToolText *m_toolText;
TQPtrList <kpTool> m_tools;
int m_lastToolNumber;
bool m_toolActionsEnabled;
kpSingleKeyTriggersAction *m_actionPrevToolOptionGroup1,
*m_actionNextToolOptionGroup1,
*m_actionPrevToolOptionGroup2,
*m_actionNextToolOptionGroup2;
int m_settingSelectionTransparency;
int m_docResizeWidth, m_docResizeHeight;
bool m_docResizeToBeCompleted;
public:
kpTool *tool () const;
bool toolHasBegunShape () const;
bool toolIsASelectionTool (bool includingTextTool = true) const;
bool toolIsTextTool () const;
kpSelectionTransparency selectionTransparency () const;
// The drawing background color is set to <transparency>.transparentColor()
// if the <transparency> is in Transparent mode or if <forceColorChange>
// is true (not the default). [x]
//
// If <transparency> is in Opaque mode and <forceColorChange> is false,
// the background color is not changed because:
//
// 1. It is ignored by the selection in Opaque mode anyway.
// 2. This avoids irritating the user with an unnecessary background
// color change.
//
// The only case where you should set <forceColorChange> to true is in
// kpToolSelectionTransparencyCommand to ensure that the state
// is identical to when the command was constructed.
// Later: I don't think setting it to true is ever necessary since:
//
// 1. The background color only counts in Transparent mode.
//
// 2. Any kpToolSelectionTransparencyCommand that switches to
// Transparent mode will automatically set the background
// color due to the first part of [x] anyway.
//
// The other fields of <transparency> are copied into the main window
// as expected.
void setSelectionTransparency (const kpSelectionTransparency &transparency,
bool forceColorChange = false);
int settingSelectionTransparency () const;
private slots:
void slotToolSelected (kpTool *tool);
private:
void readLastTool ();
int toolNumber () const;
void saveLastTool ();
private:
bool maybeDragScrollingMainView () const;
private slots:
bool slotDragScroll (const TQPoint &docPoint,
const TQPoint &docLastPoint,
int zoomLevel,
bool *didSomething);
bool slotEndDragScroll ();
private slots:
void slotBeganDocResize ();
void slotContinuedDocResize (const TQSize &size);
void slotCancelledDocResize ();
void slotEndedDocResize (const TQSize &size);
void slotDocResizeMessageChanged (const TQString &string);
private slots:
void slotActionPrevToolOptionGroup1 ();
void slotActionNextToolOptionGroup1 ();
void slotActionPrevToolOptionGroup2 ();
void slotActionNextToolOptionGroup2 ();
public slots:
void slotToolAirSpray ();
void slotToolBrush ();
void slotToolColorPicker ();
void slotToolColorWasher ();
void slotToolCurve ();
void slotToolEllipse ();
void slotToolEllipticalSelection ();
void slotToolEraser ();
void slotToolFloodFill ();
void slotToolFreeFormSelection ();
void slotToolLine ();
void slotToolPen ();
void slotToolPolygon ();
void slotToolPolyline ();
void slotToolRectangle ();
void slotToolRectSelection ();
void slotToolRoundedRectangle ();
void slotToolText ();
/*
* File Menu
*/
private:
void setupFileMenuActions ();
void enableFileMenuDocumentActions (bool enable = true);
TDEAction *m_actionNew, *m_actionOpen;
TDERecentFilesAction *m_actionOpenRecent;
TDEAction *m_actionScan, *m_actionSave, *m_actionSaveAs, *m_actionExport,
*m_actionReload,
*m_actionPrint, *m_actionPrintPreview,
*m_actionMail,
*m_actionSetAsWallpaperTiled, *m_actionSetAsWallpaperCentered,
*m_actionClose, *m_actionQuit;
KScanDialog *m_scanDialog;
KURL m_lastExportURL;
kpDocumentSaveOptions m_lastExportSaveOptions;
bool m_exportFirstTime;
private:
void addRecentURL (const KURL &url);
private slots:
void slotNew ();
private:
TQSize defaultDocSize () const;
void saveDefaultDocSize (const TQSize &size);
private:
bool shouldOpenInNewWindow () const;
void setDocumentChoosingWindow (kpDocument *doc);
private:
kpDocument *openInternal (const KURL &url,
const TQSize &fallbackDocSize,
bool newDocSameNameIfNotExist);
// Same as above except that it:
//
// 1. Assumes a default fallback document size.
// 2. If the URL is successfully opened (with the special exception of
// the "kolourpaint doesnotexist.png" case), it is bubbled up to the
// top in the Recent Files Action.
//
// As a result of this behavior, this should only be called in response
// to a user open request e.g. File / Open or "kolourpaint doesexist.png".
// It should not be used for session restore - in that case, it does not
// make sense to bubble the Recent Files list.
bool open (const KURL &url, bool newDocSameNameIfNotExist = false);
KURL::List askForOpenURLs (const TQString &caption,
const TQString &startURL,
bool allowMultipleURLs = true);
private slots:
void slotOpen ();
void slotOpenRecent (const KURL &url);
void slotScan ();
void slotScanned (const TQImage &image, int);
bool save (bool localOnly = false);
bool slotSave ();
private:
KURL askForSaveURL (const TQString &caption,
const TQString &startURL,
const TQPixmap &pixmapToBeSaved,
const kpDocumentSaveOptions &startSaveOptions,
const kpDocumentMetaInfo &docMetaInfo,
const TQString &forcedSaveOptionsGroup,
bool localOnly,
kpDocumentSaveOptions *chosenSaveOptions,
bool isSavingForFirstTime,
bool *allowOverwritePrompt,
bool *allowLossyPrompt);
private slots:
bool saveAs (bool localOnly = false);
bool slotSaveAs ();
bool slotExport ();
void slotEnableReload ();
bool slotReload ();
private:
void sendFilenameToPrinter (KPrinter *printer);
void sendPixmapToPrinter (KPrinter *printer, bool showPrinterSetupDialog);
private slots:
void slotPrint ();
void slotPrintPreview ();
void slotMail ();
private:
void setAsWallpaper (bool centered);
private slots:
void slotSetAsWallpaperCentered ();
void slotSetAsWallpaperTiled ();
void slotClose ();
void slotQuit ();
/*
* Edit Menu
*/
private:
kpPixmapFX::WarnAboutLossInfo pasteWarnAboutLossInfo ();
void setupEditMenuActions ();
void enableEditMenuDocumentActions (bool enable = true);
bool m_editMenuDocumentActionsEnabled;
TDEAction *m_actionUndo, *m_actionRedo,
*m_actionCut, *m_actionCopy,
*m_actionPaste, *m_actionPasteInNewWindow,
*m_actionDelete,
*m_actionSelectAll, *m_actionDeselect,
*m_actionCopyToFile, *m_actionPasteFromFile;
KURL m_lastPasteFromURL;
KURL m_lastCopyToURL;
kpDocumentSaveOptions m_lastCopyToSaveOptions;
bool m_copyToFirstTime;
public:
TQPopupMenu *selectionToolRMBMenu ();
private slots:
void slotCut ();
void slotCopy ();
void slotEnablePaste ();
private:
TQRect calcUsefulPasteRect (int pixmapWidth, int pixmapHeight);
void paste (const kpSelection &sel,
bool forceTopLeft = false);
public:
// (<forceNewTextSelection> is ignored if <text> is empty)
void pasteText (const TQString &text,
bool forceNewTextSelection = false,
const TQPoint &newTextSelectionTopLeft = KP_INVALID_POINT);
void pasteTextAt (const TQString &text, const TQPoint &point,
// Allow tiny adjustment of <point> so that mouse
// pointer is not exactly on top of the topLeft of
// any new text selection (so that it doesn't look
// weird by being on top of a resize handle just after
// a paste).
bool allowNewTextSelectionPointShift = false);
public slots:
void slotPaste ();
private slots:
void slotPasteInNewWindow ();
public slots:
void slotDelete ();
void slotSelectAll ();
private:
void addDeselectFirstCommand (kpCommand *cmd);
public slots:
void slotDeselect ();
private slots:
void slotCopyToFile ();
void slotPasteFromFile ();
/*
* View Menu
*/
private:
bool m_viewMenuDocumentActionsEnabled;
void setupViewMenuActions ();
bool viewMenuDocumentActionsEnabled () const;
void enableViewMenuDocumentActions (bool enable = true);
void actionShowGridUpdate ();
TDEAction *m_actionFullScreenBIC,
*m_actionActualSize,
*m_actionFitToPage, *m_actionFitToWidth, *m_actionFitToHeight,
*m_actionZoomIn, *m_actionZoomOut;
TDESelectAction *m_actionZoom;
TDEToggleAction *m_actionShowGrid,
*m_actionShowThumbnail, *m_actionZoomedThumbnail;
TQValueVector <int> m_zoomList;
private:
void sendZoomListToActionZoom ();
int zoomLevelFromString (const TQString &string);
TQString zoomLevelToString (int zoomLevel);
void zoomTo (int zoomLevel, bool centerUnderCursor = false);
private slots:
void finishZoomTo ();
private slots:
void slotActualSize ();
void slotFitToPage ();
void slotFitToWidth ();
void slotFitToHeight ();
public:
void zoomIn (bool centerUnderCursor = false);
void zoomOut (bool centerUnderCursor = false);
public slots:
void slotZoomIn ();
void slotZoomOut ();
private:
void zoomAccordingToZoomAction (bool centerUnderCursor = false);
private slots:
void slotZoom ();
void slotShowGridToggled ();
private:
void updateMainViewGrid ();
private:
TQRect mapToGlobal (const TQRect &rect) const;
TQRect mapFromGlobal (const TQRect &rect) const;
private slots:
void slotDestroyThumbnailIfNotVisible (bool tnIsVisible);
void slotDestroyThumbnail ();
void slotDestroyThumbnailInitatedByUser ();
void slotCreateThumbnail ();
private:
TQTimer *m_thumbnailSaveConfigTimer;
public:
void notifyThumbnailGeometryChanged ();
private slots:
void slotSaveThumbnailGeometry ();
void slotShowThumbnailToggled ();
void updateThumbnailZoomed ();
void slotZoomedThumbnailToggled ();
void slotThumbnailShowRectangleToggled ();
private:
void enableViewZoomedThumbnail (bool enable = true);
void enableViewShowThumbnailRectangle (bool enable = true);
void enableThumbnailOptionActions (bool enable = true);
void createThumbnailView ();
void destroyThumbnailView ();
void updateThumbnail ();
/*
* Image Menu
*/
private:
bool isSelectionActive () const;
bool isTextSelection () const;
TQString autoCropText () const;
void setupImageMenuActions ();
void enableImageMenuDocumentActions (bool enable = true);
bool m_imageMenuDocumentActionsEnabled;
TDEAction *m_actionResizeScale,
*m_actionCrop, *m_actionAutoCrop,
*m_actionFlip, *m_actionRotate, *m_actionSkew,
*m_actionConvertToBlackAndWhite, *m_actionConvertToGrayscale,
*m_actionMoreEffects,
*m_actionInvertColors, *m_actionClear;
private slots:
void slotImageMenuUpdateDueToSelection ();
public:
kpColor backgroundColor (bool ofSelection = false) const;
void addImageOrSelectionCommand (kpCommand *cmd,
bool addSelCreateCmdIfSelAvail = true,
bool addSelPullCmdIfSelAvail = true);
private slots:
void slotResizeScale ();
public slots:
void slotCrop ();
private slots:
void slotAutoCrop ();
void slotFlip ();
void slotRotate ();
void slotSkew ();
void slotConvertToBlackAndWhite ();
void slotConvertToGrayscale ();
void slotInvertColors ();
void slotClear ();
void slotMoreEffects ();
/*
* Settings Menu
*/
private:
void setupSettingsMenuActions ();
void enableSettingsMenuDocumentActions (bool enable = true);
TDEToggleAction *m_actionShowPath;
TDEAction *m_actionKeyBindings, *m_actionConfigureToolbars, *m_actionConfigure;
TDEToggleFullScreenAction *m_actionFullScreen;
private slots:
void slotFullScreen ();
void slotEnableSettingsShowPath ();
void slotShowPathToggled ();
void slotKeyBindings ();
void slotConfigureToolBars ();
void slotNewToolBarConfig ();
void slotConfigure ();
/*
* Status Bar
*/
private:
bool m_statusBarCreated;
kpSqueezedTextLabel *m_statusBarMessageLabel;
bool m_statusBarShapeLastPointsInitialised;
TQPoint m_statusBarShapeLastStartPoint, m_statusBarShapeLastEndPoint;
bool m_statusBarShapeLastSizeInitialised;
TQSize m_statusBarShapeLastSize;
enum
{
StatusBarItemMessage,
StatusBarItemShapePoints,
StatusBarItemShapeSize,
StatusBarItemDocSize,
StatusBarItemDocDepth,
StatusBarItemZoom
};
void addPermanentStatusBarItem (int id, int maxTextLen);
void createStatusBar ();
private slots:
void setStatusBarMessage (const TQString &message = TQString());
void setStatusBarShapePoints (const TQPoint &startPoint = KP_INVALID_POINT,
const TQPoint &endPoint = KP_INVALID_POINT);
void setStatusBarShapeSize (const TQSize &size = KP_INVALID_SIZE);
void setStatusBarDocSize (const TQSize &size = KP_INVALID_SIZE);
void setStatusBarDocDepth (int depth = 0);
void setStatusBarZoom (int zoom = 0);
void recalculateStatusBarMessage ();
void recalculateStatusBarShape ();
void recalculateStatusBar ();
/*
* Text ToolBar
*/
private:
void setupTextToolBarActions ();
void readAndApplyTextSettings ();
public:
void enableTextToolBarActions (bool enable = true);
private slots:
void slotTextFontFamilyChanged ();
void slotTextFontSizeChanged ();
void slotTextBoldChanged ();
void slotTextItalicChanged ();
void slotTextUnderlineChanged ();
void slotTextStrikeThruChanged ();
public:
TDEToolBar *textToolBar ();
bool isTextStyleBackgroundOpaque () const;
kpTextStyle textStyle () const;
void setTextStyle (const kpTextStyle &textStyle_);
int settingTextStyle () const;
private:
TDEFontAction *m_actionTextFontFamily;
TDEFontSizeAction *m_actionTextFontSize;
TDEToggleAction *m_actionTextBold, *m_actionTextItalic,
*m_actionTextUnderline, *m_actionTextStrikeThru;
int m_settingTextStyle;
TQString m_textOldFontFamily;
int m_textOldFontSize;
/*
* Help Menu
*/
private:
void setupHelpMenuActions ();
void enableHelpMenuDocumentActions (bool enable = true);
private slots:
void slotHelpTakingScreenshots ();
void slotHelpTakingScreenshotsFollowLink (const TQString &link);
private:
// There is no need to maintain binary compatibility at this stage.
// The d-pointer is just so that you can experiment without recompiling
// the kitchen sink.
class kpMainWindowPrivate *d;
};
#endif // KP_MAIN_WINDOW_H
|