Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Automatically detect touch painting
Carsten Hartenfelsf3af363884ec
diff --git a/libs/flake/KoPointerEvent.cpp b/libs/flake/KoPointerEvent.cppindex 05b0be3ffd..bfd849031d 100644--- a/libs/flake/KoPointerEvent.cpp+++ b/libs/flake/KoPointerEvent.cpp@@ -98,8 +98,11 @@ public:}boost::variant2::variant<QMouseEvent*, QTabletEvent*, QTouchEvent*> eventPtr;+ static bool s_tabletInputReceived;};+bool KoPointerEvent::Private::s_tabletInputReceived;+KoPointerEvent::KoPointerEvent(QMouseEvent *ev, const QPointF &pnt): point(pnt),d(new Private(ev))@@ -110,6 +113,10 @@ KoPointerEvent::KoPointerEvent(QTabletEvent *ev, const QPointF &pnt): point(pnt),d(new Private(ev)){+ if (!Private::s_tabletInputReceived) {+ Private::s_tabletInputReceived = true;+ KisConfigNotifier::instance()->notifyTouchPaintingChanged();+ }}KoPointerEvent::KoPointerEvent(QTouchEvent* ev, const QPointF &pnt)@@ -416,6 +423,11 @@ bool KoPointerEvent::isTouchEvent() constreturn d->eventPtr.index() == 2;}+bool KoPointerEvent::tabletInputReceived()+{+ return Private::s_tabletInputReceived;+}+Qt::KeyboardModifiers KoPointerEvent::modifiers() const{struct Visitor {diff --git a/libs/flake/KoPointerEvent.h b/libs/flake/KoPointerEvent.hindex 8a6e926700..6a275dee42 100644--- a/libs/flake/KoPointerEvent.h+++ b/libs/flake/KoPointerEvent.h@@ -194,6 +194,11 @@ public:*/bool isTouchEvent() const;+ /**+ * Whether we ever had any tablet inputs this session+ */+ static bool tabletInputReceived();+public:#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))static void copyQtPointerEvent(const QMouseEvent *event, QScopedPointer<QEvent> &dst);diff --git a/libs/ui/dialogs/kis_dlg_preferences.cc b/libs/ui/dialogs/kis_dlg_preferences.ccindex fd7f990335..c2f1c64ca6 100644--- a/libs/ui/dialogs/kis_dlg_preferences.cc+++ b/libs/ui/dialogs/kis_dlg_preferences.cc@@ -50,6 +50,7 @@#include <KoColorSpaceEngine.h>#include <KoConfigAuthorPage.h>#include <KoConfig.h>+#include <KoPointerEvent.h>#include <KoFileDialog.h>#include "KoID.h"@@ -323,11 +324,16 @@ GeneralTab::GeneralTab(QWidget *_parent, const char *_name)cmbFlowMode->setCurrentIndex((int)!cfg.readEntry<bool>("useCreamyAlphaDarken", true));cmbCmykBlendingMode->setCurrentIndex((int)!cfg.readEntry<bool>("useSubtractiveBlendingForCmykColorSpaces", true));m_chkSwitchSelectionCtrlAlt->setChecked(cfg.switchSelectionCtrlAlt());- chkEnableTouch->setChecked(!cfg.disableTouchOnCanvas());+ cmbTouchPainting->addItem(+ KoPointerEvent::tabletInputReceived() ? i18nc("touch painting", "Auto (Disabled)")+ : i18nc("touch painting", "Auto (Enabled)"));+ cmbTouchPainting->addItem(i18nc("touch painting", "Enabled"));+ cmbTouchPainting->addItem(i18nc("touch painting", "Disabled"));+ cmbTouchPainting->setCurrentIndex(int(cfg.touchPainting()));chkTouchPressureSensitivity->setChecked(cfg.readEntry("useTouchPressureSensitivity", true));- connect(chkEnableTouch, SIGNAL(toggled(bool)),- chkTouchPressureSensitivity, SLOT(setEnabled(bool)));- chkTouchPressureSensitivity->setEnabled(chkEnableTouch->isChecked());+ connect(cmbTouchPainting, SIGNAL(currentIndexChanged(int)),+ SLOT(updateTouchPressureSensitivityEnabled(int)));+ updateTouchPressureSensitivityEnabled(cmbTouchPainting->currentIndex());chkEnableTransformToolAfterPaste->setChecked(cfg.activateTransformToolAfterPaste());chkZoomHorizontally->setChecked(cfg.zoomHorizontal());@@ -759,7 +765,7 @@ void GeneralTab::setDefault()m_chkKineticScrollingHideScrollbars->setChecked(cfg.kineticScrollingHiddenScrollbars(true));intZoomMarginSize->setValue(cfg.zoomMarginSize(true));m_chkSwitchSelectionCtrlAlt->setChecked(cfg.switchSelectionCtrlAlt(true));- chkEnableTouch->setChecked(!cfg.disableTouchOnCanvas(true));+ cmbTouchPainting->setCurrentIndex(int(cfg.touchPainting(true)));chkTouchPressureSensitivity->setChecked(true);chkEnableTransformToolAfterPaste->setChecked(cfg.activateTransformToolAfterPaste(true));chkZoomHorizontally->setChecked(cfg.zoomHorizontal(true));@@ -1021,6 +1027,11 @@ void GeneralTab::enableSubWindowOptions(int mdi_mode)group_subWinMode->setEnabled(mdi_mode == QMdiArea::SubWindowView);}+void GeneralTab::updateTouchPressureSensitivityEnabled(int touchPainting)+{+ chkTouchPressureSensitivity->setEnabled(touchPainting != int(KisConfig::TOUCH_PAINTING_DISABLED));+}+#include "kactioncollection.h"#include "KisActionsSnapshot.h"@@ -2619,7 +2630,7 @@ bool KisDlgPreferences::editPreferences()cfg.setZoomMarginSize(m_general->zoomMarginSize());cfg.setSwitchSelectionCtrlAlt(m_general->switchSelectionCtrlAlt());- cfg.setDisableTouchOnCanvas(!m_general->chkEnableTouch->isChecked());+ cfg.setTouchPainting(KisConfig::TouchPainting(m_general->cmbTouchPainting->currentIndex()));cfg.writeEntry("useTouchPressureSensitivity", m_general->chkTouchPressureSensitivity->isChecked());cfg.setActivateTransformToolAfterPaste(m_general->chkEnableTransformToolAfterPaste->isChecked());cfg.setZoomHorizontal(m_general->chkZoomHorizontally->isChecked());diff --git a/libs/ui/dialogs/kis_dlg_preferences.h b/libs/ui/dialogs/kis_dlg_preferences.hindex 00ef63805d..ef5aa3eae6 100644--- a/libs/ui/dialogs/kis_dlg_preferences.h+++ b/libs/ui/dialogs/kis_dlg_preferences.h@@ -108,6 +108,7 @@ private Q_SLOTS:void clearBackgroundImage();void checkResourcePath();void enableSubWindowOptions(int);+ void updateTouchPressureSensitivityEnabled(int);void showAdvancedCumulativeUndoSettings();public:diff --git a/libs/ui/forms/wdggeneralsettings.ui b/libs/ui/forms/wdggeneralsettings.uiindex 789a5051ac..73a01a528c 100644--- a/libs/ui/forms/wdggeneralsettings.ui+++ b/libs/ui/forms/wdggeneralsettings.ui@@ -969,10 +969,10 @@</property></widget></item>- <item row="4" column="1">- <widget class="QCheckBox" name="chkEnableTouch">+ <item row="4" column="0">+ <widget class="QLabel" name="lblTouchPainting"><property name="text">- <string>Enable Touch Painting</string>+ <string>Touch Painting:</string></property></widget></item>@@ -1050,6 +1050,9 @@</property></widget></item>+ <item row="4" column="1">+ <widget class="QComboBox" name="cmbTouchPainting"/>+ </item></layout></widget><widget class="QWidget" name="Animation">diff --git a/libs/ui/kis_config.cc b/libs/ui/kis_config.ccindex 5d7433c105..58ff9e39cd 100644--- a/libs/ui/kis_config.cc+++ b/libs/ui/kis_config.cc@@ -26,6 +26,7 @@#include <KoColorSpaceRegistry.h>#include <KoColorModelStandardIds.h>#include <KoColorProfile.h>+#include <KoPointerEvent.h>#include <kis_debug.h>#include <kis_types.h>@@ -133,17 +134,37 @@ void KisConfig::logImportantSettings() const}-bool KisConfig::disableTouchOnCanvas(bool defaultValue) const+KisConfig::TouchPainting KisConfig::touchPainting(bool defaultValue) const{- return (defaultValue ? false : m_cfg.readEntry("disableTouchOnCanvas", false));+ if (defaultValue) {+ return TOUCH_PAINTING_AUTO;+ } else {+ int value = m_cfg.readEntry("touchPainting", int(TOUCH_PAINTING_AUTO));+ return TouchPainting(value);+ }}-void KisConfig::setDisableTouchOnCanvas(bool value) const+void KisConfig::setTouchPainting(TouchPainting value) const{- m_cfg.writeEntry("disableTouchOnCanvas", value);+ m_cfg.writeEntry("touchPainting", int(value));KisConfigNotifier::instance()->notifyTouchPaintingChanged();}+bool KisConfig::disableTouchOnCanvas() const+{+ switch (touchPainting()) {+ case TOUCH_PAINTING_ENABLED:+ return false;+ case TOUCH_PAINTING_DISABLED:+ return true;+ default:+ // Automatic detection: enable or disable touch input based on whether+ // we've received a tablet input during this session and therefore know+ // that the user has a pen available.+ return KoPointerEvent::tabletInputReceived();+ }+}+bool KisConfig::useProjections(bool defaultValue) const{return (defaultValue ? true : m_cfg.readEntry("useProjections", true));diff --git a/libs/ui/kis_config.h b/libs/ui/kis_config.hindex caa2847d40..3708e8eee7 100644--- a/libs/ui/kis_config.h+++ b/libs/ui/kis_config.h@@ -43,8 +43,15 @@ public Q_SLOTS:void logImportantSettings() const;public:- bool disableTouchOnCanvas(bool defaultValue = false) const;- void setDisableTouchOnCanvas(bool value) const;+ enum TouchPainting {+ TOUCH_PAINTING_AUTO,+ TOUCH_PAINTING_ENABLED,+ TOUCH_PAINTING_DISABLED,+ };++ TouchPainting touchPainting(bool defaultValue = false) const;+ void setTouchPainting(TouchPainting value) const;+ bool disableTouchOnCanvas() const;// XXX Unused?bool useProjections(bool defaultValue = false) const;