From 73253e93327cf4ef0932de1b4afb56af22a0f37e Mon Sep 17 00:00:00 2001 From: pohly Date: Tue, 24 Aug 2004 20:52:45 +0000 Subject: updated source to opie-reader 0.7g --- (limited to 'noncore/apps/opie-reader/GraphicWin.cpp') 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 @@ + +#include "GraphicWin.h" + +GraphicWin::GraphicWin( QWidget *parent, const char *name, WFlags f) + : QWidget(parent, name, f), m_isFitted(false), m_isRotated(false) +{ + QVBoxLayout* grid = new QVBoxLayout(this); + m_scroll = new GraphicScroll(this); + grid->addWidget(m_scroll,1); + QHBoxLayout* b = new QHBoxLayout(grid); + + QPushButton* fitButton = new QPushButton("Rotated", this); + connect(fitButton, SIGNAL( clicked() ), this, SLOT( slotRotate() ) ); + b->addWidget(fitButton); + + fitButton = new QPushButton("Fitted", this); + connect(fitButton, SIGNAL( clicked() ), this, SLOT( slotFit() ) ); + b->addWidget(fitButton); + + fitButton = new QPushButton("Close", this); + connect(fitButton, SIGNAL( clicked() ), this, SLOT( slotClosed() ) ); + b->addWidget(fitButton); +} + +void GraphicWin::setImage(QImage& im) +{ + m_isRotated = m_isFitted = false; + m_im = im; + resetpm(); +} + +QImage GraphicWin::resizeimage(int w, int h) +{ + if (w*m_im.height() < h*m_im.width()) + { + h = (m_im.height()*w + m_im.width()/2)/m_im.width(); + } + else + { + w = (m_im.width()*h + m_im.height()/2)/m_im.height(); + } + return m_im.smoothScale(w,h); +} + +void GraphicWin::slotFit() +{ + m_isFitted = !m_isFitted; + resetpm(); +} + +void GraphicWin::slotRotate() +{ + m_isRotated = !m_isRotated; + resetpm(); +} + +void GraphicWin::resetpm() +{ + QImage im; + if (m_isFitted) + { + int w, h; + if (m_isRotated) + { + w = m_scroll->height()-5; + h = m_scroll->width()-5; + } + else + { + w = m_scroll->width()-5; + h = m_scroll->height()-5; + } + im = resizeimage(w, h); + } + else + { + im = m_im; + } + QPixmap pc; + if (m_isRotated) + { + QWMatrix m; + m.rotate(90); + QPixmap pc1; + pc1.convertFromImage(im); + pc = pc1.xForm(m); + } + else + { + pc.convertFromImage(im); + } + m_scroll->setPixmap(pc); +} + +/* + Something like this should work...but doesn't quite + smoothscale is better anyway. + +void GraphicWin::resetpm() +{ + QWMatrix m; + if (m_isRotated) + { + m.rotate(90); + } + if (m_isFitted) + { + double sw = (width()-5.0)/(m_isRotated ? m_im.height() : m_im.width()); + double sh = (height()-5.0)/(m_isRotated ? m_im.width() : m_im.height()); + if (sw < sh) + { + m.scale(sw, sw); + } + else + { + m.scale(sh, sh); + } + } + QPixmap pc = m_im.xForm(m); + m_scroll->setPixmap(pc); +} +*/ -- cgit v0.9.0.2