forked from Ivasoft/DSView
v0.4 release
This commit is contained in:
194
DSLogic-gui/pv/view/devmode.cpp
Normal file
194
DSLogic-gui/pv/view/devmode.cpp
Normal file
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
* This file is part of the DSLogic-gui project.
|
||||
* DSLogic-gui is based on PulseView.
|
||||
*
|
||||
* Copyright (C) 2014 DreamSourceLab <dreamsourcelab@dreamsourcelab.com>
|
||||
*
|
||||
* 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 "devmode.h"
|
||||
#include "view.h"
|
||||
#include "trace.h"
|
||||
#include "../sigsession.h"
|
||||
#include "../device/devinst.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QStyleOption>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QRect>
|
||||
#include <QMessageBox>
|
||||
#include <QDebug>
|
||||
|
||||
using boost::shared_ptr;
|
||||
using namespace std;
|
||||
|
||||
namespace pv {
|
||||
namespace view {
|
||||
|
||||
DevMode::DevMode(View &parent) :
|
||||
QWidget(&parent),
|
||||
_view(parent),
|
||||
layout(new QGridLayout(this))
|
||||
|
||||
{
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
void DevMode::set_device()
|
||||
{
|
||||
int index = 0;
|
||||
const boost::shared_ptr<device::DevInst> dev_inst = _view.session().get_device();
|
||||
|
||||
assert(dev_inst);
|
||||
|
||||
_mode_button_list.clear();
|
||||
delete layout;
|
||||
layout = new QGridLayout(this);
|
||||
|
||||
for (GSList *l = dev_inst->get_dev_mode_list();
|
||||
l; l = l->next) {
|
||||
sr_dev_mode *mode = (sr_dev_mode *)l->data;
|
||||
|
||||
shared_ptr<QPushButton> mode_button = shared_ptr<QPushButton>(new QPushButton(NULL));
|
||||
mode_button->setFlat(true);
|
||||
mode_button->setText(mode->name);
|
||||
|
||||
_mode_button_list[mode_button] = mode;
|
||||
|
||||
connect(mode_button.get(), SIGNAL(clicked()), this, SLOT(on_mode_change()));
|
||||
|
||||
layout->addWidget(mode_button.get(), index / GRID_COLS, index % GRID_COLS);
|
||||
layout->addWidget(new QWidget(), index / GRID_COLS, GRID_COLS);
|
||||
layout->setColumnStretch(GRID_COLS, 1);
|
||||
index++;
|
||||
}
|
||||
|
||||
setLayout(layout);
|
||||
update();
|
||||
}
|
||||
|
||||
void DevMode::paintEvent(QPaintEvent*)
|
||||
{
|
||||
using pv::view::Trace;
|
||||
|
||||
QStyleOption o;
|
||||
o.initFrom(this);
|
||||
QPainter painter(this);
|
||||
style()->drawPrimitive(QStyle::PE_Widget, &o, &painter, this);
|
||||
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.setPen(Qt::NoPen);
|
||||
for(std::map<shared_ptr<QPushButton>, sr_dev_mode *>::const_iterator i = _mode_button_list.begin();
|
||||
i != _mode_button_list.end(); i++) {
|
||||
const boost::shared_ptr<device::DevInst> dev_inst = _view.session().get_device();
|
||||
assert(dev_inst);
|
||||
if (dev_inst->dev_inst()->mode == (*i).second->mode)
|
||||
painter.setBrush(Trace::dsBlue);
|
||||
else
|
||||
painter.setBrush(Trace::dsGray);
|
||||
|
||||
painter.drawRoundedRect((*i).first->geometry(), 4, 4);
|
||||
}
|
||||
|
||||
painter.end();
|
||||
}
|
||||
|
||||
void DevMode::on_mode_change()
|
||||
{
|
||||
const boost::shared_ptr<device::DevInst> dev_inst = _view.session().get_device();
|
||||
assert(dev_inst);
|
||||
QPushButton *button = qobject_cast<QPushButton *>(sender());
|
||||
|
||||
for(std::map<shared_ptr<QPushButton>, sr_dev_mode *>::const_iterator i = _mode_button_list.begin();
|
||||
i != _mode_button_list.end(); i++) {
|
||||
if ((*i).first.get() == button) {
|
||||
if (dev_inst->dev_inst()->mode != (*i).second->mode) {
|
||||
dev_inst->set_config(NULL, NULL,
|
||||
SR_CONF_DEVICE_MODE,
|
||||
g_variant_new_int16((*i).second->mode));
|
||||
|
||||
mode_changed();
|
||||
|
||||
if (dev_inst->dev_inst()->mode == DSO &&
|
||||
strcmp(dev_inst->dev_inst()->driver->name, "DSLogic") == 0) {
|
||||
bool zero_adjusted = false;
|
||||
GVariant *gvar = dev_inst->get_config(NULL, NULL, SR_CONF_ZERO);
|
||||
if (gvar != NULL) {
|
||||
zero_adjusted = g_variant_get_boolean(gvar);
|
||||
g_variant_unref(gvar);
|
||||
} else {
|
||||
qDebug() << "ERROR: config_get SR_CONF_ZERO failed.";
|
||||
}
|
||||
|
||||
if (!zero_adjusted) {
|
||||
QMessageBox msg(this);
|
||||
msg.setText("Zero Adjustment");
|
||||
msg.setInformativeText("Please left both of channels unconnect for zero adjustment!");
|
||||
msg.setStandardButtons(QMessageBox::Ok);
|
||||
msg.setIcon(QMessageBox::Warning);
|
||||
msg.exec();
|
||||
|
||||
int ret = dev_inst->set_config(NULL, NULL,
|
||||
SR_CONF_ZERO,
|
||||
g_variant_new_boolean(TRUE));
|
||||
if (!ret) {
|
||||
QMessageBox msg(this);
|
||||
msg.setText("Zero Adjustment Issue");
|
||||
msg.setInformativeText("Can't send out the command of zero adjustment!");
|
||||
msg.setStandardButtons(QMessageBox::Ok);
|
||||
msg.setIcon(QMessageBox::Warning);
|
||||
msg.exec();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DevMode::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
assert(event);
|
||||
(void)event;
|
||||
}
|
||||
|
||||
void DevMode::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
assert(event);
|
||||
(void)event;
|
||||
}
|
||||
|
||||
void DevMode::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
assert(event);
|
||||
_mouse_point = event->pos();
|
||||
update();
|
||||
}
|
||||
|
||||
void DevMode::leaveEvent(QEvent*)
|
||||
{
|
||||
_mouse_point = QPoint(-1, -1);
|
||||
update();
|
||||
}
|
||||
|
||||
} // namespace view
|
||||
} // namespace pv
|
||||
Reference in New Issue
Block a user