mirror of
https://github.com/fergalmoran/flameshot.git
synced 2025-12-22 09:51:06 +00:00
Some tweaks to the capture GUI (#1841)
* Don't show buttons if selection is inactive Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Move tool creates new selection if not visible Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Make thickness adjustment methods uniform Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com> * Hide cursor while changing thickness Signed-off-by: Haris Gušić <harisgusic.dev@gmail.com>
This commit is contained in:
@@ -49,7 +49,7 @@ CaptureWidget::CaptureWidget(uint id,
|
|||||||
QWidget* parent)
|
QWidget* parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, m_mouseIsClicked(false)
|
, m_mouseIsClicked(false)
|
||||||
, m_newSelection(false)
|
, m_newSelection(true)
|
||||||
, m_grabbing(false)
|
, m_grabbing(false)
|
||||||
, m_captureDone(false)
|
, m_captureDone(false)
|
||||||
, m_previewEnabled(true)
|
, m_previewEnabled(true)
|
||||||
@@ -188,6 +188,10 @@ CaptureWidget::CaptureWidget(uint id,
|
|||||||
// Init notification widget
|
// Init notification widget
|
||||||
m_notifierBox = new NotifierBox(this);
|
m_notifierBox = new NotifierBox(this);
|
||||||
m_notifierBox->hide();
|
m_notifierBox->hide();
|
||||||
|
connect(m_notifierBox, &NotifierBox::hidden, this, [this]() {
|
||||||
|
// Show cursor if it was hidden while adjusting tool thickness
|
||||||
|
updateCursor();
|
||||||
|
});
|
||||||
|
|
||||||
initPanel();
|
initPanel();
|
||||||
}
|
}
|
||||||
@@ -215,6 +219,7 @@ void CaptureWidget::initButtons()
|
|||||||
m_sizeIndButton = b;
|
m_sizeIndButton = b;
|
||||||
}
|
}
|
||||||
b->setColor(m_uiColor);
|
b->setColor(m_uiColor);
|
||||||
|
b->hide();
|
||||||
makeChild(b);
|
makeChild(b);
|
||||||
|
|
||||||
switch (t) {
|
switch (t) {
|
||||||
@@ -253,8 +258,6 @@ void CaptureWidget::initButtons()
|
|||||||
this,
|
this,
|
||||||
&CaptureWidget::setState);
|
&CaptureWidget::setState);
|
||||||
vectorButtons << b;
|
vectorButtons << b;
|
||||||
} else {
|
|
||||||
b->hide();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_buttonHandler->setButtons(vectorButtons);
|
m_buttonHandler->setButtons(vectorButtons);
|
||||||
@@ -494,7 +497,6 @@ void CaptureWidget::mousePressEvent(QMouseEvent* e)
|
|||||||
m_selection->setGeometry(
|
m_selection->setGeometry(
|
||||||
QRect(m_mousePressedPos, m_mousePressedPos));
|
QRect(m_mousePressedPos, m_mousePressedPos));
|
||||||
m_selection->setVisible(false);
|
m_selection->setVisible(false);
|
||||||
m_newSelection = true;
|
|
||||||
m_buttonHandler->hide();
|
m_buttonHandler->hide();
|
||||||
update();
|
update();
|
||||||
} else {
|
} else {
|
||||||
@@ -663,7 +665,7 @@ void CaptureWidget::mouseMoveEvent(QMouseEvent* e)
|
|||||||
m_buttonHandler->contains(m_context.mousePos);
|
m_buttonHandler->contains(m_context.mousePos);
|
||||||
if (containsMouse) {
|
if (containsMouse) {
|
||||||
m_buttonHandler->hide();
|
m_buttonHandler->hide();
|
||||||
} else {
|
} else if (m_selection->isVisible()) {
|
||||||
m_buttonHandler->show();
|
m_buttonHandler->show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -741,8 +743,10 @@ void CaptureWidget::mouseReleaseEvent(QMouseEvent* e)
|
|||||||
}
|
}
|
||||||
m_mouseIsClicked = false;
|
m_mouseIsClicked = false;
|
||||||
m_activeToolIsMoved = false;
|
m_activeToolIsMoved = false;
|
||||||
m_newSelection = false;
|
|
||||||
m_grabbing = false;
|
m_grabbing = false;
|
||||||
|
if (m_selection->isVisible()) {
|
||||||
|
m_newSelection = false;
|
||||||
|
}
|
||||||
|
|
||||||
updateCursor();
|
updateCursor();
|
||||||
}
|
}
|
||||||
@@ -752,6 +756,36 @@ void CaptureWidget::moveSelection(QPoint p)
|
|||||||
adjustSelection(QMargins(-p.x(), -p.y(), p.x(), p.y()));
|
adjustSelection(QMargins(-p.x(), -p.y(), p.x(), p.y()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CaptureWidget::updateThickness(int thicknessOffset)
|
||||||
|
{
|
||||||
|
m_context.thickness += thicknessOffset;
|
||||||
|
m_context.thickness = qBound(1, m_context.thickness, 100);
|
||||||
|
|
||||||
|
QPoint topLeft =
|
||||||
|
QGuiAppCurrentScreen().currentScreen()->geometry().topLeft();
|
||||||
|
int offset = m_notifierBox->width() / 4;
|
||||||
|
m_notifierBox->move(mapFromGlobal(topLeft) + QPoint(offset, offset));
|
||||||
|
m_notifierBox->showMessage(QString::number(m_context.thickness));
|
||||||
|
|
||||||
|
if (m_activeButton && m_activeButton->tool() &&
|
||||||
|
m_activeButton->tool()->showMousePreview()) {
|
||||||
|
setCursor(Qt::BlankCursor);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// update selected object thickness
|
||||||
|
auto toolItem = activeToolObject();
|
||||||
|
if (toolItem) {
|
||||||
|
toolItem->thicknessChanged(m_context.thickness);
|
||||||
|
if (!m_existingObjectIsChanged) {
|
||||||
|
m_captureToolObjectsBackup = m_captureToolObjects;
|
||||||
|
m_existingObjectIsChanged = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
emit thicknessChanged(m_context.thickness);
|
||||||
|
}
|
||||||
|
|
||||||
void CaptureWidget::moveLeft()
|
void CaptureWidget::moveLeft()
|
||||||
{
|
{
|
||||||
moveSelection(QPoint(-1, 0));
|
moveSelection(QPoint(-1, 0));
|
||||||
@@ -826,29 +860,7 @@ void CaptureWidget::wheelEvent(QWheelEvent* e)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_context.thickness += thicknessOffset;
|
updateThickness(thicknessOffset);
|
||||||
m_context.thickness = qBound(1, m_context.thickness, 100);
|
|
||||||
QPoint topLeft =
|
|
||||||
QGuiAppCurrentScreen().currentScreen()->geometry().topLeft();
|
|
||||||
int offset = m_notifierBox->width() / 4;
|
|
||||||
m_notifierBox->move(mapFromGlobal(topLeft) + QPoint(offset, offset));
|
|
||||||
m_notifierBox->showMessage(QString::number(m_context.thickness));
|
|
||||||
if (m_activeButton && m_activeButton->tool() &&
|
|
||||||
m_activeButton->tool()->showMousePreview()) {
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
// update selected object thickness
|
|
||||||
// Reset selection if mouse pos is not in selection area
|
|
||||||
auto toolItem = activeToolObject();
|
|
||||||
if (toolItem) {
|
|
||||||
toolItem->thicknessChanged(m_context.thickness);
|
|
||||||
if (!m_existingObjectIsChanged) {
|
|
||||||
m_captureToolObjectsBackup = m_captureToolObjects;
|
|
||||||
m_existingObjectIsChanged = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
emit thicknessChanged(m_context.thickness);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CaptureWidget::resizeEvent(QResizeEvent* e)
|
void CaptureWidget::resizeEvent(QResizeEvent* e)
|
||||||
@@ -1148,22 +1160,10 @@ void CaptureWidget::handleToolSignal(CaptureTool::Request r)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CaptureTool::REQ_INCREASE_TOOL_SIZE:
|
case CaptureTool::REQ_INCREASE_TOOL_SIZE:
|
||||||
// increase thickness
|
updateThickness(1);
|
||||||
m_context.thickness = qBound(1, m_context.thickness + 1, 100);
|
|
||||||
|
|
||||||
// show notifier circle
|
|
||||||
m_notifierBox->showMessage(QString::number(m_context.thickness));
|
|
||||||
|
|
||||||
emit thicknessChanged(m_context.thickness);
|
|
||||||
break;
|
break;
|
||||||
case CaptureTool::REQ_DECREASE_TOOL_SIZE:
|
case CaptureTool::REQ_DECREASE_TOOL_SIZE:
|
||||||
// decrease thickness
|
updateThickness(-1);
|
||||||
m_context.thickness = qBound(1, m_context.thickness - 1, 100);
|
|
||||||
|
|
||||||
// show notifier circle
|
|
||||||
m_notifierBox->showMessage(QString::number(m_context.thickness));
|
|
||||||
|
|
||||||
emit thicknessChanged(m_context.thickness);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -127,6 +127,7 @@ private:
|
|||||||
void repositionSelection(QRect r);
|
void repositionSelection(QRect r);
|
||||||
void adjustSelection(QMargins m);
|
void adjustSelection(QMargins m);
|
||||||
void moveSelection(QPoint p);
|
void moveSelection(QPoint p);
|
||||||
|
void updateThickness(int thicknessOffset);
|
||||||
|
|
||||||
QRect extendedSelection() const;
|
QRect extendedSelection() const;
|
||||||
QRect extendedRect(const QRect& r) const;
|
QRect extendedRect(const QRect& r) const;
|
||||||
|
|||||||
@@ -57,3 +57,8 @@ void NotifierBox::showColor(const QColor& color)
|
|||||||
Q_UNUSED(color)
|
Q_UNUSED(color)
|
||||||
m_message = QLatin1String("");
|
m_message = QLatin1String("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NotifierBox::hideEvent(QHideEvent* event)
|
||||||
|
{
|
||||||
|
emit hidden();
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ protected:
|
|||||||
virtual void enterEvent(QEvent*);
|
virtual void enterEvent(QEvent*);
|
||||||
virtual void paintEvent(QPaintEvent*);
|
virtual void paintEvent(QPaintEvent*);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void hidden();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void showMessage(const QString& msg);
|
void showMessage(const QString& msg);
|
||||||
void showColor(const QColor& color);
|
void showColor(const QColor& color);
|
||||||
@@ -26,4 +29,6 @@ private:
|
|||||||
QString m_message;
|
QString m_message;
|
||||||
QColor m_bgColor;
|
QColor m_bgColor;
|
||||||
QColor m_foregroundColor;
|
QColor m_foregroundColor;
|
||||||
|
|
||||||
|
void hideEvent(QHideEvent* event) override;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user