diff --git a/DSView/pv/mainwindow.cpp b/DSView/pv/mainwindow.cpp index 2f7605c0..bc98095b 100644 --- a/DSView/pv/mainwindow.cpp +++ b/DSView/pv/mainwindow.cpp @@ -313,7 +313,7 @@ namespace pv tmp_file = ldFileName; bLoadFile = true; - QTimer::singleShot(300, this, [this](){ + QTimer::singleShot(100, this, [this](){ on_load_file(tmp_file); tmp_file = ""; }); @@ -326,7 +326,9 @@ namespace pv } if (!bLoadFile){ - _session->set_default_device(); + QTimer::singleShot(100, this, [this](){ + _session->set_default_device(); + }); } } diff --git a/DSView/pv/view/view.cpp b/DSView/pv/view/view.cpp index 1a10311e..5f0644ab 100644 --- a/DSView/pv/view/view.cpp +++ b/DSView/pv/view/view.cpp @@ -229,10 +229,15 @@ void View::capture_init() show_trig_cursor(true); else if (!_session->is_repeating()) show_trig_cursor(false); + + int width = get_view_width(); + assert(width > 0); - _maxscale = _session->cur_sampletime() / (get_view_width() * MaxViewRate); - if (mode == ANALOG) + _maxscale = _session->cur_sampletime() / (width * MaxViewRate); + + if (mode == ANALOG){ set_scale_offset(_maxscale, 0); + } status_clear(); @@ -241,7 +246,10 @@ void View::capture_init() void View::zoom(double steps) { - zoom(steps, get_view_width() / 2); + int width = get_view_width(); + assert(width > 0); + + zoom(steps, width / 2); } void View::set_update(Viewport *viewport, bool need_update) @@ -273,6 +281,9 @@ bool View::zoom(double steps, int offset) _preScale = _scale; _preOffset = _offset; + int width = get_view_width(); + assert(width > 0); + if (_device_agent->get_work_mode() != DSO) { _scale *= std::pow(3.0/2.0, -steps); _scale = max(min(_scale, _maxscale), _minscale); @@ -289,9 +300,10 @@ bool View::zoom(double steps, int offset) hori_res = _sampling_bar->hori_knob(1); if (hori_res > 0) { - const double scale = _session->cur_view_time() / get_view_width(); + const double scale = _session->cur_view_time() / width; _scale = max(min(scale, _maxscale), _minscale); - } else { + } + else { ret = false; } } @@ -314,10 +326,16 @@ void View::timebase_changed() if (_device_agent->get_work_mode() != DSO) return; + int width = get_view_width(); + assert(width > 0); + double scale = this->scale(); double hori_res = _sampling_bar->get_hori_res(); - if (hori_res > 0) - scale = _session->cur_view_time() / get_view_width(); + + if (hori_res > 0){ + scale = _session->cur_view_time() / width; + } + set_scale_offset(scale, this->offset()); } @@ -501,6 +519,9 @@ void View::set_trig_cursor_posistion(uint64_t trig_pos) const double time = trig_pos * 1.0 / _session->cur_snap_samplerate(); _trig_cursor->set_index(trig_pos); + int width = get_view_width(); + assert(width > 0); + if (ds_trigger_get_en() || _device_agent->is_virtual() || _device_agent->get_work_mode() == DSO) { @@ -508,7 +529,7 @@ void View::set_trig_cursor_posistion(uint64_t trig_pos) AppConfig &app = AppConfig::Instance(); if (app.appOptions.trigPosDisplayInMid){ - set_scale_offset(_scale, (time / _scale) - (get_view_width() / 2)); + set_scale_offset(_scale, (time / _scale) - (width / 2)); } } @@ -537,8 +558,11 @@ void View::set_search_pos(uint64_t search_pos, bool hit) _search_cursor->set_index(search_pos); _search_cursor->set_colour(hit ? View::Blue : fore); + int width = get_view_width(); + assert(width); + if (hit) { - set_scale_offset(_scale, (time / _scale) - (get_view_width() / 2)); + set_scale_offset(_scale, (time / _scale) - (width / 2)); _ruler->update(); viewport_update(); } @@ -574,7 +598,10 @@ void View::update_scroll() { assert(_viewcenter); - const QSize areaSize = QSize(get_view_width(), get_view_height()); + int width = get_view_width(); + assert(width > 0); + + const QSize areaSize = QSize(width, get_view_height()); // Set the horizontal scroll bar int64_t length = 0; @@ -603,12 +630,16 @@ void View::update_scroll() } void View::update_scale_offset() -{ +{ + int width = get_view_width(); + assert(width > 0); + if (_device_agent->get_work_mode() != DSO) { - _maxscale = _session->cur_sampletime() / (get_view_width() * MaxViewRate); + _maxscale = _session->cur_sampletime() / (width * MaxViewRate); _minscale = (1.0 / _session->cur_snap_samplerate()) / MaxPixelsPerSample; - } else { - _scale = _session->cur_view_time() / get_view_width(); + } + else { + _scale = _session->cur_view_time() / width; _maxscale = 1e9; _minscale = 1e-15; } @@ -872,11 +903,15 @@ void View::resizeEvent(QResizeEvent*) update_scroll(); signals_changed(NULL); - if (_device_agent->get_work_mode() == DSO) - _scale = _session->cur_view_time() / get_view_width(); + int width = get_view_width(); + assert(width > 0); + + if (_device_agent->get_work_mode() == DSO){ + _scale = _session->cur_view_time() / width; + } if (_device_agent->get_work_mode() != DSO) - _maxscale = _session->cur_sampletime() / (get_view_width() * MaxViewRate); + _maxscale = _session->cur_sampletime() / (width * MaxViewRate); else _maxscale = 1e9; @@ -942,10 +977,11 @@ void View::data_updated() void View::update_margins() { - _ruler->setGeometry(_viewcenter->x(), 0, get_view_width(), _viewcenter->y()); + int width = get_view_width(); + assert(width > 0); + _ruler->setGeometry(_viewcenter->x(), 0, width, _viewcenter->y()); _header->setGeometry(0, _viewcenter->y(), _viewcenter->x(), _viewcenter->height()); - _devmode->setGeometry(0, 0, _viewcenter->x(), _viewcenter->y()); } @@ -1014,13 +1050,16 @@ void View::set_cursor_middle(int index) int size = lst.size(); assert(index < size); + int width = get_view_width(); + assert(width > 0); + auto i = lst.begin(); while (index-- != 0){ i++; } - set_scale_offset(_scale, (*i)->index() / (_session->cur_snap_samplerate() * _scale) - (get_view_width() / 2)); + set_scale_offset(_scale, (*i)->index() / (_session->cur_snap_samplerate() * _scale) - (width / 2)); } void View::on_measure_updated() @@ -1138,21 +1177,30 @@ int View::get_view_height() int64_t View::get_min_offset() { + int width = get_view_width(); + assert(width > 0); + if (MaxViewRate > 1) - return floor(get_view_width() * (1 - MaxViewRate)); + return floor(width * (1 - MaxViewRate)); else return 0; } int64_t View::get_max_offset() { + int width = get_view_width(); + assert(width > 0); + return ceil((_session->cur_snap_sampletime() / _scale) - - (get_view_width() * MaxViewRate)); + (width * MaxViewRate)); } int64_t View::get_logic_lst_data_offset(){ + int width = get_view_width(); + assert(width > 0); + return ceil((_session->get_logic_data_view_time() / _scale) - - (get_view_width() * MaxViewRate)); + (width * MaxViewRate)); } void View::scroll_to_logic_last_data_time() @@ -1201,17 +1249,23 @@ void View::show_lissajous(bool show) void View::show_region(uint64_t start, uint64_t end, bool keep) { assert(start <= end); + + int width = get_view_width(); + assert(width > 0); + if (keep) { set_all_update(true); update(); - } else if (_session->get_map_zoom() == 0) { - const double ideal_scale = (end-start) * 2.0 / _session->cur_snap_samplerate() / get_view_width(); + } + else if (_session->get_map_zoom() == 0) { + const double ideal_scale = (end-start) * 2.0 / _session->cur_snap_samplerate() / width; const double new_scale = max (min(ideal_scale, _maxscale), _minscale); - const double new_off = (start + end) * 0.5 / (_session->cur_snap_samplerate() * new_scale) - (get_view_width() / 2); + const double new_off = (start + end) * 0.5 / (_session->cur_snap_samplerate() * new_scale) - (width / 2); set_scale_offset(new_scale, new_off); - } else { + } + else { const double new_scale = scale(); - const double new_off = (start + end) * 0.5 / (_session->cur_snap_samplerate() * new_scale) - (get_view_width() / 2); + const double new_off = (start + end) * 0.5 / (_session->cur_snap_samplerate() * new_scale) - (width/ 2); set_scale_offset(new_scale, new_off); } } @@ -1307,11 +1361,20 @@ double View::index2pixel(uint64_t index, bool has_hoff) } uint64_t View::pixel2index(double pixel) -{ - const double samples_per_pixel = session().cur_snap_samplerate() * scale(); - double index = (pixel + offset()) * samples_per_pixel - trig_hoff(); +{ + const uint64_t rateValue = session().cur_snap_samplerate(); + const double scaleValue = scale(); + const int64_t offsetValue = offset(); + const double hoffValue = trig_hoff(); + + const double samples_per_pixel = rateValue * scaleValue; + const double index = (pixel + offsetValue) * samples_per_pixel - hoffValue; - return (uint64_t)std::round(index); + const uint64_t sampleIndex = (uint64_t)std::round(index); + return sampleIndex; + + //const double samples_per_pixel = session().cur_snap_samplerate() * scale(); + //uint64_t index = (pixel + offset()) * samples_per_pixel - trig_hoff(); } void View::set_receive_len(uint64_t len) @@ -1368,8 +1431,14 @@ void View::set_scale(double scale) void View::auto_set_max_scale() { - _maxscale = _session->cur_sampletime() / (get_view_width() * MaxViewRate); - set_scale(_maxscale); + const double limitTime = _session->cur_sampletime(); + const int width = get_view_width(); + + if (width > 0) + { + _maxscale = limitTime / (width * MaxViewRate); + set_scale(_maxscale); + } } int View::get_body_width() diff --git a/DSView/pv/view/view.h b/DSView/pv/view/view.h index f3c23fbd..90ff4791 100644 --- a/DSView/pv/view/view.h +++ b/DSView/pv/view/view.h @@ -131,8 +131,6 @@ public: return _maxscale; } - void set_scale(double scale); - void auto_set_max_scale(); /** @@ -346,14 +344,12 @@ signals: void resize(); void auto_trig(int index); -private: - void get_scroll_layout(int64_t &length, int64_t &offset); - - void update_scroll(); - - void update_margins(); - +private: static bool compare_trace_v_offsets( const Trace *a, const Trace *b); + void get_scroll_layout(int64_t &length, int64_t &offset); + void update_scroll(); + void update_margins(); + void set_scale(double scale); void clear(); void reconstruct(); diff --git a/DSView/pv/view/viewport.cpp b/DSView/pv/view/viewport.cpp index 9c082497..8aa5b1ae 100644 --- a/DSView/pv/view/viewport.cpp +++ b/DSView/pv/view/viewport.cpp @@ -90,7 +90,7 @@ Viewport::Viewport(View &parent, View_type type) : _edge_hit = false; _transfer_started = false; _timer_cnt = 0; - _clickX = 0; + _sample_received = 0; _is_checked_trig = false; @@ -646,7 +646,6 @@ void Viewport::mousePressEvent(QMouseEvent *event) { assert(event); - _clickX = event->globalPos().x(); _mouse_down_point = event->pos(); _mouse_down_offset = _view.offset(); _drag_strength = 0; @@ -657,7 +656,7 @@ void Viewport::mousePressEvent(QMouseEvent *event) && _view.session().is_stopped_status()) { if (_view.session().get_device()->get_work_mode() == LOGIC) { - _action_type = LOGIC_ZOOM; + set_action(LOGIC_ZOOM); } else if (_view.session().get_device()->get_work_mode() == DSO) { if (_hover_hit) { @@ -679,7 +678,7 @@ void Viewport::mousePressEvent(QMouseEvent *event) DsoSignal *dsoSig = (DsoSignal*)s; if (dsoSig->get_trig_rect(0, _view.get_view_width()).contains(_mouse_point)) { _drag_sig = s; - _action_type = DSO_TRIG_MOVE; + set_action(DSO_TRIG_MOVE); dsoSig->select(true); break; } @@ -697,7 +696,7 @@ void Viewport::mousePressEvent(QMouseEvent *event) } else if (qAbs(searchX - event->pos().x()) <= HitCursorMargin) { _view.get_ruler()->set_grabbed_cursor(_view.get_search_cursor()); - _action_type = CURS_MOVE; + set_action(CURS_MOVE); } } @@ -712,7 +711,7 @@ void Viewport::mousePressEvent(QMouseEvent *event) } else if (qAbs(cursorX - event->pos().x()) <= HitCursorMargin) { _view.get_ruler()->set_grabbed_cursor(*i); - _action_type = CURS_MOVE; + set_action(CURS_MOVE); break; } i++; @@ -772,17 +771,17 @@ void Viewport::mousePressEvent(QMouseEvent *event) _view.hover_point().y() > min(cursorY0, cursorY1) && _view.hover_point().y() < max(cursorY0, cursorY1)) { (*i)->set_grabbed(XCursor::XCur_Y, true); - _action_type = CURS_MOVE; + set_action(CURS_MOVE); break; } else if (qAbs(cursorY0 - _view.hover_point().y()) <= HitCursorMargin) { (*i)->set_grabbed(XCursor::XCur_X0, true); - _action_type = CURS_MOVE; + set_action(CURS_MOVE); break; } else if (qAbs(cursorY1 - _view.hover_point().y()) <= HitCursorMargin) { (*i)->set_grabbed(XCursor::XCur_X1, true); - _action_type = CURS_MOVE; + set_action(CURS_MOVE); break; } i++; @@ -922,26 +921,31 @@ void Viewport:: mouseMoveEvent(QMouseEvent *event) update(UpdateEventType::UPDATE_EV_MS_MOVE); } -void Viewport::mouseReleaseEvent(QMouseEvent *event) +void Viewport::set_action(ActionType action) { - assert(event); + if (_action_type == LOGIC_JUMP && action != LOGIC_JUMP) + { + // int bbb = 0; + // assert(0); + } + _action_type = action; +} - bool quickScroll = AppConfig::Instance().appOptions.quickScroll; - bool isMaxWindow = AppControl::Instance()->TopWindowIsMaximized(); - - if (_type != TIME_VIEW){ - update(UpdateEventType::UPDATE_EV_MS_UP); - return; - } - - if ((_action_type == NO_ACTION) && (event->button() == Qt::LeftButton)) +void Viewport::onLogicMouseRelease(QMouseEvent *event) +{ + bool quickScroll = AppConfig::Instance().appOptions.quickScroll; + bool isMaxWindow = AppControl::Instance()->TopWindowIsMaximized(); + + switch (_action_type) + { + case NO_ACTION: { - if (_view.session().get_device()->get_work_mode() == LOGIC - && _view.session().is_stopped_status()) { + if (event->button() == Qt::LeftButton && _view.session().is_stopped_status()){ //priority 1 //try to quick scroll view... - int curX = event->globalPos().x(); - int moveLong = ABS_VAL(curX - _clickX); + int curX = event->pos().x(); + int clickX = _mouse_down_point.x(); + int moveLong = ABS_VAL(curX - clickX); int maxWidth = this->geometry().width(); float mvk = (float) moveLong / (float)maxWidth; @@ -961,12 +965,13 @@ void Viewport::mouseReleaseEvent(QMouseEvent *event) abs(_drag_strength) < MinorDragOffsetUp && abs(strength) > MinorDragRateUp) { _drag_timer.start(DragTimerInterval); - _action_type = LOGIC_MOVE; - } else if (_elapsed_time.elapsed() < 200 && + set_action(LOGIC_MOVE); + } + else if (_elapsed_time.elapsed() < 200 && abs(strength) > DragTimerInterval) { _drag_strength = strength * 5; _drag_timer.start(DragTimerInterval); - _action_type = LOGIC_MOVE; + set_action(LOGIC_MOVE); } } @@ -979,13 +984,17 @@ void Viewport::mouseReleaseEvent(QMouseEvent *event) if (s->signal_type() == SR_CHANNEL_LOGIC) { view::LogicSignal *logicSig = (view::LogicSignal*)s; if (logicSig->is_by_edge(event->pos(), _edge_start, 10)) { - _action_type = LOGIC_JUMP; + set_action(LOGIC_JUMP); _cur_preX = _view.index2pixel(_edge_start); _cur_preY = logicSig->get_y(); _cur_preY_top = logicSig->get_y() - logicSig->get_totalHeight()/2 - 12; _cur_preY_bottom = logicSig->get_y() + logicSig->get_totalHeight()/2 + 2; _cur_aftX = _cur_preX; _cur_aftY = _cur_preY; + + static int times = 0; + times++; + dsv_info("click by edge %d", times); break; } } @@ -1000,123 +1009,37 @@ void Viewport::mouseReleaseEvent(QMouseEvent *event) for(auto s : sigs) { if (abs(event->pos().y() - s->get_y()) < _view.get_signalHeight()) { - _action_type = LOGIC_EDGE; + set_action(LOGIC_EDGE); _edge_start = _view.pixel2index(event->pos().x()); break; } } } } - } - else if (_view.session().get_device()->get_work_mode() == DSO) { - // priority 0 - if (_action_type == NO_ACTION && _hover_hit) { - _action_type = DSO_YM; - _dso_ym_valid = true; - _dso_ym_sig_index = _hover_sig_index; - _dso_ym_sig_value = _hover_sig_value; - _dso_ym_index = _hover_index; - _dso_ym_start = event->pos().y(); - } - } + } + break; } - else if (_action_type == DSO_YM) { - if (event->button() == Qt::LeftButton) { - _dso_ym_end = event->pos().y(); - _action_type = NO_ACTION; - } else if (event->button() == Qt::RightButton) { - _action_type = NO_ACTION; - _dso_ym_valid = false; - } - } - else if (_action_type == DSO_TRIG_MOVE) { - if (_dso_trig_moved && event->button() == Qt::LeftButton) { - _drag_sig = NULL; - _action_type = NO_ACTION; - _dso_trig_moved = false; - - std::vector traces; - _view.get_traces(ALL_VIEW, traces); - - for(auto t : traces){ - t->select(false); - } - } - } - else if (_action_type == DSO_XM_STEP0) { - if (event->button() == Qt::LeftButton) { - _action_type = DSO_XM_STEP1; - _dso_xm_valid = true; - } - } - else if (_action_type == DSO_XM_STEP1) { - if (event->button() == Qt::LeftButton) { - _dso_xm_index[1] = _view.pixel2index(event->pos().x()); - const uint64_t max_index = max(_dso_xm_index[0], _dso_xm_index[1]); - _dso_xm_index[0] = min(_dso_xm_index[0], _dso_xm_index[1]); - _dso_xm_index[1] = max_index; - - _action_type = DSO_XM_STEP2; - } - else if (event->button() == Qt::RightButton) { - clear_dso_xm(); - measure_updated(); - } - } - else if (_action_type == DSO_XM_STEP2) { - if (event->button() == Qt::LeftButton) { - _dso_xm_index[2] = _view.pixel2index(event->pos().x()); - uint64_t max_index = max(_dso_xm_index[1], _dso_xm_index[2]); - _dso_xm_index[1] = min(_dso_xm_index[1], _dso_xm_index[2]); - _dso_xm_index[2] = max_index; - - max_index = max(_dso_xm_index[0], _dso_xm_index[1]); - _dso_xm_index[0] = min(_dso_xm_index[0], _dso_xm_index[1]); - _dso_xm_index[1] = max_index; - - _action_type = NO_ACTION; - } - else if (event->button() == Qt::RightButton) { - clear_dso_xm(); - measure_updated(); - } - } - else if (_action_type == CURS_MOVE) { - if (_curs_moved && event->button() == Qt::LeftButton) { - _action_type = NO_ACTION; - _view.get_ruler()->rel_grabbed_cursor(); - _view.cursor_moved(); - _curs_moved = false; - } - if (_xcurs_moved && event->button() == Qt::LeftButton) { - _action_type = NO_ACTION; - auto &xcursor_list = _view.get_xcursorList(); - auto i = xcursor_list.begin(); - - while (i != xcursor_list.end()) { - (*i)->rel_grabbed(); - i++; - } - - _xcurs_moved = false; - } - } - else if (_action_type == LOGIC_EDGE) { - _action_type = NO_ACTION; + case LOGIC_EDGE: + { + set_action(NO_ACTION); _edge_rising = 0; _edge_falling = 0; + break; } - else if (_action_type == LOGIC_JUMP) { - _action_type = NO_ACTION; + case LOGIC_JUMP: + { + set_action(NO_ACTION); _edge_rising = 0; _edge_falling = 0; _edge_hit = false; + break; } - else if (_action_type == LOGIC_MOVE) { + case LOGIC_MOVE: + { if (_mouse_down_point == event->pos()) { _drag_strength = 0; _drag_timer.stop(); - _action_type = NO_ACTION; + set_action(NO_ACTION); } else { const double strength = _drag_strength*DragTimerInterval*1.0/_elapsed_time.elapsed(); @@ -1133,11 +1056,13 @@ void Viewport::mouseReleaseEvent(QMouseEvent *event) else { _drag_strength = 0; _drag_timer.stop(); - _action_type = NO_ACTION; + set_action(NO_ACTION); } } + break; } - else if (_action_type == LOGIC_ZOOM) { + case LOGIC_ZOOM: + { if (event->pos().x() != _mouse_down_point.x()) { int64_t newOffset = _view.offset() + (min(event->pos().x(), _mouse_down_point.x())); const double newScale = max(min(_view.scale() * abs(event->pos().x() - _mouse_down_point.x()) / _view.get_view_width(), @@ -1146,18 +1071,161 @@ void Viewport::mouseReleaseEvent(QMouseEvent *event) if (newScale != _view.scale()) _view.set_scale_offset(newScale, newOffset); } - _action_type = NO_ACTION; + set_action(NO_ACTION); + break; + } + } +} + +void Viewport::onDsoMouseRelease(QMouseEvent *event) +{ + switch (_action_type) + { + case NO_ACTION: + { + if (event->button() == Qt::LeftButton && _hover_hit) + { + set_action(DSO_YM); + _dso_ym_valid = true; + _dso_ym_sig_index = _hover_sig_index; + _dso_ym_sig_value = _hover_sig_value; + _dso_ym_index = _hover_index; + _dso_ym_start = event->pos().y(); + } + break; + } + case DSO_YM: + { + if (event->button() == Qt::LeftButton) { + _dso_ym_end = event->pos().y(); + set_action(NO_ACTION); + } + else if (event->button() == Qt::RightButton) { + set_action(NO_ACTION); + _dso_ym_valid = false; + } + break; + } + case DSO_TRIG_MOVE: + { + if (_dso_trig_moved && event->button() == Qt::LeftButton) { + _drag_sig = NULL; + set_action(NO_ACTION); + _dso_trig_moved = false; + + std::vector traces; + _view.get_traces(ALL_VIEW, traces); + + for(auto t : traces){ + t->select(false); + } + } + break; + } + case DSO_XM_STEP0: + { + if (event->button() == Qt::LeftButton) { + set_action(DSO_XM_STEP1); + _dso_xm_valid = true; + } + break; + } + case DSO_XM_STEP1: + { + if (event->button() == Qt::LeftButton) { + _dso_xm_index[1] = _view.pixel2index(event->pos().x()); + const uint64_t max_index = max(_dso_xm_index[0], _dso_xm_index[1]); + _dso_xm_index[0] = min(_dso_xm_index[0], _dso_xm_index[1]); + _dso_xm_index[1] = max_index; + + set_action(DSO_XM_STEP2); + } + else if (event->button() == Qt::RightButton) { + clear_dso_xm(); + measure_updated(); + } + break; + } + case DSO_XM_STEP2: + { + if (event->button() == Qt::LeftButton) { + _dso_xm_index[2] = _view.pixel2index(event->pos().x()); + uint64_t max_index = max(_dso_xm_index[1], _dso_xm_index[2]); + _dso_xm_index[1] = min(_dso_xm_index[1], _dso_xm_index[2]); + _dso_xm_index[2] = max_index; + + max_index = max(_dso_xm_index[0], _dso_xm_index[1]); + _dso_xm_index[0] = min(_dso_xm_index[0], _dso_xm_index[1]); + _dso_xm_index[1] = max_index; + + set_action(NO_ACTION); + } + else if (event->button() == Qt::RightButton) { + clear_dso_xm(); + measure_updated(); + } + break; } - - if (_view.session().get_device()->get_work_mode() == LOGIC - && event->button() == Qt::LeftButton){ - const int64_t index = _view.pixel2index(_clickX); - if (index > _view.session().get_ring_sample_count()){ - _measure_type = MeasureType::NO_MEASURE; - _action_type = NO_ACTION; - } } - +} + +void Viewport::onAnalogMouseRelease(QMouseEvent *event) +{ + +} + +void Viewport::mouseReleaseEvent(QMouseEvent *event) +{ + assert(event); + + if (_type != TIME_VIEW){ + update(UpdateEventType::UPDATE_EV_MS_UP); + return; + } + + int mode = _view.session().get_device()->get_work_mode(); + + if (mode == LOGIC){ + onLogicMouseRelease(event); + } + else if (mode == DSO){ + onDsoMouseRelease(event); + } + else if (mode == ANALOG){ + onAnalogMouseRelease(event); + } + + if (_action_type == CURS_MOVE) { + if (_curs_moved && event->button() == Qt::LeftButton) { + set_action(NO_ACTION); + _view.get_ruler()->rel_grabbed_cursor(); + _view.cursor_moved(); + _curs_moved = false; + } + if (_xcurs_moved && event->button() == Qt::LeftButton) { + set_action(NO_ACTION); + auto &xcursor_list = _view.get_xcursorList(); + auto i = xcursor_list.begin(); + + while (i != xcursor_list.end()) { + (*i)->rel_grabbed(); + i++; + } + + _xcurs_moved = false; + } + } + + if (mode == LOGIC && event->button() == Qt::LeftButton){ + int clickX = _mouse_down_point.x(); + const int64_t index = _view.pixel2index(clickX); + const int64_t total = _view.session().get_ring_sample_count(); + if (index > total){ + _measure_type = MeasureType::NO_MEASURE; + set_action(NO_ACTION); + } + } + update(UpdateEventType::UPDATE_EV_MS_UP); } @@ -1227,7 +1295,7 @@ void Viewport::mouseDoubleClickEvent(QMouseEvent *event) if (s->get_view_rect().contains(event->pos())) { _dso_xm_index[0] = _view.pixel2index(event->pos().x()); _dso_xm_y = event->pos().y(); - _action_type = DSO_XM_STEP0; + set_action(DSO_XM_STEP0); } break; } @@ -1382,20 +1450,24 @@ void Viewport::leaveEvent(QEvent *) if (_action_type == LOGIC_EDGE) { _edge_rising = 0; _edge_falling = 0; - _action_type = NO_ACTION; - } else if (_action_type == LOGIC_JUMP) { + set_action(NO_ACTION); + } + else if (_action_type == LOGIC_JUMP) { _edge_rising = 0; _edge_falling = 0; - _action_type = NO_ACTION; - } else if (_action_type == LOGIC_MOVE) { + set_action(NO_ACTION); + } + else if (_action_type == LOGIC_MOVE) { _drag_strength = 0; _drag_timer.stop(); - _action_type = NO_ACTION; - } else if (_action_type == DSO_XM_STEP1 || _action_type == DSO_XM_STEP2) { + set_action(NO_ACTION); + } + else if (_action_type == DSO_XM_STEP1 || _action_type == DSO_XM_STEP2) { clear_dso_xm(); - } else if (_action_type == DSO_YM) { + } + else if (_action_type == DSO_YM) { _dso_ym_valid = false; - _action_type = NO_ACTION; + set_action(NO_ACTION); } clear_measure(); @@ -1488,7 +1560,8 @@ void Viewport::clear_dso_xm() _mm_period = View::Unknown_Str; _mm_freq = View::Unknown_Str; _mm_duty = View::Unknown_Str; - _action_type = NO_ACTION; + + set_action(NO_ACTION); } void Viewport::measure() @@ -1999,7 +2072,7 @@ void Viewport::on_drag_timer() offset == _view.get_min_offset()) { _drag_strength = 0; _drag_timer.stop(); - _action_type = NO_ACTION; + set_action(NO_ACTION); } else if (_action_type == NO_ACTION){ _drag_strength = 0; diff --git a/DSView/pv/view/viewport.h b/DSView/pv/view/viewport.h index 22ef323c..a5da560f 100644 --- a/DSView/pv/view/viewport.h +++ b/DSView/pv/view/viewport.h @@ -150,8 +150,12 @@ private: void paintCursors(QPainter &p); void start_trigger_timer(int msec); - void get_captured_progress(double &progress, int &progress100); + void set_action(ActionType action); + + void onLogicMouseRelease(QMouseEvent *event); + void onDsoMouseRelease(QMouseEvent *event); + void onAnalogMouseRelease(QMouseEvent *event); private slots: void on_trigger_timer(); @@ -235,7 +239,6 @@ private: bool _dso_trig_moved; bool _curs_moved; bool _xcurs_moved; - int _clickX; high_resolution_clock::time_point _lst_wait_tigger_time; int _tigger_wait_times;