mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-02-25 09:11:28 -05:00
Added changes from braindead:
- simplified avatarwidget - prepared property-dependend stylesheets git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5176 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
ce22ab5be9
commit
b344aebbe6
@ -16,9 +16,6 @@
|
||||
<property name="windowTitle">
|
||||
<string notr="true">MainWindow</string>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
@ -116,15 +113,6 @@
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border: transparent;</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
@ -133,7 +121,7 @@
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="AvatarWidget" name="avatarWidget" native="true">
|
||||
<widget class="AvatarWidget" name="avatarWidget">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>116</width>
|
||||
@ -162,7 +150,7 @@
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="AvatarWidget" name="ownAvatarWidget" native="true">
|
||||
<widget class="AvatarWidget" name="ownAvatarWidget">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>116</width>
|
||||
@ -215,8 +203,8 @@
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>AvatarWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>gui/common/AvatarWidget.h</header>
|
||||
<extends>QLabel</extends>
|
||||
<header>gui/common/avatarwidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
|
@ -19,6 +19,7 @@
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#include <rshare.h>
|
||||
#include <retroshare/rsstatus.h>
|
||||
#include <retroshare/rspeers.h>
|
||||
#include <retroshare/rsmsgs.h>
|
||||
@ -33,7 +34,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
AvatarWidget::AvatarWidget(QWidget *parent) :
|
||||
QWidget(parent), ui(new Ui::AvatarWidget)
|
||||
QLabel(parent), ui(new Ui::AvatarWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
@ -53,33 +54,30 @@ AvatarWidget::~AvatarWidget()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
static bool isSmall(const QSize &size)
|
||||
QString AvatarWidget::frameState()
|
||||
{
|
||||
if (size.width() <= 70 && size.height() <= 70) {
|
||||
return true;
|
||||
switch (mFrameType)
|
||||
{
|
||||
case NO_FRAME:
|
||||
return "NOTHING";
|
||||
case NORMAL_FRAME:
|
||||
return "NORMAL";
|
||||
case STATUS_FRAME:
|
||||
switch (mPeerState)
|
||||
{
|
||||
case RS_STATUS_OFFLINE:
|
||||
return "OFFLINE";
|
||||
case RS_STATUS_INACTIVE:
|
||||
return "INACTIVE";
|
||||
case RS_STATUS_ONLINE:
|
||||
return "ONLINE";
|
||||
case RS_STATUS_AWAY:
|
||||
return "AWAY";
|
||||
case RS_STATUS_BUSY:
|
||||
return "BUSY";
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void AvatarWidget::resizeEvent(QResizeEvent */*event*/)
|
||||
{
|
||||
if (mFrameType == NO_FRAME) {
|
||||
return;
|
||||
}
|
||||
|
||||
QSize widgetSize = size();
|
||||
QSize avatarSize;
|
||||
if (isSmall(widgetSize)) {
|
||||
avatarSize = QSize(widgetSize.width() * 50 / 70, widgetSize.height() * 50 / 70);
|
||||
} else {
|
||||
avatarSize = QSize(widgetSize.width() * 96 / 116, widgetSize.height() * 96 / 116);
|
||||
}
|
||||
int x = (widgetSize.width() - avatarSize.width()) / 2;
|
||||
int y = (widgetSize.height() - avatarSize.height()) / 2;
|
||||
ui->avatarFrameLayout->setContentsMargins(x, y, x, y);
|
||||
|
||||
refreshStatus();
|
||||
return "NOTHING";
|
||||
}
|
||||
|
||||
void AvatarWidget::mouseReleaseEvent(QMouseEvent */*event*/)
|
||||
@ -99,7 +97,6 @@ void AvatarWidget::setFrameType(FrameType type)
|
||||
switch (mFrameType) {
|
||||
case NO_FRAME:
|
||||
disconnect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(updateStatus(const QString&, int)));
|
||||
ui->avatarFrameLayout->setContentsMargins(0, 0, 0, 0);
|
||||
break;
|
||||
case NORMAL_FRAME:
|
||||
disconnect(NotifyQt::getInstance(), SIGNAL(peerStatusChanged(QString,int)), this, SLOT(updateStatus(const QString&, int)));
|
||||
@ -111,6 +108,7 @@ void AvatarWidget::setFrameType(FrameType type)
|
||||
|
||||
refreshStatus();
|
||||
updateAvatar(QString::fromStdString(mId));
|
||||
Rshare::refreshStyleSheet(this, false);
|
||||
}
|
||||
|
||||
void AvatarWidget::setId(const std::string &id, bool isGpg)
|
||||
@ -120,13 +118,13 @@ void AvatarWidget::setId(const std::string &id, bool isGpg)
|
||||
|
||||
if (mId == rsPeers->getOwnId()) {
|
||||
mFlag.isOwnId = true;
|
||||
ui->avatar->setToolTip(tr("Click to change your avatar"));
|
||||
setToolTip(tr("Click to change your avatar"));
|
||||
}
|
||||
|
||||
ui->avatar->setPixmap(QPixmap());
|
||||
setPixmap(QPixmap());
|
||||
|
||||
if (mId.empty()) {
|
||||
ui->avatar->setEnabled(false);
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
refreshStatus();
|
||||
@ -148,62 +146,25 @@ void AvatarWidget::refreshStatus()
|
||||
{
|
||||
switch (mFrameType) {
|
||||
case NO_FRAME:
|
||||
ui->avatarFrame->setStyleSheet("");
|
||||
break;
|
||||
case NORMAL_FRAME:
|
||||
ui->avatarFrame->setStyleSheet(isSmall(size()) ? "QFrame#avatarFrame{ border-image:url(:/images/avatarstatus-bg-70.png); }" : "QFrame#avatarFrame{ border-image:url(:/images/avatarstatus-bg-116.png); }");
|
||||
{
|
||||
Rshare::refreshStyleSheet(this, false);
|
||||
break;
|
||||
}
|
||||
case STATUS_FRAME:
|
||||
{
|
||||
StatusInfo statusInfo;
|
||||
{
|
||||
StatusInfo statusInfo;
|
||||
|
||||
if (mFlag.isOwnId) {
|
||||
rsStatus->getOwnStatus(statusInfo);
|
||||
} else {
|
||||
// No check of return value. Non existing status info is handled as offline.
|
||||
rsStatus->getStatus(mId, statusInfo);
|
||||
}
|
||||
updateStatus(QString::fromStdString(statusInfo.id), statusInfo.status);
|
||||
if (mFlag.isOwnId) {
|
||||
rsStatus->getOwnStatus(statusInfo);
|
||||
} else {
|
||||
// No check of return value. Non existing status info is handled as offline.
|
||||
rsStatus->getStatus(mId, statusInfo);
|
||||
}
|
||||
updateStatus(QString::fromStdString(statusInfo.id), statusInfo.status);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static QString getStatusFrame(bool small, int status)
|
||||
{
|
||||
if (small) {
|
||||
switch (status) {
|
||||
case RS_STATUS_OFFLINE:
|
||||
return "QFrame#avatarFrame{ border-image:url(:/images/avatarstatus-bg-offline-70.png); }";
|
||||
case RS_STATUS_INACTIVE:
|
||||
return "QFrame#avatarFrame{ border-image:url(:/images/avatarstatus-bg-idle-70.png); }";
|
||||
case RS_STATUS_ONLINE:
|
||||
return "QFrame#avatarFrame{ border-image:url(:/images/avatarstatus-bg-online-70.png); }";
|
||||
case RS_STATUS_AWAY:
|
||||
return "QFrame#avatarFrame{ border-image:url(:/images/avatarstatus-bg-away-70.png); }";
|
||||
case RS_STATUS_BUSY:
|
||||
return "QFrame#avatarFrame{ border-image:url(:/images/avatarstatus-bg-busy-70.png); }";
|
||||
}
|
||||
|
||||
return "QFrame#avatarFrame{ border-image:url(:/images/avatarstatus-bg-70.png); }";
|
||||
} else {
|
||||
switch (status) {
|
||||
case RS_STATUS_OFFLINE:
|
||||
return "QFrame#avatarFrame{ border-image:url(:/images/avatarstatus-bg-offline-116.png); }";
|
||||
case RS_STATUS_INACTIVE:
|
||||
return "QFrame#avatarFrame{ border-image:url(:/images/avatarstatus-bg-idle-116.png); }";
|
||||
case RS_STATUS_ONLINE:
|
||||
return "QFrame#avatarFrame{ border-image:url(:/images/avatarstatus-bg-online-116.png); }";
|
||||
case RS_STATUS_AWAY:
|
||||
return "QFrame#avatarFrame{ border-image:url(:/images/avatarstatus-bg-away-116.png); }";
|
||||
case RS_STATUS_BUSY:
|
||||
return "QFrame#avatarFrame{ border-image:url(:/images/avatarstatus-bg-busy-116.png); }";
|
||||
}
|
||||
|
||||
return "QFrame#avatarFrame{ border-image:url(:/images/avatarstatus-bg-116.png); }";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
void AvatarWidget::updateStatus(const QString peerId, int status)
|
||||
@ -213,36 +174,31 @@ void AvatarWidget::updateStatus(const QString peerId, int status)
|
||||
}
|
||||
|
||||
if (mId.empty()) {
|
||||
ui->avatarFrame->setStyleSheet(getStatusFrame(isSmall(size()), RS_STATUS_OFFLINE));
|
||||
return;
|
||||
mPeerState = status;
|
||||
Rshare::refreshStyleSheet(this, false);
|
||||
} else {
|
||||
/* set style for status */
|
||||
if (mId == peerId.toStdString()) {
|
||||
// the peers status has changed
|
||||
mPeerState = status;
|
||||
setEnabled(((uint32_t) status == RS_STATUS_OFFLINE) ? false : true);
|
||||
Rshare::refreshStyleSheet(this, false);
|
||||
}
|
||||
}
|
||||
|
||||
/* set style for status */
|
||||
if (mId == peerId.toStdString()) {
|
||||
// the peers status has changed
|
||||
|
||||
ui->avatarFrame->setStyleSheet(getStatusFrame(isSmall(size()), status));
|
||||
|
||||
ui->avatar->setEnabled(((uint32_t) status == RS_STATUS_OFFLINE) ? false : true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// ignore status change
|
||||
}
|
||||
|
||||
void AvatarWidget::updateAvatar(const QString &peerId)
|
||||
{
|
||||
if (mId.empty()) {
|
||||
QPixmap avatar(defaultAvatar);
|
||||
ui->avatar->setPixmap(avatar);
|
||||
setPixmap(avatar);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mFlag.isOwnId) {
|
||||
QPixmap avatar;
|
||||
AvatarDefs::getOwnAvatar(avatar);
|
||||
ui->avatar->setPixmap(avatar);
|
||||
setPixmap(avatar);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -251,7 +207,7 @@ void AvatarWidget::updateAvatar(const QString &peerId)
|
||||
/* called from AvatarWidget with gpg id */
|
||||
QPixmap avatar;
|
||||
AvatarDefs::getAvatarFromGpgId(mId, avatar, defaultAvatar);
|
||||
ui->avatar->setPixmap(avatar);
|
||||
setPixmap(avatar);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -265,7 +221,7 @@ void AvatarWidget::updateAvatar(const QString &peerId)
|
||||
/* One of the ssl ids of the gpg id */
|
||||
QPixmap avatar;
|
||||
AvatarDefs::getAvatarFromGpgId(mId, avatar, defaultAvatar);
|
||||
ui->avatar->setPixmap(avatar);
|
||||
setPixmap(avatar);
|
||||
}
|
||||
|
||||
return;
|
||||
@ -274,7 +230,7 @@ void AvatarWidget::updateAvatar(const QString &peerId)
|
||||
if (mId == peerId.toStdString()) {
|
||||
QPixmap avatar;
|
||||
AvatarDefs::getAvatarFromSslId(mId, avatar, defaultAvatar);
|
||||
ui->avatar->setPixmap(avatar);
|
||||
setPixmap(avatar);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -22,15 +22,16 @@
|
||||
#ifndef AVATARWIDGET_H
|
||||
#define AVATARWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
|
||||
namespace Ui {
|
||||
class AvatarWidget;
|
||||
}
|
||||
|
||||
class AvatarWidget : public QWidget
|
||||
class AvatarWidget : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString frameState READ frameState)
|
||||
|
||||
public:
|
||||
enum FrameType {
|
||||
@ -43,13 +44,13 @@ public:
|
||||
AvatarWidget(QWidget *parent = 0);
|
||||
~AvatarWidget();
|
||||
|
||||
QString frameState();
|
||||
void setFrameType(FrameType type);
|
||||
void setId(const std::string& id, bool isGpg);
|
||||
void setOwnId();
|
||||
void setDefaultAvatar(const QString &avatar);
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
void mouseReleaseEvent(QMouseEvent *event);
|
||||
|
||||
private slots:
|
||||
@ -69,6 +70,7 @@ private:
|
||||
bool isGpg : 1;
|
||||
} mFlag;
|
||||
FrameType mFrameType;
|
||||
uint32_t mPeerState;
|
||||
};
|
||||
|
||||
#endif // AVATARWIDGET_H
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>AvatarWidget</class>
|
||||
<widget class="QWidget" name="AvatarWidget">
|
||||
<widget class="QLabel" name="AvatarWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
@ -10,36 +10,21 @@
|
||||
<height>116</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QFrame" name="avatarFrame">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QFrame#avatarFrame{ border-image:url(:/images/avatarstatus-bg-116.png); }</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="avatarFrameLayout">
|
||||
<property name="margin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="avatar">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">AvatarWidget{border-width: 10px;}
|
||||
AvatarWidget[frameState="NORMAL"]{border-image:url(:/images/avatarstatus-bg-116.png);}
|
||||
AvatarWidget[frameState="OFFLINE"]{border-image:url(:/images/avatarstatus-bg-offline-116.png);}
|
||||
AvatarWidget[frameState="INACTIVE"]{border-image:url(:/images/avatarstatus-bg-idle-116.png);}
|
||||
AvatarWidget[frameState="ONLINE"]{border-image:url(:/images/avatarstatus-bg-online-116.png);}
|
||||
AvatarWidget[frameState="AWAY"]{border-image:url(:/images/avatarstatus-bg-away-116.png);}
|
||||
AvatarWidget[frameState="BUSY"]{border-image:url(:/images/avatarstatus-bg-busy-116.png);}</string>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include <QTextStream>
|
||||
#include <QShortcut>
|
||||
#include <QStyleFactory>
|
||||
#include <QStyle>
|
||||
#include <gui/common/vmessagebox.h>
|
||||
#include <gui/common/html.h>
|
||||
#include <util/stringutil.h>
|
||||
@ -374,6 +375,31 @@ void Rshare::loadStyleSheet(const QString &sheetName)
|
||||
qApp->setStyleSheet(styleSheet);
|
||||
}
|
||||
|
||||
void Rshare::refreshStyleSheet(QWidget *widget, bool processChildren)
|
||||
{
|
||||
if (widget != NULL) {
|
||||
// force widget to recalculate valid style
|
||||
widget->style()->unpolish(widget);
|
||||
widget->style()->polish(widget);
|
||||
// widget might need to recalculate properties (like margins) depending on style
|
||||
QEvent event(QEvent::StyleChange);
|
||||
QApplication::sendEvent(widget, &event);
|
||||
// repaint widget
|
||||
widget->update();
|
||||
|
||||
if (processChildren == true) {
|
||||
// process children recursively
|
||||
QObjectList childList = widget->children ();
|
||||
for (QObjectList::Iterator it = childList.begin(); it != childList.end(); it++) {
|
||||
QWidget *child = qobject_cast<QWidget*>(*it);
|
||||
if (child != NULL) {
|
||||
refreshStyleSheet(child, processChildren);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Initialize plugins. */
|
||||
void Rshare::initPlugins()
|
||||
{
|
||||
|
@ -79,6 +79,8 @@ public:
|
||||
static bool setSheet(QString sheet = QString());
|
||||
/** Loads stylesheet from external file **/
|
||||
static void loadStyleSheet(const QString &sheetName);
|
||||
/** Recalculates matching stylesheet for widget **/
|
||||
static void refreshStyleSheet(QWidget *widget, bool processChildren);
|
||||
|
||||
/**
|
||||
* Update Language, Style and StyleSheet.
|
||||
|
Loading…
x
Reference in New Issue
Block a user