1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 #ifndef MARGINWIDGET_H
8 #define MARGINWIDGET_H
9 
10 #include "scribusapi.h"
11 #include "scribusstructs.h"
12 
13 #include <QComboBox>
14 #include <QTabWidget>
15 #include "linkbutton.h"
16 #include "marginpresetlayout.h"
17 
18 class QCheckBox;
19 class QPushButton;
20 class QLabel;
21 class QGridLayout;
22 class QHBoxLayout;
23 class ScrSpinBox;
24 
25 
26 /*! \brief Widget for Margins setting.
27 Used e.g. in "New Doc Dialog" or "Preferences".
28 */
29 class SCRIBUS_API MarginWidget : public QTabWidget
30 {
31 	Q_OBJECT
32 
33 public:
34 	/*! \brief It creates an user interface for base margin settings for the document.
35 	\param parent Parent widget (used as standard in Qt)
36 	\param title Title of the Group box
37 	\param margs A reference to the margins in the preferences.
38 	\param unitIndex and index of the unit combobox
39 	\param showChangeAll show "apply to all pages" related items
40 	*/
41 	MarginWidget(QWidget* parent, const QString& title, const MarginStruct* margs, int unitIndex, bool showChangeAll=false, bool showBleeds=true);
~MarginWidget()42 	~MarginWidget() {}
43 	/*! \brief Setup the labels by facing pages option */
44 	void setFacingPages(bool facing, int pagetype = 0);
45 	/*! \brief Setup the spinboxes properties (min/max value etc.) by width and height */
46 	void setPageWidthHeight(double width, double height);
47 	/*! \brief Setup the spinboxes properties (min/max value etc.) by width */
48 	void setPageWidth(double width);
49 	/*! \brief Setup the spinboxes properties (min/max value etc.) by height */
50 	void setPageHeight(double height);
51 	/*! \brief Setup the widgets by new options */
52 	void setNewUnit(int newUnitIndex);
53 	/*! \brief Set the page size for margin getting from cups */
54 	void setPageSize(const QString& pageSize);
55 
56 	/*! \brief Margins
57 	\retval MarginStruct data */
58 	const MarginStruct& margins() const;
59 	/*! \brief Top Margin
60 	\retval double margin size */
61 	double top() const;
62 	/*! \brief Bottom Margin
63 	\retval double margin size */
64 	double bottom() const;
65 	/*! \brief Left Margin
66 	\retval double margin size */
67 	double left() const;
68 	/*! \brief Right Margin
69 	\retval double margin size */
70 	double right() const;
71 
72 	/*! \brief set new margin values for the dialog
73 	It calls overridden setTop(), setBottom() etc. slots itself
74 	via signals emitted from spinboxes.
75 	\param m MarginStruct
76 	*/
77 	void setNewMargins(MarginStruct& m);
78 
79 	/*! \brief Setup the presetCombo without changing the margin values, only used by tabdocument */
80 	void setMarginPreset(int p);
81 	int getMarginPreset();
82 
83 	/*! \brief Top Bleed
84 	\retval double bleed size */
85 	double topBleed() const;
86 	/*! \brief Bottom Bleed
87 	\retval double bleed size */
88 	double bottomBleed() const;
89 	/*! \brief Left Bleed
90 	\retval double bleed size */
91 	double leftBleed() const;
92 	/*! \brief Right Bleed
93 	\retval double bleed size */
94 	double rightBleed() const;
95 
96 	/*! \brief set new bleed values for the dialog
97 	\param b MarginStruct
98 	*/
99 	void setNewBleeds(MarginStruct& b);
100 
101 	/*! \brief Return marginsForAllPages property
102 	\retval bool true to apply for all pages */
103 	bool getMarginsForAllPages() const;
104 	bool getMarginsForAllMasterPages() const;
105 
106 private:
107 	/*! Tabs */
108 	QWidget *marginPage { nullptr };
109 	QWidget* bleedPage { nullptr };
110 	/*! Spinboxes */
111 	ScrSpinBox* topR { nullptr };
112 	ScrSpinBox* bottomR { nullptr };
113 	ScrSpinBox* rightR { nullptr };
114 	ScrSpinBox* leftR { nullptr };
115 	ScrSpinBox* BleedBottom { nullptr };
116 	ScrSpinBox* BleedLeft { nullptr };
117 	ScrSpinBox* BleedRight { nullptr };
118 	ScrSpinBox* BleedTop { nullptr };
119 	PresetLayout* presetCombo { nullptr };
120 	/*! Labels */
121 	QLabel* lText { nullptr };
122 	QLabel* rText { nullptr };
123 	QLabel* tText { nullptr };
124 	QLabel* bText { nullptr };
125 	QLabel* presetLabel { nullptr };
126 	QLabel* marginsForPages { nullptr };
127 	QLabel* BleedTxt1 { nullptr };
128 	QLabel* BleedTxt2 { nullptr };
129 	QLabel* BleedTxt3 { nullptr };
130 	QLabel* BleedTxt4 { nullptr };
131 	QCheckBox* marginsForAllPages { nullptr };
132 	QCheckBox* marginsForAllMasterPages { nullptr };
133 	QPushButton* usePrinterMarginsButton { nullptr };
134 	LinkButton* linkBleeds { nullptr };
135 	LinkButton* linkMargins { nullptr };
136 
137 	/*! \brief Margin values converted by unitRatio */
138 	MarginStruct marginData;
139 
140 	/*! \brief Internally used page width */
141 	double m_pageWidth { 0.0 };
142 	/*! \brief Internally used page height */
143 	double m_pageHeight { 0.0 };
144 
145 public slots:
146 	/*! \brief Recompute the values after spinbox change */
147 	void setTop();
148 	void setBottom();
149 	void setLeft();
150 	void setRight();
151 	/*! \brief Recompute margins in PresetLayout combobox and disable/enable widgets. */
152 	void setPreset();
153 	void slotLinkBleeds();
154 	void slotLinkMargins();
155 	void changeBleeds();
156 
157 protected slots:
158 	virtual void setMarginsToPrinterMargins();
159 
160 protected:
161 	void updateMarginSpinValues();
162 
163 	QGridLayout* GroupLayout { nullptr };
164 	QHBoxLayout* marginsForPagesLayout { nullptr };
165 	QGridLayout* BleedGroupLayout { nullptr };
166 
167 	QString m_pageSize;
168 	int     m_unitIndex { 0 };
169 	double  m_unitRatio { 1.0 };
170 	//! \brief if the outer facing palette points to the facing pages item
171 	bool m_facingPages { false };
172 	bool m_useBleeds { false };
173 	int  m_pageType { 0 };
174 	MarginStruct m_savedMargins;
175 	int m_savedPresetItem { PresetLayout::none };
176 };
177 
178 #endif
179