forked from blue/squawk
basic error download/upload files handling, need more testing
This commit is contained in:
parent
bd07c49755
commit
4307262f6e
8 changed files with 206 additions and 77 deletions
|
@ -394,16 +394,11 @@ void FeedView::setModel(QAbstractItemModel* p_model)
|
|||
}
|
||||
}
|
||||
|
||||
void FeedView::onMessageButtonPushed(const QString& messageId, bool download)
|
||||
void FeedView::onMessageButtonPushed(const QString& messageId)
|
||||
{
|
||||
if (specialModel) {
|
||||
Models::MessageFeed* feed = static_cast<Models::MessageFeed*>(model());
|
||||
|
||||
if (download) {
|
||||
feed->downloadAttachment(messageId);
|
||||
} else {
|
||||
feed->uploadAttachment(messageId);
|
||||
}
|
||||
feed->downloadAttachment(messageId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ protected slots:
|
|||
void rowsInserted(const QModelIndex & parent, int start, int end) override;
|
||||
void verticalScrollbarValueChanged(int value) override;
|
||||
void dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight, const QVector<int> & roles) override;
|
||||
void onMessageButtonPushed(const QString& messageId, bool download);
|
||||
void onMessageButtonPushed(const QString& messageId);
|
||||
void onMessageInvalidPath(const QString& messageId);
|
||||
void onModelSyncStateChange(Models::MessageFeed::SyncState state);
|
||||
|
||||
|
|
|
@ -137,19 +137,39 @@ void MessageDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio
|
|||
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:
|
||||
paintPreview(data, painter, opt);
|
||||
case Models::downloading:
|
||||
paintBar(getBar(data), painter, data.sentByMe, opt);
|
||||
break;
|
||||
case Models::remote:
|
||||
case Models::local:
|
||||
paintButton(getButton(data), painter, data.sentByMe, opt);
|
||||
break;
|
||||
case Models::ready:
|
||||
case Models::local:
|
||||
clearHelperWidget(data);
|
||||
paintPreview(data, painter, opt);
|
||||
break;
|
||||
case Models::errorDownload:
|
||||
case Models::errorUpload:
|
||||
case Models::errorDownload: {
|
||||
paintButton(getButton(data), painter, data.sentByMe, opt);
|
||||
painter->setFont(dateFont);
|
||||
QColor q = painter->pen().color();
|
||||
q.setAlpha(180);
|
||||
painter->setPen(q);
|
||||
painter->drawText(opt.rect, opt.displayAlignment, data.attach.error, &rect);
|
||||
opt.rect.adjust(0, rect.height() + textMargin, 0, 0);
|
||||
}
|
||||
|
||||
break;
|
||||
case Models::errorUpload:{
|
||||
clearHelperWidget(data);
|
||||
paintPreview(data, painter, opt);
|
||||
painter->setFont(dateFont);
|
||||
QColor q = painter->pen().color();
|
||||
q.setAlpha(180);
|
||||
painter->setPen(q);
|
||||
painter->drawText(opt.rect, opt.displayAlignment, data.attach.error, &rect);
|
||||
opt.rect.adjust(0, rect.height() + textMargin, 0, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
painter->restore();
|
||||
|
@ -212,18 +232,24 @@ QSize MessageDelegate::sizeHint(const QStyleOptionViewItem& option, const QModel
|
|||
case Models::none:
|
||||
break;
|
||||
case Models::uploading:
|
||||
messageSize.rheight() += calculateAttachSize(attach.localPath, messageRect).height() + textMargin;
|
||||
case Models::downloading:
|
||||
messageSize.rheight() += barHeight + textMargin;
|
||||
break;
|
||||
case Models::remote:
|
||||
case Models::local:
|
||||
messageSize.rheight() += buttonHeight + textMargin;
|
||||
break;
|
||||
case Models::ready:
|
||||
case Models::local:
|
||||
messageSize.rheight() += calculateAttachSize(attach.localPath, messageRect).height() + textMargin;
|
||||
break;
|
||||
case Models::errorDownload:
|
||||
messageSize.rheight() += buttonHeight + textMargin;
|
||||
messageSize.rheight() += dateMetrics.boundingRect(messageRect, Qt::TextWordWrap, attach.error).size().height() + textMargin;
|
||||
break;
|
||||
case Models::errorUpload:
|
||||
messageSize.rheight() += calculateAttachSize(attach.localPath, messageRect).height() + textMargin;
|
||||
messageSize.rheight() += dateMetrics.boundingRect(messageRect, Qt::TextWordWrap, attach.error).size().height() + textMargin;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -356,15 +382,7 @@ QPushButton * MessageDelegate::getButton(const Models::FeedItem& data) const
|
|||
std::map<QString, FeedButton*>::const_iterator itr = buttons->find(data.id);
|
||||
FeedButton* result = 0;
|
||||
if (itr != buttons->end()) {
|
||||
if (
|
||||
(data.attach.state == Models::remote && itr->second->download) ||
|
||||
(data.attach.state == Models::local && !itr->second->download)
|
||||
) {
|
||||
result = itr->second;
|
||||
} else {
|
||||
delete itr->second;
|
||||
buttons->erase(itr);
|
||||
}
|
||||
result = itr->second;
|
||||
} else {
|
||||
std::map<QString, QProgressBar*>::const_iterator barItr = bars->find(data.id);
|
||||
if (barItr != bars->end()) {
|
||||
|
@ -376,13 +394,7 @@ QPushButton * MessageDelegate::getButton(const Models::FeedItem& data) const
|
|||
if (result == 0) {
|
||||
result = new FeedButton();
|
||||
result->messageId = data.id;
|
||||
if (data.attach.state == Models::remote) {
|
||||
result->setText(QCoreApplication::translate("MessageLine", "Download"));
|
||||
result->download = true;
|
||||
} else {
|
||||
result->setText(QCoreApplication::translate("MessageLine", "Upload"));
|
||||
result->download = false;
|
||||
}
|
||||
result->setText(QCoreApplication::translate("MessageLine", "Download"));
|
||||
buttons->insert(std::make_pair(data.id, result));
|
||||
connect(result, &QPushButton::clicked, this, &MessageDelegate::onButtonPushed);
|
||||
}
|
||||
|
@ -529,7 +541,7 @@ void MessageDelegate::endClearWidgets()
|
|||
void MessageDelegate::onButtonPushed() const
|
||||
{
|
||||
FeedButton* btn = static_cast<FeedButton*>(sender());
|
||||
emit buttonPushed(btn->messageId, btn->download);
|
||||
emit buttonPushed(btn->messageId);
|
||||
}
|
||||
|
||||
void MessageDelegate::clearHelperWidget(const Models::FeedItem& data) const
|
||||
|
|
|
@ -55,7 +55,7 @@ public:
|
|||
void beginClearWidgets();
|
||||
|
||||
signals:
|
||||
void buttonPushed(const QString& messageId, bool download) const;
|
||||
void buttonPushed(const QString& messageId) const;
|
||||
void invalidPath(const QString& messageId) const;
|
||||
|
||||
protected:
|
||||
|
@ -77,7 +77,6 @@ private:
|
|||
class FeedButton : public QPushButton {
|
||||
public:
|
||||
QString messageId;
|
||||
bool download;
|
||||
};
|
||||
|
||||
QFont bodyFont;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue