diff options
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/QtUI/ChatSnippet.h | 1 | ||||
-rw-r--r-- | Swift/QtUI/MessageSnippet.cpp | 4 | ||||
-rw-r--r-- | Swift/QtUI/QtChatView.cpp | 44 | ||||
-rw-r--r-- | Swift/QtUI/QtChatView.h | 3 | ||||
-rw-r--r-- | Swift/QtUI/QtChatWindow.cpp | 6 | ||||
-rw-r--r-- | Swift/QtUI/SystemMessageSnippet.cpp | 4 |
6 files changed, 25 insertions, 37 deletions
diff --git a/Swift/QtUI/ChatSnippet.h b/Swift/QtUI/ChatSnippet.h index 9345f61..69ca5b8 100644 --- a/Swift/QtUI/ChatSnippet.h +++ b/Swift/QtUI/ChatSnippet.h @@ -22,7 +22,6 @@ namespace Swift { return appendToPrevious_; } - protected: static QString escape(const QString&); private: diff --git a/Swift/QtUI/MessageSnippet.cpp b/Swift/QtUI/MessageSnippet.cpp index ebcc829..0159386 100644 --- a/Swift/QtUI/MessageSnippet.cpp +++ b/Swift/QtUI/MessageSnippet.cpp @@ -29,9 +29,9 @@ MessageSnippet::MessageSnippet(const QString& message, const QString& sender, co } } - content_.replace("%message%", escape(message)); + content_.replace("%message%", "<span class='swift_message'>" + escape(message) + "</span>"); content_.replace("%sender%", escape(sender)); - content_.replace("%time%", escape(time.toString("h:mm"))); + content_.replace("%time%", "<span class='swift_time'>" + escape(time.toString("h:mm")) + "</span>"); content_.replace("%userIconPath%", escape(iconURI)); } diff --git a/Swift/QtUI/QtChatView.cpp b/Swift/QtUI/QtChatView.cpp index 1c4ed18..52b399b 100644 --- a/Swift/QtUI/QtChatView.cpp +++ b/Swift/QtUI/QtChatView.cpp @@ -63,11 +63,9 @@ QtChatView::QtChatView(QtChatTheme* theme, QWidget* parent) : QWidget(parent) { document_ = webPage_->mainFrame()->documentElement(); QWebElement chatElement = document_.findFirst("#Chat"); newInsertPoint_ = chatElement.clone(); - newInsertPoint_.setOuterXml("<div id='insert'/>"); + newInsertPoint_.setOuterXml("<div id='swift_insert'/>"); chatElement.appendInside(newInsertPoint_); - if (newInsertPoint_.isNull()) { - qWarning() << "Warning, initial insert point element is null!"; - } + Q_ASSERT(!newInsertPoint_.isNull()); } void QtChatView::handleKeyPressEvent(QKeyEvent* event) { @@ -80,35 +78,12 @@ void QtChatView::addMessage(boost::shared_ptr<ChatSnippet> snippet) { } else { queuedSnippets_.append(snippet); } -// QString content = snippet.getContent(); -// content.replace("\\", "\\\\"); -// content.replace("\"", "\\\""); -// content.replace("\n", "\\n"); -// content.replace("\r", ""); -// QString command; -// if (previousContinuationElementID_.isEmpty() || !snippet.getAppendToPrevious()) { -// command = "appendMessage(\"" + content + "\");"; -// } -// else { -// command = "appendNextMessage(\"" + content + "\");"; -// } -// if (viewReady_) { -// webPage_->mainFrame()->evaluateJavaScript(command); -// } -// else { -// queuedMessages_ += command; -// } -// -// previousContinuationElementID_ = snippet.getContinuationElementID(); - } QWebElement QtChatView::snippetToDOM(boost::shared_ptr<ChatSnippet> snippet) { QWebElement newElement = newInsertPoint_.clone(); newElement.setInnerXml(snippet->getContent()); /* FIXME: Outer, surely? */ - if (newElement.isNull()) { - qWarning() << "Warning, new element is null!"; - } + Q_ASSERT(!newElement.isNull()); return newElement; } @@ -116,6 +91,7 @@ void QtChatView::addToDOM(boost::shared_ptr<ChatSnippet> snippet) { QWebElement newElement = snippetToDOM(snippet); QWebElement continuationElement = lastElement_.findFirst("#insert"); if (snippet->getAppendToPrevious()) { + Q_ASSERT(!continuationElement.isNull()); continuationElement.replace(newElement); } else { continuationElement.removeFromDocument(); @@ -124,6 +100,18 @@ void QtChatView::addToDOM(boost::shared_ptr<ChatSnippet> snippet) { lastElement_ = newElement; } +void QtChatView::correctLastMessage(const QString& newMessage) { + /* FIXME: must be queued */ + lastElement_.findFirst("swift_message"); + lastElement_.setPlainText(ChatSnippet::escape(newMessage)); +} + +void QtChatView::correctLastMessage(const QString& newMessage, const QString& note) { + correctLastMessage(newMessage); + lastElement_.findFirst("swift_time"); + lastElement_.setPlainText(ChatSnippet::escape(note)); +} + void QtChatView::copySelectionToClipboard() { if (!webPage_->selectedText().isEmpty()) { webPage_->triggerAction(QWebPage::Copy); diff --git a/Swift/QtUI/QtChatView.h b/Swift/QtUI/QtChatView.h index 3936c18..01c1ad7 100644 --- a/Swift/QtUI/QtChatView.h +++ b/Swift/QtUI/QtChatView.h @@ -28,6 +28,8 @@ namespace Swift { QtChatView(QtChatTheme* theme, QWidget* parent); void addMessage(boost::shared_ptr<ChatSnippet> snippet); + void correctLastMessage(const QString& newMessage); + void correctLastMessage(const QString& newMessage, const QString& note); bool isScrolledToBottom() const; signals: @@ -52,7 +54,6 @@ namespace Swift { bool viewReady_; QtWebView* webView_; QWebPage* webPage_; - QString previousContinuationElementID_; QList<boost::shared_ptr<ChatSnippet> > queuedSnippets_; QtChatTheme* theme_; diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp index 73bf2c2..53b0dde 100644 --- a/Swift/QtUI/QtChatWindow.cpp +++ b/Swift/QtUI/QtChatWindow.cpp @@ -291,7 +291,7 @@ void QtChatWindow::addErrorMessage(const String& errorMessage) { QString errorMessageHTML(Qt::escape(P2QSTRING(errorMessage))); errorMessageHTML.replace("\n","<br/>"); - messageLog_->addMessage(boost::shared_ptr<ChatSnippet>(new SystemMessageSnippet(QString("<span class=\"error\">%1</span>").arg(errorMessageHTML), QDateTime::currentDateTime(),previousMessageWasSystem_, theme_))); + messageLog_->addMessage(boost::shared_ptr<ChatSnippet>(new SystemMessageSnippet(QString("<span class=\"error\">%1</span>").arg(errorMessageHTML), QDateTime::currentDateTime(), false, theme_))); previousMessageWasSelf_ = false; previousMessageWasSystem_ = true; @@ -305,7 +305,7 @@ void QtChatWindow::addSystemMessage(const String& message) { QString messageHTML(Qt::escape(P2QSTRING(message))); messageHTML.replace("\n","<br/>"); - messageLog_->addMessage(boost::shared_ptr<ChatSnippet>(new SystemMessageSnippet(messageHTML, QDateTime::currentDateTime(),previousMessageWasSystem_, theme_))); + messageLog_->addMessage(boost::shared_ptr<ChatSnippet>(new SystemMessageSnippet(messageHTML, QDateTime::currentDateTime(), false, theme_))); previousMessageWasSelf_ = false; previousMessageWasSystem_ = true; @@ -319,7 +319,7 @@ void QtChatWindow::addPresenceMessage(const String& message) { QString messageHTML(Qt::escape(P2QSTRING(message))); messageHTML.replace("\n","<br/>"); - messageLog_->addMessage(boost::shared_ptr<ChatSnippet>(new SystemMessageSnippet(messageHTML, QDateTime::currentDateTime(), previousMessageWasPresence_, theme_))); + messageLog_->addMessage(boost::shared_ptr<ChatSnippet>(new SystemMessageSnippet(messageHTML, QDateTime::currentDateTime(), false, theme_))); previousMessageWasSelf_ = false; previousMessageWasSystem_ = false; diff --git a/Swift/QtUI/SystemMessageSnippet.cpp b/Swift/QtUI/SystemMessageSnippet.cpp index db57b1f..cf70c2e 100644 --- a/Swift/QtUI/SystemMessageSnippet.cpp +++ b/Swift/QtUI/SystemMessageSnippet.cpp @@ -13,9 +13,9 @@ namespace Swift { SystemMessageSnippet::SystemMessageSnippet(const QString& message, const QDateTime& time, bool appendToPrevious, QtChatTheme* theme) : ChatSnippet(appendToPrevious) { content_ = theme->getStatus(); - content_.replace("%message%", escape(message)); + content_.replace("%message%", "<span class='swift_message'>" + escape(message) + "</span>"); content_.replace("%shortTime%", escape(time.toString("h:mm"))); - content_.replace("%time%", escape(time.toString("h:mm"))); + content_.replace("%time%", "<span class='swift_time'>" + escape(time.toString("h:mm")) + "</span>"); } SystemMessageSnippet::~SystemMessageSnippet() { |