summaryrefslogtreecommitdiffstats
path: root/scribus/guidemanagercore.h
blob: 305c59d73c725ce62c630769999ab38db3eecb44 (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
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/

#ifndef GUIDEMANAGERCORE_H
#define GUIDEMANAGERCORE_H

#include <QPair>

#include "undoobject.h"
#include "scribusapi.h"

class QColor;
class Page;
class ScPainter;
class UndoManager;
class ScribusDoc;
typedef QList<double> Guides;

/*! \brief Core manipulation with the guides.
Basic idea:
- guides are handled "on the fly", no by modal dialog.
- 2 types of guides: Standard = created one by one.
Auto = created by automatic division algorithms.
Automatic guides are kept by 2 ways: 1st its parameters (m_horizontalAutoCount etc.)
to setup the GUI and compute guides itself. 2nd the horizontalAutoG etc. set
with precomputed values from GUI actions for drawing.
- user can move only Stnadard ones
- Auto guides can be deleted only in manipulation dialog
- Auto guides are painted in different color / (probably) with diff. line.
\author Petr vanek <petr@scribus.info>
*/
class SCRIBUS_API GuideManagerCore
{
public:
	GuideManagerCore();
	GuideManagerCore(Page* parentPage);
	~GuideManagerCore();

	typedef enum {Standard, Auto} GuideType;

	void addHorizontal(double value, GuideType type);
	void addHorizontals(Guides values, GuideType type);
	void addVertical(double value, GuideType type);
	void addVerticals(Guides values, GuideType type);
	void deleteHorizontal(double value, GuideType type);
	void deleteVertical(double value, GuideType type);
	void moveHorizontal(double from, double to, GuideType type);
	void moveVertical(double from, double to, GuideType type);

	Guides horizontals(GuideType type);
	Guides verticals(GuideType type);
	double horizontal(uint ix, GuideType type);
	double vertical(uint ix, GuideType type);

	Guides getAutoHorizontals(Page* page = NULL);
	Guides getAutoVerticals(Page* page = NULL);

	void clearHorizontals(GuideType type);
	void clearVerticals(GuideType type);

	void copy(GuideManagerCore *target);
	void copy(GuideManagerCore *target, GuideType type);

	void drawPage(ScPainter *p, ScribusDoc *doc, double lineWidth);

	int isMouseOnHorizontal(double low, double high, GuideType type);
	int isMouseOnVertical(double low, double high, GuideType type);

	void setPage(Page *p);

	QPair<double, double> topLeft(double x, double y);// const;
	QPair<double, double> topRight(double x, double y);// const;
	QPair<double, double> bottomLeft(double x, double y);// const;
	QPair<double, double> bottomRight(double x, double y);// const;

	//! \brief Properties for Auto guides remembrance. See GuideManager.
	int horizontalAutoCount() { return m_horizontalAutoCount; };
	//! \brief Properties for Auto guides remembrance. See GuideManager.
	void setHorizontalAutoCount(int val) { m_horizontalAutoCount = val; };
	//! \brief Properties for Auto guides remembrance. See GuideManager.
	int verticalAutoCount() { return m_verticalAutoCount; };
	//! \brief Properties for Auto guides remembrance. See GuideManager.
	void setVerticalAutoCount(int val) { m_verticalAutoCount = val; };
	//! \brief Properties for Auto guides remembrance. See GuideManager.
	double horizontalAutoGap(){ return m_horizontalAutoGap; };
	//! \brief Properties for Auto guides remembrance. See GuideManager.
	double verticalAutoGap(){return m_verticalAutoGap; };
	//! \brief Properties for Auto guides remembrance. See GuideManager.
	void setHorizontalAutoGap(double gap){ m_horizontalAutoGap = gap; };
	//! \brief Properties for Auto guides remembrance. See GuideManager.
	void setVerticalAutoGap(double gap){ m_verticalAutoGap = gap; };
	//! \brief Properties for Auto guides remembrance. See GuideManager.
	int horizontalAutoRefer() { return m_horizontalAutoRefer; };
	//! \brief Properties for Auto guides remembrance. See GuideManager.
	void setHorizontalAutoRefer(int val) { m_horizontalAutoRefer = val; };
	//! \brief Properties for Auto guides remembrance. See GuideManager.
	int verticalAutoRefer() { return m_verticalAutoRefer; };
	//! \brief Properties for Auto guides remembrance. See GuideManager.
	void setVerticalAutoRefer(int val) { m_verticalAutoRefer = val; };

	/*! \brief Selection/group coordinates
	It's used to simulate the original selection "freezed in time"
	for parent page */
	double gx, gy, gw, gh;


private:
	UndoManager * const undoManager;
	Page* m_page;
	Guides horizontalStdG;
	Guides verticalStdG;
	Guides horizontalAutoG;
	Guides verticalAutoG;

	double m_horizontalAutoGap;
	double m_verticalAutoGap;
	int m_horizontalAutoCount;
	int m_verticalAutoCount;
	int m_horizontalAutoRefer;
	int m_verticalAutoRefer;

	double closestHorAbove(double y);// const;
	double closestHorBelow(double y);// const;
	double closestVertLeft(double x);// const;
	double closestVertRight(double x);// const;
};


/*! \brief A separate clas for Guides IO operations in reading or closing
the documents.
\author Petr Vanek <petr@scribus.info>
*/
class SCRIBUS_API GuideManagerIO
{
	public:
		GuideManagerIO(){};
		~GuideManagerIO(){};

		/*! \brief Read the guides from XML attribute (file opening).
		It's statis method sou you can call it without instance initialized:
		GuideManagerIO::readHorizontalGuides(foo blah);
		\param guideString a string with all values separated by space (' '). E.g. "1.0 23.17 6"
		\param page a reference to the Page object to append the separated guideString values
		\param type Guide type to load
		\param useOldGuides A little bit hacking here. The guides were stored in a little mess
		in the ancient times. So when is the obsolete XML attribute found in reading document
		the old reading method is used. All guides are saved in new format then. */
		static void readHorizontalGuides(const QString guideString,
										 Page *page,
										 GuideManagerCore::GuideType type,
										 bool useOldGuides=false);

		/*! \brief Read the guides from XML attribute (file opening).
		It's statis method sou you can call it without instance initialized:
		GuideManagerIO::readVerticalGuides(foo blah);
		\param guideString a string with all values separated by space (' '). E.g. "1.0 23.17 6"
		\param page a reference to the Page object to append the separated guideString values
		\param type Guide type to load
		\param useOldGuides A little bit hacking here. The guides were stored in a little mess
		in the ancient times. So when is the obsolete XML attribute found in reading document
		the old reading method is used. All guides are saved in new format then. */
		static void readVerticalGuides(const QString guideString,
									   Page *page,
									   GuideManagerCore::GuideType type,
									   bool useOldGuides=false);

		static QString writeHorizontalGuides(Page *page, GuideManagerCore::GuideType type);
		static QString writeVerticalGuides(Page *page, GuideManagerCore::GuideType type);

		static void readSelection(const QString guideString, Page *page);
		static QString writeSelection(Page *page);
};

#endif