PageRenderTime 26ms CodeModel.GetById 11ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/src/docks/skilllegenddock.cpp

https://code.google.com/p/dwarftherapist/
C++ | 84 lines | 55 code | 7 blank | 22 comment | 3 complexity | 407d10277f17dd680f2e8210b4daf5ad 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#include "skilllegenddock.h"
24#include "statetableview.h"
25#include "gamedatareader.h"
26#include "dwarfmodel.h"
27#include "columntypes.h"
28#include "rotatedheader.h"
29#include "dwarftherapist.h"
30#include "optionsmenu.h"
31
32SkillLegendDock::SkillLegendDock(QWidget *parent, Qt::WindowFlags flags) 
33	: QDockWidget(parent, flags)
34{
35	setObjectName("dock_skill_legend");
36	setWindowTitle(tr("Skill Legend"));
37	QWidget *main_widget = new QWidget(this);
38        QVBoxLayout *layout = new QVBoxLayout(main_widget);
39	main_widget->setLayout(layout);
40	
41	StateTableView *stv = new StateTableView(this);
42	stv->setContextMenuPolicy(Qt::ActionsContextMenu);
43
44	QAction *a;
45	for(int i = 0; i < UberDelegate::SDM_TOTAL_METHODS; ++i) {
46		UberDelegate::SKILL_DRAWING_METHOD m = static_cast<UberDelegate::SKILL_DRAWING_METHOD>(i);
47		a = new QAction(QString("Use %1 Method")
48			.arg(UberDelegate::name_for_method(m)), stv);
49		a->setData(m);
50		connect(a, SIGNAL(triggered()), SLOT(set_SDM()));
51		stv->addAction(a);
52	}
53	
54	layout->addWidget(stv);
55	setWidget(main_widget);
56
57	QStandardItemModel *m = new QStandardItemModel(this);
58	stv->setModel(m);
59	QList<QStandardItem*> items;
60	for(int i = 20; i >= 0; --i) {
61		QList<QStandardItem*> sub_items;
62		QStandardItem *name = new QStandardItem;
63		name->setText(GameDataReader::ptr()->get_skill_level_name(i));
64		QStandardItem *item = new QStandardItem;
65		item->setData(i, DwarfModel::DR_RATING);
66		item->setData(CT_SKILL, DwarfModel::DR_COL_TYPE);
67		item->setData(Qt::white, DwarfModel::DR_DEFAULT_BG_COLOR);
68		sub_items << name << item;
69		m->appendRow(sub_items);
70	}
71	stv->setHeaderHidden(true);
72	for(int i = 1; i < 16; ++i) {
73		stv->get_header()->resizeSection(i, 16);
74	}
75
76	connect(this, SIGNAL(change_skill_drawing_method(const UberDelegate::SKILL_DRAWING_METHOD&)),
77		DT->get_options_menu(), SLOT(set_skill_drawing_method(const UberDelegate::SKILL_DRAWING_METHOD&)));
78}
79
80void SkillLegendDock::set_SDM() {
81	QAction *a = qobject_cast<QAction*>(QObject::sender());
82	UberDelegate::SKILL_DRAWING_METHOD sdm = static_cast<UberDelegate::SKILL_DRAWING_METHOD>(a->data().toInt());
83	emit change_skill_drawing_method(sdm);
84}