PageRenderTime 20ms CodeModel.GetById 9ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/src/grid_view/currentjobcolumn.cpp

https://code.google.com/p/dwarftherapist/
C++ | 143 lines | 112 code | 9 blank | 22 comment | 8 complexity | 116da72c2fe600ced4d69daf667286a7 MD5 | raw file
  1/*
  2Dwarf Therapist
  3Copyright (c) 2009 Trey Stout (chmod)
  4
  5Permission is hereby granted, free of charge, to any person obtaining a copy
  6of this software and associated documentation files (the "Software"), to deal
  7in the Software without restriction, including without limitation the rights
  8to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9copies of the Software, and to permit persons to whom the Software is
 10furnished to do so, subject to the following conditions:
 11
 12The above copyright notice and this permission notice shall be included in
 13all copies or substantial portions of the Software.
 14
 15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 20OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 21THE SOFTWARE.
 22*/
 23
 24#include "currentjobcolumn.h"
 25#include "columntypes.h"
 26#include "viewcolumnset.h"
 27#include "dwarfmodel.h"
 28#include "dwarf.h"
 29#include "dwarftherapist.h"
 30#include "defines.h"
 31#include "dwarfjob.h"
 32#include "gamedatareader.h"
 33
 34CurrentJobColumn::CurrentJobColumn(const QString &title, ViewColumnSet *set,
 35                       QObject *parent)
 36    : ViewColumn(title, CT_IDLE, set, parent)
 37{}
 38
 39CurrentJobColumn::CurrentJobColumn(const CurrentJobColumn &to_copy)
 40    : ViewColumn(to_copy)
 41{}
 42
 43QStandardItem *CurrentJobColumn::build_cell(Dwarf *d) {
 44    QStandardItem *item = init_cell(d);
 45    short job_id = d->current_job_id();
 46    QString pixmap_name(":img/help.png");
 47    if (job_id == -1) {
 48        pixmap_name = ":status/img/bullet_red.png"; // idle
 49    } else {
 50        DwarfJob *job = GameDataReader::ptr()->get_job(job_id);
 51        if (job) {
 52
 53            DwarfJob::DWARF_JOB_TYPE job_type = job->type;
 54            if(!job->reactionClass.isEmpty() && !d->current_sub_job_id().isEmpty()) {
 55                RawObjectPtr reaction = GameDataReader::ptr()->
 56                        get_reaction(job->reactionClass, d->current_sub_job_id());
 57                if(!reaction.isNull()) {
 58                    job_type = DwarfJob::get_type(reaction->get_value("SKILL"));
 59                }
 60            }
 61
 62            TRACE << "Dwarf: " << d->nice_name() << " job -" << job_id << ": (" << job->description << "," << job_type << ")";
 63
 64            switch (job_type) {
 65            case DwarfJob::DJT_IDLE:
 66                pixmap_name = ":status/img/bullet_red.png";
 67                break;
 68            case DwarfJob::DJT_DIG:
 69                pixmap_name = ":status/img/pickaxe.png";
 70                break;
 71            case DwarfJob::DJT_CUT:
 72                pixmap_name = ":status/img/axe.png";
 73                break;
 74            case DwarfJob::DJT_REST:
 75                pixmap_name = ":status/img/status_sleep.png";
 76                break;
 77            case DwarfJob::DJT_DRINK:
 78                pixmap_name = ":status/img/status_drink.png";
 79                break;
 80            case DwarfJob::DJT_FOOD:
 81                pixmap_name = ":status/img/cheese.png";
 82                break;
 83            case DwarfJob::DJT_BUILD:
 84                pixmap_name = ":status/img/gear.png";
 85                break;
 86            case DwarfJob::DJT_HAUL:
 87                pixmap_name = ":status/img/status_haul.png";
 88                break;
 89            case DwarfJob::DJT_FIGHT:
 90                pixmap_name = ":status/img/status_fight2.png";
 91                break;
 92            case DwarfJob::DJT_MOOD:
 93                pixmap_name = ":img/exclamation.png";
 94                break;
 95            case DwarfJob::DJT_FORGE:
 96                pixmap_name = ":status/img/status_forge.png";
 97                break;
 98            case DwarfJob::DJT_MEDICAL:
 99                pixmap_name = ":status/img/first_aid_kit.png";
100                break;
101            case DwarfJob::DJT_WAX_WORKING:
102                pixmap_name = ":status/img/lump.png";
103                break;
104            case DwarfJob::DJT_POTTERY:
105                pixmap_name = ":status/img/pot.png";
106                break;
107            case DwarfJob::DJT_PRESSING:
108                pixmap_name = ":status/img/cup2.png";
109                break;
110            case DwarfJob::DJT_SPINNING:
111                pixmap_name = ":status/img/spinning.png";
112                break;
113            case DwarfJob::DJT_BEE_KEEPING:
114                pixmap_name = ":status/img/bee_i_guess.png";
115                break;
116            default:
117            case DwarfJob::DJT_DEFAULT:
118                pixmap_name = ":status/img/control_play_blue.png";
119                break;
120            }
121        }
122    }
123    item->setData(QIcon(pixmap_name), Qt::DecorationRole);
124    
125    item->setData(CT_IDLE, DwarfModel::DR_COL_TYPE);
126    item->setData(d->current_job_id(), DwarfModel::DR_SORT_VALUE);
127    QString tooltip = QString("<h3>%1</h3>%2 (%3)<h4>%4</h4>")
128        .arg(m_title)
129        .arg(d->current_job())
130        .arg(d->current_job_id())
131        .arg(d->nice_name());
132    item->setToolTip(tooltip);
133    return item;
134}
135
136QStandardItem *CurrentJobColumn::build_aggregate(const QString &group_name,
137                                           const QVector<Dwarf*> &dwarves) {
138    Q_UNUSED(group_name);
139    Q_UNUSED(dwarves);
140    QStandardItem *item = new QStandardItem;
141    item->setData(m_bg_color, DwarfModel::DR_DEFAULT_BG_COLOR);
142    return item;
143}