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
4141 ChatWindow::ChatWindow(QWidget* parent) :
4242 QWidget(parent, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint |
4343 Qt::WindowCloseButtonHint),
44− ui(new Ui::ChatWindow),
45− numMessagesAfterLastTimeStamp(0),
44+ _ui(new Ui::ChatWindow),
45+ _numMessagesAfterLastTimeStamp(0),
4646 _mousePressed(false),
4747 _mouseStartPosition(),
4848 _trayIcon(parent),
@@ -50,15 +50,15 @@ ChatWindow::ChatWindow(QWidget* parent) : · 1 unmodified line
5050 {
5151 setAttribute(Qt::WA_DeleteOnClose, false);
5252
53− ui->setupUi(this);
53+ _ui->setupUi(this);
5454
5555 FlowLayout* flowLayout = new FlowLayout(0, 4, 4);
56− ui->usersWidget->setLayout(flowLayout);
56+ _ui->usersWidget->setLayout(flowLayout);
5757
58− ui->messagePlainTextEdit->installEventFilter(this);
59− ui->messagePlainTextEdit->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
58+ _ui->messagePlainTextEdit->installEventFilter(this);
59+ _ui->messagePlainTextEdit->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
6060
61− QTextCursor cursor(ui->messagePlainTextEdit->textCursor());
61+ QTextCursor cursor(_ui->messagePlainTextEdit->textCursor());
6262
6363 cursor.movePosition(QTextCursor::Start);
6464
@@ -67,10 +67,10 @@ ChatWindow::ChatWindow(QWidget* parent) : · 2 unmodified lines
6767
6868 cursor.setBlockFormat(format);
6969
70− ui->messagePlainTextEdit->setTextCursor(cursor);
70+ _ui->messagePlainTextEdit->setTextCursor(cursor);
7171
7272 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."));
7474 }
7575
7676 #ifdef HAVE_QXMPP
@@ -79,13 +79,13 @@ ChatWindow::ChatWindow(QWidget* parent) : · 2 unmodified lines
7979 participantsChanged();
8080 const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
8181 connect(publicChatRoom, SIGNAL(participantsChanged()), this, SLOT(participantsChanged()));
82− ui->connectingToXMPPLabel->hide();
82+ _ui->connectingToXMPPLabel->hide();
8383 startTimerForTimeStamps();
8484 } 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();
8989 connect(&XmppClient::getInstance(), SIGNAL(joinedPublicChatRoom()), this, SLOT(connected()));
9090 }
9191 connect(&xmppClient, SIGNAL(messageReceived(QXmppMessage)), this, SLOT(messageReceived(QXmppMessage)));
@@ -106,7 +106,7 @@ ChatWindow::~ChatWindow() { · 14 unmodified lines
106106 const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
107107 disconnect(publicChatRoom, SIGNAL(participantsChanged()), this, SLOT(participantsChanged()));
108108 #endif // HAVE_QXMPP
109− delete ui;
109+ delete _ui;
110110 }
111111
112112 void ChatWindow::keyPressEvent(QKeyEvent* event) {
@@ -122,7 +122,7 @@ void ChatWindow::showEvent(QShowEvent* event) { · 9 unmodified lines
122122 QWidget::showEvent(event);
123123
124124 if (!event->spontaneous()) {
125− ui->messagePlainTextEdit->setFocus();
125+ _ui->messagePlainTextEdit->setFocus();
126126 }
127127 const QRect parentGeometry = parentWidget()->geometry();
128128 int titleBarHeight = UIUtil::getWindowTitleBarHeight(this);
@@ -145,14 +145,14 @@ void ChatWindow::showEvent(QShowEvent* event) { · 16 unmodified lines
145145 }
146146
147147 bool ChatWindow::eventFilter(QObject* sender, QEvent* event) {
148− if (sender == ui->messagePlainTextEdit) {
148+ if (sender == _ui->messagePlainTextEdit) {
149149 if (event->type() != QEvent::KeyPress) {
150150 return false;
151151 }
152152 QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
153153 if ((keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) &&
154154 (keyEvent->modifiers() & Qt::ShiftModifier) == 0) {
155− QString messageText = ui->messagePlainTextEdit->document()->toPlainText().trimmed();
155+ QString messageText = _ui->messagePlainTextEdit->document()->toPlainText().trimmed();
156156 if (!messageText.isEmpty()) {
157157 #ifdef HAVE_QXMPP
158158 const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
@@ -162,7 +162,7 @@ bool ChatWindow::eventFilter(QObject* sender, QEvent* event) { · 3 unmodified lines
162162 message.setBody(messageText);
163163 XmppClient::getInstance().getXMPPClient().sendPacket(message);
164164 #endif // HAVE_QXMPP
165− QTextCursor cursor = ui->messagePlainTextEdit->textCursor();
165+ QTextCursor cursor = _ui->messagePlainTextEdit->textCursor();
166166 cursor.select(QTextCursor::Document);
167167 cursor.removeSelectedText();
168168 }
@@ -179,7 +179,7 @@ bool ChatWindow::eventFilter(QObject* sender, QEvent* event) { · 10 unmodified lines
179179 }
180180
181181 void ChatWindow::addTimeStamp() {
182− QTimeSpan timePassed = QDateTime::currentDateTime() - lastMessageStamp;
182+ QTimeSpan timePassed = QDateTime::currentDateTime() - _lastMessageStamp;
183183 int times[] = { timePassed.daysPart(), timePassed.hoursPart(), timePassed.minutesPart() };
184184 QString strings[] = { tr("%n day(s)", 0, times[0]), tr("%n hour(s)", 0, times[1]), tr("%n minute(s)", 0, times[2]) };
185185 QString timeString = "";
@@ -200,11 +200,11 @@ void ChatWindow::addTimeStamp() { · 14 unmodified lines
200200
201201 bool atBottom = isNearBottom();
202202
203− ui->messagesVBoxLayout->addWidget(timeLabel);
204− ui->messagesVBoxLayout->parentWidget()->updateGeometry();
203+ _ui->messagesVBoxLayout->addWidget(timeLabel);
204+ _ui->messagesVBoxLayout->parentWidget()->updateGeometry();
205205
206206 Application::processEvents();
207− numMessagesAfterLastTimeStamp = 0;
207+ _numMessagesAfterLastTimeStamp = 0;
208208
209209 if (atBottom) {
210210 scrollToBottom();
@@ -220,12 +220,12 @@ void ChatWindow::startTimerForTimeStamps() { · 9 unmodified lines
220220 }
221221
222222 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();
229229 #ifdef HAVE_QXMPP
230230 const QXmppMucRoom* publicChatRoom = XmppClient::getInstance().getPublicChatRoom();
231231 connect(publicChatRoom, SIGNAL(participantsChanged()), this, SLOT(participantsChanged()));
@@ -234,7 +234,7 @@ void ChatWindow::connected() { · 2 unmodified lines
234234 }
235235
236236 void ChatWindow::timeout() {
237− if (numMessagesAfterLastTimeStamp >= NUM_MESSAGES_TO_TIME_STAMP) {
237+ if (_numMessagesAfterLastTimeStamp >= NUM_MESSAGES_TO_TIME_STAMP) {
238238 addTimeStamp();
239239 }
240240 }
@@ -249,15 +249,15 @@ void ChatWindow::notificationClicked() { · 8 unmodified lines
249249 }
250250
251251 // find last mention
252− int messageCount = ui->messagesVBoxLayout->count();
252+ int messageCount = _ui->messagesVBoxLayout->count();
253253 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();
255255 QRegularExpression usernameMention(mentionRegex.arg(AccountManager::getInstance().getAccountInfo().getUsername()));
256256 if (area->toPlainText().contains(usernameMention)) {
257257 int top = area->geometry().top();
258258 int height = area->geometry().height();
259259
260− QScrollBar* verticalScrollBar = ui->messagesScrollArea->verticalScrollBar();
260+ QScrollBar* verticalScrollBar = _ui->messagesScrollArea->verticalScrollBar();
261261 verticalScrollBar->setSliderPosition(top - verticalScrollBar->size().height() + height);
262262 return;
263263 }
@@ -273,16 +273,16 @@ QString ChatWindow::getParticipantName(const QString& participant) { · 9 unmodified lines
273273 }
274274
275275 void ChatWindow::error(QXmppClient::Error error) {
276− ui->connectingToXMPPLabel->setText(QString::number(error));
276+ _ui->connectingToXMPPLabel->setText(QString::number(error));
277277 }
278278
279279 void ChatWindow::participantsChanged() {
280280 bool atBottom = isNearBottom();
281281
282282 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()));
284284
285− while (QLayoutItem* item = ui->usersWidget->layout()->takeAt(0)) {
285+ while (QLayoutItem* item = _ui->usersWidget->layout()->takeAt(0)) {
286286 delete item->widget();
287287 delete item;
288288 }
@@ -303,7 +303,7 @@ void ChatWindow::participantsChanged() { · 14 unmodified lines
303303 userLabel->setProperty("user", participantName);
304304 userLabel->setCursor(Qt::PointingHandCursor);
305305 userLabel->installEventFilter(this);
306− ui->usersWidget->layout()->addWidget(userLabel);
306+ _ui->usersWidget->layout()->addWidget(userLabel);
307307 }
308308 Application::processEvents();
309309
@@ -355,19 +355,19 @@ void ChatWindow::messageReceived(const QXmppMessage& message) { · 45 unmodified lines
355355
356356 bool atBottom = isNearBottom();
357357
358− ui->messagesVBoxLayout->addWidget(messageArea);
359− ui->messagesVBoxLayout->parentWidget()->updateGeometry();
358+ _ui->messagesVBoxLayout->addWidget(messageArea);
359+ _ui->messagesVBoxLayout->parentWidget()->updateGeometry();
360360 Application::processEvents();
361361
362362 if (atBottom || fromSelf) {
363363 scrollToBottom();
364364 }
365365
366− ++numMessagesAfterLastTimeStamp;
366+ ++_numMessagesAfterLastTimeStamp;
367367 if (message.stamp().isValid()) {
368− lastMessageStamp = message.stamp().toLocalTime();
368+ _lastMessageStamp = message.stamp().toLocalTime();
369369 } else {
370− lastMessageStamp = QDateTime::currentDateTime();
370+ _lastMessageStamp = QDateTime::currentDateTime();
371371 }
372372
373373 QRegularExpression usernameMention(mentionRegex.arg(AccountManager::getInstance().getAccountInfo().getUsername()));
@@ -388,19 +388,19 @@ void ChatWindow::messageReceived(const QXmppMessage& message) { · 14 unmodified lines
388388 #endif // HAVE_QXMPP
389389
390390 bool ChatWindow::isNearBottom() {
391− QScrollBar* verticalScrollBar = ui->messagesScrollArea->verticalScrollBar();
391+ QScrollBar* verticalScrollBar = _ui->messagesScrollArea->verticalScrollBar();
392392 return verticalScrollBar->value() >= verticalScrollBar->maximum() - Ui::AUTO_SCROLL_THRESHOLD;
393393 }
394394
395395 // Scroll chat message area to bottom.
396396 void ChatWindow::scrollToBottom() {
397− QScrollBar* verticalScrollBar = ui->messagesScrollArea->verticalScrollBar();
397+ QScrollBar* verticalScrollBar = _ui->messagesScrollArea->verticalScrollBar();
398398 verticalScrollBar->setValue(verticalScrollBar->maximum());
399399 }
400400
401401 bool ChatWindow::event(QEvent* event) {
402402 if (event->type() == QEvent::WindowActivate) {
403− ui->messagePlainTextEdit->setFocus();
403+ _ui->messagePlainTextEdit->setFocus();
404404 }
405405 return QWidget::event(event);
406406 }

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