[Add] Mkay, last few changes. Home time.
This commit is contained in:
parent
ec660fc3ec
commit
0331399b05
@ -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);
|
||||
void FileWidget::addPageWidget(QImage* image) {
|
||||
PDFPageWidget* newPageWidget;
|
||||
newPageWidget = new PDFPageWidget();
|
||||
newPageWidget->setThumbnail(image);
|
||||
|
||||
child.push_back(newchild);
|
||||
pageWidgets.push_back(newPageWidget);
|
||||
|
||||
mainLayout->addWidget(newchild);
|
||||
adjustSize();
|
||||
}
|
||||
|
||||
void FileWidget::addChild(QImage* image) {
|
||||
PDFPageWidget* newchild;
|
||||
newchild = new PDFPageWidget();
|
||||
newchild->setThumbnail(image);
|
||||
|
||||
child.push_back(newchild);
|
||||
|
||||
mainLayout->addWidget(newchild);
|
||||
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);
|
||||
|
||||
for(int i = 0; i < child.size(); i++) {
|
||||
qDebug() << child[i]->size();
|
||||
}
|
||||
|
||||
mainLayout->removeWidget(child[from]);
|
||||
mainLayout->insertWidget(to, child[from]);
|
||||
mainLayout->removeWidget(pageWidgets[from]);
|
||||
mainLayout->insertWidget(to, pageWidgets[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,20 +67,20 @@ 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) {
|
||||
@ -116,11 +89,13 @@ PDFFileWidget::PDFFileWidget(QWidget* parent) {
|
||||
topLayout = new QGridLayout();
|
||||
|
||||
scrollArea = new QScrollArea();
|
||||
mainChild = new FileWidget();
|
||||
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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user