mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-22 06:09:09 -04:00
Fix GroupTreeWidget with RSElidedItemDelegate for StyleSheet.
This commit is contained in:
parent
cfcd68e661
commit
c6350ff044
5 changed files with 86 additions and 130 deletions
|
@ -18,28 +18,20 @@
|
|||
* *
|
||||
*******************************************************************************/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "GroupTreeWidget.h"
|
||||
#include "ui_GroupTreeWidget.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QLabel>
|
||||
#include <QMenu>
|
||||
#include <QMovie>
|
||||
#include <QToolButton>
|
||||
|
||||
#include "retroshare/rsgxsflags.h"
|
||||
|
||||
#include "PopularityDefs.h"
|
||||
#include "RSElidedItemDelegate.h"
|
||||
#include "RSTreeWidgetItem.h"
|
||||
#include "gui/common/ElidedLabel.h"
|
||||
#include "gui/settings/rsharesettings.h"
|
||||
#include "util/QtVersion.h"
|
||||
#include "util/DateTime.h"
|
||||
|
||||
#include <QMenu>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define COLUMN_NAME 0
|
||||
|
@ -66,9 +58,6 @@
|
|||
#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)
|
||||
{
|
||||
|
@ -143,7 +132,7 @@ GroupTreeWidget::GroupTreeWidget(QWidget *parent) :
|
|||
/* Initialize display button */
|
||||
initDisplayMenu(ui->displayButton);
|
||||
|
||||
ui->treeWidget->setIconSize(QSize(S*1.8,S*1.8));
|
||||
ui->treeWidget->setIconSize(QSize(S*1.8,S*1.8));
|
||||
}
|
||||
|
||||
GroupTreeWidget::~GroupTreeWidget()
|
||||
|
@ -151,38 +140,6 @@ 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);
|
||||
|
@ -346,11 +303,6 @@ void GroupTreeWidget::updateColors()
|
|||
}
|
||||
|
||||
item->setForeground(COLUMN_NAME, brush);
|
||||
|
||||
ElidedLabel *nameLabel = NULL;
|
||||
QLabel *waitLabel = NULL;
|
||||
getNameWidget(ui->treeWidget, item, nameLabel, waitLabel);
|
||||
nameLabel->setTextColor(brush.color());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -390,24 +342,21 @@ QTreeWidgetItem *GroupTreeWidget::addCategoryItem(const QString &name, const QIc
|
|||
QFont font;
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem();
|
||||
ui->treeWidget->addTopLevelItem(item);
|
||||
// To get StyleSheet for Items
|
||||
ui->treeWidget->style()->unpolish(ui->treeWidget);
|
||||
ui->treeWidget->style()->polish(ui->treeWidget);
|
||||
|
||||
ElidedLabel *nameLabel = NULL;
|
||||
QLabel *waitLabel = NULL;
|
||||
getNameWidget(ui->treeWidget, item, nameLabel, waitLabel);
|
||||
|
||||
nameLabel->setText(name);
|
||||
item->setText(COLUMN_NAME, name);
|
||||
item->setData(COLUMN_DATA, ROLE_NAME, name);
|
||||
font = item->font(COLUMN_NAME);
|
||||
font.setBold(true);
|
||||
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.9, S*1.9));
|
||||
item->setForeground(COLUMN_NAME, QBrush(textColorCategory()));
|
||||
nameLabel->setTextColor(textColorCategory());
|
||||
item->setData(COLUMN_DATA, ROLE_COLOR, GROUPTREEWIDGET_COLOR_CATEGORY);
|
||||
|
||||
item->setExpanded(expand);
|
||||
|
@ -437,19 +386,19 @@ void GroupTreeWidget::setDistSearchVisible(bool visible)
|
|||
|
||||
bool GroupTreeWidget::isSearchRequestResult(QPoint &point,QString& group_id,uint32_t& search_req_id)
|
||||
{
|
||||
QTreeWidgetItem *item = ui->treeWidget->itemAt(point);
|
||||
QTreeWidgetItem *item = ui->treeWidget->itemAt(point);
|
||||
if (item == NULL)
|
||||
return false;
|
||||
|
||||
QTreeWidgetItem *parent = item->parent();
|
||||
QTreeWidgetItem *parent = item->parent();
|
||||
|
||||
if(parent == NULL)
|
||||
return false ;
|
||||
if(parent == NULL)
|
||||
return false ;
|
||||
|
||||
search_req_id = parent->data(COLUMN_DATA, ROLE_REQUEST_ID).toUInt();
|
||||
group_id = itemId(item) ;
|
||||
group_id = itemId(item) ;
|
||||
|
||||
return search_req_id > 0;
|
||||
return search_req_id > 0;
|
||||
}
|
||||
|
||||
bool GroupTreeWidget::isSearchRequestItem(QPoint &point,uint32_t& search_req_id)
|
||||
|
@ -514,11 +463,7 @@ void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList<
|
|||
categoryItem->addChild(item);
|
||||
}
|
||||
|
||||
ElidedLabel *nameLabel = NULL;
|
||||
QLabel *waitLabel = NULL;
|
||||
getNameWidget(ui->treeWidget, item, nameLabel, waitLabel);
|
||||
|
||||
nameLabel->setText(itemInfo.name);
|
||||
item->setText(COLUMN_NAME, itemInfo.name);
|
||||
item->setData(COLUMN_DATA, ROLE_NAME, itemInfo.name);
|
||||
item->setData(COLUMN_DATA, ROLE_DESCRIPTION, itemInfo.description);
|
||||
|
||||
|
@ -535,12 +480,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 (waitLabel->isVisible()) {
|
||||
/* Item is waiting, save icon in role */
|
||||
item->setData(COLUMN_DATA, ROLE_SAVED_ICON, itemInfo.icon);
|
||||
} else {
|
||||
item->setIcon(COLUMN_NAME, itemInfo.icon);
|
||||
}
|
||||
item->setIcon(COLUMN_NAME, itemInfo.icon);
|
||||
|
||||
/* Set popularity */
|
||||
QString tooltip = PopularityDefs::tooltip(itemInfo.popularity);
|
||||
|
@ -582,7 +522,6 @@ 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);
|
||||
|
@ -616,11 +555,8 @@ void GroupTreeWidget::setUnreadCount(QTreeWidgetItem *item, int unreadCount)
|
|||
if (item == NULL) {
|
||||
return;
|
||||
}
|
||||
ElidedLabel *nameLabel = NULL;
|
||||
QLabel *waitLabel = NULL;
|
||||
getNameWidget(ui->treeWidget, item, nameLabel, waitLabel);
|
||||
|
||||
QFont font = nameLabel->font();
|
||||
QFont font = item->font(COLUMN_NAME);
|
||||
|
||||
if (unreadCount) {
|
||||
item->setData(COLUMN_DATA, ROLE_UNREAD, unreadCount);
|
||||
|
@ -631,7 +567,7 @@ void GroupTreeWidget::setUnreadCount(QTreeWidgetItem *item, int unreadCount)
|
|||
font.setBold(false);
|
||||
}
|
||||
|
||||
nameLabel->setFont(font);
|
||||
item->setFont(COLUMN_NAME, font);
|
||||
}
|
||||
|
||||
QTreeWidgetItem *GroupTreeWidget::getItemFromId(const QString &id)
|
||||
|
@ -677,40 +613,7 @@ bool GroupTreeWidget::setWaiting(const QString &id, bool wait)
|
|||
return false;
|
||||
}
|
||||
|
||||
ElidedLabel *nameLabel = NULL;
|
||||
QLabel *waitLabel = NULL;
|
||||
getNameWidget(ui->treeWidget, item, nameLabel, waitLabel);
|
||||
if (wait) {
|
||||
if (waitLabel->isVisible()) {
|
||||
/* Allready waiting */
|
||||
} else {
|
||||
/* Save icon in role */
|
||||
QIcon icon = item->icon(COLUMN_NAME);
|
||||
item->setData(COLUMN_DATA, ROLE_SAVED_ICON, icon);
|
||||
|
||||
/* Create empty icon of the same size */
|
||||
QPixmap pixmap(ui->treeWidget->iconSize());
|
||||
pixmap.fill(Qt::transparent);
|
||||
item->setIcon(COLUMN_NAME, QIcon(pixmap));
|
||||
|
||||
/* Show waitLabel and hide nameLabel */
|
||||
nameLabel->setHidden(true);
|
||||
waitLabel->setVisible(true);
|
||||
waitLabel->movie()->start();
|
||||
}
|
||||
} else {
|
||||
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>());
|
||||
item->setData(COLUMN_DATA, ROLE_SAVED_ICON, QIcon());
|
||||
}
|
||||
}
|
||||
|
||||
item->setData(COLUMN_NAME, Qt::StatusTipRole, wait ? "waiting" : "");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue