1 /*
2  * Copyright (C) 2004-2010 Geometer Plus <contact@geometerplus.com>
3  *
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.
8  *
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.
13  *
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.
18  */
19 
20 #include <ZLOptionsDialog.h>
21 #include <ZLPaintContext.h>
22 
23 #include <optionEntries/ZLSimpleOptionEntry.h>
24 
25 #include <ZLTextView.h>
26 #include <ZLTextStyle.h>
27 #include <ZLTextStyleCollection.h>
28 #include <ZLTextStyleOptions.h>
29 
30 #include "StyleOptionsPage.h"
31 
32 #include "../../options/FBTextStyle.h"
33 #include "../../bookmodel/FBTextKind.h"
34 
35 static const ZLResourceKey KEY_STYLE("style");
36 static const ZLResourceKey KEY_BASE("Base");
37 
38 static const ZLResourceKey KEY_BOLD("bold");
39 static const ZLResourceKey KEY_ITALIC("italic");
40 static const ZLResourceKey KEY_FONTFAMILY("fontFamily");
41 static const ZLResourceKey KEY_FONTSIZE("fontSize");
42 static const ZLResourceKey KEY_FONTSIZEDIFFERENCE("fontSizeDifference");
43 static const ZLResourceKey KEY_ALLOWHYPHENATIONS("allowHyphenations");
44 static const ZLResourceKey KEY_AUTOHYPHENATIONS("autoHyphenations");
45 static const ZLResourceKey KEY_DUMMY("");
46 
StyleOptionsPage(ZLDialogContent & dialogTab,ZLPaintContext & context)47 StyleOptionsPage::StyleOptionsPage(ZLDialogContent &dialogTab, ZLPaintContext &context) {
48 	const ZLResource &styleResource = ZLResource::resource(KEY_STYLE);
49 
50 	myComboEntry = new ComboOptionEntry(*this, styleResource[KEY_BASE].value());
51 	myComboEntry->addValue(myComboEntry->initialValue());
52 
53 	ZLTextStyleCollection &collection = ZLTextStyleCollection::Instance();
54 	ZLTextKind styles[] = { REGULAR, TITLE, SECTION_TITLE, SUBTITLE, H1, H2, H3, H4, H5, H6, CONTENTS_TABLE_ENTRY, LIBRARY_ENTRY, ANNOTATION, EPIGRAPH, AUTHOR, DATEKIND, POEM_TITLE, STANZA, VERSE, CITE, INTERNAL_HYPERLINK, EXTERNAL_HYPERLINK, BOOK_HYPERLINK, FOOTNOTE, ITALIC, EMPHASIS, BOLD, STRONG, DEFINITION, DEFINITION_DESCRIPTION, PREFORMATTED, CODE };
55 	const int STYLES_NUMBER = sizeof(styles) / sizeof(ZLTextKind);
56 	for (int i = 0; i < STYLES_NUMBER; ++i) {
57 		const ZLTextStyleDecoration *decoration = collection.decoration(styles[i]);
58 		if (decoration != 0) {
59 			myComboEntry->addValue(styleResource[decoration->name()].value());
60 		}
61 	}
62 	dialogTab.addOption(ZLResourceKey("optionsFor"), myComboEntry);
63 
64 	{
65 		const std::string &name = myComboEntry->initialValue();
66 		FBTextStyle &baseStyle = FBTextStyle::Instance();
67 
68 		registerEntry(dialogTab,
69 			KEY_FONTFAMILY, new ZLFontFamilyOptionEntry(baseStyle.FontFamilyOption, context),
70 			name
71 		);
72 
73 		registerEntry(dialogTab,
74 			KEY_FONTSIZE, new ZLSimpleSpinOptionEntry(baseStyle.FontSizeOption, 2),
75 			name
76 		);
77 
78 		registerEntry(dialogTab,
79 			KEY_BOLD, new ZLSimpleBooleanOptionEntry(baseStyle.BoldOption),
80 			name
81 		);
82 
83 		registerEntry(dialogTab,
84 			KEY_ITALIC, new ZLSimpleBooleanOptionEntry(baseStyle.ItalicOption),
85 			name
86 		);
87 
88 		registerEntry(dialogTab,
89 			KEY_AUTOHYPHENATIONS, new ZLSimpleBooleanOptionEntry(collection.AutoHyphenationOption),
90 			name
91 		);
92 	}
93 
94 	for (int i = 0; i < STYLES_NUMBER; ++i) {
95 		ZLTextStyleDecoration *decoration = collection.decoration(styles[i]);
96 		if (decoration != 0) {
97 			const std::string &name = styleResource[decoration->name()].value();
98 
99 			registerEntry(dialogTab,
100 				KEY_FONTFAMILY, new ZLTextFontFamilyWithBaseOptionEntry(decoration->FontFamilyOption, dialogTab.resource(KEY_FONTFAMILY), context),
101 				name
102 			);
103 
104 			registerEntry(dialogTab,
105 				KEY_FONTSIZEDIFFERENCE, new ZLSimpleSpinOptionEntry(decoration->FontSizeDeltaOption, 2),
106 				name
107 			);
108 
109 			registerEntry(dialogTab,
110 				KEY_BOLD, new ZLSimpleBoolean3OptionEntry(decoration->BoldOption),
111 				name
112 			);
113 
114 			registerEntry(dialogTab,
115 				KEY_ITALIC, new ZLSimpleBoolean3OptionEntry(decoration->ItalicOption),
116 				name
117 			);
118 
119 			registerEntry(dialogTab,
120 				KEY_ALLOWHYPHENATIONS, new ZLSimpleBoolean3OptionEntry(decoration->AllowHyphenationsOption),
121 				name
122 			);
123 		}
124 	}
125 
126 	myComboEntry->onValueSelected(0);
127 }
128