forked from blue/squawk
cleanup some warnings suppression
This commit is contained in:
parent
5fbb03fc46
commit
23ec80ccba
26 changed files with 630 additions and 924 deletions
|
@ -19,6 +19,8 @@
|
|||
#include "chat.h"
|
||||
#include "ui_conversation.h"
|
||||
|
||||
#include "shared/defines.h"
|
||||
|
||||
Chat::Chat(Models::Account* acc, Models::Contact* p_contact, QWidget* parent):
|
||||
Conversation(false, acc, p_contact, p_contact->getJid(), "", parent),
|
||||
contact(p_contact)
|
||||
|
@ -39,6 +41,7 @@ Chat::~Chat()
|
|||
{}
|
||||
|
||||
void Chat::onContactChanged(Models::Item* item, int row, int col) {
|
||||
SHARED_UNUSED(row);
|
||||
if (item == contact) {
|
||||
switch (col) {
|
||||
case 0:
|
||||
|
|
|
@ -115,15 +115,14 @@ Conversation::Conversation(bool muc, Models::Account* acc, Models::Element* el,
|
|||
initializeOverlay();
|
||||
}
|
||||
|
||||
Conversation::~Conversation()
|
||||
{
|
||||
Conversation::~Conversation() {
|
||||
delete contextMenu;
|
||||
|
||||
element->feed->decrementObservers();
|
||||
}
|
||||
|
||||
void Conversation::onAccountChanged(Models::Item* item, int row, int col)
|
||||
{
|
||||
void Conversation::onAccountChanged(Models::Item* item, int row, int col) {
|
||||
SHARED_UNUSED(row);
|
||||
if (item == account) {
|
||||
if (col == 2 && account->getState() == Shared::ConnectionState::connected) { //to request the history when we're back online after reconnect
|
||||
//if (!requestingHistory) {
|
||||
|
@ -136,8 +135,7 @@ void Conversation::onAccountChanged(Models::Item* item, int row, int col)
|
|||
}
|
||||
}
|
||||
|
||||
void Conversation::initializeOverlay()
|
||||
{
|
||||
void Conversation::initializeOverlay() {
|
||||
QGridLayout* gr = static_cast<QGridLayout*>(layout());
|
||||
QLabel* progressLabel = new QLabel(tr("Drop files here to attach them to your message"));
|
||||
gr->addWidget(overlay, 0, 0, 2, 1);
|
||||
|
@ -160,26 +158,22 @@ void Conversation::initializeOverlay()
|
|||
overlay->hide();
|
||||
}
|
||||
|
||||
void Conversation::setName(const QString& name)
|
||||
{
|
||||
void Conversation::setName(const QString& name) {
|
||||
m_ui->nameLabel->setText(name);
|
||||
setWindowTitle(name);
|
||||
}
|
||||
|
||||
QString Conversation::getAccount() const
|
||||
{
|
||||
QString Conversation::getAccount() const {
|
||||
return account->getName();
|
||||
}
|
||||
|
||||
QString Conversation::getJid() const
|
||||
{
|
||||
QString Conversation::getJid() const {
|
||||
return palJid;
|
||||
}
|
||||
|
||||
KeyEnterReceiver::KeyEnterReceiver(QObject* parent): QObject(parent), ownEvent(false) {}
|
||||
|
||||
bool KeyEnterReceiver::eventFilter(QObject* obj, QEvent* event)
|
||||
{
|
||||
bool KeyEnterReceiver::eventFilter(QObject* obj, QEvent* event) {
|
||||
QEvent::Type type = event->type();
|
||||
if (type == QEvent::KeyPress) {
|
||||
QKeyEvent* key = static_cast<QKeyEvent*>(event);
|
||||
|
@ -215,18 +209,15 @@ bool Conversation::checkClipboardImage() {
|
|||
return !QApplication::clipboard()->image().isNull();
|
||||
}
|
||||
|
||||
QString Conversation::getPalResource() const
|
||||
{
|
||||
QString Conversation::getPalResource() const {
|
||||
return activePalResource;
|
||||
}
|
||||
|
||||
void Conversation::setPalResource(const QString& res)
|
||||
{
|
||||
void Conversation::setPalResource(const QString& res) {
|
||||
activePalResource = res;
|
||||
}
|
||||
|
||||
void Conversation::initiateMessageSending()
|
||||
{
|
||||
void Conversation::initiateMessageSending() {
|
||||
QString body(m_ui->messageEditor->toPlainText());
|
||||
|
||||
if (body.size() > 0) {
|
||||
|
@ -245,8 +236,7 @@ void Conversation::initiateMessageSending()
|
|||
clear();
|
||||
}
|
||||
|
||||
void Conversation::initiateMessageSending(const Shared::Message& msg)
|
||||
{
|
||||
void Conversation::initiateMessageSending(const Shared::Message& msg) {
|
||||
if (currentAction == CurrentAction::edit) {
|
||||
emit replaceMessage(currentMessageId, msg);
|
||||
currentAction = CurrentAction::none;
|
||||
|
@ -255,12 +245,11 @@ void Conversation::initiateMessageSending(const Shared::Message& msg)
|
|||
}
|
||||
}
|
||||
|
||||
void Conversation::onImagePasted()
|
||||
{
|
||||
void Conversation::onImagePasted() {
|
||||
QImage image = QApplication::clipboard()->image();
|
||||
if (image.isNull()) {
|
||||
if (image.isNull())
|
||||
return;
|
||||
}
|
||||
|
||||
QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + QStringLiteral("/squawk_img_attach_XXXXXX.png"), QApplication::instance());
|
||||
tempFile->open();
|
||||
image.save(tempFile, "PNG");
|
||||
|
@ -273,8 +262,7 @@ void Conversation::onImagePasted()
|
|||
// See Core::NetworkAccess::onUploadFinished.
|
||||
}
|
||||
|
||||
void Conversation::onAttach()
|
||||
{
|
||||
void Conversation::onAttach() {
|
||||
QFileDialog* d = new QFileDialog(this, tr("Chose a file to send"));
|
||||
d->setFileMode(QFileDialog::ExistingFile);
|
||||
|
||||
|
@ -284,37 +272,31 @@ void Conversation::onAttach()
|
|||
d->show();
|
||||
}
|
||||
|
||||
void Conversation::onFileSelected()
|
||||
{
|
||||
void Conversation::onFileSelected() {
|
||||
QFileDialog* d = static_cast<QFileDialog*>(sender());
|
||||
|
||||
for (const QString& path : d->selectedFiles()) {
|
||||
for (const QString& path : d->selectedFiles())
|
||||
addAttachedFile(path);
|
||||
}
|
||||
|
||||
d->deleteLater();
|
||||
}
|
||||
|
||||
void Conversation::setStatus(const QString& status)
|
||||
{
|
||||
void Conversation::setStatus(const QString& status) {
|
||||
statusLabel->setText(Shared::processMessageBody(status));
|
||||
}
|
||||
|
||||
Models::Roster::ElId Conversation::getId() const
|
||||
{
|
||||
Models::Roster::ElId Conversation::getId() const {
|
||||
return {getAccount(), getJid()};
|
||||
}
|
||||
|
||||
void Conversation::addAttachedFile(const QString& path)
|
||||
{
|
||||
void Conversation::addAttachedFile(const QString& path) {
|
||||
QMimeDatabase db;
|
||||
QMimeType type = db.mimeTypeForFile(path);
|
||||
QFileInfo info(path);
|
||||
|
||||
QIcon fileIcon = QIcon::fromTheme(type.iconName());
|
||||
if (fileIcon.isNull()) {
|
||||
if (fileIcon.isNull())
|
||||
fileIcon.addFile(QString::fromUtf8(":/images/fallback/dark/big/mail-attachment.svg"), QSize(), QIcon::Normal, QIcon::Off);
|
||||
}
|
||||
|
||||
Badge* badge = new Badge(path, info.fileName(), fileIcon);
|
||||
|
||||
connect(badge, &Badge::close, this, &Conversation::onBadgeClose);
|
||||
|
@ -331,35 +313,31 @@ void Conversation::addAttachedFile(const QString& path)
|
|||
}
|
||||
}
|
||||
|
||||
void Conversation::removeAttachedFile(Badge* badge)
|
||||
{
|
||||
void Conversation::removeAttachedFile(Badge* badge) {
|
||||
W::Order<Badge*, Badge::Comparator>::const_iterator itr = filesToAttach.find(badge);
|
||||
if (itr != filesToAttach.end()) {
|
||||
filesToAttach.erase(badge);
|
||||
if (filesLayout->count() == 1) {
|
||||
if (filesLayout->count() == 1)
|
||||
filesLayout->setContentsMargins(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
badge->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void Conversation::onBadgeClose()
|
||||
{
|
||||
void Conversation::onBadgeClose() {
|
||||
Badge* badge = static_cast<Badge*>(sender());
|
||||
removeAttachedFile(badge);
|
||||
}
|
||||
|
||||
void Conversation::clearAttachedFiles()
|
||||
{
|
||||
for (Badge* badge : filesToAttach) {
|
||||
void Conversation::clearAttachedFiles() {
|
||||
for (Badge* badge : filesToAttach)
|
||||
badge->deleteLater();
|
||||
}
|
||||
|
||||
filesToAttach.clear();
|
||||
filesLayout->setContentsMargins(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
void Conversation::clear()
|
||||
{
|
||||
void Conversation::clear() {
|
||||
currentMessageId.clear();
|
||||
currentAction = CurrentAction::none;
|
||||
m_ui->currentActionBadge->setVisible(false);
|
||||
|
@ -367,8 +345,7 @@ void Conversation::clear()
|
|||
m_ui->messageEditor->clear();
|
||||
}
|
||||
|
||||
void Conversation::setAvatar(const QString& path)
|
||||
{
|
||||
void Conversation::setAvatar(const QString& path) {
|
||||
QPixmap pixmap;
|
||||
if (path.size() == 0) {
|
||||
pixmap = Shared::icon("user", true).pixmap(avatarSize);
|
||||
|
@ -390,13 +367,11 @@ void Conversation::setAvatar(const QString& path)
|
|||
m_ui->avatar->setPixmap(result);
|
||||
}
|
||||
|
||||
void Conversation::onTextEditDocSizeChanged(const QSizeF& size)
|
||||
{
|
||||
void Conversation::onTextEditDocSizeChanged(const QSizeF& size) {
|
||||
m_ui->messageEditor->setMaximumHeight(int(size.height()));
|
||||
}
|
||||
|
||||
void Conversation::setFeedFrames(bool top, bool right, bool bottom, bool left)
|
||||
{
|
||||
void Conversation::setFeedFrames(bool top, bool right, bool bottom, bool left) {
|
||||
shadow.setFrames(top, right, bottom, left);
|
||||
}
|
||||
|
||||
|
@ -421,13 +396,12 @@ void Conversation::dragEnterEvent(QDragEnterEvent* event)
|
|||
}
|
||||
}
|
||||
|
||||
void Conversation::dragLeaveEvent(QDragLeaveEvent* event)
|
||||
{
|
||||
void Conversation::dragLeaveEvent(QDragLeaveEvent* event) {
|
||||
SHARED_UNUSED(event);
|
||||
overlay->hide();
|
||||
}
|
||||
|
||||
void Conversation::dropEvent(QDropEvent* event)
|
||||
{
|
||||
void Conversation::dropEvent(QDropEvent* event) {
|
||||
bool accept = false;
|
||||
if (event->mimeData()->hasUrls()) {
|
||||
QList<QUrl> list = event->mimeData()->urls();
|
||||
|
@ -441,14 +415,13 @@ void Conversation::dropEvent(QDropEvent* event)
|
|||
}
|
||||
}
|
||||
}
|
||||
if (accept) {
|
||||
if (accept)
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
overlay->hide();
|
||||
}
|
||||
|
||||
Shared::Message Conversation::createMessage() const
|
||||
{
|
||||
Shared::Message Conversation::createMessage() const {
|
||||
Shared::Message msg;
|
||||
msg.setOutgoing(true);
|
||||
msg.generateRandomId();
|
||||
|
@ -457,23 +430,20 @@ Shared::Message Conversation::createMessage() const
|
|||
return msg;
|
||||
}
|
||||
|
||||
void Conversation::onFeedMessage(const Shared::Message& msg)
|
||||
{
|
||||
void Conversation::onFeedMessage(const Shared::Message& msg) {
|
||||
this->onMessage(msg);
|
||||
}
|
||||
|
||||
void Conversation::onMessage(const Shared::Message& msg)
|
||||
{
|
||||
void Conversation::onMessage(const Shared::Message& msg) {
|
||||
if (!msg.getForwarded()) {
|
||||
QApplication::alert(this);
|
||||
if (window()->windowState().testFlag(Qt::WindowMinimized)) {
|
||||
if (window()->windowState().testFlag(Qt::WindowMinimized))
|
||||
emit notifyableMessage(getAccount(), msg);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Conversation::positionShadow()
|
||||
{
|
||||
void Conversation::positionShadow() {
|
||||
int w = width();
|
||||
int h = feed->height();
|
||||
|
||||
|
@ -482,8 +452,7 @@ void Conversation::positionShadow()
|
|||
shadow.raise();
|
||||
}
|
||||
|
||||
void Conversation::onFeedContext(const QPoint& pos)
|
||||
{
|
||||
void Conversation::onFeedContext(const QPoint& pos) {
|
||||
QModelIndex index = feed->indexAt(pos);
|
||||
if (index.isValid()) {
|
||||
Shared::Message* item = static_cast<Shared::Message*>(index.internalPointer());
|
||||
|
@ -542,14 +511,12 @@ void Conversation::onFeedContext(const QPoint& pos)
|
|||
connect(edit, &QAction::triggered, this, std::bind(&Conversation::onMessageEditRequested, this, id));
|
||||
}
|
||||
|
||||
if (showMenu) {
|
||||
if (showMenu)
|
||||
contextMenu->popup(feed->viewport()->mapToGlobal(pos));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Conversation::onMessageEditorContext(const QPoint& pos)
|
||||
{
|
||||
void Conversation::onMessageEditorContext(const QPoint& pos) {
|
||||
pasteImageAction->setEnabled(Conversation::checkClipboardImage());
|
||||
|
||||
QMenu *editorMenu = m_ui->messageEditor->createStandardContextMenu();
|
||||
|
@ -559,8 +526,7 @@ void Conversation::onMessageEditorContext(const QPoint& pos)
|
|||
editorMenu->exec(this->m_ui->messageEditor->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void Conversation::onMessageEditRequested(const QString& id)
|
||||
{
|
||||
void Conversation::onMessageEditRequested(const QString& id) {
|
||||
clear();
|
||||
|
||||
try {
|
||||
|
@ -582,8 +548,7 @@ void Conversation::onMessageEditRequested(const QString& id)
|
|||
}
|
||||
}
|
||||
|
||||
void Conversation::showEvent(QShowEvent* event)
|
||||
{
|
||||
void Conversation::showEvent(QShowEvent* event) {
|
||||
QWidget::showEvent(event);
|
||||
|
||||
emit shown();
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "shared/icons.h"
|
||||
#include "shared/utils.h"
|
||||
#include "shared/pathcheck.h"
|
||||
#include "shared/defines.h"
|
||||
|
||||
#include "ui/models/account.h"
|
||||
#include "ui/models/roster.h"
|
||||
|
@ -159,8 +160,6 @@ private:
|
|||
static QPainterPath* avatarMask;
|
||||
static QPixmap* avatarPixmap;
|
||||
static QPainter* avatarPainter;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // CONVERSATION_H
|
||||
|
|
|
@ -79,11 +79,10 @@ QModelIndex FeedView::indexAt(const QPoint& point) const {
|
|||
for (std::deque<Hint>::size_type i = 0; i < hints.size(); ++i) {
|
||||
const Hint& hint = hints[i];
|
||||
if (y <= hint.offset + hint.height) {
|
||||
if (y > hint.offset) {
|
||||
if (y > hint.offset)
|
||||
return model()->index(i, 0, rootIndex());
|
||||
} else {
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,13 +155,11 @@ void FeedView::updateGeometries() {
|
|||
vo = 0;
|
||||
} else {
|
||||
int verticalMargin = 0;
|
||||
if (st->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents)) {
|
||||
if (st->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents))
|
||||
frameAroundContents = st->pixelMetric(QStyle::PM_DefaultFrameWidth) * 2;
|
||||
}
|
||||
|
||||
if (verticalScrollBarPolicy() == Qt::ScrollBarAsNeeded) {
|
||||
if (verticalScrollBarPolicy() == Qt::ScrollBarAsNeeded)
|
||||
verticalMargin = verticalScrollBarExtent + frameAroundContents;
|
||||
}
|
||||
|
||||
layoutBounds.rwidth() -= verticalMargin;
|
||||
|
||||
|
@ -176,21 +173,19 @@ void FeedView::updateGeometries() {
|
|||
QModelIndex index = m->index(i, 0, rootIndex());
|
||||
QDateTime currentDate = index.data(Models::MessageFeed::Date).toDateTime();
|
||||
if (i > 0) {
|
||||
if (currentDate.daysTo(lastDate) > 0) {
|
||||
if (currentDate.daysTo(lastDate) > 0)
|
||||
previousOffset += dividerMetrics.height() + dateDeviderMargin * 2;
|
||||
} else {
|
||||
else
|
||||
previousOffset += elementMargin;
|
||||
}
|
||||
}
|
||||
lastDate = currentDate;
|
||||
QSize messageSize = itemDelegate(index)->sizeHint(option, index);
|
||||
uint32_t offsetX(0);
|
||||
if (specialDelegate) {
|
||||
if (index.data(Models::MessageFeed::SentByMe).toBool()) {
|
||||
if (index.data(Models::MessageFeed::SentByMe).toBool())
|
||||
offsetX = layoutBounds.width() - messageSize.width() - MessageDelegate::avatarHeight - MessageDelegate::margin * 2;
|
||||
} else {
|
||||
else
|
||||
offsetX = MessageDelegate::avatarHeight + MessageDelegate::margin * 2;
|
||||
}
|
||||
}
|
||||
|
||||
hints.emplace_back(Hint({
|
||||
|
@ -204,9 +199,9 @@ void FeedView::updateGeometries() {
|
|||
}
|
||||
|
||||
int totalHeight = previousOffset - layoutBounds.height() + dividerMetrics.height() + dateDeviderMargin * 2;
|
||||
if (modelState != Models::MessageFeed::complete) {
|
||||
if (modelState != Models::MessageFeed::complete)
|
||||
totalHeight += progressSize;
|
||||
}
|
||||
|
||||
vo = qMax(qMin(vo, totalHeight), 0);
|
||||
bar->setRange(0, totalHeight);
|
||||
bar->setPageStep(layoutBounds.height());
|
||||
|
@ -219,7 +214,6 @@ void FeedView::updateGeometries() {
|
|||
clearWidgetsMode = true;
|
||||
}
|
||||
|
||||
|
||||
QAbstractItemView::updateGeometries();
|
||||
}
|
||||
|
||||
|
@ -230,26 +224,23 @@ bool FeedView::tryToCalculateGeometriesWithNoScrollbars(const QStyleOptionViewIt
|
|||
QModelIndex index = m->index(i, 0, rootIndex());
|
||||
QDateTime currentDate = index.data(Models::MessageFeed::Date).toDateTime();
|
||||
if (i > 0) {
|
||||
if (currentDate.daysTo(lastDate) > 0) {
|
||||
if (currentDate.daysTo(lastDate) > 0)
|
||||
previousOffset += dateDeviderMargin * 2 + dividerMetrics.height();
|
||||
} else {
|
||||
else
|
||||
previousOffset += elementMargin;
|
||||
}
|
||||
}
|
||||
lastDate = currentDate;
|
||||
QSize messageSize = itemDelegate(index)->sizeHint(option, index);
|
||||
|
||||
if (previousOffset + messageSize.height() + elementMargin > totalHeight) {
|
||||
if (previousOffset + messageSize.height() + elementMargin > totalHeight)
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t offsetX(0);
|
||||
if (specialDelegate) {
|
||||
if (index.data(Models::MessageFeed::SentByMe).toBool()) {
|
||||
if (index.data(Models::MessageFeed::SentByMe).toBool())
|
||||
offsetX = option.rect.width() - messageSize.width() - MessageDelegate::avatarHeight - MessageDelegate::margin * 2;
|
||||
} else {
|
||||
else
|
||||
offsetX = MessageDelegate::avatarHeight + MessageDelegate::margin * 2;
|
||||
}
|
||||
}
|
||||
hints.emplace_back(Hint({
|
||||
false,
|
||||
|
@ -262,9 +253,8 @@ bool FeedView::tryToCalculateGeometriesWithNoScrollbars(const QStyleOptionViewIt
|
|||
}
|
||||
|
||||
previousOffset += dateDeviderMargin * 2 + dividerMetrics.height();
|
||||
if (previousOffset > totalHeight) {
|
||||
if (previousOffset > totalHeight)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -284,13 +274,12 @@ void FeedView::paintEvent(QPaintEvent* event) {
|
|||
const Hint& hint = hints[i];
|
||||
int32_t relativeY1 = vph - hint.offset - hint.height;
|
||||
if (!inZone) {
|
||||
if (y2 > relativeY1) {
|
||||
if (y2 > relativeY1)
|
||||
inZone = true;
|
||||
}
|
||||
}
|
||||
if (inZone) {
|
||||
if (inZone)
|
||||
toRener.emplace_back(m->index(i, 0, rootIndex()));
|
||||
}
|
||||
|
||||
if (y1 > relativeY1) {
|
||||
inZone = false;
|
||||
break;
|
||||
|
@ -304,9 +293,8 @@ void FeedView::paintEvent(QPaintEvent* event) {
|
|||
|
||||
if (specialDelegate) {
|
||||
MessageDelegate* del = static_cast<MessageDelegate*>(itemDelegate());
|
||||
if (clearWidgetsMode) {
|
||||
if (clearWidgetsMode)
|
||||
del->beginClearWidgets();
|
||||
}
|
||||
}
|
||||
|
||||
QDateTime lastDate;
|
||||
|
@ -319,9 +307,8 @@ void FeedView::paintEvent(QPaintEvent* event) {
|
|||
int ind = index.row() - 1;
|
||||
if (ind > 0) {
|
||||
QDateTime underDate = m->index(ind, 0, rootIndex()).data(Models::MessageFeed::Date).toDateTime();
|
||||
if (currentDate.daysTo(underDate) > 0) {
|
||||
if (currentDate.daysTo(underDate) > 0)
|
||||
drawDateDevider(option.rect.bottom(), underDate, painter);
|
||||
}
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
|
@ -332,14 +319,13 @@ void FeedView::paintEvent(QPaintEvent* event) {
|
|||
option.state.setFlag(QStyle::State_MouseOver, mouseOver);
|
||||
itemDelegate(index)->paint(&painter, option, index);
|
||||
|
||||
if (!lastDate.isNull() && currentDate.daysTo(lastDate) > 0) {
|
||||
if (!lastDate.isNull() && currentDate.daysTo(lastDate) > 0)
|
||||
drawDateDevider(option.rect.bottom(), lastDate, painter);
|
||||
}
|
||||
|
||||
lastDate = currentDate;
|
||||
}
|
||||
if (!lastDate.isNull() && inZone) { //if after drawing all messages there is still space
|
||||
if (!lastDate.isNull() && inZone) //if after drawing all messages there is still space
|
||||
drawDateDevider(option.rect.top() - dateDeviderMargin * 2 - dividerMetrics.height(), lastDate, painter);
|
||||
}
|
||||
|
||||
if (clearWidgetsMode && specialDelegate) {
|
||||
MessageDelegate* del = static_cast<MessageDelegate*>(itemDelegate());
|
||||
|
@ -362,13 +348,11 @@ void FeedView::verticalScrollbarValueChanged(int value) {
|
|||
|
||||
positionProgress();
|
||||
|
||||
if (specialDelegate) {
|
||||
if (specialDelegate)
|
||||
clearWidgetsMode = true;
|
||||
}
|
||||
|
||||
if (modelState == Models::MessageFeed::incomplete && value < progressSize) {
|
||||
if (modelState == Models::MessageFeed::incomplete && value < progressSize)
|
||||
model()->fetchMore(rootIndex());
|
||||
}
|
||||
|
||||
QAbstractItemView::verticalScrollbarValueChanged(vo);
|
||||
}
|
||||
|
@ -391,16 +375,14 @@ void FeedView::setAnchorHovered(Shared::Hover type) {
|
|||
}
|
||||
|
||||
void FeedView::mouseMoveEvent(QMouseEvent* event) {
|
||||
if (!isVisible()) {
|
||||
if (!isVisible())
|
||||
return;
|
||||
}
|
||||
|
||||
dragEndPoint = event->localPos().toPoint();
|
||||
if (mousePressed) {
|
||||
QPoint distance = dragStartPoint - dragEndPoint;
|
||||
if (distance.manhattanLength() > 5) {
|
||||
if (distance.manhattanLength() > 5)
|
||||
dragging = true;
|
||||
}
|
||||
}
|
||||
|
||||
QAbstractItemView::mouseMoveEvent(event);
|
||||
|
@ -423,11 +405,10 @@ void FeedView::mouseMoveEvent(QMouseEvent* event) {
|
|||
QModelIndex index = indexAt(dragEndPoint);
|
||||
if (index.isValid()) {
|
||||
QRect rect = visualRect(index);
|
||||
if (rect.contains(dragEndPoint)) {
|
||||
if (rect.contains(dragEndPoint))
|
||||
setAnchorHovered(del->hoverType(dragEndPoint, index, rect));
|
||||
} else {
|
||||
else
|
||||
setAnchorHovered(Shared::Hover::nothing);
|
||||
}
|
||||
} else {
|
||||
setAnchorHovered(Shared::Hover::nothing);
|
||||
}
|
||||
|
@ -447,9 +428,8 @@ void FeedView::mousePressEvent(QMouseEvent* event) {
|
|||
if (lastSelectedId.size()) {
|
||||
Models::MessageFeed* feed = static_cast<Models::MessageFeed*>(model());
|
||||
QModelIndex index = feed->modelIndexById(lastSelectedId);
|
||||
if (index.isValid()) {
|
||||
if (index.isValid())
|
||||
setDirtyRegion(visualRect(index));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -467,18 +447,16 @@ void FeedView::mouseDoubleClickEvent(QMouseEvent* event) {
|
|||
if (lastSelectedId.size()) {
|
||||
Models::MessageFeed* feed = static_cast<Models::MessageFeed*>(model());
|
||||
QModelIndex index = feed->modelIndexById(lastSelectedId);
|
||||
if (index.isValid()) {
|
||||
if (index.isValid())
|
||||
setDirtyRegion(visualRect(index));
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex index = indexAt(dragStartPoint);
|
||||
QRect rect = visualRect(index);
|
||||
if (rect.contains(dragStartPoint)) {
|
||||
selectedText = del->leftDoubleClick(dragStartPoint, index, rect);
|
||||
if (selectedText.size() > 0) {
|
||||
if (selectedText.size() > 0)
|
||||
setDirtyRegion(rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -494,9 +472,8 @@ void FeedView::mouseReleaseEvent(QMouseEvent* event) {
|
|||
if (index.isValid()) {
|
||||
QRect rect = visualRect(index);
|
||||
MessageDelegate* del = static_cast<MessageDelegate*>(itemDelegate());
|
||||
if (rect.contains(point)) {
|
||||
if (rect.contains(point))
|
||||
del->leftClick(point, index, rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
dragging = false;
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
#include "messagedelegate.h"
|
||||
#include "messagefeed.h"
|
||||
|
||||
#include "shared/defines.h"
|
||||
|
||||
constexpr int textMargin = 2;
|
||||
constexpr int statusIconSize = 16;
|
||||
|
||||
|
@ -70,27 +72,21 @@ MessageDelegate::MessageDelegate(QObject* parent):
|
|||
barHeight = bar.sizeHint().height();
|
||||
}
|
||||
|
||||
MessageDelegate::~MessageDelegate()
|
||||
{
|
||||
for (const std::pair<const QString, FeedButton*>& pair: *buttons){
|
||||
MessageDelegate::~MessageDelegate() {
|
||||
for (const std::pair<const QString, FeedButton*>& pair: *buttons)
|
||||
delete pair.second;
|
||||
}
|
||||
|
||||
for (const std::pair<const QString, QProgressBar*>& pair: *bars){
|
||||
for (const std::pair<const QString, QProgressBar*>& pair: *bars)
|
||||
delete pair.second;
|
||||
}
|
||||
|
||||
for (const std::pair<const QString, QLabel*>& pair: *statusIcons){
|
||||
for (const std::pair<const QString, QLabel*>& pair: *statusIcons)
|
||||
delete pair.second;
|
||||
}
|
||||
|
||||
for (const std::pair<const QString, QLabel*>& pair: *pencilIcons){
|
||||
for (const std::pair<const QString, QLabel*>& pair: *pencilIcons)
|
||||
delete pair.second;
|
||||
}
|
||||
|
||||
for (const std::pair<const QString, Preview*>& pair: *previews){
|
||||
for (const std::pair<const QString, Preview*>& pair: *previews)
|
||||
delete pair.second;
|
||||
}
|
||||
|
||||
delete statusIcons;
|
||||
delete pencilIcons;
|
||||
|
@ -101,29 +97,26 @@ MessageDelegate::~MessageDelegate()
|
|||
delete bodyRenderer;
|
||||
}
|
||||
|
||||
void MessageDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
void MessageDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
|
||||
QVariant vi = index.data(Models::MessageFeed::Bulk);
|
||||
if (!vi.isValid()) {
|
||||
if (!vi.isValid())
|
||||
return;
|
||||
}
|
||||
|
||||
Models::FeedItem data = qvariant_cast<Models::FeedItem>(vi);
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||
|
||||
paintBubble(data, painter, option);
|
||||
bool ntds = needToDrawSender(index, data);
|
||||
if (ntds || option.rect.y() < 1) {
|
||||
if (ntds || option.rect.y() < 1)
|
||||
paintAvatar(data, index, option, painter);
|
||||
}
|
||||
|
||||
QStyleOptionViewItem opt = option;
|
||||
opt.rect = option.rect.adjusted(bubbleMargin, bubbleMargin, -bubbleMargin, -bubbleMargin / 2);
|
||||
if (!data.sentByMe) {
|
||||
if (!data.sentByMe)
|
||||
opt.displayAlignment = Qt::AlignLeft | Qt::AlignTop;
|
||||
} else {
|
||||
else
|
||||
opt.displayAlignment = Qt::AlignRight | Qt::AlignTop;
|
||||
}
|
||||
|
||||
QRect rect;
|
||||
if (ntds) {
|
||||
|
@ -189,11 +182,11 @@ void MessageDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio
|
|||
QLabel* pencilIcon = getPencilIcon(data);
|
||||
|
||||
pencilIcon->setParent(vp);
|
||||
if (data.sentByMe) {
|
||||
if (data.sentByMe)
|
||||
pencilIcon->move(opt.rect.left() + statusIconSize + margin, currentY);
|
||||
} else {
|
||||
else
|
||||
pencilIcon->move(opt.rect.right() - statusIconSize - margin, currentY);
|
||||
}
|
||||
|
||||
pencilIcon->show();
|
||||
} else {
|
||||
std::map<QString, QLabel*>::const_iterator itr = pencilIcons->find(data.id);
|
||||
|
@ -205,27 +198,24 @@ void MessageDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio
|
|||
|
||||
painter->restore();
|
||||
|
||||
if (clearingWidgets) {
|
||||
if (clearingWidgets)
|
||||
idsToKeep->insert(data.id);
|
||||
}
|
||||
}
|
||||
|
||||
void MessageDelegate::paintBubble(const Models::FeedItem& data, QPainter* painter, const QStyleOptionViewItem& option) const
|
||||
{
|
||||
void MessageDelegate::paintBubble(const Models::FeedItem& data, QPainter* painter, const QStyleOptionViewItem& option) const {
|
||||
painter->save();
|
||||
if (data.sentByMe) {
|
||||
if (data.sentByMe)
|
||||
painter->setBrush(option.palette.brush(QPalette::Inactive, QPalette::Highlight));
|
||||
} else {
|
||||
else
|
||||
painter->setBrush(option.palette.brush(QPalette::Window));
|
||||
}
|
||||
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->drawRoundedRect(option.rect, bubbleBorderRadius, bubbleBorderRadius);
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
||||
void MessageDelegate::paintAvatar(const Models::FeedItem& data, const QModelIndex& index, const QStyleOptionViewItem& option, QPainter* painter) const
|
||||
{
|
||||
void MessageDelegate::paintAvatar(const Models::FeedItem& data, const QModelIndex& index, const QStyleOptionViewItem& option, QPainter* painter) const {
|
||||
int currentRow = index.row();
|
||||
int y = option.rect.y();
|
||||
bool firstAttempt = true;
|
||||
|
@ -255,11 +245,10 @@ void MessageDelegate::paintAvatar(const Models::FeedItem& data, const QModelInde
|
|||
QPainterPath path;
|
||||
int ax;
|
||||
|
||||
if (data.sentByMe) {
|
||||
if (data.sentByMe)
|
||||
ax = option.rect.x() + option.rect.width() + margin;
|
||||
} else {
|
||||
else
|
||||
ax = margin;
|
||||
}
|
||||
|
||||
path.addEllipse(ax, y + margin / 2, avatarHeight, avatarHeight);
|
||||
painter->save();
|
||||
|
@ -268,8 +257,7 @@ void MessageDelegate::paintAvatar(const Models::FeedItem& data, const QModelInde
|
|||
painter->restore();
|
||||
}
|
||||
|
||||
bool MessageDelegate::needToDrawAvatar(const QModelIndex& index, const Models::FeedItem& data, const QStyleOptionViewItem& option) const
|
||||
{
|
||||
bool MessageDelegate::needToDrawAvatar(const QModelIndex& index, const Models::FeedItem& data, const QStyleOptionViewItem& option) const {
|
||||
return (option.rect.y() < 1) || needToDrawSender(index, data);
|
||||
}
|
||||
|
||||
|
@ -285,8 +273,7 @@ bool MessageDelegate::needToDrawSender(const QModelIndex& index, const Models::F
|
|||
}
|
||||
}
|
||||
|
||||
QSize MessageDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
QSize MessageDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const {
|
||||
QRect messageRect = option.rect.adjusted(bubbleMargin, margin / 2 + bubbleMargin, -(avatarHeight + 3 * margin + bubbleMargin), -(margin + bubbleMargin) / 2);
|
||||
QStyleOptionViewItem opt = option;
|
||||
opt.rect = messageRect;
|
||||
|
@ -360,12 +347,10 @@ QSize MessageDelegate::sizeHint(const QStyleOptionViewItem& option, const QModel
|
|||
return messageSize;
|
||||
}
|
||||
|
||||
QRect MessageDelegate::getHoveredMessageBodyRect(const QModelIndex& index, const Models::FeedItem& data, const QRect& sizeHint) const
|
||||
{
|
||||
QRect MessageDelegate::getHoveredMessageBodyRect(const QModelIndex& index, const Models::FeedItem& data, const QRect& sizeHint) const {
|
||||
QRect localHint = sizeHint.adjusted(bubbleMargin, bubbleMargin + margin, -bubbleMargin, -bubbleMargin / 2);
|
||||
if (needToDrawSender(index, data)) {
|
||||
if (needToDrawSender(index, data))
|
||||
localHint.adjust(0, nickMetrics.lineSpacing() + textMargin, 0, 0);
|
||||
}
|
||||
|
||||
int attachHeight = 0;
|
||||
switch (data.attach.state) {
|
||||
|
@ -405,8 +390,7 @@ QRect MessageDelegate::getHoveredMessageBodyRect(const QModelIndex& index, const
|
|||
return localHint;
|
||||
}
|
||||
|
||||
QString MessageDelegate::getAnchor(const QPoint& point, const QModelIndex& index, const QRect& sizeHint) const
|
||||
{
|
||||
QString MessageDelegate::getAnchor(const QPoint& point, const QModelIndex& index, const QRect& sizeHint) const {
|
||||
QVariant vi = index.data(Models::MessageFeed::Bulk);
|
||||
Models::FeedItem data = qvariant_cast<Models::FeedItem>(vi);
|
||||
if (data.text.size() > 0) {
|
||||
|
@ -425,16 +409,13 @@ QString MessageDelegate::getAnchor(const QPoint& point, const QModelIndex& index
|
|||
return QString();
|
||||
}
|
||||
|
||||
void MessageDelegate::leftClick(const QPoint& point, const QModelIndex& index, const QRect& sizeHint) const
|
||||
{
|
||||
void MessageDelegate::leftClick(const QPoint& point, const QModelIndex& index, const QRect& sizeHint) const {
|
||||
QString anchor = getAnchor(point, index, sizeHint);
|
||||
if (anchor.size() > 0) {
|
||||
if (anchor.size() > 0)
|
||||
emit openLink(anchor);
|
||||
}
|
||||
}
|
||||
|
||||
QString MessageDelegate::leftDoubleClick(const QPoint& point, const QModelIndex& index, const QRect& sizeHint)
|
||||
{
|
||||
QString MessageDelegate::leftDoubleClick(const QPoint& point, const QModelIndex& index, const QRect& sizeHint) {
|
||||
QVariant vi = index.data(Models::MessageFeed::Bulk);
|
||||
Models::FeedItem data = qvariant_cast<Models::FeedItem>(vi);
|
||||
if (data.text.size() > 0) {
|
||||
|
@ -466,8 +447,7 @@ QString MessageDelegate::leftDoubleClick(const QPoint& point, const QModelIndex&
|
|||
return "";
|
||||
}
|
||||
|
||||
Shared::Hover MessageDelegate::hoverType(const QPoint& point, const QModelIndex& index, const QRect& sizeHint) const
|
||||
{
|
||||
Shared::Hover MessageDelegate::hoverType(const QPoint& point, const QModelIndex& index, const QRect& sizeHint) const {
|
||||
QVariant vi = index.data(Models::MessageFeed::Bulk);
|
||||
Models::FeedItem data = qvariant_cast<Models::FeedItem>(vi);
|
||||
if (data.text.size() > 0) {
|
||||
|
@ -486,17 +466,15 @@ Shared::Hover MessageDelegate::hoverType(const QPoint& point, const QModelIndex&
|
|||
return Shared::Hover::anchor;
|
||||
} else {
|
||||
int position = lay->hitTest(translated, Qt::HitTestAccuracy::ExactHit);
|
||||
if (position != -1) {
|
||||
if (position != -1)
|
||||
return Shared::Hover::text;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Shared::Hover::nothing;
|
||||
}
|
||||
|
||||
QString MessageDelegate::mouseDrag(const QPoint& start, const QPoint& end, const QModelIndex& index, const QRect& sizeHint)
|
||||
{
|
||||
QString MessageDelegate::mouseDrag(const QPoint& start, const QPoint& end, const QModelIndex& index, const QRect& sizeHint) {
|
||||
QVariant vi = index.data(Models::MessageFeed::Bulk);
|
||||
Models::FeedItem data = qvariant_cast<Models::FeedItem>(vi);
|
||||
if (data.text.size() > 0) {
|
||||
|
@ -529,30 +507,24 @@ QString MessageDelegate::mouseDrag(const QPoint& start, const QPoint& end, const
|
|||
return "";
|
||||
}
|
||||
|
||||
QString MessageDelegate::clearSelection()
|
||||
{
|
||||
QString MessageDelegate::clearSelection() {
|
||||
QString lastSelectedId = currentId;
|
||||
currentId = "";
|
||||
selection = std::pair(0, 0);
|
||||
return lastSelectedId;
|
||||
}
|
||||
|
||||
bool MessageDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index)
|
||||
{
|
||||
bool MessageDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index) {
|
||||
//qDebug() << event->type();
|
||||
|
||||
|
||||
return QStyledItemDelegate::editorEvent(event, model, option, index);
|
||||
}
|
||||
|
||||
int MessageDelegate::paintButton(QPushButton* btn, QPainter* painter, bool sentByMe, QStyleOptionViewItem& option) const
|
||||
{
|
||||
int MessageDelegate::paintButton(QPushButton* btn, QPainter* painter, bool sentByMe, QStyleOptionViewItem& option) const {
|
||||
QPoint start;
|
||||
if (sentByMe) {
|
||||
if (sentByMe)
|
||||
start = {option.rect.x() + option.rect.width() - btn->width(), option.rect.top()};
|
||||
} else {
|
||||
else
|
||||
start = option.rect.topLeft();
|
||||
}
|
||||
|
||||
QWidget* vp = static_cast<QWidget*>(painter->device());
|
||||
btn->setParent(vp);
|
||||
|
@ -563,8 +535,7 @@ int MessageDelegate::paintButton(QPushButton* btn, QPainter* painter, bool sentB
|
|||
return btn->width();
|
||||
}
|
||||
|
||||
int MessageDelegate::paintComment(const Models::FeedItem& data, QPainter* painter, QStyleOptionViewItem& option) const
|
||||
{
|
||||
int MessageDelegate::paintComment(const Models::FeedItem& data, QPainter* painter, QStyleOptionViewItem& option) const {
|
||||
painter->setFont(dateFont);
|
||||
QColor q = painter->pen().color();
|
||||
q.setAlpha(180);
|
||||
|
@ -576,8 +547,8 @@ int MessageDelegate::paintComment(const Models::FeedItem& data, QPainter* painte
|
|||
return rect.width();
|
||||
}
|
||||
|
||||
int MessageDelegate::paintBar(QProgressBar* bar, QPainter* painter, bool sentByMe, QStyleOptionViewItem& option) const
|
||||
{
|
||||
int MessageDelegate::paintBar(QProgressBar* bar, QPainter* painter, bool sentByMe, QStyleOptionViewItem& option) const {
|
||||
SHARED_UNUSED(sentByMe);
|
||||
QPoint start = option.rect.topLeft();
|
||||
bar->resize(option.rect.width(), barHeight);
|
||||
|
||||
|
@ -589,8 +560,7 @@ int MessageDelegate::paintBar(QProgressBar* bar, QPainter* painter, bool sentByM
|
|||
return option.rect.width();
|
||||
}
|
||||
|
||||
int MessageDelegate::paintPreview(const Models::FeedItem& data, QPainter* painter, QStyleOptionViewItem& option) const
|
||||
{
|
||||
int MessageDelegate::paintPreview(const Models::FeedItem& data, QPainter* painter, QStyleOptionViewItem& option) const {
|
||||
Preview* preview = 0;
|
||||
std::map<QString, Preview*>::iterator itr = previews->find(data.id);
|
||||
|
||||
|
@ -605,18 +575,16 @@ int MessageDelegate::paintPreview(const Models::FeedItem& data, QPainter* painte
|
|||
previews->insert(std::make_pair(data.id, preview));
|
||||
}
|
||||
|
||||
if (!preview->isFileReachable()) { //this is the situation when the file preview couldn't be painted because the file was moved
|
||||
if (!preview->isFileReachable()) //this is the situation when the file preview couldn't be painted because the file was moved
|
||||
emit invalidPath(data.id); //or deleted. This signal notifies the model, and the model notifies the core, preview can
|
||||
} //handle being invalid for as long as I need and can be even become valid again with a new path
|
||||
|
||||
//handle being invalid for as long as I need and can be even become valid again with a new path
|
||||
QSize pSize(preview->size());
|
||||
option.rect.adjust(0, pSize.height() + textMargin, 0, 0);
|
||||
|
||||
return pSize.width();
|
||||
}
|
||||
|
||||
QPushButton * MessageDelegate::getButton(const Models::FeedItem& data) const
|
||||
{
|
||||
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()) {
|
||||
|
@ -640,8 +608,7 @@ QPushButton * MessageDelegate::getButton(const Models::FeedItem& data) const
|
|||
return result;
|
||||
}
|
||||
|
||||
QProgressBar * MessageDelegate::getBar(const Models::FeedItem& data) const
|
||||
{
|
||||
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()) {
|
||||
|
@ -665,8 +632,7 @@ QProgressBar * MessageDelegate::getBar(const Models::FeedItem& data) const
|
|||
return result;
|
||||
}
|
||||
|
||||
QLabel * MessageDelegate::getStatusIcon(const Models::FeedItem& data) const
|
||||
{
|
||||
QLabel * MessageDelegate::getStatusIcon(const Models::FeedItem& data) const {
|
||||
std::map<QString, QLabel*>::const_iterator itr = statusIcons->find(data.id);
|
||||
QLabel* result = 0;
|
||||
|
||||
|
@ -680,9 +646,8 @@ QLabel * MessageDelegate::getStatusIcon(const Models::FeedItem& data) const
|
|||
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) {
|
||||
if (data.error > 0)
|
||||
tt += ": " + data.error;
|
||||
}
|
||||
}
|
||||
if (result->toolTip() != tt) { //If i just assign pixmap every time unconditionally
|
||||
result->setPixmap(q.pixmap(statusIconSize)); //it invokes an infinite cycle of repaint
|
||||
|
@ -692,8 +657,7 @@ QLabel * MessageDelegate::getStatusIcon(const Models::FeedItem& data) const
|
|||
return result;
|
||||
}
|
||||
|
||||
QLabel * MessageDelegate::getPencilIcon(const Models::FeedItem& data) const
|
||||
{
|
||||
QLabel * MessageDelegate::getPencilIcon(const Models::FeedItem& data) const {
|
||||
std::map<QString, QLabel*>::const_iterator itr = pencilIcons->find(data.id);
|
||||
QLabel* result = 0;
|
||||
|
||||
|
@ -755,14 +719,12 @@ int MessageDelegate::paintBody(const Models::FeedItem& data, QPainter* painter,
|
|||
return 0;
|
||||
}
|
||||
|
||||
void MessageDelegate::beginClearWidgets()
|
||||
{
|
||||
void MessageDelegate::beginClearWidgets() {
|
||||
idsToKeep->clear();
|
||||
clearingWidgets = true;
|
||||
}
|
||||
|
||||
void MessageDelegate::endClearWidgets()
|
||||
{
|
||||
void MessageDelegate::endClearWidgets() {
|
||||
if (clearingWidgets) {
|
||||
removeElements(buttons, idsToKeep);
|
||||
removeElements(bars, idsToKeep);
|
||||
|
@ -775,14 +737,12 @@ void MessageDelegate::endClearWidgets()
|
|||
}
|
||||
}
|
||||
|
||||
void MessageDelegate::onButtonPushed() const
|
||||
{
|
||||
void MessageDelegate::onButtonPushed() const {
|
||||
FeedButton* btn = static_cast<FeedButton*>(sender());
|
||||
emit buttonPushed(btn->messageId);
|
||||
}
|
||||
|
||||
void MessageDelegate::clearHelperWidget(const Models::FeedItem& data) const
|
||||
{
|
||||
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;
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
#include <QProgressBar>
|
||||
#include <QLabel>
|
||||
#include <QTextDocument>
|
||||
#include <QString>
|
||||
#include <QPainter>
|
||||
|
||||
#include "shared/icons.h"
|
||||
#include "shared/global.h"
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include <ui/models/element.h>
|
||||
#include <ui/models/room.h>
|
||||
#include <shared/defines.h>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
@ -228,24 +229,20 @@ std::set<Models::MessageFeed::MessageRoles> Models::MessageFeed::detectChanges(c
|
|||
return roles;
|
||||
}
|
||||
|
||||
void Models::MessageFeed::removeMessage(const QString& id)
|
||||
{
|
||||
void Models::MessageFeed::removeMessage(const QString& id) {
|
||||
//todo;
|
||||
}
|
||||
|
||||
Shared::Message Models::MessageFeed::getMessage(const QString& id)
|
||||
{
|
||||
Shared::Message Models::MessageFeed::getMessage(const QString& id) {
|
||||
StorageById::iterator itr = indexById.find(id);
|
||||
if (itr == indexById.end()) {
|
||||
if (itr == indexById.end())
|
||||
throw NotFound(id.toStdString(), rosterItem->getJid().toStdString(), rosterItem->getAccountName().toStdString());
|
||||
}
|
||||
|
||||
return **itr;
|
||||
}
|
||||
|
||||
|
||||
QVariant Models::MessageFeed::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
QVariant Models::MessageFeed::data(const QModelIndex& index, int role) const {
|
||||
int i = index.row();
|
||||
QVariant answer;
|
||||
|
||||
|
@ -266,11 +263,10 @@ QVariant Models::MessageFeed::data(const QModelIndex& index, int role) const
|
|||
if (sentByMe(*msg)) {
|
||||
answer = rosterItem->getAccountName();
|
||||
} else {
|
||||
if (rosterItem->isRoom()) {
|
||||
if (rosterItem->isRoom())
|
||||
answer = msg->getFromResource();
|
||||
} else {
|
||||
else
|
||||
answer = rosterItem->getDisplayedName();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Date:
|
||||
|
@ -290,19 +286,17 @@ QVariant Models::MessageFeed::data(const QModelIndex& index, int role) const
|
|||
if (sentByMe(*msg)) {
|
||||
path = rosterItem->getAccountAvatarPath();
|
||||
} else if (!rosterItem->isRoom()) {
|
||||
if (rosterItem->getAvatarState() != Shared::Avatar::empty) {
|
||||
if (rosterItem->getAvatarState() != Shared::Avatar::empty)
|
||||
path = rosterItem->getAvatarPath();
|
||||
}
|
||||
} else {
|
||||
const Room* room = static_cast<const Room*>(rosterItem);
|
||||
path = room->getParticipantIconPath(msg->getFromResource());
|
||||
}
|
||||
|
||||
if (path.size() == 0) {
|
||||
if (path.size() == 0)
|
||||
answer = Shared::iconPath("user", true);
|
||||
} else {
|
||||
else
|
||||
answer = path;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Attach:
|
||||
|
@ -342,15 +336,14 @@ QVariant Models::MessageFeed::data(const QModelIndex& index, int role) const
|
|||
item.avatar = room->getParticipantIconPath(msg->getFromResource());
|
||||
} else {
|
||||
item.sender = rosterItem->getDisplayedName();
|
||||
if (rosterItem->getAvatarState() != Shared::Avatar::empty) {
|
||||
if (rosterItem->getAvatarState() != Shared::Avatar::empty)
|
||||
item.avatar = rosterItem->getAvatarPath();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (item.avatar.size() == 0) {
|
||||
if (item.avatar.size() == 0)
|
||||
item.avatar = Shared::iconPath("user", true);
|
||||
}
|
||||
|
||||
item.attach = fillAttach(*msg);
|
||||
answer.setValue(item);
|
||||
}
|
||||
|
@ -363,13 +356,12 @@ QVariant Models::MessageFeed::data(const QModelIndex& index, int role) const
|
|||
return answer;
|
||||
}
|
||||
|
||||
int Models::MessageFeed::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
int Models::MessageFeed::rowCount(const QModelIndex& parent) const {
|
||||
SHARED_UNUSED(parent);
|
||||
return storage.size();
|
||||
}
|
||||
|
||||
bool Models::MessageFeed::markMessageAsRead(const QString& id) const
|
||||
{
|
||||
bool Models::MessageFeed::markMessageAsRead(const QString& id) const {
|
||||
std::set<QString>::const_iterator umi = unreadMessages->find(id);
|
||||
if (umi != unreadMessages->end()) {
|
||||
unreadMessages->erase(umi);
|
||||
|
@ -379,32 +371,29 @@ bool Models::MessageFeed::markMessageAsRead(const QString& id) const
|
|||
return false;
|
||||
}
|
||||
|
||||
unsigned int Models::MessageFeed::unreadMessagesCount() const
|
||||
{
|
||||
unsigned int Models::MessageFeed::unreadMessagesCount() const {
|
||||
return unreadMessages->size();
|
||||
}
|
||||
|
||||
bool Models::MessageFeed::canFetchMore(const QModelIndex& parent) const
|
||||
{
|
||||
bool Models::MessageFeed::canFetchMore(const QModelIndex& parent) const {
|
||||
SHARED_UNUSED(parent);
|
||||
return syncState == incomplete;
|
||||
}
|
||||
|
||||
void Models::MessageFeed::fetchMore(const QModelIndex& parent)
|
||||
{
|
||||
void Models::MessageFeed::fetchMore(const QModelIndex& parent) {
|
||||
SHARED_UNUSED(parent);
|
||||
if (syncState == incomplete) {
|
||||
syncState = syncing;
|
||||
emit syncStateChange(syncState);
|
||||
|
||||
if (storage.size() == 0) {
|
||||
if (storage.size() == 0)
|
||||
emit requestArchive("");
|
||||
} else {
|
||||
else
|
||||
emit requestArchive((*indexByTime.rbegin())->getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Models::MessageFeed::responseArchive(const std::list<Shared::Message> list, bool last)
|
||||
{
|
||||
void Models::MessageFeed::responseArchive(const std::list<Shared::Message> list, bool last) {
|
||||
Storage::size_type size = storage.size();
|
||||
|
||||
beginInsertRows(QModelIndex(), size, size + list.size() - 1);
|
||||
|
@ -415,21 +404,19 @@ void Models::MessageFeed::responseArchive(const std::list<Shared::Message> list,
|
|||
endInsertRows();
|
||||
|
||||
if (syncState == syncing) {
|
||||
if (last) {
|
||||
if (last)
|
||||
syncState = complete;
|
||||
} else {
|
||||
else
|
||||
syncState = incomplete;
|
||||
}
|
||||
|
||||
emit syncStateChange(syncState);
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex Models::MessageFeed::index(int row, int column, const QModelIndex& parent) const
|
||||
{
|
||||
if (!hasIndex(row, column, parent)) {
|
||||
QModelIndex Models::MessageFeed::index(int row, int column, const QModelIndex& parent) const{
|
||||
if (!hasIndex(row, column, parent))
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
|
||||
StorageByTime::iterator itr = indexByTime.nth(row);
|
||||
if (itr != indexByTime.end()) {
|
||||
Shared::Message* msg = *itr;
|
||||
|
@ -442,8 +429,7 @@ QModelIndex Models::MessageFeed::index(int row, int column, const QModelIndex& p
|
|||
|
||||
QHash<int, QByteArray> Models::MessageFeed::roleNames() const {return roles;}
|
||||
|
||||
bool Models::MessageFeed::sentByMe(const Shared::Message& msg) const
|
||||
{
|
||||
bool Models::MessageFeed::sentByMe(const Shared::Message& msg) const {
|
||||
if (rosterItem->isRoom()) {
|
||||
const Room* room = static_cast<const Room*>(rosterItem);
|
||||
return room->getNick().toLower() == msg.getFromResource().toLower();
|
||||
|
@ -452,8 +438,7 @@ bool Models::MessageFeed::sentByMe(const Shared::Message& msg) const
|
|||
}
|
||||
}
|
||||
|
||||
Models::Attachment Models::MessageFeed::fillAttach(const Shared::Message& msg) const
|
||||
{
|
||||
Models::Attachment Models::MessageFeed::fillAttach(const Shared::Message& msg) const {
|
||||
::Models::Attachment att;
|
||||
QString id = msg.getId();
|
||||
|
||||
|
@ -501,16 +486,14 @@ Models::Attachment Models::MessageFeed::fillAttach(const Shared::Message& msg) c
|
|||
return att;
|
||||
}
|
||||
|
||||
Models::Edition Models::MessageFeed::fillCorrection(const Shared::Message& msg) const
|
||||
{
|
||||
Models::Edition Models::MessageFeed::fillCorrection(const Shared::Message& msg) const {
|
||||
::Models::Edition ed({msg.getEdited(), msg.getOriginalBody(), msg.getLastModified()});
|
||||
|
||||
return ed;
|
||||
}
|
||||
|
||||
|
||||
void Models::MessageFeed::downloadAttachment(const QString& messageId)
|
||||
{
|
||||
void Models::MessageFeed::downloadAttachment(const QString& messageId) {
|
||||
bool notify = false;
|
||||
Err::const_iterator eitr = failedDownloads.find(messageId);
|
||||
if (eitr != failedDownloads.end()) {
|
||||
|
@ -532,13 +515,11 @@ void Models::MessageFeed::downloadAttachment(const QString& messageId)
|
|||
qDebug() << "An attempt to download an attachment for the message that doesn't exist. ID:" << messageId;
|
||||
}
|
||||
|
||||
if (notify) {
|
||||
if (notify)
|
||||
emit dataChanged(ind, ind, {MessageRoles::Attach});
|
||||
}
|
||||
}
|
||||
|
||||
bool Models::MessageFeed::registerUpload(const QString& messageId)
|
||||
{
|
||||
bool Models::MessageFeed::registerUpload(const QString& messageId) {
|
||||
bool success = uploads.insert(std::make_pair(messageId, 0)).second;
|
||||
|
||||
QVector<int> roles({});
|
||||
|
@ -556,8 +537,7 @@ bool Models::MessageFeed::registerUpload(const QString& messageId)
|
|||
return success;
|
||||
}
|
||||
|
||||
void Models::MessageFeed::fileProgress(const QString& messageId, qreal value, bool up)
|
||||
{
|
||||
void Models::MessageFeed::fileProgress(const QString& messageId, qreal value, bool up) {
|
||||
Progress* pr = 0;
|
||||
Err* err = 0;
|
||||
if (up) {
|
||||
|
@ -583,13 +563,11 @@ void Models::MessageFeed::fileProgress(const QString& messageId, qreal value, bo
|
|||
}
|
||||
}
|
||||
|
||||
void Models::MessageFeed::fileComplete(const QString& messageId, bool up)
|
||||
{
|
||||
void Models::MessageFeed::fileComplete(const QString& messageId, bool up) {
|
||||
fileProgress(messageId, 1, up);
|
||||
}
|
||||
|
||||
void Models::MessageFeed::fileError(const QString& messageId, const QString& error, bool up)
|
||||
{
|
||||
void Models::MessageFeed::fileError(const QString& messageId, const QString& error, bool up) {
|
||||
Err* failed;
|
||||
Progress* loads;
|
||||
if (up) {
|
||||
|
@ -601,33 +579,28 @@ void Models::MessageFeed::fileError(const QString& messageId, const QString& err
|
|||
}
|
||||
|
||||
Progress::iterator pitr = loads->find(messageId);
|
||||
if (pitr != loads->end()) {
|
||||
if (pitr != loads->end())
|
||||
loads->erase(pitr);
|
||||
}
|
||||
|
||||
std::pair<Err::iterator, bool> pair = failed->insert(std::make_pair(messageId, error));
|
||||
if (!pair.second) {
|
||||
if (!pair.second)
|
||||
pair.first->second = error;
|
||||
}
|
||||
|
||||
QModelIndex ind = modelIndexById(messageId);
|
||||
if (ind.isValid()) {
|
||||
if (ind.isValid())
|
||||
emit dataChanged(ind, ind, {MessageRoles::Attach});
|
||||
}
|
||||
}
|
||||
|
||||
void Models::MessageFeed::incrementObservers()
|
||||
{
|
||||
void Models::MessageFeed::incrementObservers() {
|
||||
++observersAmount;
|
||||
}
|
||||
|
||||
void Models::MessageFeed::decrementObservers()
|
||||
{
|
||||
void Models::MessageFeed::decrementObservers() {
|
||||
--observersAmount;
|
||||
}
|
||||
|
||||
|
||||
QModelIndex Models::MessageFeed::modelIndexById(const QString& id) const
|
||||
{
|
||||
QModelIndex Models::MessageFeed::modelIndexById(const QString& id) const {
|
||||
StorageById::const_iterator itr = indexById.find(id);
|
||||
if (itr != indexById.end()) {
|
||||
Shared::Message* msg = *itr;
|
||||
|
@ -637,8 +610,7 @@ QModelIndex Models::MessageFeed::modelIndexById(const QString& id) const
|
|||
return QModelIndex();
|
||||
}
|
||||
|
||||
QModelIndex Models::MessageFeed::modelIndexByTime(const QString& id, const QDateTime& time) const
|
||||
{
|
||||
QModelIndex Models::MessageFeed::modelIndexByTime(const QString& id, const QDateTime& time) const {
|
||||
if (indexByTime.size() > 0) {
|
||||
StorageByTime::const_iterator tItr = indexByTime.lower_bound(time);
|
||||
StorageByTime::const_iterator tEnd = indexByTime.upper_bound(time);
|
||||
|
@ -660,8 +632,7 @@ QModelIndex Models::MessageFeed::modelIndexByTime(const QString& id, const QDate
|
|||
return QModelIndex();
|
||||
}
|
||||
|
||||
void Models::MessageFeed::reportLocalPathInvalid(const QString& messageId)
|
||||
{
|
||||
void Models::MessageFeed::reportLocalPathInvalid(const QString& messageId) {
|
||||
StorageById::iterator itr = indexById.find(messageId);
|
||||
if (itr == indexById.end()) {
|
||||
qDebug() << "received a command to change a message, but the message couldn't be found, skipping";
|
||||
|
@ -679,13 +650,11 @@ void Models::MessageFeed::reportLocalPathInvalid(const QString& messageId)
|
|||
emit dataChanged(index, index, {MessageRoles::Attach});
|
||||
}
|
||||
|
||||
Models::MessageFeed::SyncState Models::MessageFeed::getSyncState() const
|
||||
{
|
||||
Models::MessageFeed::SyncState Models::MessageFeed::getSyncState() const {
|
||||
return syncState;
|
||||
}
|
||||
|
||||
void Models::MessageFeed::requestLatestMessages()
|
||||
{
|
||||
void Models::MessageFeed::requestLatestMessages() {
|
||||
if (syncState != syncing) {
|
||||
syncState = syncing;
|
||||
emit syncStateChange(syncState);
|
||||
|
|
|
@ -31,12 +31,10 @@ Room::Room(Models::Account* acc, Models::Room* p_room, QWidget* parent):
|
|||
connect(room, &Models::Room::participantLeft, this, &Room::onParticipantLeft);
|
||||
}
|
||||
|
||||
Room::~Room()
|
||||
{
|
||||
Room::~Room() {
|
||||
}
|
||||
|
||||
Shared::Message Room::createMessage() const
|
||||
{
|
||||
Shared::Message Room::createMessage() const {
|
||||
Shared::Message msg = Conversation::createMessage();
|
||||
msg.setType(Shared::Message::groupChat);
|
||||
msg.setFromJid(room->getJid());
|
||||
|
@ -45,13 +43,12 @@ Shared::Message Room::createMessage() const
|
|||
return msg;
|
||||
}
|
||||
|
||||
bool Room::autoJoined() const
|
||||
{
|
||||
bool Room::autoJoined() const {
|
||||
return room->getAutoJoin();
|
||||
}
|
||||
|
||||
void Room::onRoomChanged(Models::Item* item, int row, int col)
|
||||
{
|
||||
void Room::onRoomChanged(Models::Item* item, int row, int col) {
|
||||
SHARED_UNUSED(row);
|
||||
if (item == room) {
|
||||
switch (col) {
|
||||
case 0:
|
||||
|
@ -67,11 +64,10 @@ void Room::onRoomChanged(Models::Item* item, int row, int col)
|
|||
}
|
||||
}
|
||||
|
||||
void Room::onParticipantJoined(const Models::Participant& participant)
|
||||
{
|
||||
|
||||
void Room::onParticipantJoined(const Models::Participant& participant) {
|
||||
SHARED_UNUSED(participant);
|
||||
}
|
||||
|
||||
void Room::onParticipantLeft(const QString& name)
|
||||
{
|
||||
void Room::onParticipantLeft(const QString& name) {
|
||||
SHARED_UNUSED(name);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue