Mercurial > hg > svgui
comparison view/View.cpp @ 1148:c0d841cb8ab9 tony-2.0-integration
Merge latest SV 3.0 branch code
| author | Chris Cannam | 
|---|---|
| date | Fri, 19 Aug 2016 15:58:57 +0100 | 
| parents | 179ea8a2f650 | 
| children | 0edfed2c8482 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 1009:96cf499fad62 | 1148:c0d841cb8ab9 | 
|---|---|
| 22 #include "base/Preferences.h" | 22 #include "base/Preferences.h" | 
| 23 #include "ViewProxy.h" | 23 #include "ViewProxy.h" | 
| 24 | 24 | 
| 25 #include "layer/TimeRulerLayer.h" | 25 #include "layer/TimeRulerLayer.h" | 
| 26 #include "layer/SingleColourLayer.h" | 26 #include "layer/SingleColourLayer.h" | 
| 27 #include "layer/PaintAssistant.h" | |
| 28 | |
| 27 #include "data/model/PowerOfSqrtTwoZoomConstraint.h" | 29 #include "data/model/PowerOfSqrtTwoZoomConstraint.h" | 
| 28 #include "data/model/RangeSummarisableTimeValueModel.h" | 30 #include "data/model/RangeSummarisableTimeValueModel.h" | 
| 29 | 31 | 
| 30 #include "widgets/IconLoader.h" | 32 #include "widgets/IconLoader.h" | 
| 31 | 33 | 
| 47 #include <unistd.h> | 49 #include <unistd.h> | 
| 48 | 50 | 
| 49 //#define DEBUG_VIEW 1 | 51 //#define DEBUG_VIEW 1 | 
| 50 //#define DEBUG_VIEW_WIDGET_PAINT 1 | 52 //#define DEBUG_VIEW_WIDGET_PAINT 1 | 
| 51 | 53 | 
| 52 | |
| 53 View::View(QWidget *w, bool showProgress) : | 54 View::View(QWidget *w, bool showProgress) : | 
| 54 QFrame(w), | 55 QFrame(w), | 
| 56 m_id(getNextId()), | |
| 55 m_centreFrame(0), | 57 m_centreFrame(0), | 
| 56 m_zoomLevel(1024), | 58 m_zoomLevel(1024), | 
| 57 m_followPan(true), | 59 m_followPan(true), | 
| 58 m_followZoom(true), | 60 m_followZoom(true), | 
| 59 m_followPlay(PlaybackScrollPageWithCentre), | 61 m_followPlay(PlaybackScrollPageWithCentre), | 
| 363 } | 365 } | 
| 364 | 366 | 
| 365 sv_frame_t | 367 sv_frame_t | 
| 366 View::getFrameForX(int x) const | 368 View::getFrameForX(int x) const | 
| 367 { | 369 { | 
| 368 int z = m_zoomLevel; | 370 sv_frame_t z = m_zoomLevel; // nb not just int, or multiplication may overflow | 
| 369 sv_frame_t frame = m_centreFrame - (width()/2) * z; | 371 sv_frame_t frame = m_centreFrame - (width()/2) * z; | 
| 370 | 372 | 
| 373 frame = (frame / z) * z; // this is start frame | |
| 374 frame = frame + x * z; | |
| 375 | |
| 371 #ifdef DEBUG_VIEW_WIDGET_PAINT | 376 #ifdef DEBUG_VIEW_WIDGET_PAINT | 
| 372 SVDEBUG << "View::getFrameForX(" << x << "): z = " << z << ", m_centreFrame = " << m_centreFrame << ", width() = " << width() << ", frame = " << frame << endl; | 377 cerr << "View::getFrameForX(" << x << "): z = " << z << ", m_centreFrame = " << m_centreFrame << ", width() = " << width() << ", frame = " << frame << endl; | 
| 373 #endif | 378 #endif | 
| 374 | 379 | 
| 375 frame = (frame / z) * z; // this is start frame | 380 return frame; | 
| 376 return frame + x * z; | |
| 377 } | 381 } | 
| 378 | 382 | 
| 379 double | 383 double | 
| 380 View::getYForFrequency(double frequency, | 384 View::getYForFrequency(double frequency, | 
| 381 double minf, | 385 double minf, | 
| 409 return h - (h * (frequency - minf)) / (maxf - minf); | 413 return h - (h * (frequency - minf)) / (maxf - minf); | 
| 410 } | 414 } | 
| 411 } | 415 } | 
| 412 | 416 | 
| 413 double | 417 double | 
| 414 View::getFrequencyForY(int y, | 418 View::getFrequencyForY(double y, | 
| 415 double minf, | 419 double minf, | 
| 416 double maxf, | 420 double maxf, | 
| 417 bool logarithmic) const | 421 bool logarithmic) const | 
| 418 { | 422 { | 
| 419 int h = height(); | 423 double h = height(); | 
| 420 | 424 | 
| 421 if (logarithmic) { | 425 if (logarithmic) { | 
| 422 | 426 | 
| 423 static double lastminf = 0.0, lastmaxf = 0.0; | 427 static double lastminf = 0.0, lastmaxf = 0.0; | 
| 424 static double logminf = 0.0, logmaxf = 0.0; | 428 static double logminf = 0.0, logmaxf = 0.0; | 
| 806 m_followZoom = f; | 810 m_followZoom = f; | 
| 807 emit propertyContainerPropertyChanged(m_propertyContainer); | 811 emit propertyContainerPropertyChanged(m_propertyContainer); | 
| 808 } | 812 } | 
| 809 | 813 | 
| 810 void | 814 void | 
| 811 View::drawVisibleText(QPainter &paint, int x, int y, QString text, TextStyle style) const | |
| 812 { | |
| 813 if (style == OutlinedText || style == OutlinedItalicText) { | |
| 814 | |
| 815 paint.save(); | |
| 816 | |
| 817 if (style == OutlinedItalicText) { | |
| 818 QFont f(paint.font()); | |
| 819 f.setItalic(true); | |
| 820 paint.setFont(f); | |
| 821 } | |
| 822 | |
| 823 QColor penColour, surroundColour, boxColour; | |
| 824 | |
| 825 penColour = getForeground(); | |
| 826 surroundColour = getBackground(); | |
| 827 boxColour = surroundColour; | |
| 828 boxColour.setAlpha(127); | |
| 829 | |
| 830 paint.setPen(Qt::NoPen); | |
| 831 paint.setBrush(boxColour); | |
| 832 | |
| 833 QRect r = paint.fontMetrics().boundingRect(text); | |
| 834 r.translate(QPoint(x, y)); | |
| 835 // cerr << "drawVisibleText: r = " << r.x() << "," <<r.y() << " " << r.width() << "x" << r.height() << endl; | |
| 836 paint.drawRect(r); | |
| 837 paint.setBrush(Qt::NoBrush); | |
| 838 | |
| 839 paint.setPen(surroundColour); | |
| 840 | |
| 841 for (int dx = -1; dx <= 1; ++dx) { | |
| 842 for (int dy = -1; dy <= 1; ++dy) { | |
| 843 if (!(dx || dy)) continue; | |
| 844 paint.drawText(x + dx, y + dy, text); | |
| 845 } | |
| 846 } | |
| 847 | |
| 848 paint.setPen(penColour); | |
| 849 | |
| 850 paint.drawText(x, y, text); | |
| 851 | |
| 852 paint.restore(); | |
| 853 | |
| 854 } else { | |
| 855 | |
| 856 cerr << "ERROR: View::drawVisibleText: Boxed style not yet implemented!" << endl; | |
| 857 } | |
| 858 } | |
| 859 | |
| 860 void | |
| 861 View::setPlaybackFollow(PlaybackFollowMode m) | 815 View::setPlaybackFollow(PlaybackFollowMode m) | 
| 862 { | 816 { | 
| 863 m_followPlay = m; | 817 m_followPlay = m; | 
| 864 emit propertyContainerPropertyChanged(m_propertyContainer); | 818 emit propertyContainerPropertyChanged(m_propertyContainer); | 
| 865 } | 819 } | 
| 2365 | 2319 | 
| 2366 dxy = r.y() + r.height() + fontAscent + 2; | 2320 dxy = r.y() + r.height() + fontAscent + 2; | 
| 2367 } | 2321 } | 
| 2368 | 2322 | 
| 2369 if (axs != "") { | 2323 if (axs != "") { | 
| 2370 drawVisibleText(paint, axx, axy, axs, OutlinedText); | 2324 PaintAssistant::drawVisibleText(this, paint, axx, axy, axs, PaintAssistant::OutlinedText); | 
| 2371 axy += fontHeight; | 2325 axy += fontHeight; | 
| 2372 } | 2326 } | 
| 2373 | 2327 | 
| 2374 if (ays != "") { | 2328 if (ays != "") { | 
| 2375 drawVisibleText(paint, axx, axy, ays, OutlinedText); | 2329 PaintAssistant::drawVisibleText(this, paint, axx, axy, ays, PaintAssistant::OutlinedText); | 
| 2376 axy += fontHeight; | 2330 axy += fontHeight; | 
| 2377 } | 2331 } | 
| 2378 | 2332 | 
| 2379 if (bxs != "") { | 2333 if (bxs != "") { | 
| 2380 drawVisibleText(paint, bxx, bxy, bxs, OutlinedText); | 2334 PaintAssistant::drawVisibleText(this, paint, bxx, bxy, bxs, PaintAssistant::OutlinedText); | 
| 2381 bxy += fontHeight; | 2335 bxy += fontHeight; | 
| 2382 } | 2336 } | 
| 2383 | 2337 | 
| 2384 if (bys != "") { | 2338 if (bys != "") { | 
| 2385 drawVisibleText(paint, bxx, bxy, bys, OutlinedText); | 2339 PaintAssistant::drawVisibleText(this, paint, bxx, bxy, bys, PaintAssistant::OutlinedText); | 
| 2386 bxy += fontHeight; | 2340 bxy += fontHeight; | 
| 2387 } | 2341 } | 
| 2388 | 2342 | 
| 2389 if (dxs != "") { | 2343 if (dxs != "") { | 
| 2390 drawVisibleText(paint, dxx, dxy, dxs, OutlinedText); | 2344 PaintAssistant::drawVisibleText(this, paint, dxx, dxy, dxs, PaintAssistant::OutlinedText); | 
| 2391 dxy += fontHeight; | 2345 dxy += fontHeight; | 
| 2392 } | 2346 } | 
| 2393 | 2347 | 
| 2394 if (dys != "") { | 2348 if (dys != "") { | 
| 2395 drawVisibleText(paint, dxx, dxy, dys, OutlinedText); | 2349 PaintAssistant::drawVisibleText(this, paint, dxx, dxy, dys, PaintAssistant::OutlinedText); | 
| 2396 dxy += fontHeight; | 2350 dxy += fontHeight; | 
| 2397 } | 2351 } | 
| 2398 | 2352 | 
| 2399 paint.restore(); | 2353 paint.restore(); | 
| 2400 } | 2354 } | 
