diff options
Diffstat (limited to 'Swift')
| -rw-r--r-- | Swift/QtUI/QtChatView.cpp | 37 | ||||
| -rw-r--r-- | Swift/QtUI/QtChatView.h | 1 | ||||
| -rw-r--r-- | Swift/QtUI/QtWebView.cpp | 7 | ||||
| -rw-r--r-- | Swift/QtUI/QtWebView.h | 1 |
4 files changed, 27 insertions, 19 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 | } |
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 | |||
| @@ -39,10 +39,11 @@ namespace Swift { | |||
| 39 | public slots: | 39 | public slots: |
| 40 | void copySelectionToClipboard(); | 40 | void copySelectionToClipboard(); |
| 41 | void scrollToBottom(); | 41 | void scrollToBottom(); |
| 42 | void handleLinkClicked(const QUrl&); | 42 | void handleLinkClicked(const QUrl&); |
| 43 | void handleKeyPressEvent(QKeyEvent* event); | 43 | void handleKeyPressEvent(QKeyEvent* event); |
| 44 | void resetView(); | ||
| 44 | 45 | ||
| 45 | private slots: | 46 | private slots: |
| 46 | void handleViewLoadFinished(bool); | 47 | void handleViewLoadFinished(bool); |
| 47 | 48 | ||
| 48 | private: | 49 | private: |
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 | |||
| @@ -29,21 +29,22 @@ void QtWebView::keyPressEvent(QKeyEvent* event) { | |||
| 29 | event->count()); | 29 | event->count()); |
| 30 | QWebView::keyPressEvent(translatedEvent); | 30 | QWebView::keyPressEvent(translatedEvent); |
| 31 | delete translatedEvent; | 31 | delete translatedEvent; |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | void QtWebView::dragEnterEvent(QDragEnterEvent *event) { | 34 | void QtWebView::dragEnterEvent(QDragEnterEvent*) { |
| 35 | 35 | ||
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | void QtWebView::contextMenuEvent(QContextMenuEvent* ev) { | 38 | void QtWebView::contextMenuEvent(QContextMenuEvent* ev) { |
| 39 | QMenu menu(this); | ||
| 39 | QAction* copyLinkAction = pageAction(QWebPage::CopyLinkToClipboard); | 40 | QAction* copyLinkAction = pageAction(QWebPage::CopyLinkToClipboard); |
| 40 | if (copyLinkAction) { | 41 | if (copyLinkAction) { |
| 41 | QMenu menu(this); | ||
| 42 | menu.addAction(copyLinkAction); | 42 | menu.addAction(copyLinkAction); |
| 43 | menu.exec(ev->globalPos()); | ||
| 44 | } | 43 | } |
| 44 | menu.addAction("Clear", this, SIGNAL(clearRequested())); | ||
| 45 | menu.exec(ev->globalPos()); | ||
| 45 | } | 46 | } |
| 46 | 47 | ||
| 47 | void QtWebView::focusInEvent(QFocusEvent* event) { | 48 | void QtWebView::focusInEvent(QFocusEvent* event) { |
| 48 | QWebView::focusInEvent(event); | 49 | QWebView::focusInEvent(event); |
| 49 | emit gotFocus(); | 50 | emit gotFocus(); |
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 | |||
| @@ -18,10 +18,11 @@ namespace Swift { | |||
| 18 | void dragEnterEvent(QDragEnterEvent *event); | 18 | void dragEnterEvent(QDragEnterEvent *event); |
| 19 | void contextMenuEvent(QContextMenuEvent* ev); | 19 | void contextMenuEvent(QContextMenuEvent* ev); |
| 20 | 20 | ||
| 21 | signals: | 21 | signals: |
| 22 | void gotFocus(); | 22 | void gotFocus(); |
| 23 | void clearRequested(); | ||
| 23 | 24 | ||
| 24 | protected: | 25 | protected: |
| 25 | void focusInEvent(QFocusEvent* event); | 26 | void focusInEvent(QFocusEvent* event); |
| 26 | }; | 27 | }; |
| 27 | } | 28 | } |
Swift