[Fix] Fixed collapse and scroll.
This commit is contained in:
parent
9576e17f40
commit
e0c1454221
@ -9,13 +9,13 @@ LIBS += -L/usr/lib -lpoppler-qt5
|
|||||||
HEADERS += \
|
HEADERS += \
|
||||||
../src/pdf_factory.h \
|
../src/pdf_factory.h \
|
||||||
../src/pdf_page_widget.h \
|
../src/pdf_page_widget.h \
|
||||||
../src/pdf_table_view.h \
|
../src/pdf_table_widget.h \
|
||||||
../src/pdf_file_widget.h
|
../src/pdf_file_widget.h
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
../src/main.cpp \
|
../src/main.cpp \
|
||||||
../src/pdf_factory.cpp \
|
../src/pdf_factory.cpp \
|
||||||
../src/pdf_page_widget.cpp \
|
../src/pdf_page_widget.cpp \
|
||||||
../src/pdf_table_view.cpp \
|
../src/pdf_table_widget.cpp \
|
||||||
../src/pdf_file_widget.cpp
|
../src/pdf_file_widget.cpp
|
||||||
|
|
||||||
RESOURCES += hpdf.qrc
|
RESOURCES += hpdf.qrc
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include <QtWidgets>
|
#include <QtWidgets>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include "pdf_factory.h"
|
#include "pdf_factory.h"
|
||||||
#include "pdf_table_view.h"
|
#include "pdf_table_widget.h"
|
||||||
#include "pdf_page_widget.h"
|
#include "pdf_page_widget.h"
|
||||||
|
|
||||||
PDFFactory::PDFFactory(void) {
|
PDFFactory::PDFFactory(void) {
|
||||||
@ -32,8 +32,7 @@ void PDFFactory::createWidgets(void) {
|
|||||||
layout->addWidget(ribbon);
|
layout->addWidget(ribbon);
|
||||||
|
|
||||||
/* Create main area (table). */
|
/* Create main area (table). */
|
||||||
pdfTableView = new PDFTableView();
|
pdfTableView = new PDFTableWidget();
|
||||||
pdfTableView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
||||||
|
|
||||||
splitter = new QSplitter();
|
splitter = new QSplitter();
|
||||||
/* TODO: change pdfPreview widget. */
|
/* TODO: change pdfPreview widget. */
|
||||||
@ -43,7 +42,7 @@ void PDFFactory::createWidgets(void) {
|
|||||||
splitter->addWidget(pdfTableView);
|
splitter->addWidget(pdfTableView);
|
||||||
splitter->addWidget(pdfPreview);
|
splitter->addWidget(pdfPreview);
|
||||||
QList<int> splitterWidgetSizes;
|
QList<int> splitterWidgetSizes;
|
||||||
splitterWidgetSizes << 600 << 400;
|
splitterWidgetSizes << 900 << 400;
|
||||||
splitter->setSizes(splitterWidgetSizes);
|
splitter->setSizes(splitterWidgetSizes);
|
||||||
splitter->setStretchFactor(0, 1);
|
splitter->setStretchFactor(0, 1);
|
||||||
splitter->setStretchFactor(1, 0.5);
|
splitter->setStretchFactor(1, 0.5);
|
||||||
@ -51,7 +50,7 @@ void PDFFactory::createWidgets(void) {
|
|||||||
|
|
||||||
setWindowIcon(QIcon(":/img/hpdf.png"));
|
setWindowIcon(QIcon(":/img/hpdf.png"));
|
||||||
setWindowTitle(tr("HPDF"));
|
setWindowTitle(tr("HPDF"));
|
||||||
setGeometry(0, 0, 1000, 650);
|
setGeometry(0, 0, 1300, 650);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PDFFactory::createActions(void) {
|
void PDFFactory::createActions(void) {
|
||||||
@ -59,7 +58,7 @@ void PDFFactory::createActions(void) {
|
|||||||
openAction->setIcon(QIcon(":/img/open.png"));
|
openAction->setIcon(QIcon(":/img/open.png"));
|
||||||
openAction->setShortcut(tr("Ctrl+O"));
|
openAction->setShortcut(tr("Ctrl+O"));
|
||||||
openAction->setStatusTip(tr("Open a PDF"));
|
openAction->setStatusTip(tr("Open a PDF"));
|
||||||
connect(openAction, SIGNAL(triggered()), this, SLOT(open()));
|
connect(openAction, SIGNAL(triggered()), this, SLOT(openFile()));
|
||||||
|
|
||||||
exportAction = new QAction(tr("&Export"), this);
|
exportAction = new QAction(tr("&Export"), this);
|
||||||
exportAction->setIcon(QIcon(":/img/export.png"));
|
exportAction->setIcon(QIcon(":/img/export.png"));
|
||||||
@ -138,3 +137,16 @@ void PDFFactory::createStatusBar(void) {
|
|||||||
statusBar()->showMessage(tr(""));
|
statusBar()->showMessage(tr(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PDFFactory::openFile() {
|
||||||
|
QStringList fileNames = QFileDialog::getOpenFileNames(this,
|
||||||
|
tr("Open PDF file"), ".",
|
||||||
|
tr("PDF file (*.pdf)"));
|
||||||
|
|
||||||
|
for(int i = 0; i < fileNames.size(); i++) {
|
||||||
|
QString fileName = fileNames.at(i);
|
||||||
|
if(!fileName.isEmpty()) {
|
||||||
|
pdfTableView->loadFile(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include "pdf_table_view.h"
|
#include "pdf_table_widget.h"
|
||||||
|
|
||||||
class QAction;
|
class QAction;
|
||||||
class QWidget;
|
class QWidget;
|
||||||
@ -18,8 +18,8 @@ protected:
|
|||||||
/*void closeEvent(QCloseEvent* event);*/
|
/*void closeEvent(QCloseEvent* event);*/
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
/*void openFile(void);
|
void openFile(void);
|
||||||
void exportFile(void);
|
/*void exportFile(void);
|
||||||
void exportAllFiles(void);*/
|
void exportAllFiles(void);*/
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -39,11 +39,11 @@ private:
|
|||||||
|
|
||||||
QWidget* centralWidget;
|
QWidget* centralWidget;
|
||||||
|
|
||||||
QTabWidget* ribbon;
|
QTabWidget* ribbon;
|
||||||
QScrollArea* scrollArea;
|
QScrollArea* scrollArea;
|
||||||
PDFTableView* pdfTableView;
|
PDFTableWidget* pdfTableView;
|
||||||
QSplitter* splitter;
|
QSplitter* splitter;
|
||||||
QWidget* pdfPreview;
|
QWidget* pdfPreview;
|
||||||
|
|
||||||
QToolBar* fileToolBar;
|
QToolBar* fileToolBar;
|
||||||
QToolBar* editToolBar;
|
QToolBar* editToolBar;
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
#include <QtWidgets>
|
|
||||||
#include "pdf_table_view.h"
|
|
||||||
#include "pdf_page_widget.h"
|
|
||||||
#include "pdf_file_widget.h"
|
|
||||||
|
|
||||||
PDFTableView::PDFTableView(QWidget* parent) : QFrame(parent) {
|
|
||||||
setFrameStyle(QFrame::StyledPanel | QFrame::Plain);
|
|
||||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
||||||
|
|
||||||
outerLayout = new QVBoxLayout();
|
|
||||||
outerLayout->setContentsMargins(0, 0, 0, 0);
|
|
||||||
|
|
||||||
/* Spacer item. */
|
|
||||||
QWidget* spacer = new QWidget();
|
|
||||||
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
||||||
outerLayout->addWidget(spacer);
|
|
||||||
|
|
||||||
setLayout(outerLayout);
|
|
||||||
|
|
||||||
loadFile("/home/allanis/docs/loa.pdf");
|
|
||||||
}
|
|
||||||
|
|
||||||
void PDFTableView::loadFile(QString fileName) {
|
|
||||||
fileNames.append(fileName);
|
|
||||||
|
|
||||||
Poppler::Document* doc = Poppler::Document::load(fileName);
|
|
||||||
files.append(doc);
|
|
||||||
|
|
||||||
PDFFileWidget* fileWidget = new PDFFileWidget();
|
|
||||||
fileWidget->setAncestor(this);
|
|
||||||
fileWidget->setDocument(doc, fileName);
|
|
||||||
|
|
||||||
fileWidgets.append(fileWidget);
|
|
||||||
outerLayout->insertWidget(outerLayout->count()-1, fileWidget);
|
|
||||||
}
|
|
||||||
|
|
49
src/pdf_table_widget.cpp
Normal file
49
src/pdf_table_widget.cpp
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#include <QtWidgets>
|
||||||
|
#include "pdf_table_widget.h"
|
||||||
|
#include "pdf_page_widget.h"
|
||||||
|
#include "pdf_file_widget.h"
|
||||||
|
|
||||||
|
PDFTableWidget::PDFTableWidget(QWidget* parent) : QFrame(parent) {
|
||||||
|
/* Frame (Expanding with VBox) - Scroll Area (Expanding)
|
||||||
|
* Container (Expanding with VBox) - Children.
|
||||||
|
*/
|
||||||
|
setFrameStyle(QFrame::StyledPanel | QFrame::Plain);
|
||||||
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
|
|
||||||
|
outerLayout = new QVBoxLayout();
|
||||||
|
outerLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
|
||||||
|
scrollArea = new QScrollArea();
|
||||||
|
scrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
|
scrollArea->setWidgetResizable(true);
|
||||||
|
|
||||||
|
containerLayout = new QVBoxLayout();
|
||||||
|
containerWidget = new QWidget();
|
||||||
|
containerWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
|
QWidget* spacer = new QWidget();
|
||||||
|
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
|
containerLayout->addWidget(spacer);
|
||||||
|
containerWidget->setLayout(containerLayout);
|
||||||
|
|
||||||
|
scrollArea->setWidget(containerWidget);
|
||||||
|
|
||||||
|
outerLayout->addWidget(scrollArea);
|
||||||
|
|
||||||
|
setLayout(outerLayout);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDFTableWidget::loadFile(QString fileName) {
|
||||||
|
fileNames.append(fileName);
|
||||||
|
|
||||||
|
Poppler::Document* doc = Poppler::Document::load(fileName);
|
||||||
|
files.append(doc);
|
||||||
|
|
||||||
|
PDFFileWidget* fileWidget = new PDFFileWidget();
|
||||||
|
fileWidget->setAncestor(this);
|
||||||
|
fileWidget->setDocument(doc, fileName);
|
||||||
|
|
||||||
|
fileWidgets.append(fileWidget);
|
||||||
|
|
||||||
|
containerLayout->insertWidget(containerLayout->count()-1, fileWidget);
|
||||||
|
}
|
||||||
|
|
@ -4,20 +4,24 @@
|
|||||||
|
|
||||||
class QVBoxLayout;
|
class QVBoxLayout;
|
||||||
class QString;
|
class QString;
|
||||||
|
class QScrollArea;
|
||||||
|
|
||||||
class PDFFileWidget;
|
class PDFFileWidget;
|
||||||
|
|
||||||
class PDFTableView : public QFrame {
|
class PDFTableWidget : public QFrame {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
PDFTableView(QWidget* parent = 0);
|
PDFTableWidget(QWidget* parent = 0);
|
||||||
|
void loadFile(QString fileName);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVBoxLayout* outerLayout;
|
QVBoxLayout* outerLayout;
|
||||||
|
|
||||||
void loadFile(QString fileName);
|
QScrollArea* scrollArea;
|
||||||
|
QWidget* containerWidget;
|
||||||
|
QVBoxLayout* containerLayout;
|
||||||
|
|
||||||
QVector<Poppler::Document*> files;
|
QVector<Poppler::Document*> files;
|
||||||
QVector<QString> fileNames;
|
QVector<QString> fileNames;
|
Loading…
Reference in New Issue
Block a user