added QStyledItemDelegate based on ChannelFilesStatusWidget. Not working yet.

This commit is contained in:
csoler 2020-06-05 17:34:56 +02:00
parent a5dd33e085
commit b9c41b31d4
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
6 changed files with 93 additions and 21 deletions

View File

@ -30,8 +30,8 @@
#include "retroshare/rsfiles.h"
GxsChannelFilesStatusWidget::GxsChannelFilesStatusWidget(const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, const RsGxsFile &file, QWidget *parent) :
QWidget(parent), mGroupId(groupId), mMessageId(messageId), mFile(file), ui(new Ui::GxsChannelFilesStatusWidget)
GxsChannelFilesStatusWidget::GxsChannelFilesStatusWidget(const RsGxsFile &file, QWidget *parent) :
QWidget(parent), mFile(file), ui(new Ui::GxsChannelFilesStatusWidget)
{
ui->setupUi(this);

View File

@ -34,7 +34,7 @@ class GxsChannelFilesStatusWidget : public QWidget
Q_OBJECT
public:
explicit GxsChannelFilesStatusWidget(const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, const RsGxsFile &file, QWidget *parent = 0);
explicit GxsChannelFilesStatusWidget(const RsGxsFile &file, QWidget *parent = 0);
~GxsChannelFilesStatusWidget();
private slots:

View File

@ -113,7 +113,7 @@ void GxsChannelFilesWidget::addFiles(const RsGxsChannelPost& post, bool related)
ui->treeWidget->addTopLevelItem(treeItem);
QWidget *statusWidget = new GxsChannelFilesStatusWidget(post.mMeta.mGroupId, post.mMeta.mMsgId, file);
QWidget *statusWidget = new GxsChannelFilesStatusWidget(file);
ui->treeWidget->setItemWidget(treeItem, COLUMN_STATUS, statusWidget);
filterItem(treeItem);

View File

@ -24,12 +24,10 @@
#include "retroshare/rsgxscircles.h"
#include "GxsChannelPostsWidgetWithModel.h"
#include "GxsChannelPostsModel.h"
#include "GxsChannelPostFilesModel.h"
#include "ui_GxsChannelPostsWidgetWithModel.h"
#include "gui/feeds/GxsChannelPostItem.h"
#include "gui/gxs/GxsIdDetails.h"
#include "util/misc.h"
#include "gui/gxschannels/CreateGxsChannelMsg.h"
#include "gui/common/UIStateHelper.h"
#include "gui/settings/rsharesettings.h"
@ -40,6 +38,11 @@
#include "util/DateTime.h"
#include "util/qtthreadsutils.h"
#include "GxsChannelPostsWidgetWithModel.h"
#include "GxsChannelPostsModel.h"
#include "GxsChannelPostFilesModel.h"
#include "GxsChannelFilesStatusWidget.h"
#include <algorithm>
#define CHAN_DEFAULT_IMAGE ":/icons/png/channels.png"
@ -51,6 +54,7 @@
***/
static const int mTokenTypeGroupData = 1;
static const int CHANNEL_TABS_DETAILS= 0;
static const int CHANNEL_TABS_POSTS = 1;
@ -58,6 +62,10 @@ static const int CHANNEL_TABS_POSTS = 1;
#define VIEW_MODE_FEEDS 1
#define VIEW_MODE_FILES 2
#define CHANNEL_FILES_COLUMN_NAME 0
#define CHANNEL_FILES_COLUMN_SIZE 1
#define CHANNEL_FILES_COLUMN_FILE 2
Q_DECLARE_METATYPE(RsGxsFile)
void ChannelPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
@ -138,8 +146,31 @@ QSize ChannelPostDelegate::sizeHint(const QStyleOptionViewItem& option, const QM
return QSize(W+IMAGE_MARGIN_FACTOR*w,H + 2*h);
}
QWidget *ChannelPostFilesDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const
{
RsGxsFile file = index.data(Qt::UserRole).value<RsGxsFile>() ;
if(index.column() == CHANNEL_FILES_COLUMN_FILE)
return new GxsChannelFilesStatusWidget(file,parent);
else
return NULL;
}
void ChannelPostFilesDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
{
editor->setGeometry(option.rect);
}
void ChannelPostFilesDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
// nothing to do here. Is this override needed?
}
void ChannelPostFilesDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
RsGxsFile file = index.data(Qt::UserRole).value<RsGxsFile>() ;
#ifdef TODO
QString byteUnits[4] = {tr("B"), tr("KB"), tr("MB"), tr("GB")};
QStyleOptionViewItem opt = option;
@ -154,13 +185,14 @@ void ChannelPostFilesDelegate::paint(QPainter * painter, const QStyleOptionViewI
qlonglong completed;
qlonglong downloadtime;
qint64 qi64Value;
#endif
// prepare
painter->save();
painter->setClipRect(opt.rect);
painter->setClipRect(option.rect);
#ifdef TODO
RsGxsFile file = index.data(Qt::UserRole).value<RsGxsFile>() ;
QVariant value = index.data(Qt::TextColorRole);
if(value.isValid() && qvariant_cast<QColor>(value).isValid())
@ -172,21 +204,32 @@ void ChannelPostFilesDelegate::paint(QPainter * painter, const QStyleOptionViewI
painter->setPen(opt.palette.color(cg, QPalette::HighlightedText));
else
painter->setPen(opt.palette.color(cg, QPalette::Text));
#endif
switch(index.column())
{
case 0: painter->drawText(option.rect,Qt::AlignLeft,QString::fromUtf8(file.mName.c_str()));
case CHANNEL_FILES_COLUMN_NAME: painter->drawText(option.rect,Qt::AlignLeft | Qt::AlignVCenter,QString::fromUtf8(file.mName.c_str()));
break;
case 1: painter->drawText(option.rect,Qt::AlignLeft,QString::number(file.mSize));
case CHANNEL_FILES_COLUMN_SIZE: painter->drawText(option.rect,Qt::AlignLeft | Qt::AlignVCenter,misc::friendlyUnit(qulonglong(file.mSize)));
break;
case 2: {
case CHANNEL_FILES_COLUMN_FILE: {
GxsChannelFilesStatusWidget w(file);
QPixmap pixmap(w.size());
w.render(&pixmap);
painter->drawPixmap(option.rect.topLeft(),pixmap);
#ifdef TODO
FileInfo finfo;
if(rsFiles->FileDetails(file.mHash,RS_FILE_HINTS_DOWNLOAD,finfo))
painter->drawText(option.rect,Qt::AlignLeft,QString::number(finfo.transfered));
#endif
}
break;
default:
break;
default:
painter->drawText(option.rect,Qt::AlignLeft,QString("[No data]"));
break;
}
}
@ -198,10 +241,10 @@ QSize ChannelPostFilesDelegate::sizeHint(const QStyleOptionViewItem& option, con
switch(index.column())
{
case 0: return QSize(fm.width(QString::fromUtf8(file.mName.c_str())),fm.height());
case 1: return QSize(fm.width(QString::number(file.mSize)),fm.height());
case CHANNEL_FILES_COLUMN_NAME: return QSize(fm.width(QString::fromUtf8(file.mName.c_str())),fm.height());
case CHANNEL_FILES_COLUMN_SIZE: return QSize(fm.width(misc::friendlyUnit(qulonglong(file.mSize))),fm.height());
default:
case 2: return QSize(fm.height() * 20,fm.height()) ;
case CHANNEL_FILES_COLUMN_FILE: return GxsChannelFilesStatusWidget(file).size();
}
}

View File

@ -23,7 +23,7 @@
#include <map>
#include <QAbstractItemDelegate>
#include <QStyledItemDelegate>
#include "gui/gxs/GxsMessageFramePostWidget.h"
#include "gui/feeds/FeedHolder.h"
@ -38,17 +38,21 @@ class FeedItem;
class RsGxsChannelPostsModel;
class RsGxsChannelPostFilesModel;
class ChannelPostFilesDelegate: public QAbstractItemDelegate
class ChannelPostFilesDelegate: public QStyledItemDelegate
{
Q_OBJECT
public:
ChannelPostFilesDelegate(QObject *parent=0) : QAbstractItemDelegate(parent){}
ChannelPostFilesDelegate(QObject *parent=0) : QStyledItemDelegate(parent){}
virtual ~ChannelPostFilesDelegate(){}
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const override;
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &) const override;
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
void setEditorData(QWidget *editor, const QModelIndex &index) const override;
private:
};

View File

@ -413,9 +413,27 @@ p, li { white-space: pre-wrap; }
<enum>Qt::Vertical</enum>
</property>
<widget class="QTreeView" name="postsTree">
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectItems</enum>
</property>
<property name="indentation">
<number>0</number>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="itemsExpandable">
<bool>false</bool>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="headerHidden">
<bool>true</bool>
</property>
<attribute name="headerStretchLastSection">
<bool>false</bool>
</attribute>
@ -475,7 +493,14 @@ p, li { white-space: pre-wrap; }
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QTreeView" name="channelPostFiles_TV"/>
<widget class="QTreeView" name="channelPostFiles_TV">
<property name="editTriggers">
<set>QAbstractItemView::CurrentChanged</set>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="channelPostFilesDL_PB">