Import of original sources
[qcomicbook-oblomov] / src / imgview.h
1 /*
2  * This file is a part of QComicBook.
3  *
4  * Copyright (C) 2005-2006 Pawel Stolowski <yogin@linux.bydg.org>
5  *
6  * QComicBook is free software; you can redestribute it and/or modify it
7  * under terms of GNU General Public License by Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY. See GPL for more details.
11  */
12
13 #ifndef __IMGVIEW_H
14 #define __IMGVIEW_H
15
16 #include <qscrollview.h>
17
18 class QPopupMenu;
19 class QImage;
20 class QPixmap;
21 class QColor;
22 class QCursor;
23
24 namespace QComicBook
25 {
26         enum Size { Original, FitWidth, FitHeight, WholePage, BestFit };
27         //enum Scaling { Smooth, Fast };
28         enum Rotation { None, Left, Right };
29
30         class ImlibImage;
31
32         class ComicImageView: public QScrollView
33         {
34                 Q_OBJECT
35
36                 private:
37                         QPopupMenu *context_menu;
38                         ImlibImage *orgimage[2];
39                         Size isize;
40                         //Scaling iscaling;
41                         int iangle; //rotation angle, 0..3, multipled by 90
42                         int spdx, spdy; //scroll speed
43                         int xoff, yoff;
44                         int lx, ly; //last mouse position when tracking mouse moves
45                         int wheelupcnt, wheeldowncnt;
46                         QCursor *smallcursor;
47                         static const int EXTRA_WHEEL_SPIN; //number of extra wheel spins to flip the page
48
49                         // test - na potrzeby imlib
50                         double asp;
51                         double w_asp;
52                         double h_asp;
53
54                 signals:
55                         void bottomReached();
56                         void topReached();
57                         void doubleClick();
58
59                 protected:
60                         void resizeEvent(QResizeEvent *e);
61                         void updateImageSize();
62                         virtual void contentsContextMenuEvent(QContextMenuEvent *e);
63                         virtual void contentsWheelEvent(QWheelEvent *e);
64                         virtual void contentsMouseMoveEvent(QMouseEvent *e);
65                         virtual void contentsMousePressEvent(QMouseEvent *e);
66                         virtual void contentsMouseDoubleClickEvent(QMouseEvent *e);
67                         virtual void contentsMouseReleaseEvent(QMouseEvent *e);
68                         virtual void drawContents(QPainter *p, int clipx, int clipy, int clipw, int cliph);
69
70                 public slots:
71                         void setImage(ImlibImage *img, bool preserveangle=false);
72                         void setImage(ImlibImage *img1, ImlibImage *img2, bool preserveangle=false);
73                         //void setScaling(Scaling s);
74                         void setRotation(Rotation r);
75                         void setSize(Size s);
76                         void setSizeOriginal();
77                         void setSizeFitWidth();
78                         void setSizeFitHeight();
79                         void setSizeWholePage();
80                         void setSizeBestFit();
81                         void scrollToTop();
82                         void scrollToBottom();
83                         void scrollRight();
84                         void scrollLeft();
85                         void scrollRightFast();
86                         void scrollLeftFast();
87                         void scrollUp();
88                         void scrollDown();
89                         void scrollUpFast();
90                         void scrollDownFast();
91                         void rotateRight();
92                         void rotateLeft();
93                         void resetRotation();
94                         void jumpUp();
95                         void jumpDown();
96                         void clear();
97                         void enableScrollbars(bool f);
98                         void setBackground(const QColor &color);
99                         void setSmallCursor(bool f);
100
101                 public:
102                         ComicImageView(QWidget *parent, Size size=Original, const QColor &color=Qt::black);
103                         ~ComicImageView();
104                         bool onBottom();
105                         bool onTop();
106                         QPopupMenu *contextMenu() const;
107                         Size getSize() const;
108                         int imageWidth() const;
109         };
110 }
111
112 #endif
113