NC/Edit text objects on double click (#1578)
* Edit existing text objects (cherry picked from commit 3d6edca21b5615481d0ab409801baeafb523ce72) * Add 'info' to the panel for the text tool object (cherry picked from commit 2b633f560e46a0112d70653f6c55da5e97ce4cc8) * Add 'info' to the panel for the CircleCount tool object (cherry picked from commit 5ff5b667c1d6c534fe447618f9938a4581f0c9f2) * Set text settings active in the Tool Settings panel on edit text (cherry picked from commit a020a3504c0d02bbca4bb870e12e80ee87d64f75) * Set font family in the Tool Settings panel on edit text object (cherry picked from commit 70fe9bd5e79f39d544ed2d7848d05492da9b52bd) Co-authored-by: Yuriy Puchkov <yuriy.puchkov@namecheap.com>
This commit is contained in:
@@ -267,19 +267,16 @@ QPixmap CaptureWidget::pixmap()
|
||||
// tool.
|
||||
bool CaptureWidget::commitCurrentTool()
|
||||
{
|
||||
if (m_activeButton && m_activeTool) {
|
||||
if (m_activeTool->isValid() && m_toolWidget) {
|
||||
if (m_activeTool) {
|
||||
if (m_activeTool->isValid() && !m_activeTool->editMode() &&
|
||||
m_toolWidget) {
|
||||
pushToolToStack();
|
||||
} else {
|
||||
m_activeTool->deleteLater();
|
||||
m_activeTool = nullptr;
|
||||
}
|
||||
if (m_toolWidget) {
|
||||
m_toolWidget->close();
|
||||
delete m_toolWidget;
|
||||
m_toolWidget = nullptr;
|
||||
return true;
|
||||
if (m_activeTool) {
|
||||
m_activeTool->setEditMode(false);
|
||||
}
|
||||
releaseActiveTool();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -306,13 +303,29 @@ void CaptureWidget::deleteToolWidgetOrClose()
|
||||
}
|
||||
}
|
||||
|
||||
void CaptureWidget::releaseActiveTool()
|
||||
{
|
||||
if (m_activeTool) {
|
||||
if (-1 == m_panel->activeLayerIndex() && m_activeButton) {
|
||||
// delete tool if no active selection, otherwise object shouldn't be
|
||||
// deleted, because it is in undo/redo stack
|
||||
m_activeTool->deleteLater();
|
||||
}
|
||||
m_activeTool = nullptr;
|
||||
}
|
||||
if (m_toolWidget) {
|
||||
m_toolWidget->close();
|
||||
delete m_toolWidget;
|
||||
m_toolWidget = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void CaptureWidget::uncheckActiveTool()
|
||||
{
|
||||
// uncheck active tool
|
||||
m_activeButton->setColor(m_uiColor);
|
||||
m_activeButton = nullptr;
|
||||
m_activeTool->deleteLater();
|
||||
m_activeTool = nullptr;
|
||||
releaseActiveTool();
|
||||
updateCursor();
|
||||
update(); // clear mouse preview
|
||||
}
|
||||
@@ -389,8 +402,7 @@ bool CaptureWidget::startDrawObjectTool(const QPoint& pos)
|
||||
m_captureToolObjects.append(m_activeTool);
|
||||
m_undoStack.push(
|
||||
new ModificationCommand(this, m_captureToolObjects));
|
||||
m_activeTool->deleteLater();
|
||||
m_activeTool = nullptr;
|
||||
releaseActiveTool();
|
||||
m_mouseIsClicked = false;
|
||||
}
|
||||
return true;
|
||||
@@ -398,16 +410,17 @@ bool CaptureWidget::startDrawObjectTool(const QPoint& pos)
|
||||
return false;
|
||||
}
|
||||
|
||||
void CaptureWidget::selectToolItemAtPos(const QPoint& pos)
|
||||
int CaptureWidget::selectToolItemAtPos(const QPoint& pos)
|
||||
{
|
||||
// Try to select existing tool
|
||||
// Try to select existing tool, "-1" - no active tool
|
||||
int activeLayerIndex = -1;
|
||||
if (m_activeButton.isNull() &&
|
||||
m_captureToolObjects.captureToolObjects().size() > 0 &&
|
||||
m_selection->getMouseSide(pos) == SelectionWidget::NO_SIDE) {
|
||||
auto toolItem = activeToolObject();
|
||||
if (!toolItem ||
|
||||
(toolItem && !toolItem->selectionRect().contains(pos))) {
|
||||
int activeLayerIndex = m_captureToolObjects.find(pos, size());
|
||||
activeLayerIndex = m_captureToolObjects.find(pos, size());
|
||||
int thickness_old = m_context.thickness;
|
||||
m_panel->setActiveLayer(activeLayerIndex);
|
||||
drawObjectSelection();
|
||||
@@ -416,6 +429,7 @@ void CaptureWidget::selectToolItemAtPos(const QPoint& pos)
|
||||
}
|
||||
}
|
||||
}
|
||||
return activeLayerIndex;
|
||||
}
|
||||
|
||||
void CaptureWidget::mousePressEvent(QMouseEvent* e)
|
||||
@@ -457,12 +471,38 @@ void CaptureWidget::mousePressEvent(QMouseEvent* e)
|
||||
}
|
||||
}
|
||||
|
||||
// Try to select existing tool
|
||||
// Commit current tool if it has edit widget and mouse click is outside of
|
||||
// it
|
||||
if (m_toolWidget && !m_toolWidget->geometry().contains(e->pos())) {
|
||||
commitCurrentTool();
|
||||
m_panel->setToolWidget(nullptr);
|
||||
drawToolsData();
|
||||
update();
|
||||
}
|
||||
|
||||
selectToolItemAtPos(m_mousePressedPos);
|
||||
|
||||
updateCursor();
|
||||
}
|
||||
|
||||
void CaptureWidget::mouseDoubleClickEvent(QMouseEvent* event)
|
||||
{
|
||||
int activeLayerIndex = m_panel->activeLayerIndex();
|
||||
if (activeLayerIndex != -1) {
|
||||
// Start object editing
|
||||
m_activeTool = m_captureToolObjects.at(activeLayerIndex);
|
||||
if (m_activeTool && m_activeTool->nameID() == ToolType::TEXT) {
|
||||
m_mouseIsClicked = false;
|
||||
m_context.mousePos = *m_activeTool->pos();
|
||||
m_activeTool->setEditMode(true);
|
||||
drawToolsData(true, false);
|
||||
m_mouseIsClicked = false;
|
||||
handleButtonSignal(CaptureTool::REQ_ADD_CHILD_WIDGET);
|
||||
m_panel->setToolWidget(m_activeTool->configurationWidget());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CaptureWidget::mouseMoveEvent(QMouseEvent* e)
|
||||
{
|
||||
m_context.mousePos = e->pos();
|
||||
@@ -588,6 +628,7 @@ void CaptureWidget::mouseMoveEvent(QMouseEvent* e)
|
||||
void CaptureWidget::mouseReleaseEvent(QMouseEvent* e)
|
||||
{
|
||||
if (e->button() == Qt::RightButton || m_colorPicker->isVisible()) {
|
||||
// Color picker
|
||||
m_colorPicker->hide();
|
||||
if (!m_context.color.isValid()) {
|
||||
m_context.color = ConfigHandler().drawColorValue();
|
||||
@@ -604,8 +645,7 @@ void CaptureWidget::mouseReleaseEvent(QMouseEvent* e)
|
||||
if (m_activeTool->isValid()) {
|
||||
pushToolToStack();
|
||||
} else if (!m_toolWidget) {
|
||||
m_activeTool->deleteLater();
|
||||
m_activeTool = nullptr;
|
||||
releaseActiveTool();
|
||||
}
|
||||
} else {
|
||||
if (m_activeToolIsMoved) {
|
||||
@@ -625,9 +665,10 @@ void CaptureWidget::mouseReleaseEvent(QMouseEvent* e)
|
||||
}
|
||||
}
|
||||
|
||||
// Show the buttons after the resize of the selection or the creation
|
||||
// of a new one.
|
||||
if (!m_buttonHandler->isVisible() && m_selection->isVisible()) {
|
||||
// Show the buttons after the resize of the selection or the creation
|
||||
// of a new one.
|
||||
|
||||
// Don't go outside
|
||||
QRect newGeometry = m_selection->geometry().intersected(rect());
|
||||
// normalize
|
||||
@@ -924,15 +965,8 @@ void CaptureWidget::setState(CaptureToolButton* b)
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_toolWidget) {
|
||||
m_toolWidget->close();
|
||||
delete m_toolWidget;
|
||||
m_toolWidget = nullptr;
|
||||
if (m_activeTool != nullptr) {
|
||||
if (m_activeTool->isValid()) {
|
||||
pushToolToStack();
|
||||
}
|
||||
}
|
||||
if (m_toolWidget && m_activeTool && m_activeTool->isValid()) {
|
||||
pushToolToStack();
|
||||
}
|
||||
if (m_activeButton != b) {
|
||||
processTool(b->tool());
|
||||
@@ -946,7 +980,7 @@ void CaptureWidget::setState(CaptureToolButton* b)
|
||||
if (b->tool()->isSelectable()) {
|
||||
if (m_activeButton != b) {
|
||||
QWidget* confW = b->tool()->configurationWidget();
|
||||
m_panel->addToolWidget(confW);
|
||||
m_panel->setToolWidget(confW);
|
||||
if (m_activeButton) {
|
||||
m_activeButton->setColor(m_uiColor);
|
||||
}
|
||||
@@ -1360,9 +1394,9 @@ void CaptureWidget::pushToolToStack()
|
||||
disconnect(m_panel->toolWidget(), nullptr, m_activeTool, nullptr);
|
||||
}
|
||||
|
||||
m_activeTool->setEditMode(false);
|
||||
m_captureToolObjects.append(m_activeTool);
|
||||
m_activeTool->deleteLater();
|
||||
m_activeTool = nullptr;
|
||||
releaseActiveTool();
|
||||
}
|
||||
|
||||
// push current state to the undo stack
|
||||
@@ -1402,7 +1436,7 @@ void CaptureWidget::drawToolsData(bool updateLayersPanel, bool drawSelection)
|
||||
void CaptureWidget::drawObjectSelection()
|
||||
{
|
||||
auto toolItem = activeToolObject();
|
||||
if (toolItem) {
|
||||
if (toolItem && !toolItem->editMode()) {
|
||||
QPainter painter(&m_context.screenshot);
|
||||
toolItem->drawObjectSelection(painter);
|
||||
if (m_context.thickness != toolItem->thickness()) {
|
||||
|
||||
Reference in New Issue
Block a user