##// END OF EJS Templates
New Peripheral view almost done.
jeandet -
r19:1cb664ab4bb3 tip default
parent child
Show More
@@ -1,102 +1,110
1 1 #include "collapsableperipheralwidget.h"
2 2 #include "ui_collapsableperipheralwidget.h"
3 3 #include <QCursor>
4 4
5 5
6 6 CollapsablePeripheralWidget::CollapsablePeripheralWidget(peripheralWidget *periph, QWidget *parent) :
7 7 QWidget(parent),
8 8 ui(new Ui::CollapsablePeripheralWidget)
9 9 {
10 10 m_periph=0;
11 11 m_collapsed = true;
12 12 ui->setupUi(this);
13 13 tthidetmr.setSingleShot(true);
14 14 tthidetmr.setInterval(200);
15 15 connect(this->ui->collapseQpb,SIGNAL(clicked()),this,SLOT(collapse()));
16 16 connect(this->ui->periphName,SIGNAL(clicked()),this,SLOT(collapse()));
17 17 connect(this->ui->periphName,SIGNAL(enter()),this,SLOT(showTooltip()));
18 18 connect(this->ui->periphName,SIGNAL(leave()),&this->tthidetmr,SLOT(start()));
19 19 connect(&this->tthidetmr,SIGNAL(timeout()),this,SLOT(hideTooltip()));
20 20 setPeripheralWidget(periph);
21 21 }
22 22
23 23 CollapsablePeripheralWidget::~CollapsablePeripheralWidget()
24 24 {
25 25 delete ui;
26 26 }
27 27
28 28 void CollapsablePeripheralWidget::setPeripheralWidget(peripheralWidget *periph)
29 29 {
30 30 if(periph)
31 31 {
32 32 this->m_periph = periph;
33 33 this->ui->gridLayout->addWidget(periph,1,0,1,-1);
34 34 this->ui->periphName->setText(periph->name());
35 35 this->m_periph->setVisible(false);
36 36 }
37 37 }
38 38
39 39 peripheralWidget *CollapsablePeripheralWidget::getPeripheralWidget()
40 40 {
41 41 return m_periph;
42 42 }
43 43
44 44 void CollapsablePeripheralWidget::changeEvent(QEvent *e)
45 45 {
46 46 QWidget::changeEvent(e);
47 47 switch (e->type()) {
48 48 case QEvent::LanguageChange:
49 49 ui->retranslateUi(this);
50 50 break;
51 51 default:
52 52 break;
53 53 }
54 54 }
55 55
56 void CollapsablePeripheralWidget::paintEvent(QPaintEvent *)
57 {
58 QStyleOption opt;
59 opt.init(this);
60 QPainter p(this);
61 style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
62 }
63
56 64 void CollapsablePeripheralWidget::collapse()
57 65 {
58 66 this->m_periph->setVisible(m_collapsed);
59 67 if(this->m_collapsed)
60 68 {
61 69 this->ui->collapseQpb->setIcon(QIcon(":/img/Gnome-list-remove.svg"));
62 70 }
63 71 else
64 72 {
65 73 this->ui->collapseQpb->setIcon(QIcon(":/img/Gnome-list-add.svg"));
66 74 }
67 75 m_collapsed = !m_collapsed;
68 76 }
69 77
70 78 void CollapsablePeripheralWidget::setName(const QString &name)
71 79 {
72 80 if(m_periph)
73 81 {
74 82 this->ui->periphName->setText(name);
75 83 }
76 84 }
77 85
78 86 void CollapsablePeripheralWidget::showTooltip()
79 87 {
80 88 if(!m_periph->isVisible() && m_collapsed)
81 89 {
82 90 m_periph->show();
83 91 }
84 92 }
85 93
86 94 void CollapsablePeripheralWidget::hideTooltip()
87 95 {
88 96 if(m_periph->isVisible() && m_collapsed)
89 97 {
90 98 QRect temprect = this->geometry();
91 99 temprect.moveTo(this->mapToGlobal(mapFromParent(QPoint(this->x(),this->y()))));
92 100 if(temprect.contains(QCursor::pos()))
93 101 {
94 102 this->tthidetmr.start();
95 103 }
96 104 else
97 105 {
98 106 m_periph->hide();
99 107 }
100 108 }
101 109 }
102 110
@@ -1,56 +1,56
1 1 #ifndef COLLAPSABLEPERIPHERALWIDGET_H
2 2 #define COLLAPSABLEPERIPHERALWIDGET_H
3 3
4 4 #include <QWidget>
5 5 #include <peripheralwidget.h>
6 6 #include <QTimer>
7 7
8 8 namespace Ui {
9 9 class CollapsablePeripheralWidget;
10 10 }
11 11
12 12 class QRegToolTipLabel : public QLabel
13 13 {
14 14 Q_OBJECT
15 15 public:
16 16 QRegToolTipLabel(QWidget * parent = 0, Qt::WindowFlags f = 0):QLabel(parent,f){}
17 17 QRegToolTipLabel(const QString & text, QWidget * parent = 0, Qt::WindowFlags f = 0):QLabel(text,parent,f){}
18 18 signals:
19 19 void enter();
20 20 void leave();
21 21 void clicked();
22 22 protected:
23 23 void enterEvent(QEvent* event){emit enter();QLabel::enterEvent(event);}
24 24 void leaveEvent(QEvent* event){emit leave();QLabel::leaveEvent(event);}
25 25 void mousePressEvent(QMouseEvent * event){emit clicked();QLabel::mousePressEvent(event);}
26 26 };
27 27
28 28 class CollapsablePeripheralWidget : public QWidget
29 29 {
30 30 Q_OBJECT
31 31
32 32 public:
33 33 explicit CollapsablePeripheralWidget(peripheralWidget* periph,QWidget *parent = 0);
34 34 ~CollapsablePeripheralWidget();
35 35 void setPeripheralWidget(peripheralWidget* periph);
36 36 peripheralWidget* getPeripheralWidget();
37 37 protected:
38 38 void changeEvent(QEvent *e);
39
39 void paintEvent(QPaintEvent *);
40 40 public slots:
41 41 void collapse();
42 42 void setName(const QString& name);
43 43 void showTooltip();
44 44 void hideTooltip();
45 45 signals:
46 46 void clicked(peripheralWidget* sender);
47 47 void upSig(peripheralWidget* sender,int cursorIndex);
48 48 void downSig(peripheralWidget* sender,int cursorIndex);
49 49 private:
50 50 Ui::CollapsablePeripheralWidget *ui;
51 51 peripheralWidget* m_periph;
52 52 bool m_collapsed;
53 53 QTimer tthidetmr;
54 54 };
55 55
56 56 #endif // COLLAPSABLEPERIPHERALWIDGET_H
@@ -1,89 +1,89
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <ui version="4.0">
3 3 <class>CollapsablePeripheralWidget</class>
4 4 <widget class="QWidget" name="CollapsablePeripheralWidget">
5 5 <property name="geometry">
6 6 <rect>
7 7 <x>0</x>
8 8 <y>0</y>
9 <width>845</width>
10 <height>249</height>
9 <width>833</width>
10 <height>192</height>
11 11 </rect>
12 12 </property>
13 13 <property name="sizePolicy">
14 14 <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
15 15 <horstretch>0</horstretch>
16 16 <verstretch>0</verstretch>
17 17 </sizepolicy>
18 18 </property>
19 19 <property name="windowTitle">
20 20 <string>Form</string>
21 21 </property>
22 22 <property name="styleSheet">
23 <string notr="true">QWidget#CollapsablePeripheralWidget {
24 border: 1px solid gray;
25 border-radius: 9px;
26 }</string>
23 <string notr="true"/>
27 24 </property>
28 25 <layout class="QGridLayout" name="gridLayout">
29 26 <item row="0" column="2">
30 27 <widget class="QPushButton" name="collapseQpb">
31 28 <property name="sizePolicy">
32 29 <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
33 30 <horstretch>0</horstretch>
34 31 <verstretch>0</verstretch>
35 32 </sizepolicy>
36 33 </property>
34 <property name="focusPolicy">
35 <enum>Qt::NoFocus</enum>
36 </property>
37 37 <property name="text">
38 38 <string/>
39 39 </property>
40 40 <property name="icon">
41 41 <iconset resource="../ressources/peripheralwidget.qrc">
42 42 <normaloff>:/img/Gnome-list-add.svg</normaloff>
43 43 <normalon>:/img/Gnome-list-remove.svg</normalon>:/img/Gnome-list-add.svg</iconset>
44 44 </property>
45 45 <property name="flat">
46 46 <bool>true</bool>
47 47 </property>
48 48 </widget>
49 49 </item>
50 50 <item row="0" column="0">
51 51 <widget class="QRegToolTipLabel" name="periphName">
52 52 <property name="sizePolicy">
53 53 <sizepolicy hsizetype="Minimum" vsizetype="Preferred">
54 54 <horstretch>0</horstretch>
55 55 <verstretch>0</verstretch>
56 56 </sizepolicy>
57 57 </property>
58 58 <property name="text">
59 59 <string>PeriphName</string>
60 60 </property>
61 61 </widget>
62 62 </item>
63 63 <item row="0" column="1">
64 64 <spacer name="horizontalSpacer">
65 65 <property name="orientation">
66 66 <enum>Qt::Horizontal</enum>
67 67 </property>
68 68 <property name="sizeHint" stdset="0">
69 69 <size>
70 70 <width>40</width>
71 71 <height>20</height>
72 72 </size>
73 73 </property>
74 74 </spacer>
75 75 </item>
76 76 </layout>
77 77 </widget>
78 78 <customwidgets>
79 79 <customwidget>
80 80 <class>QRegToolTipLabel</class>
81 81 <extends>QLabel</extends>
82 82 <header location="global">collapsableperipheralwidget.h</header>
83 83 </customwidget>
84 84 </customwidgets>
85 85 <resources>
86 86 <include location="../ressources/peripheralwidget.qrc"/>
87 87 </resources>
88 88 <connections/>
89 89 </ui>
@@ -1,107 +1,120
1 1 #include "socregsviewernew.h"
2 2 #include "ui_socregsviewernew.h"
3 3
4 4 SocRegsViewerNew::SocRegsViewerNew(const QString &name,QWidget *parent) :
5 5 QWidget(parent),
6 6 ui(new Ui::SocRegsViewerNew)
7 7 {
8 8 ui->setupUi(this);
9 9 this->ui->socName->setText(name);
10 10 }
11 11
12 SocRegsViewerNew::SocRegsViewerNew(QWidget *parent):
13 QWidget(parent),
14 ui(new Ui::SocRegsViewerNew)
15 {
16 ui->setupUi(this);
17 this->ui->socName->setText("No name");
18 }
19
12 20 SocRegsViewerNew::~SocRegsViewerNew()
13 21 {
14 22 delete ui;
15 23 }
16 24
17 25 peripheralWidget *SocRegsViewerNew::peripheral(int index)
18 26 {
19 27 if(index>=0 && index<p_peripherals.count())
20 28 {
21 29 return p_peripherals.at(index);
22 30 }
23 31 return NULL;
24 32 }
25 33
26 34 void SocRegsViewerNew::addPeripheral(peripheralWidget *peripheral)
27 35 {
28 36 if(peripheral!=NULL)
29 37 {
30 38 CollapsablePeripheralWidget* cperiph = new CollapsablePeripheralWidget(peripheral);
31 39 cperiph->setPeripheralWidget(peripheral);
32 40 p_peripherals.append(peripheral);
33 41 p_CPeripherals.append(cperiph);
34 42 this->ui->scrollAreaWidgetContents->layout()->addWidget(cperiph);
35 43 connect(cperiph,SIGNAL(clicked(peripheralWidget*)),this,SLOT(periphClicked(peripheralWidget*)));
36 44 connect(cperiph,SIGNAL(upSig(peripheralWidget*,int)),this,SLOT(periphUp(peripheralWidget*,int)));
37 45 connect(cperiph,SIGNAL(downSig(peripheralWidget*,int)),this,SLOT(periphDown(peripheralWidget*,int)));
38 46 }
39 47 }
40 48
41 49 void SocRegsViewerNew::periphClicked(peripheralWidget *sender)
42 50 {
43 51 peripheralWidget * item;
44 52 if(sender!=NULL)
45 53 {
46 54 for(int i=0;i<p_peripherals.count();i++)
47 55 {
48 56 item = p_peripherals.at(i);
49 57 if(item!=sender)
50 58 {
51 59 item->leave();
52 60 }
53 61 }
54 62 }
55 63 }
56 64
57 65 void SocRegsViewerNew::periphUp(peripheralWidget *sender, int cursorIndex)
58 66 {
59 67 int index,senderIndex;
60 68 if(sender!=NULL)
61 69 {
62 70 index =senderIndex= p_peripherals.indexOf(sender);
63 71 while(index!=-1 && index!=0)
64 72 {
65 73 if(p_peripherals.at(index-1)->count()>0)
66 74 {
67 75 p_peripherals.at(senderIndex)->leave();
68 76 p_peripherals.at(index-1)->enter(cursorIndex,false);
69 // ensureWidgetVisible(p_peripherals.at(index-1));
77 // ensureWidgetVisible(p_peripherals.at(index-1));
70 78 break;
71 79 }
72 80 index--;
73 81 }
74 82 }
75 83 }
76 84
77 85 void SocRegsViewerNew::periphDown(peripheralWidget *sender, int cursorIndex)
78 86 {
79 87 int index,senderIndex;
80 88 if(sender!=NULL)
81 89 {
82 90 index=senderIndex= p_peripherals.indexOf(sender);
83 91 while((index!=-1) && (index<(p_peripherals.count()-1)))
84 92 {
85 93 if(p_peripherals.at(index+1)->count()>0)
86 94 {
87 95 p_peripherals.at(senderIndex)->leave();
88 96 p_peripherals.at(index+1)->enter(cursorIndex);
89 // ensureWidgetVisible(p_peripherals.at(index+1));
97 // ensureWidgetVisible(p_peripherals.at(index+1));
90 98 break;
91 99 }
92 100 index++;
93 101 }
94 102 }
95 103 }
96 104
105 void SocRegsViewerNew::setSocName(const QString &name)
106 {
107 this->ui->socName->setText(name);
108 }
109
97 110 void SocRegsViewerNew::changeEvent(QEvent *e)
98 111 {
99 112 QWidget::changeEvent(e);
100 113 switch (e->type()) {
101 114 case QEvent::LanguageChange:
102 115 ui->retranslateUi(this);
103 116 break;
104 117 default:
105 118 break;
106 119 }
107 120 }
@@ -1,38 +1,40
1 1 #ifndef SOCREGSVIEWERNEW_H
2 2 #define SOCREGSVIEWERNEW_H
3 3
4 4 #include <QWidget>
5 5 #include <peripheralwidget.h>
6 6 #include <collapsableperipheralwidget.h>
7 7
8 8 namespace Ui {
9 9 class SocRegsViewerNew;
10 10 }
11 11
12 12 class SocRegsViewerNew : public QWidget
13 13 {
14 14 Q_OBJECT
15 15
16 16 public:
17 17 explicit SocRegsViewerNew(const QString &name, QWidget *parent = 0);
18 explicit SocRegsViewerNew(QWidget *parent = 0);
18 19 ~SocRegsViewerNew();
19 20
20 21 peripheralWidget *peripheral(int index);
21 22
22 23 signals:
23 24
24 25 public slots:
25 26 void addPeripheral(peripheralWidget* peripheral);
26 27 void periphClicked(peripheralWidget* sender);
27 28 void periphUp(peripheralWidget* sender,int cursorIndex);
28 29 void periphDown(peripheralWidget* sender,int cursorIndex);
30 void setSocName(const QString& name);
29 31 protected:
30 32 void changeEvent(QEvent *e);
31 33
32 34 private:
33 35 Ui::SocRegsViewerNew *ui;
34 36 QList<peripheralWidget*> p_peripherals;
35 37 QList<CollapsablePeripheralWidget*> p_CPeripherals;
36 38 };
37 39
38 40 #endif // SOCREGSVIEWERNEW_H
@@ -1,60 +1,50
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <ui version="4.0">
3 3 <class>SocRegsViewerNew</class>
4 4 <widget class="QWidget" name="SocRegsViewerNew">
5 5 <property name="geometry">
6 6 <rect>
7 7 <x>0</x>
8 8 <y>0</y>
9 9 <width>713</width>
10 10 <height>357</height>
11 11 </rect>
12 12 </property>
13 13 <property name="windowTitle">
14 14 <string>Form</string>
15 15 </property>
16 16 <layout class="QGridLayout" name="gridLayout">
17 <item row="0" column="1">
18 <widget class="QComboBox" name="rootPluginCmbBx"/>
19 </item>
20 <item row="2" column="0" colspan="2">
17 <item row="1" column="0" colspan="2">
21 18 <widget class="QScrollArea" name="PeriphList">
22 19 <property name="widgetResizable">
23 20 <bool>true</bool>
24 21 </property>
25 22 <widget class="QWidget" name="scrollAreaWidgetContents">
26 23 <property name="geometry">
27 24 <rect>
28 25 <x>0</x>
29 26 <y>0</y>
30 27 <width>693</width>
31 <height>302</height>
28 <height>337</height>
32 29 </rect>
33 30 </property>
34 31 <layout class="QVBoxLayout" name="verticalLayout">
35 32 <item>
36 33 <widget class="QLabel" name="socName">
37 34 <property name="text">
38 35 <string>SocName</string>
39 36 </property>
40 37 <property name="alignment">
41 38 <set>Qt::AlignCenter</set>
42 39 </property>
43 40 </widget>
44 41 </item>
45 42 </layout>
46 43 </widget>
47 44 </widget>
48 45 </item>
49 <item row="0" column="0">
50 <widget class="QLabel" name="label">
51 <property name="text">
52 <string>Root Plugin</string>
53 </property>
54 </widget>
55 </item>
56 46 </layout>
57 47 </widget>
58 48 <resources/>
59 49 <connections/>
60 50 </ui>
General Comments 0
You need to be logged in to leave comments. Login now