1 /* 2 * Frequency controller widget (originally from CuteSDR) 3 */ 4 #pragma once 5 6 #include <QFrame> 7 #include <QImage> 8 #include <QtGui> 9 10 enum FctlUnit { 11 FCTL_UNIT_NONE, // Freq displayed without unit: 14.236.000 12 FCTL_UNIT_HZ, 13 FCTL_UNIT_KHZ, 14 FCTL_UNIT_MHZ, 15 FCTL_UNIT_GHZ, 16 FCTL_UNIT_SEC, 17 FCTL_UNIT_MSEC, 18 FCTL_UNIT_USEC, 19 FCTL_UNIT_NSEC 20 }; 21 22 #define FCTL_MAX_DIGITS 12 23 #define FCTL_MIN_DIGITS 4 24 25 class CFreqCtrl : public QFrame 26 { 27 Q_OBJECT 28 29 public: 30 explicit CFreqCtrl(QWidget *parent = 0); 31 ~CFreqCtrl(); 32 33 QSize minimumSizeHint() const; 34 QSize sizeHint() const; 35 36 // Use NumDigits=0 for auto 37 void setup(int NumDigits, qint64 Minf, qint64 Maxf, int MinStep, 38 FctlUnit unit); 39 void setUnit(FctlUnit unit); 40 void setDigitColor(QColor col); 41 void setBgColor(QColor col); 42 void setUnitsColor(QColor col); 43 void setHighlightColor(QColor col); getFrequency()44 qint64 getFrequency() const 45 { 46 return m_freq; 47 } 48 setResetLowerDigits(bool reset)49 void setResetLowerDigits(bool reset) 50 { 51 m_ResetLowerDigits = reset; 52 } 53 setInvertScrolling(bool invert)54 void setInvertScrolling(bool invert) 55 { 56 m_InvertScrolling = invert; 57 } 58 59 signals: 60 void newFrequency(qint64 freq); // emitted when frequency has changed 61 62 public slots: 63 void setFrequency(qint64 freq); 64 void setFrequencyFocus(); 65 66 protected: 67 void paintEvent(QPaintEvent *); 68 void resizeEvent(QResizeEvent *); 69 void mouseMoveEvent(QMouseEvent *); 70 void mousePressEvent(QMouseEvent *); 71 void wheelEvent(QWheelEvent *); 72 void leaveEvent(QEvent *); 73 void keyPressEvent(QKeyEvent *); 74 75 private: 76 void updateCtrl(bool all); 77 void drawBkGround(QPainter &Painter); 78 void drawDigits(QPainter &Painter); 79 void incDigit(); 80 void decDigit(); 81 void incFreq(); 82 void decFreq(); 83 void clearFreq(); 84 void cursorHome(); 85 void cursorEnd(); 86 void moveCursorLeft(); 87 void moveCursorRight(); 88 bool inRect(QRect &rect, QPoint &point); 89 90 bool m_UpdateAll; 91 bool m_ExternalKeyActive; 92 bool m_LRMouseFreqSel; /* Use left/right mouse buttons. If FALSE click area determines up/down. */ 93 94 bool m_ResetLowerDigits; /* If TRUE digits below the active one will be reset to 0 95 * when the active digit is incremented or decremented. */ 96 bool m_InvertScrolling; 97 98 int m_FirstEditableDigit; 99 int m_LastLeadZeroPos; 100 int m_LeadZeroPos; 101 int m_NumDigits; 102 int m_NumDigitsForUnit; // number of digits allocated for unit (kHz, MHz, ...) 103 int m_DigStart; 104 int m_ActiveEditDigit; 105 int m_LastEditDigit; 106 int m_DecPos; 107 int m_NumSeps; 108 109 qint64 m_MinStep; 110 qint64 m_freq; 111 qint64 m_Oldfreq; 112 qint64 m_MinFreq; 113 qint64 m_MaxFreq; 114 115 QColor m_DigitColor; 116 QColor m_BkColor; 117 QColor m_InactiveColor; 118 QColor m_UnitsColor; 119 QColor m_HighlightColor; 120 121 QPixmap m_Pixmap; 122 QSize m_Size; 123 FctlUnit m_Unit; 124 125 QRect m_rectCtrl; // main control rectangle 126 QRect m_UnitsRect; // rectangle where Units text goes 127 QRect m_SepRect[FCTL_MAX_DIGITS]; // separation rectangles for commas, decimal point, etc. 128 129 QString m_UnitString; 130 131 QFont m_DigitFont; 132 QFont m_UnitsFont; 133 134 struct DigStuct { 135 qint64 weight; // decimal weight of this digit 136 qint64 incval; // value this digit increments or decrements 137 QRect dQRect; // Digit bounding rectangle 138 int val; // value of this digit(0-9) 139 bool modified; // set if this digit has been modified 140 bool editmode; // set if this digit is selected for editing 141 } m_DigitInfo[FCTL_MAX_DIGITS]; 142 }; 143