⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 canvasview.cpp

📁 This a framework to test new ideas in transmission technology. Actual development is a LDPC-coder in
💻 CPP
字号:
/*******************************************************************************//*  Project:        SOFTWARE RADIO - LCM Laboratoire de Communications Mobiles *//*  -------------------------------------------------------------------------- *//*  Filename:       canvasview.cpp                                             *//*  Description:    Subclass of QCanvasview, implements mouse click functiona- *//*                  lities.                                                    *//*  -------------------------------------------------------------------------- *//*  Date:           January 09 2003                                            *//*  Version:        v1.0                                                       *//*  Authors:        Braure Jerome, Ferreiro Jose                               *//*                  Communication Systems (9th semester) - EPFL                *//*  Changelog:    04/03/01 - ineiti - gray out empty output-ports*/     /*******************************************************************************//*******************************************************************************//*  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.                                                         *//*******************************************************************************/#include <qlabel.h>#include <qobject.h>#include <qlayout.h>#include <qcombobox.h>#include <qwidget.h>#include <qdir.h>// #include <qtimer.h>#include <qcheckbox.h>#include <qmainwindow.h>#include <qapplication.h>#include <qpopupmenu.h>#include <qcursor.h>#include <qstring.h>#include <qworkspace.h>#include <stdlib.h>#include "canvasview.h"#include "parameter_types.h"#include "parameters.h"#include "global.h"#include <qpushbutton.h>#define BLOCK_PORT  1#define BLOCK_STATS 2/*******************************************************************************//* Function:    CanvasView() - (constuctor)                                    *//* Description: Constructs an instance of class CanvasView, which inherits     *//*              from class QCanvasView (and QWidget). It is used to handle the *//*              mouse click events.                                            *//* Inputs:      canvas: pointer to the QCanvas on which the user clicks.       *//*              parent: pointer to the parent QWidget.                         *//*              mapper: pointer to the module mapper.                          *//*******************************************************************************/CanvasView::CanvasView( QCanvas* canvas, QWidget* parent, Mapper* m )  : QCanvasView( canvas, parent, 0, 0 ), mapper( m ) {  selectedModule = NULL;  window = parent;  mousePressX = 0;  mousePressY = 0;  centeredX = 0;  centeredY = 0;  QString visualize_path( getenv( "VISUALIZE_PATH" ) );  graphItem = new QPixmap( QString( visualize_path ).			   append( "/icons/plot.png" ) );}/*******************************************************************************//* Function:    contentsMousePressEvent()                                      *//* Description: Function called when the user clicks on the canvas. If the     *//*              user hits the left mouse button (and holds it down), he will   *//*              be able to drag the whole canvas. If it is the right mouse     *//*              button, a context menu appears.                                *//* Inputs:      e: pointer to the QMouseEvent.                                 *//* Returns:     void.                                                          *//*******************************************************************************/void CanvasView::contentsMousePressEvent( QMouseEvent* e ) {  mousePressed = true;  mousePressX = e->x();  mousePressY = e->y();  centeredX = this->contentsX();  centeredY = this->contentsY();  Module* module = mapper->getModule( mousePressX, mousePressY );  if ( module != NULL ) {    emit moduleSelected ( module );    //       cout<<"canvasview emit moduleselected :"<<module->name<<"\n";  }  // right button click  if ( e->button() == Qt::RightButton ) {    QPopupMenu * contextMenu = new QPopupMenu;    //find out which module is under the mouse    if ( module != NULL ) {      selectedModule = module;      contextMenu->insertItem( module->name );      contextMenu->insertSeparator();      // add items to "display data" menu      int listLength = module->statsList.count();      if ( listLength != 0 ) {        QPopupMenu * dataMenu = new QPopupMenu;        contextMenu->insertItem( "Display data", dataMenu );        for ( int i = 0; i < listLength; i++ ) {	  Stats *s = module->statsList.at( i );	  // Do we want to show it?	  if ( s->isShown() ){	    // Show a nice icon for graphs and images	    if ( s->type == BLOCK || s->type == IMAGE ){	      dataMenu->insertItem( QIconSet( *graphItem ), s->getName(), i );	    } else {	      dataMenu->insertItem( s->getName(), i );	    }	  }        }        connect( dataMenu, SIGNAL( activated( int ) ),                 this, SLOT( slotDisplayStatsData( int ) ) );      }      // add items to "display outputs"      QPtrList<Port> *pList = &module->portList;      listLength = pList->count();      if ( listLength != 0 ) {        QPopupMenu * outputsMenu = new QPopupMenu;	int items = 0;        for ( int i = 0; i < listLength; i++ ) {	  Port *p = pList->at( i );	  int it = outputsMenu->insertItem( QIconSet( *graphItem ),					    p->getName(), i );	  if ( p->getLength() ){	    items++;	  } else {	    outputsMenu->setItemEnabled( it, false );	  }        }	  	if ( items ){	  contextMenu->insertItem( "Display outputs", outputsMenu );	  connect( outputsMenu, SIGNAL( activated( int ) ),		   this, SLOT( slotDisplayPortData( int ) ) );	}      }      // Are there non-hidden config parameters?      for ( uint i=0; i<module->configList.count(); i++ ){	Config *config = module->configList.at( i );	if ( config->isShown() ){	  contextMenu->insertItem( "Change config ", 1 );	  connect( contextMenu, SIGNAL( activated( int ) ),		   this, SLOT( slotConfig( int ) ) );	  break;	}      }      // Offer a 'process data' point      // cout << "Module's ID:" << module->getId() << endl;      if ( isDebug ){	contextMenu->insertItem( "Process Data", this, SLOT( processData() ) );      }    } else {           //cout << "stfaNbr is" << mapper->stfaNbr << endl;      if(mapper->stfaNbr>1){	QString stfa_id;	QPopupMenu * stfaMenu = new QPopupMenu;        contextMenu->insertItem( "Choose stfa", stfaMenu );	for(int i=0; i<mapper->stfaNbr; i++){	  stfa_id="STFA ";	  stfa_id+=(char)(i+48);	  stfaMenu->insertItem( stfa_id, i );	 	}	stfaMenu->connect( stfaMenu, SIGNAL( activated( int )), this, SLOT( slotStfaChoosen( int ) ) );       }      contextMenu->insertItem( "&Quit", qApp, SLOT( quit() ) );    }    contextMenu->exec( QCursor::pos() );  }    // left button click  else if ( e->button() == Qt::LeftButton ) {        setCursor( SizeAllCursor );  }}/*******************************************************************************//* Function:    mouseReleaseEvent()                                            *//* Description: Function called when the user releases the mouse button.       *//* Inputs:      e: pointer to the QMouseEvent.                                 *//* Returns:     void.                                                          *//*******************************************************************************/void CanvasView::mouseReleaseEvent( QMouseEvent * ) {  mousePressed = false;  setCursor( ArrowCursor );}/*******************************************************************************//* Function:    mouseMoveEvent()                                               *//* Description: Function called when the the mouse is moved while a button is  *//*              pressed.                                                       *//* Inputs:      e: pointer to the QMouseEvent.                                 *//* Returns:     void.                                                          *//*******************************************************************************/void CanvasView::mouseMoveEvent( QMouseEvent *e ) {  // follow the mouse  int windowWidth = window->width();  int windowHeight = window->height();  int x = centeredX + e->x();  int y = centeredY + e->y();  this->center( centeredX + ( mousePressX - x ) + ( windowWidth / 2 ) - 8,                centeredY + ( mousePressY - y ) + ( windowHeight / 2 ) - 23 );}/*******************************************************************************//* Function:    slotConfig()                                                   *//* Description: Called when an item of the "Change config" context menu is     *//*              clicked.                                                       *//* Inputs:      idint configId =: identify what was clicked in context menu.                 *//* Returns:     void.                                                          *//*******************************************************************************/void CanvasView::slotConfig( int id ) {  if ( id == 1 ) { // "change config" is clicked.    if ( selectedModule ){      selectedModule->showConfig();    } else {      cout << "slotconfig: Called and no selectedModule!\n";    }  }}/*******************************************************************************//* Function:    slotDisplayStatsData()                                         *//* Description: Called when an item of "display data" is clicked.              *//* Inputs:      id: index of the stat in the stat vector.                      *//* Returns:     void.                                                          *//*******************************************************************************/void CanvasView::slotDisplayStatsData( int id ) {  if ( selectedModule ){    selectedModule->plotData( id, Module::block_stats );  } else {    cout << "slotDisplayStatsData: How did we get called? Strange\n";  }}/*******************************************************************************//* Function:    slotDisplayPortData()                                          *//* Description: slot called when an item of "display outputs" is clicked.      *//* Inputs:      id: index of the stat in the ports vector.                     *//* Returns:     void.                                                          *//*******************************************************************************/void CanvasView::slotDisplayPortData( int id ) {  if ( selectedModule ){    selectedModule->plotData( id, Module::block_port );  } else {    cout << "slotDisplayPortData: How did we get called? Strange\n";  }}void CanvasView::slotStfaChoosen(int id) {  mapper->stfaChosen=id;}void CanvasView::processData(){  if ( selectedModule ){    selectedModule->processData();  } else {    cout << "processData: How did we get called? Strange\n";  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -