Commit 42be937d authored by Boudewijn Rempt's avatar Boudewijn Rempt

Merge branch 'master' into rempt/T379-resource-management

parents 3ba435ca 5345be7d
......@@ -7,6 +7,7 @@
<developer_name>Krita Foundation</developer_name>
<developer_name xml:lang="ca">Fundació Krita</developer_name>
<developer_name xml:lang="ca-valencia">Fundació Krita</developer_name>
<developer_name xml:lang="it">Fondazione Krita</developer_name>
<developer_name xml:lang="nl">Krita Foundation</developer_name>
<developer_name xml:lang="pt">Fundação do Krita</developer_name>
<developer_name xml:lang="pt-BR">Krita Foundation</developer_name>
......
......@@ -64,7 +64,8 @@ public:
void forceRepaint() override
{
m_layer->signalUpdate(m_layer->extent());
QRectF rect = KoShape::boundingRect(m_layer->shapes());
m_layer->signalUpdate(m_viewConverter->documentToView(rect));
}
void rerenderAfterBeingInvisible() override {}
......
......@@ -210,6 +210,16 @@ void KisConfig::defImageResolution(qreal res) const
m_cfg.writeEntry("imageResolutionDef", res*72.0);
}
int KisConfig::preferredVectorImportResolutionPPI(bool defaultValue) const
{
return defaultValue ? 100.0 : m_cfg.readEntry("preferredVectorImportResolution", 100.0);
}
void KisConfig::setPreferredVectorImportResolutionPPI(int value) const
{
m_cfg.writeEntry("preferredVectorImportResolution", value);
}
void cleanOldCursorStyleKeys(KConfigGroup &cfg)
{
if (cfg.hasKey("newCursorStyle") &&
......
......@@ -73,6 +73,9 @@ public:
qreal defImageResolution(bool defaultValue = false) const;
void defImageResolution(qreal res) const;
int preferredVectorImportResolutionPPI(bool defaultValue = false) const;
void setPreferredVectorImportResolutionPPI(int value) const;
/**
* @return the id of the default color model used for creating new images.
*/
......
......@@ -139,12 +139,41 @@ struct KisPaintingAssistant::Private {
}
} cachedTransform;
QColor assistantColor;
QColor assistantGlobalColor; // color to paint with if a custom color is not set
bool useCustomColor = false;
QColor assistantCustomColor;
};
void KisPaintingAssistant::setAssistantColor(QColor color)
void KisPaintingAssistant::setAssistantGlobalColor(QColor color)
{
d->assistantGlobalColor = color;
}
bool KisPaintingAssistant::useCustomColor()
{
return d->useCustomColor;
}
void KisPaintingAssistant::setUseCustomColor(bool useCustomColor)
{
d->useCustomColor = useCustomColor;
}
void KisPaintingAssistant::setAssistantCustomColor(QColor color)
{
d->assistantCustomColor = color;
}
QColor KisPaintingAssistant::assistantsGlobalColor()
{
return d->assistantGlobalColor;
}
QColor KisPaintingAssistant::assistantCustomColor()
{
d->assistantColor = color;
return d->assistantCustomColor;
}
KisPaintingAssistant::KisPaintingAssistant(const QString& id, const QString& name) : d(new Private)
......@@ -168,13 +197,16 @@ void KisPaintingAssistant::setSnappingActive(bool set)
void KisPaintingAssistant::drawPath(QPainter& painter, const QPainterPath &path, bool isSnappingOn)
{
int alpha = d->assistantColor.alpha();
QColor paintingColor = useCustomColor() ? assistantCustomColor() : d->assistantGlobalColor;
int alpha = paintingColor.alpha();
if (!isSnappingOn) {
alpha = d->assistantColor.alpha() *0.2;
alpha = alpha *0.2;
}
painter.save();
QPen pen_a(QColor(d->assistantColor.red(), d->assistantColor.green(), d->assistantColor.blue(), alpha), 2);
QPen pen_a(QColor(paintingColor.red(), paintingColor.green(), paintingColor.blue(), alpha), 2);
pen_a.setCosmetic(true);
painter.setPen(pen_a);
painter.drawPath(path);
......@@ -183,8 +215,10 @@ void KisPaintingAssistant::drawPath(QPainter& painter, const QPainterPath &path,
void KisPaintingAssistant::drawPreview(QPainter& painter, const QPainterPath &path)
{
QColor paintingColor = useCustomColor() ? assistantCustomColor() : d->assistantGlobalColor;
painter.save();
QPen pen_a(d->assistantColor, 1);
QPen pen_a(paintingColor, 1);
pen_a.setStyle(Qt::SolidLine);
pen_a.setCosmetic(true);
painter.setPen(pen_a);
......@@ -330,6 +364,9 @@ QByteArray KisPaintingAssistant::saveXml(QMap<KisPaintingAssistantHandleSP, int>
xml.writeStartElement("assistant");
xml.writeAttribute("type",d->id);
xml.writeAttribute("active", QString::number(d->isSnappingActive));
xml.writeAttribute("useCustomColor", QString::number(d->useCustomColor));
xml.writeAttribute("customColor", KisPaintingAssistantsDecoration::qColorToQString(d->assistantCustomColor));
saveCustomXml(&xml); // if any specific assistants have custom XML data to save to
......@@ -370,8 +407,29 @@ void KisPaintingAssistant::loadXml(KoStore* store, QMap<int, KisPaintingAssistan
switch (xml.readNext()) {
case QXmlStreamReader::StartElement:
if (xml.name() == "assistant") {
QStringRef active = xml.attributes().value("active");
d->isSnappingActive = (active != "0");
setSnappingActive( (active != "0") );
// load custom shared assistant properties
if ( xml.attributes().hasAttribute("useCustomColor")) {
QStringRef useCustomColor = xml.attributes().value("useCustomColor");
bool usingColor = false;
if (useCustomColor.toString() == "1") {
usingColor = true;
}
setUseCustomColor(usingColor);
}
if ( xml.attributes().hasAttribute("customColor")) {
QStringRef customColor = xml.attributes().value("customColor");
setAssistantCustomColor( KisPaintingAssistantsDecoration::qStringToQColor(customColor.toString()) );
}
}
loadCustomXml(&xml);
......
......@@ -116,7 +116,17 @@ public:
/// grabs the assistant color/opacity specified from the tool options
/// each assistant might have to use this differently, so just save a reference
void setAssistantColor(QColor color);
void setAssistantGlobalColor(QColor color);
QColor assistantsGlobalColor();
/// should this assistant use a custom color for the display? global color will be used if this is false
bool useCustomColor();
void setUseCustomColor(bool useCustomColor);
/// getter and setter for assistant's custom color
void setAssistantCustomColor(QColor color);
QColor assistantCustomColor();
virtual void drawAssistant(QPainter& gc, const QRectF& updateRect, const KisCoordinatesConverter *converter, bool cached = true,KisCanvas2 *canvas=0, bool assistantVisible=true, bool previewVisible=true);
void uncache();
......
......@@ -50,7 +50,7 @@ struct KisPaintingAssistantsDecoration::Private {
KisPaintingAssistantSP firstAssistant;
KisPaintingAssistantSP selectedAssistant;
bool aFirstStroke;
QColor m_assistantsColor = QColor(176, 176, 176, 255); // kis_assistant_tool has same default color specified
QColor m_globalAssistantsColor = QColor(176, 176, 176, 255); // kis_assistant_tool has same default color specified
bool m_isEditingAssistants = false;
bool m_outlineVisible = false;
int m_handleSize = 14; // size of editor handles on assistants
......@@ -207,7 +207,7 @@ void KisPaintingAssistantsDecoration::drawDecoration(QPainter& gc, const QRectF&
Q_FOREACH (KisPaintingAssistantSP assistant, assistants()) {
assistant->setAssistantColor(assistantsColor());
assistant->setAssistantGlobalColor(globalAssistantsColor());
assistant->drawAssistant(gc, updateRect, converter, true, canvas, assistantVisibility(), d->m_outlineVisible);
if (isEditingAssistants()) {
......@@ -227,8 +227,11 @@ void KisPaintingAssistantsDecoration::drawHandles(KisPaintingAssistantSP assista
{
QTransform initialTransform = converter->documentToWidgetTransform();
QColor colorToPaint = assistant->useCustomColor() ? assistant->assistantCustomColor() : assistant->assistantsGlobalColor();
Q_FOREACH (const KisPaintingAssistantHandleSP handle, assistant->handles()) {
QPointF transformedHandle = initialTransform.map(*handle);
QRectF ellipse(transformedHandle - QPointF(handleSize() * 0.5, handleSize() * 0.5), QSizeF(handleSize(), handleSize()));
......@@ -237,7 +240,7 @@ void KisPaintingAssistantsDecoration::drawHandles(KisPaintingAssistantSP assista
gc.save();
gc.setPen(Qt::NoPen);
gc.setBrush(assistantsColor());
gc.setBrush(colorToPaint);
gc.drawPath(path);
gc.restore();
}
......@@ -252,7 +255,7 @@ void KisPaintingAssistantsDecoration::drawHandles(KisPaintingAssistantSP assista
gc.save();
gc.setPen(Qt::NoPen);
gc.setBrush(assistantsColor());
gc.setBrush(colorToPaint);
gc.drawPath(path);
gc.restore();
}
......@@ -349,13 +352,13 @@ void KisPaintingAssistantsDecoration::toggleOutlineVisible()
setOutlineVisible(!outlineVisibility());
}
QColor KisPaintingAssistantsDecoration::assistantsColor() {
return d->m_assistantsColor;
QColor KisPaintingAssistantsDecoration::globalAssistantsColor() {
return d->m_globalAssistantsColor;
}
void KisPaintingAssistantsDecoration::setAssistantsColor(QColor color)
void KisPaintingAssistantsDecoration::setGlobalAssistantsColor(QColor color)
{
d->m_assistantsColor = color;
d->m_globalAssistantsColor = color;
uncache();
}
......@@ -471,3 +474,21 @@ void KisPaintingAssistantsDecoration::drawEditorWidget(KisPaintingAssistantSP as
}
QString KisPaintingAssistantsDecoration::qColorToQString(QColor color)
{
// color channels will usually have 0-255
QString customColor = QString::number(color.red()).append(",")
.append(QString::number(color.blue())).append(",")
.append(QString::number(color.green())).append(",")
.append(QString::number(color.alpha()));
return customColor;
}
QColor KisPaintingAssistantsDecoration::qStringToQColor(QString colorString)
{
QStringList colorComponents = colorString.split(',');
return QColor(colorComponents[0].toInt(), colorComponents[1].toInt(), colorComponents[2].toInt(), colorComponents[3].toInt());
}
......@@ -111,11 +111,14 @@ public:
/// retrieves the assistants color specified in the tool options
/// all assistants will share the same color
QColor assistantsColor();
QColor globalAssistantsColor();
int handleSize();
void setHandleSize(int handleSize);
/// helper functions when converting between QColor when saving to XML
static QString qColorToQString(QColor color);
static QColor qStringToQColor(QString colorString);
Q_SIGNALS:
void assistantChanged();
......@@ -128,7 +131,7 @@ public Q_SLOTS:
/// toggles whether there will be a preview of the assistant result when painting
void toggleOutlineVisible();
void setAssistantsColor(QColor color);
void setGlobalAssistantsColor(QColor color);
QPointF snapToGuide(KoPointerEvent *e, const QPointF &offset, bool useModifiers);
QPointF snapToGuide(const QPointF& pt, const QPointF &offset);
......
......@@ -208,6 +208,7 @@ void KisWorkspaceChooser::slotSaveWindowLayout()
layout->setValid(true);
KisWindowLayoutManager::instance()->setShowImageInAllWindowsEnabled(showImageInAllWindows);
KisWindowLayoutManager::instance()->setPrimaryWorkspaceFollowsFocus(primaryWorkspaceFollowsFocus, thisWindow->id());
KoResourceServer<KisWindowLayoutResource> * rserver = KisResourceServerProvider::instance()->windowLayoutServer();
QString saveLocation = rserver->saveLocation();
......
......@@ -6,14 +6,17 @@
<rect>
<x>0</x>
<y>0</y>
<width>284</width>
<height>274</height>
<width>255</width>
<height>265</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QFormLayout" name="formLayout_2">
<property name="rowWrapPolicy">
<enum>QFormLayout::WrapLongRows</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
......@@ -26,40 +29,44 @@
</property>
</widget>
</item>
<item>
<item row="0" column="1">
<widget class="QComboBox" name="availableAssistantsComboBox"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="loadAssistantButton">
<property name="text">
<string>Open...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="saveAssistantButton">
<property name="text">
<string>Save...</string>
</property>
</widget>
</item>
</layout>
<widget class="KisDoubleSliderSpinBox" name="vanishingPointAngleSpinbox" native="true">
<property name="minimumSize">
<size>
<width>50</width>
<height>20</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deleteAllAssistantsButton">
<widget class="QLabel" name="globalColorLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Delete all</string>
<string>Global Color:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="KisSliderSpinBox" name="assistantsOpacitySlider" native="true">
<widget class="KisSliderSpinBox" name="assistantsGlobalOpacitySlider" native="true">
<property name="minimumSize">
<size>
<width>30</width>
<height>0</height>
</size>
</property>
<property name="maximum" stdset="0">
<number>100</number>
</property>
......@@ -84,26 +91,57 @@
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<widget class="QCheckBox" name="useCustomAssistantColor">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Custom Color</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="KisDoubleSliderSpinBox" name="vanishingPointAngleSpinbox" native="true">
<widget class="KisSliderSpinBox" name="customColorOpacitySlider" native="true">
<property name="minimumSize">
<size>
<width>0</width>
<height>20</height>
<width>30</width>
<height>0</height>
</size>
</property>
<property name="maximum" stdset="0">
<number>100</number>
</property>
</widget>
</item>
<item>
<widget class="KColorButton" name="customAssistantColorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5"/>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
......@@ -117,25 +155,103 @@
</property>
</spacer>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="loadAssistantButton">
<property name="toolTip">
<string>Load Assistant Set</string>
</property>
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>18</width>
<height>18</height>
</size>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="saveAssistantButton">
<property name="toolTip">
<string>Save Assistant Set</string>
</property>
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>18</width>
<height>18</height>
</size>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="deleteAllAssistantsButton">
<property name="text">
<string>All</string>
</property>
<property name="iconSize">
<size>
<width>18</width>
<height>18</height>
</size>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KColorButton</class>
<extends>QPushButton</extends>
<header>kcolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>KisSliderSpinBox</class>
<extends>QWidget</extends>
<header>kis_slider_spin_box.h</header>
<container>1</container>
</customwidget>
<customwidget>
<customwidget>
<class>KisDoubleSliderSpinBox</class>
<extends>QWidget</extends>
<header>kis_slider_spin_box.h</header>
<header location="global">kis_slider_spin_box.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>KColorButton</class>
<extends>QPushButton</extends>
<header>kcolorbutton.h</header>
<container>1</container>
</customwidget>
</customwidgets>
......
......@@ -158,7 +158,7 @@ void SplineAssistant::drawCache(QPainter& gc, const KisCoordinatesConverter *con
{ // Draw bezier handles control lines only if we are editing the assistant
gc.save();
QColor assistantColor = m_canvas->paintingAssistantsDecoration()->assistantsColor();
QColor assistantColor = useCustomColor() ? assistantCustomColor() : assistantsGlobalColor();
QPen bezierlinePen(assistantColor);
bezierlinePen.setStyle(Qt::DotLine);
bezierlinePen.setWidth(1);
......
......@@ -157,14 +157,17 @@ void VanishingPointAssistant::drawAssistant(QPainter& gc, const QRectF& updateRe
pathCenter.addEllipse(ellipse);
drawPath(gc, pathCenter, isSnappingActive());
QColor paintingColor = useCustomColor() ? assistantCustomColor() : assistantsGlobalColor();
// draw the lines connecting the different nodes
QPen penStyle(m_canvas->paintingAssistantsDecoration()->assistantsColor(), 2.0, Qt::SolidLine);
QPen penStyle(paintingColor, 2.0, Qt::SolidLine);
if (!isSnappingActive()) {
penStyle.setColor(QColor(m_canvas->paintingAssistantsDecoration()->assistantsColor().red(),
m_canvas->paintingAssistantsDecoration()->assistantsColor().green(),
m_canvas->paintingAssistantsDecoration()->assistantsColor().blue(),
m_canvas->paintingAssistantsDecoration()->assistantsColor().alpha()*.2));
penStyle.setColor(QColor(m_canvas->paintingAssistantsDecoration()->globalAssistantsColor().red(),
m_canvas->paintingAssistantsDecoration()->globalAssistantsColor().green(),
m_canvas->paintingAssistantsDecoration()->globalAssistantsColor().blue(),
m_canvas->paintingAssistantsDecoration()->globalAssistantsColor().alpha()*.2));
}
gc.save();
......
......@@ -84,9 +84,6 @@ private:
void assistantSelected(KisPaintingAssistantSP assistant);
void updateToolOptionsUI();
public Q_SLOTS:
void activate(ToolActivation toolActivation, const QSet<KoShape*> &shapes) override;
void deactivate() override;
......@@ -98,11 +95,15 @@ private Q_SLOTS:
void removeAllAssistants();
void saveAssistants();
void loadAssistants();
void updateToolOptionsUI();
/// send the color and opacity information from the UI to the kis_painting_decoration
/// which manages the assistants
void slotAssistantsColorChanged(const QColor&);
void slotAssistantOpacityChanged();
void slotGlobalAssistantsColorChanged(const QColor&);
void slotGlobalAssistantOpacityChanged();
void slotUpdateCustomColor();
void slotcustomOpacityChanged();
protected:
/// Draws the editor widget controls with move, activate, and delete
......@@ -148,8 +149,10 @@ private:
// what color and opacity will the assistants have
// all assistant types will share this setting
QColor m_assistantColor;
float m_assistantsOpacity;
QColor m_assistantGlobalColor;
float m_assistantsGlobalOpacity;
float m_assistantCustomOpacity;
};
......
......@@ -290,11 +290,10 @@ bool KisAnimationCurvesModel::adjustKeyframes(const QModelIndexList &indexes, in
KisImageBarrierLockerWithFeedback locker(image());
if (timeOffset != 0) {
bool ok = createOffsetFramesCommand(indexes, QPoint(timeOffset, 0), false, command.data());
bool ok = createOffsetFramesCommand(indexes, QPoint(timeOffset, 0), false, false, command.data());
if (!ok) return false;
}
using KisAnimationUtils::FrameItem;
using KisAnimationUtils::FrameItemList;
FrameItemList frameItems;
......
......@@ -174,18 +174,6 @@ namespace KisAnimationUtils {
std::sort(points->begin(), points->end(), LessOperator(offset));
}
KUndo2Command* createMoveKeyframesCommand(const FrameItemList &srcFrames,
const FrameItemList &dstFrames,
bool copy,
KUndo2Command *parentCommand) {
FrameMovePairList movedFrames;
for (int i = 0; i < srcFrames.size(); i++) {
movedFrames << std::make_pair(srcFrames[i], dstFrames[i]);
}
return createMoveKeyframesCommand(movedFrames, copy, parentCommand);
}
bool supportsContentFrames(KisNodeSP node)
{
return node->inherits("KisPaintLayer") || node->inherits("KisFilterMask") || node->inherits("KisTransparencyMask") || node->inherits("KisSelectionBasedLayer");
......@@ -202,19 +190,17 @@ namespace KisAnimationUtils {
KisKeyframeChannel *dstChannel = dstNode->getKeyframeChannel(dst.channel, true);
if (srcNode == dstNode) {
// TODO: add warning!
if (!srcChannel) return;
if (!srcChannel) return; // TODO: add warning!
srcChannel->swapFrames(srcTime, dstTime, parentCommand);
} else {
// TODO: add warning!
if (!srcChannel || !dstChannel) return;
if (!srcChannel || !dstChannel) return; // TODO: add warning!
dstChannel->swapExternalKeyframe(srcChannel, srcTime, dstTime, parentCommand);
}
}
void moveOneFrameItem(const FrameItem &src, const FrameItem &dst, bool copy, KUndo2Command *parentCommand)
void moveOneFrameItem(const FrameItem &src, const FrameItem &dst, bool copy, bool moveEmptyFrames, KUndo2Command *parentCommand)
{
const int srcTime = src.time;
KisNodeSP srcNode = src.node;
......@@ -225,24 +211,28 @@ namespace KisAnimationUtils {
KisKeyframeChannel *dstChannel = dstNode->getKeyframeChannel(dst.channel, true);
if (srcNode == dstNode) {
// TODO: add warning!
if (!srcChannel) return;
if (!srcChannel) return; // TODO: add warning!
KisKeyframeSP srcKeyframe = srcChannel->keyframeAt(srcTime);