capturewidget refactor (#1114)
* Renaming methods for better file outline * Moving redundant code into helper functions * Combine implementation of move and resize * Remove checks from move
This commit is contained in:
@@ -551,46 +551,29 @@ void CaptureWidget::mouseReleaseEvent(QMouseEvent* e)
|
||||
updateCursor();
|
||||
}
|
||||
|
||||
void CaptureWidget::leftMove()
|
||||
void CaptureWidget::moveSelection(QPoint p)
|
||||
{
|
||||
if (m_selection->geometry().left() > rect().left()) {
|
||||
m_selection->move(QPoint(m_selection->x() - 1, m_selection->y()));
|
||||
m_buttonHandler->updatePosition(m_selection->geometry());
|
||||
update();
|
||||
}
|
||||
adjustSelection(QMargins(-p.x(), -p.y(), p.x(), p.y()));
|
||||
}
|
||||
|
||||
void CaptureWidget::rightMove()
|
||||
void CaptureWidget::moveLeft()
|
||||
{
|
||||
if (m_selection->geometry().right() < rect().right()) {
|
||||
m_selection->move(QPoint(m_selection->x() + 1, m_selection->y()));
|
||||
QRect newGeometry = m_selection->geometry().intersected(rect());
|
||||
m_context.selection = extendedRect(&newGeometry);
|
||||
m_buttonHandler->updatePosition(m_selection->geometry());
|
||||
update();
|
||||
}
|
||||
moveSelection(QPoint(-1, 0));
|
||||
}
|
||||
|
||||
void CaptureWidget::upMove()
|
||||
void CaptureWidget::moveRight()
|
||||
{
|
||||
if (m_selection->geometry().top() > rect().top()) {
|
||||
m_selection->move(QPoint(m_selection->x(), m_selection->y() - 1));
|
||||
QRect newGeometry = m_selection->geometry().intersected(rect());
|
||||
m_context.selection = extendedRect(&newGeometry);
|
||||
m_buttonHandler->updatePosition(m_selection->geometry());
|
||||
update();
|
||||
}
|
||||
moveSelection(QPoint(1, 0));
|
||||
}
|
||||
|
||||
void CaptureWidget::downMove()
|
||||
void CaptureWidget::moveUp()
|
||||
{
|
||||
if (m_selection->geometry().bottom() < rect().bottom()) {
|
||||
m_selection->move(QPoint(m_selection->x(), m_selection->y() + 1));
|
||||
QRect newGeometry = m_selection->geometry().intersected(rect());
|
||||
m_context.selection = extendedRect(&newGeometry);
|
||||
m_buttonHandler->updatePosition(m_selection->geometry());
|
||||
update();
|
||||
}
|
||||
moveSelection(QPoint(0, -1));
|
||||
}
|
||||
|
||||
void CaptureWidget::moveDown()
|
||||
{
|
||||
moveSelection(QPoint(0, 1));
|
||||
}
|
||||
|
||||
void CaptureWidget::keyPressEvent(QKeyEvent* e)
|
||||
@@ -897,12 +880,10 @@ void CaptureWidget::setDrawThickness(const int& t)
|
||||
emit thicknessChanged(m_context.thickness);
|
||||
}
|
||||
|
||||
void CaptureWidget::leftResize()
|
||||
void CaptureWidget::repositionSelection(QRect r)
|
||||
{
|
||||
if (m_selection->isVisible() &&
|
||||
m_selection->geometry().right() > m_selection->geometry().left()) {
|
||||
m_selection->setGeometry(m_selection->geometry() +
|
||||
QMargins(0, 0, -1, 0));
|
||||
if (m_selection->isVisible()) {
|
||||
m_selection->setGeometry(r);
|
||||
QRect newGeometry = m_selection->geometry().intersected(rect());
|
||||
m_context.selection = extendedRect(&newGeometry);
|
||||
m_buttonHandler->updatePosition(m_selection->geometry());
|
||||
@@ -911,46 +892,32 @@ void CaptureWidget::leftResize()
|
||||
}
|
||||
}
|
||||
|
||||
void CaptureWidget::rightResize()
|
||||
void CaptureWidget::adjustSelection(QMargins m)
|
||||
{
|
||||
if (m_selection->isVisible() &&
|
||||
m_selection->geometry().right() < rect().right()) {
|
||||
m_selection->setGeometry(m_selection->geometry() +
|
||||
QMargins(0, 0, 1, 0));
|
||||
QRect newGeometry = m_selection->geometry().intersected(rect());
|
||||
m_context.selection = extendedRect(&newGeometry);
|
||||
m_buttonHandler->updatePosition(m_selection->geometry());
|
||||
updateSizeIndicator();
|
||||
update();
|
||||
QRect newGeometry = m_selection->geometry() + m;
|
||||
if (rect().contains(newGeometry)) {
|
||||
repositionSelection(newGeometry);
|
||||
}
|
||||
}
|
||||
|
||||
void CaptureWidget::upResize()
|
||||
void CaptureWidget::resizeLeft()
|
||||
{
|
||||
if (m_selection->isVisible() &&
|
||||
m_selection->geometry().bottom() > m_selection->geometry().top()) {
|
||||
m_selection->setGeometry(m_selection->geometry() +
|
||||
QMargins(0, 0, 0, -1));
|
||||
QRect newGeometry = m_selection->geometry().intersected(rect());
|
||||
m_context.selection = extendedRect(&newGeometry);
|
||||
m_buttonHandler->updatePosition(m_selection->geometry());
|
||||
updateSizeIndicator();
|
||||
update();
|
||||
}
|
||||
adjustSelection(QMargins(0, 0, -1, 0));
|
||||
}
|
||||
|
||||
void CaptureWidget::downResize()
|
||||
void CaptureWidget::resizeRight()
|
||||
{
|
||||
if (m_selection->isVisible() &&
|
||||
m_selection->geometry().bottom() < rect().bottom()) {
|
||||
m_selection->setGeometry(m_selection->geometry() +
|
||||
QMargins(0, 0, 0, 1));
|
||||
QRect newGeometry = m_selection->geometry().intersected(rect());
|
||||
m_context.selection = extendedRect(&newGeometry);
|
||||
m_buttonHandler->updatePosition(m_selection->geometry());
|
||||
updateSizeIndicator();
|
||||
update();
|
||||
}
|
||||
adjustSelection(QMargins(0, 0, 1, 0));
|
||||
}
|
||||
|
||||
void CaptureWidget::resizeUp()
|
||||
{
|
||||
adjustSelection(QMargins(0, 0, 0, -1));
|
||||
}
|
||||
|
||||
void CaptureWidget::resizeDown()
|
||||
{
|
||||
adjustSelection(QMargins(0, 0, 0, 1));
|
||||
}
|
||||
|
||||
void CaptureWidget::initShortcuts()
|
||||
@@ -985,29 +952,29 @@ void CaptureWidget::initShortcuts()
|
||||
|
||||
new QShortcut(QKeySequence(ConfigHandler().shortcut("TYPE_RESIZE_LEFT")),
|
||||
this,
|
||||
SLOT(leftResize()));
|
||||
SLOT(resizeLeft()));
|
||||
new QShortcut(QKeySequence(ConfigHandler().shortcut("TYPE_RESIZE_RIGHT")),
|
||||
this,
|
||||
SLOT(rightResize()));
|
||||
SLOT(resizeRight()));
|
||||
new QShortcut(QKeySequence(ConfigHandler().shortcut("TYPE_RESIZE_UP")),
|
||||
this,
|
||||
SLOT(upResize()));
|
||||
SLOT(resizeUp()));
|
||||
new QShortcut(QKeySequence(ConfigHandler().shortcut("TYPE_RESIZE_DOWN")),
|
||||
this,
|
||||
SLOT(downResize()));
|
||||
SLOT(resizeDown()));
|
||||
|
||||
new QShortcut(QKeySequence(ConfigHandler().shortcut("TYPE_MOVE_LEFT")),
|
||||
this,
|
||||
SLOT(leftMove()));
|
||||
SLOT(moveLeft()));
|
||||
new QShortcut(QKeySequence(ConfigHandler().shortcut("TYPE_MOVE_RIGHT")),
|
||||
this,
|
||||
SLOT(rightMove()));
|
||||
SLOT(moveRight()));
|
||||
new QShortcut(QKeySequence(ConfigHandler().shortcut("TYPE_MOVE_UP")),
|
||||
this,
|
||||
SLOT(upMove()));
|
||||
SLOT(moveUp()));
|
||||
new QShortcut(QKeySequence(ConfigHandler().shortcut("TYPE_MOVE_DOWN")),
|
||||
this,
|
||||
SLOT(downMove()));
|
||||
SLOT(moveDown()));
|
||||
|
||||
new QShortcut(
|
||||
QKeySequence(ConfigHandler().shortcut("TYPE_COMMIT_CURRENT_TOOL")),
|
||||
|
||||
Reference in New Issue
Block a user