1 /*******************************************************************************
2 **
3 ** Photivo
4 **
5 ** Copyright (C) 2010-2012 Michael Munzert <mail@mm-log.com>
6 ** Copyright (C) 2012-2013 Bernd Schoeler <brjohn@brother-john.net>
7 **
8 ** This file is part of Photivo.
9 **
10 ** Photivo is free software: you can redistribute it and/or modify
11 ** it under the terms of the GNU General Public License version 3
12 ** as published by the Free Software Foundation.
13 **
14 ** Photivo is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ** GNU General Public License for more details.
18 **
19 ** You should have received a copy of the GNU General Public License
20 ** along with Photivo.  If not, see <http://www.gnu.org/licenses/>.
21 **
22 *******************************************************************************/
23 #ifndef PTCURVEWINDOW_H
24 #define PTCURVEWINDOW_H
25 
26 #include "ptImage8.h"
27 #include "ptWidget.h"
28 #include "ptCurve.h"
29 
30 #include <QPixmap>
31 
32 #include <memory>
33 #include <vector>
34 #include <utility>
35 
36 class ptFilterBase;
37 class QLabel;
38 class QActionGroup;
39 
40 typedef std::pair<int, int>        TScreenAnchor;
41 typedef std::vector<TScreenAnchor> TScreenAnchorList;
42 
43 class ptCurveWindow: public ptWidget {
44 Q_OBJECT
45 public:
46   explicit ptCurveWindow(QWidget *AParent);
47   ptCurveWindow(const ptCfgItem &ACfgItem, QWidget *AParent);
48   ~ptCurveWindow();
49 
50   void init(const ptCfgItem &ACfgItem);
51   void setValue(const QVariant &AValue);
52   void setCaption(const QString &ACaption);
53   void updateView();
54   void updateView(const std::shared_ptr<ptCurve> ANewCurve);
55 
56 protected:
57   void    mousePressEvent(QMouseEvent *AEvent);
58   void    mouseReleaseEvent(QMouseEvent *);
59   void    mouseMoveEvent(QMouseEvent *AEvent);
60   void    changeEvent(QEvent* Event);
61   void    paintEvent(QPaintEvent*);
62   void    resizeEvent(QResizeEvent*);
63 
sizeHint()64   QSize   sizeHint()                const { return QSize(100, 100); }
minimumSizeHint()65   QSize   minimumSizeHint()         const { return QSize(100, 100); }
heightForWidth(int width)66   int     heightForWidth(int width) const { return width; }
67 
68 private:
69   enum TUserAction { NoAction, InsertAction, DeleteAction, DragAction, WheelAction };
70 
71 private:
72   void          calcCurveImage();
73   void          setBWGradient(ptImage8* AImage);
74   void          setBWGammaGradient(ptImage8* AImage);
75   void          setColorGradient(ptImage8* AImage);
76   void          setColorBlocks(const QColor &ATopLeftColor, const QColor &ABottomRightColor);
77   TAnchor       clampMovingAnchor(const TAnchor &APoint, const QPoint &AMousePos);
78   int           hasCaughtAnchor(const QPoint APos);
79   inline bool   isCyclicCurve();
80   void          requestPipeRun();
81 
82   ptImage8                  FCanvas;
83   QLabel                   *FCaptionLabel;
84   std::shared_ptr<ptCurve>  FCurve;
85   TScreenAnchorList         FDisplayAnchors;
86   QPixmap                   FDisplayImage;
87   QTimer                   *FWheelTimer;
88   TUserAction               FMouseAction;
89   int                       FMovingAnchor;
90 
91   // context menu actions
92   void createMenuActions();
93   void execContextMenu(const QPoint APos);
94   QAction*            FLinearIpolAction;
95   QAction*            FSplineIpolAction;
96   QAction*            FCosineIpolAction;
97   QActionGroup*       FIpolGroup;
98   QAction*            FByLumaAction;
99   QAction*            FByChromaAction;
100   QActionGroup*       FMaskGroup;
101   QAction*            FOpenCurveAction;
102 
103 private slots:
104   void wheelTimerExpired();
105 
106   // context menu slots
107   void setMaskType();
108   void setInterpolationType();
109   void openCurveFile();
110 
111 };
112 
113 #endif // PTCURVEWINDOW_H
114