Ejemplo n.º 1
0
bool MainWindowImpl::loadPiece( QFileInfo const & fi )
{
	QString fn( fi.filePath() ); // absoluteFilePath() );
	QGIPiece * pc = new QGIPiece;
	if( pc->fileNameMatches( fn ) )
	{
	    try
	    {
		if( ! pc->s11nLoad( fn ) )
		{
		    delete pc;
		    QMessageBox::warning( this, "Load failed!",
					  QString("Failed: MainWindowImpl::loadPiece(%1)").arg(fn),
					  QMessageBox::Ok, QMessageBox::Ok );
		    return false;
		}
	    }
	    catch(...)
	    {
		delete pc;
		throw;
	    }
	}
	else
	{
	    impl->paw->applyCurrentTemplate( pc );
	    pc->setProperty( "pixmap", qboard::homeRelative(fn) );
	}
	impl->gstate.addItem(pc, true);
	return true;
}
void PieceAppearanceWidget::setupDefaultTemplates()
{
    typedef QList<QColor> QCL;
    QCL cl;
    QColor red( Qt::red );
    QColor green(Qt::green);
    QColor blue(Qt::blue);
    QColor yellow(Qt::yellow);
    QColor white(Qt::white);
    cl
	<< white
	<< red
	<< green
	<< blue
	<< yellow
	;
    int step = 24;
    int space = 4;
    int x = space;
    int y = space;
    int at = 0;
    for( QCL::iterator it = cl.begin();
	 cl.end() != it; ++it )
    {
	QColor color = *it;
	QColor darker = color.darker();
	QColor lighter = color.lighter();
	if( 0 == at++ )
	{ // the obligatory special case for White:
	    lighter = color.darker();
	    darker = lighter.darker();
	}
	for( int i = 0; i < 3; ++i )
	{
	    if( i == 1 ) color = lighter;
	    else if( i == 2 ) color = darker;
	    QGIPiece * pc = new QGIPiece;
	    if( ! this->impl->pc ) this->impl->pc = pc;
	    this->impl->gs.addItem( pc );
	    pc->setProperty("size",QSize(step,step));
	    pc->setProperty("pos",QPoint(x,y));
	    pc->setProperty("dragDisabled",int(1));
	    const QRectF bounds( pc->boundingRect() );
	    x += int(bounds.width()) + space;
	    pc->setProperty("color",color);
	    pc->setProperty("borderSize",1);
	    pc->setProperty("borderColor",QColor(0,0,0));
	}
	y += step  + space;
	x = space;
    }
    //impl->gs.scene()->setSceneRect( QRectF() );
}