QTfrontend/hats.cpp
author nemo
Thu, 08 Sep 2011 08:44:17 -0400
changeset 5807 5c8fe58dead5
parent 5238 46ddaf14509d
permissions -rw-r--r--
Define 2 script callbacks to notify of hog vanishment
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1236
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
     1
/*
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4560
diff changeset
     3
 * Copyright (c) 2008-2011 Andrey Korotaev <unC0Rr@gmail.com>
1236
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
     4
 *
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
     8
 *
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
    12
 * GNU General Public License for more details.
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
    13
 *
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
    17
 */
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
    18
1239
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    19
#include <QDir>
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    20
#include <QPixmap>
1281
1f8456577a39 Draw a hedgehog under the hat in hats combobox
unc0rr
parents: 1239
diff changeset
    21
#include <QPainter>
1239
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    22
#include "hwconsts.h"
2874
3c7c2bf1ba38 A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents: 2377
diff changeset
    23
#include "hwform.h"
1237
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
    24
#include "hats.h"
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
    25
1236
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
    26
HatsModel::HatsModel(QObject* parent) :
1239
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    27
  QAbstractListModel(parent)
1236
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
    28
{
5238
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    29
    QFile hhfile;
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    30
    hhfile.setFileName(cfgdir->absolutePath() + "/Data/Graphics/Hedgehog/Idle.png");
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    31
    if (!hhfile.exists()) hhfile.setFileName(datadir->absolutePath() + "/Graphics/Hedgehog/Idle.png");
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    32
    QPixmap hhpix = QPixmap(QFileInfo(hhfile).absoluteFilePath()).copy(0, 0, 32, 32);
1281
1f8456577a39 Draw a hedgehog under the hat in hats combobox
unc0rr
parents: 1239
diff changeset
    33
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    34
    QDir tmpdir;
5238
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    35
    tmpdir.cd(cfgdir->absolutePath());
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    36
    tmpdir.cd("Data");
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    37
    tmpdir.cd("Graphics");
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    38
    tmpdir.cd("Hats");
1239
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    39
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    40
    tmpdir.setFilter(QDir::Files);
1239
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
    41
5238
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    42
    QStringList userhatsList = tmpdir.entryList(QStringList("*.png"));
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    43
    for (QStringList::Iterator it = userhatsList.begin(); it != userhatsList.end(); ++it )
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    44
    {
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    45
        QString str = QString(*it).replace(QRegExp("^(.*)\\.png"), "\\1");
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    46
        QPixmap pix(cfgdir->absolutePath() + "/Data/Graphics/Hats/" + str + ".png");
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    47
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    48
        QPixmap tmppix(32, 37);
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    49
        tmppix.fill(QColor(Qt::transparent));
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    50
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    51
        QPainter painter(&tmppix);
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    52
        painter.drawPixmap(QPoint(0, 5), hhpix);
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    53
        painter.drawPixmap(QPoint(0, 0), pix.copy(0, 0, 32, 32));
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    54
        if(pix.width() > 32)
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    55
            painter.drawPixmap(QPoint(0, 0), pix.copy(32, 0, 32, 32));
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    56
        painter.end();
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    57
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    58
        hats.append(qMakePair(str, QIcon(tmppix)));
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    59
    }
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    60
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    61
    tmpdir.cd(datadir->absolutePath());
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    62
    tmpdir.cd("Graphics");
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    63
    tmpdir.cd("Hats");
1281
1f8456577a39 Draw a hedgehog under the hat in hats combobox
unc0rr
parents: 1239
diff changeset
    64
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    65
    QStringList hatsList = tmpdir.entryList(QStringList("*.png"));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    66
    for (QStringList::Iterator it = hatsList.begin(); it != hatsList.end(); ++it )
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    67
    {
5238
46ddaf14509d Enable ~/.hedgewars/Data (or platform equivalent) to override/extend pretty much everything in system Data dir. Obviously desyncing can occur, so this is at user's own risk. Should simplify map etc install. Needs testing.
nemo
parents: 4976
diff changeset
    68
        if (userhatsList.contains(*it,Qt::CaseInsensitive)) continue;
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    69
        QString str = (*it).replace(QRegExp("^(.*)\\.png"), "\\1");
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    70
        QPixmap pix(datadir->absolutePath() + "/Graphics/Hats/" + str + ".png");
1281
1f8456577a39 Draw a hedgehog under the hat in hats combobox
unc0rr
parents: 1239
diff changeset
    71
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    72
        QPixmap tmppix(32, 37);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    73
        tmppix.fill(QColor(Qt::transparent));
2377
f3fab2b09e0c And in frontend
nemo
parents: 1281
diff changeset
    74
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    75
        QPainter painter(&tmppix);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    76
        painter.drawPixmap(QPoint(0, 5), hhpix);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    77
        painter.drawPixmap(QPoint(0, 0), pix.copy(0, 0, 32, 32));
3445
1ce844170014 Engine:
smxx
parents: 3236
diff changeset
    78
        if(pix.width() > 32)
1ce844170014 Engine:
smxx
parents: 3236
diff changeset
    79
            painter.drawPixmap(QPoint(0, 0), pix.copy(32, 0, 32, 32));
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    80
        painter.end();
1281
1f8456577a39 Draw a hedgehog under the hat in hats combobox
unc0rr
parents: 1239
diff changeset
    81
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    82
        hats.append(qMakePair(str, QIcon(tmppix)));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    83
    }
2874
3c7c2bf1ba38 A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents: 2377
diff changeset
    84
    // Reserved hats
3c7c2bf1ba38 A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents: 2377
diff changeset
    85
    tmpdir.cd("Reserved");
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    86
    hatsList = tmpdir.entryList(QStringList(playerHash+"*.png"));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    87
    for (QStringList::Iterator it = hatsList.begin(); it != hatsList.end(); ++it )
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    88
    {
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    89
        QString str = (*it).replace(QRegExp("^(.*)\\.png"), "\\1");
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    90
        QPixmap pix(datadir->absolutePath() + "/Graphics/Hats/Reserved/" + str + ".png");
2874
3c7c2bf1ba38 A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents: 2377
diff changeset
    91
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    92
        QPixmap tmppix(32, 37);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    93
        tmppix.fill(QColor(Qt::transparent));
2874
3c7c2bf1ba38 A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents: 2377
diff changeset
    94
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    95
        QPainter painter(&tmppix);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    96
        painter.drawPixmap(QPoint(0, 5), hhpix);
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    97
        painter.drawPixmap(QPoint(0, 0), pix.copy(0, 0, 32, 32));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
    98
        painter.end();
2874
3c7c2bf1ba38 A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents: 2377
diff changeset
    99
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
   100
        hats.append(qMakePair("Reserved "+str.remove(0,32), QIcon(tmppix)));
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
   101
    }
1236
f9110fd03754 Add stubs for hats implementation
unc0rr
parents:
diff changeset
   102
}
1237
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
   103
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
   104
QVariant HatsModel::headerData(int section,
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
   105
            Qt::Orientation orientation, int role) const
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
   106
{
4560
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 3445
diff changeset
   107
    Q_UNUSED(section);
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 3445
diff changeset
   108
    Q_UNUSED(orientation);
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 3445
diff changeset
   109
    Q_UNUSED(role);
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 3445
diff changeset
   110
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
   111
    return QVariant();
1237
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
   112
}
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
   113
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
   114
int HatsModel::rowCount(const QModelIndex &parent) const
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
   115
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
   116
    if (parent.isValid())
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
   117
        return 0;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
   118
    else
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
   119
        return hats.size();
1237
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
   120
}
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
   121
1239
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
   122
/*int HatsModel::columnCount(const QModelIndex & parent) const
1237
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
   123
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
   124
    if (parent.isValid())
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
   125
        return 0;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
   126
    else
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
   127
        return 2;
1237
7f3105a15d5d Fix build
unc0rr
parents: 1236
diff changeset
   128
}
1239
4901abe4c3b0 - Finish hat selection widget
unc0rr
parents: 1238
diff changeset
   129
*/
1238
914bd2a9a249 Add hat selection control to team editing page (it's empty combobox yet)
unc0rr
parents: 1237
diff changeset
   130
QVariant HatsModel::data(const QModelIndex &index,
914bd2a9a249 Add hat selection control to team editing page (it's empty combobox yet)
unc0rr
parents: 1237
diff changeset
   131
                         int role) const
914bd2a9a249 Add hat selection control to team editing page (it's empty combobox yet)
unc0rr
parents: 1237
diff changeset
   132
{
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
   133
    if (!index.isValid() || index.row() < 0
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
   134
        || index.row() >= hats.size()
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
   135
        || (role != Qt::DisplayRole && role != Qt::DecorationRole))
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
   136
        return QVariant();
1238
914bd2a9a249 Add hat selection control to team editing page (it's empty combobox yet)
unc0rr
parents: 1237
diff changeset
   137
2948
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
   138
    if (role == Qt::DisplayRole)
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
   139
        return hats.at(index.row()).first;
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
   140
    else // role == Qt::DecorationRole
3f21a9dc93d0 Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents: 2874
diff changeset
   141
        return hats.at(index.row()).second;
1238
914bd2a9a249 Add hat selection control to team editing page (it's empty combobox yet)
unc0rr
parents: 1237
diff changeset
   142
}