compile
[kdegraphics.git] / kolourpaint / mainWindow / kpMainWindow.h
blobe384b73acfc7e5a4ab0cbc97e23da0647e4e18aa
2 /*
3 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
4 All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #ifndef KP_MAIN_WINDOW_H
30 #define KP_MAIN_WINDOW_H
33 #include <kxmlguiwindow.h>
34 #include <kurl.h>
36 #include <kpDefs.h>
37 #include <kpPixmapFX.h>
38 #include <kpImage.h>
41 class QAction;
42 class QActionGroup;
43 class QDragEnterEvent;
44 class QDropEvent;
45 class QMenu;
46 class QMoveEvent;
47 class QPoint;
48 class QRect;
49 class QSize;
50 class QStringList;
52 class KConfigGroup;
53 class KFontAction;
54 class KFontSizeAction;
55 class KSelectAction;
56 class KToggleAction;
57 class KToolBar;
58 class QPrinter;
59 class KRecentFilesAction;
60 class KScanDialog;
61 class KToggleFullScreenAction;
63 class kpColor;
64 class kpColorCells;
65 class kpColorToolBar;
66 class kpCommand;
67 class kpCommandEnvironment;
68 class kpCommandHistory;
69 class kpDocument;
70 class kpDocumentEnvironment;
71 class kpDocumentMetaInfo;
72 class kpDocumentSaveOptions;
73 class kpViewManager;
74 class kpViewScrollableContainer;
75 class kpImageSelectionTransparency;
76 class kpSqueezedTextLabel;
77 class kpTextStyle;
78 class kpThumbnail;
79 class kpThumbnailView;
80 class kpTool;
81 class kpToolEnvironment;
82 class kpToolSelectionEnvironment;
83 class kpToolText;
84 class kpToolToolBar;
85 class kpTransformDialogEnvironment;
86 class kpZoomedView;
89 class kpMainWindow : public KXmlGuiWindow
91 Q_OBJECT
93 public:
94 // Opens a new window with a blank document.
95 kpMainWindow ();
97 // Opens a new window with the document specified by <url>
98 // or creates a blank document if <url> could not be opened.
99 kpMainWindow (const KUrl &url);
101 // Opens a new window with the document <newDoc>
102 // (<newDoc> can be 0 although this would result in a new
103 // window without a document at all).
104 kpMainWindow (kpDocument *newDoc);
106 private:
107 void readGeneralSettings ();
108 void readThumbnailSettings ();
110 // WARNING: This is not virtual in our parent, KXmlGuiWindow.
111 void createGUI ();
113 void init ();
115 // (only called for restoring a previous session e.g. starting KDE with
116 // a previously saved session; it's not called on normal KolourPaint
117 // startup)
118 virtual void readProperties (const KConfigGroup &configGroup);
119 // (only called for saving the current session e.g. logging out of KDE
120 // with the KolourPaint window open; it's not called on normal KolourPaint
121 // exit)
122 virtual void saveProperties (KConfigGroup &configGroup);
124 public:
125 ~kpMainWindow ();
127 public:
128 kpDocument *document () const;
129 kpDocumentEnvironment *documentEnvironment ();
130 kpViewManager *viewManager () const;
131 kpColorToolBar *colorToolBar () const;
132 kpColorCells *colorCells () const;
133 kpToolToolBar *toolToolBar () const;
134 kpCommandHistory *commandHistory () const;
135 kpCommandEnvironment *commandEnvironment ();
137 private:
138 void setupActions ();
139 void enableDocumentActions (bool enable = true);
141 private:
142 void setDocument (kpDocument *newDoc);
144 virtual void dragEnterEvent (QDragEnterEvent *e);
145 virtual void dropEvent (QDropEvent *e);
147 private slots:
148 void slotScrollViewAboutToScroll ();
149 void slotScrollViewAfterScroll ();
151 private:
152 virtual void moveEvent (QMoveEvent *e);
154 private slots:
155 void slotUpdateCaption ();
156 void slotDocumentRestored ();
160 // Tools
163 private:
164 kpToolSelectionEnvironment *toolSelectionEnvironment ();
165 kpToolEnvironment *toolEnvironment ();
167 void setupToolActions ();
168 void createToolBox ();
169 void enableToolsDocumentActions (bool enable = true);
171 private slots:
172 void updateToolOptionPrevNextActionsEnabled ();
173 void updateActionDrawOpaqueChecked ();
174 private:
175 void updateActionDrawOpaqueEnabled ();
177 public:
178 QActionGroup *toolsActionGroup ();
180 kpTool *tool () const;
182 bool toolHasBegunShape () const;
183 bool toolIsASelectionTool (bool includingTextTool = true) const;
184 bool toolIsTextTool () const;
186 private:
187 // Ends the current shape. If there is no shape currently being drawn,
188 // it does nothing.
190 // In general, call this at the start of every kpMainWindow slot,
191 // directly invoked by the _user_ (by activating an action or via another
192 // way), so that:
194 // 1. The document contains the pixels of that shape:
196 // Most tools have the shape, currently being drawn, layered above the
197 // document as a kpTempImage. In other words, the document does not
198 // yet contain the pixels of that shape. By ending the shape, the layer
199 // is pushed down onto the document so that it now contains those
200 // pixels. Your slot can now safely read the document as it's now
201 // consistent with what's on the screen.
203 // For example, consider the case where a line is being dragged out and
204 // CTRL+I is pressed to invert the image, while the mouse is still held
205 // down. The CTRL+I invert code (kpMainWindow::slotInvertColors()) must
206 // push the line kpTempImage onto the document before the invert can
207 // meaningfully proceed (else the invert will see the state of the document
208 // before the line was dragged out).
210 // Note that selection layers are not pushed down by this method.
211 // This is a feature, not a bug. The user would be annoyed if e.g.
212 // slotSave() happened to push down the selection. Use
213 // kpDocument::imageWithSelection() to get around this problem. You
214 // should still call toolEndShape() even if a selection is active
215 // -- this ends selection "shapes", which are actually things like
216 // selection moves or smearing operations, rather than the selections
217 // themselves.
219 // AND/OR:
221 // 2. The current tool is no longer in a drawing state:
223 // If your slot is going to bring up a new main window or modal dialog
224 // or at least some widget that acquires mouse or keyboard focus, this
225 // could confuse the tool if the tool is in the middle of a drawing
226 // operation.
228 // Do not call this in slots not invoked by the user. For instance,
229 // calling this method in response to an internal timer tick would be
230 // wrong. The user's drawing operation would unexpectedly finish and
231 // this would bewilder and irritate the user.
233 // TODO: Help / KolourPaint Handbook does not call this. I'm sure there
234 // are a few other actions that don't call this but should.
235 void toolEndShape ();
237 public:
238 kpImageSelectionTransparency imageSelectionTransparency () const;
239 // The drawing background color is set to <transparency>.transparentColor()
240 // if the <transparency> is in Transparent mode or if <forceColorChange>
241 // is true (not the default). [x]
243 // If <transparency> is in Opaque mode and <forceColorChange> is false,
244 // the background color is not changed because:
246 // 1. It is ignored by the selection in Opaque mode anyway.
247 // 2. This avoids irritating the user with an unnecessary background
248 // color change.
250 // The only case where you should set <forceColorChange> to true is in
251 // kpToolImageSelectionTransparencyCommand to ensure that the state
252 // is identical to when the command was constructed.
253 // Later: I don't think setting it to true is ever necessary since:
255 // 1. The background color only counts in Transparent mode.
257 // 2. Any kpToolImageSelectionTransparencyCommand that switches to
258 // Transparent mode will automatically set the background
259 // color due to the first part of [x] anyway.
261 // The other fields of <transparency> are copied into the main window
262 // as expected.
263 void setImageSelectionTransparency (const kpImageSelectionTransparency &transparency,
264 bool forceColorChange = false);
265 int settingImageSelectionTransparency () const;
267 private slots:
268 void slotToolSelected (kpTool *tool);
270 private:
271 void readLastTool ();
272 int toolNumber () const;
273 void saveLastTool ();
275 private:
276 bool maybeDragScrollingMainView () const;
277 private slots:
278 bool slotDragScroll (const QPoint &docPoint,
279 const QPoint &docLastPoint,
280 int zoomLevel,
281 bool *didSomething);
282 bool slotEndDragScroll ();
284 private slots:
285 void slotBeganDocResize ();
286 void slotContinuedDocResize (const QSize &size);
287 void slotCancelledDocResize ();
288 void slotEndedDocResize (const QSize &size);
290 void slotDocResizeMessageChanged (const QString &string);
292 private slots:
293 void slotActionPrevToolOptionGroup1 ();
294 void slotActionNextToolOptionGroup1 ();
295 void slotActionPrevToolOptionGroup2 ();
296 void slotActionNextToolOptionGroup2 ();
298 void slotActionDrawOpaqueToggled ();
299 void slotActionDrawColorSimilarity ();
301 public slots:
302 void slotToolSpraycan ();
303 void slotToolBrush ();
304 void slotToolColorEraser ();
305 void slotToolColorPicker ();
306 void slotToolCurve ();
307 void slotToolEllipse ();
308 void slotToolEllipticalSelection ();
309 void slotToolEraser ();
310 void slotToolFloodFill ();
311 void slotToolFreeFormSelection ();
312 void slotToolLine ();
313 void slotToolPen ();
314 void slotToolPolygon ();
315 void slotToolPolyline ();
316 void slotToolRectangle ();
317 void slotToolRectSelection ();
318 void slotToolRoundedRectangle ();
319 void slotToolText ();
320 void slotToolZoom ();
324 // File Menu
327 private:
328 void setupFileMenuActions ();
329 void enableFileMenuDocumentActions (bool enable = true);
331 void addRecentURL (const KUrl &url);
333 private slots:
334 void slotNew ();
336 private:
337 QSize defaultDocSize () const;
338 void saveDefaultDocSize (const QSize &size);
340 private:
341 bool shouldOpen ();
342 void setDocumentChoosingWindow (kpDocument *doc);
344 private:
345 kpDocument *openInternal (const KUrl &url,
346 const QSize &fallbackDocSize,
347 bool newDocSameNameIfNotExist);
348 // Same as above except that it:
350 // 1. Assumes a default fallback document size.
351 // 2. If the URL is successfully opened (with the special exception of
352 // the "kolourpaint doesnotexist.png" case), it is bubbled up to the
353 // top in the Recent Files Action.
355 // As a result of this behavior, this should only be called in response
356 // to a user open request e.g. File / Open or "kolourpaint doesexist.png".
357 // It should not be used for session restore - in that case, it does not
358 // make sense to bubble the Recent Files list.
359 bool open (const KUrl &url, bool newDocSameNameIfNotExist = false);
361 KUrl::List askForOpenURLs (const QString &caption,
362 const QString &startURL,
363 bool allowMultipleURLs = true);
365 private slots:
366 void slotOpen ();
367 void slotOpenRecent (const KUrl &url);
369 void slotScan ();
370 void slotScanned (const QImage &image, int);
372 void slotProperties ();
374 bool save (bool localOnly = false);
375 bool slotSave ();
377 private:
378 KUrl askForSaveURL (const QString &caption,
379 const QString &startURL,
380 const kpImage &imageToBeSaved,
381 const kpDocumentSaveOptions &startSaveOptions,
382 const kpDocumentMetaInfo &docMetaInfo,
383 const QString &forcedSaveOptionsGroup,
384 bool localOnly,
385 kpDocumentSaveOptions *chosenSaveOptions,
386 bool isSavingForFirstTime,
387 bool *allowOverwritePrompt,
388 bool *allowLossyPrompt);
390 private slots:
391 bool saveAs (bool localOnly = false);
392 bool slotSaveAs ();
394 bool slotExport ();
396 void slotEnableReload ();
397 bool slotReload ();
399 private:
400 void sendDocumentNameToPrinter (QPrinter *printer);
401 void sendImageToPrinter (QPrinter *printer, bool showPrinterSetupDialog);
403 private slots:
404 void slotPrint ();
405 void slotPrintPreview ();
407 void slotMail ();
409 private:
410 void setAsWallpaper (bool centered);
411 private slots:
412 void slotSetAsWallpaperCentered ();
413 void slotSetAsWallpaperTiled ();
415 bool queryCloseDocument ();
416 virtual bool queryClose ();
418 void slotClose ();
419 void slotQuit ();
423 // Edit Menu
426 private:
427 kpPixmapFX::WarnAboutLossInfo pasteWarnAboutLossInfo ();
428 void setupEditMenuActions ();
429 void enableEditMenuDocumentActions (bool enable = true);
431 public:
432 QMenu *selectionToolRMBMenu ();
434 private slots:
435 void slotCut ();
436 void slotCopy ();
437 void slotEnablePaste ();
438 private:
439 QRect calcUsefulPasteRect (int imageWidth, int imageHeight);
440 // (it is possible to paste a selection border i.e. a selection with no content)
441 void paste (const kpAbstractSelection &sel,
442 bool forceTopLeft = false);
443 public:
444 // (<forceNewTextSelection> is ignored if <text> is empty)
445 void pasteText (const QString &text,
446 bool forceNewTextSelection = false,
447 const QPoint &newTextSelectionTopLeft = KP_INVALID_POINT);
448 void pasteTextAt (const QString &text, const QPoint &point,
449 // Allow tiny adjustment of <point> so that mouse
450 // pointer is not exactly on top of the topLeft of
451 // any new text selection (so that it doesn't look
452 // weird by being on top of a resize handle just after
453 // a paste).
454 bool allowNewTextSelectionPointShift = false);
455 public slots:
456 void slotPaste ();
457 private slots:
458 void slotPasteInNewWindow ();
459 public slots:
460 void slotDelete ();
462 void slotSelectAll ();
463 private:
464 void addDeselectFirstCommand (kpCommand *cmd);
465 public slots:
466 void slotDeselect ();
467 private slots:
468 void slotCopyToFile ();
469 void slotPasteFromFile ();
473 // View Menu
476 private:
477 void setupViewMenuActions ();
479 bool viewMenuDocumentActionsEnabled () const;
480 void enableViewMenuDocumentActions (bool enable = true);
482 private:
483 void actionShowGridUpdate ();
484 private slots:
485 void slotShowGridToggled ();
486 private:
487 void updateMainViewGrid ();
489 private:
490 QRect mapToGlobal (const QRect &rect) const;
491 QRect mapFromGlobal (const QRect &rect) const;
495 // View Menu - Zoom
498 private:
499 void setupViewMenuZoomActions ();
500 void enableViewMenuZoomDocumentActions (bool enable);
502 private:
503 void sendZoomListToActionZoom ();
505 void zoomToPre (int zoomLevel);
506 void zoomToPost ();
508 public:
509 void zoomTo (int zoomLevel, bool centerUnderCursor = false);
510 void zoomToRect (const QRect &normalizedDocRect,
511 bool accountForGrips,
512 bool careAboutWidth, bool careAboutHeight);
514 public slots:
515 void slotActualSize ();
516 void slotFitToPage ();
517 void slotFitToWidth ();
518 void slotFitToHeight ();
520 public:
521 void zoomIn (bool centerUnderCursor = false);
522 void zoomOut (bool centerUnderCursor = false);
524 public slots:
525 void slotZoomIn ();
526 void slotZoomOut ();
528 private:
529 void zoomAccordingToZoomAction (bool centerUnderCursor = false);
531 private slots:
532 void slotZoom ();
536 // View Menu - Thumbnail
539 private:
540 void setupViewMenuThumbnailActions ();
541 void enableViewMenuThumbnailDocumentActions (bool enable);
543 private slots:
544 void slotDestroyThumbnail ();
545 void slotDestroyThumbnailInitatedByUser ();
546 void slotCreateThumbnail ();
548 public:
549 void notifyThumbnailGeometryChanged ();
551 private slots:
552 void slotSaveThumbnailGeometry ();
553 void slotShowThumbnailToggled ();
554 void updateThumbnailZoomed ();
555 void slotZoomedThumbnailToggled ();
556 void slotThumbnailShowRectangleToggled ();
558 private:
559 void enableViewZoomedThumbnail (bool enable = true);
560 void enableViewShowThumbnailRectangle (bool enable = true);
561 void enableThumbnailOptionActions (bool enable = true);
562 void createThumbnailView ();
563 void destroyThumbnailView ();
564 void updateThumbnail ();
568 // Image Menu
571 private:
572 kpTransformDialogEnvironment *transformDialogEnvironment ();
574 bool isSelectionActive () const;
575 bool isTextSelection () const;
577 QString autoCropText () const;
579 void setupImageMenuActions ();
580 void enableImageMenuDocumentActions (bool enable = true);
582 private slots:
583 void slotImageMenuUpdateDueToSelection ();
585 public:
586 kpColor backgroundColor (bool ofSelection = false) const;
587 void addImageOrSelectionCommand (kpCommand *cmd,
588 bool addSelCreateCmdIfSelAvail = true,
589 bool addSelContentCmdIfSelAvail = true);
591 private slots:
592 void slotResizeScale ();
593 public slots:
594 void slotCrop ();
595 private slots:
596 void slotAutoCrop ();
597 void slotFlip ();
599 void slotRotate ();
600 void slotRotate270 ();
601 void slotRotate90 ();
603 void slotSkew ();
604 void slotConvertToBlackAndWhite ();
605 void slotConvertToGrayscale ();
606 void slotInvertColors ();
607 void slotClear ();
608 void slotMoreEffects ();
612 // Colors Menu
615 private:
616 void setupColorsMenuActions ();
617 void createColorBox ();
618 void enableColorsMenuDocumentActions (bool enable);
619 private slots:
620 void slotUpdateColorsDeleteRowActionEnabled ();
622 private:
623 void deselectActionColorsKDE ();
625 bool queryCloseColors ();
627 private:
628 void openDefaultColors ();
629 private slots:
630 void slotColorsDefault ();
632 private:
633 bool openKDEColors (const QString &name);
634 private slots:
635 void slotColorsKDE ();
637 private:
638 bool openColors (const KUrl &url);
639 private slots:
640 void slotColorsOpen ();
642 void slotColorsReload ();
644 bool slotColorsSave ();
645 bool slotColorsSaveAs ();
647 void slotColorsAppendRow ();
648 void slotColorsDeleteRow ();
652 // Settings Menu
655 private:
656 void setupSettingsMenuActions ();
657 void enableSettingsMenuDocumentActions (bool enable = true);
659 private slots:
660 void slotFullScreen ();
662 void slotEnableSettingsShowPath ();
663 void slotShowPathToggled ();
665 void slotKeyBindings ();
667 void slotConfigureToolBars ();
668 void slotNewToolBarConfig ();
670 void slotConfigure ();
674 // Status Bar
677 private:
678 enum
680 StatusBarItemMessage,
681 StatusBarItemShapePoints,
682 StatusBarItemShapeSize,
683 StatusBarItemDocSize,
684 StatusBarItemDocDepth,
685 StatusBarItemZoom
688 void addPermanentStatusBarItem (int id, int maxTextLen);
689 void createStatusBar ();
691 private slots:
692 void setStatusBarMessage (const QString &message = QString());
693 void setStatusBarShapePoints (const QPoint &startPoint = KP_INVALID_POINT,
694 const QPoint &endPoint = KP_INVALID_POINT);
695 void setStatusBarShapeSize (const QSize &size = KP_INVALID_SIZE);
696 void setStatusBarDocSize (const QSize &size = KP_INVALID_SIZE);
697 void setStatusBarDocDepth (int depth = 0);
698 void setStatusBarZoom (int zoom = 0);
700 void recalculateStatusBarMessage ();
701 void recalculateStatusBarShape ();
703 void recalculateStatusBar ();
707 // Text ToolBar
710 private:
711 void setupTextToolBarActions ();
712 void readAndApplyTextSettings ();
714 public:
715 void enableTextToolBarActions (bool enable = true);
717 private slots:
718 void slotTextFontFamilyChanged ();
719 void slotTextFontSizeChanged ();
720 void slotTextBoldChanged ();
721 void slotTextItalicChanged ();
722 void slotTextUnderlineChanged ();
723 void slotTextStrikeThruChanged ();
725 public:
726 KToolBar *textToolBar ();
727 bool isTextStyleBackgroundOpaque () const;
728 kpTextStyle textStyle () const;
729 void setTextStyle (const kpTextStyle &textStyle_);
730 int settingTextStyle () const;
734 // Help Menu
737 private:
738 void setupHelpMenuActions ();
739 void enableHelpMenuDocumentActions (bool enable = true);
741 private slots:
742 void slotHelpTakingScreenshots ();
743 void slotHelpTakingScreenshotsFollowLink (const QString &link);
746 private:
747 struct kpMainWindowPrivate *d;
751 #endif // KP_MAIN_WINDOW_H