Commit 91cc99e8 authored by jean lima andrade's avatar jean lima andrade
Browse files

Add support for mouse double click event in text painter

parent f6645862
......@@ -40,7 +40,7 @@ void TextPainter::changeItem(const QString& path)
void TextPainter::paint(QPoint point, bool isDragging)
{
auto textCursor = m_textEdit->cursorForPosition(point);
QTextCursor textCursor = m_textEdit->cursorForPosition(point);
Sentence *currentSentence = static_cast<Sentence*>(m_parent->currentObject());
......@@ -50,21 +50,31 @@ void TextPainter::paint(QPoint point, bool isDragging)
m_anchor = textCursor.position() - 1;
double end = textCursor.position();
bool toPaint = true;
int idxNearbySentence = -1;
int idxDoubleClick = -1;
for (int i = 0; i < m_parent->savedObjects().size(); i++) {
Sentence *obj = static_cast<Sentence*>(m_parent->savedObjects()[i]);
if (obj->hasBetween(m_anchor) || obj->hasBetween(end)) {
toPaint = false;
break;
}
if (obj->hasBetween(m_anchor) || obj->hasBetween(end))
return;
else if (m_anchor == obj->YValueOf() || end == obj->XValueOf()) {
idxNearbySentence = i;
break;
}
else if (obj->YValueOf() - obj->XValueOf() == 1 && end == obj->YValueOf()) {
idxDoubleClick = i;
break;
}
}
if (idxNearbySentence != -1) {
if (idxDoubleClick != -1) {
toSave = true;
textCursor.select(QTextCursor::WordUnderCursor);
m_anchor = textCursor.anchor();
end = textCursor.position();
m_parent->savedObjects().remove(idxDoubleClick);
}
else if (idxNearbySentence != -1) {
MarkedObject* obj = m_parent->savedObjects()[idxNearbySentence];
if (currentSentence->objClass() == obj->objClass()) {
if (end == obj->XValueOf())
......@@ -75,10 +85,8 @@ void TextPainter::paint(QPoint point, bool isDragging)
}
}
if (toPaint) {
currentSentence->append(std::min(m_anchor, end), std::max(end, m_anchor));
repaint();
}
currentSentence->append(std::min(m_anchor, end), std::max(end, m_anchor));
repaint();
}
if (toSave) {
m_parent->appendObject(currentSentence);
......
......@@ -27,22 +27,23 @@ Container::~Container()
void Container::mousePressEvent(QMouseEvent* event)
{
m_painter->paint(event->pos(), false);
QWidget::mousePressEvent(event);
}
void Container::mouseMoveEvent(QMouseEvent* event)
{
m_painter->paint(event->pos(), true);
QWidget::mouseMoveEvent(event);
}
void Container::mouseReleaseEvent(QMouseEvent* event)
{
m_painter->paint(QPoint(), false);
}
QWidget::mouseReleaseEvent(event);
void Container::mouseDoubleClickEvent(QMouseEvent* event)
{
TextPainter *textPainter = dynamic_cast<TextPainter*>(m_painter);
if (textPainter)
m_painter->paint(event->pos(), false);
}
void Container::changeItem(const QString& path)
......
......@@ -36,6 +36,11 @@ public:
*/
void mouseMoveEvent(QMouseEvent* event) override;
/** Treat mouse double click event.
* @param event - mouse event to treat.
*/
void mouseDoubleClickEvent(QMouseEvent* event) override;
/** @return pointer of the current Painter. */
Painter* painter() const { return m_painter; }
......
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