SpikeStream Application Library  0.2
SpikeStreamApplication.cpp
Go to the documentation of this file.
00001 //SpikeStream includes
00002 #include "SpikeStreamApplication.h"
00003 #include "SpikeStreamException.h"
00004 using namespace spikestream;
00005 
00006 //Qt includes
00007 #include <QDebug>
00008 
00009 //Other includes
00010 #ifdef LINUX32_SPIKESTREAM
00011         #include <X11/Xlib.h>
00012 #endif
00013 #include <iostream>
00014 using namespace std;
00015 
00016 
00018 SpikeStreamApplication::SpikeStreamApplication(int & argc, char ** argv) : QApplication(argc, argv){
00019         renderDuration_ms = 0;
00020         startRenderKeyEventTime = 0;
00021         rendering = false;
00022 
00023         //Set the application styles
00024         this->setStyleSheet("* { font-size: 12px; }");
00025 }
00026 
00027 
00029 SpikeStreamApplication::~SpikeStreamApplication(){
00030 }
00031 
00032 
00033 //Inherited from QApplication
00034 bool SpikeStreamApplication::notify(QObject* receiver, QEvent* event){
00035         bool result = true;
00036         try{
00037                 result = QApplication::notify(receiver, event);
00038         }
00039         catch(SpikeStreamException& ex){
00040                 qCritical()<<"Event handling exception: "<<ex.getMessage();
00041         }
00042         catch (exception& e) {
00043                 qCritical()<<"STD exception occurred during event handling: "<<e.what();
00044         }
00045         catch(...){
00046                 qCritical()<<"Unknown event handling exception.";
00047         }
00048         return result;
00049 }
00050 
00051 
00052 //--------------------------------------------------------------------------
00053 //-------------------------- PUBLIC METHODS --------------------------------
00054 //--------------------------------------------------------------------------
00055 
00058 void SpikeStreamApplication::startRender(){
00059         rendering = true;
00060         gettimeofday(&startRenderTime, NULL);
00061         startRenderKeyEventTime = keyEventTime;
00062 }
00063 
00064 
00067 void SpikeStreamApplication::stopRender(){
00068         rendering = false;
00069         gettimeofday(&stopRenderTime, NULL);
00070         renderDuration_ms = 1000 * (stopRenderTime.tv_sec - startRenderTime.tv_sec) + (stopRenderTime.tv_usec - startRenderTime.tv_usec) / 1000;
00071 }
00072 
00073 
00074 //---------------------------------------------------------------------------
00075 //------------------------- PROTECTED METHODS -------------------------------
00076 //---------------------------------------------------------------------------
00077 
00085 #ifdef LINUX32_SPIKESTREAM
00086         bool SpikeStreamApplication::x11EventFilter( XEvent * xEvent){
00087 
00088                 //Look for events from the keyboard
00089                 if(xEvent->type == KeyPress || xEvent->type == KeyRelease){
00090                         //Record time of key event
00091                         keyEventTime = xEvent->xkey.time;
00092 
00093                         //If the key event arrived during the render, ignore it.
00094                         if((keyEventTime - startRenderKeyEventTime) < renderDuration_ms){
00095                                 return true;
00096                         }
00097                 }
00098                 return false;
00099         }
00100 #endif//LINUX32_SPIKESTREAM
00101 
00102 
00103 
 All Classes Files Functions Variables Typedefs Friends Defines