QTfrontend/hats.cpp
changeset 5238 46ddaf14509d
parent 4976 088d40d8aba2
equal deleted inserted replaced
5237:963d787a25c2 5238:46ddaf14509d
    24 #include "hats.h"
    24 #include "hats.h"
    25 
    25 
    26 HatsModel::HatsModel(QObject* parent) :
    26 HatsModel::HatsModel(QObject* parent) :
    27   QAbstractListModel(parent)
    27   QAbstractListModel(parent)
    28 {
    28 {
    29     QPixmap hhpix = QPixmap(datadir->absolutePath() + "/Graphics/Hedgehog/Idle.png").copy(0, 0, 32, 32);
    29     QFile hhfile;
       
    30     hhfile.setFileName(cfgdir->absolutePath() + "/Data/Graphics/Hedgehog/Idle.png");
       
    31     if (!hhfile.exists()) hhfile.setFileName(datadir->absolutePath() + "/Graphics/Hedgehog/Idle.png");
       
    32     QPixmap hhpix = QPixmap(QFileInfo(hhfile).absoluteFilePath()).copy(0, 0, 32, 32);
    30 
    33 
    31     QDir tmpdir;
    34     QDir tmpdir;
    32     tmpdir.cd(datadir->absolutePath());
    35     tmpdir.cd(cfgdir->absolutePath());
       
    36     tmpdir.cd("Data");
    33     tmpdir.cd("Graphics");
    37     tmpdir.cd("Graphics");
    34     tmpdir.cd("Hats");
    38     tmpdir.cd("Hats");
    35 
    39 
    36     tmpdir.setFilter(QDir::Files);
    40     tmpdir.setFilter(QDir::Files);
    37 
    41 
       
    42     QStringList userhatsList = tmpdir.entryList(QStringList("*.png"));
       
    43     for (QStringList::Iterator it = userhatsList.begin(); it != userhatsList.end(); ++it )
       
    44     {
       
    45         QString str = QString(*it).replace(QRegExp("^(.*)\\.png"), "\\1");
       
    46         QPixmap pix(cfgdir->absolutePath() + "/Data/Graphics/Hats/" + str + ".png");
       
    47 
       
    48         QPixmap tmppix(32, 37);
       
    49         tmppix.fill(QColor(Qt::transparent));
       
    50 
       
    51         QPainter painter(&tmppix);
       
    52         painter.drawPixmap(QPoint(0, 5), hhpix);
       
    53         painter.drawPixmap(QPoint(0, 0), pix.copy(0, 0, 32, 32));
       
    54         if(pix.width() > 32)
       
    55             painter.drawPixmap(QPoint(0, 0), pix.copy(32, 0, 32, 32));
       
    56         painter.end();
       
    57 
       
    58         hats.append(qMakePair(str, QIcon(tmppix)));
       
    59     }
       
    60 
       
    61     tmpdir.cd(datadir->absolutePath());
       
    62     tmpdir.cd("Graphics");
       
    63     tmpdir.cd("Hats");
    38 
    64 
    39     QStringList hatsList = tmpdir.entryList(QStringList("*.png"));
    65     QStringList hatsList = tmpdir.entryList(QStringList("*.png"));
    40     for (QStringList::Iterator it = hatsList.begin(); it != hatsList.end(); ++it )
    66     for (QStringList::Iterator it = hatsList.begin(); it != hatsList.end(); ++it )
    41     {
    67     {
       
    68         if (userhatsList.contains(*it,Qt::CaseInsensitive)) continue;
    42         QString str = (*it).replace(QRegExp("^(.*)\\.png"), "\\1");
    69         QString str = (*it).replace(QRegExp("^(.*)\\.png"), "\\1");
    43         QPixmap pix(datadir->absolutePath() + "/Graphics/Hats/" + str + ".png");
    70         QPixmap pix(datadir->absolutePath() + "/Graphics/Hats/" + str + ".png");
    44 
    71 
    45         QPixmap tmppix(32, 37);
    72         QPixmap tmppix(32, 37);
    46         tmppix.fill(QColor(Qt::transparent));
    73         tmppix.fill(QColor(Qt::transparent));