QTfrontend/chatwidget.cpp
author unc0rr
Wed, 21 Feb 2007 19:40:06 +0000
changeset 471 e1eb64ba5e9c
parent 465 07eca0a2546c
child 480 09434d6c3865
permissions -rw-r--r--
Small cleanup, faster compilation as a result
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);
462
91baab07b79a resizing and grid problems
displacer
parents: 461
diff changeset
    12
  mainLayout.setSizeConstraint(QLayout::SetMinimumSize);
464
7f48321fc38a vertical size fix for chatwidget
displacer
parents: 463
diff changeset
    13
  mainLayout.setColumnStretch(0, 75);
7f48321fc38a vertical size fix for chatwidget
displacer
parents: 463
diff changeset
    14
  mainLayout.setColumnStretch(1, 25);
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    15
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    16
  chatEditLine = new QLineEdit(this);
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    17
  connect(chatEditLine, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    18
463
353c2f830888 fixes last commit problems
displacer
parents: 462
diff changeset
    19
  mainLayout.addWidget(chatEditLine, 1, 0, 1, 2);
462
91baab07b79a resizing and grid problems
displacer
parents: 461
diff changeset
    20
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    21
  chatText = new QListWidget(this);
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    22
  chatText->setMinimumHeight(10);
462
91baab07b79a resizing and grid problems
displacer
parents: 461
diff changeset
    23
  chatText->setMinimumWidth(10);
463
353c2f830888 fixes last commit problems
displacer
parents: 462
diff changeset
    24
  chatText->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    25
  mainLayout.addWidget(chatText, 0, 0);
462
91baab07b79a resizing and grid problems
displacer
parents: 461
diff changeset
    26
91baab07b79a resizing and grid problems
displacer
parents: 461
diff changeset
    27
  chatNicks = new QListWidget(this);
91baab07b79a resizing and grid problems
displacer
parents: 461
diff changeset
    28
  chatNicks->setMinimumHeight(10);
91baab07b79a resizing and grid problems
displacer
parents: 461
diff changeset
    29
  chatNicks->setMinimumWidth(10);
463
353c2f830888 fixes last commit problems
displacer
parents: 462
diff changeset
    30
  chatNicks->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
462
91baab07b79a resizing and grid problems
displacer
parents: 461
diff changeset
    31
  mainLayout.addWidget(chatNicks, 0, 1);
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    32
}
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    33
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    34
void HWChatWidget::returnPressed()
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    35
{
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    36
  emit chatLine(chatEditLine->text());
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    37
  chatEditLine->clear();
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    38
}
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    39
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    40
void HWChatWidget::onChatStringFromNet(const QStringList& str)
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    41
{
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    42
  QListWidget* w=chatText;
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    43
  w->addItem(str[0]+": "+str[1]);
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    44
  w->scrollToBottom();
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    45
  w->setSelectionMode(QAbstractItemView::NoSelection);
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    46
}
465
07eca0a2546c chatWidget with nicks ready
displacer
parents: 464
diff changeset
    47
07eca0a2546c chatWidget with nicks ready
displacer
parents: 464
diff changeset
    48
void HWChatWidget::nickAdded(const QString& nick)
07eca0a2546c chatWidget with nicks ready
displacer
parents: 464
diff changeset
    49
{
07eca0a2546c chatWidget with nicks ready
displacer
parents: 464
diff changeset
    50
  chatNicks->addItem(nick);
07eca0a2546c chatWidget with nicks ready
displacer
parents: 464
diff changeset
    51
}
07eca0a2546c chatWidget with nicks ready
displacer
parents: 464
diff changeset
    52
07eca0a2546c chatWidget with nicks ready
displacer
parents: 464
diff changeset
    53
void HWChatWidget::nickRemoved(const QString& nick)
07eca0a2546c chatWidget with nicks ready
displacer
parents: 464
diff changeset
    54
{
07eca0a2546c chatWidget with nicks ready
displacer
parents: 464
diff changeset
    55
  QList<QListWidgetItem *> items=chatNicks->findItems(nick, Qt::MatchExactly);
07eca0a2546c chatWidget with nicks ready
displacer
parents: 464
diff changeset
    56
  for(QList<QListWidgetItem *>::iterator it=items.begin(); it!=items.end();) {
07eca0a2546c chatWidget with nicks ready
displacer
parents: 464
diff changeset
    57
    chatNicks->takeItem(chatNicks->row(*it));
07eca0a2546c chatWidget with nicks ready
displacer
parents: 464
diff changeset
    58
    ++it;
07eca0a2546c chatWidget with nicks ready
displacer
parents: 464
diff changeset
    59
  }
07eca0a2546c chatWidget with nicks ready
displacer
parents: 464
diff changeset
    60
}
07eca0a2546c chatWidget with nicks ready
displacer
parents: 464
diff changeset
    61
07eca0a2546c chatWidget with nicks ready
displacer
parents: 464
diff changeset
    62
void HWChatWidget::clear()
07eca0a2546c chatWidget with nicks ready
displacer
parents: 464
diff changeset
    63
{
07eca0a2546c chatWidget with nicks ready
displacer
parents: 464
diff changeset
    64
  chatNicks->clear();
07eca0a2546c chatWidget with nicks ready
displacer
parents: 464
diff changeset
    65
}