diff --git a/plugins/tools/defaulttool/referenceimagestool/ToolReferenceImagesWidget.cpp b/plugins/tools/defaulttool/referenceimagestool/ToolReferenceImagesWidget.cpp index 506a302c20..efa2de987c 100644 --- a/plugins/tools/defaulttool/referenceimagestool/ToolReferenceImagesWidget.cpp +++ b/plugins/tools/defaulttool/referenceimagestool/ToolReferenceImagesWidget.cpp @@ -1,176 +1,213 @@ /* * Copyright (c) 2017 Eugene Ingerman * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU 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 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 "ToolReferenceImagesWidget.h" #include "ui_WdgToolOptions.h" #include #include #include #include #include #include #include "ToolReferenceImages.h" struct ToolReferenceImagesWidget::Private { Private(ToolReferenceImages *tool) : tool(tool) { } Ui_WdgToolOptions *ui; ToolReferenceImages *tool; }; ToolReferenceImagesWidget::ToolReferenceImagesWidget(ToolReferenceImages *tool, KisCanvasResourceProvider */*provider*/, QWidget *parent) : QWidget(parent), d(new Private(tool)) { d->ui = new Ui_WdgToolOptions(); d->ui->setupUi(this); d->ui->opacitySlider->setRange(0, 100); d->ui->opacitySlider->setPrefixes(i18n("Opacity: "), i18n("Opacity [*varies*]: ")); d->ui->opacitySlider->setSuffix(i18n(" %")); d->ui->opacitySlider->setValueGetter( [](KoShape *s){ return 100.0 * (1.0 - s->transparency()); } ); d->ui->saturationSlider->setRange(0, 100); d->ui->saturationSlider->setPrefixes(i18n("Saturation: "), i18n("Saturation [*varies*]: ")); d->ui->saturationSlider->setSuffix(i18n(" %")); d->ui->saturationSlider->setValueGetter( [](KoShape *s){ auto *r = dynamic_cast(s); KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(r, 0.0); return 100.0 * r->saturation(); } ); + d->ui->bnAddReferenceImage->setToolTip(i18n("Add Reference Image")); + d->ui->bnAddReferenceImage->setIcon(KisIconUtils::loadIcon("addlayer")); + + + d->ui->bnDelete->setToolTip(i18n("Delete all Reference Images")); + d->ui->bnDelete->setIcon(KisIconUtils::loadIcon("edit-clear")); + + d->ui->bnLoad->setToolTip(i18n("Load Reference Images Set")); + d->ui->bnLoad->setIcon(KisIconUtils::loadIcon("document-open")); + + + d->ui->bnSave->setToolTip(i18n("Export Reference Images Set")); + d->ui->bnSave->setIcon(KisIconUtils::loadIcon("document-save")); + + + + connect(d->ui->bnAddReferenceImage, SIGNAL(clicked()), tool, SLOT(addReferenceImage())); connect(d->ui->bnDelete, SIGNAL(clicked()), tool, SLOT(removeAllReferenceImages())); connect(d->ui->bnSave, SIGNAL(clicked()), tool, SLOT(saveReferenceImages())); connect(d->ui->bnLoad, SIGNAL(clicked()), tool, SLOT(loadReferenceImages())); connect(d->ui->chkKeepAspectRatio, SIGNAL(stateChanged(int)), this, SLOT(slotKeepAspectChanged())); connect(d->ui->opacitySlider, SIGNAL(valueChanged(qreal)), this, SLOT(slotOpacitySliderChanged(qreal))); connect(d->ui->saturationSlider, SIGNAL(valueChanged(qreal)), this, SLOT(slotSaturationSliderChanged(qreal))); - connect(d->ui->radioEmbed, SIGNAL(toggled(bool)), this, SLOT(slotEmbeddingChanged())); - connect(d->ui->radioLinkExternal, SIGNAL(toggled(bool)), this, SLOT(slotEmbeddingChanged())); + d->ui->referenceImageLocationCombobox->addItem(i18n("Embed to .KRA")); + d->ui->referenceImageLocationCombobox->addItem(i18n("Link to Image")); + connect(d->ui->referenceImageLocationCombobox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSaveLocationChanged(int))); + + updateVisibility(false); // no selection when we start } ToolReferenceImagesWidget::~ToolReferenceImagesWidget() { } void ToolReferenceImagesWidget::selectionChanged(KoSelection *selection) { QList shapes = selection->selectedEditableShapes(); d->ui->opacitySlider->setSelection(shapes); d->ui->saturationSlider->setSelection(shapes); bool anyKeepingAspectRatio = false; bool anyNotKeepingAspectRatio = false; bool anyEmbedded = false; bool anyLinked = false; bool anyNonLinkable = false; bool anySelected = selection->count() > 0; Q_FOREACH(KoShape *shape, shapes) { KisReferenceImage *reference = dynamic_cast(shape); anyKeepingAspectRatio |= shape->keepAspectRatio(); anyNotKeepingAspectRatio |= !shape->keepAspectRatio(); if (reference) { anyEmbedded |= reference->embed(); anyLinked |= !reference->embed(); anyNonLinkable |= !reference->hasLocalFile(); } } KisSignalsBlocker blocker( d->ui->chkKeepAspectRatio, - d->ui->radioEmbed, - d->ui->radioLinkExternal + d->ui->referenceImageLocationCombobox ); d->ui->chkKeepAspectRatio->setCheckState( (anyKeepingAspectRatio && anyNotKeepingAspectRatio) ? Qt::PartiallyChecked : anyKeepingAspectRatio ? Qt::Checked : Qt::Unchecked); - d->ui->radioEmbed->setChecked(anyEmbedded && !anyLinked); - d->ui->radioLinkExternal->setChecked(anyLinked && !anyEmbedded); - d->ui->radioEmbed->setEnabled(!anyNonLinkable && anySelected); - d->ui->radioLinkExternal->setEnabled(!anyNonLinkable && anySelected); - d->ui->chkKeepAspectRatio->setEnabled(anySelected); + + // set save location combobox + bool imagesEmbedded = anyEmbedded && !anyLinked; + int comboBoxIndex = imagesEmbedded ? 0 : 1; // maps state to combobox index + d->ui->referenceImageLocationCombobox->setCurrentIndex(comboBoxIndex); + + + updateVisibility(anySelected); } void ToolReferenceImagesWidget::slotKeepAspectChanged() { KoSelection *selection = d->tool->koSelection(); QList shapes = selection->selectedEditableShapes(); KUndo2Command *cmd = new KoShapeKeepAspectRatioCommand(shapes, d->ui->chkKeepAspectRatio->isChecked()); d->tool->canvas()->addCommand(cmd); } void ToolReferenceImagesWidget::slotOpacitySliderChanged(qreal newOpacity) { QList shapes = d->ui->opacitySlider->selection(); if (shapes.isEmpty()) return; KUndo2Command *cmd = new KoShapeTransparencyCommand(shapes, 1.0 - newOpacity / 100.0); d->tool->canvas()->addCommand(cmd); } void ToolReferenceImagesWidget::slotSaturationSliderChanged(qreal newSaturation) { QList shapes = d->ui->saturationSlider->selection(); if (shapes.isEmpty()) return; KUndo2Command *cmd = new KisReferenceImage::SetSaturationCommand(shapes, newSaturation / 100.0); d->tool->canvas()->addCommand(cmd); } -void ToolReferenceImagesWidget::slotEmbeddingChanged() +void ToolReferenceImagesWidget::slotSaveLocationChanged(int index) { KoSelection *selection = d->tool->koSelection(); QList shapes = selection->selectedEditableShapes(); + Q_FOREACH(KoShape *shape, shapes) { KisReferenceImage *reference = dynamic_cast(shape); KIS_SAFE_ASSERT_RECOVER_RETURN(reference); - if (d->ui->radioEmbed->isChecked()) { + if (index == 0) { // embed to KRA reference->setEmbed(true); - } else if (d->ui->radioLinkExternal->isChecked()) { + } else { // link to file reference->setEmbed(false); } } } + +void ToolReferenceImagesWidget::updateVisibility(bool hasSelection) +{ + // hide UI elements if nothing is selected. + d->ui->referenceImageLocationCombobox->setVisible(hasSelection); + d->ui->chkKeepAspectRatio->setVisible(hasSelection); + d->ui->saveLocationLabel->setVisible(hasSelection); + d->ui->opacitySlider->setVisible(hasSelection); + d->ui->saturationSlider->setVisible(hasSelection); + + // show a label indicating that a selection is required to show options + d->ui->referenceImageOptionsLabel->setVisible(!hasSelection); + +} diff --git a/plugins/tools/defaulttool/referenceimagestool/ToolReferenceImagesWidget.h b/plugins/tools/defaulttool/referenceimagestool/ToolReferenceImagesWidget.h index b891fd892e..a5cb030541 100644 --- a/plugins/tools/defaulttool/referenceimagestool/ToolReferenceImagesWidget.h +++ b/plugins/tools/defaulttool/referenceimagestool/ToolReferenceImagesWidget.h @@ -1,53 +1,56 @@ /* * Copyright (c) 2017 Eugene Ingerman * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU 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 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 __TOOL_REFERENCE_IMAGES_WIDGET_H #define __TOOL_REFERENCE_IMAGES_WIDGET_H #include #include #include #include "kis_types.h" class KoColor; class KoSelection; class KisCanvasResourceProvider; class ToolReferenceImages; class ToolReferenceImagesWidget : public QWidget { Q_OBJECT public: ToolReferenceImagesWidget(ToolReferenceImages *tool, KisCanvasResourceProvider *provider = 0, QWidget *parent = 0); ~ToolReferenceImagesWidget() override; void selectionChanged(KoSelection *selection); private Q_SLOTS: void slotOpacitySliderChanged(qreal); void slotSaturationSliderChanged(qreal); void slotKeepAspectChanged(); - void slotEmbeddingChanged(); + void slotSaveLocationChanged(int index); + + private: struct Private; const QScopedPointer d; + void updateVisibility(bool hasSelection); }; #endif diff --git a/plugins/tools/defaulttool/referenceimagestool/WdgToolOptions.ui b/plugins/tools/defaulttool/referenceimagestool/WdgToolOptions.ui index 2d11d1000d..f7bd0dbf77 100644 --- a/plugins/tools/defaulttool/referenceimagestool/WdgToolOptions.ui +++ b/plugins/tools/defaulttool/referenceimagestool/WdgToolOptions.ui @@ -1,88 +1,208 @@ WdgToolOptions 0 0 - 246 - 196 + 279 + 352 + + + 0 + 0 + + + + 6 + + + 0 + - - - Add reference image... - - + - - - Load set... - - + - + - Save set... + Keep aspect ratio - + - Delete all reference images + Save Location: - - - Qt::Horizontal - - + - + - Keep aspect ratio + Add/Select an image to show options + + + true - - - - + + + Qt::Vertical + + + QSizePolicy::MinimumExpanding + + + + 20 + 20 + + + - - - Embed to .kra + + + Qt::Horizontal - - - Link to external file + + + 0 - + + + + + 0 + 0 + + + + + + + + 18 + 18 + + + + true + + + + + + + Qt::Horizontal + + + + 20 + 20 + + + + + + + + + 0 + 0 + + + + + + + + 18 + 18 + + + + true + + + + + + + + 0 + 0 + + + + + + + + 18 + 18 + + + + true + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + All + + + + 18 + 18 + + + + true + + + + KisShapePropertySlider QWidget
KisSelectionPropertySlider.h
1