From 89f18c8af344fc94bb5cf19035c74385d1c9df9c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be>
Date: Sun, 5 Sep 2010 14:59:02 +0200
Subject: Added "Clear" context menu for chat log.

Resolves: #225

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
@@ -31,6 +31,7 @@ QtChatView::QtChatView(QtChatTheme* theme, QWidget* parent) : QWidget(parent) {
 	connect(webView_, SIGNAL(linkClicked(const QUrl&)), SLOT(handleLinkClicked(const QUrl&)));
 	connect(webView_, SIGNAL(loadFinished(bool)), SLOT(handleViewLoadFinished(bool)));
 	connect(webView_, SIGNAL(gotFocus()), SIGNAL(gotFocus()));
+	connect(webView_, SIGNAL(clearRequested()), SLOT(resetView()));
 #ifdef Q_WS_X11
 	/* To give a border on Linux, where it looks bad without */
 	QStackedWidget* stack = new QStackedWidget(this);
@@ -51,22 +52,7 @@ QtChatView::QtChatView(QtChatTheme* theme, QWidget* parent) : QWidget(parent) {
 	connect(webPage_, SIGNAL(selectionChanged()), SLOT(copySelectionToClipboard()));
 
 	viewReady_ = false;
-	QString pageHTML = theme_->getTemplate();
-	pageHTML.replace("==bodyBackground==", "background-color:#e3e3e3");
-	pageHTML.replace(pageHTML.indexOf("%@"), 2, theme_->getBase());
-	if (pageHTML.count("%@") > 3) {
-		pageHTML.replace(pageHTML.indexOf("%@"), 2, theme_->getMainCSS());
-	}
-	pageHTML.replace(pageHTML.indexOf("%@"), 2, "Variants/Blue on Green.css");
-	pageHTML.replace(pageHTML.indexOf("%@"), 2, ""/*headerSnippet.getContent()*/);
-	pageHTML.replace(pageHTML.indexOf("%@"), 2, ""/*footerSnippet.getContent()*/);
-	webPage_->mainFrame()->setHtml(pageHTML);
-	document_ = webPage_->mainFrame()->documentElement();
-	QWebElement chatElement = document_.findFirst("#Chat");
-	newInsertPoint_ = chatElement.clone();
-	newInsertPoint_.setOuterXml("<div id='swift_insert'/>");
-	chatElement.appendInside(newInsertPoint_);
-	Q_ASSERT(!newInsertPoint_.isNull());
+	resetView();
 }
 
 void QtChatView::handleKeyPressEvent(QKeyEvent* event) {
@@ -163,4 +149,23 @@ void QtChatView::handleViewLoadFinished(bool ok) {
 	addQueuedSnippets();
 }
 
+void QtChatView::resetView() {
+	QString pageHTML = theme_->getTemplate();
+	pageHTML.replace("==bodyBackground==", "background-color:#e3e3e3");
+	pageHTML.replace(pageHTML.indexOf("%@"), 2, theme_->getBase());
+	if (pageHTML.count("%@") > 3) {
+		pageHTML.replace(pageHTML.indexOf("%@"), 2, theme_->getMainCSS());
+	}
+	pageHTML.replace(pageHTML.indexOf("%@"), 2, "Variants/Blue on Green.css");
+	pageHTML.replace(pageHTML.indexOf("%@"), 2, ""/*headerSnippet.getContent()*/);
+	pageHTML.replace(pageHTML.indexOf("%@"), 2, ""/*footerSnippet.getContent()*/);
+	webPage_->mainFrame()->setHtml(pageHTML);
+	document_ = webPage_->mainFrame()->documentElement();
+	QWebElement chatElement = document_.findFirst("#Chat");
+	newInsertPoint_ = chatElement.clone();
+	newInsertPoint_.setOuterXml("<div id='swift_insert'/>");
+	chatElement.appendInside(newInsertPoint_);
+	Q_ASSERT(!newInsertPoint_.isNull());
+}
+
 }
diff --git a/Swift/QtUI/QtChatView.h b/Swift/QtUI/QtChatView.h
index e60c92f..8c1a99a 100644
--- a/Swift/QtUI/QtChatView.h
+++ b/Swift/QtUI/QtChatView.h
@@ -41,6 +41,7 @@ namespace Swift {
 			void scrollToBottom();
 			void handleLinkClicked(const QUrl&);
 			void handleKeyPressEvent(QKeyEvent* event);
+			void resetView();
 
 		private slots:
 			void handleViewLoadFinished(bool);
diff --git a/Swift/QtUI/QtWebView.cpp b/Swift/QtUI/QtWebView.cpp
index 93ecc18..df8479d 100644
--- a/Swift/QtUI/QtWebView.cpp
+++ b/Swift/QtUI/QtWebView.cpp
@@ -31,17 +31,18 @@ void QtWebView::keyPressEvent(QKeyEvent* event) {
 	delete translatedEvent;
 }
 
-void QtWebView::dragEnterEvent(QDragEnterEvent *event) {
+void QtWebView::dragEnterEvent(QDragEnterEvent*) {
 
 }
 
 void QtWebView::contextMenuEvent(QContextMenuEvent* ev) {
+	QMenu menu(this);
 	QAction* copyLinkAction = pageAction(QWebPage::CopyLinkToClipboard);
 	if (copyLinkAction) {
-		QMenu menu(this);
 		menu.addAction(copyLinkAction);
-		menu.exec(ev->globalPos());
 	}
+	menu.addAction("Clear", this, SIGNAL(clearRequested()));
+	menu.exec(ev->globalPos());
 }
 
 void QtWebView::focusInEvent(QFocusEvent* event) {
diff --git a/Swift/QtUI/QtWebView.h b/Swift/QtUI/QtWebView.h
index 171330d..f60e5ef 100644
--- a/Swift/QtUI/QtWebView.h
+++ b/Swift/QtUI/QtWebView.h
@@ -20,6 +20,7 @@ namespace Swift {
 
 		signals:
 			void gotFocus();
+			void clearRequested();
 
 		protected:
 			void focusInEvent(QFocusEvent* event);
-- 
cgit v0.10.2-6-g49f6