]> sigrok.org Git - pulseview.git/blobdiff - pv/views/trace/ruler.hpp
Trace View: Move ruler time conversion from View to Ruler
[pulseview.git] / pv / views / trace / ruler.hpp
index 40aae48daa3faed09cb258b49f02599d5f942e02..bfab766619d135c7d251a2863c7e9078c102ee81 100644 (file)
@@ -46,6 +46,17 @@ namespace trace {
 class TimeItem;
 class ViewItem;
 
+struct TickPositions
+{
+       vector<pair<double, QString>> major;
+       vector<double> minor;
+};
+
+/**
+ * The Ruler class manages and displays the time scale above the trace canvas.
+ * It may also contain @ref TimeItem instances used to identify or highlight
+ * time-related information.
+ */
 class Ruler : public MarginWidget
 {
        Q_OBJECT
@@ -58,15 +69,12 @@ private:
        /// Height of the ruler in multipes of the text height
        static const float RulerHeight;
 
-       static const int MinorTickSubdivision;
-
        /// Height of the hover arrow in multiples of the text height
        static const float HoverArrowSize;
 
 public:
        Ruler(View &parent);
 
-public:
        QSize sizeHint() const override;
 
        /**
@@ -109,6 +117,16 @@ public:
                unsigned precision = 0,
                bool sign = true);
 
+       pv::util::Timestamp get_absolute_time_from_x_pos(uint32_t x) const;
+       pv::util::Timestamp get_ruler_time_from_x_pos(uint32_t x) const;
+
+       pv::util::Timestamp get_ruler_time_from_absolute_time(const pv::util::Timestamp& abs_time) const;
+       pv::util::Timestamp get_absolute_time_from_ruler_time(const pv::util::Timestamp& ruler_time) const;
+
+protected:
+       virtual void contextMenuEvent(QContextMenuEvent *event) override;
+       void resizeEvent(QResizeEvent*) override;
+
 private:
        /**
         * Gets the time items.
@@ -123,10 +141,10 @@ private:
         */
        shared_ptr<ViewItem> get_mouse_over_item(const QPoint &pt) override;
 
-       void paintEvent(QPaintEvent *event) override;
-
        void mouseDoubleClickEvent(QMouseEvent *event) override;
 
+       void paintEvent(QPaintEvent *event) override;
+
        /**
         * Draw a hover arrow under the cursor position.
         * @param p The painter to draw into.
@@ -136,23 +154,11 @@ private:
 
        int calculate_text_height() const;
 
-       struct TickPositions
-       {
-               vector<pair<double, QString>> major;
-               vector<double> minor;
-       };
-
-       /**
-        * Holds the tick positions so that they don't have to be recalculated on
-        * every redraw. Set by 'paintEvent()' when needed.
-        */
-       boost::optional<TickPositions> tick_position_cache_;
-
        /**
         * Calculates the major and minor tick positions.
         *
         * @param major_period The period between the major ticks.
-        * @param offset The time at the left border of the ruler.
+        * @param offset The virtual time at the left border of the ruler.
         * @param scale The scale in seconds per pixel.
         * @param width the Width of the ruler.
         * @param format_function A function used to format the major tick times.
@@ -165,16 +171,26 @@ private:
                const pv::util::Timestamp& offset,
                const double scale,
                const int width,
+               const unsigned int minor_tick_count,
                function<QString(const pv::util::Timestamp&)> format_function);
 
-protected:
-       void resizeEvent(QResizeEvent*) override;
-
 private Q_SLOTS:
-       void hover_point_changed();
+       void on_hover_point_changed(const QWidget* widget, const QPoint &hp);
 
-       // Resets the 'tick_position_cache_'.
        void invalidate_tick_position_cache();
+
+       void on_createMarker();
+       void on_setZeroPosition();
+       void on_toggleHoverMarker();
+
+private:
+       /**
+        * Holds the tick positions so that they don't have to be recalculated on
+        * every redraw. Set by 'paintEvent()' when needed.
+        */
+       boost::optional<TickPositions> tick_position_cache_;
+
+       uint32_t context_menu_x_pos_;
 };
 
 } // namespace trace