summaryrefslogtreecommitdiffstats
path: root/libkscan/img_canvas.h
blob: 4179750bb4561e9ad28220566d10ac95a63ef4aa (plain)
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
/* This file is part of the KDE Project
   Copyright (C) 1999 Klaas Freitag <freitag@suse.de>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef __IMG_CANVAS_H__
#define __IMG_CANVAS_H__

#include <tqwidget.h>
#include <tqrect.h>
#include <stdlib.h>
#include <tqsize.h>
#include <tqwmatrix.h>
#include <tqscrollview.h>
#include <tqstrlist.h>

#ifdef USE_KPIXMAPIO
#include <kpixmapio.h>
#endif

class TQPopupMenu;
class TQPixmap;
class TQImage;
class TQPainter;

enum preview_state {
	MOVE_NONE,
	MOVE_TOP_LEFT,
	MOVE_TOP_RIGHT,
	MOVE_BOTTOM_LEFT,
	MOVE_BOTTOM_RIGHT,
	MOVE_LEFT,
	MOVE_RIGHT,
	MOVE_TOP,
	MOVE_BOTTOM,
	MOVE_WHOLE
};

enum cursor_type {
	CROSS,
	VSIZE,
	HSIZE,
	BDIAG,
	FDIAG,
	ALL,
	HREN
};

const int MIN_AREA_WIDTH = 3;
const int MIN_AREA_HEIGHT = 3;
const int delta = 3;
#ifdef __PREVIEW_CPP__
int max_dpi = 600;
#else
extern int max_dpi;
#endif



class ImageCanvas: public TQScrollView
{
    Q_OBJECT
  TQ_OBJECT
    Q_ENUMS( PopupIDs )
    TQ_PROPERTY( int brightness READ getBrightness WRITE setBrightness )
    TQ_PROPERTY( int contrast READ getContrast WRITE setContrast )
    TQ_PROPERTY( int gamma READ getGamma WRITE setGamma )
    TQ_PROPERTY( int scale_factor READ getScaleFactor WRITE setScaleFactor )

public:
    ImageCanvas( TQWidget *parent = 0,
                 const TQImage *start_image = 0,
                 const char *name = 0);
    ~ImageCanvas( );

    int getBrightness() const;
    int getContrast() const;
    int getGamma() const;

    int getScaleFactor() const;

    const TQImage *rootImage();

    bool hasImage( void ) 	{ return acquired; }
    TQPopupMenu* contextMenu() { return m_contextMenu; }
    TQRect sel( void );

    enum ScaleKinds { UNSPEC, DYNAMIC, FIT_ORIG, FIT_WIDTH, FIT_HEIGHT, ZOOM };

    enum PopupIDs { ID_POP_ZOOM, ID_POP_CLOSE, ID_FIT_WIDTH,
                    ID_FIT_HEIGHT, ID_ORIG_SIZE };

    bool selectedImage( TQImage* );

    ScaleKinds scaleKind();
    const TQString scaleKindString();

    ScaleKinds defaultScaleKind();

    const TQString imageInfoString( int w=0, int h=0, int d=0 );

public slots:
    void setBrightness(int);
    void setContrast(int );
    void setGamma(int );

    void toggleAspect( int aspect_in_mind )
        {
            maintain_aspect = aspect_in_mind;
            tqrepaint();
        }
    virtual TQSize sizeHint() const;
    void newImage( TQImage* );
    void newImageHoldZoom( TQImage* );
    void deleteView( TQImage *);
    void newRectSlot();
    void newRectSlot( TQRect newSel );
    void noRectSlot( void );
    void setScaleFactor( int i );
    void handle_popup(int item );
    void enableContextMenu( bool wantContextMenu );
    void setKeepZoom( bool k );
    void setScaleKind( ScaleKinds k );
    void setDefaultScaleKind( ScaleKinds k );

    /**
     * Highlight a rectangular area on the current image using the given brush
     * and pen.
     * The function returns a id that needs to be given to the remove method.
     */
    int highlight( const TQRect&, const TQPen&, const TQBrush&, bool ensureVis=false );

    /**
     * reverts the highlighted region back to normal view.
     */
    void removeHighlight( int idx = -1 );

    /**
     * permit to do changes to the image that are saved back to the file
     */
    void setReadOnly( bool );

    bool readOnly();
	
signals:
    void noRect( void );
    void newRect( void );
    void newRect( TQRect );
    void scalingRequested();
    void closingRequested();
    void scalingChanged( const TQString& );
    /**
     * signal emitted if the permission of the currently displayed image changed,
     * ie. if it goes from writeable to readable.
     * @param shows if the image is now read only (true) or not.
     */
    void imageReadOnly( bool isRO );
    
protected:
    void drawContents( TQPainter * p, int clipx, int clipy, int clipw, int cliph );

    void timerEvent(TQTimerEvent *);
    void viewportMousePressEvent(TQMouseEvent *);
    void viewportMouseReleaseEvent(TQMouseEvent *);
    void viewportMouseMoveEvent(TQMouseEvent *);

    void resizeEvent( TQResizeEvent * event );

private:
    TQStrList      urls;

    int           scale_factor;
    const TQImage        *image;
    int           brightness, contrast, gamma;


#ifdef USE_KPIXMAPIO
    KPixmapIO	 pixIO;
#endif

    TQWMatrix	 scale_matrix;
    TQWMatrix	 inv_scale_matrix;
    TQPixmap       *pmScaled;
    float	 used_yscaler;
    float	 used_xscaler;
    TQPopupMenu    *m_contextMenu;
    bool		 maintain_aspect;

    int	         timer_id;
    TQRect 	 *selected;
    preview_state moving;
    int 		 cr1,cr2;
    int 		 lx,ly;
    bool 	 acquired;

    /* private functions for the running ant */
    void drawHAreaBorder(TQPainter &p,int x1,int x2,int y,int r = FALSE);
    void drawVAreaBorder(TQPainter &p,int x,int y1,int y2,int r = FALSE);
    void drawAreaBorder(TQPainter *p,int r = FALSE);
    void update_scaled_pixmap( void );

    preview_state classifyPoint(int x,int y);

    class ImageCanvasPrivate;
    ImageCanvasPrivate *d;
};

#endif