WIP
This commit is contained in:
parent
c6713d0876
commit
6a484c615a
17 changed files with 175 additions and 7 deletions
9
Icons.qrc
Normal file
9
Icons.qrc
Normal file
|
|
@ -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>
|
||||
BIN
edit_tool.png
Normal file
BIN
edit_tool.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 448 B |
BIN
move_tool.png
Normal file
BIN
move_tool.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 519 B |
|
|
@ -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())
|
||||
|
|
|
|||
12
numberator.h
12
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
BIN
open-iconic-master/png/tag-3x.png
Normal file
BIN
open-iconic-master/png/tag-3x.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 267 B |
BIN
selection_tool.png
Normal file
BIN
selection_tool.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 471 B |
|
|
@ -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:
|
||||
|
|
|
|||
BIN
tag.png
Normal file
BIN
tag.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 322 B |
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
BIN
tags.png
Normal file
BIN
tags.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 280 B |
49
tagscene.cpp
49
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
16
tagscene.h
16
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
|
||||
|
|
|
|||
28
tagview.cpp
28
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());
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue