/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. /*
  2. Dwarf Therapist
  3. Copyright (c) 2009 Trey Stout (chmod)
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. */
  20. #include "skilllegenddock.h"
  21. #include "statetableview.h"
  22. #include "gamedatareader.h"
  23. #include "dwarfmodel.h"
  24. #include "columntypes.h"
  25. #include "rotatedheader.h"
  26. #include "dwarftherapist.h"
  27. #include "optionsmenu.h"
  28. SkillLegendDock::SkillLegendDock(QWidget *parent, Qt::WindowFlags flags)
  29. : QDockWidget(parent, flags)
  30. {
  31. setObjectName("dock_skill_legend");
  32. setWindowTitle(tr("Skill Legend"));
  33. QWidget *main_widget = new QWidget(this);
  34. QVBoxLayout *layout = new QVBoxLayout(main_widget);
  35. main_widget->setLayout(layout);
  36. StateTableView *stv = new StateTableView(this);
  37. stv->setContextMenuPolicy(Qt::ActionsContextMenu);
  38. QAction *a;
  39. for(int i = 0; i < UberDelegate::SDM_TOTAL_METHODS; ++i) {
  40. UberDelegate::SKILL_DRAWING_METHOD m = static_cast<UberDelegate::SKILL_DRAWING_METHOD>(i);
  41. a = new QAction(QString("Use %1 Method")
  42. .arg(UberDelegate::name_for_method(m)), stv);
  43. a->setData(m);
  44. connect(a, SIGNAL(triggered()), SLOT(set_SDM()));
  45. stv->addAction(a);
  46. }
  47. layout->addWidget(stv);
  48. setWidget(main_widget);
  49. QStandardItemModel *m = new QStandardItemModel(this);
  50. stv->setModel(m);
  51. QList<QStandardItem*> items;
  52. for(int i = 20; i >= 0; --i) {
  53. QList<QStandardItem*> sub_items;
  54. QStandardItem *name = new QStandardItem;
  55. name->setText(GameDataReader::ptr()->get_skill_level_name(i));
  56. QStandardItem *item = new QStandardItem;
  57. item->setData(i, DwarfModel::DR_RATING);
  58. item->setData(CT_SKILL, DwarfModel::DR_COL_TYPE);
  59. item->setData(Qt::white, DwarfModel::DR_DEFAULT_BG_COLOR);
  60. sub_items << name << item;
  61. m->appendRow(sub_items);
  62. }
  63. stv->setHeaderHidden(true);
  64. for(int i = 1; i < 16; ++i) {
  65. stv->get_header()->resizeSection(i, 16);
  66. }
  67. connect(this, SIGNAL(change_skill_drawing_method(const UberDelegate::SKILL_DRAWING_METHOD&)),
  68. DT->get_options_menu(), SLOT(set_skill_drawing_method(const UberDelegate::SKILL_DRAWING_METHOD&)));
  69. }
  70. void SkillLegendDock::set_SDM() {
  71. QAction *a = qobject_cast<QAction*>(QObject::sender());
  72. UberDelegate::SKILL_DRAWING_METHOD sdm = static_cast<UberDelegate::SKILL_DRAWING_METHOD>(a->data().toInt());
  73. emit change_skill_drawing_method(sdm);
  74. }