[Add] Mkay, last few changes. Home time.
This commit is contained in:
parent
ec660fc3ec
commit
0331399b05
@ -1,13 +1,5 @@
|
|||||||
#include <QDebug>
|
#include <QtWidgets>
|
||||||
#include <QSizePolicy>
|
#include <QtGlobal>
|
||||||
|
|
||||||
#include <QPixmap>
|
|
||||||
#include <QSize>
|
|
||||||
#include <QDrag>
|
|
||||||
#include <QDragEnterEvent>
|
|
||||||
#include <QMouseEvent>
|
|
||||||
#include <QDropEvent>
|
|
||||||
#include <QMimeData>
|
|
||||||
|
|
||||||
#include "pdf_file_widget.h"
|
#include "pdf_file_widget.h"
|
||||||
#include "pdf_page_widget.h"
|
#include "pdf_page_widget.h"
|
||||||
@ -26,35 +18,22 @@ FileWidget::FileWidget(QWidget* parent) {
|
|||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FileWidget::getChildCount() const {
|
int FileWidget::getPagesCount() const {
|
||||||
return child.size();
|
return pageWidgets.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize FileWidget::sizeHint() const {
|
QSize FileWidget::sizeHint() const {
|
||||||
qDebug() << size();
|
return QSize(CHILD_AREA_WIDTH*getPagesCount(), CHILD_AREA_HEIGHT + 20);
|
||||||
return QSize(CHILD_AREA_WIDTH*getChildCount(), CHILD_AREA_HEIGHT + 20);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileWidget::addChild(QString name) {
|
void FileWidget::addPageWidget(QImage* image) {
|
||||||
PDFPageWidget* newchild;
|
PDFPageWidget* newPageWidget;
|
||||||
newchild = new PDFPageWidget();
|
newPageWidget = new PDFPageWidget();
|
||||||
newchild->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
newPageWidget->setThumbnail(image);
|
||||||
newchild->resize(CHILD_AREA_WIDTH, CHILD_AREA_HEIGHT);
|
|
||||||
|
|
||||||
child.push_back(newchild);
|
pageWidgets.push_back(newPageWidget);
|
||||||
|
|
||||||
mainLayout->addWidget(newchild);
|
mainLayout->addWidget(newPageWidget);
|
||||||
adjustSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
void FileWidget::addChild(QImage* image) {
|
|
||||||
PDFPageWidget* newchild;
|
|
||||||
newchild = new PDFPageWidget();
|
|
||||||
newchild->setThumbnail(image);
|
|
||||||
|
|
||||||
child.push_back(newchild);
|
|
||||||
|
|
||||||
mainLayout->addWidget(newchild);
|
|
||||||
adjustSize();
|
adjustSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,23 +44,17 @@ void FileWidget::dragEnterEvent(QDragEnterEvent* event) {
|
|||||||
|
|
||||||
void FileWidget::dropEvent(QDropEvent* event) {
|
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 = 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();
|
event->acceptProposedAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileWidget::mousePressEvent(QMouseEvent* event) {
|
void FileWidget::mousePressEvent(QMouseEvent* event) {
|
||||||
if(event->button() == Qt::LeftButton) {
|
if(event->button() == Qt::LeftButton) {
|
||||||
int draggedChild = (findClickEventChild(event->pos()));
|
int draggedChild = (findPageContainingClickEvent(event->pos()));
|
||||||
|
|
||||||
QDrag* drag = new QDrag(this);
|
QDrag* drag = new QDrag(this);
|
||||||
QMimeData* mimeData = new QMimeData;
|
QMimeData* mimeData = new QMimeData;
|
||||||
@ -94,20 +67,20 @@ void FileWidget::mousePressEvent(QMouseEvent* event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int FileWidget::findClickEventChild(QPoint pos) {
|
int FileWidget::findPageContainingClickEvent(QPoint pos) {
|
||||||
for(int i = 0; i < getChildCount(); i++)
|
for(int i = 0; i < getPagesCount(); i++)
|
||||||
if(child[i]->geometry().contains(pos))
|
if(pageWidgets[i]->geometry().contains(pos))
|
||||||
return i;
|
return i;
|
||||||
|
|
||||||
return getChildCount()-1;
|
return getPagesCount()-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FileWidget::findChildPositionInLayout(PDFPageWidget* child) {
|
int FileWidget::findPageWidgetInLayout(PDFPageWidget* pageWidget) {
|
||||||
for(int i = 0; i < getChildCount(); i++)
|
for(int i = 0; i < getPagesCount(); i++)
|
||||||
if(mainLayout->itemAt(i)->widget() == child)
|
if(mainLayout->itemAt(i)->widget() == pageWidget)
|
||||||
return i;
|
return i;
|
||||||
|
|
||||||
return getChildCount()-1;
|
return getPagesCount()-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
PDFFileWidget::PDFFileWidget(QWidget* parent) {
|
PDFFileWidget::PDFFileWidget(QWidget* parent) {
|
||||||
@ -116,11 +89,13 @@ PDFFileWidget::PDFFileWidget(QWidget* parent) {
|
|||||||
topLayout = new QGridLayout();
|
topLayout = new QGridLayout();
|
||||||
|
|
||||||
scrollArea = new QScrollArea();
|
scrollArea = new QScrollArea();
|
||||||
mainChild = new FileWidget();
|
fileWidget = new FileWidget();
|
||||||
|
scrollArea->setWidget(fileWidget);
|
||||||
|
|
||||||
widgetName = new QLabel();
|
fileNameLabel = new QLabel();
|
||||||
widgetName->setText(tr("File 1"));
|
fileNameLabel->setText(tr("File 1"));
|
||||||
topLayout->addWidget(widgetName, 0, 1);
|
|
||||||
|
topLayout->addWidget(fileNameLabel, 0, 1);
|
||||||
|
|
||||||
collapseButton = new QPushButton(tr("X"));
|
collapseButton = new QPushButton(tr("X"));
|
||||||
collapseButton->setMinimumSize(QSize(COLLAPSE_BUTTON_WIDTH, COLLAPSE_BUTTON_HEIGHT));
|
collapseButton->setMinimumSize(QSize(COLLAPSE_BUTTON_WIDTH, COLLAPSE_BUTTON_HEIGHT));
|
||||||
@ -129,8 +104,6 @@ PDFFileWidget::PDFFileWidget(QWidget* parent) {
|
|||||||
topLayout->addWidget(collapseButton, 0, 0);
|
topLayout->addWidget(collapseButton, 0, 0);
|
||||||
|
|
||||||
topLayout->addWidget(scrollArea, 1, 0, 1, 5);
|
topLayout->addWidget(scrollArea, 1, 0, 1, 5);
|
||||||
scrollArea->setWidget(mainChild);
|
|
||||||
|
|
||||||
setLayout(topLayout);
|
setLayout(topLayout);
|
||||||
|
|
||||||
setCollapsed(false);
|
setCollapsed(false);
|
||||||
@ -153,7 +126,7 @@ void PDFFileWidget::setCollapsed(bool state) {
|
|||||||
scrollArea->hide();
|
scrollArea->hide();
|
||||||
} else {
|
} else {
|
||||||
collapsed = false;
|
collapsed = false;
|
||||||
setFixedHeight(collapseButton->height() + mainChild->height() + 50);
|
setFixedHeight(collapseButton->height() + fileWidget->height() + 50);
|
||||||
scrollArea->show();
|
scrollArea->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,14 +140,14 @@ void PDFFileWidget::collapsedButtonClick(void) {
|
|||||||
setCollapsed(true);
|
setCollapsed(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PDFFileWidget::setDocument(Poppler::Document* document, QString filename) {
|
void PDFFileWidget::setDocument(Poppler::Document* document, QString fileName) {
|
||||||
int numPages = document->numPages();
|
int numPages = document->numPages();
|
||||||
for(int i; i < numPages; i++) {
|
for(int i; i < numPages; i++) {
|
||||||
Poppler::Page* pdfPage = document->page(i);
|
Poppler::Page* pdfPage = document->page(i);
|
||||||
QImage* image = new QImage();
|
QImage* image = new QImage();
|
||||||
*image = pdfPage->renderToImage();
|
*image = pdfPage->renderToImage(144, 144);
|
||||||
|
|
||||||
mainChild->addChild(image);
|
fileWidget->addPageWidget(image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,38 +1,43 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QScrollArea>
|
|
||||||
#include <QHBoxLayout>
|
|
||||||
#include <QLabel>
|
|
||||||
#include <QPushButton>
|
|
||||||
#include <QGridLayout>
|
|
||||||
#include <QImage>
|
|
||||||
#include <QString>
|
|
||||||
#include <QPoint>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <poppler-qt5.h>
|
#include <poppler-qt5.h>
|
||||||
#include "pdf_page_widget.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 {
|
class FileWidget : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
FileWidget(QWidget* parent = 0);
|
FileWidget(QWidget* parent = 0);
|
||||||
QSize sizeHint() const;
|
QSize sizeHint() const;
|
||||||
|
|
||||||
void addChild(QString name);
|
void addPageWidget(QImage* image);
|
||||||
void addChild(QImage* image);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void dragEnterEvent(QDragEnterEvent* event);
|
void dragEnterEvent(QDragEnterEvent* event);
|
||||||
void dropEvent(QDropEvent* event);
|
void dropEvent(QDropEvent* event);
|
||||||
void mousePressEvent(QMouseEvent* event);
|
void mousePressEvent(QMouseEvent* event);
|
||||||
private:
|
private:
|
||||||
std::vector<PDFPageWidget*> child;
|
std::vector<PDFPageWidget*> pageWidgets;
|
||||||
|
|
||||||
QHBoxLayout* mainLayout;
|
QHBoxLayout* mainLayout;
|
||||||
|
|
||||||
int findClickEventChild(QPoint pos);
|
int findPageContainingClickEvent(QPoint pos);
|
||||||
int findChildPositionInLayout(PDFPageWidget* child);
|
int findPageWidgetInLayout(PDFPageWidget* pageWidgets);
|
||||||
int getChildCount() const;
|
int getPagesCount() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PDFFileWidget : public QWidget {
|
class PDFFileWidget : public QWidget {
|
||||||
@ -44,7 +49,7 @@ public:
|
|||||||
/*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);
|
||||||
@ -58,11 +63,10 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
QGridLayout* topLayout;
|
QGridLayout* topLayout;
|
||||||
|
|
||||||
QLabel* widgetName;
|
QLabel* fileNameLabel;
|
||||||
QPushButton* collapseButton;
|
QPushButton* collapseButton;
|
||||||
QScrollArea* scrollArea;
|
QScrollArea* scrollArea;
|
||||||
|
FileWidget* fileWidget;
|
||||||
FileWidget* mainChild;
|
|
||||||
QWidget* ancestor;
|
QWidget* ancestor;
|
||||||
bool collapsed;
|
bool collapsed;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user