diff --git a/CHANGELOG.md b/CHANGELOG.md index 85d0290..228f369 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,25 +1,26 @@ # Change log ## Release 0.1.0 * New: Double Arrow annotation tool. ([#23](https://github.com/DamirPorobic/kImageAnnotator/issues/23)) * New: Marker Rectangle and Ellipse annotation tool. ([#26](https://github.com/DamirPorobic/kImageAnnotator/issues/26)) * New: Add icons for dark theme. ([#37](https://github.com/DamirPorobic/kImageAnnotator/issues/37)) +* New: Add config option to setup blur radius. ([#25](https://github.com/DamirPorobic/kImageAnnotator/issues/25)) * Changed: Blur tool is now preciser and fits the rect. ([#28](https://github.com/DamirPorobic/kImageAnnotator/issues/28)) * Changed: Enter finishes text input and shift-enter adds new line in Text Tool. ([#30](https://github.com/DamirPorobic/kImageAnnotator/issues/30)) * Changed: Text item draws border around the text when in text edit mode. ([#34](https://github.com/DamirPorobic/kImageAnnotator/issues/34)) * Fixed: Double-click on annotation area causes SIGSEGV crash. ([#29](https://github.com/DamirPorobic/kImageAnnotator/issues/29)) * Fixed: CAPS LOCK doesnt work on image editor. ([#27](https://github.com/DamirPorobic/kImageAnnotator/issues/27)) * Fixed: Unable to select text item when clicking on text. ([#32](https://github.com/DamirPorobic/kImageAnnotator/issues/32)) * Fixed: Some blurs get removed when losing focus. ([#35](https://github.com/DamirPorobic/kImageAnnotator/issues/35)) * Fixed: Items cannot be resized when drawn from bottom right to top left. ([#38](https://github.com/DamirPorobic/kImageAnnotator/issues/38)) * Fixed: Right click on annotation items selects item but doesn't switch tool. ([#40](https://github.com/DamirPorobic/kImageAnnotator/issues/40)) * Fixed: Copy number annotation item doesn't increment number. ([#41](https://github.com/DamirPorobic/kImageAnnotator/issues/41)) ## Release 0.0.2 * New: Added blur annotation tool. ([#20](https://github.com/DamirPorobic/kImageAnnotator/issues/20)) * New: Keep number tool sequence consecutive after deleting item. ([#7](https://github.com/DamirPorobic/kImageAnnotator/issues/7)) * New: Added control for setting first number for numbering tool. ([#7](https://github.com/DamirPorobic/kImageAnnotator/issues/7)) * New: Text and Number tool have now noBorderAndNoFill type. ([#22](https://github.com/DamirPorobic/kImageAnnotator/issues/22)) ## Release 0.0.1 * New: Initial release \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6e0fa37..8fdd04f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,81 +1,82 @@ set(KIMAGEANNOTATOR_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/gui/KImageAnnotator.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/CoreView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/annotator/AnnotationWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/annotator/WidgetConfigurator.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/cropper/CropWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/cropper/CropView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/cropper/CropSelectionHandler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/cropper/CropSelectionRestrictor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/cropper/CropHandles.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/cropper/CropSelectionMoveHelper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/scaler/ScaleDialog.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/scaler/ScaleWidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gui/scaler/ScaleSizeHandler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/core/AnnotationArea.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/core/AnnotationItemFactory.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/core/AnnotationPropertiesFactory.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/properties/AnnotationProperties.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/properties/AnnotationPathProperties.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/properties/AnnotationTextProperties.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/annotations/properties/AnnotationBlurProperties.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/AnnotationItemModifier.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/AnnotationItemResizer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/AnnotationMultiItemResizer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/AnnotationItemSelector.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/AnnotationItemMover.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/AnnotationItemArranger.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/resizeHandles/AbstractItemResizeHandles.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/resizeHandles/AbstractRectResizeHandles.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/resizeHandles/LineResizeHandles.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/resizeHandles/RectResizeHandles.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/resizeHandles/PathResizeHandles.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/resizeHandles/ResizeHandle.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/modifiers/resizeHandles/ResizeHandlesFactory.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AbstractAnnotationItem.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AbstractAnnotationLine.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AbstractAnnotationRect.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AbstractAnnotationPath.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationLine.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationArrow.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationDoubleArrow.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationRect.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationEllipse.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationNumber.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationPen.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationText.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/AnnotationBlur.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/helper/KeyInputHelper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/helper/TextCursor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/items/helper/CapsLockStatusChecker.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/undo/AddCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/undo/DeleteCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/undo/MoveCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/undo/ResizeCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/undo/ArrangeCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/undo/CropCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/undo/ScaleCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/undo/PasteCommand.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/misc/ShadowEffect.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/misc/ImageBlurrer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/misc/AnnotationItemClipboard.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/misc/AnnotationContextMenu.cpp ${CMAKE_CURRENT_SOURCE_DIR}/annotations/misc/NumberManager.cpp ${CMAKE_CURRENT_SOURCE_DIR}/backend/Config.cpp ${CMAKE_CURRENT_SOURCE_DIR}/common/helper/CursorHelper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/common/helper/KeyHelper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/common/helper/MathHelper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/common/helper/ItemHelper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/common/helper/ShapeHelper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/common/helper/ConfigNameHelper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/common/helper/IconLoader.cpp ${CMAKE_CURRENT_SOURCE_DIR}/common/filter/IgnoreShortcutsFilter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/ToolPicker.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/ColorPicker.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/NumberPicker.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/FillTypePicker.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/CustomSpinBox.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/CustomToolButton.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/CustomToolButtonAction.cpp ) set(KIMAGEANNOTATOR_SRCS ${KIMAGEANNOTATOR_SRCS} PARENT_SCOPE) diff --git a/src/annotations/core/AnnotationPropertiesFactory.cpp b/src/annotations/core/AnnotationPropertiesFactory.cpp index 2bc2efc..532b1fb 100644 --- a/src/annotations/core/AnnotationPropertiesFactory.cpp +++ b/src/annotations/core/AnnotationPropertiesFactory.cpp @@ -1,121 +1,132 @@ /* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationPropertiesFactory.h" namespace kImageAnnotator { AnnotationPropertiesFactory::AnnotationPropertiesFactory(Config *config) { mConfig = config; } AnnotationProperties *AnnotationPropertiesFactory::create(ToolTypes toolType) const { auto properties = createPropertiesObject(toolType); setColor(properties, toolType); setTextColor(properties, toolType); setWidthSize(properties, toolType); setFill(properties, toolType); setShadowEnabled(properties, toolType); setPathProperties(properties); setTextProperties(properties, toolType); + setBlurProperties(properties); return properties; } AnnotationProperties *AnnotationPropertiesFactory::createPropertiesObject(ToolTypes toolType) const { switch (toolType) { case ToolTypes::Pen: case ToolTypes::MarkerPen: return new AnnotationPathProperties(); case ToolTypes::Number: case ToolTypes::Text: return new AnnotationTextProperties(); + case ToolTypes::Blur: + return new AnnotationBlurProperties(); default: return new AnnotationProperties(); } } void AnnotationPropertiesFactory::setColor(AnnotationProperties *properties, ToolTypes toolType) const { auto color = mConfig->toolColor(toolType); if (isMarkerTool(toolType)) { color.setAlpha(100); } properties->setColor(color); } void AnnotationPropertiesFactory::setTextColor(AnnotationProperties *properties, ToolTypes toolType) const { properties->setTextColor(mConfig->toolTextColor(toolType)); } void AnnotationPropertiesFactory::setWidthSize(AnnotationProperties *properties, ToolTypes toolType) const { auto width = mConfig->toolWidth(toolType); if (toolType == ToolTypes::MarkerPen) { width *= 3; } properties->setWidth(width); } void AnnotationPropertiesFactory::setFill(AnnotationProperties *properties, ToolTypes toolType) const { properties->setFillType(mConfig->toolFillType(toolType)); } void AnnotationPropertiesFactory::setShadowEnabled(AnnotationProperties *properties, ToolTypes toolType) const { if (toolType == ToolTypes::Blur || isMarkerTool(toolType)) { properties->setShadowEnabled(false); } else { properties->setShadowEnabled(mConfig->itemShadowEnabled()); } } void AnnotationPropertiesFactory::setPathProperties(AnnotationProperties *properties) const { auto pathProperties = dynamic_cast(properties); if (pathProperties != nullptr) { pathProperties->setSmoothPathEnabled(mConfig->smoothPathEnabled()); pathProperties->setSmoothFactor(mConfig->smoothFactor()); } } void AnnotationPropertiesFactory::setTextProperties(AnnotationProperties *properties, ToolTypes toolType) const { auto pathProperties = dynamic_cast(properties); if (pathProperties != nullptr) { pathProperties->setFont(mConfig->toolFont(toolType)); } } bool AnnotationPropertiesFactory::isMarkerTool(const ToolTypes &toolType) const { return toolType == ToolTypes::MarkerPen || toolType == ToolTypes::MarkerRect || toolType == ToolTypes::MarkerEllipse; } +void AnnotationPropertiesFactory::setBlurProperties(AnnotationProperties *properties) const +{ + auto pathProperties = dynamic_cast(properties); + if (pathProperties != nullptr) { + pathProperties->setRadius(mConfig->blurRadius()); + } +} + } // namespace kImageAnnotator diff --git a/src/annotations/core/AnnotationPropertiesFactory.h b/src/annotations/core/AnnotationPropertiesFactory.h index 91b1cc1..8086665 100644 --- a/src/annotations/core/AnnotationPropertiesFactory.h +++ b/src/annotations/core/AnnotationPropertiesFactory.h @@ -1,54 +1,56 @@ /* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONPROPERTIESFACTORY_H #define KIMAGEANNOTATOR_ANNOTATIONPROPERTIESFACTORY_H #include "src/annotations/properties/AnnotationProperties.h" #include "src/annotations/properties/AnnotationPathProperties.h" #include "src/annotations/properties/AnnotationTextProperties.h" +#include "src/annotations/properties/AnnotationBlurProperties.h" #include "src/backend/Config.h" #include "src/common/enum/ToolTypes.h" namespace kImageAnnotator { class AnnotationPropertiesFactory { public: explicit AnnotationPropertiesFactory(Config *config); ~AnnotationPropertiesFactory() = default; AnnotationProperties *create(ToolTypes toolType) const; private: Config *mConfig; AnnotationProperties *createPropertiesObject(ToolTypes toolType) const; void setShadowEnabled(AnnotationProperties *properties, ToolTypes toolType) const; void setColor(AnnotationProperties *properties, ToolTypes toolType) const; void setTextColor(AnnotationProperties *properties, ToolTypes toolType) const; void setWidthSize(AnnotationProperties *properties, ToolTypes toolType) const; void setFill(AnnotationProperties *properties, ToolTypes toolType) const; void setPathProperties(AnnotationProperties *properties) const; void setTextProperties(AnnotationProperties *properties, ToolTypes toolType) const; + void setBlurProperties(AnnotationProperties *properties) const; bool isMarkerTool(const ToolTypes &toolType) const; }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_ANNOTATIONPROPERTIESFACTORY_H diff --git a/src/annotations/items/AnnotationBlur.cpp b/src/annotations/items/AnnotationBlur.cpp index e49c437..13acf50 100644 --- a/src/annotations/items/AnnotationBlur.cpp +++ b/src/annotations/items/AnnotationBlur.cpp @@ -1,75 +1,80 @@ /* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AnnotationBlur.h" namespace kImageAnnotator { AnnotationBlur::AnnotationBlur(const QPointF &startPosition, AnnotationProperties *properties) : AbstractAnnotationRect(startPosition, properties) { } AnnotationBlur::AnnotationBlur(const AnnotationBlur &other) : AbstractAnnotationRect(other) { } ToolTypes AnnotationBlur::toolType() const { return ToolTypes::Blur; } +const AnnotationBlurProperties *AnnotationBlur::properties() const +{ + return dynamic_cast(AbstractAnnotationItem::properties()); +} + void AnnotationBlur::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) { // We need to update the image here, otherwise the scene is not ready // to be painted and we only draw the background if (mBlurUpdateRequired) { updateBlurredImage(); mBlurUpdateRequired = false; } painter->drawImage(mRect->normalized(), mBlurredImage); } void AnnotationBlur::updateShape() { mBlurUpdateRequired = true; QPainterPath path; path.addRect(*mRect); setShape(path); } void AnnotationBlur::updateBlurredImage() { auto parentScene = scene(); if (parentScene != nullptr) { auto sceneSize = parentScene->sceneRect().size().toSize(); QImage image(sceneSize, QImage::Format_ARGB32_Premultiplied); image.fill(Qt::transparent); QPainter imagePainter(&image); parentScene->render(&imagePainter); auto itemRect = mRect->normalized().toRect(); auto sceneBehindItem = image.copy(itemRect); - mBlurredImage = mItemBlurrer.blurred(sceneBehindItem, 10, false); + mBlurredImage = mItemBlurrer.blurred(sceneBehindItem, properties()->radius(), false); } } } // namespace kImageAnnotator diff --git a/src/annotations/items/AnnotationBlur.h b/src/annotations/items/AnnotationBlur.h index 28403a5..3692fa7 100644 --- a/src/annotations/items/AnnotationBlur.h +++ b/src/annotations/items/AnnotationBlur.h @@ -1,52 +1,54 @@ /* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONBLUR_H #define KIMAGEANNOTATOR_ANNOTATIONBLUR_H #include #include "AbstractAnnotationRect.h" #include "src/annotations/misc/ImageBlurrer.h" +#include "src/annotations/properties/AnnotationBlurProperties.h" namespace kImageAnnotator { class AnnotationBlur : public AbstractAnnotationRect { public: AnnotationBlur(const QPointF &startPosition, AnnotationProperties *properties); AnnotationBlur(const AnnotationBlur &other); ~AnnotationBlur() override = default; ToolTypes toolType() const override; + const AnnotationBlurProperties *properties() const override; protected: void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override; void updateShape() override; private: ImageBlurrer mItemBlurrer; QImage mBlurredImage; bool mBlurUpdateRequired; void updateBlurredImage(); }; } // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONBLUR_H diff --git a/src/annotations/properties/AnnotationTextProperties.h b/src/annotations/properties/AnnotationBlurProperties.cpp similarity index 53% copy from src/annotations/properties/AnnotationTextProperties.h copy to src/annotations/properties/AnnotationBlurProperties.cpp index 5d82953..362c597 100644 --- a/src/annotations/properties/AnnotationTextProperties.h +++ b/src/annotations/properties/AnnotationBlurProperties.cpp @@ -1,47 +1,44 @@ /* - * Copyright (C) 2018 Damir Porobic + * Copyright (C) 2019 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ -#ifndef KIMAGEANNOTATOR_ANNOTATIONTEXTPROPERTIES_H -#define KIMAGEANNOTATOR_ANNOTATIONTEXTPROPERTIES_H - -#include - -#include "AnnotationProperties.h" +#include "AnnotationBlurProperties.h" namespace kImageAnnotator { -class AnnotationTextProperties : public AnnotationProperties +AnnotationBlurProperties::AnnotationBlurProperties(const AnnotationBlurProperties &other) : AnnotationProperties(other) { -public: - AnnotationTextProperties() = default; - AnnotationTextProperties(const QColor &color, int size); - AnnotationTextProperties(const AnnotationTextProperties &other); - ~AnnotationTextProperties() override = default; - AnnotationTextProperties *clone() const override; + mRadius = other.mRadius; +} - QFont font() const; - void setFont(const QFont &font); +AnnotationBlurProperties *AnnotationBlurProperties::clone() const +{ + return new AnnotationBlurProperties(*this); +} -private: - QFont mFont; -}; +int AnnotationBlurProperties::radius() const +{ + return mRadius; +} +void AnnotationBlurProperties::setRadius(int radius) +{ + mRadius = radius; } -#endif //KIMAGEANNOTATOR_ANNOTATIONTEXTPROPERTIES_H +} // namespace kImageAnnotator \ No newline at end of file diff --git a/src/annotations/properties/AnnotationTextProperties.h b/src/annotations/properties/AnnotationBlurProperties.h similarity index 57% copy from src/annotations/properties/AnnotationTextProperties.h copy to src/annotations/properties/AnnotationBlurProperties.h index 5d82953..5ae8dc2 100644 --- a/src/annotations/properties/AnnotationTextProperties.h +++ b/src/annotations/properties/AnnotationBlurProperties.h @@ -1,47 +1,44 @@ /* - * Copyright (C) 2018 Damir Porobic + * Copyright (C) 2019 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ -#ifndef KIMAGEANNOTATOR_ANNOTATIONTEXTPROPERTIES_H -#define KIMAGEANNOTATOR_ANNOTATIONTEXTPROPERTIES_H - -#include +#ifndef KIMAGEANNOTATOR_ANNOTATIONBLURPROPERTIES_H +#define KIMAGEANNOTATOR_ANNOTATIONBLURPROPERTIES_H #include "AnnotationProperties.h" namespace kImageAnnotator { -class AnnotationTextProperties : public AnnotationProperties +class AnnotationBlurProperties : public AnnotationProperties { public: - AnnotationTextProperties() = default; - AnnotationTextProperties(const QColor &color, int size); - AnnotationTextProperties(const AnnotationTextProperties &other); - ~AnnotationTextProperties() override = default; - AnnotationTextProperties *clone() const override; + AnnotationBlurProperties() = default; + AnnotationBlurProperties(const AnnotationBlurProperties &other); + ~AnnotationBlurProperties() override = default; + AnnotationBlurProperties *clone() const override; - QFont font() const; - void setFont(const QFont &font); + int radius() const; + void setRadius(int radius); private: - QFont mFont; + int mRadius; }; -} +} // namespace kImageAnnotator -#endif //KIMAGEANNOTATOR_ANNOTATIONTEXTPROPERTIES_H +#endif //KIMAGEANNOTATOR_ANNOTATIONBLURPROPERTIES_H diff --git a/src/annotations/properties/AnnotationTextProperties.h b/src/annotations/properties/AnnotationTextProperties.h index 5d82953..a208360 100644 --- a/src/annotations/properties/AnnotationTextProperties.h +++ b/src/annotations/properties/AnnotationTextProperties.h @@ -1,47 +1,47 @@ /* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIMAGEANNOTATOR_ANNOTATIONTEXTPROPERTIES_H #define KIMAGEANNOTATOR_ANNOTATIONTEXTPROPERTIES_H #include #include "AnnotationProperties.h" namespace kImageAnnotator { class AnnotationTextProperties : public AnnotationProperties { public: AnnotationTextProperties() = default; AnnotationTextProperties(const QColor &color, int size); AnnotationTextProperties(const AnnotationTextProperties &other); ~AnnotationTextProperties() override = default; AnnotationTextProperties *clone() const override; QFont font() const; void setFont(const QFont &font); private: QFont mFont; }; -} +} // namespace kImageAnnotator #endif //KIMAGEANNOTATOR_ANNOTATIONTEXTPROPERTIES_H diff --git a/src/backend/Config.cpp b/src/backend/Config.cpp index 0d74652..2836786 100644 --- a/src/backend/Config.cpp +++ b/src/backend/Config.cpp @@ -1,487 +1,487 @@ /* * Copyright (C) 2018 Damir Porobic * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "Config.h" namespace kImageAnnotator { Config::Config() { mAllTools = QList{ ToolTypes::Pen, ToolTypes::MarkerPen, ToolTypes::MarkerRect, ToolTypes::MarkerEllipse, ToolTypes::Line, ToolTypes::Arrow, ToolTypes::DoubleArrow, ToolTypes::Rect, ToolTypes::Ellipse, ToolTypes::Number, ToolTypes::Text, ToolTypes::Blur }; initGeneralSettings(); initToolSettings(); } ToolTypes Config::selectedTool() const { return mSelectTool; } void Config::setSelectedTool(ToolTypes tool) { if (selectedTool() == tool) { return; } mSelectTool = tool; saveToolType(tool); emit toolChanged(tool); } QColor Config::toolColor(ToolTypes tool) const { return mToolToColor[tool]; } void Config::setToolColor(const QColor &color, ToolTypes tool) { if (toolColor(tool) == color) { return; } mToolToColor[tool] = color; saveToolColor(tool, color); } QColor Config::toolTextColor(ToolTypes tool) const { return mToolToTextColor[tool]; } void Config::setToolTextColor(const QColor &color, ToolTypes tool) { if (toolTextColor(tool) == color) { return; } mToolToTextColor[tool] = color; saveToolTextColor(tool, color); } int Config::toolWidth(ToolTypes tool) const { return mToolToWidth[tool]; } void Config::setToolWidth(int size, ToolTypes tool) { if (toolWidth(tool) == size) { return; } mToolToWidth[tool] = size; saveToolWidth(tool, size); } FillTypes Config::toolFillType(ToolTypes tool) const { return mToolToFillType[tool]; } void Config::setToolFillType(FillTypes fillType, ToolTypes tool) { if (toolFillType(tool) == fillType) { return; } mToolToFillType[tool] = fillType; saveToolFillType(tool, fillType); } QFont Config::toolFont(ToolTypes toolType) const { return mToolToFont[toolType]; } void Config::setToolFont(const QFont &font, ToolTypes toolType) { auto tmpFont = font; tmpFont.setPointSize(toolFontSize(toolType)); if (toolFont(toolType) == tmpFont) { return; } mToolToFont[toolType] = tmpFont; } int Config::toolFontSize(ToolTypes toolType) const { return mToolToFont[toolType].pointSize(); } void Config::setToolFontSize(int fontSize, ToolTypes toolType) { if (toolFontSize(toolType) == fontSize) { return; } mToolToFont[toolType].setPointSize(fontSize); saveToolFontSize(toolType, fontSize); } bool Config::itemShadowEnabled() const { return mItemShadowEnabled; } void Config::setItemShadowEnabled(bool enabled) { mItemShadowEnabled = enabled; } bool Config::smoothPathEnabled() const { return mSmoothPathEnabled; } void Config::setSmoothPathEnabled(bool enabled) { mSmoothPathEnabled = enabled; } void Config::setSaveToolSelection(bool enabled) { if (mSaveToolSelection == enabled) { return; } mSaveToolSelection = enabled; initToolSettings(); } int Config::smoothFactor() const { return mSmoothFactor; } void Config::setSmoothFactor(int factor) { mSmoothFactor = factor; } void Config::setFirstBadgeNumber(int number) { if (mFirstBadgeNumber != number) { mFirstBadgeNumber = number; emit firstBadgeNumberChanged(number); } } int Config::blurRadius() const { return mBlurRadius; } void Config::setBlurRadius(int radius) { if (blurRadius() == radius) { return; } mBlurRadius = radius; saveBlurRadius(radius); } // Private Methods void Config::initToolSettings() { initSelectedTool(); initToolColors(); initToolTextColors(); initToolWidths(); initToolFillTypes(); initToolFonts(); initBlurRadius(); emit loaded(); } void Config::initSelectedTool() { mSelectTool = loadToolType(); }; void Config::initToolColors() { for (auto toolType : mAllTools) { mToolToColor[toolType] = loadToolColor(toolType); } } void Config::initToolTextColors() { for (auto toolType : mAllTools) { mToolToTextColor[toolType] = loadToolTextColor(toolType); } } void Config::initToolWidths() { for (auto toolType : mAllTools) { mToolToWidth[toolType] = loadToolWidth(toolType); } } void Config::initToolFillTypes() { for (auto toolType : mAllTools) { mToolToFillType[toolType] = loadToolFillType(toolType); } } void Config::initToolFonts() { mToolToFont[ToolTypes::Text] = QFont(QStringLiteral("Times"), loadToolFontSize(ToolTypes::Text), QFont::Bold); mToolToFont[ToolTypes::Number] = QFont(QStringLiteral("Helvetica"), loadToolFontSize(ToolTypes::Number), QFont::Bold); } void Config::initBlurRadius() { mBlurRadius = loadBlurRadius(); } void Config::initGeneralSettings() { mSaveToolSelection = false; mSmoothPathEnabled = true; mItemShadowEnabled = true; mSmoothFactor = 7; mFirstBadgeNumber = 1; } QColor Config::loadToolColor(ToolTypes toolType) { if (mSaveToolSelection) { return mConfig.value(ConfigNameHelper::toolColor(toolType), defaultToolColor(toolType)).value(); } else { return defaultToolColor(toolType); } } void Config::saveToolColor(ToolTypes toolType, const QColor &color) { if (mSaveToolSelection) { mConfig.setValue(ConfigNameHelper::toolColor(toolType), color); mConfig.sync(); } } QColor Config::loadToolTextColor(ToolTypes toolType) { if (mSaveToolSelection) { return mConfig.value(ConfigNameHelper::toolTextColor(toolType), defaultToolTextColor(toolType)).value(); } else { return defaultToolTextColor(toolType); } } void Config::saveToolTextColor(ToolTypes toolType, const QColor &color) { if (mSaveToolSelection) { mConfig.setValue(ConfigNameHelper::toolTextColor(toolType), color); mConfig.sync(); } } int Config::loadToolWidth(ToolTypes toolType) { if (mSaveToolSelection) { return mConfig.value(ConfigNameHelper::toolWidth(toolType), defaultToolWidth(toolType)).value(); } else { return defaultToolWidth(toolType); } } void Config::saveToolWidth(ToolTypes toolType, int size) { if (mSaveToolSelection) { mConfig.setValue(ConfigNameHelper::toolWidth(toolType), size); mConfig.sync(); } } FillTypes Config::loadToolFillType(ToolTypes toolType) { if (mSaveToolSelection) { return mConfig.value(ConfigNameHelper::toolFillType(toolType), static_cast(defaultToolFillType(toolType))).value(); } else { return defaultToolFillType(toolType); } } void Config::saveToolFillType(ToolTypes toolType, FillTypes fillType) { if (mSaveToolSelection) { mConfig.setValue(ConfigNameHelper::toolFillType(toolType), static_cast(fillType)); mConfig.sync(); } } ToolTypes Config::loadToolType() { if (mSaveToolSelection) { return mConfig.value(ConfigNameHelper::toolType(), static_cast(defaultToolType())).value(); } else { return defaultToolType(); } } void Config::saveToolType(ToolTypes toolType) { if (mSaveToolSelection) { mConfig.setValue(ConfigNameHelper::toolType(), static_cast(toolType)); mConfig.sync(); } } int Config::loadToolFontSize(ToolTypes toolType) { if (mSaveToolSelection) { return mConfig.value(ConfigNameHelper::toolFontSize(toolType), defaultToolFontSize(toolType)).value(); } else { return defaultToolFontSize(toolType); } } void Config::saveToolFontSize(ToolTypes toolType, int fontSize) { if (mSaveToolSelection) { mConfig.setValue(ConfigNameHelper::toolFontSize(toolType), fontSize); mConfig.sync(); } } int Config::loadBlurRadius() { if (mSaveToolSelection) { return mConfig.value(ConfigNameHelper::blurRadius(), defaultBlurRadius()).value(); } else { return defaultBlurRadius(); } } void Config::saveBlurRadius(int radius) { if (mSaveToolSelection) { mConfig.setValue(ConfigNameHelper::blurRadius(), radius); mConfig.sync(); } } QColor Config::defaultToolColor(ToolTypes toolType) const { switch (toolType) { case ToolTypes::MarkerPen: case ToolTypes::MarkerRect: case ToolTypes::MarkerEllipse: return { Qt::yellow }; case ToolTypes::Line: return { Qt::blue }; case ToolTypes::Rect: return { Qt::gray }; case ToolTypes::Text: return { Qt::black }; case ToolTypes::Blur: return { Qt::white }; default: return { Qt::red }; } } QColor Config::defaultToolTextColor(ToolTypes toolType) const { switch (toolType) { case ToolTypes::Text: case ToolTypes::Number: return { Qt::white }; default: return { Qt::blue }; } } int Config::defaultToolWidth(ToolTypes toolType) const { switch (toolType) { case ToolTypes::MarkerPen: return 10; case ToolTypes::Arrow: case ToolTypes::DoubleArrow: return 6; case ToolTypes::Number: return 5; case ToolTypes::Text: return 2; default: return 3; } } FillTypes Config::defaultToolFillType(ToolTypes toolType) const { switch (toolType) { case ToolTypes::Arrow: case ToolTypes::DoubleArrow: case ToolTypes::Rect: case ToolTypes::Number: case ToolTypes::Blur: return FillTypes::BorderAndFill; case ToolTypes::MarkerRect: case ToolTypes::MarkerEllipse: return FillTypes::NoBorderAndFill; default: return FillTypes::BorderAndNoFill; } } ToolTypes Config::defaultToolType() { return ToolTypes::Pen; } int Config::defaultToolFontSize(ToolTypes toolType) const { switch (toolType) { case ToolTypes::Text: return 15; case ToolTypes::Number: return 20; default: return 10; } } int Config::defaultBlurRadius() const { - return 7; + return 10; } } // namespace kImageAnnotator