Crossfire Server, Trunk  R20513
CRERulePanel.cpp
Go to the documentation of this file.
1 #include <Qt>
2 #include "CRERulePanel.h"
3 #include "MessageFile.h"
4 #include <QtGui>
5 #include "CREStringListPanel.h"
6 #include "CREPrePostPanel.h"
7 #include "CREReplyPanel.h"
8 #include "MessageManager.h"
9 
10 CRERulePanel::CRERulePanel(const MessageManager* manager, const QuestManager* quests, QWidget* parent) : QTabWidget(parent)
11 {
12  QWidget* m = new QWidget(this);
13  QVBoxLayout* ml = new QVBoxLayout(m);
14  ml->addWidget(new QLabel(tr("Matches (one per line, not case sensitive):"), this));
15  myMatches = new QTextEdit(this);
16  myMatches->setAcceptRichText(false);
17  connect(myMatches, SIGNAL(textChanged()), this, SLOT(onMatchModified()));
18  ml->addWidget(myMatches);
19  addTab(m, tr("matches"));
20 
21 
22  myPre = new CREPrePostPanel(true, manager->preConditions(), quests, this);
23  connect(myPre, SIGNAL(dataModified()), this, SLOT(onPreModified()));
24  addTab(myPre, tr("pre"));
25  myMessages = new CREStringListPanel(this);
26  connect(myMessages, SIGNAL(dataModified()), this, SLOT(onMessageModified()));
27  addTab(myMessages, tr("message"));
28  myPost = new CREPrePostPanel(false, manager->postConditions(), quests, this);
29  connect(myPost, SIGNAL(dataModified()), this, SLOT(onPostModified()));
30  addTab(myPost, tr("post"));
31 
32  myReplies = new CREReplyPanel(this);
33  connect(myReplies, SIGNAL(dataModified()), this, SLOT(onRepliesModified()));
34  addTab(myReplies, tr("replies"));
35 
36  QWidget* w = new QWidget(this);
37  QVBoxLayout* l = new QVBoxLayout(w);
38  l->addWidget(new QLabel(tr("Includes (one per line, path can be absolute or relative to the current message file):"), this));
39  myInclude = new QTextEdit(this);
40  myInclude->setAcceptRichText(false);
41  connect(myInclude, SIGNAL(textChanged()), this, SLOT(onIncludeModified()));
42  l->addWidget(myInclude);
43  addTab(w, tr("includes"));
44 
45  myRule = NULL;
46 }
47 
49 {
50 }
51 
53 {
54  myRule = NULL;
55 
56  myMatches->clear();
58  myInclude->clear();
59 
60  myRule = rule;
61 
62  if (rule != NULL)
63  {
64  myMatches->setText(rule->match().join("\n"));
65  myPre->setData(rule->preconditions());
66  myMessages->setData(rule->messages());
67  myPost->setData(rule->postconditions());
68  myReplies->setData(rule->replies());
69  myInclude->setText(rule->include().join("\n"));
70  }
71 }
72 
74 {
75  if (myRule == NULL)
76  return;
77  myRule->setMatch(myMatches->toPlainText().trimmed().split("\n"));
78  emit currentRuleModified();
79 }
80 
82 {
83  if (myRule == NULL)
84  return;
86  emit currentRuleModified();
87 }
88 
90 {
91  if (myRule == NULL)
92  return;
94  emit currentRuleModified();
95 }
96 
98 {
99  if (myRule == NULL)
100  return;
102  emit currentRuleModified();
103 }
104 
106 {
107  if (myRule == NULL)
108  return;
110  emit currentRuleModified();
111 }
112 
114 {
115  if (myRule != NULL)
116  {
117  QStringList include;
118  include = myInclude->toPlainText().split("\n");
119  for (int i = include.length() - 1; i >= 0; i--)
120  {
121  if (include[i].isEmpty())
122  include.removeAt(i);
123  }
124 
125  myRule->setInclude(include);
126  emit currentRuleModified();
127  }
128 }
This panel is the &#39;replies&#39; subpanel in the messages panel.
Definition: CREReplyPanel.h:14
QTextEdit * myMatches
Definition: CRERulePanel.h:33
const QList< QStringList > & postconditions() const
Definition: MessageFile.cpp:66
CREPrePostPanel * myPre
Definition: CRERulePanel.h:34
const QList< QStringList > & preconditions() const
Definition: MessageFile.cpp:56
CREReplyPanel * myReplies
Definition: CRERulePanel.h:37
void onRepliesModified()
void setData(const QStringList &list)
void setPostconditions(const QList< QStringList > &postconditions)
Definition: MessageFile.cpp:71
CREStringListPanel * myMessages
Definition: CRERulePanel.h:35
QStringList getData() const
void setPreconditions(const QList< QStringList > &preconditions)
Definition: MessageFile.cpp:61
void onPostModified()
void setData(const QList< QStringList > &data)
void onMessageModified()
void setMessageRule(MessageRule *rule)
This panel is the &#39;pre&#39; or &#39;post&#39; subpanel in the messages panel.
void setMatch(const QStringList &match)
Definition: MessageFile.cpp:51
CRERulePanel(const MessageManager *manager, const QuestManager *quests, QWidget *parent)
void setReplies(const QList< QStringList > &replies)
QList< QuestConditionScript * > preConditions() const
CREPrePostPanel * myPost
Definition: CRERulePanel.h:36
void setInclude(const QStringList &include)
Definition: MessageFile.cpp:91
void setData(const QList< QStringList > data)
QList< QStringList > getData()
const QStringList & match() const
Definition: MessageFile.cpp:41
void onPreModified()
virtual ~CRERulePanel()
void setMessages(const QStringList &messages)
Definition: MessageFile.cpp:81
void onMatchModified()
const QStringList & include() const
Definition: MessageFile.cpp:86
QTextEdit * myInclude
Definition: CRERulePanel.h:38
QList< QStringList > getData()
QList< QuestConditionScript * > postConditions() const
MessageRule * myRule
Definition: CRERulePanel.h:32
static quest_definition * quests
All known quests.
Definition: quest.c:93
void onIncludeModified()
void currentRuleModified()
const QStringList & messages() const
Definition: MessageFile.cpp:76
const QList< QStringList > & replies() const
Definition: MessageFile.cpp:96