config.cpp 4.77 KB
Newer Older
Philipp Erhardt's avatar
Philipp Erhardt committed
1
2
3
4
5
6
7
8
9
10
#include "config.h"
#include <QHashIterator>


CFG::CFG() :
		settings(QSettings::IniFormat, QSettings::UserScope, "katarakt") {
	// TODO warn about invalid user input

	settings.beginGroup("Settings");
	// canvas options
11
12
	defaults["background_color"] = "0xDF000000";
	defaults["background_color_fullscreen"] = "0xFF000000";
13
	defaults["default_layout"] = "presentation";
Philipp Erhardt's avatar
Philipp Erhardt committed
14
15
	defaults["mouse_wheel_factor"] = 120; // (qt-)delta for turning the mouse wheel 1 click
	defaults["smooth_scroll_delta"] = 30; // pixel scroll offset
Philipp Erhardt's avatar
Philipp Erhardt committed
16
	defaults["screen_scroll_factor"] = 0.9; // creates overlap for scrolling 1 screen down, should be <= 1
Philipp Erhardt's avatar
Philipp Erhardt committed
17
18
19
20
21
22
23
24
25
26
27
28
29
	// layout options
	defaults["useless_gap"] = 2;
	defaults["min_page_width"] = 150;
	defaults["min_zoom"] = -14;
	defaults["max_zoom"] = 30;
	defaults["zoom_factor"] = 0.05;
	defaults["prefetch_count"] = 3;
	defaults["search_padding"] = 0.2; // must be <= 0.5
	// resourcemanager options
	defaults["smooth_downscaling"] = true; // filter when creating thumbnail image
	defaults["thumbnail_size"] = 32;
	// search options
	defaults["rect_expansion"] = 2;
30
	// viewer options
31
	defaults["quit_on_init_fail"] = false;
32
	defaults["icon_theme"] = "";
33
34
35
36
37

	// mouse buttons
	defaults["click_link_button"] = 1;
	defaults["drag_view_button"] = 2;
	defaults["select_text_button"] = 1;
Philipp Erhardt's avatar
Philipp Erhardt committed
38
39
	settings.endGroup();

40
41
42
	tmp_values["start_page"] = 0;
	tmp_values["fullscreen"] = false;

43
	settings.beginGroup("Keys");
Philipp Erhardt's avatar
Philipp Erhardt committed
44
45
46
	// canvas keys
	keys["set_presentation_layout"] = QStringList() << "1";
	keys["set_grid_layout"] = QStringList() << "2";
47
	keys["set_presenter_layout"] = QStringList() << "3";
Philipp Erhardt's avatar
Philipp Erhardt committed
48
49
	keys["page_up"] = QStringList() << "PgUp";
	keys["page_down"] = QStringList() << "PgDown";
50
51
	keys["page_first"] = QStringList() << "Home" << "G";
	keys["page_last"] = QStringList() << "End" << "Shift+G";
Philipp Erhardt's avatar
Philipp Erhardt committed
52
53
54
55
56
57
58
59
	keys["half_screen_up"] = QStringList() << "Ctrl+U";
	keys["half_screen_down"] = QStringList() << "Ctrl+D";
	keys["screen_up"] = QStringList() << "Backspace" << "Ctrl+B";
	keys["screen_down"] = QStringList() << "Space" << "Ctrl+F";
	keys["smooth_up"] = QStringList() << "Up" << "K";
	keys["smooth_down"] = QStringList() << "Down" << "J";
	keys["smooth_left"] = QStringList() << "Left" << "H";
	keys["smooth_right"] = QStringList() << "Right" << "L";
Philipp Erhardt's avatar
Philipp Erhardt committed
60
61
62
63
64
	keys["zoom_in"] = QStringList() << "=" << "+";
	keys["zoom_out"] = QStringList() << "-";
	keys["reset_zoom"] = QStringList() << "Z";
	keys["columns_inc"] = QStringList() << "]";
	keys["columns_dec"] = QStringList() << "[";
Philipp Erhardt's avatar
Philipp Erhardt committed
65
66
	keys["offset_inc"] = QStringList() << "}";
	keys["offset_dec"] = QStringList() << "{";
Philipp Erhardt's avatar
Philipp Erhardt committed
67
68
69
	keys["toggle_overlay"] = QStringList() << "T";
	keys["quit"] = QStringList() << "Q" << "W,E,E,E";
	keys["search"] = QStringList() << "/";
70
	keys["search_backward"] = QStringList() << "?";
Philipp Erhardt's avatar
Philipp Erhardt committed
71
72
	keys["next_hit"] = QStringList() << "N";
	keys["previous_hit"] = QStringList() << "Shift+N";
73
74
	keys["next_invisible_hit"] = QStringList() << "Ctrl+N";
	keys["previous_invisible_hit"] = QStringList() << "Ctrl+Shift+N";
Philipp Erhardt's avatar
Philipp Erhardt committed
75
	keys["focus_goto"] = QStringList() << "Ctrl+G";
76
77
	keys["rotate_left"] = QStringList() << ",";
	keys["rotate_right"] = QStringList() << ".";
Philipp Erhardt's avatar
Philipp Erhardt committed
78
79
	keys["jump_back"] = QStringList() << "Ctrl+O" << "Alt+Left";
	keys["jump_forward"] = QStringList() << "Ctrl+I" << "Alt+Right";
80
81
	keys["mark_jump"] = QStringList() << "M";
	keys["toggle_invert_colors"] = QStringList() << "I";
Philipp Erhardt's avatar
Philipp Erhardt committed
82
83
84
85
	// viewer keys
	keys["toggle_fullscreen"] = QStringList() << "F";
	keys["close_search"] = QStringList() << "Esc";
	keys["reload"] = QStringList() << "R";
86
	keys["open"] = QStringList() << "O";
Philipp Erhardt's avatar
Philipp Erhardt committed
87
	keys["toggle_toc"] = QStringList() << "F9";
Philipp Erhardt's avatar
Philipp Erhardt committed
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
	settings.endGroup();
}

CFG::CFG(const CFG &/*other*/) {
}

CFG &CFG::operator=(const CFG &/*other*/) {
	return *this;
}

CFG::~CFG() {
//	set_defaults(); // uncomment to create ini file with all the default settings
}

void CFG::set_defaults() {
	settings.beginGroup("Settings");
	QHashIterator<QString,QVariant> it(defaults);
	while (it.hasNext()) {
		it.next();
		settings.setValue(it.key(), it.value());
	}
	settings.endGroup();

	settings.beginGroup("Keys");
	QHashIterator<QString,QStringList> i2(keys);
	while (i2.hasNext()) {
		i2.next();
		settings.setValue(i2.key(), i2.value());
	}
	settings.endGroup();
}

CFG *CFG::get_instance() {
	static CFG instance;
	return &instance;
}

QVariant CFG::get_value(const char *key) const {
	return settings.value(QString("Settings/") + key, defaults[key]);
}

void CFG::set_value(const char *key, QVariant value) {
	settings.setValue(QString("Settings/") + key, value);
}

133
134
135
136
137
138
139
140
QVariant CFG::get_tmp_value(const char *key) const {
	return tmp_values[key];
}

void CFG::set_tmp_value(const char *key, QVariant value) {
	tmp_values[key] = value;
}

141
142
143
144
bool CFG::has_tmp_value(const char *key) const {
	return tmp_values.contains(key);
}

Philipp Erhardt's avatar
Philipp Erhardt committed
145
146
147
148
QStringList CFG::get_keys(const char *action) const {
	return settings.value(QString("Keys/") + action, keys[action]).toStringList();
}