]> sigrok.org Git - pulseview.git/commitdiff
Moved Signal label layout to get_label_rect
authorJoel Holdsworth <redacted>
Sun, 14 Oct 2012 14:46:43 +0000 (15:46 +0100)
committerJoel Holdsworth <redacted>
Sat, 20 Oct 2012 17:29:25 +0000 (18:29 +0100)
pv/signal.cpp
pv/signal.h

index 282d272bf7df3395287fd6e5e5b127b022cfdca1..1a11cfeec1909d39c7a2ffeca54c24b91899dc80 100644 (file)
@@ -36,25 +36,29 @@ QString Signal::get_name() const
        return _name;
 }
 
-void Signal::paint_label(QPainter &p, const QRect &rect)
+QRectF Signal::get_label_rect(QPainter &p, const QRect &rect)
 {
-       p.setBrush(get_colour());
-
-       const QString text(_name);
-       const QColor colour = get_colour();
-
        const QSizeF text_size = p.boundingRect(
-               QRectF(0, 0, rect.width(), 0), 0, text).size();
+               QRectF(0, 0, rect.width(), 0), 0, _name).size();
 
        const float nominal_offset = get_nominal_offset(rect);
        const QSizeF label_size(
                text_size.width() + LabelPadding.width() * 2,
                text_size.height() + LabelPadding.height() * 2);
        const float label_arrow_length = label_size.height() / 2;
-       const QRectF label_rect(
+       return QRectF(
                rect.right() - label_arrow_length - label_size.width(),
                nominal_offset - label_size.height() / 2,
                label_size.width(), label_size.height());
+}
+
+void Signal::paint_label(QPainter &p, const QRect &rect)
+{
+       p.setBrush(get_colour());
+
+       const QColor colour = get_colour();
+       const float nominal_offset = get_nominal_offset(rect);
+       const QRectF label_rect = get_label_rect(p, rect);
 
        // Paint the label
        const QPointF points[] = {
@@ -87,7 +91,7 @@ void Signal::paint_label(QPainter &p, const QRect &rect)
 
        // Paint the text
        p.setPen((colour.lightness() > 64) ? Qt::black : Qt::white);
-       p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, text);
+       p.drawText(label_rect, Qt::AlignCenter | Qt::AlignVCenter, _name);
 }
 
 } // namespace pv
index 2351a2f911256c0a591c953a6d7d9d63e1421848..1b2f5df92a7221813e0dbb6afbdb7de74eac172c 100644 (file)
@@ -52,6 +52,14 @@ public:
        virtual void paint(QPainter &p, const QRect &rect, double scale,
                double offset) = 0;
 
+       /**
+        * Computes the outline rectangle of a label.
+        * @param p the QPainter to lay out text with.
+        * @param rect The rectangle of the signal header.
+        * @return Returns the rectangle of the signal label.
+        */
+       virtual QRectF get_label_rect(QPainter &p, const QRect &rect);
+       
        /**
         * Paints the signal label into a QGLWidget.
         * @param p the QPainter to paint into.