File: freqctrl.h

package info (click to toggle)
gqrx-sdr 2.6-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,700 kB
  • ctags: 2,724
  • sloc: cpp: 22,413; ansic: 564; xml: 25; makefile: 4
file content (144 lines) | stat: -rw-r--r-- 4,276 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//////////////////////////////////////////////////////////////////////
// freqctrl.h: interface for the CFreqCtrl class.
//
// History:
//  2010-09-15  Initial creation MSW
//  2011-03-27  Initial release
/////////////////////////////////////////////////////////////////////
#ifndef FREQCTRL_H
#define FREQCTRL_H
///////////////////////////////////////////////////////////////////////
// To use this control, add a frame using the QT designer editor.
//  Promote it to the CFreqCtrl class and include file freqctrl.h
// Initilaize the control in the constructor of the controls parent
//  ex: ui->frameFreqCtrl->Setup(9, 10000U, 230000000U, 1, UNITS_MHZ );
// where 9 is the number of display digits, min freq is 10kHz , Max is 230MHz
// the minimum step size is 1Hz and the freq is displayed as MHz
//    NOTE: the frequency is a qint64  64 bit integer value
//  to change frequency call SetFrequency()
//  ex:  ui->frameFreqCtrl->SetFrequency(146000000);
//
// One signal is sent when the control frequency changes:
//void NewFrequency(qint64 freq);   //emitted when frequency has changed
///////////////////////////////////////////////////////////////////////

#include <QtGui>
#include <QFrame>
#include <QImage>

enum FUNITS
{
    UNITS_HZ,
    UNITS_KHZ,
    UNITS_MHZ,
    UNITS_GHZ,
    UNITS_SEC,
    UNITS_MSEC,
    UNITS_USEC,
    UNITS_NSEC
};

#define MAX_DIGITS 12
#define MIN_DIGITS 4

class CFreqCtrl : public QFrame
{
    Q_OBJECT
public:
    explicit CFreqCtrl(QWidget *parent = 0);
    ~CFreqCtrl();
    QSize minimumSizeHint() const;
    QSize sizeHint() const;

    //primary access routines
    void setup(int NumDigits, qint64 Minf, qint64 Maxf,int MinStep, FUNITS UnitsType);
    void setUnits(FUNITS units);
    void setDigitColor(QColor cr);
    void setBkColor(QColor cr);
    void setUnitsColor(QColor cr);
    void setHighlightColor(QColor cr);
    qint64 getFrequency() { return m_freq; }

signals:
    void newFrequency(qint64 freq); //emitted when frequency has changed

public slots:
    void setFrequency(qint64 freq);

protected:      //overrides for this control
    void paintEvent(QPaintEvent *);
    void resizeEvent(QResizeEvent *);
    void mouseMoveEvent(QMouseEvent *);
    void mousePressEvent(QMouseEvent *);
    void wheelEvent(QWheelEvent *);
    void leaveEvent(QEvent *);
    void keyPressEvent(QKeyEvent *);

private:
    void updateCtrl(bool all);
    void drawBkGround(QPainter &Painter);
    void drawDigits(QPainter &Painter);
    void incDigit();
    void decDigit();
    void incFreq();
    void decFreq();
    void clearFreq();
    void cursorHome();
    void cursorEnd();
    void moveCursorLeft();
    void moveCursorRight();
    bool inRect(QRect &rect, QPoint &point);

    bool m_UpdateAll;
    bool m_ExternalKeyActive;
    bool m_LRMouseFreqSel;    /*! Use left/right mouse buttons. If FALSE click area determines up/down. */

    bool m_ResetLowerDigits;  /*! If TRUE digits below the active one will be reset to 0
                                  when the active digit is incremented or decremented. */

    int m_FirstEditableDigit;
    int m_LastLeadZeroPos;
    int m_LeadZeroPos;
    int m_NumDigits;
    int m_DigStart;
    int m_ActiveEditDigit;
    int m_LastEditDigit;
    int m_DecPos;
    int m_NumSeps;

    qint64 m_MinStep;
    qint64 m_freq;
    qint64 m_Oldfreq;
    qint64 m_MinFreq;
    qint64 m_MaxFreq;

    QColor m_DigitColor;
    QColor m_BkColor;
    QColor m_UnitsColor;
    QColor m_HighlightColor;

    QPixmap m_Pixmap;
    QSize m_Size;
    FUNITS m_Units;

    QRect m_rectCtrl;               //main control rectangle
    QRect m_UnitsRect;              //rectangle where Units text goes
    QRect m_SepRect[MAX_DIGITS];    //separation rectangles for commas,dec pt, etc.

    QString m_UnitString;

    QFont m_DigitFont;
    QFont m_UnitsFont;

    struct DigStuct
    {
        qint64 weight;  //decimal weight of this digit
        qint64 incval;  //value this digit increments or decrements
        QRect dQRect;   //Digit bounding rectangle
        int val;    //value of this digit(0-9)
        bool modified;  //set if this digit has been modified
        bool editmode;  //set if this digit is selected for editing
    } m_DigitInfo[MAX_DIGITS];
};

#endif // FREQCTRL_H