! \internal This is a \ref placeTickLabel helper function. Calculates the offset at which the top left corner of the specified tick label shall be drawn. The offset is relative to a point right next to the tick the label belongs to. This function is thus responsible for e.g. centering tick labels under ticks and positioning them appropriately when they are rotated. */
| 9707 | appropriately when they are rotated. |
| 9708 | */ |
| 9709 | QPointF QCPAxisPainterPrivate::getTickLabelDrawOffset(const TickLabelData &labelData) const |
| 9710 | { |
| 9711 | /* |
| 9712 | calculate label offset from base point at tick (non-trivial, for best visual appearance): short |
| 9713 | explanation for bottom axis: The anchor, i.e. the point in the label that is placed |
| 9714 | horizontally under the corresponding tick is always on the label side that is closer to the |
| 9715 | axis (e.g. the left side of the text when we're rotating clockwise). On that side, the height |
| 9716 | is halved and the resulting point is defined the anchor. This way, a 90 degree rotated text |
| 9717 | will be centered under the tick (i.e. displaced horizontally by half its height). At the same |
| 9718 | time, a 45 degree rotated text will "point toward" its tick, as is typical for rotated tick |
| 9719 | labels. |
| 9720 | */ |
| 9721 | bool doRotation = !qFuzzyIsNull(tickLabelRotation); |
| 9722 | bool flip = qFuzzyCompare(qAbs(tickLabelRotation), 90.0); // perfect +/-90 degree flip. Indicates vertical label centering on vertical axes. |
| 9723 | double radians = tickLabelRotation/180.0*M_PI; |
| 9724 | int x=0, y=0; |
| 9725 | if ((type == QCPAxis::atLeft && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atRight && tickLabelSide == QCPAxis::lsInside)) // Anchor at right side of tick label |
| 9726 | { |
| 9727 | if (doRotation) |
| 9728 | { |
| 9729 | if (tickLabelRotation > 0) |
| 9730 | { |
| 9731 | x = -qCos(radians)*labelData.totalBounds.width(); |
| 9732 | y = flip ? -labelData.totalBounds.width()/2.0 : -qSin(radians)*labelData.totalBounds.width()-qCos(radians)*labelData.totalBounds.height()/2.0; |
| 9733 | } else |
| 9734 | { |
| 9735 | x = -qCos(-radians)*labelData.totalBounds.width()-qSin(-radians)*labelData.totalBounds.height(); |
| 9736 | y = flip ? +labelData.totalBounds.width()/2.0 : +qSin(-radians)*labelData.totalBounds.width()-qCos(-radians)*labelData.totalBounds.height()/2.0; |
| 9737 | } |
| 9738 | } else |
| 9739 | { |
| 9740 | x = -labelData.totalBounds.width(); |
| 9741 | y = -labelData.totalBounds.height()/2.0; |
| 9742 | } |
| 9743 | } else if ((type == QCPAxis::atRight && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atLeft && tickLabelSide == QCPAxis::lsInside)) // Anchor at left side of tick label |
| 9744 | { |
| 9745 | if (doRotation) |
| 9746 | { |
| 9747 | if (tickLabelRotation > 0) |
| 9748 | { |
| 9749 | x = +qSin(radians)*labelData.totalBounds.height(); |
| 9750 | y = flip ? -labelData.totalBounds.width()/2.0 : -qCos(radians)*labelData.totalBounds.height()/2.0; |
| 9751 | } else |
| 9752 | { |
| 9753 | x = 0; |
| 9754 | y = flip ? +labelData.totalBounds.width()/2.0 : -qCos(-radians)*labelData.totalBounds.height()/2.0; |
| 9755 | } |
| 9756 | } else |
| 9757 | { |
| 9758 | x = 0; |
| 9759 | y = -labelData.totalBounds.height()/2.0; |
| 9760 | } |
| 9761 | } else if ((type == QCPAxis::atTop && tickLabelSide == QCPAxis::lsOutside) || (type == QCPAxis::atBottom && tickLabelSide == QCPAxis::lsInside)) // Anchor at bottom side of tick label |
| 9762 | { |
| 9763 | if (doRotation) |
| 9764 | { |
| 9765 | if (tickLabelRotation > 0) |
| 9766 | { |
nothing calls this directly
no outgoing calls
no test coverage detected