Crossfire Server, Trunk
CREStringListPanel.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2022 the Crossfire Development Team
5  *
6  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7  * welcome to redistribute it under certain conditions. For details, please
8  * see COPYING and LICENSE.
9  *
10  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
11  */
12 
13 #include <QtWidgets>
14 #include "CREStringListPanel.h"
16 
17 CREStringListPanel::CREStringListPanel(QWidget* parent) : QDialog(parent)
18 {
19  setModal(true);
20  setWindowTitle(tr("NPC possible messages"));
21 
22  QVBoxLayout* layout = new QVBoxLayout(this);
23  layout->addWidget(new QLabel(tr("Messages:"), this));
24 
25  myItems = new QListWidget(this);
26  layout->addWidget(myItems);
27  myItems->setItemDelegateForColumn(0, new CREMultilineItemDelegate(myItems, false));
28 
29  QHBoxLayout* buttons = new QHBoxLayout();
30 
31  QPushButton* add = new QPushButton(tr("add"), this);
32  connect(add, SIGNAL(clicked(bool)), this, SLOT(onAddItem(bool)));
33  buttons->addWidget(add);
34 
35  QPushButton* remove = new QPushButton(tr("remove"), this);
36  connect(remove, SIGNAL(clicked(bool)), this, SLOT(onDeleteItem(bool)));
37  buttons->addWidget(remove);
38 
39  QPushButton* reset = new QPushButton(tr("reset changes"), this);
40  connect(reset, SIGNAL(clicked(bool)), this, SLOT(onReset(bool)));
41  buttons->addWidget(reset);
42 
43  layout->addLayout(buttons);
44 }
45 
47 {
48 }
49 
50 void CREStringListPanel::setData(const QStringList& list)
51 {
52  myItems->clear();
53  for (const QString item : list)
55  myOriginal = list;
56 }
57 
58 QStringList CREStringListPanel::data() const
59 {
60  QStringList data;
61  for (int i = 0; i < myItems->count(); i++)
62  data.append(myItems->item(i)->text().trimmed());
63  return data;
64 }
65 
66 QListWidgetItem* CREStringListPanel::createItem(const QString& text)
67 {
68  QListWidgetItem* wi = new QListWidgetItem(text);
69  wi->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
70  myItems->addItem(wi);
71  return wi;
72 }
73 
75 {
76  myItems->editItem(createItem("<message>"));
77 }
78 
80 {
81  if (myItems->currentRow() < 0 || myItems->currentRow() >= myItems->count())
82  return;
83  delete myItems->takeItem(myItems->currentRow());
84 }
85 
87 {
88  if (QMessageBox::question(this, "Confirm reset", "Reset the values, losing all changes?") != QMessageBox::StandardButton::Yes)
89  return;
91 }
CREStringListPanel::myItems
QListWidget * myItems
Definition: CREStringListPanel.h:38
CREStringListPanel::onDeleteItem
void onDeleteItem(bool)
Definition: CREStringListPanel.cpp:79
CREStringListPanel::data
QStringList data() const
Definition: CREStringListPanel.cpp:58
layout
Definition: main.cpp:84
guildoracle.list
list
Definition: guildoracle.py:87
CREStringListPanel::onAddItem
void onAddItem(bool)
Definition: CREStringListPanel.cpp:74
CREStringListPanel::CREStringListPanel
CREStringListPanel(QWidget *parent)
Definition: CREStringListPanel.cpp:17
CREStringListPanel::~CREStringListPanel
virtual ~CREStringListPanel()
Definition: CREStringListPanel.cpp:46
CREStringListPanel::setData
void setData(const QStringList &list)
Definition: CREStringListPanel.cpp:50
guild_entry.text
text
Definition: guild_entry.py:41
CREStringListPanel::createItem
QListWidgetItem * createItem(const QString &text)
Definition: CREStringListPanel.cpp:66
CREStringListPanel::myOriginal
QStringList myOriginal
Definition: CREStringListPanel.h:39
CREMultilineItemDelegate.h
item
Definition: item.py:1
connect
Definition: connect.py:1
CREMultilineItemDelegate
Definition: CREMultilineItemDelegate.h:19
CREStringListPanel.h
CREStringListPanel::onReset
void onReset(bool)
Definition: CREStringListPanel.cpp:86