From 17ed926cdfd4a260856d53558d7e4d743e518bc6 Mon Sep 17 00:00:00 2001 From: John Toman Date: Tue, 26 May 2009 00:57:02 +0000 Subject: [PATCH] reverting trunk back to stable 3.4.1 version git-svn-id: svn://svn.code.sf.net/p/qjoypad/code/trunk@82 c05e91a0-76c8-4ec0-b377-ef19ce7cc080 --- src/Makefile | 745 ++++++++++++++++------------------ src/axis.cpp | 534 ++++++++++++------------ src/axis.h | 23 +- src/axis_edit.cpp | 235 +++++------ src/axis_edit.h | 18 +- src/axisw.cpp | 49 ++- src/axisw.h | 6 +- src/button.cpp | 254 ++++++------ src/button.h | 20 +- src/button_edit.cpp | 100 +++-- src/button_edit.h | 9 +- src/buttonw.cpp | 33 +- src/buttonw.h | 5 - src/component.h | 36 ++ src/constant.h | 2 - src/device.h | 5 +- src/error.h | 2 +- src/event.cpp | 26 +- src/flash.cpp | 134 +++--- src/flash.h | 5 +- src/icon.cpp | 41 +- src/icon.h | 16 +- src/joypad.cpp | 381 +++++++---------- src/joypad.h | 41 +- src/joypadw.cpp | 149 ++++--- src/joypadw.h | 6 +- src/joyslider.cpp | 375 +++++++++-------- src/joyslider.h | 15 +- src/keycode.cpp | 231 +++++++---- src/keycode.h | 35 +- src/layout.cpp | 579 +++++++++++--------------- src/layout.h | 30 +- src/layout_edit.cpp | 200 ++++----- src/layout_edit.h | 12 +- src/loop.cpp | 65 +++ src/loop.h | 39 ++ src/main.cpp | 403 +++++++++--------- src/qjoypad | Bin 3556445 -> 232556 bytes src/qjoypad.pro | 10 +- src/quickset.cpp | 91 ++--- src/quickset.h | 10 +- src/timer.h | 11 + src/trayicon/trayicon.cpp | 109 ++--- src/trayicon/trayicon.h | 14 +- src/trayicon/trayicon_x11.cpp | 354 ++++++++-------- 45 files changed, 2674 insertions(+), 2784 deletions(-) create mode 100644 src/component.h create mode 100644 src/loop.cpp create mode 100644 src/loop.h create mode 100644 src/timer.h diff --git a/src/Makefile b/src/Makefile index 38f50f8..f950ab4 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,48 +1,74 @@ ############################################################################# # Makefile for building: qjoypad -# Generated by qmake (2.01a) (Qt 4.5.1) on: Mon May 25 00:43:37 2009 +# Generated by qmake (1.07a) (Qt 3.3.6) on: Wed Nov 1 12:59:29 2006 # Project: qjoypad.pro # Template: app -# Command: /usr/bin/qmake -unix -o Makefile qjoypad.pro +# Command: $(QMAKE) "DEVDIR=/dev/input" "PREFIX=/usr" "DEFINES += " -o Makefile qjoypad.pro ############################################################################# ####### Compiler, tools and options -CC = gcc -CXX = g++ -DEFINES = -DDEVDIR="" -DICON24="/share/pixmaps/qjoypad/icon24.png" -DICON64="/share/pixmaps/qjoypad/icon64.png" -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -CFLAGS = -pipe -march=i686 -mtune=generic -O2 -pipe -Wall -W -D_REENTRANT $(DEFINES) -CXXFLAGS = -pipe -march=i686 -mtune=generic -O2 -pipe -Wall -W -D_REENTRANT $(DEFINES) -INCPATH = -I/usr/share/qt/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I. -Itrayicon -I. -I. -LINK = g++ -LFLAGS = -Wl,-O1 -Wl,-rpath,/usr/lib -LIBS = $(SUBLIBS) -L/usr/lib -lXtst -lQtGui -L/usr/lib -L/usr/X11R6/lib -pthread -lpng -lfreetype -lgobject-2.0 -lSM -lICE -pthread -pthread -lXrender -lfontconfig -lXext -lX11 -lQtCore -lz -lm -pthread -lgthread-2.0 -lrt -lglib-2.0 -ldl -lpthread -AR = ar cqs -RANLIB = -QMAKE = /usr/bin/qmake -TAR = tar -cf -COMPRESS = gzip -9f -COPY = cp -f -SED = sed -COPY_FILE = $(COPY) -COPY_DIR = $(COPY) -r -INSTALL_FILE = install -m 644 -p -INSTALL_DIR = $(COPY_DIR) -INSTALL_PROGRAM = install -m 755 -p -DEL_FILE = rm -f -SYMLINK = ln -sf -DEL_DIR = rmdir -MOVE = mv -f +CC = gcc +CXX = g++ +LEX = flex +YACC = yacc +CFLAGS = -pipe -Wall -W -O2 -D_REENTRANT -DDEVDIR='"/dev/input"' -DICON24='"/usr/share/pixmaps/qjoypad/icon24.png"' -DICON64='"/usr/share/pixmaps/qjoypad/icon64.png"' -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -DQT_SHARED -DQT_TABLET_SUPPORT +CXXFLAGS = -pipe -Wall -W -O2 -D_REENTRANT -DDEVDIR='"/dev/input"' -DICON24='"/usr/share/pixmaps/qjoypad/icon24.png"' -DICON64='"/usr/share/pixmaps/qjoypad/icon64.png"' -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -DQT_SHARED -DQT_TABLET_SUPPORT +LEXFLAGS = +YACCFLAGS= -d +INCPATH = -I/usr/share/qt3/mkspecs/default -I. -I. -Itrayicon -I/usr/include/qt3 +LINK = g++ +LFLAGS = +LIBS = $(SUBLIBS) -L/usr/share/qt3/lib -L/usr/X11R6/lib -lXtst -lqt-mt -lXext -lX11 -lm -lpthread +AR = ar cqs +RANLIB = +MOC = /usr/share/qt3/bin/moc +UIC = /usr/share/qt3/bin/uic +QMAKE = qmake +TAR = tar -cf +GZIP = gzip -9f +COPY = cp -f +COPY_FILE= $(COPY) +COPY_DIR = $(COPY) -r +INSTALL_FILE= $(COPY_FILE) +INSTALL_DIR = $(COPY_DIR) +DEL_FILE = rm -f +SYMLINK = ln -sf +DEL_DIR = rmdir +MOVE = mv -f CHK_DIR_EXISTS= test -d -MKDIR = mkdir -p +MKDIR = mkdir -p ####### Output directory -OBJECTS_DIR = ./ +OBJECTS_DIR = ./ ####### Files -SOURCES = axis.cpp \ +HEADERS = axis.h \ + axis_edit.h \ + axisw.h \ + button.h \ + button_edit.h \ + buttonw.h \ + component.h \ + constant.h \ + device.h \ + error.h \ + event.h \ + flash.h \ + icon.h \ + joypad.h \ + joypadw.h \ + joyslider.h \ + keycode.h \ + layout.h \ + layout_edit.h \ + loop.h \ + quickset.h \ + timer.h \ + trayicon/trayicon.h +SOURCES = axis.cpp \ axis_edit.cpp \ axisw.cpp \ button.cpp \ @@ -57,23 +83,12 @@ SOURCES = axis.cpp \ keycode.cpp \ layout.cpp \ layout_edit.cpp \ + loop.cpp \ main.cpp \ quickset.cpp \ - getkey.cpp \ trayicon/trayicon.cpp \ - trayicon/trayicon_x11.cpp moc_axis.cpp \ - moc_axis_edit.cpp \ - moc_button.cpp \ - moc_button_edit.cpp \ - moc_flash.cpp \ - moc_icon.cpp \ - moc_joypad.cpp \ - moc_joypadw.cpp \ - moc_keycode.cpp \ - moc_layout.cpp \ - moc_getkey.cpp \ - moc_trayicon.cpp -OBJECTS = axis.o \ + trayicon/trayicon_x11.cpp +OBJECTS = axis.o \ axis_edit.o \ axisw.o \ button.o \ @@ -88,126 +103,85 @@ OBJECTS = axis.o \ keycode.o \ layout.o \ layout_edit.o \ + loop.o \ main.o \ quickset.o \ - getkey.o \ trayicon.o \ - trayicon_x11.o \ - moc_axis.o \ - moc_axis_edit.o \ - moc_button.o \ + trayicon_x11.o +FORMS = +UICDECLS = +UICIMPLS = +SRCMOC = moc_axis_edit.cpp \ + moc_button_edit.cpp \ + moc_flash.cpp \ + moc_icon.cpp \ + moc_joypadw.cpp \ + moc_keycode.cpp \ + moc_layout.cpp \ + trayicon/moc_trayicon.cpp +OBJMOC = moc_axis_edit.o \ moc_button_edit.o \ moc_flash.o \ moc_icon.o \ - moc_joypad.o \ moc_joypadw.o \ moc_keycode.o \ moc_layout.o \ - moc_getkey.o \ moc_trayicon.o -DIST = /usr/share/qt/mkspecs/common/g++.conf \ - /usr/share/qt/mkspecs/common/unix.conf \ - /usr/share/qt/mkspecs/common/linux.conf \ - /usr/share/qt/mkspecs/qconfig.pri \ - /usr/share/qt/mkspecs/features/qt_functions.prf \ - /usr/share/qt/mkspecs/features/qt_config.prf \ - /usr/share/qt/mkspecs/features/exclusive_builds.prf \ - /usr/share/qt/mkspecs/features/default_pre.prf \ - /usr/share/qt/mkspecs/features/release.prf \ - /usr/share/qt/mkspecs/features/default_post.prf \ - /usr/share/qt/mkspecs/features/warn_on.prf \ - /usr/share/qt/mkspecs/features/qt.prf \ - /usr/share/qt/mkspecs/features/unix/thread.prf \ - /usr/share/qt/mkspecs/features/moc.prf \ - /usr/share/qt/mkspecs/features/resources.prf \ - /usr/share/qt/mkspecs/features/uic.prf \ - /usr/share/qt/mkspecs/features/yacc.prf \ - /usr/share/qt/mkspecs/features/lex.prf \ - /usr/share/qt/mkspecs/features/include_source_dir.prf \ - qjoypad.pro -QMAKE_TARGET = qjoypad -DESTDIR = -TARGET = qjoypad +DIST = qjoypad.pro +QMAKE_TARGET = qjoypad +DESTDIR = +TARGET = qjoypad first: all ####### Implicit rules -.SUFFIXES: .o .c .cpp .cc .cxx .C +.SUFFIXES: .c .o .cpp .cc .cxx .C .cpp.o: - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< .cc.o: - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< .cxx.o: - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< .C.o: - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< .c.o: - $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<" + $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $< ####### Build rules all: Makefile $(TARGET) -$(TARGET): $(OBJECTS) - $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS) +$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) + $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJMOC) $(OBJCOMP) $(LIBS) -Makefile: qjoypad.pro /usr/share/qt/mkspecs/linux-g++/qmake.conf /usr/share/qt/mkspecs/common/g++.conf \ - /usr/share/qt/mkspecs/common/unix.conf \ - /usr/share/qt/mkspecs/common/linux.conf \ - /usr/share/qt/mkspecs/qconfig.pri \ - /usr/share/qt/mkspecs/features/qt_functions.prf \ - /usr/share/qt/mkspecs/features/qt_config.prf \ - /usr/share/qt/mkspecs/features/exclusive_builds.prf \ - /usr/share/qt/mkspecs/features/default_pre.prf \ - /usr/share/qt/mkspecs/features/release.prf \ - /usr/share/qt/mkspecs/features/default_post.prf \ - /usr/share/qt/mkspecs/features/warn_on.prf \ - /usr/share/qt/mkspecs/features/qt.prf \ - /usr/share/qt/mkspecs/features/unix/thread.prf \ - /usr/share/qt/mkspecs/features/moc.prf \ - /usr/share/qt/mkspecs/features/resources.prf \ - /usr/share/qt/mkspecs/features/uic.prf \ - /usr/share/qt/mkspecs/features/yacc.prf \ - /usr/share/qt/mkspecs/features/lex.prf \ - /usr/share/qt/mkspecs/features/include_source_dir.prf \ - /usr/lib/libQtGui.prl \ - /usr/lib/libQtCore.prl - $(QMAKE) -unix -o Makefile qjoypad.pro -/usr/share/qt/mkspecs/common/g++.conf: -/usr/share/qt/mkspecs/common/unix.conf: -/usr/share/qt/mkspecs/common/linux.conf: -/usr/share/qt/mkspecs/qconfig.pri: -/usr/share/qt/mkspecs/features/qt_functions.prf: -/usr/share/qt/mkspecs/features/qt_config.prf: -/usr/share/qt/mkspecs/features/exclusive_builds.prf: -/usr/share/qt/mkspecs/features/default_pre.prf: -/usr/share/qt/mkspecs/features/release.prf: -/usr/share/qt/mkspecs/features/default_post.prf: -/usr/share/qt/mkspecs/features/warn_on.prf: -/usr/share/qt/mkspecs/features/qt.prf: -/usr/share/qt/mkspecs/features/unix/thread.prf: -/usr/share/qt/mkspecs/features/moc.prf: -/usr/share/qt/mkspecs/features/resources.prf: -/usr/share/qt/mkspecs/features/uic.prf: -/usr/share/qt/mkspecs/features/yacc.prf: -/usr/share/qt/mkspecs/features/lex.prf: -/usr/share/qt/mkspecs/features/include_source_dir.prf: -/usr/lib/libQtGui.prl: -/usr/lib/libQtCore.prl: -qmake: FORCE - @$(QMAKE) -unix -o Makefile qjoypad.pro +mocables: $(SRCMOC) +uicables: $(UICDECLS) $(UICIMPLS) + +$(MOC): + ( cd $(QTDIR)/src/moc && $(MAKE) ) + +Makefile: qjoypad.pro /usr/share/qt3/mkspecs/default/qmake.conf /usr/share/qt3/lib/libqt-mt.prl + $(QMAKE) "DEVDIR=/dev/input" "PREFIX=/usr" "DEFINES += " -o Makefile qjoypad.pro +qmake: + @$(QMAKE) "DEVDIR=/dev/input" "PREFIX=/usr" "DEFINES += " -o Makefile qjoypad.pro dist: - @$(CHK_DIR_EXISTS) .tmp/qjoypad1.0.0 || $(MKDIR) .tmp/qjoypad1.0.0 - $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/qjoypad1.0.0/ && $(COPY_FILE) --parents axis.h axis_edit.h axisw.h button.h button_edit.h buttonw.h constant.h device.h error.h event.h flash.h icon.h joypad.h joypadw.h joyslider.h keycode.h layout.h getkey.h layout_edit.h quickset.h trayicon/trayicon.h .tmp/qjoypad1.0.0/ && $(COPY_FILE) --parents axis.cpp axis_edit.cpp axisw.cpp button.cpp button_edit.cpp buttonw.cpp event.cpp flash.cpp icon.cpp joypad.cpp joypadw.cpp joyslider.cpp keycode.cpp layout.cpp layout_edit.cpp main.cpp quickset.cpp getkey.cpp trayicon/trayicon.cpp trayicon/trayicon_x11.cpp .tmp/qjoypad1.0.0/ && (cd `dirname .tmp/qjoypad1.0.0` && $(TAR) qjoypad1.0.0.tar qjoypad1.0.0 && $(COMPRESS) qjoypad1.0.0.tar) && $(MOVE) `dirname .tmp/qjoypad1.0.0`/qjoypad1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/qjoypad1.0.0 + @mkdir -p .tmp/qjoypad && $(COPY_FILE) --parents $(SOURCES) $(HEADERS) $(FORMS) $(DIST) .tmp/qjoypad/ && ( cd `dirname .tmp/qjoypad` && $(TAR) qjoypad.tar qjoypad && $(GZIP) qjoypad.tar ) && $(MOVE) `dirname .tmp/qjoypad`/qjoypad.tar.gz . && $(DEL_FILE) -r .tmp/qjoypad +mocclean: + -$(DEL_FILE) $(OBJMOC) + -$(DEL_FILE) $(SRCMOC) -clean:compiler_clean +uiclean: + +yaccclean: +lexclean: +clean: mocclean -$(DEL_FILE) $(OBJECTS) -$(DEL_FILE) *~ core *.core @@ -215,308 +189,220 @@ clean:compiler_clean ####### Sub-libraries distclean: clean - -$(DEL_FILE) $(TARGET) - -$(DEL_FILE) Makefile + -$(DEL_FILE) $(TARGET) $(TARGET) -mocclean: compiler_moc_header_clean compiler_moc_source_clean - -mocables: compiler_moc_header_make_all compiler_moc_source_make_all - -compiler_moc_header_make_all: moc_axis.cpp moc_axis_edit.cpp moc_button.cpp moc_button_edit.cpp moc_flash.cpp moc_icon.cpp moc_joypad.cpp moc_joypadw.cpp moc_keycode.cpp moc_layout.cpp moc_getkey.cpp moc_trayicon.cpp -compiler_moc_header_clean: - -$(DEL_FILE) moc_axis.cpp moc_axis_edit.cpp moc_button.cpp moc_button_edit.cpp moc_flash.cpp moc_icon.cpp moc_joypad.cpp moc_joypadw.cpp moc_keycode.cpp moc_layout.cpp moc_getkey.cpp moc_trayicon.cpp -moc_axis.cpp: constant.h \ - axis.h - /usr/bin/moc $(DEFINES) $(INCPATH) axis.h -o moc_axis.cpp - -moc_axis_edit.cpp: axis.h \ - constant.h \ - joyslider.h \ - keycode.h \ - axis_edit.h - /usr/bin/moc $(DEFINES) $(INCPATH) axis_edit.h -o moc_axis_edit.cpp - -moc_button.cpp: keycode.h \ - constant.h \ - button.h - /usr/bin/moc $(DEFINES) $(INCPATH) button.h -o moc_button.cpp - -moc_button_edit.cpp: button.h \ - keycode.h \ - constant.h \ - button_edit.h - /usr/bin/moc $(DEFINES) $(INCPATH) button_edit.h -o moc_button_edit.cpp - -moc_flash.cpp: flash.h - /usr/bin/moc $(DEFINES) $(INCPATH) flash.h -o moc_flash.cpp - -moc_icon.cpp: constant.h \ - icon.h - /usr/bin/moc $(DEFINES) $(INCPATH) icon.h -o moc_icon.cpp - -moc_joypad.cpp: button.h \ - keycode.h \ - constant.h \ - axis.h \ - joypadw.h \ - axisw.h \ - flash.h \ - axis_edit.h \ - joyslider.h \ - joypad.h \ - error.h \ - buttonw.h \ - button_edit.h \ - quickset.h \ - joypad.h - /usr/bin/moc $(DEFINES) $(INCPATH) joypad.h -o moc_joypad.cpp - -moc_joypadw.cpp: axisw.h \ - axis.h \ - constant.h \ - flash.h \ - axis_edit.h \ - joyslider.h \ - keycode.h \ - joypad.h \ - button.h \ - joypadw.h \ - buttonw.h \ - button_edit.h \ - quickset.h \ - error.h \ - joypadw.h - /usr/bin/moc $(DEFINES) $(INCPATH) joypadw.h -o moc_joypadw.cpp - -moc_keycode.cpp: constant.h \ - keycode.h - /usr/bin/moc $(DEFINES) $(INCPATH) keycode.h -o moc_keycode.cpp - -moc_layout.cpp: joypad.h \ - button.h \ - keycode.h \ - constant.h \ - axis.h \ - joypadw.h \ - axisw.h \ - flash.h \ - axis_edit.h \ - joyslider.h \ - buttonw.h \ - button_edit.h \ - quickset.h \ - error.h \ - device.h \ - trayicon/trayicon.h \ - icon.h \ - layout_edit.h \ - layout.h \ - layout.h - /usr/bin/moc $(DEFINES) $(INCPATH) layout.h -o moc_layout.cpp - -moc_getkey.cpp: constant.h \ - getkey.h - /usr/bin/moc $(DEFINES) $(INCPATH) getkey.h -o moc_getkey.cpp - -moc_trayicon.cpp: trayicon/trayicon.h - /usr/bin/moc $(DEFINES) $(INCPATH) trayicon/trayicon.h -o moc_trayicon.cpp - -compiler_rcc_make_all: -compiler_rcc_clean: -compiler_image_collection_make_all: qmake_image_collection.cpp -compiler_image_collection_clean: - -$(DEL_FILE) qmake_image_collection.cpp -compiler_moc_source_make_all: -compiler_moc_source_clean: -compiler_uic_make_all: -compiler_uic_clean: -compiler_yacc_decl_make_all: -compiler_yacc_decl_clean: -compiler_yacc_impl_make_all: -compiler_yacc_impl_clean: -compiler_lex_make_all: -compiler_lex_clean: -compiler_clean: compiler_moc_header_clean +FORCE: ####### Compile axis.o: axis.cpp axis.h \ - constant.h \ - event.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o axis.o axis.cpp + component.h \ + timer.h \ + event.h \ + constant.h axis_edit.o: axis_edit.cpp axis_edit.h \ + joyslider.h \ + keycode.h \ axis.h \ constant.h \ - joyslider.h \ - keycode.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o axis_edit.o axis_edit.cpp + component.h \ + timer.h \ + event.h axisw.o: axisw.cpp axisw.h \ axis.h \ - constant.h \ - flash.h \ axis_edit.h \ + flash.h \ + component.h \ + timer.h \ + event.h \ + constant.h \ joyslider.h \ keycode.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o axisw.o axisw.cpp button.o: button.cpp button.h \ + component.h \ + timer.h \ keycode.h \ - constant.h \ - event.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o button.o button.cpp + event.h \ + constant.h button_edit.o: button_edit.cpp button_edit.h \ button.h \ keycode.h \ + component.h \ + timer.h \ + event.h \ constant.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o button_edit.o button_edit.cpp buttonw.o: buttonw.cpp buttonw.h \ button.h \ - keycode.h \ - constant.h \ button_edit.h \ - flash.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o buttonw.o buttonw.cpp + flash.h \ + component.h \ + timer.h \ + keycode.h \ + event.h \ + constant.h event.o: event.cpp event.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o event.o event.cpp flash.o: flash.cpp flash.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o flash.o flash.cpp icon.o: icon.cpp icon.h \ constant.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o icon.o icon.cpp joypad.o: joypad.cpp joypad.h \ button.h \ - keycode.h \ - constant.h \ axis.h \ joypadw.h \ + error.h \ + component.h \ + timer.h \ + keycode.h \ + event.h \ + constant.h \ axisw.h \ - flash.h \ - axis_edit.h \ - joyslider.h \ buttonw.h \ - button_edit.h \ quickset.h \ - error.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o joypad.o joypad.cpp + axis_edit.h \ + flash.h \ + joyslider.h \ + button_edit.h joypadw.o: joypadw.cpp joypadw.h \ - axisw.h \ - axis.h \ - constant.h \ - flash.h \ - axis_edit.h \ - joyslider.h \ - keycode.h \ joypad.h \ - button.h \ - error.h \ + axisw.h \ buttonw.h \ - button_edit.h \ - quickset.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o joypadw.o joypadw.cpp + quickset.h \ + button.h \ + axis.h \ + error.h \ + component.h \ + timer.h \ + keycode.h \ + event.h \ + constant.h \ + axis_edit.h \ + flash.h \ + joyslider.h \ + button_edit.h joyslider.o: joyslider.cpp joyslider.h \ constant.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o joyslider.o joyslider.cpp keycode.o: keycode.cpp keycode.h \ - constant.h \ - getkey.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o keycode.o keycode.cpp + constant.h layout.o: layout.cpp layout.h \ joypad.h \ - button.h \ - keycode.h \ - constant.h \ - axis.h \ - joypadw.h \ - axisw.h \ - flash.h \ - axis_edit.h \ - joyslider.h \ - buttonw.h \ - button_edit.h \ - quickset.h \ - error.h \ - device.h \ - trayicon/trayicon.h \ - icon.h \ - layout_edit.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o layout.o layout.cpp - -layout_edit.o: layout_edit.cpp layout_edit.h \ - flash.h \ - layout.h \ - joypad.h \ - button.h \ - keycode.h \ - constant.h \ - axis.h \ - joypadw.h \ - axisw.h \ - axis_edit.h \ - joyslider.h \ - buttonw.h \ - button_edit.h \ - quickset.h \ - error.h \ - device.h \ - trayicon/trayicon.h \ - icon.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o layout_edit.o layout_edit.cpp - -main.o: main.cpp layout.h \ - joypad.h \ - button.h \ - keycode.h \ - constant.h \ - axis.h \ - joypadw.h \ - axisw.h \ - flash.h \ - axis_edit.h \ - joyslider.h \ - buttonw.h \ - button_edit.h \ - quickset.h \ error.h \ device.h \ trayicon/trayicon.h \ icon.h \ layout_edit.h \ - event.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp - -quickset.o: quickset.cpp quickset.h \ - joypad.h \ button.h \ - keycode.h \ - constant.h \ axis.h \ joypadw.h \ + component.h \ + timer.h \ + keycode.h \ + event.h \ + constant.h \ axisw.h \ + buttonw.h \ + quickset.h \ + axis_edit.h \ flash.h \ + joyslider.h \ + button_edit.h + +layout_edit.o: layout_edit.cpp layout_edit.h \ + flash.h \ + layout.h \ + device.h \ + joypadw.h \ + joypad.h \ + error.h \ + trayicon/trayicon.h \ + icon.h \ + button.h \ + axis.h \ + component.h \ + timer.h \ + keycode.h \ + event.h \ + constant.h \ + axisw.h \ + buttonw.h \ + quickset.h \ axis_edit.h \ joyslider.h \ - buttonw.h \ - button_edit.h \ - error.h \ - getkey.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o quickset.o quickset.cpp + button_edit.h -getkey.o: getkey.cpp getkey.h \ - constant.h - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o getkey.o getkey.cpp +loop.o: loop.cpp loop.h \ + joypad.h \ + device.h \ + button.h \ + axis.h \ + joypadw.h \ + error.h \ + component.h \ + timer.h \ + keycode.h \ + event.h \ + constant.h \ + axisw.h \ + buttonw.h \ + quickset.h \ + axis_edit.h \ + flash.h \ + joyslider.h \ + button_edit.h + +main.o: main.cpp loop.h \ + layout.h \ + event.h \ + device.h \ + error.h \ + joypad.h \ + button.h \ + axis.h \ + joypadw.h \ + component.h \ + timer.h \ + keycode.h \ + constant.h \ + axisw.h \ + buttonw.h \ + quickset.h \ + axis_edit.h \ + flash.h \ + joyslider.h \ + button_edit.h \ + trayicon/trayicon.h \ + icon.h \ + layout_edit.h + +quickset.o: quickset.cpp quickset.h \ + keycode.h \ + joypad.h \ + constant.h \ + button.h \ + axis.h \ + joypadw.h \ + error.h \ + component.h \ + timer.h \ + event.h \ + axisw.h \ + buttonw.h \ + axis_edit.h \ + flash.h \ + joyslider.h \ + button_edit.h trayicon.o: trayicon/trayicon.cpp trayicon/trayicon.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o trayicon.o trayicon/trayicon.cpp @@ -524,67 +410,116 @@ trayicon.o: trayicon/trayicon.cpp trayicon/trayicon.h trayicon_x11.o: trayicon/trayicon_x11.cpp trayicon/trayicon.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o trayicon_x11.o trayicon/trayicon_x11.cpp -moc_axis.o: moc_axis.cpp - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_axis.o moc_axis.cpp +moc_axis_edit.o: moc_axis_edit.cpp axis_edit.h joyslider.h \ + keycode.h \ + axis.h \ + constant.h \ + component.h \ + timer.h \ + event.h -moc_axis_edit.o: moc_axis_edit.cpp - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_axis_edit.o moc_axis_edit.cpp +moc_button_edit.o: moc_button_edit.cpp button_edit.h button.h \ + keycode.h \ + component.h \ + timer.h \ + event.h \ + constant.h -moc_button.o: moc_button.cpp - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_button.o moc_button.cpp +moc_flash.o: moc_flash.cpp flash.h -moc_button_edit.o: moc_button_edit.cpp - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_button_edit.o moc_button_edit.cpp +moc_icon.o: moc_icon.cpp icon.h constant.h -moc_flash.o: moc_flash.cpp - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_flash.o moc_flash.cpp +moc_joypadw.o: moc_joypadw.cpp joypadw.h joypad.h \ + axisw.h \ + buttonw.h \ + quickset.h \ + button.h \ + axis.h \ + error.h \ + component.h \ + timer.h \ + keycode.h \ + event.h \ + constant.h \ + axis_edit.h \ + flash.h \ + joyslider.h \ + button_edit.h -moc_icon.o: moc_icon.cpp - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_icon.o moc_icon.cpp +moc_keycode.o: moc_keycode.cpp keycode.h constant.h -moc_joypad.o: moc_joypad.cpp - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_joypad.o moc_joypad.cpp +moc_layout.o: moc_layout.cpp layout.h joypad.h \ + error.h \ + device.h \ + trayicon/trayicon.h \ + icon.h \ + layout_edit.h \ + button.h \ + axis.h \ + joypadw.h \ + component.h \ + timer.h \ + keycode.h \ + event.h \ + constant.h \ + axisw.h \ + buttonw.h \ + quickset.h \ + axis_edit.h \ + flash.h \ + joyslider.h \ + button_edit.h -moc_joypadw.o: moc_joypadw.cpp - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_joypadw.o moc_joypadw.cpp +moc_trayicon.o: trayicon/moc_trayicon.cpp trayicon/trayicon.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_trayicon.o trayicon/moc_trayicon.cpp -moc_keycode.o: moc_keycode.cpp - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_keycode.o moc_keycode.cpp +moc_axis_edit.cpp: $(MOC) axis_edit.h + $(MOC) axis_edit.h -o moc_axis_edit.cpp -moc_layout.o: moc_layout.cpp - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_layout.o moc_layout.cpp +moc_button_edit.cpp: $(MOC) button_edit.h + $(MOC) button_edit.h -o moc_button_edit.cpp -moc_getkey.o: moc_getkey.cpp - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_getkey.o moc_getkey.cpp +moc_flash.cpp: $(MOC) flash.h + $(MOC) flash.h -o moc_flash.cpp -moc_trayicon.o: moc_trayicon.cpp - $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_trayicon.o moc_trayicon.cpp +moc_icon.cpp: $(MOC) icon.h + $(MOC) icon.h -o moc_icon.cpp + +moc_joypadw.cpp: $(MOC) joypadw.h + $(MOC) joypadw.h -o moc_joypadw.cpp + +moc_keycode.cpp: $(MOC) keycode.h + $(MOC) keycode.h -o moc_keycode.cpp + +moc_layout.cpp: $(MOC) layout.h + $(MOC) layout.h -o moc_layout.cpp + +trayicon/moc_trayicon.cpp: $(MOC) trayicon/trayicon.h + $(MOC) trayicon/trayicon.h -o trayicon/moc_trayicon.cpp ####### Install -install_target: first FORCE - @$(CHK_DIR_EXISTS) $(INSTALL_ROOT)/bin/ || $(MKDIR) $(INSTALL_ROOT)/bin/ - -$(INSTALL_PROGRAM) "$(QMAKE_TARGET)" "$(INSTALL_ROOT)/bin/$(QMAKE_TARGET)" - -strip "$(INSTALL_ROOT)/bin/$(QMAKE_TARGET)" +install_target: all + @$(CHK_DIR_EXISTS) "$(INSTALL_ROOT)/usr/bin/" || $(MKDIR) "$(INSTALL_ROOT)/usr/bin/" + -$(INSTALL_FILE) "$(QMAKE_TARGET)" "$(INSTALL_ROOT)/usr/bin/$(QMAKE_TARGET)" + -strip "$(INSTALL_ROOT)/usr/bin/$(QMAKE_TARGET)" -uninstall_target: FORCE - -$(DEL_FILE) "$(INSTALL_ROOT)/bin/$(QMAKE_TARGET)" - -$(DEL_DIR) $(INSTALL_ROOT)/bin/ +uninstall_target: + -$(DEL_FILE) "$(INSTALL_ROOT)/usr/bin/$(QMAKE_TARGET)" + -$(DEL_DIR) "$(INSTALL_ROOT)/usr/bin/" -install_icons: first FORCE - @$(CHK_DIR_EXISTS) $(INSTALL_ROOT)/share/pixmaps/qjoypad/ || $(MKDIR) $(INSTALL_ROOT)/share/pixmaps/qjoypad/ - cp ../icons/* /share/pixmaps/qjoypad; cd /share/pixmaps/qjoypad; ln -sf gamepad4-24x24.png icon24.png; ln -sf gamepad3-64x64.png icon64.png; chmod -R a+r /share/pixmaps/qjoypad +install_icons: all + @$(CHK_DIR_EXISTS) "$(INSTALL_ROOT)/usr/share/pixmaps/qjoypad/" || $(MKDIR) "$(INSTALL_ROOT)/usr/share/pixmaps/qjoypad/" + cp ../icons/* /usr/share/pixmaps/qjoypad; cd /usr/share/pixmaps/qjoypad; ln -sf gamepad4-24x24.png icon24.png; ln -sf gamepad3-64x64.png icon64.png; chmod -R a+r /usr/share/pixmaps/qjoypad -install_doc: first FORCE - @$(CHK_DIR_EXISTS) $(INSTALL_ROOT)/doc/qjoypad3/ || $(MKDIR) $(INSTALL_ROOT)/doc/qjoypad3/ - cp ../README.txt ../LICENSE.txt /doc/qjoypad3 +install_doc: all + @$(CHK_DIR_EXISTS) "$(INSTALL_ROOT)/usr/doc/qjoypad3/" || $(MKDIR) "$(INSTALL_ROOT)/usr/doc/qjoypad3/" + cp ../README.txt ../LICENSE.txt /usr/doc/qjoypad3 -install: install_target install_icons install_doc FORCE +install: install_target install_icons install_doc -uninstall: uninstall_target FORCE - -FORCE: +uninstall: uninstall_target diff --git a/src/axis.cpp b/src/axis.cpp index 9bbb596..054587f 100644 --- a/src/axis.cpp +++ b/src/axis.cpp @@ -1,208 +1,194 @@ #include "axis.h" -#include "event.h" + #define sqr(a) ((a)*(a)) Axis::Axis( int i ) { - index = i; - isOn = false; - isDown = false; - state = 0; - gradient = false; - toDefault(); - tick = 0; - timer = new QTimer(this); + index = i; + isOn = false; + //to keep toDefault from calling tossTimer without first calling takeTimer + gradient = false; + toDefault(); } Axis::~Axis() { - release(); - delete timer; + release(); } bool Axis::read( QTextStream* stream ) { // At this point, toDefault has just been called. - //read in a line from the stream, and split it up into individual words - QString input = stream->readLine().toLower(); - QRegExp regex("[\\s,]+"); - QStringList words = input.split(regex); + //read in a line from the stream, and split it up into individual words + QString input = stream->readLine().lower(); + QRegExp regex("[\\s,]+"); + QStringList words = QStringList::split(regex,input); + + //used to assure QString->int conversions worked + bool ok; + //int to store values derived from strings + int val; - //used to assure QString->int conversions worked - bool ok; - //int to store values derived from strings - int val; - - //step through each word, check if it's a token we recognize + //step through each word, check if it's a token we recognize for ( QStringList::Iterator it = words.begin(); it != words.end(); ++it ) { if (*it == "maxspeed") { - ++it; //move to the next word, which should be the maximum speed. - //if no value was given, there's an error in the file, stop reading. - if (it == words.end()) return false; - //try to convert the value. - val = (*it).toInt(&ok); - //if that worked and the maximum speed is in range, set it. - if (ok && val >= 0 && val <= MAXMOUSESPEED) maxSpeed = val; - //otherwise, faulty input, give up. - else return false; - } - //pretty much the same process for getting the dead zone - else if (*it == "dzone") { - ++it; - if (it == words.end()) return false; - val = (*it).toInt(&ok); - if (ok && val >= 0 && val <= JOYMAX) dZone = val; - else return false; - } - //and again for the extreme zone, - else if (*it == "xzone") { - ++it; - if (it == words.end()) return false; - val = (*it).toInt(&ok); - if (ok && val >= 0 && val <= JOYMAX) xZone = val; - else return false; - } - //and for the positive keycode, - else if (*it == "+key") { - ++it; - if (it == words.end()) return false; - val = (*it).toInt(&ok); - if (ok && val >= 0 && val <= MAXKEY) pkeycode = val; - else return false; - } - //and finally for the negative keycode. - else if (*it == "-key") { - ++it; - if (it == words.end()) return false; - val = (*it).toInt(&ok); - if (ok && val >= 0 && val <= MAXKEY) nkeycode = val; - else return false; - } - //the rest of the options are keywords without integers - else if (*it == "gradient") { - gradient = true; - } - else if (*it == "throttle+") { - throttle = 1; - } - else if (*it == "throttle-") { - throttle = -1; - } - else if (*it == "mouse+v") { - mode = mousepv; - } - else if (*it == "mouse-v") { - mode = mousenv; - } - else if (*it == "mouse+h") { - mode = mouseph; - } - else if (*it == "mouse-h") { - mode = mousenh; - } - //we ignore unrecognized words to be friendly and allow for additions to - //the format in later versions. Note, this means that typos will not get - //the desired effect OR produce an error message. + ++it; //move to the next word, which should be the maximum speed. + //if no value was given, there's an error in the file, stop reading. + if (it == words.end()) return false; + //try to convert the value. + val = (*it).toInt(&ok); + //if that worked and the maximum speed is in range, set it. + if (ok && val >= 0 && val <= MAXMOUSESPEED) maxSpeed = val; + //otherwise, faulty input, give up. + else return false; + } + //pretty much the same process for getting the dead zone + else if (*it == "dzone") { + ++it; + if (it == words.end()) return false; + val = (*it).toInt(&ok); + if (ok && val >= 0 && val <= JOYMAX) dZone = val; + else return false; + } + //and again for the extreme zone, + else if (*it == "xzone") { + ++it; + if (it == words.end()) return false; + val = (*it).toInt(&ok); + if (ok && val >= 0 && val <= JOYMAX) xZone = val; + else return false; + } + //and for the positive keycode, + else if (*it == "+key") { + ++it; + if (it == words.end()) return false; + val = (*it).toInt(&ok); + if (ok && val >= 0 && val <= MAXKEY) pkeycode = val; + else return false; + } + //and finally for the negative keycode. + else if (*it == "-key") { + ++it; + if (it == words.end()) return false; + val = (*it).toInt(&ok); + if (ok && val >= 0 && val <= MAXKEY) nkeycode = val; + else return false; + } + //the rest of the options are keywords without integers + else if (*it == "gradient") { + if (!gradient) takeTimer( this ); + gradient = true; + } + else if (*it == "throttle+") { + throttle = 1; + } + else if (*it == "throttle-") { + throttle = -1; + } + else if (*it == "mouse+v") { + mode = mousepv; + } + else if (*it == "mouse-v") { + mode = mousenv; + } + else if (*it == "mouse+h") { + mode = mouseph; + } + else if (*it == "mouse-h") { + mode = mousenh; + } + //we ignore unrecognized words to be friendly and allow for additions to + //the format in later versions. Note, this means that typos will not get + //the desired effect OR produce an error message. } - //assume that xZone, dZone, or maxSpeed has changed, for simplicity. - //do a few floating point calculations. - adjustGradient(); - - //if we parsed through all of the words, yay! All done. - return true; -} - -void Axis::timerCalled() { - timerTick(++tick); + //assume that xZone, dZone, or maxSpeed has changed, for simplicity. + //do a few floating point calculations. + adjustGradient(); + + //if we parsed through all of the words, yay! All done. + return true; } void Axis::write( QTextStream* stream ) { - *stream << "\t" << getName() << ": "; - if (gradient) *stream << "gradient, "; - if (throttle > 0) *stream << "throttle+, "; - else if (throttle < 0) *stream << "throttle-, "; - if (dZone != DZONE) *stream << "dZone " << dZone << ", "; - if (xZone != XZONE) *stream << "xZone " << xZone << ", "; - if (mode == keybd) { - *stream << "+key " << pkeycode << ", " - << "-key " << nkeycode << "\n"; - } - else { - if (gradient) *stream << "maxSpeed " << maxSpeed << ", "; - *stream << "mouse"; - if (mode == mousepv) - *stream << "+v\n"; - else if (mode == mousenv) - *stream << "-v\n"; - else if (mode == mouseph) - *stream << "+h\n"; - else if (mode == mousenh) - *stream << "-h\n"; - } - + *stream << "\t" << getName() << ": "; + if (gradient) *stream << "gradient, "; + if (throttle > 0) *stream << "throttle+, "; + else if (throttle < 0) *stream << "throttle-, "; + if (dZone != DZONE) *stream << "dZone " << dZone << ", "; + if (xZone != XZONE) *stream << "xZone " << xZone << ", "; + if (mode == keybd) { + *stream << "+key " << pkeycode << ", " + << "-key " << nkeycode << "\n"; + } + else { + if (gradient) *stream << "maxSpeed " << maxSpeed << ", "; + *stream << "mouse"; + if (mode == mousepv) + *stream << "+v\n"; + else if (mode == mousenv) + *stream << "-v\n"; + else if (mode == mouseph) + *stream << "+h\n"; + else if (mode == mousenh) + *stream << "-h\n"; + } + } void Axis::release() { - //if we're pressing a key, let it go. - if (isDown) { - move(false); - isDown = false; - } + //if we're pressing a key, let it go. + if (isDown) { + move(false); + isDown = false; + } } void Axis::jsevent( int value ) { - //adjust real value to throttle value - if (throttle == 0) - state = value; - else if (throttle == -1) - state = (value + JOYMIN) / 2; - else - state = (value + JOYMAX) / 2; - - //set isOn, deal with state changing. - //if was on but now should be off: - if (isOn && abs(state) <= dZone) { - isOn = false; - if (gradient) { - release(); - timer->stop(); - tick = 0; - } - } - //if was off but now should be on: - else if (!isOn && abs(state) >= dZone) { - isOn = true; - if (gradient) { - duration = (abs(state) * FREQ) / JOYMAX; - connect(timer, SIGNAL(timeout()), this, SLOT(timerCalled())); - timer->start(MSEC); - } - } - //otherwise, state doesn't change! Don't touch it. - else return; - - //gradient will trigger movement on its own via timer(). - //non-gradient needs to be told to move. - if (!gradient) { - move(isOn); - } + //adjust real value to throttle value + if (throttle == 0) + state = value; + else if (throttle == -1) + state = (value + JOYMIN) / 2; + else + state = (value + JOYMAX) / 2; + + //set isOn, deal with state changing. + //if was on but now should be off: + if (isOn && abs(state) <= dZone) { + isOn = false; + if (gradient) release(); + } + //if was off but now should be on: + else if (!isOn && abs(state) >= dZone) { + isOn = true; + if (gradient) duration = (abs(state) * FREQ) / JOYMAX; + } + //otherwise, state doesn't change! Don't touch it. + else return; + + //gradient will trigger movement on its own via timer(). + //non-gradient needs to be told to move. + if (!gradient) { + move(isOn); + } } void Axis::toDefault() { - release(); - gradient = false; - throttle = 0; - maxSpeed = 100; - dZone = DZONE; - tick = 0; - xZone = XZONE; - mode = keybd; - pkeycode = 0; - nkeycode = 0; - downkey = 0; - state = 0; - adjustGradient(); + release(); + + if (gradient) tossTimer( this ); + gradient = false; + throttle = 0; + maxSpeed = 100; + dZone = DZONE; + xZone = XZONE; + mode = keybd; + pkeycode = 0; + nkeycode = 0; + downkey = 0; + state = 0; + adjustGradient(); } bool Axis::isDefault() { @@ -217,119 +203,119 @@ bool Axis::isDefault() { } bool Axis::inDeadZone( int val ) { - int value; - if (throttle == 0) - value = val; - else if (throttle == -1) - value = (val + JOYMIN) / 2; - else - value = (val + JOYMAX) / 2; - return (abs(value) < dZone); + int value; + if (throttle == 0) + value = val; + else if (throttle == -1) + value = (val + JOYMIN) / 2; + else + value = (val + JOYMAX) / 2; + return (abs(value) < dZone); } QString Axis::status() { - QString result = getName() + " : ["; - if (mode == keybd) { - if (throttle == 0) - result += "KEYBOARD"; - else result += "THROTTLE"; - } - else result += "MOUSE"; - return result + "]"; + QString result = getName() + " : ["; + if (mode == keybd) { + if (throttle == 0) + result += "KEYBOARD"; + else result += "THROTTLE"; + } + else result += "MOUSE"; + return result + "]"; } void Axis::setKey(bool positive, int value) { - if (positive) - pkeycode = value; - else - nkeycode = value; + if (positive) + pkeycode = value; + else + nkeycode = value; } -void Axis::timerTick( int tick ) { - if (isOn) { - if (mode == keybd) { - if (tick % FREQ == 0) { - if (duration == FREQ) { - if (!isDown) move(true); - duration = (abs(state) * FREQ) / JOYMAX; - return; - } - move(true); - } - if (tick % FREQ == duration) { - move(false); - duration = (abs(state) * FREQ) / JOYMAX; - } - } - else { - move(true); - } - } +void Axis::timer( int tick ) { + if (isOn) { + if (mode == keybd) { + if (tick % FREQ == 0) { + if (duration == FREQ) { + if (!isDown) move(true); + duration = (abs(state) * FREQ) / JOYMAX; + return; + } + move(true); + } + if (tick % FREQ == duration) { + move(false); + duration = (abs(state) * FREQ) / JOYMAX; + } + } + else { + move(true); + } + } } void Axis::adjustGradient() { - //create a nice quadratic curve fitting it to the points - //(dZone,0) and (xZone,MaxSpeed) - a = (double) (maxSpeed) / sqr(xZone - dZone); - b = -2 * a * dZone; - c = a * sqr(dZone); - //actual equation for curve is: y = ax^2 + b - //where x is the state of the axis and y is the distance the mouse should move. + //create a nice quadratic curve fitting it to the points + //(dZone,0) and (xZone,MaxSpeed) + a = (double) (maxSpeed) / sqr(xZone - dZone); + b = -2 * a * dZone; + c = a * sqr(dZone); + //actual equation for curve is: y = ax^2 + b + //where x is the state of the axis and y is the distance the mouse should move. } void Axis::move( bool press ) { - xevent e; - if (mode == keybd) { - //prevent KeyPress-KeyPress and KeyRelease-KeyRelease pairs. - //this would only happen in odd circumstances involving the setup - //dialog being open and blocking events from happening. - if (isDown == press) return; - isDown = press; - if (press) { - e.type = KPRESS; - downkey = (state > 0)?pkeycode:nkeycode; - } - else { - e.type = KREL; - } - e.value1 = downkey; - e.value2 = 0; - } - //if using the mouse - else if (press) { - int dist; - if (gradient) { - //calculate our mouse speed curve based on calculations made in - //adjustGradient() - int absState = abs(state); - if (absState >= xZone) dist = maxSpeed; - else if (absState <= dZone) dist = 0; - else dist = (int) (a*sqr(absState) + b*absState + c); - } - //if not gradient, always go full speed. - else dist = maxSpeed; + xevent e; + if (mode == keybd) { + //prevent KeyPress-KeyPress and KeyRelease-KeyRelease pairs. + //this would only happen in odd circumstances involving the setup + //dialog being open and blocking events from happening. + if (isDown == press) return; + isDown = press; + if (press) { + e.type = KPRESS; + downkey = (state > 0)?pkeycode:nkeycode; + } + else { + e.type = KREL; + } + e.value1 = downkey; + e.value2 = 0; + } + //if using the mouse + else if (press){ + int dist; + if (gradient) { + //calculate our mouse speed curve based on calculations made in + //adjustGradient() + int absState = abs(state); + if (absState >= xZone) dist = maxSpeed; + else if (absState <= dZone) dist = 0; + else dist = (int) (a*sqr(absState) + b*absState + c); + } + //if not gradient, always go full speed. + else dist = maxSpeed; - //if we're on the negative side of the axis, must compensate for - //squaring and make distance negative. - if (state < 0) dist = -dist; - e.type = WARP; - if (mode == mousepv) { - e.value1 = 0; - e.value2 = dist; - } - else if (mode == mousenv) { - e.value1 = 0; - e.value2 = -dist; - } - else if (mode == mouseph) { - e.value1 = dist; - e.value2 = 0; - } - else if (mode == mousenh) { - e.value1 = -dist; - e.value2 = 0; - } - } - //actually create the event - sendevent(e); + //if we're on the negative side of the axis, must compensate for + //squaring and make distance negative. + if (state < 0) dist = -dist; + e.type = WARP; + if (mode == mousepv) { + e.value1 = 0; + e.value2 = dist; + } + else if (mode == mousenv) { + e.value1 = 0; + e.value2 = -dist; + } + else if (mode == mouseph) { + e.value1 = dist; + e.value2 = 0; + } + else if (mode == mousenh) { + e.value1 = -dist; + e.value2 = 0; + } + } + //actually create the event + sendevent(e); } diff --git a/src/axis.h b/src/axis.h index 760f34e..ff47498 100644 --- a/src/axis.h +++ b/src/axis.h @@ -4,11 +4,11 @@ //abs() #include -#include -#include -#include -#include -#include "constant.h" +//parent of Axis +#include "component.h" + +//to request a periodic tap on the shoulder for gradient mode +#include "timer.h" //default and arbitrary values for dZone and xZone #define DZONE 3000 @@ -18,9 +18,8 @@ enum AxisMode {keybd, mousepv, mousenv, mouseph, mousenh}; //represents one joystick axis -class Axis : public QObject { - Q_OBJECT - //so AxisEdit can manipulate fields directly. +class Axis : public Component { + //so AxisEdit can manipulate fields directly. friend class AxisEdit; public: Axis( int i ); @@ -46,13 +45,12 @@ class Axis : public QObject { void setKey(bool positive, int value); //happens every MSEC milliseconds (constant.h) //uses tick to decide if key events should be generated - void timerTick( int tick ); + void timer( int tick ); //recalculates the gradient curve. This should be run every time //maxSpeed, xZone, or dZone are changed. void adjustGradient(); protected: - int tick; - //This axis is logically depressed (positive or negative) + //This axis is logically depressed (positive or negative) //if the axis is gradient, this is true even if it is not //currently generating a keypress at the instant. bool isOn; @@ -86,9 +84,6 @@ class Axis : public QObject { //note, the key is still clicked at the same pace no matter what, //this just decides how long it stays down each cycle. int duration; - QTimer *timer; - public slots: - void timerCalled(); }; #endif diff --git a/src/axis_edit.cpp b/src/axis_edit.cpp index 82dc625..6020081 100644 --- a/src/axis_edit.cpp +++ b/src/axis_edit.cpp @@ -1,150 +1,131 @@ #include "axis_edit.h" - AxisEdit::AxisEdit( Axis* ax ) - :QDialog() { - //build the dialog, display current axis settings :) - axis = ax; - setWindowTitle("Set " + axis->getName()); - setWindowIcon(QPixmap(ICON24)); + :QDialog() { + //build the dialog, display current axis settings :) + axis = ax; + setCaption("Set " + axis->getName()); + setIcon(QPixmap(ICON24)); + + //h, v, and v2 are all references to layouts. They are used to refer to + //various layouts as the dialog is built and are not pointing to the same + //thing throughout. This is just because I don't care about the layouts + //after I have placed the widgets within them and there's no reasno to + //keep track of them. + + QVBoxLayout* v = new QVBoxLayout(this, 5, 5); + + QHBoxLayout* h = new QHBoxLayout(); + QVBoxLayout* v2 = new QVBoxLayout(0,5,5); + CGradient = new QCheckBox("Gradient", this); + CGradient->setChecked(axis->gradient); + v2->addWidget(CGradient); + + CMode = new QComboBox(this); + CMode->insertItem("Keyboard",keybd); + CMode->insertItem("Mouse (Vert.)",mousepv); + CMode->insertItem("Mouse (Vert. Rev.)", mousenv); + CMode->insertItem("Mouse (Hor.)", mouseph); + CMode->insertItem("Mouse (Hor. Rev.)", mousenh); + CMode->setCurrentItem( axis->mode ); + connect(CMode, SIGNAL(activated(int)), this, SLOT( CModeChanged( int ))); + v2->addWidget(CMode); + h->addLayout(v2); + + MouseBox = new QFrame(this); + MouseBox->setFrameStyle( QFrame::Box | QFrame::Sunken ); + v2 = new QVBoxLayout(MouseBox,5,5); + v2->setAutoAdd(true); + new QLabel("Mouse Speed", MouseBox); + SSpeed = new QSpinBox(0,MAXMOUSESPEED,1,MouseBox); + SSpeed->setValue(axis->maxSpeed); + h->addWidget(MouseBox); + v->addLayout(h); - //h, v, and v2 are all references to layouts. They are used to refer to - //various layouts as the dialog is built and are not pointing to the same - //thing throughout. This is just because I don't care about the layouts - //after I have placed the widgets within them and there's no reasno to - //keep track of them. + Slider = new JoySlider(axis->dZone, axis->xZone, axis->state, this); + v->addWidget(Slider); - QVBoxLayout* v = new QVBoxLayout(this); - v->setMargin(5); - v->setSpacing(5); - - QHBoxLayout* h = new QHBoxLayout(); - QVBoxLayout* v2 = new QVBoxLayout(); - v2->setMargin(5); - v2->setSpacing(5); - CGradient = new QCheckBox("Gradient", this); - CGradient->setChecked(axis->gradient); - v2->addWidget(CGradient); - - CMode = new QComboBox(this); - CMode->insertItem((int)keybd, QString("Keyboard"), QVariant(NULL)); - CMode->insertItem((int) mousepv,QString("Mouse (Vert.)"),QVariant(NULL)); - CMode->insertItem((int) mousenv, QString("Mouse (Vert. Rev.)"), QVariant(NULL)); - CMode->insertItem((int) mouseph, "Mouse (Hor.)", QVariant(NULL)); - CMode->insertItem((int)mousenh, QString("Mouse (Hor. Rev.)"), NULL); - CMode->setCurrentIndex( axis->mode ); - connect(CMode, SIGNAL(activated(int)), this, SLOT( CModeChanged( int ))); - v2->addWidget(CMode); - h->addLayout(v2); - - MouseBox = new QFrame(this); - MouseBox->setFrameStyle( QFrame::Box | QFrame::Sunken ); - v2 = new QVBoxLayout(MouseBox); - v2->setSpacing(5); - v2->setMargin(5); - //v2->setAutoAdd(true); - QLabel *mouseLabel = new QLabel("Mouse Speed", MouseBox); - v2->addWidget(mouseLabel); - SSpeed = new QSpinBox(MouseBox); - SSpeed->setRange(0,MAXMOUSESPEED); - SSpeed->setSingleStep(1); - SSpeed->setValue(axis->maxSpeed); - v2->addWidget(SSpeed); - h->addWidget(MouseBox); - v->addLayout(h); - - Slider = new JoySlider(axis->dZone, axis->xZone, axis->state, this); - v->addWidget(Slider); - - KeyBox = new QFrame(this); - KeyBox->setFrameStyle( QFrame::Box | QFrame::Sunken ); - h = new QHBoxLayout(KeyBox); - h->setSpacing(5); - h->setMargin(5); - //h->setAutoAdd(true); - BNeg = new KeyButton(axis->getName(),axis->nkeycode,KeyBox); - - CThrottle = new QComboBox(KeyBox); - CThrottle->insertItem(0,"Neg. Throttle",QVariant(NULL)); - CThrottle->insertItem(1,"No Throttle",QVariant(NULL)); - CThrottle->insertItem(2,"Pos. Throttle",QVariant(NULL)); - CThrottle->setCurrentIndex(axis->throttle + 1); - connect( CThrottle, SIGNAL( activated( int )), this, SLOT( CThrottleChanged( int ))); - - BPos = new KeyButton(axis->getName(),axis->pkeycode,KeyBox); - h->addWidget(BNeg); - h->addWidget(CThrottle); - h->addWidget(BPos); - v->addWidget( KeyBox ); - - h = new QHBoxLayout(); - BOkay = new QPushButton("Okay", this); - connect(BOkay, SIGNAL( clicked() ), this, SLOT( accept())); - h->addWidget(BOkay); - BCancel = new QPushButton("Cancel", this); - connect(BCancel, SIGNAL( clicked() ), this, SLOT( reject())); - h->addWidget(BCancel); - v->addLayout(h); - - CModeChanged( axis->mode ); - CThrottleChanged( axis->throttle + 1 ); + KeyBox = new QFrame(this); + KeyBox->setFrameStyle( QFrame::Box | QFrame::Sunken ); + h = new QHBoxLayout(KeyBox, 5, 5); + h->setAutoAdd(true); + BNeg = new KeyButton(axis->getName(),axis->nkeycode,KeyBox); + + CThrottle = new QComboBox(KeyBox); + CThrottle->insertItem("Neg. Throttle",0); + CThrottle->insertItem("No Throttle",1); + CThrottle->insertItem("Pos. Throttle",2); + CThrottle->setCurrentItem(axis->throttle + 1); + connect( CThrottle, SIGNAL( activated( int )), this, SLOT( CThrottleChanged( int ))); + + BPos = new KeyButton(axis->getName(),axis->pkeycode,KeyBox); + v->addWidget( KeyBox ); + + h = new QHBoxLayout(); + BOkay = new QPushButton("Okay", this); + connect(BOkay, SIGNAL( clicked() ), this, SLOT( accept())); + h->addWidget(BOkay); + BCancel = new QPushButton("Cancel", this); + connect(BCancel, SIGNAL( clicked() ), this, SLOT( reject())); + h->addWidget(BCancel); + v->addLayout(h); + + CModeChanged( axis->mode ); + CThrottleChanged( axis->throttle + 1 ); } void AxisEdit::show() { - QDialog::show(); - setFixedSize(size()); + QDialog::show(); + setFixedSize(size()); } void AxisEdit::setState( int val ) { - Slider->setValue( val ); + Slider->setValue( val ); } void AxisEdit::CModeChanged( int index ) { - if (index == keybd) { - MouseBox->setEnabled(false); - KeyBox->setEnabled(true); - } - else { - MouseBox->setEnabled(true); - KeyBox->setEnabled(false); - } + if (index == keybd) { + MouseBox->setEnabled(false); + KeyBox->setEnabled(true); + } + else { + MouseBox->setEnabled(true); + KeyBox->setEnabled(false); + } } void AxisEdit::CThrottleChanged( int index ) { - switch (index) { - case 0: - BNeg->setEnabled(true); - BPos->setEnabled(false); - break; - case 1: - BNeg->setEnabled(true); - BPos->setEnabled(true); - break; - case 2: - BNeg->setEnabled(false); - BPos->setEnabled(true); - break; - } - Slider->setThrottle( index - 1 ); + switch (index) { + case 0: BNeg->setEnabled(true); + BPos->setEnabled(false); + break; + case 1: BNeg->setEnabled(true); + BPos->setEnabled(true); + break; + case 2: BNeg->setEnabled(false); + BPos->setEnabled(true); + break; + } + Slider->setThrottle( index - 1 ); } void AxisEdit::accept() { //if the gradient status has changed, either request a timer or turn it down. - /*if (axis->gradient) { - if (!CGradient->isChecked()) tossTimer(axis); - } - else { - if (CGradient->isChecked()) takeTimer(axis); - }*/ - axis->gradient = CGradient->isChecked(); - axis->maxSpeed = SSpeed->value(); - axis->throttle = CThrottle->currentIndex() - 1; - axis->dZone = Slider->dZone(); - axis->xZone = Slider->xZone(); - axis->mode = (AxisMode) CMode->currentIndex(); - axis->pkeycode = BPos->getValue(); - axis->nkeycode = BNeg->getValue(); - axis->adjustGradient(); + if (axis->gradient) { + if (!CGradient->isChecked()) tossTimer(axis); + } + else { + if (CGradient->isChecked()) takeTimer(axis); + } + axis->gradient = CGradient->isChecked(); + axis->maxSpeed = SSpeed->value(); + axis->throttle = CThrottle->currentItem() - 1; + axis->dZone = Slider->dZone(); + axis->xZone = Slider->xZone(); + axis->mode = (AxisMode) CMode->currentItem(); + axis->pkeycode = BPos->getValue(); + axis->nkeycode = BNeg->getValue(); + axis->adjustGradient(); - QDialog::accept(); + QDialog::accept(); } diff --git a/src/axis_edit.h b/src/axis_edit.h index 8a8b56c..78bb904 100644 --- a/src/axis_edit.h +++ b/src/axis_edit.h @@ -1,16 +1,22 @@ #ifndef AXIS_EDIT_H #define AXIS_EDIT_H -//to refer to the axis we're editing + //for building up the dialog we need -#include "axis.h" -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include + //for my home-brewed widgets #include "joyslider.h" #include "keycode.h" +//to refer to the axis we're editing +#include "axis.h" + class AxisEdit : public QDialog { Q_OBJECT public: diff --git a/src/axisw.cpp b/src/axisw.cpp index e85bd0c..ec4522c 100644 --- a/src/axisw.cpp +++ b/src/axisw.cpp @@ -1,38 +1,37 @@ #include "axisw.h" - AxisWidget::AxisWidget( Axis* a, QWidget* parent ) - : FlashButton( "",parent) { - axis = a; - ae = NULL; - update(); - on = false; + : FlashButton( "",parent) { + axis = a; + ae = NULL; + update(); + on = false; } void AxisWidget::jsevent( int val ) { - bool newOn = !axis->inDeadZone(val); - if (on != newOn) { - on = newOn; - flash(); - } - if (ae != NULL) ae->setState(val); + bool newOn = !axis->inDeadZone(val); + if (on != newOn) { + on = newOn; + flash(); + } + if (ae != NULL) ae->setState(val); } void AxisWidget::update() { - setText( axis->status()); + setText( axis->status()); } void AxisWidget::mouseReleaseEvent( QMouseEvent* e ) { - //create the edit dialog, - ae = new AxisEdit(axis); - //get its input - ae->exec(); - //now that it's done, destroy it! - delete ae; - //and remember that it's gone. - ae = NULL; - update(); - //release the button. Waiting to do this until the very end has the nice - //effect of keeping the button depressed while the dialog is shown. - FlashButton::mouseReleaseEvent( e ); + //create the edit dialog, + ae = new AxisEdit(axis); + //get its input + ae->exec(); + //now that it's done, destroy it! + delete ae; + //and remember that it's gone. + ae = NULL; + update(); + //release the button. Waiting to do this until the very end has the nice + //effect of keeping the button depressed while the dialog is shown. + FlashButton::mouseReleaseEvent( e ); } diff --git a/src/axisw.h b/src/axisw.h index 0c2b540..6b51812 100644 --- a/src/axisw.h +++ b/src/axisw.h @@ -1,14 +1,12 @@ #ifndef AXIS_WIDGET_H #define AXIS_WIDGET_H -#include //so we can interact with the axis this refers to #include "axis.h" -//for the FlashButton widget -#include "flash.h" - //so we can edit this axis when the user clicks the button #include "axis_edit.h" +//for the FlashButton widget +#include "flash.h" class AxisWidget : public FlashButton { public: diff --git a/src/button.cpp b/src/button.cpp index 1503400..acf1b3a 100644 --- a/src/button.cpp +++ b/src/button.cpp @@ -1,178 +1,156 @@ #include "button.h" -#include "event.h" + Button::Button( int i ) { - index = i; - isButtonPressed = false; - isDown = false; - rapidfire = false; - timer = new QTimer(this); - toDefault(); - tick = 0; + index = i; + isOn = false; + //to keep toDefault from calling tossTimer without first calling takeTimer + rapidfire = false; + toDefault(); } Button::~Button() { - release(); - //delete timer; + release(); } bool Button::read( QTextStream* stream ) { // at this point, toDefault() has just been called. - - //read in a line of text and break it into words - QString input = stream->readLine().toLower(); - QRegExp regex("[\\s,]+"); - QStringList words = input.split(regex); - - //used to assure correct conversion of QStrings -> ints - bool ok; - //used to receive converted ints from QStrings. - int val; - - //go through every word on the line describing this button. + + //read in a line of text and break it into words + QString input = stream->readLine().lower(); + QRegExp regex("[\\s,]+"); + QStringList words = QStringList::split(regex,input); + + //used to assure correct conversion of QStrings -> ints + bool ok; + //used to receive converted ints from QStrings. + int val; + + //go through every word on the line describing this button. for ( QStringList::Iterator it = words.begin(); it != words.end(); ++it ) { if (*it == "mouse") { - ++it; - if (it == words.end()) return false; - val = (*it).toInt(&ok); - if (ok && val >= 0 && val <= MAXKEY) { - useMouse = true; - mousecode = val; - } - else return false; - } - else if (*it == "key") { - ++it; - if (it == words.end()) return false; - val = (*it).toInt(&ok); - if (ok && val >= 0 && val <= MAXKEY) { - useMouse = false; - keycode = val; - } - else return false; - } - else if (*it == "rapidfire") { - rapidfire = true; - } - else if (*it == "sticky") { - sticky = true; - } + ++it; + if (it == words.end()) return false; + val = (*it).toInt(&ok); + if (ok && val >= 0 && val <= MAXKEY) { + useMouse = true; + mousecode = val; + } + else return false; + } + else if (*it == "key") { + ++it; + if (it == words.end()) return false; + val = (*it).toInt(&ok); + if (ok && val >= 0 && val <= MAXKEY) { + useMouse = false; + keycode = val; + } + else return false; + } + else if (*it == "rapidfire") { + if (rapidfire == false) takeTimer( this ); + rapidfire = true; + } + else if (*it == "sticky") { + sticky = true; + } } - return true; + return true; } void Button::write( QTextStream* stream ) { - *stream << "\t" << getName() << ": "; - if (rapidfire) *stream << "rapidfire, "; - if (sticky) *stream << "sticky, "; - *stream << (useMouse?"mouse ":"key ") << (useMouse?mousecode:keycode) << "\n"; + *stream << "\t" << getName() << ": "; + if (rapidfire) *stream << "rapidfire, "; + if (sticky) *stream << "sticky, "; + *stream << (useMouse?"mouse ":"key ") << (useMouse?mousecode:keycode) << "\n"; } void Button::release() { - if (isDown) { - click(false); - isDown = true; - } + if (isDown) { + click(false); + isDown = true; + } } void Button::jsevent( int value ) { - bool newval = (value == 1); - if (sticky) { - //the state of a sticky key only changes on button press, not button release. - if (value == 1) { - isButtonPressed = !isButtonPressed; - } - else return; - } - //if the received event indicates a change in state, - else if (newval != isButtonPressed) { - isButtonPressed = newval; //change state - if (isButtonPressed && rapidfire) { - tick = 0; - connect(timer, SIGNAL(timeout()), this, SLOT(timerCalled())); - timer->start(MSEC); - } - if (!isButtonPressed && rapidfire) { - timer->stop(); - if(isDown) { - click(false); - } - tick = 0; - } - } - //otherwise... we don't care. This shouldn't happen. - else return; - //if rapidfire is on, then timer() will do its job. Otherwise we must - //manually triger the key event. - if (!rapidfire) { - click(isButtonPressed); - } + bool newval = (value == 1); + if (sticky) { + //the state of a sticky key only changes on button press, not button release. + if (newval) isOn = !isOn; + else return; + } + //if the received event indicates a change in state, + else if (newval != isOn) { + isOn = newval; //change state + } + //otherwise... we don't care. This shouldn't happen. + else return; + //if rapidfire is on, then timer() will do its job. Otherwise we must + //manually triger the key event. + if (!rapidfire) click(isOn); } void Button::toDefault() { - rapidfire = false; - sticky = false; - useMouse = false; - keycode = 0; - mousecode = 0; - timer->stop(); + if (rapidfire == true) tossTimer( this ); + rapidfire = false; + sticky = false; + useMouse = false; + keycode = 0; + mousecode = 0; } bool Button::isDefault() { - return (rapidfire == false) && - (sticky == false) && - (useMouse == false) && - (keycode == 0) && - (mousecode == 0); + return (rapidfire == false) && + (sticky == false) && + (useMouse == false) && + (keycode == 0) && + (mousecode == 0); } QString Button::status() { - if (useMouse) { - return getName() + " : Mouse " + QString::number(mousecode); - } - else { - return getName() + " : " + QString(ktos(keycode)); - } + if (useMouse) { + return getName() + " : Mouse " + QString::number(mousecode); + } + else { + return getName() + " : " + QString(ktos(keycode)); + } } void Button::setKey( bool mouse, int value ) { - if (mouse) { - mousecode = value; - useMouse = true; - } - else { - keycode = value; - useMouse = false; - } + if (mouse) { + mousecode = value; + useMouse = true; + } + else { + keycode = value; + useMouse = false; + } } -void Button::timerTick( int tick ) { - if (isButtonPressed) { - //originally I just clicked true and then false right after, but this - //was not recognized by some programs. I need a delay in between. - if (tick % FREQ == 0) { - click(true); - } - if (tick % FREQ == FREQ / 2) { - click(false); - } - } +void Button::timer( int tick ) { + if (isOn) { + //originally I just clicked true and then false right after, but this + //was not recognized by some programs. I need a delay in between. + if (tick % FREQ == 0) { + click(true); + } + if (tick % FREQ == FREQ / 2) { + click(false); + } + } } void Button::click( bool press ) { - if (isDown == press) return; - isDown = press; - xevent click; - //determine which of the four possible events we're sending. - if (press) click.type = useMouse?BPRESS:KPRESS; - else click.type = useMouse?BREL:KREL; - //set up the event, - click.value1 = useMouse?mousecode:keycode; - click.value2 = 0; - //and send it. - sendevent( click ); -} - -void Button::timerCalled() { - timerTick(++tick); + if (isDown == press) return; + isDown = press; + xevent click; + //determine which of the four possible events we're sending. + if (press) click.type = useMouse?BPRESS:KPRESS; + else click.type = useMouse?BREL:KREL; + //set up the event, + click.value1 = useMouse?mousecode:keycode; + click.value2 = 0; + //and send it. + sendevent( click ); } diff --git a/src/button.h b/src/button.h index a0954be..ffffc61 100644 --- a/src/button.h +++ b/src/button.h @@ -1,18 +1,19 @@ #ifndef BUTTON_H #define BUTTON_H -#include -#include +//parent of Button +#include "component.h" +//to request a periodic tap on the shoulder for rapidfire +#include "timer.h" //for getting a key name in status() #include "keycode.h" //note that the Button class, unlike the axis class, does not need a release //function because it releases the key as soon as it is pressed. -class Button : public QObject { - Q_OBJECT - friend class ButtonEdit; +class Button : public Component { + friend class ButtonEdit; public: Button( int i ); ~Button(); @@ -35,26 +36,23 @@ class Button : public QObject { //set the key code for this axis. Used by quickset. void setKey(bool mouse, int value); //happens every MSEC (constant.h) milliseconds - void timerTick( int tick ); + void timer( int tick ); protected: //true iff this button is physically depressed. - bool isButtonPressed; + bool isOn; //the index of this button on the joystick int index; //actually sends a key press/release virtual void click( bool press ); //is a simulated key currently depressed? bool isDown; - int tick; + //button settings bool rapidfire; bool sticky; bool useMouse; int keycode; int mousecode; //like keycode, only mousebutton ;) - QTimer *timer; - public slots: - void timerCalled(); }; #endif diff --git a/src/button_edit.cpp b/src/button_edit.cpp index 43de502..51003d2 100644 --- a/src/button_edit.cpp +++ b/src/button_edit.cpp @@ -1,66 +1,60 @@ #include "button_edit.h" -#include -#include - ButtonEdit::ButtonEdit(Button* butt) - :QDialog(0) { - setModal(true); - //build the dialog! - button = butt; - setWindowTitle("Set " + button->getName()); - setWindowIcon(QPixmap(ICON24)); + :QDialog(0,0,true) { + //build the dialog! + button = butt; + setCaption("Set " + button->getName()); + setIcon(QPixmap(ICON24)); + + QVBoxLayout* v = new QVBoxLayout(this, 5, 5); - QVBoxLayout* v = new QVBoxLayout(this); - v->setMargin(5); - v->setSpacing(5); - - BKKey = new KeyButton( button->getName(), button->useMouse?button->mousecode:button->keycode, this, true, button->useMouse); - v->addWidget(BKKey); - - QHBoxLayout* h = new QHBoxLayout(); - CSticky = new QCheckBox("Sticky", this); - CSticky->setChecked(button->sticky); - h->addWidget(CSticky); - CRapid = new QCheckBox("Rapid Fire", this); - CRapid->setChecked(button->rapidfire); - h->addWidget(CRapid); - v->addLayout(h); - - h = new QHBoxLayout(); - BOkay = new QPushButton("Okay", this); - connect(BOkay, SIGNAL( clicked() ), this, SLOT( accept())); - h->addWidget(BOkay); - BCancel = new QPushButton("Cancel", this); - connect(BCancel, SIGNAL( clicked() ), this, SLOT( reject())); - h->addWidget(BCancel); - v->addLayout(h); + BKKey = new KeyButton( button->getName(), button->useMouse?button->mousecode:button->keycode, this, true, button->useMouse); + v->addWidget(BKKey); + + QHBoxLayout* h = new QHBoxLayout(); + CSticky = new QCheckBox("Sticky", this); + CSticky->setChecked(button->sticky); + h->addWidget(CSticky); + CRapid = new QCheckBox("Rapid Fire", this); + CRapid->setChecked(button->rapidfire); + h->addWidget(CRapid); + v->addLayout(h); + + h = new QHBoxLayout(); + BOkay = new QPushButton("Okay", this); + connect(BOkay, SIGNAL( clicked() ), this, SLOT( accept())); + h->addWidget(BOkay); + BCancel = new QPushButton("Cancel", this); + connect(BCancel, SIGNAL( clicked() ), this, SLOT( reject())); + h->addWidget(BCancel); + v->addLayout(h); } void ButtonEdit::show() { - QDialog::show(); - setFixedSize(size()); + QDialog::show(); + setFixedSize(size()); } void ButtonEdit::accept() { //if the rapidfire status has changed, either request a timer or turn it down. - /*if (button->rapidfire) { - if (!CRapid->isChecked()) tossTimer(button); - } - else { - if (CRapid->isChecked()) takeTimer(button); - }*/ - button->rapidfire = CRapid->isChecked(); - button->sticky = (CSticky->isChecked()); - //if the user chose a mouse button... - if (BKKey->choseMouse()) { - button->useMouse = true; - button->mousecode = BKKey->getValue(); - } - else { - button->useMouse = false; - button->keycode = BKKey->getValue(); - } + if (button->rapidfire) { + if (!CRapid->isChecked()) tossTimer(button); + } + else { + if (CRapid->isChecked()) takeTimer(button); + } + button->rapidfire = CRapid->isChecked(); + button->sticky = (CSticky->isChecked()); + //if the user chose a mouse button... + if (BKKey->choseMouse()) { + button->useMouse = true; + button->mousecode = BKKey->getValue(); + } + else { + button->useMouse = false; + button->keycode = BKKey->getValue(); + } - QDialog::accept(); + QDialog::accept(); } diff --git a/src/button_edit.h b/src/button_edit.h index 4248a0b..c746e38 100644 --- a/src/button_edit.h +++ b/src/button_edit.h @@ -1,13 +1,14 @@ #ifndef BUTTON_EDIT_H #define BUTTON_EDIT_H -#include -#include +//used to build the dialog: +#include +#include +#include +#include //we need to edit a Button #include "button.h" - - //to get a new key for the button. #include "keycode.h" diff --git a/src/buttonw.cpp b/src/buttonw.cpp index 0211b8c..9731766 100644 --- a/src/buttonw.cpp +++ b/src/buttonw.cpp @@ -1,30 +1,29 @@ #include "buttonw.h" - ButtonWidget::ButtonWidget( Button* b, QWidget* parent ) - : FlashButton( "", parent) { - button = b; - update(); - on = false; + : FlashButton( "", parent) { + button = b; + update(); + on = false; } void ButtonWidget::jsevent( int val ) { - bool newOn = (val == 1); - if (on != newOn) { - on = newOn; - flash(); - } + bool newOn = (val == 1); + if (on != newOn) { + on = newOn; + flash(); + } } void ButtonWidget::update() { - setText( button->status()); + setText( button->status()); } void ButtonWidget::mouseReleaseEvent( QMouseEvent* e ) { - ButtonEdit* be = new ButtonEdit(button); - be->exec(); - delete be; - - update(); - FlashButton::mouseReleaseEvent( e ); + ButtonEdit* be = new ButtonEdit(button); + be->exec(); + delete be; + + update(); + FlashButton::mouseReleaseEvent( e ); } diff --git a/src/buttonw.h b/src/buttonw.h index 856df81..c601a77 100644 --- a/src/buttonw.h +++ b/src/buttonw.h @@ -7,11 +7,6 @@ #include "button_edit.h" //this IS a FlashButton #include "flash.h" -#ifdef Bool -#undef Bool -#endif - -#include class ButtonWidget : public FlashButton { public: diff --git a/src/component.h b/src/component.h new file mode 100644 index 0000000..4b7c219 --- /dev/null +++ b/src/component.h @@ -0,0 +1,36 @@ +#ifndef COMPONENT_H +#define COMPONENT_H + + +//for parsing data from a file +#include +#include +#include + +//parent of Component +#include + +#include "event.h" +#include "constant.h" + + +//just a general blanket class to cover Button and Axis +//it is completely worthless in itself. +class Component : public QObject { + public: + virtual bool read( QTextStream* ) {return true; }; + virtual void write( QTextStream* ) {}; + virtual void release() {}; + virtual void jsevent( int ) {}; + virtual void toDefault() {}; + virtual bool isDefault() { return true; }; + virtual QString getName() { return ""; }; + virtual QString status() { return ""; }; + virtual void timer( int ) {}; + protected: + bool isOn; + bool isDown; + int index; +}; + +#endif diff --git a/src/constant.h b/src/constant.h index 93ecc3a..0d13b98 100644 --- a/src/constant.h +++ b/src/constant.h @@ -24,6 +24,4 @@ #define NAME "QJoyPad 3.4" -#define MOUSE_OFFSET 400 - #endif diff --git a/src/device.h b/src/device.h index b7158a6..902488b 100644 --- a/src/device.h +++ b/src/device.h @@ -1,16 +1,17 @@ #ifndef JOY_DEVICE_H #define JOY_DEVICE_H +#include #include "joypad.h" //the purpose of this file is to make device information available to what //needs it. //a collection of joysticks currently available on this computer -extern QHash available; +extern QIntDict available; //a collection of joypad objects representing all the available joysticks //as well as the ones defined in a layout buy not currently plugged in. -extern QHash joypads; +extern QIntDict joypads; #endif diff --git a/src/error.h b/src/error.h index df70408..e637f3c 100644 --- a/src/error.h +++ b/src/error.h @@ -7,7 +7,7 @@ static void error(QString type, QString message ) { QMessageBox::warning(0,NAME" - " + type, - message, QMessageBox::Ok, Qt::NoButton); + message, QMessageBox::Ok, QMessageBox::NoButton); } #endif diff --git a/src/event.cpp b/src/event.cpp index 6191807..633a928 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -5,17 +5,17 @@ Display* display; //actually creates an XWindows event :) void sendevent( xevent e ) { - if (e.value1 == 0 && e.value2 == 0) return; - if (e.type == WARP) { - XTestFakeRelativeMotionEvent(display, e.value1, e.value2, 0); - } - else { - if (e.type == KREL || e.type == KPRESS) { - XTestFakeKeyEvent(display, e.value1, (e.type == KPRESS), 0); - } - else if (e.type == BREL || e.type == BPRESS) { - XTestFakeButtonEvent(display, e.value1, (e.type == BPRESS), 0); - } - } - XFlush(display); + if (e.value1 == 0 && e.value2 == 0) return; + if (e.type == WARP) { + XTestFakeRelativeMotionEvent(display, e.value1, e.value2, 0); + } + else { + if (e.type == KREL || e.type == KPRESS) { + XTestFakeKeyEvent(display, e.value1, (e.type == KPRESS), 0); + } + else if (e.type == BREL | e.type == BPRESS) { + XTestFakeButtonEvent(display, e.value1, (e.type == BPRESS), 0); + } + } + XFlush(display); } diff --git a/src/flash.cpp b/src/flash.cpp index 58eccbe..7bf57d7 100644 --- a/src/flash.cpp +++ b/src/flash.cpp @@ -1,99 +1,97 @@ #include "flash.h" -//Added by qt3to4: //Modified here (and in .h) to not have default arguments for 2 and 3. //This caused an error with a development version of g++ on a Mandrake system //in Sweden. FlashButton::FlashButton( QString text, QWidget* parent, QString name ) - :QPushButton( text, parent ) + :QPushButton( text, parent, name ) { - this->setObjectName(name); - //record the base palette for posterity. - Normal = palette(); + //record the base palette for posterity. + Normal = palette(); - //define the palette the button will have when it flashes. - QPalette cg = this->palette(); - cg.setCurrentColorGroup(QPalette::Inactive); - cg.setColor(QPalette::Button, HIGHLIGHT); - cg.setColor(QPalette::Light, HIGHLIGHT.light(150)); - cg.setColor(QPalette::Midlight, HIGHLIGHT.light(125)); - cg.setColor(QPalette::Dark, HIGHLIGHT.dark(200)); - cg.setColor(QPalette::Mid, HIGHLIGHT.dark(150)); - Flash = cg; - isflash=false; + //define the palette the button will have when it flashes. + QColorGroup cg = this->palette().inactive(); + cg.setColor(QColorGroup::Button, HIGHLIGHT); + cg.setColor(QColorGroup::Light, HIGHLIGHT.light(150)); + cg.setColor(QColorGroup::Midlight, HIGHLIGHT.light(125)); + cg.setColor(QColorGroup::Dark, HIGHLIGHT.dark(200)); + cg.setColor(QColorGroup::Mid, HIGHLIGHT.dark(150)); + Flash = QPalette(cg,cg,cg); + isflash=false; - setAutoDefault( false ); - setFocusPolicy(Qt::NoFocus); - + setAutoDefault( false ); + setFocusPolicy(QWidget::NoFocus); } void FlashButton::flash() { - emit( flashed( !isflash ) ); - if (isflash) - { - setPalette( Normal ); - isflash = false; - } - else - { - setPalette( Flash ); - isflash = true; - } + emit( flashed( !isflash ) ); + if (isflash) + { + setPalette( Normal ); + isflash = false; + } + else + { + setPalette( Flash ); + isflash = true; + } } + + + + + + + FlashRadioArray::FlashRadioArray( int count, QString names[], bool horizontal, QWidget* parent) - :QWidget( parent ) + :QWidget( parent ) { - if (horizontal) { - LMain = new QHBoxLayout( this); - LMain->setMargin(5); - LMain->setSpacing(5); - } else { - LMain = new QVBoxLayout( this); - LMain->setMargin(5); - LMain->setSpacing(5); - } - - Buttons = new FlashButton*[count]; - for (int i = 0; i < count; i++) - { - Buttons[i] = new FlashButton( names[i], this, "" ); - //when any of the buttons is clicked, it calls the same function on this. - connect( Buttons[i], SIGNAL( clicked() ), this, SLOT( clicked() )); - LMain->addWidget(Buttons[i]); - } - - Count = count; - State = 0; - Buttons[0]->setDown( true ); + if (horizontal) + LMain = new QHBoxLayout( this, 5, 5 ); + else + LMain = new QVBoxLayout( this, 5, 5 ); + LMain->setAutoAdd( true ); + + Buttons = new FlashButton*[count]; + for (int i = 0; i < count; i++) + { + Buttons[i] = new FlashButton( names[i], this, "" ); + //when any of the buttons is clicked, it calls the same function on this. + connect( Buttons[i], SIGNAL( clicked() ), this, SLOT( clicked() )); + } + + Count = count; + State = 0; + Buttons[0]->setDown( true ); } int FlashRadioArray::getState() { - return State; + return State; } void FlashRadioArray::flash( int index ) { - Buttons[index]->flash(); + Buttons[index]->flash(); } void FlashRadioArray::clicked() { - //go through each button. If it wasn't the button that was just clicked, - //then make sure that it is up. If it WAS the button that was clicked, - //remember that index as the new state. - for (int i = 0; i < Count; i++) - { - if ( Buttons[i] != sender() ) - Buttons[i]->setDown( false ); - else - { - State = i; - Buttons[i]->setDown( true ); - } - } - emit changed( State ); + //go through each button. If it wasn't the button that was just clicked, + //then make sure that it is up. If it WAS the button that was clicked, + //remember that index as the new state. + for (int i = 0; i < Count; i++) + { + if ( Buttons[i] != sender() ) + Buttons[i]->setDown( false ); + else + { + State = i; + Buttons[i]->setDown( true ); + } + } + emit changed( State ); } diff --git a/src/flash.h b/src/flash.h index b37595d..da720ff 100644 --- a/src/flash.h +++ b/src/flash.h @@ -15,9 +15,8 @@ -#include -#include -#include +#include +#include //A QPushButton that can flash a color diff --git a/src/icon.cpp b/src/icon.cpp index e95b4b4..4d01ad6 100644 --- a/src/icon.cpp +++ b/src/icon.cpp @@ -1,33 +1,30 @@ #include "icon.h" +#include -FloatingIcon::FloatingIcon( const QPixmap &icon, QMenu *popup, QWidget *parent, const char *name) - : QDialog( parent ) { - this->setObjectName(name); - setWindowTitle(NAME); - QPalette palette; - palette.setBrush(backgroundRole(), QBrush(icon)); - setPalette(palette); - //setPaletteBackgroundPixmap(icon); - pop = popup; +FloatingIcon::FloatingIcon( const QPixmap &icon, QPopupMenu *popup, QWidget *parent, const char *name) + : QDialog( parent, name ) { + setCaption(NAME); + setPaletteBackgroundPixmap(icon); + pop = popup; - setFixedSize(64,64); + setFixedSize(64,64); } void FloatingIcon::mousePressEvent( QMouseEvent* e ) { - //if it was the right mouse button, - if (e->button() == Qt::RightButton) { - //bring up the popup menu. - pop->popup( e->globalPos() ); - e->accept(); - } - else { - //otherwise, treat it as a regular click. - emit clicked(); - } + //if it was the right mouse button, + if (e->button() == RightButton) { + //bring up the popup menu. + pop->popup( e->globalPos() ); + e->accept(); + } + else { + //otherwise, treat it as a regular click. + emit clicked(); + } } void FloatingIcon::closeEvent( QCloseEvent* e ) { - emit closed(); - e->accept(); + emit closed(); + e->accept(); } diff --git a/src/icon.h b/src/icon.h index fa5689d..96fdc45 100644 --- a/src/icon.h +++ b/src/icon.h @@ -1,25 +1,27 @@ #ifndef JOY_ICON_H #define JOY_ICON_H -#include -#include -#include -#include -#include +//for creating a floating icon in notray mode :) +#include +//the pixmap to load +#include #include "constant.h" +//A quirk in QT forbids me from simply including qpopupmenu.h +class QPopupMenu; + class FloatingIcon : public QDialog { Q_OBJECT public: - FloatingIcon( const QPixmap &icon, QMenu *popup = 0, QWidget *parent = 0, const char *name = 0); + FloatingIcon( const QPixmap &icon, QPopupMenu *popup = 0, QWidget *parent = 0, const char *name = 0); signals: void closed(); void clicked(); protected: void mousePressEvent( QMouseEvent* e ); void closeEvent( QCloseEvent* e ); - QMenu* pop; + QPopupMenu* pop; }; #endif diff --git a/src/joypad.cpp b/src/joypad.cpp index 7024d77..1adbf3e 100644 --- a/src/joypad.cpp +++ b/src/joypad.cpp @@ -1,270 +1,175 @@ -#include "unistd.h" -#include "joypad.h" -#include -#include -#include -#include -JoyPad::JoyPad( int i, int dev ) { - //remember the index, - index = i; - //load data from the joystick device, if available. - joydevFileHandle = NULL; - if(dev > 0) { - resetToDev(dev); - joydevFileHandle = new QSocketNotifier(dev, QSocketNotifier::Read, this); - connect(joydevFileHandle, SIGNAL(activated(int)), this, SLOT(handleJoyEvents(int))); - } - //there is no JoyPadWidget yet. - jpw = NULL; +#include "joypad.h" +JoyPad::JoyPad( int i, int dev ) { + //remember the index, + index = i; + + //load data from the joystick device, if available. + resetToDev(dev); + + //there is no JoyPadWidget yet. + jpw = NULL; } void JoyPad::resetToDev(int dev ) { - //remember the device file descriptor - joydev = dev; + //remember the device file descriptor + joydev = dev; - //read in the number of axes / buttons - axes = 0; - ioctl (joydev, JSIOCGAXES, &axes); - buttons = 0; - ioctl (joydev, JSIOCGBUTTONS, &buttons); - - //make sure that we have the axes we need. - //if one that we need doesn't yet exist, add it in. - //Note: if the current layout has a key assigned to an axis that did not - //have a real joystick axis mapped to it, and this function suddenly brings - //that axis into use, the key assignment will not be lost because the axis - //will already exist and no new axis will be created. - for (int i = 0; i < axes; i++) { - if (Axes[i] == 0) Axes.insert(i, new Axis( i )); - } - for (int i = 0; i < buttons; i++) { - if (Buttons[i] == 0) Buttons.insert(i, new Button( i )); - } - struct pollfd read_struct; - read_struct.fd = joydev; - read_struct.events = POLLIN; - char buf[10]; - while(poll(&read_struct, 1, 2)!=0) { - printf("reading junk data\n"); - read(joydev, buf, 10); - } - setupJoyDeviceListener(dev); -} - -void JoyPad::setupJoyDeviceListener(int dev) { - if(joydevFileHandle != NULL) { - delete joydevFileHandle; - } - joydevFileHandle = new QSocketNotifier(dev, QSocketNotifier::Read, this); - connect(joydevFileHandle, SIGNAL(activated(int)), this, SLOT(handleJoyEvents(int))); + //read in the number of axes / buttons + axes = 0; + ioctl (joydev, JSIOCGAXES, &axes); + buttons = 0; + ioctl (joydev, JSIOCGBUTTONS, &buttons); + + //make sure that we have the axes we need. + //if one that we need doesn't yet exist, add it in. + //Note: if the current layout has a key assigned to an axis that did not + //have a real joystick axis mapped to it, and this function suddenly brings + //that axis into use, the key assignment will not be lost because the axis + //will already exist and no new axis will be created. + for (int i = 0; i < axes; i++) { + if (Axes[i] == 0) Axes.insert(i, new Axis( i )); + } + for (int i = 0; i < buttons; i++) { + if (Buttons[i] == 0) Buttons.insert(i, new Button( i )); + } } void JoyPad::toDefault() { - //to reset the whole, reset all the parts. - do - { - QHashIterator it( Axes ); - while (it.hasNext()) - { - it.next(); - it.value()->toDefault(); - } - } while (0); - do - { - QHashIterator it( Buttons ); - while (it.hasNext()) - { - it.next(); - it.value()->toDefault(); - } - } while (0); + //to reset the whole, reset all the parts. + for ( QIntDictIterator it( Axes ); it.current(); ++it ) + it.current()->toDefault(); + for ( QIntDictIterator