Changeset View
Changeset View
Standalone View
Standalone View
src/creator/qml/BookPage.qml
Context not available. | |||||
22 | import QtQuick 2.2 | 22 | import QtQuick 2.2 | ||
---|---|---|---|---|---|
23 | 23 | | |||
24 | import org.kde.kirigami 2.1 as Kirigami | 24 | import org.kde.kirigami 2.1 as Kirigami | ||
25 | 25 | /** | |||
26 | * Page that holds an image to edit the frames on. | ||||
27 | */ | ||||
26 | Kirigami.Page { | 28 | Kirigami.Page { | ||
27 | id: root; | 29 | id: root; | ||
28 | property string categoryName: "bookPage"; | 30 | property string categoryName: "bookPage"; | ||
29 | title: i18nc("title of the page editing sub-page for the book editor", "Page %1", root.title); | 31 | title: i18nc("title of the page editing sub-page for the book editor", "Page %1", root.pageTitle === "" ? root.index : root.pageTitle); | ||
30 | property string title; | 32 | property QtObject model; | ||
33 | property QtObject currentPage; | ||||
34 | property int index: -1; | ||||
35 | property string pageUrl: ""; | ||||
36 | property string pageTitle: ""; | ||||
37 | signal save(); | ||||
38 | | ||||
39 | | ||||
40 | onIndexChanged: { | ||||
41 | if (root.index===0) { | ||||
42 | root.currentPage = root.model.acbfData.metaData.bookInfo.coverpage(); | ||||
43 | } else if (root.index > 0) { | ||||
44 | root.currentPage = root.model.acbfData.body.page(root.index-1); | ||||
45 | } | ||||
46 | root.pageTitle = root.currentPage.title(""); | ||||
47 | // Let's ensure there's always a default text-layer. | ||||
48 | if (root.currentPage.textLayerLanguages.length === 0) { | ||||
49 | root.currentPage.addTextLayer("") | ||||
50 | } else if (root.currentPage.textLayerLanguages.indexOf("") < 0) { | ||||
51 | root.currentPage.duplicateTextLayer(root.currentPage.textLayerLanguages[1], ""); | ||||
52 | } | ||||
53 | } | ||||
54 | | ||||
55 | actions { | ||||
56 | main: saveAndCloseAction; | ||||
57 | right: editPageDataAction; | ||||
58 | } | ||||
59 | Kirigami.Action { | ||||
60 | id: saveAndCloseAction; | ||||
61 | text: i18nc("Saves the remaining unsaved edited fields and closes the page editor", "Save and Close Page"); | ||||
62 | iconName: "dialog-ok"; | ||||
63 | shortcut: "Esc"; | ||||
64 | onTriggered: { | ||||
65 | root.save(); | ||||
66 | root.model.setDirty(); | ||||
67 | pageStack.pop(); | ||||
68 | } | ||||
69 | } | ||||
70 | Kirigami.Action { | ||||
71 | id: editPageDataAction; | ||||
72 | text: i18nc("Edit the page data in detail", "Edit Page Data"); | ||||
73 | iconName: "document-edit" | ||||
74 | onTriggered: pageStack.push(pageInfo) | ||||
75 | } | ||||
76 | | ||||
77 | Image { | ||||
78 | id: coverImage; | ||||
79 | anchors { | ||||
80 | fill: parent; | ||||
81 | margins: Kirigami.Units.smallSpacing; | ||||
82 | } | ||||
83 | asynchronous: true; | ||||
84 | fillMode: Image.PreserveAspectFit; | ||||
85 | source: pageUrl; | ||||
86 | width: root.width; | ||||
87 | height: root.height; | ||||
88 | property real muliplierWidth: (paintedWidth / sourceSize.width); | ||||
89 | property real muliplierHeight: (paintedHeight / sourceSize.height); | ||||
90 | property int offsetX: (width-paintedWidth)/2 | ||||
91 | property int offsetY: (height-paintedHeight)/2 | ||||
92 | | ||||
93 | Repeater { | ||||
94 | model: root.currentPage.frameCount | ||||
95 | | ||||
96 | Rectangle { | ||||
97 | width: coverImage.muliplierWidth * root.currentPage.frame(index).bounds.width; | ||||
98 | height: coverImage.muliplierHeight * root.currentPage.frame(index).bounds.height; | ||||
99 | x: coverImage.muliplierWidth * root.currentPage.frame(index).bounds.x + coverImage.offsetX | ||||
100 | y: coverImage.muliplierHeight * root.currentPage.frame(index).bounds.y + coverImage.offsetY; | ||||
101 | border.color: "blue"; | ||||
102 | color: "transparent"; | ||||
103 | opacity: 0.5; | ||||
104 | border.width: Kirigami.Units.smallSpacing; | ||||
105 | Rectangle { | ||||
106 | anchors.fill: parent; | ||||
107 | opacity: 0.4; | ||||
108 | color: "blue"; | ||||
109 | } | ||||
110 | Text { | ||||
111 | text: index+1; | ||||
112 | anchors { | ||||
113 | centerIn: parent; | ||||
114 | } | ||||
115 | color: "blue"; | ||||
116 | font.weight: Font.Bold; | ||||
117 | } | ||||
118 | } | ||||
119 | } | ||||
120 | | ||||
121 | Repeater { | ||||
122 | model: root.currentPage.textLayer("").textareaCount | ||||
123 | | ||||
124 | Rectangle { | ||||
125 | width: coverImage.muliplierWidth * root.currentPage.textLayer("").textarea(index).bounds.width; | ||||
126 | height: coverImage.muliplierHeight * root.currentPage.textLayer("").textarea(index).bounds.height; | ||||
127 | x: coverImage.muliplierWidth * root.currentPage.textLayer("").textarea(index).bounds.x + coverImage.offsetX | ||||
128 | y: coverImage.muliplierHeight * root.currentPage.textLayer("").textarea(index).bounds.y + coverImage.offsetY; | ||||
129 | border.color: "red"; | ||||
130 | color: "transparent"; | ||||
131 | opacity: 0.5; | ||||
132 | border.width: Kirigami.Units.smallSpacing; | ||||
133 | Rectangle { | ||||
134 | anchors.fill: parent; | ||||
135 | opacity: 0.4; | ||||
136 | color: "red"; | ||||
137 | } | ||||
138 | Text { | ||||
139 | text: index+1; | ||||
140 | anchors { | ||||
141 | centerIn: parent; | ||||
142 | } | ||||
143 | color: "red"; | ||||
144 | font.weight: Font.Bold; | ||||
145 | } | ||||
146 | } | ||||
147 | } | ||||
148 | | ||||
149 | Repeater { | ||||
150 | model: root.currentPage.jumpCount | ||||
151 | | ||||
152 | Rectangle { | ||||
153 | width: coverImage.muliplierWidth * root.currentPage.jump(index).bounds.width; | ||||
154 | height: coverImage.muliplierHeight * root.currentPage.jump(index).bounds.height; | ||||
155 | x: coverImage.muliplierWidth * root.currentPage.jump(index).bounds.x + coverImage.offsetX | ||||
156 | y: coverImage.muliplierHeight * root.currentPage.jump(index).bounds.y + coverImage.offsetY; | ||||
157 | border.color: "green"; | ||||
158 | color: "transparent"; | ||||
159 | opacity: 0.5; | ||||
160 | border.width: Kirigami.Units.smallSpacing; | ||||
161 | Rectangle { | ||||
162 | anchors.fill: parent; | ||||
163 | opacity: 0.4; | ||||
164 | color: "green"; | ||||
165 | } | ||||
166 | Text { | ||||
167 | text: index+1; | ||||
168 | anchors { | ||||
169 | centerIn: parent; | ||||
170 | } | ||||
171 | color: "green"; | ||||
172 | font.weight: Font.Bold; | ||||
173 | } | ||||
174 | } | ||||
175 | } | ||||
176 | MouseArea { | ||||
177 | anchors.fill: parent; | ||||
178 | id: pointCatchArea; | ||||
179 | property point startPoint: Qt.point(0,0); | ||||
180 | property point endPoint: Qt.point(0,0); | ||||
181 | property bool dragging: false; | ||||
182 | //hoverEnabled: true; | ||||
183 | preventStealing: true; | ||||
184 | | ||||
185 | onPressed: { | ||||
186 | if (dragging == false) { | ||||
187 | startPoint = Qt.point(mouse.x, mouse.y); | ||||
188 | endPoint = startPoint; | ||||
189 | dragging = true; | ||||
190 | mouse.accepted | ||||
191 | } | ||||
192 | | ||||
193 | } | ||||
194 | | ||||
195 | onPositionChanged: { | ||||
196 | if (dragging) { | ||||
197 | endPoint = Qt.point(mouse.x, mouse.y) | ||||
198 | mouse.accepted | ||||
199 | } | ||||
200 | } | ||||
201 | | ||||
202 | onReleased: { | ||||
203 | if (dragging) { | ||||
204 | if (Qt.point(mouse.x, mouse.y)!==startPoint) { | ||||
205 | endPoint = Qt.point(mouse.x, mouse.y); | ||||
206 | dragging = false; | ||||
207 | createFrame(); | ||||
208 | mouse.accepted | ||||
209 | } | ||||
210 | } | ||||
211 | | ||||
212 | } | ||||
213 | onCanceled: { | ||||
214 | dragging = false; | ||||
215 | endPoint: Qt.point(0,0); | ||||
216 | startPoint: Qt.point(0,0); | ||||
217 | } | ||||
218 | | ||||
219 | Rectangle { | ||||
220 | x: Math.min(parent.startPoint.x, parent.endPoint.x); | ||||
221 | y: Math.min(parent.startPoint.y, parent.endPoint.y); | ||||
222 | width: Math.max(parent.startPoint.x, parent.endPoint.x) - Math.min(parent.startPoint.x, parent.endPoint.x); | ||||
223 | height: Math.max(parent.startPoint.y, parent.endPoint.y) - Math.min(parent.startPoint.y, parent.endPoint.y); | ||||
224 | opacity: 0.5; | ||||
225 | border.color: "black"; | ||||
226 | border.width: 1; | ||||
227 | } | ||||
228 | | ||||
229 | function createFrame() { | ||||
230 | var x = ( Math.min(startPoint.x, endPoint.x) - coverImage.offsetX ) / coverImage.muliplierWidth; | ||||
231 | var x2 = ( Math.max(startPoint.x, endPoint.x) - coverImage.offsetX ) / coverImage.muliplierWidth; | ||||
232 | var y = ( Math.min(startPoint.y, endPoint.y) - coverImage.offsetY ) / coverImage.muliplierHeight; | ||||
233 | var y2 = ( Math.max(startPoint.y, endPoint.y) - coverImage.offsetY ) / coverImage.muliplierHeight; | ||||
234 | | ||||
235 | addPageArea.topLeft = Qt.point(x,y); | ||||
236 | addPageArea.bottomRight = Qt.point(x2,y2); | ||||
237 | endPoint = startPoint; | ||||
238 | addPageArea.open(); | ||||
239 | } | ||||
240 | | ||||
241 | } | ||||
242 | } | ||||
243 | Component { | ||||
244 | id: pageInfo; | ||||
245 | PageMetaInfo { | ||||
246 | colorname: root.model.acbfData.body.bgcolor !== ""? root.model.acbfData.body.bgcolor: "#ffffff"; | ||||
247 | page: root.currentPage; | ||||
248 | onSave: {root.pageTitle = page.title(""); root.model.setDirty();} | ||||
249 | } | ||||
250 | } | ||||
251 | | ||||
252 | AddPageArea { | ||||
253 | id: addPageArea | ||||
254 | onSave: { | ||||
255 | var index = 0; | ||||
256 | if (type===0) { | ||||
257 | index = root.currentPage.frameCount; | ||||
258 | root.currentPage.addFrame(index); | ||||
259 | root.currentPage.frame(index).setPointsFromRect(topLeft, bottomRight); | ||||
260 | } else if (type===1) { | ||||
261 | index = root.currentPage.textLayer("").textareaCount; | ||||
262 | root.currentPage.textLayer("").addTextarea(index); | ||||
263 | root.currentPage.textLayer("").textarea(index).setPointsFromRect(topLeft, bottomRight); | ||||
264 | } else if (type===2) { | ||||
265 | index = root.currentPage.jumpCount; | ||||
266 | root.currentPage.addJump(index); | ||||
267 | root.currentPage.jump(index).setPointsFromRect(topLeft, bottomRight); | ||||
268 | } | ||||
269 | } | ||||
270 | } | ||||
271 | | ||||
31 | } | 272 | } | ||
Context not available. |