krita

kis_view.h

00001 /*
00002  *  Copyright (c) 1999 Matthias Elter  <me@kde.org>
00003  *                1999 Michael Koch    <koch@kde.org>
00004  *                1999 Carsten Pfeiffer <pfeiffer@kde.org>
00005  *                2002 Patrick Julien <freak@codepimps.org>
00006  *                2004 Clarence Dang <dang@kde.org>
00007  *
00008  *  This program is free software; you can redistribute it and/or modify
00009  *  it under the terms of the GNU General Public License as published by
00010  *  the Free Software Foundation; either version 2 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  This program is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  *  GNU General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU General Public License
00019  *  along with this program; if not, write to the Free Software
00020  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00021  */
00022 
00023 #ifndef KIS_VIEW_H_
00024 #define KIS_VIEW_H_
00025 
00026 #ifdef HAVE_CONFIG_H
00027 #include <config.h>
00028 #endif
00029 
00030 #include <list>
00031 
00032 #include <qdatetime.h>
00033 #include <qpixmap.h>
00034 #include <qstringlist.h>
00035 #include <qtimer.h>
00036 
00037 #include <ksqueezedtextlabel.h>
00038 #include <kdebug.h>
00039 #include <kxmlguibuilder.h>
00040 #include <kxmlguiclient.h>
00041 #include <KoView.h>
00042 
00043 #include "kis_canvas_controller.h"
00044 #include "kis_canvas_subject.h"
00045 #include "kis_global.h"
00046 // #include "kis_debug_areas.h"
00047 #include "kis_types.h"
00048 #include "kis_profile.h"
00049 #include "kis_opengl_image_context.h"
00050 #include "kis_id.h"
00051 #include "koffice_export.h"
00052 #include "kis_color.h"
00053 #include "kis_input_device.h"
00054 
00055 class QButton;
00056 class QLabel;
00057 class QPaintEvent;
00058 class QScrollBar;
00059 class QWidget;
00060 class QPopup;
00061 class QPopupMenu;
00062 
00063 class DCOPObject;
00064 class KAction;
00065 class KActionMenu;
00066 class KPrinter;
00067 class KToggleAction;
00068 class KToolBar;
00069 
00070 class KoPartSelectAction;
00071 class KoDocumentEntry;
00072 class KoIconItem;
00073 class KoTabBar;
00074 class KoPaletteManager;
00075 class KoGrayWidget;
00076 class KoHSVWidget;
00077 class KoRGBWidget;
00078 
00079 class KisBirdEyeBox;
00080 class KisBrush;
00081 class KisButtonPressEvent;
00082 class KisButtonReleaseEvent;
00083 class KisCanvas;
00084 class KisCanvasObserver;
00085 class KisCompositeOp;
00086 class KisControlFrame;
00087 class KisDoc;
00088 class KisDoubleClickEvent;
00089 class KisFilterManager;
00090 class KisFilterStrategy;
00091 class KisGradient;
00092 class KisGridManager;
00093 class KisPerspectiveGridManager;
00094 class KisLabelProgress;
00095 class KisLayerBox;
00096 class KisMoveEvent;
00097 class KisPaletteWidget;
00098 class KisPattern;
00099 class KisPoint;
00100 class KisRect;
00101 class KisResource;
00102 class KisResourceMediator;
00103 class KisRuler;
00104 class KisSelectionManager;
00105 class KoToolBox;
00106 class KisToolControllerInterface;
00107 class KisToolManager;
00108 class KisUndoAdapter;
00109 class KisFilterConfiguration;
00110 class KisPartLayerHandler;
00111 class KisPaintOpSettings;
00112 
00113 class KRITA_EXPORT KisView
00114     : public KoView,
00115       public KisCanvasSubject,
00116       public KXMLGUIBuilder,
00117       private KisCanvasController
00118 {
00119 
00120     Q_OBJECT
00121 
00122     typedef KoView super;
00123 
00124     typedef std::list<KisCanvasObserver*> vKisCanvasObserver;
00125     typedef vKisCanvasObserver::iterator vKisCanvasObserver_it;
00126     typedef vKisCanvasObserver::const_iterator vKisCanvasObserver_cit;
00127 
00128 public:
00129     KisView(KisDoc *doc, KisUndoAdapter *adapter, QWidget *parent = 0, const char *name = 0);
00130     virtual ~KisView();
00131 
00132 public: // KXMLGUIBuilder implementation
00133 
00134     virtual QWidget *createContainer( QWidget *parent, int index, const QDomElement &element, int &id );
00135     virtual void removeContainer( QWidget *container, QWidget *parent, QDomElement &element, int id );
00136 
00137 public: // KoView implementation
00138     virtual bool eventFilter(QObject *o, QEvent *e);
00139 
00140     virtual DCOPObject* dcopObject();
00141 
00142     virtual void print(KPrinter &printer);
00143     virtual void setupPrinter(KPrinter &printer);
00144 
00145     virtual void updateReadWrite(bool readwrite);
00146     virtual void guiActivateEvent(KParts::GUIActivateEvent *event);
00147 
00148     virtual int leftBorder() const;
00149     virtual int rightBorder() const;
00150     virtual int topBorder() const;
00151     virtual int bottomBorder() const;
00152 
00153     Q_INT32 docWidth() const;
00154     Q_INT32 docHeight() const;
00155 
00156     void updateStatusBarSelectionLabel();
00157 
00158     virtual QPoint applyViewTransformations(const QPoint& p) const;
00159     virtual QPoint reverseViewTransformations( const QPoint& p) const;
00160     virtual void canvasAddChild(KoViewChild *child);
00161 
00162 signals:
00163 
00164     void brushChanged(KisBrush * brush);
00165     void gradientChanged(KisGradient * gradient);
00166     void patternChanged(KisPattern * pattern);
00167     void paintopChanged(KisID paintop, const KisPaintOpSettings *paintopSettings);
00172     void currentColorSpaceChanged(KisColorSpace* cs);
00173     void cursorPosition(Q_INT32 xpos, Q_INT32 ypos);
00174 
00175     void sigFGQColorChanged(const QColor &);
00176     void sigBGQColorChanged(const QColor &);
00177 
00178     void sigInputDeviceChanged(const KisInputDevice& inputDevice);
00179 
00180     /*
00181      * Emitted whenever the zoom or scroll values change.
00182      */
00183     void viewTransformationsChanged();
00184 
00185 public slots:
00186 
00187     void slotSetFGColor(const KisColor& c);
00188     void slotSetBGColor(const KisColor& c);
00189 
00190     void rotateLayer180();
00191     void rotateLayerLeft90();
00192     void rotateLayerRight90();
00193     void mirrorLayerX();
00194     void mirrorLayerY();
00195     void scaleLayer(double sx, double sy, KisFilterStrategy *filterStrategy);
00196     void rotateLayer(double angle);
00197     void shearLayer(double angleX, double angleY);
00198 
00199     void slotCreateMask();
00200     void slotMaskFromSelection();
00201     void slotMaskToSelection();
00202     void slotApplyMask();
00203     void slotRemoveMask();
00204     void slotEditMask();
00205     void slotShowMask();
00206 
00207     void brushActivated(KisResource *brush);
00208     void patternActivated(KisResource *pattern);
00209     void gradientActivated(KisResource *gradient);
00210     void paintopActivated(const KisID & paintop, const KisPaintOpSettings *paintopSettings);
00211 
00212 
00213 public:
00214     virtual void mouseMoveEvent(QMouseEvent *e);
00215 
00216     void resizeCurrentImage(Q_INT32 w, Q_INT32 h, bool cropLayers = false);
00217     void scaleCurrentImage(double sx, double sy, KisFilterStrategy *filterStrategy);
00218     void rotateCurrentImage(double angle);
00219     void shearCurrentImage(double angleX, double angleY);
00220 
00221     void insertPart(const QRect& viewRect, const KoDocumentEntry& entry,
00222                     KisGroupLayerSP parent, KisLayerSP above);
00223 
00232     Q_INT32 importImage(const KURL& url = KURL());
00233 protected:
00234 
00235     virtual void resizeEvent(QResizeEvent*); // From QWidget
00236     virtual void styleChange(QStyle& oldStyle); // From QWidget
00237     virtual void paletteChange(const QPalette& oldPalette); // From QWidget
00238     virtual void showEvent(QShowEvent *);
00239 
00240 protected slots:
00241     virtual void slotChildActivated(bool a); // from KoView
00242 
00243 // -------------------------------------------------------------------------//
00244 //                    KisCanvasSubject implementation
00245 // -------------------------------------------------------------------------//
00246 public:
00247 
00248     KisCanvasSubject * canvasSubject() { return this; };
00249 
00250 private:
00251 
00252     virtual KisImageSP currentImg() const;
00253 
00254     virtual void attach(KisCanvasObserver *observer);
00255     virtual void detach(KisCanvasObserver *observer);
00256     virtual void notifyObservers();
00257 
00258     virtual KisColor bgColor() const;
00259     virtual void setBGColor(const KisColor& c);
00260 
00261     virtual KisColor fgColor() const;
00262     virtual void setFGColor(const KisColor& c);
00263 
00264     float HDRExposure() const;
00265     void setHDRExposure(float exposure);
00266 
00267     virtual KisBrush *currentBrush() const;
00268     virtual KisPattern *currentPattern() const;
00269     virtual KisGradient *currentGradient() const;
00270     virtual KisID currentPaintop() const;
00271     virtual const KisPaintOpSettings *currentPaintopSettings() const;
00272 
00273     virtual double zoomFactor() const;
00274 
00275     virtual KisUndoAdapter *undoAdapter() const;
00276 
00277     virtual KisCanvasController *canvasController() const;
00278     virtual KisToolControllerInterface *toolController() const;
00279 
00280     virtual KisProgressDisplayInterface *progressDisplay() const;
00281 
00282     virtual KisDoc * document() const;
00283 
00284     inline KisGridManager * gridManager() { return m_gridManager; }
00285     inline KisPerspectiveGridManager* perspectiveGridManager() { return m_perspectiveGridManager; }
00286     
00287     inline KisSelectionManager * selectionManager() { return m_selectionManager; }
00288 
00289     KoPaletteManager * paletteManager();
00290 
00291     KisProfile *  monitorProfile();
00292 
00293 
00294 // -------------------------------------------------------------------------//
00295 //                    KisCanvasController implementation
00296 // -------------------------------------------------------------------------//
00297 
00298 public:
00299 
00300     KisCanvasController * getCanvasController() { return this; };
00301 
00302 
00303 private slots:
00304     virtual void updateCanvas();
00305 
00306     void updateStatusBarZoomLabel();
00307     void updateStatusBarProfileLabel();
00308 
00309 private:
00310     virtual KisCanvas *kiscanvas() const;
00311     
00312     virtual Q_INT32 horzValue() const;
00313     virtual Q_INT32 vertValue() const;
00314 
00315     virtual void scrollTo(Q_INT32 x, Q_INT32 y);
00316 
00317     virtual void updateCanvas(Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h);
00318     virtual void updateCanvas(const QRect& imageRect);
00319 
00320     virtual void zoomIn();
00321     virtual void zoomIn(Q_INT32 x, Q_INT32 y);
00322 
00323     virtual void zoomOut();
00324     virtual void zoomOut(Q_INT32 x, Q_INT32 y);
00325 
00326     virtual void zoomTo(Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h);
00327     virtual void zoomTo(const QRect& r);
00328     virtual void zoomTo(const KisRect& r);
00329     virtual void zoomAroundPoint(double x, double y, double zf);
00330 
00331     virtual QPoint viewToWindow(const QPoint& pt);
00332     virtual QPoint viewToWindow(const QPoint& pt) const;
00333     virtual KisPoint viewToWindow(const KisPoint& pt);
00334     virtual QRect viewToWindow(const QRect& rc);
00335     virtual KisRect viewToWindow(const KisRect& rc);
00336     virtual void viewToWindow(Q_INT32 *x, Q_INT32 *y);
00337 
00338     virtual QPoint windowToView(const QPoint& pt);
00339     virtual QPoint windowToView(const QPoint& pt) const;
00340     virtual KisPoint windowToView(const KisPoint& pt);
00341     virtual QRect windowToView(const QRect& rc);
00342     virtual KisRect windowToView(const KisRect& rc);
00343     virtual void windowToView(Q_INT32 *x, Q_INT32 *y);
00344 
00345     virtual QCursor setCanvasCursor(const QCursor & cursor);
00346 
00347     void setInputDevice(KisInputDevice inputDevice);
00348     KisInputDevice currentInputDevice() const;
00349 
00350 // -------------------------------------------------------------------------//
00351 //                      KisView internals
00352 // -------------------------------------------------------------------------//
00353 
00354 private:
00355 
00356     void connectCurrentImg();
00357     void disconnectCurrentImg();
00358 //    void eraseGuides();
00359 //    void paintGuides();
00360 //    void updateGuides();
00361 //    void viewGuideLines();
00362 
00363     void imgUpdateGUI();
00364 
00365     void layerUpdateGUI(bool enable);
00366     void createLayerBox();
00367     void createDockers();
00368 
00369     void paintToolOverlay(const QRegion& region);
00370 
00371     void paintQPaintDeviceView(const QRegion& canvasRegion);
00372     void paintOpenGLView(const QRect& canvasRect);
00373 
00374     void updateQPaintDeviceCanvas(const QRect& imageRect);
00375     void updateOpenGLCanvas(const QRect& imageRect);
00376 
00380     void refreshKisCanvas();
00381 
00382     void selectionDisplayToggled(bool displaySelection);
00383 
00384     bool activeLayerHasSelection();
00385 
00389     void resetMonitorProfile();
00390 
00391     void setupActions();
00392     void setupCanvas();
00393     void setupRulers();
00394     void setupScrollBars();
00395     void setupStatusBar();
00396 
00397 
00398     KisFilterManager * filterManager() { return m_filterManager; }
00399     void setCurrentImage(KisImageSP image);
00400 
00404     double nextZoomInLevel() const;
00405 
00409     double nextZoomOutLevel() const;
00410 
00414     double nextZoomOutLevel(double zoomLevel) const;
00415 
00419     double fitToCanvasZoomLevel() const;
00420 
00424     void setInitialZoomLevel();
00425 
00426     void startInitialZoomTimerIfReady();
00427 
00428 private slots:
00429     void layersUpdated(); // Used in the channel separation to notify the view that we have added a few layers.
00430     void maskUpdated(); // To update the enabled or disabled status of the mask entries
00431 
00432     void slotSetFGQColor(const QColor & c);
00433     void slotSetBGQColor(const QColor & c);
00434 
00435     void imgUpdated(QRect rc);
00436     void slotOpenGLImageUpdated(QRect rc);
00437 
00438     void imgResizeToActiveLayer();
00439 
00440     void canvasGotMoveEvent(KisMoveEvent *e);
00441     void canvasGotButtonPressEvent(KisButtonPressEvent *e);
00442     void canvasGotButtonReleaseEvent(KisButtonReleaseEvent *e);
00443     void canvasGotDoubleClickEvent(KisDoubleClickEvent *e);
00444     void canvasGotPaintEvent(QPaintEvent *e);
00445     void canvasGotEnterEvent(QEvent *e);
00446     void canvasGotLeaveEvent(QEvent *e);
00447     void canvasGotMouseWheelEvent(QWheelEvent *e);
00448     void canvasGotKeyPressEvent(QKeyEvent*);
00449     void canvasGotKeyReleaseEvent(QKeyEvent*);
00450     void canvasGotDragEnterEvent(QDragEnterEvent*);
00451     void canvasGotDropEvent(QDropEvent*);
00452 
00453     void reconnectAfterPartInsert();
00454 
00455     QPoint mapToScreen(const QPoint& pt);
00456     void slotImageProperties();
00457 
00458     void layerCompositeOp(const KisCompositeOp& compositeOp);
00459     void layerOpacity(int opacity, bool dontundo);
00460     void layerOpacityFinishedChanging(int previous, int opacity);
00461 
00462     void layerToggleVisible();
00463     void layerToggleLocked();
00464     void actLayerVisChanged(int show);
00465     void layerProperties();
00466     void showLayerProperties(KisLayerSP layer);
00467     void layerAdd();
00468     void addLayer(KisGroupLayerSP parent, KisLayerSP above);
00469     void addGroupLayer(KisGroupLayerSP parent, KisLayerSP above);
00470     void addPartLayer();
00471     void addPartLayer(KisGroupLayerSP parent, KisLayerSP above, const KoDocumentEntry& entry);
00472     void addAdjustmentLayer();
00473     void addAdjustmentLayer(KisGroupLayerSP parent, KisLayerSP above);
00474     void addAdjustmentLayer(KisGroupLayerSP parent, KisLayerSP above, const QString & name, KisFilterConfiguration * filter, KisSelectionSP selection = 0);
00475     void layerRemove();
00476     void layerDuplicate();
00477     void layerRaise();
00478     void layerLower();
00479     void layerFront();
00480     void layerBack();
00481     void flattenImage();
00482     void mergeLayer();
00483     void saveLayerAsImage();
00484     
00485     void slotUpdateFullScreen(bool toggle);
00486     void showRuler();
00487 
00488     void slotZoomIn();
00489     void slotZoomOut();
00490     void slotActualPixels();
00491     void slotActualSize();
00492     void slotFitToCanvas();
00493 
00494     void slotImageSizeChanged(Q_INT32 w, Q_INT32 h);
00495 
00496     void scrollH(int value);
00497     void scrollV(int value);
00498 
00499     void slotInsertImageAsLayer();
00500     void profileChanged(KisProfile *  profile);
00501 
00502     void slotAddPalette();
00503     void slotEditPalette();
00504 
00505     void preferences();
00506 
00507     void slotAutoScroll(const QPoint &p);
00508 
00509     void handlePartLayerAdded(KisLayerSP layer);
00510 
00512     void slotLoadingFinished();
00513 
00514     void slotInitialZoomTimeout();
00515 
00516 private:
00517 
00518     bool m_panning;
00519     
00520     KisTool * m_oldTool;
00521     
00522     KisDoc *m_doc;
00523     KisCanvas *m_canvas;
00524     QPopupMenu * m_popup;
00525     KisPartLayerHandler* m_partHandler;
00526 
00527     KisGridManager * m_gridManager;
00528     KisPerspectiveGridManager * m_perspectiveGridManager;
00529     KisSelectionManager * m_selectionManager;
00530     KisFilterManager * m_filterManager;
00531     KoPaletteManager * m_paletteManager;
00532     KisToolManager * m_toolManager;
00533     bool m_actLayerVis;
00534 
00535     // Fringe benefits
00536     KisRuler *m_hRuler;
00537     KisRuler *m_vRuler;
00538     Q_INT32 m_rulerThickness;
00539     Q_INT32 m_vScrollBarExtent;
00540     Q_INT32 m_hScrollBarExtent;
00541 
00542     // Actions
00543     KAction *m_imgFlatten;
00544     KAction *m_imgMergeLayer;
00545     KAction *m_imgRename;
00546     KAction *m_imgResizeToLayer;
00547     KAction *m_imgScan;
00548 
00549     KoPartSelectAction * m_actionPartLayer;
00550     KAction * m_actionAdjustmentLayer;
00551     KAction *m_layerAdd;
00552     KAction *m_layerBottom;
00553     KAction *m_layerDup;
00554     KAction *m_layerHide;
00555     KAction *m_layerLower;
00556     KAction *m_layerProperties;
00557     KAction *m_layerRaise;
00558     KAction *m_layerRm;
00559     KAction *m_layerSaveAs;
00560     KAction *m_layerTop;
00561 
00562     KAction *m_createMask;
00563     KAction *m_maskFromSelection;
00564     KAction *m_maskToSelection;
00565     KAction *m_applyMask;
00566     KAction *m_removeMask;
00567     KToggleAction *m_editMask;
00568     KToggleAction *m_showMask;
00569 
00570     KAction *m_zoomIn;
00571     KAction *m_zoomOut;
00572     KAction *m_actualPixels;
00573     KAction *m_actualSize;
00574     KAction *m_fitToCanvas;
00575 
00576     KAction *m_fullScreen;
00577     KAction *m_imgProperties;
00578 
00579     KToggleAction *m_RulerAction;
00580     KToggleAction *m_guideAction;
00581 
00582     DCOPObject *m_dcop;
00583 
00584     // Widgets
00585     QScrollBar *m_hScroll; // XXX: the sizing of the scrollthumbs
00586     QScrollBar *m_vScroll; // is not right yet.
00587     int m_scrollX;
00588     int m_scrollY;
00589     int m_canvasXOffset;
00590     int m_canvasYOffset;
00591 
00592     bool m_paintViewEnabled;
00593     bool m_guiActivateEventReceived;
00594     bool m_showEventReceived;
00595     bool m_imageLoaded;
00596 
00597     QTimer m_initialZoomTimer;
00598 
00599 
00600 //    KisGuideSP m_currentGuide;
00601 //    QPoint m_lastGuidePoint;
00602     KisUndoAdapter *m_adapter;
00603     vKisCanvasObserver m_observers;
00604     QLabel *m_statusBarZoomLabel;
00605     KSqueezedTextLabel *m_statusBarSelectionLabel;
00606     KSqueezedTextLabel *m_statusBarProfileLabel;
00607     KisLabelProgress *m_progress;
00608 
00609 
00610     KisLayerBox *m_layerBox;
00611     KoToolBox * m_toolBox;
00612     KisControlFrame * m_brushesAndStuffToolBar;
00613 
00614     // Current colours, brushes, patterns etc.
00615 
00616     KisColor m_fg;
00617     KisColor m_bg;
00618 
00619     KisBrush *m_brush;
00620     KisPattern *m_pattern;
00621     KisGradient *m_gradient;
00622 
00623     KisID m_paintop;
00624     const KisPaintOpSettings *m_paintopSettings;
00625 
00626     QTime m_tabletEventTimer;
00627     QTabletEvent::TabletDevice m_lastTabletEventDevice;
00628 
00629     QPixmap m_canvasPixmap;
00630     bool m_toolIsPainting;
00631 
00632 #ifdef HAVE_GL
00633     // OpenGL context for the current image, containing textures
00634     // shared between multiple views.
00635     KisOpenGLImageContextSP m_OpenGLImageContext;
00636 #endif
00637 
00638     // Monitorprofile for this view
00639     KisProfile *  m_monitorProfile;
00640 
00641     float m_HDRExposure;
00642 
00643     // Currently active input device (mouse, stylus, eraser...)
00644     KisInputDevice m_inputDevice;
00645 
00646     KisBirdEyeBox * m_birdEyeBox;
00647     KoHSVWidget *m_hsvwidget;
00648     KoRGBWidget *m_rgbwidget;
00649     KoGrayWidget *m_graywidget;
00650     KisPaletteWidget *m_palettewidget;
00651     KisID m_currentColorChooserDisplay;
00652 
00653 private:
00654     KisImageSP m_image;
00655 
00656 protected:
00657 
00658     friend class KisSelectionManager;
00659     friend class KisFilterManager;
00660     friend class KisGridManager;
00661     friend class KisPerspectiveGridManager;
00662 };
00663 
00664 #endif // KIS_VIEW_H_
KDE Home | KDE Accessibility Home | Description of Access Keys