[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [trojita] src/Gui: polish TagWidget
From: Thomas_Lübking <thomas.luebking () gmail ! com>
Date: 2016-03-05 16:57:05
Message-ID: E1acFVp-0000Mk-3H () scm ! kde ! org
[Download RAW message or body]
Git commit f97fbb6aa8b87daed1060cbbdd5a078b6a65d772 by Thomas Lübking.
Committed on 28/02/2016 at 12:07.
Pushed by gerrit into branch 'master'.
polish TagWidget
- no stylesheets
* operate on application palette
* didn't control foreground (near unreadable on bright on dark)
* issues with rounded rects (if 2*roundness > width/height)
- more subtle coloring
- centered text (notable on "+")
- use pointing hand to indicate clickability
- only remove tag on clicking X
- disable deleted tag as immediate feedback (before imap sync)
Change-Id: Idec2543da57a9c5156d32cc4d9dbf6cc8076e1c5
M +0 -2 src/Gui/MessageView.cpp
M +47 -10 src/Gui/TagWidget.cpp
M +3 -1 src/Gui/TagWidget.h
http://commits.kde.org/trojita/f97fbb6aa8b87daed1060cbbdd5a078b6a65d772
diff --git a/src/Gui/MessageView.cpp b/src/Gui/MessageView.cpp
index 063afa9..08bcee7 100644
--- a/src/Gui/MessageView.cpp
+++ b/src/Gui/MessageView.cpp
@@ -103,8 +103,6 @@ MessageView::MessageView(QWidget *parent, QSettings *settings, \
Plugins::PluginMa
// the tag bar
tags = new TagListWidget(headerSection);
- tags->setBackgroundRole(helpingHeader.backgroundRole());
- tags->setForegroundRole(helpingHeader.foregroundRole());
tags->hide();
connect(tags, &TagListWidget::tagAdded, this, &MessageView::newLabelAction);
connect(tags, &TagListWidget::tagRemoved, this, \
&MessageView::deleteLabelAction);
diff --git a/src/Gui/TagWidget.cpp b/src/Gui/TagWidget.cpp
index 86a563c..8e76596 100644
--- a/src/Gui/TagWidget.cpp
+++ b/src/Gui/TagWidget.cpp
@@ -23,57 +23,94 @@
*/
#include <QEvent>
+#include <QMouseEvent>
+#include <QPainter>
#include <QPair>
+#include "UiUtils/Color.h"
+
#include "TagWidget.h"
namespace Gui
{
-TagWidget::TagWidget(const Mode mode, const QString &tagName, const QString \
&backgroundColor): +static const QLatin1String closeIndicator(" | x");
+
+TagWidget::TagWidget(const Mode mode, const QString &tagName, const QColor \
&backgroundColor): QLabel(),
m_tagName(tagName),
- m_mode(mode)
+ m_mode(mode),
+ m_tint(backgroundColor),
+ m_splitPos(0)
{
- setStyleSheet(QStringLiteral("border: 1px solid black; border-radius: 4px; \
background-color: %1;").arg(backgroundColor)); + \
m_tint.setAlpha(m_tint.alpha()/3); + setAlignment(Qt::AlignCenter);
+ int l,t,r,b;
+ getContentsMargins(&l, &t, &r, &b);
+ setContentsMargins(l + 4, t, r + 4, b);
+ setCursor(Qt::PointingHandCursor);
}
TagWidget *TagWidget::addingWidget()
{
- auto res = new TagWidget(Mode::AddingWidget, QString(), \
QStringLiteral("lightgreen")); + auto res = new TagWidget(Mode::AddingWidget, \
QString(), Qt::green); res->setText(QStringLiteral("+"));
return res;
}
TagWidget *TagWidget::userKeyword(const QString &tagName)
{
- auto res = new TagWidget(Mode::UserKeyword, tagName, \
QStringLiteral("lightyellow"));
- res->setText(tagName + QLatin1String(" | x"));
+ auto res = new TagWidget(Mode::UserKeyword, tagName, Qt::yellow);
+ res->setText(tagName + closeIndicator);
+ res->setMouseTracking(true);
return res;
}
TagWidget *TagWidget::systemFlag(const QString &flagName)
{
- auto res = new TagWidget(Mode::SystemFlag, flagName, \
QStringLiteral("lightgrey")); + auto res = new TagWidget(Mode::SystemFlag, \
flagName, Qt::gray); res->setText(flagName);
return res;
}
bool TagWidget::event(QEvent *e)
{
- if (e->type() == QEvent::MouseButtonPress) {
+ if (e->type() == QEvent::MouseMove) {
+ if (m_mode == Mode::UserKeyword)
+ setCursor(static_cast<QMouseEvent*>(e)->pos().x() > m_splitPos ? \
Qt::PointingHandCursor : Qt::ArrowCursor); + } else if (e->type() == \
QEvent::Resize) { + if (m_mode == Mode::UserKeyword)
+ m_splitPos = contentsRect().right() - \
fontMetrics().width(closeIndicator); + } else if (e->type() == \
QEvent::MouseButtonPress) { switch (m_mode) {
case Mode::AddingWidget:
emit addingClicked();
return true;
- case Mode::UserKeyword:
+ case Mode::UserKeyword: {
Q_ASSERT(!m_tagName.isEmpty());
- emit removeClicked(m_tagName);
+ if (static_cast<QMouseEvent*>(e)->pos().x() > m_splitPos) {
+ setDisabled(true);
+ setText(m_tagName);
+ setCursor(Qt::ArrowCursor);
+ setMouseTracking(false);
+ emit removeClicked(m_tagName);
+ }
return true;
+ }
case Mode::SystemFlag:
// do nothing -- this is just an indicator
break;
}
+ } else if (e->type() == QEvent::Paint) {
+ if (isEnabled()) {
+ QPainter p(this);
+ p.setRenderHint(QPainter::Antialiasing);
+ p.setBrush(UiUtils::tintColor(palette().color(QPalette::Active, \
backgroundRole()), m_tint)); + p.setPen(Qt::NoPen);
+ const int rnd = qMin(width()/2, height()/4);
+ p.drawRoundedRect(rect(), rnd, rnd);
+ p.end();
+ }
}
return QLabel::event(e);
diff --git a/src/Gui/TagWidget.h b/src/Gui/TagWidget.h
index 1faba34..6cd76b1 100644
--- a/src/Gui/TagWidget.h
+++ b/src/Gui/TagWidget.h
@@ -56,8 +56,10 @@ private:
QString m_tagName;
const Mode m_mode;
+ QColor m_tint;
+ int m_splitPos;
- TagWidget(const Mode mode, const QString &tagName, const QString \
&backgroundColor); + TagWidget(const Mode mode, const QString &tagName, const \
QColor &backgroundColor); };
} // namespace Gui
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic