diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp index 58715e48d..f4e0a5696 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.cpp @@ -44,7 +44,7 @@ Q_DECLARE_METATYPE(RsGxsChannelPost) std::ostream& operator<<(std::ostream& o, const QModelIndex& i);// defined elsewhere RsGxsChannelPostsModel::RsGxsChannelPostsModel(QObject *parent) - : QAbstractItemModel(parent), mTreeMode(TREE_MODE_PLAIN), mColumns(6) + : QAbstractItemModel(parent), mTreeMode(RsGxsChannelPostsModel::TREE_MODE_GRID), mColumns(6) { initEmptyHierarchy(); @@ -62,6 +62,15 @@ RsGxsChannelPostsModel::~RsGxsChannelPostsModel() rsEvents->unregisterEventsHandler(mEventHandlerId); } +void RsGxsChannelPostsModel::setMode(TreeMode mode) +{ + mTreeMode = mode; + + if(mode == TREE_MODE_LIST) + setNumColumns(1); + + // needs some update here +} void RsGxsChannelPostsModel::handleEvent_main_thread(std::shared_ptr event) { const RsGxsChannelEvent *e = dynamic_cast(event.get()); @@ -124,18 +133,12 @@ void RsGxsChannelPostsModel::initEmptyHierarchy() mPosts.clear(); mFilteredPosts.clear(); -// mPosts.resize(1); // adds a sentinel item -// mPosts[0].mMeta.mMsgName = "Root sentinel post" ; -// mFilteredPosts.resize(1); -// mFilteredPosts[0] = 1; postMods(); } void RsGxsChannelPostsModel::preMods() { - //emit layoutAboutToBeChanged(); //Generate SIGSEGV when click on button move next/prev. - beginResetModel(); } void RsGxsChannelPostsModel::postMods() diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h index 47e0caee5..75464368e 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsModel.h @@ -92,8 +92,8 @@ public: #endif enum TreeMode{ TREE_MODE_UNKWN = 0x00, - TREE_MODE_PLAIN = 0x01, - TREE_MODE_FILES = 0x02, + TREE_MODE_GRID = 0x01, + TREE_MODE_LIST = 0x02, }; #ifdef TODO @@ -112,6 +112,8 @@ public: const RsGxsGroupId& currentGroupId() const; void setNumColumns(int n); + void setMode(TreeMode mode); + TreeMode getMode() const { return mTreeMode; } // Retrieve the full list of files for all posts. diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp index 1265f531f..35d37ef0b 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp @@ -74,11 +74,16 @@ static const int CHANNEL_TABS_FILES = 2; #define STAR_OVERLAY_IMAGE ":icons/star_overlay_128.png" #define IMAGE_COPYLINK ":/images/copyrslink.png" +#define IMAGE_GRID_VIEW ":icons/png/menu.png" Q_DECLARE_METATYPE(ChannelPostFileInfo) // Delegate used to paint into the table of thumbnails +//===============================================================================================================================================// +//=== ChannelPostDelegate ===// +//===============================================================================================================================================// + int ChannelPostDelegate::cellSize(const QFont& font) const { return mZoom*COLUMN_SIZE_FONT_FACTOR_W*QFontMetricsF(font).height(); @@ -126,16 +131,6 @@ void ChannelPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem & p.drawPixmap(mZoom*QPoint(6.2*fm.height(),6.9*fm.height()),FilesDefs::getPixmapFromQtResourcePath(STAR_OVERLAY_IMAGE).scaled(mZoom*7*fm.height(),mZoom*7*fm.height(),Qt::KeepAspectRatio,Qt::SmoothTransformation)); } - // debug - // if(index.row()==0 && index.column()==0) - // { - // QFile file("yourFile.png"); - // file.open(QIODevice::WriteOnly); - // pixmap.save(&file, "PNG"); - // 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; - painter->drawPixmap(option.rect.topLeft(), pixmap.scaled(option.rect.width(),option.rect.width()*w.height()/(float)w.width(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation)); } @@ -146,9 +141,21 @@ QSize ChannelPostDelegate::sizeHint(const QStyleOptionViewItem& option, const QM QFontMetricsF fm(option.font); - return QSize(mZoom*COLUMN_SIZE_FONT_FACTOR_W*fm.height(),mZoom*COLUMN_SIZE_FONT_FACTOR_H*fm.height()); + if(mUseGrid) + return QSize(mZoom*COLUMN_SIZE_FONT_FACTOR_W*fm.height(),mZoom*COLUMN_SIZE_FONT_FACTOR_H*fm.height()); + else + return QSize(option.rect.width(),mZoom*COLUMN_SIZE_FONT_FACTOR_H*fm.height()); } +void ChannelPostDelegate::setWidgetGrid(bool use_grid) +{ + mUseGrid = use_grid; +} + +//===============================================================================================================================================// +//=== ChannelPostFilesDelegate ===// +//===============================================================================================================================================// + QWidget *ChannelPostFilesDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex& index) const { ChannelPostFileInfo file = index.data(Qt::UserRole).value() ; @@ -222,6 +229,10 @@ QSize ChannelPostFilesDelegate::sizeHint(const QStyleOptionViewItem& option, con } } +//===============================================================================================================================================// +//=== GxsChannelPostWidgetWithModel ===// +//===============================================================================================================================================// + /** Constructor */ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupId &channelId, QWidget *parent) : GxsMessageFrameWidget(rsGxsChannels, parent), @@ -366,7 +377,13 @@ void GxsChannelPostsWidgetWithModel::postContextMenu(const QPoint&) { QMenu menu(this); - menu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyMessageLink())); + if(mChannelPostsModel->getMode() == RsGxsChannelPostsModel::TREE_MODE_GRID) + menu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_GRID_VIEW), tr("Switch to list view"), this, SLOT(switchView())); + else + menu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_GRID_VIEW), tr("Switch to grid view"), this, SLOT(switchView())); + + menu.addSeparator(); + menu.addAction(FilesDefs::getIconFromQtResourcePath(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyMessageLink())); if(IS_GROUP_PUBLISHER(mGroup.mMeta.mSubscribeFlags)) menu.addAction(FilesDefs::getIconFromQtResourcePath(":/images/edit_16.png"), tr("Edit"), this, SLOT(editPost())); @@ -374,6 +391,19 @@ void GxsChannelPostsWidgetWithModel::postContextMenu(const QPoint&) menu.exec(QCursor::pos()); } +void GxsChannelPostsWidgetWithModel::switchView() +{ + if(mChannelPostsModel->getMode() == RsGxsChannelPostsModel::TREE_MODE_GRID) + { + mChannelPostsDelegate->setWidgetGrid(false); + mChannelPostsModel->setMode(RsGxsChannelPostsModel::TREE_MODE_LIST); + } + else + { + mChannelPostsDelegate->setWidgetGrid(true); + mChannelPostsModel->setMode(RsGxsChannelPostsModel::TREE_MODE_GRID); + } +} void GxsChannelPostsWidgetWithModel::copyMessageLink() { try diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h index 5fb04bb6f..8b1ca56a8 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.h @@ -68,13 +68,16 @@ class ChannelPostDelegate: public QAbstractItemDelegate int cellSize(const QFont& font) const; void zoom(bool zoom_or_unzoom) ; - private: + void setWidgetGrid(bool use_grid) ; + + 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; float mZoom; // zoom factor for the whole thumbnail + bool mUseGrid; // wether we use the grid widget or the list widget }; class GxsChannelPostsWidgetWithModel: public GxsMessageFrameWidget @@ -147,6 +150,7 @@ private slots: void postContextMenu(const QPoint&); void copyMessageLink(); void updateZoomFactor(bool zoom_or_unzoom); + void switchView(); public slots: void sortColumnFiles(int col,Qt::SortOrder so);