Commit fa60f994 authored by Nicolas Fella's avatar Nicolas Fella Committed by Nicolas Fella

Add image annotation via libKImageAnnotator

Summary:
Adds an annotaion mode that makes use of https://github.com/ksnip/kImageAnnotator

While in annotation mode all other actions are disabled.
When the annotation mode is left the changes are applied

FEATURE: 372464
FIXED-IN: 19.08.0

Closes T6321

Test Plan: {F6931191}

Reviewers: #spectacle, dporobic, ngraham

Reviewed By: #spectacle, ngraham

Subscribers: justinzobel, lephuong, mmustac, vperepechin, andisa, Leon0402, davidre, cfeck, ngraham, #spectacle

Tags: #spectacle

Maniphest Tasks: T6321

Differential Revision: https://phabricator.kde.org/D22074
parent 406a7cfa
......@@ -49,6 +49,7 @@ find_package(
Widgets
DBus
PrintSupport
Svg
Test
)
......@@ -104,6 +105,13 @@ if(NOT XCB_CURSOR_FOUND)
set(XCB_COMPONENTS_FOUND FALSE)
endif()
find_package(kImageAnnotator)
if(kImageAnnotator_FOUND)
find_package(kColorPicker ${KCOLORPICKER_MIN_VERSION} REQUIRED)
set(KIMAGEANNOTATOR_FOUND 1)
endif()
# fail build if none of the platform backends can be found
if (NOT XCB_FOUND OR NOT XCB_COMPONENTS_FOUND)
message(FATAL_ERROR "No suitable backend platform was found. Currently supported platforms are: XCB Components Required: ${XCB_COMPONENTS_ERRORS}")
......
......@@ -115,4 +115,8 @@ if(PURPOSE_FOUND)
)
endif()
if(KIMAGEANNOTATOR_FOUND)
target_link_libraries(spectacle kImageAnnotator::kImageAnnotator)
endif()
install(TARGETS spectacle ${INSTALL_TARGETS_DEFAULT_ARGS})
......@@ -13,4 +13,7 @@
/* Set the Spectacle version from CMake */
#cmakedefine SPECTACLE_VERSION "@SPECTACLE_VERSION@"
/* Define to 1 if we have kImageAnnotator */
#cmakedefine KIMAGEANNOTATOR_FOUND 1
#endif
......@@ -80,6 +80,10 @@ KSMainWindow::KSMainWindow(Platform::GrabModes theGrabModes, Platform::ShutterMo
mScreenRecorderToolsMenu(new QMenu(this)),
mExportMenu(new ExportMenu(this)),
mShutterModes(theShutterModes)
#ifdef KIMAGEANNOTATOR_FOUND
,mAnnotateButton(new QToolButton(this))
,mAnnotatorActive(false)
#endif
{
// before we do anything, we need to set a window property
// that skips the close/hide window animation on kwin. this
......@@ -152,6 +156,31 @@ void KSMainWindow::init()
mConfigureButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
mDialogButtonBox->addButton(mConfigureButton, QDialogButtonBox::ResetRole);
#ifdef KIMAGEANNOTATOR_FOUND
mAnnotateButton->setText(i18n("Annotate"));
mAnnotateButton->setToolTip(i18n("Add annotation to the screenshot"));
mAnnotateButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
mAnnotateButton->setIcon(QIcon::fromTheme(QStringLiteral("document-edit")));
connect(mAnnotateButton, &QToolButton::pressed, this, [this] {
if (mAnnotatorActive) {
mKSWidget->hideAnnotator();
mAnnotateButton->setText(i18n("Annotate"));
} else {
mKSWidget->showAnnotator();
mAnnotateButton->setText(i18n("Annotation done"));
}
mAnnotatorActive = !mAnnotatorActive;
mToolsButton->setEnabled(!mAnnotatorActive);
mSendToButton->setEnabled(!mAnnotatorActive);
mClipboardButton->setEnabled(!mAnnotatorActive);
mSaveButton->setEnabled(!mAnnotatorActive);
});
mDialogButtonBox->addButton(mAnnotateButton, QDialogButtonBox::ActionRole);
#endif
KGuiItem::assign(mToolsButton, KGuiItem(i18n("Tools")));
mToolsButton->setIcon(QIcon::fromTheme(QStringLiteral("tools"),
QIcon::fromTheme(QStringLiteral("application-menu"))));
......
......@@ -26,6 +26,7 @@
#include <QFrame>
#include <QToolButton>
#include <QDialogButtonBox>
#include <QStackedLayout>
#include <KMessageWidget>
#include <KNS3/KMoreToolsMenuFactory>
......@@ -35,6 +36,7 @@
#include "KSWidget.h"
#include "ExportMenu.h"
#include "Platforms/Platform.h"
#include "Config.h"
#include <memory>
......@@ -118,4 +120,10 @@ class KSMainWindow: public QDialog
ExportMenu *mExportMenu;
Platform::ShutterModes mShutterModes;
QTimer *mHideMessageWidgetTimer;
QStackedLayout *mStack;
#ifdef KIMAGEANNOTATOR_FOUND
QToolButton *mAnnotateButton;
bool mAnnotatorActive;
#endif
};
......@@ -25,6 +25,8 @@
#include "settings.h"
#include "SmartSpinBox.h"
#include "ProgressButton.h"
#include "ExportManager.h"
#include "Config.h"
#include <QAction>
#include <QApplication>
......@@ -34,6 +36,11 @@
#include <QGridLayout>
#include <QLabel>
#include <QShortcut>
#include <QStackedLayout>
#ifdef KIMAGEANNOTATOR_FOUND
#include <kImageAnnotator/KImageAnnotator.h>
#endif
#include <KConfigDialogManager>
#include <KLocalizedString>
......@@ -41,11 +48,19 @@
KSWidget::KSWidget(Platform::GrabModes theGrabModes, QWidget *parent)
: QWidget(parent)
{
mStack = new QStackedLayout(this);
// we'll init the widget that holds the image first
mImageWidget = new KSImageWidget(this);
mImageWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
connect(mImageWidget, &KSImageWidget::dragInitiated, this, &KSWidget::dragInitiated);
#ifdef KIMAGEANNOTATOR_FOUND
mAnnotator = new kImageAnnotator::KImageAnnotator();
mAnnotator->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
mStack->addWidget(mAnnotator);
#endif
// the capture mode options first
mCaptureModeLabel = new QLabel(i18n("<b>Capture Mode</b>"), this);
mCaptureArea = new QComboBox(this);
......@@ -157,7 +172,8 @@ KSWidget::KSWidget(Platform::GrabModes theGrabModes, QWidget *parent)
mRightLayout->addWidget(mTakeScreenshotButton, 1, Qt::AlignHCenter);
mRightLayout->setContentsMargins(10, 0, 0, 10);
mMainLayout = new QGridLayout(this);
mMainLayout = new QGridLayout();
mMainLayout->addWidget(mImageWidget, 0, 0, 1, 1);
mMainLayout->addLayout(mRightLayout, 0, 1, 1, 1);
mMainLayout->setColumnMinimumWidth(0, 320);
......@@ -167,6 +183,15 @@ KSWidget::KSWidget(Platform::GrabModes theGrabModes, QWidget *parent)
mCaptureArea->setCurrentIndex(index >= 0 ? index : 0);
auto mConfigManager = new KConfigDialogManager(this, Settings::self());
connect(mConfigManager, &KConfigDialogManager::widgetModified, mConfigManager, &KConfigDialogManager::updateSettings);
placeHolder = new QWidget();
placeHolder->setLayout(mMainLayout);
mStack->addWidget(placeHolder);
#ifdef KIMAGEANNOTATOR_FOUND
mStack->addWidget(mAnnotator);
#endif
}
int KSWidget::imagePaddingWidth() const
......@@ -280,3 +305,19 @@ void KSWidget::setProgress(double progress)
mTakeScreenshotButton->setProgress(progress);
}
#ifdef KIMAGEANNOTATOR_FOUND
void KSWidget::showAnnotator()
{
mStack->setCurrentIndex(1);
mAnnotator->loadImage(ExportManager::instance()->pixmap());
}
void KSWidget::hideAnnotator()
{
mStack->setCurrentIndex(0);
QImage image = mAnnotator->image();
QPixmap px = QPixmap::fromImage(image);
setScreenshotPixmap(px);
ExportManager::instance()->setPixmap(px);
}
#endif
......@@ -26,6 +26,7 @@
#include "SpectacleCommon.h"
#include "Platforms/Platform.h"
#include "Config.h"
class QAction;
class QGridLayout;
......@@ -35,13 +36,18 @@ class QFormLayout;
class QComboBox;
class QCheckBox;
class QLabel;
class KConfigDialogManager;
class QPushButton;
class QStackedLayout;
class KSImageWidget;
class ProgressButton;
class SmartSpinBox;
namespace kImageAnnotator {
class KImageAnnotator;
}
class KSWidget : public QWidget
{
Q_OBJECT
......@@ -73,6 +79,11 @@ class KSWidget : public QWidget
void setButtonState(KSWidget::State state);
void setProgress(double progress);
#ifdef KIMAGEANNOTATOR_FOUND
void showAnnotator();
void hideAnnotator();
#endif
private Q_SLOTS:
void newScreenshotClicked();
......@@ -101,4 +112,9 @@ class KSWidget : public QWidget
QAction *mTakeNewScreenshotAction;
QAction *mCancelAction;
KConfigDialogManager *mConfigManager;
QStackedLayout *mStack { nullptr };
QWidget *placeHolder;
#ifdef KIMAGEANNOTATOR_FOUND
kImageAnnotator::KImageAnnotator *mAnnotator { nullptr };
#endif
};
Markdown is supported
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