summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2020-04-09 00:07:04 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2020-04-10 08:48:30 +0200
commitd68b24188fd453bd8ca09e3035edc4faee74c6af (patch)
tree8ef4b507d59a59225b7d1573dc469516e952412e
parentMake Filemessage background size by content (diff)
downloadnheko-d68b24188fd453bd8ca09e3035edc4faee74c6af.tar.xz
Size reply background by contents
-rw-r--r--resources/qml/delegates/MessageDelegate.qml1
-rw-r--r--resources/qml/delegates/Reply.qml10
-rw-r--r--src/timeline/DelegateChooser.cpp21
-rw-r--r--src/timeline/DelegateChooser.h6
4 files changed, 26 insertions, 12 deletions
diff --git a/resources/qml/delegates/MessageDelegate.qml b/resources/qml/delegates/MessageDelegate.qml
index daeb61d6..ff103459 100644
--- a/resources/qml/delegates/MessageDelegate.qml
+++ b/resources/qml/delegates/MessageDelegate.qml
@@ -11,6 +11,7 @@ Item {
 	property alias modelData: model.data
 
 	height: chooser.childrenRect.height
+	property real implicitWidth: (chooser.child && chooser.child.implicitWidth) ? chooser.child.implicitWidth : width
 
 	DelegateChooser {
 		id: chooser
diff --git a/resources/qml/delegates/Reply.qml b/resources/qml/delegates/Reply.qml
index 06804328..c5ac0ca3 100644
--- a/resources/qml/delegates/Reply.qml
+++ b/resources/qml/delegates/Reply.qml
@@ -54,5 +54,13 @@ Rectangle {
 		}
 	}
 
-	color: Qt.rgba(userColor.r, userColor.g, userColor.b, 0.2)
+	color: "transparent"
+
+	Rectangle {
+		id: backgroundItem
+		z: -1
+		height: replyContainer.height
+		width: Math.min(Math.max(reply.implicitWidth, userName.implicitWidth) + 8 + 4, parent.width)
+		color: Qt.rgba(userColor.r, userColor.g, userColor.b, 0.2)
+	}
 }
diff --git a/src/timeline/DelegateChooser.cpp b/src/timeline/DelegateChooser.cpp
index 46ab6c0e..1f5fae7e 100644
--- a/src/timeline/DelegateChooser.cpp
+++ b/src/timeline/DelegateChooser.cpp
@@ -94,9 +94,9 @@ DelegateChooser::recalcChild()
         for (const auto choice : qAsConst(choices_)) {
                 auto choiceValue = choice->roleValue();
                 if (!roleValue_.isValid() || !choiceValue.isValid() || choiceValue == roleValue_) {
-                        if (child) {
-                                child->setParentItem(nullptr);
-                                child = nullptr;
+                        if (child_) {
+                                child_->setParentItem(nullptr);
+                                child_ = nullptr;
                         }
 
                         choice->delegate()->create(incubator, QQmlEngine::contextForObject(this));
@@ -116,19 +116,20 @@ void
 DelegateChooser::DelegateIncubator::statusChanged(QQmlIncubator::Status status)
 {
         if (status == QQmlIncubator::Ready) {
-                chooser.child = dynamic_cast<QQuickItem *>(object());
-                if (chooser.child == nullptr) {
+                chooser.child_ = dynamic_cast<QQuickItem *>(object());
+                if (chooser.child_ == nullptr) {
                         nhlog::ui()->error("Delegate has to be derived of Item!");
                         return;
                 }
 
-                chooser.child->setParentItem(&chooser);
-                connect(chooser.child, &QQuickItem::heightChanged, &chooser, [this]() {
-                        chooser.setHeight(chooser.child->height());
+                chooser.child_->setParentItem(&chooser);
+                connect(chooser.child_, &QQuickItem::heightChanged, &chooser, [this]() {
+                        chooser.setHeight(chooser.child_->height());
                 });
-                chooser.setHeight(chooser.child->height());
-                QQmlEngine::setObjectOwnership(chooser.child,
+                chooser.setHeight(chooser.child_->height());
+                QQmlEngine::setObjectOwnership(chooser.child_,
                                                QQmlEngine::ObjectOwnership::JavaScriptOwnership);
+                emit chooser.childChanged();
 
         } else if (status == QQmlIncubator::Error) {
                 for (const auto &e : errors())
diff --git a/src/timeline/DelegateChooser.h b/src/timeline/DelegateChooser.h
index 68ebeb04..2524b068 100644
--- a/src/timeline/DelegateChooser.h
+++ b/src/timeline/DelegateChooser.h
@@ -45,18 +45,22 @@ class DelegateChooser : public QQuickItem
 public:
         Q_PROPERTY(QQmlListProperty<DelegateChoice> choices READ choices CONSTANT)
         Q_PROPERTY(QVariant roleValue READ roleValue WRITE setRoleValue NOTIFY roleValueChanged)
+        Q_PROPERTY(QQuickItem *child READ child NOTIFY childChanged)
 
         QQmlListProperty<DelegateChoice> choices();
 
         QVariant roleValue() const;
         void setRoleValue(const QVariant &value);
 
+        QQuickItem *child() const { return child_; }
+
         void recalcChild();
         void componentComplete() override;
 
 signals:
         void roleChanged();
         void roleValueChanged();
+        void childChanged();
 
 private:
         struct DelegateIncubator : public QQmlIncubator
@@ -72,7 +76,7 @@ private:
 
         QVariant roleValue_;
         QList<DelegateChoice *> choices_;
-        QQuickItem *child = nullptr;
+        QQuickItem *child_ = nullptr;
         DelegateIncubator incubator{*this};
 
         static void appendChoice(QQmlListProperty<DelegateChoice> *, DelegateChoice *);