Added ActivityModel in new tray backend, implemented as delegate in UI

Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
This commit is contained in:
Dominique Fuchs 2020-01-02 10:39:53 +01:00
Родитель 36467c1e3a
Коммит 556a1a5ef2
4 изменённых файлов: 110 добавлений и 17 удалений

Просмотреть файл

@ -48,6 +48,7 @@ Systray::Systray() // TODO: make singleton, provide ::instance()
engine->addImageProvider("avatars", new ImageProvider);
engine->rootContext()->setContextProperty("userModelBackend", UserModel::instance());
engine->rootContext()->setContextProperty("activityModel", ActivityModel::instance());
engine->rootContext()->setContextProperty("systrayBackend", this);
// TODO: hack to pass the icon to QML

Просмотреть файл

@ -23,7 +23,7 @@ void User::setCurrentUser(const bool &isCurrent)
_isCurrentUser = isCurrent;
}
Folder* User::getFolder()
Folder *User::getFolder()
{
foreach (Folder *folder, FolderMan::instance()->map()) {
if (folder->accountState() == _account.data()) {
@ -99,12 +99,6 @@ UserModel::UserModel(QObject *parent)
, _currentUserId()
{
// TODO: Remember selected user from last quit via settings file
// this is the reason why this looks like an unnecessary double check atm
/*if (AccountManager::instance()->accounts().size() > 0) {
addUser(AccountManager::instance()->accounts().first(), true);
} else {
return;
}*/
if (AccountManager::instance()->accounts().size() > 0) {
initUserList();
}
@ -212,6 +206,76 @@ QHash<int, QByteArray> UserModel::roleNames() const
/*-------------------------------------------------------------------------------------*/
QString UserActivity::type() const
{
return "Test";
}
QString UserActivity::fileName() const
{
return "Test";
}
QString UserActivity::info() const
{
return "Test";
}
ActivityModel *ActivityModel::_instance = nullptr;
ActivityModel *ActivityModel::instance()
{
if (_instance == nullptr) {
_instance = new ActivityModel();
}
return _instance;
}
ActivityModel::ActivityModel(QObject *parent)
: QAbstractListModel()
{
}
QHash<int, QByteArray> ActivityModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[TypeRole] = "type";
roles[FileNameRole] = "filename";
roles[InfoRole] = "info";
return roles;
}
int ActivityModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return _activities.count();
}
QVariant ActivityModel::data(const QModelIndex &index, int role) const
{
if (index.row() < 0 || index.row() >= _activities.count()) {
return QVariant();
}
const UserActivity &activity = _activities[index.row()];
if (role == TypeRole)
return activity.type();
else if (role == FileNameRole)
return activity.fileName();
else if (role == InfoRole)
return activity.info();
return QVariant();
}
void ActivityModel::addActivity(const UserActivity &activity)
{
beginInsertRows(QModelIndex(), rowCount(), rowCount());
_activities << activity;
endInsertRows();
}
/*-------------------------------------------------------------------------------------*/
ImageProvider::ImageProvider()
: QQuickImageProvider(QQuickImageProvider::Image)
{

Просмотреть файл

@ -21,7 +21,7 @@ public:
bool isConnected() const;
bool isCurrentUser() const;
void setCurrentUser(const bool &isCurrent);
Folder* getFolder();
Folder *getFolder();
void openLocalFolder();
QString name() const;
QString server() const;
@ -85,6 +85,40 @@ private:
void initUserList();
};
class UserActivity
{
public:
QString type() const;
QString fileName() const;
QString info() const;
};
class ActivityModel : public QAbstractListModel
{
Q_OBJECT
public:
static ActivityModel *instance();
virtual ~ActivityModel() {};
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
void addActivity(const UserActivity &activity);
enum ActivityRoles {
TypeRole = Qt::UserRole + 1,
FileNameRole,
InfoRole
};
protected:
QHash<int, QByteArray> roleNames() const;
private:
static ActivityModel *_instance;
ActivityModel(QObject *parent = 0);
QList<UserActivity> _activities;
};
class ImageProvider : public QQuickImageProvider
{
public:

Просмотреть файл

@ -263,7 +263,6 @@ Window {
Layout.preferredHeight: (trayWindowHeaderBackground.height)
flat: true
//icon.source: "../../theme/white/talk-app.svg"
icon.source: "qrc:///client/theme/white/talk-app.svg"
icon.color: "transparent"
@ -291,7 +290,6 @@ Window {
Layout.preferredHeight: (trayWindowHeaderBackground.height)
flat: true
//icon.source: "../../theme/white/more-apps.svg"
icon.source: "qrc:///client/theme/white/more-apps.svg"
icon.color: "transparent"
@ -355,10 +353,6 @@ Window {
}
} // Rectangle trayWindowHeaderBackground
ListModel {
id: activityListModel
}
ListView {
id: activityListView
anchors.top: trayWindowHeaderBackground.bottom
@ -366,7 +360,7 @@ Window {
height: trayWindowBackground.height - trayWindowHeaderBackground.height
clip: true
model: activityListModel
model: activityModel
delegate: RowLayout {
id: activityItem
@ -389,12 +383,12 @@ Window {
Layout.alignment: Qt.AlignLeft
Text {
id: activityTextTitle
text: name
text: filename
font.pointSize: 9
}
Text {
id: activityTextInfo
text: "Lorem ipsum dolor sit amet"
text: info
font.pointSize: 8
}
}