14.3: New Canvas in inches, cm or mm at 72 or 300 DPI, transparent, white or black, every setting a pill
This commit is contained in:
12 files changed
+521
-38
No files matched your search
@@ -91,10 +91,10 @@ void EditorSession::clearProject()
|
||||
notify();
|
||||
}
|
||||
|
||||
void EditorSession::createNewProject(int width, int height)
|
||||
void EditorSession::createNewProject(int width, int height, double resolution, std::optional<QColor> background)
|
||||
{
|
||||
if (m_isProjectBusy || m_isImporting || width < 1 || width > DocumentLimits::maxSide || height < 1 || height > DocumentLimits::maxSide)
|
||||
return;
|
||||
clearProject();
|
||||
createDocument(width, height, true);
|
||||
createDocument(width, height, true, resolution, background);
|
||||
}
|
||||
@@ -6,4 +6,4 @@ public:
|
||||
// Swift's reloadProject: what the package holds now, the view kept.
|
||||
void reloadProject(const ProjectSnapshot &snapshot);
|
||||
void clearProject();
|
||||
void createNewProject(int width, int height);
|
||||
void createNewProject(int width, int height, double resolution = 72, std::optional<QColor> background = std::nullopt);
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "Document/EditorSession.h"
|
||||
#include "Document/DocumentLimits.h"
|
||||
#include "Document/Crop.h"
|
||||
#include "Document/PixelAdjust.h"
|
||||
#include "IO/ImageExporter.h"
|
||||
#include "Logging.h"
|
||||
#include <cmath>
|
||||
|
||||
@@ -281,17 +283,18 @@ void EditorSession::insert(const ImportedImage &asset, std::optional<QPointF> ce
|
||||
endEdit();
|
||||
}
|
||||
|
||||
void EditorSession::createDocument(int width, int height, bool emptyLayer)
|
||||
void EditorSession::createDocument(int width, int height, bool emptyLayer, double resolution, std::optional<QColor> background)
|
||||
{
|
||||
if (m_isProjectBusy || m_isImporting || width < 1 || width > DocumentLimits::maxSide || height < 1 || height > DocumentLimits::maxSide)
|
||||
return;
|
||||
commitTransform();
|
||||
beginEdit(QStringLiteral("New Canvas"));
|
||||
CanvasDocument document(width, height);
|
||||
// File > New starts with a selected blank "Layer 1".
|
||||
document.resolution = resolution >= 1 && resolution <= 9600 ? resolution : 72;
|
||||
// File > New starts with a selected first layer.
|
||||
std::optional<QUuid> selected;
|
||||
if (emptyLayer) {
|
||||
document.layers.push_back(ImageLayer(QStringLiteral("Layer 1"), document.size()));
|
||||
document.layers.push_back(firstLayer(document.size(), background));
|
||||
selected = document.layers.back().id;
|
||||
}
|
||||
m_document = document;
|
||||
@@ -305,6 +308,23 @@ void EditorSession::createDocument(int width, int height, bool emptyLayer)
|
||||
endEdit();
|
||||
}
|
||||
|
||||
// Empty, or the background in full-size pixels, as Photoshop's.
|
||||
ImageLayer EditorSession::firstLayer(QSizeF size, const std::optional<QColor> &background)
|
||||
{
|
||||
if (!background)
|
||||
return ImageLayer(QStringLiteral("Layer 1"), size);
|
||||
try {
|
||||
QImage image = BrushRaster::context(int(size.width()), int(size.height()), false);
|
||||
image.fill(*background);
|
||||
ImageLayer layer(QStringLiteral("Background"), size);
|
||||
layer.asset = ImportedImage(image, PixelAdjust::thumbnail(image), QStringLiteral("Background"));
|
||||
return layer;
|
||||
} catch (const ExportError &error) {
|
||||
qCWarning(lcApp) << "a new canvas's background could not be made:" << error.what();
|
||||
return ImageLayer(QStringLiteral("Layer 1"), size);
|
||||
}
|
||||
}
|
||||
|
||||
void EditorSession::fit()
|
||||
{
|
||||
if (!m_document)
|
||||
|
||||
@@ -234,7 +234,8 @@ public:
|
||||
void moveActiveLayer(int offset);
|
||||
|
||||
void insert(const ImportedImage &asset, std::optional<QPointF> centeredAt = std::nullopt);
|
||||
void createDocument(int width, int height, bool emptyLayer = false);
|
||||
// White or black fills a Background layer; none stays clear.
|
||||
void createDocument(int width, int height, bool emptyLayer = false, double resolution = 72, std::optional<QColor> background = std::nullopt);
|
||||
void fit();
|
||||
void zoom(double value, std::optional<QPointF> anchor = std::nullopt);
|
||||
// Swift's stepped keyboard zoom about the view's centre.
|
||||
@@ -313,6 +314,7 @@ private:
|
||||
void resumeFileRequests();
|
||||
void updateBusyIndicator();
|
||||
void endDuplicateTransform();
|
||||
static ImageLayer firstLayer(QSizeF size, const std::optional<QColor> &background);
|
||||
// Clone Stamp is family 1, the Smear 2, others 0.
|
||||
static int tipFamily(NavigationTool tool);
|
||||
|
||||
|
||||
Reference in new issue
Block a user