120 lines
3.5 KiB
C++
120 lines
3.5 KiB
C++
#ifndef PREVIEWPDFWIDGET_H
|
|
#define PREVIEWPDFWIDGET_H
|
|
|
|
#include <QWidget>
|
|
#include <QVBoxLayout>
|
|
#include <QLabel>
|
|
#include <QScrollArea>
|
|
#include <QFrame>
|
|
#include <QDebug>
|
|
#include <QPainter>
|
|
#include <QPixmap>
|
|
#include <QList>
|
|
#include <QComboBox>
|
|
#include <QPushButton>
|
|
#include <QHBoxLayout>
|
|
#include <QSpacerItem>
|
|
#include <QTransform>
|
|
#include <QWheelEvent>
|
|
|
|
// Включаем структуру PageInfo
|
|
#include "../model/pageinfo.h"
|
|
|
|
// Класс-обертка для QScrollArea с поддержкой Ctrl+колесико
|
|
class ZoomableScrollArea : public QScrollArea
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit ZoomableScrollArea(QWidget *parent = nullptr);
|
|
|
|
protected:
|
|
void wheelEvent(QWheelEvent *event) override;
|
|
|
|
signals:
|
|
void zoomRequested(int delta);
|
|
};
|
|
|
|
class MainController;
|
|
class PDFController;
|
|
|
|
class PreviewPdfWidget : public QWidget
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit PreviewPdfWidget(QWidget *parent = nullptr);
|
|
|
|
// Метод для установки главного контроллера (PDFController получается автоматически)
|
|
void setMainController(MainController *mainController);
|
|
|
|
// Метод для обновления предварительного просмотра
|
|
void updatePreview();
|
|
|
|
public slots:
|
|
// Слот для изменения типа документа (вызывается извне)
|
|
void onDocumentTypeChanged(const QString &documentType);
|
|
void onZoomChanged(int index);
|
|
void onPageChanged(int page);
|
|
|
|
private:
|
|
void setUp();
|
|
void setWidgets();
|
|
void setUpLayout();
|
|
void setUpConnections();
|
|
|
|
// Методы для работы с предварительным просмотром
|
|
void generatePages();
|
|
void renderPage(int pageIndex);
|
|
void updatePageNavigation();
|
|
|
|
// Вспомогательные методы
|
|
QPixmap createPagePixmap(const PageInfo &pageInfo);
|
|
void clearPages();
|
|
|
|
// Метод для изменения масштаба с любым значением
|
|
void setZoom(int zoom);
|
|
|
|
// Устаревший метод (для обратной совместимости)
|
|
void setPdfController(PDFController *pdfController);
|
|
|
|
// UI элементы
|
|
QVBoxLayout* m_mainLayout;
|
|
QHBoxLayout* m_controlsLayout;
|
|
ZoomableScrollArea* m_scrollArea;
|
|
QFrame* m_pagesContainer;
|
|
QVBoxLayout* m_pagesLayout;
|
|
QComboBox* m_documentTypeCombo;
|
|
QComboBox* m_zoomCombo;
|
|
QComboBox* m_pageCombo;
|
|
QPushButton* m_prevPageBtn;
|
|
QPushButton* m_nextPageBtn;
|
|
QPushButton* m_refreshBtn;
|
|
QLabel* m_pageInfoLabel;
|
|
|
|
// Контроллеры
|
|
MainController* m_mainController;
|
|
PDFController* m_pdfController;
|
|
|
|
// Данные
|
|
QList<PageInfo> m_pagesInfo;
|
|
QList<QPixmap> m_pagePixmaps;
|
|
int m_currentPage;
|
|
int m_currentZoom;
|
|
QString m_currentDocumentType;
|
|
|
|
// Константы
|
|
static const int ZOOM_LEVELS[];
|
|
static const QStringList DOCUMENT_TYPES;
|
|
|
|
// Дополнительные константы для мелкого масштабирования
|
|
static const int FINE_ZOOM_STEP; // Шаг для Ctrl+колесико (5%)
|
|
static const int MIN_ZOOM; // Минимальный масштаб 10%
|
|
static const int MAX_ZOOM; // Максимальный масштаб 400%
|
|
|
|
signals:
|
|
void pageChanged(int page);
|
|
void documentTypeChanged(const QString &type);
|
|
void zoomChanged(int zoom);
|
|
};
|
|
|
|
#endif // PREVIEWPDFWIDGET_H
|