Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

GraphicWin.cpp

Go to the documentation of this file.
00001 
00002 #include "GraphicWin.h"
00003 
00004 GraphicWin::GraphicWin( QWidget *parent, const char *name, WFlags f)
00005   : QWidget(parent, name, f), m_isFitted(false), m_isRotated(false)
00006 {
00007   QVBoxLayout* grid = new QVBoxLayout(this);
00008   m_scroll = new GraphicScroll(this);
00009   grid->addWidget(m_scroll,1);
00010   QHBoxLayout* b = new QHBoxLayout(grid);
00011 
00012   QPushButton* fitButton = new QPushButton("Rotated", this);
00013   connect(fitButton, SIGNAL( clicked() ), this, SLOT( slotRotate() ) );
00014   b->addWidget(fitButton);
00015 
00016   fitButton = new QPushButton("Fitted", this);
00017   connect(fitButton, SIGNAL( clicked() ), this, SLOT( slotFit() ) );
00018   b->addWidget(fitButton);
00019 
00020   fitButton = new QPushButton("Close", this);
00021   connect(fitButton, SIGNAL( clicked() ), this, SLOT( slotClosed() ) );
00022   b->addWidget(fitButton);
00023 }
00024 
00025 void GraphicWin::setImage(QImage& im)
00026 {
00027   m_isRotated = m_isFitted = false;
00028   m_im = im;
00029   resetpm();
00030 }
00031 
00032 QImage GraphicWin::resizeimage(int w, int h)
00033 {
00034   if (w*m_im.height() < h*m_im.width())
00035     {
00036       h = (m_im.height()*w + m_im.width()/2)/m_im.width();
00037     }
00038   else
00039     {
00040       w = (m_im.width()*h + m_im.height()/2)/m_im.height();
00041     }
00042   return m_im.smoothScale(w,h);
00043 }
00044 
00045 void GraphicWin::slotFit()
00046 {
00047   m_isFitted = !m_isFitted;
00048   resetpm();
00049 }
00050 
00051 void GraphicWin::slotRotate()
00052 {
00053   m_isRotated = !m_isRotated;
00054   resetpm();
00055 }
00056 
00057 void GraphicWin::resetpm()
00058 {
00059   QImage im;
00060   if (m_isFitted)
00061     {
00062       int w, h;
00063       if (m_isRotated)
00064         {
00065           w = m_scroll->height()-5;
00066           h = m_scroll->width()-5;
00067         }
00068       else
00069         {
00070           w = m_scroll->width()-5;
00071           h = m_scroll->height()-5;
00072         }
00073       im = resizeimage(w, h);
00074     }
00075   else
00076     {
00077       im = m_im;
00078     }
00079   QPixmap pc;
00080   if (m_isRotated)
00081     {
00082       QWMatrix m;
00083       m.rotate(90);
00084       QPixmap pc1;
00085       pc1.convertFromImage(im);
00086       pc = pc1.xForm(m);
00087     }
00088   else
00089     {
00090       pc.convertFromImage(im);
00091     }
00092   m_scroll->setPixmap(pc);
00093 }
00094 
00095 /*
00096  Something like this should work...but doesn't quite
00097  smoothscale is better anyway.
00098 
00099 void GraphicWin::resetpm()
00100 {
00101   QWMatrix m;
00102   if (m_isRotated)
00103     {
00104       m.rotate(90);
00105     }
00106   if (m_isFitted)
00107     {
00108       double sw = (width()-5.0)/(m_isRotated ? m_im.height() : m_im.width());
00109       double sh = (height()-5.0)/(m_isRotated ? m_im.width() : m_im.height());
00110       if (sw < sh)
00111         {
00112           m.scale(sw, sw);
00113         }
00114       else
00115         {
00116           m.scale(sh, sh);
00117         }
00118     }
00119   QPixmap pc = m_im.xForm(m);
00120   m_scroll->setPixmap(pc);
00121 }
00122 */

Generated on Sat Nov 5 16:16:55 2005 for OPIE by  doxygen 1.4.2