mirror of
https://invent.kde.org/graphics/okular
synced 2024-08-25 10:55:37 +00:00
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
This commit is contained in:
parent
06a50cf15f
commit
c09daf3f09
11
kpdf/kpdf_canvas.cpp
Normal file
11
kpdf/kpdf_canvas.cpp
Normal file
|
@ -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
|
19
kpdf/kpdf_canvas.h
Normal file
19
kpdf/kpdf_canvas.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
#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 @@
|
|||
#include <math.h>
|
||||
|
||||
#include <qfile.h>
|
||||
#include <qscrollview.h>
|
||||
#include <qtextstream.h>
|
||||
|
||||
#include <kaction.h>
|
||||
#include <kdebug.h>
|
||||
|
@ -20,6 +18,7 @@
|
|||
#include "PDFDoc.h"
|
||||
#include "XOutputDev.h"
|
||||
|
||||
#include "kpdf_canvas.h"
|
||||
#include "kpdf_pagewidget.h"
|
||||
|
||||
typedef KParts::GenericFactory<KPDF::Part> 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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue