Commit edf38cc6 authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

Reindent thumbnailist to use tabs (i love tabs) and while at it make its 1...

Reindent thumbnailist to use tabs (i love tabs) and while at it make its 1 based (i mean first thumbnail is thumbnail number one) as all the rest of classes.
Also changes by Pinto made on head

svn path=/branches/kpdf_experiments/kdegraphics/kpdf/; revision=344820
parent 44783a71
......@@ -686,8 +686,7 @@ void Part::redrawPage()
void Part::pageClicked ( int i )
{
// ThumbnailList is 0 based
goToPage(i+1);
goToPage(i);
}
BrowserExtension::BrowserExtension(Part* parent)
......
......@@ -169,7 +169,7 @@ Shell::fileOpen()
// this slot is called whenever the File->Open menu is selected,
// the Open shortcut is pressed (usually CTRL+O) or the Open toolbar
// button is clicked
KURL url = KFileDialog::getOpenURL();//getOpenFileName();
KURL url = KFileDialog::getOpenURL( QString::null, "application/pdf" );//getOpenFileName();
if (!url.isEmpty())
openURL(url);
......
......@@ -10,7 +10,6 @@
#include "part.h"
#include <qlayout.h>
#include <qtable.h>
#include "kpdf_pagewidget.h"
#include "thumbnaillist.h"
......@@ -47,8 +46,7 @@ PDFPartView::~PDFPartView()
void PDFPartView::setCurrentThumbnail(int i)
{
// ThumbnailList is 0 based
pagesList->setCurrentItem(i-1);
pagesList->setCurrentItem(i);
}
void PDFPartView::setPages(int i, double ar)
......
......@@ -17,154 +17,161 @@
ThumbnailList::ThumbnailList(QWidget *parent, QMutex *docMutex) : QTable(parent), m_tg(0), m_doc(0), m_docMutex(docMutex)
{
setNumCols(1);
setLeftMargin(0);
setTopMargin(0);
setHScrollBarMode(QScrollView::AlwaysOff);
m_selected = 0;
connect(this, SIGNAL(pressed(int, int, int, const QPoint&)), this, SIGNAL(clicked(int)));
connect(this, SIGNAL(currentChanged(int, int)), this, SIGNAL(clicked(int)));
connect(this, SIGNAL(currentChanged(int, int)), this, SLOT(changeSelected(int)));
setNumCols(1);
setLeftMargin(0);
setTopMargin(0);
setHScrollBarMode(QScrollView::AlwaysOff);
m_selected = 0;
connect(this, SIGNAL(pressed(int, int, int, const QPoint&)), this, SLOT(emitClicked(int)));
connect(this, SIGNAL(currentChanged(int, int)), this, SLOT(emitClicked(int)));
connect(this, SIGNAL(currentChanged(int, int)), this, SLOT(changeSelected(int)));
}
ThumbnailList::~ThumbnailList()
{
if (m_tg)
{
m_tg->wait();
delete m_tg;
}
if (m_tg)
{
m_tg->wait();
delete m_tg;
}
}
void ThumbnailList::setCurrentItem(int i)
{
setCurrentCell(i, 0);
changeSelected(i);
setCurrentCell(i-1, 0);
changeSelected(i-1);
}
void ThumbnailList::changeSelected(int i)
{
Thumbnail *t;
t = dynamic_cast<Thumbnail *>(cellWidget(m_selected, 0));
if (t) t -> setSelected(false);
m_selected = i;
t = dynamic_cast<Thumbnail *>(cellWidget(m_selected, 0));
if (t) t -> setSelected(true);
Thumbnail *t;
t = dynamic_cast<Thumbnail *>(cellWidget(m_selected, 0));
if (t) t -> setSelected(false);
m_selected = i;
t = dynamic_cast<Thumbnail *>(cellWidget(m_selected, 0));
if (t) t -> setSelected(true);
}
void ThumbnailList::generateThumbnails(PDFDoc *doc)
{
m_nextThumbnail = 1;
m_doc = doc;
generateNextThumbnail();
m_nextThumbnail = 1;
m_doc = doc;
generateNextThumbnail();
}
void ThumbnailList::generateNextThumbnail()
{
if (m_tg)
{
m_tg->wait();
delete m_tg;
}
m_tg = new ThumbnailGenerator(m_doc, m_docMutex, m_nextThumbnail, QPaintDevice::x11AppDpiX(), this);
m_tg->start(QThread::LowPriority);
if (m_tg)
{
m_tg->wait();
delete m_tg;
}
m_tg = new ThumbnailGenerator(m_doc, m_docMutex, m_nextThumbnail, QPaintDevice::x11AppDpiX(), this);
m_tg->start();
}
void ThumbnailList::stopThumbnailGeneration()
{
if (m_tg)
{
m_ignoreNext = true;
m_tg->wait();
delete m_tg;
m_tg = 0;
}
if (m_tg)
{
m_ignoreNext = true;
m_tg->wait();
delete m_tg;
m_tg = 0;
}
}
void ThumbnailList::customEvent(QCustomEvent *e)
{
if (e->type() == 65432 && !m_ignoreNext)
{
QImage *i = (QImage*)(e -> data());
setThumbnail(m_nextThumbnail, i);
m_nextThumbnail++;
if (m_nextThumbnail <= m_doc->getNumPages()) generateNextThumbnail();
else
{
m_tg->wait();
delete m_tg;
m_tg = 0;
}
}
m_ignoreNext = false;
if (e->type() == 65432 && !m_ignoreNext)
{
QImage *i = (QImage*)(e -> data());
setThumbnail(m_nextThumbnail, i);
m_nextThumbnail++;
if (m_nextThumbnail <= m_doc->getNumPages()) generateNextThumbnail();
else
{
m_tg->wait();
delete m_tg;
m_tg = 0;
}
}
m_ignoreNext = false;
}
void ThumbnailList::setPages(int i, double ar)
{
Thumbnail *t;
m_ar = ar;
setNumRows(i);
for(int j=1; j <= i; j++)
{
t = new Thumbnail(this, QString::number(j), viewport()->paletteBackgroundColor(), (int)(visibleWidth()*ar), visibleWidth());
setCellWidget(j-1, 0, t);
setRowHeight(j-1, t->sizeHint().height());
}
m_heightLimit = 0;
Thumbnail *t;
m_ar = ar;
setNumRows(i);
for(int j=1; j <= i; j++)
{
t = new Thumbnail(this, QString::number(j), viewport()->paletteBackgroundColor(), (int)(visibleWidth()*ar), visibleWidth());
setCellWidget(j-1, 0, t);
setRowHeight(j-1, t->sizeHint().height());
}
m_heightLimit = 0;
}
void ThumbnailList::setThumbnail(int i, const QImage *thumbnail)
{
Thumbnail *t;
t = dynamic_cast<Thumbnail *>(cellWidget(i-1, 0));
t->setImage(thumbnail);
Thumbnail *t;
t = dynamic_cast<Thumbnail *>(cellWidget(i-1, 0));
t->setImage(thumbnail);
}
void ThumbnailList::viewportResizeEvent(QResizeEvent *)
{
// that if are here to avoid recursive resizing of death
// where the user makes the window smaller, that makes appear
// the vertical scrollbar, that makes thumbnails smaller, and
// while they get smaller the vertical scrollbar is not needed
// and ...
// ... it also works for when the user makes the window larger
// and then the scrollbar disappears but that makes thumbnails
// larger and then scrollbar reappears and ...
Thumbnail *t;
if (numRows() == 0) return;
t = dynamic_cast<Thumbnail *>(cellWidget(0, 0));
if (size().height() <= m_heightLimit)
{
if (t->getImageHeight() > (int)(visibleWidth()*m_ar))
{
setColumnWidth(0, visibleWidth());
resizeThumbnails();
}
}
else
{
if (visibleWidth() != columnWidth(0))
{
setColumnWidth(0, visibleWidth());
resizeThumbnails();
if (size().height() > m_heightLimit && verticalScrollBar() -> isVisible())
m_heightLimit = (int) ceil(numRows() * ((visibleWidth() + verticalScrollBar() -> width()) * m_ar + t -> labelSizeHintHeight()));
// that if are here to avoid recursive resizing of death
// where the user makes the window smaller, that makes appear
// the vertical scrollbar, that makes thumbnails smaller, and
// while they get smaller the vertical scrollbar is not needed
// and ...
// ... it also works for when the user makes the window larger
// and then the scrollbar disappears but that makes thumbnails
// larger and then scrollbar reappears and ...
Thumbnail *t;
if (numRows() == 0) return;
t = dynamic_cast<Thumbnail *>(cellWidget(0, 0));
if (size().height() <= m_heightLimit)
{
if (t->getImageHeight() > (int)(visibleWidth()*m_ar))
{
setColumnWidth(0, visibleWidth());
resizeThumbnails();
}
}
else
{
if (visibleWidth() != columnWidth(0))
{
setColumnWidth(0, visibleWidth());
resizeThumbnails();
if (size().height() > m_heightLimit && verticalScrollBar() -> isVisible())
{
m_heightLimit = (int) ceil(numRows() * ((visibleWidth() + verticalScrollBar() -> width()) * m_ar + t -> labelSizeHintHeight()));
}
}
}
}
void ThumbnailList::resizeThumbnails()
{
Thumbnail *t;
for(int i = 0; i < numRows(); ++i)
{
t = dynamic_cast<Thumbnail *>(cellWidget(i, 0));
t->setImageSize((int)(visibleWidth()*m_ar), visibleWidth());
setRowHeight(i, (int)(visibleWidth()*m_ar) + t->labelSizeHintHeight());
Thumbnail *t;
for(int i = 0; i < numRows(); ++i)
{
t = dynamic_cast<Thumbnail *>(cellWidget(i, 0));
t->setImageSize((int)(visibleWidth()*m_ar), visibleWidth());
setRowHeight(i, (int)(visibleWidth()*m_ar) + t->labelSizeHintHeight());
}
}
void ThumbnailList::emitClicked(int i)
{
emit clicked(i+1);
}
#include "thumbnaillist.moc"
......@@ -7,7 +7,6 @@
* (at your option) any later version. *
***************************************************************************/
#ifndef THUMBNAILLIST_H
#define THUMBNAILLIST_H
......@@ -21,42 +20,43 @@ class ThumbnailGenerator;
class ThumbnailList : public QTable
{
Q_OBJECT
public:
ThumbnailList(QWidget *parent, QMutex *docMutex);
~ThumbnailList();
void setCurrentItem(int i);
void setPages(int i, double ar);
void generateThumbnails(PDFDoc *doc);
void stopThumbnailGeneration();
protected slots:
void customEvent(QCustomEvent *e);
private slots:
void changeSelected(int i);
signals:
void clicked(int);
protected:
void viewportResizeEvent(QResizeEvent *);
private:
void generateNextThumbnail();
void resizeThumbnails();
void setThumbnail(int i, const QImage *thumbnail);
double m_ar;
int m_selected;
int m_heightLimit;
int m_nextThumbnail;
ThumbnailGenerator *m_tg;
PDFDoc *m_doc;
QMutex *m_docMutex;
bool m_ignoreNext;
Q_OBJECT
public:
ThumbnailList(QWidget *parent, QMutex *docMutex);
~ThumbnailList();
void setCurrentItem(int i);
void setPages(int i, double ar);
void generateThumbnails(PDFDoc *doc);
void stopThumbnailGeneration();
protected slots:
void customEvent(QCustomEvent *e);
private slots:
void changeSelected(int i);
void emitClicked(int i);
signals:
void clicked(int);
protected:
void viewportResizeEvent(QResizeEvent *);
private:
void generateNextThumbnail();
void resizeThumbnails();
void setThumbnail(int i, const QImage *thumbnail);
double m_ar;
int m_selected;
int m_heightLimit;
int m_nextThumbnail;
ThumbnailGenerator *m_tg;
PDFDoc *m_doc;
QMutex *m_docMutex;
bool m_ignoreNext;
};
#endif
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