mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-12-24 06:49:46 -05:00
parent
d57d167e9c
commit
49a2849489
@ -29,6 +29,10 @@ class GroupModel : public QAbstractItemModel
|
||||
|
||||
public:
|
||||
explicit GroupModel(Database* db, QObject* parent = nullptr);
|
||||
const Database* database() const
|
||||
{
|
||||
return m_db;
|
||||
}
|
||||
void changeDatabase(Database* newDb);
|
||||
QModelIndex index(Group* group) const;
|
||||
Group* groupFromIndex(const QModelIndex& index) const;
|
||||
|
@ -98,21 +98,29 @@ void GroupView::changeDatabase(const QSharedPointer<Database>& newDb)
|
||||
|
||||
void GroupView::dragMoveEvent(QDragMoveEvent* event)
|
||||
{
|
||||
if (event->keyboardModifiers() & Qt::ControlModifier) {
|
||||
event->setDropAction(Qt::CopyAction);
|
||||
} else {
|
||||
event->setDropAction(Qt::MoveAction);
|
||||
}
|
||||
|
||||
QTreeView::dragMoveEvent(event);
|
||||
|
||||
// entries may only be dropped on groups
|
||||
if (event->isAccepted() && event->mimeData()->hasFormat("application/x-keepassx-entry")
|
||||
&& (dropIndicatorPosition() == AboveItem || dropIndicatorPosition() == BelowItem)) {
|
||||
event->ignore();
|
||||
if (event->isAccepted()) {
|
||||
// we need to fix the drop action to have the correct cursor icon
|
||||
fixDropAction(event);
|
||||
if (event->dropAction() != event->proposedAction()) {
|
||||
event->accept();
|
||||
}
|
||||
|
||||
// entries may only be dropped on groups
|
||||
if (event->mimeData()->hasFormat("application/x-keepassx-entry")
|
||||
&& (dropIndicatorPosition() == AboveItem || dropIndicatorPosition() == BelowItem)) {
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GroupView::dropEvent(QDropEvent* event)
|
||||
{
|
||||
fixDropAction(event);
|
||||
QTreeView::dropEvent(event);
|
||||
}
|
||||
|
||||
void GroupView::focusInEvent(QFocusEvent* event)
|
||||
{
|
||||
emit groupFocused();
|
||||
@ -151,6 +159,39 @@ void GroupView::recInitExpanded(Group* group)
|
||||
}
|
||||
}
|
||||
|
||||
void GroupView::fixDropAction(QDropEvent* event)
|
||||
{
|
||||
if (event->keyboardModifiers().testFlag(Qt::ControlModifier) && event->possibleActions().testFlag(Qt::CopyAction)) {
|
||||
event->setDropAction(Qt::CopyAction);
|
||||
} else if (event->keyboardModifiers().testFlag(Qt::ShiftModifier)
|
||||
&& event->possibleActions().testFlag(Qt::MoveAction)) {
|
||||
event->setDropAction(Qt::MoveAction);
|
||||
} else {
|
||||
static const QString groupMimeDataType = "application/x-keepassx-group";
|
||||
static const QString entryMimeDataType = "application/x-keepassx-entry";
|
||||
|
||||
bool isGroup = event->mimeData()->hasFormat(groupMimeDataType);
|
||||
bool isEntry = event->mimeData()->hasFormat(entryMimeDataType);
|
||||
|
||||
if (isGroup || isEntry) {
|
||||
QByteArray encoded = event->mimeData()->data(isGroup ? groupMimeDataType : entryMimeDataType);
|
||||
QDataStream stream(&encoded, QIODevice::ReadOnly);
|
||||
|
||||
QUuid dbUuid;
|
||||
QUuid itemUuid;
|
||||
stream >> dbUuid >> itemUuid;
|
||||
|
||||
if (dbUuid != m_model->database()->uuid()) {
|
||||
if (event->possibleActions().testFlag(Qt::CopyAction)) {
|
||||
event->setDropAction(Qt::CopyAction);
|
||||
} else if (event->possibleActions().testFlag(Qt::MoveAction)) {
|
||||
event->setDropAction(Qt::MoveAction);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GroupView::expandGroup(Group* group, bool expand)
|
||||
{
|
||||
QModelIndex index = m_model->index(group);
|
||||
|
@ -51,10 +51,12 @@ private slots:
|
||||
|
||||
protected:
|
||||
void dragMoveEvent(QDragMoveEvent* event) override;
|
||||
void dropEvent(QDropEvent* event) override;
|
||||
void focusInEvent(QFocusEvent* event) override;
|
||||
|
||||
private:
|
||||
void recInitExpanded(Group* group);
|
||||
void fixDropAction(QDropEvent* event);
|
||||
|
||||
GroupModel* const m_model;
|
||||
bool m_updatingExpanded;
|
||||
|
Loading…
Reference in New Issue
Block a user