[Add] Load PDF files.
This commit is contained in:
parent
a79a6e09b3
commit
ec660fc3ec
@ -23,10 +23,6 @@ FileWidget::FileWidget(QWidget* parent) {
|
|||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
mainLayout = new QHBoxLayout();
|
mainLayout = new QHBoxLayout();
|
||||||
|
|
||||||
for(int i = 0; i < 4; i++) {
|
|
||||||
addChild(tr("Child number #") + QString::number(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,6 +31,7 @@ int FileWidget::getChildCount() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QSize FileWidget::sizeHint() const {
|
QSize FileWidget::sizeHint() const {
|
||||||
|
qDebug() << size();
|
||||||
return QSize(CHILD_AREA_WIDTH*getChildCount(), CHILD_AREA_HEIGHT + 20);
|
return QSize(CHILD_AREA_WIDTH*getChildCount(), CHILD_AREA_HEIGHT + 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,12 +40,22 @@ void FileWidget::addChild(QString name) {
|
|||||||
newchild = new PDFPageWidget();
|
newchild = new PDFPageWidget();
|
||||||
newchild->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
newchild->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||||
newchild->resize(CHILD_AREA_WIDTH, CHILD_AREA_HEIGHT);
|
newchild->resize(CHILD_AREA_WIDTH, CHILD_AREA_HEIGHT);
|
||||||
/*newchild->setText(name);*/
|
|
||||||
/*newchild->setStyleSheet("QLabel { background-color : red; color : blue }");*/
|
|
||||||
|
|
||||||
child.push_back(newchild);
|
child.push_back(newchild);
|
||||||
|
|
||||||
mainLayout->addWidget(newchild);
|
mainLayout->addWidget(newchild);
|
||||||
|
adjustSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileWidget::addChild(QImage* image) {
|
||||||
|
PDFPageWidget* newchild;
|
||||||
|
newchild = new PDFPageWidget();
|
||||||
|
newchild->setThumbnail(image);
|
||||||
|
|
||||||
|
child.push_back(newchild);
|
||||||
|
|
||||||
|
mainLayout->addWidget(newchild);
|
||||||
|
adjustSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileWidget::dragEnterEvent(QDragEnterEvent* event) {
|
void FileWidget::dragEnterEvent(QDragEnterEvent* event) {
|
||||||
@ -60,7 +67,11 @@ void FileWidget::dropEvent(QDropEvent* event) {
|
|||||||
int from = event->mimeData()->text().toInt();
|
int from = event->mimeData()->text().toInt();
|
||||||
int to = findChildPositionInLayout(child[findClickEventChild(event->pos())]);
|
int to = findChildPositionInLayout(child[findClickEventChild(event->pos())]);
|
||||||
|
|
||||||
qDebug() << QString::number(from) + " " + QString::number(to);
|
qDebug() << "Moving " + QString::number(from) + " " + QString::number(to);
|
||||||
|
|
||||||
|
for(int i = 0; i < child.size(); i++) {
|
||||||
|
qDebug() << child[i]->size();
|
||||||
|
}
|
||||||
|
|
||||||
mainLayout->removeWidget(child[from]);
|
mainLayout->removeWidget(child[from]);
|
||||||
mainLayout->insertWidget(to, child[from]);
|
mainLayout->insertWidget(to, child[from]);
|
||||||
@ -126,19 +137,23 @@ PDFFileWidget::PDFFileWidget(QWidget* parent) {
|
|||||||
adjustSize();
|
adjustSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
QSize PDFFileWidget::sizeHint() const {
|
QSize PDFFileWidget::sizeHint() const {
|
||||||
if(collapsed == true)
|
if(collapsed == true)
|
||||||
return QSize(mainChild->width(), collapseButton->height());
|
return QSize(mainChild->width(), collapseButton->height());
|
||||||
else
|
else
|
||||||
return QSize(mainChild->width(), collapseButton->height() + mainChild->height() + 50);
|
return QSize(mainChild->width(), collapseButton->height() + mainChild->height() + 50);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void PDFFileWidget::setCollapsed(bool state) {
|
void PDFFileWidget::setCollapsed(bool state) {
|
||||||
if(state == true) {
|
if(state == true) {
|
||||||
collapsed = true;
|
collapsed = true;
|
||||||
|
setFixedHeight(collapseButton->height() + 80);
|
||||||
scrollArea->hide();
|
scrollArea->hide();
|
||||||
} else {
|
} else {
|
||||||
collapsed = false;
|
collapsed = false;
|
||||||
|
setFixedHeight(collapseButton->height() + mainChild->height() + 50);
|
||||||
scrollArea->show();
|
scrollArea->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,3 +167,14 @@ void PDFFileWidget::collapsedButtonClick(void) {
|
|||||||
setCollapsed(true);
|
setCollapsed(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PDFFileWidget::setDocument(Poppler::Document* document, QString filename) {
|
||||||
|
int numPages = document->numPages();
|
||||||
|
for(int i; i < numPages; i++) {
|
||||||
|
Poppler::Page* pdfPage = document->page(i);
|
||||||
|
QImage* image = new QImage();
|
||||||
|
*image = pdfPage->renderToImage();
|
||||||
|
|
||||||
|
mainChild->addChild(image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
@ -16,6 +17,10 @@ class FileWidget : public QWidget {
|
|||||||
public:
|
public:
|
||||||
FileWidget(QWidget* parent = 0);
|
FileWidget(QWidget* parent = 0);
|
||||||
QSize sizeHint() const;
|
QSize sizeHint() const;
|
||||||
|
|
||||||
|
void addChild(QString name);
|
||||||
|
void addChild(QImage* image);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void dragEnterEvent(QDragEnterEvent* event);
|
void dragEnterEvent(QDragEnterEvent* event);
|
||||||
void dropEvent(QDropEvent* event);
|
void dropEvent(QDropEvent* event);
|
||||||
@ -25,7 +30,6 @@ private:
|
|||||||
|
|
||||||
QHBoxLayout* mainLayout;
|
QHBoxLayout* mainLayout;
|
||||||
|
|
||||||
void addChild(QString name);
|
|
||||||
int findClickEventChild(QPoint pos);
|
int findClickEventChild(QPoint pos);
|
||||||
int findChildPositionInLayout(PDFPageWidget* child);
|
int findChildPositionInLayout(PDFPageWidget* child);
|
||||||
int getChildCount() const;
|
int getChildCount() const;
|
||||||
@ -37,10 +41,10 @@ class PDFFileWidget : public QWidget {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
PDFFileWidget(QWidget* parent = 0);
|
PDFFileWidget(QWidget* parent = 0);
|
||||||
QSize sizeHint() const;
|
/*QSize sizeHint() const;*/
|
||||||
|
|
||||||
void setAncestor(QWidget* ancestor) { this->ancestor = ancestor; }
|
void setAncestor(QWidget* ancestor) { this->ancestor = ancestor; }
|
||||||
void setDocument(Poppler::Document* document, QString filename) {};
|
void setDocument(Poppler::Document* document, QString filename);
|
||||||
|
|
||||||
bool isCollapsed(void) { return collapsed; }
|
bool isCollapsed(void) { return collapsed; }
|
||||||
void setCollapsed(bool collapsed);
|
void setCollapsed(bool collapsed);
|
||||||
|
@ -8,6 +8,7 @@ PDFPageWidget::PDFPageWidget(QWidget* parent) :
|
|||||||
/* Resize widget. */
|
/* Resize widget. */
|
||||||
this->resize(150, 150);
|
this->resize(150, 150);
|
||||||
this->setMinimumHeight(150);
|
this->setMinimumHeight(150);
|
||||||
|
this->setMinimumWidth(150);
|
||||||
|
|
||||||
this->setMouseTracking(true);
|
this->setMouseTracking(true);
|
||||||
this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||||
|
@ -18,36 +18,29 @@ TableView::TableView(QWidget* parent) : QWidget(parent) {
|
|||||||
scrollArea->setWidget(frame);
|
scrollArea->setWidget(frame);
|
||||||
frame->setLayout(layout);
|
frame->setLayout(layout);
|
||||||
frame->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
|
frame->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
/* TODO: Page widget is placed for testing only.
|
|
||||||
* To remove pagewidget and add filewidgets later,
|
|
||||||
* use QVector<PDFFile> files to store files.
|
|
||||||
*/
|
|
||||||
/*for(i = 0; i < 10; i++) {
|
|
||||||
test[i] = new PDFPageWidget();
|
|
||||||
test[i]->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
|
|
||||||
|
|
||||||
layout->addWidget(test[i]);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
for(i = 0; i < 10; i++) {
|
|
||||||
test[i] = new PDFFileWidget();
|
|
||||||
/*test[i]->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);*/
|
|
||||||
|
|
||||||
test[i]->setAncestor(this);
|
|
||||||
layout->addWidget(test[i]);
|
|
||||||
}
|
|
||||||
/* End TODO. */
|
|
||||||
frame->adjustSize();
|
frame->adjustSize();
|
||||||
|
loadFile("/home/allanis/docs/loa.pdf");
|
||||||
|
loadFile("/home/allanis/docs/loa.pdf");
|
||||||
|
}
|
||||||
|
|
||||||
|
void TableView::loadFile(QString fileName) {
|
||||||
|
filenames.append(fileName);
|
||||||
|
Poppler::Document* doc = Poppler::Document::load(fileName);
|
||||||
|
files.append(doc);
|
||||||
|
PDFFileWidget* pfw = new PDFFileWidget();
|
||||||
|
pfw->setAncestor(this);
|
||||||
|
pfw->setDocument(doc, fileName);
|
||||||
|
|
||||||
|
fileWidgets.append(pfw);
|
||||||
|
layout->addWidget(pfw);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableView::paintEvent(QPaintEvent* event) {
|
void TableView::paintEvent(QPaintEvent* event) {
|
||||||
frame->adjustSize();
|
frame->adjustSize();
|
||||||
int newWidth = width() - 50;
|
int newWidth = width() - 50;
|
||||||
|
|
||||||
for(int i = 0; i < 10; i++) {
|
for(int i = 0; i < fileWidgets.size(); i++) {
|
||||||
test[i]->resize(newWidth, test[i]->height());
|
fileWidgets.at(i)->resize(newWidth, fileWidgets.at(i)->height());
|
||||||
}
|
}
|
||||||
|
|
||||||
frame->resize(newWidth, frame->height());
|
frame->resize(newWidth, frame->height());
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
#include <poppler-qt5.h>
|
#include <poppler-qt5.h>
|
||||||
#include "pdf_page_widget.h"
|
#include "pdf_page_widget.h"
|
||||||
|
#include "pdf_file_widget.h"
|
||||||
|
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
class QWidget;
|
class QWidget;
|
||||||
@ -26,8 +27,10 @@ private:
|
|||||||
QVBoxLayout* outerLayout;
|
QVBoxLayout* outerLayout;
|
||||||
|
|
||||||
void paintEvent(QPaintEvent* event);
|
void paintEvent(QPaintEvent* event);
|
||||||
|
void loadFile(QString fileName);
|
||||||
|
|
||||||
QVector<Poppler::Document*> files;
|
QVector<Poppler::Document*> files;
|
||||||
QVector<QString> filenames;
|
QVector<QString> filenames;
|
||||||
|
QVector<PDFFileWidget*> fileWidgets;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user