Skip to content

Commit

Permalink
Add tabs for images #48
Browse files Browse the repository at this point in the history
  • Loading branch information
DamirPorobic committed Jun 12, 2020
1 parent a41ef85 commit ab037d4
Show file tree
Hide file tree
Showing 22 changed files with 459 additions and 56 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
@@ -1,6 +1,7 @@
# Change log

## Release 0.2.2
## Release 0.3.0
* New: Tabs for images. ([#48](https://github.com/ksnip/kImageAnnotator/issues/48))

## Release 0.2.1
* Fixed: Edit border around text box doesn't disappear when done with editing. ([#71](https://github.com/ksnip/kImageAnnotator/issues/71))
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.5)
project(kImageAnnotator LANGUAGES CXX VERSION 0.2.2)
project(kImageAnnotator LANGUAGES CXX VERSION 0.3.0)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down
2 changes: 1 addition & 1 deletion README.md
@@ -1,7 +1,7 @@
# kImageAnnotator [![Build Status](https://travis-ci.org/ksnip/kImageAnnotator.svg?branch=master)](https://travis-ci.org/ksnip/kImageAnnotator)
Tool for annotating images

Version 0.2.2 - Work in Progress
Version 0.3.0 - Work in Progress


![kImageAnnotator](https://imgur.com/HguleRO.png "kImageAnnotator")
Expand Down
9 changes: 8 additions & 1 deletion include/kImageAnnotator/KImageAnnotator.h
Expand Up @@ -36,7 +36,7 @@ Q_OBJECT

public:
explicit KImageAnnotator();
~KImageAnnotator();
~KImageAnnotator() override;
QImage image() const;
QAction *undoAction();
QAction *redoAction();
Expand All @@ -47,16 +47,23 @@ Q_OBJECT

public slots:
void loadImage(const QPixmap &pixmap);
int addImage(const QPixmap &pixmap, const QString &title, const QString &toolTip);
void updateTabInfo(int index, const QString &title, const QString &toolTip);
void insertImageItem(const QPointF &position, const QPixmap &pixmap);
void setTextFont(const QFont &font);
void setNumberFont(const QFont &font);
void setItemShadowEnabled(bool enabled);
void setSmoothPathEnabled(bool enabled);
void setSaveToolSelection(bool enabled);
void setSmoothFactor(int factor);
void setTabBarAutoHide(bool enabled);
void removeTab(int index);

signals:
void imageChanged() const;
void currentTabChanged(int index) const;
void tabCloseRequested(int index) const;
void tabMoved(int fromIndex, int toIndex);

private:
QScopedPointer<KImageAnnotatorPrivate> const d_ptr;
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Expand Up @@ -5,6 +5,8 @@ set(KIMAGEANNOTATOR_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/gui/annotator/AnnotationView.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gui/annotator/WidgetConfigurator.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gui/annotator/AnnotationSettings.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gui/annotator/AnnotationTabContent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gui/annotator/AnnotationTabWidget.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gui/cropper/CropWidget.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gui/cropper/CropView.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gui/cropper/CropSelectionHandler.cpp
Expand Down
37 changes: 30 additions & 7 deletions src/gui/CoreView.cpp
Expand Up @@ -21,17 +21,20 @@

namespace kImageAnnotator {

CoreView::CoreView(Config *config)
CoreView::CoreView(Config *config) :
mConfig(config),
mAnnotationWidget(new AnnotationWidget(mConfig)),
mCropWidget(new CropWidget),
mScaleWidget(new ScaleWidget)
{
mConfig = config;
mAnnotationWidget = new AnnotationWidget(mConfig);
mCropWidget = new CropWidget(mAnnotationWidget->annotationArea());
mScaleWidget = new ScaleWidget(mAnnotationWidget->annotationArea());
addWidget(mAnnotationWidget);
addWidget(mCropWidget);
addWidget(mScaleWidget);

connect(mAnnotationWidget, &AnnotationWidget::imageChanged, this, &CoreView::imageChanged);
connect(mAnnotationWidget, &AnnotationWidget::currentTabChanged, this, &CoreView::currentTabChanged);
connect(mAnnotationWidget, &AnnotationWidget::tabCloseRequested, this, &CoreView::tabCloseRequested);
connect(mAnnotationWidget, &AnnotationWidget::tabMoved, this, &CoreView::tabMoved);
connect(mCropWidget, &CropWidget::closing, this, &CoreView::showAnnotator);
connect(mScaleWidget, &ScaleWidget::closing, this, &CoreView::showAnnotator);
}
Expand All @@ -53,11 +56,26 @@ void CoreView::loadImage(const QPixmap &pixmap)
mAnnotationWidget->loadImage(pixmap);
}

int CoreView::addImage(const QPixmap &pixmap, const QString &title, const QString &toolTip)
{
return mAnnotationWidget->addImage(pixmap, title, toolTip);
}

void CoreView::updateTabInfo(int index, const QString &title, const QString &toolTip)
{
mAnnotationWidget->updateTabInfo(index, title, toolTip);
}

void CoreView::insertImageItem(const QPointF &position, const QPixmap &pixmap)
{
mAnnotationWidget->insertImageItem(position, pixmap);
}

void CoreView::removeTab(int index)
{
mAnnotationWidget->removeTab(index);
}

void CoreView::showAnnotator()
{
mAnnotationWidget->setUndoEnabled(true);
Expand All @@ -69,15 +87,20 @@ void CoreView::showCropper()
mAnnotationWidget->setUndoEnabled(false);
mAnnotationWidget->clearSelection();
setCurrentWidget(mCropWidget);
mCropWidget->activate();
mCropWidget->activate(mAnnotationWidget->annotationArea());
}

void CoreView::showScaler()
{
mAnnotationWidget->setUndoEnabled(false);
mAnnotationWidget->clearSelection();
setCurrentWidget(mScaleWidget);
mScaleWidget->activate();
mScaleWidget->activate(mAnnotationWidget->annotationArea());
}

void CoreView::setTabBarAutoHide(bool enabled)
{
mAnnotationWidget->setTabBarAutoHide(enabled);
}

QAction *CoreView::undoAction()
Expand Down
7 changes: 7 additions & 0 deletions src/gui/CoreView.h
Expand Up @@ -43,13 +43,20 @@ Q_OBJECT

signals:
void imageChanged() const;
void currentTabChanged(int index) const;
void tabCloseRequested(int index) const;
void tabMoved(int fromIndex, int toIndex);

public slots:
void loadImage(const QPixmap &pixmap);
int addImage(const QPixmap &pixmap, const QString &title, const QString &toolTip);
void updateTabInfo(int index, const QString &title, const QString &toolTip);
void insertImageItem(const QPointF &position, const QPixmap &pixmap);
void removeTab(int index);
void showAnnotator();
void showCropper();
void showScaler();
void setTabBarAutoHide(bool enabled);

private:
Config *mConfig;
Expand Down
33 changes: 33 additions & 0 deletions src/gui/KImageAnnotator.cpp
Expand Up @@ -79,6 +79,24 @@ void KImageAnnotator::loadImage(const QPixmap &pixmap)
}
}

int KImageAnnotator::addImage(const QPixmap &pixmap, const QString &title, const QString &toolTip)
{
Q_D(KImageAnnotator);
auto newTabIndex = d->mCoreView.addImage(pixmap, title, toolTip);

if (isHidden()) {
show();
}

return newTabIndex;
}

void KImageAnnotator::updateTabInfo(int index, const QString &title, const QString &toolTip)
{
Q_D(KImageAnnotator);
d->mCoreView.updateTabInfo(index, title, toolTip);
}

void KImageAnnotator::insertImageItem(const QPointF &position, const QPixmap &pixmap)
{
Q_D(KImageAnnotator);
Expand Down Expand Up @@ -132,6 +150,18 @@ void KImageAnnotator::setSmoothFactor(int factor)
d->mConfig.setSmoothFactor(factor);
}

void KImageAnnotator::setTabBarAutoHide(bool enabled)
{
Q_D(KImageAnnotator);
d->mCoreView.setTabBarAutoHide(enabled);
}

void KImageAnnotator::removeTab(int index)
{
Q_D(KImageAnnotator);
d->mCoreView.removeTab(index);
}

void KImageAnnotator::showAnnotator()
{
Q_D(KImageAnnotator);
Expand Down Expand Up @@ -163,6 +193,9 @@ KImageAnnotatorPrivate::KImageAnnotatorPrivate(KImageAnnotator *kImageAnnotator)
kImageAnnotator->hide();

kImageAnnotator->connect(&mCoreView, &CoreView::imageChanged, kImageAnnotator, &KImageAnnotator::imageChanged);
kImageAnnotator->connect(&mCoreView, &CoreView::currentTabChanged, kImageAnnotator, &KImageAnnotator::currentTabChanged);
kImageAnnotator->connect(&mCoreView, &CoreView::tabCloseRequested, kImageAnnotator, &KImageAnnotator::tabCloseRequested);
kImageAnnotator->connect(&mCoreView, &CoreView::tabMoved, kImageAnnotator, &KImageAnnotator::tabMoved);
}

} // namespace kImageAnnotator
46 changes: 46 additions & 0 deletions src/gui/annotator/AnnotationTabContent.cpp
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2020 Damir Porobic <damir.porobic@gmx.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser 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 "AnnotationTabContent.h"

namespace kImageAnnotator {

AnnotationTabContent::AnnotationTabContent(const QPixmap &pixmap, Config *config, AbstractSettingsProvider *settingsProvider) :
mAnnotationArea(new AnnotationArea(config, settingsProvider)),
mAnnotationView(new AnnotationView(mAnnotationArea)),
mMainLayout(new QHBoxLayout(this))
{
mAnnotationArea->loadImage(pixmap);
mMainLayout->addWidget(mAnnotationView);
setLayout(mMainLayout);
}

AnnotationTabContent::~AnnotationTabContent()
{
delete mMainLayout;
delete mAnnotationArea;
delete mAnnotationView;
}

AnnotationArea* AnnotationTabContent::annotationArea() const
{
return mAnnotationArea;
}

} // namespace kImageAnnotator
49 changes: 49 additions & 0 deletions src/gui/annotator/AnnotationTabContent.h
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2020 Damir Porobic <damir.porobic@gmx.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser 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 Lesser 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 ANNOTATIONTAB_H
#define ANNOTATIONTAB_H

#include <QWidget>
#include <QHBoxLayout>

#include "AnnotationView.h"
#include "AnnotationSettings.h"
#include "src/annotations/core/AnnotationArea.h"

namespace kImageAnnotator {

class AnnotationTabContent : public QWidget
{
Q_OBJECT
public:
AnnotationTabContent(const QPixmap &pixmap, Config *config, AbstractSettingsProvider *settingsProvider);
~AnnotationTabContent() override;

AnnotationArea* annotationArea() const;

private:
AnnotationArea *mAnnotationArea;
AnnotationView *mAnnotationView;
QHBoxLayout *mMainLayout;
};

} // namespace kImageAnnotator

#endif //ANNOTATIONTAB_H

0 comments on commit ab037d4

Please sign in to comment.