Extract code for obtaining a window from the QML engine into a function
This commit is contained in:
committed by
Tobias Fella
parent
c379a7fa27
commit
4cf5b516d0
@@ -589,7 +589,7 @@ void Controller::setActiveConnection(Connection *connection)
|
|||||||
Q_EMIT activeConnectionChanged();
|
Q_EMIT activeConnectionChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::restoreWindowGeometry(QQuickWindow *window)
|
void Controller::restoreWindowGeometry(QWindow *window)
|
||||||
{
|
{
|
||||||
KConfig dataResource("data", KConfig::SimpleConfig, QStandardPaths::AppDataLocation);
|
KConfig dataResource("data", KConfig::SimpleConfig, QStandardPaths::AppDataLocation);
|
||||||
KConfigGroup windowGroup(&dataResource, "Window");
|
KConfigGroup windowGroup(&dataResource, "Window");
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class QKeySequences;
|
|||||||
class NeoChatRoom;
|
class NeoChatRoom;
|
||||||
class NeoChatUser;
|
class NeoChatUser;
|
||||||
class TrayIcon;
|
class TrayIcon;
|
||||||
class QQuickWindow;
|
class QWindow;
|
||||||
class QQuickTextDocument;
|
class QQuickTextDocument;
|
||||||
|
|
||||||
namespace QKeychain
|
namespace QKeychain
|
||||||
@@ -146,7 +146,7 @@ public Q_SLOTS:
|
|||||||
void logout(Quotient::Connection *conn, bool serverSideLogout);
|
void logout(Quotient::Connection *conn, bool serverSideLogout);
|
||||||
void changeAvatar(Quotient::Connection *conn, const QUrl &localFile);
|
void changeAvatar(Quotient::Connection *conn, const QUrl &localFile);
|
||||||
static void markAllMessagesAsRead(Quotient::Connection *conn);
|
static void markAllMessagesAsRead(Quotient::Connection *conn);
|
||||||
void restoreWindowGeometry(QQuickWindow *);
|
void restoreWindowGeometry(QWindow *);
|
||||||
void saveWindowGeometry(QQuickWindow *);
|
void saveWindowGeometry(QQuickWindow *);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
35
src/main.cpp
35
src/main.cpp
@@ -110,6 +110,14 @@ static void raiseWindow(QWindow *window)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static QWindow *windowFromEngine(QQmlApplicationEngine *engine)
|
||||||
|
{
|
||||||
|
const auto rootObjects = engine->rootObjects();
|
||||||
|
auto *window = qobject_cast<QQuickWindow *>(rootObjects.first());
|
||||||
|
Q_ASSERT(window);
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef Q_OS_ANDROID
|
#ifdef Q_OS_ANDROID
|
||||||
Q_DECL_EXPORT
|
Q_DECL_EXPORT
|
||||||
#endif
|
#endif
|
||||||
@@ -283,15 +291,9 @@ int main(int argc, char *argv[])
|
|||||||
Q_UNUSED(workingDirectory);
|
Q_UNUSED(workingDirectory);
|
||||||
|
|
||||||
// Raise windows
|
// Raise windows
|
||||||
const auto rootObjects = engine.rootObjects();
|
QWindow *window = windowFromEngine(&engine);
|
||||||
for (auto obj : rootObjects) {
|
window->show();
|
||||||
auto view = qobject_cast<QQuickWindow *>(obj);
|
raiseWindow(window);
|
||||||
if (view) {
|
|
||||||
view->show();
|
|
||||||
raiseWindow(view);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Open matrix uri
|
// Open matrix uri
|
||||||
if (arguments.isEmpty()) {
|
if (arguments.isEmpty()) {
|
||||||
@@ -304,15 +306,12 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
const auto rootObjects = engine.rootObjects();
|
|
||||||
for (auto obj : rootObjects) {
|
QWindow *window = windowFromEngine(&engine);
|
||||||
auto view = qobject_cast<QQuickWindow *>(obj);
|
|
||||||
if (view) {
|
if (window->isVisible()) {
|
||||||
if (view->isVisible()) {
|
Controller::instance().restoreWindowGeometry(window);
|
||||||
Controller::instance().restoreWindowGeometry(view);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user