diff --git a/src/gui/annotator/WidgetConfigurator.cpp b/src/gui/annotator/WidgetConfigurator.cpp index 9108c6b..e574b98 100644 --- a/src/gui/annotator/WidgetConfigurator.cpp +++ b/src/gui/annotator/WidgetConfigurator.cpp @@ -1,253 +1,254 @@ /* * 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 "WidgetConfigurator.h" namespace kImageAnnotator { WidgetConfigurator::WidgetConfigurator() { mColorWidget = nullptr; mTextColorWidget = nullptr; mWidthWidget = nullptr; mFillTypeWidget = nullptr; mFontSizeWidget = nullptr; mFirstNumberWidget = nullptr; + mBlurRadiusWidget = nullptr; mCurrentTool = ToolTypes::Select; } void WidgetConfigurator::setCurrentTool(ToolTypes tool) { if (mCurrentTool == tool) { return; } mCurrentTool = tool; updateWidgets(); } void WidgetConfigurator::setColorWidget(ColorPicker *widget) { mColorWidget = widget; updateWidgets(); } void WidgetConfigurator::setTextColorWidget(ColorPicker *widget) { mTextColorWidget = widget; updateWidgets(); } void WidgetConfigurator::setWidthWidget(NumberPicker *widget) { mWidthWidget = widget; updateWidgets(); } void WidgetConfigurator::setFillTypeWidget(FillTypePicker *widget) { mFillTypeWidget = widget; updateWidgets(); } void WidgetConfigurator::setFontSizeWidget(NumberPicker *widget) { mFontSizeWidget = widget; updateWidgets(); } void WidgetConfigurator::setFirstNumberWidget(NumberPicker *widget) { mFirstNumberWidget = widget; updateWidgets(); } void WidgetConfigurator::setBlurRadiusWidget(NumberPicker *widget) { mBlurRadiusWidget = widget; updateWidgets(); } -void WidgetConfigurator::updateWidgets() +void WidgetConfigurator::updateWidgets() const { updateProperties(); updateVisibility(); } -void WidgetConfigurator::updateProperties() +void WidgetConfigurator::updateProperties() const { switch (mCurrentTool) { case ToolTypes::Text: case ToolTypes::Number: setNoFillAndNoBorderEnabled(true); break; default: setNoFillAndNoBorderEnabled(false); } } -void WidgetConfigurator::setNoFillAndNoBorderEnabled(bool enabled) const -{ - if (mFillTypeWidget == nullptr) { - return; - } - - if (enabled) { - mFillTypeWidget->addNoFillAndNoBorderToList(); - } else { - mFillTypeWidget->removeNoFillAndNoBorderToList(); - } -} - -void WidgetConfigurator::updateVisibility() +void WidgetConfigurator::updateVisibility() const { switch (mCurrentTool) { case ToolTypes::Select: setColorWidgetEnabled(false); setTextColorWidgetEnabled(false); setWidthWidgetEnabled(false); setFillWidgetEnabled(false); setFontSizeWidgetEnabled(false); setFirstNumberWidgetEnabled(false); setBlurRadiusWidgetEnabled(false); break; case ToolTypes::Pen: case ToolTypes::MarkerPen: setColorWidgetEnabled(true); setTextColorWidgetEnabled(false); setWidthWidgetEnabled(true); setFillWidgetEnabled(false); setFontSizeWidgetEnabled(false); setFirstNumberWidgetEnabled(false); setBlurRadiusWidgetEnabled(false); break; case ToolTypes::MarkerRect: case ToolTypes::MarkerEllipse: setColorWidgetEnabled(true); setTextColorWidgetEnabled(false); setWidthWidgetEnabled(false); setFillWidgetEnabled(false); setFontSizeWidgetEnabled(false); setFirstNumberWidgetEnabled(false); setBlurRadiusWidgetEnabled(false); break; case ToolTypes::Line: case ToolTypes::Arrow: case ToolTypes::DoubleArrow: setColorWidgetEnabled(true); setTextColorWidgetEnabled(false); setWidthWidgetEnabled(true); setFillWidgetEnabled(false); setFontSizeWidgetEnabled(false); setFirstNumberWidgetEnabled(false); setBlurRadiusWidgetEnabled(false); break; case ToolTypes::Ellipse: case ToolTypes::Rect: setColorWidgetEnabled(true); setTextColorWidgetEnabled(false); setWidthWidgetEnabled(true); setFillWidgetEnabled(true); setFontSizeWidgetEnabled(false); setFirstNumberWidgetEnabled(false); setBlurRadiusWidgetEnabled(false); break; case ToolTypes::Number: setColorWidgetEnabled(true); setTextColorWidgetEnabled(true); setWidthWidgetEnabled(true); setFillWidgetEnabled(true); setFontSizeWidgetEnabled(true); setFirstNumberWidgetEnabled(true); setBlurRadiusWidgetEnabled(false); break; case ToolTypes::Text: setColorWidgetEnabled(true); setTextColorWidgetEnabled(true); setWidthWidgetEnabled(true); setFillWidgetEnabled(true); setFontSizeWidgetEnabled(true); setFirstNumberWidgetEnabled(false); setBlurRadiusWidgetEnabled(false); break; case ToolTypes::Blur: setColorWidgetEnabled(false); setTextColorWidgetEnabled(false); setWidthWidgetEnabled(false); setFillWidgetEnabled(false); setFontSizeWidgetEnabled(false); setFirstNumberWidgetEnabled(false); setBlurRadiusWidgetEnabled(true); break; default: qCritical("Unknown tooltype in WidgetConfigurator"); } } -void WidgetConfigurator::setColorWidgetEnabled(bool enabled) +void WidgetConfigurator::setColorWidgetEnabled(bool enabled) const { if (mColorWidget) { mColorWidget->setEnabled(enabled); } } -void WidgetConfigurator::setTextColorWidgetEnabled(bool enabled) +void WidgetConfigurator::setTextColorWidgetEnabled(bool enabled) const { if (mTextColorWidget) { mTextColorWidget->setEnabled(enabled); } } -void WidgetConfigurator::setWidthWidgetEnabled(bool enabled) +void WidgetConfigurator::setWidthWidgetEnabled(bool enabled) const { if (mWidthWidget) { mWidthWidget->setEnabled(enabled); } } -void WidgetConfigurator::setFillWidgetEnabled(bool enabled) +void WidgetConfigurator::setFillWidgetEnabled(bool enabled) const { if (mFillTypeWidget) { mFillTypeWidget->setEnabled(enabled); } } -void WidgetConfigurator::setFontSizeWidgetEnabled(bool enabled) +void WidgetConfigurator::setFontSizeWidgetEnabled(bool enabled) const { if (mFontSizeWidget) { mFontSizeWidget->setEnabled(enabled); } } -void WidgetConfigurator::setFirstNumberWidgetEnabled(bool enabled) +void WidgetConfigurator::setFirstNumberWidgetEnabled(bool enabled) const { if (mFirstNumberWidget) { mFirstNumberWidget->setEnabled(enabled); } } +void WidgetConfigurator::setNoFillAndNoBorderEnabled(bool enabled) const +{ + if (mFillTypeWidget == nullptr) { + return; + } + + if (enabled) { + mFillTypeWidget->addNoFillAndNoBorderToList(); + } else { + mFillTypeWidget->removeNoFillAndNoBorderToList(); + } +} + void WidgetConfigurator::setBlurRadiusWidgetEnabled(bool enabled) const { if (mBlurRadiusWidget) { mBlurRadiusWidget->setEnabled(enabled); } } } // namespace kImageAnnotator diff --git a/src/gui/annotator/WidgetConfigurator.h b/src/gui/annotator/WidgetConfigurator.h index 4cd0587..eb938ee 100644 --- a/src/gui/annotator/WidgetConfigurator.h +++ b/src/gui/annotator/WidgetConfigurator.h @@ -1,72 +1,72 @@ /* * 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_WIDGETCONFIGURATORSWITCHER_H #define KIMAGEANNOTATOR_WIDGETCONFIGURATORSWITCHER_H #include #include "src/common/enum/ToolTypes.h" #include "src/widgets/ColorPicker.h" #include "src/widgets/FillTypePicker.h" #include "src/widgets/ToolPicker.h" #include "src/widgets/NumberPicker.h" namespace kImageAnnotator { class WidgetConfigurator { public: explicit WidgetConfigurator(); ~WidgetConfigurator() = default; void setCurrentTool(ToolTypes tool); void setColorWidget(ColorPicker *widget); void setTextColorWidget(ColorPicker *widget); void setWidthWidget(NumberPicker *widget); void setFillTypeWidget(FillTypePicker *widget); void setFontSizeWidget(NumberPicker *widget); void setFirstNumberWidget(NumberPicker *widget); void setBlurRadiusWidget(NumberPicker *widget); private: ToolTypes mCurrentTool; ColorPicker *mColorWidget; ColorPicker *mTextColorWidget; NumberPicker *mWidthWidget; FillTypePicker *mFillTypeWidget; NumberPicker *mFontSizeWidget; NumberPicker *mFirstNumberWidget; NumberPicker *mBlurRadiusWidget; - void updateWidgets(); - void updateProperties(); - void updateVisibility(); - void setColorWidgetEnabled(bool enabled); - void setTextColorWidgetEnabled(bool enabled); - void setWidthWidgetEnabled(bool enabled); - void setFillWidgetEnabled(bool enabled); - void setFontSizeWidgetEnabled(bool enabled); - void setFirstNumberWidgetEnabled(bool enabled); + void updateWidgets() const; + void updateProperties() const; + void updateVisibility() const; + void setColorWidgetEnabled(bool enabled) const; + void setTextColorWidgetEnabled(bool enabled) const; + void setWidthWidgetEnabled(bool enabled) const; + void setFillWidgetEnabled(bool enabled) const; + void setFontSizeWidgetEnabled(bool enabled) const; + void setFirstNumberWidgetEnabled(bool enabled) const; void setNoFillAndNoBorderEnabled(bool enabled) const; void setBlurRadiusWidgetEnabled(bool enabled) const; }; } // namespace kImageAnnotator #endif // KIMAGEANNOTATOR_WIDGETCONFIGURATORSWITCHER_H