Added popup show/hide logic

Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
This commit is contained in:
Dominique Fuchs 2019-12-30 11:39:21 +01:00
parent 438a445353
commit bb45a5f67e
6 changed files with 27 additions and 6 deletions

View file

@ -188,7 +188,8 @@ void ownCloudGui::slotTrayClicked(QSystemTrayIcon::ActivationReason reason)
raiseDialog(_settingsDialog.data()); raiseDialog(_settingsDialog.data());
} }
#else #else
slotOpenSettingsDialog(); UserModel::instance()->showWindow();
//slotOpenSettingsDialog();
#endif #endif
} }
} }

View file

@ -35,14 +35,15 @@ namespace OCC {
Systray::Systray() // TODO: make singleton, provide ::instance() Systray::Systray() // TODO: make singleton, provide ::instance()
: _currentAccount(nullptr) : _currentAccount(nullptr)
, _trayComponent(nullptr)
, _trayContext(nullptr) , _trayContext(nullptr)
, _accountMenuModel(nullptr) , _accountMenuModel(nullptr)
{ {
// Create QML tray engine, build component, set C++ backend context used in window.qml // Create QML tray engine, build component, set C++ backend context used in window.qml
// Use pointer instead of engine() helper function until Qt 5.12 is minimum standard // Use pointer instead of engine() helper function until Qt 5.12 is minimum standard
QQmlEngine *engine = new QQmlEngine; QQmlEngine *engine = new QQmlEngine;
QQmlComponent systray(engine, QUrl(QStringLiteral("qrc:/qml/src/gui/tray/window.qml"))); _trayComponent = new QQmlComponent(engine, QUrl(QStringLiteral("qrc:/qml/src/gui/tray/window.qml")));
_trayContext = engine->contextForObject(systray.create()); _trayContext = engine->contextForObject(_trayComponent->create());
_accountMenuModel = UserModel::instance(); _accountMenuModel = UserModel::instance();
@ -54,12 +55,12 @@ Systray::Systray() // TODO: make singleton, provide ::instance()
//ctxt->setContextProperty("filename", "state-offline"); //ctxt->setContextProperty("filename", "state-offline");
if (!AccountManager::instance()->accounts().isEmpty()) { if (!AccountManager::instance()->accounts().isEmpty()) {
slotChangeActivityModel(AccountManager::instance()->accounts().first()); slotChangeActivityModel(AccountManager::instance()->accounts().first());
} }
//connect(AccountManager::instance(), &AccountManager::accountAdded, //connect(AccountManager::instance(), &AccountManager::accountAdded,
// this, &Systray::slotChangeActivityModel); // this, &Systray::slotChangeActivityModel);
UserModel::instance()->hideWindow();
} }
Systray::~Systray() Systray::~Systray()

View file

@ -47,6 +47,8 @@ public:
~Systray(); ~Systray();
void showMessage(const QString &title, const QString &message, MessageIcon icon = Information, int millisecondsTimeoutHint = 10000); void showMessage(const QString &title, const QString &message, MessageIcon icon = Information, int millisecondsTimeoutHint = 10000);
void setToolTip(const QString &tip); void setToolTip(const QString &tip);
void showWindow();
void hideWindow();
signals: signals:
void currentUserChanged(); void currentUserChanged();
@ -56,6 +58,7 @@ private slots:
private: private:
AccountStatePtr _currentAccount; AccountStatePtr _currentAccount;
QQmlComponent *_trayComponent;
QQmlContext *_trayContext; QQmlContext *_trayContext;
UserModel *_accountMenuModel; UserModel *_accountMenuModel;
}; };

View file

@ -114,7 +114,7 @@ Q_INVOKABLE bool UserModel::isCurrentUserConnected()
return _users[_currentUserId].isConnected(); return _users[_currentUserId].isConnected();
} }
QImage UserModel::currentUserAvatar() Q_INVOKABLE QImage UserModel::currentUserAvatar()
{ {
return _users[_currentUserId].avatar(); return _users[_currentUserId].avatar();
} }

View file

@ -45,9 +45,9 @@ public:
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QImage currentUserAvatar();
QImage avatarById(const int &id); QImage avatarById(const int &id);
Q_INVOKABLE QImage currentUserAvatar();
Q_INVOKABLE int numUsers(); Q_INVOKABLE int numUsers();
Q_INVOKABLE bool isCurrentUserConnected(); Q_INVOKABLE bool isCurrentUserConnected();
Q_INVOKABLE QString currentUserName(); Q_INVOKABLE QString currentUserName();
@ -72,6 +72,9 @@ signals:
Q_INVOKABLE void newUserSelected(); Q_INVOKABLE void newUserSelected();
Q_INVOKABLE void refreshUserMenu(); Q_INVOKABLE void refreshUserMenu();
Q_INVOKABLE void hideWindow();
Q_INVOKABLE void showWindow();
protected: protected:
QHash<int, QByteArray> roleNames() const; QHash<int, QByteArray> roleNames() const;

View file

@ -14,6 +14,12 @@ Window {
color: "transparent" color: "transparent"
flags: Qt.FramelessWindowHint flags: Qt.FramelessWindowHint
onActiveChanged: {
if(!active) {
trayWindow.hide();
}
}
Component.onCompleted: { Component.onCompleted: {
/* desktopAvailableWidth and Height doesn't include the system tray bar /* desktopAvailableWidth and Height doesn't include the system tray bar
but breaks application anyway on windows when using multi monitor setup, but breaks application anyway on windows when using multi monitor setup,
@ -32,6 +38,13 @@ Window {
onNewUserSelected: { onNewUserSelected: {
accountMenu.close() accountMenu.close()
} }
onShowWindow: {
trayWindow.show();
trayWindow.requestActivate();
}
onHideWindow: {
trayWindow.hide();
}
} }
Rectangle { Rectangle {