improved design: moved channel details+posts into tabs, and added tabs for comments+post details

This commit is contained in:
csoler 2020-06-03 21:06:37 +02:00
parent 5a6c8de005
commit da968379d6
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
3 changed files with 332 additions and 304 deletions

View File

@ -20,6 +20,7 @@
#include <QDateTime> #include <QDateTime>
#include <QSignalMapper> #include <QSignalMapper>
#include <QPainter>
#include "retroshare/rsgxscircles.h" #include "retroshare/rsgxscircles.h"
@ -52,6 +53,86 @@
#define VIEW_MODE_FEEDS 1 #define VIEW_MODE_FEEDS 1
#define VIEW_MODE_FILES 2 #define VIEW_MODE_FILES 2
Q_DECLARE_METATYPE(RsGxsChannelPost*)
void ChannelPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
QString byteUnits[4] = {tr("B"), tr("KB"), tr("MB"), tr("GB")};
QStyleOptionViewItem opt = option;
QStyleOptionProgressBarV2 newopt;
QRect pixmapRect;
QPixmap pixmap;
qlonglong fileSize;
double dlspeed, multi;
int seconds,minutes, hours, days;
qlonglong remaining;
QString temp ;
qlonglong completed;
qlonglong downloadtime;
qint64 qi64Value;
// prepare
painter->save();
painter->setClipRect(opt.rect);
RsGxsChannelPost post = index.data(Qt::UserRole).value<RsGxsChannelPost>() ;
//const RsGxsChannelPost& post(*pinfo);
QVariant value = index.data(Qt::TextColorRole);
if(value.isValid() && qvariant_cast<QColor>(value).isValid())
opt.palette.setColor(QPalette::Text, qvariant_cast<QColor>(value));
QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;
if(option.state & QStyle::State_Selected)
painter->setPen(opt.palette.color(cg, QPalette::HighlightedText));
else
painter->setPen(opt.palette.color(cg, QPalette::Text));
//painter->drawText(option.rect, Qt::AlignRight, QString("TODO"));
QPixmap thumbnail;
GxsIdDetails::loadPixmapFromData(post.mThumbnail.mData, post.mThumbnail.mSize, thumbnail,GxsIdDetails::ORIGINAL);
QFontMetricsF fm(opt.font);
int W = IMAGE_SIZE_FACTOR_W * fm.height() * IMAGE_ZOOM_FACTOR;
int H = IMAGE_SIZE_FACTOR_H * fm.height() * IMAGE_ZOOM_FACTOR;
int w = fm.width("X") ;
int h = fm.height() ;
float img_coord_x = IMAGE_MARGIN_FACTOR*0.5*w;
float img_coord_y = IMAGE_MARGIN_FACTOR*0.5*h;
QPoint img_pos(img_coord_x,img_coord_y);
QPoint img_size(W,H);
QPoint txt_pos(0,img_coord_y + H + h);
painter->drawPixmap(QRect(opt.rect.topLeft() + img_pos,opt.rect.topLeft()+img_pos+img_size),thumbnail.scaled(W,H,Qt::KeepAspectRatio,Qt::SmoothTransformation));
painter->drawText(QRect(option.rect.topLeft() + txt_pos,option.rect.bottomRight()),Qt::AlignCenter,QString::fromStdString(post.mMeta.mMsgName));
}
QSize ChannelPostDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{
RsGxsChannelPost post = index.data(Qt::UserRole).value<RsGxsChannelPost>() ;
//QPixmap thumbnail;
//GxsIdDetails::loadPixmapFromData(post.mThumbnail.mData, post.mThumbnail.mSize, thumbnail,GxsIdDetails::ORIGINAL);
QFontMetricsF fm(option.font);
int W = IMAGE_SIZE_FACTOR_W * fm.height() * IMAGE_ZOOM_FACTOR;
int H = IMAGE_SIZE_FACTOR_H * fm.height() * IMAGE_ZOOM_FACTOR;
int h = fm.height() ;
int w = fm.width("X") ;
return QSize(W+IMAGE_MARGIN_FACTOR*w,H + 2*h);
}
/** Constructor */ /** Constructor */
GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupId &channelId, QWidget *parent) : GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupId &channelId, QWidget *parent) :
GxsMessageFrameWidget(rsGxsChannels, parent), GxsMessageFrameWidget(rsGxsChannels, parent),
@ -61,6 +142,9 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
ui->setupUi(this); ui->setupUi(this);
ui->postsTree->setModel(mThreadModel = new RsGxsChannelPostsModel()); ui->postsTree->setModel(mThreadModel = new RsGxsChannelPostsModel());
ui->postsTree->setItemDelegate(new ChannelPostDelegate());
connect(ui->postsTree->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),this,SLOT(showPostDetails()));
/* Setup UI helper */ /* Setup UI helper */
@ -95,7 +179,7 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
/* Initialize view button */ /* Initialize view button */
//setViewMode(VIEW_MODE_FEEDS); see processSettings //setViewMode(VIEW_MODE_FEEDS); see processSettings
ui->infoWidget->hide(); //ui->infoWidget->hide();
QSignalMapper *signalMapper = new QSignalMapper(this); QSignalMapper *signalMapper = new QSignalMapper(this);
connect(ui->feedToolButton, SIGNAL(clicked()), signalMapper, SLOT(map())); connect(ui->feedToolButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
@ -109,7 +193,7 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
ui->loadingLabel->hide(); ui->loadingLabel->hide();
ui->progressBar->hide(); ui->progressBar->hide();
ui->nameLabel->setMinimumWidth(20); //ui->nameLabel->setMinimumWidth(20);
/* Initialize feed widget */ /* Initialize feed widget */
//ui->feedWidget->setSortRole(ROLE_PUBLISH, Qt::DescendingOrder); //ui->feedWidget->setSortRole(ROLE_PUBLISH, Qt::DescendingOrder);
@ -169,6 +253,13 @@ void GxsChannelPostsWidgetWithModel::handleEvent_main_thread(std::shared_ptr<con
} }
} }
void GxsChannelPostsWidgetWithModel::showPostDetails()
{
QModelIndex selected_index = ui->postsTree->selectionModel()->currentIndex();
std::cerr << "Showing details about selected index : "<< selected_index.row() << "," << selected_index.column() << std::endl;
}
void GxsChannelPostsWidgetWithModel::updateGroupData() void GxsChannelPostsWidgetWithModel::updateGroupData()
{ {
if(groupId().isNull()) if(groupId().isNull())
@ -280,12 +371,12 @@ QString GxsChannelPostsWidgetWithModel::groupName(bool)
void GxsChannelPostsWidgetWithModel::groupNameChanged(const QString &name) void GxsChannelPostsWidgetWithModel::groupNameChanged(const QString &name)
{ {
if (groupId().isNull()) { // if (groupId().isNull()) {
ui->nameLabel->setText(tr("No Channel Selected")); // ui->nameLabel->setText(tr("No Channel Selected"));
ui->logoLabel->setPixmap(QPixmap(":/icons/png/channels.png")); // ui->logoLabel->setPixmap(QPixmap(":/icons/png/channels.png"));
} else { // } else {
ui->nameLabel->setText(name); // ui->nameLabel->setText(name);
} // }
} }
QIcon GxsChannelPostsWidgetWithModel::groupIcon() QIcon GxsChannelPostsWidgetWithModel::groupIcon()
@ -336,7 +427,7 @@ void GxsChannelPostsWidgetWithModel::insertChannelDetails(const RsGxsChannelGrou
} else { } else {
chanImage = QPixmap(CHAN_DEFAULT_IMAGE); chanImage = QPixmap(CHAN_DEFAULT_IMAGE);
} }
ui->logoLabel->setPixmap(chanImage); //ui->logoLabel->setPixmap(chanImage);
if (group.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_PUBLISH) if (group.mMeta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_PUBLISH)
{ {
@ -361,7 +452,7 @@ void GxsChannelPostsWidgetWithModel::insertChannelDetails(const RsGxsChannelGrou
ui->feedToolButton->setEnabled(true); ui->feedToolButton->setEnabled(true);
ui->fileToolButton->setEnabled(true); ui->fileToolButton->setEnabled(true);
ui->infoWidget->hide(); //ui->infoWidget->hide();
setViewMode(viewMode()); setViewMode(viewMode());
ui->subscribeToolButton->setText(tr("Subscribed") + " " + QString::number(group.mMeta.mPop) ); ui->subscribeToolButton->setText(tr("Subscribed") + " " + QString::number(group.mMeta.mPop) );
@ -785,7 +876,7 @@ void GxsChannelPostsWidgetWithModel::blank()
mThreadModel->clear(); mThreadModel->clear();
groupNameChanged(QString()); groupNameChanged(QString());
ui->infoWidget->hide(); //ui->infoWidget->hide();
} }
bool GxsChannelPostsWidgetWithModel::navigate(const RsGxsMessageId &msgId) bool GxsChannelPostsWidgetWithModel::navigate(const RsGxsMessageId &msgId)

View File

@ -23,8 +23,9 @@
#include <map> #include <map>
#include "gui/gxs/GxsMessageFramePostWidget.h" #include <QAbstractItemDelegate>
#include "gui/gxs/GxsMessageFramePostWidget.h"
#include "gui/feeds/FeedHolder.h" #include "gui/feeds/FeedHolder.h"
namespace Ui { namespace Ui {
@ -36,6 +37,24 @@ class QTreeWidgetItem;
class FeedItem; class FeedItem;
class RsGxsChannelPostsModel; class RsGxsChannelPostsModel;
class ChannelPostDelegate: public QAbstractItemDelegate
{
Q_OBJECT
public:
ChannelPostDelegate(QObject *parent=0) : QAbstractItemDelegate(parent){}
virtual ~ChannelPostDelegate(){}
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const override;
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;
private:
static constexpr float IMAGE_MARGIN_FACTOR = 1.0;
static constexpr float IMAGE_SIZE_FACTOR_W = 4.0 ;
static constexpr float IMAGE_SIZE_FACTOR_H = 6.0 ;
static constexpr float IMAGE_ZOOM_FACTOR = 1.0;
};
class GxsChannelPostsWidgetWithModel: public GxsMessageFrameWidget class GxsChannelPostsWidgetWithModel: public GxsMessageFrameWidget
{ {
Q_OBJECT Q_OBJECT
@ -91,6 +110,7 @@ protected:
virtual void setAllMessagesReadDo(bool read, uint32_t &token); virtual void setAllMessagesReadDo(bool read, uint32_t &token);
private slots: private slots:
void showPostDetails();
void updateGroupData(); void updateGroupData();
void createMsg(); void createMsg();
void toggleAutoDownload(); void toggleAutoDownload();

View File

@ -26,69 +26,6 @@
<property name="bottomMargin"> <property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item>
<widget class="QFrame" name="headFrame">
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<widget class="QLabel" name="logoLabel">
<property name="minimumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap>:/images/channels.png</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="StyledElidedLabel" name="nameLabel">
<property name="palette">
<palette>
<active/>
<inactive/>
<disabled/>
</palette>
</property>
<property name="text">
<string notr="true">Channel Name</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item> <item>
<widget class="QFrame" name="toolBarFrame"> <widget class="QFrame" name="toolBarFrame">
<property name="frameShape"> <property name="frameShape">
@ -285,48 +222,16 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QWidget" name="infoWidget" native="true"> <widget class="QTabWidget" name="tabWidget">
<property name="styleSheet"> <property name="currentIndex">
<string notr="true"/>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>0</number> <number>0</number>
</property> </property>
<property name="rightMargin"> <widget class="QWidget" name="tab_3">
<number>3</number> <attribute name="title">
</property> <string>Channel details</string>
<property name="bottomMargin"> </attribute>
<number>3</number> <layout class="QHBoxLayout" name="horizontalLayout_3">
</property>
<item> <item>
<widget class="QFrame" name="infoFrame">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>6</number>
</property>
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBox">
<property name="title"> <property name="title">
<string>Channel details</string> <string>Channel details</string>
@ -497,25 +402,46 @@ p, li { white-space: pre-wrap; }
</item> </item>
</layout> </layout>
</widget> </widget>
</item> <widget class="QWidget" name="tab_4">
<attribute name="title">
<string>Posts</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item> <item>
<spacer name="verticalSpacer"> <widget class="QTreeView" name="postsTree">
<property name="orientation"> <property name="selectionBehavior">
<enum>Qt::Vertical</enum> <enum>QAbstractItemView::SelectItems</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <attribute name="headerStretchLastSection">
<size> <bool>false</bool>
<width>0</width> </attribute>
<height>0</height> </widget>
</size>
</property>
</spacer>
</item> </item>
</layout> </layout>
</widget> </widget>
</widget>
</item> </item>
<item> <item>
<widget class="QTreeView" name="postsTree"/> <widget class="QTabWidget" name="details_TW">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Details</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTextEdit" name="textEdit"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Comments</string>
</attribute>
</widget>
</widget>
</item> </item>
</layout> </layout>
<action name="actionFeeds"> <action name="actionFeeds">
@ -528,10 +454,6 @@ p, li { white-space: pre-wrap; }
<string>Files</string> <string>Files</string>
</property> </property>
</action> </action>
<zorder>toolBarFrame</zorder>
<zorder>headFrame</zorder>
<zorder>infoWidget</zorder>
<zorder>postsTree</zorder>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
@ -544,11 +466,6 @@ p, li { white-space: pre-wrap; }
<extends>QToolButton</extends> <extends>QToolButton</extends>
<header>gui/common/SubscribeToolButton.h</header> <header>gui/common/SubscribeToolButton.h</header>
</customwidget> </customwidget>
<customwidget>
<class>StyledElidedLabel</class>
<extends>QLabel</extends>
<header>gui/common/StyledElidedLabel.h</header>
</customwidget>
<customwidget> <customwidget>
<class>LineEditClear</class> <class>LineEditClear</class>
<extends>QLineEdit</extends> <extends>QLineEdit</extends>
@ -556,8 +473,8 @@ p, li { white-space: pre-wrap; }
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="../icons.qrc"/>
<include location="../images.qrc"/> <include location="../images.qrc"/>
<include location="../icons.qrc"/>
</resources> </resources>
<connections/> <connections/>
</ui> </ui>