00001 /* 00002 * Copyright (c) 2006 Adrian Page <adrian@pagenet.plus.com> 00003 * 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include "KoInputDevice.h" 00021 00022 #define UNKNOWN_INPUT_DEVICE_ID -1 00023 #define FIRST_INPUT_DEVICE_ID 0 00024 00025 qint32 KoInputDevice::NextInputDeviceID = FIRST_INPUT_DEVICE_ID; 00026 00027 KoInputDevice KoInputDevice::Mouse; 00028 KoInputDevice KoInputDevice::Stylus; 00029 KoInputDevice KoInputDevice::Eraser; 00030 KoInputDevice KoInputDevice::Puck; 00031 KoInputDevice KoInputDevice::Unknown(UNKNOWN_INPUT_DEVICE_ID); 00032 00033 QList<KoInputDevice> KoInputDevice::InputDevices; 00034 00035 KoInputDevice::KoInputDevice() 00036 { 00037 m_id = UNKNOWN_INPUT_DEVICE_ID; 00038 } 00039 00040 KoInputDevice KoInputDevice::allocateNextDevice() 00041 { 00042 KoInputDevice inputDevice(NextInputDeviceID); 00043 NextInputDeviceID++; 00044 InputDevices.append(inputDevice); 00045 00046 return inputDevice; 00047 } 00048 00049 KoInputDevice KoInputDevice::allocateInputDevice() 00050 { 00051 allocateDefaultDevicesIfNeeded(); 00052 00053 return allocateNextDevice(); 00054 } 00055 00056 void KoInputDevice::allocateDefaultDevicesIfNeeded() 00057 { 00058 if (NextInputDeviceID == FIRST_INPUT_DEVICE_ID) { 00059 Mouse = allocateNextDevice(); 00060 Stylus = allocateNextDevice(); 00061 Eraser = allocateNextDevice(); 00062 Puck = allocateNextDevice(); 00063 } 00064 } 00065 00066 QList<KoInputDevice> KoInputDevice::inputDevices() 00067 { 00068 allocateDefaultDevicesIfNeeded(); 00069 00070 return InputDevices; 00071 } 00072 00073 KoInputDevice KoInputDevice::mouse() 00074 { 00075 allocateDefaultDevicesIfNeeded(); 00076 return Mouse; 00077 } 00078 00079 KoInputDevice KoInputDevice::stylus() 00080 { 00081 allocateDefaultDevicesIfNeeded(); 00082 return Stylus; 00083 } 00084 00085 KoInputDevice KoInputDevice::eraser() 00086 { 00087 allocateDefaultDevicesIfNeeded(); 00088 return Eraser; 00089 } 00090 00091 KoInputDevice KoInputDevice::puck() 00092 { 00093 allocateDefaultDevicesIfNeeded(); 00094 return Puck; 00095 } 00096 00097 KoInputDevice KoInputDevice::unknown() 00098 { 00099 allocateDefaultDevicesIfNeeded(); 00100 return Unknown; 00101 } 00102