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();
|
||||
}
|
||||
|
||||
void Controller::restoreWindowGeometry(QQuickWindow *window)
|
||||
void Controller::restoreWindowGeometry(QWindow *window)
|
||||
{
|
||||
KConfig dataResource("data", KConfig::SimpleConfig, QStandardPaths::AppDataLocation);
|
||||
KConfigGroup windowGroup(&dataResource, "Window");
|
||||
|
||||
@@ -20,7 +20,7 @@ class QKeySequences;
|
||||
class NeoChatRoom;
|
||||
class NeoChatUser;
|
||||
class TrayIcon;
|
||||
class QQuickWindow;
|
||||
class QWindow;
|
||||
class QQuickTextDocument;
|
||||
|
||||
namespace QKeychain
|
||||
@@ -146,7 +146,7 @@ public Q_SLOTS:
|
||||
void logout(Quotient::Connection *conn, bool serverSideLogout);
|
||||
void changeAvatar(Quotient::Connection *conn, const QUrl &localFile);
|
||||
static void markAllMessagesAsRead(Quotient::Connection *conn);
|
||||
void restoreWindowGeometry(QQuickWindow *);
|
||||
void restoreWindowGeometry(QWindow *);
|
||||
void saveWindowGeometry(QQuickWindow *);
|
||||
};
|
||||
|
||||
|
||||
35
src/main.cpp
35
src/main.cpp
@@ -110,6 +110,14 @@ static void raiseWindow(QWindow *window)
|
||||
}
|
||||
#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
|
||||
Q_DECL_EXPORT
|
||||
#endif
|
||||
@@ -283,15 +291,9 @@ int main(int argc, char *argv[])
|
||||
Q_UNUSED(workingDirectory);
|
||||
|
||||
// Raise windows
|
||||
const auto rootObjects = engine.rootObjects();
|
||||
for (auto obj : rootObjects) {
|
||||
auto view = qobject_cast<QQuickWindow *>(obj);
|
||||
if (view) {
|
||||
view->show();
|
||||
raiseWindow(view);
|
||||
return;
|
||||
}
|
||||
}
|
||||
QWindow *window = windowFromEngine(&engine);
|
||||
window->show();
|
||||
raiseWindow(window);
|
||||
|
||||
// Open matrix uri
|
||||
if (arguments.isEmpty()) {
|
||||
@@ -304,15 +306,12 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
});
|
||||
#endif
|
||||
const auto rootObjects = engine.rootObjects();
|
||||
for (auto obj : rootObjects) {
|
||||
auto view = qobject_cast<QQuickWindow *>(obj);
|
||||
if (view) {
|
||||
if (view->isVisible()) {
|
||||
Controller::instance().restoreWindowGeometry(view);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
QWindow *window = windowFromEngine(&engine);
|
||||
|
||||
if (window->isVisible()) {
|
||||
Controller::instance().restoreWindowGeometry(window);
|
||||
}
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user