[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [trojita] src/Gui: add function to add in-labeled addresses
From: Thomas_Lübking <thomas.luebking () gmail ! com>
Date: 2016-03-05 16:57:05
Message-ID: E1acFVp-0000Mk-LB () scm ! kde ! org
[Download RAW message or body]
Git commit 1f8c5bee546004628033dc8f60aefaa4cac21233 by Thomas Lübking.
Committed on 28/02/2016 at 12:07.
Pushed by gerrit into branch 'master'.
add function to add in-labeled addresses
Change-Id: Ib43f7db0a8991e722219b39f9cd21441c153bac6
M +41 -24 src/Gui/AddressRowWidget.cpp
M +5 -4 src/Gui/AddressRowWidget.h
http://commits.kde.org/trojita/1f8c5bee546004628033dc8f60aefaa4cac21233
diff --git a/src/Gui/AddressRowWidget.cpp b/src/Gui/AddressRowWidget.cpp
index aa97d68..c0ff942 100644
--- a/src/Gui/AddressRowWidget.cpp
+++ b/src/Gui/AddressRowWidget.cpp
@@ -30,6 +30,8 @@
namespace Gui {
+static const int nonExpandingLength = 3*33;
+
static int plainChars(const QLabel *l)
{
static QTextDocument converter;
@@ -37,43 +39,55 @@ static int plainChars(const QLabel *l)
return converter.toPlainText().length();
}
-AddressRowWidget::AddressRowWidget(QWidget *parent, const QString &headerName,
+AddressRowWidget::AddressRowWidget(QWidget *parent, const QString &description,
const QList<Imap::Message::MailAddress> \
&addresses, MessageView *messageView):
- QWidget(parent), m_expander(0)
+ QWidget(parent), m_expander(0), m_expandedLength(0)
{
FlowLayout *lay = new FlowLayout(this, 0, 0, -1);
setLayout(lay);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
- QLabel *title = new \
QLabel(QStringLiteral("<b>%1:</b>").arg(headerName.toHtmlEscaped()), \
this);
- title->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
- title->setTextInteractionFlags(Qt::TextSelectableByMouse | \
Qt::LinksAccessibleByMouse);
- lay->addWidget(title);
- int chars = 0;
- bool collapse = false;
+ addAddresses(description, addresses, messageView);
+}
+
+void AddressRowWidget::addAddresses(const QString &description, const \
QList<Imap::Message::MailAddress> &addresses, MessageView *messageView) +{
+ if (m_expander)
+ layout()->removeWidget(m_expander);
+ if (!description.isEmpty()) {
+ QLabel *title = new QLabel(description, this);
+ title->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+ title->setTextInteractionFlags(Qt::TextSelectableByMouse | \
Qt::LinksAccessibleByMouse); + layout()->addWidget(title);
+ if (m_expander)
+ title->hide();
+ }
+ int collapse = m_expander ? m_expander->expanding() : 0;
for (int i = 0; i < addresses.size(); ++i) {
auto *w = new OneEnvelopeAddress(this, addresses[i], messageView,
i == addresses.size() - 1 ?
OneEnvelopeAddress::Position::Last :
OneEnvelopeAddress::Position::Middle);
- chars += plainChars(w);
- lay->addWidget(w);
- if (i > 1 && chars > 66) {
+ m_expandedLength += plainChars(w);
+ layout()->addWidget(w);
+ if (collapse || (i > 1 && m_expandedLength > nonExpandingLength)) {
w->hide();
- collapse = true;
+ ++collapse;
}
}
- if (collapse) {
- lay->addWidget(m_expander = new Expander(this));
+ if (collapse && !m_expander) {
+ m_expander = new Expander(this, collapse);
connect(m_expander, &Expander::clicked, this, &AddressRowWidget::toggle);
}
+ if (m_expander)
+ layout()->addWidget(m_expander);
}
void AddressRowWidget::toggle()
{
Q_ASSERT(m_expander);
- if (m_expander->isExpanding()) {
+ if (m_expander->expanding()) {
m_expander->setExpanding(false);
for (int i = 0; i < layout()->count(); ++i) {
if (QWidget *w = layout()->itemAt(i)->widget())
@@ -83,27 +97,30 @@ void AddressRowWidget::toggle()
int chars = 0, addresses = 0;
int collapse = 0;
for (int i = 0; i < layout()->count(); ++i) {
- if (OneEnvelopeAddress *w =
- qobject_cast<OneEnvelopeAddress*>(layout()->itemAt(i)->widget())) {
+ QWidget *w = layout()->itemAt(i)->widget();
+ if (collapse && w != m_expander) {
+ ++collapse;
+ w->hide();
+ continue;
+ }
+ if (OneEnvelopeAddress *oea = qobject_cast<OneEnvelopeAddress*>(w)) {
++addresses;
- chars += plainChars(w);
- if (addresses > 1 && chars > 66) {
- ++collapse;
+ chars += plainChars(oea);
+ if ((collapse = (addresses > 1 && chars > nonExpandingLength)))
w->hide();
- }
}
}
m_expander->setExpanding(collapse);
}
}
-Expander::Expander(QWidget *parent, Expander::Direction d) : QLabel(parent)
+Expander::Expander(QWidget *parent, int count) : QLabel(parent)
{
setCursor(Qt::PointingHandCursor);
- setExpanding(d == Direction::Expanding);
+ setExpanding(count);
}
-bool Expander::isExpanding() const {
+int Expander::expanding() const {
return m_expanding;
}
diff --git a/src/Gui/AddressRowWidget.h b/src/Gui/AddressRowWidget.h
index 46fa109..3cd3039 100644
--- a/src/Gui/AddressRowWidget.h
+++ b/src/Gui/AddressRowWidget.h
@@ -39,9 +39,8 @@ class Expander : public QLabel
{
Q_OBJECT
public:
- enum class Direction { Collapsing = 0, Expanding };
- explicit Expander(QWidget *parent, Direction d = Direction::Expanding);
- bool isExpanding() const;
+ explicit Expander(QWidget *parent, int count = 0);
+ int expanding() const;
void setExpanding(const int expanding);
QSize sizeHint() const;
signals:
@@ -58,7 +57,8 @@ class AddressRowWidget : public QWidget
{
Q_OBJECT
public:
- AddressRowWidget(QWidget *parent, const QString &headerName, const \
QList<Imap::Message::MailAddress> &addresses, MessageView *messageView); + \
AddressRowWidget(QWidget *parent, const QString &description, const \
QList<Imap::Message::MailAddress> &addresses, MessageView *messageView); + void \
addAddresses(const QString &description, const QList<Imap::Message::MailAddress> \
&addresses, MessageView *messageView);
private slots:
void toggle();
@@ -66,6 +66,7 @@ private:
AddressRowWidget(const AddressRowWidget &) = delete;
AddressRowWidget &operator=(const AddressRowWidget &) = delete;
Expander *m_expander;
+ uint m_expandedLength;
};
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic