socregsviewer.cpp
113 lines
| 3.8 KiB
| text/x-c
|
CppLexer
/ src / socregsviewer.cpp
Jeandet Alexis
|
r17 | /*------------------------------------------------------------------------------ | ||
-- This file is a part of the SocExplorer Software | ||||
-- Copyright (C) 2014, Plasma Physics Laboratory - CNRS | ||||
-- | ||||
-- 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 3 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||||
-------------------------------------------------------------------------------*/ | ||||
/*-- Author : Alexis Jeandet | ||||
-- Mail : alexis.jeandet@member.fsf.org | ||||
----------------------------------------------------------------------------*/ | ||||
r6 | #include "socregsviewer.h" | |||
socRegsViewer::socRegsViewer(const QString &name, QWidget *parent) : | ||||
QScrollArea(parent) | ||||
{ | ||||
p_name = name; | ||||
p_scrollAreaWdgt = new QWidget(this); | ||||
p_scrollAreaWdgtLayout = new QGridLayout(p_scrollAreaWdgt); | ||||
//p_layout = new QGridLayout(this); | ||||
p_nameLabel = new QLabel(name); | ||||
setWidget(p_scrollAreaWdgt); | ||||
setWidgetResizable(true); | ||||
p_scrollAreaWdgt->setLayout(p_scrollAreaWdgtLayout); | ||||
p_scrollAreaWdgtLayout->addWidget(p_nameLabel,0,0,1,1); | ||||
} | ||||
peripheralWidget *socRegsViewer::peripheral(int index) | ||||
{ | ||||
if(index>=0 && index<p_peripherals.count()) | ||||
{ | ||||
return p_peripherals.at(index); | ||||
} | ||||
return NULL; | ||||
} | ||||
void socRegsViewer::addPeripheral(peripheralWidget *peripheral) | ||||
{ | ||||
if(peripheral!=NULL) | ||||
{ | ||||
p_peripherals.append(peripheral); | ||||
p_scrollAreaWdgtLayout->addWidget(peripheral,p_peripherals.count(),0,1,-1); | ||||
Jeandet Alexis
|
r11 | connect(peripheral,SIGNAL(clicked(peripheralWidget*)),this,SLOT(periphClicked(peripheralWidget*))); | ||
connect(peripheral,SIGNAL(upSig(peripheralWidget*,int)),this,SLOT(periphUp(peripheralWidget*,int))); | ||||
connect(peripheral,SIGNAL(downSig(peripheralWidget*,int)),this,SLOT(periphDown(peripheralWidget*,int))); | ||||
} | ||||
} | ||||
void socRegsViewer::periphClicked(peripheralWidget *sender) | ||||
{ | ||||
peripheralWidget * item; | ||||
if(sender!=NULL) | ||||
{ | ||||
for(int i=0;i<p_peripherals.count();i++) | ||||
{ | ||||
item = p_peripherals.at(i); | ||||
if(item!=sender) | ||||
{ | ||||
item->leave(); | ||||
} | ||||
} | ||||
r6 | } | |||
} | ||||
Jeandet Alexis
|
r11 | |||
void socRegsViewer::periphUp(peripheralWidget *sender, int cursorIndex) | ||||
{ | ||||
r16 | int index,senderIndex; | |||
Jeandet Alexis
|
r11 | if(sender!=NULL) | ||
{ | ||||
r16 | index =senderIndex= p_peripherals.indexOf(sender); | |||
while(index!=-1 && index!=0) | ||||
Jeandet Alexis
|
r11 | { | ||
r16 | 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--; | ||||
Jeandet Alexis
|
r11 | } | ||
} | ||||
} | ||||
void socRegsViewer::periphDown(peripheralWidget *sender, int cursorIndex) | ||||
{ | ||||
r16 | int index,senderIndex; | |||
Jeandet Alexis
|
r11 | if(sender!=NULL) | ||
{ | ||||
r16 | index=senderIndex= p_peripherals.indexOf(sender); | |||
while((index!=-1) && (index<(p_peripherals.count()-1))) | ||||
Jeandet Alexis
|
r11 | { | ||
r16 | 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++; | ||||
Jeandet Alexis
|
r11 | } | ||
} | ||||
} | ||||