diff --git a/.travis.yml b/.travis.yml index 499a393ed..4fec84f99 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,8 +24,8 @@ before_install: sudo apt-get install -y build-essential libssl-dev libsqlcipher-dev libbz2-dev libsqlite3-dev libupnp-dev pkg-config qt5-default libxss-dev qtmultimedia5-dev - libqt5x11extras5-dev libqt5designer5 libqt5svg5-dev - libxapian-dev qttools5-dev rapidjson-dev ; + libqt5x11extras5-dev libqt5designer5 libxapian-dev qttools5-dev + rapidjson-dev ; fi - if [ $TRAVIS_OS_NAME == osx ]; then brew update ; fi - if [ $TRAVIS_OS_NAME == osx ]; then brew install qt5; fi diff --git a/retroshare-gui/src/gui/common/GroupTreeWidget.cpp b/retroshare-gui/src/gui/common/GroupTreeWidget.cpp index a206c32ac..8a5516f6f 100644 --- a/retroshare-gui/src/gui/common/GroupTreeWidget.cpp +++ b/retroshare-gui/src/gui/common/GroupTreeWidget.cpp @@ -18,20 +18,28 @@ * * *******************************************************************************/ +#include + #include "GroupTreeWidget.h" #include "ui_GroupTreeWidget.h" +#include +#include +#include +#include +#include +#include + #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 - #include #define COLUMN_NAME 0 @@ -58,6 +66,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) { @@ -140,6 +151,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(); + waitLabel = widget->property("waitLabel").value(); + } +} + void GroupTreeWidget::changeEvent(QEvent *e) { QWidget::changeEvent(e); @@ -303,6 +346,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()); } } @@ -343,17 +391,23 @@ QTreeWidgetItem *GroupTreeWidget::addCategoryItem(const QString &name, const QIc QTreeWidgetItem *item = new QTreeWidgetItem(); ui->treeWidget->addTopLevelItem(item); - item->setText(COLUMN_NAME, name); + 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->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); @@ -383,19 +437,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) @@ -460,7 +514,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); @@ -477,7 +535,12 @@ void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList< item->setData(COLUMN_DATA, ROLE_POSTS, -itemInfo.max_visible_posts);// negative for correct sorting /* Set icon */ - item->setIcon(COLUMN_NAME, itemInfo.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); + } /* Set popularity */ QString tooltip = PopularityDefs::tooltip(itemInfo.popularity); @@ -519,6 +582,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); @@ -552,8 +616,11 @@ 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 = item->font(COLUMN_NAME); + QFont font = nameLabel->font(); if (unreadCount) { item->setData(COLUMN_DATA, ROLE_UNREAD, unreadCount); @@ -564,7 +631,7 @@ void GroupTreeWidget::setUnreadCount(QTreeWidgetItem *item, int unreadCount) font.setBold(false); } - item->setFont(COLUMN_NAME, font); + nameLabel->setFont(font); } QTreeWidgetItem *GroupTreeWidget::getItemFromId(const QString &id) @@ -610,7 +677,40 @@ bool GroupTreeWidget::setWaiting(const QString &id, bool wait) return false; } - item->setData(COLUMN_NAME, Qt::StatusTipRole, wait ? "waiting" : ""); + 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()); + item->setData(COLUMN_DATA, ROLE_SAVED_ICON, QIcon()); + } + } + return true; } @@ -619,25 +719,6 @@ RSTreeWidget *GroupTreeWidget::treeWidget() return ui->treeWidget; } -void GroupTreeWidget::setWaitingSVG(const QString &value) -{ - if (ui->treeWidget->itemDelegate()) - ui->treeWidget->itemDelegate()->setProperty("waitingSVG",value); - - for(int i=0; itreeWidget->itemDelegateForColumn(i)) - ui->treeWidget->itemDelegateForColumn(i)->setProperty("waitingSVG",value); -} -void GroupTreeWidget::setWaitingSVG_Over(const bool &value) -{ - if (ui->treeWidget->itemDelegate()) - ui->treeWidget->itemDelegate()->setProperty("waitingSVG_Over",value); - - for(int i=0; itreeWidget->itemDelegateForColumn(i)) - ui->treeWidget->itemDelegateForColumn(i)->setProperty("waitingSVG_Over",value); -} - bool GroupTreeWidget::getGroupName(QString id, QString& name) { QTreeWidgetItem *item = getItemFromId(id); diff --git a/retroshare-gui/src/gui/common/GroupTreeWidget.h b/retroshare-gui/src/gui/common/GroupTreeWidget.h index 7332d8b61..cc414c6db 100644 --- a/retroshare-gui/src/gui/common/GroupTreeWidget.h +++ b/retroshare-gui/src/gui/common/GroupTreeWidget.h @@ -21,6 +21,8 @@ #ifndef GROUPTREEWIDGET_H #define GROUPTREEWIDGET_H +#include +#include #include #include @@ -66,8 +68,6 @@ class GroupTreeWidget : public QWidget Q_PROPERTY(QColor textColorCategory READ textColorCategory WRITE setTextColorCategory) Q_PROPERTY(QColor textColorPrivateKey READ textColorPrivateKey WRITE setTextColorPrivateKey) - Q_PROPERTY(QString waitingSVG WRITE setWaitingSVG) - Q_PROPERTY(bool waitingSVG_Over WRITE setWaitingSVG_Over) public: GroupTreeWidget(QWidget *parent = 0); @@ -109,11 +109,7 @@ public: void setTextColorCategory(QColor color) { mTextColor[GROUPTREEWIDGET_COLOR_CATEGORY] = color; } void setTextColorPrivateKey(QColor color) { mTextColor[GROUPTREEWIDGET_COLOR_PRIVATEKEY] = color; } - - void setWaitingSVG(const QString &value); - void setWaitingSVG_Over(const bool &value); - - bool getGroupName(QString id, QString& name); + bool getGroupName(QString id, QString& name); int subscribeFlags(const QString &id); diff --git a/retroshare-gui/src/gui/common/RSElidedItemDelegate.cpp b/retroshare-gui/src/gui/common/RSElidedItemDelegate.cpp index 87784702b..6407c2fe1 100644 --- a/retroshare-gui/src/gui/common/RSElidedItemDelegate.cpp +++ b/retroshare-gui/src/gui/common/RSElidedItemDelegate.cpp @@ -23,7 +23,6 @@ #include "gui/common/StyledElidedLabel.h" #include "util/rsdebug.h" -#include #include #include #include @@ -33,9 +32,7 @@ RSElidedItemDelegate::RSElidedItemDelegate(QObject *parent) : RSStyledItemDelegate(parent) , mOnlyPlainText(false), mPaintRoundedRect(true) - , mWaitingSVG(":/icons/svg/waiting.svg"), mWaitingSVG_Over(true) { - mSVG_Renderer = new QSvgRenderer(this); } QSize RSElidedItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const @@ -127,35 +124,13 @@ void RSElidedItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem & } // draw the icon { - if (!ownOption.icon.isNull()) - { - QString status; - if (index.data(Qt::StatusTipRole).canConvert(QMetaType::QString)) - status = index.data(Qt::StatusTipRole).toString(); - - if (mWaitingSVG_Over || (status.toLower() != "waiting")) - { - QIcon::Mode mode = QIcon::Normal; - if (!(ownOption.state & QStyle::State_Enabled)) - mode = QIcon::Disabled; - else if (ownOption.state & QStyle::State_Selected) - mode = QIcon::Selected; - QIcon::State state = ownOption.state & QStyle::State_Open ? QIcon::On : QIcon::Off; - ownOption.icon.paint(painter, iconRect, ownOption.decorationAlignment, mode, state); - } - if (status.toLower() == "waiting") - { - if (mLastSVG_Loaded != mWaitingSVG) - mSVG_Renderer->load(mWaitingSVG); - mLastSVG_Loaded = mWaitingSVG; - - const QAbstractItemView* aiv = dynamic_cast(option.widget); - if (aiv) - connect(mSVG_Renderer, SIGNAL(repaintNeeded()), aiv->viewport(),SLOT(update())); - - mSVG_Renderer->render(painter, iconRect); - } - } + QIcon::Mode mode = QIcon::Normal; + if (!(ownOption.state & QStyle::State_Enabled)) + mode = QIcon::Disabled; + else if (ownOption.state & QStyle::State_Selected) + mode = QIcon::Selected; + QIcon::State state = ownOption.state & QStyle::State_Open ? QIcon::On : QIcon::Off; + ownOption.icon.paint(painter, iconRect, ownOption.decorationAlignment, mode, state); } // draw the text if (!ownOption.text.isEmpty()) { @@ -166,7 +141,6 @@ void RSElidedItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem & if (ownOption.state & QStyle::State_Selected) { painter->setPen(ownOption.palette.color(cg, QPalette::HighlightedText)); } else { -#if QT_VERSION >= QT_VERSION_CHECK(5,6,0) if (ownOption.state & QStyle::State_MouseOver) { //TODO: Manage to get palette with HOVER css pseudoclass // For now this is hidden by Qt: https://code.woboq.org/qt5/qtbase/src/widgets/styles/qstylesheetstyle.cpp.html#6103 @@ -253,7 +227,6 @@ void RSElidedItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem & painter->setPen(moColor); } else -#endif if (textColor.spec()==QColor::Invalid) { painter->setPen(ownOption.palette.color(cg, QPalette::Text)); } else { //Only get color from index for unselected(as Qt does) diff --git a/retroshare-gui/src/gui/common/RSElidedItemDelegate.h b/retroshare-gui/src/gui/common/RSElidedItemDelegate.h index 3c78d40cb..9e2ff7cc9 100644 --- a/retroshare-gui/src/gui/common/RSElidedItemDelegate.h +++ b/retroshare-gui/src/gui/common/RSElidedItemDelegate.h @@ -23,18 +23,11 @@ #include -#include - class RSElidedItemDelegate : public RSStyledItemDelegate { Q_OBJECT - - // For now, these properties cannot be changed by StyleSheet - // If needed, you can add properties to owner widget then copy them in this delegate. Q_PROPERTY(bool isOnlyPlainText READ isOnlyPlainText WRITE setOnlyPlainText) Q_PROPERTY(bool paintRoundedRect READ paintRoundedRect WRITE setPaintRoundedRect) - Q_PROPERTY(QString waitingSVG READ waitingSVG WRITE setWaitingSVG) - Q_PROPERTY(bool waitingSVG_Over READ waitingSVG_Over WRITE setWaitingSVG_Over) public: RSElidedItemDelegate(QObject *parent = 0); @@ -46,10 +39,6 @@ public: void setOnlyPlainText(const bool &value) { mOnlyPlainText = value; } bool paintRoundedRect() const { return mPaintRoundedRect; } void setPaintRoundedRect(const bool &value) { mPaintRoundedRect = value; } - QString waitingSVG() const {return mWaitingSVG; } - void setWaitingSVG(const QString &value) {mWaitingSVG = value; } - bool waitingSVG_Over() const {return mWaitingSVG_Over; } - void setWaitingSVG_Over(const bool &value) {mWaitingSVG_Over = value; } protected: bool editorEvent(QEvent *event, @@ -60,10 +49,7 @@ protected: private: bool mOnlyPlainText; bool mPaintRoundedRect; - QSvgRenderer* mSVG_Renderer; - mutable QString mLastSVG_Loaded; - QString mWaitingSVG; - bool mWaitingSVG_Over; + }; #endif // RSELIDEDITEMDELEGATE_H diff --git a/retroshare-gui/src/gui/icons.qrc b/retroshare-gui/src/gui/icons.qrc index 37cffa4c8..a2d5b89d2 100644 --- a/retroshare-gui/src/gui/icons.qrc +++ b/retroshare-gui/src/gui/icons.qrc @@ -217,7 +217,6 @@ icons/svg/thumbs-up.svg icons/svg/upload.svg icons/svg/video.svg - icons/svg/waiting.svg icons/switch00_128.png icons/switch01_128.png icons/switch10_128.png diff --git a/retroshare-gui/src/gui/icons/svg/waiting.svg b/retroshare-gui/src/gui/icons/svg/waiting.svg deleted file mode 100644 index c1f564cee..000000000 --- a/retroshare-gui/src/gui/icons/svg/waiting.svg +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - diff --git a/retroshare-gui/src/qss/qdarkstyle-v2.qss b/retroshare-gui/src/qss/qdarkstyle-v2.qss index 2b707e12b..0ad0b4d51 100644 --- a/retroshare-gui/src/qss/qdarkstyle-v2.qss +++ b/retroshare-gui/src/qss/qdarkstyle-v2.qss @@ -2143,10 +2143,3 @@ PostedCardView > QFrame#mainFrame[new=true] { WireGroupItem QFrame#frame{ background: transparent; } - -GxsChannelDialog GroupTreeWidget#groupTreeWidget{ - background-color: #F050F0; - qproperty-waitingSVG_Over: false; - qproperty-waitingSVG: url(%THISPATH%/qdarkstyle/channel_waiting.svg); -} - diff --git a/retroshare-gui/src/qss/qdarkstyle/channel_waiting.svg b/retroshare-gui/src/qss/qdarkstyle/channel_waiting.svg deleted file mode 100644 index ce28e3c64..000000000 --- a/retroshare-gui/src/qss/qdarkstyle/channel_waiting.svg +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - diff --git a/retroshare-gui/src/retroshare-gui.pro b/retroshare-gui/src/retroshare-gui.pro index b03560c47..a5d6838ae 100644 --- a/retroshare-gui/src/retroshare-gui.pro +++ b/retroshare-gui/src/retroshare-gui.pro @@ -19,7 +19,7 @@ !include("../../retroshare.pri"): error("Could not include file ../../retroshare.pri") TEMPLATE = app -QT += network xml svg +QT += network xml CONFIG += qt gui uic qrc resources idle CONFIG += console TARGET = retroshare