File indexing completed on 2024-06-16 08:27:25

0001 /***************************************************************************
0002  *   Copyright (C) 2005 by David Saxton                                    *
0003  *   david@bluehaze.org                                                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  ***************************************************************************/
0010 
0011 #ifndef PROBEPOSITIONER_H
0012 #define PROBEPOSITIONER_H
0013 
0014 #include <QMap>
0015 #include <QWidget>
0016 
0017 class ProbeData;
0018 typedef QMap<int, ProbeData *> ProbeDataMap;
0019 
0020 const float probeArrowWidth = 9;
0021 const float probeArrowHeight = 12;
0022 
0023 /**
0024 Widget for positioning the output of Probes in the OscilloscopeView
0025 @author David Saxton
0026 */
0027 class ProbePositioner : public QWidget
0028 {
0029     Q_OBJECT
0030 public:
0031     ProbePositioner(QWidget *parent = nullptr);
0032     ~ProbePositioner() override;
0033     /**
0034      * Returns the amount of space (height in pixels) that a probe output
0035      * takes up
0036      */
0037     int probeOutputHeight() const;
0038     /**
0039      * Returns the probe position (from the top) in pixels that the probe
0040      * with the given id should be displayed at, or -1 if probe with the
0041      * given id couldn't be found
0042      */
0043     int probePosition(ProbeData *probeData) const;
0044     /**
0045      * Sets the probe position relative to the top of this widget (and hence
0046      * relative to the top of the oscilloscope view) in pixels
0047      */
0048     void setProbePosition(ProbeData *probeData, int position);
0049     /**
0050      * Returns the probe at the given position (plus or minus an arrow),
0051      * or nullptr if none. Records the offset of the position from the mouse
0052      * in m_probePosOffset.
0053      */
0054     ProbeData *probeAtPosition(const QPoint &pos);
0055 
0056 public slots:
0057     void forceRepaint();
0058 
0059 protected slots:
0060     void slotProbeDataRegistered(int id, ProbeData *probe);
0061     void slotProbeDataUnregistered(int id);
0062 
0063 protected:
0064     void mousePressEvent(QMouseEvent *e) override;
0065     void mouseReleaseEvent(QMouseEvent *e) override;
0066     void mouseMoveEvent(QMouseEvent *e) override;
0067     void paintEvent(QPaintEvent *e) override;
0068     void resizeEvent(QResizeEvent *event) override;
0069 
0070     ProbeDataMap m_probeDataMap;
0071     ProbeData *p_draggedProbe;
0072     int m_probePosOffset;
0073 
0074     bool b_needRedraw;
0075     QPixmap *m_pixmap;
0076 };
0077 
0078 #endif