Skip to content

Commit

Permalink
Add shortcut for Grab Color
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexP11223 committed Oct 22, 2023
1 parent 0bbb952 commit 0ab4590
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/config/shortcutswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ void ShortcutsWidget::loadShortcuts()

// additional tools that don't have their own buttons
appendShortcut("TYPE_TOGGLE_PANEL", tr("Toggle side panel"));
appendShortcut("TYPE_GRAB_COLOR", tr("Grab color"));
appendShortcut("TYPE_RESIZE_LEFT", tr("Resize selection left 1px"));
appendShortcut("TYPE_RESIZE_RIGHT", tr("Resize selection right 1px"));
appendShortcut("TYPE_RESIZE_UP", tr("Resize selection up 1px"));
Expand Down
1 change: 1 addition & 0 deletions src/utils/confighandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ static QMap<QString, QSharedPointer<KeySequence>> recognizedShortcuts = {
SHORTCUT("TYPE_REDO" , "Ctrl+Shift+Z" ),
SHORTCUT("TYPE_TEXT" , "T" ),
SHORTCUT("TYPE_TOGGLE_PANEL" , "Space" ),
SHORTCUT("TYPE_GRAB_COLOR" , "G" ),
SHORTCUT("TYPE_RESIZE_LEFT" , "Shift+Left" ),
SHORTCUT("TYPE_RESIZE_RIGHT" , "Shift+Right" ),
SHORTCUT("TYPE_RESIZE_UP" , "Shift+Up" ),
Expand Down
14 changes: 14 additions & 0 deletions src/widgets/capture/capturewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,13 @@ void CaptureWidget::onGridSizeChanged(int size)
repaint();
}

void CaptureWidget::startColorGrab()
{
if (m_sidePanel) {
m_sidePanel->startColorGrab();
}
}

void CaptureWidget::showxywh()
{
m_xywhDisplay = true;
Expand Down Expand Up @@ -1150,6 +1157,10 @@ void CaptureWidget::initPanel()
&SidePanelWidget::togglePanel,
m_panel,
&UtilityPanel::toggle);
connect(
m_sidePanel, &SidePanelWidget::showPanel, m_panel, &UtilityPanel::show);
connect(
m_sidePanel, &SidePanelWidget::hidePanel, m_panel, &UtilityPanel::hide);
connect(m_sidePanel,
&SidePanelWidget::displayGridChanged,
this,
Expand Down Expand Up @@ -1521,6 +1532,9 @@ void CaptureWidget::initShortcuts()
newShortcut(QKeySequence(ConfigHandler().shortcut("TYPE_TOGGLE_PANEL")),
this,
SLOT(togglePanel()));
newShortcut(QKeySequence(ConfigHandler().shortcut("TYPE_GRAB_COLOR")),
this,
SLOT(startColorGrab()));

newShortcut(QKeySequence(ConfigHandler().shortcut("TYPE_RESIZE_LEFT")),
m_selection,
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/capture/capturewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ private slots:
void onDisplayGridChanged(bool display);
void onGridSizeChanged(int size);

void startColorGrab();

public:
void removeToolObject(int index = -1);
void showxywh();
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/panel/sidepanelwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void SidePanelWidget::startColorGrab()
this,
&SidePanelWidget::onColorGrabAborted);

emit togglePanel();
emit hidePanel();
m_colorGrabber->startGrabbing();
}

Expand All @@ -192,7 +192,7 @@ void SidePanelWidget::onTemporaryColorUpdated(const QColor& color)

void SidePanelWidget::finalizeGrab()
{
emit togglePanel();
emit showPanel();
}

void SidePanelWidget::updateColorNoWheel(const QColor& c)
Expand Down
4 changes: 3 additions & 1 deletion src/widgets/panel/sidepanelwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ class SidePanelWidget : public QWidget
void colorChanged(const QColor& color);
void toolSizeChanged(int size);
void togglePanel();
void showPanel();
void hidePanel();
void displayGridChanged(bool display);
void gridSizeChanged(int size);

public slots:
void onToolSizeChanged(int tool);
void onColorChanged(const QColor& color);
void startColorGrab();

private slots:
void startColorGrab();
void onColorGrabFinished();
void onColorGrabAborted();
void onTemporaryColorUpdated(const QColor& color);
Expand Down
6 changes: 6 additions & 0 deletions src/widgets/panel/utilitypanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ void UtilityPanel::pushWidget(QWidget* widget)

void UtilityPanel::show()
{
if (!m_internalPanel->isHidden()) {
return;
}
setAttribute(Qt::WA_TransparentForMouseEvents, false);
m_showAnimation->setStartValue(QRect(-width(), 0, 0, height()));
m_showAnimation->setEndValue(QRect(0, 0, width(), height()));
Expand All @@ -95,6 +98,9 @@ void UtilityPanel::show()

void UtilityPanel::hide()
{
if (m_internalPanel->isHidden()) {
return;
}
setAttribute(Qt::WA_TransparentForMouseEvents);
m_hideAnimation->setStartValue(QRect(0, 0, width(), height()));
m_hideAnimation->setEndValue(QRect(-width(), 0, 0, height()));
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/panel/utilitypanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class UtilityPanel : public QWidget
void setToolWidget(QWidget* weight);
void clearToolWidget();
void pushWidget(QWidget* widget);
void hide();
void show();
void fillCaptureTools(
const QList<QPointer<CaptureTool>>& captureToolObjectsHistory);
void setActiveLayer(int index);
Expand All @@ -40,6 +38,8 @@ class UtilityPanel : public QWidget

public slots:
void toggle();
void hide();
void show();
void slotButtonDelete(bool clicked);
void onCurrentRowChanged(int currentRow);

Expand Down

0 comments on commit 0ab4590

Please sign in to comment.