viewer: allow resizing while text gizmo is active
This commit is contained in:
@@ -32,6 +32,12 @@ TextGizmo::TextGizmo(QObject *parent)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextGizmo::SetRect(const QRectF &r)
|
||||||
|
{
|
||||||
|
rect_ = r;
|
||||||
|
emit RectChanged(rect_);
|
||||||
|
}
|
||||||
|
|
||||||
void TextGizmo::UpdateInputHtml(const QString &s, const rational &time)
|
void TextGizmo::UpdateInputHtml(const QString &s, const rational &time)
|
||||||
{
|
{
|
||||||
if (input_.IsValid()) {
|
if (input_.IsValid()) {
|
||||||
@@ -41,4 +47,10 @@ void TextGizmo::UpdateInputHtml(const QString &s, const rational &time)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextGizmo::SetVerticalAlignment(Qt::Alignment va)
|
||||||
|
{
|
||||||
|
valign_ = va;
|
||||||
|
emit VerticalAlignmentChanged(valign_);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-11
@@ -33,7 +33,7 @@ public:
|
|||||||
explicit TextGizmo(QObject *parent = nullptr);
|
explicit TextGizmo(QObject *parent = nullptr);
|
||||||
|
|
||||||
const QRectF &GetRect() const { return rect_; }
|
const QRectF &GetRect() const { return rect_; }
|
||||||
void SetRect(const QRectF &r) { rect_ = r; }
|
void SetRect(const QRectF &r);
|
||||||
|
|
||||||
const QString &GetHtml() const { return text_; }
|
const QString &GetHtml() const { return text_; }
|
||||||
void SetHtml(const QString &t) { text_ = t; }
|
void SetHtml(const QString &t) { text_ = t; }
|
||||||
@@ -42,21 +42,14 @@ public:
|
|||||||
|
|
||||||
void UpdateInputHtml(const QString &s, const rational &time);
|
void UpdateInputHtml(const QString &s, const rational &time);
|
||||||
|
|
||||||
Qt::Alignment GetVerticalAlignment() const
|
Qt::Alignment GetVerticalAlignment() const { return valign_; }
|
||||||
{
|
void SetVerticalAlignment(Qt::Alignment va);
|
||||||
return valign_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetVerticalAlignment(Qt::Alignment va)
|
|
||||||
{
|
|
||||||
valign_ = va;
|
|
||||||
emit VerticalAlignmentChanged(valign_);
|
|
||||||
}
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void Activated();
|
void Activated();
|
||||||
void Deactivated();
|
void Deactivated();
|
||||||
void VerticalAlignmentChanged(Qt::Alignment va);
|
void VerticalAlignmentChanged(Qt::Alignment va);
|
||||||
|
void RectChanged(const QRectF &r);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QRectF rect_;
|
QRectF rect_;
|
||||||
|
|||||||
@@ -677,6 +677,10 @@ QTransform ViewerDisplayWidget::GenerateGizmoTransform(NodeTraverser >, const
|
|||||||
|
|
||||||
NodeGizmo *ViewerDisplayWidget::TryGizmoPress(const NodeValueRow &row, const QPointF &p)
|
NodeGizmo *ViewerDisplayWidget::TryGizmoPress(const NodeValueRow &row, const QPointF &p)
|
||||||
{
|
{
|
||||||
|
if (!gizmos_) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
for (auto it=gizmos_->GetGizmos().crbegin(); it!=gizmos_->GetGizmos().crend(); it++) {
|
for (auto it=gizmos_->GetGizmos().crbegin(); it!=gizmos_->GetGizmos().crend(); it++) {
|
||||||
NodeGizmo *gizmo = *it;
|
NodeGizmo *gizmo = *it;
|
||||||
if (gizmo->IsVisible()) {
|
if (gizmo->IsVisible()) {
|
||||||
@@ -705,6 +709,7 @@ NodeGizmo *ViewerDisplayWidget::TryGizmoPress(const NodeValueRow &row, const QPo
|
|||||||
void ViewerDisplayWidget::OpenTextGizmo(TextGizmo *text, QMouseEvent *event)
|
void ViewerDisplayWidget::OpenTextGizmo(TextGizmo *text, QMouseEvent *event)
|
||||||
{
|
{
|
||||||
active_text_gizmo_ = text;
|
active_text_gizmo_ = text;
|
||||||
|
connect(active_text_gizmo_, &TextGizmo::RectChanged, this, &ViewerDisplayWidget::UpdateActiveTextGizmoSize);
|
||||||
text_transform_ = GenerateGizmoTransform();
|
text_transform_ = GenerateGizmoTransform();
|
||||||
text_transform_inverted_ = text_transform_.inverted();
|
text_transform_inverted_ = text_transform_.inverted();
|
||||||
|
|
||||||
@@ -736,9 +741,7 @@ void ViewerDisplayWidget::OpenTextGizmo(TextGizmo *text, QMouseEvent *event)
|
|||||||
connect(text_edit_, &ViewerTextEditor::destroyed, this, &ViewerDisplayWidget::TextEditDestroyed);
|
connect(text_edit_, &ViewerTextEditor::destroyed, this, &ViewerDisplayWidget::TextEditDestroyed);
|
||||||
|
|
||||||
// Set text editor's size to logical size
|
// Set text editor's size to logical size
|
||||||
QRectF text_rect = text->GetRect();
|
QRectF text_rect = UpdateActiveTextGizmoSize();
|
||||||
text_edit_pos_ = text_rect.topLeft();
|
|
||||||
text_edit_->setGeometry(text_rect.toRect());
|
|
||||||
|
|
||||||
// Emit text gizmo activation signal
|
// Emit text gizmo activation signal
|
||||||
emit text->Activated();
|
emit text->Activated();
|
||||||
@@ -808,9 +811,9 @@ bool ViewerDisplayWidget::OnMousePress(QMouseEvent *event)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else if (text_edit_) {
|
} else if (text_edit_ && ForwardMouseEventToTextEdit(event, true)) {
|
||||||
|
|
||||||
return ForwardMouseEventToTextEdit(event, true);
|
return true;
|
||||||
|
|
||||||
} else if (event->button() == Qt::LeftButton) {
|
} else if (event->button() == Qt::LeftButton) {
|
||||||
|
|
||||||
@@ -821,8 +824,7 @@ bool ViewerDisplayWidget::OnMousePress(QMouseEvent *event)
|
|||||||
add_band_end_ = add_band_start_;
|
add_band_end_ = add_band_start_;
|
||||||
add_band_ = true;
|
add_band_ = true;
|
||||||
|
|
||||||
} else if (gizmos_
|
} else if ((current_gizmo_ = TryGizmoPress(gizmo_db_, gizmo_last_draw_transform_inverted_.map(event->pos())))) {
|
||||||
&& (current_gizmo_ = TryGizmoPress(gizmo_db_, gizmo_last_draw_transform_inverted_.map(event->pos())))) {
|
|
||||||
|
|
||||||
// Handle gizmo click
|
// Handle gizmo click
|
||||||
gizmo_start_drag_ = event->pos();
|
gizmo_start_drag_ = event->pos();
|
||||||
@@ -856,18 +858,9 @@ bool ViewerDisplayWidget::OnMouseMove(QMouseEvent *event)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else if (text_edit_) {
|
} else if (text_edit_ && ForwardMouseEventToTextEdit(event)) {
|
||||||
|
|
||||||
if (event->buttons() == Qt::NoButton) {
|
return true;
|
||||||
QPointF mapped = text_transform_inverted_.map(event->pos()) - text_edit_pos_;
|
|
||||||
if (mapped.x() >= 0 && mapped.y() >= 0 && mapped.x() < text_edit_->width() && mapped.y() < text_edit_->height()) {
|
|
||||||
inner_widget()->setCursor(Qt::IBeamCursor);
|
|
||||||
} else {
|
|
||||||
inner_widget()->unsetCursor();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ForwardMouseEventToTextEdit(event);
|
|
||||||
|
|
||||||
} else if (add_band_) {
|
} else if (add_band_) {
|
||||||
|
|
||||||
@@ -927,9 +920,9 @@ bool ViewerDisplayWidget::OnMouseRelease(QMouseEvent *e)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else if (text_edit_) {
|
} else if (text_edit_ && ForwardMouseEventToTextEdit(e)) {
|
||||||
|
|
||||||
return ForwardMouseEventToTextEdit(e);
|
return true;
|
||||||
|
|
||||||
} else if (add_band_) {
|
} else if (add_band_) {
|
||||||
|
|
||||||
@@ -964,8 +957,8 @@ bool ViewerDisplayWidget::OnMouseRelease(QMouseEvent *e)
|
|||||||
|
|
||||||
bool ViewerDisplayWidget::OnMouseDoubleClick(QMouseEvent *event)
|
bool ViewerDisplayWidget::OnMouseDoubleClick(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (text_edit_) {
|
if (text_edit_ && ForwardMouseEventToTextEdit(event)) {
|
||||||
return ForwardMouseEventToTextEdit(event);
|
return true;
|
||||||
} else if (event->button() == Qt::LeftButton && gizmos_) {
|
} else if (event->button() == Qt::LeftButton && gizmos_) {
|
||||||
QPointF ptr = TransformViewerSpaceToBufferSpace(event->pos());
|
QPointF ptr = TransformViewerSpaceToBufferSpace(event->pos());
|
||||||
foreach (NodeGizmo *g, gizmos_->GetGizmos()) {
|
foreach (NodeGizmo *g, gizmos_->GetGizmos()) {
|
||||||
@@ -1148,13 +1141,31 @@ void ViewerDisplayWidget::ForwardDragEventToTextEdit(T *e)
|
|||||||
|
|
||||||
bool ViewerDisplayWidget::ForwardMouseEventToTextEdit(QMouseEvent *event, bool check_if_outside)
|
bool ViewerDisplayWidget::ForwardMouseEventToTextEdit(QMouseEvent *event, bool check_if_outside)
|
||||||
{
|
{
|
||||||
|
if (current_gizmo_) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Transform screen mouse coords to world mouse coords
|
// Transform screen mouse coords to world mouse coords
|
||||||
QPointF local_pos = GetVirtualPosForTextEdit(event->pos());
|
QPointF local_pos = GetVirtualPosForTextEdit(event->pos());
|
||||||
|
|
||||||
|
if (event->type() == QEvent::MouseMove && event->buttons() == Qt::NoButton) {
|
||||||
|
QPointF mapped = text_transform_inverted_.map(event->pos()) - text_edit_pos_;
|
||||||
|
if (mapped.x() >= 0 && mapped.y() >= 0 && mapped.x() < text_edit_->width() && mapped.y() < text_edit_->height()) {
|
||||||
|
inner_widget()->setCursor(Qt::IBeamCursor);
|
||||||
|
} else {
|
||||||
|
inner_widget()->unsetCursor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (check_if_outside) {
|
if (check_if_outside) {
|
||||||
if (local_pos.x() < 0 || local_pos.x() >= text_edit_->width() || local_pos.y() < 0 || local_pos.y() >= text_edit_->height()) {
|
if (local_pos.x() < 0 || local_pos.x() >= text_edit_->width() || local_pos.y() < 0 || local_pos.y() >= text_edit_->height()) {
|
||||||
CloseTextEditor();
|
// Allow clicking other gizmos so the user can resize while the text editor is active
|
||||||
return true;
|
if ((current_gizmo_ = TryGizmoPress(gizmo_db_, gizmo_last_draw_transform_inverted_.map(event->pos())))) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
CloseTextEditor();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1191,6 +1202,9 @@ void ViewerDisplayWidget::CloseTextEditor()
|
|||||||
{
|
{
|
||||||
text_edit_->deleteLater();
|
text_edit_->deleteLater();
|
||||||
text_edit_ = nullptr;
|
text_edit_ = nullptr;
|
||||||
|
|
||||||
|
disconnect(active_text_gizmo_, &TextGizmo::RectChanged, this, &ViewerDisplayWidget::UpdateActiveTextGizmoSize);
|
||||||
|
active_text_gizmo_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewerDisplayWidget::GenerateGizmoTransforms()
|
void ViewerDisplayWidget::GenerateGizmoTransforms()
|
||||||
@@ -1382,4 +1396,12 @@ void ViewerDisplayWidget::FocusChanged(QWidget *old, QWidget *now)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QRectF ViewerDisplayWidget::UpdateActiveTextGizmoSize()
|
||||||
|
{
|
||||||
|
QRectF text_rect = active_text_gizmo_->GetRect();
|
||||||
|
text_edit_pos_ = text_rect.topLeft();
|
||||||
|
text_edit_->setGeometry(text_rect.toRect());
|
||||||
|
return text_rect;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -438,6 +438,8 @@ private slots:
|
|||||||
|
|
||||||
void FocusChanged(QWidget *old, QWidget *now);
|
void FocusChanged(QWidget *old, QWidget *now);
|
||||||
|
|
||||||
|
QRectF UpdateActiveTextGizmoSize();
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user