Save work on labels.
This commit is contained in:
parent
a9b6ecd351
commit
b51f2e6dd5
@ -4,10 +4,13 @@
|
||||
|
||||
#include "gui/dialogs/formmain.h"
|
||||
#include "gui/messagebox.h"
|
||||
#include "gui/plaintoolbutton.h"
|
||||
#include "gui/searchtextwidget.h"
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/databasequeries.h"
|
||||
#include "network-web/webfactory.h"
|
||||
#include "services/abstract/label.h"
|
||||
#include "services/abstract/labelsnode.h"
|
||||
#include "services/abstract/serviceroot.h"
|
||||
|
||||
#if defined (USE_WEBENGINE)
|
||||
@ -17,6 +20,7 @@
|
||||
#include "gui/messagebrowser.h"
|
||||
#endif
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QGridLayout>
|
||||
#include <QKeyEvent>
|
||||
#include <QPainter>
|
||||
@ -42,7 +46,8 @@ void MessagePreviewer::createConnections() {
|
||||
}
|
||||
|
||||
MessagePreviewer::MessagePreviewer(QWidget* parent)
|
||||
: QWidget(parent), m_layout(new QGridLayout(this)), m_toolBar(new QToolBar(this)), m_verticalScrollBarPosition(0.0) {
|
||||
: QWidget(parent), m_layout(new QGridLayout(this)), m_toolBar(new QToolBar(this)), m_verticalScrollBarPosition(0.0),
|
||||
m_separator(nullptr), m_btnLabels(QList<QPair<QToolButton*, QAction*>>()) {
|
||||
#if defined (USE_WEBENGINE)
|
||||
m_txtMessage = new WebBrowser(this);
|
||||
#else
|
||||
@ -74,6 +79,7 @@ WebBrowser* MessagePreviewer::webBrowser() const {
|
||||
#endif
|
||||
|
||||
void MessagePreviewer::clear() {
|
||||
updateLabels(true);
|
||||
m_txtMessage->clear();
|
||||
hide();
|
||||
|
||||
@ -96,6 +102,7 @@ void MessagePreviewer::loadMessage(const Message& message, RootItem* root) {
|
||||
|
||||
if (!m_root.isNull()) {
|
||||
updateButtons();
|
||||
updateLabels(false);
|
||||
show();
|
||||
m_actionSwitchImportance->setChecked(m_message.m_isImportant);
|
||||
m_txtMessage->loadMessage(message, root);
|
||||
@ -103,6 +110,8 @@ void MessagePreviewer::loadMessage(const Message& message, RootItem* root) {
|
||||
if (same_message) {
|
||||
m_txtMessage->setVerticalScrollBarPosition(m_verticalScrollBarPosition);
|
||||
}
|
||||
|
||||
auto labels = m_root->getParentServiceRoot()->labelsNode()->labels();
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,3 +172,43 @@ void MessagePreviewer::updateButtons() {
|
||||
m_actionMarkRead->setEnabled(!m_message.m_isRead);
|
||||
m_actionMarkUnread->setEnabled(m_message.m_isRead);
|
||||
}
|
||||
|
||||
void MessagePreviewer::updateLabels(bool only_clear) {
|
||||
for (auto& lbl : m_btnLabels) {
|
||||
m_toolBar->removeAction(lbl.second);
|
||||
lbl.second->deleteLater();
|
||||
lbl.first->deleteLater();
|
||||
}
|
||||
|
||||
m_btnLabels.clear();
|
||||
|
||||
if (m_separator != nullptr) {
|
||||
m_toolBar->removeAction(m_separator);
|
||||
}
|
||||
|
||||
if (only_clear) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_root.data() != nullptr) {
|
||||
m_separator = m_toolBar->addSeparator();
|
||||
|
||||
for (auto* label : m_root.data()->getParentServiceRoot()->labelsNode()->labels()) {
|
||||
QToolButton* btn_label = new QToolButton(this);
|
||||
|
||||
btn_label->setCheckable(true);
|
||||
btn_label->setIcon(Label::generateIcon(label->color()));
|
||||
btn_label->setAutoRaise(false);
|
||||
btn_label->setText(label->title());
|
||||
btn_label->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextBesideIcon);
|
||||
|
||||
QAction* act_label = m_toolBar->addWidget(btn_label);
|
||||
|
||||
connect(act_label, &QAction::triggered, this, []() {
|
||||
int a = 5;
|
||||
});
|
||||
|
||||
m_btnLabels.append(QPair<QToolButton*, QAction*>(btn_label, act_label));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
class QToolButton;
|
||||
class QGridLayout;
|
||||
class QToolBar;
|
||||
|
||||
@ -51,6 +52,7 @@ class MessagePreviewer : public QWidget {
|
||||
private:
|
||||
void createConnections();
|
||||
void updateButtons();
|
||||
void updateLabels(bool only_clear);
|
||||
|
||||
QGridLayout* m_layout;
|
||||
QToolBar* m_toolBar;
|
||||
@ -67,6 +69,8 @@ class MessagePreviewer : public QWidget {
|
||||
QAction* m_actionMarkRead;
|
||||
QAction* m_actionMarkUnread;
|
||||
QAction* m_actionSwitchImportance;
|
||||
QAction* m_separator;
|
||||
QList<QPair<QToolButton*, QAction*>> m_btnLabels;
|
||||
};
|
||||
|
||||
#endif // MESSAGEPREVIEWER_H
|
||||
|
@ -87,10 +87,10 @@ QIcon Label::generateIcon(const QColor& color) {
|
||||
pxm.fill(Qt::GlobalColor::transparent);
|
||||
|
||||
QPainter paint(&pxm);
|
||||
QPainterPath path;
|
||||
|
||||
path.addRoundedRect(QRectF(pxm.rect()), 16, 16);
|
||||
paint.fillPath(path, color);
|
||||
paint.setBrush(color);
|
||||
paint.setPen(Qt::GlobalColor::transparent);
|
||||
paint.drawEllipse(pxm.rect().marginsRemoved(QMargins(2, 2, 2, 2)));
|
||||
|
||||
return pxm;
|
||||
}
|
||||
|
@ -9,6 +9,8 @@
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
#include "services/abstract/serviceroot.h"
|
||||
|
||||
#include "3rd-party/boolinq/boolinq.h"
|
||||
|
||||
LabelsNode::LabelsNode(RootItem* parent_item) : RootItem(parent_item), m_actLabelNew(nullptr) {
|
||||
setKind(RootItem::Kind::Labels);
|
||||
setId(ID_LABELS);
|
||||
@ -24,6 +26,12 @@ void LabelsNode::loadLabels(const QList<Label*>& labels) {
|
||||
}
|
||||
}
|
||||
|
||||
QList<Label*> LabelsNode::labels() const {
|
||||
return QList<Label*>::fromStdList(boolinq::from(childItems()).select([](RootItem* it) {
|
||||
return static_cast<Label*>(it);
|
||||
}).toStdList());
|
||||
}
|
||||
|
||||
QList<QAction*> LabelsNode::contextMenuFeedsList() {
|
||||
if (m_actLabelNew == nullptr) {
|
||||
// Initialize it all.
|
||||
|
@ -13,6 +13,7 @@ class LabelsNode : public RootItem {
|
||||
public:
|
||||
explicit LabelsNode(RootItem* parent_item = nullptr);
|
||||
|
||||
QList<Label*> labels() const;
|
||||
void loadLabels(const QList<Label*>& labels);
|
||||
|
||||
virtual QList<QAction*> contextMenuFeedsList();
|
||||
|
Loading…
x
Reference in New Issue
Block a user