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());
}
#else
slotOpenSettingsDialog();
UserModel::instance()->showWindow();
//slotOpenSettingsDialog();
#endif
}
}

View file

@ -35,14 +35,15 @@ namespace OCC {
Systray::Systray() // TODO: make singleton, provide ::instance()
: _currentAccount(nullptr)
, _trayComponent(nullptr)
, _trayContext(nullptr)
, _accountMenuModel(nullptr)
{
// 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
QQmlEngine *engine = new QQmlEngine;
QQmlComponent systray(engine, QUrl(QStringLiteral("qrc:/qml/src/gui/tray/window.qml")));
_trayContext = engine->contextForObject(systray.create());
_trayComponent = new QQmlComponent(engine, QUrl(QStringLiteral("qrc:/qml/src/gui/tray/window.qml")));
_trayContext = engine->contextForObject(_trayComponent->create());
_accountMenuModel = UserModel::instance();
@ -54,12 +55,12 @@ Systray::Systray() // TODO: make singleton, provide ::instance()
//ctxt->setContextProperty("filename", "state-offline");
if (!AccountManager::instance()->accounts().isEmpty()) {
slotChangeActivityModel(AccountManager::instance()->accounts().first());
}
//connect(AccountManager::instance(), &AccountManager::accountAdded,
// this, &Systray::slotChangeActivityModel);
UserModel::instance()->hideWindow();
}
Systray::~Systray()

View file

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

View file

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

View file

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

View file

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