summaryrefslogtreecommitdiff
path: root/src/modlistview.cpp
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2021-01-03 12:51:54 +0100
committerMikaël Capelle <capelle.mikael@gmail.com>2021-01-03 12:51:54 +0100
commit3366d9f192ef88cccc2d901c666e15061db20b4e (patch)
treed65ce6bfdcd6ddbc4ce48df453613057eca18b1e /src/modlistview.cpp
parentc36d1126df94d879181a95d63862117a62d5ff60 (diff)
Create CopyEventFilter. Add Ctrl+C to the plugin list.
Diffstat (limited to 'src/modlistview.cpp')
-rw-r--r--src/modlistview.cpp48
1 files changed, 16 insertions, 32 deletions
diff --git a/src/modlistview.cpp b/src/modlistview.cpp
index bc6b5a65..29c68165 100644
--- a/src/modlistview.cpp
+++ b/src/modlistview.cpp
@@ -22,6 +22,7 @@
#include "modlistdropinfo.h"
#include "modlistcontextmenu.h"
#include "genericicondelegate.h"
+#include "copyeventfilter.h"
#include "shared/fileentry.h"
#include "shared/directoryentry.h"
#include "shared/filesorigin.h"
@@ -135,6 +136,21 @@ ModListView::ModListView(QWidget* parent)
connect(this, &ModListView::doubleClicked, this, &ModListView::onDoubleClicked);
connect(this, &ModListView::customContextMenuRequested, this, &ModListView::onCustomContextMenuRequested);
+
+ installEventFilter(new CopyEventFilter(this, [=](auto& index) {
+ QVariant mIndex = index.data(ModList::IndexRole);
+ QString name = index.data(Qt::DisplayRole).toString();
+ if (mIndex.isValid() && hasCollapsibleSeparators()) {
+ ModInfo::Ptr info = ModInfo::getByIndex(mIndex.toInt());
+ if (info->isSeparator()) {
+ name = "[" + name + "]";
+ }
+ }
+ else if (model()->hasChildren(index)) {
+ name = "[" + name + "]";
+ }
+ return name;
+ }));
}
void ModListView::refresh()
@@ -615,35 +631,6 @@ bool ModListView::toggleSelectionState()
return m_core->modList()->toggleState(indexViewToModel(selectionModel()->selectedRows()));
}
-bool ModListView::copySelection()
-{
- if (!selectionModel()->hasSelection()) {
- return true;
- }
-
- // sort to reflect the visual order
- QModelIndexList selectedRows = selectionModel()->selectedRows();
- std::sort(selectedRows.begin(), selectedRows.end(), [=](const auto& lidx, const auto& ridx) {
- return visualRect(lidx).top() < visualRect(ridx).top();
- });
-
- QStringList rows;
- for (auto& idx : selectedRows) {
- ModInfo::Ptr info = ModInfo::getByIndex(idx.data(ModList::IndexRole).toInt());
- QString name = idx.data(Qt::DisplayRole).toString();
- if (model()->hasChildren(idx) || (
- sortColumn() == ModList::COL_PRIORITY
- && (groupByMode() == GroupByMode::NONE || groupByMode() == GroupByMode::SEPARATOR)
- && info->isSeparator())) {
- name = "[" + name + "]";
- }
- rows.append(name);
- }
-
- QGuiApplication::clipboard()->setText(rows.join("\n"));
- return true;
-}
-
void ModListView::updateGroupByProxy(int groupIndex)
{
// if the index is -1, we do not refresh unless we are grouping
@@ -1225,9 +1212,6 @@ bool ModListView::event(QEvent* event)
&& (keyEvent->key() == Qt::Key_Up || keyEvent->key() == Qt::Key_Down)) {
return moveSelection(keyEvent->key());
}
- else if (keyEvent->key() == Qt::Key_C) {
- return copySelection();
- }
}
else if (keyEvent->modifiers() == Qt::ShiftModifier) {
// shift+enter expand