X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;ds=inline;f=pv%2Fview%2Fcursorpair.cpp;h=3259524c754acbf151dc7755146b220a347eaa31;hb=HEAD;hp=5df658dbf31cdff74cc9f789552634d75db50dc0;hpb=3fed1f316d4eebb20e10dbc04c6bd7ed6c6475da;p=pulseview.git diff --git a/pv/view/cursorpair.cpp b/pv/view/cursorpair.cpp deleted file mode 100644 index 5df658db..00000000 --- a/pv/view/cursorpair.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* - * This file is part of the PulseView project. - * - * Copyright (C) 2013 Joel Holdsworth - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "cursorpair.hpp" - -#include "view.hpp" -#include "pv/util.hpp" - -#include -#include - -using std::max; -using std::make_pair; -using std::min; -using std::shared_ptr; -using std::pair; - -namespace pv { -namespace view { - -const int CursorPair::DeltaPadding = 8; -const QColor CursorPair::ViewportFillColour(220, 231, 243); - -CursorPair::CursorPair(View &view) : - TimeItem(view), - first_(new Cursor(view, 0.0)), - second_(new Cursor(view, 1.0)) -{ -} - -bool CursorPair::enabled() const -{ - return view_.cursors_shown(); -} - -shared_ptr CursorPair::first() const -{ - return first_; -} - -shared_ptr CursorPair::second() const -{ - return second_; -} - -void CursorPair::set_time(double time) { - const double delta = second_->time() - first_->time(); - first_->set_time(time); - second_->set_time(time + delta); -} - -float CursorPair::get_x() const -{ - return (first_->get_x() + second_->get_x()) / 2.0f; -} - -QPoint CursorPair::point() const -{ - return first_->point(); -} - -pv::widgets::Popup* CursorPair::create_popup(QWidget *parent) -{ - (void)parent; - return nullptr; -} - -QRectF CursorPair::label_rect(const QRectF &rect) const -{ - const QSizeF label_size(text_size_ + LabelPadding * 2); - const pair offsets(get_cursor_offsets()); - const pair normal_offsets( - (offsets.first < offsets.second) ? offsets : - make_pair(offsets.second, offsets.first)); - - const float height = label_size.height(); - const float left = max(normal_offsets.first + DeltaPadding, -height); - const float right = min(normal_offsets.second - DeltaPadding, - (float)rect.width() + height); - - return QRectF(left, rect.height() - label_size.height() - - TimeMarker::ArrowSize - 0.5f, - right - left, height); -} - -void CursorPair::paint_label(QPainter &p, const QRect &rect, bool hover) -{ - assert(first_); - assert(second_); - - if (!enabled()) - return; - - const unsigned int prefix = view_.tick_prefix(); - const QColor text_colour = - ViewItem::select_text_colour(Cursor::FillColour); - - p.setPen(text_colour); - compute_text_size(p, prefix); - QRectF delta_rect(label_rect(rect)); - - const int radius = delta_rect.height() / 2; - const QRectF text_rect(delta_rect.intersected( - rect).adjusted(radius, 0, -radius, 0)); - if(text_rect.width() >= text_size_.width()) - { - const int highlight_radius = delta_rect.height() / 2 - 2; - - if (selected()) { - p.setBrush(Qt::transparent); - p.setPen(highlight_pen()); - p.drawRoundedRect(delta_rect, radius, radius); - } - - p.setBrush(hover ? Cursor::FillColour.lighter() : - Cursor::FillColour); - p.setPen(Cursor::FillColour.darker()); - p.drawRoundedRect(delta_rect, radius, radius); - - delta_rect.adjust(1, 1, -1, -1); - p.setPen(Cursor::FillColour.lighter()); - p.drawRoundedRect(delta_rect, highlight_radius, highlight_radius); - - p.setPen(text_colour); - p.drawText(text_rect, Qt::AlignCenter | Qt::AlignVCenter, - pv::util::format_time(second_->time() - first_->time(), prefix, 2)); - } -} - -void CursorPair::paint_back(QPainter &p, const ViewItemPaintParams &pp) { - if (!enabled()) - return; - - p.setPen(Qt::NoPen); - p.setBrush(QBrush(ViewportFillColour)); - - const pair offsets(get_cursor_offsets()); - const int l = (int)max(min( - offsets.first, offsets.second), 0.0f); - const int r = (int)min(max( - offsets.first, offsets.second), (float)pp.width()); - - p.drawRect(l, pp.top(), r - l, pp.height()); -} - -void CursorPair::compute_text_size(QPainter &p, unsigned int prefix) -{ - assert(first_); - assert(second_); - - text_size_ = p.boundingRect(QRectF(), 0, pv::util::format_time( - second_->time() - first_->time(), prefix, 2)).size(); -} - -pair CursorPair::get_cursor_offsets() const -{ - assert(first_); - assert(second_); - - return pair( - (first_->time() - view_.offset()) / view_.scale(), - (second_->time() - view_.offset()) / view_.scale()); -} - -} // namespace view -} // namespace pv