Skip to content

Commit 0246932

Browse files
Grab color shortcut rebase (flameshot-org#4164)
* Add shortcut for Grab Color * Update README.md * Improve description * Add shortcut to flameshot.example.ini --------- Co-authored-by: Alex P <[email protected]>
1 parent f402e36 commit 0246932

File tree

10 files changed

+33
-5
lines changed

10 files changed

+33
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ These shortcuts are available in GUI mode:
225225
| <kbd>Ctrl</kbd> + <kbd>Backspace</kbd> | Cancel current selection |
226226
| <kbd>Return</kbd> | Upload the selection to Imgur |
227227
| <kbd>Spacebar</kbd> | Toggle visibility of sidebar with options of the selected tool, color picker for the drawing color and history menu |
228+
| <kbd>G</kbd> | Starts the color picker |
228229
| Right Click | Show the color wheel |
229230
| Mouse Wheel | Change the tool's thickness |
230231
| <kbd>Print screen</kbd> | Capture Screen |

flameshot.example.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,5 @@
153153
;TYPE_SELECT_ALL=Ctrl+A
154154
;TYPE_TEXT=T
155155
;TYPE_TOGGLE_PANEL=Space
156+
;TYPE_GRAB_COLOR=G
156157
;TYPE_UNDO=Ctrl+Z

src/config/shortcutswidget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ void ShortcutsWidget::loadShortcuts()
167167

168168
// additional tools that don't have their own buttons
169169
appendShortcut("TYPE_TOGGLE_PANEL", tr("Toggle side panel"));
170+
appendShortcut("TYPE_GRAB_COLOR", tr("Grab a color from the screen"));
170171
appendShortcut("TYPE_RESIZE_LEFT", tr("Resize selection left 1px"));
171172
appendShortcut("TYPE_RESIZE_RIGHT", tr("Resize selection right 1px"));
172173
appendShortcut("TYPE_RESIZE_UP", tr("Resize selection up 1px"));

src/utils/confighandler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ static QMap<QString, QSharedPointer<KeySequence>> recognizedShortcuts = {
166166
SHORTCUT("TYPE_REDO" , "Ctrl+Shift+Z" ),
167167
SHORTCUT("TYPE_TEXT" , "T" ),
168168
SHORTCUT("TYPE_TOGGLE_PANEL" , "Space" ),
169+
SHORTCUT("TYPE_GRAB_COLOR" , "G" ),
169170
SHORTCUT("TYPE_RESIZE_LEFT" , "Shift+Left" ),
170171
SHORTCUT("TYPE_RESIZE_RIGHT" , "Shift+Right" ),
171172
SHORTCUT("TYPE_RESIZE_UP" , "Shift+Up" ),

src/widgets/capture/capturewidget.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,13 @@ void CaptureWidget::onGridSizeChanged(int size)
417417
repaint();
418418
}
419419

420+
void CaptureWidget::startColorGrab()
421+
{
422+
if (m_sidePanel) {
423+
m_sidePanel->startColorGrab();
424+
}
425+
}
426+
420427
void CaptureWidget::showxywh()
421428
{
422429
m_xywhDisplay = true;
@@ -1210,6 +1217,10 @@ void CaptureWidget::initPanel()
12101217
&SidePanelWidget::togglePanel,
12111218
m_panel,
12121219
&UtilityPanel::toggle);
1220+
connect(
1221+
m_sidePanel, &SidePanelWidget::showPanel, m_panel, &UtilityPanel::show);
1222+
connect(
1223+
m_sidePanel, &SidePanelWidget::hidePanel, m_panel, &UtilityPanel::hide);
12131224
connect(m_sidePanel,
12141225
&SidePanelWidget::displayGridChanged,
12151226
this,
@@ -1577,6 +1588,9 @@ void CaptureWidget::initShortcuts()
15771588
newShortcut(QKeySequence(ConfigHandler().shortcut("TYPE_TOGGLE_PANEL")),
15781589
this,
15791590
SLOT(togglePanel()));
1591+
newShortcut(QKeySequence(ConfigHandler().shortcut("TYPE_GRAB_COLOR")),
1592+
this,
1593+
SLOT(startColorGrab()));
15801594

15811595
newShortcut(QKeySequence(ConfigHandler().shortcut("TYPE_RESIZE_LEFT")),
15821596
m_selection,

src/widgets/capture/capturewidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ private slots:
9292
void onDisplayGridChanged(bool display);
9393
void onGridSizeChanged(int size);
9494

95+
void startColorGrab();
96+
9597
public:
9698
void removeToolObject(int index = -1);
9799
void showxywh();

src/widgets/panel/sidepanelwidget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ void SidePanelWidget::startColorGrab()
171171
this,
172172
&SidePanelWidget::onColorGrabAborted);
173173

174-
emit togglePanel();
174+
emit hidePanel();
175175
m_colorGrabber->startGrabbing();
176176
}
177177

@@ -196,7 +196,7 @@ void SidePanelWidget::onTemporaryColorUpdated(const QColor& color)
196196

197197
void SidePanelWidget::finalizeGrab()
198198
{
199-
emit togglePanel();
199+
emit showPanel();
200200
}
201201

202202
void SidePanelWidget::updateColorNoWheel(const QColor& c)

src/widgets/panel/sidepanelwidget.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@ class SidePanelWidget : public QWidget
3232
void colorChanged(const QColor& color);
3333
void toolSizeChanged(int size);
3434
void togglePanel();
35+
void showPanel();
36+
void hidePanel();
3537
void displayGridChanged(bool display);
3638
void gridSizeChanged(int size);
3739

3840
public slots:
3941
void onToolSizeChanged(int tool);
4042
void onColorChanged(const QColor& color);
43+
void startColorGrab();
4144

4245
private slots:
43-
void startColorGrab();
4446
void onColorGrabFinished();
4547
void onColorGrabAborted();
4648
void onTemporaryColorUpdated(const QColor& color);

src/widgets/panel/utilitypanel.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ void UtilityPanel::pushWidget(QWidget* widget)
8282

8383
void UtilityPanel::show()
8484
{
85+
if (!m_internalPanel->isHidden()) {
86+
return;
87+
}
8588
setAttribute(Qt::WA_TransparentForMouseEvents, false);
8689
m_showAnimation->setStartValue(QRect(-width(), 0, 0, height()));
8790
m_showAnimation->setEndValue(QRect(0, 0, width(), height()));
@@ -95,6 +98,9 @@ void UtilityPanel::show()
9598

9699
void UtilityPanel::hide()
97100
{
101+
if (m_internalPanel->isHidden()) {
102+
return;
103+
}
98104
setAttribute(Qt::WA_TransparentForMouseEvents);
99105
m_hideAnimation->setStartValue(QRect(0, 0, width(), height()));
100106
m_hideAnimation->setEndValue(QRect(-width(), 0, 0, height()));

src/widgets/panel/utilitypanel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ class UtilityPanel : public QWidget
2525
void setToolWidget(QWidget* weight);
2626
void clearToolWidget();
2727
void pushWidget(QWidget* widget);
28-
void hide();
29-
void show();
3028
void fillCaptureTools(
3129
const QList<QPointer<CaptureTool>>& captureToolObjectsHistory);
3230
void setActiveLayer(int index);
@@ -40,6 +38,8 @@ class UtilityPanel : public QWidget
4038

4139
public slots:
4240
void toggle();
41+
void hide();
42+
void show();
4343
void slotButtonDelete(bool clicked);
4444
void onCurrentRowChanged(int currentRow);
4545

0 commit comments

Comments
 (0)