Mercurial > hg > svgui
comparison layer/TimeValueLayer.cpp @ 615:156a120345ae
Add discrete-curve drawing mode for time-value layer
author | Chris Cannam |
---|---|
date | Fri, 16 Nov 2012 17:14:12 +0000 |
parents | 5b72899d692b |
children | d632a1e87018 355fa700ce70 |
comparison
equal
deleted
inserted
replaced
614:7ac63919fd52 | 615:156a120345ae |
---|---|
158 val = m_colourMap; | 158 val = m_colourMap; |
159 | 159 |
160 } else if (name == "Plot Type") { | 160 } else if (name == "Plot Type") { |
161 | 161 |
162 if (min) *min = 0; | 162 if (min) *min = 0; |
163 if (max) *max = 5; | 163 if (max) *max = 6; |
164 if (deflt) *deflt = int(PlotConnectedPoints); | 164 if (deflt) *deflt = int(PlotConnectedPoints); |
165 | 165 |
166 val = int(m_plotStyle); | 166 val = int(m_plotStyle); |
167 | 167 |
168 } else if (name == "Vertical Scale") { | 168 } else if (name == "Vertical Scale") { |
216 case 1: return tr("Stems"); | 216 case 1: return tr("Stems"); |
217 case 2: return tr("Connected Points"); | 217 case 2: return tr("Connected Points"); |
218 case 3: return tr("Lines"); | 218 case 3: return tr("Lines"); |
219 case 4: return tr("Curve"); | 219 case 4: return tr("Curve"); |
220 case 5: return tr("Segmentation"); | 220 case 5: return tr("Segmentation"); |
221 case 6: return tr("Discrete Curves"); | |
221 } | 222 } |
222 } else if (name == "Vertical Scale") { | 223 } else if (name == "Vertical Scale") { |
223 switch (value) { | 224 switch (value) { |
224 default: | 225 default: |
225 case 0: return tr("Auto-Align"); | 226 case 0: return tr("Auto-Align"); |
305 { | 306 { |
306 // We don't illuminate sections in the line or curve modes, so | 307 // We don't illuminate sections in the line or curve modes, so |
307 // they're always scrollable | 308 // they're always scrollable |
308 | 309 |
309 if (m_plotStyle == PlotLines || | 310 if (m_plotStyle == PlotLines || |
310 m_plotStyle == PlotCurve) return true; | 311 m_plotStyle == PlotCurve || |
312 m_plotStyle == PlotDiscreteCurves) return true; | |
311 | 313 |
312 QPoint discard; | 314 QPoint discard; |
313 return !v->shouldIlluminateLocalFeatures(this, discard); | 315 return !v->shouldIlluminateLocalFeatures(this, discard); |
314 } | 316 } |
315 | 317 |
913 paint.drawLine(x0, originY, x1, originY); | 915 paint.drawLine(x0, originY, x1, originY); |
914 paint.restore(); | 916 paint.restore(); |
915 } | 917 } |
916 } | 918 } |
917 | 919 |
920 int prevFrame = 0; | |
921 | |
918 for (SparseTimeValueModel::PointList::const_iterator i = points.begin(); | 922 for (SparseTimeValueModel::PointList::const_iterator i = points.begin(); |
919 i != points.end(); ++i) { | 923 i != points.end(); ++i) { |
920 | 924 |
921 if (m_derivative && i == points.begin()) continue; | 925 if (m_derivative && i == points.begin()) continue; |
922 | 926 |
929 value -= j->value; | 933 value -= j->value; |
930 } | 934 } |
931 | 935 |
932 int x = v->getXForFrame(p.frame); | 936 int x = v->getXForFrame(p.frame); |
933 int y = getYForValue(v, value); | 937 int y = getYForValue(v, value); |
938 | |
939 bool gap = false; | |
940 if (m_plotStyle == PlotDiscreteCurves) { | |
941 gap = (p.frame > prevFrame && | |
942 (p.frame - prevFrame >= m_model->getResolution() * 2)); | |
943 } | |
934 | 944 |
935 if (m_plotStyle != PlotSegmentation) { | 945 if (m_plotStyle != PlotSegmentation) { |
936 textY = y - paint.fontMetrics().height() | 946 textY = y - paint.fontMetrics().height() |
937 + paint.fontMetrics().ascent(); | 947 + paint.fontMetrics().ascent(); |
938 if (textY < paint.fontMetrics().ascent() + 1) { | 948 if (textY < paint.fontMetrics().ascent() + 1) { |
939 textY = paint.fontMetrics().ascent() + 1; | 949 textY = paint.fontMetrics().ascent() + 1; |
940 } | 950 } |
941 } | 951 } |
942 | 952 |
943 bool haveNext = false; | 953 bool haveNext = false; |
944 int nx = v->getXForFrame(v->getModelsEndFrame()); | 954 int nf = v->getModelsEndFrame(); |
955 int nx = v->getXForFrame(nf); | |
945 int ny = y; | 956 int ny = y; |
946 | 957 |
947 SparseTimeValueModel::PointList::const_iterator j = i; | 958 SparseTimeValueModel::PointList::const_iterator j = i; |
948 ++j; | 959 ++j; |
949 | 960 |
950 if (j != points.end()) { | 961 if (j != points.end()) { |
951 const SparseTimeValueModel::Point &q(*j); | 962 const SparseTimeValueModel::Point &q(*j); |
952 float nvalue = q.value; | 963 float nvalue = q.value; |
953 if (m_derivative) nvalue -= p.value; | 964 if (m_derivative) nvalue -= p.value; |
954 nx = v->getXForFrame(q.frame); | 965 nf = q.frame; |
966 nx = v->getXForFrame(nf); | |
955 ny = getYForValue(v, nvalue); | 967 ny = getYForValue(v, nvalue); |
956 haveNext = true; | 968 haveNext = true; |
957 } | 969 } |
958 | 970 |
959 // std::cout << "frame = " << p.frame << ", x = " << x << ", haveNext = " << haveNext | 971 // std::cout << "frame = " << p.frame << ", x = " << x << ", haveNext = " << haveNext |
960 // << ", nx = " << nx << std::endl; | 972 // << ", nx = " << nx << std::endl; |
961 | 973 |
962 if (w < 1) w = 1; | 974 if (w < 1) w = 1; |
963 paint.setPen(getBaseQColor()); | 975 |
964 | 976 if (m_plotStyle == PlotDiscreteCurves) { |
965 if (m_plotStyle == PlotSegmentation) { | 977 paint.setPen(QPen(getBaseQColor(), 3)); |
978 paint.setBrush(Qt::NoBrush); | |
979 } else if (m_plotStyle == PlotSegmentation) { | |
966 paint.setPen(getForegroundQColor(v)); | 980 paint.setPen(getForegroundQColor(v)); |
967 paint.setBrush(getColourForValue(v, value)); | 981 paint.setBrush(getColourForValue(v, value)); |
968 } else if (m_plotStyle == PlotLines || | 982 } else if (m_plotStyle == PlotLines || |
969 m_plotStyle == PlotCurve) { | 983 m_plotStyle == PlotCurve) { |
984 paint.setPen(getBaseQColor()); | |
970 paint.setBrush(Qt::NoBrush); | 985 paint.setBrush(Qt::NoBrush); |
971 } else { | 986 } else { |
987 paint.setPen(getBaseQColor()); | |
972 paint.setBrush(brushColour); | 988 paint.setBrush(brushColour); |
973 } | 989 } |
974 | 990 |
975 if (m_plotStyle == PlotStems) { | 991 if (m_plotStyle == PlotStems) { |
976 /* | 992 /* |
997 | 1013 |
998 //!!! not equipped to illuminate the right section in line | 1014 //!!! not equipped to illuminate the right section in line |
999 //or curve mode | 1015 //or curve mode |
1000 | 1016 |
1001 if (m_plotStyle != PlotCurve && | 1017 if (m_plotStyle != PlotCurve && |
1018 m_plotStyle != PlotDiscreteCurves && | |
1002 m_plotStyle != PlotLines) { | 1019 m_plotStyle != PlotLines) { |
1003 paint.setPen(getForegroundQColor(v)); | 1020 paint.setPen(getForegroundQColor(v)); |
1004 } | 1021 } |
1005 } | 1022 } |
1006 | 1023 |
1007 if (m_plotStyle != PlotLines && | 1024 if (m_plotStyle != PlotLines && |
1008 m_plotStyle != PlotCurve && | 1025 m_plotStyle != PlotCurve && |
1026 m_plotStyle != PlotDiscreteCurves && | |
1009 m_plotStyle != PlotSegmentation) { | 1027 m_plotStyle != PlotSegmentation) { |
1010 if (m_plotStyle != PlotStems || | 1028 if (m_plotStyle != PlotStems || |
1011 w > 1) { | 1029 w > 1) { |
1012 paint.drawRect(x, y - 1, w, 2); | 1030 paint.drawRect(x, y - 1, w, 2); |
1013 } | 1031 } |
1014 } | 1032 } |
1015 | 1033 |
1016 if (m_plotStyle == PlotConnectedPoints || | 1034 if (m_plotStyle == PlotConnectedPoints || |
1017 m_plotStyle == PlotLines || | 1035 m_plotStyle == PlotLines || |
1036 m_plotStyle == PlotDiscreteCurves || | |
1018 m_plotStyle == PlotCurve) { | 1037 m_plotStyle == PlotCurve) { |
1019 | 1038 |
1020 if (haveNext) { | 1039 if (haveNext) { |
1021 | 1040 |
1022 if (m_plotStyle == PlotConnectedPoints) { | 1041 if (m_plotStyle == PlotConnectedPoints) { |
1042 float x1 = nx + float(w)/2; | 1061 float x1 = nx + float(w)/2; |
1043 | 1062 |
1044 float y0 = y; | 1063 float y0 = y; |
1045 float y1 = ny; | 1064 float y1 = ny; |
1046 | 1065 |
1047 if (pointCount == 0) { | 1066 if (m_plotStyle == PlotDiscreteCurves) { |
1067 bool nextGap = nf - p.frame >= m_model->getResolution() * 2; | |
1068 if (nextGap) { | |
1069 x1 = x0; | |
1070 y1 = y0; | |
1071 } | |
1072 } | |
1073 | |
1074 if (pointCount == 0 || gap) { | |
1048 path.moveTo((x0 + x1) / 2, (y0 + y1) / 2); | 1075 path.moveTo((x0 + x1) / 2, (y0 + y1) / 2); |
1049 } | 1076 } |
1050 ++pointCount; | 1077 ++pointCount; |
1051 | 1078 |
1052 if (nx - x > 5) { | 1079 if (nx - x > 5) { |
1089 if (!haveNext || nx > x + 6 + paint.fontMetrics().width(p.label)) { | 1116 if (!haveNext || nx > x + 6 + paint.fontMetrics().width(p.label)) { |
1090 v->drawVisibleText(paint, x + 5, textY, p.label, View::OutlinedText); | 1117 v->drawVisibleText(paint, x + 5, textY, p.label, View::OutlinedText); |
1091 // paint.drawText(x + 5, textY, p.label); | 1118 // paint.drawText(x + 5, textY, p.label); |
1092 } | 1119 } |
1093 } | 1120 } |
1094 } | 1121 |
1095 | 1122 prevFrame = p.frame; |
1096 if ((m_plotStyle == PlotCurve || m_plotStyle == PlotLines) | 1123 } |
1124 | |
1125 if ((m_plotStyle == PlotCurve || m_plotStyle == PlotDiscreteCurves || | |
1126 m_plotStyle == PlotLines) | |
1097 && !path.isEmpty()) { | 1127 && !path.isEmpty()) { |
1098 paint.setRenderHint(QPainter::Antialiasing, pointCount <= v->width()); | 1128 paint.setRenderHint(QPainter::Antialiasing, pointCount <= v->width()); |
1099 paint.drawPath(path); | 1129 paint.drawPath(path); |
1100 } | 1130 } |
1101 | 1131 |