View › Grid Settings…: spacing, subdivisions, colour, style and opacity, kept across launches (13.5b)
This commit is contained in:
1 parent
3992bc913d
commit
93a4c62b8f
29 files changed
+1353
-46
No files matched your search
@@ -30,7 +30,7 @@ void CompositorMenusTests::everyEntryHasSwiftsShortcutWithCtrlForCommand()
|
||||
{"newCanvas", "Ctrl+N"}, {"openProject", "Ctrl+O"}, {"importImages", ""}, {"save", "Ctrl+S"}, {"saveAs", "Ctrl+Shift+S"},
|
||||
{"exportPNG", "Ctrl+Shift+E"}, {"exportJPEG", "Ctrl+Alt+Shift+S"},
|
||||
{"closeProject", "Ctrl+W"}, {"undo", "Ctrl+Z"}, {"redo", "Ctrl+Shift+Z"}, {"fit", "Ctrl+0"}, {"actualPixels", "Ctrl+1"},
|
||||
{"zoomIn", "Ctrl+="}, {"zoomOut", "Ctrl+-"}, {"pixelGrid", ""}, {"snap", ""}, {"showGrid", "Ctrl+'"}, {"showGuides", "Ctrl+;"}, {"showRulers", "Ctrl+R"}, {"snapEnabled", "Ctrl+Shift+;"}, {"snapToGuides", ""}, {"snapToGrid", ""}, {"snapToLayers", ""}, {"snapToDocumentBounds", ""}, {"lockGuides", "Ctrl+Alt+;"}, {"clearGuides", ""}, {"transformControls", "Ctrl+H"}, {"transformLayer", "Ctrl+T"},
|
||||
{"zoomIn", "Ctrl+="}, {"zoomOut", "Ctrl+-"}, {"pixelGrid", ""}, {"snap", ""}, {"showGrid", "Ctrl+'"}, {"showGuides", "Ctrl+;"}, {"gridSettings", ""}, {"showRulers", "Ctrl+R"}, {"snapEnabled", "Ctrl+Shift+;"}, {"snapToGuides", ""}, {"snapToGrid", ""}, {"snapToLayers", ""}, {"snapToDocumentBounds", ""}, {"lockGuides", "Ctrl+Alt+;"}, {"clearGuides", ""}, {"transformControls", "Ctrl+H"}, {"transformLayer", "Ctrl+T"},
|
||||
{"layerViaCopy", "Ctrl+J"}, {"cut", "Ctrl+X"}, {"copy", "Ctrl+C"}, {"copyMerged", "Ctrl+Shift+C"}, {"paste", "Ctrl+V"}, {"keyboardShortcuts", ""}, {"fillForeground", "Alt+Backspace"}, {"fillBackground", "Ctrl+Backspace"}, {"clearSelectionPixels", ""}, {"contentAwareFill", "Shift+Backspace"}, {"clippingMask", "Ctrl+Alt+G"}, {"groupLayers", "Ctrl+G"},
|
||||
{"moveOutOfFolder", ""}, {"newBlankLayer", "Ctrl+Shift+N"}, {"renameLayer", ""}, {"layerVisibility", ""}, {"moveLayerUp", "Ctrl+]"}, {"moveLayerDown", "Ctrl+["},
|
||||
{"mergeLayers", "Ctrl+E"}, {"flipHorizontal", ""}, {"flipVertical", ""}, {"deleteLayer", ""},
|
||||
@@ -52,7 +52,7 @@ void CompositorMenusTests::everyEntryHasSwiftsShortcutWithCtrlForCommand()
|
||||
QCOMPARE(titles, (QStringList{"&File", "&Edit", "&View", "&Select", "&Image", "Fil&ter", "&Layer"}));
|
||||
QCOMPARE(menus[0]->actions().size(), 12);
|
||||
QCOMPARE(menus[1]->actions().size(), 13);
|
||||
QCOMPARE(menus[2]->actions().size(), 16);
|
||||
QCOMPARE(menus[2]->actions().size(), 17);
|
||||
QCOMPARE(menus[3]->actions().size(), 11);
|
||||
// Swift 1.3.4's Color Range… follows Subject.
|
||||
const QList<QAction *> select = menus[3]->actions();
|
||||
|
||||
@@ -0,0 +1,319 @@
|
||||
#include "UI/ColorPickerSheet+Dialog.h"
|
||||
#include "UI/ColorPickerSheet.h"
|
||||
#include "UI/GridSettingsSheet.h"
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QSlider>
|
||||
#include <QVBoxLayout>
|
||||
#include <QtTest>
|
||||
|
||||
// Swift 1.3.5's GridSettingsSheet: the controls, previews and answers.
|
||||
class GridSettingsSheetTests : public QObject {
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void theSheetLaysOutAsSwifts();
|
||||
void eachChangePreviewsTheGrid();
|
||||
void aPickedColourBecomesCustom();
|
||||
void restoreDefaultsOkAndCancel();
|
||||
void theRowsHoldSwiftsControls();
|
||||
void aSliderOrScrubReplacesTyping();
|
||||
};
|
||||
|
||||
namespace {
|
||||
// Drags a scrubbable title `points` to the right.
|
||||
void scrub(QLabel &title, int points)
|
||||
{
|
||||
QTest::mousePress(&title, Qt::LeftButton, Qt::NoModifier, QPoint(2, 2));
|
||||
QMouseEvent move(QEvent::MouseMove, QPointF(2 + points, 2), title.mapToGlobal(QPointF(2 + points, 2)), Qt::NoButton, Qt::LeftButton, Qt::NoModifier);
|
||||
QApplication::sendEvent(&title, &move);
|
||||
QTest::mouseRelease(&title, Qt::LeftButton, Qt::NoModifier, QPoint(2 + points, 2));
|
||||
}
|
||||
|
||||
struct Sheet {
|
||||
EditorSession session;
|
||||
std::vector<GridSettingsSheet::Settings> previews;
|
||||
std::optional<std::optional<GridSettingsSheet::Settings>> answer;
|
||||
std::unique_ptr<GridSettingsSheet> sheet;
|
||||
explicit Sheet(LayoutGrid grid = LayoutGrid(), GridAppearance appearance = GridAppearance())
|
||||
: sheet(std::make_unique<GridSettingsSheet>(
|
||||
session, grid, appearance, [this](const GridSettingsSheet::Settings &settings) { previews.push_back(settings); },
|
||||
[this](std::optional<GridSettingsSheet::Settings> settings) { answer = settings; }))
|
||||
{
|
||||
sheet->show();
|
||||
if (!QTest::qWaitForWindowActive(sheet.get()))
|
||||
throw std::runtime_error("the sheet never became active");
|
||||
}
|
||||
template <typename Widget> Widget &find(const char *name)
|
||||
{
|
||||
Widget *found = sheet->findChild<Widget *>(QString::fromLatin1(name));
|
||||
if (!found)
|
||||
throw std::runtime_error(std::string("no widget named ") + name);
|
||||
return *found;
|
||||
}
|
||||
// Typed, then Return: the field commits.
|
||||
void type(const char *name, const QString &text)
|
||||
{
|
||||
auto &field = find<PickerField>(name);
|
||||
field.setFocus();
|
||||
field.selectAll();
|
||||
QTest::keyClicks(&field, text);
|
||||
QTest::keyClick(&field, Qt::Key_Return);
|
||||
}
|
||||
QString note() { return find<QLabel>("gridNote").text(); }
|
||||
const GridSettingsSheet::Settings &last() const { return previews.back(); }
|
||||
};
|
||||
}
|
||||
|
||||
void GridSettingsSheetTests::theSheetLaysOutAsSwifts()
|
||||
{
|
||||
Sheet shown;
|
||||
auto *column = qobject_cast<QVBoxLayout *>(shown.sheet->layout());
|
||||
QVERIFY(column && shown.sheet->width() == 360 && column->spacing() == 18 && column->contentsMargins() == QMargins(24, 24, 24, 24));
|
||||
auto *heading = qobject_cast<QLabel *>(column->itemAt(0)->widget());
|
||||
QVERIFY(heading->text() == "Grid" && heading->font().pixelSize() == 17 && heading->font().bold());
|
||||
// Titles 110 wide, each naming its control.
|
||||
const auto rowOf = [column](int index) { return qobject_cast<QHBoxLayout *>(column->itemAt(index)->layout()); };
|
||||
const QStringList titles{"Color", "Style", "Opacity"};
|
||||
for (int index = 0; index < 3; ++index) {
|
||||
auto *title = qobject_cast<QLabel *>(rowOf(index + 1)->itemAt(0)->widget());
|
||||
QVERIFY(title->text() == titles[index] && title->width() == 110 && title->buddy());
|
||||
}
|
||||
auto &preset = shown.find<QComboBox>("gridPreset");
|
||||
QCOMPARE(preset.count(), 10);
|
||||
QVERIFY(preset.itemText(0) == "Light Gray" && preset.itemText(9) == "Custom" && preset.currentText() == "Light Gray");
|
||||
auto &swatch = shown.find<DialogColorSwatch>("gridColor");
|
||||
QVERIFY(swatch.accessibleName() == "Grid Color" && swatch.toolTip() == "Choose a custom grid color" && rowOf(1)->itemAt(2)->widget() == &swatch);
|
||||
auto &style = shown.find<QComboBox>("gridStyle");
|
||||
QVERIFY(style.count() == 3 && style.itemText(1) == "Dashed Lines" && style.currentText() == "Lines");
|
||||
auto &opacity = shown.find<PickerField>("gridOpacity");
|
||||
QVERIFY(opacity.text() == "45" && opacity.width() == 48 && opacity.alignment() == Qt::AlignRight && opacity.accessibleName() == "Opacity");
|
||||
QVERIFY(shown.find<QSlider>("gridOpacitySlider").minimum() == 1 && shown.find<QSlider>("gridOpacitySlider").maximum() == 100);
|
||||
QCOMPARE(shown.find<QSlider>("gridOpacitySlider").value(), 45);
|
||||
auto *rule = qobject_cast<QFrame *>(column->itemAt(4)->widget());
|
||||
QVERIFY(rule && rule->frameShape() == QFrame::HLine);
|
||||
QVERIFY(qobject_cast<QLabel *>(rowOf(5)->itemAt(0)->widget())->text() == "Gridline every" && shown.find<PickerField>("gridSpacing").text() == "64");
|
||||
QCOMPARE(qobject_cast<QLabel *>(rowOf(5)->itemAt(2)->widget())->text(), QString("pixels"));
|
||||
QVERIFY(qobject_cast<QLabel *>(rowOf(6)->itemAt(0)->widget())->text() == "Subdivisions" && shown.find<PickerField>("gridSubdivisions").text() == "8");
|
||||
QCOMPARE(shown.note(), QString("A subdivision every 8 pixels."));
|
||||
QCOMPARE(shown.find<QLabel>("gridNote").foregroundRole(), QPalette::PlaceholderText);
|
||||
auto *buttons = rowOf(8);
|
||||
QVERIFY(qobject_cast<QPushButton *>(buttons->itemAt(0)->widget())->text() == "Cancel" && qobject_cast<QPushButton *>(buttons->itemAt(1)->widget())->text() == "Restore Defaults");
|
||||
QVERIFY(buttons->itemAt(2)->spacerItem() && shown.find<QPushButton>("gridOK").isDefault());
|
||||
QVERIFY(shown.previews.empty());
|
||||
}
|
||||
|
||||
void GridSettingsSheetTests::eachChangePreviewsTheGrid()
|
||||
{
|
||||
Sheet shown;
|
||||
auto &preset = shown.find<QComboBox>("gridPreset");
|
||||
preset.setCurrentIndex(7);
|
||||
emit preset.activated(7);
|
||||
QVERIFY(shown.previews.size() == 1 && shown.last().second.preset == GridAppearance::Preset::cyan && shown.last().first == LayoutGrid());
|
||||
shown.find<QComboBox>("gridStyle").setCurrentIndex(2);
|
||||
emit shown.find<QComboBox>("gridStyle").activated(2);
|
||||
QCOMPARE(shown.last().second.style, GridAppearance::Style::dots);
|
||||
// Opacity: the slider, the field (clamped), its arrows.
|
||||
shown.find<QSlider>("gridOpacitySlider").setValue(80);
|
||||
QCOMPARE(shown.last().second.opacity, 80);
|
||||
shown.type("gridOpacity", "150");
|
||||
QVERIFY(shown.last().second.opacity == 100 && shown.find<PickerField>("gridOpacity").text() == "100");
|
||||
QTest::keyClick(&shown.find<PickerField>("gridOpacity"), Qt::Key_Down, Qt::ShiftModifier);
|
||||
QCOMPARE(shown.last().second.opacity, 90);
|
||||
// The grid previews only while valid; the note says why.
|
||||
shown.type("gridSpacing", "100");
|
||||
QVERIFY(shown.last().first == LayoutGrid(100, 8));
|
||||
QCOMPARE(shown.note(), QString("A subdivision every 12.5 pixels."));
|
||||
shown.type("gridSubdivisions", "3");
|
||||
QCOMPARE(shown.note(), QString("A subdivision every 33.33 pixels."));
|
||||
const size_t seen = shown.previews.size();
|
||||
shown.type("gridSpacing", "1");
|
||||
QVERIFY(shown.previews.size() == seen && !shown.find<QPushButton>("gridOK").isEnabled());
|
||||
QCOMPARE(shown.note(), QString("Use gridlines every 2–4,096 pixels and 1–64 subdivisions, no more than the pixels between gridlines."));
|
||||
QCOMPARE(shown.find<QLabel>("gridNote").foregroundRole(), QPalette::BrightText);
|
||||
shown.type("gridSpacing", "2");
|
||||
QCOMPARE(shown.note().left(5), QString("Use g"));
|
||||
shown.type("gridSubdivisions", "2");
|
||||
QVERIFY(shown.last().first == LayoutGrid(2, 2) && shown.find<QPushButton>("gridOK").isEnabled());
|
||||
// Text that is no number goes back.
|
||||
shown.type("gridSpacing", "lots");
|
||||
QCOMPARE(shown.find<PickerField>("gridSpacing").text(), QString("2"));
|
||||
// The titles scrub: opacity a point per half.
|
||||
auto &title = *qobject_cast<QLabel *>(qobject_cast<QHBoxLayout *>(shown.sheet->layout()->itemAt(3)->layout())->itemAt(0)->widget());
|
||||
QTest::mousePress(&title, Qt::LeftButton, Qt::NoModifier, QPoint(2, 2));
|
||||
QMouseEvent move(QEvent::MouseMove, QPointF(12, 2), title.mapToGlobal(QPointF(12, 2)), Qt::NoButton, Qt::LeftButton, Qt::NoModifier);
|
||||
QApplication::sendEvent(&title, &move);
|
||||
QTest::mouseRelease(&title, Qt::LeftButton, Qt::NoModifier, QPoint(12, 2));
|
||||
QCOMPARE(shown.last().second.opacity, 95);
|
||||
}
|
||||
|
||||
void GridSettingsSheetTests::aPickedColourBecomesCustom()
|
||||
{
|
||||
GridAppearance cyan;
|
||||
cyan.preset = GridAppearance::Preset::cyan;
|
||||
Sheet shown(LayoutGrid(), cyan);
|
||||
auto &swatch = shown.find<DialogColorSwatch>("gridColor");
|
||||
swatch.click();
|
||||
QCOMPARE(shown.session.colorPicker().value().target.title(), QString("Color Picker (Grid Color)"));
|
||||
QCOMPARE(shown.session.colorPicker().value().original, (PaletteColor{0, 1, 1}));
|
||||
// Its opening colour keeps the preset; another makes Custom.
|
||||
shown.session.previewDialogColor();
|
||||
QVERIFY(shown.previews.empty());
|
||||
const PaletteColor teal{0, 128 / 255.0, 128 / 255.0};
|
||||
shown.session.setColorPickerHSB(PickerHSB(teal));
|
||||
QVERIFY(shown.last().second.preset == GridAppearance::Preset::custom && shown.last().second.customColor == teal);
|
||||
QCOMPARE(shown.find<QComboBox>("gridPreset").currentText(), QString("Custom"));
|
||||
// Picking the first preset's colour again returns to it.
|
||||
shown.session.setColorPickerHSB(PickerHSB(PaletteColor{0, 1, 1}));
|
||||
QVERIFY(shown.last().second.preset == GridAppearance::Preset::cyan && shown.last().second.customColor == teal);
|
||||
shown.session.closeColorPicker(false);
|
||||
// Beyond Swift: Light Gray's 0.7, no byte, still stays.
|
||||
auto &preset = shown.find<QComboBox>("gridPreset");
|
||||
preset.setCurrentIndex(0);
|
||||
emit preset.activated(0);
|
||||
swatch.click();
|
||||
shown.session.closeColorPicker(true);
|
||||
QCOMPARE(shown.last().second.preset, GridAppearance::Preset::lightGray);
|
||||
swatch.click();
|
||||
shown.session.setColorPickerHSB(PickerHSB(teal));
|
||||
shown.session.setColorPickerHSB(PickerHSB(PaletteColor{0.7, 0.7, 0.7}));
|
||||
QCOMPARE(shown.last().second.preset, GridAppearance::Preset::lightGray);
|
||||
shown.session.closeColorPicker(false);
|
||||
// The picker's Cancel hands back 0.7 itself: Light Gray stays.
|
||||
const size_t seen = shown.previews.size();
|
||||
swatch.click();
|
||||
shown.session.closeColorPicker(false);
|
||||
QCOMPARE(shown.previews.size(), seen);
|
||||
swatch.click();
|
||||
shown.session.setColorPickerHSB(PickerHSB(teal));
|
||||
shown.session.closeColorPicker(false);
|
||||
QCOMPARE(shown.last().second.preset, GridAppearance::Preset::lightGray);
|
||||
// A preset chosen from the menu ends a pick.
|
||||
swatch.click();
|
||||
shown.session.setColorPickerHSB(PickerHSB(teal));
|
||||
preset.setCurrentIndex(8);
|
||||
emit preset.activated(8);
|
||||
shown.session.setColorPickerHSB(PickerHSB(PaletteColor{0.7, 0.7, 0.7}));
|
||||
QVERIFY(shown.last().second.preset == GridAppearance::Preset::custom && shown.last().second.customColor == (PaletteColor{0.7, 0.7, 0.7}).quantized());
|
||||
shown.session.closeColorPicker(false);
|
||||
// Restore Defaults ends a pick too.
|
||||
preset.setCurrentIndex(7);
|
||||
emit preset.activated(7);
|
||||
swatch.click();
|
||||
shown.session.setColorPickerHSB(PickerHSB(teal));
|
||||
shown.find<QPushButton>("gridDefaults").click();
|
||||
shown.session.setColorPickerHSB(PickerHSB(PaletteColor{0, 1, 1}));
|
||||
QVERIFY(shown.last().second.preset == GridAppearance::Preset::custom && shown.last().second.customColor == (PaletteColor{0, 1, 1}));
|
||||
// A changed preset repaints the swatch.
|
||||
shown.session.closeColorPicker(false);
|
||||
QCoreApplication::processEvents();
|
||||
int paints = 0;
|
||||
struct Counter : QObject {
|
||||
int &count;
|
||||
explicit Counter(int &count) : count(count) {}
|
||||
bool eventFilter(QObject *, QEvent *event) override
|
||||
{
|
||||
count += event->type() == QEvent::Paint;
|
||||
return false;
|
||||
}
|
||||
} counter(paints);
|
||||
swatch.installEventFilter(&counter);
|
||||
preset.setCurrentIndex(5);
|
||||
emit preset.activated(5);
|
||||
QTRY_VERIFY(paints > 0);
|
||||
swatch.removeEventFilter(&counter);
|
||||
shown.sheet.reset();
|
||||
QVERIFY(!shown.session.colorPicker());
|
||||
}
|
||||
|
||||
void GridSettingsSheetTests::restoreDefaultsOkAndCancel()
|
||||
{
|
||||
GridAppearance look{GridAppearance::Preset::custom, PaletteColor{0, 0.5, 0.5}, GridAppearance::Style::dots, 70};
|
||||
Sheet shown(LayoutGrid(100, 4), look);
|
||||
QVERIFY(shown.find<QComboBox>("gridPreset").currentText() == "Custom" && shown.find<PickerField>("gridSpacing").text() == "100");
|
||||
QVERIFY(shown.find<QComboBox>("gridStyle").currentText() == "Dots" && shown.find<PickerField>("gridOpacity").text() == "70");
|
||||
shown.find<QPushButton>("gridDefaults").click();
|
||||
const GridSettingsSheet::Settings restored = shown.last();
|
||||
QVERIFY(restored.first == LayoutGrid() && restored.second.preset == GridAppearance::Preset::lightGray && restored.second.style == GridAppearance::Style::lines);
|
||||
QVERIFY(restored.second.opacity == 45 && restored.second.customColor == look.customColor);
|
||||
QVERIFY(shown.find<PickerField>("gridSpacing").text() == "64" && shown.find<QComboBox>("gridStyle").currentText() == "Lines");
|
||||
// OK closes an open picker and answers what is shown.
|
||||
shown.find<DialogColorSwatch>("gridColor").click();
|
||||
shown.find<QPushButton>("gridOK").click();
|
||||
QVERIFY(!shown.session.colorPicker() && shown.answer.value().value() == restored);
|
||||
Sheet cancelled;
|
||||
cancelled.find<DialogColorSwatch>("gridColor").click();
|
||||
cancelled.find<QPushButton>("gridCancel").click();
|
||||
QVERIFY(!cancelled.session.colorPicker() && !cancelled.answer.value());
|
||||
}
|
||||
|
||||
void GridSettingsSheetTests::theRowsHoldSwiftsControls()
|
||||
{
|
||||
Sheet shown;
|
||||
auto *column = qobject_cast<QVBoxLayout *>(shown.sheet->layout());
|
||||
const auto rowOf = [column](int index) { return qobject_cast<QHBoxLayout *>(column->itemAt(index)->layout()); };
|
||||
for (const int index : {1, 2, 3, 5, 6})
|
||||
QCOMPARE(rowOf(index)->spacing(), 8);
|
||||
// Colour and Style: title, menu (and swatch), then room.
|
||||
QVERIFY(rowOf(1)->count() == 4 && rowOf(1)->itemAt(3)->spacerItem());
|
||||
QVERIFY(rowOf(2)->count() == 3 && rowOf(2)->itemAt(1)->widget() == &shown.find<QComboBox>("gridStyle") && rowOf(2)->itemAt(2)->spacerItem());
|
||||
// Opacity: the slider stretches; % sits two after.
|
||||
QVERIFY(rowOf(3)->itemAt(1)->widget() == &shown.find<QSlider>("gridOpacitySlider") && rowOf(3)->stretch(1) == 1);
|
||||
auto *suffixed = qobject_cast<QHBoxLayout *>(rowOf(3)->itemAt(2)->layout());
|
||||
QVERIFY(suffixed && suffixed->spacing() == 2 && suffixed->itemAt(0)->widget() == &shown.find<PickerField>("gridOpacity"));
|
||||
QCOMPARE(qobject_cast<QLabel *>(suffixed->itemAt(1)->widget())->text(), QString("%"));
|
||||
QCOMPARE(qobject_cast<QFrame *>(column->itemAt(4)->widget())->foregroundRole(), QPalette::Mid);
|
||||
// The fields stretch, named by their titles.
|
||||
auto &spacing = shown.find<PickerField>("gridSpacing");
|
||||
auto &subdivisions = shown.find<PickerField>("gridSubdivisions");
|
||||
QVERIFY(qobject_cast<QLabel *>(rowOf(5)->itemAt(0)->widget())->buddy() == &spacing && rowOf(5)->stretch(1) == 1);
|
||||
QVERIFY(qobject_cast<QLabel *>(rowOf(6)->itemAt(0)->widget())->buddy() == &subdivisions && rowOf(6)->stretch(1) == 1);
|
||||
QCOMPARE(qobject_cast<QLabel *>(rowOf(5)->itemAt(2)->widget())->foregroundRole(), QPalette::PlaceholderText);
|
||||
QVERIFY(spacing.placeholderText() == "Gridline every" && subdivisions.placeholderText() == "Subdivisions" && shown.find<PickerField>("gridOpacity").placeholderText() == "Opacity");
|
||||
auto ¬e = shown.find<QLabel>("gridNote");
|
||||
QVERIFY(note.wordWrap() && note.font().pixelSize() == 12);
|
||||
QCOMPARE(rowOf(8)->itemAt(3)->widget(), &shown.find<QPushButton>("gridOK"));
|
||||
// In the controller's dialog only OK takes Return.
|
||||
QDialog dialog;
|
||||
shown.sheet->setParent(&dialog);
|
||||
QVERIFY(!shown.find<QPushButton>("gridCancel").autoDefault() && !shown.find<QPushButton>("gridDefaults").autoDefault());
|
||||
QVERIFY(shown.find<QPushButton>("gridOK").autoDefault());
|
||||
shown.sheet->setParent(nullptr);
|
||||
}
|
||||
|
||||
void GridSettingsSheetTests::aSliderOrScrubReplacesTyping()
|
||||
{
|
||||
Sheet shown;
|
||||
auto &opacity = shown.find<PickerField>("gridOpacity");
|
||||
opacity.setFocus();
|
||||
opacity.selectAll();
|
||||
QTest::keyClicks(&opacity, QStringLiteral("77"));
|
||||
shown.find<QSlider>("gridOpacitySlider").setValue(60);
|
||||
QCOMPARE(opacity.text(), QString("60"));
|
||||
// Each title scrubs, and the note follows.
|
||||
auto *column = qobject_cast<QVBoxLayout *>(shown.sheet->layout());
|
||||
const auto titleOf = [column](int index) { return qobject_cast<QLabel *>(qobject_cast<QHBoxLayout *>(column->itemAt(index)->layout())->itemAt(0)->widget()); };
|
||||
auto &spacing = shown.find<PickerField>("gridSpacing");
|
||||
spacing.setFocus();
|
||||
spacing.selectAll();
|
||||
QTest::keyClicks(&spacing, QStringLiteral("99"));
|
||||
scrub(*titleOf(5), 10);
|
||||
QVERIFY(spacing.text() == "74" && shown.last().first == LayoutGrid(74, 8));
|
||||
QCOMPARE(shown.note(), QString("A subdivision every 9.25 pixels."));
|
||||
auto &subdivisions = shown.find<PickerField>("gridSubdivisions");
|
||||
subdivisions.setFocus();
|
||||
subdivisions.selectAll();
|
||||
QTest::keyClicks(&subdivisions, QStringLiteral("33"));
|
||||
scrub(*titleOf(6), 10);
|
||||
QVERIFY(subdivisions.text() == "10" && shown.last().first == LayoutGrid(74, 10));
|
||||
opacity.setFocus();
|
||||
opacity.selectAll();
|
||||
QTest::keyClicks(&opacity, QStringLiteral("33"));
|
||||
scrub(*titleOf(3), 10);
|
||||
QVERIFY(opacity.text() == "65" && shown.last().second.opacity == 65);
|
||||
}
|
||||
|
||||
QTEST_MAIN(GridSettingsSheetTests)
|
||||
#include "GridSettingsSheetTests.moc"
|
||||
@@ -55,6 +55,7 @@ private slots:
|
||||
void moveToolDragsAGuideAndRulerDropDeletesIt();
|
||||
void rulerStepUsesNicePixelIntervals();
|
||||
void guidesAndTheGridDrawOverTheCanvas();
|
||||
void theGridDrawsItsSettings();
|
||||
void theCursorKeysAndLostReleasesEndADrag();
|
||||
void theRulersFrameTheCanvasAndDragOutGuides();
|
||||
};
|
||||
@@ -167,6 +168,84 @@ void GuideCanvasTests::guidesAndTheGridDrawOverTheCanvas()
|
||||
QVERIFY(quarter.pixelColor(major64, 150) != between || quarter.pixelColor(major64 - 1, 150) != between);
|
||||
}
|
||||
|
||||
// Swift 1.3.5's Grid Settings: spacing, colour, opacity, style.
|
||||
void GuideCanvasTests::theGridDrawsItsSettings()
|
||||
{
|
||||
GuideCanvas shown;
|
||||
const QImage bare = shown.canvas->grab().toImage();
|
||||
shown.session.setShowsGrid(true);
|
||||
// What a line adds to its two columns, by channel.
|
||||
const auto ink = [&](double x, int y, int channel) {
|
||||
const QImage drawn = shown.canvas->grab().toImage();
|
||||
int sum = 0;
|
||||
for (int column = int(shown.at(x, 0).x()) - 1; column <= int(shown.at(x, 0).x()); ++column) {
|
||||
const QPoint at(column, int(shown.at(0, y).y()));
|
||||
const QRgb seen = drawn.pixel(at), was = bare.pixel(at);
|
||||
sum += channel == 0 ? qRed(seen) - qRed(was) : qGreen(seen) - qGreen(was);
|
||||
}
|
||||
return sum;
|
||||
};
|
||||
// Rows 1 to 35 along a line: # inked.
|
||||
const auto pattern = [&](double x) {
|
||||
QString rows;
|
||||
for (int y = 1; y <= 35; ++y)
|
||||
rows += std::abs(ink(x, y, 1)) > 2 ? QLatin1Char('#') : QLatin1Char('.');
|
||||
return rows;
|
||||
};
|
||||
const auto rowsInked = [&](double x) {
|
||||
int rows = 0;
|
||||
// Row 0 holds the top major: rows 1 to 35.
|
||||
for (int y = 1; y <= 35; ++y)
|
||||
rows += std::abs(ink(x, y, 1)) > 2;
|
||||
return rows;
|
||||
};
|
||||
// Majors at 100, dotted halves at 50, none at 64.
|
||||
int paints = 0;
|
||||
Painted counter(paints);
|
||||
QTest::qWait(50);
|
||||
shown.canvas->installEventFilter(&counter);
|
||||
shown.session.setLayoutGrid(LayoutGrid(100, 2));
|
||||
shown.canvas->synchronizeDisplay();
|
||||
QTRY_VERIFY(paints > 0);
|
||||
QVERIFY(rowsInked(100) == 35 && rowsInked(64) == 0);
|
||||
// Dotted subdivisions: one point on, two off, flat ends.
|
||||
QCOMPARE(pattern(50), QString("..#..#..#..#..#..#..#..#..#..#..#.."));
|
||||
// Subdivisions at 28/45 of the majors' ink.
|
||||
int faint = 0;
|
||||
for (int y = 1; y <= 35; ++y)
|
||||
faint = std::max(faint, std::abs(ink(50, y, 1)));
|
||||
QVERIFY2(std::abs(faint - ink(100, 20, 1) * 28 / 45) <= 3, qPrintable(QString::number(faint)));
|
||||
// Closer than four points, subdivisions go: 64 in 32.
|
||||
shown.session.setLayoutGrid(LayoutGrid(64, 32));
|
||||
QVERIFY(rowsInked(2) == 0 && rowsInked(64) == 35);
|
||||
// Exactly four points apart, they still show: 64 in 16.
|
||||
shown.session.setLayoutGrid(LayoutGrid(64, 16));
|
||||
QVERIFY(rowsInked(4) > 0);
|
||||
shown.session.setLayoutGrid(LayoutGrid(100, 2));
|
||||
// Cyan at full opacity: green rises, red falls.
|
||||
paints = 0;
|
||||
GridAppearance cyan;
|
||||
cyan.preset = GridAppearance::Preset::cyan;
|
||||
cyan.opacity = 100;
|
||||
shown.session.setGridAppearance(cyan);
|
||||
shown.canvas->synchronizeDisplay();
|
||||
QTRY_VERIFY(paints > 0);
|
||||
shown.canvas->removeEventFilter(&counter);
|
||||
QVERIFY2(ink(100, 20, 1) >= 0 && ink(100, 20, 0) < -60, qPrintable(QString::number(ink(100, 20, 0))));
|
||||
// At 1% the line barely shows.
|
||||
cyan.opacity = 1;
|
||||
shown.session.setGridAppearance(cyan);
|
||||
QVERIFY(std::abs(ink(100, 20, 0)) < 6 && std::abs(ink(100, 20, 0)) > 0);
|
||||
// Dashes four on, three off; dots one on, two off.
|
||||
cyan.opacity = 100;
|
||||
cyan.style = GridAppearance::Style::dashedLines;
|
||||
shown.session.setGridAppearance(cyan);
|
||||
QCOMPARE(pattern(100), QString("###...####...####...####...####...#"));
|
||||
cyan.style = GridAppearance::Style::dots;
|
||||
shown.session.setGridAppearance(cyan);
|
||||
QCOMPARE(pattern(100), QString("..#..#..#..#..#..#..#..#..#..#..#.."));
|
||||
}
|
||||
|
||||
void GuideCanvasTests::theCursorKeysAndLostReleasesEndADrag()
|
||||
{
|
||||
GuideCanvas shown;
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
#include "Document/BrushStroke.h"
|
||||
#include "Document/EditorSession.h"
|
||||
#include "Document/ToolDefaults.h"
|
||||
#include <QSettings>
|
||||
#include <QStandardPaths>
|
||||
#include <QtTest>
|
||||
|
||||
// Swift 1.3.5's GuideTests for Grid Settings, and their keeping.
|
||||
class GuideGridTests : public QObject {
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void initTestCase() { QStandardPaths::setTestModeEnabled(true); }
|
||||
void layoutGridTakesItsSpacingAndSubdivisions();
|
||||
void layoutGridKeepsToItsLimits();
|
||||
void gridAppearanceColorsAndStyles();
|
||||
void gridSnapFollowsTheGridSettings();
|
||||
void theSettingsAreThePersonsAcrossLaunches();
|
||||
};
|
||||
|
||||
void GuideGridTests::layoutGridTakesItsSpacingAndSubdivisions()
|
||||
{
|
||||
const LayoutGrid grid(100, 4);
|
||||
QCOMPARE(grid.lines(200), (std::vector<double>{0, 25, 50, 75, 100, 125, 150, 175, 200}));
|
||||
QVERIFY(grid.isMajor(100) && !grid.isMajor(50));
|
||||
QCOMPARE(grid.step(), 25.0);
|
||||
// An uneven step still lands on every major line.
|
||||
const LayoutGrid thirds(100, 3);
|
||||
std::vector<double> majors;
|
||||
for (const double line : thirds.lines(300))
|
||||
if (thirds.isMajor(line))
|
||||
majors.push_back(line);
|
||||
QCOMPARE(majors, (std::vector<double>{0, 100, 200, 300}));
|
||||
QCOMPARE(thirds.lines(100), (std::vector<double>{0, 33, 67, 100}));
|
||||
QCOMPARE(LayoutGrid(50, 1).lines(120), (std::vector<double>{0, 50, 100}));
|
||||
// A hair short of a line counts it: Swift's 0.001.
|
||||
QCOMPARE(LayoutGrid(50, 1).lines(99.96), (std::vector<double>{0, 50, 100}));
|
||||
QCOMPARE(LayoutGrid(50, 1).lines(99.9), (std::vector<double>{0, 50}));
|
||||
}
|
||||
|
||||
void GuideGridTests::layoutGridKeepsToItsLimits()
|
||||
{
|
||||
QCOMPARE(LayoutGrid(0, 0), LayoutGrid(2, 1));
|
||||
QCOMPARE(LayoutGrid(10, 40).subdivisions, 10);
|
||||
QCOMPARE(LayoutGrid(1'000'000, 1'000).spacing, LayoutGrid::spacingHigh);
|
||||
QCOMPARE(LayoutGrid(1'000'000, 1'000).subdivisions, LayoutGrid::subdivisionHigh);
|
||||
QVERIFY(LayoutGrid::spacingLow == 2 && LayoutGrid::spacingHigh == 4096 && LayoutGrid::subdivisionLow == 1 && LayoutGrid::subdivisionHigh == 64);
|
||||
QVERIFY(LayoutGrid().spacing == 64 && LayoutGrid().subdivisions == 8);
|
||||
}
|
||||
|
||||
void GuideGridTests::gridAppearanceColorsAndStyles()
|
||||
{
|
||||
const GridAppearance standard;
|
||||
QVERIFY(standard.preset == GridAppearance::Preset::lightGray && standard.style == GridAppearance::Style::lines && standard.opacity == 45);
|
||||
QCOMPARE(standard.color(), (PaletteColor{0.7, 0.7, 0.7}));
|
||||
QVERIFY(dashes(GridAppearance::Style::lines).empty());
|
||||
QCOMPARE(dashes(GridAppearance::Style::dashedLines), (std::vector<double>{4, 3}));
|
||||
QCOMPARE(dashes(GridAppearance::Style::dots), (std::vector<double>{1, 2}));
|
||||
GridAppearance appearance{GridAppearance::Preset::cyan, PaletteColor::black(), GridAppearance::Style::dots};
|
||||
QCOMPARE(appearance.color(), (PaletteColor{0, 1, 1}));
|
||||
appearance.preset = GridAppearance::Preset::custom;
|
||||
QCOMPARE(appearance.color(), PaletteColor::black());
|
||||
for (const GridAppearance::Preset preset : allGridPresets)
|
||||
QCOMPARE(!presetColor(preset), preset == GridAppearance::Preset::custom);
|
||||
QCOMPARE(PaletteColor::fromHex(appearance.customColor.hex()), std::optional(appearance.customColor));
|
||||
QVERIFY(std::abs(standard.majorAlpha() - 0.45) < 0.001 && std::abs(standard.subdivisionAlpha() - 0.28) < 0.001);
|
||||
appearance.opacity = 100;
|
||||
QVERIFY(appearance.majorAlpha() == 1 && appearance.subdivisionAlpha() < 1);
|
||||
appearance.opacity = 150;
|
||||
QCOMPARE(appearance.majorAlpha(), 1.0);
|
||||
appearance.opacity = 0;
|
||||
QCOMPARE(appearance.majorAlpha(), 0.01);
|
||||
// Photoshop's names and colours, in Swift's order.
|
||||
QStringList names;
|
||||
for (const GridAppearance::Preset preset : allGridPresets)
|
||||
names << rawValue(preset);
|
||||
QCOMPARE(names, QStringList({"Light Gray", "Light Blue", "Light Red", "Green", "Medium Blue", "Yellow", "Magenta", "Cyan", "Black", "Custom"}));
|
||||
QVERIFY(presetColor(GridAppearance::Preset::lightBlue) == (PaletteColor{0.29, 0.78, 1}) && presetColor(GridAppearance::Preset::lightRed) == (PaletteColor{1, 0.4, 0.4}));
|
||||
QVERIFY(presetColor(GridAppearance::Preset::green) == (PaletteColor{0.25, 0.8, 0.25}) && presetColor(GridAppearance::Preset::mediumBlue) == (PaletteColor{0.2, 0.4, 1}));
|
||||
QVERIFY(presetColor(GridAppearance::Preset::yellow) == (PaletteColor{1, 1, 0}) && presetColor(GridAppearance::Preset::magenta) == (PaletteColor{1, 0, 1}));
|
||||
QCOMPARE(presetColor(GridAppearance::Preset::black), std::optional(PaletteColor::black()));
|
||||
QStringList styles;
|
||||
for (const GridAppearance::Style style : allGridStyles)
|
||||
styles << rawValue(style);
|
||||
QCOMPARE(styles, QStringList({"Lines", "Dashed Lines", "Dots"}));
|
||||
}
|
||||
|
||||
void GuideGridTests::gridSnapFollowsTheGridSettings()
|
||||
{
|
||||
EditorSession session;
|
||||
session.createDocument(400, 300);
|
||||
session.setSnapToLayers(false);
|
||||
session.setSnapToDocumentBounds(false);
|
||||
session.setShowsGrid(true);
|
||||
session.setSnapToGrid(true);
|
||||
QSignalSpy changed(&session, &EditorSession::changed);
|
||||
session.setLayoutGrid(LayoutGrid(100, 2));
|
||||
QCOMPARE(changed.count(), 1);
|
||||
std::vector<double> xs = session.cropSnapTargets().xs;
|
||||
std::sort(xs.begin(), xs.end());
|
||||
QCOMPARE(xs, (std::vector<double>{0, 50, 100, 150, 200, 250, 300, 350, 400}));
|
||||
QCOMPARE(session.snappedGuidePosition(52, CanvasGuide::Axis::vertical, std::nullopt), 50.0);
|
||||
// The same grid or look again is no news.
|
||||
session.setLayoutGrid(LayoutGrid(100, 2));
|
||||
session.setGridAppearance(GridAppearance());
|
||||
QCOMPARE(changed.count(), 1);
|
||||
GridAppearance dashed;
|
||||
dashed.style = GridAppearance::Style::dashedLines;
|
||||
session.setGridAppearance(dashed);
|
||||
QVERIFY(changed.count() == 2 && session.gridAppearance() == dashed);
|
||||
}
|
||||
|
||||
void GuideGridTests::theSettingsAreThePersonsAcrossLaunches()
|
||||
{
|
||||
// Tests keep compiled defaults until the app turns them on.
|
||||
QSettings().clear();
|
||||
ToolDefaults::enable();
|
||||
QCOMPARE(EditorSession().layoutGrid(), LayoutGrid());
|
||||
QCOMPARE(EditorSession().gridAppearance(), GridAppearance());
|
||||
GridAppearance look{GridAppearance::Preset::custom, PaletteColor{0.2, 0.4, 0.6}, GridAppearance::Style::dots, 70};
|
||||
{
|
||||
EditorSession session;
|
||||
session.setLayoutGrid(LayoutGrid(100, 5));
|
||||
session.setGridAppearance(look);
|
||||
}
|
||||
// Swift's keys, so a person's settings read as Swift's.
|
||||
QSettings settings;
|
||||
QVERIFY(settings.value("tool.gridSpacing").toInt() == 100 && settings.value("tool.gridSubdivisions").toInt() == 5);
|
||||
QVERIFY(settings.value("tool.gridColor").toString() == "Custom" && settings.value("tool.gridStyle").toString() == "Dots");
|
||||
QVERIFY(settings.value("tool.gridCustomColor").toString() == look.customColor.hex() && settings.value("tool.gridOpacity").toInt() == 70);
|
||||
EditorSession next;
|
||||
QVERIFY(next.layoutGrid() == LayoutGrid(100, 5) && next.gridAppearance() == look);
|
||||
// What cannot be read is warned of, then defaulted.
|
||||
settings.setValue("tool.gridSpacing", "wide");
|
||||
settings.setValue("tool.gridColor", "Plaid");
|
||||
settings.setValue("tool.gridStyle", "Wavy");
|
||||
settings.setValue("tool.gridCustomColor", "#12");
|
||||
for (int warning = 0; warning < 4; ++warning)
|
||||
QTest::ignoreMessage(QtWarningMsg, QRegularExpression("ignoring the tool setting grid"));
|
||||
EditorSession unread;
|
||||
QCOMPARE(unread.layoutGrid(), LayoutGrid(64, 5));
|
||||
QVERIFY(unread.gridAppearance().preset == GridAppearance::Preset::lightGray && unread.gridAppearance().style == GridAppearance::Style::lines);
|
||||
QCOMPARE(unread.gridAppearance().customColor, GridAppearance().customColor);
|
||||
QCOMPARE(unread.gridAppearance().opacity, 70);
|
||||
QSettings().clear();
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(GuideGridTests)
|
||||
#include "GuideGridTests.moc"
|
||||
@@ -294,14 +294,16 @@ void GuideTests::snapTargetsFollowViewMenu()
|
||||
|
||||
void GuideTests::layoutGridLinesIncludeMajorsAndSubdivisions()
|
||||
{
|
||||
const std::vector<double> lines = LayoutGrid::lines(64);
|
||||
const LayoutGrid grid;
|
||||
const std::vector<double> lines = grid.lines(64);
|
||||
QCOMPARE(int(lines.size()), 9);
|
||||
QVERIFY(lines.front() == 0 && lines.back() == 64 && lines[1] == 8);
|
||||
QVERIFY(LayoutGrid::isMajor(0) && LayoutGrid::isMajor(64) && LayoutGrid::isMajor(128) && !LayoutGrid::isMajor(8));
|
||||
QVERIFY(LayoutGrid::isMajor(63.6) && !LayoutGrid::isMajor(63.4));
|
||||
QCOMPARE(LayoutGrid::lines(-1), std::vector<double>{0});
|
||||
QCOMPARE(LayoutGrid::lines(7.9), std::vector<double>{0});
|
||||
QCOMPARE(int(LayoutGrid::lines(20).size()), 3);
|
||||
QVERIFY(grid.isMajor(0) && grid.isMajor(64) && grid.isMajor(128) && !grid.isMajor(8));
|
||||
QVERIFY(grid.isMajor(63.6) && !grid.isMajor(63.4));
|
||||
QCOMPARE(grid.lines(-1), std::vector<double>{0});
|
||||
QCOMPARE(grid.lines(qQNaN()), std::vector<double>{0});
|
||||
QCOMPARE(grid.lines(7.9), std::vector<double>{0});
|
||||
QCOMPARE(int(grid.lines(20).size()), 3);
|
||||
}
|
||||
|
||||
void GuideTests::aDragCreatesMovesAndDeletesGuides()
|
||||
|
||||
@@ -44,6 +44,7 @@ private slots:
|
||||
void theCanvasDrawsDevicePixels();
|
||||
void levelsEyedroppersDrawDevicePixels();
|
||||
void theJPEGPreviewCountsDevicePixels();
|
||||
void gridDashesAreScreenPoints();
|
||||
};
|
||||
|
||||
void HighDpiCanvasTests::theScreenScalesByTwo()
|
||||
@@ -193,6 +194,39 @@ void HighDpiCanvasTests::theJPEGPreviewCountsDevicePixels()
|
||||
QCOMPARE(preview.horizontalScrollBar()->maximum(), int(std::ceil(600 - preview.viewport()->width())));
|
||||
}
|
||||
|
||||
void HighDpiCanvasTests::gridDashesAreScreenPoints()
|
||||
{
|
||||
EditorSession session;
|
||||
session.createDocument(100, 100);
|
||||
QWidget window;
|
||||
auto *canvas = new CanvasView(session, &window);
|
||||
window.resize(100, 100);
|
||||
canvas->setGeometry(0, 0, 100, 100);
|
||||
window.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&window));
|
||||
QTRY_COMPARE(session.viewport.backingScale, 2.0);
|
||||
session.zoom(1);
|
||||
const QImage bare = canvas->grab().toImage();
|
||||
session.setShowsGrid(true);
|
||||
session.setLayoutGrid(LayoutGrid(50, 1));
|
||||
GridAppearance dashed;
|
||||
dashed.preset = GridAppearance::Preset::black;
|
||||
dashed.opacity = 100;
|
||||
dashed.style = GridAppearance::Style::dashedLines;
|
||||
session.setGridAppearance(dashed);
|
||||
canvas->synchronizeDisplay();
|
||||
const QImage drawn = canvas->grab().toImage();
|
||||
// Four points on is eight device rows, not four.
|
||||
const int column = int(std::round(session.viewport.viewPoint(QPointF(50, 0), QSizeF(100, 100)).x() * 2));
|
||||
int run = 0, longest = 0;
|
||||
for (int y = 4; y < 180; ++y) {
|
||||
const bool inked = std::abs(qGray(drawn.pixel(column, y)) - qGray(bare.pixel(column, y))) + std::abs(qGray(drawn.pixel(column - 1, y)) - qGray(bare.pixel(column - 1, y))) > 20;
|
||||
run = inked ? run + 1 : 0;
|
||||
longest = std::max(longest, run);
|
||||
}
|
||||
QVERIFY2(longest >= 7 && longest <= 9, qPrintable(QString::number(longest)));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Every widget on this screen scales by two.
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "UI/ColorPaletteControls.h"
|
||||
#include "UI/ColorPickerSheet+Dialog.h"
|
||||
#include "UI/ColorPickerSheet.h"
|
||||
#include "UI/GridSettingsSheet.h"
|
||||
#include <QComboBox>
|
||||
#include "UI/ImageSizeSheet.h"
|
||||
#include <QDialog>
|
||||
@@ -19,6 +20,7 @@ private slots:
|
||||
void theImageSizeSheetScalesThePixelsAsOneStep();
|
||||
void aResizeThatFailsIsExplained();
|
||||
void theSheetsColourOpensTheAppsPickerOverIt();
|
||||
void gridSettingsPreviewsThenKeepsOrPutsBack();
|
||||
};
|
||||
|
||||
namespace {
|
||||
@@ -194,5 +196,44 @@ void ProjectResizeTests::theSheetsColourOpensTheAppsPickerOverIt()
|
||||
QVERIFY(!desk.session.isProjectBusy());
|
||||
}
|
||||
|
||||
void ProjectResizeTests::gridSettingsPreviewsThenKeepsOrPutsBack()
|
||||
{
|
||||
Desk desk;
|
||||
QVERIFY(!desk.session.showsGrid() && !desk.session.isProjectBusy());
|
||||
const int steps = desk.session.history.undoCount();
|
||||
desk.controller.gridSettings(desk.finished());
|
||||
// The grid shows while the sheet is open; nothing busy.
|
||||
QVERIFY(desk.session.showsGrid() && !desk.session.isProjectBusy());
|
||||
QVERIFY(desk.dialog().windowTitle() == "Grid" && desk.dialog().windowModality() == Qt::WindowModal);
|
||||
auto &preset = *desk.dialog().findChild<QComboBox *>(QStringLiteral("gridPreset"));
|
||||
preset.setCurrentIndex(7);
|
||||
emit preset.activated(7);
|
||||
QCOMPARE(desk.session.gridAppearance().preset, GridAppearance::Preset::cyan);
|
||||
// Another sheet waits for this one.
|
||||
bool refused = false;
|
||||
desk.controller.gridSettings([&refused] { refused = true; });
|
||||
QTRY_VERIFY(refused);
|
||||
QCOMPARE(desk.window.findChildren<GridSettingsSheet *>().size(), 1);
|
||||
// Cancel puts back the look and the hidden grid.
|
||||
QTest::keyClick(&desk.dialog(), Qt::Key_Escape);
|
||||
QTRY_VERIFY(desk.done);
|
||||
QVERIFY(desk.session.gridAppearance() == GridAppearance() && !desk.session.showsGrid() && desk.session.history.undoCount() == steps);
|
||||
QTRY_VERIFY(!desk.window.findChild<QDialog *>());
|
||||
// OK keeps what was set, shown grid or not.
|
||||
desk.session.setShowsGrid(true);
|
||||
desk.controller.gridSettings(desk.finished());
|
||||
auto &again = *desk.dialog().findChild<QComboBox *>(QStringLiteral("gridPreset"));
|
||||
again.setCurrentIndex(7);
|
||||
emit again.activated(7);
|
||||
desk.type("gridSpacing", "100");
|
||||
QTRY_VERIFY(desk.done);
|
||||
QVERIFY(desk.session.layoutGrid() == LayoutGrid(100, 8) && desk.session.showsGrid());
|
||||
QCOMPARE(desk.session.gridAppearance().preset, GridAppearance::Preset::cyan);
|
||||
// Without a window, nothing opens.
|
||||
desk.controller.window = nullptr;
|
||||
desk.controller.gridSettings(desk.finished());
|
||||
QTRY_VERIFY(desk.done);
|
||||
}
|
||||
|
||||
QTEST_MAIN(ProjectResizeTests)
|
||||
#include "ProjectResizeTests.moc"
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "UI/CanvasSizeSheet.h"
|
||||
#include "UI/ColorPickerSheet.h"
|
||||
#include "UI/ColorRangeSheet.h"
|
||||
#include "UI/GridSettingsSheet.h"
|
||||
#include "UI/EffectsSheet.h"
|
||||
#include "UI/FilterSheet.h"
|
||||
#include "UI/HueSaturationSheet.h"
|
||||
@@ -227,6 +228,7 @@ void RemappedKeysTests::everySheetBindsSwiftsKeys()
|
||||
session.insert(ImportedImage(red, red, "Red"));
|
||||
const CanvasDocument canvas = session.document().value();
|
||||
QCOMPARE(keys(CanvasSizeSheet(canvas, session, [](std::optional<CanvasSizeOptions>) {})), both);
|
||||
QCOMPARE(keys(GridSettingsSheet(session, LayoutGrid(), GridAppearance(), [](const GridSettingsSheet::Settings &) {}, [](std::optional<GridSettingsSheet::Settings>) {})), both);
|
||||
QCOMPARE(keys(ImageSizeSheet(canvas, [](std::optional<ImageSizeOptions>) {})), both);
|
||||
QCOMPARE(keys(TrimSheet([](std::optional<TrimOptions>) {})), both);
|
||||
// Export JPEG also takes the View menu's four zoom keys.
|
||||
|
||||
@@ -181,6 +181,8 @@ compositor_test(ColorRangeSheetTests)
|
||||
compositor_test(DialogColorPickerTests)
|
||||
compositor_test(JPEGPreviewTests)
|
||||
compositor_test(SnapDrawingCanvasTests)
|
||||
compositor_test(GuideGridTests)
|
||||
compositor_test(GridSettingsSheetTests)
|
||||
# It calls the colour-range kernel itself.
|
||||
target_include_directories(ColorRangeTests PRIVATE ${OMAPHOTO_KERNELS})
|
||||
compositor_test(DitherTests)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "MenuFixtures.h"
|
||||
#include "Rendering/EditorCanvas.h"
|
||||
#include "UI/GridSettingsSheet.h"
|
||||
#include <QLineEdit>
|
||||
|
||||
// The View menu: zoom, the pixel grid and Snap.
|
||||
@@ -9,6 +10,7 @@ private slots:
|
||||
void viewEntriesZoomTheFrontSession();
|
||||
void thePixelGridEntryTogglesTheSession();
|
||||
void guideEntriesFollowTheSession();
|
||||
void gridSettingsOpensItsSheet();
|
||||
};
|
||||
|
||||
void ViewMenuTests::viewEntriesZoomTheFrontSession()
|
||||
@@ -118,5 +120,25 @@ void ViewMenuTests::guideEntriesFollowTheSession()
|
||||
QVERIFY(!bar.action("clearGuides").isEnabled());
|
||||
}
|
||||
|
||||
void ViewMenuTests::gridSettingsOpensItsSheet()
|
||||
{
|
||||
Bar bar;
|
||||
QAction &entry = bar.action("gridSettings");
|
||||
QVERIFY(entry.text() == "Grid Settings…" && !entry.isCheckable() && !entry.isEnabled());
|
||||
// Swift's place: after the Show submenu, before Rulers.
|
||||
const QList<QAction *> view = qobject_cast<QMenu *>(entry.parent())->actions();
|
||||
const qsizetype at = view.indexOf(&entry);
|
||||
QVERIFY(view[at - 1]->menu() && view[at - 1]->menu()->title() == "Show" && view[at + 1] == &bar.action("showRulers"));
|
||||
bar.session().createDocument(20, 20);
|
||||
QVERIFY(entry.isEnabled());
|
||||
bar.window.show();
|
||||
entry.trigger();
|
||||
QTRY_VERIFY(bar.window.findChild<GridSettingsSheet *>());
|
||||
QVERIFY(bar.session().showsGrid());
|
||||
QTest::keyClick(bar.window.findChild<GridSettingsSheet *>(), Qt::Key_Escape);
|
||||
QTRY_VERIFY(!bar.window.findChild<GridSettingsSheet *>());
|
||||
QVERIFY(!bar.session().showsGrid());
|
||||
}
|
||||
|
||||
QTEST_MAIN(ViewMenuTests)
|
||||
#include "ViewMenuTests.moc"
|
||||
Reference in new issue
Block a user