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 QPixmap hhpix = QPixmap(datadir->absolutePath() + "/Graphics/Hedgehog/Idle.png").copy(0, 0, 32, 32); |
30 |
30 |
31 QDir tmpdir; |
31 QDir tmpdir; |
32 tmpdir.cd(datadir->absolutePath()); |
32 tmpdir.cd(datadir->absolutePath()); |
33 tmpdir.cd("Graphics"); |
33 tmpdir.cd("Graphics"); |
34 tmpdir.cd("Hats"); |
34 tmpdir.cd("Hats"); |
35 |
35 |
36 tmpdir.setFilter(QDir::Files); |
36 tmpdir.setFilter(QDir::Files); |
37 |
37 |
38 |
38 |
39 QStringList hatsList = tmpdir.entryList(QStringList("*.png")); |
39 QStringList hatsList = tmpdir.entryList(QStringList("*.png")); |
40 for (QStringList::Iterator it = hatsList.begin(); it != hatsList.end(); ++it ) |
40 for (QStringList::Iterator it = hatsList.begin(); it != hatsList.end(); ++it ) |
41 { |
41 { |
42 QString str = (*it).replace(QRegExp("^(.*)\\.png"), "\\1"); |
42 QString str = (*it).replace(QRegExp("^(.*)\\.png"), "\\1"); |
43 QPixmap pix(datadir->absolutePath() + "/Graphics/Hats/" + str + ".png"); |
43 QPixmap pix(datadir->absolutePath() + "/Graphics/Hats/" + str + ".png"); |
44 |
44 |
45 QPixmap tmppix(32, 37); |
45 QPixmap tmppix(32, 37); |
46 tmppix.fill(QColor(Qt::transparent)); |
46 tmppix.fill(QColor(Qt::transparent)); |
47 |
47 |
48 QPainter painter(&tmppix); |
48 QPainter painter(&tmppix); |
49 painter.drawPixmap(QPoint(0, 5), hhpix); |
49 painter.drawPixmap(QPoint(0, 5), hhpix); |
50 painter.drawPixmap(QPoint(0, 0), pix.copy(0, 0, 32, 32)); |
50 painter.drawPixmap(QPoint(0, 0), pix.copy(0, 0, 32, 32)); |
51 painter.end(); |
51 painter.end(); |
52 |
52 |
53 hats.append(qMakePair(str, QIcon(tmppix))); |
53 hats.append(qMakePair(str, QIcon(tmppix))); |
54 } |
54 } |
55 // Reserved hats |
55 // Reserved hats |
56 tmpdir.cd("Reserved"); |
56 tmpdir.cd("Reserved"); |
57 hatsList = tmpdir.entryList(QStringList(playerHash+"*.png")); |
57 hatsList = tmpdir.entryList(QStringList(playerHash+"*.png")); |
58 for (QStringList::Iterator it = hatsList.begin(); it != hatsList.end(); ++it ) |
58 for (QStringList::Iterator it = hatsList.begin(); it != hatsList.end(); ++it ) |
59 { |
59 { |
60 QString str = (*it).replace(QRegExp("^(.*)\\.png"), "\\1"); |
60 QString str = (*it).replace(QRegExp("^(.*)\\.png"), "\\1"); |
61 QPixmap pix(datadir->absolutePath() + "/Graphics/Hats/Reserved/" + str + ".png"); |
61 QPixmap pix(datadir->absolutePath() + "/Graphics/Hats/Reserved/" + str + ".png"); |
62 |
62 |
63 QPixmap tmppix(32, 37); |
63 QPixmap tmppix(32, 37); |
64 tmppix.fill(QColor(Qt::transparent)); |
64 tmppix.fill(QColor(Qt::transparent)); |
65 |
65 |
66 QPainter painter(&tmppix); |
66 QPainter painter(&tmppix); |
67 painter.drawPixmap(QPoint(0, 5), hhpix); |
67 painter.drawPixmap(QPoint(0, 5), hhpix); |
68 painter.drawPixmap(QPoint(0, 0), pix.copy(0, 0, 32, 32)); |
68 painter.drawPixmap(QPoint(0, 0), pix.copy(0, 0, 32, 32)); |
69 painter.end(); |
69 painter.end(); |
70 |
70 |
71 hats.append(qMakePair("Reserved "+str.remove(0,32), QIcon(tmppix))); |
71 hats.append(qMakePair("Reserved "+str.remove(0,32), QIcon(tmppix))); |
72 } |
72 } |
73 } |
73 } |
74 |
74 |
75 QVariant HatsModel::headerData(int section, |
75 QVariant HatsModel::headerData(int section, |
76 Qt::Orientation orientation, int role) const |
76 Qt::Orientation orientation, int role) const |
77 { |
77 { |
78 return QVariant(); |
78 return QVariant(); |
79 } |
79 } |
80 |
80 |
81 int HatsModel::rowCount(const QModelIndex &parent) const |
81 int HatsModel::rowCount(const QModelIndex &parent) const |
82 { |
82 { |
83 if (parent.isValid()) |
83 if (parent.isValid()) |
84 return 0; |
84 return 0; |
85 else |
85 else |
86 return hats.size(); |
86 return hats.size(); |
87 } |
87 } |
88 |
88 |
89 /*int HatsModel::columnCount(const QModelIndex & parent) const |
89 /*int HatsModel::columnCount(const QModelIndex & parent) const |
90 { |
90 { |
91 if (parent.isValid()) |
91 if (parent.isValid()) |
92 return 0; |
92 return 0; |
93 else |
93 else |
94 return 2; |
94 return 2; |
95 } |
95 } |
96 */ |
96 */ |
97 QVariant HatsModel::data(const QModelIndex &index, |
97 QVariant HatsModel::data(const QModelIndex &index, |
98 int role) const |
98 int role) const |
99 { |
99 { |
100 if (!index.isValid() || index.row() < 0 |
100 if (!index.isValid() || index.row() < 0 |
101 || index.row() >= hats.size() |
101 || index.row() >= hats.size() |
102 || (role != Qt::DisplayRole && role != Qt::DecorationRole)) |
102 || (role != Qt::DisplayRole && role != Qt::DecorationRole)) |
103 return QVariant(); |
103 return QVariant(); |
104 |
104 |
105 if (role == Qt::DisplayRole) |
105 if (role == Qt::DisplayRole) |
106 return hats.at(index.row()).first; |
106 return hats.at(index.row()).first; |
107 else // role == Qt::DecorationRole |
107 else // role == Qt::DecorationRole |
108 return hats.at(index.row()).second; |
108 return hats.at(index.row()).second; |
109 } |
109 } |