[Change] Large refactor, this build isn't usable.
This commit is contained in:
parent
ec660fc3ec
commit
12623fc962
@ -33,27 +33,23 @@ void PDFFactory::createWidgets(void) {
|
||||
|
||||
/* Create main area (table). */
|
||||
pdfTableView = new TableView();
|
||||
/*pdfTableView->setLayout(new QVBoxLayout());*/
|
||||
/*pdfTableView->setMinimumSize(1000, 1000);*/
|
||||
pdfTableView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
|
||||
pdfSplitter = new QSplitter();
|
||||
splitter = new QSplitter();
|
||||
/* TODO: change pdfPreview widget. */
|
||||
pdfPreview = new QWidget();
|
||||
pdfPreview->setMinimumWidth(100);
|
||||
pdfSplitter->setOrientation(Qt::Horizontal);
|
||||
pdfSplitter->addWidget(pdfTableView);
|
||||
pdfSplitter->addWidget(pdfPreview);
|
||||
layout->addWidget(pdfSplitter);
|
||||
|
||||
/*PDFFile* pdfFile = new PDFFile("/home/docs/loa.pdf");
|
||||
PDFPageWidget* pdfPage = new PDFPageWidget();
|
||||
pdfPage->setPageImage(pdfFile->getPageImage(0));
|
||||
pdfTableView->layout()->addWidget(pdfPage);*/
|
||||
splitter->setOrientation(Qt::Horizontal);
|
||||
splitter->addWidget(pdfTableView);
|
||||
splitter->addWidget(pdfPreview);
|
||||
QList<int> splitterWidgetSizes;
|
||||
splitterWidgetSizes << 700 << 300;
|
||||
splitter->setSizes(splitterWidgetSizes);
|
||||
layout->addWidget(splitter);
|
||||
|
||||
setWindowIcon(QIcon(":/img/hpdf.png"));
|
||||
setWindowTitle(tr("HPDF"));
|
||||
setGeometry(0, 0, 550, 650);
|
||||
setGeometry(0, 0, 1000, 650);
|
||||
}
|
||||
|
||||
void PDFFactory::createActions(void) {
|
||||
|
@ -7,6 +7,7 @@ class QWidget;
|
||||
class QTabWidget;
|
||||
class QScrollArea;
|
||||
class QSplitter;
|
||||
class QToolBar;
|
||||
|
||||
class PDFFactory : public QMainWindow {
|
||||
Q_OBJECT
|
||||
@ -41,7 +42,7 @@ private:
|
||||
QTabWidget* ribbon;
|
||||
QScrollArea* scrollArea;
|
||||
TableView* pdfTableView;
|
||||
QSplitter* pdfSplitter;
|
||||
QSplitter* splitter;
|
||||
QWidget* pdfPreview;
|
||||
|
||||
QToolBar* fileToolBar;
|
||||
|
@ -1,13 +1,5 @@
|
||||
#include <QDebug>
|
||||
#include <QSizePolicy>
|
||||
|
||||
#include <QPixmap>
|
||||
#include <QSize>
|
||||
#include <QDrag>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QDropEvent>
|
||||
#include <QMimeData>
|
||||
#include <QtWidgets>
|
||||
#include <QtGlobal>
|
||||
|
||||
#include "pdf_file_widget.h"
|
||||
#include "pdf_page_widget.h"
|
||||
@ -26,35 +18,22 @@ FileWidget::FileWidget(QWidget* parent) {
|
||||
setLayout(mainLayout);
|
||||
}
|
||||
|
||||
int FileWidget::getChildCount() const {
|
||||
return child.size();
|
||||
int FileWidget::getPagesCount() const {
|
||||
return pageWidgets.size();
|
||||
}
|
||||
|
||||
QSize FileWidget::sizeHint() const {
|
||||
qDebug() << size();
|
||||
return QSize(CHILD_AREA_WIDTH*getChildCount(), CHILD_AREA_HEIGHT + 20);
|
||||
return QSize(CHILD_AREA_WIDTH*getPagesCount(), CHILD_AREA_HEIGHT + 20);
|
||||
}
|
||||
|
||||
void FileWidget::addChild(QString name) {
|
||||
PDFPageWidget* newchild;
|
||||
newchild = new PDFPageWidget();
|
||||
newchild->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
newchild->resize(CHILD_AREA_WIDTH, CHILD_AREA_HEIGHT);
|
||||
|
||||
child.push_back(newchild);
|
||||
|
||||
mainLayout->addWidget(newchild);
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
void FileWidget::addChild(QImage* image) {
|
||||
PDFPageWidget* newchild;
|
||||
newchild = new PDFPageWidget();
|
||||
newchild->setThumbnail(image);
|
||||
|
||||
child.push_back(newchild);
|
||||
void FileWidget::addPageWidget(QImage* image) {
|
||||
PDFPageWidget* newPageWidget;
|
||||
newPageWidget = new PDFPageWidget();
|
||||
newPageWidget->setThumbnail(image);
|
||||
|
||||
mainLayout->addWidget(newchild);
|
||||
pageWidgets.push_back(newPageWidget);
|
||||
|
||||
mainLayout->addWidget(newPageWidget);
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
@ -65,23 +44,17 @@ void FileWidget::dragEnterEvent(QDragEnterEvent* event) {
|
||||
|
||||
void FileWidget::dropEvent(QDropEvent* event) {
|
||||
int from = event->mimeData()->text().toInt();
|
||||
int to = findChildPositionInLayout(child[findClickEventChild(event->pos())]);
|
||||
int to = findPageWidgetInLayout(pageWidgets[findPageContainingClickEvent(event->pos())]);
|
||||
|
||||
qDebug() << "Moving " + QString::number(from) + " " + QString::number(to);
|
||||
mainLayout->removeWidget(pageWidgets[from]);
|
||||
mainLayout->insertWidget(to, pageWidgets[from]);
|
||||
|
||||
for(int i = 0; i < child.size(); i++) {
|
||||
qDebug() << child[i]->size();
|
||||
}
|
||||
|
||||
mainLayout->removeWidget(child[from]);
|
||||
mainLayout->insertWidget(to, child[from]);
|
||||
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
void FileWidget::mousePressEvent(QMouseEvent* event) {
|
||||
if(event->button() == Qt::LeftButton) {
|
||||
int draggedChild = (findClickEventChild(event->pos()));
|
||||
int draggedChild = (findPageContainingClickEvent(event->pos()));
|
||||
|
||||
QDrag* drag = new QDrag(this);
|
||||
QMimeData* mimeData = new QMimeData;
|
||||
@ -94,33 +67,35 @@ void FileWidget::mousePressEvent(QMouseEvent* event) {
|
||||
}
|
||||
}
|
||||
|
||||
int FileWidget::findClickEventChild(QPoint pos) {
|
||||
for(int i = 0; i < getChildCount(); i++)
|
||||
if(child[i]->geometry().contains(pos))
|
||||
int FileWidget::findPageContainingClickEvent(QPoint pos) {
|
||||
for(int i = 0; i < getPagesCount(); i++)
|
||||
if(pageWidgets[i]->geometry().contains(pos))
|
||||
return i;
|
||||
|
||||
return getChildCount()-1;
|
||||
return getPagesCount()-1;
|
||||
}
|
||||
|
||||
int FileWidget::findChildPositionInLayout(PDFPageWidget* child) {
|
||||
for(int i = 0; i < getChildCount(); i++)
|
||||
if(mainLayout->itemAt(i)->widget() == child)
|
||||
int FileWidget::findPageWidgetInLayout(PDFPageWidget* pageWidget) {
|
||||
for(int i = 0; i < getPagesCount(); i++)
|
||||
if(mainLayout->itemAt(i)->widget() == pageWidget)
|
||||
return i;
|
||||
|
||||
return getChildCount()-1;
|
||||
return getPagesCount()-1;
|
||||
}
|
||||
|
||||
PDFFileWidget::PDFFileWidget(QWidget* parent) {
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
|
||||
topLayout = new QGridLayout();
|
||||
topLayout = new QGridLayout();
|
||||
|
||||
scrollArea = new QScrollArea();
|
||||
mainChild = new FileWidget();
|
||||
scrollArea = new QScrollArea();
|
||||
fileWidget = new FileWidget();
|
||||
scrollArea->setWidget(fileWidget);
|
||||
|
||||
widgetName = new QLabel();
|
||||
widgetName->setText(tr("File 1"));
|
||||
topLayout->addWidget(widgetName, 0, 1);
|
||||
fileNameLabel = new QLabel();
|
||||
fileNameLabel->setText(tr("File 1"));
|
||||
|
||||
topLayout->addWidget(fileNameLabel, 0, 1);
|
||||
|
||||
collapseButton = new QPushButton(tr("X"));
|
||||
collapseButton->setMinimumSize(QSize(COLLAPSE_BUTTON_WIDTH, COLLAPSE_BUTTON_HEIGHT));
|
||||
@ -129,8 +104,6 @@ PDFFileWidget::PDFFileWidget(QWidget* parent) {
|
||||
topLayout->addWidget(collapseButton, 0, 0);
|
||||
|
||||
topLayout->addWidget(scrollArea, 1, 0, 1, 5);
|
||||
scrollArea->setWidget(mainChild);
|
||||
|
||||
setLayout(topLayout);
|
||||
|
||||
setCollapsed(false);
|
||||
@ -153,7 +126,7 @@ void PDFFileWidget::setCollapsed(bool state) {
|
||||
scrollArea->hide();
|
||||
} else {
|
||||
collapsed = false;
|
||||
setFixedHeight(collapseButton->height() + mainChild->height() + 50);
|
||||
setFixedHeight(collapseButton->height() + fileWidget->height() + 50);
|
||||
scrollArea->show();
|
||||
}
|
||||
|
||||
@ -167,14 +140,14 @@ void PDFFileWidget::collapsedButtonClick(void) {
|
||||
setCollapsed(true);
|
||||
}
|
||||
|
||||
void PDFFileWidget::setDocument(Poppler::Document* document, QString filename) {
|
||||
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();
|
||||
*image = pdfPage->renderToImage(144, 144);
|
||||
|
||||
mainChild->addChild(image);
|
||||
fileWidget->addPageWidget(image);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,38 +1,43 @@
|
||||
#pragma once
|
||||
#include <QWidget>
|
||||
#include <QScrollArea>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QGridLayout>
|
||||
#include <QImage>
|
||||
#include <QString>
|
||||
#include <QPoint>
|
||||
#include <vector>
|
||||
#include <poppler-qt5.h>
|
||||
#include "pdf_page_widget.h"
|
||||
|
||||
class QImage;
|
||||
class QHBoxLayout;
|
||||
class QGridLayout;
|
||||
class QScrollArea;
|
||||
class QPushButton;
|
||||
class QLabel;
|
||||
class QString;
|
||||
class QSize;
|
||||
class QPoint;
|
||||
class QDragEnterEvent;
|
||||
class QDropEvent;
|
||||
class QMouseEvent;
|
||||
class PDFPageWidget;
|
||||
|
||||
class FileWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
FileWidget(QWidget* parent = 0);
|
||||
QSize sizeHint() const;
|
||||
|
||||
void addChild(QString name);
|
||||
void addChild(QImage* image);
|
||||
void addPageWidget(QImage* image);
|
||||
|
||||
protected:
|
||||
void dragEnterEvent(QDragEnterEvent* event);
|
||||
void dropEvent(QDropEvent* event);
|
||||
void mousePressEvent(QMouseEvent* event);
|
||||
private:
|
||||
std::vector<PDFPageWidget*> child;
|
||||
std::vector<PDFPageWidget*> pageWidgets;
|
||||
|
||||
QHBoxLayout* mainLayout;
|
||||
|
||||
int findClickEventChild(QPoint pos);
|
||||
int findChildPositionInLayout(PDFPageWidget* child);
|
||||
int getChildCount() const;
|
||||
int findPageContainingClickEvent(QPoint pos);
|
||||
int findPageWidgetInLayout(PDFPageWidget* pageWidgets);
|
||||
int getPagesCount() const;
|
||||
};
|
||||
|
||||
class PDFFileWidget : public QWidget {
|
||||
@ -44,7 +49,7 @@ public:
|
||||
/*QSize sizeHint() const;*/
|
||||
|
||||
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; }
|
||||
void setCollapsed(bool collapsed);
|
||||
@ -58,11 +63,10 @@ private slots:
|
||||
private:
|
||||
QGridLayout* topLayout;
|
||||
|
||||
QLabel* widgetName;
|
||||
QLabel* fileNameLabel;
|
||||
QPushButton* collapseButton;
|
||||
QScrollArea* scrollArea;
|
||||
|
||||
FileWidget* mainChild;
|
||||
FileWidget* fileWidget;
|
||||
QWidget* ancestor;
|
||||
bool collapsed;
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include <QtGlobal>
|
||||
#include <QtWidgets>
|
||||
#include <QSize>
|
||||
#include "pdf_page_widget.h"
|
||||
|
||||
PDFPageWidget::PDFPageWidget(QWidget* parent) :
|
||||
@ -7,20 +7,12 @@ PDFPageWidget::PDFPageWidget(QWidget* parent) :
|
||||
|
||||
/* Resize widget. */
|
||||
this->resize(150, 150);
|
||||
this->setMinimumHeight(150);
|
||||
this->setMinimumWidth(150);
|
||||
this->setMinimumSize(150, 150);
|
||||
this->setMinimumSize(150, 150);
|
||||
|
||||
this->setMouseTracking(true);
|
||||
this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
|
||||
/* Initialize buttons. */
|
||||
/*button = new QPushButton();
|
||||
QPushButton* btn = new QPusBbutton();
|
||||
QGridLayout* lo = new QGridLayout();
|
||||
btn->setFixedSize(100, 100);
|
||||
qDebug() << btn->geometry();
|
||||
*lo->addWidget(btn);*/
|
||||
|
||||
QVBoxLayout* vbox = new QVBoxLayout(this);
|
||||
QHBoxLayout* hbox = new QHBoxLayout();
|
||||
|
||||
@ -57,6 +49,8 @@ void PDFPageWidget::setButton(QPushButton* btn) {
|
||||
void PDFPageWidget::setThumbnail(QImage* pageImage) {
|
||||
image = pageImage;
|
||||
pixmap = QPixmap::fromImage(*image);
|
||||
pixmap = pixmap.scaled(size(), Qt::KeepAspectRatio);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
@ -72,10 +66,12 @@ void PDFPageWidget::enterEvent(QEvent* event) {
|
||||
|
||||
void PDFPageWidget::paintEvent(QPaintEvent* event) {
|
||||
QPainter painter(this);
|
||||
painter.drawPixmap(QRect(0, 0, width(), height()), pixmap);
|
||||
painter.drawPixmap(QRect((size().width() - pixmap.width()) / 2,
|
||||
(size().height() - pixmap.height()) / 2,
|
||||
pixmap.width(), pixmap.height()), pixmap);
|
||||
}
|
||||
|
||||
QSize PDFPageWidget::sizeHint() const {
|
||||
return QSize(150, 150);
|
||||
return size();
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,12 @@
|
||||
#pragma once
|
||||
#include <QWidget>
|
||||
#include <QPushButton>
|
||||
#include <QVector>
|
||||
|
||||
class QPushButton;
|
||||
class QImage;
|
||||
class QPixmap;
|
||||
class QPaintEvent;
|
||||
class QSize;
|
||||
class QEvent;
|
||||
|
||||
class PDFPageWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
|
@ -1,32 +1,32 @@
|
||||
#include <QtWidgets>
|
||||
#include <QWidget>
|
||||
#include <assert.h>
|
||||
#include "table_view.h"
|
||||
#include "pdf_page_widget.h"
|
||||
#include "pdf_file_widget.h"
|
||||
|
||||
PDFFileWidget* test[10];
|
||||
|
||||
TableView::TableView(QWidget* parent) : QWidget(parent) {
|
||||
outerLayout = new QVBoxLayout();
|
||||
scrollArea = new QScrollArea();
|
||||
frame = new QFrame(scrollArea);
|
||||
layout = new QVBoxLayout();
|
||||
|
||||
setLayout(outerLayout);
|
||||
outerLayout->addWidget(scrollArea);
|
||||
scrollArea->setWidget(frame);
|
||||
frame->setLayout(layout);
|
||||
frame = new QFrame();
|
||||
frame->setLayout(layout);
|
||||
frame->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
|
||||
frame->adjustSize();
|
||||
loadFile("/home/allanis/docs/loa.pdf");
|
||||
|
||||
scrollArea = new QScrollArea();
|
||||
scrollArea->setWidget(frame);
|
||||
|
||||
outerLayout = new QVBoxLayout();
|
||||
setLayout(outerLayout);
|
||||
outerLayout->addWidget(scrollArea);
|
||||
|
||||
loadFile("/home/allanis/docs/loa.pdf");
|
||||
}
|
||||
|
||||
void TableView::loadFile(QString fileName) {
|
||||
filenames.append(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);
|
||||
|
@ -1,17 +1,18 @@
|
||||
#pragma once
|
||||
#include <QWidget>
|
||||
#include <QSplitter>
|
||||
#include <QVBoxLayout>
|
||||
#include <QScrollArea>
|
||||
#include <QPushButton>
|
||||
#include <QFrame>
|
||||
#include <poppler-qt5.h>
|
||||
#include "pdf_page_widget.h"
|
||||
#include "pdf_file_widget.h"
|
||||
|
||||
class QPushButton;
|
||||
class QWidget;
|
||||
class QScrollArea;
|
||||
class QVBoxLayout;
|
||||
class QSplitter;
|
||||
class QFrame;
|
||||
class QPaintEvent;
|
||||
class QString;
|
||||
|
||||
class PDFFileWidget;
|
||||
|
||||
class TableView : public QWidget {
|
||||
Q_OBJECT
|
||||
@ -30,7 +31,7 @@ private:
|
||||
void loadFile(QString fileName);
|
||||
|
||||
QVector<Poppler::Document*> files;
|
||||
QVector<QString> filenames;
|
||||
QVector<QString> fileNames;
|
||||
QVector<PDFFileWidget*> fileWidgets;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user