Chris@58
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@59
|
4 Sonic Visualiser
|
Chris@59
|
5 An audio file viewer and annotation editor.
|
Chris@59
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@59
|
7 This file copyright 2006 Chris Cannam.
|
Chris@0
|
8
|
Chris@59
|
9 This program is free software; you can redistribute it and/or
|
Chris@59
|
10 modify it under the terms of the GNU General Public License as
|
Chris@59
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@59
|
12 License, or (at your option) any later version. See the file
|
Chris@59
|
13 COPYING included with this distribution for more information.
|
Chris@0
|
14 */
|
Chris@0
|
15
|
Chris@0
|
16 #include "widgets/Pane.h"
|
Chris@0
|
17 #include "base/Layer.h"
|
Chris@0
|
18 #include "base/Model.h"
|
Chris@0
|
19 #include "base/ZoomConstraint.h"
|
Chris@0
|
20 #include "base/RealTime.h"
|
Chris@0
|
21 #include "base/Profiler.h"
|
Chris@13
|
22 #include "base/ViewManager.h"
|
Chris@41
|
23 #include "layer/WaveformLayer.h"
|
Chris@0
|
24
|
Chris@0
|
25 #include <QPaintEvent>
|
Chris@0
|
26 #include <QPainter>
|
Chris@0
|
27 #include <iostream>
|
Chris@0
|
28 #include <cmath>
|
Chris@0
|
29
|
Chris@0
|
30 using std::cerr;
|
Chris@0
|
31 using std::endl;
|
Chris@0
|
32
|
Chris@0
|
33 Pane::Pane(QWidget *w) :
|
Chris@0
|
34 View(w, true),
|
Chris@0
|
35 m_identifyFeatures(false),
|
Chris@0
|
36 m_clickedInRange(false),
|
Chris@0
|
37 m_shiftPressed(false),
|
Chris@13
|
38 m_ctrlPressed(false),
|
Chris@17
|
39 m_navigating(false),
|
Chris@17
|
40 m_resizing(false),
|
Chris@0
|
41 m_centreLineVisible(true)
|
Chris@0
|
42 {
|
Chris@0
|
43 setObjectName("Pane");
|
Chris@0
|
44 setMouseTracking(true);
|
Chris@0
|
45 }
|
Chris@0
|
46
|
Chris@0
|
47 bool
|
Chris@44
|
48 Pane::shouldIlluminateLocalFeatures(const Layer *layer, QPoint &pos) const
|
Chris@0
|
49 {
|
Chris@42
|
50 QPoint discard;
|
Chris@42
|
51 bool b0, b1;
|
Chris@42
|
52
|
Chris@42
|
53 if (layer == getSelectedLayer() &&
|
Chris@42
|
54 !shouldIlluminateLocalSelection(discard, b0, b1)) {
|
Chris@42
|
55
|
Chris@27
|
56 pos = m_identifyPoint;
|
Chris@27
|
57 return m_identifyFeatures;
|
Chris@27
|
58 }
|
Chris@0
|
59
|
Chris@0
|
60 return false;
|
Chris@0
|
61 }
|
Chris@0
|
62
|
Chris@42
|
63 bool
|
Chris@42
|
64 Pane::shouldIlluminateLocalSelection(QPoint &pos,
|
Chris@42
|
65 bool &closeToLeft,
|
Chris@44
|
66 bool &closeToRight) const
|
Chris@42
|
67 {
|
Chris@42
|
68 if (m_identifyFeatures &&
|
Chris@42
|
69 m_manager &&
|
Chris@42
|
70 m_manager->getToolMode() == ViewManager::EditMode &&
|
Chris@42
|
71 !m_manager->getSelections().empty() &&
|
Chris@42
|
72 !selectionIsBeingEdited()) {
|
Chris@42
|
73
|
Chris@42
|
74 Selection s(getSelectionAt(m_identifyPoint.x(),
|
Chris@42
|
75 closeToLeft, closeToRight));
|
Chris@42
|
76
|
Chris@42
|
77 if (!s.isEmpty()) {
|
Chris@42
|
78 if (getSelectedLayer() && getSelectedLayer()->isLayerEditable()) {
|
Chris@42
|
79
|
Chris@42
|
80 pos = m_identifyPoint;
|
Chris@42
|
81 return true;
|
Chris@42
|
82 }
|
Chris@42
|
83 }
|
Chris@42
|
84 }
|
Chris@42
|
85
|
Chris@42
|
86 return false;
|
Chris@42
|
87 }
|
Chris@42
|
88
|
Chris@42
|
89 bool
|
Chris@42
|
90 Pane::selectionIsBeingEdited() const
|
Chris@42
|
91 {
|
Chris@42
|
92 if (!m_editingSelection.isEmpty()) {
|
Chris@42
|
93 if (m_mousePos != m_clickPos &&
|
Chris@42
|
94 getFrameForX(m_mousePos.x()) != getFrameForX(m_clickPos.x())) {
|
Chris@42
|
95 return true;
|
Chris@42
|
96 }
|
Chris@42
|
97 }
|
Chris@42
|
98 return false;
|
Chris@42
|
99 }
|
Chris@42
|
100
|
Chris@0
|
101 void
|
Chris@0
|
102 Pane::setCentreLineVisible(bool visible)
|
Chris@0
|
103 {
|
Chris@0
|
104 m_centreLineVisible = visible;
|
Chris@0
|
105 update();
|
Chris@0
|
106 }
|
Chris@0
|
107
|
Chris@0
|
108 void
|
Chris@0
|
109 Pane::paintEvent(QPaintEvent *e)
|
Chris@0
|
110 {
|
Chris@0
|
111 QPainter paint;
|
Chris@0
|
112
|
Chris@0
|
113 QRect r(rect());
|
Chris@0
|
114
|
Chris@0
|
115 if (e) {
|
Chris@0
|
116 r = e->rect();
|
Chris@0
|
117 }
|
Chris@0
|
118 /*
|
Chris@0
|
119 paint.begin(this);
|
Chris@0
|
120 paint.setClipRect(r);
|
Chris@0
|
121
|
Chris@0
|
122 if (hasLightBackground()) {
|
Chris@0
|
123 paint.setPen(Qt::white);
|
Chris@0
|
124 paint.setBrush(Qt::white);
|
Chris@0
|
125 } else {
|
Chris@0
|
126 paint.setPen(Qt::black);
|
Chris@0
|
127 paint.setBrush(Qt::black);
|
Chris@0
|
128 }
|
Chris@0
|
129 paint.drawRect(r);
|
Chris@0
|
130
|
Chris@0
|
131 paint.end();
|
Chris@0
|
132 */
|
Chris@0
|
133 View::paintEvent(e);
|
Chris@0
|
134
|
Chris@0
|
135 paint.begin(this);
|
Chris@0
|
136
|
Chris@0
|
137 if (e) {
|
Chris@0
|
138 paint.setClipRect(r);
|
Chris@0
|
139 }
|
Chris@41
|
140
|
Chris@41
|
141 const Model *waveformModel = 0; // just for reporting purposes
|
Chris@51
|
142 int verticalScaleWidth = 0;
|
Chris@41
|
143
|
Chris@55
|
144 int fontHeight = paint.fontMetrics().height();
|
Chris@55
|
145 int fontAscent = paint.fontMetrics().ascent();
|
Chris@55
|
146
|
Chris@0
|
147 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
|
Chris@0
|
148 --vi;
|
Chris@0
|
149
|
Chris@41
|
150 if (dynamic_cast<WaveformLayer *>(*vi)) {
|
Chris@41
|
151 waveformModel = (*vi)->getModel();
|
Chris@41
|
152 }
|
Chris@41
|
153
|
Chris@51
|
154 verticalScaleWidth = (*vi)->getVerticalScaleWidth(this, paint);
|
Chris@0
|
155
|
Chris@51
|
156 if (verticalScaleWidth > 0 && r.left() < verticalScaleWidth) {
|
Chris@0
|
157
|
Chris@0
|
158 // Profiler profiler("Pane::paintEvent - painting vertical scale", true);
|
Chris@0
|
159
|
Chris@0
|
160 // std::cerr << "Pane::paintEvent: calling paint.save() in vertical scale block" << std::endl;
|
Chris@0
|
161 paint.save();
|
Chris@0
|
162
|
Chris@0
|
163 paint.setPen(Qt::black);
|
Chris@0
|
164 paint.setBrush(Qt::white);
|
Chris@51
|
165 paint.drawRect(0, 0, verticalScaleWidth, height());
|
Chris@0
|
166
|
Chris@0
|
167 paint.setBrush(Qt::NoBrush);
|
Chris@51
|
168 (*vi)->paintVerticalScale
|
Chris@51
|
169 (this, paint, QRect(0, 0, verticalScaleWidth, height()));
|
Chris@0
|
170
|
Chris@0
|
171 paint.restore();
|
Chris@0
|
172 }
|
Chris@41
|
173
|
Chris@0
|
174 if (m_identifyFeatures) {
|
Chris@25
|
175
|
Chris@25
|
176 QPoint pos = m_identifyPoint;
|
Chris@44
|
177 QString desc = (*vi)->getFeatureDescription(this, pos);
|
Chris@25
|
178
|
Chris@25
|
179 if (desc != "") {
|
Chris@25
|
180
|
Chris@25
|
181 paint.save();
|
Chris@25
|
182
|
Chris@25
|
183 int tabStop =
|
Chris@25
|
184 paint.fontMetrics().width(tr("Some lengthy prefix:"));
|
Chris@25
|
185
|
Chris@25
|
186 QRect boundingRect =
|
Chris@25
|
187 paint.fontMetrics().boundingRect
|
Chris@25
|
188 (rect(),
|
Chris@25
|
189 Qt::AlignRight | Qt::AlignTop | Qt::TextExpandTabs,
|
Chris@25
|
190 desc, tabStop);
|
Chris@25
|
191
|
Chris@25
|
192 if (hasLightBackground()) {
|
Chris@25
|
193 paint.setPen(Qt::NoPen);
|
Chris@25
|
194 paint.setBrush(QColor(250, 250, 250, 200));
|
Chris@25
|
195 } else {
|
Chris@25
|
196 paint.setPen(Qt::NoPen);
|
Chris@25
|
197 paint.setBrush(QColor(50, 50, 50, 200));
|
Chris@25
|
198 }
|
Chris@25
|
199
|
Chris@25
|
200 int extra = paint.fontMetrics().descent();
|
Chris@25
|
201 paint.drawRect(width() - boundingRect.width() - 10 - extra,
|
Chris@25
|
202 10 - extra,
|
Chris@25
|
203 boundingRect.width() + 2 * extra,
|
Chris@25
|
204 boundingRect.height() + extra);
|
Chris@25
|
205
|
Chris@25
|
206 if (hasLightBackground()) {
|
Chris@25
|
207 paint.setPen(QColor(150, 20, 0));
|
Chris@25
|
208 } else {
|
Chris@25
|
209 paint.setPen(QColor(255, 150, 100));
|
Chris@25
|
210 }
|
Chris@25
|
211
|
Chris@25
|
212 QTextOption option;
|
Chris@25
|
213 option.setWrapMode(QTextOption::NoWrap);
|
Chris@25
|
214 option.setAlignment(Qt::AlignRight | Qt::AlignTop);
|
Chris@25
|
215 option.setTabStop(tabStop);
|
Chris@25
|
216 paint.drawText(QRectF(width() - boundingRect.width() - 10, 10,
|
Chris@25
|
217 boundingRect.width(),
|
Chris@25
|
218 boundingRect.height()),
|
Chris@25
|
219 desc,
|
Chris@25
|
220 option);
|
Chris@25
|
221
|
Chris@25
|
222 paint.restore();
|
Chris@25
|
223 }
|
Chris@0
|
224 }
|
Chris@0
|
225
|
Chris@0
|
226 break;
|
Chris@0
|
227 }
|
Chris@0
|
228
|
Chris@55
|
229 int sampleRate = getModelsSampleRate();
|
Chris@55
|
230 paint.setBrush(Qt::NoBrush);
|
Chris@55
|
231
|
Chris@0
|
232 if (m_centreLineVisible) {
|
Chris@0
|
233
|
Chris@0
|
234 if (hasLightBackground()) {
|
Chris@0
|
235 paint.setPen(QColor(50, 50, 50));
|
Chris@0
|
236 } else {
|
Chris@0
|
237 paint.setPen(QColor(200, 200, 200));
|
Chris@0
|
238 }
|
Chris@0
|
239 paint.drawLine(width() / 2, 0, width() / 2, height() - 1);
|
Chris@0
|
240
|
Chris@55
|
241 paint.setPen(QColor(50, 50, 50));
|
Chris@55
|
242
|
Chris@55
|
243 int y = height() - fontHeight
|
Chris@55
|
244 + fontAscent - 6;
|
Chris@0
|
245
|
Chris@0
|
246 LayerList::iterator vi = m_layers.end();
|
Chris@0
|
247
|
Chris@0
|
248 if (vi != m_layers.begin()) {
|
Chris@0
|
249
|
Chris@0
|
250 switch ((*--vi)->getPreferredFrameCountPosition()) {
|
Chris@0
|
251
|
Chris@0
|
252 case Layer::PositionTop:
|
Chris@55
|
253 y = fontAscent + 6;
|
Chris@0
|
254 break;
|
Chris@0
|
255
|
Chris@0
|
256 case Layer::PositionMiddle:
|
Chris@55
|
257 y = (height() - fontHeight) / 2
|
Chris@55
|
258 + fontAscent;
|
Chris@0
|
259 break;
|
Chris@0
|
260
|
Chris@0
|
261 case Layer::PositionBottom:
|
Chris@0
|
262 // y already set correctly
|
Chris@0
|
263 break;
|
Chris@0
|
264 }
|
Chris@0
|
265 }
|
Chris@0
|
266
|
Chris@0
|
267 if (sampleRate) {
|
Chris@0
|
268
|
Chris@0
|
269 QString text(QString::fromStdString
|
Chris@0
|
270 (RealTime::frame2RealTime
|
Chris@0
|
271 (m_centreFrame, sampleRate).toText(true)));
|
Chris@0
|
272
|
Chris@0
|
273 int tw = paint.fontMetrics().width(text);
|
Chris@0
|
274 int x = width()/2 - 4 - tw;
|
Chris@0
|
275
|
Chris@55
|
276 drawVisibleText(paint, x, y, text, OutlinedText);
|
Chris@0
|
277 }
|
Chris@0
|
278
|
Chris@0
|
279 QString text = QString("%1").arg(m_centreFrame);
|
Chris@0
|
280
|
Chris@0
|
281 int tw = paint.fontMetrics().width(text);
|
Chris@0
|
282 int x = width()/2 + 4;
|
Chris@55
|
283
|
Chris@55
|
284 drawVisibleText(paint, x, y, text, OutlinedText);
|
Chris@55
|
285
|
Chris@55
|
286 } else {
|
Chris@55
|
287
|
Chris@55
|
288 paint.setPen(QColor(50, 50, 50));
|
Chris@55
|
289 }
|
Chris@55
|
290
|
Chris@55
|
291 if (waveformModel &&
|
Chris@55
|
292 r.y() + r.height() >= height() - fontHeight - 6) {
|
Chris@55
|
293
|
Chris@55
|
294 size_t mainModelRate = m_manager->getMainModelSampleRate();
|
Chris@55
|
295 size_t playbackRate = m_manager->getPlaybackSampleRate();
|
Chris@55
|
296
|
Chris@55
|
297 QString srNote = "";
|
Chris@55
|
298
|
Chris@55
|
299 // Show (R) for waveform models that will be resampled on
|
Chris@55
|
300 // playback, and (X) for waveform models that will be played
|
Chris@55
|
301 // at the wrong rate because their rate differs from that of
|
Chris@55
|
302 // the main model.
|
Chris@55
|
303
|
Chris@55
|
304 if (sampleRate == mainModelRate) {
|
Chris@55
|
305 if (sampleRate != playbackRate) srNote = " " + tr("(R)");
|
Chris@0
|
306 } else {
|
Chris@55
|
307 std::cerr << "Sample rate = " << sampleRate << ", main model rate = " << mainModelRate << std::endl;
|
Chris@55
|
308 srNote = " " + tr("(X)");
|
Chris@0
|
309 }
|
Chris@41
|
310
|
Chris@55
|
311 QString desc = tr("%1 / %2Hz%3")
|
Chris@55
|
312 .arg(RealTime::frame2RealTime(waveformModel->getEndFrame(),
|
Chris@55
|
313 sampleRate)
|
Chris@55
|
314 .toText(false).c_str())
|
Chris@55
|
315 .arg(sampleRate)
|
Chris@55
|
316 .arg(srNote);
|
Chris@49
|
317
|
Chris@55
|
318 if (r.x() < verticalScaleWidth + 5 + paint.fontMetrics().width(desc)) {
|
Chris@55
|
319 drawVisibleText(paint, verticalScaleWidth + 5,
|
Chris@55
|
320 height() - fontHeight + fontAscent - 6,
|
Chris@55
|
321 desc, OutlinedText);
|
Chris@55
|
322 }
|
Chris@55
|
323 }
|
Chris@50
|
324
|
Chris@55
|
325 if (r.y() + r.height() >= height() - m_layers.size() * fontHeight - 6) {
|
Chris@51
|
326
|
Chris@51
|
327 std::vector<QString> texts;
|
Chris@51
|
328 int maxTextWidth = 0;
|
Chris@51
|
329
|
Chris@51
|
330 for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
|
Chris@51
|
331
|
Chris@56
|
332 QString text = (*i)->getLayerPresentationName();
|
Chris@51
|
333 int tw = paint.fontMetrics().width(text);
|
Chris@61
|
334 bool reduced = false;
|
Chris@61
|
335 while (tw > width() / 3 && text.length() > 4) {
|
Chris@61
|
336 if (!reduced && text.length() > 8) {
|
Chris@61
|
337 text = text.left(text.length() - 4);
|
Chris@61
|
338 } else {
|
Chris@61
|
339 text = text.left(text.length() - 2);
|
Chris@61
|
340 }
|
Chris@61
|
341 reduced = true;
|
Chris@61
|
342 tw = paint.fontMetrics().width(text + "...");
|
Chris@61
|
343 }
|
Chris@61
|
344 if (reduced) {
|
Chris@61
|
345 texts.push_back(text + "...");
|
Chris@61
|
346 } else {
|
Chris@61
|
347 texts.push_back(text);
|
Chris@61
|
348 }
|
Chris@51
|
349 if (tw > maxTextWidth) maxTextWidth = tw;
|
Chris@51
|
350 }
|
Chris@55
|
351
|
Chris@51
|
352 int lly = height() - 6;
|
Chris@51
|
353
|
Chris@55
|
354 if (r.x() + r.width() >= width() - maxTextWidth - 5) {
|
Chris@55
|
355
|
Chris@55
|
356 for (int i = 0; i < texts.size(); ++i) {
|
Chris@51
|
357
|
Chris@55
|
358 if (i == texts.size() - 1) {
|
Chris@51
|
359 paint.setPen(Qt::black);
|
Chris@51
|
360 }
|
Chris@55
|
361
|
Chris@55
|
362 drawVisibleText(paint, width() - maxTextWidth - 5,
|
Chris@55
|
363 lly - fontHeight + fontAscent,
|
Chris@55
|
364 texts[i], OutlinedText);
|
Chris@55
|
365
|
Chris@55
|
366 lly -= fontHeight;
|
Chris@51
|
367 }
|
Chris@51
|
368 }
|
Chris@0
|
369 }
|
Chris@0
|
370
|
Chris@0
|
371 if (m_clickedInRange && m_shiftPressed) {
|
Chris@19
|
372 if (m_manager && (m_manager->getToolMode() == ViewManager::NavigateMode)) {
|
Chris@19
|
373 //!!! be nice if this looked a bit more in keeping with the
|
Chris@19
|
374 //selection block
|
Chris@19
|
375 paint.setPen(Qt::blue);
|
Chris@19
|
376 paint.drawRect(m_clickPos.x(), m_clickPos.y(),
|
Chris@19
|
377 m_mousePos.x() - m_clickPos.x(),
|
Chris@19
|
378 m_mousePos.y() - m_clickPos.y());
|
Chris@19
|
379 }
|
Chris@0
|
380 }
|
Chris@0
|
381
|
Chris@42
|
382 if (selectionIsBeingEdited()) {
|
Chris@42
|
383
|
Chris@42
|
384 int offset = m_mousePos.x() - m_clickPos.x();
|
Chris@42
|
385 int p0 = getXForFrame(m_editingSelection.getStartFrame()) + offset;
|
Chris@42
|
386 int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset;
|
Chris@42
|
387
|
Chris@42
|
388 if (m_editingSelectionEdge < 0) {
|
Chris@42
|
389 p1 = getXForFrame(m_editingSelection.getEndFrame());
|
Chris@42
|
390 } else if (m_editingSelectionEdge > 0) {
|
Chris@42
|
391 p0 = getXForFrame(m_editingSelection.getStartFrame());
|
Chris@42
|
392 }
|
Chris@42
|
393
|
Chris@42
|
394 paint.save();
|
Chris@42
|
395 if (hasLightBackground()) {
|
Chris@42
|
396 paint.setPen(QPen(Qt::black, 2));
|
Chris@42
|
397 } else {
|
Chris@42
|
398 paint.setPen(QPen(Qt::white, 2));
|
Chris@42
|
399 }
|
Chris@42
|
400
|
Chris@42
|
401 //!!! duplicating display policy with View::drawSelections
|
Chris@42
|
402
|
Chris@42
|
403 if (m_editingSelectionEdge < 0) {
|
Chris@42
|
404 paint.drawLine(p0, 1, p1, 1);
|
Chris@42
|
405 paint.drawLine(p0, 0, p0, height());
|
Chris@42
|
406 paint.drawLine(p0, height() - 1, p1, height() - 1);
|
Chris@42
|
407 } else if (m_editingSelectionEdge > 0) {
|
Chris@42
|
408 paint.drawLine(p0, 1, p1, 1);
|
Chris@42
|
409 paint.drawLine(p1, 0, p1, height());
|
Chris@42
|
410 paint.drawLine(p0, height() - 1, p1, height() - 1);
|
Chris@42
|
411 } else {
|
Chris@42
|
412 paint.setBrush(Qt::NoBrush);
|
Chris@42
|
413 paint.drawRect(p0, 1, p1 - p0, height() - 2);
|
Chris@42
|
414 }
|
Chris@42
|
415 paint.restore();
|
Chris@42
|
416 }
|
Chris@42
|
417
|
Chris@0
|
418 paint.end();
|
Chris@0
|
419 }
|
Chris@0
|
420
|
Chris@17
|
421 Selection
|
Chris@44
|
422 Pane::getSelectionAt(int x, bool &closeToLeftEdge, bool &closeToRightEdge) const
|
Chris@17
|
423 {
|
Chris@17
|
424 closeToLeftEdge = closeToRightEdge = false;
|
Chris@17
|
425
|
Chris@17
|
426 if (!m_manager) return Selection();
|
Chris@17
|
427
|
Chris@20
|
428 long testFrame = getFrameForX(x - 5);
|
Chris@17
|
429 if (testFrame < 0) {
|
Chris@20
|
430 testFrame = getFrameForX(x);
|
Chris@17
|
431 if (testFrame < 0) return Selection();
|
Chris@17
|
432 }
|
Chris@17
|
433
|
Chris@17
|
434 Selection selection = m_manager->getContainingSelection(testFrame, true);
|
Chris@17
|
435 if (selection.isEmpty()) return selection;
|
Chris@17
|
436
|
Chris@20
|
437 int lx = getXForFrame(selection.getStartFrame());
|
Chris@20
|
438 int rx = getXForFrame(selection.getEndFrame());
|
Chris@17
|
439
|
Chris@17
|
440 int fuzz = 2;
|
Chris@17
|
441 if (x < lx - fuzz || x > rx + fuzz) return Selection();
|
Chris@17
|
442
|
Chris@17
|
443 int width = rx - lx;
|
Chris@17
|
444 fuzz = 3;
|
Chris@17
|
445 if (width < 12) fuzz = width / 4;
|
Chris@17
|
446 if (fuzz < 1) fuzz = 1;
|
Chris@17
|
447
|
Chris@17
|
448 if (x < lx + fuzz) closeToLeftEdge = true;
|
Chris@17
|
449 if (x > rx - fuzz) closeToRightEdge = true;
|
Chris@17
|
450
|
Chris@17
|
451 return selection;
|
Chris@17
|
452 }
|
Chris@17
|
453
|
Chris@0
|
454 void
|
Chris@0
|
455 Pane::mousePressEvent(QMouseEvent *e)
|
Chris@0
|
456 {
|
Chris@0
|
457 m_clickPos = e->pos();
|
Chris@0
|
458 m_clickedInRange = true;
|
Chris@42
|
459 m_editingSelection = Selection();
|
Chris@42
|
460 m_editingSelectionEdge = 0;
|
Chris@0
|
461 m_shiftPressed = (e->modifiers() & Qt::ShiftModifier);
|
Chris@13
|
462 m_ctrlPressed = (e->modifiers() & Qt::ControlModifier);
|
Chris@13
|
463
|
Chris@13
|
464 ViewManager::ToolMode mode = ViewManager::NavigateMode;
|
Chris@13
|
465 if (m_manager) mode = m_manager->getToolMode();
|
Chris@13
|
466
|
Chris@17
|
467 m_navigating = false;
|
Chris@13
|
468
|
Chris@17
|
469 if (mode == ViewManager::NavigateMode || (e->buttons() & Qt::MidButton)) {
|
Chris@17
|
470
|
Chris@17
|
471 if (mode != ViewManager::NavigateMode) {
|
Chris@17
|
472 setCursor(Qt::PointingHandCursor);
|
Chris@17
|
473 }
|
Chris@17
|
474
|
Chris@17
|
475 m_navigating = true;
|
Chris@13
|
476 m_dragCentreFrame = m_centreFrame;
|
Chris@13
|
477
|
Chris@13
|
478 } else if (mode == ViewManager::SelectMode) {
|
Chris@13
|
479
|
Chris@17
|
480 bool closeToLeft = false, closeToRight = false;
|
Chris@17
|
481 Selection selection = getSelectionAt(e->x(), closeToLeft, closeToRight);
|
Chris@17
|
482
|
Chris@17
|
483 if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) {
|
Chris@17
|
484
|
Chris@17
|
485 m_manager->removeSelection(selection);
|
Chris@17
|
486
|
Chris@17
|
487 if (closeToLeft) {
|
Chris@17
|
488 m_selectionStartFrame = selection.getEndFrame();
|
Chris@17
|
489 } else {
|
Chris@17
|
490 m_selectionStartFrame = selection.getStartFrame();
|
Chris@17
|
491 }
|
Chris@17
|
492
|
Chris@17
|
493 m_manager->setInProgressSelection(selection, false);
|
Chris@17
|
494 m_resizing = true;
|
Chris@13
|
495
|
Chris@17
|
496 } else {
|
Chris@17
|
497
|
Chris@20
|
498 int mouseFrame = getFrameForX(e->x());
|
Chris@17
|
499 size_t resolution = 1;
|
Chris@17
|
500 int snapFrame = mouseFrame;
|
Chris@17
|
501
|
Chris@17
|
502 Layer *layer = getSelectedLayer();
|
Chris@17
|
503 if (layer) {
|
Chris@44
|
504 layer->snapToFeatureFrame(this, snapFrame,
|
Chris@44
|
505 resolution, Layer::SnapLeft);
|
Chris@17
|
506 }
|
Chris@17
|
507
|
Chris@17
|
508 if (snapFrame < 0) snapFrame = 0;
|
Chris@17
|
509 m_selectionStartFrame = snapFrame;
|
Chris@17
|
510 if (m_manager) {
|
Chris@17
|
511 m_manager->setInProgressSelection(Selection(snapFrame,
|
Chris@17
|
512 snapFrame + resolution),
|
Chris@17
|
513 !m_ctrlPressed);
|
Chris@17
|
514 }
|
Chris@17
|
515
|
Chris@17
|
516 m_resizing = false;
|
Chris@17
|
517 }
|
Chris@17
|
518
|
Chris@17
|
519 update();
|
Chris@17
|
520
|
Chris@17
|
521 } else if (mode == ViewManager::DrawMode) {
|
Chris@17
|
522
|
Chris@13
|
523 Layer *layer = getSelectedLayer();
|
Chris@23
|
524 if (layer && layer->isLayerEditable()) {
|
Chris@44
|
525 layer->drawStart(this, e);
|
Chris@13
|
526 }
|
Chris@18
|
527
|
Chris@18
|
528 } else if (mode == ViewManager::EditMode) {
|
Chris@18
|
529
|
Chris@42
|
530 if (!editSelectionStart(e)) {
|
Chris@42
|
531 Layer *layer = getSelectedLayer();
|
Chris@42
|
532 if (layer && layer->isLayerEditable()) {
|
Chris@44
|
533 layer->editStart(this, e);
|
Chris@42
|
534 }
|
Chris@18
|
535 }
|
Chris@13
|
536 }
|
Chris@0
|
537
|
Chris@0
|
538 emit paneInteractedWith();
|
Chris@0
|
539 }
|
Chris@0
|
540
|
Chris@0
|
541 void
|
Chris@0
|
542 Pane::mouseReleaseEvent(QMouseEvent *e)
|
Chris@0
|
543 {
|
Chris@13
|
544 ViewManager::ToolMode mode = ViewManager::NavigateMode;
|
Chris@13
|
545 if (m_manager) mode = m_manager->getToolMode();
|
Chris@13
|
546
|
Chris@0
|
547 if (m_clickedInRange) {
|
Chris@0
|
548 mouseMoveEvent(e);
|
Chris@0
|
549 }
|
Chris@0
|
550
|
Chris@17
|
551 if (m_navigating || mode == ViewManager::NavigateMode) {
|
Chris@17
|
552
|
Chris@17
|
553 m_navigating = false;
|
Chris@17
|
554
|
Chris@17
|
555 if (mode != ViewManager::NavigateMode) {
|
Chris@17
|
556 // restore cursor
|
Chris@17
|
557 toolModeChanged();
|
Chris@17
|
558 }
|
Chris@0
|
559
|
Chris@13
|
560 if (m_shiftPressed) {
|
Chris@0
|
561
|
Chris@13
|
562 int x0 = std::min(m_clickPos.x(), m_mousePos.x());
|
Chris@13
|
563 int x1 = std::max(m_clickPos.x(), m_mousePos.x());
|
Chris@13
|
564 int w = x1 - x0;
|
Chris@13
|
565
|
Chris@20
|
566 long newStartFrame = getFrameForX(x0);
|
Chris@13
|
567
|
Chris@20
|
568 long visibleFrames = getEndFrame() - getStartFrame();
|
Chris@20
|
569 if (newStartFrame <= -visibleFrames) {
|
Chris@20
|
570 newStartFrame = -visibleFrames + 1;
|
Chris@13
|
571 }
|
Chris@13
|
572
|
Chris@13
|
573 if (newStartFrame >= long(getModelsEndFrame())) {
|
Chris@13
|
574 newStartFrame = getModelsEndFrame() - 1;
|
Chris@13
|
575 }
|
Chris@13
|
576
|
Chris@13
|
577 float ratio = float(w) / float(width());
|
Chris@13
|
578 // std::cerr << "ratio: " << ratio << std::endl;
|
Chris@13
|
579 size_t newZoomLevel = (size_t)nearbyint(m_zoomLevel * ratio);
|
Chris@13
|
580 if (newZoomLevel < 1) newZoomLevel = 1;
|
Chris@13
|
581
|
Chris@13
|
582 // std::cerr << "start: " << m_startFrame << ", level " << m_zoomLevel << std::endl;
|
Chris@13
|
583 setZoomLevel(getZoomConstraintBlockSize(newZoomLevel));
|
Chris@13
|
584 setStartFrame(newStartFrame);
|
Chris@13
|
585
|
Chris@13
|
586 //cerr << "mouseReleaseEvent: start frame now " << m_startFrame << endl;
|
Chris@13
|
587 // update();
|
Chris@0
|
588 }
|
Chris@0
|
589
|
Chris@13
|
590 } else if (mode == ViewManager::SelectMode) {
|
Chris@13
|
591
|
Chris@13
|
592 if (m_manager && m_manager->haveInProgressSelection()) {
|
Chris@13
|
593
|
Chris@13
|
594 bool exclusive;
|
Chris@13
|
595 Selection selection = m_manager->getInProgressSelection(exclusive);
|
Chris@13
|
596
|
Chris@13
|
597 if (selection.getEndFrame() < selection.getStartFrame() + 2) {
|
Chris@13
|
598 selection = Selection();
|
Chris@13
|
599 }
|
Chris@13
|
600
|
Chris@13
|
601 m_manager->clearInProgressSelection();
|
Chris@13
|
602
|
Chris@13
|
603 if (exclusive) {
|
Chris@13
|
604 m_manager->setSelection(selection);
|
Chris@13
|
605 } else {
|
Chris@13
|
606 m_manager->addSelection(selection);
|
Chris@13
|
607 }
|
Chris@0
|
608 }
|
Chris@13
|
609
|
Chris@13
|
610 update();
|
Chris@17
|
611
|
Chris@17
|
612 } else if (mode == ViewManager::DrawMode) {
|
Chris@17
|
613
|
Chris@17
|
614 Layer *layer = getSelectedLayer();
|
Chris@23
|
615 if (layer && layer->isLayerEditable()) {
|
Chris@44
|
616 layer->drawEnd(this, e);
|
Chris@17
|
617 update();
|
Chris@17
|
618 }
|
Chris@18
|
619
|
Chris@18
|
620 } else if (mode == ViewManager::EditMode) {
|
Chris@18
|
621
|
Chris@42
|
622 if (!editSelectionEnd(e)) {
|
Chris@42
|
623 Layer *layer = getSelectedLayer();
|
Chris@42
|
624 if (layer && layer->isLayerEditable()) {
|
Chris@44
|
625 layer->editEnd(this, e);
|
Chris@42
|
626 update();
|
Chris@42
|
627 }
|
Chris@18
|
628 }
|
Chris@17
|
629 }
|
Chris@0
|
630
|
Chris@0
|
631 m_clickedInRange = false;
|
Chris@0
|
632
|
Chris@0
|
633 emit paneInteractedWith();
|
Chris@0
|
634 }
|
Chris@0
|
635
|
Chris@0
|
636 void
|
Chris@0
|
637 Pane::mouseMoveEvent(QMouseEvent *e)
|
Chris@0
|
638 {
|
Chris@13
|
639 ViewManager::ToolMode mode = ViewManager::NavigateMode;
|
Chris@13
|
640 if (m_manager) mode = m_manager->getToolMode();
|
Chris@13
|
641
|
Chris@28
|
642 QPoint prevPoint = m_identifyPoint;
|
Chris@28
|
643 m_identifyPoint = e->pos();
|
Chris@28
|
644
|
Chris@0
|
645 if (!m_clickedInRange) {
|
Chris@0
|
646
|
Chris@17
|
647 if (mode == ViewManager::SelectMode) {
|
Chris@17
|
648 bool closeToLeft = false, closeToRight = false;
|
Chris@17
|
649 getSelectionAt(e->x(), closeToLeft, closeToRight);
|
Chris@17
|
650 if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) {
|
Chris@17
|
651 setCursor(Qt::SizeHorCursor);
|
Chris@17
|
652 } else {
|
Chris@17
|
653 setCursor(Qt::ArrowCursor);
|
Chris@17
|
654 }
|
Chris@17
|
655 }
|
Chris@0
|
656
|
Chris@35
|
657 //!!! if (mode != ViewManager::DrawMode) {
|
Chris@0
|
658
|
Chris@67
|
659 if (!m_manager->isPlaying()) {
|
Chris@67
|
660
|
Chris@55
|
661 if (getSelectedLayer()) {
|
Chris@55
|
662
|
Chris@17
|
663 bool previouslyIdentifying = m_identifyFeatures;
|
Chris@17
|
664 m_identifyFeatures = true;
|
Chris@17
|
665
|
Chris@17
|
666 if (m_identifyFeatures != previouslyIdentifying ||
|
Chris@17
|
667 m_identifyPoint != prevPoint) {
|
Chris@17
|
668 update();
|
Chris@17
|
669 }
|
Chris@55
|
670 }
|
Chris@55
|
671
|
Chris@67
|
672 }
|
Chris@67
|
673
|
Chris@35
|
674 // }
|
Chris@0
|
675
|
Chris@13
|
676 return;
|
Chris@13
|
677 }
|
Chris@0
|
678
|
Chris@17
|
679 if (m_navigating || mode == ViewManager::NavigateMode) {
|
Chris@0
|
680
|
Chris@13
|
681 if (m_shiftPressed) {
|
Chris@0
|
682
|
Chris@13
|
683 m_mousePos = e->pos();
|
Chris@13
|
684 update();
|
Chris@0
|
685
|
Chris@0
|
686 } else {
|
Chris@13
|
687
|
Chris@20
|
688 long frameOff = getFrameForX(e->x()) - getFrameForX(m_clickPos.x());
|
Chris@20
|
689
|
Chris@13
|
690 size_t newCentreFrame = m_dragCentreFrame;
|
Chris@13
|
691
|
Chris@13
|
692 if (frameOff < 0) {
|
Chris@13
|
693 newCentreFrame -= frameOff;
|
Chris@13
|
694 } else if (newCentreFrame >= size_t(frameOff)) {
|
Chris@13
|
695 newCentreFrame -= frameOff;
|
Chris@13
|
696 } else {
|
Chris@13
|
697 newCentreFrame = 0;
|
Chris@13
|
698 }
|
Chris@13
|
699
|
Chris@13
|
700 if (newCentreFrame >= getModelsEndFrame()) {
|
Chris@13
|
701 newCentreFrame = getModelsEndFrame();
|
Chris@13
|
702 if (newCentreFrame > 0) --newCentreFrame;
|
Chris@13
|
703 }
|
Chris@20
|
704
|
Chris@20
|
705 if (getXForFrame(m_centreFrame) != getXForFrame(newCentreFrame)) {
|
Chris@13
|
706 setCentreFrame(newCentreFrame);
|
Chris@13
|
707 }
|
Chris@0
|
708 }
|
Chris@0
|
709
|
Chris@13
|
710 } else if (mode == ViewManager::SelectMode) {
|
Chris@13
|
711
|
Chris@20
|
712 int mouseFrame = getFrameForX(e->x());
|
Chris@13
|
713 size_t resolution = 1;
|
Chris@13
|
714 int snapFrameLeft = mouseFrame;
|
Chris@13
|
715 int snapFrameRight = mouseFrame;
|
Chris@13
|
716
|
Chris@13
|
717 Layer *layer = getSelectedLayer();
|
Chris@13
|
718 if (layer) {
|
Chris@44
|
719 layer->snapToFeatureFrame(this, snapFrameLeft,
|
Chris@44
|
720 resolution, Layer::SnapLeft);
|
Chris@44
|
721 layer->snapToFeatureFrame(this, snapFrameRight,
|
Chris@44
|
722 resolution, Layer::SnapRight);
|
Chris@13
|
723 }
|
Chris@13
|
724
|
Chris@37
|
725 // std::cerr << "snap: frame = " << mouseFrame << ", start frame = " << m_selectionStartFrame << ", left = " << snapFrameLeft << ", right = " << snapFrameRight << std::endl;
|
Chris@28
|
726
|
Chris@13
|
727 if (snapFrameLeft < 0) snapFrameLeft = 0;
|
Chris@13
|
728 if (snapFrameRight < 0) snapFrameRight = 0;
|
Chris@13
|
729
|
Chris@13
|
730 size_t min, max;
|
Chris@13
|
731
|
Chris@13
|
732 if (m_selectionStartFrame > snapFrameLeft) {
|
Chris@13
|
733 min = snapFrameLeft;
|
Chris@13
|
734 max = m_selectionStartFrame;
|
Chris@13
|
735 } else if (snapFrameRight > m_selectionStartFrame) {
|
Chris@13
|
736 min = m_selectionStartFrame;
|
Chris@13
|
737 max = snapFrameRight;
|
Chris@13
|
738 } else {
|
Chris@13
|
739 min = snapFrameLeft;
|
Chris@13
|
740 max = snapFrameRight;
|
Chris@0
|
741 }
|
Chris@0
|
742
|
Chris@13
|
743 if (m_manager) {
|
Chris@13
|
744 m_manager->setInProgressSelection(Selection(min, max),
|
Chris@17
|
745 !m_resizing && !m_ctrlPressed);
|
Chris@0
|
746 }
|
Chris@15
|
747
|
Chris@15
|
748 bool doScroll = false;
|
Chris@15
|
749 if (!m_manager) doScroll = true;
|
Chris@15
|
750 if (!m_manager->isPlaying()) doScroll = true;
|
Chris@15
|
751 if (m_followPlay != PlaybackScrollContinuous) doScroll = true;
|
Chris@15
|
752
|
Chris@15
|
753 if (doScroll) {
|
Chris@13
|
754 int offset = mouseFrame - getStartFrame();
|
Chris@13
|
755 int available = getEndFrame() - getStartFrame();
|
Chris@15
|
756 if (offset >= available * 0.95) {
|
Chris@15
|
757 int move = int(offset - available * 0.95) + 1;
|
Chris@14
|
758 setCentreFrame(m_centreFrame + move);
|
Chris@15
|
759 } else if (offset <= available * 0.10) {
|
Chris@15
|
760 int move = int(available * 0.10 - offset) + 1;
|
Chris@14
|
761 if (m_centreFrame > move) {
|
Chris@14
|
762 setCentreFrame(m_centreFrame - move);
|
Chris@14
|
763 } else {
|
Chris@14
|
764 setCentreFrame(0);
|
Chris@14
|
765 }
|
Chris@13
|
766 }
|
Chris@13
|
767 }
|
Chris@13
|
768
|
Chris@13
|
769 update();
|
Chris@17
|
770
|
Chris@17
|
771 } else if (mode == ViewManager::DrawMode) {
|
Chris@17
|
772
|
Chris@17
|
773 Layer *layer = getSelectedLayer();
|
Chris@23
|
774 if (layer && layer->isLayerEditable()) {
|
Chris@44
|
775 layer->drawDrag(this, e);
|
Chris@17
|
776 }
|
Chris@18
|
777
|
Chris@18
|
778 } else if (mode == ViewManager::EditMode) {
|
Chris@18
|
779
|
Chris@42
|
780 if (!editSelectionDrag(e)) {
|
Chris@42
|
781 Layer *layer = getSelectedLayer();
|
Chris@42
|
782 if (layer && layer->isLayerEditable()) {
|
Chris@44
|
783 layer->editDrag(this, e);
|
Chris@42
|
784 }
|
Chris@18
|
785 }
|
Chris@0
|
786 }
|
Chris@0
|
787 }
|
Chris@0
|
788
|
Chris@0
|
789 void
|
Chris@0
|
790 Pane::mouseDoubleClickEvent(QMouseEvent *e)
|
Chris@0
|
791 {
|
Chris@0
|
792 std::cerr << "mouseDoubleClickEvent" << std::endl;
|
Chris@36
|
793
|
Chris@36
|
794 m_clickPos = e->pos();
|
Chris@36
|
795 m_clickedInRange = true;
|
Chris@36
|
796 m_shiftPressed = (e->modifiers() & Qt::ShiftModifier);
|
Chris@36
|
797 m_ctrlPressed = (e->modifiers() & Qt::ControlModifier);
|
Chris@36
|
798
|
Chris@36
|
799 ViewManager::ToolMode mode = ViewManager::NavigateMode;
|
Chris@36
|
800 if (m_manager) mode = m_manager->getToolMode();
|
Chris@36
|
801
|
Chris@36
|
802 if (mode == ViewManager::EditMode) {
|
Chris@36
|
803
|
Chris@36
|
804 Layer *layer = getSelectedLayer();
|
Chris@36
|
805 if (layer && layer->isLayerEditable()) {
|
Chris@44
|
806 layer->editOpen(this, e);
|
Chris@36
|
807 }
|
Chris@36
|
808 }
|
Chris@0
|
809 }
|
Chris@0
|
810
|
Chris@0
|
811 void
|
Chris@0
|
812 Pane::leaveEvent(QEvent *)
|
Chris@0
|
813 {
|
Chris@0
|
814 bool previouslyIdentifying = m_identifyFeatures;
|
Chris@0
|
815 m_identifyFeatures = false;
|
Chris@0
|
816 if (previouslyIdentifying) update();
|
Chris@0
|
817 }
|
Chris@0
|
818
|
Chris@0
|
819 void
|
Chris@0
|
820 Pane::wheelEvent(QWheelEvent *e)
|
Chris@0
|
821 {
|
Chris@0
|
822 //std::cerr << "wheelEvent, delta " << e->delta() << std::endl;
|
Chris@0
|
823
|
Chris@0
|
824 int count = e->delta();
|
Chris@0
|
825
|
Chris@0
|
826 if (count > 0) {
|
Chris@0
|
827 if (count >= 120) count /= 120;
|
Chris@0
|
828 else count = 1;
|
Chris@0
|
829 }
|
Chris@0
|
830
|
Chris@0
|
831 if (count < 0) {
|
Chris@0
|
832 if (count <= -120) count /= 120;
|
Chris@0
|
833 else count = -1;
|
Chris@0
|
834 }
|
Chris@17
|
835
|
Chris@17
|
836 if (e->modifiers() & Qt::ControlModifier) {
|
Chris@17
|
837
|
Chris@20
|
838 // Scroll left or right, rapidly
|
Chris@20
|
839
|
Chris@17
|
840 if (getStartFrame() < 0 &&
|
Chris@17
|
841 getEndFrame() >= getModelsEndFrame()) return;
|
Chris@17
|
842
|
Chris@17
|
843 long delta = ((width() / 2) * count * m_zoomLevel);
|
Chris@17
|
844
|
Chris@17
|
845 if (int(m_centreFrame) < delta) {
|
Chris@17
|
846 setCentreFrame(0);
|
Chris@17
|
847 } else if (int(m_centreFrame) - delta >= int(getModelsEndFrame())) {
|
Chris@17
|
848 setCentreFrame(getModelsEndFrame());
|
Chris@17
|
849 } else {
|
Chris@17
|
850 setCentreFrame(m_centreFrame - delta);
|
Chris@17
|
851 }
|
Chris@17
|
852
|
Chris@17
|
853 } else {
|
Chris@17
|
854
|
Chris@20
|
855 // Zoom in or out
|
Chris@20
|
856
|
Chris@17
|
857 int newZoomLevel = m_zoomLevel;
|
Chris@0
|
858
|
Chris@17
|
859 while (count > 0) {
|
Chris@17
|
860 if (newZoomLevel <= 2) {
|
Chris@17
|
861 newZoomLevel = 1;
|
Chris@17
|
862 break;
|
Chris@17
|
863 }
|
Chris@17
|
864 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel - 1,
|
Chris@17
|
865 ZoomConstraint::RoundDown);
|
Chris@17
|
866 --count;
|
Chris@0
|
867 }
|
Chris@17
|
868
|
Chris@17
|
869 while (count < 0) {
|
Chris@17
|
870 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel + 1,
|
Chris@17
|
871 ZoomConstraint::RoundUp);
|
Chris@17
|
872 ++count;
|
Chris@17
|
873 }
|
Chris@17
|
874
|
Chris@17
|
875 if (newZoomLevel != m_zoomLevel) {
|
Chris@17
|
876 setZoomLevel(newZoomLevel);
|
Chris@17
|
877 }
|
Chris@0
|
878 }
|
Chris@0
|
879
|
Chris@0
|
880 emit paneInteractedWith();
|
Chris@0
|
881 }
|
Chris@8
|
882
|
Chris@42
|
883 bool
|
Chris@42
|
884 Pane::editSelectionStart(QMouseEvent *e)
|
Chris@42
|
885 {
|
Chris@43
|
886 if (!m_identifyFeatures ||
|
Chris@43
|
887 !m_manager ||
|
Chris@43
|
888 m_manager->getToolMode() != ViewManager::EditMode) {
|
Chris@43
|
889 return false;
|
Chris@43
|
890 }
|
Chris@43
|
891
|
Chris@42
|
892 bool closeToLeft, closeToRight;
|
Chris@42
|
893 Selection s(getSelectionAt(e->x(), closeToLeft, closeToRight));
|
Chris@42
|
894 if (s.isEmpty()) return false;
|
Chris@42
|
895 m_editingSelection = s;
|
Chris@42
|
896 m_editingSelectionEdge = (closeToLeft ? -1 : closeToRight ? 1 : 0);
|
Chris@42
|
897 m_mousePos = e->pos();
|
Chris@42
|
898 return true;
|
Chris@42
|
899 }
|
Chris@42
|
900
|
Chris@42
|
901 bool
|
Chris@42
|
902 Pane::editSelectionDrag(QMouseEvent *e)
|
Chris@42
|
903 {
|
Chris@42
|
904 if (m_editingSelection.isEmpty()) return false;
|
Chris@42
|
905 m_mousePos = e->pos();
|
Chris@42
|
906 update();
|
Chris@42
|
907 return true;
|
Chris@42
|
908 }
|
Chris@42
|
909
|
Chris@42
|
910 bool
|
Chris@42
|
911 Pane::editSelectionEnd(QMouseEvent *e)
|
Chris@42
|
912 {
|
Chris@42
|
913 if (m_editingSelection.isEmpty()) return false;
|
Chris@43
|
914
|
Chris@43
|
915 int offset = m_mousePos.x() - m_clickPos.x();
|
Chris@43
|
916 Layer *layer = getSelectedLayer();
|
Chris@43
|
917
|
Chris@43
|
918 if (offset == 0 || !layer) {
|
Chris@43
|
919 m_editingSelection = Selection();
|
Chris@43
|
920 return true;
|
Chris@43
|
921 }
|
Chris@43
|
922
|
Chris@43
|
923 int p0 = getXForFrame(m_editingSelection.getStartFrame()) + offset;
|
Chris@43
|
924 int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset;
|
Chris@43
|
925
|
Chris@43
|
926 long f0 = getFrameForX(p0);
|
Chris@43
|
927 long f1 = getFrameForX(p1);
|
Chris@43
|
928
|
Chris@43
|
929 Selection newSelection(f0, f1);
|
Chris@43
|
930
|
Chris@43
|
931 if (m_editingSelectionEdge == 0) {
|
Chris@43
|
932
|
Chris@43
|
933 layer->moveSelection(m_editingSelection, f0);
|
Chris@43
|
934
|
Chris@43
|
935 } else {
|
Chris@43
|
936
|
Chris@43
|
937 if (m_editingSelectionEdge < 0) {
|
Chris@43
|
938 f1 = m_editingSelection.getEndFrame();
|
Chris@43
|
939 } else {
|
Chris@43
|
940 f0 = m_editingSelection.getStartFrame();
|
Chris@43
|
941 }
|
Chris@43
|
942
|
Chris@43
|
943 newSelection = Selection(f0, f1);
|
Chris@43
|
944 layer->resizeSelection(m_editingSelection, newSelection);
|
Chris@43
|
945 }
|
Chris@43
|
946
|
Chris@43
|
947 m_manager->removeSelection(m_editingSelection);
|
Chris@43
|
948 m_manager->addSelection(newSelection);
|
Chris@43
|
949
|
Chris@42
|
950 m_editingSelection = Selection();
|
Chris@42
|
951 return true;
|
Chris@42
|
952 }
|
Chris@42
|
953
|
Chris@13
|
954 void
|
Chris@13
|
955 Pane::toolModeChanged()
|
Chris@13
|
956 {
|
Chris@13
|
957 ViewManager::ToolMode mode = m_manager->getToolMode();
|
Chris@13
|
958 std::cerr << "Pane::toolModeChanged(" << mode << ")" << std::endl;
|
Chris@13
|
959
|
Chris@13
|
960 switch (mode) {
|
Chris@13
|
961
|
Chris@13
|
962 case ViewManager::NavigateMode:
|
Chris@13
|
963 setCursor(Qt::PointingHandCursor);
|
Chris@13
|
964 break;
|
Chris@13
|
965
|
Chris@13
|
966 case ViewManager::SelectMode:
|
Chris@13
|
967 setCursor(Qt::ArrowCursor);
|
Chris@13
|
968 break;
|
Chris@13
|
969
|
Chris@13
|
970 case ViewManager::EditMode:
|
Chris@19
|
971 setCursor(Qt::UpArrowCursor);
|
Chris@13
|
972 break;
|
Chris@13
|
973
|
Chris@13
|
974 case ViewManager::DrawMode:
|
Chris@13
|
975 setCursor(Qt::CrossCursor);
|
Chris@13
|
976 break;
|
Chris@36
|
977 /*
|
Chris@13
|
978 case ViewManager::TextMode:
|
Chris@13
|
979 setCursor(Qt::IBeamCursor);
|
Chris@13
|
980 break;
|
Chris@36
|
981 */
|
Chris@13
|
982 }
|
Chris@13
|
983 }
|
Chris@13
|
984
|
Chris@8
|
985 QString
|
Chris@8
|
986 Pane::toXmlString(QString indent, QString extraAttributes) const
|
Chris@8
|
987 {
|
Chris@8
|
988 return View::toXmlString
|
Chris@8
|
989 (indent,
|
Chris@55
|
990 QString("type=\"pane\" centreLineVisible=\"%1\" height=\"%2\" %3")
|
Chris@55
|
991 .arg(m_centreLineVisible).arg(height()).arg(extraAttributes));
|
Chris@8
|
992 }
|
Chris@8
|
993
|
Chris@0
|
994
|
Chris@0
|
995 #ifdef INCLUDE_MOCFILES
|
Chris@0
|
996 #include "Pane.moc.cpp"
|
Chris@0
|
997 #endif
|
Chris@0
|
998
|