From 4c04ce3614dd71e91641195699bd0d61f8a66319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Thu, 19 Jul 2018 16:38:52 +0200 Subject: [PATCH] further implementation of settings dialog --- glade/CMakeLists.txt | 1 + glade/dialog.glade | 5 +++-- main.c | 6 ++++++ widgets/conv-settings-dialog.c | 37 +++++++++++++++++++++++++++++----- widgets/conv-settings-dialog.h | 17 +++++++++++----- 5 files changed, 54 insertions(+), 12 deletions(-) diff --git a/glade/CMakeLists.txt b/glade/CMakeLists.txt index 8e4f70f..155519b 100644 --- a/glade/CMakeLists.txt +++ b/glade/CMakeLists.txt @@ -2,6 +2,7 @@ add_custom_target(glib-resources DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/resources.c add_custom_command(DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/resources.xml ${CMAKE_CURRENT_SOURCE_DIR}/main.glade + ${CMAKE_CURRENT_SOURCE_DIR}/dialog.glade ${CMAKE_CURRENT_SOURCE_DIR}/layer-widget.glade OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/resources.c diff --git a/glade/dialog.glade b/glade/dialog.glade index 88a35a1..fd462bc 100644 --- a/glade/dialog.glade +++ b/glade/dialog.glade @@ -45,11 +45,12 @@ - + True True adjustment1 - 1 + 0 + 0 False diff --git a/main.c b/main.c index 38f814a..69b9d62 100644 --- a/main.c +++ b/main.c @@ -23,6 +23,7 @@ #include "layer-selector.h" #include "tree-renderer/tree-store.h" #include "latex-output/latex-output.h" +#include "widgets/conv-settings-dialog.h" struct open_button_data { GtkWindow *main_window; @@ -168,9 +169,14 @@ static void on_convert_clicked(gpointer button, gpointer user) struct gds_cell *cell_to_render; FILE *tex_file; GtkWidget *dialog; + RendererSettingsDialog *settings; gint res; char *file_name; + settings = renderer_settings_dialog_new(GTK_WINDOW(data->main_window)); + gtk_dialog_run(GTK_DIALOG(settings)); + gtk_widget_destroy(GTK_WIDGET(settings)); + /* Get selected cell */ selection = gtk_tree_view_get_selection(data->tree_view); if (gtk_tree_selection_get_selected(selection, &model, &iter) == FALSE) diff --git a/widgets/conv-settings-dialog.c b/widgets/conv-settings-dialog.c index d68f515..7ce267f 100644 --- a/widgets/conv-settings-dialog.c +++ b/widgets/conv-settings-dialog.c @@ -19,8 +19,17 @@ #include "conv-settings-dialog.h" +struct _RendererSettingsDialog { + GtkDialog parent; + /* Private loot */ + GtkWidget *radio_latex; // Only Latex-radio. Other one is implicit + GtkWidget *scale; +}; + G_DEFINE_TYPE(RendererSettingsDialog, renderer_settings_dialog, GTK_TYPE_DIALOG) + + static void renderer_settings_dialog_class_init(RendererSettingsDialogClass *klass) { /* No special code needed. Child cells are destroyed automatically due to reference counter */ @@ -30,19 +39,37 @@ static void renderer_settings_dialog_class_init(RendererSettingsDialogClass *kla static void renderer_settings_dialog_init(RendererSettingsDialog *self) { GtkBuilder *builder; - GtkBox *box; + GtkWidget *box; GtkDialog *dialog; + dialog = &(self->parent); builder = gtk_builder_new_from_resource("/dialog.glade"); - box = GTK_BOX(gtk_builder_get_object(builder, "dialog-box")); + box = GTK_WIDGET(gtk_builder_get_object(builder, "dialog-box")); + self->radio_latex = GTK_WIDGET(gtk_builder_get_object(builder, "latex-radio")); + self->scale = GTK_WIDGET(gtk_builder_get_object(builder, "dialog-scale")); gtk_dialog_add_buttons(dialog, "Cancel", GTK_RESPONSE_CANCEL, "OK", GTK_RESPONSE_OK, NULL); - gtk_container_add(GTK_CONTAINER(dialog), box); + gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(dialog)), box); g_object_unref(builder); } -GtkWidget *renderer_settings_dialog_new(void) +RendererSettingsDialog *renderer_settings_dialog_new(GtkWindow *parent) { - return (GtkWidget *) g_object_new(RENDERER_TYPE_SETTINGS_DIALOG, NULL); + RendererSettingsDialog *res; + + res = RENDERER_SETTINGS_DIALOG(g_object_new(RENDERER_TYPE_SETTINGS_DIALOG, NULL)); + if (res && parent) { + gtk_window_set_transient_for(GTK_WINDOW(res), parent); + } + return res; } + +void renderer_settings_dialog_set_settings(RendererSettingsDialog *dialog, struct render_settings *settings) +{ + if (!settings) + return; + settings->scale = gtk_range_get_value(GTK_RANGE(dialog->scale)); + settings->renderer = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dialog->radio_latex)) == TRUE ? RENDERER_LATEX_TIKZ : RENDERER_CAIROGRAPHICS); +} +void renderer_settings_dialog_get_settings(RendererSettingsDialog *dialog, struct render_settings *settings); diff --git a/widgets/conv-settings-dialog.h b/widgets/conv-settings-dialog.h index cb61916..4c2b32c 100644 --- a/widgets/conv-settings-dialog.h +++ b/widgets/conv-settings-dialog.h @@ -24,16 +24,23 @@ G_BEGIN_DECLS +enum output_renderer {RENDERER_LATEX_TIKZ, RENDERER_CAIROGRAPHICS}; + G_DECLARE_FINAL_TYPE(RendererSettingsDialog, renderer_settings_dialog, RENDERER, SETTINGS_DIALOG, GtkDialog) -GtkWidget *renderer_settings_dialog_new(void); - -struct _RendererSettingsDialog { - GtkDialog parent; -}; +RendererSettingsDialog *renderer_settings_dialog_new(GtkWindow *parent); #define RENDERER_TYPE_SETTINGS_DIALOG (renderer_settings_dialog_get_type()) +struct render_settings { + double scale; + enum output_renderer renderer; +}; + G_END_DECLS + +void renderer_settings_dialog_set_settings(RendererSettingsDialog *dialog, struct render_settings *settings); +void renderer_settings_dialog_get_settings(RendererSettingsDialog *dialog, struct render_settings *settings); + #endif /* __CONV_SETTINGS_DIALOG_H__ */