Ejemplo n.º 1
0
void	hellDecoder::setup_hellDecoder (int32_t rate) {
int16_t	i, j;

	theRate		= rate;
	bandpass		= new fftFilter (1024, 127);
	averager		= NULL;	// depends on settings
	smoothener		= new average (8);
	hellIF			= HELL_IF;
	localOscillator		= new Oscillator (theRate);
	sampleCounter		= 0.0;
	maxValue 		= 0.0;
	blackBackground		= false;
	reverse			= false;
	memset (columnBuffer, 0, 2 * RxColumnLen * sizeof (int16_t));
	columnBufferp		= 0;
	agc			= 0.0;
	rateCorrector		= 0;
	fullWidth		= true;	
	hellSettings		-> beginGroup ("hellDecoder");
	rateCorrector		= hellSettings ->
	                             value ("hell_rateCorrector", 0).
	                                                         toInt ();
	hell_rateCorrector	-> setValue (rateCorrector);
	QString temp		= hellSettings -> value ("hellMode",
	                               hell_modeSelector -> currentText ()).
	                                                          toString ();
	int16_t k	= hell_modeSelector -> findText (temp);
	if (k != -1)
	   hell_modeSelector	-> setCurrentIndex (k);
	selectMode		(hell_modeSelector -> currentText ());
	hellSettings		-> endGroup ();

	connect (hell_modeSelector, SIGNAL (activated (QString)),
	         this, SLOT (selectMode (QString)));
	connect (hell_switchBlackback, SIGNAL (clicked (void)),
	         this, SLOT (switchBlackback (void)));
	connect (hell_switchWidth, SIGNAL (clicked (void)),
	         this, SLOT (switchWidth (void)));
	connect (hell_rateCorrector, SIGNAL (valueChanged (int)),
	         this, SLOT (set_rateCorrector (int)));
//
//	and for the dot canvas we have
	image			= QImage (BufferSize,
	                                  2 * RxColumnLen,
	                                  QImage::Format_RGB32);
	for (i = 0; i < image. width (); i ++)
	   for (j = 0; j < image. height (); j ++)
	      image. setPixel (QPoint (i, j), qRgb (i % 256, i % 256, i % 256));

	imageLabel		= new QLabel;
	imageLabel		-> setPixmap (QPixmap::fromImage (image));
	hellText		-> setWidget (imageLabel);
	imageLabel		-> show ();
}
/**
* begin sampling at given interface mode
*/
void Alislahish_PCM1808::begin(InterfaceModes mode, AudioInterfaceFormats format){
	setPinModes();
	//selectSamplingFrequency(freq);
	selectMode(mode);
	selectFormat(format);
	resume();
}
Ejemplo n.º 3
0
bool	hellDecoder::initforRate	(int32_t rate) {
	if (theRate == rate)
	   return true;
	theRate	= rate;
	selectMode (hellMode);
	return true;
}
Ejemplo n.º 4
0
void	hellDecoder::selectMode (QString s) {
	if (s == "feldhell")
	   hellMode	= MODE_FELDHELL;
	else
	if (s == "slowhell")
	   hellMode	= MODE_SLOWHELL;
	else
	if (s == "hellx5")
	   hellMode	= MODE_HELLX5;
	else
	if (s == "hellx9")
	   hellMode	= MODE_HELLX9;
	else
	if (s == "fskhell")
	   hellMode	= MODE_FSKHELL;
	else
	if (s == "fskh105")
	   hellMode	= MODE_FSKH105;
	else
	if (s == "fskh245")
	   hellMode	= MODE_FSKH245;
	else
	   hellMode	= MODE_HELL80;

	selectMode (hellMode);
}
Ejemplo n.º 5
0
Gyroscope::Gyroscope(L3GD20_InitTypeDef& gyroInit, L3GD20_FilterConfigTypeDef& filterConfig, uint16_t maxBufferSize) :
_maxBufferSize(maxBufferSize)
{
	switch(gyroInit.Output_DataRate)
	{
	case L3GD20_OUTPUT_DATARATE_1:
		_deltaT = 1.0 / L3G_ODR_95;
		break;
	case L3GD20_OUTPUT_DATARATE_2:
		_deltaT = 1.0 / L3G_ODR_190;
		break;
	case L3GD20_OUTPUT_DATARATE_3:
		_deltaT = 1.0 / L3G_ODR_380;
		break;
	case L3GD20_OUTPUT_DATARATE_4:
		_deltaT = 1.0 / L3G_ODR_760;
		break;
	default:
		return;
	}

    /* Configure Mems L3GD20 */ 
    L3GD20_Init(&gyroInit);
    L3GD20_FilterConfig(&filterConfig);
    selectMode(BypassMode);
    useHighPassFilter(true);
    
    /* Initialize scale buffer */
    _scaleBuffer.push_back(std::make_pair(gyroInit.Full_Scale, 0));
}
Ejemplo n.º 6
0
void runTwoway() {
  setOutput(AMIGA_FIRE_CLK);
  setOutput(AMIGA_SEL);
  while (1) {
    direction(SNESPAD_DIR_RIGHT, AMIGA_DIR_RIGHT);
    direction(SNESPAD_DIR_LEFT, AMIGA_DIR_LEFT);
    button(SNESPAD_B, AMIGA_DIR_UP);
    button(SNESPAD_Y, AMIGA_FIRE_CLK);

    selectMode();
  }
}
Ejemplo n.º 7
0
void hudMode(bool on) {
	selectMode(1);

	if(on) {
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glEnableVertexAttribArray(hudposloc);
		glEnableVertexAttribArray(texcoordloc);
	} else {
		glDisable(GL_BLEND);
		glDisableVertexAttribArray(hudposloc);
		glDisableVertexAttribArray(texcoordloc);
	}
}
Ejemplo n.º 8
0
void terrainMode(bool on) {
	selectMode(0);

	if(on) {
		glEnable(GL_DEPTH_TEST);
		glEnableVertexAttribArray(posloc);
		glEnableVertexAttribArray(normloc);
		glEnableVertexAttribArray(colloc);
	} else {
		glDisable(GL_DEPTH_TEST);
		glDisableVertexAttribArray(posloc);
		glDisableVertexAttribArray(normloc);
		glDisableVertexAttribArray(colloc);
	}
}
Ejemplo n.º 9
0
int Accelerometer::test()
{
	Stopwatch sw;
	selectMode(Accelerometer::FifoMode);
	discard(true);
	clearFifo();
	sw.start();
	while(sw.elapsed() < 1000)
	{
		retrieveValues();
	}

	// TODO: Data rate je 2x vyssi nez by mal byt
	// TODO: 400 a 1344 Hz nefunguje spravne
	return _dataBuffer.size();
}
Ejemplo n.º 10
0
int Gyroscope::test()
{
	Stopwatch sw;
	selectMode(Gyroscope::FifoMode);
	discard(true);
	clearFifo();
	sw.start();
	while(sw.elapsed() < 1000)
	{
		retrieveValues();
	}

	// TODO: Data rate je 2x vyssi nez by mal byt

	return _dataBuffer.size();
}
Ejemplo n.º 11
0
Accelerometer::Accelerometer(LSM303DLHCAcc_InitTypeDef& accInit, LSM303DLHCAcc_FilterConfigTypeDef& filterConfig, uint16_t maxBufferSize) :
_maxBufferSize(maxBufferSize)
{
	switch(accInit.AccOutput_DataRate)
	{
	case LSM303DLHC_ODR_1_HZ:
		_deltaT = 1.0 / LSM_ACC_ODR_1;
		break;
	case LSM303DLHC_ODR_10_HZ:
		_deltaT = 1.0 / LSM_ACC_ODR_10;
		break;
	case LSM303DLHC_ODR_25_HZ:
		_deltaT = 1.0 / LSM_ACC_ODR_25;
		break;
	case LSM303DLHC_ODR_50_HZ:
		_deltaT = 1.0 / LSM_ACC_ODR_50;
		break;
	case LSM303DLHC_ODR_100_HZ:
		_deltaT = 1.0 / LSM_ACC_ODR_100;
		break;
	case LSM303DLHC_ODR_200_HZ:
		_deltaT = 1.0 / LSM_ACC_ODR_200;
		break;
	case LSM303DLHC_ODR_400_HZ:
		_deltaT = 1.0 / LSM_ACC_ODR_400;
		break;
	case LSM303DLHC_ODR_1344_HZ:
		_deltaT = 1.0 / LSM_ACC_ODR_1344;
		break;
	default:
		return;
	}

    /* Configure Mems LSM303DLHC Accelerometer */
	LSM303DLHC_AccInit(&accInit);
    LSM303DLHC_AccFilterConfig(&filterConfig);
    selectMode(BypassMode);
    // TODO: filter defaultne vypnuty, po zapnuti nepodava spravne hodnoty (preco? Lebo high pass filtruje dlhodobu gravitaciu?)
    // useHighPassFilter(true);
    // uint8_t aaa;
    // LSM303DLHC_Read(ACC_I2C_ADDRESS, LSM303DLHC_CTRL_REG2_A, &aaa, 1);

    /* Initialize scale buffer */
    _scaleBuffer.push_back(std::make_pair(accInit.AccFull_Scale, 0));
}
Ejemplo n.º 12
0
Archivo: graph.c Proyecto: chain78/none
int main(void){
    PMInfoBlock *pm = NULL;
    installGDT(0xa000 >> 3,0xa0000,0xffff,0,0,1,0,1,2);
    installGDT(0xb000 >> 3,0xb0000,0xffff,0,0,1,0,1,2);
    memcpy(VGABASE,(void*)(0xc0000),VGALIMIT);
    pm = getPMInfo();
    pm->biosDataSel = 0x10;
    entry = pm->entryPoint;


    memcpy((void*)0x1000,(void*)_int10,0x100);
    selectMode(M640x480x8);
#if 0
    drawX(0,640,0,480,33);
    drawX(40,600,40,440,60);
    drawX(40,600,40,60,150);
    drawX(60,580,60,420,200);
#endif

    BMPRGB c = {0xff,0xff,0xff};
    for(int i = 1;i < 140;i++){
        drawCircle(320,240,i,0,i);
        setPalett(c,i);
    }
    for(int i = 1,ver = 1;;c.red += 131,c.green += 13,c.blue += 17){
        do{
            i += ver;
            for(int delay = 0xfff;delay--;);
            setPalett(c,i - ver);
        } while((i > 1)&& (i < 140));
        ver = -ver;
    }
#if 0
    drawX(0,640,460,480,43);
    drawCircle(20,470,10,1,40);
    drawX(600,640,460,480,60);
#endif
#ifdef  PRINT_TEXT
    for(int i = 'A';i < 127;i++) gputc(i);
#endif
    //while(1);
    return 0;
}
Ejemplo n.º 13
0
/** 
* @brief Set the mode of the mode function
* 
* @param mode
*/
void setMode(int mode) {
    GtkWidget* widget;
    switch(mode) {
        case modeLSB:
            widget=buttonLSB;
            break;
        case modeUSB:
            widget=buttonUSB;
            break;
        case modeDSB:
            widget=buttonDSB;
            break;
        case modeCWL:
            widget=buttonCWL;
            break;
        case modeCWU:
            widget=buttonCWU;
            break;
        case modeAM:
            widget=buttonAM;
            break;
        case modeSAM:
            widget=buttonSAM;
            break;
        case modeFMN:
            widget=buttonFMN;
            break;
        case modeDIGL:
            widget=buttonDIGL;
            break;
        case modeSPEC:
            widget=buttonSPEC;
            break;
        case modeDIGU:
            widget=buttonDIGU;
            break;
        case modeDRM:
            widget=buttonDRM;
            break;
    }
    selectMode(widget);
}
Ejemplo n.º 14
0
int main(void)
{
	/* Welcome Message*/	
	GWindow window = newGWindow(WIDTH, HEIGHT);			// instantiates a window
	setWindowTitle(window, "Tic-Tac-Toe");
	welcome(window);
	
	/* Mode Selection */	
	int mode = selectMode(window);
	
	
	/*  Show Rules */
	showRules(mode, window);
	
	/* Play Game */
	play(mode, window);
	
	/* End Message */
	endMessage(window);
	
	waitForClick();
	closeGWindow(window);
    return 0;		   
}
Ejemplo n.º 15
0
WorkoutWindow::WorkoutWindow(Context *context) :
    GcChartWindow(context), draw(true), context(context), active(false), recording(false)
{
    setContentsMargins(0,0,0,0);
    setProperty("color", GColor(CTRAINPLOTBACKGROUND));

    setControls(NULL);
    ergFile = NULL;

    QVBoxLayout *main = new QVBoxLayout;
    QHBoxLayout *layout = new QHBoxLayout;
    QVBoxLayout *editor = new QVBoxLayout;
    setChartLayout(main);

    connect(context, SIGNAL(configChanged(qint32)), this, SLOT(configChanged(qint32)));

    // the workout scene
    workout = new WorkoutWidget(this, context);

    // paint the TTE curve
    mmp = new WWMMPCurve(workout);

    // add a line between the dots
    line = new WWLine(workout);

    // block cursos
    bcursor = new WWBlockCursor(workout);

    // block selection
    brect = new WWBlockSelection(workout);

    // paint the W'bal curve
    wbline = new WWWBLine(workout, context);

    // telemetry
    telemetry = new WWTelemetry(workout, context);

    // add the power, W'bal scale
    powerscale = new WWPowerScale(workout, context);
    wbalscale = new WWWBalScale(workout, context);

    // lap markers
    lap = new WWLap(workout);

    // tte warning bar at bottom
    tte = new WWTTE(workout);

    // selection tool
    rect = new WWRect(workout);

    // guides always on top!
    guide = new WWSmartGuide(workout);

    // recording ...
    now = new WWNow(workout, context);

    // scroller, hidden until needed
    scroll = new QScrollBar(Qt::Horizontal, this);
    scroll->hide();

    // setup the toolbar
    toolbar = new QToolBar(this);
    toolbar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    toolbar->setFloatable(true);
    toolbar->setIconSize(QSize(18 *dpiXFactor,18 *dpiYFactor));

    QIcon newIcon(":images/toolbar/new doc.png");
    newAct = new QAction(newIcon, tr("New"), this);
    connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
    toolbar->addAction(newAct);

    QIcon saveIcon(":images/toolbar/save.png");
    saveAct = new QAction(saveIcon, tr("Save"), this);
    connect(saveAct, SIGNAL(triggered()), this, SLOT(saveFile()));
    toolbar->addAction(saveAct);

    QIcon saveAsIcon(":images/toolbar/saveas.png");
    saveAsAct = new QAction(saveAsIcon, tr("Save As"), this);
    connect(saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
    toolbar->addAction(saveAsAct);

    toolbar->addSeparator();

    //XXX TODO
    //XXXHelpWhatsThis *helpToolbar = new HelpWhatsThis(toolbar);
    //XXXtoolbar->setWhatsThis(helpToolbar->getWhatsThisText(HelpWhatsThis::ChartRides_Editor));

    // undo and redo deliberately at a distance from the
    // save icon, since accidentally hitting the wrong
    // icon in that instance would be horrible
    QIcon undoIcon(":images/toolbar/undo.png");
    undoAct = new QAction(undoIcon, tr("Undo"), this);
    connect(undoAct, SIGNAL(triggered()), workout, SLOT(undo()));
    toolbar->addAction(undoAct);

    QIcon redoIcon(":images/toolbar/redo.png");
    redoAct = new QAction(redoIcon, tr("Redo"), this);
    connect(redoAct, SIGNAL(triggered()), workout, SLOT(redo()));
    toolbar->addAction(redoAct);
    
    toolbar->addSeparator();

    QIcon drawIcon(":images/toolbar/edit.png");
    drawAct = new QAction(drawIcon, tr("Draw"), this);
    connect(drawAct, SIGNAL(triggered()), this, SLOT(drawMode()));
    toolbar->addAction(drawAct);

    QIcon selectIcon(":images/toolbar/select.png");
    selectAct = new QAction(selectIcon, tr("Select"), this);
    connect(selectAct, SIGNAL(triggered()), this, SLOT(selectMode()));
    toolbar->addAction(selectAct);

    selectAct->setEnabled(true);
    drawAct->setEnabled(false);

    toolbar->addSeparator();

    QIcon cutIcon(":images/toolbar/cut.png");
    cutAct = new QAction(cutIcon, tr("Cut"), this);
    cutAct->setEnabled(true);
    toolbar->addAction(cutAct);
    connect(cutAct, SIGNAL(triggered()), workout, SLOT(cut()));

    QIcon copyIcon(":images/toolbar/copy.png");
    copyAct = new QAction(copyIcon, tr("Copy"), this);
    copyAct->setEnabled(true);
    toolbar->addAction(copyAct);
    connect(copyAct, SIGNAL(triggered()), workout, SLOT(copy()));

    QIcon pasteIcon(":images/toolbar/paste.png");
    pasteAct = new QAction(pasteIcon, tr("Paste"), this);
    pasteAct->setEnabled(false);
    toolbar->addAction(pasteAct);
    connect(pasteAct, SIGNAL(triggered()), workout, SLOT(paste()));

    toolbar->addSeparator();

    QIcon propertiesIcon(":images/toolbar/properties.png");
    propertiesAct = new QAction(propertiesIcon, tr("Properties"), this);
    connect(propertiesAct, SIGNAL(triggered()), this, SLOT(properties()));
    toolbar->addAction(propertiesAct);

    QIcon zoomInIcon(":images/toolbar/zoom in.png");
    zoomInAct = new QAction(zoomInIcon, tr("Zoom In"), this);
    connect(zoomInAct, SIGNAL(triggered()), this, SLOT(zoomIn()));
    toolbar->addAction(zoomInAct);

    QIcon zoomOutIcon(":images/toolbar/zoom out.png");
    zoomOutAct = new QAction(zoomOutIcon, tr("Zoom Out"), this);
    connect(zoomOutAct, SIGNAL(triggered()), this, SLOT(zoomOut()));
    toolbar->addAction(zoomOutAct);

    // stretch the labels to the right hand side
    QWidget *empty = new QWidget(this);
    empty->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
    toolbar->addWidget(empty);


    xlabel = new QLabel("00:00");
    toolbar->addWidget(xlabel);

    ylabel = new QLabel("150w");
    toolbar->addWidget(ylabel);

    IFlabel = new QLabel("0 Intensity");
    toolbar->addWidget(IFlabel);

    TSSlabel = new QLabel("0 Stress");
    toolbar->addWidget(TSSlabel);

#if 0 // not yet!
    // get updates..
    connect(context, SIGNAL(telemetryUpdate(RealtimeData)), this, SLOT(telemetryUpdate(RealtimeData)));
    telemetryUpdate(RealtimeData());
#endif

    // editing the code...
    code = new CodeEditor(this);
    code->setContextMenuPolicy(Qt::NoContextMenu); // no context menu
    code->installEventFilter(this); // filter the undo/redo stuff
    code->hide();

    // WATTS and Duration for the cursor
    main->addWidget(toolbar);
    editor->addWidget(workout);
    editor->addWidget(scroll);
    layout->addLayout(editor);
    layout->addWidget(code);
    main->addLayout(layout);

    // make it look right
    saveAct->setEnabled(false);
    undoAct->setEnabled(false);
    redoAct->setEnabled(false);

    // watch for erg file selection
    connect(context, SIGNAL(ergFileSelected(ErgFile*)), this, SLOT(ergFileSelected(ErgFile*)));

    // watch for erg run/stop
    connect(context, SIGNAL(start()), this, SLOT(start()));
    connect(context, SIGNAL(stop()), this, SLOT(stop()));

    // text changed
    connect(code, SIGNAL(textChanged()), this, SLOT(qwkcodeChanged()));
    connect(code, SIGNAL(cursorPositionChanged()), workout, SLOT(hoverQwkcode()));

    // scrollbar
    connect(scroll, SIGNAL(sliderMoved(int)), this, SLOT(scrollMoved()));

    // set the widgets etc
    configChanged(CONFIG_APPEARANCE);
}
Ejemplo n.º 16
0
SceneOpenGL::SceneOpenGL(Workspace* ws)
    : Scene(ws)
    , m_resetModelViewProjectionMatrix(true)
    , init_ok(false)
{
    initGLX();
    // check for FBConfig support
    if (!hasGLExtension("GLX_SGIX_fbconfig") || !glXGetFBConfigAttrib || !glXGetFBConfigs ||
            !glXGetVisualFromFBConfig || !glXCreatePixmap || !glXDestroyPixmap ||
            !glXCreateWindow || !glXDestroyWindow) {
        kError(1212) << "GLX_SGIX_fbconfig or required GLX functions missing";
        return; // error
    }
    if (!selectMode())
        return; // error
    if (!initBuffer())  // create destination buffer
        return; // error
    if (!initRenderingContext())
        return; // error
    // Initialize OpenGL
    GLPlatform *glPlatform = GLPlatform::instance();
    glPlatform->detect();
    glPlatform->printResults();
    initGL();

    if (glPlatform->isSoftwareEmulation()) {
        kError(1212) << "OpenGL Software Rasterizer detected. Falling back to XRender.";
        QTimer::singleShot(0, Workspace::self(), SLOT(fallbackToXRenderCompositing()));
        return;
    }
    if (!hasGLExtension("GL_ARB_texture_non_power_of_two")
            && !hasGLExtension("GL_ARB_texture_rectangle")) {
        kError(1212) << "GL_ARB_texture_non_power_of_two and GL_ARB_texture_rectangle missing";
        return; // error
    }
    if (glPlatform->isMesaDriver() && glPlatform->mesaVersion() < kVersionNumber(7, 10)) {
        kError(1212) << "KWin requires at least Mesa 7.10 for OpenGL compositing.";
        return;
    }
    if (db)
        glDrawBuffer(GL_BACK);
    // Check whether certain features are supported
    has_waitSync = false;
    if (options->isGlVSync()) {
        if (glXGetVideoSync && glXSwapInterval && glXIsDirect(display(), ctxbuffer)) {
            unsigned int sync;
            if (glXGetVideoSync(&sync) == 0) {
                if (glXWaitVideoSync(1, 0, &sync) == 0) {
                    // NOTICE at this time we should actually check whether we can successfully
                    // deactivate the swapInterval "glXSwapInterval(0) == 0"
                    // (because we don't actually want it active unless we explicitly run a glXSwapBuffers)
                    // However mesa/dri will return a range error (6) because deactivating the
                    // swapinterval (as of today) seems completely unsupported
                    has_waitSync = true;
                    glXSwapInterval(0);
                }
                else
                    qWarning() << "NO VSYNC! glXWaitVideoSync(1,0,&uint) isn't 0 but" << glXWaitVideoSync(1, 0, &sync);
            } else
                qWarning() << "NO VSYNC! glXGetVideoSync(&uint) isn't 0 but" << glXGetVideoSync(&sync);
        } else
            qWarning() << "NO VSYNC! glXGetVideoSync, glXSwapInterval, glXIsDirect" <<
                        bool(glXGetVideoSync) << bool(glXSwapInterval) << glXIsDirect(display(), ctxbuffer);
    }

    debug = qstrcmp(qgetenv("KWIN_GL_DEBUG"), "1") == 0;

    // scene shader setup
    if (GLPlatform::instance()->supports(GLSL)) {
        if (!ShaderManager::instance()->isValid()) {
            kDebug(1212) << "No Scene Shaders available";
        } else {
            // push one shader on the stack so that one is always bound
            // consistency with GLES
            ShaderManager::instance()->pushShader(ShaderManager::SimpleShader);
        }
    }

    // OpenGL scene setup
    setupModelViewProjectionMatrix();
    if (checkGLError("Init")) {
        kError(1212) << "OpenGL compositing setup failed";
        return; // error
    }

    // set strict binding
    if (options->isGlStrictBindingFollowsDriver()) {
        options->setGlStrictBinding(!glPlatform->supports(LooseBinding));
    }
    kDebug(1212) << "DB:" << db << ", Direct:" << bool(glXIsDirect(display(), ctxbuffer)) << endl;
    init_ok = true;
}
Ejemplo n.º 17
0
void	hellDecoder::set_rateCorrector	(int c) {
	rateCorrector = c;
	selectMode (hellMode);
}
Ejemplo n.º 18
0
/** 
* @brief  Callback when a mode button is pressed
* 
* @param widget
* @param data
*/
void modeCallback(GtkWidget* widget,gpointer data) {
    selectMode(widget);
}
Ejemplo n.º 19
0
WorkoutWindow::WorkoutWindow(Context *context) :
    GcWindow(context), draw(true), context(context), active(false)
{
    setContentsMargins(0,0,0,0);
    setProperty("color", GColor(CTRAINPLOTBACKGROUND));

    setControls(NULL);

    QVBoxLayout *layout = new QVBoxLayout(this);

    connect(context, SIGNAL(configChanged(qint32)), this, SLOT(configChanged(qint32)));

    // the workout scene
    workout = new WorkoutWidget(this, context);

    // paint the W'bal curve
    mmp = new WWMMPCurve(workout);

    // add the power, W'bal scale
    powerscale = new WWPowerScale(workout, context);
    wbalscale = new WWWBalScale(workout, context);

    // tte warning bar at bottom
    tte = new WWTTE(workout);

    // add a line between the dots
    line = new WWLine(workout);

    // block cursos
    bcursor = new WWBlockCursor(workout);

    // block selection
    brect = new WWBlockSelection(workout);

    // paint the W'bal curve
    wbline = new WWWBLine(workout, context);

    // selection tool
    rect = new WWRect(workout);

    // guides always on top!
    guide = new WWSmartGuide(workout);

    // setup the toolbar
    toolbar = new QToolBar(this);
    toolbar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    toolbar->setFloatable(true);
    toolbar->setIconSize(QSize(18,18));

    QIcon saveIcon(":images/toolbar/save.png");
    saveAct = new QAction(saveIcon, tr("Save"), this);
    connect(saveAct, SIGNAL(triggered()), this, SLOT(saveFile()));
    toolbar->addAction(saveAct);

    toolbar->addSeparator();

    //XXX TODO
    //XXXHelpWhatsThis *helpToolbar = new HelpWhatsThis(toolbar);
    //XXXtoolbar->setWhatsThis(helpToolbar->getWhatsThisText(HelpWhatsThis::ChartRides_Editor));

    // undo and redo deliberately at a distance from the
    // save icon, since accidentally hitting the wrong
    // icon in that instance would be horrible
    QIcon undoIcon(":images/toolbar/undo.png");
    undoAct = new QAction(undoIcon, tr("Undo"), this);
    connect(undoAct, SIGNAL(triggered()), workout, SLOT(undo()));
    toolbar->addAction(undoAct);

    QIcon redoIcon(":images/toolbar/redo.png");
    redoAct = new QAction(redoIcon, tr("Redo"), this);
    connect(redoAct, SIGNAL(triggered()), workout, SLOT(redo()));
    toolbar->addAction(redoAct);
    
    toolbar->addSeparator();

    QIcon drawIcon(":images/toolbar/edit.png");
    drawAct = new QAction(drawIcon, tr("Draw"), this);
    connect(drawAct, SIGNAL(triggered()), this, SLOT(drawMode()));
    toolbar->addAction(drawAct);

    QIcon selectIcon(":images/toolbar/select.png");
    selectAct = new QAction(selectIcon, tr("Select"), this);
    connect(selectAct, SIGNAL(triggered()), this, SLOT(selectMode()));
    toolbar->addAction(selectAct);

    selectAct->setEnabled(true);
    drawAct->setEnabled(false);

    toolbar->addSeparator();

    QIcon cutIcon(":images/toolbar/cut.png");
    cutAct = new QAction(cutIcon, tr("Cut"), this);
    cutAct->setEnabled(true);
    toolbar->addAction(cutAct);
    connect(cutAct, SIGNAL(triggered()), workout, SLOT(cut()));

    QIcon copyIcon(":images/toolbar/copy.png");
    copyAct = new QAction(copyIcon, tr("Copy"), this);
    copyAct->setEnabled(true);
    toolbar->addAction(copyAct);
    connect(copyAct, SIGNAL(triggered()), workout, SLOT(copy()));

    QIcon pasteIcon(":images/toolbar/paste.png");
    pasteAct = new QAction(pasteIcon, tr("Paste"), this);
    pasteAct->setEnabled(false);
    toolbar->addAction(pasteAct);
    connect(pasteAct, SIGNAL(triggered()), workout, SLOT(paste()));

    // stretch the labels to the right hand side
    QWidget *empty = new QWidget(this);
    empty->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
    toolbar->addWidget(empty);


    xlabel = new QLabel("00:00");
    toolbar->addWidget(xlabel);

    ylabel = new QLabel("150w");
    toolbar->addWidget(ylabel);

    IFlabel = new QLabel("0 IF");
    toolbar->addWidget(IFlabel);

    TSSlabel = new QLabel("0 TSS");
    toolbar->addWidget(TSSlabel);

#if 0 // not yet!
    // get updates..
    connect(context, SIGNAL(telemetryUpdate(RealtimeData)), this, SLOT(telemetryUpdate(RealtimeData)));
    telemetryUpdate(RealtimeData());
#endif

    // WATTS and Duration for the cursor
    layout->addWidget(toolbar);
    layout->addWidget(workout);

    // make it look right
    saveAct->setEnabled(false);
    undoAct->setEnabled(false);
    redoAct->setEnabled(false);
    configChanged(CONFIG_APPEARANCE);
}