diff options
Diffstat (limited to 'Swift/QtUI/QtChatView.cpp')
| -rw-r--r-- | Swift/QtUI/QtChatView.cpp | 84 | 
1 files changed, 71 insertions, 13 deletions
| diff --git a/Swift/QtUI/QtChatView.cpp b/Swift/QtUI/QtChatView.cpp index 521b072..e3fc2b3 100644 --- a/Swift/QtUI/QtChatView.cpp +++ b/Swift/QtUI/QtChatView.cpp @@ -24,7 +24,7 @@  namespace Swift { -QtChatView::QtChatView(QtChatTheme* theme, QWidget* parent) : QWidget(parent) { +QtChatView::QtChatView(QtChatTheme* theme, QWidget* parent) : QWidget(parent), fontSizeSteps_(0) {  	theme_ = theme;  	QVBoxLayout* mainLayout = new QVBoxLayout(this); @@ -35,6 +35,8 @@ QtChatView::QtChatView(QtChatTheme* theme, QWidget* parent) : QWidget(parent) {  	connect(webView_, SIGNAL(loadFinished(bool)), SLOT(handleViewLoadFinished(bool)));  	connect(webView_, SIGNAL(gotFocus()), SIGNAL(gotFocus()));  	connect(webView_, SIGNAL(clearRequested()), SLOT(handleClearRequested())); +	connect(webView_, SIGNAL(fontGrowRequested()), SLOT(increaseFontSize())); +	connect(webView_, SIGNAL(fontShrinkRequested()), SLOT(decreaseFontSize()));  #ifdef Q_WS_X11  	/* To give a border on Linux, where it looks bad without */  	QStackedWidget* stack = new QStackedWidget(this); @@ -77,13 +79,14 @@ void QtChatView::addMessage(boost::shared_ptr<ChatSnippet> snippet) {  	if (viewReady_) {  		addToDOM(snippet);  	} else { -		queuedSnippets_.append(snippet); +		/* If this asserts, the previous queuing code was necessary and should be reinstated */ +		assert(false);  	}  }  QWebElement QtChatView::snippetToDOM(boost::shared_ptr<ChatSnippet> snippet) {  	QWebElement newElement = newInsertPoint_.clone(); -	newElement.setInnerXml(snippet->getContent()); /* FIXME: Outer, surely? */ +	newElement.setInnerXml(snippet->getContent());  	Q_ASSERT(!newElement.isNull());  	return newElement;  } @@ -103,12 +106,31 @@ void QtChatView::addToDOM(boost::shared_ptr<ChatSnippet> snippet) {  		newInsertPoint_.prependOutside(newElement);  	}  	lastElement_ = newElement; -	//qApp->processEvents(); +	if (fontSizeSteps_ != 0) { +		double size = 1.0 + 0.2 * fontSizeSteps_; +		QString sizeString(QString().setNum(size, 'g', 3) + "em"); +		const QWebElementCollection spans = lastElement_.findAll("span"); +		foreach (QWebElement span, spans) { +			span.setStyleProperty("font-size", sizeString); +		} +	} +} + +void QtChatView::addLastSeenLine() { +	if (lineSeparator_.isNull()) { +		lineSeparator_ = newInsertPoint_.clone(); +		lineSeparator_.setInnerXml(QString("<hr/>")); +		newInsertPoint_.prependOutside(lineSeparator_); +	} +	else { +		QWebElement lineSeparatorC = lineSeparator_.clone(); +		lineSeparatorC.removeFromDocument(); +	} +	newInsertPoint_.prependOutside(lineSeparator_);  }  void QtChatView::replaceLastMessage(const QString& newMessage) {  	assert(viewReady_); -	/* FIXME: must be queued? */  	rememberScrolledToBottom();  	assert(!lastElement_.isNull());  	QWebElement replace = lastElement_.findFirst("span.swift_message"); @@ -125,6 +147,25 @@ void QtChatView::replaceLastMessage(const QString& newMessage, const QString& no  	replace.setInnerXml(ChatSnippet::escape(note));  } +QString QtChatView::getLastSentMessage() { +	return lastElement_.toPlainText(); +} + +void QtChatView::replaceMessage(const QString& newMessage, const QString& id, const QDateTime& editTime) { +	rememberScrolledToBottom(); +	QWebElement message = document_.findFirst("#" + id); +	if (!message.isNull()) { +		QWebElement replaceContent = message.findFirst("span.swift_message"); +		assert(!replaceContent.isNull()); +		QString old = replaceContent.toOuterXml(); +		replaceContent.setInnerXml(ChatSnippet::escape(newMessage)); +		QWebElement replaceTime = message.findFirst("span.swift_time"); +		assert(!replaceTime.isNull()); +		old = replaceTime.toOuterXml(); +		replaceTime.setInnerXml(ChatSnippet::escape(tr("%1 edited").arg(ChatSnippet::timeToEscapedString(editTime)))); +	} +} +  void QtChatView::copySelectionToClipboard() {  	if (!webPage_->selectedText().isEmpty()) {  		webPage_->triggerAction(QWebPage::Copy); @@ -160,17 +201,34 @@ void QtChatView::handleLinkClicked(const QUrl& url) {  	QDesktopServices::openUrl(url);  } -void QtChatView::addQueuedSnippets() { -	for (int i = 0; i < queuedSnippets_.count(); i++) { -		addToDOM(queuedSnippets_[i]); -	} -	queuedSnippets_.clear(); -} -  void QtChatView::handleViewLoadFinished(bool ok) {  	Q_ASSERT(ok);  	viewReady_ = true; -	addQueuedSnippets(); +} + +void QtChatView::increaseFontSize(int numSteps) { +	qDebug() << "Increasing"; +	fontSizeSteps_ += numSteps; +	emit fontResized(fontSizeSteps_); +} + +void QtChatView::decreaseFontSize() { +	fontSizeSteps_--; +	if (fontSizeSteps_ < 0) { +		fontSizeSteps_ = 0; +	} +	emit fontResized(fontSizeSteps_); +} + +void QtChatView::resizeFont(int fontSizeSteps) { +	fontSizeSteps_ = fontSizeSteps; +	double size = 1.0 + 0.2 * fontSizeSteps_; +	QString sizeString(QString().setNum(size, 'g', 3) + "em"); +	qDebug() << "Setting to " << sizeString; +	const QWebElementCollection spans = document_.findAll("span"); +	foreach (QWebElement span, spans) { +		span.setStyleProperty("font-size", sizeString); +	}  }  void QtChatView::resetView() { | 
 Swift
 Swift