QTfrontend/hats.cpp
changeset 1281 1f8456577a39
parent 1239 4901abe4c3b0
child 2377 f3fab2b09e0c
equal deleted inserted replaced
1280:2ca5484725ba 1281:1f8456577a39
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    17  */
    17  */
    18 
    18 
    19 #include <QDir>
    19 #include <QDir>
    20 #include <QPixmap>
    20 #include <QPixmap>
       
    21 #include <QPainter>
    21 #include "hwconsts.h"
    22 #include "hwconsts.h"
    22 #include "hats.h"
    23 #include "hats.h"
    23 
    24 
    24 HatsModel::HatsModel(QObject* parent) :
    25 HatsModel::HatsModel(QObject* parent) :
    25   QAbstractListModel(parent)
    26   QAbstractListModel(parent)
    26 {
    27 {
       
    28 	QPixmap hhpix = QPixmap(datadir->absolutePath() + "/Graphics/Hedgehog/Idle.png").copy(0, 0, 32, 32);
       
    29 
    27 	QDir tmpdir;
    30 	QDir tmpdir;
    28 	tmpdir.cd(datadir->absolutePath());
    31 	tmpdir.cd(datadir->absolutePath());
    29 	tmpdir.cd("Graphics");
    32 	tmpdir.cd("Graphics");
    30 	tmpdir.cd("Hats");
    33 	tmpdir.cd("Hats");
    31 
    34 
    32 	tmpdir.setFilter(QDir::Files);
    35 	tmpdir.setFilter(QDir::Files);
    33 
    36 
       
    37 
    34 	QStringList hatsList = tmpdir.entryList(QStringList("*.png"));
    38 	QStringList hatsList = tmpdir.entryList(QStringList("*.png"));
    35 	for (QStringList::Iterator it = hatsList.begin(); it != hatsList.end(); ++it )
    39 	for (QStringList::Iterator it = hatsList.begin(); it != hatsList.end(); ++it )
    36 	{
    40 	{
    37 		QString str = (*it).replace(QRegExp("^(.*)\\.png"), "\\1");
    41 		QString str = (*it).replace(QRegExp("^(.*)\\.png"), "\\1");
    38 		QPixmap pix(datadir->absolutePath() + "/Graphics/Hats/" + str + ".png");
    42 		QPixmap pix(datadir->absolutePath() + "/Graphics/Hats/" + str + ".png");
    39 		hats.append(qMakePair(str, QIcon(pix.copy(0, 0, 32, 32))));
    43 
       
    44 		QPixmap tmppix(32, 37);
       
    45 		tmppix.fill(QColor(Qt::transparent));
       
    46 		
       
    47 		QPainter painter(&tmppix);
       
    48 		painter.drawPixmap(QPoint(0, 5), hhpix);
       
    49 		painter.drawPixmap(QPoint(0, 0), pix.copy(0, 0, 32, 32));
       
    50 		painter.end();
       
    51 
       
    52 		hats.append(qMakePair(str, QIcon(tmppix)));
    40 	}
    53 	}
    41 
       
    42 }
    54 }
    43 
    55 
    44 QVariant HatsModel::headerData(int section,
    56 QVariant HatsModel::headerData(int section,
    45             Qt::Orientation orientation, int role) const
    57             Qt::Orientation orientation, int role) const
    46 {
    58 {