mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-25 14:07:44 -05:00
Significantly improve visual when dragging entries to copy/move
* Fixes #6079
This commit is contained in:
parent
0a7585852b
commit
15b8b5d92f
@ -3965,6 +3965,13 @@ Error: %1</source>
|
|||||||
<source>Reset to defaults</source>
|
<source>Reset to defaults</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message numerus="yes">
|
||||||
|
<source>+ %1 entry(s)...</source>
|
||||||
|
<translation type="unfinished">
|
||||||
|
<numerusform></numerusform>
|
||||||
|
<numerusform></numerusform>
|
||||||
|
</translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>ExportDialog</name>
|
<name>ExportDialog</name>
|
||||||
|
@ -19,12 +19,18 @@
|
|||||||
#include "EntryView.h"
|
#include "EntryView.h"
|
||||||
|
|
||||||
#include <QAccessible>
|
#include <QAccessible>
|
||||||
|
#include <QDrag>
|
||||||
|
#include <QGuiApplication>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
|
#include <QListWidget>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QScreen>
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QStyledItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
|
#include <QWindow>
|
||||||
|
|
||||||
|
#include "gui/Icons.h"
|
||||||
#include "gui/SortFilterHideProxyModel.h"
|
#include "gui/SortFilterHideProxyModel.h"
|
||||||
|
|
||||||
#define ICON_ONLY_SECTION_SIZE 26
|
#define ICON_ONLY_SECTION_SIZE 26
|
||||||
@ -507,6 +513,74 @@ void EntryView::showEvent(QShowEvent* event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EntryView::startDrag(Qt::DropActions supportedActions)
|
||||||
|
{
|
||||||
|
auto selectedIndexes = selectionModel()->selectedRows(EntryModel::Title);
|
||||||
|
if (selectedIndexes.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a mime data object for the selected rows
|
||||||
|
auto mimeData = m_sortModel->mimeData(selectedIndexes);
|
||||||
|
if (!mimeData) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a temporary list widget to display the dragged items
|
||||||
|
int i = 0;
|
||||||
|
QListWidget listWidget;
|
||||||
|
for (auto& index : selectedIndexes) {
|
||||||
|
if (++i > 4) {
|
||||||
|
int remaining = selectedIndexes.size() - i + 1;
|
||||||
|
listWidget.addItem(tr("+ %1 entry(s)...", nullptr, remaining).arg(remaining));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
QIcon icon;
|
||||||
|
icon.addPixmap(m_sortModel->data(index, Qt::DecorationRole).value<QPixmap>());
|
||||||
|
|
||||||
|
auto item = new QListWidgetItem;
|
||||||
|
item->setText(m_sortModel->data(index, Qt::DisplayRole).toString());
|
||||||
|
item->setIcon(icon);
|
||||||
|
listWidget.addItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
listWidget.setStyleSheet("QListWidget { background-color: palette(highlight); border: 1px solid palette(dark); "
|
||||||
|
"padding: 4px; color: palette(highlighted-text); }");
|
||||||
|
auto width = listWidget.sizeHintForColumn(0) + 2 * listWidget.frameWidth();
|
||||||
|
auto height = listWidget.sizeHintForRow(0) * listWidget.count() + 2 * listWidget.frameWidth();
|
||||||
|
listWidget.setFixedWidth(width);
|
||||||
|
listWidget.setFixedHeight(height);
|
||||||
|
|
||||||
|
// Grab the screen pixel ratio where the window resides
|
||||||
|
// TODO: Use direct call to screen() when moving to Qt 6
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
||||||
|
auto screen = QGuiApplication::screenAt(window()->geometry().center());
|
||||||
|
if (!screen) {
|
||||||
|
screen = QGuiApplication::primaryScreen();
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
auto screen = QGuiApplication::primaryScreen();
|
||||||
|
if (windowHandle()) {
|
||||||
|
screen = windowHandle()->screen();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
auto pixelRatio = screen->devicePixelRatio();
|
||||||
|
|
||||||
|
// Render the list widget to a pixmap
|
||||||
|
QPixmap pixmap(QSize(width, height) * pixelRatio);
|
||||||
|
pixmap.fill(Qt::transparent);
|
||||||
|
pixmap.setDevicePixelRatio(pixelRatio);
|
||||||
|
listWidget.render(&pixmap);
|
||||||
|
|
||||||
|
// Create a drag object and start the drag
|
||||||
|
auto drag = new QDrag(this);
|
||||||
|
drag->setMimeData(mimeData);
|
||||||
|
drag->setPixmap(pixmap);
|
||||||
|
drag->exec(supportedActions, defaultDropAction());
|
||||||
|
}
|
||||||
|
|
||||||
bool EntryView::isColumnHidden(int logicalIndex)
|
bool EntryView::isColumnHidden(int logicalIndex)
|
||||||
{
|
{
|
||||||
return header()->isSectionHidden(logicalIndex) || header()->sectionSize(logicalIndex) == 0;
|
return header()->isSectionHidden(logicalIndex) || header()->sectionSize(logicalIndex) == 0;
|
||||||
|
@ -61,6 +61,7 @@ protected:
|
|||||||
void keyPressEvent(QKeyEvent* event) override;
|
void keyPressEvent(QKeyEvent* event) override;
|
||||||
void focusInEvent(QFocusEvent* event) override;
|
void focusInEvent(QFocusEvent* event) override;
|
||||||
void showEvent(QShowEvent* event) override;
|
void showEvent(QShowEvent* event) override;
|
||||||
|
void startDrag(Qt::DropActions supportedActions) override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void emitEntryActivated(const QModelIndex& index);
|
void emitEntryActivated(const QModelIndex& index);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user