diff options
| author | Remko Tronçon <git@el-tramo.be> | 2010-09-05 12:59:02 (GMT) |
|---|---|---|
| committer | Remko Tronçon <git@el-tramo.be> | 2010-09-05 12:59:02 (GMT) |
| commit | 89f18c8af344fc94bb5cf19035c74385d1c9df9c (patch) | |
| tree | d215e1ad1267431ea10d511d6f429985b5bf2800 /Swift/QtUI/QtChatView.cpp | |
| parent | 5b974445a8ce78ca73bdfae9a8114857e4fc3d36 (diff) | |
| download | swift-89f18c8af344fc94bb5cf19035c74385d1c9df9c.zip swift-89f18c8af344fc94bb5cf19035c74385d1c9df9c.tar.bz2 | |
Added "Clear" context menu for chat log.
Resolves: #225
Diffstat (limited to 'Swift/QtUI/QtChatView.cpp')
| -rw-r--r-- | Swift/QtUI/QtChatView.cpp | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/Swift/QtUI/QtChatView.cpp b/Swift/QtUI/QtChatView.cpp index 145371f..4bae755 100644 --- a/Swift/QtUI/QtChatView.cpp +++ b/Swift/QtUI/QtChatView.cpp | |||
| @@ -29,10 +29,11 @@ QtChatView::QtChatView(QtChatTheme* theme, QWidget* parent) : QWidget(parent) { | |||
| 29 | mainLayout->setContentsMargins(0,0,0,0); | 29 | mainLayout->setContentsMargins(0,0,0,0); |
| 30 | webView_ = new QtWebView(this); | 30 | webView_ = new QtWebView(this); |
| 31 | connect(webView_, SIGNAL(linkClicked(const QUrl&)), SLOT(handleLinkClicked(const QUrl&))); | 31 | connect(webView_, SIGNAL(linkClicked(const QUrl&)), SLOT(handleLinkClicked(const QUrl&))); |
| 32 | connect(webView_, SIGNAL(loadFinished(bool)), SLOT(handleViewLoadFinished(bool))); | 32 | connect(webView_, SIGNAL(loadFinished(bool)), SLOT(handleViewLoadFinished(bool))); |
| 33 | connect(webView_, SIGNAL(gotFocus()), SIGNAL(gotFocus())); | 33 | connect(webView_, SIGNAL(gotFocus()), SIGNAL(gotFocus())); |
| 34 | connect(webView_, SIGNAL(clearRequested()), SLOT(resetView())); | ||
| 34 | #ifdef Q_WS_X11 | 35 | #ifdef Q_WS_X11 |
| 35 | /* To give a border on Linux, where it looks bad without */ | 36 | /* To give a border on Linux, where it looks bad without */ |
| 36 | QStackedWidget* stack = new QStackedWidget(this); | 37 | QStackedWidget* stack = new QStackedWidget(this); |
| 37 | stack->addWidget(webView_); | 38 | stack->addWidget(webView_); |
| 38 | stack->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); | 39 | stack->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); |
| @@ -49,26 +50,11 @@ QtChatView::QtChatView(QtChatTheme* theme, QWidget* parent) : QWidget(parent) { | |||
| 49 | webPage_->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); | 50 | webPage_->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); |
| 50 | webView_->setPage(webPage_); | 51 | webView_->setPage(webPage_); |
| 51 | connect(webPage_, SIGNAL(selectionChanged()), SLOT(copySelectionToClipboard())); | 52 | connect(webPage_, SIGNAL(selectionChanged()), SLOT(copySelectionToClipboard())); |
| 52 | 53 | ||
| 53 | viewReady_ = false; | 54 | viewReady_ = false; |
| 54 | QString pageHTML = theme_->getTemplate(); | 55 | resetView(); |
| 55 | pageHTML.replace("==bodyBackground==", "background-color:#e3e3e3"); | ||
| 56 | pageHTML.replace(pageHTML.indexOf("%@"), 2, theme_->getBase()); | ||
| 57 | if (pageHTML.count("%@") > 3) { | ||
| 58 | pageHTML.replace(pageHTML.indexOf("%@"), 2, theme_->getMainCSS()); | ||
| 59 | } | ||
| 60 | pageHTML.replace(pageHTML.indexOf("%@"), 2, "Variants/Blue on Green.css"); | ||
| 61 | pageHTML.replace(pageHTML.indexOf("%@"), 2, ""/*headerSnippet.getContent()*/); | ||
| 62 | pageHTML.replace(pageHTML.indexOf("%@"), 2, ""/*footerSnippet.getContent()*/); | ||
| 63 | webPage_->mainFrame()->setHtml(pageHTML); | ||
| 64 | document_ = webPage_->mainFrame()->documentElement(); | ||
| 65 | QWebElement chatElement = document_.findFirst("#Chat"); | ||
| 66 | newInsertPoint_ = chatElement.clone(); | ||
| 67 | newInsertPoint_.setOuterXml("<div id='swift_insert'/>"); | ||
| 68 | chatElement.appendInside(newInsertPoint_); | ||
| 69 | Q_ASSERT(!newInsertPoint_.isNull()); | ||
| 70 | } | 56 | } |
| 71 | 57 | ||
| 72 | void QtChatView::handleKeyPressEvent(QKeyEvent* event) { | 58 | void QtChatView::handleKeyPressEvent(QKeyEvent* event) { |
| 73 | webView_->keyPressEvent(event); | 59 | webView_->keyPressEvent(event); |
| 74 | } | 60 | } |
| @@ -161,6 +147,25 @@ void QtChatView::handleViewLoadFinished(bool ok) { | |||
| 161 | Q_ASSERT(ok); | 147 | Q_ASSERT(ok); |
| 162 | viewReady_ = true; | 148 | viewReady_ = true; |
| 163 | addQueuedSnippets(); | 149 | addQueuedSnippets(); |
| 164 | } | 150 | } |
| 165 | 151 | ||
| 152 | void QtChatView::resetView() { | ||
| 153 | QString pageHTML = theme_->getTemplate(); | ||
| 154 | pageHTML.replace("==bodyBackground==", "background-color:#e3e3e3"); | ||
| 155 | pageHTML.replace(pageHTML.indexOf("%@"), 2, theme_->getBase()); | ||
| 156 | if (pageHTML.count("%@") > 3) { | ||
| 157 | pageHTML.replace(pageHTML.indexOf("%@"), 2, theme_->getMainCSS()); | ||
| 158 | } | ||
| 159 | pageHTML.replace(pageHTML.indexOf("%@"), 2, "Variants/Blue on Green.css"); | ||
| 160 | pageHTML.replace(pageHTML.indexOf("%@"), 2, ""/*headerSnippet.getContent()*/); | ||
| 161 | pageHTML.replace(pageHTML.indexOf("%@"), 2, ""/*footerSnippet.getContent()*/); | ||
| 162 | webPage_->mainFrame()->setHtml(pageHTML); | ||
| 163 | document_ = webPage_->mainFrame()->documentElement(); | ||
| 164 | QWebElement chatElement = document_.findFirst("#Chat"); | ||
| 165 | newInsertPoint_ = chatElement.clone(); | ||
| 166 | newInsertPoint_.setOuterXml("<div id='swift_insert'/>"); | ||
| 167 | chatElement.appendInside(newInsertPoint_); | ||
| 168 | Q_ASSERT(!newInsertPoint_.isNull()); | ||
| 169 | } | ||
| 170 | |||
| 166 | } | 171 | } |
Swift