aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/desktop-utils/lumina-pdf/mainUI.h
blob: 87d2a4e44d99aa47075f6ceef5769d669c93f833 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//===========================================
//  Lumina Desktop source code
//  Copyright (c) 2017, Ken Moore
//  Available under the 3-clause BSD license
//  See the LICENSE file for full details
//===========================================
#ifndef _LUMINA_PDF_VIEWER_MAIN_WINDOW_H
#define _LUMINA_PDF_VIEWER_MAIN_WINDOW_H

#include <QPrintPreviewWidget>
#include <QPrintDialog>
#include <QPrinter>
#include <QMainWindow>
#include <QProgressBar>
#include <QLabel>
#include <QKeyEvent>
#include <QDebug>
#include <QWheelEvent>
#include <QApplication>

#include <poppler-qt5.h>

namespace Ui{
	class MainUI;
};

class MainUI : public QMainWindow{
	Q_OBJECT
public:
	MainUI();
	~MainUI();

	void loadFile(QString path);


private:
	Poppler::Document *DOC;
	QPrintPreviewWidget *WIDGET;
	Ui::MainUI *ui;
	QPrinter* Printer;
	QPrintDialog *PrintDLG;

	QString lastdir;

	//Other Interface elements
	QProgressBar *progress;
	QAction *progAct; //action associated with the progressbar
	QTimer *clockTimer;
	//QFrame *frame_presenter;
	QLabel *label_clock;
	QAction *clockAct;

	//PDF Page Loading cache variables
	QHash<int, QImage> loadingHash;
	int numPages;

	void loadPage(int num, Poppler::Document *doc, MainUI *obj, QSize dpi, QSizeF page);

	//Functions/variables for the presentation mode
	QLabel *presentationLabel;
	QScreen *getScreen(bool current, bool &cancelled);
	int CurrentPage;
	void startPresentation(bool atStart);
	void ShowPage(int page);
	void endPresentation();

private slots:
	void startLoadingPages(QPrinter *printer);
	void slotPageLoaded(int);
	void slotStartPresentation(QAction *act);

	void paintOnWidget(QPrinter *PRINTER);
	void paintToPrinter(QPrinter *PRINTER);

	//Button Slots
	void OpenNewFile();

	//Other interface slots
	void updateClock();

signals:
	void PageLoaded(int);

protected:
	void keyPressEvent(QKeyEvent *event){
	  //See if this is one of the special hotkeys and act appropriately
	    //qDebug() << "Got Key Press:";
	  bool inPresentation = (presentationLabel!=0);
 	  if(!inPresentation){
	    //Alternate functionality when **not** in presentation mode
	    /*if(event->key()==Qt::Key_Down){
	      qDebug() << "Send Wheel Event";
 	      QWheelEvent event( WIDGET->mapFromGlobal(QCursor::pos()), QCursor::pos(),QPoint(0,0), QPoint(0,30), 0, Qt::Vertical, Qt::LeftButton, Qt::NoModifier);
	      QApplication::sendEvent(WIDGET, &event);
	      //WIDGET->scrollDown();
 	      return;
	    }else if(event->key()==Qt::Key_Up){
	      return;
	    }*/
	  }

	    if( event->key()==Qt::Key_Escape || event->key()==Qt::Key_Backspace){
	      //qDebug() << " - Escape/Backspace";
	      endPresentation();
	    }else if(event->key()==Qt::Key_Right || event->key()==Qt::Key_Down || event->key()==Qt::Key_Space || event->key()==Qt::Key_PageDown){
	      //qDebug() << " - Right/Down/Spacebar" << inPresentation;
	      ShowPage( WIDGET->currentPage() ); //currentPage() starts at 1 rather than 0
	    }else if(event->key()==Qt::Key_Left || event->key()==Qt::Key_Up || event->key()==Qt::Key_PageUp){
	      //qDebug() << " - Left/Up";
	      ShowPage( WIDGET->currentPage()-2 ); //currentPage() starts at 1 rather than 0
	    }else if(event->key()==Qt::Key_Home){
	      //qDebug() << " - Home";
	      ShowPage(0); //go to the first page
	    }else if(event->key()==Qt::Key_End){
	      //qDebug() << " - End";
	      ShowPage( numPages-1 ); //go to the last page
	    }else if(event->key()==Qt::Key_F11){
	      //qDebug() << " - F11";
	      endPresentation();
            }else{
	      QMainWindow::keyPressEvent(event);
	    }
	}
};
#endif
bgstack15