1 #ifndef __VIEWER_H 2 #define __VIEWER_H 3 4 #include <QMainWindow> 5 6 #include <QScrollArea> 7 #include <QAction> 8 #include <QTimer> 9 #include <QLabel> 10 #include <QPixmap> 11 #include <QKeyEvent> 12 #include <QResizeEvent> 13 #include <QWheelEvent> 14 #include <QMouseEvent> 15 #include <QCloseEvent> 16 #include <QPropertyAnimation> 17 #include <QParallelAnimationGroup> 18 #include <QSettings> 19 20 #include "scroll_management.h" 21 22 class ComicDB; 23 class Comic; 24 class MagnifyingGlass; 25 class GoToFlow; 26 class BookmarksDialog; 27 class Render; 28 class GoToDialog; 29 class YACReaderTranslator; 30 class GoToFlowWidget; 31 class Bookmarks; 32 class PageLabelWidget; 33 class NotificationsLabelWidget; 34 35 class Viewer : public QScrollArea, public ScrollManagement 36 { 37 Q_OBJECT 38 public: 39 bool fullscreen; //TODO, change by the right use of windowState(); 40 public slots: 41 void increaseZoomFactor(); 42 void decreaseZoomFactor(); 43 void setZoomFactor(int); 44 int getZoomFactor(); 45 46 void prepareForOpening(); 47 void open(QString pathFile, int atPage = -1); 48 void open(QString pathFile, const ComicDB &comic); 49 void prev(); 50 void next(); 51 void left(); 52 void right(); 53 void showGoToDialog(); 54 void goTo(unsigned int page); 55 void updatePage(); 56 void updateContentSize(); 57 void updateVerticalScrollBar(); 58 void updateOptions(); 59 void scrollDown(); 60 void scrollUp(); 61 void scrollForwardHorizontalFirst(); 62 void scrollBackwardHorizontalFirst(); 63 void scrollForwardVerticalFirst(); 64 void scrollBackwardVerticalFirst(); 65 void magnifyingGlassSwitch(); 66 void showMagnifyingGlass(); 67 void hideMagnifyingGlass(); 68 void informationSwitch(); 69 void updateInformation(); 70 void goToFlowSwitch(); 71 void showGoToFlow(); 72 void moveCursoToGoToFlow(); 73 void animateShowGoToFlow(); 74 void animateHideGoToFlow(); 75 void rotateLeft(); 76 void rotateRight(); magnifyingGlassIsVisible()77 bool magnifyingGlassIsVisible() { return magnifyingGlassShowed; } 78 void setBookmark(bool); 79 void save(); 80 void doublePageSwitch(); 81 void setMangaWithoutStoringSetting(bool manga); 82 void doubleMangaPageSwitch(); 83 void resetContent(); 84 void setLoadingMessage(); 85 void setPageUnavailableMessage(); 86 void configureContent(QString msg); 87 void hideCursor(); 88 void showCursor(); 89 void createConnections(); 90 void translatorSwitch(); 91 void animateShowTranslator(); 92 void animateHideTranslator(); 93 void mousePressEvent(QMouseEvent *event) override; 94 void mouseReleaseEvent(QMouseEvent *event) override; 95 void updateBackgroundColor(const QColor &color); 96 void updateConfig(QSettings *settings); 97 void showMessageErrorOpening(); 98 void showMessageErrorOpening(QString); 99 void processCRCError(QString message); 100 void setBookmarks(); 101 //deprecated 102 void updateImageOptions(); 103 void updateFilters(int brightness, int contrast, int gamma); 104 void showIsCoverMessage(); 105 void showIsLastMessage(); 106 int getCurrentPageNumber(); 107 void updateZoomRatio(int ratio); 108 bool getIsMangaMode(); 109 110 private: 111 bool information; 112 bool doublePage; 113 bool doubleMangaPage; 114 115 int zoom; 116 117 PageLabelWidget *informationLabel; 118 //QTimer * scroller; 119 QPropertyAnimation *verticalScroller; 120 QPropertyAnimation *horizontalScroller; 121 QParallelAnimationGroup *groupScroller; 122 int posByStep; 123 int nextPos; 124 GoToFlowWidget *goToFlow; 125 QPropertyAnimation *showGoToFlowAnimation; 126 GoToDialog *goToDialog; 127 //!Image properties 128 //! Comic 129 //Comic * comic; 130 int index; 131 QPixmap *currentPage; 132 BookmarksDialog *bd; 133 bool wheelStop; 134 Render *render; 135 QTimer *hideCursorTimer; 136 int direction; 137 bool drag; 138 int numScrollSteps; 139 140 //!Widgets 141 QLabel *content; 142 143 YACReaderTranslator *translator; 144 int translatorXPos; 145 QPropertyAnimation *translatorAnimation; 146 147 int yDragOrigin; 148 int xDragOrigin; 149 150 NotificationsLabelWidget *notificationsLabel; 151 152 bool shouldOpenNext; 153 bool shouldOpenPrevious; 154 155 private: 156 //!Magnifying glass 157 MagnifyingGlass *mglass; 158 bool magnifyingGlassShowed; 159 bool restoreMagnifyingGlass; 160 161 //! Manejadores de evento: 162 void keyPressEvent(QKeyEvent *event) override; 163 void resizeEvent(QResizeEvent *event) override; 164 void wheelEvent(QWheelEvent *event) override; 165 void mouseMoveEvent(QMouseEvent *event) override; 166 167 void moveAction(const QKeySequence &key); 168 169 //!ZigzagScroll 170 enum scrollDirection { UP, 171 DOWN, 172 LEFT, 173 RIGHT }; 174 bool isEdge(scrollDirection d); 175 void scrollZigzag(scrollDirection d1, scrollDirection d2, bool forward); 176 void scrollTo(int x, int y); 177 178 public: 179 Viewer(QWidget *parent = nullptr); 180 ~Viewer(); 181 const QPixmap *pixmap(); 182 //Comic * getComic(){return comic;} getBookmarksDialog()183 const BookmarksDialog *getBookmarksDialog() { return bd; } 184 //returns the current index starting in 1 [1,nPages] 185 unsigned int getIndex(); 186 void updateComic(ComicDB &comic); 187 signals: 188 void backgroundChanges(); 189 void pageAvailable(bool); 190 void pageIsBookmark(bool); 191 void reset(); 192 void openNextComic(); 193 void openPreviousComic(); 194 void zoomUpdated(int); 195 }; 196 197 #endif 198