コード例 #1
0
void QGraph::pintafunc(QPaintDevice *qpd){
	QPoint ultim(0,0), act(0,0);
	QPen pfunc;
	QPen ccursor;
	buffer = QPixmap(this->width(), this->height());
	buffer.fill(Qt::white);
	
	pfunc.setColor(QColor(0,150,0));
	pfunc.setCapStyle(Qt::RoundCap);
	pfunc.setWidth(2);
	
	if(qpd)
		finestra.begin(qpd);
	else
		finestra.begin(&buffer, this);
	
	bool nan=false, outside=false;
	dibuixa_eixos(&finestra);
	finestra.setPen(pfunc);
	
	if(funclist.count()>0){
		for (QValueList<function>::iterator it = funclist.begin(); it != funclist.end(); ++it ){
			if((*it).isShown()){
			pfunc.setColor((*it).color());
			pfunc.setWidth((*it).selected()+1);
			finestra.setPen(pfunc);
			int i = (*it).npoints();
			register int j;
			for(/*register int*/ j=0; j<i;j++){
				if(!nan){
					act=toWidget((*it).points[j].x(), (*it).points[j].y(), &nan);
// 					qDebug("%4d -- %4d", act.y(), act.x());//y->2
					
					if(act.x()!=ultim.x() && act.x() > 0 && (act.y() > 0 || (act.y()==0 && !outside)) && act.x() < this->width() && act.y() <= this->height()){
						finestra.drawLine(ultim, act);
						outside=false;
					} else if(act.x() > 0 && act.x() < this->width() && ((act.y() < 0 && ultim.y()>0)  || (act.y() > this->height() && ultim.y() < this->height()))){
						bool out;
						QPoint act2 = act;
						trunca(&ultim, &act2, &out);
						if(!outside)
							finestra.drawLine(ultim, act2);
						outside = out;
					}
				}else
					act=toWidget((*it).points[j].x(), (*it).points[j].y(), &nan);
				
				if(act.x() != ultim.x())
					ultim=act;
			}
			}
		}
	}
	valid=true;
	finestra.end();
}
コード例 #2
0
void QGraph::mouseMoveEvent(QMouseEvent *e){
	mark=calcImage(fromWidget(e->pos()));
	
	if(pushed & Qt::MidButton && ant != toViewport(e->pos())){
		QPoint rel = e->pos() - press - (toWidget(.5,.5)-toWidget(0.,0.));
		rel = toViewport(rel);
		viewport.setLeft(viewport.left() - rel.x()); viewport.setRight(viewport.right() - rel.x());
		viewport.setTop(viewport.top() - rel.y()); viewport.setBottom(viewport.bottom() - rel.y());
		
		update_points();
		press = e->pos();
		ant = toViewport(e->pos());
		valid=false;
		sendStatus(QString("(%1, %2)-(%3, %4)").arg(viewport.left()).arg(viewport.top()).arg(viewport.right()).arg(viewport.bottom()));
	} else if(pushed == Qt::LeftButton) {
		last = e->pos();
	} else if(pushed==0)
		sendStatus(QString("x=%1 y=%2") .arg(mark.x(),3,'f',2).arg(mark.y(),3,'f',2));
	
	this->repaint(false);
}
コード例 #3
0
void QGraph::dibuixa_eixos(QPainter *finestra){
	QPen ceixos;
	QPoint centre = toWidget(0.,0.);
	double x;
// 	qDebug("(%d, %d)-(%d, %d)", viewport.left(), viewport.top(), viewport.right(), viewport.bottom());
	
	if(m_squares) {
// 		ceixos.setStyle(Qt::DotLine);
		ceixos.setStyle(Qt::SolidLine);
		ceixos.setColor(QColor(225,225,255));
		finestra->setPen(ceixos);
	} else {
		ceixos.setColor(QColor(100,100,255));
		ceixos.setStyle(Qt::SolidLine);
		finestra->setPen(ceixos);
	}
	
	for(x=viewport.left(); x<(viewport.right()+1); x+=1.0) {// ralletes X
		if(m_squares)
			finestra->drawLine(QPoint(toWidget(x,viewport.top()).x(), this->height()), QPoint( toWidget(x,viewport.bottom()+1).x(), 0));
		else
			finestra->drawLine(toWidget(x,0.0f), toWidget(x,0.0f)+QPoint(0,-3));
	}
	
	for(x=viewport.top(); x>viewport.bottom(); x-=1.0) { // ralletes y
		if(m_squares)
			finestra->drawLine(toWidget(viewport.left(),x), toWidget(viewport.right()+1, x));
		else
			finestra->drawLine(toWidget(0.0f,x), toWidget(0.0f,x)+QPoint(3,0));
	}
	
	ceixos.setColor(QColor(100,100,255));
	ceixos.setStyle(Qt::SolidLine);
	finestra->setPen(ceixos);
	
	//dibuixa eixos viewport
	finestra->drawLine(QPoint(0, centre.y()), QPoint(this->width(), centre.y()));
	finestra->drawLine(QPoint(centre.x(), 0), QPoint(centre.x(),this->height()));
	//EO dibuixa eixos viewport
	//write coords
	finestra->drawText(QPoint(3+this->width()/2, 10                ), QString("%1").arg(-viewport.bottom()));//Botom coords
	finestra->drawText(QPoint(3+this->width()/2, this->height()-5  ), QString("%1").arg(-viewport.top()));	//Top coords
	finestra->drawText(QPoint(8                , this->height()/2-5), QString("%1").arg(viewport.left()));	//Left coords
	finestra->drawText(QPoint(this->width()-30 , this->height()/2-5), QString("%1").arg(viewport.right()));	//Right coords
	//EO write coords
}
コード例 #4
0
void QGraph::paintEvent( QPaintEvent * ){
	if(!valid)
		pintafunc(NULL);
	front = buffer;
	finestra.begin(&front, this);
	QPen pfunc;
	QPen ccursor;
	QPoint ultim;
	
	pfunc.setColor(QColor(0,150,0));
	pfunc.setCapStyle(Qt::RoundCap);
	pfunc.setWidth(2);
	
	if(this->hasMouseTracking() && this->cursor().shape() != Qt::PointingHandCursor) {
		ccursor.setColor(QColor(0xc0,0,0));
		ccursor.setStyle(Qt::SolidLine);
		finestra.setPen(ccursor);
		finestra.drawLine(toWidget(viewport.left(),mark.y()), QPoint(this->width(), toWidget(viewport.right()+1, mark.y()).y()));
		finestra.drawLine(QPoint(toWidget(mark.x(),viewport.top()).x(), this->height()), QPoint( toWidget(mark.x(),viewport.bottom()+1).x(), 0));
		
		int w=110, h=13;
		ultim = toWidget(mark.x(), mark.y(), NULL);
		
		if(ultim.x()+w+10 > this->width())
			ultim.setX(this->width()-w-10);
		if(ultim.y()+h+10 > this->height())
			ultim.setY(this->height()-h-10);
		if(ultim.y() < 0)
			ultim.setY(-10);
		
		finestra.setPen(QPen(QColor(0,0,0)));
		finestra.drawText(ultim.x()+15, ultim.y()+15, QString("x=%1 y=%2") .arg(mark.x(),3,'f',2).arg(mark.y(),3,'f',2));
#if 0
		ultim = toWidget(mark.x(), mark.y(), NULL);
		//micepos->setText(QString("<qt>x=<b>%1</b> &nbsp; y=<b>%1</b></qt>") .arg(mark.x(),3,'f',2).arg(mark.y(),3,'f',2));
		
		if(ultim.x()+micepos->width()+10 > this->width())
			ultim.setX(this->width()-micepos->width()-10);
		if(ultim.y()+micepos->height()+10 > this->height())
			ultim.setY(this->height()-micepos->height()-10);
		else if(ultim.y() < 0)
		ultim.setY(-10);
		
		micepos->setGeometry(ultim.x()+10, ultim.y()+10, 160, 23);
#endif
	} else if(this->hasMouseTracking() && pushed==Qt::LeftButton) {
		QBrush rectbr(yellow);
		rectbr.setStyle(Dense6Pattern);
		ccursor.setColor(QColor(0xc0,0,0));
		ccursor.setStyle(Qt::SolidLine);
		finestra.setPen(ccursor);
		finestra.setBrush(rectbr);
// 		micepos->hide();
		
		QPoint p=last;
		QPoint p1=press;
		finestra.drawRect(QRect(p1,p));
		
		/*QPoint p=toViewport(last)+viewport.topLeft(); //REAL mode
		QPoint p1=toViewport(press)+viewport.topLeft();
		p=toWidget((double)p.x(), (double)p.y(), NULL);
		p1=toWidget((double)p1.x(), (double)p1.y(), NULL);
		finestra.drawRect(QRect(p1,p));*/
	} //else micepos->hide();
// 	qDebug("<%d>", pushed);
	finestra.end();
	
	///////////////////////////////
	//bitBlt(this,0,0,&buffer,0,0,this->width(),this->height());
	bitBlt(this,0,0,&front,0,0,this->width(),this->height());
}
コード例 #5
0
ファイル: setupitem.cpp プロジェクト: Evonline/ManaPlus
void SetupItem::externalUpdated(std::string eventName A_UNUSED)
{
    load();
    toWidget();
}
コード例 #6
0
ファイル: setupitem.cpp プロジェクト: Evonline/ManaPlus
void SetupItem::cancel(std::string eventName A_UNUSED)
{
    load();
    toWidget();
}