Support Qt 5.11

This commit is contained in:
Black Hat 2018-07-07 16:24:53 +08:00
parent 531abcb48c
commit a850224c98
4 changed files with 20 additions and 128 deletions

BIN
asset/img/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

View File

@ -1,93 +0,0 @@
#include "matriqueroom.h"
#include "events/roommessageevent.h"
#include "user.h"
using namespace QMatrixClient;
MatriqueRoom::MatriqueRoom(Connection* connection, QString roomId,
JoinState joinState)
: Room(connection, roomId, joinState)
{
connect(this, &MatriqueRoom::notificationCountChanged, this, &MatriqueRoom::countChanged);
connect(this, &MatriqueRoom::highlightCountChanged, this, &MatriqueRoom::countChanged);
}
const QString& MatriqueRoom::cachedInput() const
{
return m_cachedInput;
}
void MatriqueRoom::setCachedInput(const QString& input)
{
m_cachedInput = input;
}
bool MatriqueRoom::isEventHighlighted(RoomEvent* e) const
{
return highlights.contains(e);
}
int MatriqueRoom::savedTopVisibleIndex() const
{
return firstDisplayedMarker() == timelineEdge() ? 0 :
firstDisplayedMarker() - messageEvents().rbegin();
}
int MatriqueRoom::savedBottomVisibleIndex() const
{
return lastDisplayedMarker() == timelineEdge() ? 0 :
lastDisplayedMarker() - messageEvents().rbegin();
}
void MatriqueRoom::saveViewport(int topIndex, int bottomIndex)
{
if (bottomIndex == savedBottomVisibleIndex() &&
(bottomIndex == 0 || topIndex == savedTopVisibleIndex()))
return;
if (bottomIndex == 0)
{
qDebug() << "Saving viewport as the latest available";
setFirstDisplayedEventId({}); setLastDisplayedEventId({});
return;
}
qDebug() << "Saving viewport:" << topIndex << "thru" << bottomIndex;
setFirstDisplayedEvent(maxTimelineIndex() - topIndex);
setLastDisplayedEvent(maxTimelineIndex() - bottomIndex);
}
void MatriqueRoom::countChanged()
{
if(displayed() && !hasUnreadMessages())
{
resetNotificationCount();
resetHighlightCount();
}
}
void MatriqueRoom::onAddNewTimelineEvents(timeline_iter_t from)
{
std::for_each(from, messageEvents().cend(),
[this] (const TimelineItem& ti) { checkForHighlights(ti); });
}
void MatriqueRoom::onAddHistoricalTimelineEvents(rev_iter_t from)
{
std::for_each(from, messageEvents().crend(),
[this] (const TimelineItem& ti) { checkForHighlights(ti); });
}
void MatriqueRoom::checkForHighlights(const QMatrixClient::TimelineItem& ti)
{
auto localUserId = localUser()->id();
if (ti->senderId() == localUserId)
return;
if (ti->type() == EventType::RoomMessage)
{
auto* rme = static_cast<const RoomMessageEvent*>(ti.event());
if (rme->plainBody().contains(localUserId) ||
rme->plainBody().contains(roomMembername(localUserId)))
highlights.insert(ti.event());
}
}

View File

@ -1,35 +0,0 @@
#ifndef MATRIQUEROOM_H
#define MATRIQUEROOM_H
#include "room.h"
class MatriqueRoom: public QMatrixClient::Room
{
Q_OBJECT
public:
MatriqueRoom(QMatrixClient::Connection* connection,
QString roomId, QMatrixClient::JoinState joinState);
const QString& cachedInput() const;
void setCachedInput(const QString& input);
bool isEventHighlighted(QMatrixClient::RoomEvent* e) const;
Q_INVOKABLE int savedTopVisibleIndex() const;
Q_INVOKABLE int savedBottomVisibleIndex() const;
Q_INVOKABLE void saveViewport(int topIndex, int bottomIndex);
private slots:
void countChanged();
private:
QSet<QMatrixClient::RoomEvent*> highlights;
QString m_cachedInput;
void onAddNewTimelineEvents(timeline_iter_t from) override;
void onAddHistoricalTimelineEvents(rev_iter_t from) override;
void checkForHighlights(const QMatrixClient::TimelineItem& ti);
};
#endif // MATRIQUEROOM_H

View File

@ -0,0 +1,20 @@
import QtQuick 2.10
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
Item {
property alias icon: iconText.text
property var color: "white"
id: item
Text {
id: iconText
anchors.fill: parent
font.pointSize: 16
font.family: materialFont.name
color: item.color
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
}