summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <git-bigdata-wsl-arch@jaseg.de>2020-12-17 15:43:37 +0100
committerjaseg <git-bigdata-wsl-arch@jaseg.de>2020-12-17 15:43:37 +0100
commit6a484c615ae3f04873fe41a415277ef6c2c37573 (patch)
treeb2f429eb1baf703463821624691921e1426b7361
parentc6713d0876ce2d99f912151c9884477606909681 (diff)
downloadnumberator-master.tar.gz
numberator-master.tar.bz2
numberator-master.zip
-rw-r--r--Icons.qrc9
-rw-r--r--edit_tool.pngbin0 -> 448 bytes
-rw-r--r--move_tool.pngbin0 -> 519 bytes
-rw-r--r--numberator.cpp30
-rw-r--r--numberator.h12
-rw-r--r--numberator.pro3
-rw-r--r--open-iconic-master/png/tag-3x.pngbin0 -> 267 bytes
-rw-r--r--selection_tool.pngbin0 -> 471 bytes
-rw-r--r--sqlitebackend.h3
-rw-r--r--tag.pngbin0 -> 322 bytes
-rw-r--r--tagitem.cpp9
-rw-r--r--taglistmodel.cpp20
-rw-r--r--tags.pngbin0 -> 280 bytes
-rw-r--r--tagscene.cpp49
-rw-r--r--tagscene.h16
-rw-r--r--tagview.cpp28
-rw-r--r--tagview.h3
17 files changed, 175 insertions, 7 deletions
diff --git a/Icons.qrc b/Icons.qrc
new file mode 100644
index 0000000..5c8ced5
--- /dev/null
+++ b/Icons.qrc
@@ -0,0 +1,9 @@
+<RCC>
+ <qresource prefix="/icons">
+ <file>tag.png</file>
+ <file>tags.png</file>
+ <file>selection_tool.png</file>
+ <file>move_tool.png</file>
+ <file>edit_tool.png</file>
+ </qresource>
+</RCC>
diff --git a/edit_tool.png b/edit_tool.png
new file mode 100644
index 0000000..82a859c
--- /dev/null
+++ b/edit_tool.png
Binary files differ
diff --git a/move_tool.png b/move_tool.png
new file mode 100644
index 0000000..263c216
--- /dev/null
+++ b/move_tool.png
Binary files differ
diff --git a/numberator.cpp b/numberator.cpp
index 3161ee8..3fe6497 100644
--- a/numberator.cpp
+++ b/numberator.cpp
@@ -3,6 +3,7 @@
#include "ui_TagListDock.h"
#include <QMessageBox>
+#include <QToolbar>
Numberator::Numberator(QWidget *parent)
: QMainWindow(parent)
@@ -88,6 +89,30 @@ Numberator::Numberator(QWidget *parent)
}
});
+ QToolBar *tools_tb = new QToolBar("Tools", this);
+ struct tool_def {
+ ToolType type;
+ QString filename;
+ QString name;
+ };
+
+ std::initializer_list<struct tool_def> tool_defs = {
+ {SELECTION_TOOL, ":/icons/selection_tool.png", "Select"},
+ {TAG_TOOL, ":/icons/tag.png", "Add Tag"},
+ {MOVE_TOOL, ":/icons/move_tool.png", "Move Tag"},
+ {EDIT_TOOL, ":/icons/edit_tool.png", "Edit Tag"},
+ };
+ QActionGroup toolsActionGroup(this);
+ for (auto tool : tool_defs) {
+ auto action = tools_tb->addAction(QIcon(tool.filename), tool.name, [=](){
+ setTool(tool.type);
+ });
+ action->setCheckable(true);
+ toolsActionGroup.addAction(action);
+ }
+ toolsActionGroup.actions().first()->setChecked(true);
+ this->addToolBar(Qt::TopToolBarArea, tools_tb);
+
ui->menuView->addAction(dock->toggleViewAction());
connect(ui->actionReload_Image, &QAction::triggered, &proj, &SQLiteSaveFile::reloadImageFromDisk);
@@ -151,6 +176,11 @@ Numberator::~Numberator()
delete ui;
}
+void Numberator::setTool(Numberator::ToolType tool)
+{
+ ui->graphicsView->scene()->setTool(tool);
+}
+
bool Numberator::showConfirmDiscardDialog()
{
if (!proj.isMemory() || !proj.isDirty())
diff --git a/numberator.h b/numberator.h
index f81c44b..930a171 100644
--- a/numberator.h
+++ b/numberator.h
@@ -18,6 +18,14 @@ namespace Ui {
}
QT_END_NAMESPACE
+enum ToolType {
+ SELECTION_TOOL,
+ TAG_TOOL,
+ MOVE_TOOL,
+ EDIT_TOOL,
+ NUM_TOOLS
+};
+
class Numberator : public QMainWindow
{
Q_OBJECT
@@ -26,6 +34,8 @@ public:
Numberator(QWidget *parent = nullptr);
~Numberator();
+ void setTool(ToolType tool);
+
bool showConfirmDiscardDialog();
public slots:
@@ -45,5 +55,7 @@ private:
TagListModel tagListModel;
TagPropTableModel tagPropTableModel, dialogTagPropTableModel;
Tag m_tagBeingEdited;
+
+ ToolType m_activeTool = SELECTION_TOOL;
};
#endif // NUMBERATOR_H
diff --git a/numberator.pro b/numberator.pro
index 71b9fa3..aab09b7 100644
--- a/numberator.pro
+++ b/numberator.pro
@@ -47,3 +47,6 @@ FORMS += \
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
+
+RESOURCES += \
+ Icons.qrc
diff --git a/open-iconic-master/png/tag-3x.png b/open-iconic-master/png/tag-3x.png
new file mode 100644
index 0000000..de1e4c8
--- /dev/null
+++ b/open-iconic-master/png/tag-3x.png
Binary files differ
diff --git a/selection_tool.png b/selection_tool.png
new file mode 100644
index 0000000..d3895fa
--- /dev/null
+++ b/selection_tool.png
Binary files differ
diff --git a/sqlitebackend.h b/sqlitebackend.h
index baa3b19..a1e8026 100644
--- a/sqlitebackend.h
+++ b/sqlitebackend.h
@@ -19,7 +19,7 @@ public:
Tag() : valid(false) {}
Tag(long long int id, QString name, qreal anchor_x, qreal anchor_y, QByteArray metadata);
Tag(long long int id, const Tag &other);
- Tag(QString name, const QPointF &anchor, const QVariantMap metadata=QVariantMap());
+ Tag(QString name, const QPointF &anchor=QPointF(), const QVariantMap metadata=QVariantMap());
bool operator==(const Tag &t2) const { return id == t2.id; }
@@ -29,6 +29,7 @@ public:
long long int id;
QString name;
QPointF anchor;
+ QPointF labelPos;
QVariantMap metadata;
private:
diff --git a/tag.png b/tag.png
new file mode 100644
index 0000000..5a446f5
--- /dev/null
+++ b/tag.png
Binary files differ
diff --git a/tagitem.cpp b/tagitem.cpp
index 01b26fb..8c17ba6 100644
--- a/tagitem.cpp
+++ b/tagitem.cpp
@@ -11,7 +11,6 @@ TagItem::TagItem(const Tag &tag)
, m_margins(2, 2, 2, 2)
{
setFlags(QGraphicsItem::ItemIsSelectable
- | QGraphicsItem::ItemIsMovable
| QGraphicsItem::ItemIsFocusable
| QGraphicsItem::ItemIgnoresTransformations
| QGraphicsItem::ItemSendsGeometryChanges);
@@ -97,6 +96,9 @@ QVariant TagItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVa
*
*/
/* FIXME */
+ } else if (change == ItemSelectedChange) {
+ if (!value.toBool())
+ setFlag(QGraphicsItem::ItemIsMovable, false);
}
return QGraphicsItem::itemChange(change, value);
}
@@ -123,5 +125,10 @@ void TagItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
Q_UNUSED(event);
dragAboveThreshold = false;
+ if (isSelected())
+ setFlag(QGraphicsItem::ItemIsMovable, true);
+ else
+ setFlag(QGraphicsItem::ItemIsMovable, false);
+
QGraphicsItem::mouseReleaseEvent(event);
}
diff --git a/taglistmodel.cpp b/taglistmodel.cpp
index 435f5f1..9cf4fb7 100644
--- a/taglistmodel.cpp
+++ b/taglistmodel.cpp
@@ -24,9 +24,25 @@ bool collateTagNames(QString a, QString b) {
if (res_a.captured(1).isEmpty() && !res_b.captured(1).isEmpty())
return true;
- if (res_a.captured().toInt() < res_b.captured().toInt())
+ if (res_a.captured(1).toInt() < res_b.captured(1).toInt())
return true;
- /* FIXME TODO */
+
+ if (res_a.captured(1) != res_b.captured(1))
+ return false;
+
+ if (res_a.captured(2) < res_b.captured(2))
+ return true;
+
+ if (res_a.captured(2) != res_b.captured(2))
+ return false;
+
+ if (res_a.captured(3).isEmpty() && !res_b.captured(3).isEmpty())
+ return true;
+
+ if (res_a.captured(3).toInt() < res_b.captured(3).toInt())
+ return true;
+
+ return false;
}
void TagListModel::reloadTags()
diff --git a/tags.png b/tags.png
new file mode 100644
index 0000000..4e7a713
--- /dev/null
+++ b/tags.png
Binary files differ
diff --git a/tagscene.cpp b/tagscene.cpp
index c5777e0..a10bd2d 100644
--- a/tagscene.cpp
+++ b/tagscene.cpp
@@ -90,6 +90,29 @@ void TagScene::selectTag(const Tag &tag)
it->setSelected(true);
}
+void TagScene::setTool(ToolType tool)
+{
+ abortTool();
+ m_tool = tool;
+
+ if (tool == ToolType::TAG_TOOL) {
+ m_tagToolState = TAG_TOOL_ANCHOR;
+
+ } else if (tool == ToolType::SELECTION_TOOL) {
+
+ }
+}
+
+void TagScene::abortTool()
+{
+ if (m_tool == ToolType::TAG_TOOL) {
+ removeItem(m_previewTag);
+
+ } else if (m_tool == ToolType::SELECTION_TOOL) {
+
+ }
+}
+
void TagScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem *it = itemAt(event->scenePos(), QTransform());
@@ -111,3 +134,29 @@ void TagScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
tagDoubleClicked(tagitem->tag());
}
+
+void TagScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
+{
+ if (m_tool == ToolType::TAG_TOOL) {
+ if (m_tagToolState == TAG_TOOL_LABEL) {
+ Tag t = m_previewTag->tag();
+ t.labelPos = event->scenePos();
+ m_previewTag->tagUpdated(t);
+ }
+ }
+}
+
+void TagScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+ if (m_tool == ToolType::TAG_TOOL) {
+ if (m_tagToolState == TAG_TOOL_ANCHOR) {
+ m_previewTag->tagUpdated(Tag(m_proj->getNextAutoTagName(), event->scenePos()));
+ m_tagToolState = TAG_TOOL_LABEL;
+
+ } else { /* TAG_TOOL_LABEL */
+ removeItem(m_previewTag);
+ m_proj->createTag(m_previewTag->tag());
+ m_tagToolState = TAG_TOOL_ANCHOR;
+ }
+ }
+}
diff --git a/tagscene.h b/tagscene.h
index 18f9f54..bb83da4 100644
--- a/tagscene.h
+++ b/tagscene.h
@@ -3,6 +3,7 @@
#include "sqlitebackend.h"
#include "tagitem.h"
+#include "numberator.h"
#include <QGraphicsPixmapItem>
#include <QGraphicsScene>
@@ -14,8 +15,8 @@ class TagScene : public QGraphicsScene
Q_OBJECT
public:
- TagScene() {}
- ~TagScene() { this->blockSignals(true); }
+ TagScene() : m_previewTag(new TagItem()) {}
+ ~TagScene() { this->blockSignals(true); delete m_previewTag; }
const QGraphicsPixmapItem *backgroundPixmapItem() const { return pix_it; }
public slots:
@@ -23,6 +24,9 @@ public slots:
void reloadScene();
void selectTag(const Tag &tag);
+ void setTool(ToolType tool);
+ void abortTool();
+
void setProject(SQLiteSaveFile *proj);
signals:
@@ -31,6 +35,8 @@ signals:
protected:
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
+ void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
+ void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
private slots:
void tagChanged(TagChange change, const Tag &tag);
@@ -43,6 +49,12 @@ private:
QGraphicsPixmapItem *pix_it = nullptr;
QPixmap pix;
QMap<long long int, TagItem*> tags;
+ ToolType m_tool;
+ enum TagToolState {
+ TAG_TOOL_ANCHOR,
+ TAG_TOOL_LABEL
+ } m_tagToolState = TAG_TOOL_ANCHOR;
+ TagItem *m_previewTag;
};
#endif // TAGSCENE_H
diff --git a/tagview.cpp b/tagview.cpp
index 9a9c9a0..6bc3934 100644
--- a/tagview.cpp
+++ b/tagview.cpp
@@ -3,12 +3,13 @@
#include <QWheelEvent>
#include <QScrollBar>
#include <cmath>
+#include <QApplication>
TagView::TagView(QWidget *parent)
: QGraphicsView(parent)
, saveCenterTimer(this)
{
- setDragMode(QGraphicsView::ScrollHandDrag);
+ setDragMode(QGraphicsView::RubberBandDrag);
setScene(&m_scene);
connect(&m_scene, &TagScene::tagDoubleClicked, this, &TagView::tagDoubleClicked);
connect(&m_scene, &TagScene::imageLoaded, this, &TagView::zoomToFit);
@@ -86,6 +87,31 @@ void TagView::scrollContentsBy(int dx, int dy)
saveCenterTimer.start();
}
+void TagView::keyPressEvent(QKeyEvent *event)
+{
+ if (event->modifiers() & Qt::ControlModifier)
+ setDragMode(QGraphicsView::ScrollHandDrag);
+ else
+ setDragMode(QGraphicsView::RubberBandDrag);
+}
+
+void TagView::keyReleaseEvent(QKeyEvent *event)
+{
+ if (event->modifiers() & Qt::ControlModifier)
+ setDragMode(QGraphicsView::ScrollHandDrag);
+ else
+ setDragMode(QGraphicsView::RubberBandDrag);
+}
+
+void TagView::focusInEvent(QFocusEvent *event)
+{
+ Q_UNUSED(event);
+ if (QApplication::keyboardModifiers() & Qt::ControlModifier)
+ setDragMode(QGraphicsView::ScrollHandDrag);
+ else
+ setDragMode(QGraphicsView::RubberBandDrag);
+}
+
void TagView::saveCenter()
{
QPointF p = mapToScene(viewport()->rect().center());
diff --git a/tagview.h b/tagview.h
index 12d1088..808b100 100644
--- a/tagview.h
+++ b/tagview.h
@@ -33,6 +33,9 @@ signals:
protected:
void wheelEvent(QWheelEvent *evt) override;
void scrollContentsBy(int dx, int dy) override;
+ void keyPressEvent(QKeyEvent *event) override;
+ void keyReleaseEvent(QKeyEvent *event) override;
+ void focusInEvent(QFocusEvent *event) override;
private slots:
void saveCenter();