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 KisLabelProgress;
00094 class KisLayerBox;
00095 class KisMoveEvent;
00096 class KisPaletteWidget;
00097 class KisPattern;
00098 class KisPoint;
00099 class KisRect;
00100 class KisResource;
00101 class KisResourceMediator;
00102 class KisRuler;
00103 class KisSelectionManager;
00104 class KoToolBox;
00105 class KisToolControllerInterface;
00106 class KisToolManager;
00107 class KisUndoAdapter;
00108 class KisFilterConfiguration;
00109 class KisPartLayerHandler;
00110 class KisPaintOpSettings;
00111 
00112 class KRITA_EXPORT KisView
00113     : public KoView,
00114       public KisCanvasSubject,
00115       public KXMLGUIBuilder,
00116       private KisCanvasController
00117 {
00118 
00119     Q_OBJECT
00120 
00121     typedef KoView super;
00122 
00123     typedef std::list<KisCanvasObserver*> vKisCanvasObserver;
00124     typedef vKisCanvasObserver::iterator vKisCanvasObserver_it;
00125     typedef vKisCanvasObserver::const_iterator vKisCanvasObserver_cit;
00126 
00127 public:
00128     KisView(KisDoc *doc, KisUndoAdapter *adapter, QWidget *parent = 0, const char *name = 0);
00129     virtual ~KisView();
00130 
00131 public: // KXMLGUIBuilder implementation
00132 
00133     virtual QWidget *createContainer( QWidget *parent, int index, const QDomElement &element, int &id );
00134     virtual void removeContainer( QWidget *container, QWidget *parent, QDomElement &element, int id );
00135 
00136 public: // KoView implementation
00137     virtual bool eventFilter(QObject *o, QEvent *e);
00138 
00139     virtual DCOPObject* dcopObject();
00140 
00141     virtual void print(KPrinter &printer);
00142     virtual void setupPrinter(KPrinter &printer);
00143 
00144     virtual void updateReadWrite(bool readwrite);
00145     virtual void guiActivateEvent(KParts::GUIActivateEvent *event);
00146 
00147     virtual int leftBorder() const;
00148     virtual int rightBorder() const;
00149     virtual int topBorder() const;
00150     virtual int bottomBorder() const;
00151 
00152     Q_INT32 docWidth() const;
00153     Q_INT32 docHeight() const;
00154 
00155     void updateStatusBarSelectionLabel();
00156 
00157     virtual QPoint applyViewTransformations(const QPoint& p) const;
00158     virtual QPoint reverseViewTransformations( const QPoint& p) const;
00159     virtual void canvasAddChild(KoViewChild *child);
00160 
00161 signals:
00162 
00163     void brushChanged(KisBrush * brush);
00164     void gradientChanged(KisGradient * gradient);
00165     void patternChanged(KisPattern * pattern);
00166     void paintopChanged(KisID paintop, const KisPaintOpSettings *paintopSettings);
00171     void currentColorSpaceChanged(KisColorSpace* cs);
00172     void cursorPosition(Q_INT32 xpos, Q_INT32 ypos);
00173 
00174     void sigFGQColorChanged(const QColor &);
00175     void sigBGQColorChanged(const QColor &);
00176 
00177     void sigInputDeviceChanged(const KisInputDevice& inputDevice);
00178 
00179     /*
00180      * Emitted whenever the zoom or scroll values change.
00181      */
00182     void viewTransformationsChanged();
00183 
00184 public slots:
00185 
00186     void slotSetFGColor(const KisColor& c);
00187     void slotSetBGColor(const KisColor& c);
00188 
00189     void rotateLayer180();
00190     void rotateLayerLeft90();
00191     void rotateLayerRight90();
00192     void mirrorLayerX();
00193     void mirrorLayerY();
00194     void scaleLayer(double sx, double sy, KisFilterStrategy *filterStrategy);
00195     void rotateLayer(double angle);
00196     void shearLayer(double angleX, double angleY);
00197 
00198     void brushActivated(KisResource *brush);
00199     void patternActivated(KisResource *pattern);
00200     void gradientActivated(KisResource *gradient);
00201     void paintopActivated(const KisID & paintop, const KisPaintOpSettings *paintopSettings);
00202 
00203 
00204 public:
00205     virtual void mouseMoveEvent(QMouseEvent *e);
00206 
00207     void resizeCurrentImage(Q_INT32 w, Q_INT32 h, bool cropLayers = false);
00208     void scaleCurrentImage(double sx, double sy, KisFilterStrategy *filterStrategy);
00209     void rotateCurrentImage(double angle);
00210     void shearCurrentImage(double angleX, double angleY);
00211 
00212     void insertPart(const QRect& viewRect, const KoDocumentEntry& entry,
00213                     KisGroupLayerSP parent, KisLayerSP above);
00214 
00215 
00216 protected:
00217 
00218     virtual void resizeEvent(QResizeEvent*); // From QWidget
00219     virtual void styleChange(QStyle& oldStyle); // From QWidget
00220     virtual void paletteChange(const QPalette& oldPalette); // From QWidget
00221     virtual void showEvent(QShowEvent *);
00222 
00223 protected slots:
00224     virtual void slotChildActivated(bool a); // from KoView
00225 
00226 // -------------------------------------------------------------------------//
00227 //                    KisCanvasSubject implementation
00228 // -------------------------------------------------------------------------//
00229 public:
00230 
00231     KisCanvasSubject * canvasSubject() { return this; };
00232 
00233 private:
00234 
00235     virtual KisImageSP currentImg() const;
00236 
00237     virtual void attach(KisCanvasObserver *observer);
00238     virtual void detach(KisCanvasObserver *observer);
00239     virtual void notifyObservers();
00240 
00241     virtual KisColor bgColor() const;
00242     virtual void setBGColor(const KisColor& c);
00243 
00244     virtual KisColor fgColor() const;
00245     virtual void setFGColor(const KisColor& c);
00246 
00247     float HDRExposure() const;
00248     void setHDRExposure(float exposure);
00249 
00250     virtual KisBrush *currentBrush() const;
00251     virtual KisPattern *currentPattern() const;
00252     virtual KisGradient *currentGradient() const;
00253     virtual KisID currentPaintop() const;
00254     virtual const KisPaintOpSettings *currentPaintopSettings() const;
00255 
00256     virtual double zoomFactor() const;
00257 
00258     virtual KisUndoAdapter *undoAdapter() const;
00259 
00260     virtual KisCanvasController *canvasController() const;
00261     virtual KisToolControllerInterface *toolController() const;
00262 
00263     virtual KisProgressDisplayInterface *progressDisplay() const;
00264 
00265     virtual KisDoc * document() const;
00266 
00267     inline KisGridManager * gridManager() { return m_gridManager; }
00268     
00269     inline KisSelectionManager * selectionManager() { return m_selectionManager; }
00270 
00271     KoPaletteManager * paletteManager();
00272 
00273     KisProfile *  monitorProfile();
00274 
00275 // -------------------------------------------------------------------------//
00276 //                    KisCanvasController implementation
00277 // -------------------------------------------------------------------------//
00278 
00279 public:
00280 
00281     KisCanvasController * getCanvasController() { return this; };
00282 
00283 
00284 private slots:
00285     virtual void updateCanvas();
00286 
00287     void updateStatusBarZoomLabel();
00288     void updateStatusBarProfileLabel();
00289 
00290 private:
00291     virtual KisCanvas *kiscanvas() const;
00292     
00293     virtual Q_INT32 horzValue() const;
00294     virtual Q_INT32 vertValue() const;
00295 
00296     virtual void scrollTo(Q_INT32 x, Q_INT32 y);
00297 
00298     virtual void updateCanvas(Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h);
00299     virtual void updateCanvas(const QRect& imageRect);
00300 
00301     virtual void zoomIn();
00302     virtual void zoomIn(Q_INT32 x, Q_INT32 y);
00303 
00304     virtual void zoomOut();
00305     virtual void zoomOut(Q_INT32 x, Q_INT32 y);
00306 
00307     virtual void zoomTo(Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h);
00308     virtual void zoomTo(const QRect& r);
00309     virtual void zoomTo(const KisRect& r);
00310     virtual void zoomAroundPoint(double x, double y, double zf);
00311 
00312     virtual QPoint viewToWindow(const QPoint& pt);
00313     virtual QPoint viewToWindow(const QPoint& pt) const;
00314     virtual KisPoint viewToWindow(const KisPoint& pt);
00315     virtual QRect viewToWindow(const QRect& rc);
00316     virtual KisRect viewToWindow(const KisRect& rc);
00317     virtual void viewToWindow(Q_INT32 *x, Q_INT32 *y);
00318 
00319     virtual QPoint windowToView(const QPoint& pt);
00320     virtual QPoint windowToView(const QPoint& pt) const;
00321     virtual KisPoint windowToView(const KisPoint& pt);
00322     virtual QRect windowToView(const QRect& rc);
00323     virtual KisRect windowToView(const KisRect& rc);
00324     virtual void windowToView(Q_INT32 *x, Q_INT32 *y);
00325 
00326     virtual QCursor setCanvasCursor(const QCursor & cursor);
00327 
00328     void setInputDevice(KisInputDevice inputDevice);
00329     KisInputDevice currentInputDevice() const;
00330 
00331 // -------------------------------------------------------------------------//
00332 //                      KisView internals
00333 // -------------------------------------------------------------------------//
00334 
00335 private:
00336 
00337     void connectCurrentImg();
00338     void disconnectCurrentImg();
00339 //    void eraseGuides();
00340 //    void paintGuides();
00341 //    void updateGuides();
00342 //    void viewGuideLines();
00343 
00344     void imgUpdateGUI();
00345 
00346     void layerUpdateGUI(bool enable);
00347     void createLayerBox();
00348     void createDockers();
00349 
00350     void paintToolOverlay(const QRegion& region);
00351 
00352     void paintQPaintDeviceView(const QRegion& canvasRegion);
00353     void paintOpenGLView(const QRect& canvasRect);
00354 
00355     void updateQPaintDeviceCanvas(const QRect& imageRect);
00356     void updateOpenGLCanvas(const QRect& imageRect);
00357 
00361     void refreshKisCanvas();
00362 
00363     void selectionDisplayToggled(bool displaySelection);
00364 
00365     bool activeLayerHasSelection();
00366 
00370     void resetMonitorProfile();
00371 
00372     void setupActions();
00373     void setupCanvas();
00374     void setupRulers();
00375     void setupScrollBars();
00376     void setupStatusBar();
00377 
00386     Q_INT32 importImage(const KURL& url = KURL());
00387     KisFilterManager * filterManager() { return m_filterManager; }
00388     void setCurrentImage(KisImageSP image);
00389 
00393     double nextZoomInLevel() const;
00394 
00398     double nextZoomOutLevel() const;
00399 
00403     double nextZoomOutLevel(double zoomLevel) const;
00404 
00408     double fitToCanvasZoomLevel() const;
00409 
00413     void setInitialZoomLevel();
00414 
00415     void startInitialZoomTimerIfReady();
00416 
00417 private slots:
00418     void layersUpdated(); // Used in the channel separation to notify the view that we have added a few layers.
00419 
00420     void slotSetFGQColor(const QColor & c);
00421     void slotSetBGQColor(const QColor & c);
00422 
00423     void imgUpdated(QRect rc);
00424     void slotOpenGLImageUpdated(QRect rc);
00425 
00426     void imgResizeToActiveLayer();
00427 
00428     void canvasGotMoveEvent(KisMoveEvent *e);
00429     void canvasGotButtonPressEvent(KisButtonPressEvent *e);
00430     void canvasGotButtonReleaseEvent(KisButtonReleaseEvent *e);
00431     void canvasGotDoubleClickEvent(KisDoubleClickEvent *e);
00432     void canvasGotPaintEvent(QPaintEvent *e);
00433     void canvasGotEnterEvent(QEvent *e);
00434     void canvasGotLeaveEvent(QEvent *e);
00435     void canvasGotMouseWheelEvent(QWheelEvent *e);
00436     void canvasGotKeyPressEvent(QKeyEvent*);
00437     void canvasGotKeyReleaseEvent(QKeyEvent*);
00438     void canvasGotDragEnterEvent(QDragEnterEvent*);
00439     void canvasGotDropEvent(QDropEvent*);
00440 
00441     void reconnectAfterPartInsert();
00442 
00443     QPoint mapToScreen(const QPoint& pt);
00444     void slotImageProperties();
00445 
00446     void layerCompositeOp(const KisCompositeOp& compositeOp);
00447     void layerOpacity(int opacity, bool dontundo);
00448     void layerOpacityFinishedChanging(int previous, int opacity);
00449 
00450     void layerToggleVisible();
00451     void layerToggleLocked();
00452     void actLayerVisChanged(int show);
00453     void layerProperties();
00454     void showLayerProperties(KisLayerSP layer);
00455     void layerAdd();
00456     void addLayer(KisGroupLayerSP parent, KisLayerSP above);
00457     void addGroupLayer(KisGroupLayerSP parent, KisLayerSP above);
00458     void addPartLayer();
00459     void addPartLayer(KisGroupLayerSP parent, KisLayerSP above, const KoDocumentEntry& entry);
00460     void addAdjustmentLayer();
00461     void addAdjustmentLayer(KisGroupLayerSP parent, KisLayerSP above);
00462     void addAdjustmentLayer(KisGroupLayerSP parent, KisLayerSP above, const QString & name, KisFilterConfiguration * filter, KisSelectionSP selection = 0);
00463     void layerRemove();
00464     void layerDuplicate();
00465     void layerRaise();
00466     void layerLower();
00467     void layerFront();
00468     void layerBack();
00469     void flattenImage();
00470     void mergeLayer();
00471     void saveLayerAsImage();
00472     
00473     void slotUpdateFullScreen(bool toggle);
00474     void showRuler();
00475 
00476     void slotZoomIn();
00477     void slotZoomOut();
00478     void slotActualPixels();
00479     void slotActualSize();
00480     void slotFitToCanvas();
00481 
00482     void slotImageSizeChanged(Q_INT32 w, Q_INT32 h);
00483 
00484     void scrollH(int value);
00485     void scrollV(int value);
00486 
00487     void slotInsertImageAsLayer();
00488     void profileChanged(KisProfile *  profile);
00489 
00490     void slotAddPalette();
00491     void slotEditPalette();
00492 
00493     void preferences();
00494 
00495     void slotAutoScroll(const QPoint &p);
00496 
00497     void handlePartLayerAdded(KisLayerSP layer);
00498 
00500     void slotLoadingFinished();
00501 
00502     void slotInitialZoomTimeout();
00503 
00504 private:
00505 
00506     bool m_panning;
00507     
00508     KisTool * m_oldTool;
00509     
00510     KisDoc *m_doc;
00511     KisCanvas *m_canvas;
00512     QPopupMenu * m_popup;
00513     KisPartLayerHandler* m_partHandler;
00514 
00515     KisGridManager * m_gridManager;
00516     KisSelectionManager * m_selectionManager;
00517     KisFilterManager * m_filterManager;
00518     KoPaletteManager * m_paletteManager;
00519     KisToolManager * m_toolManager;
00520     bool m_actLayerVis;
00521 
00522     // Fringe benefits
00523     KisRuler *m_hRuler;
00524     KisRuler *m_vRuler;
00525     Q_INT32 m_rulerThickness;
00526     Q_INT32 m_vScrollBarExtent;
00527     Q_INT32 m_hScrollBarExtent;
00528 
00529     // Actions
00530     KAction *m_imgFlatten;
00531     KAction *m_imgMergeLayer;
00532     KAction *m_imgRename;
00533     KAction *m_imgResizeToLayer;
00534     KAction *m_imgScan;
00535 
00536     KoPartSelectAction * m_actionPartLayer;
00537     KAction * m_actionAdjustmentLayer;
00538     KAction *m_layerAdd;
00539     KAction *m_layerBottom;
00540     KAction *m_layerDup;
00541     KAction *m_layerHide;
00542     KAction *m_layerLower;
00543     KAction *m_layerProperties;
00544     KAction *m_layerRaise;
00545     KAction *m_layerRm;
00546     KAction *m_layerSaveAs;
00547     KAction *m_layerTop;
00548 
00549     KAction *m_zoomIn;
00550     KAction *m_zoomOut;
00551     KAction *m_actualPixels;
00552     KAction *m_actualSize;
00553     KAction *m_fitToCanvas;
00554 
00555     KAction *m_fullScreen;
00556     KAction *m_imgProperties;
00557 
00558     KToggleAction *m_RulerAction;
00559     KToggleAction *m_guideAction;
00560 
00561     DCOPObject *m_dcop;
00562 
00563     // Widgets
00564     QScrollBar *m_hScroll; // XXX: the sizing of the scrollthumbs
00565     QScrollBar *m_vScroll; // is not right yet.
00566     int m_scrollX;
00567     int m_scrollY;
00568     int m_canvasXOffset;
00569     int m_canvasYOffset;
00570 
00571     bool m_paintViewEnabled;
00572     bool m_guiActivateEventReceived;
00573     bool m_showEventReceived;
00574     bool m_imageLoaded;
00575 
00576     QTimer m_initialZoomTimer;
00577 
00578 
00579 //    KisGuideSP m_currentGuide;
00580 //    QPoint m_lastGuidePoint;
00581     KisUndoAdapter *m_adapter;
00582     vKisCanvasObserver m_observers;
00583     QLabel *m_statusBarZoomLabel;
00584     KSqueezedTextLabel *m_statusBarSelectionLabel;
00585     KSqueezedTextLabel *m_statusBarProfileLabel;
00586     KisLabelProgress *m_progress;
00587 
00588 
00589     KisLayerBox *m_layerBox;
00590     KoToolBox * m_toolBox;
00591     KisControlFrame * m_brushesAndStuffToolBar;
00592 
00593     // Current colours, brushes, patterns etc.
00594 
00595     KisColor m_fg;
00596     KisColor m_bg;
00597 
00598     KisBrush *m_brush;
00599     KisPattern *m_pattern;
00600     KisGradient *m_gradient;
00601 
00602     KisID m_paintop;
00603     const KisPaintOpSettings *m_paintopSettings;
00604 
00605     QTime m_tabletEventTimer;
00606     QTabletEvent::TabletDevice m_lastTabletEventDevice;
00607 
00608     QPixmap m_canvasPixmap;
00609     bool m_toolIsPainting;
00610 
00611 #ifdef HAVE_GL
00612     // OpenGL context for the current image, containing textures
00613     // shared between multiple views.
00614     KisOpenGLImageContextSP m_OpenGLImageContext;
00615 #endif
00616 
00617     // Monitorprofile for this view
00618     KisProfile *  m_monitorProfile;
00619 
00620     float m_HDRExposure;
00621 
00622     // Currently active input device (mouse, stylus, eraser...)
00623     KisInputDevice m_inputDevice;
00624 
00625     KisBirdEyeBox * m_birdEyeBox;
00626     KoHSVWidget *m_hsvwidget;
00627     KoRGBWidget *m_rgbwidget;
00628     KoGrayWidget *m_graywidget;
00629     KisPaletteWidget *m_palettewidget;
00630     KisID m_currentColorChooserDisplay;
00631 
00632 private:
00633     KisImageSP m_image;
00634 
00635 protected:
00636 
00637     friend class KisSelectionManager;
00638     friend class KisFilterManager;
00639     friend class KisGridManager;
00640 };
00641 
00642 #endif // KIS_VIEW_H_
KDE Home | KDE Accessibility Home | Description of Access Keys