Commit c09daf3f authored by Wilco Greven's avatar Wilco Greven

Created a Canvas class. For now it's simply a QScrollView, but I will move

some stuff from the part in there.

svn path=/trunk/kdegraphics/kpdf/; revision=175355
parent 06a50cf1
#include "kpdf_canvas.h"
#include "kpdf_canvas.moc"
using namespace KPDF;
Canvas::Canvas(QWidget* parent, const char* name, WFlags f)
: QScrollView(parent, name, f)
{
}
// vim:ts=2:sw=2:tw=78:et
#ifndef _KPDF_CANVAS_H_
#define _KPDF_CANVAS_H_
#include <qscrollview.h>
namespace KPDF
{
class Canvas : public QScrollView
{
Q_OBJECT
public:
Canvas(QWidget* parent = 0, const char* name = 0, WFlags f = 0);
};
}
#endif
// vim:ts=2:sw=2:tw=78:et
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
#include <math.h> #include <math.h>
#include <qfile.h> #include <qfile.h>
#include <qscrollview.h>
#include <qtextstream.h>
#include <kaction.h> #include <kaction.h>
#include <kdebug.h> #include <kdebug.h>
...@@ -20,6 +18,7 @@ ...@@ -20,6 +18,7 @@
#include "PDFDoc.h" #include "PDFDoc.h"
#include "XOutputDev.h" #include "XOutputDev.h"
#include "kpdf_canvas.h"
#include "kpdf_pagewidget.h" #include "kpdf_pagewidget.h"
typedef KParts::GenericFactory<KPDF::Part> KPDFPartFactory; typedef KParts::GenericFactory<KPDF::Part> KPDFPartFactory;
...@@ -42,11 +41,11 @@ Part::Part(QWidget *parentWidget, const char *widgetName, ...@@ -42,11 +41,11 @@ Part::Part(QWidget *parentWidget, const char *widgetName,
// we need an instance // we need an instance
setInstance(KPDFPartFactory::instance()); setInstance(KPDFPartFactory::instance());
m_scrollView = new QScrollView(parentWidget, widgetName); m_canvas = new Canvas(parentWidget, widgetName);
setWidget(m_scrollView); setWidget(m_canvas);
m_pageWidget = new PageWidget(m_scrollView->viewport()); m_pageWidget = new PageWidget(m_canvas->viewport());
m_scrollView->addChild(m_pageWidget); m_canvas->addChild(m_pageWidget);
connect(m_pageWidget, SIGNAL(linkClicked(LinkAction*)), connect(m_pageWidget, SIGNAL(linkClicked(LinkAction*)),
SLOT(executeAction(LinkAction*))); SLOT(executeAction(LinkAction*)));
...@@ -144,25 +143,25 @@ Part::displayPage(int pageNumber, float /*zoomFactor*/) ...@@ -144,25 +143,25 @@ Part::displayPage(int pageNumber, float /*zoomFactor*/)
{ {
const double pageAR = pageWidth/pageHeight; // Aspect ratio const double pageAR = pageWidth/pageHeight; // Aspect ratio
const int scrollViewWidth = m_scrollView->contentsRect().width(); const int canvasWidth = m_canvas->contentsRect().width();
const int scrollViewHeight = m_scrollView->contentsRect().height(); const int canvasHeight = m_canvas->contentsRect().height();
const int scrollBarWidth = m_scrollView->verticalScrollBar()->width(); const int scrollBarWidth = m_canvas->verticalScrollBar()->width();
// Calculate the height so that the page fits the viewport width // Calculate the height so that the page fits the viewport width
// assuming that we need a vertical scrollbar. // assuming that we need a vertical scrollbar.
float height = float(scrollViewWidth - scrollBarWidth) / pageAR; float height = float(canvasWidth - scrollBarWidth) / pageAR;
// If the vertical scrollbar wasn't needed after all, calculate the page // If the vertical scrollbar wasn't needed after all, calculate the page
// size so that the page fits the viewport width without the scrollbar. // size so that the page fits the viewport width without the scrollbar.
if (ceil(height) <= scrollViewHeight) if (ceil(height) <= canvasHeight)
{ {
height = float(scrollViewWidth) / pageAR; height = float(canvasWidth) / pageAR;
// Handle the rare case that enlarging the page resulted in the need of // Handle the rare case that enlarging the page resulted in the need of
// a vertical scrollbar. We can fit the page to the viewport height in // a vertical scrollbar. We can fit the page to the viewport height in
// this case. // this case.
if (ceil(height) > scrollViewHeight) if (ceil(height) > canvasHeight)
height = float(scrollViewHeight) * pageAR; height = float(canvasHeight) * pageAR;
} }
m_zoomFactor = (height / pageHeight) / basePpp; m_zoomFactor = (height / pageHeight) / basePpp;
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
class QPainter; class QPainter;
class QPixmap; class QPixmap;
class QScrollView;
class QWidget; class QWidget;
class KAboutData; class KAboutData;
...@@ -22,31 +21,9 @@ class LinkDest; ...@@ -22,31 +21,9 @@ class LinkDest;
class PDFDoc; class PDFDoc;
class XOutputDev; class XOutputDev;
/*
class QPixmapWidget : public QWidget
{
public:
QPixmapWidget( QPixmap* bg, QWidget* parent = 0, const char* name = 0 )
: QWidget( parent, name )
, m_pixmap( bg )
{
setFixedSize( bg->size() );
}
protected:
void paintEvent( QPaintEvent* pe )
{
QPainter p( this );
p.drawPixmap( pe->rect().topLeft(), *m_pixmap, pe->rect() );
}
private:
QPixmap* m_pixmap;
};
*/
namespace KPDF namespace KPDF
{ {
class Canvas;
class PageWidget; class PageWidget;
/** /**
...@@ -101,11 +78,11 @@ namespace KPDF ...@@ -101,11 +78,11 @@ namespace KPDF
void executeAction(LinkAction*); void executeAction(LinkAction*);
private: private:
QScrollView* m_scrollView; Canvas* m_canvas;
QPixmap m_pagePixmap; QPixmap m_pagePixmap;
PageWidget* m_pageWidget; PageWidget* m_pageWidget;
PDFDoc* m_doc; PDFDoc* m_doc;
XOutputDev* m_outputDev; XOutputDev* m_outputDev;
KToggleAction* m_fitWidth; KToggleAction* m_fitWidth;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment