QTfrontend/chatwidget.cpp
author displacer
Tue, 20 Feb 2007 17:50:59 +0000
changeset 461 105af110b0e6
child 462 91baab07b79a
permissions -rw-r--r--
chatWidget with layout
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
     1
#include <QListWidget>
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
     2
#include <QLineEdit>
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
     3
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
     4
#include "chatwidget.h"
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
     5
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
     6
HWChatWidget::HWChatWidget(QWidget* parent) :
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
     7
  QWidget(parent),
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
     8
  mainLayout(this)
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
     9
{
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    10
  mainLayout.setSpacing(1);
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    11
  mainLayout.setMargin(1);
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    12
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    13
  chatEditLine = new QLineEdit(this);
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    14
  connect(chatEditLine, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    15
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    16
  mainLayout.addWidget(chatEditLine, 1, 0);
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    17
  
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    18
  chatText = new QListWidget(this);
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    19
  chatText->setMinimumHeight(10);
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    20
  mainLayout.addWidget(chatText, 0, 0);
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    21
}
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    22
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    23
void HWChatWidget::returnPressed()
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    24
{
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    25
  emit chatLine(chatEditLine->text());
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    26
  chatEditLine->clear();
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    27
}
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    28
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    29
void HWChatWidget::onChatStringFromNet(const QStringList& str)
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    30
{
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    31
  QListWidget* w=chatText;
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    32
  w->addItem(str[0]+": "+str[1]);
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    33
  w->scrollToBottom();
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    34
  w->setSelectionMode(QAbstractItemView::NoSelection);
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    35
}