From 2dc2b3598d3f55c63b3762c7d67809e6263f2526 Mon Sep 17 00:00:00 2001 From: Phenom Date: Tue, 14 Apr 2020 14:29:37 +0200 Subject: [PATCH] Fix Message Delete Button. Now, frame is cleared and next message selected. --- retroshare-gui/src/gui/msgs/MessageWidget.cpp | 53 ++++++++++++++----- retroshare-gui/src/gui/msgs/MessageWidget.h | 5 +- .../src/gui/msgs/MessagesDialog.cpp | 28 ++++++++-- retroshare-gui/src/gui/msgs/MessagesDialog.h | 6 +-- retroshare-gui/src/util/misc.cpp | 20 +++++++ retroshare-gui/src/util/misc.h | 5 ++ 6 files changed, 93 insertions(+), 24 deletions(-) diff --git a/retroshare-gui/src/gui/msgs/MessageWidget.cpp b/retroshare-gui/src/gui/msgs/MessageWidget.cpp index a37924c43..001866927 100644 --- a/retroshare-gui/src/gui/msgs/MessageWidget.cpp +++ b/retroshare-gui/src/gui/msgs/MessageWidget.cpp @@ -132,6 +132,7 @@ MessageWidget::MessageWidget(bool controlled, QWidget *parent, Qt::WindowFlags f isControlled = controlled; isWindow = false; currMsgFlags = 0; + expandFiles = false; ui.actionTextBesideIcon->setData(Qt::ToolButtonTextBesideIcon); ui.actionIconOnly->setData(Qt::ToolButtonIconOnly); @@ -281,10 +282,7 @@ void MessageWidget::processSettings(const QString &settingsGroup, bool load) // load settings // expandFiles - bool value = Settings->value("expandFiles", false).toBool(); - ui.expandFilesButton->setChecked(value); - ui.msgList->setVisible(value); - togglefileview(); + expandFiles = Settings->value("expandFiles", false).toBool(); // toolbar button style Qt::ToolButtonStyle style = (Qt::ToolButtonStyle) Settings->value("ToolButon_Style", Qt::ToolButtonTextBesideIcon).toInt(); @@ -293,7 +291,7 @@ void MessageWidget::processSettings(const QString &settingsGroup, bool load) // save settings // expandFiles - Settings->setValue("expandFiles", ui.expandFilesButton->isChecked()); + Settings->setValue("expandFiles", expandFiles); //toolbar button style Settings->setValue("ToolButon_Style", ui.replyButton->toolButtonStyle()); @@ -322,7 +320,7 @@ void MessageWidget::msgfilelistWidgetCostumPopupMenu( QPoint /*point*/ ) contextMnu.exec(QCursor::pos()); } -void MessageWidget::togglefileview() +void MessageWidget::togglefileview(bool noUpdate/*=false*/) { /* if msg header visible -> change icon and tooltip * three widgets... @@ -335,6 +333,10 @@ void MessageWidget::togglefileview() ui.expandFilesButton->setIcon(QIcon(QString(":/icons/png/up-arrow.png"))); ui.expandFilesButton->setToolTip(tr("Show the attachment pane")); } + if (!noUpdate) + expandFiles = ui.expandFilesButton->isChecked(); + + ui.msgList->setVisible(ui.expandFilesButton->isChecked()); } /* download the recommendations... */ @@ -426,13 +428,10 @@ void MessageWidget::messagesChanged() void MessageWidget::clearTagLabels() { /* clear all tags */ - while (tagLabels.size()) { - delete tagLabels.front(); - tagLabels.pop_front(); - } - while (ui.tagLayout->count()) { - delete ui.tagLayout->takeAt(0); - } + qDeleteAll(tagLabels); + tagLabels.clear(); + + misc::clearLayout(ui.tagLayout); ui.tagsLabel->setVisible(false); } @@ -510,6 +509,16 @@ void MessageWidget::fill(const std::string &msgId) clearTagLabels(); + ui.inviteFrame->hide(); + ui.expandFilesButton->setChecked(false); + togglefileview(true); + + ui.replyButton->setEnabled(false); + ui.replyallButton->setEnabled(false); + ui.forwardButton->setEnabled(false); + ui.deleteButton->setEnabled(false); + ui.moreButton->setEnabled(false); + currMsgFlags = 0; return; @@ -517,6 +526,13 @@ void MessageWidget::fill(const std::string &msgId) clearTagLabels(); + + ui.replyButton->setEnabled(true); + ui.replyallButton->setEnabled(true); + ui.forwardButton->setEnabled(true); + ui.deleteButton->setEnabled(true); + ui.moreButton->setEnabled(true); + MessageInfo msgInfo; if (rsMail->getMessage(currMsgId, msgInfo) == false) { std::cerr << "MessageWidget::fill() Couldn't find Msg" << std::endl; @@ -549,6 +565,8 @@ void MessageWidget::fill(const std::string &msgId) /* add the items in! */ ui.msgList->insertTopLevelItems(0, items); + ui.expandFilesButton->setChecked(expandFiles && (items.count()>0) ); + togglefileview(true); /* iterate through the sources */ RetroShareLink link; @@ -688,8 +706,15 @@ void MessageWidget::remove() if (isWindow) { window()->close(); } else { - deleteLater(); + if (isControlled) { + currMsgId.clear(); + fill(currMsgId); + } else { + deleteLater(); + } } + + emit messageRemoved(); } void MessageWidget::print() diff --git a/retroshare-gui/src/gui/msgs/MessageWidget.h b/retroshare-gui/src/gui/msgs/MessageWidget.h index 4bce2466f..2bd630cb3 100644 --- a/retroshare-gui/src/gui/msgs/MessageWidget.h +++ b/retroshare-gui/src/gui/msgs/MessageWidget.h @@ -58,6 +58,8 @@ public: QString subject(bool noEmpty); +signals: + void messageRemoved(); private slots: void reply(); @@ -75,7 +77,7 @@ private slots: void messagesTagsChanged(); void messagesChanged(); - void togglefileview(); + void togglefileview(bool noUpdate = false); void getcurrentrecommended(); void getallrecommended(); @@ -94,6 +96,7 @@ private: bool isWindow; std::string currMsgId; unsigned int currMsgFlags; + bool expandFiles; QList tagLabels; diff --git a/retroshare-gui/src/gui/msgs/MessagesDialog.cpp b/retroshare-gui/src/gui/msgs/MessagesDialog.cpp index 6fc76ed79..f31748f4b 100644 --- a/retroshare-gui/src/gui/msgs/MessagesDialog.cpp +++ b/retroshare-gui/src/gui/msgs/MessagesDialog.cpp @@ -124,9 +124,11 @@ MessagesDialog::MessagesDialog(QWidget *parent) inProcessSettings = false; inChange = false; lockUpdate = 0; + lastSelectedIndex = QModelIndex(); msgWidget = new MessageWidget(true, this); ui.msgLayout->addWidget(msgWidget); + connect(msgWidget, SIGNAL(messageRemoved()), this, SLOT(messageRemoved())); connectActions(); @@ -695,6 +697,7 @@ void MessagesDialog::openAsWindow() } msgWidget->activateWindow(); + connect(msgWidget, SIGNAL(messageRemoved()), this, SLOT(messageRemoved())); /* window will destroy itself! */ } @@ -714,6 +717,7 @@ void MessagesDialog::openAsTab() ui.tabWidget->addTab(msgWidget, msgWidget->subject(true)); ui.tabWidget->setCurrentWidget(msgWidget); + connect(msgWidget, SIGNAL(messageRemoved()), this, SLOT(messageRemoved())); /* window will destroy itself! */ } @@ -860,7 +864,8 @@ void MessagesDialog::clicked(const QModelIndex& proxy_index) case RsMessageModel::COLUMN_THREAD_READ: { mMessageModel->setMsgReadStatus(real_index, !isMessageRead(proxy_index)); - insertMsgTxtAndFiles(proxy_index); + //Already updated by currentChanged + //insertMsgTxtAndFiles(proxy_index); updateMessageSummaryList(); return; } @@ -871,8 +876,9 @@ void MessagesDialog::clicked(const QModelIndex& proxy_index) } } - // show current message directly - insertMsgTxtAndFiles(proxy_index); + // show current message directly + //Already updated by currentChanged + //insertMsgTxtAndFiles(proxy_index); } // double click in messageTreeWidget @@ -953,14 +959,20 @@ void MessagesDialog::insertMsgTxtAndFiles(const QModelIndex& proxy_index) QModelIndex real_index = mMessageProxyModel->mapToSource(proxy_index); - if(!real_index.isValid()) + if(!real_index.isValid()) { mCurrMsgId.clear(); msgWidget->fill(mCurrMsgId); updateInterface(); + lastSelectedIndex = QModelIndex(); return; } - mid = real_index.data(RsMessageModel::MsgIdRole).toString().toStdString(); + + lastSelectedIndex = proxy_index; + if (!ui.messageTreeWidget->indexBelow(proxy_index).isValid()) + lastSelectedIndex = ui.messageTreeWidget->indexAbove(proxy_index); + + mid = real_index.data(RsMessageModel::MsgIdRole).toString().toStdString(); /* Save the Data.... for later */ @@ -1025,6 +1037,12 @@ void MessagesDialog::removemessage() mMessageModel->updateMessages(); updateMessageSummaryList(); + messageRemoved(); +} + +void MessagesDialog::messageRemoved() +{ + ui.messageTreeWidget->setCurrentIndex(lastSelectedIndex); } void MessagesDialog::undeletemessage() diff --git a/retroshare-gui/src/gui/msgs/MessagesDialog.h b/retroshare-gui/src/gui/msgs/MessagesDialog.h index 57f935783..766268a79 100644 --- a/retroshare-gui/src/gui/msgs/MessagesDialog.h +++ b/retroshare-gui/src/gui/msgs/MessagesDialog.h @@ -57,10 +57,6 @@ public: void setTextColorInbox(QColor color) { mTextColorInbox = color; } -signals: - void messagesAboutToLoad(); - void messagesLoaded(); - protected: virtual UserNotify *createUserNotify(QObject *parent) override; bool eventFilter(QObject *obj, QEvent *ev); @@ -69,6 +65,7 @@ protected: public slots: //void insertMessages(); void messagesTagsChanged(); + void messageRemoved(); void preModelUpdate(); void postModelUpdate(); @@ -156,6 +153,7 @@ private: Ui::MessagesDialog ui; QList mTmpSavedSelectedIds; + QModelIndex lastSelectedIndex; }; #endif diff --git a/retroshare-gui/src/util/misc.cpp b/retroshare-gui/src/util/misc.cpp index a66de053c..4bcfd7149 100644 --- a/retroshare-gui/src/util/misc.cpp +++ b/retroshare-gui/src/util/misc.cpp @@ -405,3 +405,23 @@ QString misc::getExistingDirectory(QWidget *parent, const QString &caption, cons return QFileDialog::getExistingDirectory(parent, caption, dir, QFileDialog::DontUseNativeDialog | QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); #endif } + +/*! + * Clear a Layout content + * \param layout: Layout to Clear + */ +void misc::clearLayout(QLayout * layout) { + if (! layout) + return; + + while (auto item = layout->takeAt(0)) + { + if (auto *widget = item->widget()) + widget->deleteLater(); + if (auto *spacer = item->spacerItem()) + delete spacer; + + clearLayout(item->layout()); + delete item; + } +} diff --git a/retroshare-gui/src/util/misc.h b/retroshare-gui/src/util/misc.h index 6bf37f4b0..f09280ecf 100644 --- a/retroshare-gui/src/util/misc.h +++ b/retroshare-gui/src/util/misc.h @@ -27,6 +27,7 @@ #include #include #include +#include #include "gui/settings/rsharesettings.h" @@ -182,6 +183,10 @@ class misc : public QObject static QString getExistingDirectory(QWidget *parent = nullptr , const QString &caption = QString() , const QString &dir = QString()); + + //Clear QLayout + static void clearLayout(QLayout *layout); + }; // Trick to get a portable sleep() function