summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/GraphicWin.cpp
authorpohly <pohly>2004-08-24 20:52:45 (UTC)
committer pohly <pohly>2004-08-24 20:52:45 (UTC)
commit73253e93327cf4ef0932de1b4afb56af22a0f37e (patch) (unidiff)
tree1c9a7a6dd3341e036a894d348a3372525d29acec /noncore/apps/opie-reader/GraphicWin.cpp
parente90847c784c48bd21bf8768cb38edb853b832697 (diff)
downloadopie-73253e93327cf4ef0932de1b4afb56af22a0f37e.zip
opie-73253e93327cf4ef0932de1b4afb56af22a0f37e.tar.gz
opie-73253e93327cf4ef0932de1b4afb56af22a0f37e.tar.bz2
updated source to opie-reader 0.7g
Diffstat (limited to 'noncore/apps/opie-reader/GraphicWin.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/GraphicWin.cpp122
1 files changed, 122 insertions, 0 deletions
diff --git a/noncore/apps/opie-reader/GraphicWin.cpp b/noncore/apps/opie-reader/GraphicWin.cpp
new file mode 100644
index 0000000..df069c4
--- a/dev/null
+++ b/noncore/apps/opie-reader/GraphicWin.cpp
@@ -0,0 +1,122 @@
1
2#include "GraphicWin.h"
3
4GraphicWin::GraphicWin( QWidget *parent, const char *name, WFlags f)
5 : QWidget(parent, name, f), m_isFitted(false), m_isRotated(false)
6{
7 QVBoxLayout* grid = new QVBoxLayout(this);
8 m_scroll = new GraphicScroll(this);
9 grid->addWidget(m_scroll,1);
10 QHBoxLayout* b = new QHBoxLayout(grid);
11
12 QPushButton* fitButton = new QPushButton("Rotated", this);
13 connect(fitButton, SIGNAL( clicked() ), this, SLOT( slotRotate() ) );
14 b->addWidget(fitButton);
15
16 fitButton = new QPushButton("Fitted", this);
17 connect(fitButton, SIGNAL( clicked() ), this, SLOT( slotFit() ) );
18 b->addWidget(fitButton);
19
20 fitButton = new QPushButton("Close", this);
21 connect(fitButton, SIGNAL( clicked() ), this, SLOT( slotClosed() ) );
22 b->addWidget(fitButton);
23}
24
25void GraphicWin::setImage(QImage& im)
26{
27 m_isRotated = m_isFitted = false;
28 m_im = im;
29 resetpm();
30}
31
32QImage GraphicWin::resizeimage(int w, int h)
33{
34 if (w*m_im.height() < h*m_im.width())
35 {
36 h = (m_im.height()*w + m_im.width()/2)/m_im.width();
37 }
38 else
39 {
40 w = (m_im.width()*h + m_im.height()/2)/m_im.height();
41 }
42 return m_im.smoothScale(w,h);
43}
44
45void GraphicWin::slotFit()
46{
47 m_isFitted = !m_isFitted;
48 resetpm();
49}
50
51void GraphicWin::slotRotate()
52{
53 m_isRotated = !m_isRotated;
54 resetpm();
55}
56
57void GraphicWin::resetpm()
58{
59 QImage im;
60 if (m_isFitted)
61 {
62 int w, h;
63 if (m_isRotated)
64 {
65 w = m_scroll->height()-5;
66 h = m_scroll->width()-5;
67 }
68 else
69 {
70 w = m_scroll->width()-5;
71 h = m_scroll->height()-5;
72 }
73 im = resizeimage(w, h);
74 }
75 else
76 {
77 im = m_im;
78 }
79 QPixmap pc;
80 if (m_isRotated)
81 {
82 QWMatrix m;
83 m.rotate(90);
84 QPixmap pc1;
85 pc1.convertFromImage(im);
86 pc = pc1.xForm(m);
87 }
88 else
89 {
90 pc.convertFromImage(im);
91 }
92 m_scroll->setPixmap(pc);
93}
94
95/*
96 Something like this should work...but doesn't quite
97 smoothscale is better anyway.
98
99void GraphicWin::resetpm()
100{
101 QWMatrix m;
102 if (m_isRotated)
103 {
104 m.rotate(90);
105 }
106 if (m_isFitted)
107 {
108 double sw = (width()-5.0)/(m_isRotated ? m_im.height() : m_im.width());
109 double sh = (height()-5.0)/(m_isRotated ? m_im.width() : m_im.height());
110 if (sw < sh)
111 {
112 m.scale(sw, sw);
113 }
114 else
115 {
116 m.scale(sh, sh);
117 }
118 }
119 QPixmap pc = m_im.xForm(m);
120 m_scroll->setPixmap(pc);
121}
122*/