comparison view/View.cpp @ 1078:ee01a4062747 spectrogram-minor-refactor

Move drawVisibleText to PaintAssistant
author Chris Cannam
date Thu, 30 Jun 2016 12:40:22 +0100
parents 4e5c1c326794
children 179ea8a2f650
comparison
equal deleted inserted replaced
1077:5144d7185fb5 1078:ee01a4062747
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
808 m_followZoom = f; 810 m_followZoom = f;
809 emit propertyContainerPropertyChanged(m_propertyContainer); 811 emit propertyContainerPropertyChanged(m_propertyContainer);
810 } 812 }
811 813
812 void 814 void
813 View::drawVisibleText(QPainter &paint, int x, int y, QString text, TextStyle style) const
814 {
815 if (style == OutlinedText || style == OutlinedItalicText) {
816
817 paint.save();
818
819 if (style == OutlinedItalicText) {
820 QFont f(paint.font());
821 f.setItalic(true);
822 paint.setFont(f);
823 }
824
825 QColor penColour, surroundColour, boxColour;
826
827 penColour = getForeground();
828 surroundColour = getBackground();
829 boxColour = surroundColour;
830 boxColour.setAlpha(127);
831
832 paint.setPen(Qt::NoPen);
833 paint.setBrush(boxColour);
834
835 QRect r = paint.fontMetrics().boundingRect(text);
836 r.translate(QPoint(x, y));
837 // cerr << "drawVisibleText: r = " << r.x() << "," <<r.y() << " " << r.width() << "x" << r.height() << endl;
838 paint.drawRect(r);
839 paint.setBrush(Qt::NoBrush);
840
841 paint.setPen(surroundColour);
842
843 for (int dx = -1; dx <= 1; ++dx) {
844 for (int dy = -1; dy <= 1; ++dy) {
845 if (!(dx || dy)) continue;
846 paint.drawText(x + dx, y + dy, text);
847 }
848 }
849
850 paint.setPen(penColour);
851
852 paint.drawText(x, y, text);
853
854 paint.restore();
855
856 } else {
857
858 cerr << "ERROR: View::drawVisibleText: Boxed style not yet implemented!" << endl;
859 }
860 }
861
862 void
863 View::setPlaybackFollow(PlaybackFollowMode m) 815 View::setPlaybackFollow(PlaybackFollowMode m)
864 { 816 {
865 m_followPlay = m; 817 m_followPlay = m;
866 emit propertyContainerPropertyChanged(m_propertyContainer); 818 emit propertyContainerPropertyChanged(m_propertyContainer);
867 } 819 }
2367 2319
2368 dxy = r.y() + r.height() + fontAscent + 2; 2320 dxy = r.y() + r.height() + fontAscent + 2;
2369 } 2321 }
2370 2322
2371 if (axs != "") { 2323 if (axs != "") {
2372 drawVisibleText(paint, axx, axy, axs, OutlinedText); 2324 PaintAssistant::drawVisibleText(this, paint, axx, axy, axs, PaintAssistant::OutlinedText);
2373 axy += fontHeight; 2325 axy += fontHeight;
2374 } 2326 }
2375 2327
2376 if (ays != "") { 2328 if (ays != "") {
2377 drawVisibleText(paint, axx, axy, ays, OutlinedText); 2329 PaintAssistant::drawVisibleText(this, paint, axx, axy, ays, PaintAssistant::OutlinedText);
2378 axy += fontHeight; 2330 axy += fontHeight;
2379 } 2331 }
2380 2332
2381 if (bxs != "") { 2333 if (bxs != "") {
2382 drawVisibleText(paint, bxx, bxy, bxs, OutlinedText); 2334 PaintAssistant::drawVisibleText(this, paint, bxx, bxy, bxs, PaintAssistant::OutlinedText);
2383 bxy += fontHeight; 2335 bxy += fontHeight;
2384 } 2336 }
2385 2337
2386 if (bys != "") { 2338 if (bys != "") {
2387 drawVisibleText(paint, bxx, bxy, bys, OutlinedText); 2339 PaintAssistant::drawVisibleText(this, paint, bxx, bxy, bys, PaintAssistant::OutlinedText);
2388 bxy += fontHeight; 2340 bxy += fontHeight;
2389 } 2341 }
2390 2342
2391 if (dxs != "") { 2343 if (dxs != "") {
2392 drawVisibleText(paint, dxx, dxy, dxs, OutlinedText); 2344 PaintAssistant::drawVisibleText(this, paint, dxx, dxy, dxs, PaintAssistant::OutlinedText);
2393 dxy += fontHeight; 2345 dxy += fontHeight;
2394 } 2346 }
2395 2347
2396 if (dys != "") { 2348 if (dys != "") {
2397 drawVisibleText(paint, dxx, dxy, dys, OutlinedText); 2349 PaintAssistant::drawVisibleText(this, paint, dxx, dxy, dys, PaintAssistant::OutlinedText);
2398 dxy += fontHeight; 2350 dxy += fontHeight;
2399 } 2351 }
2400 2352
2401 paint.restore(); 2353 paint.restore();
2402 } 2354 }