[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-edu
Subject:    [kde-edu]: Need help with this code
From:       Carsten Niehaus <cniehaus () gmx ! de>
Date:       2005-07-11 14:02:23
Message-ID: 200507111602.26836.cniehaus () gmx ! de
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


I am drawing a vertical line and then want to put a string below that line....

·   ·   p->drawLine( x,0,x, m_realHeight );
·   ·   p->save();
·   ·   p->rotate( -90.0 );
·   ·   p->translate( m_realHeight,0 );
·   ·
·   ·   p->drawText( -m_realHeight,x, "test" );
·   ·
·   ·   p->restore();

I tried all kinds of "translations" but it never works. The Qt-API is not 
exactly verbose for QPainter::translate().
I am sure that there is only a missing "-" or something like that but I simple 
don't get it. I attached the comple file, you will find this code in 

void SpectrumWidget::drawLines( QPainter *p )

Can anyone help?

Carsten

["spectrum.cpp" (text/x-c++src)]

/***************************************************************************
 *   Copyright (C) 2005 by Carsten Niehaus                                 *
 *   cniehaus@kde.org                                                      *
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 *   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.             *
 ***************************************************************************/
#include "spectrum.h"

SpectrumWidget::SpectrumWidget( QWidget* parent, const char* name )
	: QWidget( parent,name )
{
	startValue = 450;
	endValue = 800;

	m_realWidth = 300;
	m_realHeight = 200;
}

SpectrumWidget::~SpectrumWidget(){}

void SpectrumWidget::paintEvent( QPaintEvent * /*e*/ )
{
	QPainter p;
	p.begin( this );
	p.fillRect( 0, 0, width(), height(), paletteBackgroundColor() ); 
	p.drawRect( 0,0, width(), height() );
	drawLines(  &p );
}

void SpectrumWidget::drawLines( QPainter *p )
{
	//the spectrum goes from about 780nm to about 400nm
	//750 is a dark red 
	//660 yellow
	//580 green
	//500 light blue
	//400 dark blue

	QImage img = KImageEffect::gradient ( QSize( m_realWidth, m_realHeight ), Qt::blue, Qt::red, 
										  KImageEffect::HorizontalGradient );
	QPixmap pm( img );

	p->drawPixmap( 0,0, pm );

	for ( QValueList<double>::Iterator it = m_spectra.begin();
			it != m_spectra.end();
			++it )
	{
		if ( (*it) < startValue || ( *it ) > endValue )
			continue;

		int x = xPos( *it );
		
		kdDebug() << *it  << " X: " << x << endl;

		p->drawLine( x,0,x, m_realHeight );
		p->save();
		p->rotate( -90.0 );
		p->translate( m_realHeight,0 );
		
		p->drawText( -m_realHeight,x, QString::number( x ) );
		
		p->restore();
	}
}

int SpectrumWidget::xPos( double value )
{
	double var = ( endValue-startValue );
	double coeff = ( value - startValue )/var;

	return coeff * m_realWidth;
}

QColor SpectrumWidget::linecolor( double spectrum )
{
	QColor c( 128,128,128 );
	return c;
}

#include "spectrum.moc"

[Attachment #8 (application/pgp-signature)]

_______________________________________________
kde-edu mailing list
kde-edu@mail.kde.org
https://mail.kde.org/mailman/listinfo/kde-edu


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic