# HG changeset patch # User Alexis Jeandet # Date 2015-03-31 20:16:47 # Node ID 9790824220ca06014e65a5c13aa4ed37f89d7593 # Parent 2c82d72694590cbc2aebb946667f11f60ea89afe Added new peripheral view. diff --git a/PeripheralWidget.pri b/PeripheralWidget.pri --- a/PeripheralWidget.pri +++ b/PeripheralWidget.pri @@ -2,13 +2,22 @@ PERIPHERAL_WDGT_SOURCES =\ src/peripheralwidget.cpp \ src/registerwidget.cpp \ - src/socregsviewer.cpp - + src/socregsviewer.cpp \ + src/socregsviewernew.cpp \ + src/collapsableperipheralwidget.cpp PERIPHERAL_WDGT_HEADERS += \ src/peripheralwidget.h \ src/registerwidget.h \ - src/socregsviewer.h + src/socregsviewer.h \ + src/socregsviewernew.h \ + src/collapsableperipheralwidget.h +PERIPHERAL_WDGT_FORMS += \ + src/socregsviewernew.ui \ + src/collapsableperipheralwidget.ui +PERIPHERAL_WDGT_RESOURCES += \ + $$PWD/ressources/peripheralwidget.qrc + diff --git a/ressources/Gnome-list-add.svg b/ressources/Gnome-list-add.svg new file mode 100644 --- /dev/null +++ b/ressources/Gnome-list-add.svg @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + \ No newline at end of file diff --git a/ressources/Gnome-list-remove.svg b/ressources/Gnome-list-remove.svg new file mode 100644 --- /dev/null +++ b/ressources/Gnome-list-remove.svg @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + image/svg+xml + + + List remove + August 2006 + + + Andreas Nilsson + + + http://www.gnome.org + + + remove + minus + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ressources/peripheralwidget.qrc b/ressources/peripheralwidget.qrc new file mode 100644 --- /dev/null +++ b/ressources/peripheralwidget.qrc @@ -0,0 +1,6 @@ + + + Gnome-list-add.svg + Gnome-list-remove.svg + + diff --git a/src/collapsableperipheralwidget.cpp b/src/collapsableperipheralwidget.cpp new file mode 100644 --- /dev/null +++ b/src/collapsableperipheralwidget.cpp @@ -0,0 +1,102 @@ +#include "collapsableperipheralwidget.h" +#include "ui_collapsableperipheralwidget.h" +#include + + +CollapsablePeripheralWidget::CollapsablePeripheralWidget(peripheralWidget *periph, QWidget *parent) : + QWidget(parent), + ui(new Ui::CollapsablePeripheralWidget) +{ + m_periph=0; + m_collapsed = true; + ui->setupUi(this); + tthidetmr.setSingleShot(true); + tthidetmr.setInterval(200); + connect(this->ui->collapseQpb,SIGNAL(clicked()),this,SLOT(collapse())); + connect(this->ui->periphName,SIGNAL(clicked()),this,SLOT(collapse())); + connect(this->ui->periphName,SIGNAL(enter()),this,SLOT(showTooltip())); + connect(this->ui->periphName,SIGNAL(leave()),&this->tthidetmr,SLOT(start())); + connect(&this->tthidetmr,SIGNAL(timeout()),this,SLOT(hideTooltip())); + setPeripheralWidget(periph); +} + +CollapsablePeripheralWidget::~CollapsablePeripheralWidget() +{ + delete ui; +} + +void CollapsablePeripheralWidget::setPeripheralWidget(peripheralWidget *periph) +{ + if(periph) + { + this->m_periph = periph; + this->ui->gridLayout->addWidget(periph,1,0,1,-1); + this->ui->periphName->setText(periph->name()); + this->m_periph->setVisible(false); + } +} + +peripheralWidget *CollapsablePeripheralWidget::getPeripheralWidget() +{ + return m_periph; +} + +void CollapsablePeripheralWidget::changeEvent(QEvent *e) +{ + QWidget::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} + +void CollapsablePeripheralWidget::collapse() +{ + this->m_periph->setVisible(m_collapsed); + if(this->m_collapsed) + { + this->ui->collapseQpb->setIcon(QIcon(":/img/Gnome-list-remove.svg")); + } + else + { + this->ui->collapseQpb->setIcon(QIcon(":/img/Gnome-list-add.svg")); + } + m_collapsed = !m_collapsed; +} + +void CollapsablePeripheralWidget::setName(const QString &name) +{ + if(m_periph) + { + this->ui->periphName->setText(name); + } +} + +void CollapsablePeripheralWidget::showTooltip() +{ + if(!m_periph->isVisible() && m_collapsed) + { + m_periph->show(); + } +} + +void CollapsablePeripheralWidget::hideTooltip() +{ + if(m_periph->isVisible() && m_collapsed) + { + QRect temprect = this->geometry(); + temprect.moveTo(this->mapToGlobal(mapFromParent(QPoint(this->x(),this->y())))); + if(temprect.contains(QCursor::pos())) + { + this->tthidetmr.start(); + } + else + { + m_periph->hide(); + } + } +} + diff --git a/src/collapsableperipheralwidget.h b/src/collapsableperipheralwidget.h new file mode 100644 --- /dev/null +++ b/src/collapsableperipheralwidget.h @@ -0,0 +1,56 @@ +#ifndef COLLAPSABLEPERIPHERALWIDGET_H +#define COLLAPSABLEPERIPHERALWIDGET_H + +#include +#include +#include + +namespace Ui { +class CollapsablePeripheralWidget; +} + +class QRegToolTipLabel : public QLabel +{ + Q_OBJECT +public: + QRegToolTipLabel(QWidget * parent = 0, Qt::WindowFlags f = 0):QLabel(parent,f){} + QRegToolTipLabel(const QString & text, QWidget * parent = 0, Qt::WindowFlags f = 0):QLabel(text,parent,f){} +signals: + void enter(); + void leave(); + void clicked(); +protected: + void enterEvent(QEvent* event){emit enter();QLabel::enterEvent(event);} + void leaveEvent(QEvent* event){emit leave();QLabel::leaveEvent(event);} + void mousePressEvent(QMouseEvent * event){emit clicked();QLabel::mousePressEvent(event);} +}; + +class CollapsablePeripheralWidget : public QWidget +{ + Q_OBJECT + +public: + explicit CollapsablePeripheralWidget(peripheralWidget* periph,QWidget *parent = 0); + ~CollapsablePeripheralWidget(); + void setPeripheralWidget(peripheralWidget* periph); + peripheralWidget* getPeripheralWidget(); +protected: + void changeEvent(QEvent *e); + +public slots: + void collapse(); + void setName(const QString& name); + void showTooltip(); + void hideTooltip(); +signals: + void clicked(peripheralWidget* sender); + void upSig(peripheralWidget* sender,int cursorIndex); + void downSig(peripheralWidget* sender,int cursorIndex); +private: + Ui::CollapsablePeripheralWidget *ui; + peripheralWidget* m_periph; + bool m_collapsed; + QTimer tthidetmr; +}; + +#endif // COLLAPSABLEPERIPHERALWIDGET_H diff --git a/src/collapsableperipheralwidget.ui b/src/collapsableperipheralwidget.ui new file mode 100644 --- /dev/null +++ b/src/collapsableperipheralwidget.ui @@ -0,0 +1,89 @@ + + + CollapsablePeripheralWidget + + + + 0 + 0 + 845 + 249 + + + + + 0 + 0 + + + + Form + + + QWidget#CollapsablePeripheralWidget { + border: 1px solid gray; + border-radius: 9px; +} + + + + + + + 0 + 0 + + + + + + + + :/img/Gnome-list-add.svg + :/img/Gnome-list-remove.svg:/img/Gnome-list-add.svg + + + true + + + + + + + + 0 + 0 + + + + PeriphName + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + QRegToolTipLabel + QLabel +
collapsableperipheralwidget.h
+
+
+ + + + +
diff --git a/src/peripheralwidget.cpp b/src/peripheralwidget.cpp --- a/src/peripheralwidget.cpp +++ b/src/peripheralwidget.cpp @@ -21,7 +21,7 @@ ----------------------------------------------------------------------------*/ #include "peripheralwidget.h" -peripheralWidget::peripheralWidget(const QString &name, qint32 baseAddress, QWidget *parent) : +peripheralWidget::peripheralWidget(const QString &name, qint32 baseAddress, readWriteProxy *proxy, QWidget *parent) : QWidget(parent) { p_name = name; @@ -29,6 +29,7 @@ peripheralWidget::peripheralWidget(const p_timer->setInterval(500); p_baseAddress = baseAddress; p_header = p_name + QString(" @0x%1").arg((uint)p_baseAddress,8,16); + p_proxy = proxy; setAttribute(Qt::WA_AlwaysShowToolTips); setMouseTracking(true); setFocusPolicy(Qt::StrongFocus); @@ -36,6 +37,8 @@ peripheralWidget::peripheralWidget(const registersWdgts.clear(); connect(p_timer,SIGNAL(timeout()),this,SLOT(blinkCursor())); setFont(QFont("Utopia", 14,QFont::Bold)); + setMinimumSize(400,100); + updateGeometry(); } int peripheralWidget::count() @@ -43,6 +46,11 @@ int peripheralWidget::count() return registersWdgts.count(); } +const QString &peripheralWidget::name() +{ + return this->p_name; +} + void peripheralWidget::blinkCursor() { if(selectedReg!=-1) @@ -87,6 +95,11 @@ void peripheralWidget::enter(int cursorI } } +void peripheralWidget::setReadWriteProxy(peripheralWidget::readWriteProxy *proxy) +{ + this->p_proxy = proxy; +} + void peripheralWidget::mousePressEvent(QMouseEvent *event) { p_timer->stop(); @@ -129,7 +142,6 @@ void peripheralWidget::mouseMoveEvent(QM { match = true; int bitfieldIndex=registersWdgts.at(i)->cursorIndex(event->pos().x()); - QString toolTipText ="< font color='Black'>"+registersWdgts.at(i)->bitFieldName(bitfieldIndex) +"
"; toolTipText+= "Hexadecimal=< font color='Blue'>"+registersWdgts.at(i)->bitFieldToHex(bitfieldIndex)+""; toolTipText+= " Decimal=< font color='BlueViolet'>"+registersWdgts.at(i)->bitFieldToDec(bitfieldIndex)+"
"; @@ -160,13 +172,13 @@ void peripheralWidget::keyPressEvent(QKe registersWdgts.at(selectedReg)->clear(registersWdgts.at(selectedReg)->cursorIndex()); break; case Qt::Key_W: - emit writeRegSig(registersWdgts.at(selectedReg)->address(),registersWdgts.at(selectedReg)->value()); + p_proxy->writeReg(registersWdgts.at(selectedReg)->address(),registersWdgts.at(selectedReg)->value()); registersWdgts.at(selectedReg)->setUpdated(true); registersWdgts.at(selectedReg)->repaint(); break; case Qt::Key_R: qint32 value; - value = emit readRegSig(registersWdgts.at(selectedReg)->address()); + value = p_proxy->readReg(registersWdgts.at(selectedReg)->address()); registersWdgts.at(selectedReg)->setValue(value); break; default: @@ -200,13 +212,13 @@ void peripheralWidget::keyPressEvent(QKe down(); break; case Qt::Key_W: - emit writeRegSig(registersWdgts.at(selectedReg)->address(),registersWdgts.at(selectedReg)->value()); + p_proxy->writeReg(registersWdgts.at(selectedReg)->address(),registersWdgts.at(selectedReg)->value()); registersWdgts.at(selectedReg)->setUpdated(true); registersWdgts.at(selectedReg)->repaint(); break; case Qt::Key_R: qint32 value; - value = emit readRegSig(registersWdgts.at(selectedReg)->address()); + value = p_proxy->readReg(registersWdgts.at(selectedReg)->address()); registersWdgts.at(selectedReg)->setValue(value); break; default: @@ -236,7 +248,9 @@ void peripheralWidget::paintEvent(QPaint } if(registersWdgts.count()>0) { - setMinimumSize(registersWdgts.first()->boundingRect().width(),offset.y()); + int w=registersWdgts.first()->boundingRect().width(); + int h=offset.y(); + setMinimumSize(w,h); } updateGeometry(); diff --git a/src/peripheralwidget.h b/src/peripheralwidget.h --- a/src/peripheralwidget.h +++ b/src/peripheralwidget.h @@ -38,11 +38,20 @@ * TODO ADD an outdated marker * Show outdated registers with a different color for example */ + class SOCEXPLORER_SDK_EXPORT peripheralWidget : public QWidget { Q_OBJECT public: - explicit peripheralWidget(const QString& name,qint32 baseAddress, QWidget *parent = 0); + class readWriteProxy + { + public: + readWriteProxy() {} + virtual void writeReg(qint32 address,qint32 value)=0; + virtual qint32 readReg(qint32 address)=0; + }; + + explicit peripheralWidget(const QString& name,qint32 baseAddress,readWriteProxy* proxy=0, QWidget *parent = 0); registerWidget* registerAt(int index) { if(index>=0 && index registersWdgts; int selectedReg; QTimer* p_timer; + readWriteProxy* p_proxy; }; diff --git a/src/socregsviewernew.cpp b/src/socregsviewernew.cpp new file mode 100644 --- /dev/null +++ b/src/socregsviewernew.cpp @@ -0,0 +1,107 @@ +#include "socregsviewernew.h" +#include "ui_socregsviewernew.h" + +SocRegsViewerNew::SocRegsViewerNew(const QString &name,QWidget *parent) : + QWidget(parent), + ui(new Ui::SocRegsViewerNew) +{ + ui->setupUi(this); + this->ui->socName->setText(name); +} + +SocRegsViewerNew::~SocRegsViewerNew() +{ + delete ui; +} + +peripheralWidget *SocRegsViewerNew::peripheral(int index) +{ + if(index>=0 && indexsetPeripheralWidget(peripheral); + p_peripherals.append(peripheral); + p_CPeripherals.append(cperiph); + this->ui->scrollAreaWidgetContents->layout()->addWidget(cperiph); + connect(cperiph,SIGNAL(clicked(peripheralWidget*)),this,SLOT(periphClicked(peripheralWidget*))); + connect(cperiph,SIGNAL(upSig(peripheralWidget*,int)),this,SLOT(periphUp(peripheralWidget*,int))); + connect(cperiph,SIGNAL(downSig(peripheralWidget*,int)),this,SLOT(periphDown(peripheralWidget*,int))); + } +} + +void SocRegsViewerNew::periphClicked(peripheralWidget *sender) +{ + peripheralWidget * item; + if(sender!=NULL) + { + for(int i=0;ileave(); + } + } + } +} + +void SocRegsViewerNew::periphUp(peripheralWidget *sender, int cursorIndex) +{ + int index,senderIndex; + if(sender!=NULL) + { + index =senderIndex= p_peripherals.indexOf(sender); + while(index!=-1 && index!=0) + { + if(p_peripherals.at(index-1)->count()>0) + { + p_peripherals.at(senderIndex)->leave(); + p_peripherals.at(index-1)->enter(cursorIndex,false); +// ensureWidgetVisible(p_peripherals.at(index-1)); + break; + } + index--; + } + } +} + +void SocRegsViewerNew::periphDown(peripheralWidget *sender, int cursorIndex) +{ + int index,senderIndex; + if(sender!=NULL) + { + index=senderIndex= p_peripherals.indexOf(sender); + while((index!=-1) && (index<(p_peripherals.count()-1))) + { + if(p_peripherals.at(index+1)->count()>0) + { + p_peripherals.at(senderIndex)->leave(); + p_peripherals.at(index+1)->enter(cursorIndex); +// ensureWidgetVisible(p_peripherals.at(index+1)); + break; + } + index++; + } + } +} + +void SocRegsViewerNew::changeEvent(QEvent *e) +{ + QWidget::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} diff --git a/src/socregsviewernew.h b/src/socregsviewernew.h new file mode 100644 --- /dev/null +++ b/src/socregsviewernew.h @@ -0,0 +1,38 @@ +#ifndef SOCREGSVIEWERNEW_H +#define SOCREGSVIEWERNEW_H + +#include +#include +#include + +namespace Ui { +class SocRegsViewerNew; +} + +class SocRegsViewerNew : public QWidget +{ + Q_OBJECT + +public: + explicit SocRegsViewerNew(const QString &name, QWidget *parent = 0); + ~SocRegsViewerNew(); + + peripheralWidget *peripheral(int index); + +signals: + +public slots: + void addPeripheral(peripheralWidget* peripheral); + void periphClicked(peripheralWidget* sender); + void periphUp(peripheralWidget* sender,int cursorIndex); + void periphDown(peripheralWidget* sender,int cursorIndex); +protected: + void changeEvent(QEvent *e); + +private: + Ui::SocRegsViewerNew *ui; + QList p_peripherals; + QList p_CPeripherals; +}; + +#endif // SOCREGSVIEWERNEW_H diff --git a/src/socregsviewernew.ui b/src/socregsviewernew.ui new file mode 100644 --- /dev/null +++ b/src/socregsviewernew.ui @@ -0,0 +1,60 @@ + + + SocRegsViewerNew + + + + 0 + 0 + 713 + 357 + + + + Form + + + + + + + + + true + + + + + 0 + 0 + 693 + 302 + + + + + + + SocName + + + Qt::AlignCenter + + + + + + + + + + + Root Plugin + + + + + + + +