CMake build error, status icon text tooltip

This commit is contained in:
Blue 2021-04-26 19:37:36 +03:00
parent 8310708c92
commit 4c5efad9dc
4 changed files with 59 additions and 11 deletions

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.3)
project(squawkUI) project(squawkUI)
# Instruct CMake to run moc automatically when needed. # Instruct CMake to run moc automatically when needed.
@ -8,7 +8,8 @@ set(CMAKE_AUTOUIC ON)
# Find the QtWidgets library # Find the QtWidgets library
find_package(Qt5 CONFIG REQUIRED COMPONENTS Widgets DBus Core) 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) if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS}) include_directories(${Boost_INCLUDE_DIRS})
endif() endif()

View File

@ -253,9 +253,11 @@ void FeedView::paintEvent(QPaintEvent* event)
option.features = QStyleOptionViewItem::WrapText; option.features = QStyleOptionViewItem::WrapText;
QPoint cursor = vp->mapFromGlobal(QCursor::pos()); QPoint cursor = vp->mapFromGlobal(QCursor::pos());
if (clearWidgetsMode && specialDelegate) { if (specialDelegate) {
MessageDelegate* del = static_cast<MessageDelegate*>(itemDelegate()); MessageDelegate* del = static_cast<MessageDelegate*>(itemDelegate());
del->beginClearWidgets(); if (clearWidgetsMode) {
del->beginClearWidgets();
}
} }
for (const QModelIndex& index : toRener) { for (const QModelIndex& index : toRener) {

View File

@ -28,6 +28,7 @@ constexpr int avatarHeight = 50;
constexpr int margin = 6; constexpr int margin = 6;
constexpr int textMargin = 2; constexpr int textMargin = 2;
constexpr int statusIconSize = 16; constexpr int statusIconSize = 16;
constexpr int maxAttachmentHeight = 500;
MessageDelegate::MessageDelegate(QObject* parent): MessageDelegate::MessageDelegate(QObject* parent):
QStyledItemDelegate(parent), QStyledItemDelegate(parent),
@ -41,6 +42,7 @@ buttonHeight(0),
barHeight(0), barHeight(0),
buttons(new std::map<QString, FeedButton*>()), buttons(new std::map<QString, FeedButton*>()),
bars(new std::map<QString, QProgressBar*>()), bars(new std::map<QString, QProgressBar*>()),
statusIcons(new std::map<QString, QLabel*>()),
idsToKeep(new std::set<QString>()), idsToKeep(new std::set<QString>()),
clearingWidgets(false) clearingWidgets(false)
{ {
@ -61,6 +63,10 @@ MessageDelegate::~MessageDelegate()
delete pair.second; delete pair.second;
} }
for (const std::pair<const QString, QLabel*>& pair: *statusIcons){
delete pair.second;
}
delete idsToKeep; delete idsToKeep;
delete buttons; delete buttons;
delete bars; delete bars;
@ -116,7 +122,6 @@ void MessageDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio
QRect rect; QRect rect;
painter->setFont(nickFont); painter->setFont(nickFont);
painter->drawText(opt.rect, opt.displayAlignment, data.sender, &rect); painter->drawText(opt.rect, opt.displayAlignment, data.sender, &rect);
opt.rect.adjust(0, rect.height() + textMargin, 0, 0); opt.rect.adjust(0, rect.height() + textMargin, 0, 0);
painter->save(); painter->save();
switch (data.attach.state) { switch (data.attach.state) {
@ -157,11 +162,13 @@ void MessageDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio
if (messageLeft > rect.x() - statusIconSize - margin) { if (messageLeft > rect.x() - statusIconSize - margin) {
messageLeft = rect.x() - statusIconSize - margin; messageLeft = rect.x() - statusIconSize - margin;
} }
QIcon q(Shared::icon(Shared::messageStateThemeIcons[static_cast<uint8_t>(data.state)])); QLabel* statusIcon = getStatusIcon(data);
if (data.state == Shared::Message::State::error) {
//TODO handle error tooltip QWidget* vp = static_cast<QWidget*>(painter->device());
} statusIcon->setParent(vp);
painter->drawPixmap(messageLeft, opt.rect.y(), q.pixmap(statusIconSize, statusIconSize)); statusIcon->move(messageLeft, opt.rect.y());
statusIcon->show();
opt.rect.adjust(0, statusIconSize + textMargin, 0, 0);
} }
painter->restore(); painter->restore();
@ -373,6 +380,31 @@ QProgressBar * MessageDelegate::getBar(const Models::FeedItem& data) const
return result; return result;
} }
QLabel * MessageDelegate::getStatusIcon(const Models::FeedItem& data) const
{
std::map<QString, QLabel*>::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<uint8_t>(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() void MessageDelegate::beginClearWidgets()
{ {
@ -385,6 +417,7 @@ void MessageDelegate::endClearWidgets()
if (clearingWidgets) { if (clearingWidgets) {
std::set<QString> toRemoveButtons; std::set<QString> toRemoveButtons;
std::set<QString> toRemoveBars; std::set<QString> toRemoveBars;
std::set<QString> toRemoveIcons;
for (const std::pair<const QString, FeedButton*>& pair: *buttons) { for (const std::pair<const QString, FeedButton*>& pair: *buttons) {
if (idsToKeep->find(pair.first) == idsToKeep->end()) { if (idsToKeep->find(pair.first) == idsToKeep->end()) {
delete pair.second; delete pair.second;
@ -397,6 +430,12 @@ void MessageDelegate::endClearWidgets()
toRemoveBars.insert(pair.first); toRemoveBars.insert(pair.first);
} }
} }
for (const std::pair<const QString, QLabel*>& pair: *statusIcons) {
if (idsToKeep->find(pair.first) == idsToKeep->end()) {
delete pair.second;
toRemoveIcons.insert(pair.first);
}
}
for (const QString& key : toRemoveButtons) { for (const QString& key : toRemoveButtons) {
buttons->erase(key); buttons->erase(key);
@ -404,6 +443,9 @@ void MessageDelegate::endClearWidgets()
for (const QString& key : toRemoveBars) { for (const QString& key : toRemoveBars) {
bars->erase(key); bars->erase(key);
} }
for (const QString& key : toRemoveIcons) {
statusIcons->erase(key);
}
idsToKeep->clear(); idsToKeep->clear();
clearingWidgets = false; clearingWidgets = false;
@ -440,7 +482,7 @@ QSize MessageDelegate::calculateAttachSize(const QString& path, const QRect& bou
QSize MessageDelegate::constrainAttachSize(QSize src, QSize bounds) const QSize MessageDelegate::constrainAttachSize(QSize src, QSize bounds) const
{ {
bounds.setHeight(500); bounds.setHeight(maxAttachmentHeight);
if (src.width() > bounds.width() || src.height() > bounds.height()) { if (src.width() > bounds.width() || src.height() > bounds.height()) {
src.scale(bounds, Qt::KeepAspectRatio); src.scale(bounds, Qt::KeepAspectRatio);

View File

@ -28,6 +28,7 @@
#include <QFontMetrics> #include <QFontMetrics>
#include <QPushButton> #include <QPushButton>
#include <QProgressBar> #include <QProgressBar>
#include <QLabel>
#include "shared/icons.h" #include "shared/icons.h"
#include "shared/global.h" #include "shared/global.h"
@ -61,6 +62,7 @@ protected:
void paintPreview(const Models::FeedItem& data, QPainter* painter, QStyleOptionViewItem& option) const; void paintPreview(const Models::FeedItem& data, QPainter* painter, QStyleOptionViewItem& option) const;
QPushButton* getButton(const Models::FeedItem& data) const; QPushButton* getButton(const Models::FeedItem& data) const;
QProgressBar* getBar(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; void clearHelperWidget(const Models::FeedItem& data) const;
QSize calculateAttachSize(const QString& path, const QRect& bounds) const; QSize calculateAttachSize(const QString& path, const QRect& bounds) const;
QSize constrainAttachSize(QSize src, QSize bounds) const; QSize constrainAttachSize(QSize src, QSize bounds) const;
@ -87,6 +89,7 @@ private:
std::map<QString, FeedButton*>* buttons; std::map<QString, FeedButton*>* buttons;
std::map<QString, QProgressBar*>* bars; std::map<QString, QProgressBar*>* bars;
std::map<QString, QLabel*>* statusIcons;
std::set<QString>* idsToKeep; std::set<QString>* idsToKeep;
bool clearingWidgets; bool clearingWidgets;