- Make find next work

- Do not allow to find if there's no document

svn path=/trunk/kdegraphics/kpdf/; revision=342164
remotes/origin/kpdf-experiments
Albert Astals Cid 22 years ago
parent 929dfa12a7
commit e456dfaafb
  1. 4
      kpdf/QOutputDev.cpp
  2. 2
      kpdf/QOutputDev.h
  3. 17
      kpdf/kpdf_pagewidget.cc
  4. 2
      kpdf/kpdf_pagewidget.h
  5. 67
      kpdf/kpdf_part.cpp
  6. 24
      kpdf/kpdf_part.h

@ -75,7 +75,7 @@ void QOutputDev::updateFont(GfxState *state)
m_text->updateFont(state);
}
bool QOutputDev::find(Unicode *u, int len, double *xMin, double *yMin, double *xMax, double *yMax)
bool QOutputDev::find(Unicode *s, int len, GBool startAtTop, GBool stopAtBottom, GBool startAtLast, GBool stopAtLast, double *xMin, double *yMin, double *xMax, double *yMax)
{
return m_text -> findText(u, len, true, false, false, false, xMin, yMin, xMax, yMax);
return m_text -> findText(s, len, startAtTop, stopAtBottom, startAtLast, stopAtLast, xMin, yMin, xMax, yMax);
}

@ -55,7 +55,7 @@ class QOutputDev : public SplashOutputDev
// Clear out the document (used when displaying an empty window).
void clear();
bool find(Unicode *u, int len, double *xMin, double *yMin, double *xMax, double *yMax);
bool find(Unicode *s, int len, GBool startAtTop, GBool stopAtBottom, GBool startAtLast, GBool stopAtLast, double *xMin, double *yMin, double *xMax, double *yMax);
private:

@ -366,16 +366,19 @@ namespace KPDF
}
}
bool PageWidget::find(Unicode *u, int len)
bool PageWidget::find(Unicode *u, int len, bool next)
{
bool b;
// dirty hack to ensure we are searching the whole page
m_xMin = 0;
m_yMin = 0;
m_xMax = 10000;
m_yMax = 10000;
if (!next)
{
// ensure we are searching the whole page
m_xMin = 0;
m_yMin = 0;
m_xMax = m_outputdev->getPixmap()->width();
m_yMax = m_outputdev->getPixmap()->height();
}
b = m_outputdev -> find(u, len, &m_xMin, &m_yMin, &m_xMax, &m_yMax);
b = m_outputdev -> find(u, len, !next, false, false, false, &m_xMin, &m_yMin, &m_xMax, &m_yMax);
m_selection = b;
updateContents();
return b;

@ -55,7 +55,7 @@ namespace KPDF
bool atBottom() const;
void zoomTo( double _value );
bool find(Unicode *u, int len);
bool find(Unicode *u, int len, bool next);
public slots:
void zoomIn();

@ -40,6 +40,7 @@
#include <kurldrag.h>
#include <kinputdialog.h>
#include <kfinddialog.h>
#include <kmessagebox.h>
#include "kpdf_error.h"
#include "part.h"
@ -100,10 +101,12 @@ Part::Part(QWidget *parentWidget, const char *widgetName,
SLOT( showMarkList( bool ) ) );
// create our actions
KStdAction::find (this, SLOT(find()),
m_find = KStdAction::find(this, SLOT(find()),
actionCollection(), "find");
KStdAction::findNext(this, SLOT(findNext()),
actionCollection(), "find_next");
m_find->setEnabled(false);
m_findNext = KStdAction::findNext(this, SLOT(findNext()),
actionCollection(), "find_next");
m_findNext->setEnabled(false);
m_fitToWidth = new KToggleAction(i18n("Fit to Page &Width"), 0,
this, SLOT(slotFitToWidthToggled()),
actionCollection(), "fit_to_width");
@ -368,9 +371,12 @@ Part::openFile()
if (!m_doc->isOk())
return false;
m_find->setEnabled(true);
m_findNext->setEnabled(true);
errors::clear();
m_currentPage = 0; //so that goToPage if is true
m_currentPage = 0; //so that the if in goToPage is true
if (m_doc->getNumPages() > 0)
{
// TODO use a qvaluelist<int> to pass aspect ratio?
@ -708,22 +714,33 @@ void Part::doPrint( KPrinter& printer )
}
void Part::find()
{
KFindDialog dlg(pdfpartview);
if (dlg.exec() != QDialog::Accepted) return;
doFind(dlg.pattern(), false);
}
void Part::findNext()
{
if (!m_findText.isEmpty()) doFind(m_findText, true);
}
void Part::doFind(QString s, bool next)
{
TextOutputDev *textOut;
Unicode *u;
bool found;
double xMin1, yMin1, xMax1, yMax1;
int len, pg;
KFindDialog dlg(pdfpartview);
if (dlg.exec() != QDialog::Accepted) return;
// This is more or less copied from what xpdf does, surely can be optimized
len = strlen(dlg.pattern().latin1());
len = s.length();
u = (Unicode *)gmalloc(len * sizeof(Unicode));
for (int i = 0; i < len; ++i) u[i] = (Unicode)(dlg.pattern().latin1()[i] & 0xff);
for (int i = 0; i < len; ++i) u[i] = (Unicode)(s.latin1()[i] & 0xff);
// search current
found = m_outputDev->find(u, len);
found = m_outputDev->find(u, len, next);
if (!found)
{
@ -744,16 +761,19 @@ void Part::find()
if (!found) pg++;
}
if (!found)
if (!found && m_currentPage != 1)
{
// search previous pages
pg = 1;
while(!found && pg < m_currentPage)
{
m_doc->displayPage(textOut, pg, 72, 72, 0, gTrue, gFalse);
found = textOut->findText(u, len, gTrue, gTrue, gFalse, gFalse, &xMin1, &yMin1, &xMax1, &yMax1);
if (!found) pg++;
}
if (KMessageBox::questionYesNo(widget(), i18n("End of document reached.\nContinue from the beginning?")) == KMessageBox::Yes)
{
// search previous pages
pg = 1;
while(!found && pg < m_currentPage)
{
m_doc->displayPage(textOut, pg, 72, 72, 0, gTrue, gFalse);
found = textOut->findText(u, len, gTrue, gTrue, gFalse, gFalse, &xMin1, &yMin1, &xMax1, &yMax1);
if (!found) pg++;
}
}
}
delete textOut;
@ -762,7 +782,14 @@ void Part::find()
kdDebug() << "found at " << pg << endl;
goToPage(pg);
// xpdf says: can happen that we do not find the text if coalescing is bad OUCH
m_outputDev->find(u, len);
m_outputDev->find(u, len, false);
m_findText = s;
}
else
{
m_findText = QString::null;
if (next) KMessageBox::information(widget(), i18n("No more matches found for '%1'.").arg(s));
else KMessageBox::information(widget(), i18n("No matches found for '%1'.").arg(s));
}
}
gfree(u);

@ -107,7 +107,7 @@ namespace KPDF
protected slots:
void find();
void findNext() { /* stub */ };
void findNext();
void zoomIn() { m_zoomFactor += 0.1; update(); };
void zoomOut() { m_zoomFactor -= 0.1; update(); };
void back() { /* stub */ };
@ -129,18 +129,24 @@ namespace KPDF
void slotZoom( const QString& );
private:
PDFDoc* m_doc;
PageWidget* m_outputDev;
void doFind(QString s, bool next);
PDFDoc* m_doc;
PageWidget* m_outputDev;
PDFPartView * pdfpartview;
KAction* m_firstPage;
KAction* m_lastPage;
KAction* m_prevPage;
KAction* m_nextPage;
KAction* m_firstPage;
KAction* m_lastPage;
KAction* m_prevPage;
KAction* m_nextPage;
KAction *m_gotoPage;
KToggleAction* m_showScrollBars;
KToggleAction* m_showPageList;
KToggleAction* m_showScrollBars;
KToggleAction* m_showPageList;
KSelectAction *m_zoomTo;
KToggleAction* m_fitToWidth;
KAction *m_find;
KAction *m_findNext;
QString m_findText;
// first page is page 1
int m_currentPage;

Loading…
Cancel
Save