diff --git a/core/dplugins/editor/enhance/hotpixels/blackframelistview.cpp b/core/dplugins/editor/enhance/hotpixels/blackframelistview.cpp index e988917309..66a94d264f 100644 --- a/core/dplugins/editor/enhance/hotpixels/blackframelistview.cpp +++ b/core/dplugins/editor/enhance/hotpixels/blackframelistview.cpp @@ -1,153 +1,155 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2005-07-05 * Description : a ListView to display black frames * * Copyright (C) 2005-2019 by Gilles Caulier * Copyright (C) 2005-2006 by Unai Garro * * 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, 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. * * ============================================================ */ #define THUMB_WIDTH 150 #include "blackframelistview.h" // Qt includes #include #include #include // KDE includes #include namespace DigikamEditorHotPixelsToolPlugin { -BlackFrameListView::BlackFrameListView(QWidget* const parent) - : QTreeWidget(parent) -{ - setColumnCount(3); - setRootIsDecorated(false); - setSelectionMode(QAbstractItemView::SingleSelection); - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - setAllColumnsShowFocus(true); - setIconSize(QSize(THUMB_WIDTH, THUMB_WIDTH)); - - QStringList labels; - labels.append( i18n("Preview") ); - labels.append( i18n("Size") ); - labels.append( i18nc("This is a column which will contain the amount of HotPixels " - "found in the black frame file", "HP") ); - setHeaderLabels(labels); -} - -// ---------------------------------------------------------------------------- - -BlackFrameListViewItem::BlackFrameListViewItem(BlackFrameListView* const parent, const QUrl& url) +BlackFrameListViewItem::BlackFrameListViewItem(QTreeWidget* const parent, const QUrl& url) : QObject(parent), QTreeWidgetItem(parent), - m_blackFrameURL(url), - m_parent(parent) + m_blackFrameURL(url) { m_parser = new BlackFrameParser(parent); m_parser->parseBlackFrame(url); connect(m_parser, SIGNAL(signalParsed(QList)), this, SLOT(slotParsed(QList))); connect(this, SIGNAL(signalParsed(QList,QUrl)), parent, SLOT(slotParsed(QList,QUrl))); connect(m_parser, SIGNAL(signalLoadingProgress(float)), this, SIGNAL(signalLoadingProgress(float))); connect(m_parser, SIGNAL(signalLoadingComplete()), this, SIGNAL(signalLoadingComplete())); } void BlackFrameListViewItem::activate() { - m_parent->setToolTip(m_blackFrameDesc); + static_cast(this)->treeWidget()->setToolTip(m_blackFrameDesc); + emit signalParsed(m_hotPixels, m_blackFrameURL); } void BlackFrameListViewItem::slotParsed(const QList& hotPixels) { m_hotPixels = hotPixels; m_image = m_parser->image(); m_imageSize = m_image.size(); m_thumb = thumb(QSize(THUMB_WIDTH, THUMB_WIDTH/3*2)).toImage(); setIcon(0, QPixmap::fromImage(m_thumb)); if (!m_imageSize.isEmpty()) { setText(1, QString::fromUtf8("%1x%2").arg(m_imageSize.width()).arg(m_imageSize.height())); } setText(2, QString::number(m_hotPixels.count())); m_blackFrameDesc = QString::fromUtf8("

%1:

").arg(m_blackFrameURL.fileName()); - for (QList ::const_iterator it = m_hotPixels.constBegin() ; it != m_hotPixels.constEnd() ; ++it) + for (QList ::const_iterator it = m_hotPixels.constBegin() ; + it != m_hotPixels.constEnd() ; ++it) { m_blackFrameDesc.append( QString::fromUtf8("[%1,%2] ").arg((*it).x()).arg((*it).y()) ); } emit signalParsed(m_hotPixels, m_blackFrameURL); } QPixmap BlackFrameListViewItem::thumb(const QSize& size) { //First scale it down to the size QPixmap thumb = QPixmap::fromImage(m_image.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation)); //And draw the hot pixel positions on the thumb QPainter p(&thumb); //Take scaling into account float xRatio, yRatio; float hpThumbX, hpThumbY; QRect hpRect; - xRatio = (float)size.width()/(float)m_image.width(); - yRatio = (float)size.height()/(float)m_image.height(); + xRatio = (float)size.width() / (float)m_image.width(); + yRatio = (float)size.height() / (float)m_image.height(); //Draw hot pixels one by one QList::const_iterator it; for (it = m_hotPixels.constBegin() ; it != m_hotPixels.constEnd() ; ++it) { hpRect = (*it).rect; hpThumbX = (hpRect.x() + hpRect.width() / 2) * xRatio; hpThumbY = (hpRect.y() + hpRect.height() / 2) * yRatio; p.setPen(QPen(Qt::black)); p.drawLine((int) hpThumbX, (int) hpThumbY - 1, (int) hpThumbX, (int) hpThumbY + 1); p.drawLine((int) hpThumbX - 1, (int) hpThumbY, (int) hpThumbX + 1, (int) hpThumbY); p.setPen(QPen(Qt::white)); p.drawPoint((int) hpThumbX - 1, (int) hpThumbY - 1); p.drawPoint((int) hpThumbX + 1, (int) hpThumbY + 1); p.drawPoint((int) hpThumbX - 1, (int) hpThumbY + 1); p.drawPoint((int) hpThumbX + 1, (int) hpThumbY - 1); } return thumb; } +// ---------------------------------------------------------------------------- + +BlackFrameListView::BlackFrameListView(QWidget* const parent) + : QTreeWidget(parent) +{ + setColumnCount(3); + setRootIsDecorated(false); + setSelectionMode(QAbstractItemView::SingleSelection); + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + setAllColumnsShowFocus(true); + setIconSize(QSize(THUMB_WIDTH, THUMB_WIDTH)); + + QStringList labels; + labels.append( i18n("Preview") ); + labels.append( i18n("Size") ); + labels.append( i18nc("This is a column which will contain the amount of HotPixels " + "found in the black frame file", "HP") ); + setHeaderLabels(labels); +} + + } // namespace DigikamEditorHotPixelsToolPlugin diff --git a/core/dplugins/editor/enhance/hotpixels/blackframelistview.h b/core/dplugins/editor/enhance/hotpixels/blackframelistview.h index da09b235ba..41a5c72272 100644 --- a/core/dplugins/editor/enhance/hotpixels/blackframelistview.h +++ b/core/dplugins/editor/enhance/hotpixels/blackframelistview.h @@ -1,118 +1,116 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2005-07-05 * Description : a ListView to display black frames * * Copyright (C) 2005-2019 by Gilles Caulier * Copyright (C) 2005-2006 by Unai Garro * * 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, 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. * * ============================================================ */ #ifndef DIGIKAM_EDITOR_BLACK_FRAME_LIST_VIEW_H #define DIGIKAM_EDITOR_BLACK_FRAME_LIST_VIEW_H // Qt includes #include #include #include #include #include #include #include #include // Local includes #include "blackframeparser.h" #include "hotpixel.h" namespace DigikamEditorHotPixelsToolPlugin { -class BlackFrameListView : public QTreeWidget -{ - Q_OBJECT - -public: - - explicit BlackFrameListView(QWidget* const parent=nullptr); - ~BlackFrameListView() {}; - -Q_SIGNALS: - - void signalBlackFrameSelected(const QList&, const QUrl&); - -private Q_SLOTS: - - void slotParsed(const QList& hotPixels, const QUrl& blackFrameURL) - { - emit signalBlackFrameSelected(hotPixels, blackFrameURL); - }; -}; - -//----------------------------------------------------------------------------------- - class BlackFrameListViewItem : public QObject, QTreeWidgetItem { Q_OBJECT public: - explicit BlackFrameListViewItem(BlackFrameListView* const parent, const QUrl& url); + explicit BlackFrameListViewItem(QTreeWidget* const parent, const QUrl& url); ~BlackFrameListViewItem() {}; Q_SIGNALS: void signalParsed(const QList&, const QUrl&); void signalLoadingProgress(float); void signalLoadingComplete(); protected: void activate(); private: QPixmap thumb(const QSize& size); private Q_SLOTS: void slotParsed(const QList&); private: // Data contained within each listview item - QImage m_thumb; - QImage m_image; + QImage m_thumb; + QImage m_image; - QSize m_imageSize; + QSize m_imageSize; - QList m_hotPixels; + QList m_hotPixels; - QString m_blackFrameDesc; + QString m_blackFrameDesc; - QUrl m_blackFrameURL; + QUrl m_blackFrameURL; - BlackFrameParser* m_parser; + BlackFrameParser* m_parser; +}; + +//----------------------------------------------------------------------------------- + +class BlackFrameListView : public QTreeWidget +{ + Q_OBJECT + +public: + + explicit BlackFrameListView(QWidget* const parent=nullptr); + ~BlackFrameListView() {}; + +Q_SIGNALS: - BlackFrameListView* m_parent; + void signalBlackFrameSelected(const QList&, const QUrl&); + +private Q_SLOTS: + + void slotParsed(const QList& hotPixels, const QUrl& blackFrameURL) + { + emit signalBlackFrameSelected(hotPixels, blackFrameURL); + }; }; } // namespace DigikamEditorHotPixelsToolPlugin #endif // DIGIKAM_EDITOR_BLACK_FRAME_LIST_VIEW_H diff --git a/core/dplugins/editor/enhance/hotpixels/hotpixelstool.cpp b/core/dplugins/editor/enhance/hotpixels/hotpixelstool.cpp index ed622bfad1..826c1cc867 100644 --- a/core/dplugins/editor/enhance/hotpixels/hotpixelstool.cpp +++ b/core/dplugins/editor/enhance/hotpixels/hotpixelstool.cpp @@ -1,299 +1,300 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2005-03-27 * Description : a digiKam image tool for fixing dots produced by * hot/stuck/dead pixels from a CCD. * * Copyright (C) 2005-2019 by Gilles Caulier * Copyright (C) 2005-2006 by Unai Garro * * 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, 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. * * ============================================================ */ #include "hotpixelstool.h" // Qt includes #include #include #include #include #include #include #include // KDE includes #include #include #include "kconfiggroup.h" // Local includes #include "blackframelistview.h" #include "dcombobox.h" #include "daboutdata.h" #include "dimg.h" #include "dimgfiltermanager.h" #include "editortooliface.h" #include "editortoolsettings.h" #include "hotpixelfixer.h" #include "imagedialog.h" #include "imageiface.h" #include "imageregionwidget.h" namespace DigikamEditorHotPixelsToolPlugin { class Q_DECL_HIDDEN HotPixelsTool::Private { public: explicit Private() : blackFrameButton(nullptr), progressBar(nullptr), filterMethodCombo(nullptr), blackFrameListView(nullptr), previewWidget(nullptr), gboxSettings(nullptr) { } static const QString configGroupName; static const QString configLastBlackFrameFileEntry; static const QString configFilterMethodEntry; QPushButton* blackFrameButton; QProgressBar* progressBar; QList hotPixelsList; QUrl blackFrameURL; DComboBox* filterMethodCombo; BlackFrameListView* blackFrameListView; ImageRegionWidget* previewWidget; EditorToolSettings* gboxSettings; }; const QString HotPixelsTool::Private::configGroupName(QLatin1String("hotpixels Tool")); const QString HotPixelsTool::Private::configLastBlackFrameFileEntry(QLatin1String("Last Black Frame File")); const QString HotPixelsTool::Private::configFilterMethodEntry(QLatin1String("Filter Method")); // -------------------------------------------------------- HotPixelsTool::HotPixelsTool(QObject* const parent) : EditorToolThreaded(parent), d(new Private) { setObjectName(QLatin1String("hotpixels")); setToolName(i18n("Hot Pixels")); setToolIcon(QIcon::fromTheme(QLatin1String("hotpixels"))); // ------------------------------------------------------------- d->gboxSettings = new EditorToolSettings(nullptr); d->gboxSettings->setButtons(EditorToolSettings::Default| EditorToolSettings::Ok| EditorToolSettings::Cancel| EditorToolSettings::Try); QGridLayout* const grid = new QGridLayout(d->gboxSettings->plainPage()); QLabel* const filterMethodLabel = new QLabel(i18n("Filter:"), d->gboxSettings->plainPage()); d->filterMethodCombo = new DComboBox(d->gboxSettings->plainPage()); d->filterMethodCombo->addItem(i18nc("average filter mode", "Average")); d->filterMethodCombo->addItem(i18nc("linear filter mode", "Linear")); d->filterMethodCombo->addItem(i18nc("quadratic filter mode", "Quadratic")); d->filterMethodCombo->addItem(i18nc("cubic filter mode", "Cubic")); d->filterMethodCombo->setDefaultIndex(HotPixelFixer::QUADRATIC_INTERPOLATION); d->blackFrameButton = new QPushButton(i18n("Black Frame..."), d->gboxSettings->plainPage()); d->blackFrameButton->setIcon(QIcon::fromTheme(QLatin1String("document-open"))); d->blackFrameButton->setWhatsThis(i18n("Use this button to add a new black frame file which will " "be used by the hot pixels removal filter.") ); d->blackFrameListView = new BlackFrameListView(d->gboxSettings->plainPage()); // ------------------------------------------------------------- const int spacing = d->gboxSettings->spacingHint(); grid->addWidget(filterMethodLabel, 0, 0, 1, 1); grid->addWidget(d->filterMethodCombo, 0, 1, 1, 1); grid->addWidget(d->blackFrameButton, 0, 2, 1, 1); grid->addWidget(d->blackFrameListView, 1, 0, 2, 3); grid->setRowStretch(3, 10); grid->setContentsMargins(spacing, spacing, spacing, spacing); grid->setSpacing(spacing); // ------------------------------------------------------------- d->previewWidget = new ImageRegionWidget; setToolSettings(d->gboxSettings); setToolView(d->previewWidget); setPreviewModeMask(PreviewToolBar::AllPreviewModes); // ------------------------------------------------------------- connect(d->filterMethodCombo, SIGNAL(activated(int)), this, SLOT(slotPreview())); connect(d->blackFrameButton, SIGNAL(clicked()), this, SLOT(slotAddBlackFrame())); connect(d->blackFrameListView, SIGNAL(signalBlackFrameSelected(QList,QUrl)), this, SLOT(slotBlackFrame(QList,QUrl))); } HotPixelsTool::~HotPixelsTool() { delete d; } void HotPixelsTool::registerFilter() { DImgFilterManager::instance()->addGenerator(new BasicDImgFilterGenerator()); } void HotPixelsTool::readSettings() { KSharedConfig::Ptr config = KSharedConfig::openConfig(); KConfigGroup group = config->group(d->configGroupName); d->blackFrameURL = QUrl::fromLocalFile(group.readEntry(d->configLastBlackFrameFileEntry, QString())); d->filterMethodCombo->setCurrentIndex(group.readEntry(d->configFilterMethodEntry, d->filterMethodCombo->defaultIndex())); if (d->blackFrameURL.isValid()) { EditorToolIface::editorToolIface()->setToolStartProgress(i18n("Loading: ")); - BlackFrameListViewItem* item = new BlackFrameListViewItem(d->blackFrameListView, d->blackFrameURL); + BlackFrameListViewItem* const item = new BlackFrameListViewItem(d->blackFrameListView, d->blackFrameURL); connect(item, SIGNAL(signalLoadingProgress(float)), this, SLOT(slotLoadingProgress(float))); connect(item, SIGNAL(signalLoadingComplete()), this, SLOT(slotLoadingComplete())); } } void HotPixelsTool::writeSettings() { KSharedConfig::Ptr config = KSharedConfig::openConfig(); KConfigGroup group = config->group(d->configGroupName); group.writeEntry(d->configLastBlackFrameFileEntry, d->blackFrameURL.url()); group.writeEntry(d->configFilterMethodEntry, d->filterMethodCombo->currentIndex()); group.sync(); } void HotPixelsTool::slotLoadingProgress(float v) { EditorToolIface::editorToolIface()->setToolProgress((int)(v*100)); } void HotPixelsTool::slotLoadingComplete() { EditorToolIface::editorToolIface()->setToolStopProgress(); } void HotPixelsTool::slotResetSettings() { d->filterMethodCombo->blockSignals(true); d->filterMethodCombo->slotReset(); d->filterMethodCombo->blockSignals(false); } void HotPixelsTool::slotAddBlackFrame() { QUrl url = ImageDialog::getImageURL(qApp->activeWindow(), d->blackFrameURL, i18n("Select Black Frame Image")); if (!url.isEmpty()) { // Load the selected file and insert into the list. d->blackFrameURL = url; d->blackFrameListView->clear(); - BlackFrameListViewItem* item = new BlackFrameListViewItem(d->blackFrameListView, d->blackFrameURL); + BlackFrameListViewItem* const item = new BlackFrameListViewItem(d->blackFrameListView, d->blackFrameURL); connect(item, SIGNAL(signalLoadingProgress(float)), this, SLOT(slotLoadingProgress(float))); connect(item, SIGNAL(signalLoadingComplete()), this, SLOT(slotLoadingComplete())); } } void HotPixelsTool::preparePreview() { DImg image = d->previewWidget->getOriginalRegionImage(); int interpolationMethod = d->filterMethodCombo->currentIndex(); QList hotPixelsRegion; QRect area = d->previewWidget->getOriginalImageRegionToRender(); - for (QList::const_iterator it = d->hotPixelsList.constBegin() ; it != d->hotPixelsList.constEnd() ; ++it) + for (QList::const_iterator it = d->hotPixelsList.constBegin() ; + it != d->hotPixelsList.constEnd() ; ++it) { HotPixel hp = (*it); if (area.contains( hp.rect )) { hp.rect.moveTopLeft(QPoint( hp.rect.x()-area.x(), hp.rect.y()-area.y() )); hotPixelsRegion.append(hp); } } setFilter(dynamic_cast(new HotPixelFixer(&image, this, hotPixelsRegion, interpolationMethod))); } void HotPixelsTool::prepareFinal() { int interpolationMethod = d->filterMethodCombo->currentIndex(); ImageIface iface; setFilter(dynamic_cast(new HotPixelFixer(iface.original(), this, d->hotPixelsList, interpolationMethod))); } void HotPixelsTool::setPreviewImage() { d->previewWidget->setPreviewImage(filter()->getTargetImage()); } void HotPixelsTool::setFinalImage() { ImageIface iface; iface.setOriginal(i18n("Hot Pixels Correction"), filter()->filterAction(), filter()->getTargetImage()); } void HotPixelsTool::slotBlackFrame(const QList& hpList, const QUrl& blackFrameURL) { d->blackFrameURL = blackFrameURL; d->hotPixelsList = hpList; QPolygon pointList(d->hotPixelsList.size()); QList ::const_iterator it; int i = 0; for (it = d->hotPixelsList.constBegin() ; it != d->hotPixelsList.constEnd() ; ++it, ++i) { pointList.setPoint(i, (*it).rect.center()); } d->previewWidget->setHighLightPoints(pointList); slotPreview(); } } // namespace DigikamEditorHotPixelsToolPlugin