fixed colors in keyring with new ModelIndex based view (patch from sss)

This commit is contained in:
csoler 2017-12-16 17:46:44 +01:00
parent acbcba8a64
commit 3007fec1b2
4 changed files with 62 additions and 33 deletions

View file

@ -2,10 +2,8 @@
#include <time.h>
#include <retroshare/rspeers.h>
#include <QIcon>
#include <QBrush>
#define IMAGE_AUTHED ":/images/accepted16.png"
#define IMAGE_DENIED ":/images/denied16.png"
#define IMAGE_TRUSTED ":/images/rs-2.png"
/*TODO:
* using list here for internal data storage is not best option
@ -151,6 +149,7 @@ QVariant pgpid_item_model::data(const QModelIndex &index, int role) const
}
}
//we using editrole only where it is useful, for other data we use display, so no "else if" here
if(role == Qt::DisplayRole || role == Qt::EditRole)
{
switch(index.column())
@ -261,23 +260,29 @@ QVariant pgpid_item_model::data(const QModelIndex &index, int role) const
}
else if(role == Qt::BackgroundRole)
{
switch(index.column())
if (detail.accept_connection)
{
default:
{
//TODO: add access to bckground colors from networkdialog
if (detail.accept_connection)
if (detail.ownsign)
{
if (detail.ownsign)
;
return QBrush(mBackgroundColorOwnSign);
}
else
{
return QBrush(mBackgroundColorAcceptConnection);
}
}
break;
else
{
if (detail.hasSignedMe)
{
return QBrush(mBackgroundColorHasSignedMe);
}
else
{
return QBrush(mBackgroundColorDenied);
}
}
}
return QVariant();
}
@ -300,14 +305,14 @@ void pgpid_item_model::data_updated(std::list<RsPgpId> &new_neighs)
//reflect actual row count in model
if(old_size < new_size)
{
beginInsertRows(QModelIndex(), old_size - 1, old_size - 1 + new_size - old_size);
insertRows(old_size - 1 , new_size - old_size);
beginInsertRows(QModelIndex(), old_size, new_size);
insertRows(old_size, new_size - old_size);
endInsertRows();
}
else if(new_size < old_size)
{
beginRemoveRows(QModelIndex(), new_size - 1, new_size - 1 + old_size - new_size);
removeRows(old_size - 1, old_size - new_size);
beginRemoveRows(QModelIndex(), new_size, old_size);
removeRows(old_size, old_size - new_size);
endRemoveRows();
}
//update data in ui, to avoid unnecessary redraw and ui updates, updating only changed elements

View file

@ -3,6 +3,12 @@
#include <QAbstractItemModel>
#include <retroshare/rspeers.h>
#include <QColor>
#define IMAGE_AUTHED ":/images/accepted16.png"
#define IMAGE_DENIED ":/images/denied16.png"
#define IMAGE_TRUSTED ":/images/rs-2.png"
#define COLUMN_CHECK 0
#define COLUMN_PEERNAME 1
@ -29,12 +35,24 @@ public:
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
void setBackgroundColorSelf(QColor color) { mBackgroundColorSelf = color; }
void setBackgroundColorOwnSign(QColor color) { mBackgroundColorOwnSign = color; }
void setBackgroundColorAcceptConnection(QColor color) { mBackgroundColorAcceptConnection = color; }
void setBackgroundColorHasSignedMe(QColor color) { mBackgroundColorHasSignedMe = color; }
void setBackgroundColorDenied(QColor color) { mBackgroundColorDenied = color; }
public slots:
void data_updated(std::list<RsPgpId> &new_neighs);
private:
std::list<RsPgpId> &neighs;
float &font_height;
float font_height;
QColor mBackgroundColorSelf;
QColor mBackgroundColorOwnSign;
QColor mBackgroundColorAcceptConnection;
QColor mBackgroundColorHasSignedMe;
QColor mBackgroundColorDenied;
};
#endif // KEY_ITEM_MODEL_H