Mercurial > hg > svgui
comparison view/View.cpp @ 267:4ed1446ad604
* more on measurement tool -- pull out some logic from pane to layer &c
still more to do
author | Chris Cannam |
---|---|
date | Thu, 21 Jun 2007 16:12:00 +0000 |
parents | 28c8e8e3c537 |
children | 70537b0434c4 |
comparison
equal
deleted
inserted
replaced
266:aee39d8c0b83 | 267:4ed1446ad604 |
---|---|
611 m_followZoom = f; | 611 m_followZoom = f; |
612 emit propertyContainerPropertyChanged(m_propertyContainer); | 612 emit propertyContainerPropertyChanged(m_propertyContainer); |
613 } | 613 } |
614 | 614 |
615 void | 615 void |
616 View::drawVisibleText(QPainter &paint, int x, int y, QString text, TextStyle style) | 616 View::drawVisibleText(QPainter &paint, int x, int y, QString text, TextStyle style) const |
617 { | 617 { |
618 if (style == OutlinedText) { | 618 if (style == OutlinedText) { |
619 | 619 |
620 QColor origPenColour = paint.pen().color(); | 620 QColor origPenColour = paint.pen().color(); |
621 QColor penColour = origPenColour; | 621 QColor penColour = origPenColour; |
1626 } | 1626 } |
1627 | 1627 |
1628 paint.restore(); | 1628 paint.restore(); |
1629 } | 1629 } |
1630 | 1630 |
1631 void | |
1632 View::drawMeasurementRect(QPainter &paint, const Layer *topLayer, QRect r) const | |
1633 { | |
1634 if (r.x() + r.width() < 0 || r.x() >= width()) return; | |
1635 | |
1636 int fontHeight = paint.fontMetrics().height(); | |
1637 int fontAscent = paint.fontMetrics().ascent(); | |
1638 | |
1639 float v0, v1; | |
1640 QString u0, u1; | |
1641 bool b0 = false, b1 = false; | |
1642 | |
1643 QString axs, ays, bxs, bys, dxs, dys; | |
1644 | |
1645 int axx, axy, bxx, bxy, dxx, dxy; | |
1646 int aw = 0, bw = 0, dw = 0; | |
1647 | |
1648 int labelCount = 0; | |
1649 | |
1650 if ((b0 = topLayer->getXScaleValue(this, r.x(), v0, u0))) { | |
1651 axs = QString("%1 %2").arg(v0).arg(u0); | |
1652 aw = paint.fontMetrics().width(axs); | |
1653 ++labelCount; | |
1654 } | |
1655 | |
1656 if (r.width() > 0) { | |
1657 if ((b1 = topLayer->getXScaleValue(this, r.x() + r.width(), v1, u1))) { | |
1658 bxs = QString("%1 %2").arg(v1).arg(u1); | |
1659 bw = paint.fontMetrics().width(bxs); | |
1660 } | |
1661 } | |
1662 | |
1663 if (b0 && b1 && u0 == u1) { | |
1664 dxs = QString("(%1 %2)").arg(fabs(v1 - v0)).arg(u1); | |
1665 dw = paint.fontMetrics().width(dxs); | |
1666 } | |
1667 | |
1668 b0 = false; | |
1669 b1 = false; | |
1670 | |
1671 if ((b0 = topLayer->getYScaleValue(this, r.y(), v0, u0))) { | |
1672 ays = QString("%1 %2").arg(v0).arg(u0); | |
1673 aw = std::max(aw, paint.fontMetrics().width(ays)); | |
1674 ++labelCount; | |
1675 } | |
1676 | |
1677 if (r.height() > 0) { | |
1678 if ((b1 = topLayer->getYScaleValue(this, r.y() + r.height(), v1, u1))) { | |
1679 bys = QString("%1 %2").arg(v1).arg(u1); | |
1680 bw = std::max(bw, paint.fontMetrics().width(bys)); | |
1681 } | |
1682 } | |
1683 | |
1684 if (b0 && b1 && u0 == u1) { | |
1685 dys = QString("(%1 %2)").arg(fabs(v1 - v0)).arg(u1); | |
1686 dw = std::max(dw, paint.fontMetrics().width(dys)); | |
1687 } | |
1688 | |
1689 int mw = r.width(); | |
1690 int mh = r.height(); | |
1691 | |
1692 bool edgeLabelsInside = false; | |
1693 bool sizeLabelsInside = false; | |
1694 | |
1695 if (mw < std::max(aw, std::max(bw, dw)) + 4) { | |
1696 // defaults stand | |
1697 } else if (mw < aw + bw + 4) { | |
1698 if (mh > fontHeight * labelCount * 3 + 4) { | |
1699 edgeLabelsInside = true; | |
1700 sizeLabelsInside = true; | |
1701 } else if (mh > fontHeight * labelCount * 2 + 4) { | |
1702 edgeLabelsInside = true; | |
1703 } | |
1704 } else if (mw < aw + bw + dw + 4) { | |
1705 if (mh > fontHeight * labelCount * 3 + 4) { | |
1706 edgeLabelsInside = true; | |
1707 sizeLabelsInside = true; | |
1708 } else if (mh > fontHeight * labelCount + 4) { | |
1709 edgeLabelsInside = true; | |
1710 } | |
1711 } else { | |
1712 if (mh > fontHeight * labelCount + 4) { | |
1713 edgeLabelsInside = true; | |
1714 sizeLabelsInside = true; | |
1715 } | |
1716 } | |
1717 | |
1718 if (edgeLabelsInside) { | |
1719 | |
1720 axx = r.x() + 2; | |
1721 axy = r.y() + fontAscent + 2; | |
1722 | |
1723 bxx = r.x() + r.width() - bw - 2; | |
1724 bxy = r.y() + r.height() - (labelCount-1) * fontHeight - 2; | |
1725 | |
1726 } else { | |
1727 | |
1728 axx = r.x() - aw - 2; | |
1729 axy = r.y() + fontAscent; | |
1730 | |
1731 bxx = r.x() + r.width() + 2; | |
1732 bxy = r.y() + r.height() - (labelCount-1) * fontHeight; | |
1733 } | |
1734 | |
1735 dxx = r.width()/2 + r.x() - dw/2; | |
1736 | |
1737 if (sizeLabelsInside) { | |
1738 | |
1739 dxy = r.height()/2 + r.y() - (labelCount * fontHeight)/2 + fontAscent; | |
1740 | |
1741 } else { | |
1742 | |
1743 dxy = r.y() + r.height() + fontAscent + 2; | |
1744 } | |
1745 | |
1746 if (axs != "") { | |
1747 drawVisibleText(paint, axx, axy, axs, OutlinedText); | |
1748 axy += fontHeight; | |
1749 } | |
1750 | |
1751 if (ays != "") { | |
1752 drawVisibleText(paint, axx, axy, ays, OutlinedText); | |
1753 axy += fontHeight; | |
1754 } | |
1755 | |
1756 if (bxs != "") { | |
1757 drawVisibleText(paint, bxx, bxy, bxs, OutlinedText); | |
1758 bxy += fontHeight; | |
1759 } | |
1760 | |
1761 if (bys != "") { | |
1762 drawVisibleText(paint, bxx, bxy, bys, OutlinedText); | |
1763 bxy += fontHeight; | |
1764 } | |
1765 | |
1766 if (dxs != "") { | |
1767 drawVisibleText(paint, dxx, dxy, dxs, OutlinedText); | |
1768 dxy += fontHeight; | |
1769 } | |
1770 | |
1771 if (dys != "") { | |
1772 drawVisibleText(paint, dxx, dxy, dys, OutlinedText); | |
1773 dxy += fontHeight; | |
1774 } | |
1775 | |
1776 if (r.width() != 0 || r.height() != 0) { | |
1777 paint.save(); | |
1778 paint.setPen(Qt::green); | |
1779 paint.drawRect(r); | |
1780 paint.restore(); | |
1781 } | |
1782 } | |
1783 | |
1631 bool | 1784 bool |
1632 View::render(QPainter &paint, int xorigin, size_t f0, size_t f1) | 1785 View::render(QPainter &paint, int xorigin, size_t f0, size_t f1) |
1633 { | 1786 { |
1634 size_t x0 = f0 / m_zoomLevel; | 1787 size_t x0 = f0 / m_zoomLevel; |
1635 size_t x1 = f1 / m_zoomLevel; | 1788 size_t x1 = f1 / m_zoomLevel; |