Commit 8f3bf87b authored by Ilya Pominov's avatar Ilya Pominov Committed by Nate Graham
Browse files

Add simple image editor using KImageAnnotator

This makes KImageAnnotator a new required dependency.

BUG: 408551
FIXED-IN: 22.08
parent 6f2203fb
Pipeline #201247 passed with stage
in 1 minute and 48 seconds
......@@ -141,6 +141,15 @@ if(X11_FOUND)
set(HAVE_X11 1)
endif()
find_package(kImageAnnotator)
set_package_properties(kImageAnnotator PROPERTIES URL "https://github.com/ksnip/kImageAnnotator" DESCRIPTION "The kImageAnnotator library provides tools to annotate" TYPE REQUIRED)
if(kImageAnnotator_FOUND)
find_package(kColorPicker REQUIRED)
if(NOT kImageAnnotator_VERSION VERSION_LESS 0.5.0)
set(KIMAGEANNOTATOR_CAN_LOAD_TRANSLATIONS 1)
endif()
endif()
configure_file(config-gwenview.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-gwenview.h)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
......
......@@ -131,3 +131,5 @@ target_link_libraries(slideshowfileitemaction
KF5::I18n
KF5::KIOWidgets
KF5::Notifications)
target_link_libraries(gwenview kImageAnnotator::kImageAnnotator)
<?xml version="1.0"?>
<!DOCTYPE gui SYSTEM "kpartgui.dtd">
<gui name="gwenview" version="65">
<gui name="gwenview" version="66">
<MenuBar>
<Menu name="file" >
......@@ -68,6 +68,7 @@
<Action name="resize" />
<Action name="crop" />
<Action name="red_eye_reduction" />
<Action name="annotate" />
</Menu>
<Menu name="go" >
<Action name="go_first"/>
......
......@@ -33,13 +33,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <KMessageBox>
// Local
#include "gwenview_app_debug.h"
#include "viewmainpage.h"
#include "gvcore.h"
#include "gwenview_app_debug.h"
#include "mainwindow.h"
#include "sidebar.h"
#include "viewmainpage.h"
#include <lib/annotate/annotatedialog.h>
#include <lib/annotate/annotateoperation.h>
#include <lib/contextmanager.h>
#include <lib/crop/croptool.h>
#include <lib/document/documentfactory.h>
......@@ -75,6 +75,7 @@ struct ImageOpsContextManagerItem::Private {
QAction *mResizeAction = nullptr;
QAction *mCropAction = nullptr;
QAction *mRedEyeReductionAction = nullptr;
QAction *mAnnotateAction = nullptr;
QList<QAction *> mActionList;
void setupActions()
......@@ -117,7 +118,24 @@ struct ImageOpsContextManagerItem::Private {
mRedEyeReductionAction->setIcon(QIcon::fromTheme(QStringLiteral("redeyes")));
actionCollection->setDefaultShortcut(mRedEyeReductionAction, Qt::SHIFT | Qt::Key_E);
mActionList << mRotateLeftAction << mRotateRightAction << mMirrorAction << mFlipAction << mResizeAction << mCropAction << mRedEyeReductionAction;
mAnnotateAction = edit->addAction(QStringLiteral("annotate"));
mAnnotateAction->setText(i18nc("@action:intoolbar", "Annotate"));
mAnnotateAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-image"), QIcon::fromTheme(QStringLiteral("draw-brush"))));
actionCollection->setDefaultShortcut(mAnnotateAction, Qt::SHIFT | Qt::Key_A);
connect(mAnnotateAction, &QAction::triggered, q, [this]() {
Document::Ptr doc = DocumentFactory::instance()->load(q->contextManager()->currentUrl());
doc->waitUntilLoaded();
AnnotateDialog dialog(mMainWindow);
dialog.setWindowTitle(i18nc("@title:window Annotate [filename]", "Annotate %1", doc->url().fileName()));
dialog.setImage(doc->image());
if (dialog.exec() == QDialog::Accepted) {
q->applyImageOperation(new AnnotateOperation(dialog.getImage()));
}
});
mActionList << mRotateLeftAction << mRotateRightAction << mMirrorAction << mFlipAction << mResizeAction << mCropAction << mRedEyeReductionAction
<< mAnnotateAction;
}
bool ensureEditable()
......@@ -191,6 +209,7 @@ void ImageOpsContextManagerItem::updateActions()
d->mResizeAction->setEnabled(canModify);
d->mCropAction->setEnabled(canModify && viewMainPageIsVisible);
d->mRedEyeReductionAction->setEnabled(canModify && viewMainPageIsVisible);
d->mAnnotateAction->setEnabled(canModify);
updateSideBarContent();
}
......
......@@ -56,6 +56,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// To enable AVIF/HEIF/JPEG-XL metadata support in Exiv2
#include <exiv2/exiv2.hpp>
#ifdef KIMAGEANNOTATOR_CAN_LOAD_TRANSLATIONS
#include <kImageAnnotator/KImageAnnotator.h>
#endif
namespace
{
Q_DECLARE_LOGGING_CATEGORY(LibTiffLog)
......@@ -202,6 +206,10 @@ int main(int argc, char *argv[])
// to be async rather than using exec().
qApp->sendPostedEvents(nullptr, QEvent::DeferredDelete);
#ifdef KIMAGEANNOTATOR_CAN_LOAD_TRANSLATIONS
kImageAnnotator::loadTranslations();
#endif
return app.exec();
}
......
......@@ -8,3 +8,4 @@
#cmakedefine KF5Activities_FOUND 1
#cmakedefine KF5Purpose_FOUND 1
#cmakedefine HAVE_TIFF 1
#cmakedefine KIMAGEANNOTATOR_CAN_LOAD_TRANSLATIONS ${KIMAGEANNOTATOR_CAN_LOAD_TRANSLATIONS}
......@@ -152,6 +152,8 @@ set(gwenviewlib_SRCS
touch/twofingertap.cpp
touch/touch_helper.cpp
${GV_JPEG_DIR}/transupp.c
annotate/annotatedialog.cpp
annotate/annotateoperation.cpp
)
set_source_files_properties(${GV_JPEG_DIR}/transupp.c PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)
......@@ -296,4 +298,6 @@ if (GWENVIEW_SEMANTICINFO_BACKEND_BALOO)
)
endif()
target_link_libraries(gwenviewlib kImageAnnotator::kImageAnnotator)
install(TARGETS gwenviewlib ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} LIBRARY NAMELINK_SKIP)
/*
Gwenview: an image viewer
Copyright 2022 Ilya Pominov <ipominov@astralinux.ru>
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 "annotatedialog.h"
// Qt
#include <QDialogButtonBox>
#include <QPixmap>
#include <QVBoxLayout>
// KImageAnnotator
#include <kImageAnnotator/KImageAnnotator.h>
namespace Gwenview
{
AnnotateDialog::AnnotateDialog(QWidget *parent)
: QDialog(parent)
, mAnnotator(new kImageAnnotator::KImageAnnotator())
{
mAnnotator->setParent(this);
auto layout = new QVBoxLayout;
layout->addWidget(mAnnotator);
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
layout->addWidget(buttonBox);
setLayout(layout);
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
}
AnnotateDialog::~AnnotateDialog()
{
delete mAnnotator;
}
void AnnotateDialog::setImage(const QImage &image)
{
mAnnotator->loadImage(QPixmap::fromImage(image));
}
QImage AnnotateDialog::getImage() const
{
return mAnnotator->image();
}
} // namespace
/*
Gwenview: an image viewer
Copyright 2022 Ilya Pominov <ipominov@astralinux.ru>
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 ANNOTATEDIALOG_H
#define ANNOTATEDIALOG_H
#include <lib/gwenviewlib_export.h>
// Qt
#include <QDialog>
namespace kImageAnnotator
{
class KImageAnnotator;
};
namespace Gwenview
{
class GWENVIEWLIB_EXPORT AnnotateDialog : public QDialog
{
public:
explicit AnnotateDialog(QWidget *parent);
~AnnotateDialog();
void setImage(const QImage &image);
QImage getImage() const;
private:
kImageAnnotator::KImageAnnotator *mAnnotator;
};
} // namespace
#endif // ANNOTATEDIALOG_H
/*
Gwenview: an image viewer
Copyright 2022 Ilya Pominov <ipominov@astralinux.ru>
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.
*/
// Self
#include "annotateoperation.h"
// Qt
#include <QImage>
// KF
#include <KLocalizedString>
// Local
#include "document/abstractdocumenteditor.h"
#include "document/document.h"
#include "document/documentjob.h"
#include "gwenview_lib_debug.h"
namespace Gwenview
{
class AnnotateOperationPrivate
{
public:
AnnotateOperationPrivate()
{
}
QImage mNewImage;
QImage mOriginalImage;
};
AnnotateOperation::AnnotateOperation(const QImage &image)
: d(new AnnotateOperationPrivate())
{
d->mNewImage = image;
setText(i18nc("@action:intoolbar", "Annotate"));
}
AnnotateOperation::~AnnotateOperation()
{
delete d;
}
void AnnotateOperation::redo()
{
if (!document()->editor()) {
qCWarning(GWENVIEW_LIB_LOG) << "!document->editor()";
return;
}
d->mOriginalImage = document()->image();
document()->editor()->setImage(d->mNewImage);
finish(true);
}
void AnnotateOperation::undo()
{
if (!document()->editor()) {
qCWarning(GWENVIEW_LIB_LOG) << "!document->editor()";
return;
}
document()->editor()->setImage(d->mOriginalImage);
finish(true);
}
} // namespace
/*
Gwenview: an image viewer
Copyright 2022 Ilya Pominov <ipominov@astralinux.ru>
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 ANNOTATEOPERATION_H
#define ANNOTATEOPERATION_H
#include <lib/gwenviewlib_export.h>
// Local
#include <lib/abstractimageoperation.h>
namespace Gwenview
{
class AnnotateOperationPrivate;
class GWENVIEWLIB_EXPORT AnnotateOperation : public AbstractImageOperation
{
public:
explicit AnnotateOperation(const QImage &image);
~AnnotateOperation() override;
void redo() override;
void undo() override;
private:
AnnotateOperationPrivate *const d;
};
} // namespace
#endif /* ANNOTATEOPERATION_H */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment