#include "view.hpp"
#include "pv/util.hpp"
+#include <QApplication>
#include <QBrush>
#include <QPainter>
#include <QPointF>
#include <cassert>
#include <cstdio>
-#include <extdef.h>
-
using std::shared_ptr;
namespace pv {
namespace view {
-const QColor Cursor::LineColour(32, 74, 135);
const QColor Cursor::FillColour(52, 101, 164);
-const QColor Cursor::HighlightColour(83, 130, 186);
-const QColor Cursor::TextColour(Qt::white);
-
-const int Cursor::Offset = 1;
-
-const int Cursor::ArrowSize = 4;
Cursor::Cursor(View &view, double time) :
- TimeMarker(view, LineColour, time)
+ TimeMarker(view, FillColour, time)
{
}
const float x = (time_ - view_.offset()) / view_.scale();
+ QFontMetrics m(QApplication::font());
+ QSize text_size = m.boundingRect(
+ pv::util::format_time(time_, view_.tick_prefix(), 2)).size();
+
const QSizeF label_size(
- text_size_.width() + View::LabelPadding.width() * 2,
- text_size_.height() + View::LabelPadding.height() * 2);
+ text_size.width() + View::LabelPadding.width() * 2,
+ text_size.height() + View::LabelPadding.height() * 2);
const float top = rect.height() - label_size.height() -
- Cursor::Offset - Cursor::ArrowSize - 0.5f;
+ TimeMarker::Offset - TimeMarker::ArrowSize - 0.5f;
const float height = label_size.height();
if (time_ > other->time())
label_size.width(), height);
}
-void Cursor::paint_label(QPainter &p, const QRect &rect)
-{
- const shared_ptr<Cursor> other(get_other_cursor());
- assert(other);
-
- const unsigned int prefix = view_.tick_prefix();
-
- compute_text_size(p, prefix);
- const QRectF r(get_label_rect(rect));
-
- const QPointF left_points[] = {
- r.topLeft(),
- r.topRight(),
- r.bottomRight(),
- QPointF(r.left() + ArrowSize, r.bottom()),
- QPointF(r.left(), rect.bottom()),
- };
-
- const QPointF right_points[] = {
- r.topRight(),
- r.topLeft(),
- r.bottomLeft(),
- QPointF(r.right() - ArrowSize, r.bottom()),
- QPointF(r.right(), rect.bottom()),
- };
-
- const QPointF left_highlight_points[] = {
- QPointF(r.left() + 1, r.top() + 1),
- QPointF(r.right() - 1, r.top() + 1),
- QPointF(r.right() - 1, r.bottom() - 1),
- QPointF(r.left() + ArrowSize - 1, r.bottom() - 1),
- QPointF(r.left() + 1, rect.bottom() - 1),
- };
-
- const QPointF right_highlight_points[] = {
- QPointF(r.right() - 1, r.top() + 1),
- QPointF(r.left() + 1, r.top() + 1),
- QPointF(r.left() + 1, r.bottom() - 1),
- QPointF(r.right() - ArrowSize + 1, r.bottom() - 1),
- QPointF(r.right() - 1, rect.bottom() - 1),
- };
-
- const QPointF *const points = (time_ > other->time()) ?
- left_points : right_points;
- const QPointF *const highlight_points = (time_ > other->time()) ?
- left_highlight_points : right_highlight_points;
-
- if (selected()) {
- p.setPen(highlight_pen());
- p.setBrush(Qt::transparent);
- p.drawPolygon(points, countof(left_points));
- }
-
- p.setPen(Qt::transparent);
- p.setBrush(FillColour);
- p.drawPolygon(points, countof(left_points));
-
- p.setPen(HighlightColour);
- p.setBrush(Qt::transparent);
- p.drawPolygon(highlight_points, countof(left_highlight_points));
-
- p.setPen(LineColour);
- p.setBrush(Qt::transparent);
- p.drawPolygon(points, countof(left_points));
-
- p.setPen(TextColour);
- p.drawText(r, Qt::AlignCenter | Qt::AlignVCenter,
- pv::util::format_time(time_, prefix, 2));
-}
-
-void Cursor::compute_text_size(QPainter &p, unsigned int prefix)
-{
- text_size_ = p.boundingRect(QRectF(), 0,
- pv::util::format_time(time_, prefix, 2)).size();
-}
-
shared_ptr<Cursor> Cursor::get_other_cursor() const
{
const CursorPair &cursors = view_.cursors();
Q_OBJECT
public:
- static const QColor LineColour;
static const QColor FillColour;
- static const QColor HighlightColour;
- static const QColor TextColour;
-
- static const int Offset;
-
- static const int ArrowSize;
public:
/**
*/
QRectF get_label_rect(const QRect &rect) const;
- /**
- * Paints the cursor's label to the ruler.
- * @param p The painter to draw with.
- * @param rect The rectangle of the ruler client area.
- */
- void paint_label(QPainter &p, const QRect &rect);
-
private:
- void compute_text_size(QPainter &p, unsigned int prefix);
-
std::shared_ptr<Cursor> get_other_cursor() const;
-
-private:
- QSizeF text_size_;
};
} // namespace view
(float)rect.width() + height);
return QRectF(left, rect.height() - label_size.height() -
- Cursor::ArrowSize - Cursor::Offset - 0.5f,
+ TimeMarker::ArrowSize - TimeMarker::Offset - 0.5f,
right - left, height);
}
const int highlight_radius = delta_rect.height() / 2 - 2;
p.setBrush(Cursor::FillColour);
- p.setPen(Cursor::LineColour);
+ p.setPen(Cursor::FillColour.darker());
p.drawRoundedRect(delta_rect, radius, radius);
delta_rect.adjust(1, 1, -1, -1);
- p.setPen(Cursor::HighlightColour);
+ p.setPen(Cursor::FillColour.lighter());
p.drawRoundedRect(delta_rect, highlight_radius, highlight_radius);
- p.setPen(Cursor::TextColour);
+ p.setPen(SelectableItem::select_text_colour(
+ Cursor::FillColour));
p.drawText(text_rect, Qt::AlignCenter | Qt::AlignVCenter,
pv::util::format_time(second_->time() - first_->time(), prefix, 2));
}
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <algorithm>
+
+#include <extdef.h>
+
#include "timemarker.hpp"
#include "view.hpp"
#include <QFormLayout>
#include <QPainter>
+#include <pv/util.hpp>
#include <pv/widgets/popup.hpp>
+using std::max;
+using std::min;
+
namespace pv {
namespace view {
+const int TimeMarker::ArrowSize = 4;
+const int TimeMarker::Offset = 1;
+
TimeMarker::TimeMarker(View &view, const QColor &colour, double time) :
view_(view),
colour_(colour),
void TimeMarker::paint(QPainter &p, const QRect &rect)
{
const float x = get_x();
- p.setPen(colour_);
+ p.setPen(colour_.darker());
p.drawLine(QPointF(x, rect.top()), QPointF(x, rect.bottom()));
}
+void TimeMarker::paint_label(QPainter &p, const QRect &rect)
+{
+ const qreal x = (time_ - view_.offset()) / view_.scale();
+ const QRectF r(get_label_rect(rect));
+
+ const QPointF points[] = {
+ r.topLeft(),
+ r.bottomLeft(),
+ QPointF(max(r.left(), x - ArrowSize), r.bottom()),
+ QPointF(x, rect.bottom()),
+ QPointF(min(r.right(), x + ArrowSize), r.bottom()),
+ r.bottomRight(),
+ r.topRight()
+ };
+
+ const QPointF highlight_points[] = {
+ QPointF(r.left() + 1, r.top() + 1),
+ QPointF(r.left() + 1, r.bottom() - 1),
+ QPointF(max(r.left() + 1, x - ArrowSize), r.bottom() - 1),
+ QPointF(min(max(r.left() + 1, x), r.right() - 1),
+ rect.bottom() - 1),
+ QPointF(min(r.right() - 1, x + ArrowSize), r.bottom() - 1),
+ QPointF(r.right() - 1, r.bottom() - 1),
+ QPointF(r.right() - 1, r.top() + 1),
+ };
+
+ if (selected()) {
+ p.setPen(highlight_pen());
+ p.setBrush(Qt::transparent);
+ p.drawPolygon(points, countof(points));
+ }
+
+ p.setPen(Qt::transparent);
+ p.setBrush(colour_);
+ p.drawPolygon(points, countof(points));
+
+ p.setPen(colour_.lighter());
+ p.setBrush(Qt::transparent);
+ p.drawPolygon(highlight_points, countof(highlight_points));
+
+ p.setPen(colour_.darker());
+ p.setBrush(Qt::transparent);
+ p.drawPolygon(points, countof(points));
+
+ p.setPen(select_text_colour(colour_));
+ p.drawText(r, Qt::AlignCenter | Qt::AlignVCenter,
+ pv::util::format_time(time_, view_.tick_prefix(), 2));
+}
+
pv::widgets::Popup* TimeMarker::create_popup(QWidget *parent)
{
using pv::widgets::Popup;
{
Q_OBJECT
+public:
+ static const int ArrowSize;
+ static const int Offset;
+
protected:
/**
* Constructor.
* @param p The painter to draw with.
* @param rect The rectangle of the ruler client area.
*/
- virtual void paint_label(QPainter &p, const QRect &rect) = 0;
+ void paint_label(QPainter &p, const QRect &rect);
pv::widgets::Popup* create_popup(QWidget *parent);