History

Merge branch 'master' of https://github.com/worklist/hifi into 19597

Stojce Slavkovski committed 12 years ago

Commit 91d7bd22 parents 8f28789 3ab61f241 files · +907 −733Browse files

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

Unified · Split

interface/src/ui/ChatWindow.cpp+61−79
@@ -12,12 +12,10 @@ · 11 unmodified lines
1212 #include <QGridLayout>
1313 #include <QFrame>
1414 #include <QLayoutItem>
15−#include <QMainWindow>
1615 #include <QPalette>
1716 #include <QScrollBar>
1817 #include <QSizePolicy>
1918 #include <QTimer>
20−#include <QWidget>
2119
2220 #include "Application.h"
2321 #include "FlowLayout.h"
@@ -31,32 +29,40 @@ · 7 unmodified lines
3129 const int NUM_MESSAGES_TO_TIME_STAMP = 20;
3230
3331 const QRegularExpression regexLinks("((?:(?:ftp)|(?:https?))://\\S+)");
32+const QRegularExpression regexHifiLinks("([#@]\\S+)");
3433
35−ChatWindow::ChatWindow() :
34+ChatWindow::ChatWindow(QWidget* parent) :
35+ FramelessDialog(parent, 0, POSITION_RIGHT),
3636 ui(new Ui::ChatWindow),
3737 numMessagesAfterLastTimeStamp(0),
3838 _mousePressed(false),
3939 _mouseStartPosition()
4040 {
41− ui->setupUi(this);
41+ setAttribute(Qt::WA_DeleteOnClose, false);
4242
43− // remove the title bar (see the Qt docs on setTitleBarWidget), but we keep it for undocking
44− //
45− titleBar = titleBarWidget();
46− setTitleBarWidget(new QWidget());
43+ ui->setupUi(this);
4744
4845 FlowLayout* flowLayout = new FlowLayout(0, 4, 4);
4946 ui->usersWidget->setLayout(flowLayout);
5047
51− ui->messagesGridLayout->setColumnStretch(0, 1);
52− ui->messagesGridLayout->setColumnStretch(1, 3);
53−
5448 ui->messagePlainTextEdit->installEventFilter(this);
49+ ui->messagePlainTextEdit->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
50+
51+ QTextCursor cursor(ui->messagePlainTextEdit->textCursor());
52+
53+ cursor.movePosition(QTextCursor::Start);
54+
55+ QTextBlockFormat format = cursor.blockFormat();
56+ format.setLineHeight(130, QTextBlockFormat::ProportionalHeight);
57+
58+ cursor.setBlockFormat(format);
59+
60+ ui->messagePlainTextEdit->setTextCursor(cursor);
5561
5662 if (!AccountManager::getInstance().isLoggedIn()) {
5763 ui->connectingToXMPPLabel->setText(tr("You must be logged in to chat with others."));
5864 }
59−
65+
6066 #ifdef HAVE_QXMPP
6167 const QXmppClient& xmppClient = XmppClient::getInstance().getXMPPClient();
6268 if (xmppClient.isConnected()) {
@@ -90,36 +96,17 @@ ChatWindow::~ChatWindow() { · 27 unmodified lines
9096 delete ui;
9197 }
9298
93−void ChatWindow::mousePressEvent(QMouseEvent *e) {
94− if (e->button() == Qt::LeftButton && isFloating()) {
95− _mousePressed = true;
96− _mouseStartPosition = e->pos();
97− }
98−}
99−
100−void ChatWindow::mouseMoveEvent(QMouseEvent *e) {
101− if (_mousePressed) {
102− move(mapToParent(e->pos() - _mouseStartPosition));
103− }
104−}
105−
106−void ChatWindow::mouseReleaseEvent( QMouseEvent *e ) {
107− if ( e->button() == Qt::LeftButton ) {
108− _mousePressed = false;
109− }
110−}
111−
11299 void ChatWindow::keyPressEvent(QKeyEvent* event) {
113− QDockWidget::keyPressEvent(event);
114100 if (event->key() == Qt::Key_Escape) {
115101 hide();
102+ } else {
103+ FramelessDialog::keyPressEvent(event);
116104 }
117105 }
118106
119107 void ChatWindow::showEvent(QShowEvent* event) {
120− QDockWidget::showEvent(event);
108+ FramelessDialog::showEvent(event);
121109 if (!event->spontaneous()) {
122− activateWindow();
123110 ui->messagePlainTextEdit->setFocus();
124111 }
125112 }
@@ -142,18 +129,20 @@ bool ChatWindow::eventFilter(QObject* sender, QEvent* event) { · 16 unmodified lines
142129 message.setBody(messageText);
143130 XmppClient::getInstance().getXMPPClient().sendPacket(message);
144131 #endif
145− ui->messagePlainTextEdit->document()->clear();
132+ QTextCursor cursor = ui->messagePlainTextEdit->textCursor();
133+ cursor.select(QTextCursor::Document);
134+ cursor.removeSelectedText();
146135 }
147136 return true;
148137 }
149− } else {
150− if (event->type() != QEvent::MouseButtonRelease) {
151− return false;
138+ } else if (event->type() == QEvent::MouseButtonRelease) {
139+ QVariant userVar = sender->property("user");
140+ if (userVar.isValid()) {
141+ Menu::getInstance()->goToUser("@" + userVar.toString());
142+ return true;
152143 }
153− QString user = sender->property("user").toString();
154− Menu::getInstance()->goToUser(user);
155144 }
156− return false;
145+ return FramelessDialog::eventFilter(sender, event);
157146 }
158147
159148 #ifdef HAVE_QXMPP
@@ -176,16 +165,17 @@ void ChatWindow::addTimeStamp() { · 16 unmodified lines
176165 timeString.chop(1);
177166 if (!timeString.isEmpty()) {
178167 QLabel* timeLabel = new QLabel(timeString);
179− timeLabel->setStyleSheet("color: palette(shadow);"
180− "background-color: palette(highlight);"
168+ timeLabel->setStyleSheet("color: #333333;"
169+ "background-color: white;"
170+ "font-size: 14pt;"
181171 "padding: 4px;");
182172 timeLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
183− timeLabel->setAlignment(Qt::AlignHCenter);
173+ timeLabel->setAlignment(Qt::AlignLeft);
184174
185− bool atBottom = isAtBottom();
175+ bool atBottom = isNearBottom();
186176
187− ui->messagesGridLayout->addWidget(timeLabel, ui->messagesGridLayout->rowCount(), 0, 1, 2);
188− ui->messagesGridLayout->parentWidget()->updateGeometry();
177+ ui->messagesVBoxLayout->addWidget(timeLabel);
178+ ui->messagesVBoxLayout->parentWidget()->updateGeometry();
189179
190180 Application::processEvents();
191181 numMessagesAfterLastTimeStamp = 0;
@@ -262,6 +252,7 @@ void ChatWindow::participantsChanged() { · 70 unmodified lines
262252 "padding-bottom: 2px;"
263253 "padding-left: 2px;"
264254 "border: 1px solid palette(shadow);"
255+ "font-size: 14pt;"
265256 "font-weight: bold");
266257 userLabel->setProperty("user", participantName);
267258 userLabel->setCursor(Qt::PointingHandCursor);
@@ -275,15 +266,11 @@ void ChatWindow::messageReceived(const QXmppMessage& message) { · 7 unmodified lines
275266 return;
276267 }
277268
278− QLabel* userLabel = new QLabel(getParticipantName(message.from()));
279− userLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
280− userLabel->setStyleSheet("padding: 2px; font-weight: bold");
281− userLabel->setAlignment(Qt::AlignTop | Qt::AlignRight);
282−
283− ChatMessageArea* messageArea = new ChatMessageArea();
269+ // Update background if this is a message from the current user
270+ bool fromSelf = getParticipantName(message.from()) == AccountManager::getInstance().getUsername();
284271
285− messageArea->setOpenLinks(true);
286− messageArea->setOpenExternalLinks(true);
272+ // Create message area
273+ ChatMessageArea* messageArea = new ChatMessageArea(true);
287274 messageArea->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
288275 messageArea->setTextInteractionFlags(Qt::TextBrowserInteraction);
289276 messageArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
@@ -294,22 +281,30 @@ void ChatWindow::messageReceived(const QXmppMessage& message) { · 4 unmodified lines
294281 "padding-left: 2px;"
295282 "padding-top: 2px;"
296283 "padding-right: 20px;"
284+ "margin: 0px;"
285+ "color: #333333;"
286+ "font-size: 14pt;"
297287 "background-color: rgba(0, 0, 0, 0%);"
298288 "border: 0;");
299289
300− bool fromSelf = getParticipantName(message.from()) == AccountManager::getInstance().getUsername();
290+ QString userLabel = getParticipantName(message.from());
301291 if (fromSelf) {
302− userLabel->setStyleSheet(userLabel->styleSheet() + "; background-color: #e1e8ea");
303− messageArea->setStyleSheet(messageArea->styleSheet() + "; background-color: #e1e8ea");
292+ userLabel = "<b style=\"color: #4a6f91\">" + userLabel + ": </b>";
293+ messageArea->setStyleSheet(messageArea->styleSheet() + "background-color: #e1e8ea");
294+ } else {
295+ userLabel = "<b>" + userLabel + ": </b>";
304296 }
305297
306− messageArea->setHtml(message.body().replace(regexLinks, "<a href=\"\\1\">\\1</a>"));
298+ messageArea->document()->setDefaultStyleSheet("a { text-decoration: none; font-weight: bold; color: #267077;}");
299+ QString messageText = message.body().toHtmlEscaped();
300+ messageText = messageText.replace(regexLinks, "<a href=\"\\1\">\\1</a>");
301+ messageText = messageText.replace(regexHifiLinks, "<a href=\"hifi://\\1\">\\1</a>");
302+ messageArea->setHtml(userLabel + messageText);
307303
308− bool atBottom = isAtBottom();
309− ui->messagesGridLayout->addWidget(userLabel, ui->messagesGridLayout->rowCount(), 0);
310− ui->messagesGridLayout->addWidget(messageArea, ui->messagesGridLayout->rowCount() - 1, 1);
304+ bool atBottom = isNearBottom();
311305
312− ui->messagesGridLayout->parentWidget()->updateGeometry();
306+ ui->messagesVBoxLayout->addWidget(messageArea);
307+ ui->messagesVBoxLayout->parentWidget()->updateGeometry();
313308 Application::processEvents();
314309
315310 if (atBottom || fromSelf) {
@@ -326,26 +321,13 @@ void ChatWindow::messageReceived(const QXmppMessage& message) { · 10 unmodified lines
326321
327322 #endif
328323
329−bool ChatWindow::isAtBottom() {
324+bool ChatWindow::isNearBottom() {
330325 QScrollBar* verticalScrollBar = ui->messagesScrollArea->verticalScrollBar();
331− return verticalScrollBar->sliderPosition() == verticalScrollBar->maximum();
326+ return verticalScrollBar->value() >= verticalScrollBar->maximum() - Ui::AUTO_SCROLL_THRESHOLD;
332327 }
333328
334329 // Scroll chat message area to bottom.
335330 void ChatWindow::scrollToBottom() {
336331 QScrollBar* verticalScrollBar = ui->messagesScrollArea->verticalScrollBar();
337− verticalScrollBar->setSliderPosition(verticalScrollBar->maximum());
338−}
339−
340−void ChatWindow::togglePinned() {
341− QMainWindow* mainWindow = Application::getInstance()->getWindow();
342− mainWindow->removeDockWidget(this);
343− if (ui->togglePinnedButton->isChecked()) {
344− mainWindow->addDockWidget(ui->togglePinnedButton->isChecked() ? Qt::RightDockWidgetArea : Qt::NoDockWidgetArea, this);
345− }
346− if (!this->toggleViewAction()->isChecked()) {
347− this->toggleViewAction()->trigger();
348− }
349− this->setFloating(!ui->togglePinnedButton->isChecked());
350− setTitleBarWidget(ui->togglePinnedButton->isChecked()?new QWidget():titleBar);
332+ verticalScrollBar->setValue(verticalScrollBar->maximum());
351333 }

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