1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Author:
4  *   Ralf Stephan <ralf@ark.in-berlin.de>
5  *
6  * Copyright (C) 2005-2006 Authors
7  *
8  * Released under GNU GPL v2+, read the file 'COPYING' for more information.
9  */
10 
11 #ifndef INKSCAPE_UI_WIDGET_PAGE_SIZER_H
12 #define INKSCAPE_UI_WIDGET_PAGE_SIZER_H
13 
14 #include <cstddef>
15 #include "ui/widget/registered-widget.h"
16 #include <sigc++/sigc++.h>
17 
18 #include "util/units.h"
19 
20 #include <gtkmm/expander.h>
21 #include <gtkmm/frame.h>
22 #include <gtkmm/grid.h>
23 #include <gtkmm/liststore.h>
24 #include <gtkmm/scrolledwindow.h>
25 #include <gtkmm/radiobutton.h>
26 
27 namespace Inkscape {
28 namespace XML {
29 class Node;
30 }
31 
32 namespace UI {
33 namespace Widget {
34 
35 class Registry;
36 
37 /**
38  * Data class used to store common paper dimensions.  Used to make
39  * PageSizer's _paperSizeTable.
40  */
41 class PaperSize
42 {
43 public:
44 
45     /**
46      * Default constructor
47      */
PaperSize()48     PaperSize()
49         { init(); }
50 
51     /**
52      * Main constructor.  Use this one.
53      */
PaperSize(Glib::ustring nameArg,double smallerArg,double largerArg,Inkscape::Util::Unit const * unitArg)54     PaperSize(Glib::ustring nameArg,
55               double smallerArg,
56               double largerArg,
57               Inkscape::Util::Unit const *unitArg)
58         : name(std::move(nameArg))
59         , smaller(smallerArg)
60         , larger(largerArg)
61         , unit(unitArg)
62         {}
63 
64     /**
65      * Copy constructor
66      */
PaperSize(const PaperSize & other)67     PaperSize(const PaperSize &other)
68         { assign(other); }
69 
70     /**
71      * Assignment operator
72      */
73     PaperSize &operator=(const PaperSize &other)
74         { assign(other); return *this; }
75 
76     /**
77      * Destructor
78      */
79 	virtual ~PaperSize()
80 	    = default;
81 
82     /**
83      * Name of this paper specification
84      */
85     Glib::ustring name;
86 
87     /**
88      * The lesser of the two dimensions
89      */
90     double smaller;
91 
92     /**
93      * The greater of the two dimensions
94      */
95     double larger;
96 
97     /**
98      * The units (px, pt, mm, etc) of this specification
99      */
100     Inkscape::Util::Unit const *unit; /// pointer to object in UnitTable, do not delete
101 
102 private:
103 
init()104 	void init()
105 	    {
106 	    name    = "";
107 	    smaller = 0.0;
108 	    larger  = 0.0;
109 	    unit    = unit_table.getUnit("px");
110 	    }
111 
assign(const PaperSize & other)112 	void assign(const PaperSize &other)
113 	    {
114 	    name    = other.name;
115 	    smaller = other.smaller;
116 	    larger  = other.larger;
117 	    unit    = other.unit;
118         }
119 
120 };
121 
122 
123 
124 
125 
126 /**
127  * A compound widget that allows the user to select the desired
128  * page size.  This widget is used in DocumentPreferences
129  */
130 class PageSizer : public Gtk::Box
131 {
132 public:
133 
134     /**
135      * Constructor
136      */
137     PageSizer(Registry & _wr);
138 
139     /**
140      * Destructor
141      */
142     ~PageSizer() override;
143 
144     /**
145      * Set up or reset this widget
146      */
147     void init ();
148 
149     /**
150      * Set the page size to the given dimensions.  If 'changeList' is
151      * true, then reset the paper size list to the closest match
152      */
153     void setDim (Inkscape::Util::Quantity w, Inkscape::Util::Quantity h, bool changeList=true, bool changeSize=true);
154 
155     /**
156      * Updates the scalar widgets for the fit margins.  (Just changes the value
157      * of the ui widgets to match the xml).
158      */
159     void updateFitMarginsUI(Inkscape::XML::Node *nv_repr);
160 
161     /**
162      * Updates the margin widgets. If lock widget is active
163      */
164     void on_margin_changed(RegisteredScalar* widg);
165 
166     void on_margin_lock_changed();
167 
168     /**
169      * Updates the scale widgets. (Just changes the values of the ui widgets.)
170      */
171     void updateScaleUI();
172 
173 protected:
174 
175     /**
176      * Our handy table of all 'standard' paper sizes.
177      */
178     std::map<Glib::ustring, PaperSize> _paperSizeTable;
179 
180     /**
181      *	Find the closest standard paper size in the table, to the
182      */
183     Gtk::ListStore::iterator find_paper_size (Inkscape::Util::Quantity w, Inkscape::Util::Quantity h) const;
184 
185     void fire_fit_canvas_to_selection_or_drawing();
186 
187     //### The Paper Size selection list
188     class PaperSizeColumns : public Gtk::TreeModel::ColumnRecord
189         {
190         public:
PaperSizeColumns()191             PaperSizeColumns()
192                { add(nameColumn); add(descColumn);  }
193             Gtk::TreeModelColumn<Glib::ustring> nameColumn;
194             Gtk::TreeModelColumn<Glib::ustring> descColumn;
195         };
196 
197     PaperSizeColumns _paperSizeListColumns;
198     Glib::RefPtr<Gtk::ListStore> _paperSizeListStore;
199     Gtk::TreeView _paperSizeList;
200     Glib::RefPtr<Gtk::TreeSelection> _paperSizeListSelection;
201     Gtk::ScrolledWindow  _paperSizeListScroller;
202     //callback
203     void on_paper_size_list_changed();
204     sigc::connection    _paper_size_list_connection;
205 
206     //### Portrait or landscape orientation
207     Gtk::Box            _orientationBox;
208     Gtk::Label          _orientationLabel;
209     Gtk::RadioButton    _portraitButton;
210     Gtk::RadioButton    _landscapeButton;
211     //callbacks
212     void on_portrait();
213     void on_landscape();
214     sigc::connection    _portrait_connection;
215     sigc::connection    _landscape_connection;
216 
217     //### Custom size frame
218     Gtk::Frame           _customFrame;
219     Gtk::Grid            _customDimTable;
220 
221     RegisteredUnitMenu   _dimensionUnits;
222     RegisteredScalarUnit _dimensionWidth;
223     RegisteredScalarUnit _dimensionHeight;
224 
225     //### Fit Page options
226     Gtk::Expander        _fitPageMarginExpander;
227 
228     Gtk::Grid              _marginTable;
229     Gtk::Box               _marginBox;
230     Gtk::Label             _marginLabel;
231     RegisteredToggleButton _marginLock;
232     Gtk::Image             _lock_icon;
233     RegisteredScalar       _marginTop;
234     RegisteredScalar       _marginLeft;
235     RegisteredScalar       _marginRight;
236     RegisteredScalar       _marginBottom;
237     Gtk::Button            _fitPageButton;
238     bool                   _lockMarginUpdate;
239 
240     // Document scale
241     Gtk::Frame           _scaleFrame;
242     Gtk::Grid            _scaleTable;
243 
244     Gtk::Label           _scaleLabel;
245     RegisteredScalar     _scaleX;
246     RegisteredScalar     _scaleY;
247     bool                 _lockScaleUpdate;
248 
249     // Viewbox
250     Gtk::Expander        _viewboxExpander;
251     Gtk::Grid            _viewboxTable;
252 
253     RegisteredScalar     _viewboxX;
254     RegisteredScalar     _viewboxY;
255     RegisteredScalar     _viewboxW;
256     RegisteredScalar     _viewboxH;
257     Gtk::Box             _viewboxSpacer;
258     bool                 _lockViewboxUpdate;
259 
260     //callback
261     void on_value_changed();
262     void on_units_changed();
263     void on_scale_changed();
264     void on_viewbox_changed();
265     sigc::connection    _changedw_connection;
266     sigc::connection    _changedh_connection;
267     sigc::connection    _changedu_connection;
268     sigc::connection    _changeds_connection;
269     sigc::connection    _changedvx_connection;
270     sigc::connection    _changedvy_connection;
271     sigc::connection    _changedvw_connection;
272     sigc::connection    _changedvh_connection;
273     sigc::connection    _changedlk_connection;
274     sigc::connection    _changedmt_connection;
275     sigc::connection    _changedmb_connection;
276     sigc::connection    _changedml_connection;
277     sigc::connection    _changedmr_connection;
278 
279     Registry            *_widgetRegistry;
280 
281     //### state - whether we are currently landscape or portrait
282     bool                 _landscape;
283 
284     Glib::ustring       _unit;
285 
286 };
287 
288 } // namespace Widget
289 } // namespace UI
290 } // namespace Inkscape
291 
292 
293 #endif // INKSCAPE_UI_WIDGET_PAGE_SIZER_H
294 
295 /*
296   Local Variables:
297   mode:c++
298   c-file-style:"stroustrup"
299   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
300   indent-tabs-mode:nil
301   fill-column:99
302   End:
303 */
304 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
305