Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* KIconThemes migration has been completed.
* The MeshMC News section is now displayed via KF6 Syndication.
* KFormat migration has been completed.
* KMainWindow migration has been completed.

## Removed

Expand Down
10 changes: 6 additions & 4 deletions launcher/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "ui/pages/global/CustomCommandsPage.h"
#include "ui/pages/global/AppearancePage.h"

#include "ui/WindowState.h"
#include "ui/themes/AppearanceManager.h"
#include "ui/themes/ThemedIcons.h"

Expand Down Expand Up @@ -1876,10 +1877,11 @@ MainWindow* Application::showMainWindow(bool minimized)
m_mainWindow->activateWindow();
} else {
m_mainWindow = new MainWindow();
m_mainWindow->restoreState(QByteArray::fromBase64(
APPLICATION->globalSettings()->mainWindowState().toUtf8()));
m_mainWindow->restoreGeometry(QByteArray::fromBase64(
APPLICATION->globalSettings()->mainWindowGeometry().toUtf8()));
WindowState::setup(
m_mainWindow, QStringLiteral("MainWindow"),
dynamic_cast<KConfigSettingsObject*>(m_settings.get()),
QStringLiteral("MainWindowGeometry"),
QStringLiteral("MainWindowState"));
if (minimized) {
m_mainWindow->showMinimized();
} else {
Expand Down
17 changes: 17 additions & 0 deletions launcher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,23 @@ set_property(TEST SettingsBinding_test APPEND PROPERTY ENVIRONMENT
"QT_QPA_PLATFORM=offscreen"
)

add_unit_test(WindowState
SOURCES ui/WindowState_test.cpp
LIBS MeshMC_logic
)
set_property(TEST WindowState_test APPEND PROPERTY ENVIRONMENT
"QT_QPA_PLATFORM=offscreen"
)

add_unit_test(NewsFeed
SOURCES news/NewsFeed_test.cpp
LIBS MeshMC_logic
)
# QTEST_MAIN makes a QApplication, which wants a display; none is needed.
set_property(TEST NewsFeed_test APPEND PROPERTY ENVIRONMENT
"QT_QPA_PLATFORM=offscreen"
)

add_unit_test(Translations
SOURCES translations/Translations_test.cpp
LIBS MeshMC_logic
Expand Down
12 changes: 0 additions & 12 deletions launcher/settings/GlobalSettings.kcfg
Original file line number Diff line number Diff line change
Expand Up @@ -242,18 +242,6 @@
<default>false</default>
</entry>
<!-- Window state and geometry -->
<entry name="MainWindowState" type="String">
<default></default>
</entry>
<entry name="MainWindowGeometry" type="String">
<default></default>
</entry>
<entry name="ConsoleWindowState" type="String">
<default></default>
</entry>
<entry name="ConsoleWindowGeometry" type="String">
<default></default>
</entry>
<entry name="SettingsGeometry" type="String">
<default></default>
</entry>
Expand Down
10 changes: 5 additions & 5 deletions launcher/settings/GlobalSettingsSetup_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class GlobalSettingsSetupTest : public QObject
void test_EverySettingIsThere()
{
Fixture f;
// 77 now: a setting that is added brings this up, one that is lost
// 73 now: a setting that is added brings this up, one that is lost
// would make a caller's get() return nothing.
QVERIFY(f.settings.allSettings().size() >= 77);
QVERIFY(f.settings.allSettings().size() >= 73);
for (const char* id :
{"InstanceDir", "JavaPath", "ProxyType", "MinMemAlloc",
"InstSortMode", "CurseForgeAPIKey", "PasteEEAPIKey",
Expand Down Expand Up @@ -163,18 +163,18 @@ class GlobalSettingsSetupTest : public QObject
auto* typed = typedGlobalSettings(&f.settings);
int changed = 0;
QVariant seen;
connect(f.settings.getSetting("MainWindowGeometry").get(),
connect(f.settings.getSetting("NewInstanceGeometry").get(),
&Setting::SettingChanged, this,
[&](const Setting&, const QVariant& value) {
++changed;
seen = value;
});
typed->setMainWindowGeometry(QStringLiteral("AAEC"));
typed->setNewInstanceGeometry(QStringLiteral("AAEC"));
typed->setSelectedInstance(QStringLiteral("abc"));
typed->save();
QCOMPARE(changed, 1);
QCOMPARE(seen.toString(), QString("AAEC"));
QCOMPARE(f.settings.get("MainWindowGeometry").toString(),
QCOMPARE(f.settings.get("NewInstanceGeometry").toString(),
QString("AAEC"));
QCOMPARE(f.settings.get("SelectedInstance").toString(),
QString("abc"));
Expand Down
2 changes: 2 additions & 0 deletions launcher/ui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ target_sources(MeshMC_logic PRIVATE
MacMenuBar.cpp
InstanceWindow.h
InstanceWindow.cpp
WindowState.h
WindowState.cpp
)

add_subdirectory(setupwizard)
Expand Down
27 changes: 12 additions & 15 deletions launcher/ui/InstanceWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include "InstanceWindow.h"
#include "settings/GlobalSettings.h"
#include "settings/KConfigSettingsObject.h"
#include "ui/WindowState.h"
#include "Application.h"

#include <QScrollBar>
Expand All @@ -39,7 +41,7 @@
#include <KLocalizedString>

InstanceWindow::InstanceWindow(InstancePtr instance, QWidget* parent)
: QMainWindow(parent), m_instance(instance)
: KMainWindow(parent), m_instance(instance)
{
setAttribute(Qt::WA_DeleteOnClose);

Expand Down Expand Up @@ -114,15 +116,12 @@ InstanceWindow::InstanceWindow(InstancePtr instance, QWidget* parent)
m_container->addButtons(horizontalLayout);
}

// restore window state
{
auto base64State =
APPLICATION->globalSettings()->consoleWindowState().toUtf8();
restoreState(QByteArray::fromBase64(base64State));
auto base64Geometry =
APPLICATION->globalSettings()->consoleWindowGeometry().toUtf8();
restoreGeometry(QByteArray::fromBase64(base64Geometry));
}
// restore window state; every console window has the one of the last
WindowState::setup(
this, QStringLiteral("ConsoleWindow"),
dynamic_cast<KConfigSettingsObject*>(APPLICATION->settings().get()),
QStringLiteral("ConsoleWindowGeometry"),
QStringLiteral("ConsoleWindowState"));

// set up instance and launch process recognition
{
Expand Down Expand Up @@ -210,11 +209,9 @@ void InstanceWindow::closeEvent(QCloseEvent* event)
return;
}

APPLICATION->globalSettings()->setConsoleWindowState(
QString::fromLatin1(saveState().toBase64()));
APPLICATION->globalSettings()->setConsoleWindowGeometry(
QString::fromLatin1(saveGeometry().toBase64()));
APPLICATION->globalSettings()->save();
// What KMainWindow::closeEvent() saves, without it quitting the
// application with the last window: Application decides that.
saveAutoSaveSettings();
emit isClosing();
event->accept();
}
Expand Down
4 changes: 2 additions & 2 deletions launcher/ui/InstanceWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#pragma once

#include <QMainWindow>
#include <KMainWindow>
#include <QSystemTrayIcon>

#include "LaunchController.h"
Expand All @@ -32,7 +32,7 @@

class QPushButton;
class PageContainer;
class InstanceWindow : public QMainWindow, public BasePageContainer
class InstanceWindow : public KMainWindow, public BasePageContainer
{
Q_OBJECT

Expand Down
26 changes: 14 additions & 12 deletions launcher/ui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,12 @@ void MainWindow::setupUi()
}

MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
: KMainWindow(parent), ui(new Ui::MainWindow)
{
// KMainWindow deletes itself when it is closed. This one is closed to be
// hidden, and Application keeps it for as long as the launcher runs.
setAttribute(Qt::WA_DeleteOnClose, false);

setupUi();

// OSX magic.
Expand Down Expand Up @@ -716,7 +720,7 @@ MainWindow::~MainWindow() {}

QMenu* MainWindow::createPopupMenu()
{
QMenu* filteredMenu = QMainWindow::createPopupMenu();
QMenu* filteredMenu = KMainWindow::createPopupMenu();
filteredMenu->removeAction(ui->mainToolBar->toggleViewAction());
filteredMenu->addAction(ui->actionLockToolbars);
return filteredMenu;
Expand Down Expand Up @@ -752,7 +756,7 @@ void MainWindow::showEvent(QShowEvent* event)
* so the user cannot hide it by hand and this cannot be overruling
* them. */
updateMenuBarVisibility();
QMainWindow::showEvent(event);
KMainWindow::showEvent(event);
}

void MainWindow::updateMenuBarVisibility()
Expand Down Expand Up @@ -780,7 +784,7 @@ void MainWindow::keyReleaseEvent(QKeyEvent* event)
ui->menuBar->setVisible(!ui->menuBar->isVisible());
return;
}
QMainWindow::keyReleaseEvent(event);
KMainWindow::keyReleaseEvent(event);
}
#endif

Expand Down Expand Up @@ -1192,7 +1196,7 @@ bool MainWindow::eventFilter(QObject* obj, QEvent* ev)
}
}
}
return QMainWindow::eventFilter(obj, ev);
return KMainWindow::eventFilter(obj, ev);
}

void MainWindow::updateNewsLabel()
Expand Down Expand Up @@ -1900,12 +1904,10 @@ void MainWindow::on_actionViewSelectedModsFolder_triggered()

void MainWindow::closeEvent(QCloseEvent* event)
{
// Save the window state and geometry.
APPLICATION->globalSettings()->setMainWindowState(
QString::fromLatin1(saveState().toBase64()));
APPLICATION->globalSettings()->setMainWindowGeometry(
QString::fromLatin1(saveGeometry().toBase64()));
APPLICATION->globalSettings()->save();
// What KMainWindow::closeEvent() saves, without what else it does: it
// quits the application with its last window, and that is Application's
// to decide (see on_windowClose()).
saveAutoSaveSettings();
event->accept();
emit isClosing();
}
Expand All @@ -1915,7 +1917,7 @@ void MainWindow::changeEvent(QEvent* event)
if (event->type() == QEvent::LanguageChange) {
retranslateUi();
}
QMainWindow::changeEvent(event);
KMainWindow::changeEvent(event);
}

void MainWindow::instanceActivated(QModelIndex index)
Expand Down
6 changes: 3 additions & 3 deletions launcher/ui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include <memory>

#include <QMainWindow>
#include <KMainWindow>
#include <QPointer>
#include <QProcess>
#include <QTimer>
Expand Down Expand Up @@ -52,7 +52,7 @@ class InstanceView;
class KonamiCode;
class InstanceTask;

class MainWindow : public QMainWindow
class MainWindow : public KMainWindow
{
Q_OBJECT

Expand Down Expand Up @@ -260,7 +260,7 @@ class MainWindow : public QMainWindow
/*!
* Toggles whether the toolbars can be dragged between dock areas.
* Persisted via the "ToolbarsLocked" setting; the resulting layout itself
* is persisted by QMainWindow::saveState() in closeEvent().
* is persisted by KMainWindow, with the rest of the window state, in closeEvent().
*/
void lockToolbars(bool state);

Expand Down
77 changes: 77 additions & 0 deletions launcher/ui/WindowState.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* SPDX-FileCopyrightText: 2026 Project Tick
* SPDX-FileContributor: Project Tick
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (C) 2026 Project Tick
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


#include "WindowState.h"

#include "settings/KConfigSettingsObject.h"

#include <QByteArray>

#include <KConfig>
#include <KConfigGroup>
#include <KMainWindow>

namespace WindowState
{
void setup(KMainWindow* window, const QString& group,
KConfigSettingsObject* legacy, const QString& geometryKey,
const QString& stateKey)
{
// Window size and state go to a group of their own: KMainWindow uses
// "MainWindow" for all of its windows unless it is told otherwise,
// which would make the console window start like the main window.
// Has to come first.
window->setStateConfigGroup(group);

// Whether the window saved anything of its own, which is asked before
// setAutoSaveSettings() makes the group.
const bool saved = window->stateConfigGroup().exists();
window->setAutoSaveSettings(group, true);

QByteArray legacyGeometry;
QByteArray legacyState;
if (legacy) {
KConfigGroup top = legacy->config()->group(QString());
legacyGeometry = QByteArray::fromBase64(
top.readEntry(geometryKey, QString()).toUtf8());
legacyState = QByteArray::fromBase64(
top.readEntry(stateKey, QString()).toUtf8());

if (top.hasKey(geometryKey) || top.hasKey(stateKey)) {
top.deleteEntry(geometryKey);
top.deleteEntry(stateKey);
legacy->config()->sync();
}
}

if (saved) {
window->applyMainWindowSettings(window->autoSaveConfigGroup());
return;
}

// The state first, then the geometry, as it always was.
if (!legacyState.isEmpty()) {
window->restoreState(legacyState);
}
if (!legacyGeometry.isEmpty()) {
window->restoreGeometry(legacyGeometry);
}
}
} // namespace WindowState
Loading
Loading