QTfrontend/chatwidget.cpp
author displacer
Tue, 20 Feb 2007 19:50:38 +0000
changeset 465 07eca0a2546c
parent 464 7f48321fc38a
child 480 09434d6c3865
permissions -rw-r--r--
chatWidget with nicks ready

#include <QListWidget>
#include <QLineEdit>

#include "chatwidget.h"

HWChatWidget::HWChatWidget(QWidget* parent) :
  QWidget(parent),
  mainLayout(this)
{
  mainLayout.setSpacing(1);
  mainLayout.setMargin(1);
  mainLayout.setSizeConstraint(QLayout::SetMinimumSize);
  mainLayout.setColumnStretch(0, 75);
  mainLayout.setColumnStretch(1, 25);

  chatEditLine = new QLineEdit(this);
  connect(chatEditLine, SIGNAL(returnPressed()), this, SLOT(returnPressed()));

  mainLayout.addWidget(chatEditLine, 1, 0, 1, 2);

  chatText = new QListWidget(this);
  chatText->setMinimumHeight(10);
  chatText->setMinimumWidth(10);
  chatText->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  mainLayout.addWidget(chatText, 0, 0);

  chatNicks = new QListWidget(this);
  chatNicks->setMinimumHeight(10);
  chatNicks->setMinimumWidth(10);
  chatNicks->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  mainLayout.addWidget(chatNicks, 0, 1);
}

void HWChatWidget::returnPressed()
{
  emit chatLine(chatEditLine->text());
  chatEditLine->clear();
}

void HWChatWidget::onChatStringFromNet(const QStringList& str)
{
  QListWidget* w=chatText;
  w->addItem(str[0]+": "+str[1]);
  w->scrollToBottom();
  w->setSelectionMode(QAbstractItemView::NoSelection);
}

void HWChatWidget::nickAdded(const QString& nick)
{
  chatNicks->addItem(nick);
}

void HWChatWidget::nickRemoved(const QString& nick)
{
  QList<QListWidgetItem *> items=chatNicks->findItems(nick, Qt::MatchExactly);
  for(QList<QListWidgetItem *>::iterator it=items.begin(); it!=items.end();) {
    chatNicks->takeItem(chatNicks->row(*it));
    ++it;
  }
}

void HWChatWidget::clear()
{
  chatNicks->clear();
}