summaryrefslogtreecommitdiff
path: root/libopie2/opiemm/oimagescrollview.h
blob: 01a2d56d53e68d7e1ceeb3aab1534ca8cabbd9c4 (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
#ifndef _IMAGE_SCROLL_VIEW_H
#define _IMAGE_SCROLL_VIEW_H

#include <qscrollview.h>
#include <qimage.h>
#include <qpixmap.h>
#include <qstring.h>
#include <qdialog.h>
#include <qbitarray.h>


class QPainter;

namespace Opie { namespace MM {

    class OImageZoomer;
/**
 * \brief Class displaying an image with scrollbars
 *
 * This class displays various image formats supported by QT an
 * gives a small interface for basics display modifications.
 *
 * @see QScrollView
 *
 * @since 1.2
 */
class OImageScrollView:public QScrollView
{
    Q_OBJECT
public:
    enum  Rotation {
        Rotate0,
        Rotate90,
        Rotate180,
        Rotate270
    };

    /**
     * Standard constructor
     * @param parent the parent widget
     * @param name the name of the widget
     * @param fl widget flags. The flag Qt::WRepaintNoErase will be always set.
     */
    OImageScrollView( QWidget* parent, const char* name = 0, WFlags fl = 0 );
    /**
     * constructor
     * @param aImage QImage object to display
     * @param parent the parent widget
     * @param name the name of the widget
     * @param fl widget flags. The flag Qt::WRepaintNoErase will be always set.
     * @param always_scale if the image should be scaled into the display
     * @param rfit the image will be rotated to fit
     */
    OImageScrollView (const QImage&aImage, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false );
    /**
     * constructor
     * @param aFile image file to display
     * @param parent the parent widget
     * @param name the name of the widget
     * @param fl widget flags. The flag Qt::WRepaintNoErase will be always set.
     * @param always_scale if the image should be scaled into the display
     * @param rfit the image will be rotated to fit
     */
    OImageScrollView (const QString&aFile, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false );
    virtual ~OImageScrollView();

    /**
     * sets the WDestructiveClose flag to the view
     */
    virtual void setDestructiveClose();

    /**
     * set if the image should be rotate to best fit
     * and repaint it if set to a new value.
     *
     * Be carefull - autorating real large images cost time!
     * @param how if true then autorotate otherwise not
     */
    virtual void setAutoRotate(bool how);
    /**
     * set if the image should be scaled to the size of the viewport if larger(!)
     *
     * if autoscaling is set when loading a jpeg image, it will use a feature of
     * jpeg lib to load the image scaled to display size. If switch of later the
     * image will reloaded.
     *
     * @param how true - display image scaled down otherwise not
     */
    virtual void setAutoScale(bool how);
    /**
     * set if the image should be scaled to the size of the viewport if larger(!)
     * and/or rotate to best fit. You avoid double repainting when you want to switch
     * booth values.
     *
     * if autoscaling is set when loading a jpeg image, it will use a feature of
     * jpeg lib to load the image scaled to display size. If switch of later the
     * image will reloaded.
     *
     * @param scale true - display image scaled down otherwise not
     * @param rotate true - the image will rotate for best fit
     */
    virtual void setAutoScaleRotate(bool scale, bool rotate);
    /**
     * set if there should be displayed a small zoomer widget at the right bottom of
     * the view when the image is larger than the viewport.
     *
     * @param how true - display zoomer
     */
    virtual void setShowZoomer(bool how);

    /**
     * return the current value of the autorotate flag.
     */
    virtual bool AutoRotate()const;
    /**
     * return the current value of the autoscale flag.
     */
    virtual bool AutoScale()const;
    /**
     * return the current value of the show zoomer flag.
     */
    virtual bool ShowZoomer()const;

public slots:
    /**
     * Displays a new image, calculations will made immediately.
     *
     * @param aImage the image to display
     */
    virtual void setImage(const QImage&aImage);
    /**
     * Displays a new image, calculations will made immediately.
     *
     * @param path the image to display
     */
    virtual void setImage( const QString& path );


signals:
    /**
     * emitted when the display image size has changed.
     */
    void imageSizeChanged( const QSize& );
    /**
     * emitted when the size of the viewport has changed, eg. in resizeEvent of
     * the view.
     *
     * @see QWidget::resizeEvent
     */
    void viewportSizeChanged( const QSize& );

protected:
    virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph );
    void init();

    Opie::MM::OImageZoomer *_zoomer;
    QImage _image_data;
    QImage _original_data;
    QPixmap _pdata;

    int _mouseStartPosX,_mouseStartPosY;

    QBitArray m_states;

    Rotation m_last_rot;
    QString m_lastName;
    virtual void rescaleImage(int w, int h);

    virtual void rotate_into_data(Rotation r);
    virtual void generateImage();
    virtual void loadJpeg(bool interncall = false);
    bool image_fit_into(const QSize&s);
    void check_zoomer();

    /* internal bitset manipulation */
    virtual bool ImageIsJpeg()const;
    virtual void setImageIsJpeg(bool how);
    virtual bool ImageScaledLoaded()const;
    virtual void setImageScaledLoaded(bool how);
    virtual bool FirstResizeDone()const;
    virtual void setFirstResizeDone(bool how);

protected slots:
    virtual void viewportMouseMoveEvent(QMouseEvent* e);
    virtual void contentsMousePressEvent ( QMouseEvent * e);
    virtual void resizeEvent(QResizeEvent * e);
    virtual void keyPressEvent(QKeyEvent * e);
};

}
}

#endif