2
0
forked from Ivasoft/DSView

improve operations of vDial/hDial

This commit is contained in:
DreamSourceLab
2015-10-24 00:32:41 +08:00
parent 705819fac3
commit df05c5c9f9
15 changed files with 481 additions and 354 deletions

View File

@@ -71,6 +71,7 @@
#include "view/trace.h"
#include "view/signal.h"
#include "view/dsosignal.h"
#include "view/logicsignal.h"
/* __STDC_FORMAT_MACROS is required for PRIu64 and friends (in C++). */
#define __STDC_FORMAT_MACROS
@@ -680,7 +681,12 @@ bool MainWindow::load_session(QString name)
if ((s->get_index() == obj["index"].toDouble()) &&
(s->get_type() == obj["type"].toDouble())) {
s->set_colour(QColor(obj["colour"].toString()));
s->set_trig(obj["strigger"].toDouble());
boost::shared_ptr<view::LogicSignal> logicSig;
if (logicSig = dynamic_pointer_cast<view::LogicSignal>(s)) {
logicSig->set_trig(obj["strigger"].toDouble());
}
boost::shared_ptr<view::DsoSignal> dsoSig;
if (dsoSig = dynamic_pointer_cast<view::DsoSignal>(s)) {
dsoSig->load_settings();
@@ -755,7 +761,12 @@ bool MainWindow::store_session(QString name)
s_obj["enabled"] = s->enabled();
s_obj["name"] = s->get_name();
s_obj["colour"] = QJsonValue::fromVariant(s->get_colour());
s_obj["strigger"] = s->get_trig();
boost::shared_ptr<view::LogicSignal> logicSig;
if (logicSig = dynamic_pointer_cast<view::LogicSignal>(s)) {
s_obj["strigger"] = logicSig->get_trig();
}
boost::shared_ptr<view::DsoSignal> dsoSig;
if (dsoSig = dynamic_pointer_cast<view::DsoSignal>(s)) {
s_obj["vdiv"] = QJsonValue::fromVariant(static_cast<qulonglong>(dsoSig->get_vDialValue()));

View File

@@ -543,9 +543,12 @@ void SigSession::sample_thread_proc(boost::shared_ptr<device::DevInst> dev_inst,
BOOST_FOREACH(const boost::shared_ptr<view::Signal> s, _signals)
{
assert(s);
if (s->get_trig() != 0) {
ds_trigger_set_en(true);
s->set_trig(s->get_trig());
boost::shared_ptr<view::LogicSignal> logicSig;
if (logicSig = dynamic_pointer_cast<view::LogicSignal>(s)) {
if (logicSig->get_trig() != 0) {
ds_trigger_set_en(true);
logicSig->set_trig(logicSig->get_trig());
}
}
}
} else {
@@ -799,8 +802,10 @@ void SigSession::reload()
std::vector< boost::shared_ptr<view::Signal> >::iterator i = _signals.begin();
while (i != _signals.end()) {
if ((*i)->get_index() == probe->index) {
signal = boost::shared_ptr<view::Signal>(
new view::LogicSignal(**i, _logic_data, probe));
boost::shared_ptr<view::LogicSignal> logicSig;
if (logicSig = dynamic_pointer_cast<view::LogicSignal>(*i))
signal = boost::shared_ptr<view::Signal>(
new view::LogicSignal(logicSig, _logic_data, probe));
break;
}
i++;

View File

@@ -821,13 +821,12 @@ int DecodeTrace::rows_size()
return _decoder_stack->cur_rows_size();
}
void DecodeTrace::paint_type_options(QPainter &p, int right, bool hover, int action)
void DecodeTrace::paint_type_options(QPainter &p, int right, const QPoint pt)
{
(void)hover;
(void)action;
(void)pt;
int y = get_y();
const QRectF group_index_rect = get_rect("groupIndex", y, right);
const QRectF group_index_rect = get_rect(CHNLREG, y, right);
QString index_string;
int last_index;
p.setPen(Qt::transparent);
@@ -849,5 +848,18 @@ void DecodeTrace::paint_type_options(QPainter &p, int right, bool hover, int act
p.drawText(group_index_rect, Qt::AlignRight | Qt::AlignVCenter, index_string);
}
QRectF DecodeTrace::get_rect(DecodeSetRegions type, int y, int right)
{
const QSizeF name_size(right - get_leftWidth() - get_rightWidth(), SquareWidth);
if (type == CHNLREG)
return QRectF(
get_leftWidth() + name_size.width() + Margin,
y - SquareWidth / 2,
SquareWidth * SquareNum, SquareWidth);
else
return QRectF(0, 0, 0, 0);
}
} // namespace view
} // namespace pv

View File

@@ -71,6 +71,11 @@ private:
const srd_channel *_pdch;
};
enum DecodeSetRegions{
NONEREG = -1,
CHNLREG,
};
private:
static const QColor DecodeColours[4];
static const QColor ErrorBgColour;
@@ -125,8 +130,10 @@ public:
int rows_size();
QRectF get_rect(DecodeSetRegions type, int y, int right);
protected:
void paint_type_options(QPainter &p, int right, bool hover, int action);
void paint_type_options(QPainter &p, int right, const QPoint pt);
private:
void create_popup_form();

View File

@@ -25,7 +25,7 @@ dslDial::~dslDial()
{
}
void dslDial::paint(QPainter &p, QRectF dialRect, QColor dialColor)
void dslDial::paint(QPainter &p, QRectF dialRect, QColor dialColor, bool hover, bool inc)
{
p.setRenderHint(QPainter::Antialiasing, true);
p.setPen(dialColor);
@@ -64,8 +64,22 @@ void dslDial::paint(QPainter &p, QRectF dialRect, QColor dialColor)
}
QString pText = QString::number(displayValue) + _unit[displayIndex] + "/div";
QFontMetrics fm(p.font());
p.drawText(QRectF(dialRect.left(), dialRect.bottom()-dialRect.width()*0.3+fm.height()*0.5, dialRect.width(), fm.height()), Qt::AlignCenter, pText);
const QRectF valueRect = QRectF(dialRect.left(), dialRect.bottom()-dialRect.width()*0.3+fm.height()*0.5, dialRect.width(), fm.height());
p.drawText(valueRect, Qt::AlignCenter, pText);
// draw +/-
if (hover) {
const int arcInc = 15;
const QRectF hoverRect = QRectF(dialRect.left()-arcInc, dialRect.top()-arcInc, dialRect.width()+arcInc*2, dialRect.height()+arcInc*2);
const double arcSpan = hoverRect.width()/(2*sqrt(2));
p.drawArc(hoverRect, 135 * 16, -90 * 16);
if (inc)
p.drawLine(hoverRect.center().x()+arcSpan, hoverRect.center().y()-arcSpan,
hoverRect.center().x()+arcSpan-4, hoverRect.center().y()-arcSpan-10);
else
p.drawLine(hoverRect.center().x()-arcSpan, hoverRect.center().y()-arcSpan,
hoverRect.center().x()-arcSpan+4, hoverRect.center().y()-arcSpan-10);
}
}
void dslDial::set_sel(uint64_t sel)

View File

@@ -20,7 +20,7 @@ public:
* @param p the QPainter to paint into.
* @param dialRect the rectangle to draw the dial at.
**/
void paint(QPainter &p, QRectF dialRect, QColor dialColor);
void paint(QPainter &p, QRectF dialRect, QColor dialColor, bool hover, bool inc);
// set/get current select
void set_sel(uint64_t sel);

View File

@@ -95,10 +95,10 @@ const QString DsoSignal::hDialUnit[DsoSignal::hDialUnitCount] = {
};
const QColor DsoSignal::SignalColours[4] = {
QColor(238, 178, 17, 200), // dsYellow
QColor(0, 153, 37, 200), // dsGreen
QColor(213, 15, 37, 200), // dsRed
QColor(17, 133, 209, 200) // dsBlue
QColor(238, 178, 17, 255), // dsYellow
QColor(0, 153, 37, 255), // dsGreen
QColor(213, 15, 37, 255), // dsRed
QColor(17, 133, 209, 255) // dsBlue
};
@@ -1011,30 +1011,31 @@ const std::vector< std::pair<uint64_t, bool> > DsoSignal::cur_edges() const
}
void DsoSignal::paint_type_options(QPainter &p, int right, bool hover, int action)
void DsoSignal::paint_type_options(QPainter &p, int right, const QPoint pt)
{
int y = get_y();
const QRectF vDial_rect = get_rect("vDial", y, right);
const QRectF x1_rect = get_rect("x1", y, right);
const QRectF x10_rect = get_rect("x10", y, right);
const QRectF x100_rect = get_rect("x100", y, right);
const QRectF hDial_rect = get_rect("hDial", y, right);
const QRectF acdc_rect = get_rect("acdc", y, right);
const QRectF chEn_rect = get_rect("chEn", y, right);
const QRectF vDial_rect = get_rect(DSO_VDIAL, y, right);
const QRectF vInc_rect = get_rect(DSO_VINC, y, right);
const QRectF hDial_rect = get_rect(DSO_HDIAL, y, right);
const QRectF hInc_rect = get_rect(DSO_HINC, y, right);
QColor vDial_color = _vDialActive ? dsActive : dsDisable;
QColor hDial_color = _hDialActive ? dsActive : dsDisable;
_vDial->paint(p, vDial_rect, vDial_color);
_hDial->paint(p, hDial_rect, hDial_color);
const QRectF x1_rect = get_rect(DSO_X1, y, right);
const QRectF x10_rect = get_rect(DSO_X10, y, right);
const QRectF x100_rect = get_rect(DSO_X100, y, right);
const QRectF acdc_rect = get_rect(DSO_ACDC, y, right);
const QRectF chEn_rect = get_rect(DSO_CHEN, y, right);
_vDial->paint(p, vDial_rect, _colour, vDial_rect.contains(pt), vInc_rect.contains(pt));
_hDial->paint(p, hDial_rect, _colour, hDial_rect.contains(pt), hInc_rect.contains(pt));
p.setPen(Qt::transparent);
p.setBrush((hover && action == CHEN) ? _colour.darker() : _colour);
p.setBrush(chEn_rect.contains(pt) ? _colour.darker() : _colour);
p.drawRect(chEn_rect);
p.setPen(Qt::white);
p.drawText(chEn_rect, Qt::AlignCenter | Qt::AlignVCenter, enabled() ? tr("EN") : tr("DIS"));
p.setPen(Qt::transparent);
p.setBrush(enabled() ? ((hover && action == ACDC) ? _colour.darker() : _colour) : dsDisable);
p.setBrush(enabled() ? (acdc_rect.contains(pt) ? _colour.darker() : _colour) : dsDisable);
p.drawRect(acdc_rect);
p.setPen(Qt::white);
p.drawText(acdc_rect, Qt::AlignCenter | Qt::AlignVCenter, (_acCoupling == SR_GND_COUPLING) ? tr("GND") :
@@ -1053,19 +1054,186 @@ void DsoSignal::paint_type_options(QPainter &p, int right, bool hover, int actio
}
p.setPen(Qt::white);
p.setBrush((enabled() && (factor == 100)) ? ((hover && action == X100) ? _colour.darker() : _colour) : ((hover && action == X100) ? _colour.darker() : dsDisable));
p.setBrush((enabled() && (factor == 100)) ? (x100_rect.contains(pt) ? _colour.darker() : _colour) : (x100_rect.contains(pt) ? _colour.darker() : dsDisable));
p.drawRect(x100_rect);
p.drawText(x100_rect, Qt::AlignCenter | Qt::AlignVCenter, "x100");
p.setBrush((enabled() && (factor == 10)) ? ((hover && action == X10) ? _colour.darker() : _colour) : ((hover && action == X10) ? _colour.darker() : dsDisable));
p.setBrush((enabled() && (factor == 10)) ? (x10_rect.contains(pt) ? _colour.darker() : _colour) : (x10_rect.contains(pt) ? _colour.darker() : dsDisable));
p.drawRect(x10_rect);
p.drawText(x10_rect, Qt::AlignCenter | Qt::AlignVCenter, "x10");
p.setBrush((enabled() && (factor == 1)) ? ((hover && action == X1) ? _colour.darker() : _colour) : ((hover && action == X1) ? _colour.darker() : dsDisable));
p.setBrush((enabled() && (factor == 1)) ? (x1_rect.contains(pt) ? _colour.darker() : _colour) : (x1_rect.contains(pt) ? _colour.darker() : dsDisable));
p.drawRect(x1_rect);
p.drawText(x1_rect, Qt::AlignCenter | Qt::AlignVCenter, "x1");
}
bool DsoSignal::mouse_double_click(int right, const QPoint pt)
{
int y = get_zeroPos();
const QRectF label_rect = Trace::get_rect("label", y, right);
if (label_rect.contains(pt)) {
this->auto_set();
return true;
}
return false;
}
bool DsoSignal::mouse_press(int right, const QPoint pt)
{
int y = get_y();
bool setted = false;
const vector< boost::shared_ptr<Trace> > traces(_view->get_traces());
const QRectF vDec_rect = get_rect(DSO_VDEC, y, right);
const QRectF vInc_rect = get_rect(DSO_VINC, y, right);
const QRectF hDec_rect = get_rect(DSO_HDEC, y, right);
const QRectF hInc_rect = get_rect(DSO_HINC, y, right);
const QRectF chEn_rect = get_rect(DSO_CHEN, y, right);
const QRectF acdc_rect = get_rect(DSO_ACDC, y, right);
const QRectF x1_rect = get_rect(DSO_X1, y, right);
const QRectF x10_rect = get_rect(DSO_X10, y, right);
const QRectF x100_rect = get_rect(DSO_X100, y, right);
if (enabled()) {
if (vDec_rect.contains(pt)) {
go_vDialPre();
} else if (vInc_rect.contains(pt)) {
go_vDialNext();
} else if (hDec_rect.contains(pt)) {
boost::shared_ptr<view::DsoSignal> dsoSig;
BOOST_FOREACH(const boost::shared_ptr<Trace> t, traces) {
if (dsoSig = dynamic_pointer_cast<view::DsoSignal>(t)) {
dsoSig->go_hDialPre(setted);
setted = true;
}
}
} else if (hInc_rect.contains(pt)) {
boost::shared_ptr<view::DsoSignal> dsoSig;
BOOST_FOREACH(const boost::shared_ptr<Trace> t, traces) {
if (dsoSig = dynamic_pointer_cast<view::DsoSignal>(t)) {
dsoSig->go_hDialNext(setted);
setted = true;
}
}
} else if (chEn_rect.contains(pt)) {
if (!_view->session().get_data_lock())
set_enable(!enabled());
} else if (acdc_rect.contains(pt)) {
if (strcmp(_view->session().get_device()->dev_inst()->driver->name, "DSLogic") == 0)
set_acCoupling((get_acCoupling()+1)%2);
else
set_acCoupling((get_acCoupling()+1)%3);
} else if (x1_rect.contains(pt)) {
set_factor(1);
} else if (x10_rect.contains(pt)) {
set_factor(10);
} else if (x100_rect.contains(pt)) {
set_factor(100);
} else {
return false;
}
return true;
}
return false;
}
bool DsoSignal::mouse_wheel(int right, const QPoint pt, const int shift)
{
int y = get_y();
const vector< boost::shared_ptr<Trace> > traces(
_view->get_traces());
bool setted = false;
const QRectF vDial_rect = get_rect(DSO_VDIAL, y, right);
const QRectF hDial_rect = get_rect(DSO_HDIAL, y, right);
if (vDial_rect.contains(pt)) {
if (shift > 1.0)
go_vDialNext();
else if (shift < -1.0)
go_vDialPre();
return true;
} else if (hDial_rect.contains(pt)) {
boost::shared_ptr<view::DsoSignal> dsoSig;
BOOST_FOREACH(const boost::shared_ptr<Trace> t, traces) {
if (dsoSig = dynamic_pointer_cast<view::DsoSignal>(t)) {
if (shift > 1.0) {
dsoSig->go_hDialNext(setted);
setted = true;
} else if (shift < -1.0) {
dsoSig->go_hDialPre(setted);
setted = true;
}
}
}
} else {
return false;
}
return true;
}
QRectF DsoSignal::get_rect(DsoSetRegions type, int y, int right)
{
const QSizeF name_size(right - get_leftWidth() - get_rightWidth(), SquareWidth);
if (type == DSO_VDIAL)
return QRectF(
get_leftWidth() + name_size.width() + SquareWidth*0.5 + Margin,
y - SquareWidth * SquareNum,
SquareWidth * (SquareNum-1), SquareWidth * (SquareNum-1));
else if (type == DSO_VDEC)
return QRectF(
get_leftWidth() + name_size.width() + SquareWidth*0.5 + Margin,
y - SquareWidth * SquareNum,
SquareWidth * (SquareNum-1) / 2, SquareWidth * (SquareNum-1));
else if (type == DSO_VINC)
return QRectF(
get_leftWidth() + name_size.width() + SquareWidth*0.5 + Margin + SquareWidth * (SquareNum-1) / 2,
y - SquareWidth * SquareNum,
SquareWidth * (SquareNum-1) / 2, SquareWidth * (SquareNum-1));
else if (type == DSO_HDIAL)
return QRectF(
get_leftWidth() + name_size.width() + SquareWidth*0.5 + Margin,
y + SquareWidth * 1.5,
SquareWidth * (SquareNum-1), SquareWidth * (SquareNum-1));
else if (type == DSO_HDEC)
return QRectF(
get_leftWidth() + name_size.width() + SquareWidth*0.5 + Margin,
y + SquareWidth * 1.5,
SquareWidth * (SquareNum-1) / 2, SquareWidth * (SquareNum-1));
else if (type == DSO_HINC)
return QRectF(
get_leftWidth() + name_size.width() + SquareWidth*0.5 + Margin + SquareWidth * (SquareNum-1) / 2,
y + SquareWidth * 1.5,
SquareWidth * (SquareNum-1) / 2, SquareWidth * (SquareNum-1));
else if (type == DSO_X1)
return QRectF(
get_leftWidth() + name_size.width() + SquareWidth*0.5 + Margin - 45,
y - SquareWidth - SquareWidth * (SquareNum-1) * 0.85,
SquareWidth * 1.75, SquareWidth);
else if (type == DSO_X10)
return QRectF(
get_leftWidth() + name_size.width() + SquareWidth*0.5 + Margin - 45,
y - SquareWidth - SquareWidth * (SquareNum-1) * 0.55,
SquareWidth * 1.75, SquareWidth);
else if (type == DSO_X100)
return QRectF(
get_leftWidth() + name_size.width() + SquareWidth*0.5 + Margin - 45,
y - SquareWidth - SquareWidth * (SquareNum-1) * 0.25,
SquareWidth * 1.75, SquareWidth);
else if (type == DSO_CHEN)
return QRectF(
get_leftWidth() + name_size.width() + SquareWidth*0.75 + Margin,
y - SquareWidth / 2,
SquareWidth * 1.5, SquareWidth);
else if (type == DSO_ACDC)
return QRectF(
get_leftWidth() + name_size.width() + SquareWidth*2.75 + Margin,
y - SquareWidth / 2,
SquareWidth * 1.5, SquareWidth);
else
return QRectF(0, 0, 0, 0);
}
void DsoSignal::paint_measure(QPainter &p)
{
sr_status status;

View File

@@ -75,6 +75,21 @@ public:
DSO_MS_END,
};
enum DsoSetRegions {
DSO_NONE = -1,
DSO_VDIAL,
DSO_HDIAL,
DSO_VDEC,
DSO_VINC,
DSO_HDEC,
DSO_HINC,
DSO_CHEN,
DSO_ACDC,
DSO_X1,
DSO_X10,
DSO_X100,
};
private:
static const uint16_t MS_RectRad = 5;
static const uint16_t MS_IconSize = 16;
@@ -184,8 +199,16 @@ public:
bool get_ms_en(int index) const;
QString get_ms_string(int index) const;
QRectF get_rect(DsoSetRegions type, int y, int right);
bool mouse_double_click(int right, const QPoint pt);
bool mouse_press(int right, const QPoint pt);
bool mouse_wheel(int right, const QPoint pt, const int shift);
protected:
void paint_type_options(QPainter &p, int right, bool hover, int action);
void paint_type_options(QPainter &p, int right, const QPoint pt);
private:
void paint_trace(QPainter &p,

View File

@@ -196,13 +196,12 @@ const std::vector< std::pair<uint64_t, bool> > GroupSignal::cur_edges() const
}
void GroupSignal::paint_type_options(QPainter &p, int right, bool hover, int action)
void GroupSignal::paint_type_options(QPainter &p, int right, const QPoint pt)
{
(void)hover;
(void)action;
(void)pt;
int y = get_y();
const QRectF group_index_rect = get_rect("groupIndex", y, right);
const QRectF group_index_rect = get_rect(CHNLREG, y, right);
QString index_string;
int last_index;
p.setPen(Qt::transparent);
@@ -224,5 +223,18 @@ void GroupSignal::paint_type_options(QPainter &p, int right, bool hover, int act
p.drawText(group_index_rect, Qt::AlignRight | Qt::AlignVCenter, index_string);
}
QRectF GroupSignal::get_rect(GroupSetRegions type, int y, int right)
{
const QSizeF name_size(right - get_leftWidth() - get_rightWidth(), SquareWidth);
if (type == CHNLREG)
return QRectF(
get_leftWidth() + name_size.width() + Margin,
y - SquareWidth / 2,
SquareWidth * SquareNum, SquareWidth);
else
return QRectF(0, 0, 0, 0);
}
} // namespace view
} // namespace pv

View File

@@ -48,6 +48,11 @@ private:
static const float EnvelopeThreshold;
enum GroupSetRegions{
NONEREG = -1,
CHNLREG,
};
public:
GroupSignal(QString name,
boost::shared_ptr<pv::data::Group> data,
@@ -74,8 +79,10 @@ public:
const std::vector< std::pair<uint64_t, bool> > cur_edges() const;
QRectF get_rect(GroupSetRegions type, int y, int right);
protected:
void paint_type_options(QPainter &p, int right, bool hover, int action);
void paint_type_options(QPainter &p, int right, const QPoint pt);
private:
void paint_trace(QPainter &p,

View File

@@ -118,7 +118,6 @@ void Header::paintEvent(QPaintEvent*)
style()->drawPrimitive(QStyle::PE_Widget, &o, &painter, this);
const int w = width();
int action = 0;
const vector< boost::shared_ptr<Trace> > traces(
_view.get_traces());
@@ -129,11 +128,7 @@ void Header::paintEvent(QPaintEvent*)
BOOST_FOREACH(const boost::shared_ptr<Trace> t, traces)
{
assert(t);
const int y = t->get_y();
const bool highlight = !dragging &&
(action = t->pt_in_rect(y, w, _mouse_point));
t->paint_label(painter, w, highlight, action);
t->paint_label(painter, w, dragging ? QPoint(-1, -1) : _mouse_point);
}
painter.end();
@@ -157,14 +152,9 @@ void Header::mouseDoubleClickEvent(QMouseEvent *event)
make_pair(t, t->get_v_offset()));
// Select the Trace if it has been clicked
const boost::shared_ptr<Trace> mTrace =
get_mTrace(action, event->pos());
if (action == Trace::LABEL && mTrace) {
boost::shared_ptr<view::DsoSignal> dsoSig;
if (dsoSig = dynamic_pointer_cast<view::DsoSignal>(mTrace)) {
dsoSig->auto_set();
}
}
BOOST_FOREACH(const boost::shared_ptr<Trace> t, traces)
if (t->mouse_double_click(width(), event->pos()))
break;
}
}
@@ -213,93 +203,12 @@ void Header::mousePressEvent(QMouseEvent *event)
}
}
mTrace->set_old_v_offset(mTrace->get_v_offset());
} else if (action == Trace::POSTRIG && mTrace) {
if (mTrace->get_trig() == Trace::POSTRIG)
mTrace->set_trig(0);
else
mTrace->set_trig(Trace::POSTRIG);
} else if (action == Trace::HIGTRIG && mTrace) {
if (mTrace->get_trig() == Trace::HIGTRIG)
mTrace->set_trig(0);
else
mTrace->set_trig(Trace::HIGTRIG);
} else if (action == Trace::NEGTRIG && mTrace) {
if (mTrace->get_trig() == Trace::NEGTRIG)
mTrace->set_trig(0);
else
mTrace->set_trig(Trace::NEGTRIG);
} else if (action == Trace::LOWTRIG && mTrace) {
if (mTrace->get_trig() == Trace::LOWTRIG)
mTrace->set_trig(0);
else
mTrace->set_trig(Trace::LOWTRIG);
} else if (action == Trace::EDGETRIG && mTrace) {
if (mTrace->get_trig() == Trace::EDGETRIG)
mTrace->set_trig(0);
else
mTrace->set_trig(Trace::EDGETRIG);
} else if (action == Trace::VDIAL && mTrace) {
boost::shared_ptr<view::DsoSignal> dsoSig;
BOOST_FOREACH(const boost::shared_ptr<Trace> t, traces) {
if (dsoSig = dynamic_pointer_cast<view::DsoSignal>(t)) {
dsoSig->set_hDialActive(false);
if (t != mTrace) {
dsoSig->set_vDialActive(false);
}
}
}
if (dsoSig = dynamic_pointer_cast<view::DsoSignal>(mTrace))
dsoSig->set_vDialActive(!dsoSig->get_vDialActive());
} else if (action == Trace::HDIAL && mTrace) {
boost::shared_ptr<view::DsoSignal> dsoSig;
if (dsoSig = dynamic_pointer_cast<view::DsoSignal>(mTrace)) {
if (dsoSig->get_hDialActive()) {
BOOST_FOREACH(const boost::shared_ptr<Trace> t, traces) {
if(dsoSig = dynamic_pointer_cast<view::DsoSignal>(t)) {
dsoSig->set_vDialActive(false);
dsoSig->set_hDialActive(false);
}
}
} else {
BOOST_FOREACH(const boost::shared_ptr<Trace> t, traces) {
if(dsoSig = dynamic_pointer_cast<view::DsoSignal>(t)) {
dsoSig->set_vDialActive(false);
dsoSig->set_hDialActive(true);
}
}
}
}
} else if (action == Trace::CHEN && mTrace) {
boost::shared_ptr<view::DsoSignal> dsoSig;
if (dsoSig = dynamic_pointer_cast<view::DsoSignal>(mTrace)) {
if (!_view.session().get_data_lock())
dsoSig->set_enable(!dsoSig->enabled());
}
} else if (action == Trace::ACDC && mTrace) {
boost::shared_ptr<view::DsoSignal> dsoSig;
if (dsoSig = dynamic_pointer_cast<view::DsoSignal>(mTrace)) {
if (strcmp(_view.session().get_device()->dev_inst()->driver->name, "DSLogic") == 0)
dsoSig->set_acCoupling((dsoSig->get_acCoupling()+1)%2);
else
dsoSig->set_acCoupling((dsoSig->get_acCoupling()+1)%3);
}
} else if (action == Trace::X1 && mTrace) {
boost::shared_ptr<view::DsoSignal> dsoSig;
if (dsoSig = dynamic_pointer_cast<view::DsoSignal>(mTrace)) {
dsoSig->set_factor(1);
}
} else if (action == Trace::X10 && mTrace) {
boost::shared_ptr<view::DsoSignal> dsoSig;
if (dsoSig = dynamic_pointer_cast<view::DsoSignal>(mTrace)) {
dsoSig->set_factor(10);
}
} else if (action == Trace::X100 && mTrace) {
boost::shared_ptr<view::DsoSignal> dsoSig;
if (dsoSig = dynamic_pointer_cast<view::DsoSignal>(mTrace)) {
dsoSig->set_factor(100);
}
}
BOOST_FOREACH(const boost::shared_ptr<Trace> t, traces)
if (t->mouse_press(width(), event->pos()))
break;
if (~QApplication::keyboardModifiers() & Qt::ControlModifier) {
// Unselect all other Traces because the Ctrl is not
// pressed
@@ -350,27 +259,9 @@ void Header::wheelEvent(QWheelEvent *event)
_view.get_traces());
// Vertical scrolling
double shift = event->delta() / 20.0;
bool setted = false;
BOOST_FOREACH(const boost::shared_ptr<Trace> t, traces) {
boost::shared_ptr<view::DsoSignal> dsoSig;
if (dsoSig = dynamic_pointer_cast<view::DsoSignal>(t)) {
if (dsoSig->get_vDialActive()) {
if (shift > 1.0)
dsoSig->go_vDialNext();
else if (shift < -1.0)
dsoSig->go_vDialPre();
break;
} else if (dsoSig->get_hDialActive()){
if (shift > 1.0)
dsoSig->go_hDialNext(setted);
else if (shift < -1.0)
dsoSig->go_hDialPre(setted);
else
break;
setted = true;
}
}
}
BOOST_FOREACH(const boost::shared_ptr<Trace> t, traces)
if (t->mouse_wheel(width(), event->pos(), shift))
break;
update();
}
}

View File

@@ -70,16 +70,18 @@ LogicSignal::LogicSignal(boost::shared_ptr<pv::device::DevInst> dev_inst,
boost::shared_ptr<data::Logic> data,
const sr_channel * const probe) :
Signal(dev_inst, probe, SR_CHANNEL_LOGIC),
_data(data)
_data(data),
_trig(NONTRIG)
{
_colour = SignalColours[probe->index % countof(SignalColours)];
}
LogicSignal::LogicSignal(const Signal &s,
LogicSignal::LogicSignal(boost::shared_ptr<view::LogicSignal> s,
boost::shared_ptr<pv::data::Logic> data,
const sr_channel * const probe) :
Signal(s, probe),
_data(data)
Signal(*s.get(), probe),
_data(data),
_trig(s->get_trig())
{
}
@@ -103,6 +105,32 @@ boost::shared_ptr<pv::data::Logic> LogicSignal::logic_data() const
return _data;
}
LogicSignal::LogicSetRegions LogicSignal::get_trig() const
{
return _trig;
}
void LogicSignal::set_trig(int trig)
{
if (trig > NONTRIG && trig <= EDGTRIG)
_trig = (LogicSetRegions)trig;
else
_trig = NONTRIG;
if (trig == NONTRIG)
ds_trigger_probe_set(_index_list.front(), 'X', 'X');
else if (trig == POSTRIG)
ds_trigger_probe_set(_index_list.front(), 'R', 'X');
else if (trig == HIGTRIG)
ds_trigger_probe_set(_index_list.front(), '1', 'X');
else if (trig == NEGTRIG)
ds_trigger_probe_set(_index_list.front(), 'F', 'X');
else if (trig == LOWTRIG)
ds_trigger_probe_set(_index_list.front(), '0', 'X');
else if (trig == EDGTRIG)
ds_trigger_probe_set(_index_list.front(), 'C', 'X');
}
void LogicSignal::paint_mid(QPainter &p, int left, int right)
{
using pv::view::View;
@@ -205,35 +233,30 @@ const std::vector< std::pair<uint64_t, bool> > LogicSignal::cur_edges() const
return _cur_edges;
}
void LogicSignal::paint_type_options(QPainter &p, int right, bool hover, int action)
void LogicSignal::paint_type_options(QPainter &p, int right, const QPoint pt)
{
int y = get_y();
const QRectF posTrig_rect = get_rect("posTrig", y, right);
const QRectF higTrig_rect = get_rect("higTrig", y, right);
const QRectF negTrig_rect = get_rect("negTrig", y, right);
const QRectF lowTrig_rect = get_rect("lowTrig", y, right);
const QRectF edgeTrig_rect = get_rect("edgeTrig", y, right);
const QRectF posTrig_rect = get_rect(POSTRIG, y, right);
const QRectF higTrig_rect = get_rect(HIGTRIG, y, right);
const QRectF negTrig_rect = get_rect(NEGTRIG, y, right);
const QRectF lowTrig_rect = get_rect(LOWTRIG, y, right);
const QRectF edgeTrig_rect = get_rect(EDGTRIG, y, right);
p.setPen(Qt::transparent);
p.setBrush(((hover && action == POSTRIG) || (_trig == POSTRIG)) ?
dsYellow :
dsBlue);
p.setBrush(posTrig_rect.contains(pt) ? dsYellow.darker() :
(_trig == POSTRIG) ? dsYellow : dsBlue);
p.drawRect(posTrig_rect);
p.setBrush(((hover && action == HIGTRIG) || (_trig == HIGTRIG)) ?
dsYellow :
dsBlue);
p.setBrush(higTrig_rect.contains(pt) ? dsYellow.darker() :
(_trig == HIGTRIG) ? dsYellow : dsBlue);
p.drawRect(higTrig_rect);
p.setBrush(((hover && action == NEGTRIG) || (_trig == NEGTRIG)) ?
dsYellow :
dsBlue);
p.setBrush(negTrig_rect.contains(pt) ? dsYellow.darker() :
(_trig == NEGTRIG) ? dsYellow : dsBlue);
p.drawRect(negTrig_rect);
p.setBrush(((hover && action == LOWTRIG) || (_trig == LOWTRIG)) ?
dsYellow :
dsBlue);
p.setBrush(lowTrig_rect.contains(pt) ? dsYellow.darker() :
(_trig == LOWTRIG) ? dsYellow : dsBlue);
p.drawRect(lowTrig_rect);
p.setBrush(((hover && action == EDGETRIG) || (_trig == EDGETRIG)) ?
dsYellow :
dsBlue);
p.setBrush(edgeTrig_rect.contains(pt) ? dsYellow.darker() :
(_trig == EDGTRIG) ? dsYellow : dsBlue);
p.drawRect(edgeTrig_rect);
p.setPen(QPen(Qt::blue, 1, Qt::DotLine));
@@ -368,5 +391,63 @@ bool LogicSignal::edges(const QPointF &p, uint64_t start, uint64_t &rising, uint
return false;
}
bool LogicSignal::mouse_press(int right, const QPoint pt)
{
int y = get_y();
const QRectF posTrig = get_rect(POSTRIG, y, right);
const QRectF higTrig = get_rect(HIGTRIG, y, right);
const QRectF negTrig = get_rect(NEGTRIG, y, right);
const QRectF lowTrig = get_rect(LOWTRIG, y, right);
const QRectF edgeTrig = get_rect(EDGTRIG, y, right);
if (posTrig.contains(pt))
set_trig((_trig == POSTRIG) ? NONTRIG : POSTRIG);
else if (higTrig.contains(pt))
set_trig((_trig == HIGTRIG) ? NONTRIG : HIGTRIG);
else if (negTrig.contains(pt))
set_trig((_trig == NEGTRIG) ? NONTRIG : NEGTRIG);
else if (lowTrig.contains(pt))
set_trig((_trig == LOWTRIG) ? NONTRIG : LOWTRIG);
else if (edgeTrig.contains(pt))
set_trig((_trig == EDGTRIG) ? NONTRIG : EDGTRIG);
else
return false;
return true;
}
QRectF LogicSignal::get_rect(LogicSetRegions type, int y, int right)
{
const QSizeF name_size(right - get_leftWidth() - get_rightWidth(), SquareWidth);
if (type == POSTRIG)
return QRectF(
get_leftWidth() + name_size.width() + Margin,
y - SquareWidth / 2,
SquareWidth, SquareWidth);
else if (type == HIGTRIG)
return QRectF(
get_leftWidth() + name_size.width() + SquareWidth + Margin,
y - SquareWidth / 2,
SquareWidth, SquareWidth);
else if (type == NEGTRIG)
return QRectF(
get_leftWidth() + name_size.width() + 2 * SquareWidth + Margin,
y - SquareWidth / 2,
SquareWidth, SquareWidth);
else if (type == LOWTRIG)
return QRectF(
get_leftWidth() + name_size.width() + 3 * SquareWidth + Margin,
y - SquareWidth / 2,
SquareWidth, SquareWidth);
else if (type == EDGTRIG)
return QRectF(
get_leftWidth() + name_size.width() + 4 * SquareWidth + Margin,
y - SquareWidth / 2,
SquareWidth, SquareWidth);
else
return QRectF(0, 0, 0, 0);
}
} // namespace view
} // namespace pv

View File

@@ -53,12 +53,21 @@ private:
static const int StateHeight;
static const int StateRound;
enum LogicSetRegions{
NONTRIG = -1,
POSTRIG,
HIGTRIG,
NEGTRIG,
LOWTRIG,
EDGTRIG,
};
public:
LogicSignal(boost::shared_ptr<pv::device::DevInst> dev_inst,
boost::shared_ptr<pv::data::Logic> data,
const sr_channel * const probe);
LogicSignal(const Signal &s,
LogicSignal(boost::shared_ptr<view::LogicSignal> s,
boost::shared_ptr<pv::data::Logic> data,
const sr_channel * const probe);
@@ -70,6 +79,12 @@ public:
boost::shared_ptr<pv::data::Logic> logic_data() const;
/**
*
*/
LogicSetRegions get_trig() const;
void set_trig(int trig);
/**
* Paints the signal with a QPainter
* @param p the QPainter to paint into.
@@ -84,8 +99,12 @@ public:
bool edges(const QPointF &p, uint64_t start, uint64_t &rising, uint64_t &falling) const;
bool mouse_press(int right, const QPoint pt);
QRectF get_rect(LogicSetRegions type, int y, int right);
protected:
void paint_type_options(QPainter &p, int right, bool hover, int action);
void paint_type_options(QPainter &p, int right, const QPoint pt);
private:
@@ -97,6 +116,7 @@ private:
private:
boost::shared_ptr<pv::data::Logic> _data;
std::vector< std::pair<uint64_t, bool> > _cur_edges;
LogicSetRegions _trig;
};
} // namespace view

View File

@@ -59,8 +59,7 @@ Trace::Trace(QString name, uint16_t index, int type) :
_v_offset(INT_MAX),
_type(type),
_sec_index(0),
_signalHeight(30),
_trig(0)
_signalHeight(30)
{
_index_list.push_back(index);
}
@@ -72,8 +71,7 @@ Trace::Trace(QString name, std::list<int> index_list, int type, int sec_index) :
_type(type),
_index_list(index_list),
_sec_index(sec_index),
_signalHeight(30),
_trig(0)
_signalHeight(30)
{
}
@@ -87,7 +85,6 @@ Trace::Trace(const Trace &t) :
_sec_index(t._sec_index),
_old_v_offset(t._old_v_offset),
_signalHeight(t._signalHeight),
_trig(t._trig),
_text_size(t._text_size)
{
}
@@ -180,28 +177,6 @@ void Trace::set_signalHeight(int height)
_signalHeight = height;
}
int Trace::get_trig() const
{
return _trig;
}
void Trace::set_trig(int trig)
{
_trig = trig;
if (trig == 0)
ds_trigger_probe_set(_index_list.front(), 'X', 'X');
else if (trig == POSTRIG)
ds_trigger_probe_set(_index_list.front(), 'R', 'X');
else if (trig == HIGTRIG)
ds_trigger_probe_set(_index_list.front(), '1', 'X');
else if (trig == NEGTRIG)
ds_trigger_probe_set(_index_list.front(), 'F', 'X');
else if (trig == LOWTRIG)
ds_trigger_probe_set(_index_list.front(), '0', 'X');
else if (trig == EDGETRIG)
ds_trigger_probe_set(_index_list.front(), 'C', 'X');
}
void Trace::set_view(pv::view::View *view)
{
assert(view);
@@ -231,7 +206,7 @@ void Trace::paint_fore(QPainter &p, int left, int right)
(void)right;
}
void Trace::paint_label(QPainter &p, int right, bool hover, int action)
void Trace::paint_label(QPainter &p, int right, const QPoint pt)
{
compute_text_size(p);
const int y = get_y();
@@ -251,7 +226,7 @@ void Trace::paint_label(QPainter &p, int right, bool hover, int action)
p.drawText(name_rect, Qt::AlignLeft | Qt::AlignVCenter, _name);
// Paint the trigButton
paint_type_options(p, right, hover, action);
paint_type_options(p, right, pt);
// Paint the label
if (enabled()) {
@@ -265,9 +240,9 @@ void Trace::paint_label(QPainter &p, int right, bool hover, int action)
p.setPen(Qt::transparent);
if (_type == SR_CHANNEL_DSO)
p.setBrush(((hover && action == LABEL) || selected()) ? _colour.darker() : _colour);
p.setBrush((label_rect.contains(pt) || selected()) ? _colour.darker() : _colour);
else
p.setBrush(((hover && action == LABEL) || selected()) ? dsYellow : dsBlue);
p.setBrush((label_rect.contains(pt) || selected()) ? dsYellow : dsBlue);
p.drawPolygon(points, countof(points));
p.setPen(QPen(Qt::blue, 1, Qt::DotLine));
@@ -288,65 +263,47 @@ void Trace::paint_label(QPainter &p, int right, bool hover, int action)
}
}
void Trace::paint_type_options(QPainter &p, int right, bool hover, int action)
void Trace::paint_type_options(QPainter &p, int right, const QPoint pt)
{
(void)p;
(void)right;
(void)hover;
(void)action;
(void)pt;
}
bool Trace::mouse_double_click(int right, const QPoint pt)
{
(void)right;
(void)pt;
return false;
}
bool Trace::mouse_press(int right, const QPoint pt)
{
(void)right;
(void)pt;
return false;
}
bool Trace::mouse_wheel(int right, const QPoint pt, const int shift)
{
(void)right;
(void)pt;
(void)shift;
return false;
}
int Trace::pt_in_rect(int y, int right, const QPoint &point)
{
const QRectF color = get_rect("color", y, right);
const QRectF name = get_rect("name", y, right);
const QRectF posTrig = get_rect("posTrig", y, right);
const QRectF higTrig = get_rect("higTrig", y, right);
const QRectF negTrig = get_rect("negTrig", y, right);
const QRectF lowTrig = get_rect("lowTrig", y, right);
const QRectF edgeTrig = get_rect("edgeTrig", y, right);
const QRectF label = get_rect("label", get_zeroPos(), right);
const QRectF vDial = get_rect("vDial", y, right);
const QRectF x1 = get_rect("x1", y, right);
const QRectF x10 = get_rect("x10", y, right);
const QRectF x100 = get_rect("x100", y, right);
const QRectF hDial = get_rect("hDial", y, right);
const QRectF chEn = get_rect("chEn", y, right);
const QRectF acdc = get_rect("acdc", y, right);
const QRectF dsoTrig = get_rect("dsoTrig", 0, right);
if (color.contains(point) && enabled())
return COLOR;
else if (name.contains(point) && enabled())
return NAME;
else if (posTrig.contains(point) && _type == SR_CHANNEL_LOGIC)
return POSTRIG;
else if (higTrig.contains(point) && _type == SR_CHANNEL_LOGIC)
return HIGTRIG;
else if (negTrig.contains(point) && _type == SR_CHANNEL_LOGIC)
return NEGTRIG;
else if (lowTrig.contains(point) && _type == SR_CHANNEL_LOGIC)
return LOWTRIG;
else if (edgeTrig.contains(point) && _type == SR_CHANNEL_LOGIC)
return EDGETRIG;
else if (label.contains(point) && enabled())
return LABEL;
else if (vDial.contains(point) && _type == SR_CHANNEL_DSO && enabled())
return VDIAL;
else if (x1.contains(point) && _type == SR_CHANNEL_DSO && enabled())
return X1;
else if (x10.contains(point) && _type == SR_CHANNEL_DSO && enabled())
return X10;
else if (x100.contains(point) && _type == SR_CHANNEL_DSO && enabled())
return X100;
else if (hDial.contains(point) && _type == SR_CHANNEL_DSO && enabled())
return HDIAL;
else if (chEn.contains(point) && _type == SR_CHANNEL_DSO)
return CHEN;
else if (acdc.contains(point) && _type == SR_CHANNEL_DSO && enabled())
return ACDC;
else if (dsoTrig.contains(point) && _type == SR_CHANNEL_DSO && enabled())
return DSOTRIG;
else
return 0;
}
@@ -381,71 +338,6 @@ QRectF Trace::get_rect(const char *s, int y, int right)
right - 1.5f * label_size.width(),
y - SquareWidth / 2,
label_size.width(), label_size.height());
else if (!strcmp(s, "posTrig"))
return QRectF(
get_leftWidth() + name_size.width() + Margin,
y - SquareWidth / 2,
SquareWidth, SquareWidth);
else if (!strcmp(s, "higTrig"))
return QRectF(
get_leftWidth() + name_size.width() + SquareWidth + Margin,
y - SquareWidth / 2,
SquareWidth, SquareWidth);
else if (!strcmp(s, "negTrig"))
return QRectF(
get_leftWidth() + name_size.width() + 2 * SquareWidth + Margin,
y - SquareWidth / 2,
SquareWidth, SquareWidth);
else if (!strcmp(s, "lowTrig"))
return QRectF(
get_leftWidth() + name_size.width() + 3 * SquareWidth + Margin,
y - SquareWidth / 2,
SquareWidth, SquareWidth);
else if (!strcmp(s, "edgeTrig"))
return QRectF(
get_leftWidth() + name_size.width() + 4 * SquareWidth + Margin,
y - SquareWidth / 2,
SquareWidth, SquareWidth);
else if (!strcmp(s, "groupIndex"))
return QRectF(
get_leftWidth() + name_size.width() + Margin,
y - SquareWidth / 2,
SquareWidth * SquareNum, SquareWidth);
else if (!strcmp(s, "vDial"))
return QRectF(
get_leftWidth() + name_size.width() + SquareWidth*0.5 + Margin,
y - SquareWidth * SquareNum,
SquareWidth * (SquareNum-1), SquareWidth * (SquareNum-1));
else if (!strcmp(s, "x1"))
return QRectF(
get_leftWidth() + name_size.width() + SquareWidth*0.5 + Margin - 45,
y - SquareWidth - SquareWidth * (SquareNum-1) * 0.85,
SquareWidth * 1.75, SquareWidth);
else if (!strcmp(s, "x10"))
return QRectF(
get_leftWidth() + name_size.width() + SquareWidth*0.5 + Margin - 45,
y - SquareWidth - SquareWidth * (SquareNum-1) * 0.55,
SquareWidth * 1.75, SquareWidth);
else if (!strcmp(s, "x100"))
return QRectF(
get_leftWidth() + name_size.width() + SquareWidth*0.5 + Margin - 45,
y - SquareWidth - SquareWidth * (SquareNum-1) * 0.25,
SquareWidth * 1.75, SquareWidth);
else if (!strcmp(s, "hDial"))
return QRectF(
get_leftWidth() + name_size.width() + SquareWidth*0.5 + Margin,
y + SquareWidth * 1.5,
SquareWidth * (SquareNum-1), SquareWidth * (SquareNum-1));
else if (!strcmp(s, "chEn"))
return QRectF(
get_leftWidth() + name_size.width() + SquareWidth*0.75 + Margin,
y - SquareWidth / 2,
SquareWidth * 1.5, SquareWidth);
else if (!strcmp(s, "acdc"))
return QRectF(
get_leftWidth() + name_size.width() + SquareWidth*2.75 + Margin,
y - SquareWidth / 2,
SquareWidth * 1.5, SquareWidth);
else
return QRectF(
2,

View File

@@ -45,7 +45,7 @@ class Trace : public SelectableItem
{
Q_OBJECT
private:
protected:
static const int Margin = 3;
static const int SquareNum = 5;
static const QPen AxisPen;
@@ -55,20 +55,7 @@ public:
static const int SquareWidth = 20;
static const int COLOR = 1;
static const int NAME = 2;
static const int POSTRIG = 3;
static const int HIGTRIG = 4;
static const int NEGTRIG = 5;
static const int LOWTRIG = 6;
static const int EDGETRIG = 7;
static const int LABEL = 8;
static const int VDIAL = 9;
static const int HDIAL = 10;
static const int CHEN = 11;
static const int ACDC = 12;
static const int DSOTRIG = 13;
static const int X1 = 14;
static const int X10 = 15;
static const int X100 = 16;
static const QColor dsBlue;
static const QColor dsYellow;
@@ -166,12 +153,6 @@ public:
virtual int get_zeroPos();
/**
*
*/
int get_trig() const;
void set_trig(int trig);
/**
* Returns true if the trace is visible and enabled.
*/
@@ -208,10 +189,9 @@ public:
* @param p the QPainter to paint into.
* @param right the x-coordinate of the right edge of the header
* area.
* @param hover true if the label is being hovered over by the mouse.
* @param action mouse position for hover
* @param point the mouse point.
*/
virtual void paint_label(QPainter &p, int right, bool hover, int action);
virtual void paint_label(QPainter &p, int right, const QPoint pt);
/**
* Gets the y-offset of the axis.
@@ -250,6 +230,12 @@ public:
virtual QRectF get_view_rect() const;
virtual bool mouse_double_click(int right, const QPoint pt);
virtual bool mouse_press(int right, const QPoint pt);
virtual bool mouse_wheel(int right, const QPoint pt, const int shift);
protected:
/**
@@ -274,10 +260,9 @@ protected:
* @param p the QPainter to paint into.
* @param right the x-coordinate of the right edge of the header
* area.
* @param hover true if the label is being hovered over by the mouse.
* @param action mouse position for hover
* @param point the mouse point.
*/
virtual void paint_type_options(QPainter &p, int right, bool hover, int action);
virtual void paint_type_options(QPainter &p, int right, const QPoint pt);
private:
@@ -307,7 +292,6 @@ protected:
int _sec_index;
int _old_v_offset;
int _signalHeight;
int _trig;
QSizeF _text_size;
};