| 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 |
#if AUTOCONF |
| 19 |
# include "config.h" |
| 20 |
#else |
| 21 |
# define HAVE_STRING_H 1 |
| 22 |
# define HAVE_STRERROR 1 |
| 23 |
# ifndef WIN32 |
| 24 |
# define HAVE_UNISTD_H 1 |
| 25 |
# endif |
| 26 |
#endif |
| 27 |
|
| 28 |
#if HAVE_STRING_H |
| 29 |
# include <string.h> |
| 30 |
#endif |
| 31 |
#if HAVE_UNISTD_H |
| 32 |
# include <unistd.h> |
| 33 |
#endif |
| 34 |
#include <errno.h> |
| 35 |
|
| 36 |
#include <libdjvu/miniexp.h> |
| 37 |
#include <libdjvu/ddjvuapi.h> |
| 38 |
|
| 39 |
#include <QAction> |
| 40 |
#include <QActionGroup> |
| 41 |
#include <QApplication> |
| 42 |
#include <QBoxLayout> |
| 43 |
#include <QClipboard> |
| 44 |
#include <QCloseEvent> |
| 45 |
#include <QComboBox> |
| 46 |
#include <QCoreApplication> |
| 47 |
#include <QDebug> |
| 48 |
#include <QDialog> |
| 49 |
#include <QDir> |
| 50 |
#include <QDockWidget> |
| 51 |
#include <QDragEnterEvent> |
| 52 |
#include <QDragMoveEvent> |
| 53 |
#include <QDropEvent> |
| 54 |
#include <QEvent> |
| 55 |
#include <QFile> |
| 56 |
#include <QFileDialog> |
| 57 |
#include <QFileInfo> |
| 58 |
#include <QFontMetrics> |
| 59 |
#include <QBoxLayout> |
| 60 |
#include <QFont> |
| 61 |
#include <QFrame> |
| 62 |
#include <QIcon> |
| 63 |
#include <QImageWriter> |
| 64 |
#include <QInputDialog> |
| 65 |
#include <QLabel> |
| 66 |
#include <QLineEdit> |
| 67 |
#include <QList> |
| 68 |
#include <QMainWindow> |
| 69 |
#include <QMenu> |
| 70 |
#include <QMenuBar> |
| 71 |
#include <QMessageBox> |
| 72 |
#include <QMimeData> |
| 73 |
#include <QObject> |
| 74 |
#include <QPair> |
| 75 |
#include <QPalette> |
| 76 |
#include <QProcess> |
| 77 |
#include <QRegExp> |
| 78 |
#include <QScrollBar> |
| 79 |
#include <QSettings> |
| 80 |
#include <QShortcut> |
| 81 |
#include <QSlider> |
| 82 |
#include <QStackedLayout> |
| 83 |
#include <QStatusBar> |
| 84 |
#include <QString> |
| 85 |
#include <QStyle> |
| 86 |
#include <QStyleOptionComboBox> |
| 87 |
#include <QTextDocument> |
| 88 |
#include <QTextStream> |
| 89 |
#include <QTimer> |
| 90 |
#include <QTabWidget> |
| 91 |
#include <QToolBar> |
| 92 |
#include <QUrl> |
| 93 |
#include <QWhatsThis> |
| 94 |
#if QT_VERSION >= 0x40200 |
| 95 |
# include <QDesktopServices> |
| 96 |
#endif |
| 97 |
#if QT_VERSION >= 0x50000 |
| 98 |
# include <QUrlQuery> |
| 99 |
#endif |
| 100 |
#if QT_VERSION >= 0x50E00 |
| 101 |
# define tr8 tr |
| 102 |
# define swidth(m,s) (m).horizontalAdvance(s) |
| 103 |
# define zero(T) T() |
| 104 |
#else |
| 105 |
# define tr8 trUtf8 |
| 106 |
# define swidth(m,s) (m).width(s) |
| 107 |
# define zero(T) 0 |
| 108 |
#endif |
| 109 |
#if QT_VERSION >= 0x60000 |
| 110 |
# define reReplace(s,r,a) (r).replaceIn((s),(a)) |
| 111 |
# define reIndex(s,r,p) (r).indexIn((s),(p)) |
| 112 |
#else |
| 113 |
# define reReplace(s,r,a) (s).replace((r),(a)) |
| 114 |
# define reIndex(s,r,p) (s).indexOf((r),(p)) |
| 115 |
#endif |
| 116 |
|
| 117 |
#include "qdjvu.h" |
| 118 |
#include "qdjvunet.h" |
| 119 |
#include "qdjvuwidget.h" |
| 120 |
#include "qdjview.h" |
| 121 |
#include "qdjviewprefs.h" |
| 122 |
#include "qdjviewdialogs.h" |
| 123 |
#include "qdjviewsidebar.h" |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
// ---------------------------------------- |
| 128 |
// UTILITIES |
| 129 |
|
| 130 |
typedef QList<QPair<QString, QString> > QueryItems; |
| 131 |
|
| 132 |
static QueryItems |
| 133 |
urlQueryItems(const QUrl &url, bool fullydecoded=false) |
| 134 |
{ |
| 135 |
#if QT_VERSION >= 0x50000 |
| 136 |
if (fullydecoded) |
| 137 |
return QUrlQuery(url).queryItems(QUrl::FullyDecoded); |
| 138 |
return QUrlQuery(url).queryItems(); |
| 139 |
#else |
| 140 |
Q_UNUSED(fullydecoded); |
| 141 |
return url.queryItems(); |
| 142 |
#endif |
| 143 |
} |
| 144 |
|
| 145 |
static void |
| 146 |
addQueryItem(QueryItems &items, const QString &k, const QString &v) |
| 147 |
{ |
| 148 |
items.append(qMakePair(k,v)); |
| 149 |
} |
| 150 |
|
| 151 |
static bool |
| 152 |
hasQueryItem(const QueryItems &items, QString key, bool afterDjvuOpts=true) |
| 153 |
{ |
| 154 |
key = key.toLower(); |
| 155 |
QPair<QString,QString> pair; |
| 156 |
foreach(pair, items) |
| 157 |
if (pair.first.toLower() == "djvuopts") |
| 158 |
afterDjvuOpts = true; |
| 159 |
else if (afterDjvuOpts && pair.first.toLower() == key) |
| 160 |
return true; |
| 161 |
return false; |
| 162 |
} |
| 163 |
|
| 164 |
static void |
| 165 |
urlSetQueryItems(QUrl &url, const QueryItems &items) |
| 166 |
{ |
| 167 |
#if QT_VERSION >= 0x50000 |
| 168 |
QUrlQuery qitems; |
| 169 |
qitems.setQueryItems(items); |
| 170 |
url.setQuery(qitems); |
| 171 |
#else |
| 172 |
url.setQueryItems(items); |
| 173 |
#endif |
| 174 |
} |
| 175 |
|
| 176 |
static void |
| 177 |
growPageCombo(QComboBox *p, QString contents = QString()) |
| 178 |
{ |
| 179 |
QFontMetrics metrics(p->font()); |
| 180 |
QSize csize = metrics.size(Qt::TextSingleLine, contents); |
| 181 |
QStyleOptionComboBox options; |
| 182 |
options.initFrom(p); |
| 183 |
options.editable = true; |
| 184 |
QSize osize = p->style()->sizeFromContents(QStyle::CT_ComboBox,&options,csize,p); |
| 185 |
p->setMinimumWidth(qMax(p->minimumWidth(), osize.width())); |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
// ---------------------------------------- |
| 191 |
// QDJVIEW |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
/*! \class QDjView |
| 196 |
\brief The main viewer interface. |
| 197 |
|
| 198 |
Class \a QDjView defines the djvu viewer graphical user interface. It is |
| 199 |
composed of a main window with menubar, toolbar, statusbar and a dockable |
| 200 |
sidebar. The center is occupied by a \a QDjVuWidget. */ |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
// ---------------------------------------- |
| 205 |
// FILL USER INTERFACE COMPONENTS |
| 206 |
|
| 207 |
|
| 208 |
void |
| 209 |
QDjView::fillPageCombo(QComboBox *pageCombo) |
| 210 |
{ |
| 211 |
pageCombo->clear(); |
| 212 |
int n = documentPages.size(); |
| 213 |
for (int j=0; j<n; j++) |
| 214 |
{ |
| 215 |
QString name = pageName(j); |
| 216 |
pageCombo->addItem(name, QVariant(j)); |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
void |
| 222 |
QDjView::fillZoomCombo(QComboBox *zoomCombo) |
| 223 |
{ |
| 224 |
zoomCombo->clear(); |
| 225 |
zoomCombo->addItem(tr("FitWidth","zoomCombo"), QDjVuWidget::ZOOM_FITWIDTH); |
| 226 |
zoomCombo->addItem(tr("FitPage","zoomCombo"), QDjVuWidget::ZOOM_FITPAGE); |
| 227 |
zoomCombo->addItem(tr("Stretch","zoomCombo"), QDjVuWidget::ZOOM_STRETCH); |
| 228 |
zoomCombo->addItem(tr("1:1","zoomCombo"), QDjVuWidget::ZOOM_ONE2ONE); |
| 229 |
zoomCombo->addItem(tr("300%","zoomCombo"), 300); |
| 230 |
zoomCombo->addItem(tr("200%","zoomCombo"), 200); |
| 231 |
zoomCombo->addItem(tr("150%","zoomCombo"), 150); |
| 232 |
zoomCombo->addItem(tr("100%","zoomCombo"), 100); |
| 233 |
zoomCombo->addItem(tr("75%","zoomCombo"), 75); |
| 234 |
zoomCombo->addItem(tr("50%","zoomCombo"), 50); |
| 235 |
} |
| 236 |
|
| 237 |
|
| 238 |
void |
| 239 |
QDjView::fillModeCombo(QComboBox *modeCombo) |
| 240 |
{ |
| 241 |
modeCombo->clear(); |
| 242 |
modeCombo->addItem(tr("Color","modeCombo"), QDjVuWidget::DISPLAY_COLOR); |
| 243 |
modeCombo->addItem(tr("Stencil","modeCombo"), QDjVuWidget::DISPLAY_STENCIL); |
| 244 |
modeCombo->addItem(tr("Foreground","modeCombo"), QDjVuWidget::DISPLAY_FG); |
| 245 |
modeCombo->addItem(tr("Background","modeCombo"), QDjVuWidget::DISPLAY_BG); |
| 246 |
modeCombo->addItem(tr("Hidden Text","modeCombo"), QDjVuWidget::DISPLAY_TEXT); |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
void |
| 251 |
QDjView::fillToolBar(QToolBar *toolBar) |
| 252 |
{ |
| 253 |
// Hide toolbar |
| 254 |
bool wasHidden = toolBar->isHidden(); |
| 255 |
toolBar->hide(); |
| 256 |
toolBar->clear(); |
| 257 |
// Hide combo boxes |
| 258 |
modeCombo->hide(); |
| 259 |
pageCombo->hide(); |
| 260 |
zoomCombo->hide(); |
| 261 |
// Use options to compose toolbar |
| 262 |
if (viewerMode >= STANDALONE) |
| 263 |
{ |
| 264 |
if (tools & QDjViewPrefs::TOOL_NEW) |
| 265 |
toolBar->addAction(actionNew); |
| 266 |
if (tools & QDjViewPrefs::TOOL_OPEN) |
| 267 |
toolBar->addAction(actionOpen); |
| 268 |
} |
| 269 |
if (tools & QDjViewPrefs::TOOL_SAVE) |
| 270 |
{ |
| 271 |
toolBar->addAction(actionSave); |
| 272 |
} |
| 273 |
if (tools & QDjViewPrefs::TOOL_PRINT) |
| 274 |
{ |
| 275 |
toolBar->addAction(actionPrint); |
| 276 |
} |
| 277 |
if (tools & QDjViewPrefs::TOOL_FIND) |
| 278 |
{ |
| 279 |
toolBar->addAction(actionFind); |
| 280 |
} |
| 281 |
if (tools & QDjViewPrefs::TOOL_SELECT) |
| 282 |
{ |
| 283 |
toolBar->addAction(actionSelect); |
| 284 |
} |
| 285 |
if (tools & QDjViewPrefs::TOOL_LAYOUT) |
| 286 |
{ |
| 287 |
toolBar->addAction(actionLayoutContinuous); |
| 288 |
toolBar->addAction(actionLayoutSideBySide); |
| 289 |
} |
| 290 |
if ((tools & QDjViewPrefs::TOOL_MODECOMBO) || |
| 291 |
(tools & QDjViewPrefs::TOOL_MODEBUTTONS) ) |
| 292 |
{ |
| 293 |
modeCombo->show(); |
| 294 |
toolBar->addWidget(modeCombo); |
| 295 |
} |
| 296 |
if (tools & QDjViewPrefs::TOOL_ZOOMCOMBO) |
| 297 |
{ |
| 298 |
zoomCombo->show(); |
| 299 |
toolBar->addWidget(zoomCombo); |
| 300 |
} |
| 301 |
if (tools & QDjViewPrefs::TOOL_ZOOMBUTTONS) |
| 302 |
{ |
| 303 |
toolBar->addAction(actionZoomIn); |
| 304 |
toolBar->addAction(actionZoomOut); |
| 305 |
} |
| 306 |
if (tools & QDjViewPrefs::TOOL_ROTATE) |
| 307 |
{ |
| 308 |
toolBar->addAction(actionRotateRight); |
| 309 |
toolBar->addAction(actionRotateLeft); |
| 310 |
} |
| 311 |
if (tools & QDjViewPrefs::TOOL_PAGECOMBO) |
| 312 |
{ |
| 313 |
pageCombo->show(); |
| 314 |
toolBar->addWidget(pageCombo); |
| 315 |
} |
| 316 |
if (tools & QDjViewPrefs::TOOL_FIRSTLAST) |
| 317 |
{ |
| 318 |
toolBar->addAction(actionNavFirst); |
| 319 |
} |
| 320 |
if (tools & QDjViewPrefs::TOOL_PREVNEXT) |
| 321 |
{ |
| 322 |
toolBar->addAction(actionNavPrev); |
| 323 |
toolBar->addAction(actionNavNext); |
| 324 |
} |
| 325 |
if (tools & QDjViewPrefs::TOOL_FIRSTLAST) |
| 326 |
{ |
| 327 |
toolBar->addAction(actionNavLast); |
| 328 |
} |
| 329 |
if (tools & QDjViewPrefs::TOOL_BACKFORW) |
| 330 |
{ |
| 331 |
toolBar->addAction(actionBack); |
| 332 |
toolBar->addAction(actionForw); |
| 333 |
} |
| 334 |
if (tools & QDjViewPrefs::TOOL_WHATSTHIS) |
| 335 |
{ |
| 336 |
toolBar->addAction(actionWhatsThis); |
| 337 |
} |
| 338 |
// Allowed areas |
| 339 |
Qt::ToolBarAreas areas = zero(Qt::ToolBarAreas); |
| 340 |
if (tools & QDjViewPrefs::TOOLBAR_TOP) |
| 341 |
areas |= Qt::TopToolBarArea; |
| 342 |
if (tools & QDjViewPrefs::TOOLBAR_BOTTOM) |
| 343 |
areas |= Qt::BottomToolBarArea; |
| 344 |
if (!areas) |
| 345 |
areas = Qt::TopToolBarArea | Qt::BottomToolBarArea; |
| 346 |
toolBar->setAllowedAreas(areas); |
| 347 |
if (! (toolBarArea(toolBar) & areas)) |
| 348 |
{ |
| 349 |
removeToolBar(toolBar); |
| 350 |
if (areas & Qt::TopToolBarArea) |
| 351 |
addToolBar(Qt::TopToolBarArea, toolBar); |
| 352 |
else |
| 353 |
addToolBar(Qt::BottomToolBarArea, toolBar); |
| 354 |
} |
| 355 |
// Done |
| 356 |
toolBar->setVisible(!wasHidden); |
| 357 |
toolsCached = tools; |
| 358 |
} |
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
// ---------------------------------------- |
| 364 |
// ACTIONS |
| 365 |
|
| 366 |
|
| 367 |
QAction * |
| 368 |
QDjView::makeAction(QString text) |
| 369 |
{ |
| 370 |
QAction *action = new QAction(text, this); |
| 371 |
allActions.append(action); |
| 372 |
return action; |
| 373 |
} |
| 374 |
|
| 375 |
QAction * |
| 376 |
QDjView::makeAction(QString text, Qt::ShortcutContext scontext) |
| 377 |
{ |
| 378 |
QAction *action = new QAction(text, widget); |
| 379 |
allActions.append(action); |
| 380 |
action->setShortcutContext(scontext); |
| 381 |
return action; |
| 382 |
} |
| 383 |
|
| 384 |
QAction * |
| 385 |
QDjView::makeAction(QString text, bool value) |
| 386 |
{ |
| 387 |
QAction *action = new QAction(text, this); |
| 388 |
allActions.append(action); |
| 389 |
action->setCheckable(true); |
| 390 |
action->setChecked(value); |
| 391 |
return action; |
| 392 |
} |
| 393 |
|
| 394 |
static inline QAction * |
| 395 |
operator<<(QAction *action, QIcon icon) |
| 396 |
{ |
| 397 |
action->setIcon(icon); |
| 398 |
return action; |
| 399 |
} |
| 400 |
|
| 401 |
static inline QAction * |
| 402 |
operator<<(QAction *action, QActionGroup &group) |
| 403 |
{ |
| 404 |
action->setActionGroup(&group); |
| 405 |
return action; |
| 406 |
} |
| 407 |
|
| 408 |
static inline QAction * |
| 409 |
operator<<(QAction *action, QKeySequence shortcut) |
| 410 |
{ |
| 411 |
QList<QKeySequence> shortcuts = action->shortcuts(); |
| 412 |
shortcuts.prepend(shortcut); |
| 413 |
action->setShortcuts(shortcuts); |
| 414 |
return action; |
| 415 |
} |
| 416 |
|
| 417 |
static inline QAction * |
| 418 |
operator<<(QAction *action, QString string) |
| 419 |
{ |
| 420 |
if (action->text().isEmpty()) |
| 421 |
action->setText(string); |
| 422 |
else if (action->statusTip().isEmpty()) |
| 423 |
action->setStatusTip(string); |
| 424 |
else if (action->whatsThis().isEmpty()) |
| 425 |
action->setWhatsThis(string); |
| 426 |
return action; |
| 427 |
} |
| 428 |
|
| 429 |
struct Trigger { |
| 430 |
QObject *object; |
| 431 |
const char *slot; |
| 432 |
Trigger(QObject *object, const char *slot) |
| 433 |
: object(object), slot(slot) { } |
| 434 |
}; |
| 435 |
|
| 436 |
static inline QAction * |
| 437 |
operator<<(QAction *action, Trigger trigger) |
| 438 |
{ |
| 439 |
QObject::connect(action, SIGNAL(triggered(bool)), |
| 440 |
trigger.object, trigger.slot); |
| 441 |
return action; |
| 442 |
} |
| 443 |
|
| 444 |
static inline QAction * |
| 445 |
operator<<(QAction *action, QVariant variant) |
| 446 |
{ |
| 447 |
action->setData(variant); |
| 448 |
return action; |
| 449 |
} |
| 450 |
|
| 451 |
void |
| 452 |
QDjView::createActions() |
| 453 |
{ |
| 454 |
// Create action groups |
| 455 |
zoomActionGroup = new QActionGroup(this); |
| 456 |
modeActionGroup = new QActionGroup(this); |
| 457 |
rotationActionGroup = new QActionGroup(this); |
| 458 |
|
| 459 |
// Create all actions |
| 460 |
actionNew = makeAction(tr("&New", "File|")) |
| 461 |
<< QKeySequence(tr("Ctrl+N", "File|New")) |
| 462 |
<< QIcon(":/images/icon_new.png") |
| 463 |
<< tr("Create a new DjView window.") |
| 464 |
<< Trigger(this, SLOT(performNew())); |
| 465 |
|
| 466 |
actionOpen = makeAction(tr("&Open", "File|")) |
| 467 |
<< QKeySequence(tr("Ctrl+O", "File|Open")) |
| 468 |
<< QIcon(":/images/icon_open.png") |
| 469 |
<< tr("Open a DjVu document.") |
| 470 |
<< Trigger(this, SLOT(performOpen())); |
| 471 |
|
| 472 |
actionOpenLocation = makeAction(tr("Open &Location...", "File|")) |
| 473 |
<< tr("Open a remote DjVu document.") |
| 474 |
<< QIcon(":/images/icon_web.png") |
| 475 |
<< Trigger(this, SLOT(performOpenLocation())); |
| 476 |
|
| 477 |
actionClose = makeAction(tr("&Close", "File|")) |
| 478 |
<< QKeySequence(tr("Ctrl+W", "File|Close")) |
| 479 |
<< QIcon(":/images/icon_close.png") |
| 480 |
<< tr("Close this window.") |
| 481 |
<< Trigger(this, SLOT(close())); |
| 482 |
|
| 483 |
actionQuit = makeAction(tr("&Quit", "File|")) |
| 484 |
<< QKeySequence(tr("Ctrl+Q", "File|Quit")) |
| 485 |
<< QIcon(":/images/icon_quit.png") |
| 486 |
<< tr("Close all windows and quit the application.") |
| 487 |
<< Trigger(QCoreApplication::instance(), SLOT(closeAllWindows())); |
| 488 |
|
| 489 |
actionSave = makeAction(tr("Save &as...", "File|")) |
| 490 |
<< QKeySequence(tr("Ctrl+S", "File|SaveAs")) |
| 491 |
<< QIcon(":/images/icon_save.png") |
| 492 |
<< tr("Save the DjVu document.") |
| 493 |
<< Trigger(this, SLOT(saveAs())); |
| 494 |
|
| 495 |
actionExport = makeAction(tr("&Export as...", "File|")) |
| 496 |
<< QKeySequence(tr("Ctrl+E", "File|ExportAs")) |
| 497 |
<< QIcon(":/images/icon_save.png") |
| 498 |
<< tr("Export DjVu page or document to other formats.") |
| 499 |
<< Trigger(this, SLOT(exportAs())); |
| 500 |
|
| 501 |
actionPrint = makeAction(tr("&Print...", "File|")) |
| 502 |
<< QKeySequence(tr("Ctrl+P", "File|Print")) |
| 503 |
<< QIcon(":/images/icon_print.png") |
| 504 |
<< tr("Print the DjVu document.") |
| 505 |
<< Trigger(this, SLOT(print())); |
| 506 |
|
| 507 |
actionFind = makeAction(tr("&Find...", "Edit|")) |
| 508 |
<< QKeySequence(tr("Ctrl+F", "Edit|Find")) |
| 509 |
<< QIcon(":/images/icon_find.png") |
| 510 |
<< tr("Find text in the document.") |
| 511 |
<< Trigger(this, SLOT(showFind())); |
| 512 |
|
| 513 |
actionFindNext = makeAction(tr("Find &Next", "Edit|")) |
| 514 |
<< QKeySequence(tr("F3", "Edit|Find Next")) |
| 515 |
<< tr("Find next occurrence of search text in the document.") |
| 516 |
<< Trigger(findWidget, SLOT(findNext())); |
| 517 |
|
| 518 |
actionFindPrev = makeAction(tr("Find &Previous", "Edit|")) |
| 519 |
<< QKeySequence(tr("Shift+F3", "Edit|Find Previous")) |
| 520 |
<< tr("Find previous occurrence of search text in the document.") |
| 521 |
<< Trigger(findWidget, SLOT(findPrev())); |
| 522 |
|
| 523 |
actionSelect = makeAction(tr("&Select", "Edit|"), false) |
| 524 |
<< QKeySequence(tr("F2", "Edit|Select")) |
| 525 |
<< QIcon(":/images/icon_select.png") |
| 526 |
<< tr("Select a rectangle in the document.") |
| 527 |
<< Trigger(this, SLOT(performSelect(bool))); |
| 528 |
|
| 529 |
actionZoomIn = makeAction(tr("Zoom &In", "Zoom|"), Qt::WidgetWithChildrenShortcut) |
| 530 |
<< QIcon(":/images/icon_zoomin.png") |
| 531 |
<< tr("Increase the magnification.") |
| 532 |
<< QKeySequence("+") |
| 533 |
<< Trigger(widget, SLOT(zoomIn())); |
| 534 |
|
| 535 |
actionZoomOut = makeAction(tr("Zoom &Out", "Zoom|"), Qt::WidgetWithChildrenShortcut) |
| 536 |
<< QIcon(":/images/icon_zoomout.png") |
| 537 |
<< tr("Decrease the magnification.") |
| 538 |
<< QKeySequence("-") |
| 539 |
<< Trigger(widget, SLOT(zoomOut())); |
| 540 |
|
| 541 |
actionZoomFitWidth = makeAction(tr("Fit &Width", "Zoom|"), false) |
| 542 |
<< tr("Set magnification to fit page width.") |
| 543 |
<< QVariant(QDjVuWidget::ZOOM_FITWIDTH) |
| 544 |
<< Trigger(this, SLOT(performZoom())) |
| 545 |
<< *zoomActionGroup; |
| 546 |
|
| 547 |
actionZoomFitPage = makeAction(tr("Fit &Page", "Zoom|"), false) |
| 548 |
<< tr("Set magnification to fit page.") |
| 549 |
<< QVariant(QDjVuWidget::ZOOM_FITPAGE) |
| 550 |
<< Trigger(this, SLOT(performZoom())) |
| 551 |
<< *zoomActionGroup; |
| 552 |
|
| 553 |
actionZoomOneToOne = makeAction(tr("One &to one", "Zoom|"), false) |
| 554 |
<< tr("Set full resolution magnification.") |
| 555 |
<< QVariant(QDjVuWidget::ZOOM_ONE2ONE) |
| 556 |
<< Trigger(this, SLOT(performZoom())) |
| 557 |
<< *zoomActionGroup; |
| 558 |
|
| 559 |
actionZoom300 = makeAction(tr("&300%", "Zoom|"), false) |
| 560 |
<< tr("Magnify 300%") |
| 561 |
<< QVariant(300) |
| 562 |
<< Trigger(this, SLOT(performZoom())) |
| 563 |
<< *zoomActionGroup; |
| 564 |
|
| 565 |
actionZoom200 = makeAction(tr("&200%", "Zoom|"), false) |
| 566 |
<< tr("Magnify 20%") |
| 567 |
<< QVariant(200) |
| 568 |
<< Trigger(this, SLOT(performZoom())) |
| 569 |
<< *zoomActionGroup; |
| 570 |
|
| 571 |
actionZoom150 = makeAction(tr("&150%", "Zoom|"), false) |
| 572 |
<< tr("Magnify 150%") |
| 573 |
<< QVariant(200) |
| 574 |
<< Trigger(this, SLOT(performZoom())) |
| 575 |
<< *zoomActionGroup; |
| 576 |
|
| 577 |
actionZoom100 = makeAction(tr("&100%", "Zoom|"), false) |
| 578 |
<< tr("Magnify 100%") |
| 579 |
<< QVariant(100) |
| 580 |
<< Trigger(this, SLOT(performZoom())) |
| 581 |
<< *zoomActionGroup; |
| 582 |
|
| 583 |
actionZoom75 = makeAction(tr("&75%", "Zoom|"), false) |
| 584 |
<< tr("Magnify 75%") |
| 585 |
<< QVariant(75) |
| 586 |
<< Trigger(this, SLOT(performZoom())) |
| 587 |
<< *zoomActionGroup; |
| 588 |
|
| 589 |
actionZoom50 = makeAction(tr("&50%", "Zoom|"), false) |
| 590 |
<< tr("Magnify 50%") |
| 591 |
<< QVariant(50) |
| 592 |
<< Trigger(this, SLOT(performZoom())) |
| 593 |
<< *zoomActionGroup; |
| 594 |
|
| 595 |
actionNavFirst = makeAction(tr("&First Page", "Go|"), Qt::WidgetWithChildrenShortcut) |
| 596 |
<< QIcon(":/images/icon_first.png") |
| 597 |
<< tr("Jump to first document page.") |
| 598 |
<< QKeySequence("Ctrl+Home") |
| 599 |
<< Trigger(widget, SLOT(firstPage())) |
| 600 |
<< Trigger(this, SLOT(updateActionsLater())); |
| 601 |
|
| 602 |
actionNavNext = makeAction(tr("&Next Page", "Go|"), Qt::WidgetWithChildrenShortcut) |
| 603 |
<< QIcon(":/images/icon_next.png") |
| 604 |
<< tr("Jump to next document page.") |
| 605 |
<< QKeySequence("PgDown") |
| 606 |
<< Trigger(widget, SLOT(nextPage())) |
| 607 |
<< Trigger(this, SLOT(updateActionsLater())); |
| 608 |
|
| 609 |
actionNavPrev = makeAction(tr("&Previous Page", "Go|"), Qt::WidgetWithChildrenShortcut) |
| 610 |
<< QIcon(":/images/icon_prev.png") |
| 611 |
<< tr("Jump to previous document page.") |
| 612 |
<< QKeySequence("PgUp") |
| 613 |
<< Trigger(widget, SLOT(prevPage())) |
| 614 |
<< Trigger(this, SLOT(updateActionsLater())); |
| 615 |
|
| 616 |
actionNavLast = makeAction(tr("&Last Page", "Go|"), Qt::WidgetWithChildrenShortcut) |
| 617 |
<< QIcon(":/images/icon_last.png") |
| 618 |
<< tr("Jump to last document page.") |
| 619 |
<< QKeySequence("Ctrl+End") |
| 620 |
<< Trigger(widget, SLOT(lastPage())) |
| 621 |
<< Trigger(this, SLOT(updateActionsLater())); |
| 622 |
|
| 623 |
actionBack = makeAction(tr("&Backward", "Go|")) |
| 624 |
<< QIcon(":/images/icon_back.png") |
| 625 |
<< tr("Backward in history.") |
| 626 |
<< QKeySequence("Alt+Left") |
| 627 |
<< Trigger(this, SLOT(performUndo())) |
| 628 |
<< Trigger(this, SLOT(updateActionsLater())); |
| 629 |
|
| 630 |
actionForw = makeAction(tr("&Forward", "Go|")) |
| 631 |
<< QIcon(":/images/icon_forw.png") |
| 632 |
<< tr("Forward in history.") |
| 633 |
<< QKeySequence("Alt+Right") |
| 634 |
<< Trigger(this, SLOT(performRedo())) |
| 635 |
<< Trigger(this, SLOT(updateActionsLater())); |
| 636 |
|
| 637 |
actionRotateLeft = makeAction(tr("Rotate &Left", "Rotate|"), Qt::WidgetWithChildrenShortcut) |
| 638 |
<< QIcon(":/images/icon_rotateleft.png") |
| 639 |
<< tr("Rotate page image counter-clockwise.") |
| 640 |
<< QKeySequence("[") |
| 641 |
<< Trigger(widget, SLOT(rotateLeft())) |
| 642 |
<< Trigger(this, SLOT(updateActionsLater())); |
| 643 |
|
| 644 |
actionRotateRight = makeAction(tr("Rotate &Right", "Rotate|"), Qt::WidgetWithChildrenShortcut) |
| 645 |
<< QIcon(":/images/icon_rotateright.png") |
| 646 |
<< tr("Rotate page image clockwise.") |
| 647 |
<< QKeySequence("]") |
| 648 |
<< Trigger(widget, SLOT(rotateRight())) |
| 649 |
<< Trigger(this, SLOT(updateActionsLater())); |
| 650 |
|
| 651 |
actionRotate0 = makeAction(tr8("Rotate &0\302\260", "Rotate|"), false) |
| 652 |
<< tr("Set natural page orientation.") |
| 653 |
<< QVariant(0) |
| 654 |
<< Trigger(this, SLOT(performRotation())) |
| 655 |
<< *rotationActionGroup; |
| 656 |
|
| 657 |
actionRotate90 = makeAction(tr8("Rotate &90\302\260", "Rotate|"), false) |
| 658 |
<< tr("Turn page on its left side.") |
| 659 |
<< QVariant(1) |
| 660 |
<< Trigger(this, SLOT(performRotation())) |
| 661 |
<< *rotationActionGroup; |
| 662 |
|
| 663 |
actionRotate180 = makeAction(tr8("Rotate &180\302\260", "Rotate|"), false) |
| 664 |
<< tr("Turn page upside-down.") |
| 665 |
<< QVariant(2) |
| 666 |
<< Trigger(this, SLOT(performRotation())) |
| 667 |
<< *rotationActionGroup; |
| 668 |
|
| 669 |
actionRotate270 = makeAction(tr8("Rotate &270\302\260", "Rotate|"), false) |
| 670 |
<< tr("Turn page on its right side.") |
| 671 |
<< QVariant(3) |
| 672 |
<< Trigger(this, SLOT(performRotation())) |
| 673 |
<< *rotationActionGroup; |
| 674 |
|
| 675 |
actionInformation = makeAction(tr("&Information...", "Edit|")) |
| 676 |
<< QKeySequence(tr("Ctrl+I", "Edit|Information")) |
| 677 |
<< tr("Show information about the document encoding and structure.") |
| 678 |
<< Trigger(this, SLOT(performInformation())); |
| 679 |
|
| 680 |
actionMetadata = makeAction(tr("&Metadata...", "Edit|")) |
| 681 |
#ifndef Q_OS_DARWIN |
| 682 |
<< QKeySequence(tr("Ctrl+M", "Edit|Metadata")) |
| 683 |
#endif |
| 684 |
<< tr("Show the document and page meta data.") |
| 685 |
<< Trigger(this, SLOT(performMetadata())); |
| 686 |
|
| 687 |
actionWhatsThis = QWhatsThis::createAction(this); |
| 688 |
|
| 689 |
actionAbout = makeAction(tr("&About DjView...")) |
| 690 |
#ifndef Q_OS_DARWIN |
| 691 |
<< QIcon(":/images/djview.png") |
| 692 |
#endif |
| 693 |
<< tr("Show information about this program.") |
| 694 |
<< Trigger(this, SLOT(performAbout())); |
| 695 |
|
| 696 |
actionDisplayColor = makeAction(tr("&Color", "Display|"), false) |
| 697 |
<< tr("Display everything.") |
| 698 |
<< Trigger(widget, SLOT(displayModeColor())) |
| 699 |
<< Trigger(this, SLOT(updateActionsLater())) |
| 700 |
<< *modeActionGroup; |
| 701 |
|
| 702 |
actionDisplayBW = makeAction(tr("&Stencil", "Display|"), false) |
| 703 |
<< tr("Only display the document bitonal stencil.") |
| 704 |
<< Trigger(widget, SLOT(displayModeStencil())) |
| 705 |
<< Trigger(this, SLOT(updateActionsLater())) |
| 706 |
<< *modeActionGroup; |
| 707 |
|
| 708 |
actionDisplayForeground |
| 709 |
= makeAction(tr("&Foreground", "Display|"), false) |
| 710 |
<< tr("Only display the foreground layer.") |
| 711 |
<< Trigger(widget, SLOT(displayModeForeground())) |
| 712 |
<< Trigger(this, SLOT(updateActionsLater())) |
| 713 |
<< *modeActionGroup; |
| 714 |
|
| 715 |
actionDisplayBackground |
| 716 |
= makeAction(tr("&Background", "Display|"), false) |
| 717 |
<< tr("Only display the background layer.") |
| 718 |
<< Trigger(widget, SLOT(displayModeBackground())) |
| 719 |
<< Trigger(this, SLOT(updateActionsLater())) |
| 720 |
<< *modeActionGroup; |
| 721 |
|
| 722 |
actionDisplayHiddenText |
| 723 |
= makeAction(tr("&Hidden Text", "Display|"), false) |
| 724 |
<< tr("Overlay a representation of the hidden text layer.") |
| 725 |
<< Trigger(widget, SLOT(displayModeText())) |
| 726 |
<< Trigger(this, SLOT(updateActionsLater())) |
| 727 |
<< *modeActionGroup; |
| 728 |
|
| 729 |
actionInvertLuminance |
| 730 |
= makeAction(tr("I&nvert Luminance", "View|"), true) |
| 731 |
<< tr("Invert image luminance while preserving hue.") |
| 732 |
<< Trigger(widget, SLOT(setInvertLuminance(bool))) |
| 733 |
<< Trigger(this, SLOT(updateActionsLater())); |
| 734 |
|
| 735 |
actionPreferences = makeAction(tr("Prefere&nces...", "Settings|")) |
| 736 |
<< QIcon(":/images/icon_prefs.png") |
| 737 |
<< tr("Show the preferences dialog.") |
| 738 |
<< Trigger(this, SLOT(performPreferences())); |
| 739 |
|
| 740 |
actionViewSideBar = makeAction(tr("Show &Sidebar", "Settings|"), true) |
| 741 |
<< QKeySequence(tr("F9", "Settings|Show sidebar")) |
| 742 |
#ifdef Q_OS_DARWIN |
| 743 |
<< QKeySequence(tr("Alt+Ctrl+S", "Settings|Show sidebar")) |
| 744 |
#endif |
| 745 |
<< tr("Show/hide the side bar.") |
| 746 |
<< Trigger(this, SLOT(showSideBar(bool))); |
| 747 |
|
| 748 |
actionViewToolBar = toolBar->toggleViewAction() |
| 749 |
<< tr("Show &Toolbar", "Settings|") |
| 750 |
<< QKeySequence(tr("F10", "Settings|Show toolbar")) |
| 751 |
#ifdef Q_OS_DARWIN |
| 752 |
<< QKeySequence(tr("Alt+Ctrl+T", "Settings|Show toolbar")) |
| 753 |
#endif |
| 754 |
<< tr("Show/hide the standard tool bar.") |
| 755 |
<< Trigger(this, SLOT(updateActionsLater())); |
| 756 |
|
| 757 |
actionViewStatusBar = makeAction(tr("Show Stat&usbar", "Settings|"), true) |
| 758 |
<< tr("Show/hide the status bar.") |
| 759 |
#ifdef Q_OS_DARWIN |
| 760 |
<< QKeySequence(tr("Alt+Ctrl+/", "Settings|Show toolbar")) |
| 761 |
#endif |
| 762 |
<< Trigger(statusBar,SLOT(setVisible(bool))) |
| 763 |
<< Trigger(this, SLOT(updateActionsLater())); |
| 764 |
|
| 765 |
actionViewFullScreen |
| 766 |
= makeAction(tr("&Full Screen","View|"), false) |
| 767 |
<< QKeySequence(tr("F11","View|FullScreen")) |
| 768 |
#ifdef Q_OS_DARWIN |
| 769 |
<< QKeySequence(tr("Meta+Ctrl+F","View|FullScreen")) |
| 770 |
#endif |
| 771 |
<< QIcon(":/images/icon_fullscreen.png") |
| 772 |
<< tr("Toggle full screen mode.") |
| 773 |
<< Trigger(this, SLOT(performViewFullScreen(bool))); |
| 774 |
|
| 775 |
actionViewSlideShow |
| 776 |
= makeAction(tr("&Slide Show","View|"), false) |
| 777 |
<< QKeySequence(tr("Shift+F11","View|Slideshow")) |
| 778 |
#ifdef Q_OS_DARWIN |
| 779 |
<< QKeySequence(tr("Shift+Ctrl+F", "Settings|Show toolbar")) |
| 780 |
#endif |
| 781 |
<< QIcon(":/images/icon_slideshow.png") |
| 782 |
<< tr("Toggle slide show mode.") |
| 783 |
<< Trigger(this, SLOT(performViewSlideShow(bool))); |
| 784 |
|
| 785 |
actionLayoutContinuous = makeAction(tr("&Continuous", "Layout|"), false) |
| 786 |
<< QIcon(":/images/icon_continuous.png") |
| 787 |
<< QKeySequence(tr("F4", "Layout|Continuous")) |
| 788 |
<< tr("Toggle continuous layout mode.") |
| 789 |
<< Trigger(widget, SLOT(setContinuous(bool))) |
| 790 |
<< Trigger(this, SLOT(updateActionsLater())); |
| 791 |
|
| 792 |
actionLayoutSideBySide = makeAction(tr("Side &by Side", "Layout|"), false) |
| 793 |
<< QIcon(":/images/icon_sidebyside.png") |
| 794 |
<< QKeySequence(tr("F5", "Layout|SideBySide")) |
| 795 |
<< tr("Toggle side-by-side layout mode.") |
| 796 |
<< Trigger(widget, SLOT(setSideBySide(bool))) |
| 797 |
<< Trigger(this, SLOT(updateActionsLater())); |
| 798 |
|
| 799 |
actionLayoutCoverPage = makeAction(tr("Co&ver Page", "Layout|"), false) |
| 800 |
#ifdef Q_OS_DARWIN |
| 801 |
<< QIcon(":/images/icon_coverpage.png") |
| 802 |
#endif |
| 803 |
<< QKeySequence(tr("F6", "Layout|CoverPage")) |
| 804 |
<< tr("Show the cover page alone in side-by-side mode.") |
| 805 |
<< Trigger(widget, SLOT(setCoverPage(bool))) |
| 806 |
<< Trigger(this, SLOT(updateActionsLater())); |
| 807 |
|
| 808 |
actionLayoutRightToLeft = makeAction(tr("&Right to Left", "Layout|"), false) |
| 809 |
#ifdef Q_OS_DARWIN |
| 810 |
<< QIcon(":/images/icon_righttoleft.png") |
| 811 |
#endif |
| 812 |
<< QKeySequence(tr("Shift+F6", "Layout|RightToLeft")) |
| 813 |
<< tr("Show pages right-to-left in side-by-side mode.") |
| 814 |
<< Trigger(widget, SLOT(setRightToLeft(bool))) |
| 815 |
<< Trigger(this, SLOT(updateActionsLater())); |
| 816 |
|
| 817 |
actionCopyUrl = makeAction(tr("Copy &URL", "Edit|")) |
| 818 |
<< tr("Save an URL for the current page into the clipboard.") |
| 819 |
<< QKeySequence(tr("Ctrl+C", "Edit|CopyURL")) |
| 820 |
<< Trigger(this, SLOT(performCopyUrl())); |
| 821 |
|
| 822 |
actionCopyOutline = makeAction(tr("Copy &Outline", "Edit|")) |
| 823 |
<< tr("Save the djvused code for the outline into the clipboard.") |
| 824 |
<< Trigger(this, SLOT(performCopyOutline())); |
| 825 |
|
| 826 |
actionCopyAnnotation = makeAction(tr("Copy &Annotations", "Edit|")) |
| 827 |
<< tr("Save the djvused code for the page annotations into the clipboard.") |
| 828 |
<< Trigger(this, SLOT(performCopyAnnotation())); |
| 829 |
|
| 830 |
actionAbout->setMenuRole(QAction::AboutRole); |
| 831 |
actionQuit->setMenuRole(QAction::QuitRole); |
| 832 |
actionPreferences->setMenuRole(QAction::PreferencesRole); |
| 833 |
} |
| 834 |
|
| 835 |
|
| 836 |
void |
| 837 |
QDjView::createMenus() |
| 838 |
{ |
| 839 |
// Layout main menu |
| 840 |
QMenu *fileMenu = menuBar->addMenu(tr("&File", "File|")); |
| 841 |
if (viewerMode >= STANDALONE) |
| 842 |
{ |
| 843 |
fileMenu->addAction(actionNew); |
| 844 |
fileMenu->addAction(actionOpen); |
| 845 |
fileMenu->addAction(actionOpenLocation); |
| 846 |
recentMenu = fileMenu->addMenu(tr("Open &Recent")); |
| 847 |
recentMenu->menuAction()->setIcon(QIcon(":/images/icon_open.png")); |
| 848 |
connect(recentMenu, SIGNAL(aboutToShow()), this, SLOT(fillRecent())); |
| 849 |
fileMenu->addSeparator(); |
| 850 |
} |
| 851 |
fileMenu->addAction(actionSave); |
| 852 |
fileMenu->addAction(actionExport); |
| 853 |
fileMenu->addAction(actionPrint); |
| 854 |
if (viewerMode >= STANDALONE) |
| 855 |
{ |
| 856 |
fileMenu->addSeparator(); |
| 857 |
fileMenu->addAction(actionClose); |
| 858 |
fileMenu->addAction(actionQuit); |
| 859 |
} |
| 860 |
QMenu *editMenu = menuBar->addMenu(tr("&Edit", "Edit|")); |
| 861 |
editMenu->addAction(actionSelect); |
| 862 |
editMenu->addAction(actionCopyUrl); |
| 863 |
editMenu->addAction(actionCopyOutline); |
| 864 |
editMenu->addAction(actionCopyAnnotation); |
| 865 |
editMenu->addSeparator(); |
| 866 |
editMenu->addAction(actionFind); |
| 867 |
editMenu->addAction(actionFindNext); |
| 868 |
editMenu->addAction(actionFindPrev); |
| 869 |
QMenu *viewMenu = menuBar->addMenu(tr("&View", "View|")); |
| 870 |
QMenu *zoomMenu = viewMenu->addMenu(tr("&Zoom","View|Zoom")); |
| 871 |
zoomMenu->addAction(actionZoomIn); |
| 872 |
zoomMenu->addAction(actionZoomOut); |
| 873 |
zoomMenu->addSeparator(); |
| 874 |
zoomMenu->addAction(actionZoomOneToOne); |
| 875 |
zoomMenu->addAction(actionZoomFitWidth); |
| 876 |
zoomMenu->addAction(actionZoomFitPage); |
| 877 |
zoomMenu->addSeparator(); |
| 878 |
zoomMenu->addAction(actionZoom300); |
| 879 |
zoomMenu->addAction(actionZoom200); |
| 880 |
zoomMenu->addAction(actionZoom150); |
| 881 |
zoomMenu->addAction(actionZoom100); |
| 882 |
zoomMenu->addAction(actionZoom75); |
| 883 |
zoomMenu->addAction(actionZoom50); |
| 884 |
QMenu *rotationMenu = viewMenu->addMenu(tr("&Rotate","View|Rotate")); |
| 885 |
rotationMenu->addAction(actionRotateLeft); |
| 886 |
rotationMenu->addAction(actionRotateRight); |
| 887 |
rotationMenu->addSeparator(); |
| 888 |
rotationMenu->addAction(actionRotate0); |
| 889 |
rotationMenu->addAction(actionRotate90); |
| 890 |
rotationMenu->addAction(actionRotate180); |
| 891 |
rotationMenu->addAction(actionRotate270); |
| 892 |
QMenu *modeMenu = viewMenu->addMenu(tr("&Display","View|Display")); |
| 893 |
modeMenu->addAction(actionDisplayColor); |
| 894 |
modeMenu->addAction(actionDisplayBW); |
| 895 |
modeMenu->addAction(actionDisplayForeground); |
| 896 |
modeMenu->addAction(actionDisplayBackground); |
| 897 |
modeMenu->addAction(actionDisplayHiddenText); |
| 898 |
viewMenu->addSeparator(); |
| 899 |
viewMenu->addAction(actionLayoutContinuous); |
| 900 |
viewMenu->addAction(actionLayoutSideBySide); |
| 901 |
viewMenu->addAction(actionLayoutCoverPage); |
| 902 |
viewMenu->addAction(actionLayoutRightToLeft); |
| 903 |
viewMenu->addSeparator(); |
| 904 |
viewMenu->addAction(actionInvertLuminance); |
| 905 |
viewMenu->addSeparator(); |
| 906 |
viewMenu->addAction(actionInformation); |
| 907 |
viewMenu->addAction(actionMetadata); |
| 908 |
if (viewerMode >= STANDALONE) |
| 909 |
viewMenu->addSeparator(); |
| 910 |
if (viewerMode >= STANDALONE) |
| 911 |
viewMenu->addAction(actionViewFullScreen); |
| 912 |
if (viewerMode >= STANDALONE) |
| 913 |
viewMenu->addAction(actionViewSlideShow); |
| 914 |
QMenu *gotoMenu = menuBar->addMenu(tr("&Go", "Go|")); |
| 915 |
gotoMenu->addAction(actionNavFirst); |
| 916 |
gotoMenu->addAction(actionNavPrev); |
| 917 |
gotoMenu->addAction(actionNavNext); |
| 918 |
gotoMenu->addAction(actionNavLast); |
| 919 |
gotoMenu->addSeparator(); |
| 920 |
gotoMenu->addAction(actionBack); |
| 921 |
gotoMenu->addAction(actionForw); |
| 922 |
QMenu *settingsMenu = menuBar->addMenu(tr("&Settings", "Settings|")); |
| 923 |
settingsMenu->addAction(actionViewSideBar); |
| 924 |
settingsMenu->addAction(actionViewToolBar); |
| 925 |
settingsMenu->addAction(actionViewStatusBar); |
| 926 |
settingsMenu->addSeparator(); |
| 927 |
settingsMenu->addAction(actionPreferences); |
| 928 |
QMenu *helpMenu = menuBar->addMenu(tr("&Help", "Help|")); |
| 929 |
helpMenu->addAction(actionWhatsThis); |
| 930 |
helpMenu->addSeparator(); |
| 931 |
helpMenu->addAction(actionAbout); |
| 932 |
|
| 933 |
// Layout context menu |
| 934 |
gotoMenu = contextMenu->addMenu(tr("&Go", "Go|")); |
| 935 |
gotoMenu->addAction(actionNavFirst); |
| 936 |
gotoMenu->addAction(actionNavPrev); |
| 937 |
gotoMenu->addAction(actionNavNext); |
| 938 |
gotoMenu->addAction(actionNavLast); |
| 939 |
zoomMenu = contextMenu->addMenu(tr("&Zoom","View|Zoom")); |
| 940 |
zoomMenu->addAction(actionZoomIn); |
| 941 |
zoomMenu->addAction(actionZoomOut); |
| 942 |
zoomMenu->addSeparator(); |
| 943 |
zoomMenu->addAction(actionZoomOneToOne); |
| 944 |
zoomMenu->addAction(actionZoomFitWidth); |
| 945 |
zoomMenu->addAction(actionZoomFitPage); |
| 946 |
zoomMenu->addSeparator(); |
| 947 |
zoomMenu->addAction(actionZoom300); |
| 948 |
zoomMenu->addAction(actionZoom200); |
| 949 |
zoomMenu->addAction(actionZoom150); |
| 950 |
zoomMenu->addAction(actionZoom100); |
| 951 |
zoomMenu->addAction(actionZoom75); |
| 952 |
zoomMenu->addAction(actionZoom50); |
| 953 |
rotationMenu = contextMenu->addMenu(tr("&Rotate","View|Rotate")); |
| 954 |
rotationMenu->addAction(actionRotateLeft); |
| 955 |
rotationMenu->addAction(actionRotateRight); |
| 956 |
rotationMenu->addSeparator(); |
| 957 |
rotationMenu->addAction(actionRotate0); |
| 958 |
rotationMenu->addAction(actionRotate90); |
| 959 |
rotationMenu->addAction(actionRotate180); |
| 960 |
rotationMenu->addAction(actionRotate270); |
| 961 |
modeMenu = contextMenu->addMenu(tr("&Display","View|Display")); |
| 962 |
modeMenu->addAction(actionDisplayColor); |
| 963 |
modeMenu->addAction(actionDisplayBW); |
| 964 |
modeMenu->addAction(actionDisplayForeground); |
| 965 |
modeMenu->addAction(actionDisplayBackground); |
| 966 |
modeMenu->addAction(actionDisplayHiddenText); |
| 967 |
contextMenu->addSeparator(); |
| 968 |
contextMenu->addAction(actionLayoutContinuous); |
| 969 |
contextMenu->addAction(actionLayoutSideBySide); |
| 970 |
contextMenu->addAction(actionLayoutCoverPage); |
| 971 |
contextMenu->addSeparator(); |
| 972 |
contextMenu->addAction(actionFind); |
| 973 |
contextMenu->addAction(actionInformation); |
| 974 |
contextMenu->addAction(actionMetadata); |
| 975 |
contextMenu->addSeparator(); |
| 976 |
contextMenu->addAction(actionSave); |
| 977 |
contextMenu->addAction(actionExport); |
| 978 |
contextMenu->addAction(actionPrint); |
| 979 |
contextMenu->addSeparator(); |
| 980 |
contextMenu->addAction(actionViewSideBar); |
| 981 |
contextMenu->addAction(actionViewToolBar); |
| 982 |
contextMenu->addAction(actionViewFullScreen); |
| 983 |
contextMenu->addAction(actionViewSlideShow); |
| 984 |
contextMenu->addSeparator(); |
| 985 |
contextMenu->addAction(actionPreferences); |
| 986 |
contextMenu->addSeparator(); |
| 987 |
contextMenu->addAction(actionWhatsThis); |
| 988 |
contextMenu->addAction(actionAbout); |
| 989 |
} |
| 990 |
|
| 991 |
|
| 992 |
/*! Update graphical interface components. |
| 993 |
This is called whenever something changes |
| 994 |
using function \a QDjView::updateActionsLater(). |
| 995 |
It updates the all gui compnents. */ |
| 996 |
|
| 997 |
void |
| 998 |
QDjView::updateActions() |
| 999 |
{ |
| 1000 |
// Rebuild toolbar if necessary |
| 1001 |
if (tools != toolsCached) |
| 1002 |
fillToolBar(toolBar); |
| 1003 |
|
| 1004 |
// Enable all actions |
| 1005 |
foreach(QObject *object, allActions) |
| 1006 |
if (QAction *action = qobject_cast<QAction*>(object)) |
| 1007 |
action->setEnabled(true); |
| 1008 |
|
| 1009 |
// Some actions are explicitly disabled |
| 1010 |
actionSave->setEnabled(savingAllowed || prefs->restrictOverride); |
| 1011 |
actionExport->setEnabled(savingAllowed || prefs->restrictOverride); |
| 1012 |
actionPrint->setEnabled(printingAllowed || prefs->restrictOverride); |
| 1013 |
|
| 1014 |
// Some actions are only available in standalone mode |
| 1015 |
actionNew->setVisible(viewerMode >= STANDALONE); |
| 1016 |
actionOpen->setVisible(viewerMode >= STANDALONE); |
| 1017 |
actionOpenLocation->setVisible(viewerMode >= STANDALONE); |
| 1018 |
actionClose->setVisible(viewerMode >= STANDALONE); |
| 1019 |
actionQuit->setVisible(viewerMode >= STANDALONE); |
| 1020 |
actionViewFullScreen->setVisible(viewerMode >= STANDALONE); |
| 1021 |
actionViewSlideShow->setVisible(viewerMode >= STANDALONE); |
| 1022 |
setAcceptDrops(viewerMode >= STANDALONE); |
| 1023 |
|
| 1024 |
// Zoom combo and actions |
| 1025 |
int zoom = widget->zoom(); |
| 1026 |
actionZoomIn->setEnabled(zoom < QDjVuWidget::ZOOM_MAX); |
| 1027 |
actionZoomOut->setEnabled(zoom < 0 || zoom > QDjVuWidget::ZOOM_MIN); |
| 1028 |
actionZoomFitPage->setChecked(zoom == QDjVuWidget::ZOOM_FITPAGE); |
| 1029 |
actionZoomFitWidth->setChecked(zoom == QDjVuWidget::ZOOM_FITWIDTH); |
| 1030 |
actionZoomOneToOne->setChecked(zoom == QDjVuWidget::ZOOM_ONE2ONE); |
| 1031 |
actionZoom300->setChecked(zoom == 300); |
| 1032 |
actionZoom200->setChecked(zoom == 200); |
| 1033 |
actionZoom150->setChecked(zoom == 150); |
| 1034 |
actionZoom100->setChecked(zoom == 100); |
| 1035 |
actionZoom75->setChecked(zoom == 75); |
| 1036 |
actionZoom50->setChecked(zoom == 50); |
| 1037 |
zoomCombo->setEnabled(!!document); |
| 1038 |
int zoomIndex = zoomCombo->findData(QVariant(zoom)); |
| 1039 |
zoomCombo->clearEditText(); |
| 1040 |
zoomCombo->setCurrentIndex(zoomIndex); |
| 1041 |
if (zoomIndex < 0 && |
| 1042 |
zoom >= QDjVuWidget::ZOOM_MIN && |
| 1043 |
zoom <= QDjVuWidget::ZOOM_MAX) |
| 1044 |
zoomCombo->setEditText(QString("%1%").arg(zoom)); |
| 1045 |
else if (zoomIndex >= 0) |
| 1046 |
zoomCombo->setEditText(zoomCombo->itemText(zoomIndex)); |
| 1047 |
|
| 1048 |
// Mode combo and actions |
| 1049 |
QDjVuWidget::DisplayMode mode = widget->displayMode(); |
| 1050 |
actionDisplayColor->setChecked(mode == QDjVuWidget::DISPLAY_COLOR); |
| 1051 |
actionDisplayBW->setChecked(mode == QDjVuWidget::DISPLAY_STENCIL); |
| 1052 |
actionDisplayBackground->setChecked(mode == QDjVuWidget::DISPLAY_BG); |
| 1053 |
actionDisplayForeground->setChecked(mode == QDjVuWidget::DISPLAY_FG); |
| 1054 |
actionDisplayHiddenText->setChecked(mode == QDjVuWidget::DISPLAY_TEXT); |
| 1055 |
modeCombo->setCurrentIndex(modeCombo->findData(QVariant(mode))); |
| 1056 |
modeCombo->setEnabled(!!document); |
| 1057 |
|
| 1058 |
// Image inversion |
| 1059 |
actionInvertLuminance->setChecked(widget->invertLuminance()); |
| 1060 |
|
| 1061 |
// Rotations |
| 1062 |
int rotation = widget->rotation(); |
| 1063 |
actionRotate0->setChecked(rotation == 0); |
| 1064 |
actionRotate90->setChecked(rotation == 1); |
| 1065 |
actionRotate180->setChecked(rotation == 2); |
| 1066 |
actionRotate270->setChecked(rotation == 3); |
| 1067 |
|
| 1068 |
// Page combo and actions |
| 1069 |
int pagenum = documentPages.size(); |
| 1070 |
int pageno = widget->page(); |
| 1071 |
pageCombo->clearEditText(); |
| 1072 |
pageCombo->setCurrentIndex(pageCombo->findData(QVariant(pageno))); |
| 1073 |
if (pageno >= 0 && pagenum > 0 && !pageCombo->hasFocus()) |
| 1074 |
{ |
| 1075 |
QString sNumber = QString("%1 / %2").arg(pageno+1).arg(pagenum); |
| 1076 |
QString sName = pageName(pageno,true); |
| 1077 |
growPageCombo(pageCombo, sNumber); |
| 1078 |
pageCombo->setEditText((sName.isEmpty()) ? sNumber : sName); |
| 1079 |
pageCombo->lineEdit()->setCursorPosition(0); |
| 1080 |
} |
| 1081 |
pageCombo->setEnabled(pagenum > 0); |
| 1082 |
actionNavFirst->setEnabled(pagenum>0 && pageno>0); |
| 1083 |
actionNavPrev->setEnabled(pagenum>0 && pageno>0); |
| 1084 |
actionNavNext->setEnabled(pagenum>0 && pageno<pagenum-1); |
| 1085 |
actionNavLast->setEnabled(pagenum>0 && pageno<pagenum-1); |
| 1086 |
|
| 1087 |
// Layout actions |
| 1088 |
actionLayoutContinuous->setChecked(widget->continuous()); |
| 1089 |
actionLayoutSideBySide->setChecked(widget->sideBySide()); |
| 1090 |
actionLayoutCoverPage->setEnabled(widget->sideBySide()); |
| 1091 |
actionLayoutCoverPage->setChecked(widget->coverPage()); |
| 1092 |
actionLayoutRightToLeft->setEnabled(widget->sideBySide()); |
| 1093 |
actionLayoutRightToLeft->setChecked(widget->rightToLeft()); |
| 1094 |
|
| 1095 |
// UndoRedo |
| 1096 |
undoTimer->stop(); |
| 1097 |
undoTimer->start(250); |
| 1098 |
actionBack->setEnabled(undoList.size() > 0); |
| 1099 |
actionForw->setEnabled(redoList.size() > 0); |
| 1100 |
|
| 1101 |
// Misc |
| 1102 |
textLabel->setVisible(prefs->showTextLabel); |
| 1103 |
textLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored); |
| 1104 |
actionCopyOutline->setVisible(prefs->advancedFeatures); |
| 1105 |
actionCopyAnnotation->setVisible(prefs->advancedFeatures); |
| 1106 |
actionCopyUrl->setEnabled(pagenum > 0); |
| 1107 |
actionCopyOutline->setEnabled(pagenum > 0); |
| 1108 |
actionCopyAnnotation->setEnabled(pagenum > 0); |
| 1109 |
actionViewSideBar->setChecked(hiddenSideBarTabs() == 0); |
| 1110 |
actionViewSlideShow->setChecked(viewerMode == STANDALONE_SLIDESHOW); |
| 1111 |
actionViewFullScreen->setChecked(viewerMode == STANDALONE_FULLSCREEN); |
| 1112 |
|
| 1113 |
// Disable almost everything when document==0 |
| 1114 |
if (! document) |
| 1115 |
{ |
| 1116 |
foreach(QObject *object, allActions) |
| 1117 |
if (QAction *action = qobject_cast<QAction*>(object)) |
| 1118 |
if (action != actionNew && |
| 1119 |
action != actionOpen && |
| 1120 |
action != actionOpenLocation && |
| 1121 |
action != actionClose && |
| 1122 |
action != actionQuit && |
| 1123 |
action != actionPreferences && |
| 1124 |
action != actionViewToolBar && |
| 1125 |
action != actionViewStatusBar && |
| 1126 |
action != actionViewSideBar && |
| 1127 |
action != actionViewFullScreen && |
| 1128 |
action != actionWhatsThis && |
| 1129 |
action != actionAbout ) |
| 1130 |
action->setEnabled(false); |
| 1131 |
} |
| 1132 |
|
| 1133 |
// Finished |
| 1134 |
updateActionsScheduled = false; |
| 1135 |
|
| 1136 |
// Reset slide show timeout |
| 1137 |
slideShowTimeout(true); |
| 1138 |
|
| 1139 |
// Notify plugin |
| 1140 |
if (viewerMode < STANDALONE) |
| 1141 |
emit pluginOnChange(); |
| 1142 |
} |
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
// ---------------------------------------- |
| 1147 |
// WHATSTHIS HELP |
| 1148 |
|
| 1149 |
|
| 1150 |
void |
| 1151 |
QDjView::createWhatsThis() |
| 1152 |
{ |
| 1153 |
#define HELP(x,y) { QString s(x); Help h(s); h y; } |
| 1154 |
|
| 1155 |
struct Help { |
| 1156 |
QString s; |
| 1157 |
Help(QString s) : s(s) { } |
| 1158 |
Help& operator>>(QWidget *w) { w->setWhatsThis(s); return *this; } |
| 1159 |
Help& operator>>(QAction *a) { a->setWhatsThis(s); return *this; } |
| 1160 |
}; |
| 1161 |
|
| 1162 |
QString mc, ms, ml; |
| 1163 |
#ifdef Q_OS_DARWIN |
| 1164 |
mc = tr("Control Left Mouse Button"); |
| 1165 |
#else |
| 1166 |
mc = tr("Right Mouse Button"); |
| 1167 |
#endif |
| 1168 |
ms = prefs->modifiersToString(prefs->modifiersForSelect); |
| 1169 |
ms = ms.replace("+"," "); |
| 1170 |
ml = prefs->modifiersToString(prefs->modifiersForLens); |
| 1171 |
ml = ml.replace("+"," "); |
| 1172 |
|
| 1173 |
HELP(tr("<html><b>Selecting a rectangle.</b><br/> " |
| 1174 |
"Once a rectangular area is selected, a popup menu " |
| 1175 |
"lets you copy the corresponding text or image. " |
| 1176 |
"Instead of using this tool, you can also hold %1 " |
| 1177 |
"and use the Left Mouse Button." |
| 1178 |
"</html>").arg(ms), |
| 1179 |
>> actionSelect ); |
| 1180 |
|
| 1181 |
HELP(tr("<html><b>Zooming.</b><br/> " |
| 1182 |
"Choose a zoom level for viewing the document. " |
| 1183 |
"Zoom level 100% displays the document for a 100 dpi screen. " |
| 1184 |
"Zoom levels <tt>Fit Page</tt> and <tt>Fit Width</tt> ensure " |
| 1185 |
"that the full page or the page width fit in the window. " |
| 1186 |
"</html>"), |
| 1187 |
>> actionZoomIn >> actionZoomOut |
| 1188 |
>> actionZoomFitPage >> actionZoomFitWidth |
| 1189 |
>> actionZoom300 >> actionZoom200 >> actionZoom150 |
| 1190 |
>> actionZoom75 >> actionZoom50 |
| 1191 |
>> zoomCombo ); |
| 1192 |
|
| 1193 |
HELP(tr("<html><b>Rotating the pages.</b><br/> " |
| 1194 |
"Choose to display pages in portrait or landscape mode. " |
| 1195 |
"You can also turn them upside down.</html>"), |
| 1196 |
>> actionRotateLeft >> actionRotateRight |
| 1197 |
>> actionRotate0 >> actionRotate90 |
| 1198 |
>> actionRotate180 >> actionRotate270 ); |
| 1199 |
|
| 1200 |
HELP(tr("<html><b>Display mode.</b><br/> " |
| 1201 |
"DjVu images compose a background layer and a foreground layer " |
| 1202 |
"using a stencil. The display mode specifies with layers " |
| 1203 |
"should be displayed.</html>"), |
| 1204 |
>> actionDisplayColor >> actionDisplayBW |
| 1205 |
>> actionDisplayForeground >> actionDisplayBackground |
| 1206 |
>> modeCombo ); |
| 1207 |
|
| 1208 |
HELP(tr("<html><b>Navigating the document.</b><br/> " |
| 1209 |
"The page selector lets you jump to any page by name " |
| 1210 |
"and can be activated at any time by pressing Ctrl+G. " |
| 1211 |
"The navigation buttons jump to the first page, the previous " |
| 1212 |
"page, the next page, or the last page. </html>"), |
| 1213 |
>> actionNavFirst >> actionNavPrev |
| 1214 |
>> actionNavNext >> actionNavLast |
| 1215 |
>> pageCombo ); |
| 1216 |
|
| 1217 |
HELP(tr("<html><b>Document and page information.</b><br> " |
| 1218 |
"Display a dialog window for viewing " |
| 1219 |
"encoding information pertaining to the document " |
| 1220 |
"or to a specific page.</html>"), |
| 1221 |
>> actionInformation ); |
| 1222 |
|
| 1223 |
HELP(tr("<html><b>Document and page metadata.</b><br> " |
| 1224 |
"Display a dialog window for viewing metadata " |
| 1225 |
"pertaining to the document " |
| 1226 |
"or to a specific page.</html>"), |
| 1227 |
>> actionMetadata ); |
| 1228 |
|
| 1229 |
HELP(tr("<html><b>Continuous layout.</b><br/> " |
| 1230 |
"Display all the document pages arranged vertically " |
| 1231 |
"inside the scrollable document viewing area.</html>"), |
| 1232 |
>> actionLayoutContinuous ); |
| 1233 |
|
| 1234 |
HELP(tr("<html><b>Side by side layout.</b><br/> " |
| 1235 |
"Display pairs of pages side by side " |
| 1236 |
"inside the scrollable document viewing area.</html>"), |
| 1237 |
>> actionLayoutSideBySide ); |
| 1238 |
|
| 1239 |
HELP(tr("<html><b>Page information.</b><br/> " |
| 1240 |
"Display information about the page located under the cursor: " |
| 1241 |
"the sequential page number, the page size in pixels, " |
| 1242 |
"and the page resolution in dots per inch. </html>"), |
| 1243 |
>> pageLabel ); |
| 1244 |
|
| 1245 |
HELP(tr("<html><b>Cursor information.</b><br/> " |
| 1246 |
"Display the position of the mouse cursor " |
| 1247 |
"expressed in page coordinates. </html>"), |
| 1248 |
>> mouseLabel ); |
| 1249 |
|
| 1250 |
HELP(tr("<html><b>Document viewing area.</b><br/> " |
| 1251 |
"This is the main display area for the DjVu document. <ul>" |
| 1252 |
"<li>Arrows and page keys to navigate the document.</li>" |
| 1253 |
"<li>Space and BackSpace to read the document.</li>" |
| 1254 |
"<li>Keys <tt>+</tt> <tt>-</tt> <tt>[</tt> <tt>]</tt> " |
| 1255 |
"to zoom or rotate the document.</li>" |
| 1256 |
"<li>Left Mouse Button for panning and selecting links.</li>" |
| 1257 |
"<li>%3 for displaying the contextual menu.</li>" |
| 1258 |
"<li>%1 Left Mouse Button for selecting text or images.</li>" |
| 1259 |
"<li>%2 for popping the magnification lens.</li>" |
| 1260 |
"</ul></html>").arg(ms).arg(ml).arg(mc), |
| 1261 |
>> widget ); |
| 1262 |
|
| 1263 |
HELP(tr("<html><b>Document viewing area.</b><br/> " |
| 1264 |
"This is the main display area for the DjVu document. " |
| 1265 |
"But you must first open a DjVu document to see anything." |
| 1266 |
"</html>"), |
| 1267 |
>> splash ); |
| 1268 |
|
| 1269 |
#undef HELP |
| 1270 |
} |
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
// ---------------------------------------- |
| 1275 |
// APPLY PREFERENCES |
| 1276 |
|
| 1277 |
|
| 1278 |
QDjViewPrefs::Saved * |
| 1279 |
QDjView::getSavedConfig(ViewerMode mode) |
| 1280 |
{ |
| 1281 |
if (mode == STANDALONE_FULLSCREEN) |
| 1282 |
return &fsSavedFullScreen; |
| 1283 |
else if (mode == STANDALONE_SLIDESHOW) |
| 1284 |
return &fsSavedSlideShow; |
| 1285 |
return &fsSavedNormal; |
| 1286 |
} |
| 1287 |
|
| 1288 |
|
| 1289 |
QDjViewPrefs::Saved * |
| 1290 |
QDjView::getSavedPrefs(void) |
| 1291 |
{ |
| 1292 |
if (viewerMode==EMBEDDED_PLUGIN) |
| 1293 |
return &prefs->forEmbeddedPlugin; |
| 1294 |
else if (viewerMode==FULLPAGE_PLUGIN) |
| 1295 |
return &prefs->forFullPagePlugin; |
| 1296 |
else if (viewerMode==STANDALONE_FULLSCREEN) |
| 1297 |
return &prefs->forFullScreen; |
| 1298 |
else if (viewerMode==STANDALONE_SLIDESHOW) |
| 1299 |
return &prefs->forSlideShow; |
| 1300 |
return &prefs->forStandalone; |
| 1301 |
} |
| 1302 |
|
| 1303 |
|
| 1304 |
void |
| 1305 |
QDjView::enableContextMenu(bool enable) |
| 1306 |
{ |
| 1307 |
QMenu *oldContextMenu = widget->contextMenu(); |
| 1308 |
if (!enable || oldContextMenu != contextMenu) |
| 1309 |
{ |
| 1310 |
// remove context menu |
| 1311 |
widget->setContextMenu(0); |
| 1312 |
// disable shortcuts |
| 1313 |
if (oldContextMenu) |
| 1314 |
{ |
| 1315 |
foreach(QAction *action, widget->actions()) |
| 1316 |
widget->removeAction(action); |
| 1317 |
} |
| 1318 |
} |
| 1319 |
if (enable && oldContextMenu != contextMenu) |
| 1320 |
{ |
| 1321 |
// setup context menu |
| 1322 |
widget->setContextMenu(contextMenu); |
| 1323 |
// enable shortcuts |
| 1324 |
if (contextMenu) |
| 1325 |
{ |
| 1326 |
// all explicit shortcuts in context menu |
| 1327 |
widget->addAction(contextMenu->menuAction()); |
| 1328 |
// things that do not have a context menu entry |
| 1329 |
widget->addAction(actionFindNext); |
| 1330 |
widget->addAction(actionFindPrev); |
| 1331 |
} |
| 1332 |
} |
| 1333 |
} |
| 1334 |
|
| 1335 |
|
| 1336 |
void |
| 1337 |
QDjView::enableScrollBars(bool enable) |
| 1338 |
{ |
| 1339 |
Qt::ScrollBarPolicy policy = Qt::ScrollBarAlwaysOff; |
| 1340 |
if (enable) |
| 1341 |
policy = Qt::ScrollBarAsNeeded; |
| 1342 |
widget->setHorizontalScrollBarPolicy(policy); |
| 1343 |
widget->setVerticalScrollBarPolicy(policy); |
| 1344 |
} |
| 1345 |
|
| 1346 |
|
| 1347 |
void |
| 1348 |
QDjView::applyOptions(bool remember) |
| 1349 |
{ |
| 1350 |
menuBar->setVisible(options & QDjViewPrefs::SHOW_MENUBAR); |
| 1351 |
toolBar->setVisible(options & QDjViewPrefs::SHOW_TOOLBAR); |
| 1352 |
statusBar->setVisible(options & QDjViewPrefs::SHOW_STATUSBAR); |
| 1353 |
enableScrollBars(options & QDjViewPrefs::SHOW_SCROLLBARS); |
| 1354 |
widget->setDisplayFrame(options & QDjViewPrefs::SHOW_FRAME); |
| 1355 |
widget->setDisplayMapAreas(options & QDjViewPrefs::SHOW_MAPAREAS); |
| 1356 |
widget->setContinuous(options & QDjViewPrefs::LAYOUT_CONTINUOUS); |
| 1357 |
widget->setSideBySide(options & QDjViewPrefs::LAYOUT_SIDEBYSIDE); |
| 1358 |
widget->setCoverPage(options & QDjViewPrefs::LAYOUT_COVERPAGE); |
| 1359 |
widget->setRightToLeft(options & QDjViewPrefs::LAYOUT_RIGHTTOLEFT); |
| 1360 |
widget->enableMouse(options & QDjViewPrefs::HANDLE_MOUSE); |
| 1361 |
widget->enableKeyboard(options & QDjViewPrefs::HANDLE_KEYBOARD); |
| 1362 |
widget->enableHyperlink(options & QDjViewPrefs::HANDLE_LINKS); |
| 1363 |
enableContextMenu(options & QDjViewPrefs::HANDLE_CONTEXTMENU); |
| 1364 |
if (!remember) |
| 1365 |
showSideBar(options & QDjViewPrefs::SHOW_SIDEBAR); |
| 1366 |
} |
| 1367 |
|
| 1368 |
|
| 1369 |
void |
| 1370 |
QDjView::updateOptions(void) |
| 1371 |
{ |
| 1372 |
options = zero(QDjViewPrefs::Options); |
| 1373 |
if (! menuBar->isHidden()) |
| 1374 |
options |= QDjViewPrefs::SHOW_MENUBAR; |
| 1375 |
if (! toolBar->isHidden()) |
| 1376 |
options |= QDjViewPrefs::SHOW_TOOLBAR; |
| 1377 |
if (! statusBar->isHidden()) |
| 1378 |
options |= QDjViewPrefs::SHOW_STATUSBAR; |
| 1379 |
if (! hiddenSideBarTabs()) |
| 1380 |
options |= QDjViewPrefs::SHOW_SIDEBAR; |
| 1381 |
if (widget->verticalScrollBarPolicy() != Qt::ScrollBarAlwaysOff) |
| 1382 |
options |= QDjViewPrefs::SHOW_SCROLLBARS; |
| 1383 |
if (widget->displayFrame()) |
| 1384 |
options |= QDjViewPrefs::SHOW_FRAME; |
| 1385 |
if (widget->displayMapAreas()) |
| 1386 |
options |= QDjViewPrefs::SHOW_MAPAREAS; |
| 1387 |
if (widget->continuous()) |
| 1388 |
options |= QDjViewPrefs::LAYOUT_CONTINUOUS; |
| 1389 |
if (widget->sideBySide()) |
| 1390 |
options |= QDjViewPrefs::LAYOUT_SIDEBYSIDE; |
| 1391 |
if (widget->coverPage()) |
| 1392 |
options |= QDjViewPrefs::LAYOUT_COVERPAGE; |
| 1393 |
if (widget->rightToLeft()) |
| 1394 |
options |= QDjViewPrefs::LAYOUT_RIGHTTOLEFT; |
| 1395 |
if (widget->mouseEnabled()) |
| 1396 |
options |= QDjViewPrefs::HANDLE_MOUSE; |
| 1397 |
if (widget->keyboardEnabled()) |
| 1398 |
options |= QDjViewPrefs::HANDLE_KEYBOARD; |
| 1399 |
if (widget->hyperlinkEnabled()) |
| 1400 |
options |= QDjViewPrefs::HANDLE_LINKS; |
| 1401 |
if (widget->contextMenu()) |
| 1402 |
options |= QDjViewPrefs::HANDLE_CONTEXTMENU; |
| 1403 |
} |
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
void |
| 1408 |
QDjView::applySaved(Saved *saved) |
| 1409 |
{ |
| 1410 |
// default dock geometry |
| 1411 |
tabifyDockWidget(thumbnailDock, outlineDock); |
| 1412 |
tabifyDockWidget(thumbnailDock, findDock); |
| 1413 |
thumbnailDock->raise(); |
| 1414 |
// main saved states |
| 1415 |
options = saved->options; |
| 1416 |
if (saved->state.size() > 0) |
| 1417 |
restoreState(saved->state); |
| 1418 |
applyOptions(saved->remember); |
| 1419 |
widget->setZoom(saved->zoom); |
| 1420 |
} |
| 1421 |
|
| 1422 |
|
| 1423 |
static const Qt::WindowStates unusualWindowStates = |
| 1424 |
(Qt::WindowMinimized|Qt::WindowMaximized|Qt::WindowFullScreen); |
| 1425 |
|
| 1426 |
void |
| 1427 |
QDjView::updateSaved(Saved *saved) |
| 1428 |
{ |
| 1429 |
updateOptions(); |
| 1430 |
if (saved->remember) |
| 1431 |
{ |
| 1432 |
// main saved states |
| 1433 |
saved->zoom = widget->zoom(); |
| 1434 |
saved->state = saveState(); |
| 1435 |
saved->options = options; |
| 1436 |
// avoid confusing options in standalone mode |
| 1437 |
if (saved == &prefs->forStandalone && |
| 1438 |
!(saved->options & QDjViewPrefs::HANDLE_CONTEXTMENU) && |
| 1439 |
!(saved->options & QDjViewPrefs::SHOW_MENUBAR) ) |
| 1440 |
saved->options |= (QDjViewPrefs::SHOW_MENUBAR | |
| 1441 |
QDjViewPrefs::SHOW_SCROLLBARS | |
| 1442 |
QDjViewPrefs::SHOW_STATUSBAR | |
| 1443 |
QDjViewPrefs::SHOW_FRAME | |
| 1444 |
QDjViewPrefs::HANDLE_CONTEXTMENU ); |
| 1445 |
// main window size in standalone mode |
| 1446 |
if (saved == &prefs->forStandalone) |
| 1447 |
{ |
| 1448 |
Qt::WindowStates wstate = windowState(); |
| 1449 |
prefs->windowMaximized = false; |
| 1450 |
if (wstate & Qt::WindowMaximized) |
| 1451 |
prefs->windowMaximized = true; |
| 1452 |
else if (! (wstate & unusualWindowStates)) |
| 1453 |
prefs->windowSize = size(); |
| 1454 |
} |
| 1455 |
// non-saved |
| 1456 |
saved->nsBorderBrush = widget->borderBrush(); |
| 1457 |
saved->nsBorderSize = widget->borderSize(); |
| 1458 |
} |
| 1459 |
} |
| 1460 |
|
| 1461 |
|
| 1462 |
void |
| 1463 |
QDjView::applyPreferences(void) |
| 1464 |
{ |
| 1465 |
// Saved preferences |
| 1466 |
applySaved(getSavedPrefs()); |
| 1467 |
|
| 1468 |
// Other preferences |
| 1469 |
QDjVuNetDocument::setProxy(prefs->proxyUrl); |
| 1470 |
djvuContext.setCacheSize(prefs->cacheSize); |
| 1471 |
widget->setPixelCacheSize(prefs->pixelCacheSize); |
| 1472 |
widget->setModifiersForLens(prefs->modifiersForLens); |
| 1473 |
widget->setModifiersForSelect(prefs->modifiersForSelect); |
| 1474 |
widget->setModifiersForLinks(prefs->modifiersForLinks); |
| 1475 |
widget->setGamma(prefs->gamma); |
| 1476 |
widget->setWhite(prefs->white); |
| 1477 |
widget->setScreenDpi(prefs->resolution ? prefs->resolution : physicalDpiY()); |
| 1478 |
widget->setLensSize(prefs->lensSize); |
| 1479 |
widget->setLensPower(prefs->lensPower); |
| 1480 |
widget->enableAnimation(prefs->enableAnimations); |
| 1481 |
widget->setInvertLuminance(prefs->invertLuminance); |
| 1482 |
widget->setMouseWheelZoom(prefs->mouseWheelZoom); |
| 1483 |
|
| 1484 |
// Thumbnail preferences |
| 1485 |
thumbnailWidget->setSize(prefs->thumbnailSize); |
| 1486 |
thumbnailWidget->setSmart(prefs->thumbnailSmart); |
| 1487 |
|
| 1488 |
// Search preferences |
| 1489 |
findWidget->setWordOnly(prefs->searchWordsOnly); |
| 1490 |
findWidget->setCaseSensitive(prefs->searchCaseSensitive); |
| 1491 |
// Too risky: findWidget->setRegExpMode(prefs->searchRegExpMode); |
| 1492 |
|
| 1493 |
// Special preferences for embedded plugins |
| 1494 |
if (viewerMode == EMBEDDED_PLUGIN) |
| 1495 |
setMinimumSize(QSize(8,8)); |
| 1496 |
|
| 1497 |
// Preload mode change prefs. |
| 1498 |
fsSavedNormal = prefs->forStandalone; |
| 1499 |
fsSavedFullScreen = prefs->forFullScreen; |
| 1500 |
fsSavedSlideShow = prefs->forSlideShow; |
| 1501 |
} |
| 1502 |
|
| 1503 |
|
| 1504 |
void |
| 1505 |
QDjView::updatePreferences(void) |
| 1506 |
{ |
| 1507 |
updateSaved(getSavedPrefs()); |
| 1508 |
prefs->thumbnailSize = thumbnailWidget->size(); |
| 1509 |
prefs->thumbnailSmart = thumbnailWidget->smart(); |
| 1510 |
prefs->searchWordsOnly = findWidget->wordOnly(); |
| 1511 |
prefs->searchCaseSensitive = findWidget->caseSensitive(); |
| 1512 |
prefs->searchRegExpMode = findWidget->regExpMode(); |
| 1513 |
} |
| 1514 |
|
| 1515 |
|
| 1516 |
void |
| 1517 |
QDjView::preferencesChanged(void) |
| 1518 |
{ |
| 1519 |
applyPreferences(); |
| 1520 |
createWhatsThis(); |
| 1521 |
updateActions(); |
| 1522 |
} |
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
// ---------------------------------------- |
| 1527 |
// SESSION MANAGEMENT |
| 1528 |
|
| 1529 |
|
| 1530 |
void |
| 1531 |
QDjView::saveSession(QSettings *s) |
| 1532 |
{ |
| 1533 |
Saved saved; |
| 1534 |
updateSaved(&saved); |
| 1535 |
s->setValue("name", objectName()); |
| 1536 |
s->setValue("options", prefs->optionsToString(saved.options)); |
| 1537 |
s->setValue("state", saved.state); |
| 1538 |
s->setValue("tools", prefs->toolsToString(tools)); |
| 1539 |
s->setValue("documentUrl", getDecoratedUrl().toString()); |
| 1540 |
} |
| 1541 |
|
| 1542 |
void |
| 1543 |
QDjView::restoreSession(QSettings *s) |
| 1544 |
{ |
| 1545 |
QUrl du = QUrl(s->value("documentUrl").toString()); |
| 1546 |
Tools tools = this->tools; |
| 1547 |
Saved saved; |
| 1548 |
updateSaved(&saved); |
| 1549 |
if (s->contains("options")) |
| 1550 |
saved.options = prefs->stringToOptions(s->value("options").toString()); |
| 1551 |
if (s->contains("zoom")) // compat |
| 1552 |
saved.zoom = s->value("zoom").toInt(); |
| 1553 |
if (s->contains("state")) |
| 1554 |
saved.state = s->value("state").toByteArray(); |
| 1555 |
if (s->contains("tools")) |
| 1556 |
tools = prefs->stringToTools(s->value("tools").toString()); |
| 1557 |
if (s->contains("name")) |
| 1558 |
setObjectName(s->value("name").toString()); |
| 1559 |
applySaved(&saved); |
| 1560 |
updateActionsLater(); |
| 1561 |
if (du.isValid()) |
| 1562 |
open(du); |
| 1563 |
if (document && s->contains("pageNo")) // compat |
| 1564 |
goToPage(s->value("pageNo", 0).toInt()); |
| 1565 |
} |
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
// ---------------------------------------- |
| 1571 |
// QDJVIEW ARGUMENTS |
| 1572 |
|
| 1573 |
|
| 1574 |
static bool |
| 1575 |
string_is_on(QString val) |
| 1576 |
{ |
| 1577 |
QString v = val.toLower(); |
| 1578 |
return v == "yes" || v == "on" || v == "true" || v == "1"; |
| 1579 |
} |
| 1580 |
|
| 1581 |
static bool |
| 1582 |
string_is_off(QString val) |
| 1583 |
{ |
| 1584 |
QString v = val.toLower(); |
| 1585 |
return v == "no" || v == "off" || v == "false" || v == "0"; |
| 1586 |
} |
| 1587 |
|
| 1588 |
static QString |
| 1589 |
get_boolean(bool b) |
| 1590 |
{ |
| 1591 |
return QString(b ? "yes" : "no"); |
| 1592 |
} |
| 1593 |
|
| 1594 |
static bool |
| 1595 |
parse_boolean(QString key, QString val, |
| 1596 |
QList<QString> &errors, bool &answer) |
| 1597 |
{ |
| 1598 |
answer = false; |
| 1599 |
if (string_is_off(val)) |
| 1600 |
return true; |
| 1601 |
answer = true; |
| 1602 |
if (string_is_on(val) || val.isNull()) |
| 1603 |
return true; |
| 1604 |
errors << QDjView::tr("Option '%1' requires boolean argument.").arg(key); |
| 1605 |
return false; |
| 1606 |
} |
| 1607 |
|
| 1608 |
static void |
| 1609 |
illegal_value(QString key, QString value, QList<QString> &errors) |
| 1610 |
{ |
| 1611 |
errors << QDjView::tr("Illegal value '%2' for option '%1'.") |
| 1612 |
.arg(key).arg(value); |
| 1613 |
} |
| 1614 |
|
| 1615 |
static bool |
| 1616 |
parse_position(QString value, double &x, double &y) |
| 1617 |
{ |
| 1618 |
bool okay0, okay1; |
| 1619 |
QStringList val = value.split(","); |
| 1620 |
if (val.size() == 2) |
| 1621 |
{ |
| 1622 |
x = val[0].toDouble(&okay0); |
| 1623 |
y = val[1].toDouble(&okay1); |
| 1624 |
return okay0 && okay1; |
| 1625 |
} |
| 1626 |
return false; |
| 1627 |
} |
| 1628 |
|
| 1629 |
static bool |
| 1630 |
parse_highlight(QString value, |
| 1631 |
int &x, int &y, int &w, int &h, |
| 1632 |
QColor &color) |
| 1633 |
{ |
| 1634 |
bool okay0, okay1, okay2, okay3; |
| 1635 |
QStringList val = value.split(","); |
| 1636 |
if (val.size() < 4) |
| 1637 |
return false; |
| 1638 |
x = val[0].toInt(&okay0); |
| 1639 |
y = val[1].toInt(&okay1); |
| 1640 |
w = val[2].toInt(&okay2); |
| 1641 |
h = val[3].toInt(&okay3); |
| 1642 |
if (! (okay0 && okay1 && okay2 && okay3)) |
| 1643 |
return false; |
| 1644 |
if (val.size() < 5) |
| 1645 |
return true; |
| 1646 |
QString c = val[4]; |
| 1647 |
if (c[0] != '#') |
| 1648 |
c = "#" + c; |
| 1649 |
color.setNamedColor(c); |
| 1650 |
if (! color.isValid()) |
| 1651 |
return false; |
| 1652 |
if (val.size() <= 5) |
| 1653 |
return true; |
| 1654 |
return false; |
| 1655 |
} |
| 1656 |
|
| 1657 |
template<class T> static inline void |
| 1658 |
set_reset(QFlags<T> &x, bool plus, bool minus, T y) |
| 1659 |
{ |
| 1660 |
if (plus) |
| 1661 |
x |= y; |
| 1662 |
else if (minus) |
| 1663 |
x &= ~y; |
| 1664 |
} |
| 1665 |
|
| 1666 |
|
| 1667 |
void |
| 1668 |
QDjView::parseToolBarOption(QString option, QStringList &errors) |
| 1669 |
{ |
| 1670 |
QString str = option.toLower(); |
| 1671 |
int len = str.size(); |
| 1672 |
bool wantselect = false; |
| 1673 |
bool wantmode = false; |
| 1674 |
bool minus = false; |
| 1675 |
bool plus = false; |
| 1676 |
int npos = 0; |
| 1677 |
while (npos < len) |
| 1678 |
{ |
| 1679 |
int pos = npos; |
| 1680 |
npos = reIndex(str, QRegExp("[-+,]"), pos); |
| 1681 |
if (npos < 0) |
| 1682 |
npos = len; |
| 1683 |
QString key = str.mid(pos, npos-pos).trimmed(); |
| 1684 |
if (string_is_off(key) && !plus && !minus) |
| 1685 |
options &= ~QDjViewPrefs::SHOW_TOOLBAR; |
| 1686 |
else if (string_is_on(key) && !plus && !minus) |
| 1687 |
options |= QDjViewPrefs::SHOW_TOOLBAR; |
| 1688 |
else if (key=="bottom" && !plus && !minus) { |
| 1689 |
options |= QDjViewPrefs::SHOW_TOOLBAR; |
| 1690 |
tools &= ~QDjViewPrefs::TOOLBAR_TOP; |
| 1691 |
} else if (key=="top" && !plus && !minus) { |
| 1692 |
options |= QDjViewPrefs::SHOW_TOOLBAR; |
| 1693 |
tools &= ~QDjViewPrefs::TOOLBAR_BOTTOM; |
| 1694 |
} else if (key=="auto" && !plus && !minus) |
| 1695 |
tools |= QDjViewPrefs::TOOLBAR_AUTOHIDE; |
| 1696 |
else if (key=="always" && !plus && !minus) { |
| 1697 |
options |= QDjViewPrefs::SHOW_TOOLBAR; |
| 1698 |
tools &= ~QDjViewPrefs::TOOLBAR_AUTOHIDE; |
| 1699 |
} else if (reIndex(key, QRegExp("^(fore|back|color|bw)(_button)?$"), 0) >= 0) |
| 1700 |
wantmode |= plus; |
| 1701 |
else if (key=="pan" || key=="zoomsel" || key=="textsel") |
| 1702 |
wantselect |= plus; |
| 1703 |
else if (key=="modecombo") |
| 1704 |
set_reset(tools, plus, minus, QDjViewPrefs::TOOL_MODECOMBO); |
| 1705 |
else if (key=="rescombo" || key=="zoomcombo") |
| 1706 |
set_reset(tools, plus, minus, QDjViewPrefs::TOOL_ZOOMCOMBO); |
| 1707 |
else if (key=="zoom") |
| 1708 |
set_reset(tools, plus, minus, QDjViewPrefs::TOOL_ZOOMBUTTONS); |
| 1709 |
else if (key=="rotate") |
| 1710 |
set_reset(tools, plus, minus, QDjViewPrefs::TOOL_ROTATE); |
| 1711 |
else if (key=="search" || key=="find") |
| 1712 |
set_reset(tools, plus, minus, QDjViewPrefs::TOOL_FIND); |
| 1713 |
else if (key=="print") |
| 1714 |
set_reset(tools, plus, minus, QDjViewPrefs::TOOL_PRINT); |
| 1715 |
else if (key=="save") |
| 1716 |
set_reset(tools, plus, minus, QDjViewPrefs::TOOL_SAVE); |
| 1717 |
else if (key=="pagecombo") |
| 1718 |
set_reset(tools, plus, minus, QDjViewPrefs::TOOL_PAGECOMBO); |
| 1719 |
else if (key=="backforw") |
| 1720 |
set_reset(tools, plus, minus, QDjViewPrefs::TOOL_BACKFORW); |
| 1721 |
else if (key=="prevnext" || key=="prevnextpage") |
| 1722 |
set_reset(tools, plus, minus, QDjViewPrefs::TOOL_PREVNEXT); |
| 1723 |
else if (key=="firstlast" || key=="firstlastpage") |
| 1724 |
set_reset(tools, plus, minus, QDjViewPrefs::TOOL_FIRSTLAST); |
| 1725 |
// lizards |
| 1726 |
else if (key=="doublepage") // lizards! |
| 1727 |
set_reset(tools, plus, minus, QDjViewPrefs::TOOL_LAYOUT); |
| 1728 |
else if (key=="calibrate" || key=="ruler" || key=="lizard") |
| 1729 |
errors << tr("Toolbar option '%1' is not implemented.").arg(key); |
| 1730 |
// djview4 |
| 1731 |
else if (key=="select") |
| 1732 |
set_reset(tools, plus, minus, QDjViewPrefs::TOOL_SELECT); |
| 1733 |
else if (key=="new") |
| 1734 |
set_reset(tools, plus, minus, QDjViewPrefs::TOOL_NEW); |
| 1735 |
else if (key=="open") |
| 1736 |
set_reset(tools, plus, minus, QDjViewPrefs::TOOL_OPEN); |
| 1737 |
else if (key=="layout") |
| 1738 |
set_reset(tools, plus, minus, QDjViewPrefs::TOOL_LAYOUT); |
| 1739 |
else if (key=="help") |
| 1740 |
set_reset(tools, plus, minus, QDjViewPrefs::TOOL_WHATSTHIS); |
| 1741 |
else if (key!="") |
| 1742 |
errors << tr("Toolbar option '%1' is not recognized.").arg(key); |
| 1743 |
// handle + or - |
| 1744 |
if (npos < len) |
| 1745 |
{ |
| 1746 |
Tools base = QDjViewPrefs::TOOLBAR_AUTOHIDE | |
| 1747 |
QDjViewPrefs::TOOLBAR_TOP | QDjViewPrefs::TOOLBAR_BOTTOM; |
| 1748 |
if (str[npos] == '-') |
| 1749 |
{ |
| 1750 |
if (!minus && !plus) |
| 1751 |
tools |= (prefs->tools & ~base); |
| 1752 |
plus = false; |
| 1753 |
minus = true; |
| 1754 |
} |
| 1755 |
else if (str[npos] == '+') |
| 1756 |
{ |
| 1757 |
if (!minus && !plus) |
| 1758 |
tools &= base; |
| 1759 |
minus = false; |
| 1760 |
plus = true; |
| 1761 |
} |
| 1762 |
npos += 1; |
| 1763 |
} |
| 1764 |
} |
| 1765 |
if (wantmode) |
| 1766 |
tools |= QDjViewPrefs::TOOL_MODECOMBO; |
| 1767 |
if (wantselect) |
| 1768 |
tools |= QDjViewPrefs::TOOL_SELECT; |
| 1769 |
} |
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
/*! Parse a qdjview option described by a pair \a key, \a value. |
| 1774 |
Such options can be provided on the command line |
| 1775 |
or passed with the document URL as pseudo-CGI arguments. |
| 1776 |
Return a list of error strings. */ |
| 1777 |
|
| 1778 |
QStringList |
| 1779 |
QDjView::parseArgument(QString key, QString value) |
| 1780 |
{ |
| 1781 |
bool okay; |
| 1782 |
QStringList errors; |
| 1783 |
key = key.toLower(); |
| 1784 |
|
| 1785 |
if (key == "fullscreen" || key == "fs") |
| 1786 |
{ |
| 1787 |
if (viewerMode < STANDALONE) |
| 1788 |
errors << tr("Option '%1' requires a standalone viewer.").arg(key); |
| 1789 |
if (parse_boolean(key, value, errors, okay)) |
| 1790 |
setViewerMode(okay ? STANDALONE_FULLSCREEN : STANDALONE); |
| 1791 |
} |
| 1792 |
else if (key == "slideshow") |
| 1793 |
{ |
| 1794 |
if (viewerMode < STANDALONE) |
| 1795 |
errors << tr("Option '%1' requires a standalone viewer.").arg(key); |
| 1796 |
int delay = value.toInt(&okay); |
| 1797 |
if (okay && delay < 0) |
| 1798 |
okay = false; |
| 1799 |
if (okay || parse_boolean(key, value, errors, okay)) |
| 1800 |
setViewerMode(okay ? STANDALONE_SLIDESHOW : STANDALONE); |
| 1801 |
if (delay > 0) |
| 1802 |
setSlideShowDelay(delay); |
| 1803 |
} |
| 1804 |
else if (key == "toolbar") |
| 1805 |
{ |
| 1806 |
parseToolBarOption(value, errors); |
| 1807 |
toolBar->setVisible(options & QDjViewPrefs::SHOW_TOOLBAR); |
| 1808 |
} |
| 1809 |
else if (key == "page") |
| 1810 |
{ |
| 1811 |
pendingPage = value; |
| 1812 |
performPendingLater(); |
| 1813 |
} |
| 1814 |
else if (key == "pageno") |
| 1815 |
{ |
| 1816 |
pendingPage = QString("$%1").arg(value.toInt()); |
| 1817 |
performPendingLater(); |
| 1818 |
} |
| 1819 |
else if (key == "cache") |
| 1820 |
{ |
| 1821 |
// see QDjVuDocument::setUrl(...) |
| 1822 |
parse_boolean(key, value, errors, okay); |
| 1823 |
} |
| 1824 |
else if (key == "passive" || key == "passivestretch") |
| 1825 |
{ |
| 1826 |
if (parse_boolean(key, value, errors, okay) && okay) |
| 1827 |
{ |
| 1828 |
enableScrollBars(false); |
| 1829 |
enableContextMenu(false); |
| 1830 |
menuBar->setVisible(false); |
| 1831 |
statusBar->setVisible(false); |
| 1832 |
thumbnailDock->setVisible(false); |
| 1833 |
outlineDock->setVisible(false); |
| 1834 |
findDock->setVisible(false); |
| 1835 |
toolBar->setVisible(false); |
| 1836 |
if (key == "passive") |
| 1837 |
widget->setZoom(QDjVuWidget::ZOOM_FITPAGE); |
| 1838 |
else |
| 1839 |
widget->setZoom(QDjVuWidget::ZOOM_STRETCH); |
| 1840 |
widget->setContinuous(false); |
| 1841 |
widget->setSideBySide(false); |
| 1842 |
widget->enableKeyboard(false); |
| 1843 |
widget->enableMouse(false); |
| 1844 |
} |
| 1845 |
} |
| 1846 |
else if (key == "scrollbars") |
| 1847 |
{ |
| 1848 |
if (parse_boolean(key, value, errors, okay)) |
| 1849 |
enableScrollBars(okay); |
| 1850 |
} |
| 1851 |
else if (key == "menubar") // new for djview4 |
| 1852 |
{ |
| 1853 |
if (parse_boolean(key, value, errors, okay)) |
| 1854 |
menuBar->setVisible(okay); |
| 1855 |
} |
| 1856 |
else if (key == "sidebar" || // new for djview4 |
| 1857 |
key == "navpane" ) // lizards |
| 1858 |
{ |
| 1859 |
showSideBar(value, errors); |
| 1860 |
} |
| 1861 |
else if (key == "statusbar") // new for djview4 |
| 1862 |
{ |
| 1863 |
if (parse_boolean(key, value, errors, okay)) |
| 1864 |
statusBar->setVisible(okay); |
| 1865 |
} |
| 1866 |
else if (key == "continuous") // new for djview4 |
| 1867 |
{ |
| 1868 |
if (parse_boolean(key, value, errors, okay)) |
| 1869 |
widget->setContinuous(okay); |
| 1870 |
} |
| 1871 |
else if (key == "side_by_side" || |
| 1872 |
key == "sidebyside") // new for djview4 |
| 1873 |
{ |
| 1874 |
if (parse_boolean(key, value, errors, okay)) |
| 1875 |
widget->setSideBySide(okay); |
| 1876 |
} |
| 1877 |
else if (key == "firstpagealone" || |
| 1878 |
key == "first_page_alone" || |
| 1879 |
key == "cover_page" || |
| 1880 |
key == "coverpage") // new for djview4 |
| 1881 |
{ |
| 1882 |
if (parse_boolean(key, value, errors, okay)) |
| 1883 |
widget->setCoverPage(okay); |
| 1884 |
} |
| 1885 |
else if (key == "right_to_left" || |
| 1886 |
key == "righttoleft") // new for djview4 |
| 1887 |
{ |
| 1888 |
if (parse_boolean(key, value, errors, okay)) |
| 1889 |
widget->setRightToLeft(okay); |
| 1890 |
} |
| 1891 |
else if (key == "layout") // lizards |
| 1892 |
{ |
| 1893 |
bool layout = false; |
| 1894 |
bool continuous = false; |
| 1895 |
bool sidebyside = false; |
| 1896 |
foreach (QString s, value.split(",")) |
| 1897 |
{ |
| 1898 |
if (s == "single") |
| 1899 |
layout = true, continuous = sidebyside = false; |
| 1900 |
else if (s == "double") |
| 1901 |
layout = sidebyside = true; |
| 1902 |
else if (s == "continuous") |
| 1903 |
layout = continuous = true; |
| 1904 |
else if (s == "ltor") |
| 1905 |
widget->setRightToLeft(false); |
| 1906 |
else if (s == "rtol") |
| 1907 |
widget->setRightToLeft(true); |
| 1908 |
else if (s == "cover") |
| 1909 |
widget->setCoverPage(true); |
| 1910 |
else if (s == "nocover") |
| 1911 |
widget->setCoverPage(false); |
| 1912 |
else if (s == "gap") |
| 1913 |
widget->setSeparatorSize(12); |
| 1914 |
else if (s == "nogap") |
| 1915 |
widget->setSeparatorSize(0); |
| 1916 |
} |
| 1917 |
if (layout) |
| 1918 |
{ |
| 1919 |
widget->setContinuous(continuous); |
| 1920 |
widget->setSideBySide(sidebyside); |
| 1921 |
} |
| 1922 |
} |
| 1923 |
else if (key == "frame") |
| 1924 |
{ |
| 1925 |
if (parse_boolean(key, value, errors, okay)) |
| 1926 |
widget->setDisplayFrame(okay); |
| 1927 |
} |
| 1928 |
else if (key == "background") |
| 1929 |
{ |
| 1930 |
QColor color; |
| 1931 |
color.setNamedColor((value[0] == '#') ? value : "#" + value); |
| 1932 |
if (color.isValid()) |
| 1933 |
{ |
| 1934 |
QBrush brush = QBrush(color); |
| 1935 |
widget->setBorderBrush(brush); |
| 1936 |
fsSavedNormal.nsBorderBrush = brush; |
| 1937 |
fsSavedFullScreen.nsBorderBrush = brush; |
| 1938 |
fsSavedSlideShow.nsBorderBrush = brush; |
| 1939 |
} |
| 1940 |
else |
| 1941 |
illegal_value(key, value, errors); |
| 1942 |
} |
| 1943 |
else if (key == "menu") |
| 1944 |
{ |
| 1945 |
if (parse_boolean(key, value, errors, okay)) |
| 1946 |
enableContextMenu(okay); |
| 1947 |
} |
| 1948 |
else if (key == "keyboard") |
| 1949 |
{ |
| 1950 |
if (parse_boolean(key, value, errors, okay)) |
| 1951 |
widget->enableKeyboard(okay); |
| 1952 |
} |
| 1953 |
else if (key == "mouse") |
| 1954 |
{ |
| 1955 |
if (parse_boolean(key, value, errors, okay)) |
| 1956 |
widget->enableMouse(okay); |
| 1957 |
} |
| 1958 |
else if (key == "links") |
| 1959 |
{ |
| 1960 |
if (parse_boolean(key, value, errors, okay)) |
| 1961 |
widget->enableHyperlink(okay); |
| 1962 |
} |
| 1963 |
else if (key == "zoom") |
| 1964 |
{ |
| 1965 |
int z = value.toInt(&okay); |
| 1966 |
QString val = value.toLower(); |
| 1967 |
if (val == "one2one") |
| 1968 |
widget->setZoom(QDjVuWidget::ZOOM_ONE2ONE); |
| 1969 |
else if (val == "width" || val == "fitwidth") |
| 1970 |
widget->setZoom(QDjVuWidget::ZOOM_FITWIDTH); |
| 1971 |
else if (val == "page" || val == "fitpage") |
| 1972 |
widget->setZoom(QDjVuWidget::ZOOM_FITPAGE); |
| 1973 |
else if (val == "stretch") |
| 1974 |
widget->setZoom(QDjVuWidget::ZOOM_STRETCH); |
| 1975 |
else if (okay && z >= QDjVuWidget::ZOOM_MIN |
| 1976 |
&& z <= QDjVuWidget::ZOOM_MAX) |
| 1977 |
widget->setZoom(z); |
| 1978 |
else |
| 1979 |
illegal_value(key, value, errors); |
| 1980 |
} |
| 1981 |
else if (key == "mode") |
| 1982 |
{ |
| 1983 |
QString val = value.toLower(); |
| 1984 |
if (val == "color") |
| 1985 |
widget->setDisplayMode(QDjVuWidget::DISPLAY_COLOR); |
| 1986 |
else if (val == "bw" || val == "mask" || val == "stencil") |
| 1987 |
widget->setDisplayMode(QDjVuWidget::DISPLAY_STENCIL); |
| 1988 |
else if (val == "fore" || val == "foreground" || val == "fg") |
| 1989 |
widget->setDisplayMode(QDjVuWidget::DISPLAY_FG); |
| 1990 |
else if (val == "back" || val == "background" || val == "bg") |
| 1991 |
widget->setDisplayMode(QDjVuWidget::DISPLAY_BG); |
| 1992 |
else if (val == "text" || val == "hiddentext") |
| 1993 |
widget->setDisplayMode(QDjVuWidget::DISPLAY_TEXT); |
| 1994 |
else |
| 1995 |
illegal_value(key, value, errors); |
| 1996 |
} |
| 1997 |
else if (key == "hor_align" || key == "halign") |
| 1998 |
{ |
| 1999 |
QString val = value.toLower(); |
| 2000 |
if (val == "left") |
| 2001 |
widget->setHorizAlign(QDjVuWidget::ALIGN_LEFT); |
| 2002 |
else if (val == "center") |
| 2003 |
widget->setHorizAlign(QDjVuWidget::ALIGN_CENTER); |
| 2004 |
else if (val == "right") |
| 2005 |
widget->setHorizAlign(QDjVuWidget::ALIGN_RIGHT); |
| 2006 |
else |
| 2007 |
illegal_value(key, value, errors); |
| 2008 |
} |
| 2009 |
else if (key == "ver_align" || key == "valign") |
| 2010 |
{ |
| 2011 |
QString val = value.toLower(); |
| 2012 |
if (val == "top") |
| 2013 |
widget->setVertAlign(QDjVuWidget::ALIGN_TOP); |
| 2014 |
else if (val == "center") |
| 2015 |
widget->setVertAlign(QDjVuWidget::ALIGN_CENTER); |
| 2016 |
else if (val == "bottom") |
| 2017 |
widget->setVertAlign(QDjVuWidget::ALIGN_BOTTOM); |
| 2018 |
else |
| 2019 |
illegal_value(key, value, errors); |
| 2020 |
} |
| 2021 |
else if (key == "highlight") |
| 2022 |
{ |
| 2023 |
int x,y,w,h; |
| 2024 |
QColor color; |
| 2025 |
if (value.isEmpty()) |
| 2026 |
widget->clearHighlights(widget->page()); |
| 2027 |
else if (parse_highlight(value, x, y, w, h, color)) |
| 2028 |
pendingHilite << StringPair(pendingPage, value); |
| 2029 |
else |
| 2030 |
illegal_value(key, value, errors); |
| 2031 |
performPendingLater(); |
| 2032 |
} |
| 2033 |
else if (key == "rotate") |
| 2034 |
{ |
| 2035 |
if (value == "0") |
| 2036 |
widget->setRotation(0); |
| 2037 |
else if (value == "90") |
| 2038 |
widget->setRotation(1); |
| 2039 |
else if (value == "180") |
| 2040 |
widget->setRotation(2); |
| 2041 |
else if (value == "270") |
| 2042 |
widget->setRotation(3); |
| 2043 |
else |
| 2044 |
illegal_value(key, value, errors); |
| 2045 |
} |
| 2046 |
else if (key == "print") |
| 2047 |
{ |
| 2048 |
if (parse_boolean(key, value, errors, okay)) |
| 2049 |
printingAllowed = okay; |
| 2050 |
} |
| 2051 |
else if (key == "save") |
| 2052 |
{ |
| 2053 |
if (parse_boolean(key, value, errors, okay)) |
| 2054 |
savingAllowed = okay; |
| 2055 |
} |
| 2056 |
else if (key == "notoolbar" || |
| 2057 |
key == "noscrollbars" || |
| 2058 |
key == "nomenu" ) |
| 2059 |
{ |
| 2060 |
QString msg = tr("Deprecated option '%1'").arg(key); |
| 2061 |
qWarning("%s",(const char*)msg.toLocal8Bit()); |
| 2062 |
if (key == "notoolbar" && value.isNull()) |
| 2063 |
toolBar->setVisible(false); |
| 2064 |
else if (key == "noscrollbars" && value.isNull()) |
| 2065 |
enableScrollBars(false); |
| 2066 |
else if (key == "nomenu" && value.isNull()) |
| 2067 |
enableContextMenu(false); |
| 2068 |
} |
| 2069 |
else if (key == "thumbnails") |
| 2070 |
{ |
| 2071 |
QStringList junk; |
| 2072 |
if (! showSideBar(value+",thumbnails", junk)) |
| 2073 |
illegal_value(key, value, errors); |
| 2074 |
} |
| 2075 |
else if (key == "outline") |
| 2076 |
{ |
| 2077 |
QStringList junk; |
| 2078 |
if (! showSideBar(value+",outline", junk)) |
| 2079 |
illegal_value(key, value, errors); |
| 2080 |
} |
| 2081 |
else if (key == "find") // new for djview4 |
| 2082 |
{ |
| 2083 |
if (findWidget) |
| 2084 |
{ |
| 2085 |
findWidget->setText(QString()); |
| 2086 |
findWidget->setRegExpMode(false); |
| 2087 |
findWidget->setWordOnly(true); |
| 2088 |
findWidget->setCaseSensitive(false); |
| 2089 |
} |
| 2090 |
pendingFind = value; |
| 2091 |
if (! value.isEmpty()) |
| 2092 |
performPendingLater(); |
| 2093 |
} |
| 2094 |
else if (key == "showposition") |
| 2095 |
{ |
| 2096 |
double x=0, y=0; |
| 2097 |
pendingPosition.clear(); |
| 2098 |
if (! parse_position(value, x, y)) |
| 2099 |
illegal_value(key, value, errors); |
| 2100 |
else |
| 2101 |
{ |
| 2102 |
pendingPosition << x << y; |
| 2103 |
performPendingLater(); |
| 2104 |
} |
| 2105 |
} |
| 2106 |
else if (key == "logo" || key == "textsel" || key == "search") |
| 2107 |
{ |
| 2108 |
QString msg = tr("Option '%1' is not implemented.").arg(key); |
| 2109 |
qWarning("%s",(const char*)msg.toLocal8Bit()); |
| 2110 |
} |
| 2111 |
else |
| 2112 |
{ |
| 2113 |
errors << tr("Option '%1' is not recognized.").arg(key); |
| 2114 |
} |
| 2115 |
updateActionsLater(); |
| 2116 |
return errors; |
| 2117 |
} |
| 2118 |
|
| 2119 |
|
| 2120 |
/*! Parse a \a QDjView option expressed a a string \a key=value. |
| 2121 |
This is very useful for processing command line options. */ |
| 2122 |
|
| 2123 |
QStringList |
| 2124 |
QDjView::parseArgument(QString keyEqualValue) |
| 2125 |
{ |
| 2126 |
int n = keyEqualValue.indexOf("="); |
| 2127 |
if (n < 0) |
| 2128 |
return parseArgument(keyEqualValue, QString()); |
| 2129 |
else |
| 2130 |
return parseArgument(keyEqualValue.left(n), |
| 2131 |
keyEqualValue.mid(n+1)); |
| 2132 |
} |
| 2133 |
|
| 2134 |
|
| 2135 |
/*! Parse the \a QDjView options passed via |
| 2136 |
the CGI query arguments of \a url. |
| 2137 |
This is called by \a QDjView::open(QDjVuDocument, QUrl). */ |
| 2138 |
|
| 2139 |
void |
| 2140 |
QDjView::parseDjVuCgiArguments(QUrl url) |
| 2141 |
{ |
| 2142 |
QStringList errors; |
| 2143 |
// parse |
| 2144 |
bool djvuopts = false; |
| 2145 |
QPair<QString,QString> pair; |
| 2146 |
foreach(pair, urlQueryItems(url, true)) |
| 2147 |
{ |
| 2148 |
if (pair.first.toLower() == "djvuopts") |
| 2149 |
djvuopts = true; |
| 2150 |
else if (djvuopts) |
| 2151 |
errors << parseArgument(pair.first, pair.second); |
| 2152 |
} |
| 2153 |
// warning for errors |
| 2154 |
if (djvuopts && errors.size() > 0) |
| 2155 |
{ |
| 2156 |
foreach(QString error, errors) |
| 2157 |
qWarning("%s",(const char*)error.toLocal8Bit()); |
| 2158 |
} |
| 2159 |
} |
| 2160 |
|
| 2161 |
|
| 2162 |
/*! Return a copy of the url without the |
| 2163 |
CGI query arguments corresponding to DjVu options. */ |
| 2164 |
|
| 2165 |
QUrl |
| 2166 |
QDjView::removeDjVuCgiArguments(QUrl url) |
| 2167 |
{ |
| 2168 |
QList<QPair<QString,QString> > args; |
| 2169 |
bool djvuopts = false; |
| 2170 |
QPair<QString,QString> pair; |
| 2171 |
foreach(pair, urlQueryItems(url)) |
| 2172 |
{ |
| 2173 |
if (pair.first.toLower() == "djvuopts") |
| 2174 |
djvuopts = true; |
| 2175 |
else if (!djvuopts) |
| 2176 |
args << pair; |
| 2177 |
} |
| 2178 |
QUrl newurl = url; |
| 2179 |
urlSetQueryItems(newurl, args); |
| 2180 |
return newurl; |
| 2181 |
} |
| 2182 |
|
| 2183 |
|
| 2184 |
/*! Returns the most adequate value |
| 2185 |
that could be passed to \a parseArgument |
| 2186 |
for the specified \a key. */ |
| 2187 |
|
| 2188 |
QString |
| 2189 |
QDjView::getArgument(QString key) |
| 2190 |
{ |
| 2191 |
key = key.toLower(); |
| 2192 |
if (key == "pages") // readonly |
| 2193 |
return QString::number(pageNum()); |
| 2194 |
else if (key == "page") |
| 2195 |
return pageName(widget->page()); |
| 2196 |
else if (key == "pageno") |
| 2197 |
return QString::number(widget->page()+1); |
| 2198 |
else if (key == "fullscreen" || key == "fs") |
| 2199 |
return get_boolean(viewerMode == STANDALONE_FULLSCREEN); |
| 2200 |
else if (key == "slideshow") |
| 2201 |
return get_boolean(viewerMode == STANDALONE_SLIDESHOW); |
| 2202 |
else if (key == "scrollbars") |
| 2203 |
return get_boolean(widget->horizontalScrollBarPolicy() != |
| 2204 |
Qt::ScrollBarAlwaysOff ); |
| 2205 |
else if (key == "menubar") |
| 2206 |
return get_boolean(menuBar->isVisibleTo(this)); |
| 2207 |
else if (key == "statusbar") |
| 2208 |
return get_boolean(statusBar->isVisibleTo(this)); |
| 2209 |
else if (key == "continuous") |
| 2210 |
return get_boolean(widget->continuous()); |
| 2211 |
else if (key == "side_by_side" || key == "sidebyside") |
| 2212 |
return get_boolean(widget->sideBySide()); |
| 2213 |
else if (key == "coverpage" || key == "firstpagealone" || |
| 2214 |
key == "first_page_alone" ) |
| 2215 |
return get_boolean(widget->coverPage()); |
| 2216 |
else if (key == "righttoleft" || key == "right_to_left") |
| 2217 |
return get_boolean(widget->rightToLeft()); |
| 2218 |
else if (key == "frame") |
| 2219 |
return get_boolean(widget->displayFrame()); |
| 2220 |
else if (key == "keyboard") |
| 2221 |
return get_boolean(widget->keyboardEnabled()); |
| 2222 |
else if (key == "mouse") |
| 2223 |
return get_boolean(widget->mouseEnabled()); |
| 2224 |
else if (key == "links") |
| 2225 |
return get_boolean(widget->hyperlinkEnabled()); |
| 2226 |
else if (key == "menu") |
| 2227 |
return get_boolean(widget->contextMenu() != 0); |
| 2228 |
else if (key == "rotate") |
| 2229 |
return QString::number(widget->rotation() * 90); |
| 2230 |
else if (key == "print") |
| 2231 |
return get_boolean(printingAllowed); |
| 2232 |
else if (key == "save") |
| 2233 |
return get_boolean(savingAllowed); |
| 2234 |
else if (key == "background") |
| 2235 |
{ |
| 2236 |
QBrush brush = widget->borderBrush(); |
| 2237 |
if (brush.style() == Qt::SolidPattern) |
| 2238 |
return brush.color().name(); |
| 2239 |
} |
| 2240 |
else if (key == "layout") |
| 2241 |
{ |
| 2242 |
QStringList l; |
| 2243 |
if (widget->sideBySide()) |
| 2244 |
l << QString("double"); |
| 2245 |
if (widget->continuous()) |
| 2246 |
l << QString("continuous"); |
| 2247 |
if (l.isEmpty()) |
| 2248 |
l << QString("single"); |
| 2249 |
l << QString(widget->rightToLeft() ? "rtol" : "ltor"); |
| 2250 |
l << QString(widget->coverPage() ? "cover" : "nocover"); |
| 2251 |
l << QString(widget->separatorSize() ? "gap" : "nogap"); |
| 2252 |
return l.join(","); |
| 2253 |
} |
| 2254 |
else if (key == "zoom") |
| 2255 |
{ |
| 2256 |
int z = widget->zoom(); |
| 2257 |
if (z == QDjVuWidget::ZOOM_ONE2ONE) |
| 2258 |
return QString("one2one"); |
| 2259 |
else if (z == QDjVuWidget::ZOOM_FITWIDTH) |
| 2260 |
return QString("width"); |
| 2261 |
else if (z == QDjVuWidget::ZOOM_FITPAGE) |
| 2262 |
return QString("page"); |
| 2263 |
else if (z == QDjVuWidget::ZOOM_STRETCH) |
| 2264 |
return QString("stretch"); |
| 2265 |
else if (z >= QDjVuWidget::ZOOM_MIN && z <= QDjVuWidget::ZOOM_MAX) |
| 2266 |
return QString::number(z); |
| 2267 |
} |
| 2268 |
else if (key == "mode") |
| 2269 |
{ |
| 2270 |
QDjVuWidget::DisplayMode m = widget->displayMode(); |
| 2271 |
if (m == QDjVuWidget::DISPLAY_COLOR) |
| 2272 |
return QString("color"); |
| 2273 |
else if (m == QDjVuWidget::DISPLAY_STENCIL) |
| 2274 |
return QString("bw"); |
| 2275 |
else if (m == QDjVuWidget::DISPLAY_FG) |
| 2276 |
return QString("fore"); |
| 2277 |
else if (m == QDjVuWidget::DISPLAY_BG) |
| 2278 |
return QString("back"); |
| 2279 |
else if (m == QDjVuWidget::DISPLAY_TEXT) |
| 2280 |
return QString("text"); |
| 2281 |
} |
| 2282 |
else if (key == "hor_align" || key == "halign") |
| 2283 |
{ |
| 2284 |
QDjVuWidget::Align a = widget->horizAlign(); |
| 2285 |
if (a == QDjVuWidget::ALIGN_LEFT) |
| 2286 |
return QString("left"); |
| 2287 |
else if (a == QDjVuWidget::ALIGN_CENTER) |
| 2288 |
return QString("center"); |
| 2289 |
else if (a == QDjVuWidget::ALIGN_RIGHT) |
| 2290 |
return QString("right"); |
| 2291 |
} |
| 2292 |
else if (key == "ver_align" || key == "valign") |
| 2293 |
{ |
| 2294 |
QDjVuWidget::Align a = widget->vertAlign(); |
| 2295 |
if (a == QDjVuWidget::ALIGN_TOP) |
| 2296 |
return QString("top"); |
| 2297 |
else if (a == QDjVuWidget::ALIGN_CENTER) |
| 2298 |
return QString("center"); |
| 2299 |
else if (a == QDjVuWidget::ALIGN_BOTTOM) |
| 2300 |
return QString("bottom"); |
| 2301 |
} |
| 2302 |
else if (key == "showposition") |
| 2303 |
{ |
| 2304 |
QPoint center = widget->rect().center(); |
| 2305 |
QDjVuWidget::Position pos = widget->positionWithClosestAnchor(center); |
| 2306 |
double ha = pos.hAnchor / 100.0; |
| 2307 |
double va = pos.vAnchor / 100.0; |
| 2308 |
return QString("%1,%2").arg(ha).arg(va); |
| 2309 |
} |
| 2310 |
else if (key == "passive" || key == "passivestretch") |
| 2311 |
{ |
| 2312 |
if (widget->horizontalScrollBarPolicy() == Qt::ScrollBarAlwaysOff |
| 2313 |
&& !menuBar->isVisibleTo(this) && !statusBar->isVisibleTo(this) |
| 2314 |
&& !thumbnailDock->isVisibleTo(this) && !outlineDock->isVisibleTo(this) |
| 2315 |
&& !findDock->isVisibleTo(this) && !toolBar->isVisibleTo(this) |
| 2316 |
&& !widget->continuous() && !widget->sideBySide() |
| 2317 |
&& !widget->keyboardEnabled() && !widget->mouseEnabled() |
| 2318 |
&& widget->contextMenu() == 0 ) |
| 2319 |
{ |
| 2320 |
int z = widget->zoom(); |
| 2321 |
if (key == "passive" && z == QDjVuWidget::ZOOM_FITPAGE) |
| 2322 |
return QString("yes"); |
| 2323 |
if (key == "passivestretch" && z == QDjVuWidget::ZOOM_STRETCH) |
| 2324 |
return QString("yes"); |
| 2325 |
} |
| 2326 |
return QString("no"); |
| 2327 |
} |
| 2328 |
else if (key == "sidebar") |
| 2329 |
{ // without position |
| 2330 |
QStringList what; |
| 2331 |
if (thumbnailDock->isVisibleTo(this)) |
| 2332 |
what << "thumbnails"; |
| 2333 |
if (outlineDock->isVisibleTo(this)) |
| 2334 |
what << "outline"; |
| 2335 |
if (findDock->isVisibleTo(this)) |
| 2336 |
what << "find"; |
| 2337 |
if (what.size() > 0) |
| 2338 |
return QString("yes,") + what.join(","); |
| 2339 |
else |
| 2340 |
return QString("no"); |
| 2341 |
} |
| 2342 |
else if (key == "toolbar") |
| 2343 |
{ // Currently without toolbar content |
| 2344 |
return get_boolean(toolBar->isVisibleTo(this)); |
| 2345 |
} |
| 2346 |
else if (key == "highlight") |
| 2347 |
{ // Currently not working |
| 2348 |
return QString(); |
| 2349 |
} |
| 2350 |
return QString(); |
| 2351 |
} |
| 2352 |
|
| 2353 |
|
| 2354 |
|
| 2355 |
|
| 2356 |
|
| 2357 |
|
| 2358 |
|
| 2359 |
|
| 2360 |
// ---------------------------------------- |
| 2361 |
// QDJVIEW |
| 2362 |
|
| 2363 |
|
| 2364 |
/*! \enum QDjView::ViewerMode |
| 2365 |
The viewer mode is selected at creation time. |
| 2366 |
Mode \a STANDALONE corresponds to a standalone program. |
| 2367 |
Modes \a FULLPAGE_PLUGIN and \a EMBEDDED_PLUGIN |
| 2368 |
correspond to a netscape plugin. */ |
| 2369 |
|
| 2370 |
|
| 2371 |
QDjView::~QDjView() |
| 2372 |
{ |
| 2373 |
closeDocument(); |
| 2374 |
} |
| 2375 |
|
| 2376 |
|
| 2377 |
/*! Construct a \a QDjView object using |
| 2378 |
the specified djvu context and viewer mode. */ |
| 2379 |
|
| 2380 |
QDjView::QDjView(QDjVuContext &context, ViewerMode mode, QWidget *parent) |
| 2381 |
: QMainWindow(parent), |
| 2382 |
viewerMode(mode < STANDALONE ? mode : STANDALONE), |
| 2383 |
djvuContext(context), |
| 2384 |
document(0), |
| 2385 |
hasNumericalPageTitle(true), |
| 2386 |
updateActionsScheduled(false), |
| 2387 |
performPendingScheduled(false), |
| 2388 |
printingAllowed(true), |
| 2389 |
savingAllowed(true) |
| 2390 |
{ |
| 2391 |
// Main window setup |
| 2392 |
setWindowTitle(tr("DjView")); |
| 2393 |
setWindowIcon(QIcon(":/images/djview.png")); |
| 2394 |
#ifndef Q_OS_DARWIN |
| 2395 |
if (QApplication::windowIcon().isNull()) |
| 2396 |
QApplication::setWindowIcon(windowIcon()); |
| 2397 |
#endif |
| 2398 |
|
| 2399 |
// Determine unique object name |
| 2400 |
if (mode >= STANDALONE) |
| 2401 |
{ |
| 2402 |
QWidgetList wl = QApplication::topLevelWidgets(); |
| 2403 |
static int num = 0; |
| 2404 |
QString name; |
| 2405 |
while(name.isEmpty()) |
| 2406 |
{ |
| 2407 |
name = QString("djview%1").arg(num++); |
| 2408 |
foreach(QWidget *w, wl) |
| 2409 |
if (w->objectName() == name) |
| 2410 |
name = QString(); |
| 2411 |
} |
| 2412 |
setObjectName(name); |
| 2413 |
} |
| 2414 |
|
| 2415 |
// Basic preferences |
| 2416 |
prefs = QDjViewPrefs::instance(); |
| 2417 |
options = QDjViewPrefs::defaultOptions; |
| 2418 |
tools = prefs->tools; |
| 2419 |
toolsCached = zero(Tools); |
| 2420 |
|
| 2421 |
// Create dialogs |
| 2422 |
errorDialog = new QDjViewErrorDialog(this); |
| 2423 |
infoDialog = 0; |
| 2424 |
metaDialog = 0; |
| 2425 |
|
| 2426 |
// Try using GLWidget? |
| 2427 |
bool useOpenGL = prefs->openGLAccel; |
| 2428 |
QString envOpenGL = QString::fromLocal8Bit(::getenv("DJVIEW_OPENGL")); |
| 2429 |
useOpenGL |= string_is_on(envOpenGL); |
| 2430 |
useOpenGL &= !string_is_off(envOpenGL); |
| 2431 |
if (viewerMode < STANDALONE) |
| 2432 |
useOpenGL = false; // GLWidget/XEmbed has focus issues |
| 2433 |
|
| 2434 |
// Create djvu widget |
| 2435 |
QWidget *central = new QWidget(this); |
| 2436 |
widget = new QDjVuWidget(useOpenGL, central); |
| 2437 |
widget->setFrameShape(QFrame::NoFrame); |
| 2438 |
if (viewerMode >= STANDALONE) |
| 2439 |
widget->setFrameShadow(QFrame::Sunken); |
| 2440 |
|
| 2441 |
widget->viewport()->installEventFilter(this); |
| 2442 |
connect(widget, SIGNAL(errorCondition(int)), |
| 2443 |
this, SLOT(errorCondition(int))); |
| 2444 |
connect(widget, SIGNAL(error(QString,QString,int)), |
| 2445 |
errorDialog, SLOT(error(QString,QString,int))); |
| 2446 |
connect(widget, SIGNAL(error(QString,QString,int)), |
| 2447 |
this, SLOT(error(QString,QString,int))); |
| 2448 |
connect(widget, SIGNAL(info(QString)), |
| 2449 |
this, SLOT(info(QString))); |
| 2450 |
connect(widget, SIGNAL(layoutChanged()), |
| 2451 |
this, SLOT(updateActionsLater())); |
| 2452 |
connect(widget, SIGNAL(pageChanged(int)), |
| 2453 |
this, SLOT(updateActionsLater())); |
| 2454 |
connect(widget, SIGNAL(pointerPosition(const Position&,const PageInfo&)), |
| 2455 |
this, SLOT(pointerPosition(const Position&,const PageInfo&))); |
| 2456 |
connect(widget, SIGNAL(pointerEnter(const Position&,miniexp_t)), |
| 2457 |
this, SLOT(pointerEnter(const Position&,miniexp_t))); |
| 2458 |
connect(widget, SIGNAL(pointerLeave(const Position&,miniexp_t)), |
| 2459 |
this, SLOT(pointerLeave(const Position&,miniexp_t))); |
| 2460 |
connect(widget, SIGNAL(pointerClick(const Position&,miniexp_t)), |
| 2461 |
this, SLOT(pointerClick(const Position&,miniexp_t))); |
| 2462 |
connect(widget, SIGNAL(pointerSelect(const QPoint&,const QRect&)), |
| 2463 |
this, SLOT(pointerSelect(const QPoint&,const QRect&))); |
| 2464 |
|
| 2465 |
// Create splash screen |
| 2466 |
splash = new QLabel(central); |
| 2467 |
splash->setFrameShadow(QFrame::Sunken); |
| 2468 |
splash->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter); |
| 2469 |
splash->setPixmap(QPixmap(":/images/splash.png")); |
| 2470 |
QPalette palette = splash->palette(); |
| 2471 |
#if QT_VERSION >= 0x60000 |
| 2472 |
palette.setColor(QPalette::Window, Qt::white); |
| 2473 |
#else |
| 2474 |
palette.setColor(QPalette::Background, Qt::white); |
| 2475 |
#endif |
| 2476 |
splash->setPalette(palette); |
| 2477 |
splash->setAutoFillBackground(true); |
| 2478 |
|
| 2479 |
// Create central layout |
| 2480 |
layout = new QStackedLayout(central); |
| 2481 |
layout->addWidget(widget); |
| 2482 |
layout->addWidget(splash); |
| 2483 |
layout->setCurrentWidget(splash); |
| 2484 |
setCentralWidget(central); |
| 2485 |
|
| 2486 |
// Create context menu |
| 2487 |
contextMenu = new QMenu(this); |
| 2488 |
recentMenu = 0; |
| 2489 |
|
| 2490 |
// Create menubar |
| 2491 |
menuBar = new QMenuBar(this); |
| 2492 |
setMenuBar(menuBar); |
| 2493 |
|
| 2494 |
// Create statusbar |
| 2495 |
statusBar = new QStatusBar(this); |
| 2496 |
QFont font = QApplication::font(); |
| 2497 |
font.setPointSize((font.pointSize() * 3 + 3) / 4); |
| 2498 |
QFontMetrics metric(font); |
| 2499 |
textLabelTimer = new QTimer(this); |
| 2500 |
textLabelTimer->setSingleShot(true); |
| 2501 |
connect(textLabelTimer,SIGNAL(timeout()),this,SLOT(updateTextLabel())); |
| 2502 |
textLabel = new QLabel(statusBar); |
| 2503 |
textLabel->setFont(font); |
| 2504 |
textLabel->setAutoFillBackground(true); |
| 2505 |
textLabel->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter); |
| 2506 |
textLabel->setFrameStyle(QFrame::Panel); |
| 2507 |
textLabel->setFrameShadow(QFrame::Sunken); |
| 2508 |
textLabel->setMinimumWidth(swidth(metric,"M")*48); |
| 2509 |
statusBar->addWidget(textLabel, 1); |
| 2510 |
pageLabel = new QLabel(statusBar); |
| 2511 |
pageLabel->setFont(font); |
| 2512 |
pageLabel->setTextFormat(Qt::PlainText); |
| 2513 |
pageLabel->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter); |
| 2514 |
pageLabel->setFrameStyle(QFrame::Panel); |
| 2515 |
pageLabel->setFrameShadow(QFrame::Sunken); |
| 2516 |
pageLabel->setMinimumWidth(swidth(metric," P88/888 8888x8888 888dpi ")); |
| 2517 |
statusBar->addPermanentWidget(pageLabel); |
| 2518 |
mouseLabel = new QLabel(statusBar); |
| 2519 |
mouseLabel->setFont(font); |
| 2520 |
mouseLabel->setTextFormat(Qt::PlainText); |
| 2521 |
mouseLabel->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter); |
| 2522 |
mouseLabel->setFrameStyle(QFrame::Panel); |
| 2523 |
mouseLabel->setFrameShadow(QFrame::Sunken); |
| 2524 |
mouseLabel->setMinimumWidth(swidth(metric," x=888 y=888 ")); |
| 2525 |
statusBar->addPermanentWidget(mouseLabel); |
| 2526 |
setStatusBar(statusBar); |
| 2527 |
|
| 2528 |
// Create toolbar |
| 2529 |
toolBar = new QToolBar(this); |
| 2530 |
toolBar->setObjectName("toolbar"); |
| 2531 |
toolBar->setAllowedAreas(Qt::TopToolBarArea|Qt::BottomToolBarArea); |
| 2532 |
addToolBar(toolBar); |
| 2533 |
|
| 2534 |
// Create mode combo box |
| 2535 |
modeCombo = new QComboBox(toolBar); |
| 2536 |
fillModeCombo(modeCombo); |
| 2537 |
connect(modeCombo, SIGNAL(activated(int)), |
| 2538 |
this, SLOT(modeComboActivated(int)) ); |
| 2539 |
connect(modeCombo, SIGNAL(activated(int)), |
| 2540 |
this, SLOT(updateActionsLater()) ); |
| 2541 |
|
| 2542 |
// Create zoom combo box |
| 2543 |
zoomCombo = new QComboBox(toolBar); |
| 2544 |
zoomCombo->setEditable(true); |
| 2545 |
zoomCombo->setInsertPolicy(QComboBox::NoInsert); |
| 2546 |
fillZoomCombo(zoomCombo); |
| 2547 |
connect(zoomCombo, SIGNAL(activated(int)), |
| 2548 |
this, SLOT(zoomComboActivated(int)) ); |
| 2549 |
connect(zoomCombo->lineEdit(), SIGNAL(editingFinished()), |
| 2550 |
this, SLOT(zoomComboEdited()) ); |
| 2551 |
|
| 2552 |
// Create page combo box |
| 2553 |
pageCombo = new QComboBox(toolBar); |
| 2554 |
pageCombo->setEditable(true); |
| 2555 |
pageCombo->setInsertPolicy(QComboBox::NoInsert); |
| 2556 |
pageCombo->setSizeAdjustPolicy(QComboBox::AdjustToContents); |
| 2557 |
pageCombo->installEventFilter(this); |
| 2558 |
connect(pageCombo, SIGNAL(activated(int)), |
| 2559 |
this, SLOT(pageComboActivated(int))); |
| 2560 |
connect(pageCombo->lineEdit(), SIGNAL(editingFinished()), |
| 2561 |
this, SLOT(pageComboEdited()) ); |
| 2562 |
|
| 2563 |
// Create sidebar |
| 2564 |
thumbnailWidget = new QDjViewThumbnails(this); |
| 2565 |
thumbnailDock = new QDockWidget(this); |
| 2566 |
thumbnailDock->setObjectName("thumbnailDock"); |
| 2567 |
thumbnailDock->setWindowTitle(tr("Thumbnails")); |
| 2568 |
thumbnailDock->setWidget(thumbnailWidget); |
| 2569 |
thumbnailDock->installEventFilter(this); |
| 2570 |
addDockWidget(Qt::LeftDockWidgetArea, thumbnailDock); |
| 2571 |
outlineWidget = new QDjViewOutline(this); |
| 2572 |
outlineDock = new QDockWidget(this); |
| 2573 |
outlineDock->setObjectName("outlineDock"); |
| 2574 |
outlineDock->setWindowTitle(tr("Outline")); |
| 2575 |
outlineDock->setWidget(outlineWidget); |
| 2576 |
outlineDock->installEventFilter(this); |
| 2577 |
addDockWidget(Qt::LeftDockWidgetArea, outlineDock); |
| 2578 |
findWidget = new QDjViewFind(this); |
| 2579 |
findDock = new QDockWidget(this); |
| 2580 |
findDock->setObjectName("findDock"); |
| 2581 |
findDock->setWindowTitle(tr("Find")); |
| 2582 |
findDock->setWidget(findWidget); |
| 2583 |
findDock->installEventFilter(this); |
| 2584 |
addDockWidget(Qt::LeftDockWidgetArea, findDock); |
| 2585 |
|
| 2586 |
// Create escape shortcut for sidebar |
| 2587 |
shortcutEscape = new QShortcut(QKeySequence("Esc"), this); |
| 2588 |
connect(shortcutEscape, SIGNAL(activated()), this, SLOT(performEscape())); |
| 2589 |
|
| 2590 |
// Create escape shortcut for activating page dialog |
| 2591 |
shortcutGoPage = new QShortcut(QKeySequence("Ctrl+G"), this); |
| 2592 |
connect(shortcutGoPage, SIGNAL(activated()), this, SLOT(performGoPage())); |
| 2593 |
|
| 2594 |
// Create MacOS shortcut for minimizing current window |
| 2595 |
#ifdef Q_OS_DARWIN |
| 2596 |
QShortcut *shortcutMinimize = new QShortcut(QKeySequence("Ctrl+M"),this); |
| 2597 |
connect(shortcutMinimize, SIGNAL(activated()), this, SLOT(showMinimized())); |
| 2598 |
#endif |
| 2599 |
|
| 2600 |
// Create misc timers |
| 2601 |
undoTimer = new QTimer(this); |
| 2602 |
undoTimer->setSingleShot(true); |
| 2603 |
connect(undoTimer,SIGNAL(timeout()), this, SLOT(saveUndoData())); |
| 2604 |
slideShowTimer = new QTimer(this); |
| 2605 |
slideShowTimer->setSingleShot(true); |
| 2606 |
connect(slideShowTimer, SIGNAL(timeout()), this, SLOT(slideShowTimeout())); |
| 2607 |
|
| 2608 |
// Actions |
| 2609 |
createActions(); |
| 2610 |
createMenus(); |
| 2611 |
createWhatsThis(); |
| 2612 |
enableContextMenu(true); |
| 2613 |
|
| 2614 |
// Remember geometry and fix viewerMode |
| 2615 |
if (mode >= STANDALONE) |
| 2616 |
if (! (prefs->windowSize.isNull())) |
| 2617 |
resize(prefs->windowSize); |
| 2618 |
if (mode >= STANDALONE) |
| 2619 |
if (prefs->windowMaximized) |
| 2620 |
setWindowState(Qt::WindowMaximized); |
| 2621 |
if (mode > STANDALONE) |
| 2622 |
setViewerMode(mode); |
| 2623 |
|
| 2624 |
// Preferences |
| 2625 |
connect(prefs, SIGNAL(updated()), this, SLOT(preferencesChanged())); |
| 2626 |
applyPreferences(); |
| 2627 |
updateActions(); |
| 2628 |
|
| 2629 |
// Options set so far have default priority |
| 2630 |
widget->reduceOptionsToPriority(QDjVuWidget::PRIORITY_DEFAULT); |
| 2631 |
} |
| 2632 |
|
| 2633 |
|
| 2634 |
void |
| 2635 |
QDjView::closeDocument() |
| 2636 |
{ |
| 2637 |
// remember recent document |
| 2638 |
QDjVuDocument *doc = document; |
| 2639 |
if (doc && viewerMode >= STANDALONE) |
| 2640 |
{ |
| 2641 |
if (documentPages.size() > 0) |
| 2642 |
addRecent(getDecoratedUrl()); |
| 2643 |
} |
| 2644 |
// clear undo data |
| 2645 |
here.clear(); |
| 2646 |
undoList.clear(); |
| 2647 |
redoList.clear(); |
| 2648 |
// kill one-shot timers |
| 2649 |
undoTimer->stop(); |
| 2650 |
textLabelTimer->stop(); |
| 2651 |
// close document |
| 2652 |
layout->setCurrentWidget(splash); |
| 2653 |
if (doc) |
| 2654 |
{ |
| 2655 |
doc->ref(); |
| 2656 |
disconnect(doc, 0, this, 0); |
| 2657 |
disconnect(doc, 0, errorDialog, 0); |
| 2658 |
printingAllowed = true; |
| 2659 |
savingAllowed = true; |
| 2660 |
} |
| 2661 |
widget->setDocument(0); |
| 2662 |
documentPages.clear(); |
| 2663 |
documentFileName.clear(); |
| 2664 |
hasNumericalPageTitle = true; |
| 2665 |
documentUrl.clear(); |
| 2666 |
documentModified = QDateTime(); |
| 2667 |
document = 0; |
| 2668 |
if (doc) |
| 2669 |
{ |
| 2670 |
emit documentClosed(doc); |
| 2671 |
doc->deref(); |
| 2672 |
} |
| 2673 |
} |
| 2674 |
|
| 2675 |
|
| 2676 |
/*! Open a document represented by a \a QDjVuDocument object. */ |
| 2677 |
|
| 2678 |
void |
| 2679 |
QDjView::open(QDjVuDocument *doc, QUrl url) |
| 2680 |
{ |
| 2681 |
closeDocument(); |
| 2682 |
document = doc; |
| 2683 |
if (url.isValid()) |
| 2684 |
documentUrl = url; |
| 2685 |
connect(doc,SIGNAL(destroyed(void)), this, SLOT(closeDocument(void))); |
| 2686 |
connect(doc,SIGNAL(docinfo(void)), this, SLOT(docinfo(void))); |
| 2687 |
widget->setDocument(document); |
| 2688 |
disconnect(document, 0, errorDialog, 0); |
| 2689 |
layout->setCurrentWidget(widget); |
| 2690 |
updateActions(); |
| 2691 |
docinfo(); |
| 2692 |
if (doc) |
| 2693 |
emit documentOpened(doc); |
| 2694 |
// process url options |
| 2695 |
if (url.isValid()) |
| 2696 |
parseDjVuCgiArguments(url); |
| 2697 |
widget->reduceOptionsToPriority(QDjVuWidget::PRIORITY_CGI); |
| 2698 |
// set focus |
| 2699 |
widget->setFocus(); |
| 2700 |
// set title |
| 2701 |
setWindowTitle(QString("%1[*] - ").arg(getShortFileName()) + tr("DjView")); |
| 2702 |
#if QT_VERSION > 0x40400 |
| 2703 |
setWindowFilePath(url.toLocalFile()); |
| 2704 |
#endif |
| 2705 |
} |
| 2706 |
|
| 2707 |
|
| 2708 |
/*! Open the djvu document stored in file \a filename. */ |
| 2709 |
|
| 2710 |
bool |
| 2711 |
QDjView::open(QString filename) |
| 2712 |
{ |
| 2713 |
closeDocument(); |
| 2714 |
QDjVuDocument *doc = new QDjVuDocument(true); |
| 2715 |
connect(doc, SIGNAL(error(QString,QString,int)), |
| 2716 |
errorDialog, SLOT(error(QString,QString,int))); |
| 2717 |
doc->setFileName(&djvuContext, filename); |
| 2718 |
if (!doc->isValid()) |
| 2719 |
{ |
| 2720 |
delete doc; |
| 2721 |
addToErrorDialog(tr("Cannot open file '%1'.").arg(filename)); |
| 2722 |
raiseErrorDialog(QMessageBox::Critical, tr("Opening DjVu file")); |
| 2723 |
return false; |
| 2724 |
} |
| 2725 |
QFileInfo fileinfo(filename); |
| 2726 |
QUrl url = QUrl::fromLocalFile(fileinfo.absoluteFilePath()); |
| 2727 |
open(doc, url); |
| 2728 |
documentFileName = filename; |
| 2729 |
documentModified = QFileInfo(filename).lastModified(); |
| 2730 |
restoreRecentDocument(url); |
| 2731 |
return true; |
| 2732 |
} |
| 2733 |
|
| 2734 |
|
| 2735 |
/* Helper class to open remote documents */ |
| 2736 |
|
| 2737 |
class QDjView::NetOpen : public QObject |
| 2738 |
{ |
| 2739 |
Q_OBJECT |
| 2740 |
private: |
| 2741 |
QDjView *q; |
| 2742 |
QDjVuNetDocument *doc; |
| 2743 |
QUrl url; |
| 2744 |
bool inNewWindow; |
| 2745 |
bool maybeInBrowser; |
| 2746 |
bool startedBrowser; |
| 2747 |
public: |
| 2748 |
~NetOpen() { |
| 2749 |
if (doc) { |
| 2750 |
doc->deref(); |
| 2751 |
if (! startedBrowser) { |
| 2752 |
q->addToErrorDialog(tr("Cannot open URL '%1'.").arg(url.toString())); |
| 2753 |
q->raiseErrorDialog(QMessageBox::Critical, tr("Opening DjVu document")); |
| 2754 |
} |
| 2755 |
} |
| 2756 |
} |
| 2757 |
NetOpen(QDjView *q, QDjVuNetDocument *d, QUrl u, bool n, bool b) |
| 2758 |
: QObject(q), |
| 2759 |
q(q), doc(d), url(u), |
| 2760 |
inNewWindow(n), maybeInBrowser(b), |
| 2761 |
startedBrowser(false) { |
| 2762 |
doc->ref(); |
| 2763 |
connect(doc, SIGNAL(docinfo()), |
| 2764 |
this, SLOT(docinfo()) ); |
| 2765 |
connect(doc, SIGNAL(gotContentType(QString,bool&)), |
| 2766 |
this, SLOT(gotContentType(QString,bool&)) ); |
| 2767 |
} |
| 2768 |
public slots: |
| 2769 |
void docinfo() { |
| 2770 |
int status = ddjvu_document_decoding_status(*doc); |
| 2771 |
if (status == DDJVU_JOB_OK) { |
| 2772 |
disconnect(doc,0,this,0); |
| 2773 |
if (inNewWindow) { |
| 2774 |
QDjView *other = q->copyWindow(); |
| 2775 |
other->open(url); |
| 2776 |
other->show(); |
| 2777 |
} else { |
| 2778 |
q->open(doc,url); |
| 2779 |
} |
| 2780 |
doc = 0; |
| 2781 |
} |
| 2782 |
if (status >= DDJVU_JOB_OK) |
| 2783 |
deleteLater(); |
| 2784 |
} |
| 2785 |
void gotContentType(QString type, bool &okay) { |
| 2786 |
QRegExp re("image/(x[.]|vnd[.-]|)(djvu|dejavu|iw44)(;.*)?"); |
| 2787 |
okay = re.exactMatch(type); |
| 2788 |
if (maybeInBrowser && !okay) { |
| 2789 |
startedBrowser = q->startBrowser(url); |
| 2790 |
if (startedBrowser) { |
| 2791 |
disconnect(doc,0,this,0); |
| 2792 |
deleteLater(); |
| 2793 |
} else { |
| 2794 |
QString msg = tr("Cannot spawn a browser for url '%1'").arg(url.toString()); |
| 2795 |
qWarning("%s",(const char*)msg.toLocal8Bit()); |
| 2796 |
} |
| 2797 |
} |
| 2798 |
} |
| 2799 |
}; |
| 2800 |
|
| 2801 |
|
| 2802 |
/*! Open the djvu document available at url \a url. */ |
| 2803 |
|
| 2804 |
bool |
| 2805 |
QDjView::open(QUrl url, bool inNewWindow, bool maybeInBrowser) |
| 2806 |
{ |
| 2807 |
QDjVuNetDocument *doc = new QDjVuNetDocument(true); |
| 2808 |
connect(doc, SIGNAL(error(QString,QString,int)), |
| 2809 |
errorDialog, SLOT(error(QString,QString,int))); |
| 2810 |
connect(doc, SIGNAL(authRequired(QString,QString&,QString&)), |
| 2811 |
this, SLOT(authRequired(QString,QString&,QString&)) ); |
| 2812 |
connect(doc, SIGNAL(sslWhiteList(QString,bool&)), |
| 2813 |
this, SLOT(sslWhiteList(QString,bool&)) ); |
| 2814 |
QUrl docurl = removeDjVuCgiArguments(url); |
| 2815 |
doc->setUrl(&djvuContext, docurl); |
| 2816 |
if (! (url.isValid() && doc->isValid())) |
| 2817 |
{ |
| 2818 |
delete doc; |
| 2819 |
addToErrorDialog(tr("Cannot open URL '%1'.").arg(url.toString())); |
| 2820 |
raiseErrorDialog(QMessageBox::Critical, tr("Opening DjVu document")); |
| 2821 |
return false; |
| 2822 |
} |
| 2823 |
new NetOpen(this, doc, url, inNewWindow, maybeInBrowser); |
| 2824 |
return true; |
| 2825 |
} |
| 2826 |
|
| 2827 |
|
| 2828 |
void |
| 2829 |
QDjView::sslWhiteList(QString why, bool &okay) |
| 2830 |
{ |
| 2831 |
#if QT_VERSION >= 0x50000 |
| 2832 |
QString ewhy = why.toHtmlEscaped(); |
| 2833 |
#else |
| 2834 |
QString ewhy = Qt::escape(why); |
| 2835 |
#endif |
| 2836 |
if (QMessageBox::question(this, |
| 2837 |
tr("Certificate validation error - DjView", "dialog caption"), |
| 2838 |
tr("<html> %1 Do you want to continue anyway? </html>").arg(ewhy), |
| 2839 |
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) |
| 2840 |
okay = true; |
| 2841 |
else |
| 2842 |
closeDocument(); |
| 2843 |
} |
| 2844 |
|
| 2845 |
void |
| 2846 |
QDjView::authRequired(QString why, QString &user, QString &pass) |
| 2847 |
{ |
| 2848 |
QDjViewAuthDialog *dialog = new QDjViewAuthDialog(this); |
| 2849 |
dialog->setInfo(why); |
| 2850 |
dialog->setUser(user); |
| 2851 |
dialog->setPass(pass); |
| 2852 |
int result = dialog->exec(); |
| 2853 |
user = dialog->user(); |
| 2854 |
pass = dialog->pass(); |
| 2855 |
if (result != QDialog::Accepted) |
| 2856 |
closeDocument(); |
| 2857 |
} |
| 2858 |
|
| 2859 |
|
| 2860 |
/*! Reload the document afresh. */ |
| 2861 |
|
| 2862 |
void |
| 2863 |
QDjView::reloadDocument() |
| 2864 |
{ |
| 2865 |
QDjVuDocument *doc = document; |
| 2866 |
QUrl url = getDecoratedUrl(); |
| 2867 |
if (doc && viewerMode >= STANDALONE && url.isValid()) |
| 2868 |
{ |
| 2869 |
closeDocument(); |
| 2870 |
ddjvu_cache_clear(djvuContext); |
| 2871 |
// Opening files more efficiently |
| 2872 |
QFileInfo file = QFileInfo(url.toLocalFile()); |
| 2873 |
if (file.exists()) |
| 2874 |
{ |
| 2875 |
open(file.absoluteFilePath()); |
| 2876 |
parseDjVuCgiArguments(url); |
| 2877 |
return; |
| 2878 |
} |
| 2879 |
// Opening the url could do it all in fact. |
| 2880 |
open(url); |
| 2881 |
} |
| 2882 |
} |
| 2883 |
|
| 2884 |
|
| 2885 |
void |
| 2886 |
QDjView::maybeReloadDocument() |
| 2887 |
{ |
| 2888 |
QDjVuDocument *doc = document; |
| 2889 |
if (doc && !documentModified.isNull() && !documentFileName.isNull()) |
| 2890 |
{ |
| 2891 |
QFileInfo info(documentFileName); |
| 2892 |
if (info.exists() && info.lastModified() > documentModified) |
| 2893 |
QTimer::singleShot(0, this, SLOT(reloadDocument())); |
| 2894 |
} |
| 2895 |
} |
| 2896 |
|
| 2897 |
|
| 2898 |
/*! Jump to the page numbered \a pageno. */ |
| 2899 |
|
| 2900 |
void |
| 2901 |
QDjView::goToPage(int pageno) |
| 2902 |
{ |
| 2903 |
int pagenum = documentPages.size(); |
| 2904 |
if (!pagenum || !document) |
| 2905 |
{ |
| 2906 |
pendingPage = QString("$%1").arg(pageno+1); |
| 2907 |
} |
| 2908 |
else |
| 2909 |
{ |
| 2910 |
if (pageno>=0 && pageno<pagenum) |
| 2911 |
{ |
| 2912 |
widget->setPage(pageno); |
| 2913 |
} |
| 2914 |
else |
| 2915 |
{ |
| 2916 |
QString msg = tr("Cannot find page numbered: %1").arg(pageno+1); |
| 2917 |
qWarning("%s",(const char*)msg.toLocal8Bit()); |
| 2918 |
} |
| 2919 |
updateActionsLater(); |
| 2920 |
} |
| 2921 |
} |
| 2922 |
|
| 2923 |
|
| 2924 |
/*! Jump to the page named \a name. |
| 2925 |
Names starting with the "#" character are interpreted |
| 2926 |
using the same rules as hyperlinks. In particular, |
| 2927 |
names of the form \a "#+n" and \a "#-n" express |
| 2928 |
relative displacement from the current page |
| 2929 |
or the page specified by argument \a from. */ |
| 2930 |
|
| 2931 |
void |
| 2932 |
QDjView::goToPage(QString name, int from) |
| 2933 |
{ |
| 2934 |
int pagenum = documentPages.size(); |
| 2935 |
if (!pagenum || !document) |
| 2936 |
{ |
| 2937 |
pendingPage = name; |
| 2938 |
} |
| 2939 |
else |
| 2940 |
{ |
| 2941 |
int pageno = pageNumber(name, from); |
| 2942 |
if (pageno >= 0 && pageno < pagenum) |
| 2943 |
{ |
| 2944 |
widget->setPage(pageno); |
| 2945 |
} |
| 2946 |
else |
| 2947 |
{ |
| 2948 |
QString msg = tr("Cannot find page named: %1").arg(name); |
| 2949 |
qWarning("%s",(const char*)msg.toLocal8Bit()); |
| 2950 |
} |
| 2951 |
updateActionsLater(); |
| 2952 |
} |
| 2953 |
} |
| 2954 |
|
| 2955 |
|
| 2956 |
/* Jump to the page named \a pagename |
| 2957 |
and tries to position the specified point in |
| 2958 |
the center of the window. Arguments \a px and \a py |
| 2959 |
must be in range 0 to 1 indicating a fraction |
| 2960 |
of the page width or height. */ |
| 2961 |
|
| 2962 |
void |
| 2963 |
QDjView::goToPosition(QString name, double px, double py) |
| 2964 |
{ |
| 2965 |
int pagenum = documentPages.size(); |
| 2966 |
if (!pagenum || !document) |
| 2967 |
{ |
| 2968 |
pendingPosition.clear(); |
| 2969 |
pendingPosition << px << py; |
| 2970 |
if (! name.isEmpty()) |
| 2971 |
pendingPage = name; |
| 2972 |
} |
| 2973 |
else |
| 2974 |
{ |
| 2975 |
int pageno = (name.isEmpty()) ? widget->page() : pageNumber(name); |
| 2976 |
if (pageno < 0 || pageno >= pagenum) |
| 2977 |
{ |
| 2978 |
QString msg = tr("Cannot find page named: %1").arg(name); |
| 2979 |
qWarning("%s",(const char*)msg.toLocal8Bit()); |
| 2980 |
} |
| 2981 |
else |
| 2982 |
{ |
| 2983 |
QDjVuWidget::Position pos; |
| 2984 |
pos.pageNo = pageno; |
| 2985 |
pos.inPage = false; |
| 2986 |
pos.posView = QPoint(0,0); |
| 2987 |
pos.posPage = QPoint(0,0); |
| 2988 |
pos.hAnchor = qBound(0, (int)(px*100), 100); |
| 2989 |
pos.vAnchor = qBound(0, (int)(py*100), 100); |
| 2990 |
widget->setPosition(pos, widget->rect().center()); |
| 2991 |
} |
| 2992 |
updateActionsLater(); |
| 2993 |
} |
| 2994 |
} |
| 2995 |
|
| 2996 |
|
| 2997 |
|
| 2998 |
/*! Add a message to the error dialog. */ |
| 2999 |
|
| 3000 |
void |
| 3001 |
QDjView::addToErrorDialog(QString message) |
| 3002 |
{ |
| 3003 |
errorDialog->error(message, __FILE__, __LINE__); |
| 3004 |
} |
| 3005 |
|
| 3006 |
|
| 3007 |
/*! Show the error dialog. */ |
| 3008 |
|
| 3009 |
void |
| 3010 |
QDjView::raiseErrorDialog(QMessageBox::Icon icon, QString caption) |
| 3011 |
{ |
| 3012 |
errorDialog->prepare(icon, caption); |
| 3013 |
errorDialog->show(); |
| 3014 |
errorDialog->raise(); |
| 3015 |
errorDialog->activateWindow(); |
| 3016 |
} |
| 3017 |
|
| 3018 |
|
| 3019 |
/*! Show the error dialog and wait until the user clicks "OK". */ |
| 3020 |
|
| 3021 |
int |
| 3022 |
QDjView::execErrorDialog(QMessageBox::Icon icon, QString caption) |
| 3023 |
{ |
| 3024 |
errorDialog->prepare(icon, caption); |
| 3025 |
return errorDialog->exec(); |
| 3026 |
} |
| 3027 |
|
| 3028 |
|
| 3029 |
/*! Set the content of the page box in the status bar. */ |
| 3030 |
|
| 3031 |
void |
| 3032 |
QDjView::setPageLabelText(QString s) |
| 3033 |
{ |
| 3034 |
QLabel *m = pageLabel; |
| 3035 |
m->setText(s); |
| 3036 |
m->setMinimumWidth(qMax(m->minimumWidth(), m->sizeHint().width())); |
| 3037 |
} |
| 3038 |
|
| 3039 |
|
| 3040 |
/*! Set the content of the mouse box in the status bar. */ |
| 3041 |
|
| 3042 |
void |
| 3043 |
QDjView::setMouseLabelText(QString s) |
| 3044 |
{ |
| 3045 |
QLabel *m = mouseLabel; |
| 3046 |
m->setText(s); |
| 3047 |
m->setMinimumWidth(qMax(m->minimumWidth(), m->sizeHint().width())); |
| 3048 |
} |
| 3049 |
|
| 3050 |
|
| 3051 |
/*! Display transient message in the status bar. |
| 3052 |
This also emits signal \a pluginStatusMessage |
| 3053 |
to mirror the message in the browser status bar. */ |
| 3054 |
|
| 3055 |
void |
| 3056 |
QDjView::statusMessage(QString message) |
| 3057 |
{ |
| 3058 |
if (message.isEmpty()) |
| 3059 |
statusBar->clearMessage(); |
| 3060 |
else |
| 3061 |
statusBar->showMessage(message); |
| 3062 |
emit pluginStatusMessage(message); |
| 3063 |
} |
| 3064 |
|
| 3065 |
|
| 3066 |
/*! Returns a bitmask of the visible sidebar tabs. */ |
| 3067 |
|
| 3068 |
int |
| 3069 |
QDjView::visibleSideBarTabs() |
| 3070 |
{ |
| 3071 |
int tabs = 0; |
| 3072 |
if (! thumbnailDock->isHidden()) |
| 3073 |
tabs |= 1; |
| 3074 |
if (! outlineDock->isHidden()) |
| 3075 |
tabs |= 2; |
| 3076 |
if (! findDock->isHidden()) |
| 3077 |
tabs |= 4; |
| 3078 |
return tabs; |
| 3079 |
} |
| 3080 |
|
| 3081 |
|
| 3082 |
/*! Returns a bitmask of the hidden sidebar tabs. */ |
| 3083 |
|
| 3084 |
int |
| 3085 |
QDjView::hiddenSideBarTabs() |
| 3086 |
{ |
| 3087 |
int tabs = 0; |
| 3088 |
if (thumbnailDock->isHidden()) |
| 3089 |
tabs |= 1; |
| 3090 |
if (outlineDock->isHidden()) |
| 3091 |
tabs |= 2; |
| 3092 |
if (findDock->isHidden()) |
| 3093 |
tabs |= 4; |
| 3094 |
return tabs; |
| 3095 |
} |
| 3096 |
|
| 3097 |
|
| 3098 |
/*! Change the position and the visibility of |
| 3099 |
the sidebars specified by bitmask \a tabs. */ |
| 3100 |
|
| 3101 |
bool |
| 3102 |
QDjView::showSideBar(Qt::DockWidgetAreas areas, int tabs) |
| 3103 |
{ |
| 3104 |
QList<QDockWidget*> allDocks; |
| 3105 |
allDocks << thumbnailDock << outlineDock << findDock; |
| 3106 |
// find first tab in desired area |
| 3107 |
QDockWidget *first = 0; |
| 3108 |
foreach(QDockWidget *w, allDocks) |
| 3109 |
if (!first && !w->isHidden() && !w->isFloating()) |
| 3110 |
if (dockWidgetArea(w) & areas) |
| 3111 |
first = w; |
| 3112 |
// find relevant docks |
| 3113 |
QList<QDockWidget*> docks; |
| 3114 |
if (tabs & 1) |
| 3115 |
docks << thumbnailDock; |
| 3116 |
if (tabs & 2) |
| 3117 |
docks << outlineDock; |
| 3118 |
if (tabs & 4) |
| 3119 |
docks << findDock; |
| 3120 |
// hide all |
| 3121 |
foreach(QDockWidget *w, docks) |
| 3122 |
w->hide(); |
| 3123 |
if (areas) |
| 3124 |
{ |
| 3125 |
Qt::DockWidgetArea area = Qt::LeftDockWidgetArea; |
| 3126 |
if (areas & Qt::LeftDockWidgetArea) |
| 3127 |
area = Qt::LeftDockWidgetArea; |
| 3128 |
else if (areas & Qt::RightDockWidgetArea) |
| 3129 |
area = Qt::RightDockWidgetArea; |
| 3130 |
else if (areas & Qt::TopDockWidgetArea) |
| 3131 |
area = Qt::TopDockWidgetArea; |
| 3132 |
else if (areas & Qt::BottomDockWidgetArea) |
| 3133 |
area = Qt::BottomDockWidgetArea; |
| 3134 |
foreach(QDockWidget *w, docks) |
| 3135 |
{ |
| 3136 |
w->show(); |
| 3137 |
if (w->isFloating()) |
| 3138 |
w->setFloating(false); |
| 3139 |
if (! (areas & dockWidgetArea(w))) |
| 3140 |
{ |
| 3141 |
removeDockWidget(w); |
| 3142 |
addDockWidget(area, w); |
| 3143 |
if (first) |
| 3144 |
tabifyDockWidget(first, w); |
| 3145 |
else |
| 3146 |
first = w; |
| 3147 |
} |
| 3148 |
w->show(); |
| 3149 |
w->raise(); |
| 3150 |
} |
| 3151 |
} |
| 3152 |
// Okay |
| 3153 |
return true; |
| 3154 |
} |
| 3155 |
|
| 3156 |
|
| 3157 |
/*! Change the position and composition of the sidebar. |
| 3158 |
String \a args contains comma separated keywords: |
| 3159 |
\a left, \a right, \a top, \a bottom, \a yes, or \a no, |
| 3160 |
\a outline, \a bookmarks, \a thumbnails, \a search, etc. |
| 3161 |
Error messages are added to string list \a errors. */ |
| 3162 |
|
| 3163 |
bool |
| 3164 |
QDjView::showSideBar(QString args, QStringList &errors) |
| 3165 |
{ |
| 3166 |
bool yes = true; |
| 3167 |
bool ret = true; |
| 3168 |
int tabs = 0; |
| 3169 |
Qt::DockWidgetAreas areas = zero(Qt::DockWidgetAreas); |
| 3170 |
QString arg; |
| 3171 |
foreach(arg, args.split(",")) |
| 3172 |
if (!args.isEmpty()) |
| 3173 |
{ |
| 3174 |
arg = arg.toLower(); |
| 3175 |
if (arg == "no" || arg == "false") |
| 3176 |
yes = false; |
| 3177 |
else if (arg == "left") |
| 3178 |
areas |= Qt::LeftDockWidgetArea; |
| 3179 |
else if (arg == "right") |
| 3180 |
areas |= Qt::RightDockWidgetArea; |
| 3181 |
else if (arg == "top") |
| 3182 |
areas |= Qt::TopDockWidgetArea; |
| 3183 |
else if (arg == "bottom") |
| 3184 |
areas |= Qt::BottomDockWidgetArea; |
| 3185 |
else if (arg == "thumbnails" || arg == "thumbnail") |
| 3186 |
tabs |= 1; |
| 3187 |
else if (arg == "outline" || arg == "bookmarks") |
| 3188 |
tabs |= 2; |
| 3189 |
else if (arg == "search" || arg == "find") |
| 3190 |
tabs |= 4; |
| 3191 |
else if (arg != "yes" && arg != "true") { |
| 3192 |
errors << tr("Unrecognized sidebar options '%1'.").arg(arg); |
| 3193 |
ret = false; |
| 3194 |
} |
| 3195 |
} |
| 3196 |
if (!tabs) |
| 3197 |
tabs = ~0; |
| 3198 |
if (yes && !areas) |
| 3199 |
areas = Qt::AllDockWidgetAreas; |
| 3200 |
if (showSideBar(areas, tabs)) |
| 3201 |
return ret; |
| 3202 |
return false; |
| 3203 |
} |
| 3204 |
|
| 3205 |
|
| 3206 |
/*! Overloaded version of \a showSideBar for convenience. |
| 3207 |
This version makes great efforts to show docks with |
| 3208 |
the exact layout they had before being hidden. */ |
| 3209 |
|
| 3210 |
bool |
| 3211 |
QDjView::showSideBar(bool show) |
| 3212 |
{ |
| 3213 |
if (! show) |
| 3214 |
{ |
| 3215 |
// save everything about dock geometry |
| 3216 |
savedDockState = saveState(); |
| 3217 |
} |
| 3218 |
else if (savedDockState.size() > 0) |
| 3219 |
{ |
| 3220 |
// hack toolbar name to avoid restoring its state |
| 3221 |
QString savedToolBarName = toolBar->objectName(); |
| 3222 |
toolBar->setObjectName(QString()); |
| 3223 |
restoreState(savedDockState); |
| 3224 |
toolBar->setObjectName(savedToolBarName); |
| 3225 |
savedDockState.clear(); |
| 3226 |
} |
| 3227 |
// set visibility |
| 3228 |
thumbnailDock->setVisible(show); |
| 3229 |
outlineDock->setVisible(show); |
| 3230 |
findDock->setVisible(show); |
| 3231 |
if (! show) |
| 3232 |
widget->setFocus(Qt::OtherFocusReason); |
| 3233 |
return true; |
| 3234 |
} |
| 3235 |
|
| 3236 |
|
| 3237 |
/*! Pops up find sidebar */ |
| 3238 |
void |
| 3239 |
QDjView::showFind() |
| 3240 |
{ |
| 3241 |
if (! actionViewSideBar->isChecked()) |
| 3242 |
actionViewSideBar->activate(QAction::Trigger); |
| 3243 |
findDock->show(); |
| 3244 |
findDock->raise(); |
| 3245 |
findWidget->selectAll(); |
| 3246 |
findWidget->takeFocus(Qt::ShortcutFocusReason); |
| 3247 |
} |
| 3248 |
|
| 3249 |
|
| 3250 |
bool |
| 3251 |
QDjView::warnAboutPrintingRestrictions() |
| 3252 |
{ |
| 3253 |
if (prefs->restrictOverride && !printingAllowed) |
| 3254 |
if (QMessageBox::warning(this, |
| 3255 |
tr("Print - DjView", "dialog caption"), |
| 3256 |
tr("<html> This file was served with " |
| 3257 |
"printing restrictions. " |
| 3258 |
"Do you want to print it anyway?</html>"), |
| 3259 |
QMessageBox::Yes | QMessageBox::Cancel, |
| 3260 |
QMessageBox::Cancel) != QMessageBox::Yes ) |
| 3261 |
return false; |
| 3262 |
return true; |
| 3263 |
} |
| 3264 |
|
| 3265 |
|
| 3266 |
bool |
| 3267 |
QDjView::warnAboutSavingRestrictions() |
| 3268 |
{ |
| 3269 |
if (prefs->restrictOverride && !savingAllowed) |
| 3270 |
if (QMessageBox::warning(this, |
| 3271 |
tr("Save - DjView", "dialog caption"), |
| 3272 |
tr("<html> This file was served with " |
| 3273 |
"saving restrictions. " |
| 3274 |
"Do you want to save it anyway?</html>"), |
| 3275 |
QMessageBox::Yes | QMessageBox::Cancel, |
| 3276 |
QMessageBox::Cancel) != QMessageBox::Yes ) |
| 3277 |
return false; |
| 3278 |
return true; |
| 3279 |
} |
| 3280 |
|
| 3281 |
|
| 3282 |
/*! Pops up a print dialog */ |
| 3283 |
void |
| 3284 |
QDjView::print() |
| 3285 |
{ |
| 3286 |
QDjViewPrintDialog *pd = printDialog; |
| 3287 |
if (! pd) |
| 3288 |
{ |
| 3289 |
printDialog = pd = new QDjViewPrintDialog(this); |
| 3290 |
pd->setAttribute(Qt::WA_DeleteOnClose); |
| 3291 |
pd->setWindowTitle(tr("Print - DjView", "dialog caption")); |
| 3292 |
} |
| 3293 |
if (warnAboutPrintingRestrictions()) |
| 3294 |
{ |
| 3295 |
pd->show(); |
| 3296 |
pd->raise(); |
| 3297 |
} |
| 3298 |
} |
| 3299 |
|
| 3300 |
|
| 3301 |
|
| 3302 |
/*! Pops up a save dialog */ |
| 3303 |
void |
| 3304 |
QDjView::saveAs() |
| 3305 |
{ |
| 3306 |
QDjViewSaveDialog *sd = saveDialog; |
| 3307 |
if (! sd) |
| 3308 |
{ |
| 3309 |
saveDialog = sd = new QDjViewSaveDialog(this); |
| 3310 |
sd->setAttribute(Qt::WA_DeleteOnClose); |
| 3311 |
sd->setWindowTitle(tr("Save - DjView", "dialog caption")); |
| 3312 |
} |
| 3313 |
if (warnAboutSavingRestrictions()) |
| 3314 |
{ |
| 3315 |
sd->show(); |
| 3316 |
sd->raise(); |
| 3317 |
} |
| 3318 |
} |
| 3319 |
|
| 3320 |
|
| 3321 |
/*! Pops up export dialog */ |
| 3322 |
void |
| 3323 |
QDjView::exportAs() |
| 3324 |
{ |
| 3325 |
QDjViewExportDialog *sd = exportDialog; |
| 3326 |
if (! sd) |
| 3327 |
{ |
| 3328 |
exportDialog = sd = new QDjViewExportDialog(this); |
| 3329 |
sd->setAttribute(Qt::WA_DeleteOnClose); |
| 3330 |
sd->setWindowTitle(tr("Export - DjView", "dialog caption")); |
| 3331 |
} |
| 3332 |
if (warnAboutSavingRestrictions()) |
| 3333 |
{ |
| 3334 |
sd->show(); |
| 3335 |
sd->raise(); |
| 3336 |
} |
| 3337 |
} |
| 3338 |
|
| 3339 |
|
| 3340 |
|
| 3341 |
/*! Start searching string \a find. |
| 3342 |
String might be terminated with a slash |
| 3343 |
followed by letters "w" (words only), |
| 3344 |
"W" (not words only), "c" (case sensitive), |
| 3345 |
or "C" (case insentitive). */ |
| 3346 |
|
| 3347 |
void |
| 3348 |
QDjView::find(QString find) |
| 3349 |
{ |
| 3350 |
if (! find.isEmpty()) |
| 3351 |
{ |
| 3352 |
QRegExp options("/[wWcCrR]*$"); |
| 3353 |
if (reIndex(find, options, 0) >= 0) |
| 3354 |
{ |
| 3355 |
for (int i=find.lastIndexOf("/"); i<find.size(); i++) |
| 3356 |
{ |
| 3357 |
int c = find[i].toLatin1(); |
| 3358 |
if (c == 'c') |
| 3359 |
findWidget->setCaseSensitive(true); |
| 3360 |
else if (c == 'C') |
| 3361 |
findWidget->setCaseSensitive(false); |
| 3362 |
else if (c == 'w') |
| 3363 |
findWidget->setWordOnly(true); |
| 3364 |
else if (c == 'W') |
| 3365 |
findWidget->setWordOnly(false); |
| 3366 |
else if (c == 'r') |
| 3367 |
findWidget->setRegExpMode(true); |
| 3368 |
else if (c == 'R') |
| 3369 |
findWidget->setRegExpMode(false); |
| 3370 |
} |
| 3371 |
find = reReplace(find, options, ""); |
| 3372 |
} |
| 3373 |
findWidget->setText(find); |
| 3374 |
} |
| 3375 |
findWidget->findNext(); |
| 3376 |
} |
| 3377 |
|
| 3378 |
|
| 3379 |
|
| 3380 |
|
| 3381 |
|
| 3382 |
|
| 3383 |
// ----------------------------------- |
| 3384 |
// UTILITIES |
| 3385 |
|
| 3386 |
|
| 3387 |
/*! \fn QDjView::getDjVuWidget() |
| 3388 |
Return the \a QDjVuWidget object managed by this window. */ |
| 3389 |
|
| 3390 |
/*! \fn QDjView::getErrorDialog() |
| 3391 |
Return the error dialog for this window. */ |
| 3392 |
|
| 3393 |
/*! \fn QDjView::getDocument() |
| 3394 |
Return the currently displayed \a QDjVuDocument. */ |
| 3395 |
|
| 3396 |
/*! \fn QDjView::getDocumentFileName() |
| 3397 |
Return the filename of the currently displayed \a QDjVuDocument. */ |
| 3398 |
|
| 3399 |
/*! \fn QDjView::getDocumentUrl() |
| 3400 |
Return the url of the currently displayed \a QDjVuDocument. */ |
| 3401 |
|
| 3402 |
/*! \fn QDjView::getViewerMode |
| 3403 |
Return the current viewer mode. */ |
| 3404 |
|
| 3405 |
|
| 3406 |
|
| 3407 |
/*! Return an url that encodes the current view and page. */ |
| 3408 |
|
| 3409 |
QUrl |
| 3410 |
QDjView::getDecoratedUrl() |
| 3411 |
{ |
| 3412 |
QUrl url = removeDjVuCgiArguments(documentUrl); |
| 3413 |
QPoint center = widget->rect().center(); |
| 3414 |
QDjVuWidget::Position pos = widget->positionWithClosestAnchor(center); |
| 3415 |
int pageNo = pos.pageNo; |
| 3416 |
if (url.isValid() && pageNo>=0 && pageNo<pageNum()) |
| 3417 |
{ |
| 3418 |
QueryItems items = urlQueryItems(url); |
| 3419 |
addQueryItem(items, "djvuopts", QString()); |
| 3420 |
QList<ddjvu_fileinfo_t> &dp = documentPages; |
| 3421 |
QString pagestr = QString("%1").arg(pageNo+1); |
| 3422 |
if (hasNumericalPageTitle && pageNo<documentPages.size()) |
| 3423 |
// Only use page ids when confusions are possible. |
| 3424 |
// Always using page ids triggers bugs in the celartem plugin :-( |
| 3425 |
pagestr = QString::fromUtf8(dp[pageNo].id); |
| 3426 |
addQueryItem(items, "page", pagestr); |
| 3427 |
int rotation = widget->rotation(); |
| 3428 |
if (rotation) |
| 3429 |
addQueryItem(items, "rotate", QString::number(90 * rotation)); |
| 3430 |
QString zoom = getArgument("zoom"); |
| 3431 |
if (zoom.isEmpty()) |
| 3432 |
zoom = QString::number(widget->zoomFactor()); |
| 3433 |
addQueryItem(items, "zoom", zoom); |
| 3434 |
double ha = pos.hAnchor / 100.0; |
| 3435 |
double va = pos.vAnchor / 100.0; |
| 3436 |
addQueryItem(items, "showposition", QString("%1,%2").arg(ha).arg(va)); |
| 3437 |
urlSetQueryItems(url, items); |
| 3438 |
} |
| 3439 |
return url; |
| 3440 |
} |
| 3441 |
|
| 3442 |
|
| 3443 |
/*! Return the base name of the current file. */ |
| 3444 |
|
| 3445 |
QString |
| 3446 |
QDjView::getShortFileName() |
| 3447 |
{ |
| 3448 |
if (! documentFileName.isEmpty()) |
| 3449 |
return QFileInfo(documentFileName).fileName(); |
| 3450 |
else if (! documentUrl.isEmpty()) |
| 3451 |
return documentUrl.path().section('/', -1); |
| 3452 |
return QString(); |
| 3453 |
} |
| 3454 |
|
| 3455 |
|
| 3456 |
/*! Return the number of pages in the document. |
| 3457 |
This function returns zero when called before |
| 3458 |
fully decoding the document header. */ |
| 3459 |
|
| 3460 |
int |
| 3461 |
QDjView::pageNum(void) |
| 3462 |
{ |
| 3463 |
return documentPages.size(); |
| 3464 |
} |
| 3465 |
|
| 3466 |
|
| 3467 |
/*! Return a name for page \a pageno. */ |
| 3468 |
|
| 3469 |
QString |
| 3470 |
QDjView::pageName(int pageno, bool titleonly) |
| 3471 |
{ |
| 3472 |
// obtain page title |
| 3473 |
if (pageno>=0 && pageno<documentPages.size()) |
| 3474 |
if ( documentPages[pageno].title ) |
| 3475 |
return QString::fromUtf8(documentPages[pageno].title); |
| 3476 |
if (titleonly) |
| 3477 |
return QString(); |
| 3478 |
// generate a name from the page number |
| 3479 |
//// if (hasNumericalPageTitle) |
| 3480 |
//// return QString("$%1").arg(pageno + 1); |
| 3481 |
return QString("%1").arg(pageno + 1); |
| 3482 |
} |
| 3483 |
|
| 3484 |
|
| 3485 |
/*! Return a page number for the page named \a name. |
| 3486 |
It first searches a page whose ID matches X. |
| 3487 |
Otherwise, if X has the form +N or -N where N is a number, |
| 3488 |
this indicates a displacement relative to the current page. |
| 3489 |
Otherwise, it searches a page with TITLE X starting |
| 3490 |
from the current page and wrapping around. |
| 3491 |
Otherwise, if X is numerical and in range, this is the page number. |
| 3492 |
Otherwise, it searches a page whose NAME matches X. |
| 3493 |
*/ |
| 3494 |
|
| 3495 |
int |
| 3496 |
QDjView::pageNumber(QString name, int from) |
| 3497 |
{ |
| 3498 |
int pagenum = documentPages.size(); |
| 3499 |
if (pagenum <= 0) |
| 3500 |
return -1; |
| 3501 |
// First search an exact page id match |
| 3502 |
QByteArray utf8Name = name.toUtf8(); |
| 3503 |
for (int i=0; i<pagenum; i++) |
| 3504 |
if (documentPages[i].id && |
| 3505 |
!strcmp(utf8Name, documentPages[i].id)) |
| 3506 |
return i; |
| 3507 |
// Then interpret the syntaxes +n, -n. |
| 3508 |
// Also recognizes $n as an ordinal page number (obsolete) |
| 3509 |
if (from < 0) |
| 3510 |
from = widget->page(); |
| 3511 |
if (from < pagenum && reIndex(name, QRegExp("^[-+$]\\d+$"), 0) >= 0 ) |
| 3512 |
{ |
| 3513 |
int num = name.mid(1).toInt(); |
| 3514 |
if (name[0]=='+') |
| 3515 |
num = from + 1 + num; |
| 3516 |
else if (name[0]=='-') |
| 3517 |
num = from + 1 - num; |
| 3518 |
return qBound(1, num, pagenum) - 1; |
| 3519 |
} |
| 3520 |
// Then search a matching page title starting |
| 3521 |
// from the current page and wrapping around |
| 3522 |
for (int i=from; i<pagenum; i++) |
| 3523 |
if (documentPages[i].title && |
| 3524 |
! strcmp(utf8Name, documentPages[i].title)) |
| 3525 |
return i; |
| 3526 |
for (int i=0; i<from; i++) |
| 3527 |
if (documentPages[i].title && |
| 3528 |
! strcmp(utf8Name, documentPages[i].title)) |
| 3529 |
return i; |
| 3530 |
// Then process a number in range [1..pagenum] |
| 3531 |
if (reIndex(name, QRegExp("^\\d+$"), 0) >= 0) |
| 3532 |
return qBound(1, name.toInt(), pagenum) - 1; |
| 3533 |
// Otherwise search page names in the unlikely |
| 3534 |
// case they are different from the page ids |
| 3535 |
for (int i=0; i<pagenum; i++) |
| 3536 |
if (documentPages[i].name && |
| 3537 |
!strcmp(utf8Name, documentPages[i].name)) |
| 3538 |
return i; |
| 3539 |
// Compatibility with unknown viewers: |
| 3540 |
// If name contains space, remove all spaces, and try again |
| 3541 |
if (name.contains(" ")) |
| 3542 |
return pageNumber(name.replace(" ", "")); |
| 3543 |
// Give up |
| 3544 |
return -1; |
| 3545 |
} |
| 3546 |
|
| 3547 |
|
| 3548 |
/*! Create another main window with the same |
| 3549 |
contents, zoom and position as the current one. */ |
| 3550 |
|
| 3551 |
QDjView* |
| 3552 |
QDjView::copyWindow(bool openDocument) |
| 3553 |
{ |
| 3554 |
// update preferences |
| 3555 |
updatePreferences(); |
| 3556 |
// create new window |
| 3557 |
QDjView *other = new QDjView(djvuContext, STANDALONE); |
| 3558 |
QDjVuWidget *otherWidget = other->widget; |
| 3559 |
other->setAttribute(Qt::WA_DeleteOnClose); |
| 3560 |
// copy window geometry |
| 3561 |
if (! (windowState() & unusualWindowStates)) |
| 3562 |
{ |
| 3563 |
other->resize( size() ); |
| 3564 |
other->toolBar->setVisible(!toolBar->isHidden()); |
| 3565 |
other->statusBar->setVisible(!statusBar->isHidden()); |
| 3566 |
other->restoreState(saveState()); |
| 3567 |
} |
| 3568 |
// copy essential properties |
| 3569 |
otherWidget->setDisplayMode( widget->displayMode() ); |
| 3570 |
otherWidget->setContinuous( widget->continuous() ); |
| 3571 |
otherWidget->setSideBySide( widget->sideBySide() ); |
| 3572 |
otherWidget->setCoverPage( widget->coverPage() ); |
| 3573 |
otherWidget->setRotation( widget->rotation() ); |
| 3574 |
otherWidget->setZoom( widget->zoom() ); |
| 3575 |
// copy document |
| 3576 |
if (document && openDocument) |
| 3577 |
{ |
| 3578 |
other->open(document); |
| 3579 |
other->documentFileName = documentFileName; |
| 3580 |
other->documentUrl = documentUrl; |
| 3581 |
// copy position |
| 3582 |
bool saved = otherWidget->animationEnabled(); |
| 3583 |
otherWidget->enableAnimation(false); |
| 3584 |
otherWidget->setPosition( widget->position() ); |
| 3585 |
otherWidget->enableAnimation(saved); |
| 3586 |
} |
| 3587 |
return other; |
| 3588 |
} |
| 3589 |
|
| 3590 |
|
| 3591 |
/*! Save \a text info the specified file. |
| 3592 |
When argument \a filename is omitted, |
| 3593 |
a file dialog is presented to the user. */ |
| 3594 |
|
| 3595 |
bool |
| 3596 |
QDjView::saveTextFile(QString text, QString filename) |
| 3597 |
{ |
| 3598 |
// obtain filename |
| 3599 |
if (filename.isEmpty()) |
| 3600 |
{ |
| 3601 |
QString filters; |
| 3602 |
filters += tr("Text files", "save filter")+" (*.txt);;"; |
| 3603 |
filters += tr("All files", "save filter") + " (*)"; |
| 3604 |
QString caption = tr("Save Text - DjView", "dialog caption"); |
| 3605 |
filename = QFileDialog::getSaveFileName(this, caption, "", filters); |
| 3606 |
if (filename.isEmpty()) |
| 3607 |
return false; |
| 3608 |
} |
| 3609 |
// open file |
| 3610 |
errno = 0; |
| 3611 |
QFile file(filename); |
| 3612 |
if (! file.open(QIODevice::WriteOnly|QIODevice::Truncate)) |
| 3613 |
{ |
| 3614 |
QString message = file.errorString(); |
| 3615 |
#if HAVE_STRERROR |
| 3616 |
if (file.error() == QFile::OpenError && errno > 0) |
| 3617 |
message = strerror(errno); |
| 3618 |
#endif |
| 3619 |
QMessageBox::critical(this, |
| 3620 |
tr("Error - DjView", "dialog caption"), |
| 3621 |
tr("Cannot write file '%1'.\n%2.") |
| 3622 |
.arg(QFileInfo(filename).fileName()) |
| 3623 |
.arg(message) ); |
| 3624 |
file.remove(); |
| 3625 |
return false; |
| 3626 |
} |
| 3627 |
// save text in current locale encoding |
| 3628 |
QTextStream(&file) << text; |
| 3629 |
return true; |
| 3630 |
} |
| 3631 |
|
| 3632 |
|
| 3633 |
/*! Save \a image info the specified file |
| 3634 |
using a format derived from the filename suffix. |
| 3635 |
When argument \a filename is omitted, |
| 3636 |
a file dialog is presented to the user. */ |
| 3637 |
|
| 3638 |
bool |
| 3639 |
QDjView::saveImageFile(QImage image, QString filename) |
| 3640 |
{ |
| 3641 |
// obtain filename with suitable suffix |
| 3642 |
if (filename.isEmpty()) |
| 3643 |
{ |
| 3644 |
QString filters; |
| 3645 |
QList<QByteArray> formats = QImageWriter::supportedImageFormats(); |
| 3646 |
foreach(QByteArray format, formats) |
| 3647 |
filters += tr("%1 files (*.%2);;", "save image filter") |
| 3648 |
.arg(QString(format).toUpper()) |
| 3649 |
.arg(QString(format).toLower()); |
| 3650 |
filters += tr("All files", "save filter") + " (*)"; |
| 3651 |
QString caption = tr("Save Image - DjView", "dialog caption"); |
| 3652 |
filename = QFileInfo(getShortFileName()).baseName(); |
| 3653 |
if (formats.size()) |
| 3654 |
filename += "." + QString(formats[0]); |
| 3655 |
filename = QFileDialog::getSaveFileName(this, caption, |
| 3656 |
filename, filters); |
| 3657 |
if (filename.isEmpty()) |
| 3658 |
return false; |
| 3659 |
} |
| 3660 |
// suffix |
| 3661 |
QString suffix = QFileInfo(filename).suffix(); |
| 3662 |
if (suffix.isEmpty()) |
| 3663 |
{ |
| 3664 |
QMessageBox::critical(this, |
| 3665 |
tr("Error - DjView", "dialog caption"), |
| 3666 |
tr("Cannot determine file format.\n" |
| 3667 |
"Filename '%1' has no suffix.") |
| 3668 |
.arg(QFileInfo(filename).fileName()) ); |
| 3669 |
return false; |
| 3670 |
} |
| 3671 |
// write |
| 3672 |
errno = 0; |
| 3673 |
QFile file(filename); |
| 3674 |
QImageWriter writer(&file, suffix.toLatin1()); |
| 3675 |
if (! writer.write(image)) |
| 3676 |
{ |
| 3677 |
QString message = file.errorString(); |
| 3678 |
if (writer.error() == QImageWriter::UnsupportedFormatError) |
| 3679 |
message = tr("Image format %1 not supported.").arg(suffix.toUpper()); |
| 3680 |
#if HAVE_STRERROR |
| 3681 |
else if (file.error() == QFile::OpenError && errno > 0) |
| 3682 |
message = strerror(errno); |
| 3683 |
#endif |
| 3684 |
QMessageBox::critical(this, |
| 3685 |
tr("Error - DjView", "dialog caption"), |
| 3686 |
tr("Cannot write file '%1'.\n%2.") |
| 3687 |
.arg(QFileInfo(filename).fileName()) |
| 3688 |
.arg(message) ); |
| 3689 |
file.remove(); |
| 3690 |
return false; |
| 3691 |
} |
| 3692 |
return true; |
| 3693 |
} |
| 3694 |
|
| 3695 |
|
| 3696 |
/*! Start the preferred browser on \a url. */ |
| 3697 |
|
| 3698 |
bool |
| 3699 |
QDjView::startBrowser(QUrl url) |
| 3700 |
{ |
| 3701 |
// Determine browsers to try |
| 3702 |
QStringList browsers; |
| 3703 |
#ifdef Q_OS_DARWIN |
| 3704 |
browsers << "open"; |
| 3705 |
#endif |
| 3706 |
#ifdef Q_OS_WIN32 |
| 3707 |
# if QT_VERSION < 0x40200 |
| 3708 |
browsers << "firefox.exe"; |
| 3709 |
browsers << "iexplore.exe"; |
| 3710 |
# endif |
| 3711 |
#endif |
| 3712 |
#ifdef Q_OS_UNIX |
| 3713 |
browsers << "x-www-browser" << "firefox" << "konqueror"; |
| 3714 |
const char *varBrowser = ::getenv("BROWSER"); |
| 3715 |
if (varBrowser && varBrowser[0]) |
| 3716 |
browsers = QFile::decodeName(varBrowser).split(":") + browsers; |
| 3717 |
browsers << "sensible-browser"; |
| 3718 |
const char *varPath = ::getenv("PATH"); |
| 3719 |
QStringList path; |
| 3720 |
if (varPath && varPath[0]) |
| 3721 |
path = QFile::decodeName(varPath).split(":"); |
| 3722 |
path << "."; |
| 3723 |
#endif |
| 3724 |
if (! prefs->browserProgram.isEmpty()) |
| 3725 |
browsers.prepend(prefs->browserProgram); |
| 3726 |
// Try them |
| 3727 |
QStringList args(url.toEncoded()); |
| 3728 |
foreach (QString browser, browsers) |
| 3729 |
{ |
| 3730 |
#ifdef Q_OS_UNIX |
| 3731 |
int i; |
| 3732 |
for (i=0; i<path.size(); i++) |
| 3733 |
if (QFileInfo(QDir(path[i]), browser).exists()) |
| 3734 |
break; |
| 3735 |
if (i >= path.size()) |
| 3736 |
continue; |
| 3737 |
#endif |
| 3738 |
if (QProcess::startDetached(browser, args)) |
| 3739 |
return true; |
| 3740 |
} |
| 3741 |
// fallback |
| 3742 |
#if QT_VERSION >= 0x40200 |
| 3743 |
return QDesktopServices::openUrl(url); |
| 3744 |
#else |
| 3745 |
return false; |
| 3746 |
#endif |
| 3747 |
} |
| 3748 |
|
| 3749 |
|
| 3750 |
|
| 3751 |
/*! \fn QDjView::documentClosed(QDjVuDocument *doc) |
| 3752 |
This signal is emitted when clearing the current document. |
| 3753 |
Argument \a doc is the previous document. */ |
| 3754 |
|
| 3755 |
/*! \fn QDjView::documentOpened(QDjVuDocument *doc) |
| 3756 |
This signal is emitted when opening a new document \a doc. */ |
| 3757 |
|
| 3758 |
/*! \fn QDjView::documentReady(QDjVuDocument *doc) |
| 3759 |
This signal is emitted when the document structure |
| 3760 |
for the current document \a doc is known. */ |
| 3761 |
|
| 3762 |
/*! \fn QDjView::pluginStatusMessage(QString message = QString()) |
| 3763 |
This signal is emitted when a message is displayed |
| 3764 |
in the status bar. This is useful for plugins because |
| 3765 |
the message must be replicated in the browser status bar. */ |
| 3766 |
|
| 3767 |
/*! \fn QDjView::pluginGetUrl(QUrl url, QString target) |
| 3768 |
This signal is emitted when the user clicks an external |
| 3769 |
hyperlink while the viewer is in plugin mode. */ |
| 3770 |
|
| 3771 |
|
| 3772 |
|
| 3773 |
// ----------------------------------- |
| 3774 |
// OVERRIDES |
| 3775 |
|
| 3776 |
|
| 3777 |
void |
| 3778 |
QDjView::closeEvent(QCloseEvent *event) |
| 3779 |
{ |
| 3780 |
// Close document. |
| 3781 |
closeDocument(); |
| 3782 |
// Save options. |
| 3783 |
// after closing the document in order to |
| 3784 |
// avoid saving document defined settings. |
| 3785 |
updatePreferences(); |
| 3786 |
prefs->saveRemembered(); |
| 3787 |
// continue closing the window |
| 3788 |
event->accept(); |
| 3789 |
} |
| 3790 |
|
| 3791 |
|
| 3792 |
void |
| 3793 |
QDjView::dragEnterEvent(QDragEnterEvent *event) |
| 3794 |
{ |
| 3795 |
if (viewerMode >= STANDALONE) |
| 3796 |
{ |
| 3797 |
const QMimeData *data = event->mimeData(); |
| 3798 |
if (data->hasUrls() && data->urls().size()==1) |
| 3799 |
event->accept(); |
| 3800 |
} |
| 3801 |
} |
| 3802 |
|
| 3803 |
|
| 3804 |
void |
| 3805 |
QDjView::dragMoveEvent(QDragMoveEvent *event) |
| 3806 |
{ |
| 3807 |
#ifdef Q_OS_WIN |
| 3808 |
QMainWindow::dragMoveEvent(event); |
| 3809 |
#else |
| 3810 |
QRect rect = centralWidget()->geometry(); |
| 3811 |
if (event->answerRect().intersects(rect)) |
| 3812 |
event->accept(rect); |
| 3813 |
else |
| 3814 |
event->ignore(); |
| 3815 |
#endif |
| 3816 |
} |
| 3817 |
|
| 3818 |
|
| 3819 |
void |
| 3820 |
QDjView::dropEvent(QDropEvent *event) |
| 3821 |
{ |
| 3822 |
if (viewerMode >= STANDALONE) |
| 3823 |
{ |
| 3824 |
const QMimeData *data = event->mimeData(); |
| 3825 |
if (data->hasUrls() && data->urls().size()==1) |
| 3826 |
if (open(data->urls()[0])) |
| 3827 |
{ |
| 3828 |
event->setDropAction(Qt::CopyAction); |
| 3829 |
event->accept(); |
| 3830 |
} |
| 3831 |
} |
| 3832 |
} |
| 3833 |
|
| 3834 |
|
| 3835 |
bool |
| 3836 |
QDjView::eventFilter(QObject *watched, QEvent *event) |
| 3837 |
{ |
| 3838 |
switch(event->type()) |
| 3839 |
{ |
| 3840 |
case QEvent::Show: |
| 3841 |
case QEvent::Hide: |
| 3842 |
if (qobject_cast<QDockWidget*>(watched)) |
| 3843 |
updateActionsLater(); |
| 3844 |
break; |
| 3845 |
case QEvent::Leave: |
| 3846 |
if ((watched == widget->viewport()) || |
| 3847 |
(qobject_cast<QDockWidget*>(watched)) ) |
| 3848 |
{ |
| 3849 |
mouseLabel->clear(); |
| 3850 |
textLabel->clear(); |
| 3851 |
statusMessage(); |
| 3852 |
return false; |
| 3853 |
} |
| 3854 |
break; |
| 3855 |
case QEvent::Enter: |
| 3856 |
if ((watched == widget->viewport()) || |
| 3857 |
(qobject_cast<QDockWidget*>(watched)) ) |
| 3858 |
maybeReloadDocument(); |
| 3859 |
break; |
| 3860 |
case QEvent::StatusTip: |
| 3861 |
if (qobject_cast<QMenu*>(watched)) |
| 3862 |
return QApplication::sendEvent(this, event); |
| 3863 |
break; |
| 3864 |
case QEvent::FocusIn: |
| 3865 |
if (watched == pageCombo) |
| 3866 |
if (widget && documentPages.size()) |
| 3867 |
pageCombo->setEditText(pageName(widget->page())); |
| 3868 |
break; |
| 3869 |
default: |
| 3870 |
break; |
| 3871 |
} |
| 3872 |
return false; |
| 3873 |
} |
| 3874 |
|
| 3875 |
|
| 3876 |
// ----------------------------------- |
| 3877 |
// PROTECTED SIGNALS |
| 3878 |
|
| 3879 |
|
| 3880 |
void |
| 3881 |
QDjView::info(QString message) |
| 3882 |
{ |
| 3883 |
if (reIndex(message, QRegExp("^\\[\\d+"), 0) < 0) |
| 3884 |
statusBar->showMessage(message, 2000); |
| 3885 |
qWarning("INFO: %s", (const char*)message.toLocal8Bit()); |
| 3886 |
} |
| 3887 |
|
| 3888 |
|
| 3889 |
void |
| 3890 |
QDjView::error(QString message, QString filename, int lineno) |
| 3891 |
{ |
| 3892 |
// just for calling qWarning |
| 3893 |
filename = filename.section("/", -1); |
| 3894 |
if (filename.isEmpty()) |
| 3895 |
qWarning("ERROR: %s", (const char*)message.toLocal8Bit()); |
| 3896 |
else |
| 3897 |
qWarning("ERROR (%s:%d): %s", (const char*)filename.toLocal8Bit(), |
| 3898 |
lineno, (const char*)message.toLocal8Bit() ); |
| 3899 |
} |
| 3900 |
|
| 3901 |
|
| 3902 |
void |
| 3903 |
QDjView::errorCondition(int pageno) |
| 3904 |
{ |
| 3905 |
QString message; |
| 3906 |
if (pageno >= 0) |
| 3907 |
message = tr("Cannot decode page %1.").arg(pageno+1); |
| 3908 |
else |
| 3909 |
message = tr("Cannot decode document."); |
| 3910 |
addToErrorDialog(message); |
| 3911 |
raiseErrorDialog(QMessageBox::Warning, tr("Decoding DjVu document")); |
| 3912 |
} |
| 3913 |
|
| 3914 |
|
| 3915 |
void |
| 3916 |
QDjView::docinfo() |
| 3917 |
{ |
| 3918 |
if (document && documentPages.size()==0 && |
| 3919 |
ddjvu_document_decoding_status(*document)==DDJVU_JOB_OK) |
| 3920 |
{ |
| 3921 |
// Obtain information about pages. |
| 3922 |
int n = ddjvu_document_get_pagenum(*document); |
| 3923 |
int m = ddjvu_document_get_filenum(*document); |
| 3924 |
for (int i=0; i<m; i++) |
| 3925 |
{ |
| 3926 |
ddjvu_fileinfo_t info; |
| 3927 |
if (ddjvu_document_get_fileinfo(*document, i, &info)!=DDJVU_JOB_OK) |
| 3928 |
qWarning("Internal(docinfo): ddjvu_document_get_fileinfo fails."); |
| 3929 |
if (info.title && info.name && !strcmp(info.title, info.name)) |
| 3930 |
info.title = 0; // clear title if equal to name. |
| 3931 |
if (info.type == 'P') |
| 3932 |
documentPages << info; |
| 3933 |
} |
| 3934 |
if (documentPages.size() != n) |
| 3935 |
qWarning("Internal(docinfo): inconsistent number of pages."); |
| 3936 |
|
| 3937 |
// Check for numerical title |
| 3938 |
hasNumericalPageTitle = false; |
| 3939 |
QRegExp allNumbers("\\d+"); |
| 3940 |
for (int i=0; i<n; i++) |
| 3941 |
if (documentPages[i].title && |
| 3942 |
allNumbers.exactMatch(QString::fromUtf8(documentPages[i].title)) ) |
| 3943 |
hasNumericalPageTitle = true; |
| 3944 |
|
| 3945 |
// Fill page combo |
| 3946 |
fillPageCombo(pageCombo); |
| 3947 |
|
| 3948 |
// Continue processing a bit later |
| 3949 |
QTimer::singleShot(0, this, SLOT(docinfoExtra())); |
| 3950 |
} |
| 3951 |
} |
| 3952 |
|
| 3953 |
void |
| 3954 |
QDjView::docinfoExtra() |
| 3955 |
{ |
| 3956 |
if (document && documentPages.size()>0) |
| 3957 |
{ |
| 3958 |
bool saved = widget->animationEnabled(); |
| 3959 |
widget->enableAnimation(false); |
| 3960 |
performPending(); |
| 3961 |
widget->enableAnimation(saved); |
| 3962 |
updateActionsLater(); |
| 3963 |
emit documentReady(document); |
| 3964 |
} |
| 3965 |
} |
| 3966 |
|
| 3967 |
|
| 3968 |
/*! Set options that could not be set before fully decoding |
| 3969 |
the document header. For instance, calling \a QDjView::goToPage |
| 3970 |
before decoding the djvu document header simply stores |
| 3971 |
the page number in a well known variable. Function \a performPending |
| 3972 |
peforms the page change as soon as the document information |
| 3973 |
is available. */ |
| 3974 |
|
| 3975 |
|
| 3976 |
void |
| 3977 |
QDjView::performPending() |
| 3978 |
{ |
| 3979 |
if (! documentPages.isEmpty()) |
| 3980 |
{ |
| 3981 |
if (! pendingPosition.isEmpty()) |
| 3982 |
{ |
| 3983 |
if (pendingPosition.size() == 2) |
| 3984 |
goToPosition(pendingPage, pendingPosition[0], pendingPosition[1]); |
| 3985 |
pendingPosition.clear(); |
| 3986 |
pendingPage.clear(); |
| 3987 |
} |
| 3988 |
if (! pendingPage.isNull()) |
| 3989 |
{ |
| 3990 |
goToPage(pendingPage); |
| 3991 |
pendingPage.clear(); |
| 3992 |
} |
| 3993 |
if (pendingHilite.size() > 0) |
| 3994 |
{ |
| 3995 |
StringPair pair; |
| 3996 |
foreach(pair, pendingHilite) |
| 3997 |
{ |
| 3998 |
int x, y, w, h; |
| 3999 |
QColor color = Qt::blue; |
| 4000 |
int pageno = widget->page(); |
| 4001 |
if (! pair.first.isEmpty()) |
| 4002 |
pageno = pageNumber(pair.first); |
| 4003 |
if (pageno < pageNum() && pageno >= 0 |
| 4004 |
&& parse_highlight(pair.second, x, y, w, h, color) |
| 4005 |
&& w > 0 && h > 0 ) |
| 4006 |
{ |
| 4007 |
color.setAlpha(96); |
| 4008 |
widget->addHighlight(pageno, x, y, w, h, color); |
| 4009 |
} |
| 4010 |
} |
| 4011 |
pendingHilite.clear(); |
| 4012 |
} |
| 4013 |
if (pendingFind.size() > 0) |
| 4014 |
{ |
| 4015 |
find(pendingFind); |
| 4016 |
pendingFind.clear(); |
| 4017 |
} |
| 4018 |
} |
| 4019 |
performPendingScheduled = false; |
| 4020 |
} |
| 4021 |
|
| 4022 |
|
| 4023 |
/*! Schedule a call to \a QDjView::performPending(). */ |
| 4024 |
|
| 4025 |
void |
| 4026 |
QDjView::performPendingLater() |
| 4027 |
{ |
| 4028 |
if (! performPendingScheduled) |
| 4029 |
{ |
| 4030 |
performPendingScheduled = true; |
| 4031 |
QTimer::singleShot(0, this, SLOT(performPending())); |
| 4032 |
} |
| 4033 |
} |
| 4034 |
|
| 4035 |
|
| 4036 |
void |
| 4037 |
QDjView::pointerPosition(const Position &pos, const PageInfo &info) |
| 4038 |
{ |
| 4039 |
// setup page label |
| 4040 |
QString p = ""; |
| 4041 |
QString m = ""; |
| 4042 |
if (pos.pageNo >= 0) |
| 4043 |
{ |
| 4044 |
p = tr(" P%1/%2 %3x%4 %5dpi ") |
| 4045 |
.arg(pos.pageNo+1).arg(documentPages.size()) |
| 4046 |
.arg(info.width).arg(info.height).arg(info.dpi); |
| 4047 |
} |
| 4048 |
if (pos.inPage || !info.segment.isEmpty()) |
| 4049 |
{ |
| 4050 |
if (info.segment.isEmpty()) |
| 4051 |
m = tr(" x=%1 y=%2 ") |
| 4052 |
.arg(pos.posPage.x()) |
| 4053 |
.arg(pos.posPage.y()); |
| 4054 |
else |
| 4055 |
m = tr(" %3x%4+%1+%2 ") |
| 4056 |
.arg(info.segment.left()) |
| 4057 |
.arg(info.segment.top()) |
| 4058 |
.arg(info.segment.width()) |
| 4059 |
.arg(info.segment.height()); |
| 4060 |
} |
| 4061 |
setPageLabelText(p); |
| 4062 |
setMouseLabelText(m); |
| 4063 |
if (textLabel->isVisibleTo(this)) |
| 4064 |
{ |
| 4065 |
textLabelRect = info.selected; |
| 4066 |
textLabelTimer->start(25); |
| 4067 |
} |
| 4068 |
} |
| 4069 |
|
| 4070 |
|
| 4071 |
void |
| 4072 |
QDjView::updateTextLabel() |
| 4073 |
{ |
| 4074 |
textLabel->clear(); |
| 4075 |
textLabel->setWordWrap(false); |
| 4076 |
textLabel->setTextFormat(Qt::PlainText); |
| 4077 |
if (document && textLabel->isVisibleTo(this)) |
| 4078 |
{ |
| 4079 |
QString text; |
| 4080 |
QFontMetrics m(textLabel->font()); |
| 4081 |
QString lb = QString::fromUtf8(" \302\253 "); |
| 4082 |
QString rb = QString::fromUtf8(" \302\273 "); |
| 4083 |
int w = textLabel->width()-2*textLabel->frameWidth()-swidth(m,lb+rb+"MM"); |
| 4084 |
if (! textLabelRect.isEmpty()) |
| 4085 |
{ |
| 4086 |
text = widget->getTextForRect(textLabelRect); |
| 4087 |
text = reReplace(text, QRegExp("\\s+"), " "); |
| 4088 |
text = m.elidedText(text, Qt::ElideMiddle, w); |
| 4089 |
} |
| 4090 |
else |
| 4091 |
{ |
| 4092 |
QString results[3]; |
| 4093 |
if (widget->getTextForPointer(results)) |
| 4094 |
{ |
| 4095 |
results[0] = results[0].simplified(); |
| 4096 |
results[1] = results[1].simplified(); |
| 4097 |
results[2] = results[2].simplified(); |
| 4098 |
if (results[0].size() || results[2].size()) |
| 4099 |
results[1] = " [" + results[1] + "] "; |
| 4100 |
int r1 = swidth(m,results[1]); |
| 4101 |
int r2 = swidth(m,results[2]); |
| 4102 |
int r0 = qMax(0, qMax( (w-r1)/2, (w-r1-r2) )); |
| 4103 |
text = m.elidedText(results[0], Qt::ElideLeft, r0) + results[1]; |
| 4104 |
text = m.elidedText(text+results[2], Qt::ElideRight, w); |
| 4105 |
} |
| 4106 |
} |
| 4107 |
text = text.trimmed(); |
| 4108 |
if (text.size()) |
| 4109 |
textLabel->setText(lb + text + rb); |
| 4110 |
} |
| 4111 |
} |
| 4112 |
|
| 4113 |
|
| 4114 |
void |
| 4115 |
QDjView::pointerEnter(const Position&, miniexp_t) |
| 4116 |
{ |
| 4117 |
// Display information message about hyperlink |
| 4118 |
QString link = widget->linkUrl(); |
| 4119 |
if (link.isEmpty()) |
| 4120 |
return; |
| 4121 |
QString target = widget->linkTarget(); |
| 4122 |
if (target=="_self" || target=="_page") |
| 4123 |
target.clear(); |
| 4124 |
QString message; |
| 4125 |
if (link.startsWith("#") && |
| 4126 |
reIndex(link, QRegExp("^#[-+]\\d+$"), 0) >= 0 ) |
| 4127 |
{ |
| 4128 |
int n = link.mid(2).toInt(); |
| 4129 |
if (link[1]=='+') |
| 4130 |
message = (n==1) ? tr("Go: 1 page forward.") |
| 4131 |
: tr("Go: %n pages forward.", 0, n); |
| 4132 |
else |
| 4133 |
message = (n==1) ? tr("Go: 1 page backward.") |
| 4134 |
: tr("Go: %n pages backward.", 0, n); |
| 4135 |
} |
| 4136 |
else if (link.startsWith("#$")) |
| 4137 |
message = tr("Go: page %1.").arg(link.mid(2)); |
| 4138 |
else if (link.startsWith("#")) |
| 4139 |
message = tr("Go: page %1.").arg(link.mid(1)); |
| 4140 |
else |
| 4141 |
message = tr("Go: %1").arg(link); |
| 4142 |
if (!target.isEmpty()) |
| 4143 |
message = message + tr(" (in other window.)"); |
| 4144 |
|
| 4145 |
statusMessage(message); |
| 4146 |
} |
| 4147 |
|
| 4148 |
|
| 4149 |
void |
| 4150 |
QDjView::pointerLeave(const Position&, miniexp_t) |
| 4151 |
{ |
| 4152 |
statusMessage(); |
| 4153 |
} |
| 4154 |
|
| 4155 |
|
| 4156 |
void |
| 4157 |
QDjView::pointerClick(const Position &pos, miniexp_t) |
| 4158 |
{ |
| 4159 |
goToLink(widget->linkUrl(), widget->linkTarget(), pos.pageNo); |
| 4160 |
} |
| 4161 |
|
| 4162 |
|
| 4163 |
void |
| 4164 |
QDjView::goToLink(QString link, QString target, int fromPage) |
| 4165 |
{ |
| 4166 |
bool inPlace = target.isEmpty() || target=="_self" || target=="_page"; |
| 4167 |
QUrl url = documentUrl; |
| 4168 |
// Internal link |
| 4169 |
if (link.startsWith("#")) |
| 4170 |
{ |
| 4171 |
QString name = link.mid(1); |
| 4172 |
if (inPlace) |
| 4173 |
{ |
| 4174 |
goToPage(name, fromPage); |
| 4175 |
return; |
| 4176 |
} |
| 4177 |
if (viewerMode >= STANDALONE) |
| 4178 |
{ |
| 4179 |
QDjView *other = copyWindow(); |
| 4180 |
other->goToPage(name, fromPage); |
| 4181 |
other->show(); |
| 4182 |
return; |
| 4183 |
} |
| 4184 |
// Construct url |
| 4185 |
url = removeDjVuCgiArguments(url); |
| 4186 |
QueryItems items = urlQueryItems(url); |
| 4187 |
addQueryItem(items, "djvuopts", QString()); |
| 4188 |
int pageno = pageNumber(name, fromPage); |
| 4189 |
if (pageno>=0 && pageno<=documentPages.size()) |
| 4190 |
addQueryItem(items, "page", QString::fromUtf8(documentPages[pageno].id)); |
| 4191 |
urlSetQueryItems(url, items); |
| 4192 |
} |
| 4193 |
else if (link.startsWith("?")) |
| 4194 |
{ |
| 4195 |
if (inPlace) |
| 4196 |
{ |
| 4197 |
foreach(QString opt, link.mid(1).split("&")) |
| 4198 |
parseArgument(opt); |
| 4199 |
return; |
| 4200 |
} |
| 4201 |
if (viewerMode >= STANDALONE) |
| 4202 |
{ |
| 4203 |
QDjView *other = copyWindow(); |
| 4204 |
foreach(QString opt, link.mid(1).split("&")) |
| 4205 |
other->parseArgument(opt); |
| 4206 |
other->show(); |
| 4207 |
return; |
| 4208 |
} |
| 4209 |
// Construct url |
| 4210 |
QUrl linkUrl = QUrl::fromEncoded("file://d/d" + link.toUtf8()); |
| 4211 |
url = removeDjVuCgiArguments(url); |
| 4212 |
QueryItems items = urlQueryItems(url); |
| 4213 |
addQueryItem(items, "djvuopts", ""); |
| 4214 |
QPair<QString,QString> pair; |
| 4215 |
foreach(pair, urlQueryItems(linkUrl)) |
| 4216 |
addQueryItem(items, pair.first, pair.second); |
| 4217 |
urlSetQueryItems(url, items); |
| 4218 |
} |
| 4219 |
else |
| 4220 |
{ |
| 4221 |
// Decode url |
| 4222 |
QUrl linkUrl = QUrl::fromEncoded(link.toUtf8()); |
| 4223 |
// Resolve url |
| 4224 |
QueryItems empty; |
| 4225 |
urlSetQueryItems(url, empty); |
| 4226 |
url = url.resolved(linkUrl); |
| 4227 |
urlSetQueryItems(url, urlQueryItems(linkUrl)); |
| 4228 |
} |
| 4229 |
// Check url |
| 4230 |
if (! url.isValid() || url.isRelative()) |
| 4231 |
{ |
| 4232 |
QString msg = tr("Cannot resolve link '%1'").arg(link); |
| 4233 |
qWarning("%s", (const char*)msg.toLocal8Bit()); |
| 4234 |
return; |
| 4235 |
} |
| 4236 |
// Signal browser |
| 4237 |
if (viewerMode < STANDALONE) |
| 4238 |
{ |
| 4239 |
emit pluginGetUrl(url, target); |
| 4240 |
return; |
| 4241 |
} |
| 4242 |
// Standalone only: call open(QUrl,...) with adequate flags |
| 4243 |
open(url, !inPlace, true); |
| 4244 |
} |
| 4245 |
|
| 4246 |
|
| 4247 |
void |
| 4248 |
QDjView::pointerSelect(const QPoint &pointerPos, const QRect &rect) |
| 4249 |
{ |
| 4250 |
// Collect text |
| 4251 |
QString text=widget->getTextForRect(rect); |
| 4252 |
int l = text.size(); |
| 4253 |
int w = rect.width(); |
| 4254 |
int h = rect.height(); |
| 4255 |
QString s = tr("%n characters", 0, l); |
| 4256 |
if (QApplication::clipboard()->supportsSelection()) |
| 4257 |
QApplication::clipboard()->setText(text, QClipboard::Selection); |
| 4258 |
// Prepare menu |
| 4259 |
QMenu *menu = new QMenu(this); |
| 4260 |
QAction *copyText = menu->addAction(tr("Copy text (%1)").arg(s)); |
| 4261 |
QAction *saveText = menu->addAction(tr("Save text as...")); |
| 4262 |
copyText->setEnabled(l>0); |
| 4263 |
saveText->setEnabled(l>0); |
| 4264 |
copyText->setStatusTip(tr("Copy text into the clipboard.")); |
| 4265 |
saveText->setStatusTip(tr("Save text into a file.")); |
| 4266 |
menu->addSeparator(); |
| 4267 |
QString copyImageString = tr("Copy image (%1x%2 pixels)").arg(w).arg(h); |
| 4268 |
QAction *copyImage = menu->addAction(copyImageString); |
| 4269 |
QAction *saveImage = menu->addAction(tr("Save image as...")); |
| 4270 |
copyImage->setStatusTip(tr("Copy image into the clipboard.")); |
| 4271 |
saveImage->setStatusTip(tr("Save image into a file.")); |
| 4272 |
menu->addSeparator(); |
| 4273 |
QAction *zoom = menu->addAction(tr("Zoom to rectangle")); |
| 4274 |
zoom->setStatusTip(tr("Zoom the selection to fit the window.")); |
| 4275 |
QAction *copyUrl = 0; |
| 4276 |
QAction *copyMaparea = 0; |
| 4277 |
if (prefs->advancedFeatures) |
| 4278 |
{ |
| 4279 |
menu->addSeparator(); |
| 4280 |
copyUrl = menu->addAction(tr("Copy URL")); |
| 4281 |
copyUrl->setStatusTip(tr("Save into the clipboard an URL that " |
| 4282 |
"highlights the selection.")); |
| 4283 |
copyMaparea = menu->addAction(tr("Copy Maparea")); |
| 4284 |
copyMaparea->setStatusTip(tr("Save into the clipboard a maparea " |
| 4285 |
"annotation expression for program " |
| 4286 |
"djvused.")); |
| 4287 |
} |
| 4288 |
|
| 4289 |
// Make sure that status tips work (hack) |
| 4290 |
menu->installEventFilter(this); |
| 4291 |
|
| 4292 |
// Execute menu |
| 4293 |
QAction *action = menu->exec(pointerPos-QPoint(5,5), copyText); |
| 4294 |
if (action == zoom) |
| 4295 |
widget->zoomRect(rect); |
| 4296 |
else if (action == copyText) |
| 4297 |
QApplication::clipboard()->setText(text); |
| 4298 |
else if (action == saveText) |
| 4299 |
saveTextFile(text); |
| 4300 |
else if (action == copyImage) |
| 4301 |
QApplication::clipboard()->setImage(widget->getImageForRect(rect)); |
| 4302 |
else if (action == saveImage) |
| 4303 |
saveImageFile(widget->getImageForRect(rect)); |
| 4304 |
else if (action && action == copyMaparea) |
| 4305 |
{ |
| 4306 |
Position pos = widget->position(pointerPos); |
| 4307 |
QRect seg = widget->getSegmentForRect(rect, pos.pageNo); |
| 4308 |
if (! rect.isEmpty()) |
| 4309 |
{ |
| 4310 |
QString s = QString("(maparea \"url\"\n" |
| 4311 |
" \"comment\"\n" |
| 4312 |
" (rect %1 %2 %3 %4))") |
| 4313 |
.arg(seg.left()).arg(seg.top()) |
| 4314 |
.arg(seg.width()).arg(seg.height()); |
| 4315 |
QApplication::clipboard()->setText(s); |
| 4316 |
} |
| 4317 |
} |
| 4318 |
else if (action && action == copyUrl) |
| 4319 |
{ |
| 4320 |
QUrl url = getDecoratedUrl(); |
| 4321 |
Position pos = widget->position(pointerPos); |
| 4322 |
QRect seg = widget->getSegmentForRect(rect, pos.pageNo); |
| 4323 |
if (url.isValid() && pos.pageNo>=0 && pos.pageNo<pageNum()) |
| 4324 |
{ |
| 4325 |
QueryItems items = urlQueryItems(url); |
| 4326 |
if (! hasQueryItem(items, "djvuopts")) |
| 4327 |
addQueryItem(items, "djvuopts", QString()); |
| 4328 |
QList<ddjvu_fileinfo_t> &dp = documentPages; |
| 4329 |
if (! hasQueryItem(items, "page", false)) |
| 4330 |
if (pos.pageNo>=0 && pos.pageNo<documentPages.size()) |
| 4331 |
addQueryItem(items, "page", QString::fromUtf8(dp[pos.pageNo].id)); |
| 4332 |
if (! rect.isEmpty()) |
| 4333 |
addQueryItem(items, "highlight", QString("%1,%2,%3,%4") |
| 4334 |
.arg(seg.left()).arg(seg.top()) |
| 4335 |
.arg(seg.width()).arg(seg.height()) ); |
| 4336 |
urlSetQueryItems(url, items); |
| 4337 |
QApplication::clipboard()->setText(url.toString()); |
| 4338 |
} |
| 4339 |
} |
| 4340 |
|
| 4341 |
// Cancel select mode. |
| 4342 |
updateActionsLater(); |
| 4343 |
if (actionSelect->isChecked()) |
| 4344 |
{ |
| 4345 |
actionSelect->setChecked(false); |
| 4346 |
performSelect(false); |
| 4347 |
} |
| 4348 |
} |
| 4349 |
|
| 4350 |
|
| 4351 |
/*! Schedule a call to \a QDjView::updateActions(). */ |
| 4352 |
|
| 4353 |
void |
| 4354 |
QDjView::updateActionsLater() |
| 4355 |
{ |
| 4356 |
if (! updateActionsScheduled) |
| 4357 |
{ |
| 4358 |
updateActionsScheduled = true; |
| 4359 |
QTimer::singleShot(0, this, SLOT(updateActions())); |
| 4360 |
} |
| 4361 |
} |
| 4362 |
|
| 4363 |
|
| 4364 |
void |
| 4365 |
QDjView::modeComboActivated(int index) |
| 4366 |
{ |
| 4367 |
int mode = modeCombo->itemData(index).toInt(); |
| 4368 |
widget->setDisplayMode((QDjVuWidget::DisplayMode)mode); |
| 4369 |
widget->setFocus(); |
| 4370 |
} |
| 4371 |
|
| 4372 |
|
| 4373 |
void |
| 4374 |
QDjView::zoomComboActivated(int index) |
| 4375 |
{ |
| 4376 |
int zoom = zoomCombo->itemData(index).toInt(); |
| 4377 |
widget->setZoom(zoom); |
| 4378 |
updateActionsLater(); |
| 4379 |
widget->setFocus(); |
| 4380 |
} |
| 4381 |
|
| 4382 |
|
| 4383 |
void |
| 4384 |
QDjView::zoomComboEdited(void) |
| 4385 |
{ |
| 4386 |
bool okay; |
| 4387 |
QString text = zoomCombo->lineEdit()->text(); |
| 4388 |
int zoom = reReplace(text, QRegExp("\\s*%?$"), "").trimmed().toInt(&okay); |
| 4389 |
if (okay && zoom>0) |
| 4390 |
widget->setZoom(zoom); |
| 4391 |
updateActionsLater(); |
| 4392 |
if (okay) |
| 4393 |
widget->setFocus(); |
| 4394 |
} |
| 4395 |
|
| 4396 |
|
| 4397 |
void |
| 4398 |
QDjView::pageComboActivated(int index) |
| 4399 |
{ |
| 4400 |
goToPage(pageCombo->itemData(index).toInt()); |
| 4401 |
updateActionsLater(); |
| 4402 |
widget->setFocus(); |
| 4403 |
} |
| 4404 |
|
| 4405 |
|
| 4406 |
void |
| 4407 |
QDjView::pageComboEdited(void) |
| 4408 |
{ |
| 4409 |
QString data = pageCombo->lineEdit()->text().trimmed(); |
| 4410 |
int pagenum = documentPages.size(); |
| 4411 |
QRegExp pattern = QRegExp(QString("\\s*(\\d+)\\s*/\\s*%1\\s*").arg(pagenum)); |
| 4412 |
if (pattern.exactMatch(data)) |
| 4413 |
goToPage(qMax(0, pattern.cap(1).toInt() - 1)); |
| 4414 |
else |
| 4415 |
goToPage(data); |
| 4416 |
updateActionsLater(); |
| 4417 |
widget->setFocus(); |
| 4418 |
} |
| 4419 |
|
| 4420 |
|
| 4421 |
|
| 4422 |
|
| 4423 |
// ----------------------------------- |
| 4424 |
// SIGNALS IMPLEMENTING ACTIONS |
| 4425 |
|
| 4426 |
|
| 4427 |
|
| 4428 |
void |
| 4429 |
QDjView::performAbout(void) |
| 4430 |
{ |
| 4431 |
QStringList version; |
| 4432 |
#if DDJVUAPI_VERSION >= 20 |
| 4433 |
version << QString(ddjvu_get_version_string()); |
| 4434 |
#endif |
| 4435 |
#ifdef QT_VERSION |
| 4436 |
version << QString("Qt-%1").arg(qVersion()); |
| 4437 |
#endif |
| 4438 |
QString versioninfo = ""; |
| 4439 |
if (version.size() > 0) |
| 4440 |
versioninfo = "(" + version.join(", ") + ")"; |
| 4441 |
QString html = tr8("<html>" |
| 4442 |
"<h2>DjVuLibre DjView %1</h2>%2" |
| 4443 |
"<p>" |
| 4444 |
"Viewer for DjVu documents<br>" |
| 4445 |
"<a href=%3>%3</a><br>" |
| 4446 |
"Copyright \302\251 2006-- L\303\251on Bottou." |
| 4447 |
"</p>" |
| 4448 |
"<p align=justify><small>" |
| 4449 |
"This program is free software. " |
| 4450 |
"You can redistribute or modify it under the terms of the " |
| 4451 |
"GNU General Public License as published " |
| 4452 |
"by the Free Software Foundation. " |
| 4453 |
"This program is distributed <i>without any warranty</i>. " |
| 4454 |
"See the GNU General Public License for more details." |
| 4455 |
"</small></p>" |
| 4456 |
"</html>") |
| 4457 |
.arg(QDjViewPrefs::versionString()) |
| 4458 |
.arg(versioninfo) |
| 4459 |
.arg("http://djvu.sourceforge.net"); |
| 4460 |
|
| 4461 |
QMessageBox::about(this, tr("About DjView"), html); |
| 4462 |
} |
| 4463 |
|
| 4464 |
|
| 4465 |
void |
| 4466 |
QDjView::performNew(void) |
| 4467 |
{ |
| 4468 |
if (viewerMode < STANDALONE) |
| 4469 |
return; |
| 4470 |
QDjView *other = copyWindow(false); |
| 4471 |
other->show(); |
| 4472 |
} |
| 4473 |
|
| 4474 |
|
| 4475 |
void |
| 4476 |
QDjView::performOpen(void) |
| 4477 |
{ |
| 4478 |
if (viewerMode < STANDALONE) |
| 4479 |
return; |
| 4480 |
QString filters; |
| 4481 |
filters += tr("DjVu files") + " (*.djvu *.djv);;"; |
| 4482 |
filters += tr("All files") + " (*)"; |
| 4483 |
QString caption = tr("Open - DjView", "dialog caption"); |
| 4484 |
QString dirname = QDir::currentPath(); |
| 4485 |
QDir dir = QFileInfo(documentFileName).absoluteDir(); |
| 4486 |
if (dir.exists() && !documentFileName.isEmpty()) |
| 4487 |
dirname = dir.absolutePath(); |
| 4488 |
QString fname; |
| 4489 |
fname = QFileDialog::getOpenFileName(this, caption, dirname, filters); |
| 4490 |
if (! fname.isEmpty()) |
| 4491 |
open(fname); |
| 4492 |
} |
| 4493 |
|
| 4494 |
|
| 4495 |
void |
| 4496 |
QDjView::performOpenLocation(void) |
| 4497 |
{ |
| 4498 |
if (viewerMode < STANDALONE) |
| 4499 |
return; |
| 4500 |
QString caption = tr("Open Location - DjView", "dialog caption"); |
| 4501 |
QString label = tr("Enter the URL of a DjVu document:"); |
| 4502 |
QString text = "http://"; |
| 4503 |
bool ok; |
| 4504 |
QUrl url = QInputDialog::getText(this, caption, label, |
| 4505 |
QLineEdit::Normal, text, &ok); |
| 4506 |
if (ok && url.isValid()) |
| 4507 |
open(url); |
| 4508 |
} |
| 4509 |
|
| 4510 |
|
| 4511 |
void |
| 4512 |
QDjView::performInformation(void) |
| 4513 |
{ |
| 4514 |
if (! documentPages.size()) |
| 4515 |
return; |
| 4516 |
if (! infoDialog) |
| 4517 |
infoDialog = new QDjViewInfoDialog(this); |
| 4518 |
infoDialog->setWindowTitle(tr("Information - DjView", "dialog caption")); |
| 4519 |
infoDialog->setPage(widget->page()); |
| 4520 |
infoDialog->refresh(); |
| 4521 |
infoDialog->raise(); |
| 4522 |
infoDialog->show(); |
| 4523 |
} |
| 4524 |
|
| 4525 |
|
| 4526 |
void |
| 4527 |
QDjView::performMetadata(void) |
| 4528 |
{ |
| 4529 |
if (! documentPages.size()) |
| 4530 |
return; |
| 4531 |
if (! metaDialog) |
| 4532 |
metaDialog = new QDjViewMetaDialog(this); |
| 4533 |
metaDialog->setWindowTitle(tr("Metadata - DjView", "dialog caption")); |
| 4534 |
metaDialog->setPage(widget->page()); |
| 4535 |
metaDialog->refresh(); |
| 4536 |
metaDialog->raise(); |
| 4537 |
metaDialog->show(); |
| 4538 |
} |
| 4539 |
|
| 4540 |
|
| 4541 |
void |
| 4542 |
QDjView::performPreferences(void) |
| 4543 |
{ |
| 4544 |
updatePreferences(); |
| 4545 |
QDjViewPrefsDialog *dialog = QDjViewPrefsDialog::instance(); |
| 4546 |
dialog->load(this); |
| 4547 |
dialog->show(); |
| 4548 |
dialog->raise(); |
| 4549 |
} |
| 4550 |
|
| 4551 |
|
| 4552 |
void |
| 4553 |
QDjView::performRotation(void) |
| 4554 |
{ |
| 4555 |
QAction *action = qobject_cast<QAction*>(sender()); |
| 4556 |
int rotation = action->data().toInt(); |
| 4557 |
widget->setRotation(rotation); |
| 4558 |
} |
| 4559 |
|
| 4560 |
|
| 4561 |
void |
| 4562 |
QDjView::performZoom(void) |
| 4563 |
{ |
| 4564 |
QAction *action = qobject_cast<QAction*>(sender()); |
| 4565 |
int zoom = action->data().toInt(); |
| 4566 |
widget->setZoom(zoom); |
| 4567 |
} |
| 4568 |
|
| 4569 |
|
| 4570 |
void |
| 4571 |
QDjView::performSelect(bool checked) |
| 4572 |
{ |
| 4573 |
if (checked) |
| 4574 |
widget->setModifiersForSelect(Qt::NoModifier); |
| 4575 |
else |
| 4576 |
widget->setModifiersForSelect(prefs->modifiersForSelect); |
| 4577 |
} |
| 4578 |
|
| 4579 |
|
| 4580 |
bool |
| 4581 |
QDjView::setViewerMode(ViewerMode mode) |
| 4582 |
{ |
| 4583 |
Saved *savedPrefs; |
| 4584 |
Saved *savedConfig; |
| 4585 |
if (viewerMode == mode) |
| 4586 |
return true; |
| 4587 |
if (viewerMode < STANDALONE || mode < STANDALONE) |
| 4588 |
return false; |
| 4589 |
savedPrefs = getSavedPrefs(); |
| 4590 |
savedConfig = getSavedConfig(viewerMode); |
| 4591 |
savedConfig->remember = true; |
| 4592 |
updateSaved(savedConfig); |
| 4593 |
updateSaved(savedPrefs); |
| 4594 |
Qt::WindowStates wstate = windowState(); |
| 4595 |
wstate &= ~unusualWindowStates; |
| 4596 |
if (mode > STANDALONE) |
| 4597 |
wstate |= Qt::WindowFullScreen; |
| 4598 |
if (mode > STANDALONE) |
| 4599 |
setUnifiedTitleAndToolBarOnMac(false); |
| 4600 |
savedConfig = getSavedConfig(mode); |
| 4601 |
setWindowState(wstate); |
| 4602 |
applySaved(savedConfig); |
| 4603 |
widget->setBorderBrush(savedConfig->nsBorderBrush); |
| 4604 |
widget->setBorderSize(savedConfig->nsBorderSize); |
| 4605 |
viewerMode = mode; |
| 4606 |
// slideshow delay |
| 4607 |
if (mode == STANDALONE_SLIDESHOW) |
| 4608 |
setSlideShowDelay(prefs->slideShowDelay); |
| 4609 |
// make sure checkboxes are set right. |
| 4610 |
updateActionsLater(); |
| 4611 |
return true; |
| 4612 |
} |
| 4613 |
|
| 4614 |
void |
| 4615 |
QDjView::setSlideShowDelay(int delay) |
| 4616 |
{ |
| 4617 |
slideShowCounter = 0; |
| 4618 |
slideShowDelay = delay; |
| 4619 |
slideShowTimeout(true); |
| 4620 |
} |
| 4621 |
|
| 4622 |
void |
| 4623 |
QDjView::slideShowTimeout(bool reset) |
| 4624 |
{ |
| 4625 |
double ratio = 0; |
| 4626 |
bool ssmode = (viewerMode == STANDALONE_SLIDESHOW) && (slideShowDelay>0); |
| 4627 |
bool active = ssmode && (widget->page() < pageNum()-1); |
| 4628 |
bool newpage = (slideShowCounter >= slideShowDelay-1); |
| 4629 |
slideShowCounter = (reset||newpage||!active) ? 0 : slideShowCounter+1; |
| 4630 |
if (newpage && active) |
| 4631 |
widget->nextPage(); |
| 4632 |
if (active) |
| 4633 |
ratio = 1.0 - (double)slideShowCounter / slideShowDelay; |
| 4634 |
widget->setHourGlassRatio(ratio); |
| 4635 |
slideShowTimer->stop(); |
| 4636 |
if (ssmode) |
| 4637 |
slideShowTimer->start(1000); |
| 4638 |
} |
| 4639 |
|
| 4640 |
void |
| 4641 |
QDjView::performViewFullScreen(bool checked) |
| 4642 |
{ |
| 4643 |
if (checked) |
| 4644 |
setViewerMode(STANDALONE_FULLSCREEN); |
| 4645 |
else |
| 4646 |
setViewerMode(STANDALONE); |
| 4647 |
} |
| 4648 |
|
| 4649 |
void |
| 4650 |
QDjView::performViewSlideShow(bool checked) |
| 4651 |
{ |
| 4652 |
if (checked) |
| 4653 |
setViewerMode(STANDALONE_SLIDESHOW); |
| 4654 |
else |
| 4655 |
setViewerMode(STANDALONE); |
| 4656 |
} |
| 4657 |
|
| 4658 |
|
| 4659 |
void |
| 4660 |
QDjView::performEscape() |
| 4661 |
{ |
| 4662 |
if (actionViewSideBar->isChecked()) |
| 4663 |
actionViewSideBar->activate(QAction::Trigger); |
| 4664 |
else if (viewerMode > STANDALONE && widget->keyboardEnabled()) |
| 4665 |
setViewerMode(STANDALONE); |
| 4666 |
} |
| 4667 |
|
| 4668 |
|
| 4669 |
void |
| 4670 |
QDjView::performGoPage() |
| 4671 |
{ |
| 4672 |
if (toolBar->isVisibleTo(this) || widget->keyboardEnabled()) |
| 4673 |
if (toolsCached & QDjViewPrefs::TOOL_PAGECOMBO) |
| 4674 |
{ |
| 4675 |
toolBar->show(); |
| 4676 |
pageCombo->setFocus(); |
| 4677 |
QTimer::singleShot(0, pageCombo->lineEdit(), SLOT(selectAll())); |
| 4678 |
} |
| 4679 |
} |
| 4680 |
|
| 4681 |
|
| 4682 |
void |
| 4683 |
QDjView::restoreRecentDocument(QUrl url) |
| 4684 |
{ |
| 4685 |
url.setPassword(QString()); |
| 4686 |
QUrl cleanUrl = removeDjVuCgiArguments(url); |
| 4687 |
QString prefix = cleanUrl.toString(QUrl::RemoveQuery); |
| 4688 |
foreach (QString recent, prefs->recentFiles) |
| 4689 |
if (recent.startsWith(prefix)) |
| 4690 |
{ |
| 4691 |
QUrl recentUrl = recent; |
| 4692 |
QUrl cleanRecentUrl = removeDjVuCgiArguments(recentUrl); |
| 4693 |
if (cleanUrl == cleanRecentUrl) |
| 4694 |
{ |
| 4695 |
parseDjVuCgiArguments(recentUrl); |
| 4696 |
return; |
| 4697 |
} |
| 4698 |
} |
| 4699 |
} |
| 4700 |
|
| 4701 |
|
| 4702 |
void |
| 4703 |
QDjView::addRecent(QUrl url) |
| 4704 |
{ |
| 4705 |
prefs->loadRecent(); |
| 4706 |
// never remember passwords |
| 4707 |
url.setPassword(QString()); |
| 4708 |
// remove matching entries |
| 4709 |
QUrl cleanUrl = removeDjVuCgiArguments(url); |
| 4710 |
QString prefix = cleanUrl.toString(QUrl::RemoveQuery); |
| 4711 |
QStringList::iterator it = prefs->recentFiles.begin(); |
| 4712 |
while (it != prefs->recentFiles.end()) |
| 4713 |
{ |
| 4714 |
if (it->startsWith(prefix) && |
| 4715 |
cleanUrl == removeDjVuCgiArguments(QUrl(*it))) |
| 4716 |
it = prefs->recentFiles.erase(it); |
| 4717 |
else |
| 4718 |
++it; |
| 4719 |
} |
| 4720 |
// add new url (max 50) |
| 4721 |
QString name = url.toString(); |
| 4722 |
prefs->recentFiles.prepend(name); |
| 4723 |
while(prefs->recentFiles.size() > 50) |
| 4724 |
prefs->recentFiles.pop_back(); |
| 4725 |
// save |
| 4726 |
prefs->saveRecent(); |
| 4727 |
} |
| 4728 |
|
| 4729 |
|
| 4730 |
void |
| 4731 |
QDjView::fillRecent() |
| 4732 |
{ |
| 4733 |
if (recentMenu) |
| 4734 |
{ |
| 4735 |
recentMenu->clear(); |
| 4736 |
prefs->loadRecent(); |
| 4737 |
int n = qMin(prefs->recentFiles.size(), 8); |
| 4738 |
for (int i=0; i<n; i++) |
| 4739 |
{ |
| 4740 |
QUrl url = prefs->recentFiles[i]; |
| 4741 |
QString base = url.path().section("/",-1); |
| 4742 |
QString name = url.toLocalFile(); |
| 4743 |
if (name.isEmpty()) |
| 4744 |
name = removeDjVuCgiArguments(url).toString(); |
| 4745 |
QFont defaultFont; |
| 4746 |
QFontMetrics metrics(defaultFont); |
| 4747 |
name = metrics.elidedText(name, Qt::ElideMiddle, 400); |
| 4748 |
name = QString("%1 [%2]").arg(base).arg(name); |
| 4749 |
QAction *action = recentMenu->addAction(name); |
| 4750 |
action->setData(url); |
| 4751 |
connect(action,SIGNAL(triggered()), this, SLOT(openRecent())); |
| 4752 |
} |
| 4753 |
recentMenu->addSeparator(); |
| 4754 |
} |
| 4755 |
QAction *action = recentMenu->addAction(tr("&Clear History")); |
| 4756 |
connect(action, SIGNAL(triggered()), this, SLOT(clearRecent())); |
| 4757 |
} |
| 4758 |
|
| 4759 |
|
| 4760 |
void |
| 4761 |
QDjView::openRecent() |
| 4762 |
{ |
| 4763 |
QAction *action = qobject_cast<QAction*>(sender()); |
| 4764 |
if (action && viewerMode >= STANDALONE) |
| 4765 |
{ |
| 4766 |
QUrl url = action->data().toUrl(); |
| 4767 |
QFileInfo file = QFileInfo(url.toLocalFile()); |
| 4768 |
if (file.exists()) |
| 4769 |
open(file.absoluteFilePath()); |
| 4770 |
else |
| 4771 |
open(url); |
| 4772 |
} |
| 4773 |
} |
| 4774 |
|
| 4775 |
|
| 4776 |
void |
| 4777 |
QDjView::clearRecent() |
| 4778 |
{ |
| 4779 |
prefs->recentFiles.clear(); |
| 4780 |
prefs->saveRecent(); |
| 4781 |
} |
| 4782 |
|
| 4783 |
|
| 4784 |
QDjView::UndoRedo::UndoRedo() |
| 4785 |
: valid(false) |
| 4786 |
{ |
| 4787 |
} |
| 4788 |
|
| 4789 |
|
| 4790 |
void |
| 4791 |
QDjView::UndoRedo::clear() |
| 4792 |
{ |
| 4793 |
valid = false; |
| 4794 |
} |
| 4795 |
|
| 4796 |
|
| 4797 |
void |
| 4798 |
QDjView::UndoRedo::set(QDjView *djview) |
| 4799 |
{ |
| 4800 |
QDjVuWidget *djvu = djview->getDjVuWidget(); |
| 4801 |
rotation = djvu->rotation(); |
| 4802 |
zoom = djvu->zoom(); |
| 4803 |
hotSpot = djvu->hotSpot(); |
| 4804 |
position = djvu->position(hotSpot); |
| 4805 |
valid = true; |
| 4806 |
} |
| 4807 |
|
| 4808 |
|
| 4809 |
void |
| 4810 |
QDjView::UndoRedo::apply(QDjView *djview) |
| 4811 |
{ |
| 4812 |
if (valid) |
| 4813 |
{ |
| 4814 |
QDjVuWidget *djvu = djview->getDjVuWidget(); |
| 4815 |
djvu->setZoom(zoom); |
| 4816 |
djvu->setRotation(rotation); |
| 4817 |
djvu->setPosition(position, hotSpot); |
| 4818 |
} |
| 4819 |
} |
| 4820 |
|
| 4821 |
|
| 4822 |
bool |
| 4823 |
QDjView::UndoRedo::changed(const QDjVuWidget *djvu) const |
| 4824 |
{ |
| 4825 |
if (valid) |
| 4826 |
{ |
| 4827 |
if (zoom != djvu->zoom() || |
| 4828 |
rotation != djvu->rotation()) |
| 4829 |
return true; |
| 4830 |
Position curpos = djvu->position(hotSpot); |
| 4831 |
if (curpos.pageNo != position.pageNo || |
| 4832 |
curpos.inPage != position.inPage) |
| 4833 |
return true; |
| 4834 |
if (curpos.inPage) |
| 4835 |
return (curpos.posPage != position.posPage); |
| 4836 |
else |
| 4837 |
return (curpos.posView != position.posView); |
| 4838 |
} |
| 4839 |
return false; |
| 4840 |
} |
| 4841 |
|
| 4842 |
|
| 4843 |
void |
| 4844 |
QDjView::saveUndoData() |
| 4845 |
{ |
| 4846 |
if (QApplication::mouseButtons() == Qt::NoButton |
| 4847 |
&& widget->pageSizeKnown(widget->page()) ) |
| 4848 |
{ |
| 4849 |
if (here.changed(widget)) |
| 4850 |
{ |
| 4851 |
undoList.prepend(here); |
| 4852 |
while (undoList.size() > 1024) |
| 4853 |
undoList.removeLast(); |
| 4854 |
redoList.clear(); |
| 4855 |
} |
| 4856 |
here.set(this); |
| 4857 |
actionBack->setEnabled(undoList.size() > 0); |
| 4858 |
actionForw->setEnabled(redoList.size() > 0); |
| 4859 |
} |
| 4860 |
else |
| 4861 |
{ |
| 4862 |
undoTimer->stop(); |
| 4863 |
undoTimer->start(250); |
| 4864 |
} |
| 4865 |
} |
| 4866 |
|
| 4867 |
|
| 4868 |
void |
| 4869 |
QDjView::performUndo() |
| 4870 |
{ |
| 4871 |
if (undoList.size() > 0) |
| 4872 |
{ |
| 4873 |
UndoRedo target = undoList.takeFirst(); |
| 4874 |
UndoRedo saved; |
| 4875 |
saved.set(this); |
| 4876 |
target.apply(this); |
| 4877 |
here.clear(); |
| 4878 |
redoList.prepend(saved); |
| 4879 |
} |
| 4880 |
} |
| 4881 |
|
| 4882 |
|
| 4883 |
void |
| 4884 |
QDjView::performRedo() |
| 4885 |
{ |
| 4886 |
if (redoList.size() > 0) |
| 4887 |
{ |
| 4888 |
UndoRedo target = redoList.takeFirst(); |
| 4889 |
UndoRedo saved; |
| 4890 |
saved.set(this); |
| 4891 |
target.apply(this); |
| 4892 |
here.clear(); |
| 4893 |
undoList.prepend(saved); |
| 4894 |
} |
| 4895 |
} |
| 4896 |
|
| 4897 |
|
| 4898 |
void |
| 4899 |
QDjView::performCopyUrl() |
| 4900 |
{ |
| 4901 |
QUrl url = getDecoratedUrl(); |
| 4902 |
if (url.isValid()) |
| 4903 |
QApplication::clipboard()->setText(url.toString()); |
| 4904 |
} |
| 4905 |
|
| 4906 |
|
| 4907 |
#if DDJVUAPI_VERSION < 21 |
| 4908 |
|
| 4909 |
static QByteArray *qstring_puts_data = 0; |
| 4910 |
static int qstring_puts(const char *s) |
| 4911 |
{ |
| 4912 |
if (qstring_puts_data) |
| 4913 |
(*qstring_puts_data) += s; |
| 4914 |
return strlen(s); |
| 4915 |
} |
| 4916 |
|
| 4917 |
static QString |
| 4918 |
miniexp_to_string(miniexp_t expr, int width=40, bool octal=false) |
| 4919 |
{ |
| 4920 |
QByteArray buffer; |
| 4921 |
qstring_puts_data = &buffer; |
| 4922 |
int (*saved_puts)(const char*) = minilisp_puts; |
| 4923 |
int saved_print_7bits = minilisp_print_7bits; |
| 4924 |
minilisp_puts = qstring_puts; |
| 4925 |
minilisp_print_7bits = (octal) ? 1 : 0; |
| 4926 |
miniexp_pprint(expr, width); |
| 4927 |
minilisp_print_7bits = saved_print_7bits; |
| 4928 |
minilisp_puts = saved_puts; |
| 4929 |
return QString::fromUtf8(buffer.data()); |
| 4930 |
} |
| 4931 |
|
| 4932 |
#else |
| 4933 |
|
| 4934 |
static int |
| 4935 |
qstring_puts(miniexp_io_t *io, const char *s) |
| 4936 |
{ |
| 4937 |
QByteArray *bap = (QByteArray*)io->data[1]; |
| 4938 |
if (bap) *bap += s; |
| 4939 |
return strlen(s); |
| 4940 |
} |
| 4941 |
|
| 4942 |
static QString |
| 4943 |
miniexp_to_string(miniexp_t expr, int width=40, bool octal=false) |
| 4944 |
{ |
| 4945 |
QByteArray buffer; |
| 4946 |
miniexp_io_t io; |
| 4947 |
miniexp_io_init(&io); |
| 4948 |
io.fputs = qstring_puts; |
| 4949 |
io.data[1] = (void*)&buffer; |
| 4950 |
#ifdef miniexp_io_print7bits |
| 4951 |
static int flags = miniexp_io_print7bits; |
| 4952 |
io.p_flags = (octal) ? &flags : 0; |
| 4953 |
#else |
| 4954 |
static int flags = 1; |
| 4955 |
io.p_print7bits = (octal) ? &flags : 0; |
| 4956 |
#endif |
| 4957 |
miniexp_pprint_r(&io, expr, width); |
| 4958 |
return QString::fromUtf8(buffer.data()); |
| 4959 |
} |
| 4960 |
|
| 4961 |
#endif |
| 4962 |
|
| 4963 |
|
| 4964 |
void |
| 4965 |
QDjView::performCopyOutline() |
| 4966 |
{ |
| 4967 |
if (document) |
| 4968 |
{ |
| 4969 |
QString s; |
| 4970 |
minivar_t expr = document->getDocumentOutline(); |
| 4971 |
if (miniexp_consp(expr)) |
| 4972 |
s += QString("# This is the existing outline.\n"); |
| 4973 |
else { |
| 4974 |
s += QString("# This is an outline template with all pages.\n"); |
| 4975 |
expr = miniexp_cons(miniexp_symbol("bookmarks"),miniexp_nil); |
| 4976 |
for (int i=0; i<documentPages.size(); i++) |
| 4977 |
{ |
| 4978 |
minivar_t p = miniexp_nil; |
| 4979 |
QByteArray ref = documentPages[i].id; |
| 4980 |
p = miniexp_cons(miniexp_string(ref.prepend("#").constData()),p); |
| 4981 |
QString name = QString("Page %1").arg(pageName(i)); |
| 4982 |
p = miniexp_cons(miniexp_string(name.toUtf8().constData()),p); |
| 4983 |
expr = miniexp_cons(p,expr); |
| 4984 |
} |
| 4985 |
expr = miniexp_reverse(expr); |
| 4986 |
} |
| 4987 |
s += QString("# Edit it and store it with command:\n" |
| 4988 |
"# $ djvused foo.djvu -f thisfile -s\n" |
| 4989 |
"# The following line is the djvused command\n" |
| 4990 |
"# to set the outline and the rest is the outline\n" |
| 4991 |
"set-outline\n\n"); |
| 4992 |
s += miniexp_to_string(expr); |
| 4993 |
// copy to clipboard |
| 4994 |
QApplication::clipboard()->setText(s); |
| 4995 |
} |
| 4996 |
} |
| 4997 |
|
| 4998 |
|
| 4999 |
void |
| 5000 |
QDjView::performCopyAnnotation() |
| 5001 |
{ |
| 5002 |
int pageNo = widget->page(); |
| 5003 |
if (document && pageNo>=0 && pageNo<pageNum()) |
| 5004 |
{ |
| 5005 |
QString s; |
| 5006 |
miniexp_t expr = document->getPageAnnotations(pageNo); |
| 5007 |
if (expr == miniexp_nil || expr == miniexp_dummy) |
| 5008 |
s += QString("# There were no annotations for page %1.\n"); |
| 5009 |
else |
| 5010 |
s += QString("# These are the annotation for page %1.\n"); |
| 5011 |
s += QString("# Edit this file and store it with command:\n" |
| 5012 |
"# $ djvused foo.djvu -f thisfile -s\n" |
| 5013 |
"# Tip: select an area in djview4 and use 'copy maparea'.\n" |
| 5014 |
"# The following line is the djvused command to set\n" |
| 5015 |
"# the annotation and the rest are the annotations\n" |
| 5016 |
"select %2; set-ant\n\n"); |
| 5017 |
s = s.arg(pageNo+1).arg(pageNo+1); |
| 5018 |
while (miniexp_consp(expr)) |
| 5019 |
{ |
| 5020 |
s += miniexp_to_string(miniexp_car(expr)); |
| 5021 |
expr = miniexp_cdr(expr); |
| 5022 |
} |
| 5023 |
// copy to clipboard |
| 5024 |
QApplication::clipboard()->setText(s); |
| 5025 |
} |
| 5026 |
} |
| 5027 |
|
| 5028 |
|
| 5029 |
// ---------------------------------------- |
| 5030 |
// MOC |
| 5031 |
|
| 5032 |
#include "qdjview.moc" |
| 5033 |
|
| 5034 |
|
| 5035 |
/* ------------------------------------------------------------- |
| 5036 |
Local Variables: |
| 5037 |
c++-font-lock-extra-types: ( "\\sw+_t" "[A-Z]\\sw*[a-z]\\sw*" ) |
| 5038 |
End: |
| 5039 |
------------------------------------------------------------- */ |