comparison view/Overview.cpp @ 946:36cddc3de023 alignment_view

Merge from default branch
author Chris Cannam
date Mon, 20 Apr 2015 09:19:52 +0100
parents 1c529a22a6a7
children 73b0dc7d6ec1
comparison
equal deleted inserted replaced
897:499b637f2a26 946:36cddc3de023
36 setPlaybackFollow(PlaybackIgnore); 36 setPlaybackFollow(PlaybackIgnore);
37 m_modelTestTime.start(); 37 m_modelTestTime.start();
38 } 38 }
39 39
40 void 40 void
41 Overview::modelChangedWithin(int startFrame, int endFrame) 41 Overview::modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame)
42 { 42 {
43 bool zoomChanged = false; 43 bool zoomChanged = false;
44 44
45 int frameCount = getModelsEndFrame() - getModelsStartFrame(); 45 sv_frame_t frameCount = getModelsEndFrame() - getModelsStartFrame();
46 int zoomLevel = frameCount / width(); 46 int zoomLevel = int(frameCount / width());
47 if (zoomLevel < 1) zoomLevel = 1; 47 if (zoomLevel < 1) zoomLevel = 1;
48 zoomLevel = getZoomConstraintBlockSize(zoomLevel, 48 zoomLevel = getZoomConstraintBlockSize(zoomLevel,
49 ZoomConstraint::RoundUp); 49 ZoomConstraint::RoundUp);
50 if (zoomLevel != m_zoomLevel) { 50 if (zoomLevel != m_zoomLevel) {
51 zoomChanged = true; 51 zoomChanged = true;
89 m_views.erase(view); 89 m_views.erase(view);
90 update(); 90 update();
91 } 91 }
92 92
93 void 93 void
94 Overview::globalCentreFrameChanged(int 94 Overview::globalCentreFrameChanged(sv_frame_t
95 #ifdef DEBUG_OVERVIEW 95 #ifdef DEBUG_OVERVIEW
96 f 96 f
97 #endif 97 #endif
98 ) 98 )
99 { 99 {
102 #endif 102 #endif
103 update(); 103 update();
104 } 104 }
105 105
106 void 106 void
107 Overview::viewCentreFrameChanged(View *v, int 107 Overview::viewCentreFrameChanged(View *v, sv_frame_t
108 #ifdef DEBUG_OVERVIEW 108 #ifdef DEBUG_OVERVIEW
109 f 109 f
110 #endif 110 #endif
111 ) 111 )
112 { 112 {
126 update(); 126 update();
127 } 127 }
128 } 128 }
129 129
130 void 130 void
131 Overview::viewManagerPlaybackFrameChanged(int f) 131 Overview::viewManagerPlaybackFrameChanged(sv_frame_t f)
132 { 132 {
133 #ifdef DEBUG_OVERVIEW 133 #ifdef DEBUG_OVERVIEW
134 cerr << "Overview[" << this << "]::viewManagerPlaybackFrameChanged(" << f << "): " << f << endl; 134 cerr << "Overview[" << this << "]::viewManagerPlaybackFrameChanged(" << f << "): " << f << endl;
135 #endif 135 #endif
136 136
142 m_playPointerFrame = f; 142 m_playPointerFrame = f;
143 143
144 if (changed) update(); 144 if (changed) update();
145 } 145 }
146 146
147 QColor
148 Overview::getFillWithin() const
149 {
150 return Qt::transparent;
151 }
152
153 QColor
154 Overview::getFillWithout() const
155 {
156 QColor c = palette().window().color();
157 c.setAlpha(100);
158 return c;
159 }
160
147 void 161 void
148 Overview::paintEvent(QPaintEvent *e) 162 Overview::paintEvent(QPaintEvent *e)
149 { 163 {
150 // Recalculate zoom in case the size of the widget has changed. 164 // Recalculate zoom in case the size of the widget has changed.
151 165
152 #ifdef DEBUG_OVERVIEW 166 #ifdef DEBUG_OVERVIEW
153 cerr << "Overview::paintEvent: width is " << width() << ", centre frame " << m_centreFrame << endl; 167 cerr << "Overview::paintEvent: width is " << width() << ", centre frame " << m_centreFrame << endl;
154 #endif 168 #endif
155 169
156 int startFrame = getModelsStartFrame(); 170 sv_frame_t startFrame = getModelsStartFrame();
157 int frameCount = getModelsEndFrame() - getModelsStartFrame(); 171 sv_frame_t frameCount = getModelsEndFrame() - getModelsStartFrame();
158 int zoomLevel = frameCount / width(); 172 int zoomLevel = int(frameCount / width());
159 if (zoomLevel < 1) zoomLevel = 1; 173 if (zoomLevel < 1) zoomLevel = 1;
160 zoomLevel = getZoomConstraintBlockSize(zoomLevel, 174 zoomLevel = getZoomConstraintBlockSize(zoomLevel,
161 ZoomConstraint::RoundUp); 175 ZoomConstraint::RoundUp);
162 if (zoomLevel != m_zoomLevel) { 176 if (zoomLevel != m_zoomLevel) {
163 m_zoomLevel = zoomLevel; 177 m_zoomLevel = zoomLevel;
164 emit zoomLevelChanged(m_zoomLevel, m_followZoom); 178 emit zoomLevelChanged(m_zoomLevel, m_followZoom);
165 } 179 }
166 180
167 int centreFrame = startFrame + m_zoomLevel * (width() / 2); 181 sv_frame_t centreFrame = startFrame + m_zoomLevel * (width() / 2);
168 if (centreFrame > (startFrame + getModelsEndFrame())/2) { 182 if (centreFrame > (startFrame + getModelsEndFrame())/2) {
169 centreFrame = (startFrame + getModelsEndFrame())/2; 183 centreFrame = (startFrame + getModelsEndFrame())/2;
170 } 184 }
171 if (centreFrame != m_centreFrame) { 185 if (centreFrame != m_centreFrame) {
172 #ifdef DEBUG_OVERVIEW 186 #ifdef DEBUG_OVERVIEW
182 196
183 View::paintEvent(e); 197 View::paintEvent(e);
184 198
185 QPainter paint; 199 QPainter paint;
186 paint.begin(this); 200 paint.begin(this);
187 201 paint.setClipRegion(e->region());
202 paint.setRenderHints(QPainter::Antialiasing);
203
188 QRect r(rect()); 204 QRect r(rect());
189 205
190 if (e) { 206 // We paint a rounded rect for each distinct set of view extents,
191 r = e->rect(); 207 // and we colour in the inside and outside of the rect that
192 paint.setClipRect(r); 208 // corresponds to the current view. (One small caveat -- we don't
193 } 209 // know which rect that is yet. We'll have to figure it out
194 210 // somehow...)
195 paint.setPen(getForeground()); 211
212 std::set<std::pair<int, int> > extents;
213 std::vector<QRect> rects;
214 QRect primary;
196 215
197 int y = 0; 216 int y = 0;
198
199 int prevx0 = -10;
200 int prevx1 = -10;
201 217
202 for (ViewSet::iterator i = m_views.begin(); i != m_views.end(); ++i) { 218 for (ViewSet::iterator i = m_views.begin(); i != m_views.end(); ++i) {
203 if (!*i) continue; 219 if (!*i) continue;
204 220
205 View *w = (View *)*i; 221 View *w = (View *)*i;
206 222
207 int f0 = w->getFrameForX(0); 223 sv_frame_t f0 = w->getFrameForX(0);
208 int f1 = w->getFrameForX(w->width()); 224 sv_frame_t f1 = w->getFrameForX(w->width());
209 225
210 if (f0 >= 0) { 226 if (f0 >= 0) {
211 int rf0 = w->alignToReference(f0); 227 sv_frame_t rf0 = w->alignToReference(f0);
212 f0 = alignFromReference(rf0); 228 f0 = alignFromReference(rf0);
213 } 229 }
214 if (f1 >= 0) { 230 if (f1 >= 0) {
215 int rf1 = w->alignToReference(f1); 231 sv_frame_t rf1 = w->alignToReference(f1);
216 f1 = alignFromReference(rf1); 232 f1 = alignFromReference(rf1);
217 } 233 }
218 234
219 int x0 = getXForFrame(f0); 235 int x0 = getXForFrame(f0);
220 int x1 = getXForFrame(f1); 236 int x1 = getXForFrame(f1);
221 237
222 if (x0 != prevx0 || x1 != prevx1) {
223 y += height() / 10 + 1;
224 prevx0 = x0;
225 prevx1 = x1;
226 }
227 238
228 if (x1 <= x0) x1 = x0 + 1; 239 if (x1 <= x0) x1 = x0 + 1;
229 240
230 paint.drawRect(x0, y, x1 - x0, height() - 2 * y); 241 std::pair<int, int> extent(x0, x1);
242
243 if (extents.find(extent) == extents.end()) {
244
245 y += height() / 10 + 1;
246 extents.insert(extent);
247
248 QRect vr(x0, y, x1 - x0, height() - 2 * y);
249 rects.push_back(vr);
250 primary = vr; //!!! for now
251 }
252 }
253
254 QPainterPath without;
255 without.addRoundedRect(primary, 4, 4);
256 without.addRect(rect());
257 paint.setPen(Qt::NoPen);
258 paint.setBrush(getFillWithout());
259 paint.drawPath(without);
260
261 paint.setBrush(getFillWithin());
262 paint.drawRoundedRect(primary, 4, 4);
263
264 foreach (QRect vr, rects) {
265 paint.setBrush(Qt::NoBrush);
266 paint.setPen(QPen(Qt::gray, 2));
267 paint.drawRoundedRect(vr, 4, 4);
231 } 268 }
232 269
233 paint.end(); 270 paint.end();
234 } 271 }
235 272
236 void 273 void
237 Overview::mousePressEvent(QMouseEvent *e) 274 Overview::mousePressEvent(QMouseEvent *e)
238 { 275 {
239 m_clickPos = e->pos(); 276 m_clickPos = e->pos();
240 int clickFrame = getFrameForX(m_clickPos.x()); 277 sv_frame_t clickFrame = getFrameForX(m_clickPos.x());
241 if (clickFrame > 0) m_dragCentreFrame = clickFrame; 278 if (clickFrame > 0) m_dragCentreFrame = clickFrame;
242 else m_dragCentreFrame = 0; 279 else m_dragCentreFrame = 0;
243 m_clickedInRange = true; 280 m_clickedInRange = true;
244 281
245 for (ViewSet::iterator i = m_views.begin(); i != m_views.end(); ++i) { 282 for (ViewSet::iterator i = m_views.begin(); i != m_views.end(); ++i) {
263 Overview::mouseMoveEvent(QMouseEvent *e) 300 Overview::mouseMoveEvent(QMouseEvent *e)
264 { 301 {
265 if (!m_clickedInRange) return; 302 if (!m_clickedInRange) return;
266 303
267 int xoff = int(e->x()) - int(m_clickPos.x()); 304 int xoff = int(e->x()) - int(m_clickPos.x());
268 int frameOff = xoff * m_zoomLevel; 305 sv_frame_t frameOff = xoff * m_zoomLevel;
269 306
270 int newCentreFrame = m_dragCentreFrame; 307 sv_frame_t newCentreFrame = m_dragCentreFrame;
271 if (frameOff > 0) { 308 if (frameOff > 0) {
272 newCentreFrame += frameOff; 309 newCentreFrame += frameOff;
273 } else if (newCentreFrame >= int(-frameOff)) { 310 } else if (newCentreFrame >= -frameOff) {
274 newCentreFrame += frameOff; 311 newCentreFrame += frameOff;
275 } else { 312 } else {
276 newCentreFrame = 0; 313 newCentreFrame = 0;
277 } 314 }
278 315
280 newCentreFrame = getModelsEndFrame(); 317 newCentreFrame = getModelsEndFrame();
281 if (newCentreFrame > 0) --newCentreFrame; 318 if (newCentreFrame > 0) --newCentreFrame;
282 } 319 }
283 320
284 if (std::max(m_centreFrame, newCentreFrame) - 321 if (std::max(m_centreFrame, newCentreFrame) -
285 std::min(m_centreFrame, newCentreFrame) > int(m_zoomLevel)) { 322 std::min(m_centreFrame, newCentreFrame) > m_zoomLevel) {
286 int rf = alignToReference(newCentreFrame); 323 sv_frame_t rf = alignToReference(newCentreFrame);
287 #ifdef DEBUG_OVERVIEW 324 #ifdef DEBUG_OVERVIEW
288 cerr << "Overview::mouseMoveEvent: x " << e->x() << " and click x " << m_clickPos.x() << " -> frame " << newCentreFrame << " -> rf " << rf << endl; 325 cerr << "Overview::mouseMoveEvent: x " << e->x() << " and click x " << m_clickPos.x() << " -> frame " << newCentreFrame << " -> rf " << rf << endl;
289 #endif 326 #endif
290 if (m_followPlay == PlaybackScrollContinuous || 327 if (m_followPlay == PlaybackScrollContinuous ||
291 m_followPlay == PlaybackScrollPageWithCentre) { 328 m_followPlay == PlaybackScrollPageWithCentre) {
297 } 334 }
298 335
299 void 336 void
300 Overview::mouseDoubleClickEvent(QMouseEvent *e) 337 Overview::mouseDoubleClickEvent(QMouseEvent *e)
301 { 338 {
302 int frame = getFrameForX(e->x()); 339 sv_frame_t frame = getFrameForX(e->x());
303 int rf = 0; 340 sv_frame_t rf = 0;
304 if (frame > 0) rf = alignToReference(frame); 341 if (frame > 0) rf = alignToReference(frame);
305 #ifdef DEBUG_OVERVIEW 342 #ifdef DEBUG_OVERVIEW
306 cerr << "Overview::mouseDoubleClickEvent: frame " << frame << " -> rf " << rf << endl; 343 cerr << "Overview::mouseDoubleClickEvent: frame " << frame << " -> rf " << rf << endl;
307 #endif 344 #endif
308 m_clickedInRange = false; // we're not starting a drag with the second click 345 m_clickedInRange = false; // we're not starting a drag with the second click