mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-23 22:01:05 -05:00
fixed auto-layout of thumbnails
This commit is contained in:
parent
3106157ab0
commit
129ffdd6c5
@ -19,12 +19,18 @@
|
|||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QResizeEvent>
|
||||||
#include "RSTreeView.h"
|
#include "RSTreeView.h"
|
||||||
|
|
||||||
RSTreeView::RSTreeView(QWidget *parent) : QTreeView(parent)
|
RSTreeView::RSTreeView(QWidget *parent) : QTreeView(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RSTreeView::resizeEvent(QResizeEvent *e)
|
||||||
|
{
|
||||||
|
emit sizeChanged(e->size());
|
||||||
|
}
|
||||||
|
|
||||||
void RSTreeView::setPlaceholderText(const QString &text)
|
void RSTreeView::setPlaceholderText(const QString &text)
|
||||||
{
|
{
|
||||||
placeholderText = text;
|
placeholderText = text;
|
||||||
|
@ -33,8 +33,12 @@ public:
|
|||||||
|
|
||||||
void setPlaceholderText(const QString &text);
|
void setPlaceholderText(const QString &text);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void sizeChanged(QSize);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event);
|
virtual void resizeEvent(QResizeEvent *e) override;
|
||||||
|
virtual void paintEvent(QPaintEvent *event) override;
|
||||||
|
|
||||||
QString placeholderText;
|
QString placeholderText;
|
||||||
};
|
};
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>367</width>
|
<width>421</width>
|
||||||
<height>27</height>
|
<height>29</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
#include "GxsChannelPostFilesModel.h"
|
#include "GxsChannelPostFilesModel.h"
|
||||||
|
|
||||||
#define DEBUG_CHANNEL_MODEL
|
//#define DEBUG_CHANNEL_MODEL
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(RsGxsFile)
|
Q_DECLARE_METATYPE(RsGxsFile)
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
#include "retroshare/rsgxschannels.h"
|
#include "retroshare/rsgxschannels.h"
|
||||||
#include "retroshare/rsexpr.h"
|
#include "retroshare/rsexpr.h"
|
||||||
|
|
||||||
#define DEBUG_CHANNEL_MODEL
|
//#define DEBUG_CHANNEL_MODEL
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(RsMsgMetaData)
|
Q_DECLARE_METATYPE(RsMsgMetaData)
|
||||||
|
|
||||||
@ -221,6 +221,21 @@ Qt::ItemFlags RsGxsChannelPostsModel::flags(const QModelIndex& index) const
|
|||||||
return QAbstractItemModel::flags(index);
|
return QAbstractItemModel::flags(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RsGxsChannelPostsModel::setNumColumns(int n)
|
||||||
|
{
|
||||||
|
preMods();
|
||||||
|
|
||||||
|
beginRemoveRows(QModelIndex(),0,rowCount()-1);
|
||||||
|
endRemoveRows();
|
||||||
|
|
||||||
|
mColumns = n;
|
||||||
|
|
||||||
|
beginInsertRows(QModelIndex(),0,rowCount()-1);
|
||||||
|
endInsertRows();
|
||||||
|
|
||||||
|
postMods();
|
||||||
|
}
|
||||||
|
|
||||||
quintptr RsGxsChannelPostsModel::getChildRef(quintptr ref,int index) const
|
quintptr RsGxsChannelPostsModel::getChildRef(quintptr ref,int index) const
|
||||||
{
|
{
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
@ -675,7 +690,7 @@ void RsGxsChannelPostsModel::setPosts(const RsGxsChannelGroup& group, std::vecto
|
|||||||
{
|
{
|
||||||
preMods();
|
preMods();
|
||||||
|
|
||||||
beginRemoveRows(QModelIndex(),0,mPosts.size()-1);
|
beginRemoveRows(QModelIndex(),0,rowCount()-1);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
|
||||||
mPosts.clear();
|
mPosts.clear();
|
||||||
@ -692,7 +707,7 @@ void RsGxsChannelPostsModel::setPosts(const RsGxsChannelGroup& group, std::vecto
|
|||||||
// debug_dump();
|
// debug_dump();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
beginInsertRows(QModelIndex(),0,mPosts.size()-1);
|
beginInsertRows(QModelIndex(),0,rowCount()-1);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
|
||||||
postMods();
|
postMods();
|
||||||
|
@ -110,6 +110,7 @@ public:
|
|||||||
const RsGxsGroupId& currentGroupId() const;
|
const RsGxsGroupId& currentGroupId() const;
|
||||||
|
|
||||||
void setTreeMode(TreeMode mode) ;
|
void setTreeMode(TreeMode mode) ;
|
||||||
|
void setNumColumns(int n);
|
||||||
#ifdef TODO
|
#ifdef TODO
|
||||||
void setSortMode(SortMode mode) ;
|
void setSortMode(SortMode mode) ;
|
||||||
|
|
||||||
|
@ -61,8 +61,21 @@ static const int CHANNEL_TABS_POSTS = 1;
|
|||||||
/* View mode */
|
/* View mode */
|
||||||
#define VIEW_MODE_FEEDS 1
|
#define VIEW_MODE_FEEDS 1
|
||||||
#define VIEW_MODE_FILES 2
|
#define VIEW_MODE_FILES 2
|
||||||
|
|
||||||
|
// Size of thumbnails as a function of the height of the font. An aspect ratio of 3/4 is good.
|
||||||
|
|
||||||
|
#define THUMBNAIL_W 4
|
||||||
|
#define THUMBNAIL_H 6
|
||||||
|
|
||||||
|
// Determine the Shape and size of cells as a factor of the font height. An aspect ratio of 3/4 is what's needed
|
||||||
|
// for the image, so it's important that the height is a bit larger so as to leave some room for the text.
|
||||||
|
//
|
||||||
|
//
|
||||||
#define COLUMN_SIZE_FONT_FACTOR_W 6
|
#define COLUMN_SIZE_FONT_FACTOR_W 6
|
||||||
#define COLUMN_SIZE_FONT_FACTOR_H 12
|
#define COLUMN_SIZE_FONT_FACTOR_H 10
|
||||||
|
|
||||||
|
// This variable determines the zoom factor on the text below thumbnails. 2.0 is mostly correct for all screen.
|
||||||
|
#define THUMBNAIL_OVERSAMPLE_FACTOR 2.0
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(RsGxsFile)
|
Q_DECLARE_METATYPE(RsGxsFile)
|
||||||
|
|
||||||
@ -95,8 +108,8 @@ public:
|
|||||||
lb->setPixmap(thumbnail);
|
lb->setPixmap(thumbnail);
|
||||||
|
|
||||||
QFontMetricsF fm(font());
|
QFontMetricsF fm(font());
|
||||||
int W = 8 * fm.height() ;
|
int W = THUMBNAIL_OVERSAMPLE_FACTOR * THUMBNAIL_W * fm.height() ;
|
||||||
int H = 12 * fm.height() ;
|
int H = THUMBNAIL_OVERSAMPLE_FACTOR * THUMBNAIL_H * fm.height() ;
|
||||||
|
|
||||||
lb->setFixedSize(W,H);
|
lb->setFixedSize(W,H);
|
||||||
|
|
||||||
@ -183,18 +196,19 @@ void ChannelPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem &
|
|||||||
//w.setFixedWidth(option.rect.width());
|
//w.setFixedWidth(option.rect.width());
|
||||||
|
|
||||||
QPixmap pixmap(w.size());
|
QPixmap pixmap(w.size());
|
||||||
pixmap.fill(option.palette.color(QPalette::Background)); // choose the background
|
pixmap.fill(QRgb(0x00ffffff)); // choose a fully transparent background
|
||||||
w.render(&pixmap,QPoint(),QRegion(),QWidget::DrawChildren );// draw the widgets, not the background
|
w.render(&pixmap,QPoint(),QRegion(),QWidget::DrawChildren );// draw the widgets, not the background
|
||||||
|
|
||||||
// debug
|
// debug
|
||||||
if(index.row()==0 && index.column()==0)
|
// if(index.row()==0 && index.column()==0)
|
||||||
{
|
// {
|
||||||
QFile file("yourFile.png");
|
// QFile file("yourFile.png");
|
||||||
file.open(QIODevice::WriteOnly);
|
// file.open(QIODevice::WriteOnly);
|
||||||
pixmap.save(&file, "PNG");
|
// pixmap.save(&file, "PNG");
|
||||||
std::cerr << "Saved pxmap to png" << std::endl;
|
// std::cerr << "Saved pxmap to png" << std::endl;
|
||||||
}
|
// }
|
||||||
std::cerr << "option.rect = " << option.rect.width() << "x" << option.rect.height() << ". fm.height()=" << QFontMetricsF(option.font).height() << std::endl;
|
//std::cerr << "option.rect = " << option.rect.width() << "x" << option.rect.height() << ". fm.height()=" << QFontMetricsF(option.font).height() << std::endl;
|
||||||
|
|
||||||
painter->drawPixmap(option.rect.topLeft(),
|
painter->drawPixmap(option.rect.topLeft(),
|
||||||
pixmap.scaled(option.rect.width(),option.rect.width()*w.height()/(float)w.width(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation));
|
pixmap.scaled(option.rect.width(),option.rect.width()*w.height()/(float)w.width(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation));
|
||||||
}
|
}
|
||||||
@ -297,7 +311,7 @@ void ChannelPostFilesDelegate::paint(QPainter * painter, const QStyleOptionViewI
|
|||||||
w.setFixedWidth(option.rect.width());
|
w.setFixedWidth(option.rect.width());
|
||||||
|
|
||||||
QPixmap pixmap(w.size());
|
QPixmap pixmap(w.size());
|
||||||
pixmap.fill(option.palette.color(QPalette::Background)); // choose the background
|
pixmap.fill(QRgb(0x00ffffff)); // choose a fully transparent background
|
||||||
w.render(&pixmap,QPoint(),QRegion(),QWidget::DrawChildren );// draw the widgets, not the background
|
w.render(&pixmap,QPoint(),QRegion(),QWidget::DrawChildren );// draw the widgets, not the background
|
||||||
|
|
||||||
painter->drawPixmap(option.rect.topLeft(),pixmap);
|
painter->drawPixmap(option.rect.topLeft(),pixmap);
|
||||||
@ -344,6 +358,7 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
|
|||||||
|
|
||||||
ui->channelPostFiles_TV->setModel(mChannelPostFilesModel = new RsGxsChannelPostFilesModel());
|
ui->channelPostFiles_TV->setModel(mChannelPostFilesModel = new RsGxsChannelPostFilesModel());
|
||||||
ui->channelPostFiles_TV->setItemDelegate(new ChannelPostFilesDelegate());
|
ui->channelPostFiles_TV->setItemDelegate(new ChannelPostFilesDelegate());
|
||||||
|
ui->channelPostFiles_TV->setPlaceholderText(tr("Post files"));
|
||||||
|
|
||||||
connect(ui->postsTree->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),this,SLOT(showPostDetails()));
|
connect(ui->postsTree->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),this,SLOT(showPostDetails()));
|
||||||
|
|
||||||
@ -386,6 +401,8 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
|
|||||||
|
|
||||||
ui->loadingLabel->hide();
|
ui->loadingLabel->hide();
|
||||||
ui->progressBar->hide();
|
ui->progressBar->hide();
|
||||||
|
ui->postsTree->setPlaceholderText(tr("Thumbnails"));
|
||||||
|
ui->postsTree->setMinimumWidth(COLUMN_SIZE_FONT_FACTOR_W*QFontMetricsF(font()).height()+1);
|
||||||
|
|
||||||
//ui->nameLabel->setMinimumWidth(20);
|
//ui->nameLabel->setMinimumWidth(20);
|
||||||
|
|
||||||
@ -414,10 +431,23 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
|
|||||||
|
|
||||||
mEventHandlerId = 0;
|
mEventHandlerId = 0;
|
||||||
// Needs to be asynced because this function is called by another thread!
|
// Needs to be asynced because this function is called by another thread!
|
||||||
rsEvents->registerEventsHandler(
|
rsEvents->registerEventsHandler( [this](std::shared_ptr<const RsEvent> event)
|
||||||
[this](std::shared_ptr<const RsEvent> event)
|
{
|
||||||
{ RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this ); },
|
RsQThreadUtils::postToObject([=](){ handleEvent_main_thread(event); }, this );
|
||||||
mEventHandlerId, RsEventType::GXS_CHANNELS );
|
}, mEventHandlerId, RsEventType::GXS_CHANNELS );
|
||||||
|
|
||||||
|
connect(ui->postsTree,SIGNAL(sizeChanged(QSize)),this,SLOT(handlePostsTreeSizeChange(QSize)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void GxsChannelPostsWidgetWithModel::handlePostsTreeSizeChange(QSize s)
|
||||||
|
{
|
||||||
|
// adjustSize();
|
||||||
|
//
|
||||||
|
int n_columns = std::max(1,(int)floor(s.width() / (COLUMN_SIZE_FONT_FACTOR_W*QFontMetricsF(font()).height())));
|
||||||
|
std::cerr << "nb columns: " << n_columns << std::endl;
|
||||||
|
|
||||||
|
if(n_columns != mChannelPostsModel->columnCount())
|
||||||
|
mChannelPostsModel->setNumColumns(n_columns);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GxsChannelPostsWidgetWithModel::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
|
void GxsChannelPostsWidgetWithModel::handleEvent_main_thread(std::shared_ptr<const RsEvent> event)
|
||||||
|
@ -108,6 +108,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
/* GxsMessageFramePostWidget */
|
/* GxsMessageFramePostWidget */
|
||||||
virtual void groupNameChanged(const QString &name);
|
virtual void groupNameChanged(const QString &name);
|
||||||
|
|
||||||
#ifdef TODO
|
#ifdef TODO
|
||||||
virtual bool insertGroupData(const RsGxsGenericGroupData *data) override;
|
virtual bool insertGroupData(const RsGxsGenericGroupData *data) override;
|
||||||
#endif
|
#endif
|
||||||
@ -134,6 +135,7 @@ private slots:
|
|||||||
void filterChanged(int filter);
|
void filterChanged(int filter);
|
||||||
void setViewMode(int viewMode);
|
void setViewMode(int viewMode);
|
||||||
void settingsChanged();
|
void settingsChanged();
|
||||||
|
void handlePostsTreeSizeChange(QSize s);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void processSettings(bool load);
|
void processSettings(bool load);
|
||||||
|
@ -412,7 +412,7 @@ p, li { white-space: pre-wrap; }
|
|||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QTreeView" name="postsTree">
|
<widget class="RSTreeView" name="postsTree">
|
||||||
<property name="sizeAdjustPolicy">
|
<property name="sizeAdjustPolicy">
|
||||||
<enum>QAbstractScrollArea::AdjustToContents</enum>
|
<enum>QAbstractScrollArea::AdjustToContents</enum>
|
||||||
</property>
|
</property>
|
||||||
@ -509,7 +509,7 @@ 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="RSTreeView" name="channelPostFiles_TV">
|
||||||
<property name="editTriggers">
|
<property name="editTriggers">
|
||||||
<set>QAbstractItemView::CurrentChanged|QAbstractItemView::SelectedClicked</set>
|
<set>QAbstractItemView::CurrentChanged|QAbstractItemView::SelectedClicked</set>
|
||||||
</property>
|
</property>
|
||||||
@ -566,6 +566,11 @@ p, li { white-space: pre-wrap; }
|
|||||||
<extends>QLineEdit</extends>
|
<extends>QLineEdit</extends>
|
||||||
<header location="global">gui/common/LineEditClear.h</header>
|
<header location="global">gui/common/LineEditClear.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>RSTreeView</class>
|
||||||
|
<extends>QTreeView</extends>
|
||||||
|
<header>gui/common/RSTreeView.h</header>
|
||||||
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../images.qrc"/>
|
<include location="../images.qrc"/>
|
||||||
|
Loading…
Reference in New Issue
Block a user