Apply all the required styling in cpp
Apply all the required styling to show links, table, spoilers, etc in cpp. This also updates the method of revealing spoilers so now you can click to reveal then click again to hide.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "contentprovider.h"
|
||||
#include "enums/messagecomponenttype.h"
|
||||
#include "neochatconnection.h"
|
||||
#include "texthandler.h"
|
||||
|
||||
using namespace Quotient;
|
||||
|
||||
@@ -17,6 +18,11 @@ MessageContentModel::MessageContentModel(NeoChatRoom *room, MessageContentModel
|
||||
, m_room(room)
|
||||
, m_eventId(eventId)
|
||||
{
|
||||
m_theme = static_cast<Kirigami::Platform::PlatformTheme *>(qmlAttachedPropertiesObject<Kirigami::Platform::PlatformTheme>(this, true));
|
||||
if (m_theme) {
|
||||
connect(m_theme, &Kirigami::Platform::PlatformTheme::colorsChanged, this, &MessageContentModel::updateSpoilers);
|
||||
}
|
||||
|
||||
initializeModel();
|
||||
}
|
||||
|
||||
@@ -277,4 +283,40 @@ void MessageContentModel::closeLinkPreview(int row)
|
||||
}
|
||||
}
|
||||
|
||||
void MessageContentModel::updateSpoilers()
|
||||
{
|
||||
for (auto it = m_components.begin(); it != m_components.end(); ++it) {
|
||||
updateSpoiler(index(it - m_components.begin()));
|
||||
}
|
||||
}
|
||||
|
||||
void MessageContentModel::updateSpoiler(const QModelIndex &index)
|
||||
{
|
||||
const auto row = index.row();
|
||||
if (row < 0 || row >= rowCount()) {
|
||||
qWarning() << __FUNCTION__ << "called with row" << row << "which does not exist. m_components.size() =" << m_components.size();
|
||||
return;
|
||||
}
|
||||
|
||||
const auto spoilerRevealed = m_components[row].attributes.value("spoilerRevealed"_L1, false).toBool();
|
||||
m_components[row].display = TextHandler::updateSpoilerText(this, m_components[row].display, spoilerRevealed);
|
||||
Q_EMIT dataChanged(index, index, {DisplayRole});
|
||||
}
|
||||
|
||||
void MessageContentModel::toggleSpoiler(QModelIndex index)
|
||||
{
|
||||
const auto row = index.row();
|
||||
if (row < 0 || row >= rowCount()) {
|
||||
qWarning() << __FUNCTION__ << "called with row" << row << "which does not exist. m_components.size() =" << m_components.size();
|
||||
return;
|
||||
}
|
||||
if (m_components[row].type != MessageComponentType::Text) {
|
||||
return;
|
||||
}
|
||||
const auto spoilerRevealed = !m_components[row].attributes.value("spoilerRevealed"_L1, false).toBool();
|
||||
m_components[row].attributes["spoilerRevealed"_L1] = spoilerRevealed;
|
||||
Q_EMIT dataChanged(index, index, {ComponentAttributesRole});
|
||||
updateSpoiler(index);
|
||||
}
|
||||
|
||||
#include "moc_messagecontentmodel.cpp"
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <QQmlEngine>
|
||||
#include <QImageReader>
|
||||
|
||||
#include <Kirigami/Platform/PlatformTheme>
|
||||
#ifndef Q_OS_ANDROID
|
||||
#include <KSyntaxHighlighting/Definition>
|
||||
#include <KSyntaxHighlighting/Repository>
|
||||
@@ -101,6 +102,11 @@ public:
|
||||
*/
|
||||
Q_INVOKABLE void closeLinkPreview(int row);
|
||||
|
||||
/**
|
||||
* @brief Toggle spoiler for the component at the given row.
|
||||
*/
|
||||
Q_INVOKABLE void toggleSpoiler(QModelIndex index);
|
||||
|
||||
Q_SIGNALS:
|
||||
void authorChanged();
|
||||
|
||||
@@ -232,4 +238,8 @@ private:
|
||||
|
||||
QList<QUrl> m_removedLinkPreviews;
|
||||
MessageComponent linkPreviewComponent(const QUrl &link);
|
||||
|
||||
Kirigami::Platform::PlatformTheme *m_theme = nullptr;
|
||||
void updateSpoilers();
|
||||
void updateSpoiler(const QModelIndex &index);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user