diff --git a/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp b/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp index 3ecf7616c..6cceecb11 100644 --- a/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp +++ b/retroshare-gui/src/gui/gxs/GxsIdDetails.cpp @@ -49,8 +49,6 @@ #define TIMER_INTERVAL 1000 #define MAX_ATTEMPTS 10 -static const int IconSize = 20; - const int kRecognTagClass_DEVELOPMENT = 1; const int kRecognTagType_Dev_Ambassador = 1; @@ -906,20 +904,22 @@ void GxsIdDetails::getIcons(const RsIdentityDetails &details, QList &icon } } -bool GxsIdDetails::GenerateCombinedIcon(QIcon &outIcon, const QList &icons) +void GxsIdDetails::GenerateCombinedPixmap(QPixmap &pixmap, const QList &icons, int iconSize) { int count = icons.size(); - QPixmap image(IconSize * count, IconSize); - QPainter painter(&image); + if (count == 0) { + pixmap = QPixmap(); + return; + } + + pixmap = QPixmap(iconSize * count, iconSize); + pixmap.fill(Qt::transparent); + QPainter painter(&pixmap); - painter.fillRect(0, 0, IconSize * count, IconSize, Qt::transparent); QList::const_iterator it; int i = 0; for(it = icons.begin(); it != icons.end(); ++it, ++i) { - it->paint(&painter, IconSize * i, 0, IconSize, IconSize); + it->paint(&painter, iconSize * i, 0, iconSize, iconSize); } - - outIcon = QIcon(image); - return true; } diff --git a/retroshare-gui/src/gui/gxs/GxsIdDetails.h b/retroshare-gui/src/gui/gxs/GxsIdDetails.h index 61a544ef7..1ff069d63 100644 --- a/retroshare-gui/src/gui/gxs/GxsIdDetails.h +++ b/retroshare-gui/src/gui/gxs/GxsIdDetails.h @@ -67,7 +67,7 @@ public: static QIcon getLoadingIcon(const RsGxsId &id); - static bool GenerateCombinedIcon(QIcon &outIcon, const QList &icons); + static void GenerateCombinedPixmap(QPixmap &pixmap, const QList &icons, int iconSize); //static QImage makeDefaultIcon(const RsGxsId& id); static QImage makeDefaultIcon(const RsGxsId& id); diff --git a/retroshare-gui/src/gui/gxs/GxsIdTreeWidget.cpp b/retroshare-gui/src/gui/gxs/GxsIdTreeWidget.cpp deleted file mode 100644 index 38fc03bf3..000000000 --- a/retroshare-gui/src/gui/gxs/GxsIdTreeWidget.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Retroshare Gxs Support - * - * Copyright 2012-2013 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - -#include "GxsIdTreeWidget.h" -#include "GxsIdDetails.h" - -#include -#include - -#include - -#include - -static void paintGxsId( QPainter * painter, - const QStyleOptionViewItem & option /*, const QRect &rect */, const RsGxsId &id ) -{ - QString desc; - QString comment; - QList icons; - if (!GxsIdDetails::MakeIdDesc(id, true, desc, icons,comment)) - { - /* flag for reloading */ - } - - const QRect &rect = option.rect; - int x = rect.left(); - int y = rect.top(); - - - QList::iterator it; - const int IconSize = 15; - int i = 0; - for(it = icons.begin(); it != icons.end(); ++it, ++i) - { - it->paint(painter, x, y, IconSize, IconSize); - x += IconSize; - } - -#define DELTA_X 4 - QRect textRect = rect.adjusted(DELTA_X + IconSize * i, 0, 0, 0); - painter->drawText(textRect, 0, desc, NULL); -} - - -GxsIdItemDelegate::GxsIdItemDelegate(GxsIdTreeWidget *tree, int col, QObject *parent) -:QStyledItemDelegate(parent), mTree(tree), mGxsIdColumn(col) -{ - return; -} - -void GxsIdItemDelegate::paint( QPainter * painter, - const QStyleOptionViewItem & option, const QModelIndex & index ) const -{ - RsGxsId id ( mTree->ItemTextFromIndex(index, mGxsIdColumn).toStdString()); - paintGxsId(painter, option, id); -} - -QSize GxsIdItemDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const -{ - return QStyledItemDelegate::sizeHint(option, index); -} - -/******************************************************************/ - -GxsIdRSItemDelegate::GxsIdRSItemDelegate(GxsIdRSTreeWidget *tree, int col, QObject *parent) -:QStyledItemDelegate(parent), mTree(tree), mGxsIdColumn(col) -{ - return; -} - -void GxsIdRSItemDelegate::paint( QPainter * painter, - const QStyleOptionViewItem & option, const QModelIndex & index ) const -{ - RsGxsId id ( mTree->ItemIdFromIndex(index, mGxsIdColumn)); - paintGxsId(painter, option, id); -} - -QSize GxsIdRSItemDelegate::sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const -{ - return QStyledItemDelegate::sizeHint(option, index); -} - -/******************************************************************/ - -GxsIdTreeWidget::GxsIdTreeWidget(QWidget *parent) -:QTreeWidget(parent), mIdDelegate(NULL) -{ - return; -} - - -void GxsIdTreeWidget::setGxsIdColumn(int col) -{ - mIdDelegate = new GxsIdItemDelegate(this, col, this); - setItemDelegateForColumn(col, mIdDelegate); -} - - -QString GxsIdTreeWidget::ItemTextFromIndex(const QModelIndex & index, int column ) const -{ - // get real item. - QTreeWidgetItem *item = itemFromIndex(index); - if (!item) - { - std::cerr << "GxsIdTreeWidget::ItemTextFromIndex() Invalid Item"; - std::cerr << std::endl; - QString text; - return text; - } - return item->text(column); -} - - -GxsIdRSTreeWidget::GxsIdRSTreeWidget(QWidget *parent) -:RSTreeWidget(parent), mIdDelegate(NULL) -{ - return; -} - -void GxsIdRSTreeWidget::setGxsIdColumn(int col) -{ - mIdDelegate = new GxsIdRSItemDelegate(this, col, this); - setItemDelegateForColumn(col, mIdDelegate); -} - -RsGxsId GxsIdRSTreeWidget::ItemIdFromIndex(const QModelIndex & index, int column ) const -{ - // get real item. - QTreeWidgetItem *item = itemFromIndex(index); - if (!item) - { - std::cerr << "GxsIdTreeWidget::ItemTextFromIndex() Invalid Item"; - std::cerr << std::endl; - return RsGxsId(); - } - return RsGxsId(item->data(column,Qt::UserRole).toString().toStdString()); -} -QString GxsIdRSTreeWidget::ItemTextFromIndex(const QModelIndex & index, int column ) const -{ - // get real item. - QTreeWidgetItem *item = itemFromIndex(index); - if (!item) - { - std::cerr << "GxsIdTreeWidget::ItemTextFromIndex() Invalid Item"; - std::cerr << std::endl; - QString text; - return text; - } - return item->text(column); -} - diff --git a/retroshare-gui/src/gui/gxs/GxsIdTreeWidget.h b/retroshare-gui/src/gui/gxs/GxsIdTreeWidget.h deleted file mode 100644 index e8e9510bb..000000000 --- a/retroshare-gui/src/gui/gxs/GxsIdTreeWidget.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Retroshare Gxs Support - * - * Copyright 2012-2013 by Robert Fernie. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License Version 2.1 as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - * - * Please report all bugs and problems to "retroshare@lunamutt.com". - * - */ - -#ifndef _GXS_ID_TREEWIDGET_H -#define _GXS_ID_TREEWIDGET_H - -#include -#include - -#include "retroshare/rsgxsifacetypes.h" -#include "gui/common/RSTreeWidget.h" - -/***** - * To draw multiple fancy Icons, and refresh IDs properly we need - * to overload QTreeWidget, and provide a QItemDelegate to draw stuff. - * - * The ItemDelegate - * - ****/ - -class GxsIdTreeWidget; -class GxsIdRSTreeWidget; - -class GxsIdItemDelegate : public QStyledItemDelegate -{ - public: - GxsIdItemDelegate(GxsIdTreeWidget *tree, int gxsIdColumn, QObject *parent = 0); - virtual void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const; - virtual QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const; - - private: - GxsIdTreeWidget *mTree; - int mGxsIdColumn; -}; - - -class GxsIdRSItemDelegate : public QStyledItemDelegate -{ - public: - GxsIdRSItemDelegate(GxsIdRSTreeWidget *tree, int gxsIdColumn, QObject *parent = 0); - virtual void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const; - virtual QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const; - - private: - GxsIdRSTreeWidget *mTree; - int mGxsIdColumn; -}; - - -class GxsIdTreeWidget : public QTreeWidget -{ -public: - GxsIdTreeWidget(QWidget *parent = NULL); - virtual ~GxsIdTreeWidget() { return; } - -void setGxsIdColumn(int col); -QString ItemTextFromIndex(const QModelIndex & index, int column ) const; - -private: - GxsIdItemDelegate *mIdDelegate; -}; - - -class GxsIdRSTreeWidget : public RSTreeWidget -{ -public: - GxsIdRSTreeWidget(QWidget *parent = NULL); - virtual ~GxsIdRSTreeWidget() { return; } - -void setGxsIdColumn(int col); -QString ItemTextFromIndex(const QModelIndex & index, int column ) const; -RsGxsId ItemIdFromIndex(const QModelIndex & index, int column ) const; - -private: - GxsIdRSItemDelegate *mIdDelegate; -}; - -#endif diff --git a/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp b/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp index 9aeb665ed..faec43011 100644 --- a/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp +++ b/retroshare-gui/src/gui/gxs/GxsIdTreeWidgetItem.cpp @@ -72,12 +72,11 @@ static void fillGxsIdRSTreeWidgetItemCallback(GxsIdDetailsType type, const RsIde item->setText(column, GxsIdDetails::getNameForType(type, details)); item->setData(column, Qt::UserRole, QString::fromStdString(details.mId.toStdString())); - QIcon combinedIcon; + QPixmap combinedPixmap; if (!icons.empty()) { - GxsIdDetails::GenerateCombinedIcon(combinedIcon, icons); + GxsIdDetails::GenerateCombinedPixmap(combinedPixmap, icons, 16); } - item->setIcon(column, combinedIcon); - + item->setData(column, Qt::DecorationRole, combinedPixmap); QImage pix ; if(details.mAvatar.mSize == 0 || !pix.loadFromData(details.mAvatar.mData, details.mAvatar.mSize, "PNG")) diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index 6bed1a6fa..cabfb3839 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -191,7 +191,6 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget ui->progressText->hide(); mFillThread = NULL; - ui->threadTreeWidget->setGxsIdColumn(COLUMN_THREAD_AUTHOR); setGroupId(forumId); @@ -850,7 +849,6 @@ QTreeWidgetItem *GxsForumThreadWidget::convertMsgToThreadWidget(const RsGxsForum item->setText(COLUMN_THREAD_DATE, text); item->setData(COLUMN_THREAD_DATE, ROLE_THREAD_SORT, sort); - //item->setText(COLUMN_THREAD_AUTHOR, QString::fromStdString(msg.mMeta.mAuthorId.toStdString())); item->setId(msg.mMeta.mAuthorId, COLUMN_THREAD_AUTHOR); //#TODO #if 0 diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.ui b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.ui index d96a70ecd..2f06c9695 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.ui +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.ui @@ -210,7 +210,7 @@ - + Qt::CustomContextMenu @@ -521,9 +521,9 @@
gui/common/RSTextBrowser.h
- GxsIdRSTreeWidget + RSTreeWidget QTreeWidget -
gui/gxs/GxsIdTreeWidget.h
+
gui/common/RSTreeWidget.h
diff --git a/retroshare-gui/src/retroshare-gui.pro b/retroshare-gui/src/retroshare-gui.pro index fa67e8220..680273a6d 100644 --- a/retroshare-gui/src/retroshare-gui.pro +++ b/retroshare-gui/src/retroshare-gui.pro @@ -1282,7 +1282,6 @@ gxsgui { gui/gxs/GxsIdLabel.h \ gui/gxs/GxsCircleChooser.h \ gui/gxs/GxsCircleLabel.h \ - gui/gxs/GxsIdTreeWidget.h \ gui/gxs/GxsIdTreeWidgetItem.h \ gui/gxs/GxsCommentTreeWidget.h \ gui/gxs/GxsCommentContainer.h \ @@ -1320,7 +1319,6 @@ gxsgui { gui/gxs/GxsCircleChooser.cpp \ gui/gxs/GxsGroupShareKey.cpp \ gui/gxs/GxsCircleLabel.cpp \ - gui/gxs/GxsIdTreeWidget.cpp \ gui/gxs/GxsIdTreeWidgetItem.cpp \ gui/gxs/GxsCommentTreeWidget.cpp \ gui/gxs/GxsCommentContainer.cpp \