Removed not used base class GxsIdTreeWidget.

Used QPixmap instead of QIcon to draw the gxs image in GxsIdTreeWidgetItem.
Fixed use of transparent background in GxsIdDetails::GenerateCombinedPixmap (formerly GxsIdDetails::GenerateCombinedIcon).

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7965 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2015-02-22 11:52:33 +00:00
parent 7178285d60
commit 41750b0d27
8 changed files with 17 additions and 291 deletions

View File

@ -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<QIcon> &icon
}
}
bool GxsIdDetails::GenerateCombinedIcon(QIcon &outIcon, const QList<QIcon> &icons)
void GxsIdDetails::GenerateCombinedPixmap(QPixmap &pixmap, const QList<QIcon> &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<QIcon>::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;
}

View File

@ -67,7 +67,7 @@ public:
static QIcon getLoadingIcon(const RsGxsId &id);
static bool GenerateCombinedIcon(QIcon &outIcon, const QList<QIcon> &icons);
static void GenerateCombinedPixmap(QPixmap &pixmap, const QList<QIcon> &icons, int iconSize);
//static QImage makeDefaultIcon(const RsGxsId& id);
static QImage makeDefaultIcon(const RsGxsId& id);

View File

@ -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 <retroshare/rspeers.h>
#include <retroshare/rsidentity.h>
#include <iostream>
#include <QPainter>
static void paintGxsId( QPainter * painter,
const QStyleOptionViewItem & option /*, const QRect &rect */, const RsGxsId &id )
{
QString desc;
QString comment;
QList<QIcon> 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<QIcon>::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);
}

View File

@ -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 <QTreeWidget>
#include <QStyledItemDelegate>
#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

View File

@ -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"))

View File

@ -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

View File

@ -210,7 +210,7 @@
</layout>
</item>
<item>
<widget class="GxsIdRSTreeWidget" name="threadTreeWidget">
<widget class="RSTreeWidget" name="threadTreeWidget">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
@ -521,9 +521,9 @@
<header>gui/common/RSTextBrowser.h</header>
</customwidget>
<customwidget>
<class>GxsIdRSTreeWidget</class>
<class>RSTreeWidget</class>
<extends>QTreeWidget</extends>
<header>gui/gxs/GxsIdTreeWidget.h</header>
<header>gui/common/RSTreeWidget.h</header>
</customwidget>
</customwidgets>
<resources>

View File

@ -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 \