Extend the color talbe of cursor

This commit is contained in:
dreamsourcelabTAI 2024-01-08 14:27:44 +08:00
parent 326b25e1dd
commit d5fb302e46
9 changed files with 52 additions and 22 deletions

View File

@ -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 + ";}";

View File

@ -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[] = {

View File

@ -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);

View File

@ -27,6 +27,8 @@
#include <QWidget>
#include <stdint.h>
#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);

View File

@ -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()));
}

View File

@ -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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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));