Debian Codegraph @

src/qdjviewprefs.cpp

raw
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 #endif
21
22 #include <stddef.h>
23 #include <stdlib.h>
24 #include <math.h>
25 #include <libdjvu/miniexp.h>
26 #include <libdjvu/ddjvuapi.h>
27
28 #include <QColor>
29 #include <QComboBox>
30 #include <QCoreApplication>
31 #include <QDebug>
32 #include <QLineEdit>
33 #include <QMetaEnum>
34 #include <QMetaObject>
35 #include <QMutex>
36 #include <QMutexLocker>
37 #include <QPainter>
38 #include <QPointer>
39 #include <QRect>
40 #include <QRegExp>
41 #include <QSettings>
42 #include <QStringList>
43 #include <QTranslator>
44 #include <QVariant>
45 #include <QWhatsThis>
46 #if QT_VERSION >= 0x60000
47 # define reReplace(s,r,a) (r).replaceIn((s),(a))
48 # define reIndex(s,r,p) (r).indexIn((s),(p))
49 #else
50 # define reReplace(s,r,a) (s).replace((r),(a))
51 # define reIndex(s,r,p) (s).indexOf((r),(p))
52 #endif
53 #if QT_VERSION < 0x60000
54 # include <QRegExpValidator>
55 #else
56 # include <QRegularExpression>
57 # include <QRegularExpressionValidator>
58 #endif
59
60 #include "qdjviewprefs.h"
61 #include "qdjview.h"
62 #include "qdjvu.h"
63 #include "djview.h"
64
65
66
67 // ========================================
68 // QDJVIEWPREFS
69 // ========================================
70
71
72 /*! \class QDjViewPrefs
73 \brief Holds the preferences for the \a QDjView instances. */
74
75 /*! \enum QDjViewPrefs::Option
76 \brief Miscellanenous flags.
77 This enumeration defines flags describing
78 (i) the visibility of the menubar, toolbar, etc.
79 (ii) the page layout flags continuous and side by side.
80 (iii) the interactive capabilities of the djvu widget. */
81
82 /*! \enum QDjViewPrefs::Tool
83 \brief Toolbar flags.
84 This enumeration defines flags describing
85 the composition of the toolbar. */
86
87 /*! \class QDjViewPrefs::Saved
88 \brief Mode dependent preferences.
89 This structure holds the preferences that are
90 saved separately for each viewer mode.
91 There are four copies of this structure,
92 for the standalone viewer mode, for the full screen mode,
93 for the full page plugin mode, and for the embedded plugin mode. */
94
95
96 /*! The default toolbar composition. */
97
98 const QDjViewPrefs::Tools
99 QDjViewPrefs::defaultTools
100 = TOOLBAR_TOP | TOOLBAR_BOTTOM
101 | TOOL_ZOOMCOMBO | TOOL_ZOOMBUTTONS
102 | TOOL_PAGECOMBO | TOOL_PREVNEXT | TOOL_FIRSTLAST
103 | TOOL_BACKFORW
104 | TOOL_OPEN | TOOL_FIND | TOOL_SELECT
105 | TOOL_PRINT | TOOL_LAYOUT
106 | TOOL_WHATSTHIS;
107
108
109 /*! The default set of miscellaneous flags. */
110
111 const QDjViewPrefs::Options
112 QDjViewPrefs::defaultOptions
113 = SHOW_MENUBAR | SHOW_TOOLBAR | SHOW_SIDEBAR
114 | SHOW_STATUSBAR | SHOW_SCROLLBARS
115 | SHOW_FRAME | SHOW_MAPAREAS
116 | HANDLE_MOUSE | HANDLE_KEYBOARD | HANDLE_LINKS
117 | HANDLE_CONTEXTMENU;
118
119
120 static QPointer<QDjViewPrefs> preferences;
121
122
123 /*! Returns the single preference object. */
124
125 QDjViewPrefs *
126 QDjViewPrefs::instance(void)
127 {
128 QMutex mutex;
129 QMutexLocker locker(&mutex);
130 if (! preferences)
131 {
132 preferences = new QDjViewPrefs();
133 preferences->load();
134 }
135 return preferences;
136 }
137
138
139 QDjViewPrefs::Saved::Saved(void)
140 : remember(true),
141 options(defaultOptions),
142 zoom(QDjVuWidget::ZOOM_FITWIDTH),
143 nsBorderBrush(QBrush(Qt::lightGray)),
144 nsBorderSize(8)
145 {
146 }
147
148
149 QDjViewPrefs::QDjViewPrefs(void)
150 : QObject(QCoreApplication::instance()),
151 windowSize(640,400),
152 windowMaximized(false),
153 tools(defaultTools),
154 gamma(2.2),
155 white(QColor(Qt::white)),
156 resolution(100),
157 cacheSize(10*1024*1024),
158 pixelCacheSize(256*1024),
159 lensSize(300),
160 lensPower(3),
161 enableAnimations(true),
162 advancedFeatures(false),
163 showTextLabel(false),
164 invertLuminance(false),
165 mouseWheelZoom(false),
166 restrictOverride(false),
167 openGLAccel(false),
168 slideShowDelay(10),
169 modifiersForLens(Qt::ControlModifier|Qt::ShiftModifier),
170 modifiersForSelect(Qt::ControlModifier),
171 modifiersForLinks(Qt::ShiftModifier),
172 thumbnailSize(64),
173 thumbnailSmart(true),
174 searchWordsOnly(true),
175 searchCaseSensitive(false),
176 searchRegExpMode(false),
177 infoDialogTab(0),
178 metaDialogTab(0),
179 printerGamma(0.0),
180 printReverse(false),
181 printCollate(true)
182 {
183 Options mss = (SHOW_MENUBAR|SHOW_STATUSBAR|SHOW_SIDEBAR);
184 forFullScreen.options &= ~(mss|SHOW_SCROLLBARS|SHOW_TOOLBAR|SHOW_SIDEBAR);
185 forSlideShow = forFullScreen;
186 forSlideShow.zoom = QDjVuWidget::ZOOM_FITPAGE;
187 forSlideShow.remember = false;
188 forSlideShow.nsBorderBrush = QBrush(Qt::black);
189 forFullPagePlugin.options &= ~(mss);
190 forEmbeddedPlugin.options &= ~(mss|SHOW_TOOLBAR);
191 forEmbeddedPlugin.remember = false;
192 forEmbeddedPlugin.zoom = 100;
193 forEmbeddedPlugin.nsBorderBrush = QBrush(Qt::white);
194 forEmbeddedPlugin.nsBorderSize = 0;
195 forStandalone.options |= LAYOUT_CONTINUOUS;
196 forFullScreen.options |= LAYOUT_CONTINUOUS;
197 }
198
199
200 /*! Return a string with the djview version. */
201
202 QString
203 QDjViewPrefs::versionString()
204 {
205 QString version = QString("%1.%2");
206 version = version.arg((DJVIEW_VERSION>>16)&0xFF);
207 version = version.arg((DJVIEW_VERSION>>8)&0xFF);
208 if (DJVIEW_VERSION & 0xFF)
209 version = version + QString(".%1").arg(DJVIEW_VERSION&0xFF);
210 return version;
211 }
212
213
214 /*! Return a string describing a set of modifier keys. */
215
216 QString
217 QDjViewPrefs::modifiersToString(Qt::KeyboardModifiers m)
218 {
219 QStringList l;
220 #ifdef Q_OS_DARWIN
221 if (m & Qt::MetaModifier)
222 l << "Control";
223 if (m & Qt::ControlModifier)
224 l << "Command";
225 #else
226 if (m & Qt::MetaModifier)
227 l << "Meta";
228 if (m & Qt::ControlModifier)
229 l << "Control";
230 #endif
231 if (m & Qt::AltModifier)
232 l << "Alt";
233 if (m & Qt::ShiftModifier)
234 l << "Shift";
235 return l.join("+");
236 }
237
238 /*! Return the modifiers described in string \a s. */
239
240 Qt::KeyboardModifiers
241 QDjViewPrefs::stringToModifiers(QString s)
242 {
243 Qt::KeyboardModifiers m = Qt::NoModifier;
244 QStringList l = s.split("+");
245 foreach(QString key, l)
246 {
247 key = key.toLower();
248 if (key == "shift")
249 m |= Qt::ShiftModifier;
250 else if (key == "alt")
251 m |= Qt::AltModifier;
252 #ifdef Q_OS_DARWIN
253 else if (key == "control")
254 m |= Qt::MetaModifier;
255 else if (key == "command")
256 m |= Qt::ControlModifier;
257 #else
258 else if (key == "meta")
259 m |= Qt::MetaModifier;
260 else if (key == "control")
261 m |= Qt::ControlModifier;
262 #endif
263 }
264 return m;
265 }
266
267
268 /*! Return a string describing a set of option flags. */
269
270 QString
271 QDjViewPrefs::optionsToString(Options options)
272 {
273 const QMetaObject *mo = metaObject();
274 QMetaEnum me = mo->enumerator(mo->indexOfEnumerator("Option"));
275 return me.valueToKeys(static_cast<int>(options));
276 }
277
278 /*! Return the option flags described by a string. */
279
280 QDjViewPrefs::Options
281 QDjViewPrefs::stringToOptions(QString s)
282 {
283 const QMetaObject *mo = metaObject();
284 QMetaEnum me = mo->enumerator(mo->indexOfEnumerator("Option"));
285 int options = me.keysToValue(s.toLatin1());
286 return QFlag(options);
287 }
288
289
290 /*! Return a string describing a set of toolbar flags. */
291
292 QString
293 QDjViewPrefs::toolsToString(Tools tools)
294 {
295 const QMetaObject *mo = metaObject();
296 QMetaEnum me = mo->enumerator(mo->indexOfEnumerator("Tool"));
297 return me.valueToKeys(tools);
298 }
299
300
301 /*! Return the toolbar flags described by a string. */
302
303 QDjViewPrefs::Tools
304 QDjViewPrefs::stringToTools(QString s)
305 {
306 const QMetaObject *mo = metaObject();
307 QMetaEnum me = mo->enumerator(mo->indexOfEnumerator("Tool"));
308 int tools = me.keysToValue(s.toLatin1());
309 return QFlag(tools);
310 }
311
312
313 void
314 QDjViewPrefs::loadGroup(QSettings &s, QString name, Saved &saved)
315 {
316 s.beginGroup(name);
317 if (s.contains("remember"))
318 saved.remember = s.value("remember").toBool();
319 if (s.contains("options"))
320 saved.options = stringToOptions(s.value("options").toString());
321 if (s.contains("zoom"))
322 saved.zoom = s.value("zoom").toInt();
323 if (s.contains("state"))
324 saved.state = s.value("state").toByteArray();
325 s.endGroup();
326 // we always want these options
327 saved.options |= (QDjViewPrefs::HANDLE_MOUSE |
328 QDjViewPrefs::HANDLE_KEYBOARD |
329 QDjViewPrefs::HANDLE_LINKS );
330
331 }
332
333
334 /*! Load recent files */
335
336 void
337 QDjViewPrefs::loadRecent()
338 {
339 QSettings s;
340 if (s.contains("recentFiles"))
341 recentFiles = s.value("recentFiles").toStringList();
342 }
343
344 /*! Load saved preferences and set all member variables. */
345
346 void
347 QDjViewPrefs::load()
348 {
349 // load recent files
350 loadRecent();
351
352 // load everything else
353 QSettings s;
354 int versionFix = 0;
355 if (s.contains("versionFix"))
356 versionFix = s.value("versionFix").toInt();
357 loadGroup(s, "forEmbeddedPlugin", forEmbeddedPlugin);
358 loadGroup(s, "forFullPagePlugin", forFullPagePlugin);
359 loadGroup(s, "forStandalone", forStandalone);
360 loadGroup(s, "forFullScreen", forFullScreen);
361 loadGroup(s, "forSlideShow", forSlideShow);
362 if (s.contains("windowSize"))
363 windowSize = s.value("windowSize").toSize();
364 if (s.contains("windowMaximized"))
365 windowMaximized = s.value("windowMaximized").toBool();
366 if (s.contains("tools"))
367 tools = stringToTools(s.value("tools").toString());
368 if (versionFix < 0x40200)
369 tools |= TOOL_BACKFORW;
370 if (s.contains("gamma"))
371 gamma = s.value("gamma").toDouble();
372 if (s.contains("white"))
373 white = QColor(s.value("white").toString());
374 if (s.contains("resolution"))
375 resolution = s.value("resolution").toInt();
376 if (s.contains("cacheSize"))
377 cacheSize = s.value("cacheSize").toLongLong();
378 if (s.contains("pixelCacheSize"))
379 pixelCacheSize = s.value("pixelCacheSize").toInt();
380 if (s.contains("lensSize"))
381 lensSize = s.value("lensSize").toInt();
382 if (s.contains("lensPower"))
383 lensPower = s.value("lensPower").toInt();
384 if (s.contains("browserProgram"))
385 browserProgram = s.value("browserProgram").toString();
386 if (s.contains("proxyUrl"))
387 proxyUrl = s.value("proxyUrl").toString();
388 if (s.contains("enableAnimations"))
389 enableAnimations = s.value("enableAnimations").toBool();
390 if (s.contains("advancedFeatures"))
391 advancedFeatures = s.value("advancedFeatures").toBool();
392 if (s.contains("showTextLabel"))
393 showTextLabel = s.value("showTextLabel").toBool();
394 if (s.contains("invertLuminance"))
395 invertLuminance = s.value("invertLuminance").toBool();
396 if (s.contains("mouseWheelZoom"))
397 mouseWheelZoom = s.value("mouseWheelZoom").toBool();
398 if (s.contains("language"))
399 languageOverride = s.value("language").toString();
400 if (s.contains("restrictOverride"))
401 restrictOverride = s.value("restrictOverride").toBool();
402 if (s.contains("openGLAccel"))
403 openGLAccel = s.value("openGLAccel").toBool();
404 if (s.contains("slideShowDelay"))
405 slideShowDelay = s.value("slideShowDelay").toInt();
406 if (s.contains("modifiersForLens"))
407 modifiersForLens
408 = stringToModifiers(s.value("modifiersForLens").toString());
409 if (s.contains("modifiersForSelect"))
410 modifiersForSelect
411 = stringToModifiers(s.value("modifiersForSelect").toString());
412 if (s.contains("modifiersForLinks"))
413 modifiersForLinks
414 = stringToModifiers(s.value("modifiersForLinks").toString());
415 if (s.contains("thumbnailSize"))
416 thumbnailSize = s.value("thumbnailSize").toInt();
417 if (s.contains("thumbnailSmart"))
418 thumbnailSmart = s.value("thumbnailSmart").toBool();
419 if (s.contains("searchWordsOnly"))
420 searchWordsOnly = s.value("searchWordsOnly").toBool();
421 if (s.contains("searchCaseSensitive"))
422 searchCaseSensitive = s.value("searchCaseSensitive").toBool();
423 if (s.contains("searchRegExpMode"))
424 searchRegExpMode = s.value("searchRegExpMode").toBool();
425 if (s.contains("infoDialogTab"))
426 infoDialogTab = s.value("infoDialogTab").toInt();
427 if (s.contains("metaDialogTab"))
428 metaDialogTab = s.value("metaDialogTab").toInt();
429 if (s.contains("printerGamma"))
430 printerGamma = s.value("printerGamma").toDouble();
431 if (s.contains("printerName"))
432 printerName = s.value("printerName").toString();
433 if (s.contains("printFile"))
434 printFile = s.value("printFile").toString();
435 if (s.contains("printCollate"))
436 printCollate = s.value("printCollate").toBool();
437 if (s.contains("printReverse"))
438 printCollate = s.value("printReverse").toBool();
439
440 // advertise change
441 emit updated();
442 }
443
444
445 void
446 QDjViewPrefs::saveGroup(QSettings &s, QString name, Saved &saved)
447 {
448 s.beginGroup(name);
449 s.setValue("remember", saved.remember);
450 s.setValue("options", optionsToString(saved.options));
451 s.setValue("zoom", saved.zoom);
452 s.setValue("state", saved.state);
453 s.endGroup();
454 }
455
456
457 /*! Save recent files. */
458
459 void
460 QDjViewPrefs::saveRecent(void)
461 {
462 QSettings s;
463 s.setValue("recentFiles", recentFiles);
464 }
465
466
467 /*! Save remembered state. */
468
469 void
470 QDjViewPrefs::saveRemembered(void)
471 {
472 QSettings s;
473
474 s.setValue("version", versionString());
475 int versionFix = 0;
476 if (s.contains("versionFix"))
477 versionFix = s.value("versionFix").toInt();
478 if (DJVIEW_VERSION > versionFix)
479 s.setValue("versionFix", DJVIEW_VERSION);
480
481 if (forEmbeddedPlugin.remember)
482 saveGroup(s, "forEmbeddedPlugin", forEmbeddedPlugin);
483 if (forFullPagePlugin.remember)
484 saveGroup(s, "forFullPagePlugin", forFullPagePlugin);
485 if (forStandalone.remember)
486 saveGroup(s, "forStandalone", forStandalone);
487 if (forFullScreen.remember)
488 saveGroup(s, "forFullScreen", forFullScreen);
489 if (forSlideShow.remember)
490 saveGroup(s, "forSlideShow", forSlideShow);
491
492 s.setValue("windowSize", windowSize);
493 s.setValue("windowMaximized", windowMaximized);
494 s.setValue("thumbnailSize", thumbnailSize);
495 s.setValue("thumbnailSmart", thumbnailSmart);
496 s.setValue("searchWordsOnly", searchWordsOnly);
497 s.setValue("searchCaseSensitive", searchCaseSensitive);
498 s.setValue("searchRegExpMode", searchRegExpMode);
499 s.setValue("infoDialogTab", infoDialogTab);
500 s.setValue("metaDialogTab", metaDialogTab);
501 s.setValue("printerName", printerName);
502 s.setValue("printFile", printFile);
503 s.setValue("printCollate", printCollate);
504 s.setValue("printReverse", printReverse);
505 }
506
507 /*! Save all member variables for later use. */
508
509 void
510 QDjViewPrefs::save(void)
511 {
512 // save parts
513 saveRecent();
514 saveRemembered();
515
516 // save everything else
517 QSettings s;
518 if (! forEmbeddedPlugin.remember)
519 saveGroup(s, "forEmbeddedPlugin", forEmbeddedPlugin);
520 if (! forFullPagePlugin.remember)
521 saveGroup(s, "forFullPagePlugin", forFullPagePlugin);
522 if (! forStandalone.remember)
523 saveGroup(s, "forStandalone", forStandalone);
524 if (! forFullScreen.remember)
525 saveGroup(s, "forFullScreen", forFullScreen);
526 if (! forSlideShow.remember)
527 saveGroup(s, "forSlideShow", forSlideShow);
528 s.setValue("tools", toolsToString(tools));
529 s.setValue("gamma", gamma);
530 s.setValue("white", white.name());
531 s.setValue("resolution", resolution);
532 s.setValue("cacheSize", cacheSize);
533 s.setValue("pixelCacheSize", pixelCacheSize);
534 s.setValue("lensSize", lensSize);
535 s.setValue("lensPower", lensPower);
536 s.setValue("browserProgram", browserProgram);
537 s.setValue("proxyUrl", proxyUrl.toString());
538 s.setValue("enableAnimations", enableAnimations);
539 s.setValue("advancedFeatures", advancedFeatures);
540 s.setValue("showTextLabel", showTextLabel);
541 s.setValue("invertLuminance", invertLuminance);
542 s.setValue("mouseWheelZoom", mouseWheelZoom);
543 s.setValue("modifiersForLens", modifiersToString(modifiersForLens));
544 s.setValue("modifiersForSelect", modifiersToString(modifiersForSelect));
545 s.setValue("modifiersForLinks", modifiersToString(modifiersForLinks));
546 s.setValue("language", languageOverride);
547 s.setValue("restrictOverride", restrictOverride);
548 s.setValue("openGLAccel", openGLAccel);
549 s.setValue("slideShowDelay", slideShowDelay);
550 s.setValue("printerGamma", printerGamma);
551 }
552
553
554
555 /*! \fn QDjViewPrefs::updated()
556 This signal indicates that viewers should reload the preferences. */
557
558
559
560
561
562
563
564 // ========================================
565 // QDJVIEWGAMMAWIDGET
566 // ========================================
567
568
569 class QDjViewGammaWidget : public QFrame
570 {
571 Q_OBJECT
572 public:
573 QDjViewGammaWidget(QWidget *parent = 0);
574 double gamma() const;
575 public slots:
576 void setGamma(double);
577 void setGammaTimesTen(int);
578 protected:
579 virtual void paintEvent(QPaintEvent *event);
580 private:
581 void paintRect(QPainter &painter, QRect r, bool strip);
582 double g;
583 };
584
585
586 QDjViewGammaWidget::QDjViewGammaWidget(QWidget *parent)
587 : QFrame(parent), g(2.2)
588 {
589 setMinimumSize(64,64);
590 setFrameShape(QFrame::Panel);
591 setFrameShadow(QFrame::Sunken);
592 setLineWidth(1);
593 }
594
595
596 double
597 QDjViewGammaWidget::gamma() const
598 {
599 return g;
600 }
601
602
603 void
604 QDjViewGammaWidget::setGamma(double gamma)
605 {
606 g = qBound(0.3, gamma, 5.0);
607 update();
608 }
609
610
611 void
612 QDjViewGammaWidget::setGammaTimesTen(int gamma)
613 {
614 setGamma((double)gamma/10);
615 }
616
617
618 void
619 QDjViewGammaWidget::paintEvent(QPaintEvent *event)
620 {
621 int w = width() - 16;
622 int h = height() - 16;
623 if (w >= 8 && h >= 8)
624 {
625 QPoint c = rect().center();
626 QPainter painter;
627 painter.begin(this);
628 int m = qMin( w, h ) / 4;
629 m = m + m;
630 QRect r(c.x()-m, c.y()-m, m, m);
631 painter.fillRect(rect(), Qt::white);
632 paintRect(painter, r.translated(m,0), true);
633 paintRect(painter, r.translated(0,m+1), true);
634 paintRect(painter, r.translated(m,m), false);
635 paintRect(painter, r, false);
636 painter.end();
637 QFrame::paintEvent(event);
638 }
639 }
640
641
642 void
643 QDjViewGammaWidget::paintRect(QPainter &painter, QRect r, bool strip)
644 {
645 if (strip)
646 {
647 // draw stripes
648 painter.setPen(QPen(Qt::black, 1));
649 painter.setRenderHint(QPainter::Antialiasing, false);
650 for(int i=r.top(); i<=r.bottom(); i+=2)
651 painter.drawLine(r.left(), i, r.right(), i);
652 }
653 else
654 {
655 // see DjVuImage.cpp
656 double gamma = g;
657 if (gamma < 0.1)
658 gamma = 0.1;
659 else if (gamma > 10)
660 gamma = 10;
661 // see GPixmap.cpp
662 double x = ::pow(0.5, 1.0/gamma);
663 int gray = (int)floor(255.0 * x + 0.5);
664 // fill
665 gray = qBound(0, gray, 255);
666 painter.fillRect(r, QColor(gray,gray,gray));
667 }
668 }
669
670
671
672
673 // ========================================
674 // QDJVIEWMODIFIERSCOMBOBOX
675 // ========================================
676
677
678 class QDjViewModifiersComboBox : public QComboBox
679 {
680 Q_OBJECT
681 Q_PROPERTY(Qt::KeyboardModifiers value READ value WRITE setValue)
682 public:
683 QDjViewModifiersComboBox(QWidget *parent);
684 Qt::KeyboardModifiers value() const;
685 public slots:
686 void setValue(Qt::KeyboardModifiers m);
687 void insertValue(Qt::KeyboardModifiers m);
688 protected slots:
689 void editingFinished();
690 private:
691 static const char *none;
692 };
693
694 const char* QDjViewModifiersComboBox::none = "None";
695
696
697 QDjViewModifiersComboBox::QDjViewModifiersComboBox(QWidget *parent)
698 : QComboBox(parent)
699 {
700 setEditable(true);
701 setInsertPolicy(QComboBox::NoInsert);
702 // validator
703 QStringList keynames;
704 keynames << "Shift";
705 keynames << "Control";
706 keynames << "Alt";
707 #ifdef Q_OS_DARWIN
708 keynames << "Command";
709 #else
710 keynames << "Meta";
711 #endif
712 QString keys = "(" + keynames.join("|") + ")";
713 keys = keys + "(\\+" + keys + ")*";
714 keys = keys + "|" + none;
715 #if QT_VERSION < 0x60000
716 QRegExp re( keys, Qt::CaseInsensitive);
717 setValidator(new QRegExpValidator(re, this));
718 #else
719 QRegularExpression re( keys, QRegularExpression::CaseInsensitiveOption);
720 setValidator(new QRegularExpressionValidator(re, this));
721 #endif
722 // menu entries
723 insertValue(Qt::ShiftModifier);
724 insertValue(Qt::ControlModifier);
725 insertValue(Qt::AltModifier);
726 insertValue(Qt::MetaModifier);
727 insertValue(Qt::ShiftModifier|Qt::ControlModifier);
728 insertValue(Qt::ControlModifier|Qt::AltModifier);
729 setValue(Qt::NoModifier);
730 connect(lineEdit(), SIGNAL(editingFinished()),
731 this, SLOT(editingFinished()) );
732 }
733
734
735 void
736 QDjViewModifiersComboBox::editingFinished()
737 {
738 QDjViewPrefs *prefs = QDjViewPrefs::instance();
739 QString text = lineEdit()->text();
740 Qt::KeyboardModifiers m = prefs->stringToModifiers(text);
741 text = (m) ? prefs->modifiersToString(m) : none;
742 setEditText(text);
743 }
744
745
746 Qt::KeyboardModifiers
747 QDjViewModifiersComboBox::value() const
748 {
749 const_cast<QDjViewModifiersComboBox*>(this)->editingFinished();
750 QString text = lineEdit()->text();
751 QDjViewPrefs *prefs = QDjViewPrefs::instance();
752 return prefs->stringToModifiers(text);
753 }
754
755
756 void
757 QDjViewModifiersComboBox::setValue(Qt::KeyboardModifiers m)
758 {
759 QDjViewPrefs *prefs = QDjViewPrefs::instance();
760 QString text = (m) ? prefs->modifiersToString(m) : none;
761 setEditText(text);
762 }
763
764
765 void
766 QDjViewModifiersComboBox::insertValue(Qt::KeyboardModifiers m)
767 {
768 QDjViewPrefs *prefs = QDjViewPrefs::instance();
769 QString text = (m) ? prefs->modifiersToString(m) : none;
770 QVariant vm(m);
771 if (findData(vm) < 0)
772 insertItem(count(), text, vm);
773 }
774
775
776
777 // ========================================
778 // QDJVIEWPREFSDIALOG
779 // ========================================
780
781
782 #include "ui_qdjviewprefsdialog.h"
783
784
785 static QPointer<QDjViewPrefsDialog> prefsDialog;
786
787
788 /*! Returns the single preference dialog. */
789
790 QDjViewPrefsDialog *
791 QDjViewPrefsDialog::instance()
792 {
793 QMutex mutex;
794 QMutexLocker locker(&mutex);
795 if (! prefsDialog)
796 {
797 QDjViewPrefsDialog *main = new QDjViewPrefsDialog();
798 main->setWindowTitle(tr("Preferences[*] - DjView"));
799 main->setAttribute(Qt::WA_DeleteOnClose, true);
800 main->setAttribute(Qt::WA_QuitOnClose, false);
801 prefsDialog = main;
802 }
803 return prefsDialog;
804 }
805
806
807 struct QDjViewPrefsDialog::Private
808 {
809 QDjVuContext *context;
810 Ui::QDjViewPrefsDialog ui;
811 QDjViewPrefs::Saved saved[5];
812 int slideShowDelay;
813 int currentSaved;
814 };
815
816
817 QDjViewPrefsDialog::~QDjViewPrefsDialog()
818 {
819 delete d;
820 }
821
822
823 static inline void
824 setHelp(QWidget *w, QString s)
825 {
826 w->setWhatsThis(s);
827 }
828
829
830 QDjViewPrefsDialog::QDjViewPrefsDialog()
831 : QDialog(), d(new Private)
832 {
833 // sanitize
834 d->context = 0;
835 d->currentSaved = -1;
836
837 // prepare ui
838 #if QT_VERSION >= 0x60000
839 setWindowModality(Qt::WindowModal);
840 #else
841 setAttribute(Qt::WA_GroupLeader, true);
842 #endif
843 d->ui.setupUi(this);
844
845 // connect buttons (some are connected in the ui file)
846 connect(d->ui.applyButton, SIGNAL(clicked()),
847 this, SLOT(apply()) );
848 connect(d->ui.gammaSlider, SIGNAL(valueChanged(int)),
849 d->ui.gammaWidget, SLOT(setGammaTimesTen(int)) );
850 connect(d->ui.forceResolutionCheckBox, SIGNAL(toggled(bool)),
851 this, SLOT(forceResolutionChanged()) );
852 connect(d->ui.resetButton, SIGNAL(clicked()),
853 this, SLOT(reset()) );
854 connect(d->ui.cacheClearButton, SIGNAL(clicked()),
855 this, SLOT(cacheClear()) );
856 connect(d->ui.modeComboBox, SIGNAL(activated(int)),
857 this, SLOT(modeComboChanged(int)) );
858 connect(d->ui.zoomCombo->lineEdit(), SIGNAL(editingFinished()),
859 this, SLOT(zoomComboEdited()) );
860
861 // modified
862 connectModified(d->ui.screenTab);
863 connectModified(d->ui.rememberCheckBox);
864 connectModified(d->ui.showGroupBox);
865 connectModified(d->ui.modeGroupBox);
866 connectModified(d->ui.keysTab);
867 connectModified(d->ui.lensTab);
868 connectModified(d->ui.networkTab);
869 connectModified(d->ui.advancedTab);
870
871 // whatsthis
872 setHelp(d->ui.screenTab,
873 tr("<html><b>Screen gamma correction.</b>"
874 "<br>The best color rendition is achieved"
875 " by adjusting the gamma correction slider"
876 " and choosing the position that makes the"
877 " gray square as uniform as possible."
878 "<p><b>Screen resolution.</b>"
879 "<br>This option forces a particular resolution instead of using"
880 " the unreliable resolution advertised by the operating system."
881 " Forcing the resolution to 100 dpi matches the behavior"
882 " of the djvulibre command line tools."
883 "</html>") );
884
885 setHelp(d->ui.interfaceTab,
886 tr("<html><b>Initial interface setup.</b>"
887 "<br>DjView can run as a standalone viewer,"
888 " as a full screen viewer, as a full page browser plugin,"
889 " or as a plugin embedded inside a html page."
890 " For each case, check the <tt>Remember</tt> box to"
891 " automatically save and restore the interface setup."
892 " Otherwise, specify an initial configuration."
893 "</html>") );
894
895 setHelp(d->ui.keysTab,
896 tr("<html><b>Modifiers keys.</b>"
897 "<br>Define which combination of modifier keys"
898 " will show the manifying lens, temporarily enable"
899 " the selection mode, or highlight the hyperlinks."
900 "</html>") );
901
902 setHelp(d->ui.lensTab,
903 tr("<html><b>Magnifying lens.</b>"
904 "<br>The magnifying lens appears when you depress"
905 " the modifier keys specified in tab <tt>Keys</tt>."
906 " This panel lets you choose the power and the size"
907 " of the magnifying lens."
908 "</html>") );
909
910 setHelp(d->ui.advancedTab,
911 tr("<html><b>Advanced.</b>"
912 "<br>You can override the default interface language, "
913 "disable the page animations, or enable additional "
914 "menu entries that are useful for authoring DjVu files."
915 "You can also disable the printing or saving restrictions "
916 "dictated by certain web sites. The manual color "
917 "correction can be useful with old printers."
918 "</html>"));
919
920 setHelp(d->ui.networkTab,
921 tr("<html><b>Network proxy settings.</b>"
922 "<br>These proxy settings are used when"
923 " the standalone djview viewer accesses"
924 " a djvu document through a http url."
925 " The djview plugin always uses the proxy"
926 " settings of the web browser."
927 "<p><b>Cache settings.</b>"
928 "<br>The <i>pixel cache</i> stores image data"
929 " located outside the visible area."
930 " This cache makes panning smoother."
931 " The <i>decoded page cache</i> contains partially"
932 " decoded pages. It provides faster response times"
933 " when navigating a multipage document or when returning"
934 " to a previously viewed page. Clearing this cache"
935 " might be useful to reflect a change in the page"
936 " data without restarting the DjVu viewer."""
937 "</html>") );
938 }
939
940
941 void
942 QDjViewPrefsDialog::connectModified(QWidget *w)
943 {
944 if (w->inherits("QComboBox"))
945 connect(w, SIGNAL(editTextChanged(QString)), this, SLOT(setModified()));
946 if (w->inherits("QComboBox"))
947 connect(w, SIGNAL(currentIndexChanged(int)), this, SLOT(setModified()));
948 if (w->inherits("QSpinBox"))
949 connect(w, SIGNAL(valueChanged(int)), this, SLOT(setModified()));
950 if (w->inherits("QAbstractButton"))
951 connect(w, SIGNAL(toggled(bool)), this, SLOT(setModified()));
952 if (w->inherits("QAbstractSlider"))
953 connect(w, SIGNAL(valueChanged(int)), this, SLOT(setModified()));
954 QObject *child;
955 foreach(child, w->children())
956 if (child->isWidgetType())
957 connectModified(qobject_cast<QWidget*>(child));
958 }
959
960 void
961 QDjViewPrefsDialog::load(QDjView *djview)
962 {
963 // load preferences into ui
964 QDjViewPrefs *prefs = QDjViewPrefs::instance();
965 d->context = &djview->getDjVuContext();
966 // 1- screen tab
967 d->ui.gammaSlider->setValue((int)(prefs->gamma * 10));
968 int res = prefs->resolution;
969 d->ui.forceResolutionCheckBox->setChecked(res > 0);
970 d->ui.resolutionSpinBox->setValue((res>0) ? res : logicalDpiY());
971 d->ui.invertLuminanceCheckBox->setChecked(prefs->invertLuminance);
972 // 2- interface tab
973 QComboBox *cb = d->ui.modeComboBox;
974 cb->clear();
975 d->saved[0] = prefs->forStandalone;
976 cb->addItem(tr("Standalone Viewer"),
977 QDjView::STANDALONE);
978 d->saved[1] = prefs->forFullScreen;
979 cb->addItem(tr("Standalone Viewer (Full Screen mode)"),
980 QDjView::STANDALONE_FULLSCREEN);
981 d->saved[2] = prefs->forSlideShow;
982 cb->addItem(tr("Standalone Viewer (Slideshow mode)"),
983 QDjView::STANDALONE_SLIDESHOW);
984 d->saved[3] = prefs->forFullPagePlugin;
985 cb->addItem(tr("Full Page Plugin"),
986 QDjView::FULLPAGE_PLUGIN);
987 d->saved[4] = prefs->forEmbeddedPlugin;
988 cb->addItem(tr("Embedded Plugin"),
989 QDjView::EMBEDDED_PLUGIN);
990 d->slideShowDelay = prefs->slideShowDelay;
991 djview->fillZoomCombo(d->ui.zoomCombo);
992 int n = qMax(0, cb->findData(djview->getViewerMode()));
993 modeComboChanged(n);
994 cb->setCurrentIndex(n);
995 // 3- keys tab
996 d->ui.keysForLensCombo->setValue(prefs->modifiersForLens);
997 d->ui.keysForSelectCombo->setValue(prefs->modifiersForSelect);
998 d->ui.keysForLinksCombo->setValue(prefs->modifiersForLinks);
999 d->ui.wheelScrollButton->setChecked(! prefs->mouseWheelZoom);
1000 d->ui.wheelZoomButton->setChecked(prefs->mouseWheelZoom);
1001 // 4- lens tab
1002 bool lens = (prefs->lensPower > 0) && (prefs->lensSize > 0);
1003 d->ui.lensEnableCheckBox->setChecked(lens);
1004 d->ui.lensPowerSpinBox->setValue(lens ? qBound(1,prefs->lensPower,10) : 3);
1005 d->ui.lensSizeSpinBox->setValue(lens ? qBound(50,prefs->lensSize,500) : 300);
1006 // 5- network tab
1007 bool proxy = prefs->proxyUrl.isValid();
1008 if (prefs->proxyUrl.scheme() != "http" ||
1009 prefs->proxyUrl.host().isEmpty())
1010 proxy = false;
1011 if (proxy)
1012 {
1013 QUrl url = prefs->proxyUrl;
1014 int port = url.port();
1015 d->ui.proxyHostLineEdit->setText(url.host());
1016 d->ui.proxyPortSpinBox->setValue(port>=0 ? port : 8080);
1017 d->ui.proxyUserLineEdit->setText(url.userName());
1018 d->ui.proxyPasswordLineEdit->setText(url.password());
1019 }
1020 d->ui.proxyCheckBox->setChecked(proxy);
1021 qreal k256 = 256 * 1024;
1022 qreal k1024 = 1024 * 1024;
1023 d->ui.pixelCacheSpinBox->setValue(qRound(prefs->pixelCacheSize / k256));
1024 d->ui.pageCacheSpinBox->setValue(qRound(prefs->cacheSize / k1024));
1025 // 6- advanced tab
1026 double pgamma = prefs->printerGamma;
1027 loadLanguageComboBox(prefs->languageOverride);
1028 d->ui.advancedCheckBox->setChecked(prefs->advancedFeatures);
1029 d->ui.animationCheckBox->setChecked(prefs->enableAnimations);
1030 d->ui.textLabelCheckBox->setChecked(prefs->showTextLabel);
1031 d->ui.restrictOverrideCheckBox->setChecked(prefs->restrictOverride);
1032 #if QT_VERSION >= 0x60000
1033 d->ui.openGLCheckBox->setChecked(true);
1034 d->ui.openGLCheckBox->setEnabled(false);
1035 #else
1036 d->ui.openGLCheckBox->setChecked(prefs->openGLAccel);
1037 #endif
1038 d->ui.printerManualCheckBox->setChecked(pgamma > 0);
1039 d->ui.printerGammaSpinBox->setValue((pgamma > 0) ? pgamma : 2.2);
1040 // no longer modified
1041 setWindowModified(false);
1042 d->ui.applyButton->setEnabled(false);
1043 }
1044
1045
1046 void
1047 QDjViewPrefsDialog::loadLanguageComboBox(QString lang)
1048 {
1049 // supported languages
1050 static const char *languages[] = {
1051 "cs","de","en","es","fr","it","ja","pl","ru","uk",
1052 "zh_CN","zh_TW",0 } ;
1053 // get application
1054 QComboBox *cb = d->ui.languageComboBox;
1055 QCheckBox *db = d->ui.languageCheckBox;
1056 QDjViewApplication *app = qobject_cast<QDjViewApplication*>(qApp);
1057 db->setEnabled(app != 0);
1058 cb->clear();
1059 // prepare combobox
1060 static struct { const char *src; const char *com; } thisLang[] = {
1061 QT_TRANSLATE_NOOP3("Generic", "thisLanguage", "Name of THIS language") };
1062 QString myLanguage = QApplication::translate("Generic", thisLang[0].src);
1063 if (myLanguage == thisLang[0].src)
1064 myLanguage = "English";
1065 int index = -1;
1066 if (app)
1067 for (int i=0; languages[i]; i++)
1068 {
1069 QString nlang = languages[i];
1070 QString xlang = QString();
1071 QTranslator *dTrans = new QTranslator();
1072 QTranslator *qTrans = new QTranslator();
1073 if (app->loadTranslators(QStringList(nlang), dTrans, qTrans))
1074 xlang = dTrans->translate("Generic", thisLang[0].src);
1075 else if (nlang == "en" || nlang.startsWith("en"))
1076 xlang = "English";
1077 if (lang == nlang && xlang.size() > 0)
1078 index = cb->count();
1079 if (index < 0 && xlang == myLanguage)
1080 index = cb->count();
1081 if (xlang.size() > 0)
1082 cb->addItem(xlang, nlang);
1083 delete dTrans;
1084 delete qTrans;
1085 }
1086 db->setChecked(index >= 0 && lang.size() > 0);
1087 cb->setCurrentIndex(index);
1088 }
1089
1090 void
1091 QDjViewPrefsDialog::apply()
1092 {
1093 // save ui into preferences
1094 QDjViewPrefs *prefs = QDjViewPrefs::instance();
1095 // 1- screen tab
1096 prefs->gamma = d->ui.gammaSlider->value() / 10.0;
1097 prefs->resolution = 0;
1098 if (d->ui.forceResolutionCheckBox->isChecked())
1099 prefs->resolution = d->ui.resolutionSpinBox->value();
1100 prefs->invertLuminance = d->ui.invertLuminanceCheckBox->isChecked();
1101 // 2- interface tab
1102 QComboBox *cb = d->ui.modeComboBox;
1103 int n = cb->currentIndex();
1104 modeComboChanged(n);
1105 for (int i=0; i<5; i++)
1106 switch (cb->itemData(i).toInt())
1107 {
1108 case QDjView::STANDALONE:
1109 prefs->forStandalone = d->saved[i]; break;
1110 case QDjView::STANDALONE_SLIDESHOW:
1111 prefs->forSlideShow = d->saved[i]; break;
1112 case QDjView::STANDALONE_FULLSCREEN:
1113 prefs->forFullScreen = d->saved[i]; break;
1114 case QDjView::EMBEDDED_PLUGIN:
1115 prefs->forEmbeddedPlugin = d->saved[i]; break;
1116 case QDjView::FULLPAGE_PLUGIN:
1117 prefs->forFullPagePlugin = d->saved[i]; break;
1118 }
1119 // 3- keys
1120 prefs->modifiersForLens = d->ui.keysForLensCombo->value();
1121 prefs->modifiersForSelect = d->ui.keysForSelectCombo->value();
1122 prefs->modifiersForLinks = d->ui.keysForLinksCombo->value();
1123 prefs->mouseWheelZoom = d->ui.wheelZoomButton->isChecked();
1124 // 4- lens tab
1125 bool lens = d->ui.lensEnableCheckBox->isChecked();
1126 prefs->lensPower = (lens) ? d->ui.lensPowerSpinBox->value() : 0;
1127 prefs->lensSize = d->ui.lensSizeSpinBox->value();
1128 // 5- network tab
1129 prefs->proxyUrl = QUrl();
1130 if (d->ui.proxyCheckBox->isChecked())
1131 {
1132 prefs->proxyUrl.setScheme("http");
1133 prefs->proxyUrl.setHost(d->ui.proxyHostLineEdit->text());
1134 prefs->proxyUrl.setPort(d->ui.proxyPortSpinBox->value());
1135 prefs->proxyUrl.setUserName(d->ui.proxyUserLineEdit->text());
1136 prefs->proxyUrl.setPassword(d->ui.proxyPasswordLineEdit->text());
1137 }
1138 prefs->pixelCacheSize = d->ui.pixelCacheSpinBox->value() * 256 * 1024;
1139 prefs->cacheSize = d->ui.pageCacheSpinBox->value() * 1024 * 1024;
1140 // 6- advanced tab
1141 prefs->languageOverride = QString();
1142 if (d->ui.languageCheckBox->isChecked())
1143 {
1144 int n = d->ui.languageComboBox->currentIndex();
1145 prefs->languageOverride = d->ui.languageComboBox->itemData(n).toString();
1146 }
1147 prefs->enableAnimations = d->ui.animationCheckBox->isChecked();
1148 prefs->advancedFeatures = d->ui.advancedCheckBox->isChecked();
1149 prefs->showTextLabel = d->ui.textLabelCheckBox->isChecked();
1150 prefs->restrictOverride = d->ui.restrictOverrideCheckBox->isChecked();
1151 prefs->openGLAccel = d->ui.openGLCheckBox->isChecked();
1152 prefs->printerGamma = 0;
1153 if (d->ui.printerManualCheckBox->isChecked())
1154 prefs->printerGamma = d->ui.printerGammaSpinBox->value();
1155 // broadcast change
1156 setWindowModified(false);
1157 d->ui.applyButton->setEnabled(false);
1158 prefs->save();
1159 emit prefs->updated();
1160 }
1161
1162
1163 void
1164 QDjViewPrefsDialog::reset()
1165 {
1166 // 1- gamma tab
1167 d->ui.gammaSlider->setValue(22);
1168 d->ui.forceResolutionCheckBox->setChecked(true);
1169 d->ui.resolutionSpinBox->setValue(100);
1170 // 2- interface tab
1171 QDjViewPrefs::Saved defsaved;
1172 QDjViewPrefs::Options optMSS = (QDjViewPrefs::SHOW_MENUBAR|
1173 QDjViewPrefs::SHOW_STATUSBAR|
1174 QDjViewPrefs::SHOW_SIDEBAR);
1175 QDjViewPrefs::Options optS = QDjViewPrefs::SHOW_SCROLLBARS;
1176 QDjViewPrefs::Options optT = QDjViewPrefs::SHOW_TOOLBAR;
1177 QComboBox *cb = d->ui.modeComboBox;
1178 for (int i=0; i<5; i++)
1179 {
1180 d->saved[i] = defsaved;
1181 switch (cb->itemData(i).toInt())
1182 {
1183 case QDjView::STANDALONE_SLIDESHOW:
1184 d->saved[i].remember = false;
1185 d->saved[i].zoom = QDjVuWidget::ZOOM_FITPAGE;
1186 /* FALLTHRU */
1187 case QDjView::STANDALONE_FULLSCREEN:
1188 d->saved[i].options &= ~(optMSS|optS|optT);
1189 /* FALLTHRU */
1190 case QDjView::STANDALONE:
1191 break;
1192 case QDjView::EMBEDDED_PLUGIN:
1193 d->saved[i].remember = false;
1194 d->saved[i].options &= ~(optMSS|optT);
1195 d->saved[i].zoom = 100;
1196 break;
1197 case QDjView::FULLPAGE_PLUGIN:
1198 d->saved[i].options &= ~(optMSS);
1199 break;
1200 }
1201 }
1202 d->slideShowDelay = 10;
1203 d->currentSaved = -1;
1204 modeComboChanged(d->ui.modeComboBox->currentIndex());
1205 // 3- keys tab
1206 d->ui.keysForLensCombo->setValue(Qt::ShiftModifier|Qt::ControlModifier);
1207 d->ui.keysForSelectCombo->setValue(Qt::ControlModifier);
1208 d->ui.keysForLinksCombo->setValue(Qt::ShiftModifier);
1209 // 4- lens tab
1210 d->ui.lensEnableCheckBox->setChecked(true);
1211 d->ui.lensPowerSpinBox->setValue(3);
1212 d->ui.lensSizeSpinBox->setValue(300);
1213 // 5- network tab
1214 d->ui.proxyCheckBox->setChecked(false);
1215 d->ui.pixelCacheSpinBox->setValue(1);
1216 d->ui.pageCacheSpinBox->setValue(10);
1217 // 6- advanced tab
1218 d->ui.languageCheckBox->setChecked(false);
1219 d->ui.animationCheckBox->setChecked(true);
1220 d->ui.advancedCheckBox->setChecked(false);
1221 d->ui.textLabelCheckBox->setChecked(false);
1222 d->ui.openGLCheckBox->setChecked(false);
1223 d->ui.printerManualCheckBox->setChecked(false);
1224 d->ui.printerGammaSpinBox->setValue(2.2);
1225 }
1226
1227
1228 void
1229 QDjViewPrefsDialog::setModified()
1230 {
1231 d->ui.applyButton->setEnabled(true);
1232 setWindowModified(true);
1233 }
1234
1235
1236 void
1237 QDjViewPrefsDialog::done(int result)
1238 {
1239 if (result == QDialog::Accepted)
1240 apply();
1241 QDialog::done(result);
1242 }
1243
1244
1245 void
1246 QDjViewPrefsDialog::cacheClear()
1247 {
1248 if (d->context)
1249 ddjvu_cache_clear(*d->context);
1250 }
1251
1252
1253 template<class T> static inline void
1254 set_reset(QFlags<T> &x, T y, bool plus, bool minus=true)
1255 {
1256 if (plus)
1257 x |= y;
1258 else if (minus)
1259 x &= ~y;
1260 }
1261
1262
1263 void
1264 QDjViewPrefsDialog::modeComboChanged(int n)
1265 {
1266 QComboBox *cb = d->ui.modeComboBox;
1267 if (d->currentSaved >=0 && d->currentSaved <5)
1268 {
1269 // save ui values
1270 QDjViewPrefs::Saved &saved = d->saved[d->currentSaved];
1271 saved.remember = d->ui.rememberCheckBox->isChecked();
1272 set_reset(saved.options, QDjViewPrefs::SHOW_MENUBAR,
1273 d->ui.menuBarCheckBox->isChecked() );
1274 set_reset(saved.options, QDjViewPrefs::SHOW_TOOLBAR,
1275 d->ui.toolBarCheckBox->isChecked() );
1276 set_reset(saved.options, QDjViewPrefs::SHOW_SCROLLBARS,
1277 d->ui.scrollBarsCheckBox->isChecked() );
1278 set_reset(saved.options, QDjViewPrefs::SHOW_STATUSBAR,
1279 d->ui.statusBarCheckBox->isChecked() );
1280 set_reset(saved.options, QDjViewPrefs::SHOW_SIDEBAR,
1281 d->ui.sideBarCheckBox->isChecked() );
1282 set_reset(saved.options, QDjViewPrefs::SHOW_FRAME,
1283 d->ui.frameCheckBox->isChecked() );
1284 set_reset(saved.options, QDjViewPrefs::SHOW_MAPAREAS,
1285 d->ui.mapAreasCheckBox->isChecked() );
1286 set_reset(saved.options, QDjViewPrefs::LAYOUT_CONTINUOUS,
1287 d->ui.continuousCheckBox->isChecked() );
1288 set_reset(saved.options, QDjViewPrefs::LAYOUT_SIDEBYSIDE,
1289 d->ui.sideBySideCheckBox->isChecked() );
1290 set_reset(saved.options, QDjViewPrefs::LAYOUT_COVERPAGE,
1291 d->ui.coverPageCheckBox->isChecked() );
1292 set_reset(saved.options, QDjViewPrefs::LAYOUT_RIGHTTOLEFT,
1293 d->ui.rtolCheckBox->isChecked() );
1294 // zoom
1295 bool okay;
1296 int zoomIndex = d->ui.zoomCombo->currentIndex();
1297 QString zoomText = d->ui.zoomCombo->lineEdit()->text();
1298 int zoom = reReplace(zoomText,QRegExp("\\s*%?$"),"").trimmed().toInt(&okay);
1299 if (okay && zoom>=QDjVuWidget::ZOOM_MIN && zoom<=QDjVuWidget::ZOOM_MAX)
1300 saved.zoom = zoom;
1301 else if (zoomIndex >= 0)
1302 saved.zoom = d->ui.zoomCombo->itemData(zoomIndex).toInt();
1303 // delay
1304 if (cb->itemData(d->currentSaved) == QDjView::STANDALONE_SLIDESHOW)
1305 d->slideShowDelay = d->ui.slideShowSpinBox->value();
1306 }
1307 d->currentSaved = n;
1308 if (d->currentSaved >=0 && d->currentSaved <5)
1309 {
1310 // save modified flag
1311 bool modified = isWindowModified();
1312 // load ui values
1313 QDjViewPrefs::Saved &saved = d->saved[d->currentSaved];
1314 d->ui.rememberCheckBox->setChecked(saved.remember);
1315 QDjViewPrefs::Options opt = saved.options;
1316 d->ui.menuBarCheckBox->setChecked(opt & QDjViewPrefs::SHOW_MENUBAR);
1317 d->ui.toolBarCheckBox->setChecked(opt & QDjViewPrefs::SHOW_TOOLBAR);
1318 d->ui.scrollBarsCheckBox->setChecked(opt & QDjViewPrefs::SHOW_SCROLLBARS);
1319 d->ui.statusBarCheckBox->setChecked(opt & QDjViewPrefs::SHOW_STATUSBAR);
1320 d->ui.sideBarCheckBox->setChecked(opt & QDjViewPrefs::SHOW_SIDEBAR);
1321 d->ui.frameCheckBox->setChecked(opt & QDjViewPrefs::SHOW_FRAME);
1322 d->ui.mapAreasCheckBox->setChecked(opt & QDjViewPrefs::SHOW_MAPAREAS);
1323 d->ui.continuousCheckBox->setChecked(opt & QDjViewPrefs::LAYOUT_CONTINUOUS);
1324 d->ui.sideBySideCheckBox->setChecked(opt & QDjViewPrefs::LAYOUT_SIDEBYSIDE);
1325 d->ui.coverPageCheckBox->setChecked(opt & QDjViewPrefs::LAYOUT_COVERPAGE);
1326 d->ui.rtolCheckBox->setChecked(opt & QDjViewPrefs::LAYOUT_RIGHTTOLEFT);
1327 // zoom
1328 int zoomIndex = d->ui.zoomCombo->findData(QVariant(saved.zoom));
1329 d->ui.zoomCombo->clearEditText();
1330 d->ui.zoomCombo->setCurrentIndex(zoomIndex);
1331 if (zoomIndex < 0 &&
1332 saved.zoom >= QDjVuWidget::ZOOM_MIN &&
1333 saved.zoom <= QDjVuWidget::ZOOM_MAX)
1334 d->ui.zoomCombo->setEditText(QString("%1%").arg(saved.zoom));
1335 else if (zoomIndex >= 0)
1336 d->ui.zoomCombo->setEditText(d->ui.zoomCombo->itemText(zoomIndex));
1337 // delay
1338 d->ui.slideShowSpinBox->setValue(d->slideShowDelay);
1339 d->ui.slideShowSpinBox->setVisible(d->currentSaved == 2);
1340 d->ui.slideShowLabel->setVisible(d->currentSaved == 2);
1341 // reset modified flag
1342 setWindowModified(modified);
1343 }
1344 }
1345
1346
1347 void
1348 QDjViewPrefsDialog::zoomComboEdited()
1349 {
1350 bool okay;
1351 QString zoomText = d->ui.zoomCombo->lineEdit()->text();
1352 int zoom = reReplace(zoomText,QRegExp("\\s*%?$"),"").trimmed().toInt(&okay);
1353 if (d->ui.zoomCombo->findText(zoomText) >= 0)
1354 d->ui.zoomCombo->setEditText(zoomText);
1355 else if (okay && zoom >= QDjVuWidget::ZOOM_MIN
1356 && zoom <= QDjVuWidget::ZOOM_MAX)
1357 d->ui.zoomCombo->setEditText(QString("%1%").arg(zoom));
1358 }
1359
1360
1361
1362 void
1363 QDjViewPrefsDialog::forceResolutionChanged()
1364 {
1365 if (! d->ui.forceResolutionCheckBox->isChecked())
1366 d->ui.resolutionSpinBox->setValue(physicalDpiY());
1367 }
1368
1369
1370
1371 // ----------------------------------------
1372 // MOC
1373
1374 #include "qdjviewprefs.moc"
1375
1376
1377 /* -------------------------------------------------------------
1378 Local Variables:
1379 c++-font-lock-extra-types: ( "\\sw+_t" "[A-Z]\\sw*[a-z]\\sw*" )
1380 End:
1381 ------------------------------------------------------------- */