Commit fcc0d938 authored by Christophe Devriese's avatar Christophe Devriese

lots of updates

-> list of pages to the left of the pdf file
-> zooming works (although zooming modes like fit to page aren't done yet)
-> added zooming buttons to the top bar

svn path=/trunk/kdegraphics/kpdf/; revision=234250
parent 0edb09e9
......@@ -43,7 +43,7 @@ shellrc_DATA = kpdf_shell.rc
kde_module_LTLIBRARIES = libkpdfpart.la
# the Part's source, library search path, and link libraries
libkpdfpart_la_SOURCES = kpdf_canvas.cpp kpdf_part.cpp kpdf_pagewidget.cc QOutputDev.cpp
libkpdfpart_la_SOURCES = kpdf_canvas.cpp kpdf_part.cpp kpdf_pagewidget.cc QOutputDev.cpp part.ui
libkpdfpart_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries)
libkpdfpart_la_LIBADD = ../xpdf/libxpdf.la $(LIB_KPARTS) $(LIB_KFILE) $(LIB_KDEPRINT)
......
......@@ -185,6 +185,9 @@ QOutputDev::QOutputDev ( QWidget *parent, const char *name, int flags ) : QScrol
// create text object
m_text = new TextPage ( gFalse );
// enable mouse tracking for links
setMouseTracking(true);
}
QOutputDev::~QOutputDev ( )
......
......@@ -2,7 +2,10 @@
#include <math.h>
#include <qwidget.h>
#include <qlistbox.h>
#include <qfile.h>
#include <qtimer.h>
#include <kaction.h>
#include <kdebug.h>
......@@ -11,14 +14,18 @@
#include <kstdaction.h>
#include <kparts/genericfactory.h>
#include <kdebug.h>
#include "GString.h"
#include "GlobalParams.h"
#include "PDFDoc.h"
#include "XOutputDev.h"
#include "kpdf_canvas.h"
#include "kpdf_pagewidget.h"
// #include "kpdf_canvas.h"
// #include "kpdf_pagewidget.h"
#include "part.h"
typedef KParts::GenericFactory<KPDF::Part> KPDFPartFactory;
K_EXPORT_COMPONENT_FACTORY(libkpdfpart, KPDFPartFactory);
......@@ -41,8 +48,13 @@ Part::Part(QWidget *parentWidget, const char *widgetName,
// we need an instance
setInstance(KPDFPartFactory::instance());
m_outputDev = new QOutputDev(parentWidget, widgetName);
setWidget(m_outputDev);
pdfpartview = new PDFPartView(parentWidget, widgetName);
connect(pdfpartview->pagesListBox, SIGNAL( clicked ( QListBoxItem * ) ),
this, SLOT( pageClicked ( QListBoxItem * ) ));
m_outputDev = pdfpartview->outputdev;
setWidget(pdfpartview);
// create our actions
KStdAction::find (this, SLOT(find()),
......@@ -113,7 +125,16 @@ Part::openFile()
// just for fun, set the status bar
// emit setStatusBarText( QString::number( m_doc->getNumPages() ) );
m_doc->displayPage( m_outputDev , 1, 72, 0, false );
// fill the listbox with entries for every page
pdfpartview->pagesListBox->setUpdatesEnabled(false);
pdfpartview->pagesListBox->clear();
for (int i = 1; i <= m_doc->getNumPages(); i++)
{
pdfpartview->pagesListBox->insertItem(QString("%1").arg(i));
}
pdfpartview->pagesListBox->setUpdatesEnabled(true);
pdfpartview->pagesListBox->update();
displayPage(1);
return true;
......@@ -122,11 +143,30 @@ Part::openFile()
void
Part::displayPage(int pageNumber, float /*zoomFactor*/)
{
kdDebug() << "display page" << endl;
kdDebug() << "page : " << pageNumber << endl;
kdDebug() << "zoom factor : " << m_zoomFactor << endl;
Page * p = m_doc->getCatalog()->getPage(pageNumber);
kdDebug() << "metadata stream : " << endl;
char * md = new char[4096];
if (p->getMetadata())
{
while(p->getMetadata()->getLine(md, 4096) != NULL)
{
kdDebug() << md << endl;
}
}
kdDebug() << "------------" << endl;
if (pageNumber <= 0 || pageNumber > m_doc->getNumPages())
return;
const double pageWidth = m_doc->getPageWidth (pageNumber);
const double pageHeight = m_doc->getPageHeight(pageNumber);
const double pageWidth = m_doc->getPageWidth (pageNumber) * m_zoomFactor;
const double pageHeight = m_doc->getPageHeight(pageNumber) * m_zoomFactor;
// Pixels per point when the zoomFactor is 1.
const float basePpp = QPaintDevice::x11AppDpiX() / 72.0;
......@@ -169,7 +209,7 @@ Part::displayPage(int pageNumber, float /*zoomFactor*/)
const float ppp = basePpp * m_zoomFactor; // pixels per point
m_doc->displayPage(m_outputDev, pageNumber, int(ppp*72.0), 0, true);
m_doc->displayPage(m_outputDev, pageNumber, int(m_zoomFactor * ppp * 72.0), 0, true);
m_outputDev->show();
......@@ -371,7 +411,33 @@ Part::slotFitToWidthToggled()
displayPage(m_currentPage);
}
// for optimization
bool redrawing = false;
void
Part::update()
{
if (m_outputDev && ! redrawing)
{
redrawing = true;
QTimer::singleShot(200, this, SLOT( redrawPage() ));
}
};
void
Part::redrawPage()
{
redrawing = false;
displayPage(m_currentPage);
}
void
Part::pageClicked ( QListBoxItem * qbi )
{
m_currentPage = pdfpartview->pagesListBox->index(qbi);
update();
}
BrowserExtension::BrowserExtension(Part* parent)
: KParts::BrowserExtension( parent, "KPDF::BrowserExtension" )
{
......@@ -385,8 +451,6 @@ BrowserExtension::print()
static_cast<Part*>(parent())->print();
}
#include "kpdf_part.moc"
// vim:ts=2:sw=2:tw=78:et
......@@ -13,6 +13,7 @@
class QPainter;
class QPixmap;
class QWidget;
class QListBoxItem;
class KAboutData;
class KAction;
......@@ -24,6 +25,8 @@ class LinkDest;
class PDFDoc;
class XOutputDev;
class PDFPartView;
namespace KPDF
{
class BrowserExtension;
......@@ -73,11 +76,13 @@ namespace KPDF
*/
virtual bool openFile();
void update();
protected slots:
void find() { /* stub */ };
void findNext() { /* stub */ };
void zoomIn() { /* stub */ };
void zoomOut() { /* stub */ };
void zoomIn() { m_zoomFactor += 0.1; update(); };
void zoomOut() { m_zoomFactor -= 0.1; update(); };
void back() { /* stub */ };
void forward() { /* stub */ };
......@@ -89,6 +94,7 @@ namespace KPDF
private:
PDFDoc* m_doc;
QOutputDev* m_outputDev;
PDFPartView * pdfpartview;
KToggleAction* m_fitToWidth;
......@@ -99,6 +105,8 @@ namespace KPDF
private slots:
void slotFitToWidthToggled();
void redrawPage();
void pageClicked ( QListBoxItem * );
};
class BrowserExtension : public KParts::BrowserExtension
......
......@@ -22,5 +22,8 @@
<ToolBar name="mainToolBar">
<Action name="previous_page"/>
<Action name="next_page"/>
<Separator/>
<Action name="zoom_in"/>
<Action name="zoom_out"/>
</ToolBar>
</kpartgui>
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