Example #1
0
void TextBoxContent::animateZoom()
{
	//elapsed = (elapsed + qobject_cast<QTimer*>(sender())->interval()) % 2000;
	//printf("elapsed=%d\n",elapsed);
	if(m_zoomDir > 0)
	{
		m_zoomCurSize.setX(m_zoomCurSize.x() + m_zoomStep.x());
		m_zoomCurSize.setY(m_zoomCurSize.y() + m_zoomStep.y());
		if(m_zoomCurSize.x() >= m_zoomEndSize.x() &&
		   m_zoomCurSize.y() >= m_zoomEndSize.y())
		   	if(modelItem()->zoomLoop())
				m_zoomDir = -1;
			else
				if(m_zoomAnimationTimer->isActive())
					m_zoomAnimationTimer->stop();
			
	}
	else
	{
		m_zoomCurSize.setX(m_zoomCurSize.x() - m_zoomStep.x());
		m_zoomCurSize.setY(m_zoomCurSize.y() - m_zoomStep.y());
		if(m_zoomCurSize.x() <= m_zoomStartSize.x() &&
		   m_zoomCurSize.y() <= m_zoomStartSize.y())
			if(modelItem()->zoomLoop())
				m_zoomDir = +1;
			else
				if(m_zoomAnimationTimer->isActive())
					m_zoomAnimationTimer->stop();
	}
	//qDebug() << "AnimateZoom: "<<PTR(this)<<modelItem()->itemName()<<": size:"<<m_zoomCurSize<<", step:"<<m_zoomStep;
	
	update();
}
Example #2
0
		void ValidationItem::writeConfigSection(std::ofstream& out)
		{
			out << "[Validator]" << "\n";
			out << "model_file = "<< modelItem()->savedAs().toStdString() << "\n";
			out << "data_file = "<< modelItem()->inputDataItem()->savedAs().toStdString() << "\n";
			out << "validation_type = "<<type_<<std::endl;
			
			// for nested cross validation save the names of the prediction output-files in order to be able to restore the pipeline later
			if(external_validations_.size()>0)
			{
				out<<"external_validation_predictions = ";
				for(list<ValidationItem*>::iterator it=external_validations_.begin(); it!=external_validations_.end(); it++)
				{
					out<<(*it)->savedAs().toStdString()<<" ";
				}
				out<<std::endl;
			}
			int s = getValidationStatistic();
			if(s>=0)
			{
				String stat = modelItem()->getRegistryEntry()->getStatName(s);
				if(!model_item_->getRegistryEntry()->regression) out<< "classification_statistic = "<<stat.c_str()<<std::endl;
				else out<< "regression_statistic = "<<stat.c_str()<<std::endl;
			}
			
			if(type_>0) out << "k_fold = "<< k() <<  "\n";
			if(num_of_samples_>0) out << "bootstrap_samples = "<< num_of_samples_ << "\n";
			if(num_of_runs_>0) out << "no_of_permutation_tests = " <<  num_of_runs_ << "\n";
			out << "output = " << savedAs().toStdString() << "\n\n";	
		}
Example #3
0
void TextBoxContent::setHtml(const QString & htmlCode)
{
        DEBUG_TSTART();
	
	//qDebug()<<modelItem()->itemName()<<"TextBoxContent::setHtml(): htmlCode:"<<htmlCode;
	m_text->setHtml(htmlCode);
	m_shadowText->setHtml(htmlCode);
	
	updateTextConstraints();
	syncToModelItem(0);

	// Apply outline pen to the html
	QTextCursor cursor(m_text);
	cursor.select(QTextCursor::Document);

	QTextCharFormat format;

	QPen p(Qt::NoPen);
	if(modelItem() && modelItem()->outlineEnabled())
	{
		p = modelItem()->outlinePen();
		p.setJoinStyle(Qt::MiterJoin);
	}

	format.setTextOutline(p);
	format.setForeground(modelItem() && modelItem()->fillType() == AbstractVisualItem::Solid ? modelItem()->fillBrush() : Qt::NoBrush);

	
	cursor.mergeCharFormat(format);
	
	#if QT46_SHADOW_ENAB == 0
	// Setup the shadow text formatting if enabled
	if(modelItem() && modelItem()->shadowEnabled())
	{
		if(qFuzzyIsNull(modelItem()->shadowBlurRadius()))
		{
			QTextCursor cursor(m_shadowText);
			cursor.select(QTextCursor::Document);
	
			QTextCharFormat format;
			format.setTextOutline(Qt::NoPen);
			format.setForeground(modelItem() ? modelItem()->shadowBrush() : Qt::black);
	
			cursor.mergeCharFormat(format);
		}
	}
	#endif
	
	// Cache gets dirty in syncfrommodelitem conditionally based on model revision
	//dirtyCache();

	update();
	
	//qDebug() << "TextBoxContent::setHtml(): \t \t Elapsed:"<<(((double)total.elapsed())/1000.0)<<" sec";
}
Example #4
0
		BALL::String ValidationItem::getMouseOverText()
		{
			String message="";
			if(view_->name!="view") return message;
			
			if(type_!=6)
			{
				message+="using ";
				message += modelItem()->getRegistryEntry()->getStatName(validation_statistic_);
			}
			else if(done_ && type_==6)
			{
				message+="average ratio between stddev\nand coeff: "+String(coeff_stderr_ratio_);
			}
			return message;				
		}
Example #5
0
QString TextBoxContent::toHtml()
{
	TextItem * textModel = dynamic_cast<TextItem*>(modelItem());
	return textModel ? textModel->text() : "";
}
Example #6
0
void TextBoxContent::renderShadow(QPainter *painter, QAbstractTextDocumentLayout::PaintContext *pCtx)
{
	AbstractVisualItem *model = modelItem();
	if(qFuzzyIsNull(model->shadowBlurRadius()))
	{
		// render a "cheap" version of the shadow using the shadow text document
		painter->save();

		painter->translate(model->shadowOffsetX(),model->shadowOffsetY());
		m_shadowText->documentLayout()->draw(painter, *pCtx);

		painter->restore();
	}
	else
	{
// 		double radius = model->shadowBlurRadius();
// 		double radiusSquared = radius*radius;
// 		
// 		// create temporary pixmap to hold a copy of the text
// 		double blurSize = (int)(radiusSquared*2);
// 		QSize shadowSize(blurSize,blurSize);
// 		QPixmap tmpPx(contentsRect().size()+shadowSize);
// 		tmpPx.fill(Qt::transparent);
// 		
// 		// render the text
// 		QPainter tmpPainter(&tmpPx);
// 		tmpPainter.save();
// 		tmpPainter.translate(radiusSquared, radiusSquared);
// 		m_text->documentLayout()->draw(&tmpPainter, *pCtx);
// 		tmpPainter.restore();
// 		
// 		// blacken the text by applying a color to the copy using a QPainter::CompositionMode_DestinationIn operation. 
// 		// This produces a homogeneously-colored pixmap.
// 		QRect rect = QRect(0, 0, tmpPx.width(), tmpPx.height());
// 		tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
// 		tmpPainter.fillRect(rect, model->shadowBrush().color());
// 		tmpPainter.end();
// 
// 		// blur the colored text
// 		QImage  orignalImage   = tmpPx.toImage();
// 		QImage  blurredImage   = ImageFilters::blurred(orignalImage, rect, (int)radius);
// 		QPixmap blurredPixmap  = QPixmap::fromImage(blurredImage);
// 		
// 		// render the blurred text at an offset into the cache
// 		painter->save();
// 		painter->translate(model->shadowOffsetX() - radiusSquared,
// 				model->shadowOffsetY() - radiusSquared);
// 		painter->drawPixmap(0, 0, blurredPixmap);
// 		painter->restore();
		
		// New method of rendering shadows
		double radius = model->shadowBlurRadius();
		
		// create temporary pixmap to hold a copy of the text
		QSizeF blurSize = ImageFilters::blurredSizeFor(model->contentsRect().size(), (int)radius);
		//qDebug() << "Blur size:"<<blurSize<<", doc:"<<doc.size()<<", radius:"<<radius;
		QImage tmpImage(blurSize.toSize(),QImage::Format_ARGB32_Premultiplied);
		memset(tmpImage.scanLine(0),0,tmpImage.byteCount());
		
		// render the text
		QPainter tmpPainter(&tmpImage);
		
		tmpPainter.save();
		tmpPainter.translate(radius, radius);
		m_text->documentLayout()->draw(&tmpPainter, *pCtx);
		tmpPainter.restore();
		
		// blacken the text by applying a color to the copy using a QPainter::CompositionMode_DestinationIn operation. 
		// This produces a homogeneously-colored pixmap.
		QRect rect = tmpImage.rect();
		tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
		tmpPainter.fillRect(rect, model->shadowBrush().color());
		tmpPainter.end();

		// blur the colored text
		ImageFilters::blurImage(tmpImage, (int)radius);
		
		// render the blurred text at an offset into the cache
		painter->save();
		painter->translate(model->shadowOffsetX() - radius,
				      model->shadowOffsetY() - radius);
		painter->drawImage(0, 0, tmpImage);
		painter->restore();
	}
}
Example #7
0
void TextBoxContent::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
{
	DEBUG_TSTART();
	// paint parent
	AbstractContent::paint(painter, option, widget);

	
	painter->save();
	
	//TODO should we clip to the rect or FORCE resize the rect? probably clip...
	//painter->setClipRect(contentsRect());
	//if(option)
	//	painter->setClipRect(option->exposedRect);
	painter->translate(contentsRect().topLeft()); // + QPoint(p.width(),p.width()));

	if(sceneContextHint() == MyGraphicsScene::StaticPreview || !modelItem()->shadowEnabled())
	{
		// If we're drawing in a Preview scene, then we render directly with the painter
		// (rather than caching the results in a pixmap) because this allows the painter 
		// to scale the text glyphs directly (vector scaling), rather than scaling bits 
		// in a pixmap (bitmap scaling), producing more legible results at lower scalings
		
// 		qDebug() << modelItem()->itemName()<<"TextBoxContent::paint: Rendering either preview or no shadow";
		
		QAbstractTextDocumentLayout::PaintContext pCtx;

		// What was this for - improving performance?
		// I've removed it because it seems to be causing the issue reported in Issue #51 on the google code issues tracker.
		// I'll keep an eye on performance to see if it suffers at all. For now, closing issue #51.
		//pCtx.clip = option->exposedRect;
		
		bool needRestore = false;
		
		if(m_zoomEnabled && sceneContextHint() == MyGraphicsScene::Live)
		{
			needRestore = true;
			painter->save();
			double xf = (1/m_zoomDestPoint.x());
			double yf = (1/m_zoomDestPoint.y());
			double sx = m_zoomCurSize.x() / m_zoomStartSize.x();
			double sy = m_zoomCurSize.y() / m_zoomStartSize.y();
			QRect cRect = contentsRect();
			painter->translate(cRect.width()/xf - m_zoomCurSize.x()/xf,cRect.height()/yf - m_zoomCurSize.y()/yf);
			painter->scale(sx,sy);
			
// 			qDebug() << modelItem()->itemName()<<"TextBoxContent::paint: Enabling tranlate & scale. Scale:"<<sx<<","<<sy<<". xf/yf:"<<xf<<","<<yf;
		}
			
			
	
		if(modelItem()->shadowEnabled())
		{
// 			qDebug() << modelItem()->itemName()<<"TextBoxContent::paint: Drawing m_shadowText";
							
			painter->save();
			
			painter->translate(modelItem()->shadowOffsetX(),modelItem()->shadowOffsetY());
			m_shadowText->documentLayout()->draw(painter, pCtx);
	
			painter->restore();
		}
		
		m_text->documentLayout()->draw(painter, pCtx);
		
		if(needRestore)
			painter->restore();
		
	}
	else
	{
		QPixmap cache;
// 		qDebug() << modelItem()->itemName()<<"TextBoxContent::paint: Rendering either live or with shadow";
		
		// The primary and only reason we cache the text rendering is inorder
		// to paint the text and shadow as a single unit (e.g. composite the
		// shadow+text BEFORE applying opacity rather than setting the opacity
		// before rendering the shaodw.) If we didnt cache the text as a pixmap
		// (e.g. render text directly) then when crossfading, the shadow
		// "apperas" to fade out last, after the text.
		
		// Update 20091015: Implemented very aggressive caching across TextBoxContent instances
		// that share the same modelItem() (see ::cacheKey()) inorder to avoid re-rendering 
		// potentially expensive drop shadows, below.
		
		
		
		QString key = cacheKey();
		if(m_text->toPlainText().trimmed().isEmpty())
		{
			// "<< m_text->toHtml()<<"
			//qDebug() << modelItem()->itemName()<<": Not rendering cache because:"<< QPixmapCache::find(key,cache)<< " or ...";//plain "<<m_text->toPlainText()<<" is empty";
			cache = QPixmap(contentsRect().size());
			cache.fill(Qt::transparent);
		}
		else
		{
			if(!QPixmapCache::find(key,cache))
			{
				if(QFile(key).exists())
				{
					cache.load(key);
					QPixmapCache::insert(key,cache);
					//qDebug()<<"TextBoxContent::paint(): modelItem:"<<modelItem()->itemName()<<": Cache load from"<<key;
				}
				else
				{
					qDebug()<<"TextBoxContent::paint(): modelItem:"<<modelItem()->itemName()<<": Cache redraw";

					QSizeF shadowSize = modelItem()->shadowEnabled() ? QSizeF(modelItem()->shadowOffsetX(),modelItem()->shadowOffsetY()) : QSizeF(0,0);
					cache = QPixmap((contentsRect().size()+shadowSize).toSize());

					cache.fill(Qt::transparent);
					QPainter textPainter(&cache);

					QAbstractTextDocumentLayout::PaintContext pCtx;

					#if QT46_SHADOW_ENAB == 0
					if(modelItem()->shadowEnabled())
						renderShadow(&textPainter,&pCtx);
					#endif

					// If we're zooming, we want to render the text straight to the painter
					// so it can transform the raw vectors instead of scaling the bitmap.
					// But if we're not zooming, we cache the text with the shadow since it
					// looks better that way when we're crossfading.
					if(!m_zoomEnabled)
						m_text->documentLayout()->draw(&textPainter, pCtx);

					cache.save(key,"PNG");
					QPixmapCache::insert(key, cache);
				}
			}
		}
	
		// Draw a rectangular outline in the editor inorder to visually locate empty text blocks
		if(sceneContextHint() == MyGraphicsScene::Editor &&
			m_text->toPlainText().trimmed() == "")
		{
			QPen p = modelItem() ? modelItem()->outlinePen() : QPen(Qt::black,1.5);
			painter->setPen(p);
			painter->setBrush(Qt::NoBrush);
	
			painter->drawRect(QRect(QPoint(0,0),contentsRect().size()));
		}
		else
		{
			if(m_zoomEnabled)
			{
				double xf = (1/m_zoomDestPoint.x());
				double yf = (1/m_zoomDestPoint.y());
				double sx = m_zoomCurSize.x() / m_zoomStartSize.x();
				double sy = m_zoomCurSize.y() / m_zoomStartSize.y();
				painter->save();
				QRect cRect = contentsRect();
				painter->translate(cRect.width()/xf - m_zoomCurSize.x()/xf,cRect.height()/yf - m_zoomCurSize.y()/yf);
				painter->scale(sx,sy);
				painter->drawPixmap(0,0,cache);
				QAbstractTextDocumentLayout::PaintContext pCtx;
				m_text->documentLayout()->draw(painter, pCtx);
				painter->restore();
				
			}
			else
			{
				painter->drawPixmap(0,0,cache);
				if(sceneContextHint() != MyGraphicsScene::Live && modelItem()->zoomEffectEnabled())
				{
					// cache may not contain the actual text, just shadow, since its not live,
					// so render the text
					QAbstractTextDocumentLayout::PaintContext pCtx;
					m_text->documentLayout()->draw(painter, pCtx);
				}
					
			}
		}
	}


	painter->restore();
	
	//qDebug() << "TextBoxContent::paint(): \t \t Elapsed:"<<(((double)total.elapsed())/1000.0)<<" sec";
}
Example #8
0
void TextBoxContent::syncFromModelItem(AbstractVisualItem *model)
{
        DEBUG_TSTART();
	m_dontSyncToModel = true;
	if(!modelItem())
	{
		setModelItem(model);
		
		// Start out the last remembered model rev at the rev of the model
		// so we dont force a redraw of the cache just because we're a fresh
		// object.
		if(QPixmapCache::find(cacheKey()))
			m_lastModelRev = modelItem()->revision();
	}

	static int x = 0;
	x++;
	//qDebug() << x<<": TextBoxContent::syncFromModelItem() mark";
	QFont font;
	TextItem * textModel = dynamic_cast<TextItem*>(model);

	font.setFamily(textModel->fontFamily());
	font.setPointSize((int)textModel->fontSize());
	m_text->setDefaultFont(font);
	
	

	if (!Qt::mightBeRichText(textModel->text()))
	{
		qDebug() << "TextBoxContent:: converting plain text from model item to html";
		m_text->setPlainText(textModel->text());
		textModel->setText(m_text->toHtml());
	}
	
	//qDebug() << "TextBoxContent:: Original HTML:"<<textModel->text();
	setHtml(textModel->text());
	//qDebug() << "TextBoxContent::      New HTML:"<<m_text->toHtml();
	

	AbstractContent::syncFromModelItem(model);
	
	if(modelItem()->revision() != m_lastModelRev)
	{
		//qDebug()<<"modelItem():"<<modelItem()->itemName()<<": last revision:"<<m_lastModelRev<<", this revision:"<<m_lastModelRev<<", cache dirty!";
		
		m_lastModelRev = modelItem()->revision();
		
		// DONT dirty cache here since we changed the cacheKey algorithm - cache key is now based on visual description, not on item identity
		//dirtyCache();
	}
	
	if(   model->zoomEffectEnabled() 
 	   && model->zoomSpeed() > 0 
 	   && sceneContextHint() == MyGraphicsScene::Live)
	{
		m_zoomEnabled = true;
		
		m_zoomAnimationTimer->start(1000 / 20); // / model->zoomSpeed());
		
		QSize size = contentsRect().size();
			
		double width  = size.width();
		double height = size.height();
		
		double aspectRatio = height == 0 ? 1 : width/height;
			
// 		if(!m_zoomInit)
// 		{
			//qDebug() << "aspectRatio: "<<aspectRatio;
			
			QPointF delta;
			
			m_zoomStartSize.setX(width);
			m_zoomStartSize.setY(height);
			 
			m_zoomEndSize.setX(width  * model->zoomFactor());
			m_zoomEndSize.setY(height * model->zoomFactor());
			
			bool zoomIn = true;
			if(model->zoomDirection() == AbstractVisualItem::ZoomIn)
				zoomIn = true;
			else
			if(model->zoomDirection() == AbstractVisualItem::ZoomOut)
				zoomIn = false;
			else
			if(model->zoomDirection() == AbstractVisualItem::ZoomRandom)
				zoomIn = qrand() < RAND_MAX/2;
			
			m_zoomCurSize = zoomIn ? m_zoomStartSize : m_zoomEndSize;
			m_zoomDir     = zoomIn ? 1 : -1;
			
			delta.setX(m_zoomEndSize.x() - m_zoomCurSize.x());
			delta.setY(m_zoomEndSize.y() - m_zoomCurSize.y());
			//step.setX(delta.x()/ZOOM_STEPS);
			//step.setY(delta.y()/ZOOM_STEPS);
// 			m_zoomInit = true;
// 		}
		
		// allow it to go below 1.0 for step size by using 75.0 when the max of the zoomSpeed slider in config is 100
		m_zoomStep.setX(8.0 / (100.01 - ((double)model->zoomSpeed())) * aspectRatio);
		m_zoomStep.setY(8.0 / (100.01 - ((double)model->zoomSpeed())));
		
		
		if(model->zoomAnchorPoint() == AbstractVisualItem::ZoomAnchorRandom)
		{
			// pick a third intersection
			double x = qrand() < RAND_MAX/2 ? .33 : .66;
			double y = qrand() < RAND_MAX/2 ? .33 : .66;
			
			// apply a fudge factor
// 			x += 0.15 - ((double)qrand()) / ((double)RAND_MAX) * 0.075;
// 			y += 0.15 - ((double)qrand()) / ((double)RAND_MAX) * 0.075;
			
			m_zoomDestPoint = QPointF(x,y);
			//qDebug() << "ZoomRandom:	"<<x<<","<<y;
			
			//qDebug() << model->itemName() << "Random zoom anchor: "<<m_zoomDestPoint;
		}
		else
		{
			double x = .0, y = .0;
			switch(model->zoomAnchorPoint())
			{
				case AbstractVisualItem::ZoomTopLeft:		x = .33; y = .33; break;
				case AbstractVisualItem::ZoomTopMid:		x = .50; y = .25; break;
				case AbstractVisualItem::ZoomTopRight:		x = .66; y = .33; break;
				case AbstractVisualItem::ZoomRightMid:		x = .75; y = .50; break;
				case AbstractVisualItem::ZoomBottomRight:	x = .66; y = .66; break;
				case AbstractVisualItem::ZoomBottomMid:		x = .50; y = .75; break;
				case AbstractVisualItem::ZoomBottomLeft:	x = .33; y = .66; break;
				case AbstractVisualItem::ZoomLeftMid:		x = .25; y = .50; break;
				case AbstractVisualItem::ZoomCenter:
				default:					x = .50; y = .50; break;
			};
			
			m_zoomDestPoint = QPointF(x,y);
		}

	}
	else
	{
		m_zoomEnabled = false;
		if(m_zoomAnimationTimer->isActive())
			m_zoomAnimationTimer->stop();
	}

        m_dontSyncToModel = false;
}