feat(UI模块): 添加是否响应拖拽设置

This commit is contained in:
huheng@kylinos.cn 2022-11-25 11:33:22 +08:00
parent 1897e73ada
commit 0b1df76404
2 changed files with 8 additions and 1 deletions

View File

@ -142,6 +142,11 @@ FileView::ItemSelectMode FileView::getItemMode() const
return m_itemMode; return m_itemMode;
} }
void FileView::setAllowDrag(bool isAllowDrag)
{
m_isAllowDrag = isAllowDrag;
}
void FileView::mousePressEvent(QMouseEvent *event) void FileView::mousePressEvent(QMouseEvent *event)
{ {
if (!indexAt(event->pos()).isValid()) { if (!indexAt(event->pos()).isValid()) {
@ -181,7 +186,7 @@ void FileView::keyPressEvent(QKeyEvent *event)
void FileView::dragEnterEvent(QDragEnterEvent *event) void FileView::dragEnterEvent(QDragEnterEvent *event)
{ {
if (event->mimeData()->hasUrls() && m_itemMode == ItemSelectMode::Default) { if (m_isAllowDrag && m_itemMode == ItemSelectMode::Default && event->mimeData()->hasUrls()) {
event->accept(); event->accept();
} else { } else {
event->ignore(); event->ignore();

View File

@ -34,6 +34,7 @@ public:
PublicAttributes::Theme getTheme() const; PublicAttributes::Theme getTheme() const;
void setItemMode(FileView::ItemSelectMode mode); void setItemMode(FileView::ItemSelectMode mode);
FileView::ItemSelectMode getItemMode() const; FileView::ItemSelectMode getItemMode() const;
void setAllowDrag(bool isAllowDrag);
protected: protected:
void mousePressEvent(QMouseEvent *event) override; void mousePressEvent(QMouseEvent *event) override;
@ -72,6 +73,7 @@ private:
QListView::ViewMode m_viewModel = QListView::IconMode; // 当前视图模式 QListView::ViewMode m_viewModel = QListView::IconMode; // 当前视图模式
PublicAttributes::Theme m_theme = PublicAttributes::Theme::Light; // 当前主题 PublicAttributes::Theme m_theme = PublicAttributes::Theme::Light; // 当前主题
FileView::ItemSelectMode m_itemMode = FileView::ItemSelectMode::Default; // 当前item视图模式 FileView::ItemSelectMode m_itemMode = FileView::ItemSelectMode::Default; // 当前item视图模式
bool m_isAllowDrag = true;
}; };
#endif // FILEVIEW_H #endif // FILEVIEW_H