plugin code
[lbook_fbreader.git] / fbreader / src / optionsDialog / IndicatorTab.cpp
blobd8a76a48b1fd785e7a3add32937114e9cfbc6042
1 /*
2 * Copyright (C) 2004-2008 Geometer Plus <contact@geometerplus.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
20 #include <ZLOptionsDialog.h>
22 #include <optionEntries/ZLToggleBooleanOptionEntry.h>
24 #include <ZLTextStyleOptions.h>
26 #include "OptionsDialog.h"
28 #include "../fbreader/FBReader.h"
29 #include "../fbreader/FBView.h"
30 #include "../fbreader/BookTextView.h"
32 class StateOptionEntry : public ZLToggleBooleanOptionEntry {
34 public:
35 StateOptionEntry(ZLBooleanOption &option);
36 void onStateChanged(bool state);
38 private:
39 bool myState;
41 friend class SpecialFontSizeEntry;
44 class SpecialFontSizeEntry : public ZLSimpleSpinOptionEntry {
46 public:
47 SpecialFontSizeEntry(ZLIntegerRangeOption &option, int step, StateOptionEntry &first, StateOptionEntry &second);
48 void setVisible(bool state);
50 private:
51 StateOptionEntry &myFirst;
52 StateOptionEntry &mySecond;
55 StateOptionEntry::StateOptionEntry(ZLBooleanOption &option) : ZLToggleBooleanOptionEntry(option) {
56 myState = option.value();
59 void StateOptionEntry::onStateChanged(bool state) {
60 myState = state;
61 ZLToggleBooleanOptionEntry::onStateChanged(state);
64 SpecialFontSizeEntry::SpecialFontSizeEntry(ZLIntegerRangeOption &option, int step, StateOptionEntry &first, StateOptionEntry &second) : ZLSimpleSpinOptionEntry(option, step), myFirst(first), mySecond(second) {
67 void SpecialFontSizeEntry::setVisible(bool) {
68 ZLSimpleSpinOptionEntry::setVisible(
69 (myFirst.isVisible() && myFirst.myState) ||
70 (mySecond.isVisible() && mySecond.myState)
74 void OptionsDialog::createIndicatorTab(FBReader &fbreader) {
75 ZLDialogContent &indicatorTab = myDialog->createTab(ZLResourceKey("Indicator"));
76 FBIndicatorStyle &indicatorInfo = FBView::commonIndicatorInfo();
77 ZLToggleBooleanOptionEntry *showIndicatorEntry =
78 new ZLToggleBooleanOptionEntry(indicatorInfo.ShowOption);
79 indicatorTab.addOption(ZLResourceKey("show"), showIndicatorEntry);
81 ZLOptionEntry *heightEntry =
82 new ZLSimpleSpinOptionEntry(indicatorInfo.HeightOption, 1);
83 ZLOptionEntry *offsetEntry =
84 new ZLSimpleSpinOptionEntry(indicatorInfo.OffsetOption, 1);
85 indicatorTab.addOptions(ZLResourceKey("height"), heightEntry, ZLResourceKey("offset"), offsetEntry);
86 showIndicatorEntry->addDependentEntry(heightEntry);
87 showIndicatorEntry->addDependentEntry(offsetEntry);
89 StateOptionEntry *showTextPositionEntry =
90 new StateOptionEntry(indicatorInfo.ShowTextPositionOption);
91 indicatorTab.addOption(ZLResourceKey("pageNumber"), showTextPositionEntry);
92 showIndicatorEntry->addDependentEntry(showTextPositionEntry);
94 StateOptionEntry *showTimeEntry =
95 new StateOptionEntry(indicatorInfo.ShowTimeOption);
96 indicatorTab.addOption(ZLResourceKey("time"), showTimeEntry);
97 showIndicatorEntry->addDependentEntry(showTimeEntry);
99 SpecialFontSizeEntry *fontSizeEntry =
100 new SpecialFontSizeEntry(indicatorInfo.FontSizeOption, 2, *showTextPositionEntry, *showTimeEntry);
101 indicatorTab.addOption(ZLResourceKey("fontSize"), fontSizeEntry);
102 showIndicatorEntry->addDependentEntry(fontSizeEntry);
103 showTextPositionEntry->addDependentEntry(fontSizeEntry);
104 showTimeEntry->addDependentEntry(fontSizeEntry);
106 ZLOptionEntry *tocMarksEntry =
107 new ZLSimpleBooleanOptionEntry(fbreader.bookTextView().ShowTOCMarksOption);
108 indicatorTab.addOption(ZLResourceKey("tocMarks"), tocMarksEntry);
109 showIndicatorEntry->addDependentEntry(tocMarksEntry);
111 ZLOptionEntry *navigationEntry =
112 new ZLSimpleBooleanOptionEntry(indicatorInfo.IsSensitiveOption);
113 indicatorTab.addOption(ZLResourceKey("navigation"), navigationEntry);
114 showIndicatorEntry->addDependentEntry(navigationEntry);
116 showIndicatorEntry->onStateChanged(showIndicatorEntry->initialState());
117 showTextPositionEntry->onStateChanged(showTextPositionEntry->initialState());
118 showTimeEntry->onStateChanged(showTimeEntry->initialState());