| 1 |
//C- -*- C++ -*- |
| 2 |
//C- ------------------------------------------------------------------- |
| 3 |
//C- DjView4 |
| 4 |
//C- Copyright (c) 2006- Leon Bottou |
| 5 |
//C- |
| 6 |
//C- This software is subject to, and may be distributed under, the |
| 7 |
//C- GNU General Public License, either version 2 of the license, |
| 8 |
//C- or (at your option) any later version. The license should have |
| 9 |
//C- accompanied the software or you may obtain a copy of the license |
| 10 |
//C- from the Free Software Foundation at http://www.fsf.org . |
| 11 |
//C- |
| 12 |
//C- This program is distributed in the hope that it will be useful, |
| 13 |
//C- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
//C- GNU General Public License for more details. |
| 16 |
//C- ------------------------------------------------------------------ |
| 17 |
|
| 18 |
#ifndef QDJVUWIDGET_H |
| 19 |
#define QDJVUWIDGET_H |
| 20 |
|
| 21 |
#if AUTOCONF |
| 22 |
# include "config.h" |
| 23 |
#endif |
| 24 |
|
| 25 |
#include "qdjvu.h" |
| 26 |
|
| 27 |
#include <QPoint> |
| 28 |
#include <QWidget> |
| 29 |
#include <QMenu> |
| 30 |
#include <QAbstractScrollArea> |
| 31 |
|
| 32 |
|
| 33 |
class QDjVuPrivate; |
| 34 |
class QDjVuLens; |
| 35 |
|
| 36 |
class QDjVuWidget : public QAbstractScrollArea |
| 37 |
{ |
| 38 |
Q_OBJECT |
| 39 |
Q_ENUMS(DisplayMode PointerMode Align Priority) |
| 40 |
Q_PROPERTY(int page |
| 41 |
READ page WRITE setPage) |
| 42 |
Q_PROPERTY(int rotation |
| 43 |
READ rotation WRITE setRotation) |
| 44 |
Q_PROPERTY(int zoom |
| 45 |
READ zoom WRITE setZoom) |
| 46 |
Q_PROPERTY(double gamma |
| 47 |
READ gamma WRITE setGamma) |
| 48 |
Q_PROPERTY(double bool |
| 49 |
READ invertLuminance WRITE setInvertLuminance) |
| 50 |
Q_PROPERTY(QColor white |
| 51 |
READ white WRITE setWhite) |
| 52 |
Q_PROPERTY(int screenDpi |
| 53 |
READ screenDpi WRITE setScreenDpi) |
| 54 |
Q_PROPERTY(DisplayMode displayMode |
| 55 |
READ displayMode WRITE setDisplayMode) |
| 56 |
Q_PROPERTY(bool displayFrame |
| 57 |
READ displayFrame WRITE setDisplayFrame) |
| 58 |
Q_PROPERTY(Align horizAlign |
| 59 |
READ horizAlign WRITE setHorizAlign) |
| 60 |
Q_PROPERTY(Align vertAlign |
| 61 |
READ vertAlign WRITE setVertAlign) |
| 62 |
Q_PROPERTY(bool continuous |
| 63 |
READ continuous WRITE setContinuous) |
| 64 |
Q_PROPERTY(bool sideBySide |
| 65 |
READ sideBySide WRITE setSideBySide) |
| 66 |
Q_PROPERTY(bool coverPage |
| 67 |
READ coverPage WRITE setCoverPage) |
| 68 |
Q_PROPERTY(bool rightToLeft |
| 69 |
READ rightToLeft WRITE setRightToLeft) |
| 70 |
Q_PROPERTY(QBrush borderBrush |
| 71 |
READ borderBrush WRITE setBorderBrush) |
| 72 |
Q_PROPERTY(int borderSize |
| 73 |
READ borderSize WRITE setBorderSize) |
| 74 |
Q_PROPERTY(int separatorSize |
| 75 |
READ separatorSize WRITE setSeparatorSize) |
| 76 |
Q_PROPERTY(int pixelCacheSize |
| 77 |
READ pixelCacheSize WRITE setPixelCacheSize) |
| 78 |
Q_PROPERTY(bool displayMapAreas |
| 79 |
READ displayMapAreas WRITE setDisplayMapAreas) |
| 80 |
Q_PROPERTY(bool keyboardEnabled |
| 81 |
READ keyboardEnabled WRITE enableKeyboard) |
| 82 |
Q_PROPERTY(bool hyperlinkEnabled |
| 83 |
READ hyperlinkEnabled WRITE enableHyperlink) |
| 84 |
Q_PROPERTY(bool mouseEnabled |
| 85 |
READ mouseEnabled WRITE enableMouse) |
| 86 |
Q_PROPERTY(bool animationEnabled |
| 87 |
READ animationEnabled WRITE enableAnimation) |
| 88 |
Q_PROPERTY(bool animationInProgress |
| 89 |
READ animationInProgress) |
| 90 |
Q_PROPERTY(bool mouseWheelZoom |
| 91 |
READ mouseWheelZoom WRITE setMouseWheelZoom) |
| 92 |
Q_PROPERTY(int lensPower |
| 93 |
READ lensPower WRITE setLensPower) |
| 94 |
Q_PROPERTY(int lensSize |
| 95 |
READ lensSize WRITE setLensSize) |
| 96 |
Q_PROPERTY(double hourGlassRatio |
| 97 |
READ hourGlassRatio WRITE setHourGlassRatio) |
| 98 |
Q_PROPERTY(QDjVuDocument* document |
| 99 |
READ document WRITE setDocument) |
| 100 |
Q_PROPERTY(QMenu* contextMenu |
| 101 |
READ contextMenu WRITE setContextMenu) |
| 102 |
Q_PROPERTY(Position position |
| 103 |
READ position WRITE setPosition) |
| 104 |
Q_PROPERTY(Qt::KeyboardModifiers modifiersForLens |
| 105 |
READ modifiersForLens WRITE setModifiersForLens) |
| 106 |
Q_PROPERTY(Qt::KeyboardModifiers modifiersForSelect |
| 107 |
READ modifiersForSelect WRITE setModifiersForSelect) |
| 108 |
Q_PROPERTY(Qt::KeyboardModifiers modifiersForLinks |
| 109 |
READ modifiersForLinks WRITE setModifiersForLinks) |
| 110 |
|
| 111 |
public: |
| 112 |
|
| 113 |
enum { |
| 114 |
ZOOM_STRETCH = -4, //!< Stretch full page into viewport |
| 115 |
ZOOM_ONE2ONE = -3, //!< Maximal resolution for each page |
| 116 |
ZOOM_FITPAGE = -2, //!< Fit entire pages into viewport |
| 117 |
ZOOM_FITWIDTH = -1, //!< Fit page width into viewport |
| 118 |
ZOOM_MIN = 5, //!< Minimal magnification |
| 119 |
ZOOM_100 = 100, //!< Standard magnification |
| 120 |
ZOOM_MAX = 1200, //!< Maximal magnification |
| 121 |
}; |
| 122 |
|
| 123 |
enum DisplayMode { |
| 124 |
DISPLAY_COLOR, //!< Default dislplay mode |
| 125 |
DISPLAY_STENCIL, //!< Only display the b&w mask layer |
| 126 |
DISPLAY_BG, //!< Only display the background layer |
| 127 |
DISPLAY_FG, //!< Only display the foregroud layer |
| 128 |
DISPLAY_TEXT, //!< Overprint the text layer |
| 129 |
}; |
| 130 |
|
| 131 |
enum Align { |
| 132 |
ALIGN_TOP, //!< Align page top sides. |
| 133 |
ALIGN_LEFT = ALIGN_TOP, //!< Align page left sides. |
| 134 |
ALIGN_CENTER, //!< Center pages. |
| 135 |
ALIGN_BOTTOM, //!< Align page bottom sides. |
| 136 |
ALIGN_RIGHT = ALIGN_BOTTOM, //!< Align page right sides. |
| 137 |
}; |
| 138 |
|
| 139 |
enum Priority { |
| 140 |
PRIORITY_DEFAULT, //!< Priority for default option values. |
| 141 |
PRIORITY_ANNO, //!< Priority for annotation defined options. |
| 142 |
PRIORITY_CGI, //!< Priority for cgi defined options. |
| 143 |
PRIORITY_USER, //!< Priority for gui defined options. |
| 144 |
}; |
| 145 |
|
| 146 |
struct Position { |
| 147 |
int pageNo; |
| 148 |
QPoint posPage; |
| 149 |
QPoint posView; |
| 150 |
bool inPage; |
| 151 |
bool doPage; |
| 152 |
char hAnchor; |
| 153 |
char vAnchor; |
| 154 |
Position(); |
| 155 |
}; |
| 156 |
|
| 157 |
struct PageInfo { |
| 158 |
int pageno; |
| 159 |
int dpi; |
| 160 |
int width; |
| 161 |
int height; |
| 162 |
QRect segment; |
| 163 |
QRect selected; |
| 164 |
}; |
| 165 |
|
| 166 |
~QDjVuWidget(); |
| 167 |
|
| 168 |
QDjVuWidget(QWidget *parent=0); |
| 169 |
QDjVuWidget(QDjVuDocument *doc, QWidget *parent=0); |
| 170 |
QDjVuWidget(bool opengl, QWidget *parent=0); |
| 171 |
QDjVuWidget(QDjVuDocument *doc, bool opengl, QWidget *parent=0); |
| 172 |
|
| 173 |
QDjVuDocument *document(void) const; |
| 174 |
int page(void) const; |
| 175 |
QPoint hotSpot(void) const; |
| 176 |
Position position(void) const; |
| 177 |
Position position(const QPoint &point) const; |
| 178 |
Position positionWithClosestAnchor(const QPoint &point) const; |
| 179 |
int rotation(void) const; |
| 180 |
int zoom(void) const; |
| 181 |
int zoomFactor(void) const; |
| 182 |
double gamma(void) const; |
| 183 |
bool invertLuminance(void) const; |
| 184 |
QColor white(void) const; |
| 185 |
int screenDpi(void) const; |
| 186 |
DisplayMode displayMode(void) const; |
| 187 |
bool displayFrame(void) const; |
| 188 |
Align horizAlign(void) const; |
| 189 |
Align vertAlign(void) const; |
| 190 |
bool continuous(void) const; |
| 191 |
bool sideBySide(void) const; |
| 192 |
bool coverPage(void) const; |
| 193 |
bool rightToLeft(void) const; |
| 194 |
QBrush borderBrush(void) const; |
| 195 |
int borderSize(void) const; |
| 196 |
int separatorSize(void) const; |
| 197 |
QMenu* contextMenu(void) const; |
| 198 |
int pixelCacheSize(void) const; |
| 199 |
bool displayMapAreas(void) const; |
| 200 |
bool keyboardEnabled(void) const; |
| 201 |
bool mouseEnabled(void) const; |
| 202 |
bool hyperlinkEnabled(void) const; |
| 203 |
bool animationEnabled(void) const; |
| 204 |
bool animationInProgress(void) const; |
| 205 |
bool mouseWheelZoom(void) const; |
| 206 |
int lensPower(void) const; |
| 207 |
int lensSize(void) const; |
| 208 |
double hourGlassRatio(void) const; |
| 209 |
Qt::KeyboardModifiers modifiersForLens() const; |
| 210 |
Qt::KeyboardModifiers modifiersForSelect() const; |
| 211 |
Qt::KeyboardModifiers modifiersForLinks() const; |
| 212 |
|
| 213 |
public slots: |
| 214 |
void setDocument(QDjVuDocument *d); |
| 215 |
void setPage(int p, bool keep=false); |
| 216 |
void setPosition(const Position &pos); |
| 217 |
void setPosition(const Position &pos, const QPoint &p, bool animate=true); |
| 218 |
void setRotation(int); |
| 219 |
void setZoom(int); |
| 220 |
void setGamma(double); |
| 221 |
void setInvertLuminance(bool); |
| 222 |
void setWhite(QColor); |
| 223 |
void setScreenDpi(int); |
| 224 |
void setDisplayMode(DisplayMode m); |
| 225 |
void setDisplayFrame(bool); |
| 226 |
void setHorizAlign(Align); |
| 227 |
void setVertAlign(Align); |
| 228 |
void setContinuous(bool); |
| 229 |
void setSideBySide(bool); |
| 230 |
void setCoverPage(bool); |
| 231 |
void setRightToLeft(bool); |
| 232 |
void setBorderBrush(QBrush); |
| 233 |
void setBorderSize(int); |
| 234 |
void setSeparatorSize(int); |
| 235 |
void setContextMenu(QMenu*); |
| 236 |
void setDisplayMapAreas(bool); |
| 237 |
void setPixelCacheSize(int); |
| 238 |
void enableKeyboard(bool); |
| 239 |
void enableMouse(bool); |
| 240 |
void enableHyperlink(bool); |
| 241 |
void enableAnimation(bool); |
| 242 |
void terminateAnimation(void); |
| 243 |
void setMouseWheelZoom(bool); |
| 244 |
void setLensPower(int); |
| 245 |
void setLensSize(int); |
| 246 |
void setHourGlassRatio(double ratio); |
| 247 |
void setModifiersForLens(Qt::KeyboardModifiers); |
| 248 |
void setModifiersForSelect(Qt::KeyboardModifiers); |
| 249 |
void setModifiersForLinks(Qt::KeyboardModifiers); |
| 250 |
void reduceOptionsToPriority(Priority); |
| 251 |
|
| 252 |
public: |
| 253 |
QString pastErrorMessage(int n=0); |
| 254 |
QString pastInfoMessage(int n=0); |
| 255 |
bool startSelecting(const QPoint &point); |
| 256 |
bool startPanning(const QPoint &point); |
| 257 |
bool startLensing(const QPoint &point); |
| 258 |
bool startLinking(const QPoint &point); |
| 259 |
bool stopInteraction(void); |
| 260 |
QString linkUrl(void); |
| 261 |
QString linkTarget(void); |
| 262 |
QString linkComment(void); |
| 263 |
QString getTextForRect(const QRect &rect); |
| 264 |
bool getTextForPointer(QString results[]); |
| 265 |
QImage getImageForRect(const QRect &rect); |
| 266 |
QRect getSegmentForRect(const QRect &rect, int pageNo); |
| 267 |
|
| 268 |
bool pageSizeKnown(int pageno) const; |
| 269 |
void clearHighlights(int pageno); |
| 270 |
void addHighlight(int pageno, int x, int y, int w, int h, |
| 271 |
QColor color, bool rc=false); |
| 272 |
|
| 273 |
protected: |
| 274 |
virtual bool event(QEvent *event); |
| 275 |
virtual bool viewportEvent (QEvent *event); |
| 276 |
virtual void scrollContentsBy(int dx, int dy); |
| 277 |
virtual void resizeEvent(QResizeEvent *event); |
| 278 |
virtual void keyPressEvent(QKeyEvent *event); |
| 279 |
virtual void modifierEvent(Qt::KeyboardModifiers, Qt::MouseButtons, QPoint); |
| 280 |
virtual void mousePressEvent(QMouseEvent *event); |
| 281 |
virtual void mouseDoubleClickEvent(QMouseEvent *event); |
| 282 |
virtual void mouseReleaseEvent(QMouseEvent *event); |
| 283 |
virtual void mouseMoveEvent(QMouseEvent *event); |
| 284 |
virtual void contextMenuEvent (QContextMenuEvent *event); |
| 285 |
virtual void wheelEvent(QWheelEvent *e); |
| 286 |
virtual void gestureEvent(QEvent *e); |
| 287 |
virtual void paintEvent(QPaintEvent *event); |
| 288 |
virtual void chooseTooltip(void); |
| 289 |
virtual void paintDesk(QPainter &p, const QRegion ®ion); |
| 290 |
virtual void paintFrame(QPainter &p, const QRect &rect, int width); |
| 291 |
virtual void paintEmpty(QPainter &p, const QRect &rect, bool, bool, bool); |
| 292 |
|
| 293 |
public slots: |
| 294 |
void nextPage(void); |
| 295 |
void prevPage(void); |
| 296 |
void firstPage(void); |
| 297 |
void lastPage(void); |
| 298 |
void moveToPageTop(void); |
| 299 |
void moveToPageBottom(void); |
| 300 |
void readNext(void); |
| 301 |
void readPrev(void); |
| 302 |
void zoomIn(void); |
| 303 |
void zoomOut(void); |
| 304 |
void zoomRect(QRect rect); |
| 305 |
void displayModeColor(void); |
| 306 |
void displayModeStencil(void); |
| 307 |
void displayModeBackground(void); |
| 308 |
void displayModeForeground(void); |
| 309 |
void displayModeText(void); |
| 310 |
void rotateRight(void); |
| 311 |
void rotateLeft(void); |
| 312 |
|
| 313 |
signals: |
| 314 |
void layoutChanged(); |
| 315 |
void pageChanged(int pageno); |
| 316 |
void pointerPosition(const Position &pos, const PageInfo &page); |
| 317 |
void pointerEnter(const Position &pos, miniexp_t maparea); |
| 318 |
void pointerLeave(const Position &pos, miniexp_t maparea); |
| 319 |
void pointerClick(const Position &pos, miniexp_t maparea); |
| 320 |
void pointerSelect(const QPoint &pointerPos, const QRect &rect); |
| 321 |
void errorCondition(int pageno); |
| 322 |
void stopCondition(int pageno); |
| 323 |
void keyPressSignal(QKeyEvent *event, bool &done); |
| 324 |
void error(QString message, QString filename, int lineno); |
| 325 |
void info(QString message); |
| 326 |
|
| 327 |
private: |
| 328 |
QDjVuPrivate *priv; |
| 329 |
friend class QDjVuPrivate; |
| 330 |
friend class QDjVuLens; |
| 331 |
}; |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
#endif |
| 338 |
|
| 339 |
/* ------------------------------------------------------------- |
| 340 |
Local Variables: |
| 341 |
c++-font-lock-extra-types: ( "\\sw+_t" "[A-Z]\\sw*[a-z]\\sw*" ) |
| 342 |
End: |
| 343 |
------------------------------------------------------------- */ |