[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 += \
|
||||
../src/pdf_factory.h \
|
||||
../src/pdf_page_widget.h \
|
||||
../src/pdf_table_view.h \
|
||||
../src/pdf_table_widget.h \
|
||||
../src/pdf_file_widget.h
|
||||
SOURCES += \
|
||||
../src/main.cpp \
|
||||
../src/pdf_factory.cpp \
|
||||
../src/pdf_page_widget.cpp \
|
||||
../src/pdf_table_view.cpp \
|
||||
../src/pdf_table_widget.cpp \
|
||||
../src/pdf_file_widget.cpp
|
||||
|
||||
RESOURCES += hpdf.qrc
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <QtWidgets>
|
||||
#include <QtGlobal>
|
||||
#include "pdf_factory.h"
|
||||
#include "pdf_table_view.h"
|
||||
#include "pdf_table_widget.h"
|
||||
#include "pdf_page_widget.h"
|
||||
|
||||
PDFFactory::PDFFactory(void) {
|
||||
@ -32,8 +32,7 @@ void PDFFactory::createWidgets(void) {
|
||||
layout->addWidget(ribbon);
|
||||
|
||||
/* Create main area (table). */
|
||||
pdfTableView = new PDFTableView();
|
||||
pdfTableView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
pdfTableView = new PDFTableWidget();
|
||||
|
||||
splitter = new QSplitter();
|
||||
/* TODO: change pdfPreview widget. */
|
||||
@ -43,7 +42,7 @@ void PDFFactory::createWidgets(void) {
|
||||
splitter->addWidget(pdfTableView);
|
||||
splitter->addWidget(pdfPreview);
|
||||
QList<int> splitterWidgetSizes;
|
||||
splitterWidgetSizes << 600 << 400;
|
||||
splitterWidgetSizes << 900 << 400;
|
||||
splitter->setSizes(splitterWidgetSizes);
|
||||
splitter->setStretchFactor(0, 1);
|
||||
splitter->setStretchFactor(1, 0.5);
|
||||
@ -51,7 +50,7 @@ void PDFFactory::createWidgets(void) {
|
||||
|
||||
setWindowIcon(QIcon(":/img/hpdf.png"));
|
||||
setWindowTitle(tr("HPDF"));
|
||||
setGeometry(0, 0, 1000, 650);
|
||||
setGeometry(0, 0, 1300, 650);
|
||||
}
|
||||
|
||||
void PDFFactory::createActions(void) {
|
||||
@ -59,7 +58,7 @@ void PDFFactory::createActions(void) {
|
||||
openAction->setIcon(QIcon(":/img/open.png"));
|
||||
openAction->setShortcut(tr("Ctrl+O"));
|
||||
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->setIcon(QIcon(":/img/export.png"));
|
||||
@ -138,3 +137,16 @@ void PDFFactory::createStatusBar(void) {
|
||||
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
|
||||
#include <QMainWindow>
|
||||
#include "pdf_table_view.h"
|
||||
#include "pdf_table_widget.h"
|
||||
|
||||
class QAction;
|
||||
class QWidget;
|
||||
@ -18,8 +18,8 @@ protected:
|
||||
/*void closeEvent(QCloseEvent* event);*/
|
||||
|
||||
private slots:
|
||||
/*void openFile(void);
|
||||
void exportFile(void);
|
||||
void openFile(void);
|
||||
/*void exportFile(void);
|
||||
void exportAllFiles(void);*/
|
||||
|
||||
private:
|
||||
@ -41,7 +41,7 @@ private:
|
||||
|
||||
QTabWidget* ribbon;
|
||||
QScrollArea* scrollArea;
|
||||
PDFTableView* pdfTableView;
|
||||
PDFTableWidget* pdfTableView;
|
||||
QSplitter* splitter;
|
||||
QWidget* pdfPreview;
|
||||
|
||||
|
@ -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 QString;
|
||||
class QScrollArea;
|
||||
|
||||
class PDFFileWidget;
|
||||
|
||||
class PDFTableView : public QFrame {
|
||||
class PDFTableWidget : public QFrame {
|
||||
Q_OBJECT
|
||||
public:
|
||||
PDFTableView(QWidget* parent = 0);
|
||||
PDFTableWidget(QWidget* parent = 0);
|
||||
void loadFile(QString fileName);
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
QVBoxLayout* outerLayout;
|
||||
|
||||
void loadFile(QString fileName);
|
||||
QScrollArea* scrollArea;
|
||||
QWidget* containerWidget;
|
||||
QVBoxLayout* containerLayout;
|
||||
|
||||
QVector<Poppler::Document*> files;
|
||||
QVector<QString> fileNames;
|
Loading…
Reference in New Issue
Block a user