diff --git a/DSView/pv/dock/measuredock.cpp b/DSView/pv/dock/measuredock.cpp index 460c975e..381b078f 100644 --- a/DSView/pv/dock/measuredock.cpp +++ b/DSView/pv/dock/measuredock.cpp @@ -723,8 +723,8 @@ void MeasureDock::set_cursor_btn_color(QPushButton *btn) QColor bkColor = AppConfig::Instance().GetStyleColor(); bool isCursor = false; - const unsigned int start = btn->text().toInt(&isCursor) - 1; - QColor cursor_color = isCursor ? view::Ruler::CursorColorTable[start%CURSOR_COLOR_TABLE_SIZE] : bkColor; + const unsigned int start = btn->text().toInt(&isCursor); + QColor cursor_color = isCursor ? view::Ruler::GetColorByCursorOrder(start) : bkColor; set_cursor_btn_color(btn, cursor_color, bkColor, isCursor); } diff --git a/DSView/pv/view/cursor.cpp b/DSView/pv/view/cursor.cpp index 46ba8bfc..7ec7647a 100644 --- a/DSView/pv/view/cursor.cpp +++ b/DSView/pv/view/cursor.cpp @@ -33,6 +33,7 @@ #include #include #include "../dsvdef.h" +#include "ruler.h" namespace pv { namespace view { @@ -41,17 +42,14 @@ const QColor Cursor::LineColour(32, 74, 135); const QColor Cursor::FillColour(52, 101, 164); const QColor Cursor::HighlightColour(83, 130, 186); const QColor Cursor::TextColour(Qt::white); - const int Cursor::Offset = 1; - const int Cursor::ArrowSize = 10; - const int Cursor::CloseSize = 10; -Cursor::Cursor(View &view, QColor color, uint64_t index) : - TimeMarker(view, color, index), - _other(*this) +Cursor::Cursor(View &view, int order, uint64_t sampleIndex) : + TimeMarker(view, sampleIndex) { + _order = _order; } QRect Cursor::get_label_rect(const QRect &rect, bool &visible, bool has_hoff) @@ -82,10 +80,8 @@ QRect Cursor::get_close_rect(const QRect &rect) } void Cursor::paint_label(QPainter &p, const QRect &rect, - unsigned int prefix, int index, bool has_hoff) + unsigned int prefix, bool has_hoff) { - assert(index > 0); - using pv::view::Ruler; bool visible; @@ -98,11 +94,11 @@ void Cursor::paint_label(QPainter &p, const QRect &rect, p.setPen(Qt::transparent); if (close.contains(QPoint(_view.hover_point().x(), _view.hover_point().y()))) - p.setBrush(Ruler::CursorColorTable[(index - 1) % CURSOR_COLOR_TABLE_SIZE]); + p.setBrush(Ruler::GetColorByCursorOrder(_order)); else if (r.contains(QPoint(_view.hover_point().x(), _view.hover_point().y()))) p.setBrush(View::Orange); else - p.setBrush(Ruler::CursorColorTable[(index - 1) % CURSOR_COLOR_TABLE_SIZE]); + p.setBrush(Ruler::GetColorByCursorOrder(_order)); p.drawRect(r); @@ -126,7 +122,7 @@ void Cursor::paint_label(QPainter &p, const QRect &rect, Ruler::format_real_time(_index, _view.session().cur_snap_samplerate())); const QRect arrowRect = QRect(r.bottomLeft().x(), r.bottomLeft().y(), r.width(), ArrowSize); - p.drawText(arrowRect, Qt::AlignCenter | Qt::AlignVCenter, QString::number(index)); + p.drawText(arrowRect, Qt::AlignCenter | Qt::AlignVCenter, QString::number(_order)); } void Cursor::paint_fix_label(QPainter &p, const QRect &rect, diff --git a/DSView/pv/view/cursor.h b/DSView/pv/view/cursor.h index b01f53c2..f2c63522 100644 --- a/DSView/pv/view/cursor.h +++ b/DSView/pv/view/cursor.h @@ -44,9 +44,7 @@ public: static const QColor FillColour; static const QColor HighlightColour; static const QColor TextColour; - static const int Offset; - static const int ArrowSize; static const int CloseSize; @@ -57,7 +55,7 @@ public: * @param time The time to set the flag to. * @param other A reference to the other cursor. */ - Cursor(View &view, QColor color, uint64_t index); + Cursor(View &view, int order, uint64_t sampleIndex); public: @@ -77,7 +75,7 @@ public: * @param prefix The index of the SI prefix to use. */ void paint_label(QPainter &p, const QRect &rect, - unsigned int prefix, int index, bool has_hoff); + unsigned int prefix, bool has_hoff); void paint_fix_label(QPainter &p, const QRect &rect, unsigned int prefix, QChar label, QColor color, bool has_hoff); @@ -87,8 +85,7 @@ public: return (uint64_t)this; } - inline uint64_t get_index() - { + inline uint64_t get_index(){ return _index; } @@ -96,7 +93,6 @@ private: void compute_text_size(QPainter &p, unsigned int prefix); private: - const Cursor &_other; QSizeF _text_size; }; diff --git a/DSView/pv/view/ruler.cpp b/DSView/pv/view/ruler.cpp index 1307813f..61b9353d 100644 --- a/DSView/pv/view/ruler.cpp +++ b/DSView/pv/view/ruler.cpp @@ -21,22 +21,19 @@ */ #include "ruler.h" - +#include +#include +#include +#include +#include +#include +#include #include "cursor.h" #include "view.h" #include "viewport.h" #include "../sigsession.h" #include "dsosignal.h" #include "../dsvdef.h" - -#include -#include -#include -#include - -#include -#include -#include #include "../appcontrol.h" #include "../config/appconfig.h" #include "../ui/fn.h" @@ -63,31 +60,30 @@ const int Ruler::HoverArrowSize = 4; const int Ruler::CursorSelWidth = 20; -const QColor Ruler::CursorColorTable[CURSOR_COLOR_TABLE_SIZE] = - { - QColor(154,205,50, 250), //YellowGreen - QColor(0xf1,0x5b,0x6c, 250), // - // QColor(245,222,179, 250), //Wheat - QColor(208,32,144, 250), //VioletRed - QColor(255,99,71, 250), //Tomato - QColor(0,128,128, 250), //Teal - QColor(70,130,180, 250), //SteelBlue - QColor(106,90,205, 250),//SlateBlue - QColor(160,82,45, 250), //Sienna - QColor(46,139,87, 250), //SeaGreen - QColor(128,0,128, 250), //Purple - // QColor(127,255,0, 250), //Chartreuse - QColor(0,0,255, 250), //Blue - QColor(220,20,60, 250), //Crimson - QColor(184,134,11, 250), //DarkGoldenRod - QColor(139,0,139, 250), //DarkMagenta - QColor(255,20,147, 250), //DeepPink - QColor(34,139,34, 250), //ForestGreen - //QColor(0,0,128, 250), //Navy - QColor(255,0,255, 250), //Fuchsia - QColor(255,127,80, 250), //Coral - QColor(255,69,0, 250), //OrangeRed - }; +const int Ruler::CursorHsbColorTable[CURSOR_HSB_COLOR_TABLE_LENGTH] = { + 120, + 195, + 270, + 345, + 60, //5 + 135, + 210, + 285, + 15, + 75, //10 + 150, + 225, + 300, + 30, + 90, //15 + 165, + 240, + 315, + 45, + 105, //20 + 180, + 255, +}; Ruler::Ruler(View &parent) : QWidget(&parent), @@ -105,6 +101,18 @@ Ruler::Ruler(View &parent) : this, SLOT(hover_point_changed())); } +QColor Ruler::GetColorByCursorOrder(int order) +{ + assert(order > 0); + + int hsv = CursorHsbColorTable[(order - 1) % CURSOR_HSB_COLOR_TABLE_LENGTH]; + QColor color; + + int b = AppConfig::Instance().IsDarkStyle() ? 200 : 200; + color.setHsv(hsv, 200, b, 180); + return color; +} + QString Ruler::format_freq(double period, unsigned int precision) { if (period <= 0) { @@ -331,7 +339,7 @@ void Ruler::mouseReleaseEvent(QMouseEvent *event) overCursor = in_cursor_sel_rect(event->pos()); if (overCursor == 0) { - _view.add_cursor(CursorColorTable[cursor_list.size() % CURSOR_COLOR_TABLE_SIZE], index); + _view.add_cursor(index); _view.show_cursors(true); updatedCursor = true; } @@ -387,7 +395,7 @@ void Ruler::mouseReleaseEvent(QMouseEvent *event) auto i = cursor_list.begin(); while (--overCursor != 0){ - i++; + i++; } _view.del_cursor(*i); @@ -401,9 +409,8 @@ void Ruler::mouseReleaseEvent(QMouseEvent *event) } update(); + if (updatedCursor) { - //const QRect reDrawRect = QRect(_cursor_sel_x - 1, 0, 3, _view.viewport()->height()); - //_view.viewport()->update(reDrawRect); _view.viewport()->update(); } } @@ -518,23 +525,29 @@ void Ruler::draw_logic_tick_mark(QPainter &p) // Draw the cursors auto &cursor_list = _view.get_cursorList(); + bool bWorkStoped = _view.session().is_stopped_status(); + + for (auto cursor : cursor_list) + { + cursor->paint_label(p, rect(), prefix, bWorkStoped); + } if (cursor_list.size()) { auto i = cursor_list.begin(); int index = 1; while (i != cursor_list.end()) { - (*i)->paint_label(p, rect(), prefix, index, _view.session().is_stopped_status()); + (*i)->paint_label(p, rect(), prefix, bWorkStoped); index++; i++; } } if (_view.trig_cursor_shown()) { - _view.get_trig_cursor()->paint_fix_label(p, rect(), prefix, 'T', _view.get_trig_cursor()->colour(), false); + _view.get_trig_cursor()->paint_fix_label(p, rect(), prefix, 'T', _view.get_trig_cursor()->get_color(), false); } if (_view.search_cursor_shown()) { - _view.get_search_cursor()->paint_fix_label(p, rect(), prefix, 'S', _view.get_search_cursor()->colour(), true); + _view.get_search_cursor()->paint_fix_label(p, rect(), prefix, 'S', _view.get_search_cursor()->get_color(), true); } } @@ -639,21 +652,18 @@ void Ruler::draw_osc_tick_mark(QPainter &p) auto &cursor_list = _view.get_cursorList(); if (!cursor_list.empty()) { - auto i = cursor_list.begin(); - int index = 1; + bool bWorkStoped = _view.session().is_stopped_status(); - while (i != cursor_list.end()) { - (*i)->paint_label(p, rect(), prefix, index, _view.session().is_stopped_status()); - index++; - i++; + for (auto cursor : cursor_list) { + cursor->paint_label(p, rect(), prefix, bWorkStoped); } } if (_view.trig_cursor_shown()) { - _view.get_trig_cursor()->paint_fix_label(p, rect(), prefix, 'T', _view.get_trig_cursor()->colour(), false); + _view.get_trig_cursor()->paint_fix_label(p, rect(), prefix, 'T', _view.get_trig_cursor()->get_color(), false); } if (_view.search_cursor_shown()) { - _view.get_search_cursor()->paint_fix_label(p, rect(), prefix, 'S', _view.get_search_cursor()->colour(), true); + _view.get_search_cursor()->paint_fix_label(p, rect(), prefix, 'S', _view.get_search_cursor()->get_color(), true); } } @@ -710,7 +720,7 @@ void Ruler::draw_cursor_sel(QPainter &p) int index = 1; auto i = cursor_list.begin(); - while (i != cursor_list.end()) { + for (auto curosr : cursor_list) { const QRectF cursorRect = get_cursor_sel_rect(index); p.setPen(QPen(Qt::black, 1, Qt::DotLine)); p.drawLine(cursorRect.left(), cursorRect.top() + 3, @@ -720,13 +730,12 @@ void Ruler::draw_cursor_sel(QPainter &p) if (in_cursor_sel_rect(pos) == index) p.setBrush(View::Orange); else - p.setBrush(CursorColorTable[(index - 1)%CURSOR_COLOR_TABLE_SIZE]); + p.setBrush(curosr->get_color()); p.drawRect(cursorRect); p.setPen(Qt::black); p.drawText(cursorRect, Qt::AlignCenter | Qt::AlignVCenter, QString::number(index)); index++; - i++; } } } diff --git a/DSView/pv/view/ruler.h b/DSView/pv/view/ruler.h index c5d521d5..e2b83552 100644 --- a/DSView/pv/view/ruler.h +++ b/DSView/pv/view/ruler.h @@ -27,7 +27,7 @@ #include #include -#define CURSOR_COLOR_TABLE_SIZE 19 +#define CURSOR_HSB_COLOR_TABLE_LENGTH 22 namespace pv { namespace view { @@ -45,17 +45,17 @@ private: static const int MinorTickSubdivision; static const int ScaleUnits[3]; static const int MinPeriodScale; - static const QString SIPrefixes[9]; static const QString FreqPrefixes[9]; static const int FirstSIPrefixPower; static const int pricision; - static const int HoverArrowSize; static const int CursorSelWidth; + static const int CursorHsbColorTable[CURSOR_HSB_COLOR_TABLE_LENGTH]; + public: - static const QColor CursorColorTable[CURSOR_COLOR_TABLE_SIZE]; + static QColor GetColorByCursorOrder(int order); public: Ruler(View &parent); diff --git a/DSView/pv/view/timemarker.cpp b/DSView/pv/view/timemarker.cpp index 2fba38f2..e34231a7 100644 --- a/DSView/pv/view/timemarker.cpp +++ b/DSView/pv/view/timemarker.cpp @@ -21,22 +21,22 @@ */ #include "timemarker.h" - +#include #include "view.h" #include "ruler.h" -#include namespace pv { namespace view { -TimeMarker::TimeMarker(View &view, QColor &colour, +TimeMarker::TimeMarker(View &view, uint64_t index) : _view(view), _index(index), - _grabbed(false), - _colour(colour) + _grabbed(false) { + _colour = Qt::blue; + _order = -1; } TimeMarker::TimeMarker(const TimeMarker &s) : @@ -45,11 +45,7 @@ TimeMarker::TimeMarker(const TimeMarker &s) : _index(s._index), _colour(s._colour) { -} -QColor TimeMarker::colour() -{ - return _colour; } void TimeMarker::set_colour(QColor color) @@ -57,6 +53,14 @@ void TimeMarker::set_colour(QColor color) _colour = color; } +QColor TimeMarker::get_color() +{ + if (_order > 0){ + return Ruler::GetColorByCursorOrder(_order); + } + return _colour; +} + bool TimeMarker::grabbed() { return _grabbed; @@ -81,11 +85,11 @@ void TimeMarker::set_index(int64_t index) time_changed(); } -void TimeMarker::paint(QPainter &p, const QRect &rect, const bool highlight, int order, bool trig_hoff) +void TimeMarker::paint(QPainter &p, const QRect &rect, const bool highlight, bool trig_hoff) { const int64_t x = _view.index2pixel(_index, trig_hoff); if (x <= rect.right()) { - QColor color = (order == -1) ? _colour : Ruler::CursorColorTable[order%CURSOR_COLOR_TABLE_SIZE]; + QColor color = (_order < 1) ? _colour : Ruler::GetColorByCursorOrder(_order); p.setPen((_grabbed | highlight) ? QPen(color.lighter(), 2, Qt::DashLine) : QPen(color, 1, Qt::DashLine)); p.drawLine(QPoint(x, 0), QPoint(x, rect.bottom())); } diff --git a/DSView/pv/view/timemarker.h b/DSView/pv/view/timemarker.h index 7cbe8136..88f894ab 100644 --- a/DSView/pv/view/timemarker.h +++ b/DSView/pv/view/timemarker.h @@ -49,7 +49,7 @@ protected: * @param colour A reference to the colour of this cursor. * @param time The time to set the flag to. */ - TimeMarker(View &view, QColor &colour, uint64_t index); + TimeMarker(View &view, uint64_t index); /** * Copy constructor @@ -71,7 +71,8 @@ public: /** * Gets/Sets colour of the marker */ - QColor colour(); + QColor get_color(); + void set_colour(QColor color); /* @@ -85,7 +86,7 @@ public: * @param p The painter to draw with. * @param rect The rectangle of the viewport client area. */ - virtual void paint(QPainter &p, const QRect &rect, const bool highlight, int order, bool trig_hoff = true); + virtual void paint(QPainter &p, const QRect &rect, const bool highlight, bool trig_hoff = true); /** * Gets the marker label rectangle. @@ -102,7 +103,16 @@ public: * @param prefix The SI prefix to paint time value with. */ virtual void paint_label(QPainter &p, const QRect &rect, - unsigned int prefix, int index, bool has_hoff) = 0; + unsigned int prefix, bool has_hoff) = 0; + + inline void set_order(int order){ + assert( order > 0); + _order = order; + } + + inline int order(){ + return _order; + } signals: void time_changed(); @@ -116,7 +126,10 @@ protected: private: bool _grabbed; - QColor _colour; + +protected: + QColor _colour; + int _order; }; } // namespace view diff --git a/DSView/pv/view/view.cpp b/DSView/pv/view/view.cpp index 74a141c7..e74b039d 100644 --- a/DSView/pv/view/view.cpp +++ b/DSView/pv/view/view.cpp @@ -181,10 +181,12 @@ View::View(SigSession *session, pv::toolbars::SamplingBar *sampling_bar, QWidget fore.setAlpha(View::BackAlpha); _show_trig_cursor = false; - _trig_cursor = new Cursor(*this, View::LightRed, 0); + _trig_cursor = new Cursor(*this, -1, 0); + _trig_cursor->set_colour(View::LightRed); _show_search_cursor = false; _search_pos = 0; - _search_cursor = new Cursor(*this, fore, _search_pos); + _search_cursor = new Cursor(*this, -1, _search_pos); + _search_cursor->set_colour(fore); _cali = new pv::dialogs::Calibration(this); _cali->hide(); @@ -1010,19 +1012,37 @@ void View::on_traces_moved() viewport_update(); } -void View::add_cursor(QColor color, uint64_t index) +void View::make_cursors_order() { - Cursor *newCursor = new Cursor(*this, color, index); + int dex = 1; + + for (auto cursor : get_cursorList()) + { + cursor->set_order(dex++); + } + + dex = 1; + for (auto cursor : get_xcursorList()) + { + cursor->set_order(dex++); + } +} + +void View::add_cursor(QColor color, uint64_t sampleIndex) +{ + Cursor *newCursor = new Cursor(*this, -1, sampleIndex); get_cursorList().push_back(newCursor); + make_cursors_order(); cursor_update(); } -void View::add_cursor(uint64_t index) +void View::add_cursor(uint64_t sampleIndex) { - static int addIndex = 0; - QColor color = view::Ruler::CursorColorTable[addIndex%CURSOR_COLOR_TABLE_SIZE]; - add_cursor(color, index); - addIndex++; + static int lastOrder = 1; + Cursor *newCursor = new Cursor(*this, lastOrder++, sampleIndex); + get_cursorList().push_back(newCursor); + make_cursors_order(); + cursor_update(); } void View::del_cursor(Cursor* cursor) @@ -1031,6 +1051,8 @@ void View::del_cursor(Cursor* cursor) get_cursorList().remove(cursor); delete cursor; + make_cursors_order(); + cursor_update(); } @@ -1044,6 +1066,25 @@ void View::clear_cursors() lst.clear(); } +void View::add_xcursor(double value0, double value1) +{ + static int lastXCursorOrder = 1; + XCursor *newXCursor = new XCursor(*this, lastXCursorOrder++, value0, value1); + _xcursorList.push_back(newXCursor); + make_cursors_order(); + xcursor_update(); +} + +void View::del_xcursor(XCursor* xcursor) +{ + assert(xcursor); + + _xcursorList.remove(xcursor); + delete xcursor; + make_cursors_order(); + xcursor_update(); +} + void View::set_cursor_middle(int index) { auto &lst = get_cursorList(); @@ -1332,22 +1373,6 @@ bool View::get_dso_trig_moved() return _time_viewport->get_dso_trig_moved(); } -void View::add_xcursor(QColor color, double value0, double value1) -{ - XCursor *newXCursor = new XCursor(*this, color, value0, value1); - _xcursorList.push_back(newXCursor); - xcursor_update(); -} - -void View::del_xcursor(XCursor* xcursor) -{ - assert(xcursor); - - _xcursorList.remove(xcursor); - delete xcursor; - xcursor_update(); -} - double View::index2pixel(uint64_t index, bool has_hoff) { const double samples_per_pixel = session().cur_snap_samplerate() * scale(); diff --git a/DSView/pv/view/view.h b/DSView/pv/view/view.h index 73043272..f77a2389 100644 --- a/DSView/pv/view/view.h +++ b/DSView/pv/view/view.h @@ -219,9 +219,12 @@ public: */ std::list& get_cursorList(); - void add_cursor(QColor color, uint64_t index); - void add_cursor(uint64_t index); + void add_cursor(QColor color, uint64_t sampleIndex); + void add_cursor(uint64_t sampleIndex); void del_cursor(Cursor* cursor); + void add_xcursor(double value0, double value1); + void del_xcursor(XCursor* xcursor); + void clear_cursors(); void set_cursor_middle(int index); @@ -261,9 +264,6 @@ public: inline std::list& get_xcursorList(){ return _xcursorList; } - - void add_xcursor(QColor color, double value0, double value1); - void del_xcursor(XCursor* xcursor); void set_update(Viewport *viewport, bool need_update); void set_all_update(bool need_update); @@ -420,6 +420,7 @@ private slots: private: void set_trig_cursor_posistion(uint64_t percent); + void make_cursors_order(); public: void show_wait_trigger(); @@ -429,7 +430,6 @@ public: int get_body_height(); private: - SigSession *_session; pv::toolbars::SamplingBar *_sampling_bar; diff --git a/DSView/pv/view/viewport.cpp b/DSView/pv/view/viewport.cpp index 8aa5b1ae..428156e5 100644 --- a/DSView/pv/view/viewport.cpp +++ b/DSView/pv/view/viewport.cpp @@ -250,18 +250,14 @@ void Viewport::paintCursors(QPainter &p) auto &cursor_list = _view.get_cursorList(); if (_view.cursors_shown() && _type == TIME_VIEW) { - auto i = cursor_list.begin(); - int index = 0; - while (i != cursor_list.end()) { - const int64_t cursorX = _view.index2pixel((*i)->index()); + for (auto cursor : cursor_list) { + const int64_t cursorX = _view.index2pixel(cursor->index()); if (xrect.contains(_view.hover_point().x(), _view.hover_point().y()) && qAbs(cursorX - _view.hover_point().x()) <= HitCursorMargin) - (*i)->paint(p, xrect, 1, index, _view.session().is_stopped_status()); + cursor->paint(p, xrect, 1, _view.session().is_stopped_status()); else - (*i)->paint(p, xrect, 0, index, _view.session().is_stopped_status()); - i++; - index++; + cursor->paint(p, xrect, 0, _view.session().is_stopped_status()); } } } @@ -354,30 +350,30 @@ void Viewport::paintSignals(QPainter &p, QColor fore, QColor back) if (!hovered && ((*i)->get_close_rect(xrect).contains(_view.hover_point()) || (*i)->get_map_rect(xrect).contains(_view.hover_point()))) { - (*i)->paint(p, xrect, XCursor::XCur_All, index); + (*i)->paint(p, xrect, XCursor::XCur_All); hovered = true; } else if(!hovered && xrect.contains(_view.hover_point())) { if (qAbs(cursorX - _view.hover_point().x()) <= HitCursorMargin && _view.hover_point().y() > min(cursorY0, cursorY1) && _view.hover_point().y() < max(cursorY0, cursorY1)) { - (*i)->paint(p, xrect, XCursor::XCur_Y, index); + (*i)->paint(p, xrect, XCursor::XCur_Y); hovered = true; } else if (qAbs(cursorY0 - _view.hover_point().y()) <= HitCursorMargin) { - (*i)->paint(p, xrect, XCursor::XCur_X0, index); + (*i)->paint(p, xrect, XCursor::XCur_X0); hovered = true; } else if (qAbs(cursorY1 - _view.hover_point().y()) <= HitCursorMargin) { - (*i)->paint(p, xrect, XCursor::XCur_X1, index); + (*i)->paint(p, xrect, XCursor::XCur_X1); hovered = true; } else { - (*i)->paint(p, xrect, XCursor::XCur_None, index); + (*i)->paint(p, xrect, XCursor::XCur_None); } } else { - (*i)->paint(p, xrect, XCursor::XCur_None, index); + (*i)->paint(p, xrect, XCursor::XCur_None); } i++; @@ -387,7 +383,7 @@ void Viewport::paintSignals(QPainter &p, QColor fore, QColor back) if (_type == TIME_VIEW) { if (_view.trig_cursor_shown()) { - _view.get_trig_cursor()->paint(p, xrect, 0, -1, false); + _view.get_trig_cursor()->paint(p, xrect, 0, false); } if (_view.search_cursor_shown()) { const int64_t searchX = _view.index2pixel(_view.get_search_cursor()->index()); @@ -1277,7 +1273,7 @@ void Viewport::mouseDoubleClickEvent(QMouseEvent *event) } auto &cursor_list = _view.get_cursorList(); - _view.add_cursor(view::Ruler::CursorColorTable[cursor_list.size() % CURSOR_COLOR_TABLE_SIZE], index); + _view.add_cursor(index); _view.show_cursors(true); } @@ -1300,13 +1296,14 @@ void Viewport::mouseDoubleClickEvent(QMouseEvent *event) break; } } - } else if (_view.session().get_device()->get_work_mode() == ANALOG) { + } + else if (_view.session().get_device()->get_work_mode() == ANALOG) { if (event->button() == Qt::LeftButton) { uint64_t index; const double curX = event->pos().x(); index = _view.pixel2index(curX); auto &cursor_list = _view.get_cursorList(); - _view.add_cursor(view::Ruler::CursorColorTable[cursor_list.size() % CURSOR_COLOR_TABLE_SIZE], index); + _view.add_cursor(index); _view.show_cursors(true); } } @@ -2117,18 +2114,15 @@ void Viewport::show_contextmenu(const QPoint& pos) void Viewport::add_cursor_y() { uint64_t index; - //const double curX = _menu_pos.x(); - index = _view.pixel2index(_cur_preX); - auto &cursor_list = _view.get_cursorList(); - _view.add_cursor(view::Ruler::CursorColorTable[cursor_list.size() % CURSOR_COLOR_TABLE_SIZE], index); + index = _view.pixel2index(_cur_preX); + _view.add_cursor(index); _view.show_cursors(true); } void Viewport::add_cursor_x() { - double ypos = (_cur_preY - _view.get_view_rect().top()) * 1.0 / _view.get_view_height(); - auto &cursor_list = _view.get_cursorList(); - _view.add_xcursor(view::Ruler::CursorColorTable[cursor_list.size() % CURSOR_COLOR_TABLE_SIZE], ypos, ypos); + double ypos = (_cur_preY - _view.get_view_rect().top()) * 1.0 / _view.get_view_height(); + _view.add_xcursor(ypos, ypos); _view.show_xcursors(true); } diff --git a/DSView/pv/view/xcursor.cpp b/DSView/pv/view/xcursor.cpp index 904a88c9..0efc759e 100644 --- a/DSView/pv/view/xcursor.cpp +++ b/DSView/pv/view/xcursor.cpp @@ -21,30 +21,29 @@ */ #include "xcursor.h" - +#include #include "view.h" #include "ruler.h" #include "dsosignal.h" #include "../log.h" - -#include +#include "ruler.h" using namespace std; namespace pv { namespace view { -XCursor::XCursor(View &view, QColor &colour, - double value0, double value1) : +XCursor::XCursor(View &view, int order, double value0, double value1) : _view(view), _yvalue(0.5), _value0(value0), _value1(value1), _grabbed(XCur_None), - _colour(colour) + _order(order) { _dsoSig = NULL; _sig_index = -1; + _colour = Qt::blue; for(auto s : _view.session().get_signals()) { if (s->signal_type() == SR_CHANNEL_DSO){ @@ -82,7 +81,7 @@ XCursor::XCursor(const XCursor &x) : QColor XCursor::colour() { - return _colour; + return get_color(); } void XCursor::set_colour(QColor color) @@ -156,7 +155,7 @@ void XCursor::set_value(XCur_type type, double value) value_changed(); } -void XCursor::paint(QPainter &p, const QRect &rect, XCur_type highlight, int order) +void XCursor::paint(QPainter &p, const QRect &rect, XCur_type highlight) { // Attach the channel if (_dsoSig == NULL && _sig_index != -1){ @@ -174,7 +173,7 @@ void XCursor::paint(QPainter &p, const QRect &rect, XCur_type highlight, int or const int x = rect.left() + _yvalue * rect.width(); const int y0 = rect.top() + _value0 * rect.height(); const int y1 = rect.top() + _value1 * rect.height(); - QColor color = (order == -1) ? _colour : Ruler::CursorColorTable[order%CURSOR_COLOR_TABLE_SIZE]; + QColor color = get_color(); const bool hit0 = (_grabbed == XCur_X0) | (_grabbed == XCur_None && (highlight == XCur_X0 || highlight == XCur_All)); p.setPen(hit0 ? QPen(color.lighter(), 2, Qt::DashLine) : QPen(color, 1, Qt::DashLine)); p.drawLine(QPoint(0, y0), QPoint(rect.right()-_v0_size.width(), y0)); @@ -270,5 +269,13 @@ void XCursor::paint_label(QPainter &p, const QRect &rect) p.drawLine(close.left() + 2, close.bottom() - 2, close.right() - 2, close.top() + 2); } +QColor XCursor::get_color() +{ + if (_order > 0){ + return Ruler::GetColorByCursorOrder(_order); + } + return _colour; +} + } // namespace view } // namespace pv diff --git a/DSView/pv/view/xcursor.h b/DSView/pv/view/xcursor.h index 96f2b892..0e336e2c 100644 --- a/DSView/pv/view/xcursor.h +++ b/DSView/pv/view/xcursor.h @@ -60,7 +60,7 @@ public: * @param value0 * @param value1 */ - XCursor(View &view, QColor &colour, double value0, double value1); + XCursor(View &view, int order, double value0, double value1); /** * Copy constructor @@ -78,8 +78,20 @@ public: * Gets/Sets colour of the marker */ QColor colour(); + + QColor get_color(); + void set_colour(QColor color); + inline void set_order(int order){ + assert( order > 0); + _order = order; + } + + inline int order(){ + return _order; + } + /** * Gets/Sets the mapping channel of the marker */ @@ -98,7 +110,7 @@ public: * @param p The painter to draw with. * @param rect The rectangle of the viewport client area. */ - void paint(QPainter &p, const QRect &rect, enum XCur_type highlight, int order); + void paint(QPainter &p, const QRect &rect, enum XCur_type highlight); /** * Gets the map label rectangle. @@ -141,7 +153,8 @@ protected: private: enum XCur_type _grabbed; - QColor _colour; + QColor _colour; + int _order; }; } // namespace view