From 4c5efad9dce74c1612162c5e876a2a00feba4b44 Mon Sep 17 00:00:00 2001 From: blue Date: Mon, 26 Apr 2021 19:37:36 +0300 Subject: [PATCH] CMake build error, status icon text tooltip --- ui/CMakeLists.txt | 5 ++-- ui/utils/feedview.cpp | 6 ++-- ui/utils/messagedelegate.cpp | 56 +++++++++++++++++++++++++++++++----- ui/utils/messagedelegate.h | 3 ++ 4 files changed, 59 insertions(+), 11 deletions(-) diff --git a/ui/CMakeLists.txt b/ui/CMakeLists.txt index c4a8aa6..d6e29d3 100644 --- a/ui/CMakeLists.txt +++ b/ui/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.3) project(squawkUI) # Instruct CMake to run moc automatically when needed. @@ -8,7 +8,8 @@ set(CMAKE_AUTOUIC ON) # Find the QtWidgets library find_package(Qt5 CONFIG REQUIRED COMPONENTS Widgets DBus Core) -find_package(Boost 1.36.0 CONFIG REQUIRED) +find_package(Boost 1.36.0 CONFIG REQUIRED COMPONENTS + date_time filesystem iostreams) if(Boost_FOUND) include_directories(${Boost_INCLUDE_DIRS}) endif() diff --git a/ui/utils/feedview.cpp b/ui/utils/feedview.cpp index 3f3b4b7..550b8d4 100644 --- a/ui/utils/feedview.cpp +++ b/ui/utils/feedview.cpp @@ -253,9 +253,11 @@ void FeedView::paintEvent(QPaintEvent* event) option.features = QStyleOptionViewItem::WrapText; QPoint cursor = vp->mapFromGlobal(QCursor::pos()); - if (clearWidgetsMode && specialDelegate) { + if (specialDelegate) { MessageDelegate* del = static_cast(itemDelegate()); - del->beginClearWidgets(); + if (clearWidgetsMode) { + del->beginClearWidgets(); + } } for (const QModelIndex& index : toRener) { diff --git a/ui/utils/messagedelegate.cpp b/ui/utils/messagedelegate.cpp index 02aca8f..910db72 100644 --- a/ui/utils/messagedelegate.cpp +++ b/ui/utils/messagedelegate.cpp @@ -28,6 +28,7 @@ constexpr int avatarHeight = 50; constexpr int margin = 6; constexpr int textMargin = 2; constexpr int statusIconSize = 16; +constexpr int maxAttachmentHeight = 500; MessageDelegate::MessageDelegate(QObject* parent): QStyledItemDelegate(parent), @@ -41,6 +42,7 @@ buttonHeight(0), barHeight(0), buttons(new std::map()), bars(new std::map()), +statusIcons(new std::map()), idsToKeep(new std::set()), clearingWidgets(false) { @@ -61,6 +63,10 @@ MessageDelegate::~MessageDelegate() delete pair.second; } + for (const std::pair& pair: *statusIcons){ + delete pair.second; + } + delete idsToKeep; delete buttons; delete bars; @@ -116,7 +122,6 @@ void MessageDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio QRect rect; painter->setFont(nickFont); painter->drawText(opt.rect, opt.displayAlignment, data.sender, &rect); - opt.rect.adjust(0, rect.height() + textMargin, 0, 0); painter->save(); switch (data.attach.state) { @@ -157,11 +162,13 @@ void MessageDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio if (messageLeft > rect.x() - statusIconSize - margin) { messageLeft = rect.x() - statusIconSize - margin; } - QIcon q(Shared::icon(Shared::messageStateThemeIcons[static_cast(data.state)])); - if (data.state == Shared::Message::State::error) { - //TODO handle error tooltip - } - painter->drawPixmap(messageLeft, opt.rect.y(), q.pixmap(statusIconSize, statusIconSize)); + QLabel* statusIcon = getStatusIcon(data); + + QWidget* vp = static_cast(painter->device()); + statusIcon->setParent(vp); + statusIcon->move(messageLeft, opt.rect.y()); + statusIcon->show(); + opt.rect.adjust(0, statusIconSize + textMargin, 0, 0); } painter->restore(); @@ -373,6 +380,31 @@ QProgressBar * MessageDelegate::getBar(const Models::FeedItem& data) const return result; } +QLabel * MessageDelegate::getStatusIcon(const Models::FeedItem& data) const +{ + std::map::const_iterator itr = statusIcons->find(data.id); + QLabel* result = 0; + + if (itr != statusIcons->end()) { + result = itr->second; + } else { + result = new QLabel(); + statusIcons->insert(std::make_pair(data.id, result)); + } + + QIcon q(Shared::icon(Shared::messageStateThemeIcons[static_cast(data.state)])); + QString tt = Shared::Global::getName(data.state); + if (data.state == Shared::Message::State::error) { + if (data.error > 0) { + tt += ": " + data.error; + } + } + + result->setToolTip(tt); + result->setPixmap(q.pixmap(statusIconSize)); + + return result; +} void MessageDelegate::beginClearWidgets() { @@ -385,6 +417,7 @@ void MessageDelegate::endClearWidgets() if (clearingWidgets) { std::set toRemoveButtons; std::set toRemoveBars; + std::set toRemoveIcons; for (const std::pair& pair: *buttons) { if (idsToKeep->find(pair.first) == idsToKeep->end()) { delete pair.second; @@ -397,6 +430,12 @@ void MessageDelegate::endClearWidgets() toRemoveBars.insert(pair.first); } } + for (const std::pair& pair: *statusIcons) { + if (idsToKeep->find(pair.first) == idsToKeep->end()) { + delete pair.second; + toRemoveIcons.insert(pair.first); + } + } for (const QString& key : toRemoveButtons) { buttons->erase(key); @@ -404,6 +443,9 @@ void MessageDelegate::endClearWidgets() for (const QString& key : toRemoveBars) { bars->erase(key); } + for (const QString& key : toRemoveIcons) { + statusIcons->erase(key); + } idsToKeep->clear(); clearingWidgets = false; @@ -440,7 +482,7 @@ QSize MessageDelegate::calculateAttachSize(const QString& path, const QRect& bou QSize MessageDelegate::constrainAttachSize(QSize src, QSize bounds) const { - bounds.setHeight(500); + bounds.setHeight(maxAttachmentHeight); if (src.width() > bounds.width() || src.height() > bounds.height()) { src.scale(bounds, Qt::KeepAspectRatio); diff --git a/ui/utils/messagedelegate.h b/ui/utils/messagedelegate.h index cbad6cd..ed42e2f 100644 --- a/ui/utils/messagedelegate.h +++ b/ui/utils/messagedelegate.h @@ -28,6 +28,7 @@ #include #include #include +#include #include "shared/icons.h" #include "shared/global.h" @@ -61,6 +62,7 @@ protected: void paintPreview(const Models::FeedItem& data, QPainter* painter, QStyleOptionViewItem& option) const; QPushButton* getButton(const Models::FeedItem& data) const; QProgressBar* getBar(const Models::FeedItem& data) const; + QLabel* getStatusIcon(const Models::FeedItem& data) const; void clearHelperWidget(const Models::FeedItem& data) const; QSize calculateAttachSize(const QString& path, const QRect& bounds) const; QSize constrainAttachSize(QSize src, QSize bounds) const; @@ -87,6 +89,7 @@ private: std::map* buttons; std::map* bars; + std::map* statusIcons; std::set* idsToKeep; bool clearingWidgets;