Crossfire Server, Trunk  R20513
CREStringListPanel.cpp
Go to the documentation of this file.
1 #include "CREStringListPanel.h"
2 #include <QtGui>
3 
4 CREStringListPanel::CREStringListPanel(QWidget* parent) : QWidget(parent)
5 {
6  QGridLayout* layout = new QGridLayout(this);
7  myItems = new QListWidget(this);
8  connect(myItems, SIGNAL(currentRowChanged(int)), this, SLOT(onCurrentItemChanged(int)));
9  layout->addWidget(new QLabel(tr("Message:"), this), 0, 0, 1, 2);
10  layout->addWidget(myItems, 1, 0, 1, 2);
11 
12  QPushButton* add = new QPushButton(tr("add"), this);
13  connect(add, SIGNAL(clicked(bool)), this, SLOT(onAddItem(bool)));
14  layout->addWidget(add, 2, 0);
15 
16  QPushButton* remove = new QPushButton(tr("remove"), this);
17  connect(remove, SIGNAL(clicked(bool)), this, SLOT(onDeleteItem(bool)));
18  layout->addWidget(remove, 2, 1);
19 
20  layout->addWidget(new QLabel(tr("Message:"), this), 3, 0);
21 
22  myTextEdit = new QTextEdit(this);
23  connect(myTextEdit, SIGNAL(textChanged()), this, SLOT(onTextEditChanged()));
24  layout->addWidget(myTextEdit, 3, 1);
25 
26  myCurrentLine = -1;
27 }
28 
30 {
31 }
32 
34 {
35 
36 }
37 
38 void CREStringListPanel::setData(const QStringList& list)
39 {
40  myCurrentLine = -1;
41  myItems->clear();
42  myItems->addItems(list);
43  if (myTextEdit != NULL)
44  myTextEdit->setText("");
45 }
46 
47 QStringList CREStringListPanel::getData() const
48 {
49  QStringList data;
50  for (int i = 0; i < myItems->count(); i++)
51  data.append(myItems->item(i)->text());
52  return data;
53 }
54 
56 {
57  myItems->addItem("<item>");
58  emit dataModified();
59 }
60 
62 {
63  if (myCurrentLine == -1 || myCurrentLine >= myItems->count())
64  return;
65 
66  delete myItems->takeItem(myCurrentLine);
67  myCurrentLine = -1;
68  if (myTextEdit != NULL)
69  myTextEdit->setText("");
70  emit dataModified();
71 }
72 
74 {
75  if (myCurrentLine == -1 || myCurrentLine >= myItems->count())
76  return;
77 
78  myItems->item(myCurrentLine)->setText(myTextEdit->toPlainText());
79  emit dataModified();
80 }
81 
83 {
84  commitData();
85  if (currentRow == -1)
86  return;
87  myCurrentLine = currentRow;
88  myTextEdit->setText(myItems->item(myCurrentLine)->text());
89 }
90 
92 {
93  if (myCurrentLine == -1)
94  return;
95  myItems->item(myCurrentLine)->setText(myTextEdit->toPlainText());
96  emit dataModified();
97 }
void onCurrentItemChanged(int currentRow)
void setData(const QStringList &list)
QStringList getData() const
CREStringListPanel(QWidget *parent)
Definition: main.c:88