mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-12 16:09:37 -05:00
added QStyledItemDelegate based on ChannelFilesStatusWidget. Not working yet.
This commit is contained in:
parent
a5dd33e085
commit
b9c41b31d4
@ -30,8 +30,8 @@
|
|||||||
|
|
||||||
#include "retroshare/rsfiles.h"
|
#include "retroshare/rsfiles.h"
|
||||||
|
|
||||||
GxsChannelFilesStatusWidget::GxsChannelFilesStatusWidget(const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, const RsGxsFile &file, QWidget *parent) :
|
GxsChannelFilesStatusWidget::GxsChannelFilesStatusWidget(const RsGxsFile &file, QWidget *parent) :
|
||||||
QWidget(parent), mGroupId(groupId), mMessageId(messageId), mFile(file), ui(new Ui::GxsChannelFilesStatusWidget)
|
QWidget(parent), mFile(file), ui(new Ui::GxsChannelFilesStatusWidget)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ class GxsChannelFilesStatusWidget : public QWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit GxsChannelFilesStatusWidget(const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, const RsGxsFile &file, QWidget *parent = 0);
|
explicit GxsChannelFilesStatusWidget(const RsGxsFile &file, QWidget *parent = 0);
|
||||||
~GxsChannelFilesStatusWidget();
|
~GxsChannelFilesStatusWidget();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -113,7 +113,7 @@ void GxsChannelFilesWidget::addFiles(const RsGxsChannelPost& post, bool related)
|
|||||||
|
|
||||||
ui->treeWidget->addTopLevelItem(treeItem);
|
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);
|
ui->treeWidget->setItemWidget(treeItem, COLUMN_STATUS, statusWidget);
|
||||||
|
|
||||||
filterItem(treeItem);
|
filterItem(treeItem);
|
||||||
|
@ -24,12 +24,10 @@
|
|||||||
|
|
||||||
#include "retroshare/rsgxscircles.h"
|
#include "retroshare/rsgxscircles.h"
|
||||||
|
|
||||||
#include "GxsChannelPostsWidgetWithModel.h"
|
|
||||||
#include "GxsChannelPostsModel.h"
|
|
||||||
#include "GxsChannelPostFilesModel.h"
|
|
||||||
#include "ui_GxsChannelPostsWidgetWithModel.h"
|
#include "ui_GxsChannelPostsWidgetWithModel.h"
|
||||||
#include "gui/feeds/GxsChannelPostItem.h"
|
#include "gui/feeds/GxsChannelPostItem.h"
|
||||||
#include "gui/gxs/GxsIdDetails.h"
|
#include "gui/gxs/GxsIdDetails.h"
|
||||||
|
#include "util/misc.h"
|
||||||
#include "gui/gxschannels/CreateGxsChannelMsg.h"
|
#include "gui/gxschannels/CreateGxsChannelMsg.h"
|
||||||
#include "gui/common/UIStateHelper.h"
|
#include "gui/common/UIStateHelper.h"
|
||||||
#include "gui/settings/rsharesettings.h"
|
#include "gui/settings/rsharesettings.h"
|
||||||
@ -40,6 +38,11 @@
|
|||||||
#include "util/DateTime.h"
|
#include "util/DateTime.h"
|
||||||
#include "util/qtthreadsutils.h"
|
#include "util/qtthreadsutils.h"
|
||||||
|
|
||||||
|
#include "GxsChannelPostsWidgetWithModel.h"
|
||||||
|
#include "GxsChannelPostsModel.h"
|
||||||
|
#include "GxsChannelPostFilesModel.h"
|
||||||
|
#include "GxsChannelFilesStatusWidget.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#define CHAN_DEFAULT_IMAGE ":/icons/png/channels.png"
|
#define CHAN_DEFAULT_IMAGE ":/icons/png/channels.png"
|
||||||
@ -51,6 +54,7 @@
|
|||||||
***/
|
***/
|
||||||
|
|
||||||
static const int mTokenTypeGroupData = 1;
|
static const int mTokenTypeGroupData = 1;
|
||||||
|
|
||||||
static const int CHANNEL_TABS_DETAILS= 0;
|
static const int CHANNEL_TABS_DETAILS= 0;
|
||||||
static const int CHANNEL_TABS_POSTS = 1;
|
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_FEEDS 1
|
||||||
#define VIEW_MODE_FILES 2
|
#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)
|
Q_DECLARE_METATYPE(RsGxsFile)
|
||||||
|
|
||||||
void ChannelPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
|
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);
|
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
|
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")};
|
QString byteUnits[4] = {tr("B"), tr("KB"), tr("MB"), tr("GB")};
|
||||||
|
|
||||||
QStyleOptionViewItem opt = option;
|
QStyleOptionViewItem opt = option;
|
||||||
@ -154,13 +185,14 @@ void ChannelPostFilesDelegate::paint(QPainter * painter, const QStyleOptionViewI
|
|||||||
qlonglong completed;
|
qlonglong completed;
|
||||||
qlonglong downloadtime;
|
qlonglong downloadtime;
|
||||||
qint64 qi64Value;
|
qint64 qi64Value;
|
||||||
|
#endif
|
||||||
|
|
||||||
// prepare
|
// prepare
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->setClipRect(opt.rect);
|
painter->setClipRect(option.rect);
|
||||||
|
|
||||||
|
#ifdef TODO
|
||||||
RsGxsFile file = index.data(Qt::UserRole).value<RsGxsFile>() ;
|
RsGxsFile file = index.data(Qt::UserRole).value<RsGxsFile>() ;
|
||||||
|
|
||||||
QVariant value = index.data(Qt::TextColorRole);
|
QVariant value = index.data(Qt::TextColorRole);
|
||||||
|
|
||||||
if(value.isValid() && qvariant_cast<QColor>(value).isValid())
|
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));
|
painter->setPen(opt.palette.color(cg, QPalette::HighlightedText));
|
||||||
else
|
else
|
||||||
painter->setPen(opt.palette.color(cg, QPalette::Text));
|
painter->setPen(opt.palette.color(cg, QPalette::Text));
|
||||||
|
#endif
|
||||||
|
|
||||||
switch(index.column())
|
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;
|
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;
|
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;
|
FileInfo finfo;
|
||||||
if(rsFiles->FileDetails(file.mHash,RS_FILE_HINTS_DOWNLOAD,finfo))
|
if(rsFiles->FileDetails(file.mHash,RS_FILE_HINTS_DOWNLOAD,finfo))
|
||||||
painter->drawText(option.rect,Qt::AlignLeft,QString::number(finfo.transfered));
|
painter->drawText(option.rect,Qt::AlignLeft,QString::number(finfo.transfered));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
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())
|
switch(index.column())
|
||||||
{
|
{
|
||||||
case 0: return QSize(fm.width(QString::fromUtf8(file.mName.c_str())),fm.height());
|
case CHANNEL_FILES_COLUMN_NAME: 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_SIZE: return QSize(fm.width(misc::friendlyUnit(qulonglong(file.mSize))),fm.height());
|
||||||
default:
|
default:
|
||||||
case 2: return QSize(fm.height() * 20,fm.height()) ;
|
case CHANNEL_FILES_COLUMN_FILE: return GxsChannelFilesStatusWidget(file).size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include <QAbstractItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
#include "gui/gxs/GxsMessageFramePostWidget.h"
|
#include "gui/gxs/GxsMessageFramePostWidget.h"
|
||||||
#include "gui/feeds/FeedHolder.h"
|
#include "gui/feeds/FeedHolder.h"
|
||||||
@ -38,17 +38,21 @@ class FeedItem;
|
|||||||
class RsGxsChannelPostsModel;
|
class RsGxsChannelPostsModel;
|
||||||
class RsGxsChannelPostFilesModel;
|
class RsGxsChannelPostFilesModel;
|
||||||
|
|
||||||
class ChannelPostFilesDelegate: public QAbstractItemDelegate
|
class ChannelPostFilesDelegate: public QStyledItemDelegate
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ChannelPostFilesDelegate(QObject *parent=0) : QAbstractItemDelegate(parent){}
|
ChannelPostFilesDelegate(QObject *parent=0) : QStyledItemDelegate(parent){}
|
||||||
virtual ~ChannelPostFilesDelegate(){}
|
virtual ~ChannelPostFilesDelegate(){}
|
||||||
|
|
||||||
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const override;
|
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const override;
|
||||||
QSize sizeHint(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:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -413,9 +413,27 @@ p, li { white-space: pre-wrap; }
|
|||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QTreeView" name="postsTree">
|
<widget class="QTreeView" name="postsTree">
|
||||||
|
<property name="sizeAdjustPolicy">
|
||||||
|
<enum>QAbstractScrollArea::AdjustToContents</enum>
|
||||||
|
</property>
|
||||||
<property name="selectionBehavior">
|
<property name="selectionBehavior">
|
||||||
<enum>QAbstractItemView::SelectItems</enum>
|
<enum>QAbstractItemView::SelectItems</enum>
|
||||||
</property>
|
</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">
|
<attribute name="headerStretchLastSection">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</attribute>
|
</attribute>
|
||||||
@ -475,7 +493,14 @@ p, li { white-space: pre-wrap; }
|
|||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||||
<item>
|
<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>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="channelPostFilesDL_PB">
|
<widget class="QPushButton" name="channelPostFilesDL_PB">
|
||||||
|
Loading…
Reference in New Issue
Block a user