X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fview%2Fcursorpair.cpp;h=e0e3de65f3c9adc427f0ae877e79f0fcb4b0de1e;hb=87a97d8aa169936ec2dcd229df88b8c5b4a1411c;hp=2ff32c53ef9fbbe4d46b2d1d8fb22425ee03626f;hpb=2fae5107535c39adde322393d2f6d18098c0154e;p=pulseview.git
diff --git a/pv/view/cursorpair.cpp b/pv/view/cursorpair.cpp
index 2ff32c5..e0e3de6 100644
--- a/pv/view/cursorpair.cpp
+++ b/pv/view/cursorpair.cpp
@@ -14,12 +14,12 @@
* 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
+ * along with this program; if not, see .
*/
#include "cursorpair.hpp"
+#include "ruler.hpp"
#include "view.hpp"
#include "pv/util.hpp"
@@ -33,9 +33,11 @@ using std::shared_ptr;
using std::pair;
namespace pv {
-namespace view {
+namespace views {
+namespace TraceView {
const int CursorPair::DeltaPadding = 8;
+const QColor CursorPair::ViewportFillColour(220, 231, 243);
CursorPair::CursorPair(View &view) :
TimeItem(view),
@@ -59,8 +61,9 @@ shared_ptr CursorPair::second() const
return second_;
}
-void CursorPair::set_time(double time) {
- const double delta = second_->time() - first_->time();
+void CursorPair::set_time(const pv::util::Timestamp& time)
+{
+ const pv::util::Timestamp delta = second_->time() - first_->time();
first_->set_time(time);
second_->set_time(time + delta);
}
@@ -70,9 +73,9 @@ float CursorPair::get_x() const
return (first_->get_x() + second_->get_x()) / 2.0f;
}
-QPoint CursorPair::point() const
+QPoint CursorPair::point(const QRect &rect) const
{
- return first_->point();
+ return first_->point(rect);
}
pv::widgets::Popup* CursorPair::create_popup(QWidget *parent)
@@ -83,9 +86,7 @@ pv::widgets::Popup* CursorPair::create_popup(QWidget *parent)
QRectF CursorPair::label_rect(const QRectF &rect) const
{
- const QSizeF label_size(
- text_size_.width() + View::LabelPadding.width() * 2,
- text_size_.height() + View::LabelPadding.height() * 2);
+ const QSizeF label_size(text_size_ + LabelPadding * 2);
const pair offsets(get_cursor_offsets());
const pair normal_offsets(
(offsets.first < offsets.second) ? offsets :
@@ -97,25 +98,29 @@ QRectF CursorPair::label_rect(const QRectF &rect) const
(float)rect.width() + height);
return QRectF(left, rect.height() - label_size.height() -
- TimeMarker::ArrowSize - TimeMarker::Offset - 0.5f,
+ TimeMarker::ArrowSize - 0.5f,
right - left, height);
}
-void CursorPair::paint_label(QPainter &p, const QRect &rect)
+void CursorPair::paint_label(QPainter &p, const QRect &rect, bool hover)
{
assert(first_);
assert(second_);
- const unsigned int prefix = view_.tick_prefix();
+ if (!enabled())
+ return;
+
+ const QColor text_colour =
+ ViewItem::select_text_colour(Cursor::FillColour);
- compute_text_size(p, prefix);
+ p.setPen(text_colour);
+ compute_text_size(p);
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())
- {
+ if (text_rect.width() >= text_size_.width()) {
const int highlight_radius = delta_rect.height() / 2 - 2;
if (selected()) {
@@ -124,7 +129,8 @@ void CursorPair::paint_label(QPainter &p, const QRect &rect)
p.drawRoundedRect(delta_rect, radius, radius);
}
- p.setBrush(Cursor::FillColour);
+ p.setBrush(hover ? Cursor::FillColour.lighter() :
+ Cursor::FillColour);
p.setPen(Cursor::FillColour.darker());
p.drawRoundedRect(delta_rect, radius, radius);
@@ -132,49 +138,48 @@ void CursorPair::paint_label(QPainter &p, const QRect &rect)
p.setPen(Cursor::FillColour.lighter());
p.drawRoundedRect(delta_rect, highlight_radius, highlight_radius);
- p.setPen(SelectableItem::select_text_colour(
- Cursor::FillColour));
+ p.setPen(text_colour);
p.drawText(text_rect, Qt::AlignCenter | Qt::AlignVCenter,
- pv::util::format_time(second_->time() - first_->time(), prefix, 2));
+ format_string());
}
-
- // Paint the cursor markers
- first_->paint_label(p, rect);
- second_->paint_label(p, rect);
}
-void CursorPair::draw_viewport_background(QPainter &p,
- const QRect &rect)
+void CursorPair::paint_back(QPainter &p, const ViewItemPaintParams &pp)
{
+ if (!enabled())
+ return;
+
p.setPen(Qt::NoPen);
- p.setBrush(QBrush(View::CursorAreaColour));
+ 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)rect.width());
+ offsets.first, offsets.second), (float)pp.width());
- p.drawRect(l, 0, r - l, rect.height());
+ p.drawRect(l, pp.top(), r - l, pp.height());
}
-void CursorPair::draw_viewport_foreground(QPainter &p,
- const QRect &rect)
+QString CursorPair::format_string()
{
- assert(first_);
- assert(second_);
+ const pv::util::SIPrefix prefix = view_.tick_prefix();
+ const pv::util::Timestamp diff = abs(second_->time() - first_->time());
+
+ const QString s1 = Ruler::format_time_with_distance(
+ diff, diff, prefix, view_.time_unit(), view_.tick_precision(), false);
+ const QString s2 = util::format_time_si(
+ 1 / diff, pv::util::SIPrefix::unspecified, 4, "Hz", false);
- first_->paint(p, rect);
- second_->paint(p, rect);
+ return QString("%1 / %2").arg(s1).arg(s2);
}
-void CursorPair::compute_text_size(QPainter &p, unsigned int prefix)
+void CursorPair::compute_text_size(QPainter &p)
{
assert(first_);
assert(second_);
- text_size_ = p.boundingRect(QRectF(), 0, pv::util::format_time(
- second_->time() - first_->time(), prefix, 2)).size();
+ text_size_ = p.boundingRect(QRectF(), 0, format_string()).size();
}
pair CursorPair::get_cursor_offsets() const
@@ -183,9 +188,10 @@ pair CursorPair::get_cursor_offsets() const
assert(second_);
return pair(
- (first_->time() - view_.offset()) / view_.scale(),
- (second_->time() - view_.offset()) / view_.scale());
+ ((first_->time() - view_.offset()) / view_.scale()).convert_to(),
+ ((second_->time() - view_.offset()) / view_.scale()).convert_to());
}
-} // namespace view
+} // namespace TraceView
+} // namespace views
} // namespace pv