Skip to content

Commit

Permalink
Fixed editor's selection outline
Browse files Browse the repository at this point in the history
Merge branch 'fix-selection-outline' into develop
  • Loading branch information
riuson committed Feb 27, 2018
2 parents f1eac42 + 67275c5 commit 34d4b61
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
24 changes: 22 additions & 2 deletions classes/parser/convert/bitmaphelper.cpp
Expand Up @@ -22,6 +22,7 @@

#include <QPainter>
#include <QPainterPath>
#include <QPainterPathStroker>
#include <QtSvg/QSvgRenderer>

namespace Parsing
Expand Down Expand Up @@ -207,7 +208,7 @@ QImage BitmapHelper::drawGrid(const QImage *source, int scale)
return result;
}

QImage BitmapHelper::drawSelection(const QImage *source, const QPainterPath &selectedPath)
QImage BitmapHelper::drawSelection(const QImage *source, const QPainterPath &selectedPath, int scale)
{
QImage image = *source;
QPixmap pixmap = QPixmap::fromImage(image);
Expand All @@ -216,12 +217,31 @@ QImage BitmapHelper::drawSelection(const QImage *source, const QPainterPath &sel
QColor selectionBorderColor = QColor(0, 0, 248, 128);
QBrush selectionFillBrush(QColor(64, 128, 248, 128));

QTransform transform;
transform = transform.scale((float)scale, (float)scale);
painter.setTransform(transform);

painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
painter.setRenderHint(QPainter::Antialiasing, false);
painter.setRenderHint(QPainter::HighQualityAntialiasing, false);
painter.setPen(selectionBorderColor);
painter.setBrush(selectionFillBrush);
painter.drawPath(selectedPath);

painter.fillPath(selectedPath, selectionFillBrush);

if (scale > 5) {
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setRenderHint(QPainter::HighQualityAntialiasing, true);

QPainterPathStroker stroker;
float offset = 1.0f / (float)scale;
stroker.setWidth(offset * 2.0f);
stroker.setJoinStyle(Qt::RoundJoin);
stroker.setDashPattern(Qt::DashLine);

QPainterPath strokedPath = stroker.createStroke(selectedPath);
painter.fillPath(strokedPath, QBrush(selectionBorderColor));
}

return pixmap.toImage();
}
Expand Down
2 changes: 1 addition & 1 deletion classes/parser/convert/bitmaphelper.h
Expand Up @@ -55,7 +55,7 @@ class BitmapHelper
static void findEmptyArea(const QImage *source, int *left, int *top, int *right, int *bottom);
static QImage scale(const QImage *source, int scale);
static QImage drawGrid(const QImage *source, int scale);
static QImage drawSelection(const QImage *source, const QPainterPath &selectedPath);
static QImage drawSelection(const QImage *source, const QPainterPath &selectedPath, int scale);
static QImage drawPixel(const QImage *source, int x, int y, const QColor &color);
static QColor detectBackgroundColor(const QImage *image);
static QImage fromSvg(const QString &path, int size);
Expand Down
2 changes: 1 addition & 1 deletion controls/imageeditor/windoweditor.cpp
Expand Up @@ -185,9 +185,9 @@ void WindowEditor::updateImageScaled(int value)
if (!this->mImageOriginal.isNull()) {
QImage image = this->mImageOriginal;

image = Parsing::Conversion::BitmapHelper::drawSelection(&image, this->mTools->selectedPath());
image = Parsing::Conversion::BitmapHelper::scale(&image, value);
image = Parsing::Conversion::BitmapHelper::drawGrid(&image, value);
image = Parsing::Conversion::BitmapHelper::drawSelection(&image, this->mTools->selectedPath(), value);
this->mImageScaled = image;
this->mPixmapScaled = QPixmap::fromImage(image);

Expand Down
1 change: 1 addition & 0 deletions resources/history.xml
Expand Up @@ -19,6 +19,7 @@
<item category="fixed">Losing of empty parameters in Image settings block.</item>
<item category="fixed">Selection of template files in the settings.</item>
<item category="fixed">Clear the fill mask when changing the data block size.</item>
<item category="fixed">Editor's selection outline.</item>
<item category="removed">Support for Qt version &lt; 5.5.</item>
<item category="removed">Ability to hide toolbars.</item>
</changes>
Expand Down

0 comments on commit 34d4b61

Please sign in to comment.