X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fqtui%2Fchatscene.cpp;h=085bb92817246636043a2edfe71060ebafa7f84d;hb=35ca85f1c4371ee28d00d5ff0195a5b44aadb299;hp=a7f2360a8da3a8511d7a8de4439e96b3086278c6;hpb=4ee4a3edb832d7ac01951007cf55f7fa4b5918b4;p=quassel.git diff --git a/src/qtui/chatscene.cpp b/src/qtui/chatscene.cpp index a7f2360a..085bb928 100644 --- a/src/qtui/chatscene.cpp +++ b/src/qtui/chatscene.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2014 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -23,19 +23,22 @@ #include #include #include +#include #include #include #include #include #include -#ifdef HAVE_KDE +#ifdef HAVE_KDE4 # include #else # include #endif -#ifdef HAVE_WEBKIT +#ifdef HAVE_WEBENGINE +# include +#elif defined HAVE_WEBKIT # include #endif @@ -48,7 +51,6 @@ #include "clientbacklogmanager.h" #include "columnhandleitem.h" #include "contextmenuactionprovider.h" -#include "iconloader.h" #include "mainwin.h" #include "markerlineitem.h" #include "messagefilter.h" @@ -89,12 +91,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); @@ -122,7 +124,7 @@ ChatScene::ChatScene(QAbstractItemModel *model, const QString &idString, qreal w this, SLOT(rowsRemoved())); connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), SLOT(dataChanged(QModelIndex, QModelIndex))); -#ifdef HAVE_WEBKIT +#if defined HAVE_WEBKIT || defined HAVE_WEBENGINE webPreview.timer.setSingleShot(true); connect(&webPreview.timer, SIGNAL(timeout()), this, SLOT(webPreviewNextStep())); #endif @@ -159,6 +161,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 { @@ -640,7 +653,7 @@ void ChatScene::firstHandlePositionChanged(qreal xpos) QPointF senderPos(firstColumnHandle()->sceneRight(), 0); while (lineIter != lineIterBegin) { - lineIter--; + --lineIter; (*lineIter)->setFirstColumn(timestampWidth, senderWidth, senderPos); } //setItemIndexMethod(QGraphicsScene::BspTreeIndex); @@ -676,7 +689,7 @@ void ChatScene::secondHandlePositionChanged(qreal xpos) qreal contentsWidth = _sceneRect.width() - secondColumnHandle()->sceneRight(); QPointF contentsPos(secondColumnHandle()->sceneRight(), 0); while (lineIter != lineIterBegin) { - lineIter--; + --lineIter; (*lineIter)->setSecondColumn(senderWidth, contentsWidth, contentsPos, linePos); } //setItemIndexMethod(QGraphicsScene::BspTreeIndex); @@ -812,7 +825,7 @@ void ChatScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) // 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(SmallIcon("edit-copy"), tr("Copy Selection"), &menu, this, + QAction *act = new Action(QIcon::fromTheme("edit-copy"), tr("Copy Selection"), &menu, this, SLOT(selectionToClipboard()), QKeySequence::Copy); menu.insertAction(sep, act); @@ -821,12 +834,18 @@ void ChatScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) searchSelectionText = searchSelectionText.left(_webSearchSelectionTextMaxVisible).append(QString::fromUtf8("…")); searchSelectionText = tr("Search '%1'").arg(searchSelectionText); - menu.addAction(SmallIcon("edit-find"), searchSelectionText, this, SLOT(webSearchOnSelection())); + QAction *webSearchAction = new Action(QIcon::fromTheme("edit-find"), searchSelectionText, &menu, this, SLOT(webSearchOnSelection())); + menu.insertAction(sep, webSearchAction); } 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()); } @@ -1154,9 +1173,9 @@ void ChatScene::updateSceneRect(const QRectF &rect) // ======================================== -// Webkit Only stuff +// Webkit/WebEngine Only stuff // ======================================== -#ifdef HAVE_WEBKIT +#if defined HAVE_WEBKIT || defined HAVE_WEBENGINE void ChatScene::loadWebPreview(ChatItem *parentItem, const QUrl &url, const QRectF &urlRect) { if (!_showWebPreview) @@ -1238,7 +1257,8 @@ void ChatScene::webPreviewNextStep() qWarning() << "removing preview"; if (webPreview.previewItem && webPreview.previewItem->scene()) removeItem(webPreview.previewItem); - // Fall through to deletion! + // Fall through to deletion! + [[clang::fallthrough]]; case WebPreview::HidePreview: if (webPreview.previewItem) { delete webPreview.previewItem; @@ -1265,7 +1285,8 @@ void ChatScene::clearWebPreview(ChatItem *parentItem) if (webPreview.previewItem && webPreview.previewItem->scene()) removeItem(webPreview.previewItem); } - // fall through into to set hidden state + // fall through into to set hidden state + [[clang::fallthrough]]; case WebPreview::DelayPreview: // we're just loading, so haven't shown the preview yet. webPreview.previewState = WebPreview::HidePreview;