1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Authors:
3  *   Lauris Kaplinski <lauris@kaplinski.com>
4  *   bulia byak <buliabyak@users.sf.net>
5  *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
6  *
7  * Copyright (C) 1999-2007 Authors
8  * Copyright (C) 2001-2002 Ximian, Inc.
9  *
10  * Released under GNU GPL v2+, read the file 'COPYING' for more information.
11  */
12 
13 #ifndef SP_EXPORT_H
14 #define SP_EXPORT_H
15 
16 #include <gtkmm/checkbutton.h>
17 #include <gtkmm/comboboxtext.h>
18 #include <gtkmm/expander.h>
19 #include <gtkmm/grid.h>
20 #include <gtkmm/progressbar.h>
21 #include <gtkmm/radiobutton.h>
22 #include <gtkmm/spinbutton.h>
23 
24 #include "extension/output.h"
25 #include "ui/dialog/dialog-base.h"
26 #include "ui/widget/scrollprotected.h"
27 
28 namespace Inkscape {
29 namespace UI {
30 namespace Dialog {
31 
32 class ExportProgressDialog;
33 
34 /** What type of button is being pressed */
35 enum selection_type {
36     SELECTION_PAGE = 0,  /**< Export the whole page */
37     SELECTION_DRAWING,   /**< Export everything drawn on the page */
38     SELECTION_SELECTION, /**< Export everything that is selected */
39     SELECTION_CUSTOM,    /**< Allows the user to set the region exported */
40     SELECTION_NUMBER_OF  /**< A counter for the number of these guys */
41 };
42 
43 /**
44  * A dialog widget to export to various image formats such as bitmap and png.
45  *
46  * Creates a dialog window for exporting an image to a bitmap if one doesn't already exist and
47  * shows it to the user. If the dialog has already been created, it simply shows the window.
48  *
49  */
50 class Export : public DialogBase
51 {
52 public:
53     Export ();
54     ~Export () override;
55 
getInstance()56     static Export &getInstance() {
57         return *new Export();
58     }
59 
60 private:
61 
62     /**
63      * A function to set the xdpi.
64      *
65      * This function grabs all of the x values and then figures out the
66      * new bitmap size based on the changing dpi value.  The dpi value is
67      * gotten from the xdpi setting as these can not currently be independent.
68      *
69      */
70     void setImageX();
71 
72     /**
73      * A function to set the ydpi.
74      *
75      * This function grabs all of the y values and then figures out the
76      * new bitmap size based on the changing dpi value.  The dpi value is
77      * gotten from the xdpi setting as these can not currently be independent.
78      */
79     void setImageY();
80     bool bbox_equal(Geom::Rect const &one, Geom::Rect const &two);
81     void updateCheckbuttons ();
82     inline void findDefaultSelection();
83     void detectSize();
84     void setArea ( double x0, double y0, double x1, double y1);
85     /*
86      * Getter/setter style functions for the spinbuttons
87      */
88     void setValue(Glib::RefPtr<Gtk::Adjustment>& adj, double val);
89     void setValuePx(Glib::RefPtr<Gtk::Adjustment>& adj, double val);
90     float getValue(Glib::RefPtr<Gtk::Adjustment>& adj);
91     float getValuePx(Glib::RefPtr<Gtk::Adjustment>& adj);
92 
93     /**
94      * Helper function to create, style and pack spinbuttons for the export dialog.
95      *
96      * Creates a new spin button for the export dialog.
97      * @param  key  The name of the spin button
98      * @param  val  A default value for the spin button
99      * @param  min  Minimum value for the spin button
100      * @param  max  Maximum value for the spin button
101      * @param  step The step size for the spin button
102      * @param  page Size of the page increment
103      * @param  t    Table to put the spin button in
104      * @param  x    X location in the table \c t to start with
105      * @param  y    Y location in the table \c t to start with
106      * @param  ll   Text to put on the left side of the spin button (optional)
107      * @param  lr   Text to put on the right side of the spin button (optional)
108      * @param  digits  Number of digits to display after the decimal
109      * @param  sensitive  Whether the spin button is sensitive or not
110      * @param  cb   Callback for when this spin button is changed (optional)
111      *
112      * No unit_selector is stored in the created spinbutton, relies on external unit management
113      */
114     Glib::RefPtr<Gtk::Adjustment> createSpinbutton( gchar const *key,
115             double val, double min, double max, double step, double page,
116                                                     Gtk::Grid *t, int x, int y,
117                                                     const Glib::ustring& ll, const Glib::ustring& lr,
118                                                     int digits, unsigned int sensitive,
119                                                     void (Export::*cb)() );
120 
121     /**
122      * One of the area select radio buttons was pressed
123      */
124     void onAreaTypeToggled();
125     void refreshArea();
126 
127     /**
128      * Export button callback
129      */
130     void onExport ();
131     void _export_raster(Inkscape::Extension::Output *extension);
132 
133     /**
134      * File Browse button callback
135      */
136     void onBrowse ();
137 
138     /**
139      * Area X value changed callback
140      */
onAreaX0Change()141     void onAreaX0Change() {
142         areaXChange(x0_adj);
143     } ;
onAreaX1Change()144     void onAreaX1Change() {
145         areaXChange(x1_adj);
146     } ;
147     void areaXChange(Glib::RefPtr<Gtk::Adjustment>& adj);
148 
149     /**
150      * Area Y value changed callback
151      */
onAreaY0Change()152     void onAreaY0Change() {
153         areaYChange(y0_adj);
154     } ;
onAreaY1Change()155     void onAreaY1Change() {
156         areaYChange(y1_adj);
157     } ;
158     void areaYChange(Glib::RefPtr<Gtk::Adjustment>& adj);
159 
160     /**
161      * Unit changed callback
162      */
163     void onUnitChanged();
164 
165     /**
166      * Hide except selected callback
167      */
168     void onHideExceptSelected ();
169 
170     /**
171      * Area width value changed callback
172      */
173     void onAreaWidthChange   ();
174 
175     /**
176      * Area height value changed callback
177      */
178     void onAreaHeightChange  ();
179 
180     /**
181      * Bitmap width value changed callback
182      */
183     void onBitmapWidthChange ();
184 
185     /**
186      * Bitmap height value changed callback
187      */
188     void onBitmapHeightChange ();
189 
190     /**
191      * Export xdpi value changed callback
192      */
193     void onExportXdpiChange ();
194 
195     /**
196      * Batch export callback
197      */
198     void onBatchClicked ();
199 
200     /**
201      * Inkscape selection change callback
202      */
203     void onSelectionChanged ();
204     void onSelectionModified (guint flags);
205 
206     /**
207      * Filename modified callback
208      */
209     void onFilenameModified ();
210 
211     /**
212      * Can be invoked for setting the desktop. Currently not used.
213      */
214     void setDesktop(SPDesktop *desktop);
215 
216     /**
217      * Update active window.
218      */
219     void update() override;
220 
221     /**
222      * Creates progress dialog for batch exporting.
223      *
224      * @param progress_text Text to be shown in the progress bar
225      */
226     ExportProgressDialog * create_progress_dialog(Glib::ustring progress_text);
227 
228     /**
229      * Callback to be used in for loop to update the progress bar.
230      *
231      * @param value number between 0 and 1 indicating the fraction of progress (0.17 = 17 % progress)
232      * @param dlg void pointer to the Gtk::Dialog progress dialog
233      */
234     static unsigned int onProgressCallback(float value, void *dlg);
235 
236     /**
237      * Callback for pressing the cancel button.
238      */
239     void onProgressCancel ();
240 
241     /**
242      * Callback invoked on closing the progress dialog.
243      */
244     bool onProgressDelete (GdkEventAny *event);
245 
246     /**
247      * Handles state changes as exporting starts or stops.
248      */
249     void setExporting(bool exporting, Glib::ustring const &text = "");
250 
251     /*
252      * Utility filename and path functions
253      */
254     void set_default_filename ();
255 
256     /*
257      * Currently selected export area type
258      * can be changed by code
259      */
260     selection_type current_key;
261     /*
262      * Manually selected export area type(only changed by buttons)
263      */
264     selection_type manual_key;
265     /*
266      * Original name for the export object
267      */
268     Glib::ustring original_name;
269     Glib::ustring doc_export_name;
270     /*
271      * Was the Original name modified
272      */
273     bool filename_modified;
274 
275     /*
276      * Flag to stop simultaneous updates
277      */
278     bool update_flag;
279 
280     /* Area selection radio buttons */
281     Gtk::Box togglebox;
282     Gtk::RadioButton *selectiontype_buttons[SELECTION_NUMBER_OF];
283 
284     Gtk::Box area_box;
285     Gtk::Box singleexport_box;
286 
287     /* Custom size widgets */
288     Glib::RefPtr<Gtk::Adjustment> x0_adj;
289     Glib::RefPtr<Gtk::Adjustment> x1_adj;
290     Glib::RefPtr<Gtk::Adjustment> y0_adj;
291     Glib::RefPtr<Gtk::Adjustment> y1_adj;
292     Glib::RefPtr<Gtk::Adjustment> width_adj;
293     Glib::RefPtr<Gtk::Adjustment> height_adj;
294 
295     /* Bitmap size widgets */
296     Glib::RefPtr<Gtk::Adjustment> bmwidth_adj;
297     Glib::RefPtr<Gtk::Adjustment> bmheight_adj;
298     Glib::RefPtr<Gtk::Adjustment> xdpi_adj;
299     Glib::RefPtr<Gtk::Adjustment> ydpi_adj;
300 
301     Gtk::Box size_box;
302     Gtk::Label* bm_label;
303 
304     Gtk::Box file_box;
305     Gtk::Label *flabel;
306     Gtk::Entry filename_entry;
307 
308     /* Unit selector widgets */
309     Gtk::Box unitbox;
310     Inkscape::UI::Widget::UnitMenu unit_selector;
311     Gtk::Label units_label;
312 
313     /* Filename widgets  */
314     Gtk::Box filename_box;
315     Gtk::Button browse_button;
316     Gtk::Label browse_label;
317     Gtk::Image browse_image;
318 
319     Gtk::Box batch_box;
320     Gtk::CheckButton    batch_export;
321 
322     Gtk::Box hide_box;
323     Gtk::CheckButton    hide_export;
324 
325     Gtk::CheckButton closeWhenDone;
326 
327     /* Advanced */
328     Gtk::Expander expander;
329     Gtk::CheckButton interlacing;
330     Gtk::Label                        bitdepth_label;
331     Inkscape::UI::Widget::ScrollProtected<Gtk::ComboBoxText> bitdepth_cb;
332     Gtk::Label                        zlib_label;
333     Inkscape::UI::Widget::ScrollProtected<Gtk::ComboBoxText> zlib_compression;
334     Gtk::Label                        pHYs_label;
335     Glib::RefPtr<Gtk::Adjustment>     pHYs_adj;
336     Inkscape::UI::Widget::ScrollProtected<Gtk::SpinButton> pHYs_sb;
337     Gtk::Label                        antialiasing_label;
338     Inkscape::UI::Widget::ScrollProtected<Gtk::ComboBoxText> antialiasing_cb;
339 
340     /* Export Button widgets */
341     Gtk::Box button_box;
342     Gtk::Button export_button;
343 
344     Gtk::ProgressBar _prog;
345 
346     ExportProgressDialog *prog_dlg;
347     bool interrupted; // indicates whether export needs to be interrupted (read: user pressed cancel in the progress dialog)
348 
349     Inkscape::Preferences *prefs;
350     sigc::connection selectChangedConn;
351     sigc::connection subselChangedConn;
352     sigc::connection selectModifiedConn;
353     sigc::connection unitChangedConn;
354 
355 };
356 
357 }
358 }
359 }
360 #endif
361 
362 /*
363   Local Variables:
364   mode:c++
365   c-file-style:"stroustrup"
366   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
367   indent-tabs-mode:nil
368   fill-column:99
369   End:
370 */
371 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
372