From c09daf3f0938f079a88e99c68f34c8011a1cedf6 Mon Sep 17 00:00:00 2001 From: Wilco Greven Date: Mon, 2 Sep 2002 19:47:18 +0000 Subject: [PATCH] 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 --- kpdf/kpdf_canvas.cpp | 11 +++++++++++ kpdf/kpdf_canvas.h | 19 +++++++++++++++++++ kpdf/kpdf_part.cpp | 27 +++++++++++++-------------- kpdf/kpdf_part.h | 35 ++++++----------------------------- 4 files changed, 49 insertions(+), 43 deletions(-) create mode 100644 kpdf/kpdf_canvas.cpp create mode 100644 kpdf/kpdf_canvas.h diff --git a/kpdf/kpdf_canvas.cpp b/kpdf/kpdf_canvas.cpp new file mode 100644 index 000000000..b4d466f9e --- /dev/null +++ b/kpdf/kpdf_canvas.cpp @@ -0,0 +1,11 @@ +#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 diff --git a/kpdf/kpdf_canvas.h b/kpdf/kpdf_canvas.h new file mode 100644 index 000000000..52cb6a196 --- /dev/null +++ b/kpdf/kpdf_canvas.h @@ -0,0 +1,19 @@ +#ifndef _KPDF_CANVAS_H_ +#define _KPDF_CANVAS_H_ + +#include + +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 diff --git a/kpdf/kpdf_part.cpp b/kpdf/kpdf_part.cpp index 0713bef7b..f70aedf7d 100644 --- a/kpdf/kpdf_part.cpp +++ b/kpdf/kpdf_part.cpp @@ -3,8 +3,6 @@ #include #include -#include -#include #include #include @@ -20,6 +18,7 @@ #include "PDFDoc.h" #include "XOutputDev.h" +#include "kpdf_canvas.h" #include "kpdf_pagewidget.h" typedef KParts::GenericFactory KPDFPartFactory; @@ -42,11 +41,11 @@ Part::Part(QWidget *parentWidget, const char *widgetName, // we need an instance setInstance(KPDFPartFactory::instance()); - m_scrollView = new QScrollView(parentWidget, widgetName); - setWidget(m_scrollView); + m_canvas = new Canvas(parentWidget, widgetName); + setWidget(m_canvas); - m_pageWidget = new PageWidget(m_scrollView->viewport()); - m_scrollView->addChild(m_pageWidget); + m_pageWidget = new PageWidget(m_canvas->viewport()); + m_canvas->addChild(m_pageWidget); connect(m_pageWidget, SIGNAL(linkClicked(LinkAction*)), SLOT(executeAction(LinkAction*))); @@ -144,25 +143,25 @@ Part::displayPage(int pageNumber, float /*zoomFactor*/) { const double pageAR = pageWidth/pageHeight; // Aspect ratio - const int scrollViewWidth = m_scrollView->contentsRect().width(); - const int scrollViewHeight = m_scrollView->contentsRect().height(); - const int scrollBarWidth = m_scrollView->verticalScrollBar()->width(); + const int canvasWidth = m_canvas->contentsRect().width(); + const int canvasHeight = m_canvas->contentsRect().height(); + const int scrollBarWidth = m_canvas->verticalScrollBar()->width(); // Calculate the height so that the page fits the viewport width // 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 // 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 // a vertical scrollbar. We can fit the page to the viewport height in // this case. - if (ceil(height) > scrollViewHeight) - height = float(scrollViewHeight) * pageAR; + if (ceil(height) > canvasHeight) + height = float(canvasHeight) * pageAR; } m_zoomFactor = (height / pageHeight) / basePpp; diff --git a/kpdf/kpdf_part.h b/kpdf/kpdf_part.h index 42dc9e7f6..2316799aa 100644 --- a/kpdf/kpdf_part.h +++ b/kpdf/kpdf_part.h @@ -9,7 +9,6 @@ class QPainter; class QPixmap; -class QScrollView; class QWidget; class KAboutData; @@ -22,31 +21,9 @@ class LinkDest; class PDFDoc; 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 { + class Canvas; class PageWidget; /** @@ -101,11 +78,11 @@ namespace KPDF void executeAction(LinkAction*); private: - QScrollView* m_scrollView; - QPixmap m_pagePixmap; - PageWidget* m_pageWidget; - PDFDoc* m_doc; - XOutputDev* m_outputDev; + Canvas* m_canvas; + QPixmap m_pagePixmap; + PageWidget* m_pageWidget; + PDFDoc* m_doc; + XOutputDev* m_outputDev; KToggleAction* m_fitWidth;