<div dir="ltr">Sounds cool. Thanks for the feature<br></div><div class="gmail_extra"><br><div class="gmail_quote">2015-05-10 15:23 GMT+02:00 Dmitry Kazakov <span dir="ltr"><<a href="mailto:dimula73@gmail.com" target="_blank">dimula73@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Git commit 55d7eaebed3923da01150a38654df8a4fe3b199d by Dmitry Kazakov.<br>
Committed on 10/05/2015 at 13:23.<br>
Pushed by dkazakov into branch 'calligra/2.9'.<br>
<br>
[FEATURE] Add on-canvas preview of current color<br>
<br>
1) Now when activating color picker in the brush tool<br>
with Ctrl or any other shortcut, currently selected color<br>
will be displayed near the cursor on screen.<br>
<br>
2) If you start actual color-picking, the two colors will be<br>
compared side-by-side.<br>
<br>
BUG:338128<br>
Fixes task T206<br>
<a href="mailto:CC%3Akimageshop@kde.org">CC:kimageshop@kde.org</a><br>
<br>
M +10 -0 krita/ui/kis_config.cc<br>
M +3 -0 krita/ui/kis_config.h<br>
M +111 -8 krita/ui/tool/kis_tool_paint.cc<br>
M +14 -1 krita/ui/tool/kis_tool_paint.h<br>
<br>
<a href="http://commits.kde.org/calligra/55d7eaebed3923da01150a38654df8a4fe3b199d" target="_blank">http://commits.kde.org/calligra/55d7eaebed3923da01150a38654df8a4fe3b199d</a><br>
<br>
diff --git a/krita/ui/kis_config.cc b/krita/ui/kis_config.cc<br>
index f9f96c7..b409a3f 100644<br>
--- a/krita/ui/kis_config.cc<br>
+++ b/krita/ui/kis_config.cc<br>
@@ -324,6 +324,16 @@ void KisConfig::setNewOutlineStyle(OutlineStyle style)<br>
m_cfg.writeEntry("newOutlineStyle", (int)style);<br>
}<br>
<br>
+QRect KisConfig::colorPreviewRect() const<br>
+{<br>
+ return m_cfg.readEntry("colorPreviewRect", QVariant(QRect(32, 32, 48, 48))).toRect();<br>
+}<br>
+<br>
+void KisConfig::setColorPreviewRect(const QRect &rect)<br>
+{<br>
+ m_cfg.writeEntry("colorPreviewRect", QVariant(rect));<br>
+}<br>
+<br>
bool KisConfig::useDirtyPresets(bool defaultValue) const<br>
{<br>
return (defaultValue ? false : m_cfg.readEntry("useDirtyPresets",false));<br>
diff --git a/krita/ui/kis_config.h b/krita/ui/kis_config.h<br>
index f68f881..43f52f8 100644<br>
--- a/krita/ui/kis_config.h<br>
+++ b/krita/ui/kis_config.h<br>
@@ -105,6 +105,9 @@ public:<br>
OutlineStyle newOutlineStyle(bool defaultValue = false) const;<br>
void setNewOutlineStyle(OutlineStyle style);<br>
<br>
+ QRect colorPreviewRect() const;<br>
+ void setColorPreviewRect(const QRect &rect);<br>
+<br>
/// get the profile the user has selected for the given screen<br>
QString monitorProfile(int screen) const;<br>
void setMonitorProfile(int screen, const QString & monitorProfile, bool override) const;<br>
diff --git a/krita/ui/tool/kis_tool_paint.cc b/krita/ui/tool/kis_tool_paint.cc<br>
index 00aa2a1..0c6b528 100644<br>
--- a/krita/ui/tool/kis_tool_paint.cc<br>
+++ b/krita/ui/tool/kis_tool_paint.cc<br>
@@ -60,6 +60,7 @@<br>
#include <KisViewManager.h><br>
#include <kis_canvas2.h><br>
#include <kis_cubic_curve.h><br>
+#include "kis_display_color_converter.h"<br>
<br>
#include "kis_config.h"<br>
#include "kis_config_notifier.h"<br>
@@ -74,7 +75,8 @@<br>
<br>
KisToolPaint::KisToolPaint(KoCanvasBase * canvas, const QCursor & cursor)<br>
: KisTool(canvas, cursor),<br>
- m_isOutlineEnabled(false)<br>
+ m_showColorPreview(false),<br>
+ m_colorPreviewShowComparePlate(false)<br>
{<br>
m_specialHoverModifier = false;<br>
m_optionsWidgetLayout = 0;<br>
@@ -208,6 +210,16 @@ void KisToolPaint::paint(QPainter &gc, const KoViewConverter &converter)<br>
<br>
QPainterPath path = tryFixBrushOutline(pixelToView(m_currentOutline));<br>
paintToolOutline(&gc, path);<br>
+<br>
+ if (m_showColorPreview) {<br>
+ QRectF viewRect = converter.documentToView(m_oldColorPreviewRect);<br>
+ gc.fillRect(viewRect, m_colorPreviewCurrentColor);<br>
+<br>
+ if (m_colorPreviewShowComparePlate) {<br>
+ QRectF baseColorRect = viewRect.translated(viewRect.width(), 0);<br>
+ gc.fillRect(baseColorRect, m_colorPreviewBaseColor);<br>
+ }<br>
+ }<br>
}<br>
<br>
void KisToolPaint::setMode(ToolMode mode)<br>
@@ -222,22 +234,62 @@ void KisToolPaint::setMode(ToolMode mode)<br>
KisTool::setMode(mode);<br>
}<br>
<br>
+void KisToolPaint::activatePickColor(AlternateAction action)<br>
+{<br>
+ m_showColorPreview = true;<br>
+<br>
+ requestUpdateOutline(m_outlineDocPoint, 0);<br>
+<br>
+ int resource = colorPreviewResourceId(action);<br>
+ KoColor color = canvas()->resourceManager()->koColorResource(resource);<br>
+<br>
+ KisCanvas2 * kisCanvas = dynamic_cast<KisCanvas2*>(canvas());<br>
+ KIS_ASSERT_RECOVER_RETURN(kisCanvas);<br>
+<br>
+ m_colorPreviewCurrentColor = kisCanvas->displayColorConverter()->toQColor(color);<br>
+<br>
+ if (!m_colorPreviewBaseColor.isValid()) {<br>
+ m_colorPreviewBaseColor = m_colorPreviewCurrentColor;<br>
+ }<br>
+}<br>
+<br>
+void KisToolPaint::deactivatePickColor(AlternateAction action)<br>
+{<br>
+ Q_UNUSED(action);<br>
+<br>
+ m_showColorPreview = false;<br>
+ m_oldColorPreviewRect = QRect();<br>
+ m_oldColorPreviewUpdateRect = QRect();<br>
+ m_colorPreviewCurrentColor = QColor();<br>
+}<br>
+<br>
+void KisToolPaint::pickColorWasOverridden()<br>
+{<br>
+ m_colorPreviewShowComparePlate = false;<br>
+ m_colorPreviewBaseColor = QColor();<br>
+}<br>
+<br>
void KisToolPaint::activateAlternateAction(AlternateAction action)<br>
{<br>
switch (action) {<br>
case PickFgNode:<br>
useCursor(KisCursor::pickerLayerForegroundCursor());<br>
+ activatePickColor(action);<br>
break;<br>
case PickBgNode:<br>
useCursor(KisCursor::pickerLayerBackgroundCursor());<br>
+ activatePickColor(action);<br>
break;<br>
case PickFgImage:<br>
useCursor(KisCursor::pickerImageForegroundCursor());<br>
+ activatePickColor(action);<br>
break;<br>
case PickBgImage:<br>
useCursor(KisCursor::pickerImageBackgroundCursor());<br>
+ activatePickColor(action);<br>
break;<br>
default:<br>
+ pickColorWasOverridden();<br>
KisTool::activateAlternateAction(action);<br>
};<br>
}<br>
@@ -254,6 +306,7 @@ void KisToolPaint::deactivateAlternateAction(AlternateAction action)<br>
}<br>
<br>
resetCursorStyle();<br>
+ deactivatePickColor(action);<br>
}<br>
<br>
void KisToolPaint::beginAlternateAction(KoPointerEvent *event, AlternateAction action)<br>
@@ -271,6 +324,8 @@ void KisToolPaint::continueAlternateAction(KoPointerEvent *event, AlternateActio<br>
{<br>
if (!pickColor(event->point, action)) {<br>
KisTool::continueAlternateAction(event, action);<br>
+ } else {<br>
+ requestUpdateOutline(event->point, event);<br>
}<br>
}<br>
<br>
@@ -284,6 +339,15 @@ void KisToolPaint::endAlternateAction(KoPointerEvent *event, AlternateAction act<br>
}<br>
}<br>
<br>
+int KisToolPaint::colorPreviewResourceId(AlternateAction action)<br>
+{<br>
+ bool toForegroundColor = action == PickFgNode || action == PickFgImage;<br>
+ int resource = toForegroundColor ?<br>
+ KoCanvasResourceManager::ForegroundColor : KoCanvasResourceManager::BackgroundColor;<br>
+<br>
+ return resource;<br>
+}<br>
+<br>
bool KisToolPaint::pickColor(const QPointF &documentPixel,<br>
AlternateAction action)<br>
{<br>
@@ -295,11 +359,9 @@ bool KisToolPaint::pickColor(const QPointF &documentPixel,<br>
return false;<br>
}<br>
<br>
- bool toForegroundColor = action == PickFgNode || action == PickFgImage;<br>
bool fromCurrentNode = action == PickFgNode || action == PickBgNode;<br>
<br>
- int resource = toForegroundColor ?<br>
- KoCanvasResourceManager::ForegroundColor : KoCanvasResourceManager::BackgroundColor;<br>
+ int resource = colorPreviewResourceId(action);<br>
<br>
KisPaintDeviceSP device = fromCurrentNode ?<br>
currentNode()->projection() : image()->projection();<br>
@@ -307,10 +369,19 @@ bool KisToolPaint::pickColor(const QPointF &documentPixel,<br>
QPoint imagePoint = image()->documentToIntPixel(documentPixel);<br>
<br>
KoColor color;<br>
+ QColor previewColor;<br>
+<br>
if (KisToolUtils::pick(device, imagePoint, &color)) {<br>
canvas()->resourceManager()->setResource(resource, color);<br>
+<br>
+ KisCanvas2 * kisCanvas = dynamic_cast<KisCanvas2*>(canvas());<br>
+ KIS_ASSERT_RECOVER(kisCanvas) { return true; }<br>
+ previewColor = kisCanvas->displayColorConverter()->toQColor(color);<br>
}<br>
<br>
+ m_colorPreviewCurrentColor = previewColor;<br>
+ m_colorPreviewShowComparePlate = true;<br>
+<br>
return true;<br>
}<br>
<br>
@@ -496,6 +567,7 @@ KisToolPaint::NodePaintAbility KisToolPaint::nodePaintAbility()<br>
<br>
void KisToolPaint::activatePrimaryAction()<br>
{<br>
+ pickColorWasOverridden();<br>
setOutlineEnabled(true);<br>
}<br>
<br>
@@ -549,6 +621,18 @@ void KisToolPaint::decreaseBrushSize()<br>
requestUpdateOutline(m_outlineDocPoint, 0);<br>
}<br>
<br>
+QRectF KisToolPaint::colorPreviewDocRect(const QPointF &outlineDocPoint)<br>
+{<br>
+ if (!m_showColorPreview) return QRect();<br>
+<br>
+ KisConfig cfg;<br>
+<br>
+ const QRectF colorPreviewViewRect = cfg.colorPreviewRect();<br>
+ const QRectF colorPreviewDocumentRect = canvas()->viewConverter()->viewToDocument(colorPreviewViewRect);<br>
+<br>
+ return colorPreviewDocumentRect.translated(outlineDocPoint);<br>
+}<br>
+<br>
void KisToolPaint::requestUpdateOutline(const QPointF &outlineDocPoint, const KoPointerEvent *event)<br>
{<br>
if (!m_supportOutline) return;<br>
@@ -583,17 +667,36 @@ void KisToolPaint::requestUpdateOutline(const QPointF &outlineDocPoint, const Ko<br>
canvas()->viewConverter()->zoom(&zoomX, &zoomY);<br>
qreal xoffset = 2.0/zoomX;<br>
qreal yoffset = 2.0/zoomY;<br>
- QRectF newOutlineRect = outlineDocRect.adjusted(-xoffset,-yoffset,xoffset,yoffset);<br>
+<br>
+ if (!outlineDocRect.isEmpty()) {<br>
+ outlineDocRect.adjust(-xoffset,-yoffset,xoffset,yoffset);<br>
+ }<br>
+<br>
+ QRectF colorPreviewDocRect = this->colorPreviewDocRect(m_outlineDocPoint);<br>
+ QRectF colorPreviewDocUpdateRect;<br>
+ if (!colorPreviewDocRect.isEmpty()) {<br>
+ colorPreviewDocUpdateRect.adjust(-xoffset,-yoffset,xoffset,yoffset);<br>
+ }<br>
+<br>
+ if (!m_oldColorPreviewUpdateRect.isEmpty()) {<br>
+ canvas()->updateCanvas(m_oldColorPreviewUpdateRect);<br>
+ }<br>
<br>
if (!m_oldOutlineRect.isEmpty()) {<br>
canvas()->updateCanvas(m_oldOutlineRect);<br>
}<br>
<br>
- if (!newOutlineRect.isEmpty()) {<br>
- canvas()->updateCanvas(newOutlineRect);<br>
+ if (!outlineDocRect.isEmpty()) {<br>
+ canvas()->updateCanvas(outlineDocRect);<br>
+ }<br>
+<br>
+ if (!colorPreviewDocUpdateRect.isEmpty()) {<br>
+ canvas()->updateCanvas(colorPreviewDocUpdateRect);<br>
}<br>
<br>
- m_oldOutlineRect = newOutlineRect;<br>
+ m_oldOutlineRect = outlineDocRect;<br>
+ m_oldColorPreviewRect = colorPreviewDocRect;<br>
+ m_oldColorPreviewUpdateRect = colorPreviewDocUpdateRect;<br>
}<br>
<br>
QPainterPath KisToolPaint::getOutlinePath(const QPointF &documentPos,<br>
diff --git a/krita/ui/tool/kis_tool_paint.h b/krita/ui/tool/kis_tool_paint.h<br>
index b1c25da..48c1f35 100644<br>
--- a/krita/ui/tool/kis_tool_paint.h<br>
+++ b/krita/ui/tool/kis_tool_paint.h<br>
@@ -169,12 +169,25 @@ protected:<br>
QPointF m_outlineDocPoint;<br>
QPainterPath m_currentOutline;<br>
QRectF m_oldOutlineRect;<br>
- bool m_toForegroundColor;<br>
+<br>
+ bool m_showColorPreview;<br>
+ QRectF m_oldColorPreviewRect;<br>
+ QRectF m_oldColorPreviewUpdateRect;<br>
+ QColor m_colorPreviewCurrentColor;<br>
+ bool m_colorPreviewShowComparePlate;<br>
+ QColor m_colorPreviewBaseColor;<br>
<br>
private:<br>
QPainterPath tryFixBrushOutline(const QPainterPath &originalOutline);<br>
void setOpacity(qreal opacity);<br>
<br>
+ void activatePickColor(AlternateAction action);<br>
+ void deactivatePickColor(AlternateAction action);<br>
+ void pickColorWasOverridden();<br>
+<br>
+ int colorPreviewResourceId(AlternateAction action);<br>
+ QRectF colorPreviewDocRect(const QPointF &outlineDocPoint);<br>
+<br>
private:<br>
<br>
bool m_specialHoverModifier;<br>
_______________________________________________<br>
Krita mailing list<br>
<a href="mailto:kimageshop@kde.org">kimageshop@kde.org</a><br>
<a href="https://mail.kde.org/mailman/listinfo/kimageshop" target="_blank">https://mail.kde.org/mailman/listinfo/kimageshop</a><br>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature"><div dir="ltr"><div>_______________________________________<br>Ramón Miranda<br><a href="http://www.ramonmiranda.com" target="_blank">www.ramonmiranda.com</a><br></div>@ramonmva<br></div></div>
</div>