Mercurial > hg > svgui
comparison layer/Layer.cpp @ 273:e954c00cbe55
* proper (though ugly) handling of y coord for measure rects in scrollable layers
author | Chris Cannam |
---|---|
date | Fri, 29 Jun 2007 16:50:59 +0000 |
parents | 87e4c880b4c8 |
children | b9380f679f70 |
comparison
equal
deleted
inserted
replaced
272:87e4c880b4c8 | 273:e954c00cbe55 |
---|---|
167 s += QString("startX=\"%1\" endX=\"%2\" ") | 167 s += QString("startX=\"%1\" endX=\"%2\" ") |
168 .arg(pixrect.x()).arg(pixrect.x() + pixrect.width()); | 168 .arg(pixrect.x()).arg(pixrect.x() + pixrect.width()); |
169 } | 169 } |
170 | 170 |
171 s += QString("startY=\"%1\" endY=\"%2\"/>\n") | 171 s += QString("startY=\"%1\" endY=\"%2\"/>\n") |
172 .arg(pixrect.y()).arg(pixrect.y() + pixrect.height()); | 172 .arg(startY).arg(endY); |
173 | 173 |
174 return s; | 174 return s; |
175 } | 175 } |
176 | 176 |
177 void | 177 void |
178 Layer::addMeasurementRect(const QXmlAttributes &attributes) | 178 Layer::addMeasurementRect(const QXmlAttributes &attributes) |
179 { | 179 { |
180 MeasureRect rect; | 180 MeasureRect rect; |
181 QString fs = attributes.value("startFrame"); | 181 QString fs = attributes.value("startFrame"); |
182 int x0 = 0, y0 = 0, x1 = 0, y1 = 0; | 182 int x0 = 0, x1 = 0; |
183 if (fs != "") { | 183 if (fs != "") { |
184 rect.startFrame = fs.toLong(); | 184 rect.startFrame = fs.toLong(); |
185 rect.endFrame = attributes.value("endFrame").toLong(); | 185 rect.endFrame = attributes.value("endFrame").toLong(); |
186 rect.haveFrames = true; | 186 rect.haveFrames = true; |
187 } else { | 187 } else { |
188 x0 = attributes.value("startX").toInt(); | 188 x0 = attributes.value("startX").toInt(); |
189 x1 = attributes.value("endX").toInt(); | 189 x1 = attributes.value("endX").toInt(); |
190 rect.haveFrames = false; | 190 rect.haveFrames = false; |
191 } | 191 } |
192 y0 = attributes.value("startY").toInt(); | 192 rect.startY = attributes.value("startY").toDouble(); |
193 y1 = attributes.value("endY").toInt(); | 193 rect.endY = attributes.value("endY").toDouble(); |
194 rect.pixrect = QRect(x0, y0, x1 - x0, y1 - y0); | 194 rect.pixrect = QRect(x0, 0, x1 - x0, 0); |
195 addMeasureRectToSet(rect); | 195 addMeasureRectToSet(rect); |
196 } | 196 } |
197 | 197 |
198 QString | 198 QString |
199 Layer::AddMeasurementRectCommand::getName() const | 199 Layer::AddMeasurementRectCommand::getName() const |
222 m_draggingRect.startFrame = v->getFrameForX(e->x()); | 222 m_draggingRect.startFrame = v->getFrameForX(e->x()); |
223 m_draggingRect.endFrame = m_draggingRect.startFrame; | 223 m_draggingRect.endFrame = m_draggingRect.startFrame; |
224 } else { | 224 } else { |
225 m_draggingRect.haveFrames = false; | 225 m_draggingRect.haveFrames = false; |
226 } | 226 } |
227 setMeasureRectYCoord(v, m_draggingRect, true, e->y()); | |
227 m_haveDraggingRect = true; | 228 m_haveDraggingRect = true; |
228 } | 229 } |
229 | 230 |
230 void | 231 void |
231 Layer::measureDrag(View *v, QMouseEvent *e) | 232 Layer::measureDrag(View *v, QMouseEvent *e) |
236 m_draggingRect.pixrect.y(), | 237 m_draggingRect.pixrect.y(), |
237 e->x() - m_draggingRect.pixrect.x(), | 238 e->x() - m_draggingRect.pixrect.x(), |
238 e->y() - m_draggingRect.pixrect.y()) | 239 e->y() - m_draggingRect.pixrect.y()) |
239 .normalized(); | 240 .normalized(); |
240 | 241 |
242 setMeasureRectYCoord(v, m_draggingRect, false, e->y()); | |
243 | |
241 if (hasTimeXAxis()) { | 244 if (hasTimeXAxis()) { |
242 m_draggingRect.endFrame = v->getFrameForX(e->x()); | 245 m_draggingRect.endFrame = v->getFrameForX(e->x()); |
243 } | 246 } |
244 } | 247 } |
245 | 248 |
257 | 260 |
258 void | 261 void |
259 Layer::paintMeasurementRects(View *v, QPainter &paint, | 262 Layer::paintMeasurementRects(View *v, QPainter &paint, |
260 bool showFocus, QPoint focusPoint) const | 263 bool showFocus, QPoint focusPoint) const |
261 { | 264 { |
262 updateMeasurementPixrects(v); | 265 updateMeasurePixrects(v); |
263 | 266 |
264 MeasureRectSet::const_iterator focusRectItr = m_measureRects.end(); | 267 MeasureRectSet::const_iterator focusRectItr = m_measureRects.end(); |
265 | 268 |
266 if (m_haveDraggingRect) { | 269 if (m_haveDraggingRect) { |
267 | 270 |
279 } | 282 } |
280 | 283 |
281 bool | 284 bool |
282 Layer::nearestMeasurementRectChanged(View *v, QPoint prev, QPoint now) const | 285 Layer::nearestMeasurementRectChanged(View *v, QPoint prev, QPoint now) const |
283 { | 286 { |
284 updateMeasurementPixrects(v); | 287 updateMeasurePixrects(v); |
285 | 288 |
286 MeasureRectSet::const_iterator i0 = findFocusedMeasureRect(prev); | 289 MeasureRectSet::const_iterator i0 = findFocusedMeasureRect(prev); |
287 MeasureRectSet::const_iterator i1 = findFocusedMeasureRect(now); | 290 MeasureRectSet::const_iterator i1 = findFocusedMeasureRect(now); |
288 | 291 |
289 return (i0 != i1); | 292 return (i0 != i1); |
290 } | 293 } |
291 | 294 |
292 void | 295 void |
293 Layer::updateMeasurementPixrects(View *v) const | 296 Layer::updateMeasurePixrects(View *v) const |
294 { | 297 { |
295 long sf = v->getStartFrame(); | 298 long sf = v->getStartFrame(); |
296 long ef = v->getEndFrame(); | 299 long ef = v->getEndFrame(); |
297 | 300 |
298 for (MeasureRectSet::const_iterator i = m_measureRects.begin(); | 301 for (MeasureRectSet::const_iterator i = m_measureRects.begin(); |
299 i != m_measureRects.end(); ++i) { | 302 i != m_measureRects.end(); ++i) { |
300 | 303 |
301 if (!i->haveFrames) continue; | 304 // This logic depends on the fact that if one measure rect in |
302 | 305 // a layer has frame values, they all will. That is in fact |
303 if (i->startFrame >= ef) break; | 306 // the case, because haveFrames is based on whether the layer |
304 if (i->endFrame <= sf) continue; | 307 // hasTimeXAxis() or not. Measure rect ordering in the rect |
305 | 308 // set wouldn't work correctly either, if haveFrames could |
306 int x0 = -1; | 309 // vary. |
307 int x1 = v->width() + 1; | 310 |
308 | 311 if (i->haveFrames) { |
309 if (i->startFrame >= v->getStartFrame()) { | 312 if (i->startFrame >= ef) break; |
310 x0 = v->getXForFrame(i->startFrame); | 313 if (i->endFrame <= sf) continue; |
311 } | 314 } |
312 if (i->endFrame <= long(v->getEndFrame())) { | 315 |
313 x1 = v->getXForFrame(i->endFrame); | 316 int x0 = i->pixrect.x(); |
314 } | 317 int x1 = x0 + i->pixrect.width(); |
315 | 318 |
316 QRect pr = QRect(x0, i->pixrect.y(), x1 - x0, i->pixrect.height()); | 319 if (i->haveFrames) { |
317 | 320 if (i->startFrame >= v->getStartFrame()) { |
318 i->pixrect = pr; | 321 x0 = v->getXForFrame(i->startFrame); |
322 } | |
323 if (i->endFrame <= long(v->getEndFrame())) { | |
324 x1 = v->getXForFrame(i->endFrame); | |
325 } | |
326 } | |
327 | |
328 i->pixrect = QRect(x0, i->pixrect.y(), x1 - x0, i->pixrect.height()); | |
329 | |
330 updateMeasureRectYCoords(v, *i); | |
331 | |
332 i->pixrect = i->pixrect.normalized(); | |
333 } | |
334 } | |
335 | |
336 void | |
337 Layer::updateMeasureRectYCoords(View *v, const MeasureRect &r) const | |
338 { | |
339 int y0 = lrint(r.startY * v->height()); | |
340 int y1 = lrint(r.endY * v->height()); | |
341 r.pixrect = QRect(r.pixrect.x(), y0, r.pixrect.width(), y1 - y0); | |
342 } | |
343 | |
344 void | |
345 Layer::setMeasureRectYCoord(View *v, MeasureRect &r, bool start, int y) const | |
346 { | |
347 if (start) { | |
348 r.startY = double(y) / double(v->height()); | |
349 r.endY = r.startY; | |
350 } else { | |
351 r.endY = double(y) / double(v->height()); | |
319 } | 352 } |
320 } | 353 } |
321 | 354 |
322 Layer::MeasureRectSet::const_iterator | 355 Layer::MeasureRectSet::const_iterator |
323 Layer::findFocusedMeasureRect(QPoint focusPoint) const | 356 Layer::findFocusedMeasureRect(QPoint focusPoint) const |