1
0
forked from blue/squawk

started progress bars, changed gcc standard to 17

This commit is contained in:
Blue 2021-03-22 21:04:26 +03:00
parent a0348b8fd2
commit 50bb3f5fd7
6 changed files with 96 additions and 8 deletions

View File

@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.4)
project(squawk)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)

View File

@ -302,7 +302,7 @@ void Models::MessageFeed::downloadAttachment(const QString& messageId)
QModelIndex ind = modelIndexById(messageId);
if (ind.isValid()) {
std::pair<Progress::iterator, bool> progressPair = downloads.insert(std::make_pair(messageId, 0));
if (!progressPair.second) { //Only to take action if we weren't already downloading it
if (progressPair.second) { //Only to take action if we weren't already downloading it
Shared::Message* msg = static_cast<Shared::Message*>(ind.internalPointer());
emit dataChanged(ind, ind);
emit fileLocalPathRequest(messageId, msg->getOutOfBandUrl());

View File

@ -431,6 +431,8 @@ void Squawk::fileError(const QString& messageId, const QString& error)
}
}
//TODO! Need to make it look like a standard message change event!
void Squawk::fileLocalPathResponse(const QString& messageId, const QString& path)
{
std::map<QString, std::set<Models::Roster::ElId>>::const_iterator itr = requestedFiles.find(messageId);

View File

@ -36,12 +36,17 @@ bodyMetrics(bodyFont),
nickMetrics(nickFont),
dateMetrics(dateFont),
buttonHeight(0),
barHeight(0),
buttons(new std::map<QString, FeedButton*>()),
bars(new std::map<QString, QProgressBar*>()),
idsToKeep(new std::set<QString>()),
clearingWidgets(false)
{
QPushButton btn;
buttonHeight = btn.sizeHint().height();
QProgressBar bar;
barHeight = bar.sizeHint().height();
}
MessageDelegate::~MessageDelegate()
@ -50,8 +55,13 @@ MessageDelegate::~MessageDelegate()
delete pair.second;
}
for (const std::pair<const QString, QProgressBar*>& pair: *bars){
delete pair.second;
}
delete idsToKeep;
delete buttons;
delete bars;
}
void MessageDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
@ -110,9 +120,11 @@ void MessageDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio
painter->save();
switch (data.attach.state) {
case Models::none:
break;
clearHelperWidget(data); //i can't imagine the situation where it's gonna be needed
break; //but it's a possible performance problem
case Models::uploading:
case Models::downloading:
paintBar(getBar(data), painter, data.sentByMe, opt);
break;
case Models::remote:
case Models::local:
@ -159,6 +171,7 @@ QSize MessageDelegate::sizeHint(const QStyleOptionViewItem& option, const QModel
break;
case Models::uploading:
case Models::downloading:
messageSize.rheight() += barHeight;
break;
case Models::remote:
case Models::local:
@ -225,6 +238,18 @@ void MessageDelegate::paintButton(QPushButton* btn, QPainter* painter, bool sent
option.rect.adjust(0, buttonHeight, 0, 0);
}
void MessageDelegate::paintBar(QProgressBar* bar, QPainter* painter, bool sentByMe, QStyleOptionViewItem& option) const
{
QPoint start = option.rect.topLeft();
QWidget* vp = static_cast<QWidget*>(painter->device());
bar->setParent(vp);
bar->move(start);
bar->resize(option.rect.width(), barHeight);
bar->show();
option.rect.adjust(0, barHeight, 0, 0);
}
QPushButton * MessageDelegate::getButton(const Models::FeedItem& data) const
{
@ -240,6 +265,12 @@ QPushButton * MessageDelegate::getButton(const Models::FeedItem& data) const
delete itr->second;
buttons->erase(itr);
}
} else {
std::map<QString, QProgressBar*>::const_iterator barItr = bars->find(data.id);
if (barItr != bars->end()) {
delete barItr->second;
bars->erase(barItr);
}
}
if (result == 0) {
@ -259,6 +290,30 @@ QPushButton * MessageDelegate::getButton(const Models::FeedItem& data) const
return result;
}
QProgressBar * MessageDelegate::getBar(const Models::FeedItem& data) const
{
std::map<QString, QProgressBar*>::const_iterator barItr = bars->find(data.id);
QProgressBar* result = 0;
if (barItr != bars->end()) {
result = barItr->second;
} else {
std::map<QString, FeedButton*>::const_iterator itr = buttons->find(data.id);
if (itr != buttons->end()) {
delete itr->second;
buttons->erase(itr);
}
}
if (result == 0) {
result = new QProgressBar();
bars->insert(std::make_pair(data.id, result));
}
result->setValue(data.attach.progress);
return result;
}
void MessageDelegate::beginClearWidgets()
{
@ -269,17 +324,27 @@ void MessageDelegate::beginClearWidgets()
void MessageDelegate::endClearWidgets()
{
if (clearingWidgets) {
std::set<QString> toRemove;
std::set<QString> toRemoveButtons;
std::set<QString> toRemoveBars;
for (const std::pair<const QString, FeedButton*>& pair: *buttons) {
if (idsToKeep->find(pair.first) == idsToKeep->end()) {
delete pair.second;
toRemove.insert(pair.first);
toRemoveButtons.insert(pair.first);
}
}
for (const std::pair<const QString, QProgressBar*>& pair: *bars) {
if (idsToKeep->find(pair.first) == idsToKeep->end()) {
delete pair.second;
toRemoveBars.insert(pair.first);
}
}
for (const QString& key : toRemove) {
for (const QString& key : toRemoveButtons) {
buttons->erase(key);
}
for (const QString& key : toRemoveBars) {
bars->erase(key);
}
idsToKeep->clear();
clearingWidgets = false;
@ -292,6 +357,22 @@ void MessageDelegate::onButtonPushed() const
emit buttonPushed(btn->messageId, btn->download);
}
void MessageDelegate::clearHelperWidget(const Models::FeedItem& data) const
{
std::map<QString, FeedButton*>::const_iterator itr = buttons->find(data.id);
if (itr != buttons->end()) {
delete itr->second;
buttons->erase(itr);
} else {
std::map<QString, QProgressBar*>::const_iterator barItr = bars->find(data.id);
if (barItr != bars->end()) {
delete barItr->second;
bars->erase(barItr);
}
}
}
// void MessageDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const
// {
//

View File

@ -27,6 +27,7 @@
#include <QFont>
#include <QFontMetrics>
#include <QPushButton>
#include <QProgressBar>
#include "shared/icons.h"
@ -55,7 +56,10 @@ signals:
protected:
void paintButton(QPushButton* btn, QPainter* painter, bool sentByMe, QStyleOptionViewItem& option) const;
void paintBar(QProgressBar* bar, QPainter* painter, bool sentByMe, QStyleOptionViewItem& option) const;
QPushButton* getButton(const Models::FeedItem& data) const;
QProgressBar* getBar(const Models::FeedItem& data) const;
void clearHelperWidget(const Models::FeedItem& data) const;
protected slots:
void onButtonPushed() const;
@ -75,8 +79,10 @@ private:
QFontMetrics dateMetrics;
int buttonHeight;
int barHeight;
std::map<QString, FeedButton*>* buttons;
std::map<QString, QProgressBar*>* bars;
std::set<QString>* idsToKeep;
bool clearingWidgets;
};

View File

@ -99,7 +99,6 @@ protected slots:
void onEnterPressed();
void onAttach();
void onFileSelected();
void onScrollResize();
void onBadgeClose();
void onClearButton();
void onTextEditDocSizeChanged(const QSizeF& size);