| 1 |
/* ============================================================ |
| 2 |
* |
| 3 |
* This file is a part of digiKam project |
| 4 |
* https://www.digikam.org |
| 5 |
* |
| 6 |
* Date : 2010-03-17 |
| 7 |
* Description : batch tool to add border. |
| 8 |
* |
| 9 |
* SPDX-FileCopyrightText: 2010-2026 by Gilles Caulier <caulier dot gilles at gmail dot com> |
| 10 |
* |
| 11 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 12 |
* |
| 13 |
* ============================================================ */ |
| 14 |
|
| 15 |
#include "border.h" |
| 16 |
|
| 17 |
// Qt includes |
| 18 |
|
| 19 |
#include <QWidget> |
| 20 |
|
| 21 |
// KDE includes |
| 22 |
|
| 23 |
#include <klocalizedstring.h> |
| 24 |
|
| 25 |
// Local includes |
| 26 |
|
| 27 |
#include "digikam_debug.h" |
| 28 |
#include "dimg.h" |
| 29 |
#include "borderfilter.h" |
| 30 |
|
| 31 |
namespace DigikamBqmBorderPlugin |
| 32 |
{ |
| 33 |
|
| 34 |
Border::Border(QObject* const parent) |
| 35 |
: BatchTool(QLatin1String("Border"), DecorateTool, parent) |
| 36 |
{ |
| 37 |
} |
| 38 |
|
| 39 |
BatchTool* Border::clone(QObject* const parent) const |
| 40 |
{ |
| 41 |
return new Border(parent); |
| 42 |
} |
| 43 |
|
| 44 |
void Border::registerSettingsWidget() |
| 45 |
{ |
| 46 |
m_settingsWidget = new QWidget; |
| 47 |
m_settingsView = new BorderSettings(m_settingsWidget); |
| 48 |
m_settingsView->resetToDefault(); |
| 49 |
|
| 50 |
connect(m_settingsView, SIGNAL(signalSettingsChanged()), |
| 51 |
this, SLOT(slotSettingsChanged())); |
| 52 |
|
| 53 |
BatchTool::registerSettingsWidget(); |
| 54 |
} |
| 55 |
|
| 56 |
BatchToolSettings Border::defaultSettings() |
| 57 |
{ |
| 58 |
BatchToolSettings prm; |
| 59 |
BorderContainer defaultPrm = m_settingsView->defaultSettings(); |
| 60 |
|
| 61 |
prm.insert(QLatin1String("preserveAspectRatio"), defaultPrm.preserveAspectRatio); |
| 62 |
prm.insert(QLatin1String("orgWidth"), defaultPrm.orgWidth); |
| 63 |
prm.insert(QLatin1String("orgHeight"), defaultPrm.orgHeight); |
| 64 |
prm.insert(QLatin1String("borderType"), defaultPrm.borderType); |
| 65 |
prm.insert(QLatin1String("borderWidth1"), defaultPrm.borderWidth1); |
| 66 |
prm.insert(QLatin1String("borderWidth2"), defaultPrm.borderWidth2); |
| 67 |
prm.insert(QLatin1String("borderWidth3"), defaultPrm.borderWidth3); |
| 68 |
prm.insert(QLatin1String("borderWidth4"), defaultPrm.borderWidth4); |
| 69 |
prm.insert(QLatin1String("borderPercent"), defaultPrm.borderPercent); |
| 70 |
prm.insert(QLatin1String("borderPath"), defaultPrm.borderPath); |
| 71 |
prm.insert(QLatin1String("solidColor"), defaultPrm.solidColor); |
| 72 |
prm.insert(QLatin1String("niepceBorderColor"), defaultPrm.niepceBorderColor); |
| 73 |
prm.insert(QLatin1String("niepceLineColor"), defaultPrm.niepceLineColor); |
| 74 |
prm.insert(QLatin1String("bevelUpperLeftColor"), defaultPrm.bevelUpperLeftColor); |
| 75 |
prm.insert(QLatin1String("bevelLowerRightColor"), defaultPrm.bevelLowerRightColor); |
| 76 |
prm.insert(QLatin1String("decorativeFirstColor"), defaultPrm.decorativeFirstColor); |
| 77 |
prm.insert(QLatin1String("decorativeSecondColor"), defaultPrm.decorativeSecondColor); |
| 78 |
|
| 79 |
return prm; |
| 80 |
} |
| 81 |
|
| 82 |
void Border::slotAssignSettings2Widget() |
| 83 |
{ |
| 84 |
BorderContainer prm; |
| 85 |
|
| 86 |
prm.preserveAspectRatio = settings().value(QLatin1String("preserveAspectRatio")).toBool(); |
| 87 |
prm.borderType = settings().value(QLatin1String("borderType")).toInt(); |
| 88 |
prm.borderWidth1 = settings().value(QLatin1String("borderWidth1")).toInt(); |
| 89 |
prm.borderWidth2 = settings().value(QLatin1String("borderWidth2")).toInt(); |
| 90 |
prm.borderWidth3 = settings().value(QLatin1String("borderWidth3")).toInt(); |
| 91 |
prm.borderWidth4 = settings().value(QLatin1String("borderWidth4")).toInt(); |
| 92 |
prm.borderPercent = settings().value(QLatin1String("borderPercent")).toDouble(); |
| 93 |
prm.borderPath = settings().value(QLatin1String("borderPath")).toString(); |
| 94 |
prm.solidColor = settings().value(QLatin1String("solidColor")).value<QColor>(); |
| 95 |
prm.niepceBorderColor = settings().value(QLatin1String("niepceBorderColor")).value<QColor>(); |
| 96 |
prm.niepceLineColor = settings().value(QLatin1String("niepceLineColor")).value<QColor>(); |
| 97 |
prm.bevelUpperLeftColor = settings().value(QLatin1String("bevelUpperLeftColor")).value<QColor>(); |
| 98 |
prm.bevelLowerRightColor = settings().value(QLatin1String("bevelLowerRightColor")).value<QColor>(); |
| 99 |
prm.decorativeFirstColor = settings().value(QLatin1String("decorativeFirstColor")).value<QColor>(); |
| 100 |
prm.decorativeSecondColor = settings().value(QLatin1String("decorativeSecondColor")).value<QColor>(); |
| 101 |
|
| 102 |
m_settingsView->setSettings(prm); |
| 103 |
} |
| 104 |
|
| 105 |
void Border::slotSettingsChanged() |
| 106 |
{ |
| 107 |
BatchToolSettings prm; |
| 108 |
BorderContainer currentPrm = m_settingsView->settings(); |
| 109 |
|
| 110 |
prm.insert(QLatin1String("preserveAspectRatio"), currentPrm.preserveAspectRatio); |
| 111 |
prm.insert(QLatin1String("borderType"), currentPrm.borderType); |
| 112 |
prm.insert(QLatin1String("borderWidth1"), currentPrm.borderWidth1); |
| 113 |
prm.insert(QLatin1String("borderWidth2"), currentPrm.borderWidth2); |
| 114 |
prm.insert(QLatin1String("borderWidth3"), currentPrm.borderWidth3); |
| 115 |
prm.insert(QLatin1String("borderWidth4"), currentPrm.borderWidth4); |
| 116 |
prm.insert(QLatin1String("borderPercent"), currentPrm.borderPercent); |
| 117 |
prm.insert(QLatin1String("borderPath"), currentPrm.borderPath); |
| 118 |
prm.insert(QLatin1String("solidColor"), currentPrm.solidColor); |
| 119 |
prm.insert(QLatin1String("niepceBorderColor"), currentPrm.niepceBorderColor); |
| 120 |
prm.insert(QLatin1String("niepceLineColor"), currentPrm.niepceLineColor); |
| 121 |
prm.insert(QLatin1String("bevelUpperLeftColor"), currentPrm.bevelUpperLeftColor); |
| 122 |
prm.insert(QLatin1String("bevelLowerRightColor"), currentPrm.bevelLowerRightColor); |
| 123 |
prm.insert(QLatin1String("decorativeFirstColor"), currentPrm.decorativeFirstColor); |
| 124 |
prm.insert(QLatin1String("decorativeSecondColor"), currentPrm.decorativeSecondColor); |
| 125 |
|
| 126 |
BatchTool::slotSettingsChanged(prm); |
| 127 |
} |
| 128 |
|
| 129 |
bool Border::toolOperations() |
| 130 |
{ |
| 131 |
if (!loadToDImg()) |
| 132 |
{ |
| 133 |
return false; |
| 134 |
} |
| 135 |
|
| 136 |
BorderContainer prm; |
| 137 |
prm.preserveAspectRatio = settings().value(QLatin1String("preserveAspectRatio")).toBool(); |
| 138 |
prm.borderType = settings().value(QLatin1String("borderType")).toInt(); |
| 139 |
prm.borderWidth1 = settings().value(QLatin1String("borderWidth1")).toInt(); |
| 140 |
prm.borderWidth2 = settings().value(QLatin1String("borderWidth2")).toInt(); |
| 141 |
prm.borderWidth3 = settings().value(QLatin1String("borderWidth3")).toInt(); |
| 142 |
prm.borderWidth4 = settings().value(QLatin1String("borderWidth4")).toInt(); |
| 143 |
prm.borderPercent = settings().value(QLatin1String("borderPercent")).toDouble(); |
| 144 |
prm.borderPath = settings().value(QLatin1String("borderPath")).toString(); |
| 145 |
prm.solidColor = settings().value(QLatin1String("solidColor")).value<QColor>(); |
| 146 |
prm.niepceBorderColor = settings().value(QLatin1String("niepceBorderColor")).value<QColor>(); |
| 147 |
prm.niepceLineColor = settings().value(QLatin1String("niepceLineColor")).value<QColor>(); |
| 148 |
prm.bevelUpperLeftColor = settings().value(QLatin1String("bevelUpperLeftColor")).value<QColor>(); |
| 149 |
prm.bevelLowerRightColor = settings().value(QLatin1String("bevelLowerRightColor")).value<QColor>(); |
| 150 |
prm.decorativeFirstColor = settings().value(QLatin1String("decorativeFirstColor")).value<QColor>(); |
| 151 |
prm.decorativeSecondColor = settings().value(QLatin1String("decorativeSecondColor")).value<QColor>(); |
| 152 |
prm.orgWidth = image().width(); |
| 153 |
prm.orgHeight = image().height(); |
| 154 |
|
| 155 |
BorderFilter bd(&image(), nullptr, prm); |
| 156 |
applyFilterChangedProperties(&bd); |
| 157 |
|
| 158 |
return (savefromDImg()); |
| 159 |
} |
| 160 |
|
| 161 |
} // namespace DigikamBqmBorderPlugin |
| 162 |
|
| 163 |
#include "moc_border.cpp" |