Example #1
0
 void class_base::add_cast(
     class_id src, class_id target, cast_function cast)
 {
     m_registration->m_casts.push_back(cast_entry(src, target, cast));
 }
void MovieTickets::createMovieEntry(MovieEntry entry, int top_x, int top_y, int center_x, int center_y){
	//load image
	QPixmap* image;
	QString image_full_path(this->image_path);
	image_full_path.append(entry.getImage_path());
	image = new QPixmap(image_full_path);
	
	//Adapt image
	QPixmap aux = image->scaledToWidth(r_width);

	int image_x = top_x + (r_width - aux.width())/2.0;
	int image_y = top_y + (r_height - aux.height())/2.0;

	if(aux.height() > r_height){
		aux = image->scaledToHeight(r_height);

		image_x = top_x + (r_width - aux.width())/2.0;
		image_y = top_y + (r_height - aux.height())/2.0;
	}

	//Paint Image
	painter.drawPixmap(image_x,image_y,aux);

	//Text Preparation
	int advance = 20;
	QFont font_normal = painter.font();
	QFont font_bold = painter.font();
	font_bold.setBold(true);

	//Print Title
	painter.setFont(font_bold);
	painter.drawText(center_x,center_y + advance, "Title:");
	//advance += 20;
	painter.setFont(font_normal);
	painter.drawText(center_x + 35,center_y + advance, entry.getTitle());
	advance += 20;


	//Print Director
	painter.setFont(font_bold);
	painter.drawText(center_x,center_y + advance, "Director:");
	//advance += 20;
	painter.setFont(font_normal);
	painter.drawText(center_x + 55,center_y + advance, entry.getDirector());
	advance += 20;

	//Print Year
	painter.setFont(font_bold);
	painter.drawText(center_x,center_y + advance, "Year:");
	//advance += 20;
	painter.setFont(font_normal);
	painter.drawText(center_x + 35,center_y + advance, entry.getYear());
	advance += 20;

	//Print Duration
	painter.setFont(font_bold);
	painter.drawText(center_x,center_y + advance, "Duration:");
	//advance += 20;
	painter.setFont(font_normal);
	painter.drawText(center_x + 55,center_y + advance, entry.getDuration().append("min"));
	advance += 20;

	//Print IMDB Rating
	painter.setFont(font_bold);
	painter.drawText(center_x,center_y + advance, "IMDB Rating:");
	//advance += 20;
	painter.setFont(font_normal);
	painter.drawText(center_x + 77,center_y + advance, entry.getRating().append("/10.0"));
	advance += 20;

	//Print Visualzation Date
	painter.setFont(font_bold);
	painter.drawText(center_x,center_y + advance, "Visualization Date:");
	//advance += 20;
	painter.setFont(font_normal);
	painter.drawText(center_x + 110,center_y + advance, entry.getVisualization_date());
	advance += 20;

	//Print Plot
	painter.setFont(font_bold);
	painter.drawText(center_x,center_y + advance, "Plot:");
	advance += 10;
	painter.setFont(font_normal);
	int nLines = 1;

	//this represent the required rectangled size
	QRect required = QRect(); 
		
	//this represent our calculated rectangle size
	QRect r = QRect(center_x, center_y + advance, r_width, 20);
		
	painter.drawRect(r);
		
	//now we draw the text into the given rectangle, using word wrap option.
	//the last parameter indicates a rectangle in which the text should be enclosed         
	painter.drawText(r, Qt::AlignJustify | Qt::TextWordWrap, entry.getPlot(), &required);
	
	while (required.height() > r.height())
	{
		//here you must call painter.eraseRect(r) for each drawn rectangle,
		nLines++;
		painter.eraseRect(r);
		r.setHeight(nLines * 20);
		painter.drawText(r, Qt::AlignJustify | Qt::TextWordWrap, entry.getPlot(), &required);
		}

	advance += (nLines * 20) + 10;

	
	//Print cast
	painter.setFont(font_bold);
	painter.drawText(center_x,center_y + advance, "Cast:");
	advance += 20;
	painter.setFont(font_normal);

	int lines_left = (((printer_orig_height/2.0 - advance)/20) - 1) * 2;
	for(int i = 0 ; i < entry.getCast().size() && i < lines_left ; i+=2){
		QString cast_entry(entry.getCast()[i]);
		cast_entry.append(" ... ");
		cast_entry.append(entry.getCast()[i+1]);

		painter.drawText(center_x,center_y + advance, cast_entry);
		advance += 20;
	}

	
}