History

Coding standard

David Rowe committed 12 years ago

Commit 51515631 parent 87d067c2 files · +48 −48Browse files

Showing the changes to interface/src/ui/ChatWindow.cpp (1 of 2 files). Show all

Unified · Split

interface/src/ui/ChatWindow.cpp+45−45
@@ -41,8 +41,8 @@ const QString mentionRegex("@(\\b%1\\b)"); · 40 unmodified lines
41ChatWindow::ChatWindow(QWidget* parent) :41ChatWindow::ChatWindow(QWidget* parent) :
42 QWidget(parent, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint |42 QWidget(parent, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint |
43 Qt::WindowCloseButtonHint),43 Qt::WindowCloseButtonHint),
44 ui(new Ui::ChatWindow),44 _ui(new Ui::ChatWindow),
45 numMessagesAfterLastTimeStamp(0),45 _numMessagesAfterLastTimeStamp(0),
46 _mousePressed(false),46 _mousePressed(false),
47 _mouseStartPosition(),47 _mouseStartPosition(),
48 _trayIcon(parent),48 _trayIcon(parent),
@@ -50,15 +50,15 @@ ChatWindow::ChatWindow(QWidget* parent) : · 1 unmodified line
50{50{
51 setAttribute(Qt::WA_DeleteOnClose, false);51 setAttribute(Qt::WA_DeleteOnClose, false);
52 52
53 ui->setupUi(this);53 _ui->setupUi(this);
54 54
55 FlowLayout* flowLayout = new FlowLayout(0, 4, 4);55 FlowLayout* flowLayout = new FlowLayout(0, 4, 4);
56 ui->usersWidget->setLayout(flowLayout);56 _ui->usersWidget->setLayout(flowLayout);
57 57
58 ui->messagePlainTextEdit->installEventFilter(this);58 _ui->messagePlainTextEdit->installEventFilter(this);
59 ui->messagePlainTextEdit->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);59 _ui->messagePlainTextEdit->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
60 60
61 QTextCursor cursor(ui->messagePlainTextEdit->textCursor());61 QTextCursor cursor(_ui->messagePlainTextEdit->textCursor());
62 62
63 cursor.movePosition(QTextCursor::Start);63 cursor.movePosition(QTextCursor::Start);
64 64
@@ -67,10 +67,10 @@ ChatWindow::ChatWindow(QWidget* parent) : · 2 unmodified lines
67 67
68 cursor.setBlockFormat(format);68 cursor.setBlockFormat(format);
69 69
70 ui->messagePlainTextEdit->setTextCursor(cursor);70 _ui->messagePlainTextEdit->setTextCursor(cursor);
71 71
72 if (!AccountManager::getInstance().isLoggedIn()) {72 if (!AccountManager::getInstance().isLoggedIn()) {
73 ui->connectingToXMPPLabel->setText(tr("You must be logged in to chat with others."));73 _ui->connectingToXMPPLabel->setText(tr("You must be logged in to chat with others."));
74 }74 }
75 75
76#ifdef HAVE_QXMPP76#ifdef HAVE_QXMPP
@@ -79,13 +79,13 @@ ChatWindow::ChatWindow(QWidget* parent) : · 2 unmodified lines
79 participantsChanged();79 participantsChanged();
80 const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();80 const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
81 connect(publicChatRoom, SIGNAL(participantsChanged()), this, SLOT(participantsChanged()));81 connect(publicChatRoom, SIGNAL(participantsChanged()), this, SLOT(participantsChanged()));
82 ui->connectingToXMPPLabel->hide();82 _ui->connectingToXMPPLabel->hide();
83 startTimerForTimeStamps();83 startTimerForTimeStamps();
84 } else {84 } else {
85 ui->numOnlineLabel->hide();85 _ui->numOnlineLabel->hide();
86 ui->usersArea->hide();86 _ui->usersArea->hide();
87 ui->messagesScrollArea->hide();87 _ui->messagesScrollArea->hide();
88 ui->messagePlainTextEdit->hide();88 _ui->messagePlainTextEdit->hide();
89 connect(&XmppClient::getInstance(), SIGNAL(joinedPublicChatRoom()), this, SLOT(connected()));89 connect(&XmppClient::getInstance(), SIGNAL(joinedPublicChatRoom()), this, SLOT(connected()));
90 }90 }
91 connect(&xmppClient, SIGNAL(messageReceived(QXmppMessage)), this, SLOT(messageReceived(QXmppMessage)));91 connect(&xmppClient, SIGNAL(messageReceived(QXmppMessage)), this, SLOT(messageReceived(QXmppMessage)));
@@ -106,7 +106,7 @@ ChatWindow::~ChatWindow() { · 14 unmodified lines
106 const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();106 const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
107 disconnect(publicChatRoom, SIGNAL(participantsChanged()), this, SLOT(participantsChanged()));107 disconnect(publicChatRoom, SIGNAL(participantsChanged()), this, SLOT(participantsChanged()));
108#endif // HAVE_QXMPP108#endif // HAVE_QXMPP
109 delete ui;109 delete _ui;
110}110}
111 111
112void ChatWindow::keyPressEvent(QKeyEvent* event) {112void ChatWindow::keyPressEvent(QKeyEvent* event) {
@@ -122,7 +122,7 @@ void ChatWindow::showEvent(QShowEvent* event) { · 9 unmodified lines
122 QWidget::showEvent(event);122 QWidget::showEvent(event);
123 123
124 if (!event->spontaneous()) {124 if (!event->spontaneous()) {
125 ui->messagePlainTextEdit->setFocus();125 _ui->messagePlainTextEdit->setFocus();
126 }126 }
127 const QRect parentGeometry = parentWidget()->geometry();127 const QRect parentGeometry = parentWidget()->geometry();
128 int titleBarHeight = UIUtil::getWindowTitleBarHeight(this);128 int titleBarHeight = UIUtil::getWindowTitleBarHeight(this);
@@ -145,14 +145,14 @@ void ChatWindow::showEvent(QShowEvent* event) { · 16 unmodified lines
145}145}
146 146
147bool ChatWindow::eventFilter(QObject* sender, QEvent* event) {147bool ChatWindow::eventFilter(QObject* sender, QEvent* event) {
148 if (sender == ui->messagePlainTextEdit) {148 if (sender == _ui->messagePlainTextEdit) {
149 if (event->type() != QEvent::KeyPress) {149 if (event->type() != QEvent::KeyPress) {
150 return false;150 return false;
151 }151 }
152 QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);152 QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
153 if ((keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) &&153 if ((keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) &&
154 (keyEvent->modifiers() & Qt::ShiftModifier) == 0) {154 (keyEvent->modifiers() & Qt::ShiftModifier) == 0) {
155 QString messageText = ui->messagePlainTextEdit->document()->toPlainText().trimmed();155 QString messageText = _ui->messagePlainTextEdit->document()->toPlainText().trimmed();
156 if (!messageText.isEmpty()) {156 if (!messageText.isEmpty()) {
157#ifdef HAVE_QXMPP157#ifdef HAVE_QXMPP
158 const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();158 const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
@@ -162,7 +162,7 @@ bool ChatWindow::eventFilter(QObject* sender, QEvent* event) { · 3 unmodified lines
162 message.setBody(messageText);162 message.setBody(messageText);
163 XmppClient::getInstance().getXMPPClient().sendPacket(message);163 XmppClient::getInstance().getXMPPClient().sendPacket(message);
164#endif // HAVE_QXMPP164#endif // HAVE_QXMPP
165 QTextCursor cursor = ui->messagePlainTextEdit->textCursor();165 QTextCursor cursor = _ui->messagePlainTextEdit->textCursor();
166 cursor.select(QTextCursor::Document);166 cursor.select(QTextCursor::Document);
167 cursor.removeSelectedText();167 cursor.removeSelectedText();
168 }168 }
@@ -179,7 +179,7 @@ bool ChatWindow::eventFilter(QObject* sender, QEvent* event) { · 10 unmodified lines
179}179}
180 180
181void ChatWindow::addTimeStamp() {181void ChatWindow::addTimeStamp() {
182 QTimeSpan timePassed = QDateTime::currentDateTime() - lastMessageStamp;182 QTimeSpan timePassed = QDateTime::currentDateTime() - _lastMessageStamp;
183 int times[] = { timePassed.daysPart(), timePassed.hoursPart(), timePassed.minutesPart() };183 int times[] = { timePassed.daysPart(), timePassed.hoursPart(), timePassed.minutesPart() };
184 QString strings[] = { tr("%n day(s)", 0, times[0]), tr("%n hour(s)", 0, times[1]), tr("%n minute(s)", 0, times[2]) };184 QString strings[] = { tr("%n day(s)", 0, times[0]), tr("%n hour(s)", 0, times[1]), tr("%n minute(s)", 0, times[2]) };
185 QString timeString = "";185 QString timeString = "";
@@ -200,11 +200,11 @@ void ChatWindow::addTimeStamp() { · 14 unmodified lines
200 200
201 bool atBottom = isNearBottom();201 bool atBottom = isNearBottom();
202 202
203 ui->messagesVBoxLayout->addWidget(timeLabel);203 _ui->messagesVBoxLayout->addWidget(timeLabel);
204 ui->messagesVBoxLayout->parentWidget()->updateGeometry();204 _ui->messagesVBoxLayout->parentWidget()->updateGeometry();
205 205
206 Application::processEvents();206 Application::processEvents();
207 numMessagesAfterLastTimeStamp = 0;207 _numMessagesAfterLastTimeStamp = 0;
208 208
209 if (atBottom) {209 if (atBottom) {
210 scrollToBottom();210 scrollToBottom();
@@ -220,12 +220,12 @@ void ChatWindow::startTimerForTimeStamps() { · 9 unmodified lines
220}220}
221 221
222void ChatWindow::connected() {222void ChatWindow::connected() {
223 ui->connectingToXMPPLabel->hide();223 _ui->connectingToXMPPLabel->hide();
224 ui->numOnlineLabel->show();224 _ui->numOnlineLabel->show();
225 ui->usersArea->show();225 _ui->usersArea->show();
226 ui->messagesScrollArea->show();226 _ui->messagesScrollArea->show();
227 ui->messagePlainTextEdit->show();227 _ui->messagePlainTextEdit->show();
228 ui->messagePlainTextEdit->setFocus();228 _ui->messagePlainTextEdit->setFocus();
229#ifdef HAVE_QXMPP229#ifdef HAVE_QXMPP
230 const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();230 const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
231 connect(publicChatRoom, SIGNAL(participantsChanged()), this, SLOT(participantsChanged()));231 connect(publicChatRoom, SIGNAL(participantsChanged()), this, SLOT(participantsChanged()));
@@ -234,7 +234,7 @@ void ChatWindow::connected() { · 2 unmodified lines
234}234}
235 235
236void ChatWindow::timeout() {236void ChatWindow::timeout() {
237 if (numMessagesAfterLastTimeStamp >= NUM_MESSAGES_TO_TIME_STAMP) {237 if (_numMessagesAfterLastTimeStamp >= NUM_MESSAGES_TO_TIME_STAMP) {
238 addTimeStamp();238 addTimeStamp();
239 }239 }
240}240}
@@ -249,15 +249,15 @@ void ChatWindow::notificationClicked() { · 8 unmodified lines
249 }249 }
250 250
251 // find last mention251 // find last mention
252 int messageCount = ui->messagesVBoxLayout->count();252 int messageCount = _ui->messagesVBoxLayout->count();
253 for (unsigned int i = messageCount; i > 0; i--) {253 for (unsigned int i = messageCount; i > 0; i--) {
254 ChatMessageArea* area = (ChatMessageArea*)ui->messagesVBoxLayout->itemAt(i - 1)->widget();254 ChatMessageArea* area = (ChatMessageArea*)_ui->messagesVBoxLayout->itemAt(i - 1)->widget();
255 QRegularExpression usernameMention(mentionRegex.arg(AccountManager::getInstance().getAccountInfo().getUsername()));255 QRegularExpression usernameMention(mentionRegex.arg(AccountManager::getInstance().getAccountInfo().getUsername()));
256 if (area->toPlainText().contains(usernameMention)) {256 if (area->toPlainText().contains(usernameMention)) {
257 int top = area->geometry().top();257 int top = area->geometry().top();
258 int height = area->geometry().height();258 int height = area->geometry().height();
259 259
260 QScrollBar* verticalScrollBar = ui->messagesScrollArea->verticalScrollBar();260 QScrollBar* verticalScrollBar = _ui->messagesScrollArea->verticalScrollBar();
261 verticalScrollBar->setSliderPosition(top - verticalScrollBar->size().height() + height);261 verticalScrollBar->setSliderPosition(top - verticalScrollBar->size().height() + height);
262 return;262 return;
263 }263 }
@@ -273,16 +273,16 @@ QString ChatWindow::getParticipantName(const QString& participant) { · 9 unmodified lines
273}273}
274 274
275void ChatWindow::error(QXmppClient::Error error) {275void ChatWindow::error(QXmppClient::Error error) {
276 ui->connectingToXMPPLabel->setText(QString::number(error));276 _ui->connectingToXMPPLabel->setText(QString::number(error));
277}277}
278 278
279void ChatWindow::participantsChanged() {279void ChatWindow::participantsChanged() {
280 bool atBottom = isNearBottom();280 bool atBottom = isNearBottom();
281 281
282 QStringList participants = XmppClient::getInstance().getPublicChatRoom()->participants();282 QStringList participants = XmppClient::getInstance().getPublicChatRoom()->participants();
283 ui->numOnlineLabel->setText(tr("%1 online now:").arg(participants.count()));283 _ui->numOnlineLabel->setText(tr("%1 online now:").arg(participants.count()));
284 284
285 while (QLayoutItem* item = ui->usersWidget->layout()->takeAt(0)) {285 while (QLayoutItem* item = _ui->usersWidget->layout()->takeAt(0)) {
286 delete item->widget();286 delete item->widget();
287 delete item;287 delete item;
288 }288 }
@@ -303,7 +303,7 @@ void ChatWindow::participantsChanged() { · 14 unmodified lines
303 userLabel->setProperty("user", participantName);303 userLabel->setProperty("user", participantName);
304 userLabel->setCursor(Qt::PointingHandCursor);304 userLabel->setCursor(Qt::PointingHandCursor);
305 userLabel->installEventFilter(this);305 userLabel->installEventFilter(this);
306 ui->usersWidget->layout()->addWidget(userLabel);306 _ui->usersWidget->layout()->addWidget(userLabel);
307 }307 }
308 Application::processEvents();308 Application::processEvents();
309 309
@@ -355,19 +355,19 @@ void ChatWindow::messageReceived(const QXmppMessage& message) { · 45 unmodified lines
355 355
356 bool atBottom = isNearBottom();356 bool atBottom = isNearBottom();
357 357
358 ui->messagesVBoxLayout->addWidget(messageArea);358 _ui->messagesVBoxLayout->addWidget(messageArea);
359 ui->messagesVBoxLayout->parentWidget()->updateGeometry();359 _ui->messagesVBoxLayout->parentWidget()->updateGeometry();
360 Application::processEvents();360 Application::processEvents();
361 361
362 if (atBottom || fromSelf) {362 if (atBottom || fromSelf) {
363 scrollToBottom();363 scrollToBottom();
364 }364 }
365 365
366 ++numMessagesAfterLastTimeStamp;366 ++_numMessagesAfterLastTimeStamp;
367 if (message.stamp().isValid()) {367 if (message.stamp().isValid()) {
368 lastMessageStamp = message.stamp().toLocalTime();368 _lastMessageStamp = message.stamp().toLocalTime();
369 } else {369 } else {
370 lastMessageStamp = QDateTime::currentDateTime();370 _lastMessageStamp = QDateTime::currentDateTime();
371 }371 }
372 372
373 QRegularExpression usernameMention(mentionRegex.arg(AccountManager::getInstance().getAccountInfo().getUsername()));373 QRegularExpression usernameMention(mentionRegex.arg(AccountManager::getInstance().getAccountInfo().getUsername()));
@@ -388,19 +388,19 @@ void ChatWindow::messageReceived(const QXmppMessage& message) { · 14 unmodified lines
388#endif // HAVE_QXMPP388#endif // HAVE_QXMPP
389 389
390bool ChatWindow::isNearBottom() {390bool ChatWindow::isNearBottom() {
391 QScrollBar* verticalScrollBar = ui->messagesScrollArea->verticalScrollBar();391 QScrollBar* verticalScrollBar = _ui->messagesScrollArea->verticalScrollBar();
392 return verticalScrollBar->value() >= verticalScrollBar->maximum() - Ui::AUTO_SCROLL_THRESHOLD;392 return verticalScrollBar->value() >= verticalScrollBar->maximum() - Ui::AUTO_SCROLL_THRESHOLD;
393}393}
394 394
395// Scroll chat message area to bottom.395// Scroll chat message area to bottom.
396void ChatWindow::scrollToBottom() {396void ChatWindow::scrollToBottom() {
397 QScrollBar* verticalScrollBar = ui->messagesScrollArea->verticalScrollBar();397 QScrollBar* verticalScrollBar = _ui->messagesScrollArea->verticalScrollBar();
398 verticalScrollBar->setValue(verticalScrollBar->maximum());398 verticalScrollBar->setValue(verticalScrollBar->maximum());
399}399}
400 400
401bool ChatWindow::event(QEvent* event) {401bool ChatWindow::event(QEvent* event) {
402 if (event->type() == QEvent::WindowActivate) {402 if (event->type() == QEvent::WindowActivate) {
403 ui->messagePlainTextEdit->setFocus();403 _ui->messagePlainTextEdit->setFocus();
404 }404 }
405 return QWidget::event(event);405 return QWidget::event(event);
406}406}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t