Some work about adaptive color scheme for Web UI (PR #19901)
http://[316:c51a:62a3:8b9::4]/d4708/qBittorrent/src/branch/adaptive-webui
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
3.0 KiB
112 lines
3.0 KiB
#ifndef FEEDLIST_H |
|
#define FEEDLIST_H |
|
|
|
#include <QTreeWidget> |
|
#include <QTreeWidgetItem> |
|
#include <QDropEvent> |
|
#include <QDragMoveEvent> |
|
#include <QStringList> |
|
#include <QHash> |
|
#include <QUrl> |
|
#include "rss.h" |
|
|
|
class FeedList : public QTreeWidget { |
|
|
|
private: |
|
RssManager *rssmanager; |
|
QHash<QTreeWidgetItem*, RssFile*> mapping; |
|
QHash<QString, QTreeWidgetItem*> feeds_items; |
|
QTreeWidgetItem* current_feed; |
|
|
|
public: |
|
FeedList(QWidget *parent, RssManager *rssmanager): QTreeWidget(parent), rssmanager(rssmanager) { |
|
setContextMenuPolicy(Qt::CustomContextMenu); |
|
setDragDropMode(QAbstractItemView::InternalMove); |
|
setSelectionMode(QAbstractItemView::ExtendedSelection); |
|
setColumnCount(1); |
|
QTreeWidgetItem *___qtreewidgetitem = headerItem(); |
|
___qtreewidgetitem->setText(0, QApplication::translate("RSS", "RSS feeds", 0, QApplication::UnicodeUTF8)); |
|
connect(this, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(updateCurrentFeed(QTreeWidgetItem*))); |
|
} |
|
|
|
void itemAdded(QTreeWidgetItem *item, RssFile* file) { |
|
mapping[item] = file; |
|
if(file->getType() == RssFile::STREAM) |
|
feeds_items[file->getID()] = item; |
|
} |
|
|
|
void itemRemoved(QTreeWidgetItem *item) { |
|
RssFile* file = mapping.take(item); |
|
if(file->getType() == RssFile::STREAM) |
|
feeds_items.remove(file->getID()); |
|
} |
|
|
|
bool hasFeed(QString url) { |
|
return feeds_items.contains(QUrl(url).toString()); |
|
} |
|
|
|
RssFile* getRSSItem(QTreeWidgetItem *item) { |
|
return mapping[item]; |
|
} |
|
|
|
RssFile* getCurrentRSSItem() { |
|
return mapping[current_feed]; |
|
} |
|
|
|
RssFile::FileType getItemType(QTreeWidgetItem *item) { |
|
return mapping[item]->getType(); |
|
} |
|
|
|
QString getItemID(QTreeWidgetItem *item) { |
|
return mapping[item]->getID(); |
|
} |
|
|
|
QTreeWidgetItem* getTreeItemFromUrl(QString url) const{ |
|
return feeds_items[url]; |
|
} |
|
|
|
QTreeWidgetItem* currentItem() const { |
|
return current_feed; |
|
} |
|
|
|
QTreeWidgetItem* currentFeed() const { |
|
return current_feed; |
|
} |
|
|
|
protected slots: |
|
void updateCurrentFeed(QTreeWidgetItem* new_item) { |
|
if(getItemType(new_item) == RssFile::STREAM) |
|
current_feed = new_item; |
|
} |
|
|
|
protected: |
|
void dragMoveEvent(QDragMoveEvent * event) { |
|
QTreeWidgetItem *item = itemAt(event->pos()); |
|
if(item && getItemType(item) != RssFile::FOLDER) |
|
event->ignore(); |
|
else { |
|
QTreeWidget::dragMoveEvent(event); |
|
} |
|
} |
|
|
|
void dropEvent(QDropEvent *event) { |
|
qDebug("dropEvent"); |
|
QTreeWidgetItem *dest_folder_item = itemAt(event->pos()); |
|
RssFolder *dest_folder; |
|
if(dest_folder_item) |
|
dest_folder = (RssFolder*)getRSSItem(dest_folder_item); |
|
else |
|
dest_folder = rssmanager; |
|
QList<QTreeWidgetItem *> src_items = selectedItems(); |
|
foreach(QTreeWidgetItem *src_item, src_items) { |
|
RssFile *file = getRSSItem(src_item); |
|
rssmanager->moveFile(file, dest_folder); |
|
} |
|
QTreeWidget::dropEvent(event); |
|
if(dest_folder_item) |
|
dest_folder_item->setExpanded(true); |
|
} |
|
|
|
}; |
|
|
|
#endif // FEEDLIST_H
|
|
|