Skip to content
Permalink
Browse files

implement configurable default zoom mode

  • Loading branch information...
alexandervdm committed Oct 13, 2019
1 parent 87b7018 commit 18e8d6d4ac12f9bcae644246b578e7b9d154c436
Showing with 183 additions and 7 deletions.
  1. +118 −3 data/ui/prefs.glade
  2. +1 −1 src/configfile.c
  3. +36 −0 src/gui/gui-prefs.c
  4. +2 −0 src/gui/gui-prefs.h
  5. +26 −0 src/gui/gui-preview.c
  6. +0 −3 src/tabmanager.c
@@ -49,6 +49,47 @@
<column type="gchararray"/>
</columns>
</object>
<object class="GtkListStore" id="list_zoom_modes">
<columns>
<!-- column-name fixduplicatestoringthis -->
<column type="gchararray"/>
</columns>
<data>
<row>
<col id="0" translatable="yes">Best Fit</col>
</row>
<row>
<col id="0" translatable="yes">Fit Page Width</col>
</row>
<row>
<col id="0" translatable="yes">50%</col>
</row>
<row>
<col id="0" translatable="yes">70%</col>
</row>
<row>
<col id="0" translatable="yes">85%</col>
</row>
<row>
<col id="0" translatable="yes">100%</col>
</row>
<row>
<col id="0" translatable="yes">125%</col>
</row>
<row>
<col id="0" translatable="yes">150%</col>
</row>
<row>
<col id="0" translatable="yes">200%</col>
</row>
<row>
<col id="0" translatable="yes">300%</col>
</row>
<row>
<col id="0" translatable="yes">400%</col>
</row>
</data>
</object>
<object class="GtkListStore" id="liststore1">
<columns>
<!-- column-name column1 -->
@@ -1545,7 +1586,7 @@
<object class="GtkLabel" id="label13">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">PDF Compiling</property>
<property name="label" translatable="yes">PDF compiling</property>
<property name="xalign">0</property>
<attributes>
<attribute name="weight" value="bold"/>
@@ -1655,6 +1696,80 @@
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="box_defaultzoom">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">3</property>
<child>
<object class="GtkLabel" id="label53">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Default zoom mode</property>
<property name="xalign">0</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="padding">5</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox26">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label54">
<property name="width_request">12</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes"> </property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="combo_zoom_modes">
<property name="width_request">300</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="model">list_zoom_modes</property>
<property name="active">0</property>
<signal name="changed" handler="on_combo_zoom_modes_changed" swapped="no"/>
<child>
<object class="GtkCellRendererText" id="cellrenderertext2"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="box_animatescroll">
<property name="visible">True</property>
@@ -1726,7 +1841,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
<child>
@@ -1817,7 +1932,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
<property name="position">3</property>
</packing>
</child>
</object>
@@ -72,7 +72,7 @@ const gchar config_str[] =
"font = Monospace 14\n"
"\n"
"[Preview]\n"
"zoommode = pagewidth\n"
"zoom_mode = Fit Page Width\n"
"pagelayout = one_column\n"
"autosync = False\n"
"animated_scroll = always\n"
@@ -134,6 +134,10 @@ GuPrefsGui* prefsgui_init (GtkWindow* mainwindow) {
p->opt_synctex =
GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, "opt_synctex"));

p->combo_zoom_modes =
GTK_COMBO_BOX (gtk_builder_get_object (builder, "combo_zoom_modes"));
p->list_zoom_modes =
GTK_LIST_STORE (gtk_builder_get_object (builder, "list_zoom_modes"));
p->combo_animated_scroll =
GTK_COMBO_BOX (gtk_builder_get_object (builder, "combo_animated_scroll"));
p->spin_cache_size =
@@ -341,6 +345,29 @@ static void set_tab_preview_settings (GuPrefsGui* prefs) {
if (STR_EQU (config_get_value ("compile_scheme"), "real_time"))
gtk_combo_box_set_active (prefs->compile_scheme, 1);

// default zoom mode:
GtkTreeModel* model = 0;
GtkTreeIter iter;
gboolean valid = FALSE;
gint count = 0;

const gchar *conf_str = config_get_value("zoom_mode");

model = gtk_combo_box_get_model (GTK_COMBO_BOX (prefs->combo_zoom_modes));
valid = gtk_tree_model_get_iter_first (model, &iter);

while (valid) {
const gchar* list_str;
gtk_tree_model_get (model, &iter, 0, &list_str, -1);
if (STR_EQU (list_str, conf_str)) {
gtk_combo_box_set_active (GTK_COMBO_BOX (prefs->combo_zoom_modes), count);
break;
}
++count;
valid = gtk_tree_model_iter_next (model, &iter);
}

// animated scroll:
if (STR_EQU (config_get_value ("animated_scroll"), "always")) {
gtk_combo_box_set_active (prefs->combo_animated_scroll, 0);
} else if (STR_EQU (config_get_value ("animated_scroll"), "never")) {
@@ -740,6 +767,15 @@ void on_combo_compilescheme_changed (GtkWidget* widget, void* user) {
previewgui_reset (gui->previewgui);
}

G_MODULE_EXPORT
void on_combo_zoom_modes_changed (GtkWidget* widget, void* user) {
gint selected = gtk_combo_box_get_active (GTK_COMBO_BOX (widget));
// lazily duplicating this again for now (TODO fix in 0.8.1)
gchar scheme[][16] = {"Best Fit", "Fit Page Width", "50%", "70%", "85%",
"100%", "125%", "150%", "200%", "300%", "400%"};
config_set_value ("zoom_mode", scheme[selected]);
}

G_MODULE_EXPORT
void on_combo_animated_scroll_changed (GtkWidget* widget, void* user) {
gint selected = gtk_combo_box_get_active (GTK_COMBO_BOX (widget));
@@ -72,6 +72,8 @@ struct _GuPrefsGui {
GtkToggleButton* method_texdvipspdf;

GtkComboBox* combo_animated_scroll;
GtkComboBox* combo_zoom_modes;
GtkListStore* list_zoom_modes;
};

GuPrefsGui* prefsgui_init (GtkWindow* mainwindow);
@@ -937,6 +937,32 @@ void previewgui_set_pdffile (GuPreviewGui* pc, const gchar *uri) {
synctex_clear_sync_nodes(pc);

// Restore scale and fit mode
if (!g_active_tab->fit_mode) {
const gchar* conf_zoom = config_get_value ("zoom_mode");
gint new_fit, new_zoom;

// TODO: build a dict like structure combining zoom fit strs with
// id (combo) so we dont have to do this verbose stuff all over the place
if (STR_EQU (conf_zoom, "Best Fit")) new_fit = 0, new_zoom = 0;
else
if (STR_EQU (conf_zoom, "Fit Page Width")) new_fit = 1, new_zoom = 1;
else {
new_fit = 2;
if (STR_EQU (conf_zoom, "50%")) new_zoom = 2;
else if (STR_EQU (conf_zoom, "70%")) new_zoom = 3;
else if (STR_EQU (conf_zoom, "85%")) new_zoom = 4;
else if (STR_EQU (conf_zoom, "100%")) new_zoom = 5;
else if (STR_EQU (conf_zoom, "125%")) new_zoom = 6;
else if (STR_EQU (conf_zoom, "150%")) new_zoom = 7;
else if (STR_EQU (conf_zoom, "200%")) new_zoom = 8;
else if (STR_EQU (conf_zoom, "300%")) new_zoom = 9;
else if (STR_EQU (conf_zoom, "400%")) new_zoom = 10;
else slog (L_ERROR, "should not happen\n");
}
g_active_tab->fit_mode = new_fit;
g_active_tab->zoom_mode = new_zoom;
}

g_signal_handler_block(pc->combo_sizes, pc->combo_sizes_changed_handler);

switch (g_active_tab->fit_mode) {
@@ -125,9 +125,6 @@ void tabmanager_create_tab (OpenAct act, const gchar* filename, gchar* opt) {
g_tabs = g_list_append(g_tabs, tc);
pos = tabmanagergui_create_page (tc, tc->editor);
tabmanagergui_set_current_page (pos);

tc->fit_mode = FIT_WIDTH;
tc->zoom_mode = FIT_WIDTH;
}

tabmanager_set_active_tab (pos);

0 comments on commit 18e8d6d

Please sign in to comment.
You can’t perform that action at this time.