Export JPEG and Canvas Size take the app's colour picker; a panel opens over a modal sheet (13.4a)
This commit is contained in:
1 parent
0b7eb6cb6f
commit
bc49b722eb
23 files changed
+470
-134
No files matched your search
@@ -1,8 +1,9 @@
|
||||
#include "UI/CanvasSizeSheet.h"
|
||||
#include "UI/ColorPaletteControls.h"
|
||||
#include "UI/ColorPickerSheet+Dialog.h"
|
||||
#include "UI/ColorPickerSheet.h"
|
||||
#include <QCheckBox>
|
||||
#include <QColorDialog>
|
||||
#include <QHBoxLayout>
|
||||
#include <QComboBox>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
@@ -19,7 +20,7 @@ private slots:
|
||||
void fieldsSetTheDraftInItsUnits();
|
||||
void anInvalidSizeRestsOK();
|
||||
void theAnchorAndTheExtensionGoWithOK();
|
||||
void aCustomColorComesFromTheColorDialog();
|
||||
void aCustomColorComesFromTheAppsPicker();
|
||||
void theAnchorsDrawTheirCircles();
|
||||
void aFieldKeepsItsTypingAndItsNumber();
|
||||
void aWheelOverUnitsCommitsTheTypingFirst();
|
||||
@@ -34,12 +35,22 @@ CanvasDocument document(qint64 width, qint64 height)
|
||||
return canvas;
|
||||
}
|
||||
|
||||
// A session whose palette holds these two colours.
|
||||
EditorSession &painted(EditorSession &session, PaletteColor foreground, PaletteColor background)
|
||||
{
|
||||
session.setPaletteColor(foreground, false);
|
||||
session.setPaletteColor(background, true);
|
||||
return session;
|
||||
}
|
||||
|
||||
struct Sheet {
|
||||
std::optional<std::optional<CanvasSizeOptions>> answer;
|
||||
EditorSession session;
|
||||
CanvasSizeSheet sheet;
|
||||
explicit Sheet(qint64 width = 1200, qint64 height = 800, PaletteColor foreground = PaletteColor::black(),
|
||||
PaletteColor background = PaletteColor::white())
|
||||
: sheet(document(width, height), foreground, background, [this](std::optional<CanvasSizeOptions> options) { answer = options; })
|
||||
: sheet(document(width, height), painted(session, foreground, background),
|
||||
[this](std::optional<CanvasSizeOptions> options) { answer = options; })
|
||||
{
|
||||
sheet.show();
|
||||
}
|
||||
@@ -187,47 +198,51 @@ void CanvasSizeSheetTests::theAnchorAndTheExtensionGoWithOK()
|
||||
}
|
||||
}
|
||||
|
||||
void CanvasSizeSheetTests::aCustomColorComesFromTheColorDialog()
|
||||
void CanvasSizeSheetTests::aCustomColorComesFromTheAppsPicker()
|
||||
{
|
||||
Sheet shown;
|
||||
auto &extension = shown.find<QComboBox>("canvasExtension");
|
||||
extension.setCurrentIndex(5);
|
||||
emit extension.activated(5);
|
||||
QVERIFY(shown.find<QWidget>("extensionColorRow").isVisible());
|
||||
auto &swatch = shown.find<SwatchButton>("extensionColor");
|
||||
QCOMPARE(swatch.accessibleName(), QString("Extension color"));
|
||||
QCOMPARE(qobject_cast<QHBoxLayout *>(shown.find<QWidget>("extensionColorRow").layout())->spacing(), 8);
|
||||
auto &swatch = shown.find<DialogColorSwatch>("extensionColor");
|
||||
QVERIFY(swatch.accessibleName() == QString("Extension Color") && swatch.toolTip() == QString("Color for the added canvas"));
|
||||
swatch.click();
|
||||
auto *dialog = shown.sheet.findChild<QColorDialog *>();
|
||||
QVERIFY(dialog && dialog->isVisible());
|
||||
QVERIFY(!dialog->testOption(QColorDialog::ShowAlphaChannel));
|
||||
QCOMPARE(dialog->currentColor(), QColor(Qt::white));
|
||||
dialog->setCurrentColor(QColor(0, 128, 255));
|
||||
// The swatch repaints with the colour chosen.
|
||||
int painted = 0;
|
||||
struct Spy : QObject {
|
||||
int &count;
|
||||
explicit Spy(int &count) : count(count) {}
|
||||
bool eventFilter(QObject *, QEvent *event) override
|
||||
{
|
||||
count += event->type() == QEvent::Paint;
|
||||
return false;
|
||||
}
|
||||
} spy(painted);
|
||||
swatch.installEventFilter(&spy);
|
||||
QApplication::processEvents();
|
||||
const int before = painted;
|
||||
dialog->accept();
|
||||
QTRY_VERIFY(painted > before);
|
||||
swatch.removeEventFilter(&spy);
|
||||
QCOMPARE(shown.session.colorPicker().value().target.title(), QString("Color Picker (Extension Color)"));
|
||||
QVERIFY(shown.session.colorPicker().value().original == PaletteColor::white());
|
||||
// OK takes the open picker's colour, closing it first.
|
||||
const PaletteColor sky{0, 128 / 255.0, 1};
|
||||
shown.session.setColorPickerHSB(PickerHSB(sky));
|
||||
QCOMPARE(swatch.grab().toImage().pixelColor(17, 9), QColor(0, 128, 255));
|
||||
shown.find<QPushButton>("canvasOK").click();
|
||||
QVERIFY(!shown.session.colorPicker());
|
||||
const CanvasExtensionColor fill = shown.answer.value().value().fill.value();
|
||||
QCOMPARE(fill.red, 0.0);
|
||||
QCOMPARE(fill.green, QColor(0, 128, 255).greenF());
|
||||
QCOMPARE(fill.blue, 1.0);
|
||||
// Chosen again, the dialog opens on the colour kept.
|
||||
QVERIFY(fill.red == 0 && fill.green == 128 / 255.0 && fill.blue == 1);
|
||||
// Chosen again, the picker opens on the colour kept.
|
||||
swatch.click();
|
||||
QTRY_VERIFY(shown.sheet.findChild<QColorDialog *>() && shown.sheet.findChild<QColorDialog *>()->isVisible());
|
||||
QCOMPARE(shown.sheet.findChild<QColorDialog *>()->currentColor(), QColor(0, 128, 255));
|
||||
QVERIFY(shown.session.colorPicker().value().original == sky);
|
||||
shown.session.setColorPickerHSB(PickerHSB(PaletteColor{1, 0, 0}));
|
||||
shown.session.closeColorPicker(false);
|
||||
QCOMPARE(swatch.grab().toImage().pixelColor(17, 9), QColor(0, 128, 255));
|
||||
// Another extension hides the swatch: the picker goes, colour kept.
|
||||
swatch.click();
|
||||
shown.session.setColorPickerHSB(PickerHSB(PaletteColor{1, 0, 0}));
|
||||
extension.setCurrentIndex(0);
|
||||
emit extension.activated(0);
|
||||
QVERIFY(!shown.session.colorPicker());
|
||||
extension.setCurrentIndex(5);
|
||||
emit extension.activated(5);
|
||||
QCOMPARE(swatch.grab().toImage().pixelColor(17, 9), QColor(255, 0, 0));
|
||||
// Cancel and the sheet going close it too.
|
||||
swatch.click();
|
||||
shown.find<QPushButton>("canvasCancel").click();
|
||||
QVERIFY(!shown.session.colorPicker() && !shown.answer.value());
|
||||
EditorSession session;
|
||||
auto gone = std::make_unique<CanvasSizeSheet>(document(10, 10), session, [](std::optional<CanvasSizeOptions>) {});
|
||||
gone->findChild<DialogColorSwatch *>()->click();
|
||||
gone.reset();
|
||||
QVERIFY(!session.colorPicker());
|
||||
}
|
||||
|
||||
void CanvasSizeSheetTests::theAnchorsDrawTheirCircles()
|
||||
@@ -291,7 +306,8 @@ void CanvasSizeSheetTests::halfwayNumbersRoundToEven()
|
||||
{
|
||||
CanvasDocument canvas{17, 19};
|
||||
canvas.resolution = 16;
|
||||
CanvasSizeSheet sheet(canvas, PaletteColor::black(), PaletteColor::white(), [](std::optional<CanvasSizeOptions>) {});
|
||||
EditorSession session;
|
||||
CanvasSizeSheet sheet(canvas, session, [](std::optional<CanvasSizeOptions>) {});
|
||||
auto &units = *sheet.findChild<QComboBox *>(QStringLiteral("canvasUnits"));
|
||||
const int inches = units.findText(QStringLiteral("Inches"));
|
||||
units.setCurrentIndex(inches);
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
#include "SelectionCanvasFixtures.h"
|
||||
#include "UI/ColorPaletteControls.h"
|
||||
#include "UI/ColorPickerSheet+Dialog.h"
|
||||
#include "UI/ColorPickerSheet.h"
|
||||
#include <QDialog>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
// Swift 1.3.5's dialog colours: the app's picker on a swatch.
|
||||
class DialogColorPickerTests : public QObject {
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void initTestCase() { QStandardPaths::setTestModeEnabled(true); }
|
||||
void thePickerTellsTheDialogAsItMoves();
|
||||
void theSwatchOpensItFollowsItAndClosesIt();
|
||||
void thePanelOpensOverAModalSheet();
|
||||
void aDialogsPickerSamplesNothing();
|
||||
};
|
||||
|
||||
namespace {
|
||||
const PaletteColor blue{0, 0, 1};
|
||||
|
||||
struct Heard {
|
||||
std::vector<PaletteColor> colours;
|
||||
std::function<void(const PaletteColor &)> listener()
|
||||
{
|
||||
return [this](const PaletteColor &colour) { colours.push_back(colour); };
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void DialogColorPickerTests::thePickerTellsTheDialogAsItMoves()
|
||||
{
|
||||
EditorSession session;
|
||||
Heard heard;
|
||||
QSignalSpy changed(&session, &EditorSession::changed);
|
||||
session.openDialogColorPicker(QStringLiteral("JPEG Background"), PaletteColor::white(), heard.listener());
|
||||
QCOMPARE(changed.count(), 1);
|
||||
const ColorPickerState &picker = session.colorPicker().value();
|
||||
QVERIFY(picker.target.kind == ColorPickerTarget::Kind::dialog && picker.original == PaletteColor::white());
|
||||
QCOMPARE(picker.target.title(), QStringLiteral("Color Picker (JPEG Background)"));
|
||||
QVERIFY(session.pickingForDialog());
|
||||
// One picker at a time: a second ask changes nothing.
|
||||
Heard other;
|
||||
session.openDialogColorPicker(QStringLiteral("Extension Color"), blue, other.listener());
|
||||
QVERIFY(changed.count() == 1 && session.colorPicker().value().target.dialogTitle == QStringLiteral("JPEG Background"));
|
||||
// The working colour reaches the dialog, the session silent.
|
||||
session.setColorPickerHSB(PickerHSB(blue));
|
||||
changed.clear();
|
||||
session.previewDialogColor();
|
||||
QVERIFY(changed.isEmpty() && heard.colours == std::vector<PaletteColor>{blue});
|
||||
// Cancel tells the original; OK the chosen colour.
|
||||
session.closeColorPicker(false);
|
||||
QVERIFY(!session.pickingForDialog() && heard.colours.back() == PaletteColor::white() && changed.count() == 1);
|
||||
session.openDialogColorPicker(QStringLiteral("JPEG Background"), PaletteColor::white(), heard.listener());
|
||||
session.setColorPickerHSB(PickerHSB(blue));
|
||||
session.closeColorPicker(true);
|
||||
QVERIFY(heard.colours.back() == blue && other.colours.empty());
|
||||
// Not a dialog's picker: nothing to tell, nothing told.
|
||||
session.openColorPicker(false);
|
||||
QVERIFY(session.colorPicker() && !session.pickingForDialog());
|
||||
const size_t told = heard.colours.size();
|
||||
session.previewDialogColor();
|
||||
QCOMPARE(heard.colours.size(), told);
|
||||
// The picker's sheet asks no sample for a dialog.
|
||||
QVERIFY(ColorPickerSheet(session, [](bool) {}).findChild<QLabel *>(QStringLiteral("pickerHint")));
|
||||
session.closeColorPicker(false);
|
||||
session.openDialogColorPicker(QStringLiteral("JPEG Background"), PaletteColor::white(), heard.listener());
|
||||
QVERIFY(!ColorPickerSheet(session, [](bool) {}).findChild<QLabel *>(QStringLiteral("pickerHint")));
|
||||
}
|
||||
|
||||
void DialogColorPickerTests::theSwatchOpensItFollowsItAndClosesIt()
|
||||
{
|
||||
EditorSession session;
|
||||
PaletteColor kept = PaletteColor::white();
|
||||
QWidget host;
|
||||
auto *swatch = new DialogColorSwatch(QStringLiteral("Extension Color"), [&kept] { return kept; }, [&kept](const PaletteColor &colour) { kept = colour; },
|
||||
session, &host);
|
||||
host.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&host));
|
||||
QVERIFY(swatch->size() == QSize(34, 18) && swatch->accessibleName() == QStringLiteral("Extension Color"));
|
||||
// The brush's look: colour, white ring, black rim.
|
||||
QImage drawn = swatch->grab().toImage();
|
||||
QVERIFY(drawn.pixelColor(0, 9).value() < 40 && drawn.pixelColor(1, 9) == QColor(Qt::white) && drawn.pixelColor(17, 9) == QColor(Qt::white));
|
||||
swatch->click();
|
||||
QVERIFY(session.pickingForDialog() && session.colorPicker().value().original == PaletteColor::white());
|
||||
// The dialog follows the working colour; the swatch repaints.
|
||||
QCoreApplication::processEvents();
|
||||
PaintSpy painted(*swatch);
|
||||
session.setColorPickerHSB(PickerHSB(blue));
|
||||
QVERIFY(kept == blue);
|
||||
QTRY_VERIFY(painted.count > 0);
|
||||
drawn = swatch->grab().toImage();
|
||||
QCOMPARE(drawn.pixelColor(17, 9), QColor(Qt::blue));
|
||||
// Rim, white ring, colour; a corner rounded by four.
|
||||
QVERIFY(drawn.pixelColor(0, 9) == QColor(Qt::black) && drawn.pixelColor(1, 9) == QColor(Qt::white) && drawn.pixelColor(2, 9) == QColor(Qt::blue));
|
||||
QVERIFY(drawn.pixelColor(0, 0).red() > 220 && drawn.pixelColor(1, 1).red() < 20);
|
||||
// A palette picker leaves the swatch alone.
|
||||
session.closeColorPicker(true);
|
||||
session.openColorPicker(true);
|
||||
session.setColorPickerHSB(PickerHSB(PaletteColor::black()));
|
||||
DialogColorSwatch::closePicker(session);
|
||||
QVERIFY(kept == blue && session.colorPicker() && !session.pickingForDialog());
|
||||
session.closeColorPicker(false);
|
||||
// Hidden, the swatch closes its picker, keeping the colour.
|
||||
swatch->click();
|
||||
session.setColorPickerHSB(PickerHSB(PaletteColor{1, 0, 0}));
|
||||
// A minimized window hides it spontaneously: the picker stays.
|
||||
host.showMinimized();
|
||||
QCoreApplication::processEvents();
|
||||
QVERIFY(session.pickingForDialog());
|
||||
host.showNormal();
|
||||
swatch->hide();
|
||||
QVERIFY(!session.colorPicker() && kept == (PaletteColor{1, 0, 0}));
|
||||
}
|
||||
|
||||
void DialogColorPickerTests::thePanelOpensOverAModalSheet()
|
||||
{
|
||||
EditorSession session;
|
||||
QWidget window;
|
||||
window.setLayout(new QVBoxLayout);
|
||||
window.layout()->addWidget(new ColorPaletteControls(session, &window));
|
||||
window.show();
|
||||
QVERIFY(QTest::qWaitForWindowActive(&window));
|
||||
const auto panel = [] {
|
||||
for (QWidget *widget : QApplication::topLevelWidgets())
|
||||
if (widget->objectName() == ColorPickerPanelController::identifier() && widget->isVisible())
|
||||
return widget;
|
||||
return static_cast<QWidget *>(nullptr);
|
||||
};
|
||||
session.openColorPicker(false);
|
||||
QTRY_VERIFY(panel());
|
||||
QCOMPARE(panel()->parentWidget(), &window);
|
||||
session.closeColorPicker(false);
|
||||
QTRY_VERIFY(!panel());
|
||||
// Window-modal, as the controller's sheets: the panel moves under it.
|
||||
auto *sheet = new QDialog(&window);
|
||||
sheet->setWindowModality(Qt::WindowModal);
|
||||
sheet->open();
|
||||
QTRY_COMPARE(QApplication::activeModalWidget(), sheet);
|
||||
PaletteColor kept = PaletteColor::white();
|
||||
session.openDialogColorPicker(QStringLiteral("JPEG Background"), kept, [&kept](const PaletteColor &colour) { kept = colour; });
|
||||
QTRY_VERIFY(panel());
|
||||
QCOMPARE(panel()->parentWidget(), sheet);
|
||||
QCOMPARE(panel()->windowTitle(), QStringLiteral("Color Picker (JPEG Background)"));
|
||||
QTRY_COMPARE(QApplication::activeWindow(), panel());
|
||||
// It dies with the sheet; the next is the window's.
|
||||
session.closeColorPicker(true);
|
||||
QTRY_VERIFY(!panel());
|
||||
delete sheet;
|
||||
session.openColorPicker(false);
|
||||
QTRY_VERIFY(panel());
|
||||
QCOMPARE(panel()->parentWidget(), &window);
|
||||
session.closeColorPicker(false);
|
||||
}
|
||||
|
||||
void DialogColorPickerTests::aDialogsPickerSamplesNothing()
|
||||
{
|
||||
Canvas shown;
|
||||
const QCursor dropper = CanvasView::eyedropperCursor(shown.canvas->devicePixelRatio());
|
||||
shown.session.openDialogColorPicker(QStringLiteral("JPEG Background"), PaletteColor::white(), [](const PaletteColor &) {});
|
||||
shown.canvas->synchronizeDisplay();
|
||||
QVERIFY(!shown.shows(dropper));
|
||||
shown.session.closeColorPicker(false);
|
||||
shown.session.openColorPicker(false);
|
||||
shown.canvas->synchronizeDisplay();
|
||||
QVERIFY(shown.shows(dropper));
|
||||
}
|
||||
|
||||
QTEST_MAIN(DialogColorPickerTests)
|
||||
#include "DialogColorPickerTests.moc"
|
||||
@@ -1,7 +1,8 @@
|
||||
#include "UI/ByteCounts.h"
|
||||
#include "UI/ColorPaletteControls.h"
|
||||
#include "UI/JPEGExportSheet.h"
|
||||
#include <QColorDialog>
|
||||
#include "UI/ColorPickerSheet+Dialog.h"
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QProgressBar>
|
||||
#include <QPushButton>
|
||||
@@ -19,7 +20,7 @@ private slots:
|
||||
void theSheetShowsTheRasterAndWaitsForItsPreview();
|
||||
void aChangeSupersedesThePreview();
|
||||
void aSupersededEncodingNeverLands();
|
||||
void theMatteComesFromTheColorDialog();
|
||||
void theMatteComesFromTheAppsPicker();
|
||||
void exportKeepsTheQualityAndCancelDoesNot();
|
||||
void theSavedQualityIsReadAsSwiftReadsIt();
|
||||
void anEncodingThatFailsIsShown();
|
||||
@@ -39,9 +40,10 @@ ExportRaster halfRed(int width = 64, int height = 32)
|
||||
|
||||
struct Sheet {
|
||||
std::optional<std::optional<QByteArray>> answer;
|
||||
EditorSession session;
|
||||
JPEGExportSheet sheet;
|
||||
explicit Sheet(ExportRaster raster = halfRed())
|
||||
: sheet(std::move(raster), [this](std::optional<QByteArray> data) { answer = std::move(data); })
|
||||
: sheet(std::move(raster), session, [this](std::optional<QByteArray> data) { answer = std::move(data); })
|
||||
{
|
||||
sheet.show();
|
||||
}
|
||||
@@ -162,36 +164,49 @@ void JPEGExportSheetTests::aSupersededEncodingNeverLands()
|
||||
QCOMPARE(shown.find<QLabel>("jpegPercent").text(), QString("50%"));
|
||||
}
|
||||
|
||||
void JPEGExportSheetTests::theMatteComesFromTheColorDialog()
|
||||
void JPEGExportSheetTests::theMatteComesFromTheAppsPicker()
|
||||
{
|
||||
QSettings().remove(JPEGExportSheet::qualityKey);
|
||||
Sheet shown;
|
||||
QTRY_VERIFY(shown.ready());
|
||||
shown.find<SwatchButton>("jpegMatte").click();
|
||||
auto *dialog = shown.sheet.findChild<QColorDialog *>();
|
||||
QVERIFY(dialog && dialog->isVisible());
|
||||
QVERIFY(!dialog->testOption(QColorDialog::ShowAlphaChannel));
|
||||
QCOMPARE(dialog->currentColor(), QColor(Qt::white));
|
||||
auto &matte = shown.find<DialogColorSwatch>("jpegMatte");
|
||||
QVERIFY(matte.accessibleName() == QString("JPEG Background") && matte.toolTip() == QString("Color that fills transparent areas"));
|
||||
QCOMPARE(qobject_cast<QHBoxLayout *>(shown.sheet.layout()->itemAt(3)->layout())->spacing(), 8);
|
||||
matte.click();
|
||||
QCOMPARE(shown.session.colorPicker().value().target.title(), QString("Color Picker (JPEG Background)"));
|
||||
QVERIFY(shown.session.colorPicker().value().original == PaletteColor::white());
|
||||
// The same colour asks for nothing.
|
||||
dialog->setCurrentColor(Qt::white);
|
||||
dialog->accept();
|
||||
shown.session.closeColorPicker(true);
|
||||
QVERIFY(shown.ready() && !shown.find<QTimer>("jpegWait").isActive());
|
||||
shown.find<SwatchButton>("jpegMatte").click();
|
||||
dialog = shown.sheet.findChild<QColorDialog *>();
|
||||
dialog->setCurrentColor(QColor(0, 0, 255));
|
||||
// The well repaints with its colour.
|
||||
PaintCount painted(shown.find<SwatchButton>("jpegMatte"));
|
||||
dialog->accept();
|
||||
QTRY_VERIFY(painted.count > 0);
|
||||
// The working colour reaches the preview; Cancel takes it back.
|
||||
matte.click();
|
||||
shown.session.setColorPickerHSB(PickerHSB(PaletteColor{0, 0, 1}));
|
||||
QVERIFY(!shown.ready());
|
||||
QCOMPARE(shown.find<SwatchButton>("jpegMatte").grab().toImage().pixelColor(18, 9), QColor(0, 0, 255));
|
||||
QCOMPARE(matte.grab().toImage().pixelColor(17, 9), QColor(0, 0, 255));
|
||||
shown.session.closeColorPicker(false);
|
||||
QCOMPARE(matte.grab().toImage().pixelColor(17, 9), QColor(Qt::white));
|
||||
QTRY_VERIFY(shown.ready());
|
||||
// Export closes an open picker, keeping its colour.
|
||||
matte.click();
|
||||
shown.session.setColorPickerHSB(PickerHSB(PaletteColor{0, 0, 1}));
|
||||
QTRY_VERIFY(shown.ready());
|
||||
shown.find<QPushButton>("jpegExport").click();
|
||||
QVERIFY(!shown.session.colorPicker());
|
||||
const QImage written = QImage::fromData(shown.answer.value().value(), "jpeg");
|
||||
const QColor left = written.pixelColor(8, 16), right = written.pixelColor(56, 16);
|
||||
QVERIFY(left.blue() > 240 && left.red() < 16 && left.green() < 16);
|
||||
QVERIFY(right.red() > 240 && right.blue() < 16);
|
||||
QCOMPARE(shown.answer.value().value(), ImageExporter::jpeg(halfRed(), {.red = 0, .green = 0, .blue = 1}).data);
|
||||
// Cancel and the sheet going close it too.
|
||||
Sheet cancelled;
|
||||
cancelled.find<DialogColorSwatch>("jpegMatte").click();
|
||||
cancelled.find<QPushButton>("jpegCancel").click();
|
||||
QVERIFY(!cancelled.session.colorPicker() && !cancelled.answer.value());
|
||||
EditorSession session;
|
||||
auto gone = std::make_unique<JPEGExportSheet>(halfRed(), session, [](std::optional<QByteArray>) {});
|
||||
gone->findChild<DialogColorSwatch *>()->click();
|
||||
gone.reset();
|
||||
QVERIFY(!session.colorPicker());
|
||||
}
|
||||
|
||||
void JPEGExportSheetTests::exportKeepsTheQualityAndCancelDoesNot()
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
#include "DialogDesk.h"
|
||||
#include "IO/ProjectController.h"
|
||||
#include "UI/CanvasSizeSheet.h"
|
||||
#include "UI/ColorPaletteControls.h"
|
||||
#include "UI/ColorPickerSheet+Dialog.h"
|
||||
#include "UI/ColorPickerSheet.h"
|
||||
#include <QComboBox>
|
||||
#include "UI/ImageSizeSheet.h"
|
||||
#include <QDialog>
|
||||
#include <QPushButton>
|
||||
@@ -15,6 +18,7 @@ private slots:
|
||||
void aCancelledOrRefusedSheetChangesNothing();
|
||||
void theImageSizeSheetScalesThePixelsAsOneStep();
|
||||
void aResizeThatFailsIsExplained();
|
||||
void theSheetsColourOpensTheAppsPickerOverIt();
|
||||
};
|
||||
|
||||
namespace {
|
||||
@@ -159,5 +163,36 @@ void ProjectResizeTests::aResizeThatFailsIsExplained()
|
||||
QVERIFY(alerts.seen.last().startsWith("alert|2|Couldn’t change canvas size|"));
|
||||
}
|
||||
|
||||
void ProjectResizeTests::theSheetsColourOpensTheAppsPickerOverIt()
|
||||
{
|
||||
Desk desk;
|
||||
new ColorPaletteControls(desk.session, &desk.window);
|
||||
desk.controller.canvasSize(desk.finished());
|
||||
auto &extension = *desk.dialog().findChild<QComboBox *>(QStringLiteral("canvasExtension"));
|
||||
extension.setCurrentIndex(5);
|
||||
emit extension.activated(5);
|
||||
desk.dialog().findChild<DialogColorSwatch *>()->click();
|
||||
// The panel sits over the sheet and takes the keys.
|
||||
QWidget *panel = nullptr;
|
||||
QTRY_VERIFY((panel = desk.dialog().findChild<QDialog *>(ColorPickerPanelController::identifier())) && panel->isVisible());
|
||||
QTRY_COMPARE(QApplication::activeWindow(), panel);
|
||||
desk.session.setColorPickerHSB(PickerHSB(PaletteColor{0, 0, 1}));
|
||||
// Escape there cancels the picker; the sheet stays.
|
||||
QTest::keyClick(panel, Qt::Key_Escape);
|
||||
QTRY_VERIFY(!desk.session.colorPicker() && !panel->isVisible());
|
||||
QVERIFY(desk.dialog().isVisible() && !desk.done);
|
||||
desk.dialog().findChild<DialogColorSwatch *>()->click();
|
||||
QTRY_VERIFY(panel->isVisible());
|
||||
desk.session.setColorPickerHSB(PickerHSB(PaletteColor{0, 0, 1}));
|
||||
panel->findChild<QPushButton *>(QStringLiteral("pickerOK"))->click();
|
||||
QVERIFY(!desk.session.colorPicker());
|
||||
desk.type("canvasWidth", "200");
|
||||
QTRY_VERIFY(desk.done);
|
||||
// The added canvas takes the colour picked.
|
||||
const ImageLayer bottom = desk.session.document().value().layers.front();
|
||||
QCOMPARE(bottom.asset.value().image().pixelColor(0, 25), QColor(0, 0, 255));
|
||||
QVERIFY(!desk.session.isProjectBusy());
|
||||
}
|
||||
|
||||
QTEST_MAIN(ProjectResizeTests)
|
||||
#include "ProjectResizeTests.moc"
|
||||
@@ -226,10 +226,10 @@ void RemappedKeysTests::everySheetBindsSwiftsKeys()
|
||||
red.fill(Qt::red);
|
||||
session.insert(ImportedImage(red, red, "Red"));
|
||||
const CanvasDocument canvas = session.document().value();
|
||||
QCOMPARE(keys(CanvasSizeSheet(canvas, PaletteColor::black(), PaletteColor::white(), [](std::optional<CanvasSizeOptions>) {})), both);
|
||||
QCOMPARE(keys(CanvasSizeSheet(canvas, session, [](std::optional<CanvasSizeOptions>) {})), both);
|
||||
QCOMPARE(keys(ImageSizeSheet(canvas, [](std::optional<ImageSizeOptions>) {})), both);
|
||||
QCOMPARE(keys(TrimSheet([](std::optional<TrimOptions>) {})), both);
|
||||
QCOMPARE(keys(JPEGExportSheet(ExportRaster{red, 72}, [](std::optional<QByteArray>) {})), both);
|
||||
QCOMPARE(keys(JPEGExportSheet(ExportRaster{red, 72}, session, [](std::optional<QByteArray>) {})), both);
|
||||
QCOMPARE(keys(ColorPickerSheet(session, [](bool) {})), both);
|
||||
QCOMPARE(keys(NewCanvasSheet(session, [](int, int) {}, [] {})), QSet<QString>{"Ctrl+K"});
|
||||
QCOMPARE(keys(TransformInspector(session)), both);
|
||||
|
||||
@@ -178,6 +178,7 @@ compositor_test(TextFontControlsTests)
|
||||
compositor_test(ColorRangeTests)
|
||||
compositor_test(ColorRangeCanvasTests)
|
||||
compositor_test(ColorRangeSheetTests)
|
||||
compositor_test(DialogColorPickerTests)
|
||||
# It calls the colour-range kernel itself.
|
||||
target_include_directories(ColorRangeTests PRIVATE ${OMAPHOTO_KERNELS})
|
||||
compositor_test(DitherTests)
|
||||
|
||||
Reference in new issue
Block a user