#include <QApplication>
#include <QClipboard>
+#include <QDesktopServices>
#include <QDrag>
#include <QGraphicsSceneMouseEvent>
#include <QMenu>
#include <QMenuBar>
#include <QMimeData>
#include <QPersistentModelIndex>
+#include <QUrl>
#ifdef HAVE_KDE
# include <KMenuBar>
QAction *act = new Action(SmallIcon("edit-copy"), tr("Copy Selection"), &menu, this,
SLOT(selectionToClipboard()), QKeySequence::Copy);
menu.insertAction(sep, act);
+
+ QString searchSelectionText = selection();
+ if (searchSelectionText.length() > _webSearchSelectionTextMaxVisible)
+ searchSelectionText = searchSelectionText.left(_webSearchSelectionTextMaxVisible).append(QString::fromUtf8("\u2026"));
+ searchSelectionText = tr("Search '%1'").arg(searchSelectionText);
+
+ menu.addAction(SmallIcon("zoom-in"), searchSelectionText, this, SLOT(webSearchOnSelection()));
}
if (QtUi::mainWindow()->menuBar()->isHidden())
}
+/******** *************************************************************************************/
+
+void ChatScene::webSearchOnSelection()
+{
+ if (!hasSelection())
+ return;
+
+ ChatViewSettings settings;
+ QString webSearchBaseUrl = settings.webSearchUrlFormatString();
+ QString webSearchUrl = webSearchBaseUrl.replace(QString("%s"), selection());
+ QUrl url = QUrl::fromUserInput(webSearchUrl);
+ QDesktopServices::openUrl(url);
+}
+
+
/******** *************************************************************************************/
void ChatScene::requestBacklog()
void selectionToClipboard(QClipboard::Mode = QClipboard::Clipboard);
void stringToClipboard(const QString &str, QClipboard::Mode = QClipboard::Clipboard);
+ void webSearchOnSelection();
+
void requestBacklog();
#ifdef HAVE_WEBKIT
bool _showWebPreview;
+ static const int _webSearchSelectionTextMaxVisible = 24;
+
#ifdef HAVE_WEBKIT
struct WebPreview {
enum PreviewState {
inline QString timestampFormatString() { return localValue("TimestampFormat", "[hh:mm:ss]").toString(); }
inline void setTimestampFormatString(const QString &format) { setLocalValue("TimestampFormat", format); }
+
+ inline QString webSearchUrlFormatString() { return localValue("WebSearchUrlFormat", "https://www.google.com/search?q=%s").toString(); }
+ inline void setWebSearchUrlFormatString(const QString &format) { setLocalValue("WebSearchUrlFormat", format); }
};
</property>
</widget>
</item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_4">
+ <item>
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Web Search Url:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="webSearchUrlFormat">
+ <property name="toolTip">
+ <string><html><head/><body><p>The URL to open with the selected text as the parameter. Place <span style=" font-weight:600;">%s</span> where selected text should go.</p><p>Eg:</p><p>https://www.google.com/search?q=<span style=" font-weight:600;">%s<br/></span>https://duckduckgo.com/?q=<span style=" font-weight:600;">%s</span></p></body></html></string>
+ </property>
+ <property name="settingsKey" stdset="0">
+ <string>WebSearchUrlFormat</string>
+ </property>
+ <property name="defaultValue" stdset="0">
+ <string>https://www.google.com/search?q=%s</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
<item>
<widget class="QGroupBox" name="useCustomColors">
<property name="title">