-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New design and logic of notifications
- Loading branch information
Showing
12 changed files
with
425 additions
and
9 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
import QtQuick | ||
import "../Style.js" as Style | ||
import notificationType 1.0 | ||
|
||
Row { | ||
id: notification | ||
|
||
width: listView.width - 2 * Style.commonSpacing | ||
height: Style.notificationHeight | ||
anchors.horizontalCenter: parent ? parent.horizontalCenter : undefined | ||
|
||
readonly property int innerSpacing: 5 * __dp | ||
|
||
Rectangle { | ||
width: parent.width | ||
height: parent.height | ||
color: Style.forest | ||
radius: Style.notificationRadius | ||
|
||
Rectangle { | ||
id: borderRect | ||
|
||
anchors.centerIn: parent | ||
width: parent.width - notification.innerSpacing | ||
height: parent.height - notification.innerSpacing | ||
radius: Style.notificationRadius | ||
color: Style.transparent | ||
border.width: __dp | ||
border.color: { | ||
switch( type ) { | ||
case NotificationType.Information: return Style.sky | ||
case NotificationType.Warning: return Style.warning | ||
case NotificationType.Error: return Style.negative | ||
default: return Style.positive | ||
} | ||
} | ||
} | ||
|
||
Rectangle { | ||
id: icon | ||
|
||
anchors.verticalCenter: parent.verticalCenter | ||
anchors.left: parent.left | ||
anchors.leftMargin: Style.commonSpacing | ||
width: 18 * __dp | ||
height: 18 * __dp | ||
color: borderRect.border.color | ||
radius: width/2 | ||
} | ||
|
||
Text { | ||
anchors.verticalCenter: parent.verticalCenter | ||
anchors.left: icon.right | ||
width: parent.width - 3 * Style.commonSpacing - closeButton.width - icon.width | ||
text: message | ||
color: Style.white | ||
verticalAlignment: Text.AlignVCenter | ||
horizontalAlignment: Text.AlignLeft | ||
leftPadding: Style.commonSpacing - notification.innerSpacing | ||
font: Qt.font(Style.t3) | ||
clip: true | ||
} | ||
|
||
Image { | ||
id: closeButton | ||
|
||
anchors.right: parent.right | ||
anchors.rightMargin: Style.commonSpacing | ||
anchors.verticalCenter: parent.verticalCenter | ||
scale: maRemove.containsMouse ? 1.2 : 1 | ||
source: Style.closeIcon | ||
|
||
MouseArea { | ||
id: maRemove | ||
|
||
anchors.fill: parent | ||
hoverEnabled: true | ||
onClicked: notificationModel.remove(id) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
import QtQuick | ||
import "../Style.js" as Style | ||
|
||
Item { | ||
id: control | ||
|
||
anchors.top: parent.top | ||
anchors.topMargin: Style.commonSpacing | ||
width: parent.width | ||
height: parent.height | ||
|
||
// just for information - will be removed in release version | ||
Rectangle { | ||
anchors.bottom: parent.bottom | ||
width: control.width | ||
height: 20 | ||
color: Style.white | ||
|
||
Text { | ||
text: listView.count | ||
anchors.centerIn: parent | ||
color: Style.forest | ||
} | ||
} | ||
|
||
ListView { | ||
id: listView | ||
|
||
anchors.top: parent.top | ||
width: parent.width | ||
height: Style.notificationHeight * listView.count + spacing * (listView.count - 1) | ||
spacing: Style.notificationSpace | ||
clip: true | ||
model: notificationModel | ||
delegate: MMNotification { | ||
|
||
} | ||
|
||
add: Transition { | ||
NumberAnimation { property: "opacity"; from: 0; to: 1.0; duration: 200 } | ||
NumberAnimation { property: "scale"; easing.type: Easing.OutCubic; from: 0; to: 1.0; duration: 200 } | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "notificationmodel.h" | ||
#include <QQmlEngine> | ||
|
||
Notification::Notification(uint id, const QString &message, uint interval, NotificationType::MessageType type = NotificationType::Information) | ||
{ | ||
mId = id; | ||
mMessage = message; | ||
mInterval = interval; | ||
mType = type; | ||
} | ||
|
||
NotificationModel::NotificationModel(QObject *parent) : QAbstractListModel{parent} | ||
{ | ||
qmlRegisterUncreatableType<NotificationType>("notificationType", 1, 0, "NotificationType", "Not creatable as it is an enum type"); | ||
|
||
mTimer = new QTimer(this); | ||
connect(mTimer, &QTimer::timeout, this, &NotificationModel::timerFired); | ||
mTimer->start(1000); | ||
|
||
// Initial data | ||
mNotifications << Notification{ nextId(), "Ahoj", 10, NotificationType::Information }; | ||
mNotifications << Notification{ nextId(), "Hello all", 5, NotificationType::Information }; | ||
} | ||
|
||
NotificationModel::~NotificationModel() | ||
{ | ||
mTimer->stop(); | ||
delete mTimer; | ||
} | ||
|
||
QHash<int, QByteArray> NotificationModel::roleNames() const | ||
{ | ||
return { | ||
{ IdRole, "id" }, | ||
{ MessageRole, "message" }, | ||
{ TypeRole, "type" } | ||
}; | ||
} | ||
|
||
int NotificationModel::rowCount(const QModelIndex &parent) const | ||
{ | ||
Q_UNUSED(parent) | ||
return mNotifications.size(); | ||
} | ||
|
||
QVariant NotificationModel::data(const QModelIndex &index, int role) const | ||
{ | ||
if (!hasIndex(index.row(), index.column(), index.parent())) | ||
return {}; | ||
|
||
Notification notification = mNotifications.at(index.row()); | ||
if (role == IdRole) return notification.id(); | ||
if (role == MessageRole) return notification.message(); | ||
if (role == TypeRole) return notification.type(); | ||
|
||
return {}; | ||
} | ||
|
||
// remove item by message | ||
void NotificationModel::remove(uint id) | ||
{ | ||
for(int i=0; i<mNotifications.count(); i++) { | ||
if(mNotifications[i].id() == id) { | ||
beginRemoveRows(QModelIndex(), i, i); | ||
mNotifications.removeAt(i); | ||
endRemoveRows(); | ||
|
||
emit dataChanged(createIndex(0, 0), createIndex(rowCount(), 0)); // refresh whole model | ||
emit rowCountChanged(); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
// add new unique message with interval | ||
void NotificationModel::add(const QString &message, uint interval, NotificationType::MessageType type = NotificationType::Information) | ||
{ | ||
for(Notification ¬ification : mNotifications) { | ||
if(notification.message() == message) | ||
return; | ||
} | ||
|
||
beginInsertRows(QModelIndex(), rowCount(), rowCount()); | ||
mNotifications << Notification{ nextId(), message, interval, type }; | ||
endInsertRows(); | ||
|
||
emit rowCountChanged(); | ||
} | ||
|
||
// check for auto removing notification | ||
void NotificationModel::timerFired() | ||
{ | ||
for(Notification ¬ification : mNotifications) { | ||
if(notification.canBeRemoved()) | ||
remove(notification.id()); | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.
9a38dbe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iOS - version 23.10.470411 just submitted!