Skip to content

Commit

Permalink
Allow assigning brush presets to shortcuts
Browse files Browse the repository at this point in the history
And also rejigging a bunch of other stuff with regards to shortcuts and
the settings dialog. The input tab is now the tablet tab instead and
there's a button at the bottom for the tablet tester. Analogously,
there's a touch tester button on the touch page. Brush presets are their
own tab in the shortcuts settings and allow assigning the same key
sequence to multiple brushes, which it will toggle through in sequence.
Conflicts are handled across all types of shortcuts now and you can
filter for them. The mirror and flip actions have gotten extra
descriptive text to allow searching for them as "mirror" and "flip",
since otherwise you may think you can only do one of those. Searching
for the keybinds themselves is also possible now.

Implements #1367, #1368 and #1377. Relates to #1386.
  • Loading branch information
askmeaboutlo0m committed Oct 14, 2024
1 parent fd2d3e6 commit b3ef503
Show file tree
Hide file tree
Showing 41 changed files with 2,346 additions and 545 deletions.
8 changes: 6 additions & 2 deletions src/desktop/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ target_sources(drawpile PRIVATE
dialogs/settingsdialog/general.cpp
dialogs/settingsdialog/general.h
dialogs/settingsdialog/helpers.h
dialogs/settingsdialog/input.cpp
dialogs/settingsdialog/input.h
dialogs/settingsdialog/network.cpp
dialogs/settingsdialog/network.h
dialogs/settingsdialog/notifications.cpp
Expand All @@ -151,8 +149,14 @@ target_sources(drawpile PRIVATE
dialogs/settingsdialog/userinterface.h
dialogs/settingsdialog/servers.cpp
dialogs/settingsdialog/servers.h
dialogs/settingsdialog/shortcutfilterinput.cpp
dialogs/settingsdialog/shortcutfilterinput.h
dialogs/settingsdialog/shortcuts.cpp
dialogs/settingsdialog/shortcuts.h
dialogs/settingsdialog/tablet.cpp
dialogs/settingsdialog/tablet.h
dialogs/settingsdialog/touch.cpp
dialogs/settingsdialog/touch.h
dialogs/settingsdialog/tools.cpp
dialogs/settingsdialog/tools.h
dialogs/startdialog.cpp
Expand Down
12 changes: 0 additions & 12 deletions src/desktop/assets/theme/dark/dialog-input-devices.svg

This file was deleted.

14 changes: 14 additions & 0 deletions src/desktop/assets/theme/dark/input-tablet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions src/desktop/assets/theme/dark/input-touchscreen.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 0 additions & 12 deletions src/desktop/assets/theme/light/dialog-input-devices.svg

This file was deleted.

14 changes: 14 additions & 0 deletions src/desktop/assets/theme/light/input-tablet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions src/desktop/assets/theme/light/input-touchscreen.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 76 additions & 1 deletion src/desktop/dialogs/brushsettingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "desktop/filewrangler.h"
#include "desktop/utils/widgetutils.h"
#include "desktop/widgets/curvewidget.h"
#include "desktop/widgets/keysequenceedit.h"
#include "desktop/widgets/kis_slider_spin_box.h"
#include "desktop/widgets/toolmessage.h"
#include "libclient/canvas/blendmodes.h"
Expand Down Expand Up @@ -30,6 +31,33 @@

namespace dialogs {

namespace {

class ShortcutLineEdit : public QLineEdit {
public:
ShortcutLineEdit(QPushButton *button)
: QLineEdit()
, m_button(button)
{
setReadOnly(true);
setEnabled(false);
}

protected:
void mousePressEvent(QMouseEvent *event) override
{
QLineEdit::mousePressEvent(event);
if(event->button() == Qt::LeftButton) {
m_button->click();
}
}

private:
QPushButton *m_button;
};

}

struct BrushSettingsDialog::Private {
struct MyPaintPage {
KisDoubleSliderSpinBox *baseValueSpinner;
Expand All @@ -51,6 +79,8 @@ struct BrushSettingsDialog::Private {
QLineEdit *presetLabelEdit;
QLineEdit *presetNameEdit;
QPlainTextEdit *presetDescriptionEdit;
ShortcutLineEdit *presetShortcutEdit;
QPushButton *presetShortcutButton;
QComboBox *brushTypeCombo;
QLabel *brushModeLabel;
QComboBox *brushModeCombo;
Expand Down Expand Up @@ -94,6 +124,7 @@ struct BrushSettingsDialog::Private {
DP_BrushShape lastShape;
brushes::ActiveBrush brush;
int globalSmoothing;
int presetId = 0;
bool useBrushSampleCount;
bool presetAttached = true;
bool updating = false;
Expand Down Expand Up @@ -129,7 +160,18 @@ void BrushSettingsDialog::showGeneralPage()
}


void BrushSettingsDialog::setPresetAttached(bool presetAttached)
bool BrushSettingsDialog::isPresetAttached() const
{
return d->presetAttached;
}

int BrushSettingsDialog::presetId() const
{
return d->presetId;
}


void BrushSettingsDialog::setPresetAttached(bool presetAttached, int presetId)
{
utils::ScopedUpdateDisabler disabler(this);
if(presetAttached && !d->presetAttached) {
Expand All @@ -139,6 +181,7 @@ void BrushSettingsDialog::setPresetAttached(bool presetAttached)
d->presetAttachedWidget->hide();
d->presetDetachedWidget->show();
}
d->presetId = presetId;
d->presetAttached = presetAttached;
d->presetAttachedWidget->setEnabled(presetAttached);
d->overwriteBrushButton->setEnabled(presetAttached);
Expand Down Expand Up @@ -171,6 +214,13 @@ void BrushSettingsDialog::setPresetThumbnail(const QPixmap &presetThumbnail)
}
}

void BrushSettingsDialog::setPresetShortcut(const QKeySequence &presetShortcut)
{
QString text = presetShortcut.toString(QKeySequence::NativeText);
d->presetShortcutEdit->setText(
text.isEmpty() ? tr("No shortcut assigned") : text);
}

void BrushSettingsDialog::setForceEraseMode(bool forceEraseMode)
{
d->eraseModeBox->setEnabled(!forceEraseMode);
Expand Down Expand Up @@ -343,6 +393,24 @@ QWidget *BrushSettingsDialog::buildPresetPageUi()
attachedLayout->setContentsMargins(0, 0, 0, 0);
d->presetAttachedWidget->setLayout(attachedLayout);

d->presetShortcutButton = new QPushButton(tr("Change…"));
connect(
d->presetShortcutButton, &QPushButton::clicked, this,
&BrushSettingsDialog::requestShortcutChange);

d->presetShortcutEdit = new ShortcutLineEdit(d->presetShortcutButton);
d->presetShortcutEdit->setAlignment(Qt::AlignCenter);
d->presetShortcutEdit->setReadOnly(true);
d->presetShortcutEdit->setEnabled(false);

QHBoxLayout *shortcutLayout = new QHBoxLayout;
shortcutLayout->setContentsMargins(0, 0, 0, 0);
shortcutLayout->addWidget(d->presetShortcutEdit);
shortcutLayout->addWidget(d->presetShortcutButton);
attachedLayout->addRow(tr("Shortcut:"), shortcutLayout);

utils::addFormSpacer(attachedLayout);

QGridLayout *thumbnailLayout = new QGridLayout;

d->presetThumbnailView = new QGraphicsView;
Expand Down Expand Up @@ -1339,6 +1407,13 @@ bool BrushSettingsDialog::disableIndirectMyPaintInputs(int setting)
}
}

void BrushSettingsDialog::requestShortcutChange()
{
if(d->presetAttached) {
emit shortcutChangeRequested(d->presetId);
}
}

void BrushSettingsDialog::choosePresetThumbnailFile()
{
FileWrangler::ImageOpenFn imageOpenCompleted = [this](QImage &img) {
Expand Down
9 changes: 8 additions & 1 deletion src/desktop/dialogs/brushsettingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class KisSliderSpinBox;
class QComboBox;
class QKeySequence;
class QListWidgetItem;
class QPushButton;
class QVBoxLayout;
Expand All @@ -23,19 +24,24 @@ class BrushSettingsDialog final : public QDialog {
void showPresetPage();
void showGeneralPage();

bool isPresetAttached() const;
int presetId() const;

signals:
void presetNameChanged(const QString &presetName);
void presetDescriptionChanged(const QString &presetDescription);
void presetThumbnailChanged(const QPixmap &presetThumbnail);
void brushSettingsChanged(const brushes::ActiveBrush &brush);
void newBrushRequested();
void overwriteBrushRequested();
void shortcutChangeRequested(int presetId);

public slots:
void setPresetAttached(bool presetAttached);
void setPresetAttached(bool presetAttached, int presetId);
void setPresetName(const QString &presetName);
void setPresetDescription(const QString &presetDescription);
void setPresetThumbnail(const QPixmap &presetThumbnail);
void setPresetShortcut(const QKeySequence &presetShortcut);
void setForceEraseMode(bool forceEraseMode);
void setStabilizerUseBrushSampleCount(bool useBrushSampleCount);
void setGlobalSmoothing(int smoothing);
Expand Down Expand Up @@ -121,6 +127,7 @@ private slots:
static QString getMyPaintSettingTitle(int setting);
static QString getMyPaintSettingDescription(int setting);

void requestShortcutChange();
void choosePresetThumbnailFile();
void showPresetThumbnail(const QPixmap &thumbnail);
void renderPresetThumbnail();
Expand Down
Loading

0 comments on commit b3ef503

Please sign in to comment.