X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatscene.cpp;h=f1ef2886d1224e1e04985c91e1cc7bfb429c7a97;hp=42529f33860aaf79947696f73f46630dfbeb9a7a;hb=7de4debb5a6744d9f67cb09c5fc0aa136f05be96;hpb=694f9bfbf7f1af19108461c7e00d133e55082bce diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index 42529f33..f1ef2886 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2012 by the Quassel Project * + * Copyright (C) 2005-2014 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -15,17 +15,19 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include #include +#include #include #include #include #include #include #include +#include #ifdef HAVE_KDE # include @@ -87,12 +89,12 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, qreal w connect(this, SIGNAL(sceneRectChanged(const QRectF &)), _markerLine, SLOT(sceneRectChanged(const QRectF &))); ChatViewSettings defaultSettings; - int defaultFirstColHandlePos = defaultSettings.value("FirstColumnHandlePos", 80).toInt(); - int defaultSecondColHandlePos = defaultSettings.value("SecondColumnHandlePos", 200).toInt(); + _defaultFirstColHandlePos = defaultSettings.value("FirstColumnHandlePos", 80).toInt(); + _defaultSecondColHandlePos = defaultSettings.value("SecondColumnHandlePos", 200).toInt(); ChatViewSettings viewSettings(this); - _firstColHandlePos = viewSettings.value("FirstColumnHandlePos", defaultFirstColHandlePos).toInt(); - _secondColHandlePos = viewSettings.value("SecondColumnHandlePos", defaultSecondColHandlePos).toInt(); + _firstColHandlePos = viewSettings.value("FirstColumnHandlePos", _defaultFirstColHandlePos).toInt(); + _secondColHandlePos = viewSettings.value("SecondColumnHandlePos", _defaultSecondColHandlePos).toInt(); _firstColHandle = new ColumnHandleItem(QtUi::style()->firstColumnSeparator()); addItem(_firstColHandle); @@ -157,6 +159,17 @@ ColumnHandleItem *ChatScene::secondColumnHandle() const return _secondColHandle; } +void ChatScene::resetColumnWidths() +{ + //make sure first column is at least 80 px wide, second 120 px + int firstColHandlePos = qMax(_defaultFirstColHandlePos, + 80); + int secondColHandlePos = qMax(_defaultSecondColHandlePos, + firstColHandlePos + 120); + + _firstColHandle->setXPos(firstColHandlePos); + _secondColHandle->setXPos(secondColHandlePos); +} ChatLine *ChatScene::chatLine(MsgId msgId, bool matchExact, bool ignoreDayChange) const { @@ -799,11 +812,6 @@ void ChatScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) chatView()->addActionsToMenu(&menu, pos); menu.addSeparator(); - if (isPosOverSelection(pos)) - menu.addAction(SmallIcon("edit-copy"), tr("Copy Selection"), - this, SLOT(selectionToClipboard()), - QKeySequence::Copy); - // item-specific options (select link etc) ChatItem *item = chatItemAt(pos); if (item) @@ -812,9 +820,29 @@ void ChatScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) // no item -> default scene actions GraphicalUi::contextMenuActionProvider()->addActions(&menu, filter(), BufferId()); + // If we have text selected, insert the Copy Selection as first item + if (isPosOverSelection(pos)) { + QAction *sep = menu.insertSeparator(menu.actions().first()); + QAction *act = new Action(QIcon::fromTheme("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("…")); + searchSelectionText = tr("Search '%1'").arg(searchSelectionText); + + menu.addAction(QIcon::fromTheme("edit-find"), searchSelectionText, this, SLOT(webSearchOnSelection())); + } + if (QtUi::mainWindow()->menuBar()->isHidden()) menu.addAction(QtUi::actionCollection("General")->action("ToggleMenuBar")); + // show column reset action if columns have been resized in this session or there is at least one very narrow column + if ((_firstColHandlePos != _defaultFirstColHandlePos) || (_secondColHandlePos != _defaultSecondColHandlePos) || + (_firstColHandlePos <= 10) || (_secondColHandlePos - _firstColHandlePos <= 10)) + menu.addAction(new Action(tr("Reset Column Widths"), &menu, this, SLOT(resetColumnWidths()), 0)); + menu.exec(event->screenPos()); } @@ -1044,6 +1072,21 @@ void ChatScene::clearSelection() } +/******** *************************************************************************************/ + +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()