sigsession.cpp
signal.cpp
pv/view/header.cpp
+ pv/view/ruler.cpp
pv/view/view.cpp
pv/view/viewport.cpp
)
samplingbar.h
sigsession.h
pv/view/header.h
+ pv/view/ruler.h
pv/view/view.h
pv/view/viewport.h
)
--- /dev/null
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * 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 "ruler.h"
+#include "view.h"
+
+#include "../../extdef.h"
+
+#include <assert.h>
+#include <math.h>
+
+#include <QPainter>
+#include <QTextStream>
+
+namespace pv {
+namespace view {
+
+const int Ruler::MinorTickSubdivision = 4;
+const int Ruler::ScaleUnits[3] = {1, 2, 5};
+
+const QString Ruler::SIPrefixes[9] =
+ {"f", "p", "n", QChar(0x03BC), "m", "", "k", "M", "G"};
+const int Ruler::FirstSIPrefixPower = -15;
+
+Ruler::Ruler(View &parent) :
+ QWidget(&parent),
+ _view(parent)
+{
+}
+
+void Ruler::paintEvent(QPaintEvent *event)
+{
+ QPainter p(this);
+
+ const double MinSpacing = 80;
+
+ const double min_period = _view.scale() * MinSpacing;
+
+ const int order = (int)floorf(log10f(min_period));
+ const double order_decimal = pow(10, order);
+
+ int unit = 0;
+ double tick_period = 0.0f;
+
+ do
+ {
+ tick_period = order_decimal * ScaleUnits[unit++];
+ } while(tick_period < min_period && unit < countof(ScaleUnits));
+
+ const int prefix = (order - FirstSIPrefixPower) / 3;
+ assert(prefix >= 0);
+ assert(prefix < countof(SIPrefixes));
+
+ const int text_height = p.boundingRect(0, 0, INT_MAX, INT_MAX,
+ Qt::AlignLeft | Qt::AlignTop, "8").height();
+
+ // Draw the tick marks
+ p.setPen(Qt::black);
+
+ const double minor_tick_period = tick_period / MinorTickSubdivision;
+ const double first_major_division =
+ floor(_view.offset() / tick_period);
+ const double first_minor_division =
+ ceil(_view.offset() / minor_tick_period);
+ const double t0 = first_major_division * tick_period;
+
+ int division = (int)round(first_minor_division -
+ first_major_division * MinorTickSubdivision);
+ while(1)
+ {
+ const double t = t0 + division * minor_tick_period;
+ const double x = (t - _view.offset()) / _view.scale();
+
+ if(x >= width())
+ break;
+
+ if(division % MinorTickSubdivision == 0)
+ {
+ // Draw a major tick
+ QString s;
+ QTextStream ts(&s);
+ ts << (t / order_decimal) << SIPrefixes[prefix] << "s";
+ p.drawText(x, 0, 0, text_height, Qt::AlignCenter |
+ Qt::AlignTop | Qt::TextDontClip, s);
+ p.drawLine(x, text_height, x, height());
+ }
+ else
+ {
+ // Draw a minor tick
+ p.drawLine(x, (text_height + height()) / 2,
+ x, height());
+ }
+
+ division++;
+ }
+
+ p.end();
+}
+
+} // namespace view
+} // namespace pv
--- /dev/null
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2012 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * 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
+ */
+
+#ifndef PV_VIEW_RULER_H
+#define PV_VIEW_RULER_H
+
+#include <QWidget>
+
+namespace pv {
+namespace view {
+
+class View;
+
+class Ruler : public QWidget
+{
+ Q_OBJECT
+
+private:
+ static const int MinorTickSubdivision;
+ static const int ScaleUnits[3];
+
+ static const QString SIPrefixes[9];
+ static const int FirstSIPrefixPower;
+
+public:
+ Ruler(View &parent);
+
+private:
+ void paintEvent(QPaintEvent *event);
+
+private:
+ View &_view;
+};
+
+} // namespace view
+} // namespace pv
+
+#endif // PV_VIEW_HEADER_H
#include <QScrollBar>
#include "header.h"
+#include "ruler.h"
#include "view.h"
#include "viewport.h"
QAbstractScrollArea(parent),
_session(session),
_viewport(new Viewport(*this)),
+ _ruler(new Ruler(*this)),
_header(new Header(*this)),
_data_length(0),
_scale(1e-6),
connect(&_session, SIGNAL(data_updated()),
this, SLOT(data_updated()));
- setViewportMargins(LabelMarginWidth, 0, 0, 0);
+ setViewportMargins(LabelMarginWidth, RulerHeight, 0, 0);
setViewport(_viewport);
}
{
_scale = scale;
_offset = offset;
+
update_scroll();
+ _ruler->update();
_viewport->update();
}
_scale *= pow(3.0/2.0, -steps);
_scale = max(min(_scale, MaxScale), MinScale);
_offset = cursor_offset - _scale * offset;
+
+ _ruler->update();
_viewport->update();
update_scroll();
}
void View::resizeEvent(QResizeEvent *e)
{
- _header->setGeometry(0, RulerHeight,
+ _ruler->setGeometry(_viewport->x(), 0,
+ _viewport->width(), _viewport->y());
+ _header->setGeometry(0, _viewport->y(),
_viewport->x(), _viewport->height());
update_scroll();
}
void View::h_scroll_value_changed(int value)
{
_offset = _scale * value;
+ _ruler->update();
_viewport->update();
}
namespace view {
class Header;
+class Ruler;
class Viewport;
class View : public QAbstractScrollArea {
SigSession &_session;
Viewport *_viewport;
+ Ruler *_ruler;
Header *_header;
uint64_t _data_length;
#include "../../sigsession.h"
#include "../../signal.h"
-#include "../../extdef.h"
-
#include <QMouseEvent>
-#include <QTextStream>
-
-#include <math.h>
#include <boost/foreach.hpp>
namespace pv {
namespace view {
-const int Viewport::MinorTickSubdivision = 4;
-const int Viewport::ScaleUnits[3] = {1, 2, 5};
-
-const QString Viewport::SIPrefixes[9] =
- {"f", "p", "n", QChar(0x03BC), "m", "", "k", "M", "G"};
-const int Viewport::FirstSIPrefixPower = -15;
-
Viewport::Viewport(View &parent) :
QGLWidget(&parent),
_view(parent)
// Plot the signal
glEnable(GL_SCISSOR_TEST);
glScissor(0, 0, width(), height());
- offset = View::RulerHeight - _view.v_offset();
+ offset = -_view.v_offset();
BOOST_FOREACH(const shared_ptr<Signal> s, sigs)
{
assert(s);
glPopMatrix();
QPainter painter(this);
- painter.setRenderHint(QPainter::Antialiasing);
-
- // Paint the ruler
- paint_ruler(painter);
-
painter.end();
}
glMatrixMode(GL_MODELVIEW);
}
-void Viewport::paint_ruler(QPainter &p)
-{
- const double MinSpacing = 80;
-
- const double min_period = _view.scale() * MinSpacing;
-
- const int order = (int)floorf(log10f(min_period));
- const double order_decimal = pow(10, order);
-
- int unit = 0;
- double tick_period = 0.0f;
-
- do
- {
- tick_period = order_decimal * ScaleUnits[unit++];
- } while(tick_period < min_period && unit < countof(ScaleUnits));
-
- const int prefix = (order - FirstSIPrefixPower) / 3;
- assert(prefix >= 0);
- assert(prefix < countof(SIPrefixes));
-
- const int text_height = p.boundingRect(0, 0, INT_MAX, INT_MAX,
- Qt::AlignLeft | Qt::AlignTop, "8").height();
-
- // Draw the tick marks
- p.setPen(Qt::black);
-
- const double minor_tick_period = tick_period / MinorTickSubdivision;
- const double first_major_division =
- floor(_view.offset() / tick_period);
- const double first_minor_division =
- ceil(_view.offset() / minor_tick_period);
- const double t0 = first_major_division * tick_period;
-
- int division = (int)round(first_minor_division -
- first_major_division * MinorTickSubdivision);
- while(1)
- {
- const double t = t0 + division * minor_tick_period;
- const double x = (t - _view.offset()) / _view.scale();
-
- if(x >= width())
- break;
-
- if(division % MinorTickSubdivision == 0)
- {
- // Draw a major tick
- QString s;
- QTextStream ts(&s);
- ts << (t / order_decimal) << SIPrefixes[prefix] << "s";
- p.drawText(x, 0, 0, text_height, Qt::AlignCenter | Qt::AlignTop |
- Qt::TextDontClip, s);
- p.drawLine(x, text_height, x, View::RulerHeight);
- }
- else
- {
- // Draw a minor tick
- p.drawLine(x,
- (text_height + View::RulerHeight) / 2, x,
- View::RulerHeight);
- }
-
- division++;
- }
-}
-
} // namespace view
} // namespace pv
{
Q_OBJECT
-private:
- static const int MinorTickSubdivision;
- static const int ScaleUnits[3];
-
- static const QString SIPrefixes[9];
- static const int FirstSIPrefixPower;
-
public:
explicit Viewport(View &parent);
private:
void setup_viewport(int width, int height);
- void paint_ruler(QPainter &p);
-
private:
View &_view;