From d5fb302e465046312d7a63adf940bb2c5ea9710e Mon Sep 17 00:00:00 2001 From: dreamsourcelabTAI Date: Mon, 8 Jan 2024 14:27:44 +0800 Subject: [PATCH] Extend the color talbe of cursor --- DSView/pv/dock/measuredock.cpp | 2 +- DSView/pv/view/cursor.cpp | 6 ++++-- DSView/pv/view/ruler.cpp | 39 ++++++++++++++++++++++++---------- DSView/pv/view/ruler.h | 4 +++- DSView/pv/view/timemarker.cpp | 2 +- DSView/pv/view/view.cpp | 8 +++++++ DSView/pv/view/view.h | 1 + DSView/pv/view/viewport.cpp | 10 ++++----- DSView/pv/view/xcursor.cpp | 2 +- 9 files changed, 52 insertions(+), 22 deletions(-) diff --git a/DSView/pv/dock/measuredock.cpp b/DSView/pv/dock/measuredock.cpp index 4fa44743..f4a8671b 100644 --- a/DSView/pv/dock/measuredock.cpp +++ b/DSView/pv/dock/measuredock.cpp @@ -672,7 +672,7 @@ void MeasureDock::set_cursor_btn_color(QPushButton *btn) { bool ret; const unsigned int start = btn->text().toInt(&ret) - 1; - QColor cursor_color = ret ? view::Ruler::CursorColor[start%8] : QColor("#302F2F"); + QColor cursor_color = ret ? view::Ruler::CursorColorTable[start%CURSOR_COLOR_TABLE_SIZE] : QColor("#302F2F"); QString border_width = ret ? "0px" : "1px"; QString normal = "{background-color:" + cursor_color.name() + "; color:black" + "; border-width:" + border_width + ";}"; diff --git a/DSView/pv/view/cursor.cpp b/DSView/pv/view/cursor.cpp index e9a11af5..46ba8bfc 100644 --- a/DSView/pv/view/cursor.cpp +++ b/DSView/pv/view/cursor.cpp @@ -96,12 +96,14 @@ void Cursor::paint_label(QPainter &p, const QRect &rect, const QRect close(get_close_rect(r)); p.setPen(Qt::transparent); + if (close.contains(QPoint(_view.hover_point().x(), _view.hover_point().y()))) - p.setBrush(Ruler::CursorColor[(index - 1) % 8]); + p.setBrush(Ruler::CursorColorTable[(index - 1) % CURSOR_COLOR_TABLE_SIZE]); else if (r.contains(QPoint(_view.hover_point().x(), _view.hover_point().y()))) p.setBrush(View::Orange); else - p.setBrush(Ruler::CursorColor[(index - 1) % 8]); + p.setBrush(Ruler::CursorColorTable[(index - 1) % CURSOR_COLOR_TABLE_SIZE]); + p.drawRect(r); const QPoint points[] = { diff --git a/DSView/pv/view/ruler.cpp b/DSView/pv/view/ruler.cpp index 3076275b..24558a82 100644 --- a/DSView/pv/view/ruler.cpp +++ b/DSView/pv/view/ruler.cpp @@ -62,15 +62,32 @@ const int Ruler::pricision = 2; const int Ruler::HoverArrowSize = 4; const int Ruler::CursorSelWidth = 20; -const QColor Ruler::CursorColor[8] = - {QColor(25, 189, 155, 200), - QColor(46, 205, 113, 200), - QColor(53, 152, 220, 200), - QColor(154, 89, 181, 200), - QColor(52, 73, 94, 200), - QColor(242, 196, 15, 200), - QColor(231, 126, 34, 200), - QColor(232, 76, 61, 200)}; + +const QColor Ruler::CursorColorTable[CURSOR_COLOR_TABLE_SIZE] = + { + QColor(154,205,50, 200), //YellowGreen + QColor(255,255,0, 200), //Yellow + QColor(245,222,179, 200), //Wheat + QColor(208,32,144, 200), //VioletRed + QColor(255,99,71, 200), //Tomato + QColor(0,128,128, 200), //Teal + QColor(70,130,180, 200), //SteelBlue + QColor(106,90,205, 200),//SlateBlue + QColor(160,82,45, 200), //Sienna + QColor(46,139,87, 200), //SeaGreen + QColor(128,0,128, 200), //Purple + QColor(127,255,0, 200), //Chartreuse + QColor(0,0,255, 200), //Blue + QColor(220,20,60, 200), //Crimson + QColor(184,134,11, 200), //DarkGoldenRod + QColor(139,0,139, 200), //DarkMagenta + QColor(255,20,147, 200), //DeepPink + QColor(34,139,34, 200), //ForestGreen + QColor(0,0,128, 200), //Navy + QColor(255,0,255, 200), //Fuchsia + QColor(255,127,80, 200), //Coral + QColor(255,69,0, 200), //OrangeRed + }; Ruler::Ruler(View &parent) : QWidget(&parent), @@ -314,7 +331,7 @@ void Ruler::mouseReleaseEvent(QMouseEvent *event) overCursor = in_cursor_sel_rect(event->pos()); if (overCursor == 0) { - _view.add_cursor(CursorColor[cursor_list.size() % 8], index); + _view.add_cursor(CursorColorTable[cursor_list.size() % CURSOR_COLOR_TABLE_SIZE], index); _view.show_cursors(true); updatedCursor = true; } @@ -703,7 +720,7 @@ void Ruler::draw_cursor_sel(QPainter &p) if (in_cursor_sel_rect(pos) == index) p.setBrush(View::Orange); else - p.setBrush(CursorColor[(index - 1)%8]); + p.setBrush(CursorColorTable[(index - 1)%CURSOR_COLOR_TABLE_SIZE]); p.drawRect(cursorRect); p.setPen(Qt::black); diff --git a/DSView/pv/view/ruler.h b/DSView/pv/view/ruler.h index 822c7d5f..37c92d5e 100644 --- a/DSView/pv/view/ruler.h +++ b/DSView/pv/view/ruler.h @@ -27,6 +27,8 @@ #include #include +#define CURSOR_COLOR_TABLE_SIZE 22 + namespace pv { namespace view { @@ -53,7 +55,7 @@ private: static const int CursorSelWidth; public: - static const QColor CursorColor[8]; + static const QColor CursorColorTable[CURSOR_COLOR_TABLE_SIZE]; public: Ruler(View &parent); diff --git a/DSView/pv/view/timemarker.cpp b/DSView/pv/view/timemarker.cpp index ad9693e9..0a6b049b 100644 --- a/DSView/pv/view/timemarker.cpp +++ b/DSView/pv/view/timemarker.cpp @@ -82,7 +82,7 @@ void TimeMarker::paint(QPainter &p, const QRect &rect, const bool highlight, int { const int64_t x = _view.index2pixel(_index, trig_hoff); if (x <= rect.right()) { - QColor color = (order == -1) ? _colour : Ruler::CursorColor[order%8]; + QColor color = (order == -1) ? _colour : Ruler::CursorColorTable[order%CURSOR_COLOR_TABLE_SIZE]; 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/view.cpp b/DSView/pv/view/view.cpp index f1ff8b74..8983776d 100644 --- a/DSView/pv/view/view.cpp +++ b/DSView/pv/view/view.cpp @@ -979,6 +979,14 @@ void View::add_cursor(QColor color, uint64_t index) cursor_update(); } +void View::add_cursor(uint64_t index) +{ + static int addIndex = 0; + QColor color = view::Ruler::CursorColorTable[addIndex%CURSOR_COLOR_TABLE_SIZE]; + add_cursor(color, index); + addIndex++; +} + void View::del_cursor(Cursor* cursor) { assert(cursor); diff --git a/DSView/pv/view/view.h b/DSView/pv/view/view.h index 5e53e4f7..da711f8a 100644 --- a/DSView/pv/view/view.h +++ b/DSView/pv/view/view.h @@ -222,6 +222,7 @@ public: } void add_cursor(QColor color, uint64_t index); + void add_cursor(uint64_t index); void del_cursor(Cursor* cursor); void clear_cursors(); void set_cursor_middle(int index); diff --git a/DSView/pv/view/viewport.cpp b/DSView/pv/view/viewport.cpp index 9a0e2081..7ea974b8 100644 --- a/DSView/pv/view/viewport.cpp +++ b/DSView/pv/view/viewport.cpp @@ -645,7 +645,7 @@ void Viewport::mousePressEvent(QMouseEvent *event) if (_hover_hit) { const int64_t index = _view.pixel2index(event->pos().x()); auto &cursor_list = _view.get_cursorList(); - _view.add_cursor(view::Ruler::CursorColor[cursor_list.size() % 8], index); + _view.add_cursor(index); _view.show_cursors(true); } } @@ -1191,7 +1191,7 @@ void Viewport::mouseDoubleClickEvent(QMouseEvent *event) } auto &cursor_list = _view.get_cursorList(); - _view.add_cursor(view::Ruler::CursorColor[cursor_list.size() % 8], index); + _view.add_cursor(view::Ruler::CursorColorTable[cursor_list.size() % CURSOR_COLOR_TABLE_SIZE], index); _view.show_cursors(true); } @@ -1220,7 +1220,7 @@ void Viewport::mouseDoubleClickEvent(QMouseEvent *event) const double curX = event->pos().x(); index = _view.pixel2index(curX); auto &cursor_list = _view.get_cursorList(); - _view.add_cursor(view::Ruler::CursorColor[cursor_list.size() % 8], index); + _view.add_cursor(view::Ruler::CursorColorTable[cursor_list.size() % CURSOR_COLOR_TABLE_SIZE], index); _view.show_cursors(true); } } @@ -2025,7 +2025,7 @@ void Viewport::add_cursor_y() //const double curX = _menu_pos.x(); index = _view.pixel2index(_cur_preX); auto &cursor_list = _view.get_cursorList(); - _view.add_cursor(view::Ruler::CursorColor[cursor_list.size() % 8], index); + _view.add_cursor(view::Ruler::CursorColorTable[cursor_list.size() % CURSOR_COLOR_TABLE_SIZE], index); _view.show_cursors(true); } @@ -2033,7 +2033,7 @@ 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::CursorColor[cursor_list.size() % 8], ypos, ypos); + _view.add_xcursor(view::Ruler::CursorColorTable[cursor_list.size() % CURSOR_COLOR_TABLE_SIZE], ypos, ypos); _view.show_xcursors(true); } diff --git a/DSView/pv/view/xcursor.cpp b/DSView/pv/view/xcursor.cpp index 37adc4f6..904a88c9 100644 --- a/DSView/pv/view/xcursor.cpp +++ b/DSView/pv/view/xcursor.cpp @@ -174,7 +174,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::CursorColor[order%8]; + QColor color = (order == -1) ? _colour : Ruler::CursorColorTable[order%CURSOR_COLOR_TABLE_SIZE]; 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));