From 6a484c615ae3f04873fe41a415277ef6c2c37573 Mon Sep 17 00:00:00 2001 From: jaseg Date: Thu, 17 Dec 2020 15:43:37 +0100 Subject: [PATCH] WIP --- Icons.qrc | 9 ++++++ edit_tool.png | Bin 0 -> 448 bytes move_tool.png | Bin 0 -> 519 bytes numberator.cpp | 30 ++++++++++++++++++ numberator.h | 12 ++++++++ numberator.pro | 3 ++ open-iconic-master/png/tag-3x.png | Bin 0 -> 267 bytes selection_tool.png | Bin 0 -> 471 bytes sqlitebackend.h | 3 +- tag.png | Bin 0 -> 322 bytes tagitem.cpp | 9 +++++- taglistmodel.cpp | 20 ++++++++++-- tags.png | Bin 0 -> 280 bytes tagscene.cpp | 49 ++++++++++++++++++++++++++++++ tagscene.h | 16 ++++++++-- tagview.cpp | 28 ++++++++++++++++- tagview.h | 3 ++ 17 files changed, 175 insertions(+), 7 deletions(-) create mode 100644 Icons.qrc create mode 100644 edit_tool.png create mode 100644 move_tool.png create mode 100644 open-iconic-master/png/tag-3x.png create mode 100644 selection_tool.png create mode 100644 tag.png create mode 100644 tags.png diff --git a/Icons.qrc b/Icons.qrc new file mode 100644 index 0000000..5c8ced5 --- /dev/null +++ b/Icons.qrc @@ -0,0 +1,9 @@ + + + tag.png + tags.png + selection_tool.png + move_tool.png + edit_tool.png + + diff --git a/edit_tool.png b/edit_tool.png new file mode 100644 index 0000000000000000000000000000000000000000..82a859c6984255c4de386df64108db88916af790 GIT binary patch literal 448 zcmeAS@N?(olHy`uVBq!ia0y~yU{C;I4mJh`hT^KKFANL}EX7WqAsieW95oy%9SjT% zoCO|{#S9D#Z$Ox_QloG$0|SF(iEBhjaDG}zd16s2LwR|*US?i)adKios$PCk`s{Z$ zQVa}?ww^AIArY-_uk80a>>$Jbq2J2Vg6kJU*j!mFu{8>IP3IL}JXo7{X+G@RGp8yC7%yHwDaFHN1gAg#2)*Hzlvp+bAAvKPU!d=e=V-%^Q=s! zEy7H1RM)I_dA4^s=Z9$m4^o(FI?e@kF|* literal 0 HcmV?d00001 diff --git a/move_tool.png b/move_tool.png new file mode 100644 index 0000000000000000000000000000000000000000..263c21603660d6abb3a42ad24d4f85ad825608da GIT binary patch literal 519 zcmeAS@N?(olHy`uVBq!ia0y~yU{C;I4mJh`hT^KKFANL}EX7WqAsieW95oy%9SjT% zoCO|{#S9D#Z$Ox_QloG$0|SF(iEBhjaDG}zd16s2LwR|*US?i)adKios$PCk`s{Z$ zQVa}?EuJopArY--ulxE*I|{Hq(0{_j_^8*C<=6yf6(x^5P4lCfxPs2`xi;#0`UxZp zM7Nwt+V%9=@p*E_j~{xf_NG<6+WT(Zx>recUq15JZ~Vw+U%aqg@z}w<4@-4Fg&YZs ze!?vn=yq>KhiOdu1b690vmaMz1|QH1)8dFb>eu>l>5m>px6Zq>&;0mzbNhTpm&F#o zEOXAiPPrwv=Anb(=k1G{YiAldPQ03QfH$q@bZn#Xy?uPq6=5_2?(fGwk@jjo-(ichR-yE4D%{=#k_HK!%i>4LL>F!&!>S>$@+r#;{ z3RYB2yS+ZxA^cvi#jUMu-)dz48=sJV%X`X2XNh&x^`vaEi&@1|8yoEp{`zcH$s)@2 Wa_zdPFkuD;1_n=8KbLh*2~7ZcKHqEr literal 0 HcmV?d00001 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 +#include 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 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 0000000000000000000000000000000000000000..de1e4c8426988dc17a9f9d08a17b5252d76a6cc8 GIT binary patch literal 267 zcmeAS@N?(olHy`uVBq!ia0y~yV2}V|4mJh`h6m-gKNuJoSc;uILpV4%IBGajIv5xj zI14-?iy0WWg+Z8+Vb&awjUr4Zt7qIY z1TuwuSsgom%Kc&dA(@t%7}215gv&?S=mEEg0&{fq{M8*fdd*ddA5}IP^1rHN*dcIp zizS2cqS%YS*$fnmKA-%0VrT33{x@!`6cc`Nt3P0fJFreRRI>WCWmSXvM3t_7g_YWE z%C-W1Jq;dD7U!;DslTmpM8>Xp$6?zOB|BIn`Sv>>I^^zAvBTxc2YagTe~DWM4f20mY6 literal 0 HcmV?d00001 diff --git a/selection_tool.png b/selection_tool.png new file mode 100644 index 0000000000000000000000000000000000000000..d3895fac67fda8b4d413639f1a61689c0e1663b5 GIT binary patch literal 471 zcmeAS@N?(olHy`uVBq!ia0y~yU{C;I4mJh`hT^KKFANL}EX7WqAsieW95oy%9SjT% zoCO|{#S9D#Z$Ox_QloG$0|SF(iEBhjaDG}zd16s2LwR|*US?i)adKios$PCk`s{Z$ zQVa}?A)YRdArY-dukH4l<0!)L;5>KSWF4zA~^Z(x+%z^-q^*eL(v zEDOuNh3dirKf2!eI3%#no!M}pNL%1615K@h`^LobrKO0JwZzkq-94XqRL zk4^1D&uo9pv|p}yg;?y1^&8X9#2%lze8bJ0k5x&F7gcZupXdDX;@#T+eVL^(hof^s XtuC%9X`02rz`)??>gTe~DWM4f$cVnv literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..5a446f5248a8d4a33b2880fb560d45b8b496fcf9 GIT binary patch literal 322 zcmeAS@N?(olHy`uVBq!ia0y~yU{C;I4mJh`hT^KKFANL}EX7WqAsieW95oy%9SjT% zoCO|{#S9GG!XV7ZFl&wk0|UboPZ!6Kh}NT59J!he1X>^N-w}3e-U;Q7uMTo&?=A9p ze@U-IQL*hziV+)I%$_s9#T*;v7o_#{izM`2VDJ%)YLHag_Jf(nVfT5CHCqKXeyUda zzM_?5I&bHj*DL`o9O7F$bEY$_5S+#!suW|Owkep+p@&0%eGb2#jsJt$oC1nT)5Ev1 zUw>=NdD^uja^nr2iwxWa%)eyTKKkGZBc;6YypV~k)rgSiXW zgT{*IZ0U3A1GWl2D)MgGb%!Z1Ca%dq`?|uJ)2ba=Pc1uMJ=JW9uH<i_JW XuKJg1tt%K97#KWV{an^LB{Ts5zasX(%Izem%ggJk zHI2nYQz^T^=3h%wWsp|?eHm}YZq|F+^TprIX;_}LkK=;OM5c@`4^|WBmg#y9{1yp! zm;~cqh^PAn&g$i8zxycXM^J>QAYY$x62m${2h*1L$W15vGdt!hmN7lhImz{D*7TK+ zR(}4aY@qpUvtZCo#)>C;*AsetSelected(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 #include @@ -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 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 #include #include +#include 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();