summaryrefslogtreecommitdiffstats
path: root/src/ui/widget/page-sizer.h
blob: b399835b7d683c4b35b162ae91ea2df25fb55a72 (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
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Author:
 *   Ralf Stephan <ralf@ark.in-berlin.de>
 *
 * Copyright (C) 2005-2006 Authors
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#ifndef INKSCAPE_UI_WIDGET_PAGE_SIZER_H
#define INKSCAPE_UI_WIDGET_PAGE_SIZER_H

#include <cstddef>
#include "ui/widget/registered-widget.h"
#include <sigc++/sigc++.h>

#include "util/units.h"

#include <gtkmm/expander.h>
#include <gtkmm/frame.h>
#include <gtkmm/grid.h>
#include <gtkmm/liststore.h>
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/radiobutton.h>

namespace Inkscape {    
namespace XML {
class Node;
}

namespace UI {
namespace Widget {

class Registry;

/**
 * Data class used to store common paper dimensions.  Used to make
 * PageSizer's _paperSizeTable. 
 */ 
class PaperSize
{
public:

    /**
     * Default constructor
     */
    PaperSize()
        { init(); }

    /**
     * Main constructor.  Use this one.
     */
    PaperSize(const Glib::ustring &nameArg,
	          double smallerArg,
	          double largerArg,
			  Inkscape::Util::Unit const *unitArg)
	    {
	    name    = nameArg;
	    smaller = smallerArg;
	    larger  = largerArg;
	    unit    = unitArg;
	    }

    /**
     * Copy constructor
     */
    PaperSize(const PaperSize &other)
        { assign(other); }
        
    /**
     * Assignment operator
     */	     
    PaperSize &operator=(const PaperSize &other)
        { assign(other); return *this; }

    /**
     * Destructor
     */	     
	virtual ~PaperSize()
	    = default;
	    
    /**
     * Name of this paper specification
     */	     
    Glib::ustring name;
    
    /**
     * The lesser of the two dimensions
     */	     
    double smaller;
    
    /**
     * The greater of the two dimensions
     */	     
    double larger;
    
    /**
     * The units (px, pt, mm, etc) of this specification
     */	     
    Inkscape::Util::Unit const *unit; /// pointer to object in UnitTable, do not delete

private:

	void init()
	    {
	    name    = "";
	    smaller = 0.0;
	    larger  = 0.0;
	    unit    = unit_table.getUnit("px");
	    }

	void assign(const PaperSize &other)
	    {
	    name    = other.name;
	    smaller = other.smaller;
	    larger  = other.larger;
	    unit    = other.unit;
        }

};





/**
 * A compound widget that allows the user to select the desired
 * page size.  This widget is used in DocumentPreferences 
 */ 
class PageSizer : public Gtk::VBox
{
public:

    /**
     * Constructor
     */
    PageSizer(Registry & _wr);

    /**
     * Destructor
     */
    ~PageSizer() override;

    /**
     * Set up or reset this widget
     */	     
    void init ();
    
    /**
     * Set the page size to the given dimensions.  If 'changeList' is
     * true, then reset the paper size list to the closest match
     */
    void setDim (Inkscape::Util::Quantity w, Inkscape::Util::Quantity h, bool changeList=true, bool changeSize=true);
    
    /**
     * Updates the scalar widgets for the fit margins.  (Just changes the value
     * of the ui widgets to match the xml).
     */
    void updateFitMarginsUI(Inkscape::XML::Node *nv_repr);
    
    /**
     * Updates the margin widgets. If lock widget is active
     */
    void on_margin_changed(RegisteredScalar* widg);
    
    void on_margin_lock_changed();
    
    /**
     * Updates the scale widgets. (Just changes the values of the ui widgets.)
     */
    void updateScaleUI();

protected:

    /**
     * Our handy table of all 'standard' paper sizes.
     */	     
    std::map<Glib::ustring, PaperSize> _paperSizeTable;

    /**
     *	Find the closest standard paper size in the table, to the
     */
    Gtk::ListStore::iterator find_paper_size (Inkscape::Util::Quantity w, Inkscape::Util::Quantity h) const;
 
    void fire_fit_canvas_to_selection_or_drawing();
    
    //### The Paper Size selection list
    Gtk::HBox _paperSizeListBox;
    Gtk::Label _paperSizeListLabel;
    class PaperSizeColumns : public Gtk::TreeModel::ColumnRecord
        {
        public:
            PaperSizeColumns()
               { add(nameColumn); add(descColumn);  }
            Gtk::TreeModelColumn<Glib::ustring> nameColumn;
            Gtk::TreeModelColumn<Glib::ustring> descColumn;
        };

    PaperSizeColumns _paperSizeListColumns;
    Glib::RefPtr<Gtk::ListStore> _paperSizeListStore;
    Gtk::TreeView _paperSizeList;
    Glib::RefPtr<Gtk::TreeSelection> _paperSizeListSelection;
    Gtk::ScrolledWindow  _paperSizeListScroller;
    //callback
    void on_paper_size_list_changed();
    sigc::connection    _paper_size_list_connection;
    
    //### Portrait or landscape orientation
    Gtk::HBox           _orientationBox;
    Gtk::Label          _orientationLabel;
    Gtk::RadioButton    _portraitButton;
    Gtk::RadioButton    _landscapeButton;
    //callbacks
    void on_portrait();
    void on_landscape();
    sigc::connection    _portrait_connection;
    sigc::connection    _landscape_connection;

    //### Custom size frame
    Gtk::Frame           _customFrame;
    Gtk::Grid            _customDimTable;

    RegisteredUnitMenu   _dimensionUnits;
    RegisteredScalarUnit _dimensionWidth;
    RegisteredScalarUnit _dimensionHeight;

    //### Fit Page options
    Gtk::Expander        _fitPageMarginExpander;

    Gtk::Grid              _marginTable;
    Gtk::Box               _marginBox;
    Gtk::Label             _marginLabel;
    RegisteredToggleButton _marginLock;
    Gtk::Image             _lock_icon;
    RegisteredScalar       _marginTop;
    RegisteredScalar       _marginLeft;
    RegisteredScalar       _marginRight;
    RegisteredScalar       _marginBottom;
    Gtk::Button            _fitPageButton;
    bool                   _lockMarginUpdate;

    // Document scale
    Gtk::Frame           _scaleFrame;
    Gtk::Grid            _scaleTable;

    Gtk::Label           _scaleLabel;
    RegisteredScalar     _scaleX;
    RegisteredScalar     _scaleY;
    bool                 _lockScaleUpdate;

    // Viewbox
    Gtk::Expander        _viewboxExpander;
    Gtk::Grid            _viewboxTable;

    RegisteredScalar     _viewboxX;
    RegisteredScalar     _viewboxY;
    RegisteredScalar     _viewboxW;
    RegisteredScalar     _viewboxH;
    Gtk::Box             _viewboxSpacer;
    bool                 _lockViewboxUpdate;

    //callback
    void on_value_changed();
    void on_units_changed();
    void on_scale_changed();
    void on_viewbox_changed();
    sigc::connection    _changedw_connection;
    sigc::connection    _changedh_connection;
    sigc::connection    _changedu_connection;
    sigc::connection    _changeds_connection;
    sigc::connection    _changedvx_connection;
    sigc::connection    _changedvy_connection;
    sigc::connection    _changedvw_connection;
    sigc::connection    _changedvh_connection;
    sigc::connection    _changedlk_connection;
    sigc::connection    _changedmt_connection;
    sigc::connection    _changedmb_connection;
    sigc::connection    _changedml_connection;
    sigc::connection    _changedmr_connection;

    Registry            *_widgetRegistry;

    //### state - whether we are currently landscape or portrait
    bool                 _landscape;
    
    Glib::ustring       _unit;

};

} // namespace Widget
} // namespace UI
} // namespace Inkscape


#endif // INKSCAPE_UI_WIDGET_PAGE_SIZER_H

/*
  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 :