Skip to content

Commit

Permalink
Fix SplitView state carrying over to new projects
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchcurtis committed Jun 22, 2019
1 parent a47ed40 commit 0fd7457
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
8 changes: 7 additions & 1 deletion app/qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ ApplicationWindow {
project.uiState.value("mainSplitViewState")))
panelSplitView.restoreState(project.uiState.base64ToBinary(
project.uiState.value("panelSplitViewState")))
} else {
// We should still restore the default sizes for all other cases, though.
// We only need to restore panelSplitView's preferredWidth, as mainSplitView fills.
panelSplitView.SplitView.preferredWidth = panelSplitView.defaultPreferredWidth
}
}
}
Expand Down Expand Up @@ -224,8 +228,10 @@ ApplicationWindow {
implicitHeight: 4
}

readonly property int defaultPreferredWidth: 240

SplitView.minimumWidth: 200
SplitView.preferredWidth: 240
SplitView.preferredWidth: defaultPreferredWidth
SplitView.maximumWidth: window.width / 3

Ui.ColourPanel {
Expand Down
32 changes: 30 additions & 2 deletions tests/auto/tst_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ private Q_SLOTS:
void recentFiles();
void newProjectSizeFromClipboard_data();
void newProjectSizeFromClipboard();
void splitViewStateAcrossProjects();

// Tools, misc.
void animationPlayback_data();
Expand Down Expand Up @@ -246,7 +247,6 @@ void tst_App::repeatedNewProject()
{
QFETCH(ProjectTypeVector, projectTypes);

int i = -1;
foreach (auto projectType, projectTypes) {
// Shouldn't crash on repeated opening of new projects.
QVERIFY2(createNewProject(projectType), failureMessage);
Expand Down Expand Up @@ -770,6 +770,35 @@ void tst_App::newProjectSizeFromClipboard()
QTRY_VERIFY(!newImageProjectPopup->property("visible").toBool());
}

void tst_App::splitViewStateAcrossProjects()
{
QVERIFY2(createNewLayeredImageProject(), failureMessage);

// Make the panel split item larger.
QPointer<QQuickItem> mainSplitView = window->findChild<QQuickItem*>("mainSplitView");
QVERIFY(mainSplitView);
QPointer<QQuickItem> panelSplitView = window->findChild<QQuickItem*>("panelSplitView");
QVERIFY(panelSplitView);
const qreal defaultPanelSplitItemWidth = panelSplitView->width();
QPointer<QQuickItem> mainSplitViewHandle = findSplitViewHandle("mainSplitView", 0);
QVERIFY(mainSplitViewHandle);
const QPoint mainSplitViewHandleCentreAfterMoving = QPoint(
mainSplitView->width() / 2, mainSplitView->height() / 2);
QVERIFY2(dragSplitViewHandle("mainSplitView", 0, mainSplitViewHandleCentreAfterMoving), failureMessage);
const qreal resizedPanelSplitItemWidth = panelSplitView->width();
QVERIFY(resizedPanelSplitItemWidth > defaultPanelSplitItemWidth);

// Save the project with the new split size.
QVERIFY(layeredImageProject->canSave());
const QUrl saveUrl = QUrl::fromLocalFile(tempProjectDir->path() + QLatin1String("/splitViewStateAcrossProjects.slp"));
layeredImageProject->saveAs(saveUrl);
QVERIFY(!layeredImageProject->hasUnsavedChanges());

// Create a new project. It should have the default panel split item size.
QVERIFY2(createNewLayeredImageProject(), failureMessage);
QCOMPARE(panelSplitView->width(), defaultPanelSplitItemWidth);
}

void tst_App::animationPlayback_data()
{
addImageProjectTypes();
Expand Down Expand Up @@ -888,7 +917,6 @@ void tst_App::animationPlayback()
// Save.
const QUrl saveUrl = QUrl::fromLocalFile(tempProjectDir->path() + QLatin1String("/animationStuffSaved.slp"));
layeredImageProject->saveAs(saveUrl);
QVERIFY_NO_CREATION_ERRORS_OCCURRED();
QVERIFY(!layeredImageProject->hasUnsavedChanges());

// Close.
Expand Down
7 changes: 0 additions & 7 deletions tests/shared/testhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1995,13 +1995,6 @@ bool TestHelper::updateVariables(bool isNewProject, Project::Type projectType)
return false;

if (isNewProject) {
// If we're not loading a saved project (where we'd want to use the saved split sizes),
// return the SplitView back to roughly its original size.
// It doesn't matter if it's not perfect, it's just important that it's not already
// at its max width so that the tests can resize it.
if (!dragSplitViewHandle("mainSplitView", 0, QPoint(window->width() - 240, window->height() / 2)))
return false;

// Restore the colour panel's contentY to the default.
QQuickItem *colourPanelFlickable = window->findChild<QQuickItem*>("colourPanelFlickable");
VERIFY(colourPanelFlickable);
Expand Down

0 comments on commit 0fd7457

Please sign in to comment.