mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 06:06:10 -04:00
FeedReader: The feed can be moved with drag and drop to a folder
This commit is contained in:
parent
571f709b50
commit
186976e209
10 changed files with 285 additions and 8 deletions
|
@ -84,9 +84,16 @@ FeedReaderDialog::FeedReaderDialog(RsFeedReader *feedReader, FeedReaderNotify *n
|
|||
connect(ui->feedAddButton, SIGNAL(clicked()), this, SLOT(newFeed()));
|
||||
connect(ui->feedProcessButton, SIGNAL(clicked()), this, SLOT(processFeed()));
|
||||
|
||||
connect(ui->feedTreeWidget, SIGNAL(feedReparent(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(feedTreeReparent(QTreeWidgetItem*,QTreeWidgetItem*)));
|
||||
|
||||
mFeedCompareRole = new RSTreeWidgetItemCompareRole;
|
||||
mFeedCompareRole->setRole(COLUMN_FEED_NAME, ROLE_FEED_SORT);
|
||||
|
||||
/* enable drag and drop */
|
||||
ui->feedTreeWidget->setAcceptDrops(true);
|
||||
ui->feedTreeWidget->setDragEnabled(true);
|
||||
ui->feedTreeWidget->setDragDropMode(QAbstractItemView::InternalMove);
|
||||
|
||||
/* initialize root item */
|
||||
mRootItem = new QTreeWidgetItem(ui->feedTreeWidget);
|
||||
QString name = tr("Message Folders");
|
||||
|
@ -395,6 +402,9 @@ void FeedReaderDialog::updateFeeds(uint32_t parentId, QTreeWidgetItem *parentIte
|
|||
mOpenFeedIds->removeAt(index);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* disable drop */
|
||||
item->setFlags(item->flags() & ~Qt::ItemIsDropEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -832,3 +842,30 @@ void FeedReaderDialog::processFeed()
|
|||
|
||||
mFeedReader->processFeed(feedId);
|
||||
}
|
||||
|
||||
void FeedReaderDialog::feedTreeReparent(QTreeWidgetItem *item, QTreeWidgetItem *newParent)
|
||||
{
|
||||
if (!item || ! newParent) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t feedId = item->data(COLUMN_FEED_DATA, ROLE_FEED_ID).toUInt();
|
||||
uint32_t parentId = newParent->data(COLUMN_FEED_DATA, ROLE_FEED_ID).toUInt();
|
||||
|
||||
if (feedId == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
RsFeedAddResult result = mFeedReader->setParent(feedId, parentId);
|
||||
if (FeedReaderStringDefs::showError(this, result, tr("Move feed"), tr("Cannot move feed."))) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool expanded = item->isExpanded();
|
||||
item->parent()->removeChild(item);
|
||||
newParent->addChild(item);
|
||||
item->setExpanded(expanded);
|
||||
newParent->setExpanded(true);
|
||||
|
||||
calculateFeedItems();
|
||||
}
|
||||
|
|
|
@ -61,6 +61,7 @@ private slots:
|
|||
void editFeed();
|
||||
void activateFeed();
|
||||
void processFeed();
|
||||
void feedTreeReparent(QTreeWidgetItem *item, QTreeWidgetItem *newParent);
|
||||
|
||||
void messageTabCloseRequested(int index);
|
||||
void messageTabChanged(int index);
|
||||
|
|
|
@ -150,7 +150,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="RSTreeWidget" name="feedTreeWidget">
|
||||
<widget class="FeedTreeWidget" name="feedTreeWidget">
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::CustomContextMenu</enum>
|
||||
</property>
|
||||
|
@ -186,9 +186,9 @@
|
|||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>RSTreeWidget</class>
|
||||
<class>FeedTreeWidget</class>
|
||||
<extends>QTreeWidget</extends>
|
||||
<header>gui/common/RSTreeWidget.h</header>
|
||||
<header>gui/FeedTreeWidget.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>RSTabWidget</class>
|
||||
|
|
119
plugins/FeedReader/gui/FeedTreeWidget.cpp
Normal file
119
plugins/FeedReader/gui/FeedTreeWidget.cpp
Normal file
|
@ -0,0 +1,119 @@
|
|||
/*******************************************************************************
|
||||
* plugins/FeedReader/gui/FeedTreeWidget.cpp *
|
||||
* *
|
||||
* Copyright (C) 2012 RetroShare Team <retroshare.project@gmail.com> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Affero General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Affero General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Affero General Public License *
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
|
||||
#include <QDropEvent>
|
||||
#include "FeedTreeWidget.h"
|
||||
|
||||
FeedTreeWidget::FeedTreeWidget(QWidget *parent) : RSTreeWidget(parent)
|
||||
{
|
||||
mDraggedItem = NULL;
|
||||
}
|
||||
|
||||
void FeedTreeWidget::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
mDraggedItem = currentItem();
|
||||
RSTreeWidget::dragEnterEvent(event);
|
||||
}
|
||||
|
||||
void FeedTreeWidget::dragLeaveEvent(QDragLeaveEvent *event)
|
||||
{
|
||||
RSTreeWidget::dragLeaveEvent(event);
|
||||
mDraggedItem = NULL;
|
||||
}
|
||||
|
||||
bool FeedTreeWidget::canDrop(QDropEvent *event, QTreeWidgetItem **dropItem)
|
||||
{
|
||||
if (dropItem) {
|
||||
*dropItem = NULL;
|
||||
}
|
||||
|
||||
if (!mDraggedItem) {
|
||||
/* no drag item */
|
||||
return false;
|
||||
}
|
||||
|
||||
QModelIndex droppedIndex = indexAt(event->pos());
|
||||
if (!droppedIndex.isValid()) {
|
||||
/* no drop target */
|
||||
return false;
|
||||
}
|
||||
|
||||
QTreeWidgetItem *dropItemIntern = itemFromIndex(droppedIndex);
|
||||
if (!dropItemIntern) {
|
||||
/* no drop item */
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((dropItemIntern->flags() & Qt::ItemIsDropEnabled) == 0) {
|
||||
/* drop is disabled */
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dropItemIntern == mDraggedItem->parent()) {
|
||||
/* drag item parent */
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dropItem) {
|
||||
*dropItem = dropItemIntern;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void FeedTreeWidget::dragMoveEvent(QDragMoveEvent *event)
|
||||
{
|
||||
if (!canDrop(event)) {
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
|
||||
RSTreeWidget::dragMoveEvent(event);
|
||||
}
|
||||
|
||||
void FeedTreeWidget::dropEvent(QDropEvent *event)
|
||||
{
|
||||
QTreeWidgetItem *dropItem;
|
||||
if (!canDrop(event, &dropItem)) {
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mDraggedItem) {
|
||||
/* no drag item */
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
|
||||
QTreeWidgetItem *draggedParent = mDraggedItem->parent();
|
||||
if (!draggedParent) {
|
||||
/* no drag item parent */
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dropItem) {
|
||||
/* no drop item */
|
||||
event->ignore();
|
||||
return;
|
||||
}
|
||||
|
||||
emit feedReparent(mDraggedItem, dropItem);
|
||||
}
|
50
plugins/FeedReader/gui/FeedTreeWidget.h
Normal file
50
plugins/FeedReader/gui/FeedTreeWidget.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*******************************************************************************
|
||||
* plugins/FeedReader/gui/FeedTreeWidget.h *
|
||||
* *
|
||||
* Copyright (C) 2012 by Retroshare Team <retroshare.project@gmail.com> *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU Affero General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Affero General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Affero General Public License *
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef _FEEDTREEWIDGET_H
|
||||
#define _FEEDTREEWIDGET_H
|
||||
|
||||
#include "gui/common/RSTreeWidget.h"
|
||||
|
||||
/* Subclassing RSTreeWidget */
|
||||
class FeedTreeWidget : public RSTreeWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FeedTreeWidget(QWidget *parent = 0);
|
||||
|
||||
Q_SIGNALS:
|
||||
void feedReparent(QTreeWidgetItem *item, QTreeWidgetItem *newParent);
|
||||
|
||||
protected:
|
||||
void dragEnterEvent(QDragEnterEvent *event);
|
||||
void dragLeaveEvent(QDragLeaveEvent *event);
|
||||
void dragMoveEvent(QDragMoveEvent *event);
|
||||
void dropEvent(QDropEvent *event);
|
||||
|
||||
private:
|
||||
bool canDrop(QDropEvent *event, QTreeWidgetItem **dropItem = NULL);
|
||||
|
||||
private:
|
||||
QTreeWidgetItem *mDraggedItem;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue