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