mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Merge pull request #536 from PhenomRetroShare/Add_ElidedLabelToGroupTreeWidget
Add ElidedLabel to GroupTreeWidget
This commit is contained in:
commit
c77d0521d0
@ -52,7 +52,9 @@ ElidedLabel::ElidedLabel(const QString &text, QWidget *parent)
|
||||
, mElided(false)
|
||||
, mOnlyPlainText(false)
|
||||
, mContent(text)
|
||||
, mTextColor(QColor())
|
||||
{
|
||||
setStyleSheet("background-color: rgba(0,0,0,0%)");
|
||||
mRectElision = QRect();
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
}
|
||||
@ -62,7 +64,9 @@ ElidedLabel::ElidedLabel(QWidget *parent)
|
||||
, mElided(false)
|
||||
, mOnlyPlainText(false)
|
||||
, mContent("")
|
||||
, mTextColor(QColor())
|
||||
{
|
||||
setStyleSheet("background-color: rgba(0,0,0,0%)");
|
||||
mRectElision = QRect();
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
}
|
||||
@ -225,3 +229,11 @@ void ElidedLabel::mousePressEvent(QMouseEvent *ev)
|
||||
}
|
||||
QLabel::mousePressEvent(ev);
|
||||
}
|
||||
|
||||
void ElidedLabel::setTextColor(const QColor &color)
|
||||
{
|
||||
QPalette tmpPalette = palette();
|
||||
tmpPalette.setColor(foregroundRole(), color);
|
||||
setPalette(tmpPalette);
|
||||
mTextColor = color;
|
||||
}
|
||||
|
@ -53,6 +53,7 @@ class ElidedLabel : public QLabel
|
||||
Q_PROPERTY(QString text READ text WRITE setText)
|
||||
Q_PROPERTY(bool isElided READ isElided)
|
||||
Q_PROPERTY(bool isOnlyPlainText READ isOnlyPlainText WRITE setOnlyPlainText)
|
||||
Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor)
|
||||
|
||||
public:
|
||||
ElidedLabel(const QString &text, QWidget *parent = 0);
|
||||
@ -62,6 +63,9 @@ public:
|
||||
bool isElided() const { return mElided; }
|
||||
bool isOnlyPlainText() const { return mOnlyPlainText; }
|
||||
|
||||
QColor textColor() const { return mTextColor; }
|
||||
void setTextColor(const QColor &color);
|
||||
|
||||
public slots:
|
||||
void setText(const QString &text);
|
||||
void setOnlyPlainText(const bool &value);
|
||||
@ -79,6 +83,7 @@ private:
|
||||
bool mOnlyPlainText;
|
||||
QString mContent;
|
||||
QRect mRectElision;
|
||||
QColor mTextColor;
|
||||
};
|
||||
|
||||
#endif // ELIDEDLABEL_H
|
||||
|
@ -510,6 +510,7 @@ static void getNameWidget(QTreeWidget *treeWidget, QTreeWidgetItem *item, Elided
|
||||
|
||||
if (!widget) {
|
||||
widget = new QWidget;
|
||||
widget->setAttribute(Qt::WA_TranslucentBackground);
|
||||
nameLabel = new ElidedLabel(widget);
|
||||
textLabel = new ElidedLabel(widget);
|
||||
|
||||
|
@ -18,20 +18,22 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
#include <QMenu>
|
||||
#include <QToolButton>
|
||||
#include <QLabel>
|
||||
#include <QMovie>
|
||||
|
||||
#include "retroshare/rsgxsflags.h"
|
||||
#include "GroupTreeWidget.h"
|
||||
#include "ui_GroupTreeWidget.h"
|
||||
|
||||
#include "RSItemDelegate.h"
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QMenu>
|
||||
#include <QMovie>
|
||||
#include <QToolButton>
|
||||
|
||||
#include "retroshare/rsgxsflags.h"
|
||||
|
||||
#include "PopularityDefs.h"
|
||||
#include "gui/settings/rsharesettings.h"
|
||||
#include "RSItemDelegate.h"
|
||||
#include "RSTreeWidgetItem.h"
|
||||
#include "gui/common/ElidedLabel.h"
|
||||
#include "gui/settings/rsharesettings.h"
|
||||
#include "util/QtVersion.h"
|
||||
|
||||
#include <stdint.h>
|
||||
@ -55,6 +57,9 @@
|
||||
#define FILTER_NAME_INDEX 0
|
||||
#define FILTER_DESC_INDEX 1
|
||||
|
||||
Q_DECLARE_METATYPE(ElidedLabel*)
|
||||
Q_DECLARE_METATYPE(QLabel*)
|
||||
|
||||
GroupTreeWidget::GroupTreeWidget(QWidget *parent) :
|
||||
QWidget(parent), ui(new Ui::GroupTreeWidget)
|
||||
{
|
||||
@ -116,6 +121,38 @@ GroupTreeWidget::~GroupTreeWidget()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
static void getNameWidget(QTreeWidget *treeWidget, QTreeWidgetItem *item, ElidedLabel *&nameLabel, QLabel *&waitLabel)
|
||||
{
|
||||
QWidget *widget = treeWidget->itemWidget(item, COLUMN_NAME);
|
||||
|
||||
if (!widget) {
|
||||
widget = new QWidget;
|
||||
widget->setAttribute(Qt::WA_TranslucentBackground);
|
||||
nameLabel = new ElidedLabel(widget);
|
||||
waitLabel = new QLabel(widget);
|
||||
QMovie *movie = new QMovie(":/images/loader/circleball-16.gif");
|
||||
waitLabel->setMovie(movie);
|
||||
waitLabel->setHidden(true);
|
||||
|
||||
widget->setProperty("nameLabel", qVariantFromValue(nameLabel));
|
||||
widget->setProperty("waitLabel", qVariantFromValue(waitLabel));
|
||||
|
||||
QHBoxLayout *layout = new QHBoxLayout;
|
||||
layout->setSpacing(0);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
layout->addWidget(nameLabel);
|
||||
layout->addWidget(waitLabel);
|
||||
|
||||
widget->setLayout(layout);
|
||||
|
||||
treeWidget->setItemWidget(item, COLUMN_NAME, widget);
|
||||
} else {
|
||||
nameLabel = widget->property("nameLabel").value<ElidedLabel*>();
|
||||
waitLabel = widget->property("waitLabel").value<QLabel*>();
|
||||
}
|
||||
}
|
||||
|
||||
void GroupTreeWidget::changeEvent(QEvent *e)
|
||||
{
|
||||
QWidget::changeEvent(e);
|
||||
@ -255,6 +292,11 @@ void GroupTreeWidget::updateColors()
|
||||
}
|
||||
|
||||
item->setForeground(COLUMN_NAME, brush);
|
||||
|
||||
ElidedLabel *nameLabel = NULL;
|
||||
QLabel *waitLabel = NULL;
|
||||
getNameWidget(ui->treeWidget, item, nameLabel, waitLabel);
|
||||
nameLabel->setTextColor(brush.color());
|
||||
}
|
||||
}
|
||||
|
||||
@ -293,21 +335,27 @@ QTreeWidgetItem *GroupTreeWidget::addCategoryItem(const QString &name, const QIc
|
||||
{
|
||||
QFont font;
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem();
|
||||
ui->treeWidget->addTopLevelItem(item);
|
||||
|
||||
ElidedLabel *nameLabel = NULL;
|
||||
QLabel *waitLabel = NULL;
|
||||
getNameWidget(ui->treeWidget, item, nameLabel, waitLabel);
|
||||
|
||||
nameLabel->setText(name);
|
||||
item->setData(COLUMN_DATA, ROLE_NAME, name);
|
||||
font = item->font(COLUMN_NAME);
|
||||
font.setBold(true);
|
||||
item->setText(COLUMN_NAME, name);
|
||||
item->setData(COLUMN_DATA, ROLE_NAME, name);
|
||||
item->setFont(COLUMN_NAME, font);
|
||||
nameLabel->setFont(font);
|
||||
item->setIcon(COLUMN_NAME, icon);
|
||||
|
||||
int S = QFontMetricsF(font).height();
|
||||
|
||||
item->setSizeHint(COLUMN_NAME, QSize(S*1.1, S*1.1));
|
||||
item->setForeground(COLUMN_NAME, QBrush(textColorCategory()));
|
||||
nameLabel->setTextColor(textColorCategory());
|
||||
item->setData(COLUMN_DATA, ROLE_COLOR, GROUPTREEWIDGET_COLOR_CATEGORY);
|
||||
|
||||
ui->treeWidget->addTopLevelItem(item);
|
||||
|
||||
item->setExpanded(expand);
|
||||
|
||||
return item;
|
||||
@ -364,7 +412,11 @@ void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList<
|
||||
categoryItem->addChild(item);
|
||||
}
|
||||
|
||||
item->setText(COLUMN_NAME, itemInfo.name);
|
||||
ElidedLabel *nameLabel = NULL;
|
||||
QLabel *waitLabel = NULL;
|
||||
getNameWidget(ui->treeWidget, item, nameLabel, waitLabel);
|
||||
|
||||
nameLabel->setText(itemInfo.name);
|
||||
item->setData(COLUMN_DATA, ROLE_NAME, itemInfo.name);
|
||||
item->setData(COLUMN_DATA, ROLE_DESCRIPTION, itemInfo.description);
|
||||
|
||||
@ -376,7 +428,7 @@ void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList<
|
||||
item->setData(COLUMN_DATA, ROLE_POSTS, -itemInfo.max_visible_posts);// negative for correct sorting
|
||||
|
||||
/* Set icon */
|
||||
if (ui->treeWidget->itemWidget(item, COLUMN_NAME)) {
|
||||
if (waitLabel->isVisible()) {
|
||||
/* Item is waiting, save icon in role */
|
||||
item->setData(COLUMN_DATA, ROLE_SAVED_ICON, itemInfo.icon);
|
||||
} else {
|
||||
@ -416,6 +468,7 @@ void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList<
|
||||
item->setData(COLUMN_DATA, ROLE_COLOR, GROUPTREEWIDGET_COLOR_STANDARD);
|
||||
}
|
||||
item->setForeground(COLUMN_NAME, brush);
|
||||
nameLabel->setTextColor(brush.color());
|
||||
|
||||
/* Calculate score */
|
||||
calculateScore(item, filterText);
|
||||
@ -449,19 +502,22 @@ void GroupTreeWidget::setUnreadCount(QTreeWidgetItem *item, int unreadCount)
|
||||
if (item == NULL) {
|
||||
return;
|
||||
}
|
||||
ElidedLabel *nameLabel = NULL;
|
||||
QLabel *waitLabel = NULL;
|
||||
getNameWidget(ui->treeWidget, item, nameLabel, waitLabel);
|
||||
|
||||
QString name = item->data(COLUMN_DATA, ROLE_NAME).toString();
|
||||
QFont font = item->font(COLUMN_NAME);
|
||||
QFont font = nameLabel->font();
|
||||
|
||||
if (unreadCount) {
|
||||
name += QString(" (%1)").arg(unreadCount);
|
||||
name = QString("(%1) ").arg(unreadCount) + name;
|
||||
font.setBold(true);
|
||||
} else {
|
||||
font.setBold(false);
|
||||
}
|
||||
|
||||
item->setText(COLUMN_NAME, name);
|
||||
item->setFont(COLUMN_NAME, font);
|
||||
nameLabel->setText(name);
|
||||
nameLabel->setFont(font);
|
||||
}
|
||||
|
||||
QTreeWidgetItem *GroupTreeWidget::getItemFromId(const QString &id)
|
||||
@ -507,9 +563,11 @@ bool GroupTreeWidget::setWaiting(const QString &id, bool wait)
|
||||
return false;
|
||||
}
|
||||
|
||||
QWidget *w = ui->treeWidget->itemWidget(item, COLUMN_NAME);
|
||||
ElidedLabel *nameLabel = NULL;
|
||||
QLabel *waitLabel = NULL;
|
||||
getNameWidget(ui->treeWidget, item, nameLabel, waitLabel);
|
||||
if (wait) {
|
||||
if (w) {
|
||||
if (waitLabel->isVisible()) {
|
||||
/* Allready waiting */
|
||||
} else {
|
||||
/* Save icon in role */
|
||||
@ -519,21 +577,19 @@ bool GroupTreeWidget::setWaiting(const QString &id, bool wait)
|
||||
/* Create empty icon of the same size */
|
||||
QPixmap pixmap(ui->treeWidget->iconSize());
|
||||
pixmap.fill(Qt::transparent);
|
||||
|
||||
item->setIcon(COLUMN_NAME, QIcon(pixmap));
|
||||
|
||||
QLabel *label = new QLabel(this);
|
||||
QMovie *movie = new QMovie(":/images/loader/circleball-16.gif");
|
||||
label->setMovie(movie);
|
||||
|
||||
ui->treeWidget->setItemWidget(item, COLUMN_NAME, label);
|
||||
|
||||
movie->start();
|
||||
/* Show waitLabel and hide nameLabel */
|
||||
nameLabel->setHidden(true);
|
||||
waitLabel->setVisible(true);
|
||||
waitLabel->movie()->start();
|
||||
}
|
||||
} else {
|
||||
if (w) {
|
||||
ui->treeWidget->setItemWidget(item, COLUMN_NAME, NULL);
|
||||
delete(w);
|
||||
if (waitLabel->isVisible()) {
|
||||
/* Show nameLabel and hide waitLabel */
|
||||
waitLabel->movie()->stop();
|
||||
waitLabel->setHidden(true);
|
||||
nameLabel->setVisible(true);
|
||||
|
||||
/* Set icon saved in role */
|
||||
item->setIcon(COLUMN_NAME, item->data(COLUMN_DATA, ROLE_SAVED_ICON).value<QIcon>());
|
||||
|
Loading…
Reference in New Issue
Block a user