summaryrefslogtreecommitdiffstats
path: root/src/ui/dialog/export.h
blob: 9210ac545a4628684ccc937138062fdb03a725b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
// SPDX-License-Identifier: GPL-2.0-or-later
/* Authors:
 *   Lauris Kaplinski <lauris@kaplinski.com>
 *   bulia byak <buliabyak@users.sf.net>
 *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
 *
 * Copyright (C) 1999-2007 Authors
 * Copyright (C) 2001-2002 Ximian, Inc.
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#ifndef SP_EXPORT_H
#define SP_EXPORT_H

#include <gtkmm/progressbar.h>
#include <gtkmm/expander.h>
#include <gtkmm/grid.h>
#include <gtkmm/comboboxtext.h>

#include "ui/dialog/desktop-tracker.h"
#include "ui/widget/panel.h"

namespace Gtk {
class Dialog;
}

namespace Inkscape {
namespace UI {
namespace Dialog {

/** What type of button is being pressed */
enum selection_type {
    SELECTION_PAGE = 0,  /**< Export the whole page */
    SELECTION_DRAWING,   /**< Export everything drawn on the page */
    SELECTION_SELECTION, /**< Export everything that is selected */
    SELECTION_CUSTOM,    /**< Allows the user to set the region exported */
    SELECTION_NUMBER_OF  /**< A counter for the number of these guys */
};

/**
 * A dialog widget to export to various image formats such as bitmap and png.
 *
 * Creates a dialog window for exporting an image to a bitmap if one doesn't already exist and
 * shows it to the user. If the dialog has already been created, it simply shows the window.
 *
 */
class Export : public Widget::Panel {
public:
    Export ();
    ~Export () override;

    static Export &getInstance() {
        return *new Export();
    }

private:

    /**
     * A function to set the xdpi.
     *
     * This function grabs all of the x values and then figures out the
     * new bitmap size based on the changing dpi value.  The dpi value is
     * gotten from the xdpi setting as these can not currently be independent.
     *
     */
    void setImageX();

    /**
     * A function to set the ydpi.
     *
     * This function grabs all of the y values and then figures out the
     * new bitmap size based on the changing dpi value.  The dpi value is
     * gotten from the xdpi setting as these can not currently be independent.
     */
    void setImageY();
    bool bbox_equal(Geom::Rect const &one, Geom::Rect const &two);
    void updateCheckbuttons ();
    inline void findDefaultSelection();
    void detectSize();
    void setArea ( double x0, double y0, double x1, double y1);
    /*
     * Getter/setter style functions for the spinbuttons
     */
    void setValue(Glib::RefPtr<Gtk::Adjustment>& adj, double val);
    void setValuePx(Glib::RefPtr<Gtk::Adjustment>& adj, double val);
    float getValue(Glib::RefPtr<Gtk::Adjustment>& adj);
    float getValuePx(Glib::RefPtr<Gtk::Adjustment>& adj);

    /**
     * Helper function to create, style and pack spinbuttons for the export dialog.
     *
     * Creates a new spin button for the export dialog.
     * @param  key  The name of the spin button
     * @param  val  A default value for the spin button
     * @param  min  Minimum value for the spin button
     * @param  max  Maximum value for the spin button
     * @param  step The step size for the spin button
     * @param  page Size of the page increment
     * @param  t    Table to put the spin button in
     * @param  x    X location in the table \c t to start with
     * @param  y    Y location in the table \c t to start with
     * @param  ll   Text to put on the left side of the spin button (optional)
     * @param  lr   Text to put on the right side of the spin button (optional)
     * @param  digits  Number of digits to display after the decimal
     * @param  sensitive  Whether the spin button is sensitive or not
     * @param  cb   Callback for when this spin button is changed (optional)
     *
     * No unit_selector is stored in the created spinbutton, relies on external unit management
     */
    Glib::RefPtr<Gtk::Adjustment> createSpinbutton( gchar const *key, float val, float min, float max,
                                                    float step, float page,
                                                    Gtk::Grid *t, int x, int y,
                                                    const Glib::ustring& ll, const Glib::ustring& lr,
                                                    int digits, unsigned int sensitive,
                                                    void (Export::*cb)() );

    /**
     * One of the area select radio buttons was pressed
     */
    void onAreaToggled();

    /**
     * Export button callback
     */
    void onExport ();

    /**
     * File Browse button callback
     */
    void onBrowse ();

    /**
     * Area X value changed callback
     */
    void onAreaX0Change() {
        areaXChange(x0_adj);
    } ;
    void onAreaX1Change() {
        areaXChange(x1_adj);
    } ;
    void areaXChange(Glib::RefPtr<Gtk::Adjustment>& adj);

    /**
     * Area Y value changed callback
     */
    void onAreaY0Change() {
        areaYChange(y0_adj);
    } ;
    void onAreaY1Change() {
        areaYChange(y1_adj);
    } ;
    void areaYChange(Glib::RefPtr<Gtk::Adjustment>& adj);

    /**
     * Unit changed callback
     */
    void onUnitChanged();

    /**
     * Hide except selected callback
     */
    void onHideExceptSelected ();

    /**
     * Area width value changed callback
     */
    void onAreaWidthChange   ();

    /**
     * Area height value changed callback
     */
    void onAreaHeightChange  ();

    /**
     * Bitmap width value changed callback
     */
    void onBitmapWidthChange ();

    /**
     * Bitmap height value changed callback
     */
    void onBitmapHeightChange ();

    /**
     * Export xdpi value changed callback
     */
    void onExportXdpiChange ();

    /**
     * Batch export callback
     */
    void onBatchClicked ();

    /**
     * Inkscape selection change callback
     */
    void onSelectionChanged ();
    void onSelectionModified (guint flags);

    /**
     * Filename modified callback
     */
    void onFilenameModified ();

    /**
     * Can be invoked for setting the desktop. Currently not used.
     */
    void setDesktop(SPDesktop *desktop) override;

    /**
     * Is invoked by the desktop tracker when the desktop changes.
     */
    void setTargetDesktop(SPDesktop *desktop);

    /**
     * Creates progress dialog for batch exporting.
     *
     * @param progress_text Text to be shown in the progress bar
     */
    Gtk::Dialog * create_progress_dialog (Glib::ustring progress_text);

    /**
     * Callback to be used in for loop to update the progress bar.
     *
     * @param value number between 0 and 1 indicating the fraction of progress (0.17 = 17 % progress)
     * @param dlg void pointer to the Gtk::Dialog progress dialog
     */
    static unsigned int onProgressCallback(float value, void *dlg);

    /**
     * Callback for pressing the cancel button.
     */
    void onProgressCancel ();

    /**
     * Callback invoked on closing the progress dialog.
     */
    bool onProgressDelete (GdkEventAny *event);

    /**
     * Handles state changes as exporting starts or stops.
     */
    void setExporting(bool exporting, Glib::ustring const &text = "");

    /*
     * Utility filename and path functions
     */
    void set_default_filename ();
    Glib::ustring create_filepath_from_id (Glib::ustring id, const Glib::ustring &file_entry_text);
    Glib::ustring filename_add_extension (Glib::ustring filename, Glib::ustring extension);
    Glib::ustring absolutize_path_from_document_location (SPDocument *doc, const Glib::ustring &filename);

    /*
     * Currently selected export area type
     */
    selection_type current_key;
    /*
     * Original name for the export object
     */
    Glib::ustring original_name;
    Glib::ustring doc_export_name;
    /*
     * Was the Original name modified
     */
    bool filename_modified;
    bool was_empty;
    /*
     * Flag to stop simultaneous updates
     */
    bool update;

    /* Area selection radio buttons */
    Gtk::HBox togglebox;
    Gtk::RadioButton *selectiontype_buttons[SELECTION_NUMBER_OF];

    Gtk::VBox area_box;
    Gtk::VBox singleexport_box;

    /* Custom size widgets */
    Glib::RefPtr<Gtk::Adjustment> x0_adj;
    Glib::RefPtr<Gtk::Adjustment> x1_adj;
    Glib::RefPtr<Gtk::Adjustment> y0_adj;
    Glib::RefPtr<Gtk::Adjustment> y1_adj;
    Glib::RefPtr<Gtk::Adjustment> width_adj;
    Glib::RefPtr<Gtk::Adjustment> height_adj;

    /* Bitmap size widgets */
    Glib::RefPtr<Gtk::Adjustment> bmwidth_adj;
    Glib::RefPtr<Gtk::Adjustment> bmheight_adj;
    Glib::RefPtr<Gtk::Adjustment> xdpi_adj;
    Glib::RefPtr<Gtk::Adjustment> ydpi_adj;

    Gtk::VBox size_box;
    Gtk::Label* bm_label;

    Gtk::VBox file_box;
    Gtk::Label *flabel;
    Gtk::Entry filename_entry;

    /* Unit selector widgets */
    Gtk::HBox unitbox;
    Inkscape::UI::Widget::UnitMenu unit_selector;
    Gtk::Label units_label;

    /* Filename widgets  */
    Gtk::HBox filename_box;
    Gtk::Button browse_button;
    Gtk::Label browse_label;
    Gtk::Image browse_image;

    Gtk::HBox batch_box;
    Gtk::CheckButton    batch_export;

    Gtk::HBox hide_box;
    Gtk::CheckButton    hide_export;

    Gtk::CheckButton closeWhenDone;

    /* Advanced */
    Gtk::Expander expander;
    Gtk::CheckButton interlacing;
    Gtk::Label                        bitdepth_label;
    Gtk::ComboBoxText                 bitdepth_cb;
    Gtk::Label                        zlib_label;
    Gtk::ComboBoxText                 zlib_compression;
    Gtk::Label                        pHYs_label;
    Glib::RefPtr<Gtk::Adjustment>     pHYs_adj;
    Gtk::SpinButton                   pHYs_sb;
    Gtk::Label                        antialiasing_label;
    Gtk::ComboBoxText                 antialiasing_cb;

    /* Export Button widgets */
    Gtk::HBox button_box;
    Gtk::Button export_button;

    Gtk::ProgressBar _prog;

    Gtk::Dialog *prog_dlg;
    bool interrupted; // indicates whether export needs to be interrupted (read: user pressed cancel in the progress dialog)

    Inkscape::Preferences *prefs;
    SPDesktop *desktop;
    DesktopTracker deskTrack;
    sigc::connection desktopChangeConn;
    sigc::connection selectChangedConn;
    sigc::connection subselChangedConn;
    sigc::connection selectModifiedConn;
    sigc::connection unitChangedConn;

};

}
}
}
#endif

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :