Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set circle count on "Ctrl+Scroll Wheel" #2162

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/tools/capturecontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ struct CaptureContext
QPoint mousePos;
// Size of the active tool
int toolSize;
// Current circle count
int circleCount;
// Mode of the capture widget
bool fullscreen;
CaptureRequest request = CaptureRequest::GRAPHICAL_MODE;
Expand Down
39 changes: 29 additions & 10 deletions src/widgets/capture/capturewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ CaptureWidget::CaptureWidget(const CaptureRequest& req,
m_buttonHandler->updateScreenRegions(areas);
m_buttonHandler->hide();

m_context.circleCount = 1;

initButtons();
initSelection(); // button handler must be initialized before
initShortcuts(); // must be called after initSelection
Expand Down Expand Up @@ -554,6 +556,7 @@ bool CaptureWidget::startDrawObjectTool(const QPoint& pos)
// While it is based on AbstractTwoPointTool it has the only one
// point and shouldn't wait for second point and move event
m_activeTool->drawEnd(m_context.mousePos);
m_activeTool->setCount(m_context.circleCount++);

m_captureToolObjectsBackup = m_captureToolObjects;
m_captureToolObjects.append(m_activeTool);
Expand Down Expand Up @@ -797,6 +800,20 @@ void CaptureWidget::setToolSize(int size)
}
}

/**
* Show notifier box displaying the selected circle count
*/
void CaptureWidget::setCircleCount(int count)
{
m_context.circleCount = count;

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.circleCount));
}

void CaptureWidget::keyPressEvent(QKeyEvent* e)
{
// If the key is a digit, change the tool size
Expand Down Expand Up @@ -843,29 +860,35 @@ void CaptureWidget::wheelEvent(QWheelEvent* e)
* impossible to scroll. It's easier to calculate number of requests and do
* not accept events faster that one in 200ms.
* */
int toolSizeOffset = 0;
int offset = 0;
if (e->angleDelta().y() >= 60) {
// mouse scroll (wheel) increment
toolSizeOffset = 1;
offset = 1;
} else if (e->angleDelta().y() <= -60) {
// mouse scroll (wheel) decrement
toolSizeOffset = -1;
offset = -1;
} else {
// touchpad scroll
qint64 current = QDateTime::currentMSecsSinceEpoch();
if ((current - m_lastMouseWheel) > 200) {
if (e->angleDelta().y() > 0) {
toolSizeOffset = 1;
offset = 1;
} else if (e->angleDelta().y() < 0) {
toolSizeOffset = -1;
offset = -1;
}
m_lastMouseWheel = current;
} else {
return;
}
}

setToolSize(m_context.toolSize + toolSizeOffset);
bool counterMod = qApp->keyboardModifiers() & Qt::ControlModifier;

if (counterMod) {
setCircleCount(m_context.circleCount + offset);
} else {
setToolSize(m_context.toolSize + offset);
}
}

void CaptureWidget::resizeEvent(QResizeEvent* e)
Expand Down Expand Up @@ -1475,11 +1498,7 @@ void CaptureWidget::drawToolsData()
// TODO refactor this for performance. The objects should not all be updated
// at once every time
QPixmap pixmapItem = m_context.origScreenshot;
int circleCount = 1;
for (auto toolItem : m_captureToolObjects.captureToolObjects()) {
if (toolItem->type() == CaptureTool::TYPE_CIRCLECOUNT) {
toolItem->setCount(circleCount++);
}
processPixmapWithTool(&pixmapItem, toolItem);
update(paddedUpdateRect(toolItem->boundingRect()));
}
Expand Down
1 change: 1 addition & 0 deletions src/widgets/capture/capturewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ private slots:
const char* slot);

void setToolSize(int size);
void setCircleCount(int count);

QRect extendedSelection() const;
QRect extendedRect(const QRect& r) const;
Expand Down