Mercurial > hg > svgui
comparison view/Pane.cpp @ 264:7e9e533f1863
* few more measurement mode bits
author | Chris Cannam |
---|---|
date | Fri, 15 Jun 2007 12:55:16 +0000 |
parents | 16fffa24da02 |
children | aee39d8c0b83 |
comparison
equal
deleted
inserted
replaced
263:16fffa24da02 | 264:7e9e533f1863 |
---|---|
2 | 2 |
3 /* | 3 /* |
4 Sonic Visualiser | 4 Sonic Visualiser |
5 An audio file viewer and annotation editor. | 5 An audio file viewer and annotation editor. |
6 Centre for Digital Music, Queen Mary, University of London. | 6 Centre for Digital Music, Queen Mary, University of London. |
7 This file copyright 2006 Chris Cannam and QMUL. | 7 This file copyright 2006-2007 Chris Cannam and QMUL. |
8 | 8 |
9 This program is free software; you can redistribute it and/or | 9 This program is free software; you can redistribute it and/or |
10 modify it under the terms of the GNU General Public License as | 10 modify it under the terms of the GNU General Public License as |
11 published by the Free Software Foundation; either version 2 of the | 11 published by the Free Software Foundation; either version 2 of the |
12 License, or (at your option) any later version. See the file | 12 License, or (at your option) any later version. See the file |
758 float v0, v1; | 758 float v0, v1; |
759 QString u0, u1; | 759 QString u0, u1; |
760 bool b0 = false, b1 = false; | 760 bool b0 = false, b1 = false; |
761 | 761 |
762 QString axs, ays, bxs, bys, dxs, dys; | 762 QString axs, ays, bxs, bys, dxs, dys; |
763 | 763 |
764 int axx, axy, bxx, bxy, dxx, dxy; | |
765 int aw = 0, bw = 0, dw = 0; | |
766 | |
767 int labelCount = 0; | |
768 | |
764 if ((b0 = topLayer->getXScaleValue(this, m_measureStart.x(), v0, u0))) { | 769 if ((b0 = topLayer->getXScaleValue(this, m_measureStart.x(), v0, u0))) { |
765 axs = QString("%1 %2").arg(v0).arg(u0); | 770 axs = QString("%1 %2").arg(v0).arg(u0); |
771 aw = paint.fontMetrics().width(axs); | |
772 ++labelCount; | |
766 } | 773 } |
767 | 774 |
768 if (m_measureStart != m_measureEnd) { | 775 if (m_measureStart != m_measureEnd) { |
769 if ((b1 = topLayer->getXScaleValue(this, m_measureEnd.x(), v1, u1))) { | 776 if ((b1 = topLayer->getXScaleValue(this, m_measureEnd.x(), v1, u1))) { |
770 bxs = QString("%1 %2").arg(v1).arg(u1); | 777 bxs = QString("%1 %2").arg(v1).arg(u1); |
778 bw = paint.fontMetrics().width(bxs); | |
771 } | 779 } |
772 } | 780 } |
773 | 781 |
774 if (b0 && b1 && u0 == u1) { | 782 if (b0 && b1 && u0 == u1) { |
775 dxs = QString("(%1 %2)").arg(v1 - v0).arg(u1); | 783 dxs = QString("(%1 %2)").arg(fabs(v1 - v0)).arg(u1); |
784 dw = paint.fontMetrics().width(dxs); | |
776 } | 785 } |
777 | 786 |
778 b0 = false; | 787 b0 = false; |
779 b1 = false; | 788 b1 = false; |
780 | 789 |
781 if ((b0 = topLayer->getYScaleValue(this, m_measureStart.y(), v0, u0))) { | 790 if ((b0 = topLayer->getYScaleValue(this, m_measureStart.y(), v0, u0))) { |
782 ays = QString("%1 %2").arg(v0).arg(u0); | 791 ays = QString("%1 %2").arg(v0).arg(u0); |
792 aw = std::max(aw, paint.fontMetrics().width(ays)); | |
793 ++labelCount; | |
783 } | 794 } |
784 | 795 |
785 if (m_measureStart != m_measureEnd) { | 796 if (m_measureStart != m_measureEnd) { |
786 if ((b1 = topLayer->getYScaleValue(this, m_measureEnd.y(), v1, u1))) { | 797 if ((b1 = topLayer->getYScaleValue(this, m_measureEnd.y(), v1, u1))) { |
787 bys = QString("%1 %2").arg(v1).arg(u1); | 798 bys = QString("%1 %2").arg(v1).arg(u1); |
799 bw = std::max(bw, paint.fontMetrics().width(bys)); | |
788 } | 800 } |
789 } | 801 } |
790 | 802 |
791 if (b0 && b1 && u0 == u1) { | 803 if (b0 && b1 && u0 == u1) { |
792 dys = QString("(%1 %2)").arg(v1 - v0).arg(u1); | 804 dys = QString("(%1 %2)").arg(fabs(v1 - v0)).arg(u1); |
793 } | 805 dw = std::max(dw, paint.fontMetrics().width(dys)); |
794 | 806 } |
795 int x = m_measureStart.x() + 2; | 807 |
796 int y = m_measureStart.y() + fontAscent + 2; | 808 int mw = abs(m_measureEnd.x() - m_measureStart.x()); |
809 int mh = abs(m_measureEnd.y() - m_measureStart.y()); | |
810 | |
811 bool edgeLabelsInside = false; | |
812 bool sizeLabelsInside = false; | |
813 | |
814 if (mw < std::max(aw, std::max(bw, dw)) + 4) { | |
815 // defaults stand | |
816 } else if (mw < aw + bw + 4) { | |
817 if (mh > fontHeight * labelCount * 3 + 4) { | |
818 edgeLabelsInside = true; | |
819 sizeLabelsInside = true; | |
820 } else if (mh > fontHeight * labelCount * 2 + 4) { | |
821 edgeLabelsInside = true; | |
822 } | |
823 } else if (mw < aw + bw + dw + 4) { | |
824 if (mh > fontHeight * labelCount * 3 + 4) { | |
825 edgeLabelsInside = true; | |
826 sizeLabelsInside = true; | |
827 } else if (mh > fontHeight * labelCount + 4) { | |
828 edgeLabelsInside = true; | |
829 } | |
830 } else { | |
831 if (mh > fontHeight * labelCount + 4) { | |
832 edgeLabelsInside = true; | |
833 sizeLabelsInside = true; | |
834 } | |
835 } | |
836 | |
837 if (edgeLabelsInside) { | |
838 | |
839 axx = m_measureStart.x() + 2; | |
840 axy = m_measureStart.y() + fontAscent + 2; | |
841 | |
842 bxx = m_measureEnd.x() - bw - 2; | |
843 bxy = m_measureEnd.y() - (labelCount-1) * fontHeight - 2; | |
844 | |
845 } else { | |
846 | |
847 axx = m_measureStart.x() - aw - 2; | |
848 axy = m_measureStart.y() + fontAscent; | |
849 | |
850 bxx = m_measureEnd.x() + 2; | |
851 bxy = m_measureEnd.y() - (labelCount-1) * fontHeight; | |
852 } | |
853 | |
854 dxx = (m_measureEnd.x() - m_measureStart.x()) | |
855 / 2 + m_measureStart.x() - dw/2; | |
856 | |
857 if (sizeLabelsInside) { | |
858 | |
859 dxy = (m_measureEnd.y() - m_measureStart.y()) | |
860 / 2 + m_measureStart.y() - (labelCount * fontHeight)/2 + fontAscent; | |
861 | |
862 } else { | |
863 | |
864 dxy = std::max(m_measureEnd.y(), m_measureStart.y()) + fontAscent + 2; | |
865 } | |
797 | 866 |
798 if (axs != "") { | 867 if (axs != "") { |
799 drawVisibleText(paint, x, y, axs, OutlinedText); | 868 drawVisibleText(paint, axx, axy, axs, OutlinedText); |
800 y += fontHeight; | 869 axy += fontHeight; |
801 } | 870 } |
802 | 871 |
803 if (ays != "") { | 872 if (ays != "") { |
804 drawVisibleText(paint, x, y, ays, OutlinedText); | 873 drawVisibleText(paint, axx, axy, ays, OutlinedText); |
805 y += fontHeight; | 874 axy += fontHeight; |
806 } | 875 } |
807 | 876 |
808 x = m_measureEnd.x() - paint.fontMetrics().width(bxs) - 2; | |
809 y = m_measureEnd.y() - 2; | |
810 | |
811 if (bys != "" && bxs != "") y -= fontHeight; | |
812 | |
813 if (bxs != "") { | 877 if (bxs != "") { |
814 drawVisibleText(paint, x, y, bxs, OutlinedText); | 878 drawVisibleText(paint, bxx, bxy, bxs, OutlinedText); |
815 y += fontHeight; | 879 bxy += fontHeight; |
816 } | 880 } |
817 | |
818 x = m_measureEnd.x() - paint.fontMetrics().width(bys) - 2; | |
819 | 881 |
820 if (bys != "") { | 882 if (bys != "") { |
821 drawVisibleText(paint, x, y, bys, OutlinedText); | 883 drawVisibleText(paint, bxx, bxy, bys, OutlinedText); |
822 y += fontHeight; | 884 bxy += fontHeight; |
885 } | |
886 | |
887 if (dxs != "") { | |
888 drawVisibleText(paint, dxx, dxy, dxs, OutlinedText); | |
889 dxy += fontHeight; | |
890 } | |
891 | |
892 if (dys != "") { | |
893 drawVisibleText(paint, dxx, dxy, dys, OutlinedText); | |
894 dxy += fontHeight; | |
823 } | 895 } |
824 | 896 |
825 if (m_measureStart != m_measureEnd) { | 897 if (m_measureStart != m_measureEnd) { |
826 | 898 |
827 paint.save(); | 899 paint.save(); |