Size reply background by contents
This commit is contained in:
parent
d2e495532d
commit
d68b24188f
@ -11,6 +11,7 @@ Item {
|
|||||||
property alias modelData: model.data
|
property alias modelData: model.data
|
||||||
|
|
||||||
height: chooser.childrenRect.height
|
height: chooser.childrenRect.height
|
||||||
|
property real implicitWidth: (chooser.child && chooser.child.implicitWidth) ? chooser.child.implicitWidth : width
|
||||||
|
|
||||||
DelegateChooser {
|
DelegateChooser {
|
||||||
id: chooser
|
id: chooser
|
||||||
|
@ -54,5 +54,13 @@ Rectangle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
color: Qt.rgba(userColor.r, userColor.g, userColor.b, 0.2)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,9 +94,9 @@ DelegateChooser::recalcChild()
|
|||||||
for (const auto choice : qAsConst(choices_)) {
|
for (const auto choice : qAsConst(choices_)) {
|
||||||
auto choiceValue = choice->roleValue();
|
auto choiceValue = choice->roleValue();
|
||||||
if (!roleValue_.isValid() || !choiceValue.isValid() || choiceValue == roleValue_) {
|
if (!roleValue_.isValid() || !choiceValue.isValid() || choiceValue == roleValue_) {
|
||||||
if (child) {
|
if (child_) {
|
||||||
child->setParentItem(nullptr);
|
child_->setParentItem(nullptr);
|
||||||
child = nullptr;
|
child_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
choice->delegate()->create(incubator, QQmlEngine::contextForObject(this));
|
choice->delegate()->create(incubator, QQmlEngine::contextForObject(this));
|
||||||
@ -116,19 +116,20 @@ void
|
|||||||
DelegateChooser::DelegateIncubator::statusChanged(QQmlIncubator::Status status)
|
DelegateChooser::DelegateIncubator::statusChanged(QQmlIncubator::Status status)
|
||||||
{
|
{
|
||||||
if (status == QQmlIncubator::Ready) {
|
if (status == QQmlIncubator::Ready) {
|
||||||
chooser.child = dynamic_cast<QQuickItem *>(object());
|
chooser.child_ = dynamic_cast<QQuickItem *>(object());
|
||||||
if (chooser.child == nullptr) {
|
if (chooser.child_ == nullptr) {
|
||||||
nhlog::ui()->error("Delegate has to be derived of Item!");
|
nhlog::ui()->error("Delegate has to be derived of Item!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
chooser.child->setParentItem(&chooser);
|
chooser.child_->setParentItem(&chooser);
|
||||||
connect(chooser.child, &QQuickItem::heightChanged, &chooser, [this]() {
|
connect(chooser.child_, &QQuickItem::heightChanged, &chooser, [this]() {
|
||||||
chooser.setHeight(chooser.child->height());
|
chooser.setHeight(chooser.child_->height());
|
||||||
});
|
});
|
||||||
chooser.setHeight(chooser.child->height());
|
chooser.setHeight(chooser.child_->height());
|
||||||
QQmlEngine::setObjectOwnership(chooser.child,
|
QQmlEngine::setObjectOwnership(chooser.child_,
|
||||||
QQmlEngine::ObjectOwnership::JavaScriptOwnership);
|
QQmlEngine::ObjectOwnership::JavaScriptOwnership);
|
||||||
|
emit chooser.childChanged();
|
||||||
|
|
||||||
} else if (status == QQmlIncubator::Error) {
|
} else if (status == QQmlIncubator::Error) {
|
||||||
for (const auto &e : errors())
|
for (const auto &e : errors())
|
||||||
|
@ -45,18 +45,22 @@ class DelegateChooser : public QQuickItem
|
|||||||
public:
|
public:
|
||||||
Q_PROPERTY(QQmlListProperty<DelegateChoice> choices READ choices CONSTANT)
|
Q_PROPERTY(QQmlListProperty<DelegateChoice> choices READ choices CONSTANT)
|
||||||
Q_PROPERTY(QVariant roleValue READ roleValue WRITE setRoleValue NOTIFY roleValueChanged)
|
Q_PROPERTY(QVariant roleValue READ roleValue WRITE setRoleValue NOTIFY roleValueChanged)
|
||||||
|
Q_PROPERTY(QQuickItem *child READ child NOTIFY childChanged)
|
||||||
|
|
||||||
QQmlListProperty<DelegateChoice> choices();
|
QQmlListProperty<DelegateChoice> choices();
|
||||||
|
|
||||||
QVariant roleValue() const;
|
QVariant roleValue() const;
|
||||||
void setRoleValue(const QVariant &value);
|
void setRoleValue(const QVariant &value);
|
||||||
|
|
||||||
|
QQuickItem *child() const { return child_; }
|
||||||
|
|
||||||
void recalcChild();
|
void recalcChild();
|
||||||
void componentComplete() override;
|
void componentComplete() override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void roleChanged();
|
void roleChanged();
|
||||||
void roleValueChanged();
|
void roleValueChanged();
|
||||||
|
void childChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct DelegateIncubator : public QQmlIncubator
|
struct DelegateIncubator : public QQmlIncubator
|
||||||
@ -72,7 +76,7 @@ private:
|
|||||||
|
|
||||||
QVariant roleValue_;
|
QVariant roleValue_;
|
||||||
QList<DelegateChoice *> choices_;
|
QList<DelegateChoice *> choices_;
|
||||||
QQuickItem *child = nullptr;
|
QQuickItem *child_ = nullptr;
|
||||||
DelegateIncubator incubator{*this};
|
DelegateIncubator incubator{*this};
|
||||||
|
|
||||||
static void appendChoice(QQmlListProperty<DelegateChoice> *, DelegateChoice *);
|
static void appendChoice(QQmlListProperty<DelegateChoice> *, DelegateChoice *);
|
||||||
|
Loading…
Reference in New Issue
Block a user