Commit 7bd9daf2 authored by Kevin Funk's avatar Kevin Funk
Browse files

followup: Make widget more user-friendly

Changes:
- Add double-click action
  (shows answer message if there, otherwise original message)
- Allow to delete one or more items via the Delete button
parent 245ffaba
Pipeline #127442 passed with stage
in 3 minutes and 47 seconds
......@@ -15,6 +15,7 @@
#include <QHBoxLayout>
#include <QHeaderView>
#include <QIcon>
#include <QKeyEvent>
#include <QLocale>
#include <QMenu>
#include <QTreeWidget>
......@@ -68,14 +69,31 @@ FollowUpReminderInfoWidget::FollowUpReminderInfoWidget(QWidget *parent)
mTreeWidget->setRootIsDecorated(false);
mTreeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
mTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
mTreeWidget->installEventFilter(this);
connect(mTreeWidget, &QTreeWidget::customContextMenuRequested, this, &FollowUpReminderInfoWidget::slotCustomContextMenuRequested);
connect(mTreeWidget, &QTreeWidget::itemDoubleClicked, this, &FollowUpReminderInfoWidget::slotItemDoubleClicked);
hbox->addWidget(mTreeWidget);
}
FollowUpReminderInfoWidget::~FollowUpReminderInfoWidget() = default;
bool FollowUpReminderInfoWidget::eventFilter(QObject *object, QEvent *event)
{
if (object == mTreeWidget) {
if (event->type() == QEvent::KeyPress) {
auto *keyEvent = static_cast<QKeyEvent *>(event);
if (keyEvent->key() == Qt::Key_Delete) {
const auto listItems = mTreeWidget->selectedItems();
deleteItems(listItems);
}
}
}
return false;
}
void FollowUpReminderInfoWidget::setInfo(const QList<FollowUpReminder::FollowUpReminderInfo *> &infoList)
{
mTreeWidget->clear();
......@@ -169,6 +187,20 @@ bool FollowUpReminderInfoWidget::save() const
return true;
}
void FollowUpReminderInfoWidget::slotItemDoubleClicked(QTreeWidgetItem *item)
{
if (!item)
return;
const auto mailItem = static_cast<FollowUpReminderInfoItem *>(item);
const auto answerMessageItemId = mailItem->info()->answerMessageItemId();
if (answerMessageItemId >= 0) {
openShowMessage(answerMessageItemId);
} else {
openShowMessage(mailItem->info()->originalMessageItemId());
}
}
void FollowUpReminderInfoWidget::slotCustomContextMenuRequested(const QPoint &pos)
{
Q_UNUSED(pos)
......
......@@ -46,7 +46,11 @@ public:
Q_REQUIRED_RESULT QList<qint32> listRemoveId() const;
protected:
bool eventFilter(QObject *object, QEvent *event) override;
private:
void slotItemDoubleClicked(QTreeWidgetItem *item);
void slotCustomContextMenuRequested(const QPoint &pos);
void createOrUpdateItem(FollowUpReminder::FollowUpReminderInfo *info, FollowUpReminderInfoItem *item = nullptr);
void deleteItems(const QList<QTreeWidgetItem *> &mailItemLst);
......
......@@ -21,7 +21,7 @@ FollowUpReminderShowMessageJob::~FollowUpReminderShowMessageJob() = default;
void FollowUpReminderShowMessageJob::start()
{
if (mId < 0) {
qCDebug(FOLLOWUPREMINDERAGENT_LOG) << " value < 0";
qCWarning(FOLLOWUPREMINDERAGENT_LOG) << " value < 0";
deleteLater();
return;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment