Commit 58dd54d7 authored by Adrian Page's avatar Adrian Page
Browse files

- Make tablet devices fully configurable. Device names still need to match...

- Make tablet devices fully configurable. Device names still need to match Qt's hidden requirements (stylus, eraser, pen) in order to tie devices to tools, however this should be fixable in time for the beta now the groundwork's in.
- Add Tool ID support to allow more than one stylus, airbrush etc to be used.
- Add wheel support at the low level, though nothing uses it.
- Remove the OpenGL shaders option as that's no longer for 1.5.

svn path=/trunk/koffice/; revision=498672
parent 1d177ffa
......@@ -23,13 +23,13 @@
#include <qpoint.h>
#include <qrect.h>
#include "kis_types.h"
#include "kis_global.h"
class QWidget;
class KisTool;
class KisRect;
class KisPoint;
class KisCanvas;
class KisInputDevice;
/**
* Interface for classes that implement a canvas; i.e., a widget where KisImages
......@@ -183,12 +183,12 @@ public:
*
* @param inputDevice the new input device
*/
virtual void setInputDevice(enumInputDevice inputDevice) = 0;
virtual void setInputDevice(KisInputDevice inputDevice) = 0;
/**
* @return the current input device, such as a mouse or a stylus
*/
virtual enumInputDevice currentInputDevice() const = 0;
virtual KisInputDevice currentInputDevice() const = 0;
private:
......
......@@ -40,14 +40,6 @@ const Q_UINT8 MAX_SELECTED = UCHAR_MAX;
const Q_UINT8 MIN_SELECTED = 0;
const Q_UINT8 SELECTION_THRESHOLD = 1;
enum enumInputDevice {
INPUT_DEVICE_UNKNOWN,
INPUT_DEVICE_MOUSE, // Standard mouse
INPUT_DEVICE_STYLUS, // Wacom stylus
INPUT_DEVICE_ERASER, // Wacom eraser
INPUT_DEVICE_PUCK // Wacom puck
};
enum enumCursorStyle {
CURSOR_STYLE_TOOLICON = 0,
CURSOR_STYLE_CROSSHAIR = 1,
......
......@@ -37,8 +37,8 @@ libkritaui_la_SOURCES = kis_histogram_view.cc imageviewer.cc kcurve.cc \
wdgnewimage.ui wdgperformancesettings.ui wdgselectionoptions.ui wdgshapeoptions.ui \
wdgpressuresettings.ui wdgcustombrush.ui wdgcustompalette.ui wdgcustompattern.ui \
wdgtextbrush.ui kis_dlg_adjustment_layer.cc kis_filters_listview.cc \
wdgpalettechooser.ui wdggridsettings.ui kis_grid_manager.cpp \
wdgtabletdevicesettings.ui wdgtabletsettings.ui
wdgpalettechooser.ui wdggridsettings.ui kis_grid_manager.cpp \
wdgtabletdevicesettings.ui wdgtabletsettings.ui kis_input_device.cc
noinst_HEADERS = imageviewer.h layerlist.h kcurve.h kis_aboutdata.h \
kis_autobrush.h kis_autogradient.h kis_birdeye_box.h kis_brush_chooser.h \
......@@ -56,7 +56,7 @@ noinst_HEADERS = imageviewer.h layerlist.h kcurve.h kis_aboutdata.h \
kis_ruler.h kis_selection_manager.h kis_selection_options.h kis_tool_controller.h \
kis_tool_dummy.h kis_tool_manager.h kis_tool_registry.h kis_view.h kis_view_iface.h \
kobirdeyepanel.h kis_custom_brush.h kis_custom_pattern.h kis_custom_image_widget.h \
kis_dlg_adjustment_layer.h kis_filters_listview.h kis_grid_manager.h
kis_dlg_adjustment_layer.h kis_filters_listview.h kis_grid_manager.h kis_input_device.h
METASOURCES = AUTO
......
......@@ -28,7 +28,7 @@ public:
protected:
KisButtonEvent() {}
KisButtonEvent(enumEventType type,
enumInputDevice device,
KisInputDevice device,
const KisPoint& pos,
const KisPoint& globalPos,
double pressure,
......
......@@ -24,7 +24,7 @@ class KisButtonPressEvent : public KisButtonEvent {
typedef KisButtonEvent super;
public:
KisButtonPressEvent() {}
KisButtonPressEvent(enumInputDevice device, const KisPoint& pos, const KisPoint& globalPos, double pressure, double xTilt, double yTilt, Qt::ButtonState button, Qt::ButtonState state) : super(ButtonPressEvent, device, pos, globalPos, pressure, xTilt, yTilt, button, state) {}
KisButtonPressEvent(KisInputDevice device, const KisPoint& pos, const KisPoint& globalPos, double pressure, double xTilt, double yTilt, Qt::ButtonState button, Qt::ButtonState state) : super(ButtonPressEvent, device, pos, globalPos, pressure, xTilt, yTilt, button, state) {}
};
#endif // KIS_BUTTON_PRESS_EVENT_H_
......
......@@ -24,7 +24,7 @@ class KisButtonReleaseEvent : public KisButtonEvent {
typedef KisButtonEvent super;
public:
KisButtonReleaseEvent() {}
KisButtonReleaseEvent(enumInputDevice device, const KisPoint& pos, const KisPoint& globalPos, double pressure, double xTilt, double yTilt, Qt::ButtonState button, Qt::ButtonState state) : super(ButtonReleaseEvent, device, pos, globalPos, pressure, xTilt, yTilt, button, state) {}
KisButtonReleaseEvent(KisInputDevice device, const KisPoint& pos, const KisPoint& globalPos, double pressure, double xTilt, double yTilt, Qt::ButtonState button, Qt::ButtonState state) : super(ButtonReleaseEvent, device, pos, globalPos, pressure, xTilt, yTilt, button, state) {}
};
#endif // KIS_BUTTON_RELEASE_EVENT_H_
......
This diff is collapsed.
/*
* Copyright (c) 1999 Matthias Elter <me@kde.org>
* Copyright (c) 2004 Adrian Page <adrian@pagenet.plus.com>
* Copyright (c) 2004-2006 Adrian Page <adrian@pagenet.plus.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -33,6 +33,7 @@
#include "kis_global.h"
#include "kis_point.h"
#include "kis_vec.h"
#include "kis_input_device.h"
#ifdef Q_WS_X11
......@@ -52,7 +53,6 @@
#endif // Q_WS_X11
class KisEvent;
class KisMoveEvent;
class KisButtonPressEvent;
......@@ -74,6 +74,15 @@ public:
virtual KisCanvasWidgetPainter *createPainter() = 0;
#ifdef EXTENDED_X11_TABLET_SUPPORT
static KisInputDevice inputDevice(XEvent *event);
virtual void selectTabletDeviceEvents() = 0;
#endif
#ifdef Q_WS_X11
static void initX11Support();
#endif
signals:
void sigGotPaintEvent(QPaintEvent*);
void sigGotEnterEvent(QEvent*);
......@@ -118,7 +127,6 @@ protected:
// is unable to keep up with them. We override this behaviour so that
// we receive all move events, so that painting follows the mouse's motion
// accurately.
static void initX11Support();
bool x11Event(XEvent *event, Display *x11Display, WId winId, QPoint widgetOriginPos);
static Qt::ButtonState translateX11ButtonState(int state);
static Qt::ButtonState translateX11Button(unsigned int button);
......@@ -134,36 +142,76 @@ protected:
#ifdef EXTENDED_X11_TABLET_SUPPORT
public:
class X11TabletDevice
{
public:
X11TabletDevice();
X11TabletDevice(const XDeviceInfo *deviceInfo);
bool mightBeTabletDevice() const { return m_mightBeTabletDevice; }
XID id() const { return m_deviceId; }
enumInputDevice device() const { return m_device; }
QString name() const { return m_name; }
KisInputDevice inputDevice() const { return m_inputDevice; }
void setInputDevice(KisInputDevice inputDevice) { m_inputDevice = inputDevice; }
void setEnabled(bool enabled);
bool enabled() const;
Q_INT32 numAxes() const;
void setXAxis(Q_INT32 axis);
void setYAxis(Q_INT32 axis);
void setPressureAxis(Q_INT32 axis);
void setXTiltAxis(Q_INT32 axis);
void setYTiltAxis(Q_INT32 axis);
void setWheelAxis(Q_INT32 axis);
void setToolIDAxis(Q_INT32 axis);
void setSerialNumberAxis(Q_INT32 axis);
static const Q_INT32 NoAxis = -1;
static const Q_INT32 DefaultAxis = -2;
Q_INT32 xAxis() const;
Q_INT32 yAxis() const;
Q_INT32 pressureAxis() const;
Q_INT32 xTiltAxis() const;
Q_INT32 yTiltAxis() const;
Q_INT32 wheelAxis() const;
Q_INT32 toolIDAxis() const;
Q_INT32 serialNumberAxis() const;
void readSettingsFromConfig();
void writeSettingsToConfig();
// These return -1 if the device does not support the event
int buttonPressEvent() const { return m_buttonPressEvent; }
int buttonReleaseEvent() const { return m_buttonReleaseEvent; }
int motionNotifyEvent() const { return m_motionNotifyEvent; }
void enableEvents(QWidget *widget) const;
void disableEvents(QWidget *widget) const;
class State
{
public:
State() {}
State(const KisPoint& pos, double pressure, const KisVector2D& tilt);
State(const KisPoint& pos, double pressure, const KisVector2D& tilt, double wheel);
// Position and pressure are normalised to 0 - 1
// Position, pressure and wheel are normalised to 0 - 1
KisPoint pos() const { return m_pos; }
double pressure() const { return m_pressure; }
// Tilt is normalised to -1 -> +1
KisVector2D tilt() const { return m_tilt; }
double wheel() const { return m_wheel; }
private:
KisPoint m_pos;
double m_pressure;
KisVector2D m_tilt;
double m_wheel;
};
State translateAxisData(const int *axisData) const;
......@@ -172,23 +220,43 @@ protected:
double translateAxisValue(int value, const XAxisInfo& axisInfo) const;
XID m_deviceId;
enumInputDevice m_device;
XAxisInfo m_xInfo;
XAxisInfo m_yInfo;
XAxisInfo m_pressureInfo;
XAxisInfo m_tiltXInfo;
XAxisInfo m_tiltYInfo;
QString m_name;
bool m_mightBeTabletDevice;
KisInputDevice m_inputDevice;
bool m_enabled;
Q_INT32 m_xAxis;
Q_INT32 m_yAxis;
Q_INT32 m_pressureAxis;
Q_INT32 m_xTiltAxis;
Q_INT32 m_yTiltAxis;
Q_INT32 m_wheelAxis;
Q_INT32 m_toolIDAxis;
Q_INT32 m_serialNumberAxis;
QValueVector<XAxisInfo> m_axisInfo;
int m_motionNotifyEvent;
int m_buttonPressEvent;
int m_buttonReleaseEvent;
QValueVector<XEventClass> m_eventClassList;
};
typedef std::map<XID, X11TabletDevice> X11XIDTabletDeviceMap;
static X11XIDTabletDeviceMap& tabletDeviceMap();
protected:
static void selectTabletDeviceEvents(QWidget *widget);
static int X11DeviceMotionNotifyEvent;
static int X11DeviceButtonPressEvent;
static int X11DeviceButtonReleaseEvent;
typedef std::map<XID, X11TabletDevice> X11XIDTabletDeviceMap;
static X11XIDTabletDeviceMap X11TabletDeviceMap;
#endif // EXTENDED_X11_TABLET_SUPPORT
#endif // Q_WS_X11
......@@ -222,6 +290,10 @@ public:
void updateGeometry();
#if defined(EXTENDED_X11_TABLET_SUPPORT)
void selectTabletDeviceEvents();
#endif
signals:
void sigGotPaintEvent(QPaintEvent*);
void sigGotEnterEvent(QEvent*);
......
......@@ -256,6 +256,26 @@ Q_INT32 KisConfig::getDefaultPressureCorrection()
return DEFAULT_PRESSURE_CORRECTION;
}
bool KisConfig::tabletDeviceEnabled(const QString& tabletDeviceName) const
{
return m_cfg -> readBoolEntry("TabletDevice" + tabletDeviceName + "Enabled", false);
}
void KisConfig::setTabletDeviceEnabled(const QString& tabletDeviceName, bool enabled)
{
m_cfg -> writeEntry("TabletDevice" + tabletDeviceName + "Enabled", enabled);
}
Q_INT32 KisConfig::tabletDeviceAxis(const QString& tabletDeviceName, const QString& axisName, Q_INT32 defaultAxis) const
{
return m_cfg -> readNumEntry("TabletDevice" + tabletDeviceName + axisName, defaultAxis);
}
void KisConfig::setTabletDeviceAxis(const QString& tabletDeviceName, const QString& axisName, Q_INT32 axis) const
{
m_cfg -> writeEntry("TabletDevice" + tabletDeviceName + axisName, axis);
}
void KisConfig::setDockability( Q_INT32 dockability )
{
m_cfg->writeEntry( "palettesdockability", dockability );
......
......@@ -88,6 +88,12 @@ public:
void setPressureCorrection( Q_INT32 correction);
Q_INT32 getDefaultPressureCorrection();
bool tabletDeviceEnabled(const QString& tabletDeviceName) const;
void setTabletDeviceEnabled(const QString& tabletDeviceName, bool enabled);
Q_INT32 tabletDeviceAxis(const QString& tabletDeviceName, const QString& axisName, Q_INT32 defaultAxis) const;
void setTabletDeviceAxis(const QString& tabletDeviceName, const QString& axisName, Q_INT32 axis) const;
Q_INT32 dockability();
Q_INT32 getDefaultDockability();
void setDockability( Q_INT32 dockability);
......
......@@ -56,6 +56,7 @@
#include "kis_id.h"
#include "kis_cmb_idlist.h"
#include "kis_profile.h"
#include "kis_canvas.h"
#include "wdgcolorsettings.h"
#include "wdgperformancesettings.h"
#include "wdggeneralsettings.h"
......@@ -208,21 +209,412 @@ void PerformanceTab::setDefault()
//---------------------------------------------------------------------------------------------------
PressureSettingsTab::PressureSettingsTab( QWidget *parent, const char *name)
: WdgPressureSettings( parent, name )
TabletSettingsTab::TabletSettingsTab( QWidget *parent, const char *name)
: WdgTabletSettings( parent, name )
{
KisConfig cfg;
// XXX: Bad me -- hard-coded constant.
slPressure->setValue( 100 - cfg.getPressureCorrection() );
#ifdef EXTENDED_X11_TABLET_SUPPORT
initTabletDevices();
#else
grpTabletDevices -> hide();
#endif
}
void PressureSettingsTab::setDefault()
void TabletSettingsTab::setDefault()
{
KisConfig cfg;
// XXX: Bad me -- hard-coded constant.
slPressure->setValue(100 - cfg.getDefaultPressureCorrection());
}
void TabletSettingsTab::applySettings()
{
KisConfig cfg;
// Pressure sensitivity setting == between 0 and 99
cfg.setPressureCorrection(100 - slPressure -> value());
#ifdef EXTENDED_X11_TABLET_SUPPORT
applyTabletDeviceSettings();
#endif
}
#ifdef EXTENDED_X11_TABLET_SUPPORT
TabletSettingsTab::DeviceSettings::DeviceSettings(KisCanvasWidget::X11TabletDevice *tabletDevice, bool enabled,
Q_INT32 xAxis, Q_INT32 yAxis, Q_INT32 pressureAxis,
Q_INT32 xTiltAxis, Q_INT32 yTiltAxis, Q_INT32 wheelAxis,
Q_INT32 toolIDAxis, Q_INT32 serialNumberAxis)
: m_tabletDevice(tabletDevice),
m_enabled(enabled),
m_xAxis(xAxis),
m_yAxis(yAxis),
m_pressureAxis(pressureAxis),
m_xTiltAxis(xTiltAxis),
m_yTiltAxis(yTiltAxis),
m_wheelAxis(wheelAxis),
m_toolIDAxis(toolIDAxis),
m_serialNumberAxis(serialNumberAxis)
{
}
TabletSettingsTab::DeviceSettings::DeviceSettings()
: m_tabletDevice(0),
m_enabled(false),
m_xAxis(KisCanvasWidget::X11TabletDevice::NoAxis),
m_yAxis(KisCanvasWidget::X11TabletDevice::NoAxis),
m_pressureAxis(KisCanvasWidget::X11TabletDevice::NoAxis),
m_xTiltAxis(KisCanvasWidget::X11TabletDevice::NoAxis),
m_yTiltAxis(KisCanvasWidget::X11TabletDevice::NoAxis),
m_wheelAxis(KisCanvasWidget::X11TabletDevice::NoAxis),
m_toolIDAxis(KisCanvasWidget::X11TabletDevice::NoAxis),
m_serialNumberAxis(KisCanvasWidget::X11TabletDevice::NoAxis)
{
}
void TabletSettingsTab::DeviceSettings::applySettings()
{
m_tabletDevice -> setEnabled(enabled());
m_tabletDevice -> setXAxis(xAxis());
m_tabletDevice -> setYAxis(yAxis());
m_tabletDevice -> setPressureAxis(pressureAxis());
m_tabletDevice -> setXTiltAxis(xTiltAxis());
m_tabletDevice -> setYTiltAxis(yTiltAxis());
m_tabletDevice -> setWheelAxis(wheelAxis());
m_tabletDevice -> setToolIDAxis(toolIDAxis());
m_tabletDevice -> setSerialNumberAxis(serialNumberAxis());
m_tabletDevice -> writeSettingsToConfig();
}
void TabletSettingsTab::DeviceSettings::setEnabled(bool enabled)
{
m_enabled = enabled;
}
bool TabletSettingsTab::DeviceSettings::enabled() const
{
return m_enabled;
}
Q_INT32 TabletSettingsTab::DeviceSettings::numAxes() const
{
return m_tabletDevice -> numAxes();
}
void TabletSettingsTab::DeviceSettings::setXAxis(Q_INT32 axis)
{
m_xAxis = axis;
}
void TabletSettingsTab::DeviceSettings::setYAxis(Q_INT32 axis)
{
m_yAxis = axis;
}
void TabletSettingsTab::DeviceSettings::setPressureAxis(Q_INT32 axis)
{
m_pressureAxis = axis;
}
void TabletSettingsTab::DeviceSettings::setXTiltAxis(Q_INT32 axis)
{
m_xTiltAxis = axis;
}
void TabletSettingsTab::DeviceSettings::setYTiltAxis(Q_INT32 axis)
{
m_yTiltAxis = axis;
}
void TabletSettingsTab::DeviceSettings::setWheelAxis(Q_INT32 axis)
{
m_wheelAxis = axis;
}
void TabletSettingsTab::DeviceSettings::setToolIDAxis(Q_INT32 axis)
{
m_toolIDAxis = axis;
}
void TabletSettingsTab::DeviceSettings::setSerialNumberAxis(Q_INT32 axis)
{
m_serialNumberAxis = axis;
}
Q_INT32 TabletSettingsTab::DeviceSettings::xAxis() const
{
return m_xAxis;
}
Q_INT32 TabletSettingsTab::DeviceSettings::yAxis() const
{
return m_yAxis;
}
Q_INT32 TabletSettingsTab::DeviceSettings::pressureAxis() const
{
return m_pressureAxis;
}
Q_INT32 TabletSettingsTab::DeviceSettings::xTiltAxis() const
{
return m_xTiltAxis;
}
Q_INT32 TabletSettingsTab::DeviceSettings::yTiltAxis() const
{
return m_yTiltAxis;
}
Q_INT32 TabletSettingsTab::DeviceSettings::wheelAxis() const
{
return m_wheelAxis;
}
Q_INT32 TabletSettingsTab::DeviceSettings::toolIDAxis() const
{
return m_toolIDAxis;
}
Q_INT32 TabletSettingsTab::DeviceSettings::serialNumberAxis() const
{
return m_serialNumberAxis;
}
TabletSettingsTab::TabletDeviceSettingsDialog::TabletDeviceSettingsDialog(const QString& deviceName, DeviceSettings settings,
QWidget *parent, const char *name)
: super(parent, name, true, "", Ok | Cancel)
{
setCaption(i18n("Configure %1").arg(deviceName));
m_page = new WdgTabletDeviceSettings(this);
setMainWidget(m_page);
resize(m_page -> sizeHint());
for (Q_INT32 axis = 0; axis < settings.numAxes(); axis++) {
QString axisString;
axisString.setNum(axis);
m_page -> cbX -> insertItem(axisString);
m_page -> cbY -> insertItem(axisString);
m_page -> cbPressure -> insertItem(axisString);
m_page -> cbXTilt -> insertItem(axisString);
m_page -> cbYTilt -> insertItem(axisString);
m_page -> cbWheel -> insertItem(axisString);
m_page -> cbToolID -> insertItem(axisString);
m_page -> cbSerialNumber -> insertItem(axisString);
}
m_page -> cbX -> insertItem(i18n("None"));
m_page -> cbY -> insertItem(i18n("None"));
m_page -> cbPressure -> insertItem(i18n("None"));
m_page -> cbXTilt -> insertItem(i18n("None"));
m_page -> cbYTilt -> insertItem(i18n("None"));
m_page -> cbWheel -> insertItem(i18n("None"));
m_page -> cbToolID -> insertItem(i18n("None"));
m_page -> cbSerialNumber -> insertItem(i18n("None"));
if (settings.xAxis() != KisCanvasWidget::X11TabletDevice::NoAxis) {
m_page -> cbX -> setCurrentItem(settings.xAxis());
} else {
m_page -> cbX -> setCurrentItem(settings.numAxes());
}
if (settings.yAxis() != KisCanvasWidget::X11TabletDevice::NoAxis) {
m_page -> cbY -> setCurrentItem(settings.yAxis());
} else {
m_page -> cbY -> setCurrentItem(settings.numAxes());
}
if (settings.pressureAxis() != KisCanvasWidget::X11TabletDevice::NoAxis) {
m_page -> cbPressure -> setCurrentItem(settings.pressureAxis());
} else {
m_page -> cbPressure -> setCurrentItem(settings.numAxes());
}
if (settings.xTiltAxis() != KisCanvasWidget::X11TabletDevice::NoAxis) {
m_page -> cbXTilt -> setCurrentItem(settings.xTiltAxis());
} else {
m_page -> cbXTilt -> setCurrentItem(settings.numAxes());
}
if (settings.yTiltAxis() != KisCanvasWidget::X11TabletDevice::NoAxis) {
m_page -> cbYTilt -> setCurrentItem(settings.yTiltAxis());
} else {
m_page -> cbYTilt -> setCurrentItem(settings.numAxes());
}
if (settings.wheelAxis() != KisCanvasWidget::X11TabletDevice::NoAxis) {
m_page -> cbWheel -> setCurrentItem(settings.wheelAxis());
} else {
m_page -> cbWheel -> setCurrentItem(settings.numAxes());
}
if (settings.toolIDAxis() != KisCanvasWidget::X11TabletDevice::NoAxis) {
m_page -> cbToolID -> setCurrentItem(settings.toolIDAxis());
} else {
m_page -> cbToolID -> setCurrentItem(settings.numAxes());
}
if (settings.serialNumberAxis() != KisCanvasWidget::X11TabletDevice::NoAxis) {
m_page -> cbSerialNumber -> setCurrentItem(settings.serialNumberAxis());
} else {
m_page -> cbSerialNumber -> setCurrentItem(settings.numAxes());
}
m_settings = settings;
}
TabletSettingsTab::TabletDeviceSettingsDialog::~TabletDeviceSettingsDialog()
{
delete m_page;
}
TabletSettingsTab::DeviceSettings TabletSettingsTab::TabletDeviceSettingsDialog::settings()
{
const Q_INT32 noAxis = m_settings.numAxes();
if (m_page -> cbX -> currentItem() != noAxis ) {
m_settings.setXAxis(m_page -> cbX -> currentItem());