mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-12 16:09:37 -05:00
more work on list view in channels
This commit is contained in:
parent
38f1df2b36
commit
f76264b170
@ -19,49 +19,77 @@
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
#include <QWheelEvent>
|
#include <QWheelEvent>
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
#include "gui/common/FilesDefs.h"
|
#include "gui/common/FilesDefs.h"
|
||||||
#include "gui/gxschannels/GxsChannelPostThumbnail.h"
|
#include "gui/gxschannels/GxsChannelPostThumbnail.h"
|
||||||
|
|
||||||
ChannelPostThumbnailView::ChannelPostThumbnailView(const RsGxsChannelPost& post,QWidget *parent)
|
ChannelPostThumbnailView::ChannelPostThumbnailView(const RsGxsChannelPost& post,uint32_t flags,QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent),mFlags(flags)
|
||||||
{
|
{
|
||||||
// now fill the data
|
// now fill the data
|
||||||
|
|
||||||
QPixmap thumbnail;
|
init(post);
|
||||||
|
|
||||||
if(post.mThumbnail.mSize > 0)
|
|
||||||
GxsIdDetails::loadPixmapFromData(post.mThumbnail.mData, post.mThumbnail.mSize, thumbnail,GxsIdDetails::ORIGINAL);
|
|
||||||
else if(post.mMeta.mPublishTs > 0) // this is for testing that the post is not an empty post (happens at the end of the last row)
|
|
||||||
thumbnail = FilesDefs::getPixmapFromQtResourcePath(CHAN_DEFAULT_IMAGE);
|
|
||||||
|
|
||||||
init(thumbnail, QString::fromUtf8(post.mMeta.mMsgName.c_str()), IS_MSG_UNREAD(post.mMeta.mMsgStatus) || IS_MSG_NEW(post.mMeta.mMsgStatus) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ChannelPostThumbnailView::ChannelPostThumbnailView(QWidget *parent)
|
ChannelPostThumbnailView::ChannelPostThumbnailView(QWidget *parent,uint32_t flags)
|
||||||
: QWidget(parent)
|
: QWidget(parent),mFlags(flags)
|
||||||
{
|
{
|
||||||
init(FilesDefs::getPixmapFromQtResourcePath(CHAN_DEFAULT_IMAGE), QString("New post"),false);
|
init(RsGxsChannelPost());
|
||||||
}
|
}
|
||||||
|
|
||||||
ChannelPostThumbnailView::~ChannelPostThumbnailView()
|
ChannelPostThumbnailView::~ChannelPostThumbnailView()
|
||||||
{
|
{
|
||||||
delete lb;
|
delete mPostImage;
|
||||||
delete lt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChannelPostThumbnailView::init(const QPixmap& thumbnail,const QString& msg,bool is_msg_new)
|
void ChannelPostThumbnailView::init(const RsGxsChannelPost& post)
|
||||||
{
|
{
|
||||||
|
QString msg = QString::fromUtf8(post.mMeta.mMsgName.c_str());
|
||||||
|
bool is_msg_new = IS_MSG_UNREAD(post.mMeta.mMsgStatus) || IS_MSG_NEW(post.mMeta.mMsgStatus);
|
||||||
|
|
||||||
|
QPixmap thumbnail;
|
||||||
|
|
||||||
|
if(post.mThumbnail.mSize > 0)
|
||||||
|
GxsIdDetails::loadPixmapFromData(post.mThumbnail.mData, post.mThumbnail.mSize, thumbnail,GxsIdDetails::ORIGINAL);
|
||||||
|
else if(post.mMeta.mPublishTs > 0) // this is for testing that the post is not an empty post (happens at the end of the last row)
|
||||||
|
thumbnail = FilesDefs::getPixmapFromQtResourcePath(CHAN_DEFAULT_IMAGE);
|
||||||
|
|
||||||
|
mPostImage = new ZoomableLabel(this);
|
||||||
|
mPostImage->setEnableZoom(mFlags & FLAG_ALLOW_PAN);
|
||||||
|
mPostImage->setScaledContents(true);
|
||||||
|
mPostImage->setPicture(thumbnail);
|
||||||
|
|
||||||
|
if(mFlags & FLAG_ALLOW_PAN)
|
||||||
|
mPostImage->setToolTip(tr("Use mouse to center and zoom into the image"));
|
||||||
|
|
||||||
|
mPostTitle = new QLabel(this);
|
||||||
|
|
||||||
|
if(mFlags & FLAG_SHOW_TEXT)
|
||||||
|
{
|
||||||
|
QBoxLayout *layout = new QHBoxLayout(this);
|
||||||
|
|
||||||
|
layout->addWidget(mPostImage);
|
||||||
|
|
||||||
|
QVBoxLayout *vlayout = new QVBoxLayout(this);
|
||||||
|
|
||||||
|
mPostTitle->setText(msg);
|
||||||
|
vlayout->addWidget(mPostTitle);
|
||||||
|
|
||||||
|
QLabel *date_label = new QLabel(this);
|
||||||
|
date_label->setText(QDateTime::fromSecsSinceEpoch(post.mMeta.mPublishTs).toString());
|
||||||
|
vlayout->addWidget(date_label);
|
||||||
|
|
||||||
|
vlayout->addStretch();
|
||||||
|
layout->addLayout(vlayout);
|
||||||
|
setLayout(layout);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||||
|
|
||||||
lb = new ZoomableLabel(this);
|
layout->addWidget(mPostImage);
|
||||||
lb->setScaledContents(true);
|
layout->addWidget(mPostTitle);
|
||||||
lb->setToolTip(tr("Use mouse to center and zoom into the image"));
|
|
||||||
layout->addWidget(lb);
|
|
||||||
|
|
||||||
lt = new QLabel(this);
|
|
||||||
layout->addWidget(lt);
|
|
||||||
|
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum);
|
setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum);
|
||||||
@ -70,28 +98,33 @@ void ChannelPostThumbnailView::init(const QPixmap& thumbnail,const QString& msg,
|
|||||||
int W = THUMBNAIL_OVERSAMPLE_FACTOR * THUMBNAIL_W * fm.height() ;
|
int W = THUMBNAIL_OVERSAMPLE_FACTOR * THUMBNAIL_W * fm.height() ;
|
||||||
int H = THUMBNAIL_OVERSAMPLE_FACTOR * THUMBNAIL_H * fm.height() ;
|
int H = THUMBNAIL_OVERSAMPLE_FACTOR * THUMBNAIL_H * fm.height() ;
|
||||||
|
|
||||||
lb->setFixedSize(W,H);
|
mPostImage->setFixedSize(W,H);
|
||||||
lb->setPicture(thumbnail);
|
|
||||||
|
|
||||||
setText(msg);
|
QString ss = (msg.length() > 30)? (msg.left(30)+"..."):msg;
|
||||||
|
|
||||||
QFont font = lt->font();
|
mPostTitle->setText(ss);
|
||||||
|
|
||||||
|
QFont font = mPostTitle->font();
|
||||||
|
|
||||||
if(is_msg_new)
|
if(is_msg_new)
|
||||||
{
|
{
|
||||||
font.setBold(true);
|
font.setBold(true);
|
||||||
lt->setFont(font);
|
mPostTitle->setFont(font);
|
||||||
}
|
}
|
||||||
|
|
||||||
lt->setMaximumWidth(W);
|
mPostTitle->setMaximumWidth(W);
|
||||||
lt->setWordWrap(true);
|
mPostTitle->setWordWrap(true);
|
||||||
|
}
|
||||||
|
|
||||||
adjustSize();
|
adjustSize();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoomableLabel::mouseMoveEvent(QMouseEvent *me)
|
void ZoomableLabel::mouseMoveEvent(QMouseEvent *me)
|
||||||
{
|
{
|
||||||
|
if(!mZoomEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
float new_center_x = mCenterX - (me->x() - mLastX);
|
float new_center_x = mCenterX - (me->x() - mLastX);
|
||||||
float new_center_y = mCenterY - (me->y() - mLastY);
|
float new_center_y = mCenterY - (me->y() - mLastY);
|
||||||
|
|
||||||
@ -121,6 +154,9 @@ void ZoomableLabel::mouseReleaseEvent(QMouseEvent *)
|
|||||||
}
|
}
|
||||||
void ZoomableLabel::wheelEvent(QWheelEvent *me)
|
void ZoomableLabel::wheelEvent(QWheelEvent *me)
|
||||||
{
|
{
|
||||||
|
if(!mZoomEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
float new_zoom_factor = (me->delta() > 0)?(mZoomFactor*1.05):(mZoomFactor/1.05);
|
float new_zoom_factor = (me->delta() > 0)?(mZoomFactor*1.05):(mZoomFactor/1.05);
|
||||||
float new_center_x = mCenterX;
|
float new_center_x = mCenterX;
|
||||||
float new_center_y = mCenterY;
|
float new_center_y = mCenterY;
|
||||||
|
@ -38,9 +38,10 @@
|
|||||||
class ZoomableLabel: public QLabel
|
class ZoomableLabel: public QLabel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ZoomableLabel(QWidget *parent): QLabel(parent),mZoomFactor(1.0),mCenterX(0.0),mCenterY(0.0) {}
|
ZoomableLabel(QWidget *parent): QLabel(parent),mZoomFactor(1.0),mCenterX(0.0),mCenterY(0.0),mZoomEnabled(true) {}
|
||||||
|
|
||||||
void setPicture(const QPixmap& pix);
|
void setPicture(const QPixmap& pix);
|
||||||
|
void setEnableZoom(bool b) { mZoomEnabled = b; }
|
||||||
QPixmap extractCroppedScaledPicture() const;
|
QPixmap extractCroppedScaledPicture() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -57,8 +58,9 @@ protected:
|
|||||||
float mCenterX;
|
float mCenterX;
|
||||||
float mCenterY;
|
float mCenterY;
|
||||||
float mZoomFactor;
|
float mZoomFactor;
|
||||||
int mLastX,mLastY;
|
int mLastX,mLastY;
|
||||||
bool mMoving;
|
bool mMoving;
|
||||||
|
bool mZoomEnabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Class to paint the thumbnails with title
|
// Class to paint the thumbnails with title
|
||||||
@ -71,6 +73,10 @@ public:
|
|||||||
// This variable determines the zoom factor on the text below thumbnails. 2.0 is mostly correct for all screen.
|
// This variable determines the zoom factor on the text below thumbnails. 2.0 is mostly correct for all screen.
|
||||||
static constexpr float THUMBNAIL_OVERSAMPLE_FACTOR = 2.0;
|
static constexpr float THUMBNAIL_OVERSAMPLE_FACTOR = 2.0;
|
||||||
|
|
||||||
|
static constexpr uint32_t FLAG_NONE = 0x00;
|
||||||
|
static constexpr uint32_t FLAG_SHOW_TEXT = 0x01;
|
||||||
|
static constexpr uint32_t FLAG_ALLOW_PAN = 0x02;
|
||||||
|
|
||||||
// Size of thumbnails as a function of the height of the font. An aspect ratio of 3/4 is good.
|
// Size of thumbnails as a function of the height of the font. An aspect ratio of 3/4 is good.
|
||||||
|
|
||||||
static const int THUMBNAIL_W = 4;
|
static const int THUMBNAIL_W = 4;
|
||||||
@ -79,13 +85,13 @@ public:
|
|||||||
static constexpr char *CHAN_DEFAULT_IMAGE = ":images/thumb-default-video.png";
|
static constexpr char *CHAN_DEFAULT_IMAGE = ":images/thumb-default-video.png";
|
||||||
|
|
||||||
virtual ~ChannelPostThumbnailView();
|
virtual ~ChannelPostThumbnailView();
|
||||||
ChannelPostThumbnailView(QWidget *parent=NULL);
|
ChannelPostThumbnailView(QWidget *parent=NULL,uint32_t flags=FLAG_ALLOW_PAN);
|
||||||
ChannelPostThumbnailView(const RsGxsChannelPost& post,QWidget *parent=NULL);
|
ChannelPostThumbnailView(const RsGxsChannelPost& post,uint32_t flags,QWidget *parent=NULL);
|
||||||
|
|
||||||
void init(const QPixmap& thumbnail,const QString& msg,bool is_msg_new);
|
void init(const RsGxsChannelPost& post);
|
||||||
|
|
||||||
void setPixmap(const QPixmap& p) { lb->setPicture(p); }
|
void setPixmap(const QPixmap& p) { mPostImage->setPicture(p); }
|
||||||
QPixmap getCroppedScaledPicture() const { return lb->extractCroppedScaledPicture() ; }
|
QPixmap getCroppedScaledPicture() const { return mPostImage->extractCroppedScaledPicture() ; }
|
||||||
|
|
||||||
void setText(const QString& s)
|
void setText(const QString& s)
|
||||||
{
|
{
|
||||||
@ -95,11 +101,12 @@ public:
|
|||||||
else
|
else
|
||||||
ss =s;
|
ss =s;
|
||||||
|
|
||||||
lt->setText(ss);
|
mPostTitle->setText(ss);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ZoomableLabel *lb;
|
ZoomableLabel *mPostImage;
|
||||||
QLabel *lt;
|
QLabel *mPostTitle;
|
||||||
|
uint32_t mFlags;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -84,9 +84,12 @@ Q_DECLARE_METATYPE(ChannelPostFileInfo)
|
|||||||
//=== ChannelPostDelegate ===//
|
//=== ChannelPostDelegate ===//
|
||||||
//===============================================================================================================================================//
|
//===============================================================================================================================================//
|
||||||
|
|
||||||
int ChannelPostDelegate::cellSize(const QFont& font) const
|
int ChannelPostDelegate::cellSize(const QFont& font,uint32_t parent_width) const
|
||||||
{
|
{
|
||||||
return mZoom*COLUMN_SIZE_FONT_FACTOR_W*QFontMetricsF(font).height();
|
if(mUseGrid)
|
||||||
|
return mZoom*COLUMN_SIZE_FONT_FACTOR_W*QFontMetricsF(font).height();
|
||||||
|
else
|
||||||
|
return parent_width;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChannelPostDelegate::zoom(bool zoom_or_unzoom)
|
void ChannelPostDelegate::zoom(bool zoom_or_unzoom)
|
||||||
@ -110,7 +113,8 @@ void ChannelPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem &
|
|||||||
painter->fillRect( option.rect, option.backgroundBrush);
|
painter->fillRect( option.rect, option.backgroundBrush);
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
|
||||||
ChannelPostThumbnailView w(post);
|
uint32_t flags = (mUseGrid)?0:(ChannelPostThumbnailView::FLAG_SHOW_TEXT);
|
||||||
|
ChannelPostThumbnailView w(post,flags);
|
||||||
|
|
||||||
QPixmap pixmap(w.size());
|
QPixmap pixmap(w.size());
|
||||||
|
|
||||||
@ -282,7 +286,7 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
|
|||||||
QFontMetricsF fm(font());
|
QFontMetricsF fm(font());
|
||||||
|
|
||||||
for(int i=0;i<mChannelPostsModel->columnCount();++i)
|
for(int i=0;i<mChannelPostsModel->columnCount();++i)
|
||||||
ui->postsTree->setColumnWidth(i,mChannelPostsDelegate->cellSize(font()));
|
ui->postsTree->setColumnWidth(i,mChannelPostsDelegate->cellSize(font(),ui->postsTree->width()));
|
||||||
|
|
||||||
/* Setup UI helper */
|
/* Setup UI helper */
|
||||||
|
|
||||||
@ -350,11 +354,11 @@ void GxsChannelPostsWidgetWithModel::updateZoomFactor(bool zoom_or_unzoom)
|
|||||||
mChannelPostsDelegate->zoom(zoom_or_unzoom);
|
mChannelPostsDelegate->zoom(zoom_or_unzoom);
|
||||||
|
|
||||||
for(int i=0;i<mChannelPostsModel->columnCount();++i)
|
for(int i=0;i<mChannelPostsModel->columnCount();++i)
|
||||||
ui->postsTree->setColumnWidth(i,mChannelPostsDelegate->cellSize(font()));
|
ui->postsTree->setColumnWidth(i,mChannelPostsDelegate->cellSize(font(),ui->postsTree->width()));
|
||||||
|
|
||||||
QSize s = ui->postsTree->size();
|
QSize s = ui->postsTree->size();
|
||||||
|
|
||||||
int n_columns = std::max(1,(int)floor(s.width() / (mChannelPostsDelegate->cellSize(font()))));
|
int n_columns = std::max(1,(int)floor(s.width() / (mChannelPostsDelegate->cellSize(font(),s.width()))));
|
||||||
std::cerr << "nb columns: " << n_columns << std::endl;
|
std::cerr << "nb columns: " << n_columns << std::endl;
|
||||||
|
|
||||||
mChannelPostsModel->setNumColumns(n_columns); // forces the update
|
mChannelPostsModel->setNumColumns(n_columns); // forces the update
|
||||||
@ -402,6 +406,8 @@ void GxsChannelPostsWidgetWithModel::switchView()
|
|||||||
{
|
{
|
||||||
mChannelPostsDelegate->setWidgetGrid(true);
|
mChannelPostsDelegate->setWidgetGrid(true);
|
||||||
mChannelPostsModel->setMode(RsGxsChannelPostsModel::TREE_MODE_GRID);
|
mChannelPostsModel->setMode(RsGxsChannelPostsModel::TREE_MODE_GRID);
|
||||||
|
|
||||||
|
handlePostsTreeSizeChange(ui->postsTree->size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void GxsChannelPostsWidgetWithModel::copyMessageLink()
|
void GxsChannelPostsWidgetWithModel::copyMessageLink()
|
||||||
@ -447,7 +453,7 @@ void GxsChannelPostsWidgetWithModel::editPost()
|
|||||||
|
|
||||||
void GxsChannelPostsWidgetWithModel::handlePostsTreeSizeChange(QSize s)
|
void GxsChannelPostsWidgetWithModel::handlePostsTreeSizeChange(QSize s)
|
||||||
{
|
{
|
||||||
int n_columns = std::max(1,(int)floor(s.width() / (mChannelPostsDelegate->cellSize(font()))));
|
int n_columns = std::max(1,(int)floor(s.width() / (mChannelPostsDelegate->cellSize(font(),ui->postsTree->width()))));
|
||||||
std::cerr << "nb columns: " << n_columns << std::endl;
|
std::cerr << "nb columns: " << n_columns << std::endl;
|
||||||
|
|
||||||
if(n_columns != mChannelPostsModel->columnCount())
|
if(n_columns != mChannelPostsModel->columnCount())
|
||||||
|
@ -66,7 +66,7 @@ class ChannelPostDelegate: public QAbstractItemDelegate
|
|||||||
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;
|
||||||
|
|
||||||
int cellSize(const QFont& font) const;
|
int cellSize(const QFont& font,uint32_t parent_width) const;
|
||||||
void zoom(bool zoom_or_unzoom) ;
|
void zoom(bool zoom_or_unzoom) ;
|
||||||
void setWidgetGrid(bool use_grid) ;
|
void setWidgetGrid(bool use_grid) ;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user