straight copy of qt4 branch over to trunk, merge refused to work

git-svn-id: svn://svn.code.sf.net/p/qjoypad/code/trunk@95 c05e91a0-76c8-4ec0-b377-ef19ce7cc080
This commit is contained in:
John Toman
2009-08-03 01:01:45 +00:00
committed by virtuoussin13
parent c1ef3fa0b7
commit 345bb5748e
36 changed files with 1152 additions and 1506 deletions

View File

@ -4,11 +4,11 @@
//abs() //abs()
#include <stdlib.h> #include <stdlib.h>
//parent of Axis #include <QTimer>
#include "component.h" #include <QTextStream>
#include <QRegExp>
//to request a periodic tap on the shoulder for gradient mode #include <QStringList>
#include "timer.h" #include "constant.h"
//default and arbitrary values for dZone and xZone //default and arbitrary values for dZone and xZone
#define DZONE 3000 #define DZONE 3000
@ -18,8 +18,9 @@
enum AxisMode {keybd, mousepv, mousenv, mouseph, mousenh}; enum AxisMode {keybd, mousepv, mousenv, mouseph, mousenh};
//represents one joystick axis //represents one joystick axis
class Axis : public Component { class Axis : public QObject {
//so AxisEdit can manipulate fields directly. Q_OBJECT
//so AxisEdit can manipulate fields directly.
friend class AxisEdit; friend class AxisEdit;
public: public:
Axis( int i ); Axis( int i );
@ -45,12 +46,13 @@ class Axis : public Component {
void setKey(bool positive, int value); void setKey(bool positive, int value);
//happens every MSEC milliseconds (constant.h) //happens every MSEC milliseconds (constant.h)
//uses tick to decide if key events should be generated //uses tick to decide if key events should be generated
void timer( int tick ); void timerTick( int tick );
//recalculates the gradient curve. This should be run every time //recalculates the gradient curve. This should be run every time
//maxSpeed, xZone, or dZone are changed. //maxSpeed, xZone, or dZone are changed.
void adjustGradient(); void adjustGradient();
protected: protected:
//This axis is logically depressed (positive or negative) int tick;
//This axis is logically depressed (positive or negative)
//if the axis is gradient, this is true even if it is not //if the axis is gradient, this is true even if it is not
//currently generating a keypress at the instant. //currently generating a keypress at the instant.
bool isOn; bool isOn;
@ -84,6 +86,9 @@ class Axis : public Component {
//note, the key is still clicked at the same pace no matter what, //note, the key is still clicked at the same pace no matter what,
//this just decides how long it stays down each cycle. //this just decides how long it stays down each cycle.
int duration; int duration;
QTimer *timer;
public slots:
void timerCalled();
}; };
#endif #endif

View File

@ -1,131 +1,150 @@
#include "axis_edit.h" #include "axis_edit.h"
AxisEdit::AxisEdit( Axis* ax ) AxisEdit::AxisEdit( Axis* ax )
:QDialog() { :QDialog() {
//build the dialog, display current axis settings :) //build the dialog, display current axis settings :)
axis = ax; axis = ax;
setCaption("Set " + axis->getName()); setWindowTitle("Set " + axis->getName());
setIcon(QPixmap(ICON24)); setWindowIcon(QPixmap(ICON24));
//h, v, and v2 are all references to layouts. They are used to refer to //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 //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 //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 //after I have placed the widgets within them and there's no reasno to
//keep track of them. //keep track of them.
QVBoxLayout* v = new QVBoxLayout(this, 5, 5); QVBoxLayout* v = new QVBoxLayout(this);
v->setMargin(5);
v->setSpacing(5);
QHBoxLayout* h = new QHBoxLayout(); QHBoxLayout* h = new QHBoxLayout();
QVBoxLayout* v2 = new QVBoxLayout(0,5,5); QVBoxLayout* v2 = new QVBoxLayout();
CGradient = new QCheckBox("Gradient", this); v2->setMargin(5);
CGradient->setChecked(axis->gradient); v2->setSpacing(5);
v2->addWidget(CGradient); CGradient = new QCheckBox("Gradient", this);
CGradient->setChecked(axis->gradient);
v2->addWidget(CGradient);
CMode = new QComboBox(this); CMode = new QComboBox(this);
CMode->insertItem("Keyboard",keybd); CMode->insertItem((int)keybd, QString("Keyboard"), QVariant(NULL));
CMode->insertItem("Mouse (Vert.)",mousepv); CMode->insertItem((int) mousepv,QString("Mouse (Vert.)"),QVariant(NULL));
CMode->insertItem("Mouse (Vert. Rev.)", mousenv); CMode->insertItem((int) mousenv, QString("Mouse (Vert. Rev.)"), QVariant(NULL));
CMode->insertItem("Mouse (Hor.)", mouseph); CMode->insertItem((int) mouseph, "Mouse (Hor.)", QVariant(NULL));
CMode->insertItem("Mouse (Hor. Rev.)", mousenh); CMode->insertItem((int)mousenh, QString("Mouse (Hor. Rev.)"), NULL);
CMode->setCurrentItem( axis->mode ); CMode->setCurrentIndex( axis->mode );
connect(CMode, SIGNAL(activated(int)), this, SLOT( CModeChanged( int ))); connect(CMode, SIGNAL(activated(int)), this, SLOT( CModeChanged( int )));
v2->addWidget(CMode); v2->addWidget(CMode);
h->addLayout(v2); h->addLayout(v2);
MouseBox = new QFrame(this); MouseBox = new QFrame(this);
MouseBox->setFrameStyle( QFrame::Box | QFrame::Sunken ); MouseBox->setFrameStyle( QFrame::Box | QFrame::Sunken );
v2 = new QVBoxLayout(MouseBox,5,5); v2 = new QVBoxLayout(MouseBox);
v2->setAutoAdd(true); v2->setSpacing(5);
new QLabel("Mouse Speed", MouseBox); v2->setMargin(5);
SSpeed = new QSpinBox(0,MAXMOUSESPEED,1,MouseBox); //v2->setAutoAdd(true);
SSpeed->setValue(axis->maxSpeed); QLabel *mouseLabel = new QLabel("Mouse Speed", MouseBox);
h->addWidget(MouseBox); v2->addWidget(mouseLabel);
v->addLayout(h); 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); Slider = new JoySlider(axis->dZone, axis->xZone, axis->state, this);
v->addWidget(Slider); v->addWidget(Slider);
KeyBox = new QFrame(this); KeyBox = new QFrame(this);
KeyBox->setFrameStyle( QFrame::Box | QFrame::Sunken ); KeyBox->setFrameStyle( QFrame::Box | QFrame::Sunken );
h = new QHBoxLayout(KeyBox, 5, 5); h = new QHBoxLayout(KeyBox);
h->setAutoAdd(true); h->setSpacing(5);
BNeg = new KeyButton(axis->getName(),axis->nkeycode,KeyBox); h->setMargin(5);
//h->setAutoAdd(true);
BNeg = new KeyButton(axis->getName(),axis->nkeycode,KeyBox);
CThrottle = new QComboBox(KeyBox); CThrottle = new QComboBox(KeyBox);
CThrottle->insertItem("Neg. Throttle",0); CThrottle->insertItem(0,"Neg. Throttle",QVariant(NULL));
CThrottle->insertItem("No Throttle",1); CThrottle->insertItem(1,"No Throttle",QVariant(NULL));
CThrottle->insertItem("Pos. Throttle",2); CThrottle->insertItem(2,"Pos. Throttle",QVariant(NULL));
CThrottle->setCurrentItem(axis->throttle + 1); CThrottle->setCurrentIndex(axis->throttle + 1);
connect( CThrottle, SIGNAL( activated( int )), this, SLOT( CThrottleChanged( int ))); connect( CThrottle, SIGNAL( activated( int )), this, SLOT( CThrottleChanged( int )));
BPos = new KeyButton(axis->getName(),axis->pkeycode,KeyBox); BPos = new KeyButton(axis->getName(),axis->pkeycode,KeyBox);
v->addWidget( KeyBox ); h->addWidget(BNeg);
h->addWidget(CThrottle);
h->addWidget(BPos);
v->addWidget( KeyBox );
h = new QHBoxLayout(); h = new QHBoxLayout();
BOkay = new QPushButton("Okay", this); BOkay = new QPushButton("Okay", this);
connect(BOkay, SIGNAL( clicked() ), this, SLOT( accept())); connect(BOkay, SIGNAL( clicked() ), this, SLOT( accept()));
h->addWidget(BOkay); h->addWidget(BOkay);
BCancel = new QPushButton("Cancel", this); BCancel = new QPushButton("Cancel", this);
connect(BCancel, SIGNAL( clicked() ), this, SLOT( reject())); connect(BCancel, SIGNAL( clicked() ), this, SLOT( reject()));
h->addWidget(BCancel); h->addWidget(BCancel);
v->addLayout(h); v->addLayout(h);
CModeChanged( axis->mode ); CModeChanged( axis->mode );
CThrottleChanged( axis->throttle + 1 ); CThrottleChanged( axis->throttle + 1 );
} }
void AxisEdit::show() { void AxisEdit::show() {
QDialog::show(); QDialog::show();
setFixedSize(size()); setFixedSize(size());
} }
void AxisEdit::setState( int val ) { void AxisEdit::setState( int val ) {
Slider->setValue( val ); Slider->setValue( val );
} }
void AxisEdit::CModeChanged( int index ) { void AxisEdit::CModeChanged( int index ) {
if (index == keybd) { if (index == keybd) {
MouseBox->setEnabled(false); MouseBox->setEnabled(false);
KeyBox->setEnabled(true); KeyBox->setEnabled(true);
} }
else { else {
MouseBox->setEnabled(true); MouseBox->setEnabled(true);
KeyBox->setEnabled(false); KeyBox->setEnabled(false);
} }
} }
void AxisEdit::CThrottleChanged( int index ) { void AxisEdit::CThrottleChanged( int index ) {
switch (index) { switch (index) {
case 0: BNeg->setEnabled(true); case 0:
BPos->setEnabled(false); BNeg->setEnabled(true);
break; BPos->setEnabled(false);
case 1: BNeg->setEnabled(true); break;
BPos->setEnabled(true); case 1:
break; BNeg->setEnabled(true);
case 2: BNeg->setEnabled(false); BPos->setEnabled(true);
BPos->setEnabled(true); break;
break; case 2:
} BNeg->setEnabled(false);
Slider->setThrottle( index - 1 ); BPos->setEnabled(true);
break;
}
Slider->setThrottle( index - 1 );
} }
void AxisEdit::accept() { void AxisEdit::accept() {
//if the gradient status has changed, either request a timer or turn it down. //if the gradient status has changed, either request a timer or turn it down.
if (axis->gradient) { /*if (axis->gradient) {
if (!CGradient->isChecked()) tossTimer(axis); if (!CGradient->isChecked()) tossTimer(axis);
} }
else { else {
if (CGradient->isChecked()) takeTimer(axis); if (CGradient->isChecked()) takeTimer(axis);
} }*/
axis->gradient = CGradient->isChecked(); axis->gradient = CGradient->isChecked();
axis->maxSpeed = SSpeed->value(); axis->maxSpeed = SSpeed->value();
axis->throttle = CThrottle->currentItem() - 1; axis->throttle = CThrottle->currentIndex() - 1;
axis->dZone = Slider->dZone(); axis->dZone = Slider->dZone();
axis->xZone = Slider->xZone(); axis->xZone = Slider->xZone();
axis->mode = (AxisMode) CMode->currentItem(); axis->mode = (AxisMode) CMode->currentIndex();
axis->pkeycode = BPos->getValue(); axis->pkeycode = BPos->getValue();
axis->nkeycode = BNeg->getValue(); axis->nkeycode = BNeg->getValue();
axis->adjustGradient(); axis->adjustGradient();
QDialog::accept(); QDialog::accept();
} }

View File

@ -1,22 +1,16 @@
#ifndef AXIS_EDIT_H #ifndef AXIS_EDIT_H
#define AXIS_EDIT_H #define AXIS_EDIT_H
//to refer to the axis we're editing
//for building up the dialog we need //for building up the dialog we need
#include <qdialog.h> #include "axis.h"
#include <qcheckbox.h> #include <QComboBox>
#include <qcombobox.h> #include <QSpinBox>
#include <qframe.h> #include <QCheckBox>
#include <qspinbox.h> #include <QLabel>
#include <qlayout.h>
#include <qlabel.h>
//for my home-brewed widgets //for my home-brewed widgets
#include "joyslider.h" #include "joyslider.h"
#include "keycode.h" #include "keycode.h"
//to refer to the axis we're editing
#include "axis.h"
class AxisEdit : public QDialog { class AxisEdit : public QDialog {
Q_OBJECT Q_OBJECT
public: public:

View File

@ -1,37 +1,38 @@
#include "axisw.h" #include "axisw.h"
AxisWidget::AxisWidget( Axis* a, QWidget* parent ) AxisWidget::AxisWidget( Axis* a, QWidget* parent )
: FlashButton( "",parent) { : FlashButton( "",parent) {
axis = a; axis = a;
ae = NULL; ae = NULL;
update(); update();
on = false; on = false;
} }
void AxisWidget::jsevent( int val ) { void AxisWidget::jsevent( int val ) {
bool newOn = !axis->inDeadZone(val); bool newOn = !axis->inDeadZone(val);
if (on != newOn) { if (on != newOn) {
on = newOn; on = newOn;
flash(); flash();
} }
if (ae != NULL) ae->setState(val); if (ae != NULL) ae->setState(val);
} }
void AxisWidget::update() { void AxisWidget::update() {
setText( axis->status()); setText( axis->status());
} }
void AxisWidget::mouseReleaseEvent( QMouseEvent* e ) { void AxisWidget::mouseReleaseEvent( QMouseEvent* e ) {
//create the edit dialog, //create the edit dialog,
ae = new AxisEdit(axis); ae = new AxisEdit(axis);
//get its input //get its input
ae->exec(); ae->exec();
//now that it's done, destroy it! //now that it's done, destroy it!
delete ae; delete ae;
//and remember that it's gone. //and remember that it's gone.
ae = NULL; ae = NULL;
update(); update();
//release the button. Waiting to do this until the very end has the nice //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. //effect of keeping the button depressed while the dialog is shown.
FlashButton::mouseReleaseEvent( e ); FlashButton::mouseReleaseEvent( e );
} }

View File

@ -1,13 +1,15 @@
#ifndef AXIS_WIDGET_H #ifndef AXIS_WIDGET_H
#define AXIS_WIDGET_H #define AXIS_WIDGET_H
#include <QMouseEvent>
//so we can interact with the axis this refers to //so we can interact with the axis this refers to
#include "axis.h" #include "axis.h"
//so we can edit this axis when the user clicks the button
#include "axis_edit.h"
//for the FlashButton widget //for the FlashButton widget
#include "flash.h" #include "flash.h"
//so we can edit this axis when the user clicks the button
#include "axis_edit.h"
class AxisWidget : public FlashButton { class AxisWidget : public FlashButton {
public: public:
AxisWidget( Axis* a, QWidget* parent ); AxisWidget( Axis* a, QWidget* parent );

View File

@ -1,156 +1,178 @@
#include "button.h" #include "button.h"
#include "event.h"
Button::Button( int i ) { Button::Button( int i ) {
index = i; index = i;
isOn = false; isButtonPressed = false;
//to keep toDefault from calling tossTimer without first calling takeTimer isDown = false;
rapidfire = false; rapidfire = false;
toDefault(); timer = new QTimer(this);
toDefault();
tick = 0;
} }
Button::~Button() { Button::~Button() {
release(); release();
//delete timer;
} }
bool Button::read( QTextStream* stream ) { bool Button::read( QTextStream* stream ) {
// at this point, toDefault() has just been called. // at this point, toDefault() has just been called.
//read in a line of text and break it into words //read in a line of text and break it into words
QString input = stream->readLine().lower(); QString input = stream->readLine().toLower();
QRegExp regex("[\\s,]+"); QRegExp regex("[\\s,]+");
QStringList words = QStringList::split(regex,input); QStringList words = input.split(regex);
//used to assure correct conversion of QStrings -> ints //used to assure correct conversion of QStrings -> ints
bool ok; bool ok;
//used to receive converted ints from QStrings. //used to receive converted ints from QStrings.
int val; int val;
//go through every word on the line describing this button. //go through every word on the line describing this button.
for ( QStringList::Iterator it = words.begin(); it != words.end(); ++it ) { for ( QStringList::Iterator it = words.begin(); it != words.end(); ++it ) {
if (*it == "mouse") { if (*it == "mouse") {
++it; ++it;
if (it == words.end()) return false; if (it == words.end()) return false;
val = (*it).toInt(&ok); val = (*it).toInt(&ok);
if (ok && val >= 0 && val <= MAXKEY) { if (ok && val >= 0 && val <= MAXKEY) {
useMouse = true; useMouse = true;
mousecode = val; mousecode = val;
} }
else return false; else return false;
} }
else if (*it == "key") { else if (*it == "key") {
++it; ++it;
if (it == words.end()) return false; if (it == words.end()) return false;
val = (*it).toInt(&ok); val = (*it).toInt(&ok);
if (ok && val >= 0 && val <= MAXKEY) { if (ok && val >= 0 && val <= MAXKEY) {
useMouse = false; useMouse = false;
keycode = val; keycode = val;
} }
else return false; else return false;
} }
else if (*it == "rapidfire") { else if (*it == "rapidfire") {
if (rapidfire == false) takeTimer( this ); rapidfire = true;
rapidfire = true; }
} else if (*it == "sticky") {
else if (*it == "sticky") { sticky = true;
sticky = true; }
}
} }
return true; return true;
} }
void Button::write( QTextStream* stream ) { void Button::write( QTextStream* stream ) {
*stream << "\t" << getName() << ": "; *stream << "\t" << getName() << ": ";
if (rapidfire) *stream << "rapidfire, "; if (rapidfire) *stream << "rapidfire, ";
if (sticky) *stream << "sticky, "; if (sticky) *stream << "sticky, ";
*stream << (useMouse?"mouse ":"key ") << (useMouse?mousecode:keycode) << "\n"; *stream << (useMouse?"mouse ":"key ") << (useMouse?mousecode:keycode) << "\n";
} }
void Button::release() { void Button::release() {
if (isDown) { if (isDown) {
click(false); click(false);
isDown = true; isDown = true;
} }
} }
void Button::jsevent( int value ) { void Button::jsevent( int value ) {
bool newval = (value == 1); bool newval = (value == 1);
if (sticky) { if (sticky) {
//the state of a sticky key only changes on button press, not button release. //the state of a sticky key only changes on button press, not button release.
if (newval) isOn = !isOn; if (value == 1) {
else return; isButtonPressed = !isButtonPressed;
} }
//if the received event indicates a change in state, else return;
else if (newval != isOn) { }
isOn = newval; //change state //if the received event indicates a change in state,
} else if (newval != isButtonPressed) {
//otherwise... we don't care. This shouldn't happen. isButtonPressed = newval; //change state
else return; if (isButtonPressed && rapidfire) {
//if rapidfire is on, then timer() will do its job. Otherwise we must tick = 0;
//manually triger the key event. connect(timer, SIGNAL(timeout()), this, SLOT(timerCalled()));
if (!rapidfire) click(isOn); 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);
}
} }
void Button::toDefault() { void Button::toDefault() {
if (rapidfire == true) tossTimer( this ); rapidfire = false;
rapidfire = false; sticky = false;
sticky = false; useMouse = false;
useMouse = false; keycode = 0;
keycode = 0; mousecode = 0;
mousecode = 0; timer->stop();
} }
bool Button::isDefault() { bool Button::isDefault() {
return (rapidfire == false) && return (rapidfire == false) &&
(sticky == false) && (sticky == false) &&
(useMouse == false) && (useMouse == false) &&
(keycode == 0) && (keycode == 0) &&
(mousecode == 0); (mousecode == 0);
} }
QString Button::status() { QString Button::status() {
if (useMouse) { if (useMouse) {
return getName() + " : Mouse " + QString::number(mousecode); return getName() + " : Mouse " + QString::number(mousecode);
} }
else { else {
return getName() + " : " + QString(ktos(keycode)); return getName() + " : " + QString(ktos(keycode));
} }
} }
void Button::setKey( bool mouse, int value ) { void Button::setKey( bool mouse, int value ) {
if (mouse) { if (mouse) {
mousecode = value; mousecode = value;
useMouse = true; useMouse = true;
} }
else { else {
keycode = value; keycode = value;
useMouse = false; useMouse = false;
} }
} }
void Button::timer( int tick ) { void Button::timerTick( int tick ) {
if (isOn) { if (isButtonPressed) {
//originally I just clicked true and then false right after, but this //originally I just clicked true and then false right after, but this
//was not recognized by some programs. I need a delay in between. //was not recognized by some programs. I need a delay in between.
if (tick % FREQ == 0) { if (tick % FREQ == 0) {
click(true); click(true);
} }
if (tick % FREQ == FREQ / 2) { if (tick % FREQ == FREQ / 2) {
click(false); click(false);
} }
} }
} }
void Button::click( bool press ) { void Button::click( bool press ) {
if (isDown == press) return; if (isDown == press) return;
isDown = press; isDown = press;
xevent click; xevent click;
//determine which of the four possible events we're sending. //determine which of the four possible events we're sending.
if (press) click.type = useMouse?BPRESS:KPRESS; if (press) click.type = useMouse?BPRESS:KPRESS;
else click.type = useMouse?BREL:KREL; else click.type = useMouse?BREL:KREL;
//set up the event, //set up the event,
click.value1 = useMouse?mousecode:keycode; click.value1 = useMouse?mousecode:keycode;
click.value2 = 0; click.value2 = 0;
//and send it. //and send it.
sendevent( click ); sendevent( click );
}
void Button::timerCalled() {
timerTick(++tick);
} }

View File

@ -1,19 +1,18 @@
#ifndef BUTTON_H #ifndef BUTTON_H
#define BUTTON_H #define BUTTON_H
//parent of Button #include <QTimer>
#include "component.h" #include <QTextStream>
//to request a periodic tap on the shoulder for rapidfire
#include "timer.h"
//for getting a key name in status() //for getting a key name in status()
#include "keycode.h" #include "keycode.h"
//note that the Button class, unlike the axis class, does not need a release //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. //function because it releases the key as soon as it is pressed.
class Button : public Component { class Button : public QObject {
friend class ButtonEdit; Q_OBJECT
friend class ButtonEdit;
public: public:
Button( int i ); Button( int i );
~Button(); ~Button();
@ -36,23 +35,26 @@ class Button : public Component {
//set the key code for this axis. Used by quickset. //set the key code for this axis. Used by quickset.
void setKey(bool mouse, int value); void setKey(bool mouse, int value);
//happens every MSEC (constant.h) milliseconds //happens every MSEC (constant.h) milliseconds
void timer( int tick ); void timerTick( int tick );
protected: protected:
//true iff this button is physically depressed. //true iff this button is physically depressed.
bool isOn; bool isButtonPressed;
//the index of this button on the joystick //the index of this button on the joystick
int index; int index;
//actually sends a key press/release //actually sends a key press/release
virtual void click( bool press ); virtual void click( bool press );
//is a simulated key currently depressed? //is a simulated key currently depressed?
bool isDown; bool isDown;
int tick;
//button settings //button settings
bool rapidfire; bool rapidfire;
bool sticky; bool sticky;
bool useMouse; bool useMouse;
int keycode; int keycode;
int mousecode; //like keycode, only mousebutton ;) int mousecode; //like keycode, only mousebutton ;)
QTimer *timer;
public slots:
void timerCalled();
}; };
#endif #endif

View File

@ -1,60 +1,66 @@
#include "button_edit.h" #include "button_edit.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
ButtonEdit::ButtonEdit(Button* butt) ButtonEdit::ButtonEdit(Button* butt)
:QDialog(0,0,true) { :QDialog(0) {
//build the dialog! setModal(true);
button = butt; //build the dialog!
setCaption("Set " + button->getName()); button = butt;
setIcon(QPixmap(ICON24)); setWindowTitle("Set " + button->getName());
setWindowIcon(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); BKKey = new KeyButton( button->getName(), button->useMouse?button->mousecode:button->keycode, this, true, button->useMouse);
v->addWidget(BKKey); v->addWidget(BKKey);
QHBoxLayout* h = new QHBoxLayout(); QHBoxLayout* h = new QHBoxLayout();
CSticky = new QCheckBox("Sticky", this); CSticky = new QCheckBox("Sticky", this);
CSticky->setChecked(button->sticky); CSticky->setChecked(button->sticky);
h->addWidget(CSticky); h->addWidget(CSticky);
CRapid = new QCheckBox("Rapid Fire", this); CRapid = new QCheckBox("Rapid Fire", this);
CRapid->setChecked(button->rapidfire); CRapid->setChecked(button->rapidfire);
h->addWidget(CRapid); h->addWidget(CRapid);
v->addLayout(h); v->addLayout(h);
h = new QHBoxLayout(); h = new QHBoxLayout();
BOkay = new QPushButton("Okay", this); BOkay = new QPushButton("Okay", this);
connect(BOkay, SIGNAL( clicked() ), this, SLOT( accept())); connect(BOkay, SIGNAL( clicked() ), this, SLOT( accept()));
h->addWidget(BOkay); h->addWidget(BOkay);
BCancel = new QPushButton("Cancel", this); BCancel = new QPushButton("Cancel", this);
connect(BCancel, SIGNAL( clicked() ), this, SLOT( reject())); connect(BCancel, SIGNAL( clicked() ), this, SLOT( reject()));
h->addWidget(BCancel); h->addWidget(BCancel);
v->addLayout(h); v->addLayout(h);
} }
void ButtonEdit::show() { void ButtonEdit::show() {
QDialog::show(); QDialog::show();
setFixedSize(size()); setFixedSize(size());
} }
void ButtonEdit::accept() { void ButtonEdit::accept() {
//if the rapidfire status has changed, either request a timer or turn it down. //if the rapidfire status has changed, either request a timer or turn it down.
if (button->rapidfire) { /*if (button->rapidfire) {
if (!CRapid->isChecked()) tossTimer(button); if (!CRapid->isChecked()) tossTimer(button);
} }
else { else {
if (CRapid->isChecked()) takeTimer(button); if (CRapid->isChecked()) takeTimer(button);
} }*/
button->rapidfire = CRapid->isChecked(); button->rapidfire = CRapid->isChecked();
button->sticky = (CSticky->isChecked()); button->sticky = (CSticky->isChecked());
//if the user chose a mouse button... //if the user chose a mouse button...
if (BKKey->choseMouse()) { if (BKKey->choseMouse()) {
button->useMouse = true; button->useMouse = true;
button->mousecode = BKKey->getValue(); button->mousecode = BKKey->getValue();
} }
else { else {
button->useMouse = false; button->useMouse = false;
button->keycode = BKKey->getValue(); button->keycode = BKKey->getValue();
} }
QDialog::accept(); QDialog::accept();
} }

View File

@ -1,14 +1,13 @@
#ifndef BUTTON_EDIT_H #ifndef BUTTON_EDIT_H
#define BUTTON_EDIT_H #define BUTTON_EDIT_H
//used to build the dialog: #include <QPushButton>
#include <qdialog.h> #include <QCheckBox>
#include <qpushbutton.h>
#include <qcheckbox.h>
#include <qlayout.h>
//we need to edit a Button //we need to edit a Button
#include "button.h" #include "button.h"
//to get a new key for the button. //to get a new key for the button.
#include "keycode.h" #include "keycode.h"

View File

@ -1,29 +1,30 @@
#include "buttonw.h" #include "buttonw.h"
ButtonWidget::ButtonWidget( Button* b, QWidget* parent ) ButtonWidget::ButtonWidget( Button* b, QWidget* parent )
: FlashButton( "", parent) { : FlashButton( "", parent) {
button = b; button = b;
update(); update();
on = false; on = false;
} }
void ButtonWidget::jsevent( int val ) { void ButtonWidget::jsevent( int val ) {
bool newOn = (val == 1); bool newOn = (val == 1);
if (on != newOn) { if (on != newOn) {
on = newOn; on = newOn;
flash(); flash();
} }
} }
void ButtonWidget::update() { void ButtonWidget::update() {
setText( button->status()); setText( button->status());
} }
void ButtonWidget::mouseReleaseEvent( QMouseEvent* e ) { void ButtonWidget::mouseReleaseEvent( QMouseEvent* e ) {
ButtonEdit* be = new ButtonEdit(button); ButtonEdit* be = new ButtonEdit(button);
be->exec(); be->exec();
delete be; delete be;
update(); update();
FlashButton::mouseReleaseEvent( e ); FlashButton::mouseReleaseEvent( e );
} }

View File

@ -7,6 +7,11 @@
#include "button_edit.h" #include "button_edit.h"
//this IS a FlashButton //this IS a FlashButton
#include "flash.h" #include "flash.h"
#ifdef Bool
#undef Bool
#endif
#include <QMouseEvent>
class ButtonWidget : public FlashButton { class ButtonWidget : public FlashButton {
public: public:

View File

@ -1,36 +0,0 @@
#ifndef COMPONENT_H
#define COMPONENT_H
//for parsing data from a file
#include <qstringlist.h>
#include <qtextstream.h>
#include <qregexp.h>
//parent of Component
#include <qobject.h>
#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

View File

@ -24,4 +24,6 @@
#define NAME "QJoyPad 3.4" #define NAME "QJoyPad 3.4"
#define MOUSE_OFFSET 400
#endif #endif

View File

@ -1,17 +1,16 @@
#ifndef JOY_DEVICE_H #ifndef JOY_DEVICE_H
#define JOY_DEVICE_H #define JOY_DEVICE_H
#include <qintdict.h>
#include "joypad.h" #include "joypad.h"
//the purpose of this file is to make device information available to what //the purpose of this file is to make device information available to what
//needs it. //needs it.
//a collection of joysticks currently available on this computer //a collection of joysticks currently available on this computer
extern QIntDict<JoyPad> available; extern QHash<int, JoyPad*> available;
//a collection of joypad objects representing all the available joysticks //a collection of joypad objects representing all the available joysticks
//as well as the ones defined in a layout buy not currently plugged in. //as well as the ones defined in a layout buy not currently plugged in.
extern QIntDict<JoyPad> joypads; extern QHash<int, JoyPad*> joypads;
#endif #endif

View File

@ -7,7 +7,7 @@
static void error(QString type, QString message ) { static void error(QString type, QString message ) {
QMessageBox::warning(0,NAME" - " + type, QMessageBox::warning(0,NAME" - " + type,
message, QMessageBox::Ok, QMessageBox::NoButton); message, QMessageBox::Ok, Qt::NoButton);
} }
#endif #endif

View File

@ -5,17 +5,17 @@ Display* display;
//actually creates an XWindows event :) //actually creates an XWindows event :)
void sendevent( xevent e ) { void sendevent( xevent e ) {
if (e.value1 == 0 && e.value2 == 0) return; if (e.value1 == 0 && e.value2 == 0) return;
if (e.type == WARP) { if (e.type == WARP) {
XTestFakeRelativeMotionEvent(display, e.value1, e.value2, 0); XTestFakeRelativeMotionEvent(display, e.value1, e.value2, 0);
} }
else { else {
if (e.type == KREL || e.type == KPRESS) { if (e.type == KREL || e.type == KPRESS) {
XTestFakeKeyEvent(display, e.value1, (e.type == KPRESS), 0); XTestFakeKeyEvent(display, e.value1, (e.type == KPRESS), 0);
} }
else if (e.type == BREL | e.type == BPRESS) { else if (e.type == BREL || e.type == BPRESS) {
XTestFakeButtonEvent(display, e.value1, (e.type == BPRESS), 0); XTestFakeButtonEvent(display, e.value1, (e.type == BPRESS), 0);
} }
} }
XFlush(display); XFlush(display);
} }

View File

@ -1,97 +1,99 @@
#include "flash.h" #include "flash.h"
//Added by qt3to4:
//Modified here (and in .h) to not have default arguments for 2 and 3. //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 //This caused an error with a development version of g++ on a Mandrake system
//in Sweden. //in Sweden.
FlashButton::FlashButton( QString text, QWidget* parent, QString name ) FlashButton::FlashButton( QString text, QWidget* parent, QString name )
:QPushButton( text, parent, name ) :QPushButton( text, parent )
{ {
//record the base palette for posterity. this->setObjectName(name);
Normal = palette(); //record the base palette for posterity.
Normal = palette();
//define the palette the button will have when it flashes. //define the palette the button will have when it flashes.
QColorGroup cg = this->palette().inactive(); QPalette cg = this->palette();
cg.setColor(QColorGroup::Button, HIGHLIGHT); cg.setCurrentColorGroup(QPalette::Inactive);
cg.setColor(QColorGroup::Light, HIGHLIGHT.light(150)); cg.setColor(QPalette::Button, HIGHLIGHT);
cg.setColor(QColorGroup::Midlight, HIGHLIGHT.light(125)); cg.setColor(QPalette::Light, HIGHLIGHT.light(150));
cg.setColor(QColorGroup::Dark, HIGHLIGHT.dark(200)); cg.setColor(QPalette::Midlight, HIGHLIGHT.light(125));
cg.setColor(QColorGroup::Mid, HIGHLIGHT.dark(150)); cg.setColor(QPalette::Dark, HIGHLIGHT.dark(200));
Flash = QPalette(cg,cg,cg); cg.setColor(QPalette::Mid, HIGHLIGHT.dark(150));
isflash=false; Flash = cg;
isflash=false;
setAutoDefault( false );
setFocusPolicy(Qt::NoFocus);
setAutoDefault( false );
setFocusPolicy(QWidget::NoFocus);
} }
void FlashButton::flash() void FlashButton::flash()
{ {
emit( flashed( !isflash ) ); emit( flashed( !isflash ) );
if (isflash) if (isflash)
{ {
setPalette( Normal ); setPalette( Normal );
isflash = false; isflash = false;
} }
else else
{ {
setPalette( Flash ); setPalette( Flash );
isflash = true; isflash = true;
} }
} }
FlashRadioArray::FlashRadioArray( int count, QString names[], bool horizontal, QWidget* parent) FlashRadioArray::FlashRadioArray( int count, QString names[], bool horizontal, QWidget* parent)
:QWidget( parent ) :QWidget( parent )
{ {
if (horizontal) if (horizontal) {
LMain = new QHBoxLayout( this, 5, 5 ); LMain = new QHBoxLayout( this);
else LMain->setMargin(5);
LMain = new QVBoxLayout( this, 5, 5 ); LMain->setSpacing(5);
LMain->setAutoAdd( true ); } else {
LMain = new QVBoxLayout( this);
LMain->setMargin(5);
LMain->setSpacing(5);
}
Buttons = new FlashButton*[count]; Buttons = new FlashButton*[count];
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
Buttons[i] = new FlashButton( names[i], this, "" ); Buttons[i] = new FlashButton( names[i], this, "" );
//when any of the buttons is clicked, it calls the same function on this. //when any of the buttons is clicked, it calls the same function on this.
connect( Buttons[i], SIGNAL( clicked() ), this, SLOT( clicked() )); connect( Buttons[i], SIGNAL( clicked() ), this, SLOT( clicked() ));
} LMain->addWidget(Buttons[i]);
}
Count = count; Count = count;
State = 0; State = 0;
Buttons[0]->setDown( true ); Buttons[0]->setDown( true );
} }
int FlashRadioArray::getState() int FlashRadioArray::getState()
{ {
return State; return State;
} }
void FlashRadioArray::flash( int index ) void FlashRadioArray::flash( int index )
{ {
Buttons[index]->flash(); Buttons[index]->flash();
} }
void FlashRadioArray::clicked() void FlashRadioArray::clicked()
{ {
//go through each button. If it wasn't the button that was just 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, //then make sure that it is up. If it WAS the button that was clicked,
//remember that index as the new state. //remember that index as the new state.
for (int i = 0; i < Count; i++) for (int i = 0; i < Count; i++)
{ {
if ( Buttons[i] != sender() ) if ( Buttons[i] != sender() )
Buttons[i]->setDown( false ); Buttons[i]->setDown( false );
else else
{ {
State = i; State = i;
Buttons[i]->setDown( true ); Buttons[i]->setDown( true );
} }
} }
emit changed( State ); emit changed( State );
} }

View File

@ -15,8 +15,9 @@
#include <qpushbutton.h> #include <QPushButton>
#include <qlayout.h> #include <QPalette>
#include <QBoxLayout>
//A QPushButton that can flash a color //A QPushButton that can flash a color

View File

@ -1,30 +1,33 @@
#include "icon.h" #include "icon.h"
#include <qpopupmenu.h>
FloatingIcon::FloatingIcon( const QPixmap &icon, QPopupMenu *popup, QWidget *parent, const char *name) FloatingIcon::FloatingIcon( const QPixmap &icon, QMenu *popup, QWidget *parent, const char *name)
: QDialog( parent, name ) { : QDialog( parent ) {
setCaption(NAME); this->setObjectName(name);
setPaletteBackgroundPixmap(icon); setWindowTitle(NAME);
pop = popup; QPalette palette;
palette.setBrush(backgroundRole(), QBrush(icon));
setPalette(palette);
//setPaletteBackgroundPixmap(icon);
pop = popup;
setFixedSize(64,64); setFixedSize(64,64);
} }
void FloatingIcon::mousePressEvent( QMouseEvent* e ) { void FloatingIcon::mousePressEvent( QMouseEvent* e ) {
//if it was the right mouse button, //if it was the right mouse button,
if (e->button() == RightButton) { if (e->button() == Qt::RightButton) {
//bring up the popup menu. //bring up the popup menu.
pop->popup( e->globalPos() ); pop->popup( e->globalPos() );
e->accept(); e->accept();
} }
else { else {
//otherwise, treat it as a regular click. //otherwise, treat it as a regular click.
emit clicked(); emit clicked();
} }
} }
void FloatingIcon::closeEvent( QCloseEvent* e ) { void FloatingIcon::closeEvent( QCloseEvent* e ) {
emit closed(); emit closed();
e->accept(); e->accept();
} }

View File

@ -1,27 +1,25 @@
#ifndef JOY_ICON_H #ifndef JOY_ICON_H
#define JOY_ICON_H #define JOY_ICON_H
//for creating a floating icon in notray mode :) #include <QDialog>
#include <qdialog.h> #include <QMenu>
//the pixmap to load #include <QPixmap>
#include <qpixmap.h> #include <QMouseEvent>
#include <QCloseEvent>
#include "constant.h" #include "constant.h"
//A quirk in QT forbids me from simply including qpopupmenu.h
class QPopupMenu;
class FloatingIcon : public QDialog { class FloatingIcon : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
FloatingIcon( const QPixmap &icon, QPopupMenu *popup = 0, QWidget *parent = 0, const char *name = 0); FloatingIcon( const QPixmap &icon, QMenu *popup = 0, QWidget *parent = 0, const char *name = 0);
signals: signals:
void closed(); void closed();
void clicked(); void clicked();
protected: protected:
void mousePressEvent( QMouseEvent* e ); void mousePressEvent( QMouseEvent* e );
void closeEvent( QCloseEvent* e ); void closeEvent( QCloseEvent* e );
QPopupMenu* pop; QMenu* pop;
}; };
#endif #endif

View File

@ -1,93 +1,102 @@
#include "joypadw.h" #include "joypadw.h"
//Added by qt3to4:
JoyPadWidget::JoyPadWidget( JoyPad* jp, int i, QWidget* parent ) JoyPadWidget::JoyPadWidget( JoyPad* jp, int i, QWidget* parent )
: QWidget(parent) { : QWidget(parent) {
//initialize things, build the dialog //initialize things, build the dialog
joypad = jp; joypad = jp;
index = i; index = i;
LMain = new QGridLayout(this, (joypad->axes+1)/2 +(joypad->buttons+1)/2 + 2, 2, 5, 5); /* This was in below, no idea what it does :( ...
LMain->setAutoAdd( true ); * (joypad->axes+1)/2 +(joypad->buttons+1)/2 + 2
flashcount = 0; */
quickset = NULL; LMain = new QGridLayout(this);
LMain->setSpacing(5);
LMain->setMargin(5);
flashcount = 0;
int insertCounter = 0;
quickset = NULL;
Axes = new AxisWidget*[joypad->axes]; Axes = new AxisWidget*[joypad->axes];
for (int i = 0; i < joypad->axes; i++) { for (int i = 0; i < joypad->axes; i++) {
Axes[i] = new AxisWidget(joypad->Axes[i],this); Axes[i] = new AxisWidget(joypad->Axes[i],this);
connect( Axes[i], SIGNAL( flashed( bool ) ), this, SLOT( flash( bool ))); connect( Axes[i], SIGNAL( flashed( bool ) ), this, SLOT( flash( bool )));
} LMain->addWidget(Axes[i], insertCounter / 2, insertCounter %2);
if (joypad->axes % 2 == 1) { insertCounter++;
new QWidget(this); }
}
Buttons = new ButtonWidget*[joypad->buttons]; Buttons = new ButtonWidget*[joypad->buttons];
for (int i = 0; i < joypad->buttons; i++) { for (int i = 0; i < joypad->buttons; i++) {
Buttons[i] = new ButtonWidget(joypad->Buttons[i],this); Buttons[i] = new ButtonWidget(joypad->Buttons[i],this);
connect( Buttons[i], SIGNAL( flashed( bool ) ), this, SLOT( flash( bool ))); connect( Buttons[i], SIGNAL( flashed( bool ) ), this, SLOT( flash( bool )));
} LMain->addWidget(Buttons[i], insertCounter/2, insertCounter%2);
if (joypad->buttons % 2 == 1) { insertCounter++;
new QWidget(this); }
}
new QWidget(this);
new QWidget(this);
BClear = new QPushButton("Clear", this); if(insertCounter % 2 == 1) {
connect(BClear, SIGNAL(clicked()), this, SLOT(clear())); insertCounter++;
BAll = new QPushButton("Quick Set", this); }
connect(BAll, SIGNAL(clicked()), this, SLOT(setAll())); insertCounter+=2;
BClear = new QPushButton("Clear", this);
connect(BClear, SIGNAL(clicked()), this, SLOT(clear()));
LMain->addWidget(BClear, insertCounter / 2, insertCounter %2);
insertCounter++;
BAll = new QPushButton("Quick Set", this);
LMain->addWidget(BAll, insertCounter /2, insertCounter%2);
connect(BAll, SIGNAL(clicked()), this, SLOT(setAll()));
} }
JoyPadWidget::~JoyPadWidget() { JoyPadWidget::~JoyPadWidget() {
//so the joypad knows that we're done. //so the joypad knows that we're done.
joypad->releaseWidget(); joypad->releaseWidget();
} }
void JoyPadWidget::flash( bool on ) { void JoyPadWidget::flash( bool on ) {
//true iff this entire widget was considered "flashed" before //true iff this entire widget was considered "flashed" before
bool wasOn = (flashcount != 0); bool wasOn = (flashcount != 0);
//adjust the count based on this new flash //adjust the count based on this new flash
flashcount += (on?1:-1); flashcount += (on?1:-1);
//if we were on and should now be off, or visa versa, flash the whole widget //if we were on and should now be off, or visa versa, flash the whole widget
if (wasOn != (flashcount != 0)) if (wasOn != (flashcount != 0))
emit flashed(index); emit flashed(index);
} }
void JoyPadWidget::update() { void JoyPadWidget::update() {
for (int i = 0; i < joypad->axes; i++) { for (int i = 0; i < joypad->axes; i++) {
Axes[i]->update(); Axes[i]->update();
} }
for (int i = 0; i < joypad->buttons; i++) { for (int i = 0; i < joypad->buttons; i++) {
Buttons[i]->update(); Buttons[i]->update();
} }
} }
void JoyPadWidget::clear() { void JoyPadWidget::clear() {
joypad->toDefault(); joypad->toDefault();
update(); update();
} }
void JoyPadWidget::setAll() { void JoyPadWidget::setAll() {
//quickset is NULL if there is no quickset dialog, and a pointer to the //quickset is NULL if there is no quickset dialog, and a pointer to the
//dialog otherwise. This is so we can forward jsevents properly. //dialog otherwise. This is so we can forward jsevents properly.
quickset = new QuickSet(joypad); quickset = new QuickSet(joypad);
quickset->exec(); quickset->exec();
update(); update();
delete quickset; delete quickset;
quickset = NULL; quickset = NULL;
} }
void JoyPadWidget::jsevent( js_event msg ) { void JoyPadWidget::jsevent( js_event msg ) {
//notify the component this event applies to. this cannot generate anything //notify the component this event applies to. this cannot generate anything
//other than a flash :) //other than a flash :)
if (msg.type == JS_EVENT_AXIS) { if (msg.type == JS_EVENT_AXIS) {
Axes[msg.number]->jsevent(msg.value); Axes[msg.number]->jsevent(msg.value);
} }
else { else {
Buttons[msg.number]->jsevent(msg.value); Buttons[msg.number]->jsevent(msg.value);
} }
//if we're doing quickset, it needs to know when we do something. //if we're doing quickset, it needs to know when we do something.
if (quickset != NULL) if (quickset != NULL)
quickset->jsevent(msg); quickset->jsevent(msg);
} }

View File

@ -2,13 +2,13 @@
#define JOYPAD_WIDGET_H #define JOYPAD_WIDGET_H
//parts for the widget //parts for the widget
#include <qpushbutton.h> //Added by qt3to4:
#include <qlayout.h>
#include <linux/joystick.h>
#include "axisw.h"
//this all relates to a JoyPad //this all relates to a JoyPad
#include "joypad.h" #include "joypad.h"
//and a JoyPadWidget is composed of AxisWidgets and ButtonWidgets //and a JoyPadWidget is composed of AxisWidgets and ButtonWidgets
#include "axisw.h"
#include "buttonw.h" #include "buttonw.h"
//JoyPadWidget also is what initiates the whole QuickSet procedure :) //JoyPadWidget also is what initiates the whole QuickSet procedure :)
#include "quickset.h" #include "quickset.h"

View File

@ -1,238 +1,239 @@
#include "joyslider.h" #include "joyslider.h"
//Added by qt3to4:
JoySlider::JoySlider( int dz, int xz, int val, QWidget* parent ) JoySlider::JoySlider( int dz, int xz, int val, QWidget* parent )
:QWidget( parent ) :QWidget( parent )
{ {
//initialize :) //initialize :)
JoyVal = val; JoyVal = val;
DeadZone = dz; DeadZone = dz;
XZone = xz; XZone = xz;
setMinimumHeight(20); setMinimumHeight(20);
} }
void JoySlider::setValue( int newval ) void JoySlider::setValue( int newval )
{ {
//adjust the new position based on the throttle settings //adjust the new position based on the throttle settings
if (throttle == 0) JoyVal = newval; if (throttle == 0) JoyVal = newval;
else if (throttle < 0) JoyVal = (newval + JOYMIN) / 2; else if (throttle < 0) JoyVal = (newval + JOYMIN) / 2;
else JoyVal = (newval + JOYMAX) / 2; else JoyVal = (newval + JOYMAX) / 2;
//then redraw! //then redraw!
update(); update();
} }
void JoySlider::setThrottle( int newval ) void JoySlider::setThrottle( int newval )
{ {
//change throttle settings. This WILL quite likely cause minor issues with //change throttle settings. This WILL quite likely cause minor issues with
//status if the axis is not currently at zero, but these will be corrected //status if the axis is not currently at zero, but these will be corrected
//as soon as the axis moves again. //as soon as the axis moves again.
throttle = newval; throttle = newval;
update(); update();
} }
int JoySlider::pointFor( int value, bool negative ) int JoySlider::pointFor( int value, bool negative )
{ {
//complicated... this just finds the pixel the given value should be. //complicated... this just finds the pixel the given value should be.
if (throttle == 0) { if (throttle == 0) {
int result = ((boxwidth - 4) * value) / JOYMAX; int result = ((boxwidth - 4) * value) / JOYMAX;
if (negative) result = lboxstart + boxwidth - 2 - result; if (negative) result = lboxstart + boxwidth - 2 - result;
else result += rboxstart + 2; else result += rboxstart + 2;
return result; return result;
} }
else { else {
int result = ((twidth - 4) * value) / JOYMAX; int result = ((twidth - 4) * value) / JOYMAX;
if (negative) result = lboxstart + twidth - 2 - result; if (negative) result = lboxstart + twidth - 2 - result;
else result += lboxstart + 2; else result += lboxstart + 2;
return result; return result;
} }
} }
int JoySlider::valueFrom( int point ) int JoySlider::valueFrom( int point )
{ {
//the inverse of above :) //the inverse of above :)
if (throttle == 0) { if (throttle == 0) {
if (point <= lboxstart) return JOYMAX; if (point <= lboxstart) return JOYMAX;
if (point >= lboxend - 2 && point <= rboxstart + 2) return 0; if (point >= lboxend - 2 && point <= rboxstart + 2) return 0;
if (point >= rboxend - 2) return JOYMAX; if (point >= rboxend - 2) return JOYMAX;
if (point < lboxend - 2) return ((lboxend - point) * JOYMAX) / boxwidth; if (point < lboxend - 2) return ((lboxend - point) * JOYMAX) / boxwidth;
if (point > rboxstart) return ((point - rboxstart) * JOYMAX) / boxwidth; if (point > rboxstart) return ((point - rboxstart) * JOYMAX) / boxwidth;
else return 0; else return 0;
} }
else if (throttle > 0) { else if (throttle > 0) {
if (point <= lboxstart) return 0; if (point <= lboxstart) return 0;
else if (point >= tend) return JOYMAX; else if (point >= tend) return JOYMAX;
else return ((point - lboxstart) * JOYMAX) / twidth; else return ((point - lboxstart) * JOYMAX) / twidth;
} }
else { else {
if (point <= lboxstart - 2) return JOYMAX; if (point <= lboxstart - 2) return JOYMAX;
else if (point >= tend) return 0; else if (point >= tend) return 0;
else return ((tend - point) * JOYMAX) / twidth; else return ((tend - point) * JOYMAX) / twidth;
} }
} }
void JoySlider::resizeEvent( QResizeEvent* ) void JoySlider::resizeEvent( QResizeEvent* )
{ {
//when we resize, we need to recalculate a bunch of measurements. //when we resize, we need to recalculate a bunch of measurements.
boxwidth = (this->width() - 6) / 2 - 1; boxwidth = (this->width() - 6) / 2 - 1;
twidth = this->width() - 4; twidth = this->width() - 4;
boxheight = this->height() - 4; boxheight = this->height() - 4;
lboxstart = 1; lboxstart = 1;
lboxend = lboxstart + boxwidth - 1; lboxend = lboxstart + boxwidth - 1;
tend = lboxstart + twidth - 1; tend = lboxstart + twidth - 1;
rboxstart = lboxend + 5; rboxstart = lboxend + 5;
rboxend = rboxstart + boxwidth - 1; rboxend = rboxstart + boxwidth - 1;
} }
void JoySlider::drawBox( int x, int width ) { void JoySlider::drawBox( int x, int width ) {
//draws a nice, pretty, 3d-styled box. that takes up the full height of the //draws a nice, pretty, 3d-styled box. that takes up the full height of the
//widget but is defined by x-coordinate and width //widget but is defined by x-coordinate and width
QPainter paint( this ); QPainter paint( this );
paint.setPen( (isEnabled())?white:colorGroup().background() ); paint.setPen( (isEnabled())?Qt::white:palette().background().color() );
paint.setBrush( (isEnabled())?white:colorGroup().background() ); paint.setBrush( (isEnabled())?Qt::white:palette().background() );
paint.drawRect( x, 1, width, boxheight); paint.drawRect( x, 1, width, boxheight);
paint.setPen( colorGroup().dark() ); paint.setPen( palette().dark().color() );
paint.drawLine( x, 1 + boxheight, x, 1 ); paint.drawLine( x, 1 + boxheight, x, 1 );
paint.drawLine( x, 1, x + width - 1, 1); paint.drawLine( x, 1, x + width - 1, 1);
paint.setPen( colorGroup().shadow() ); paint.setPen( palette().shadow().color() );
paint.drawLine( x + 1, 1 + boxheight - 1, x + 1, 2); paint.drawLine( x + 1, 1 + boxheight - 1, x + 1, 2);
paint.drawLine( x + 1, 2, x + width - 2, 2); paint.drawLine( x + 1, 2, x + width - 2, 2);
paint.setPen( colorGroup().light() ); paint.setPen( palette().light().color() );
paint.drawLine( x + 2, 1 + boxheight - 1, x + width - 1, 1 + boxheight - 1); paint.drawLine( x + 2, 1 + boxheight - 1, x + width - 1, 1 + boxheight - 1);
paint.drawLine( x + width - 1, 1 + boxheight - 1, x + width - 1, 2); paint.drawLine( x + width - 1, 1 + boxheight - 1, x + width - 1, 2);
paint.setPen( colorGroup().midlight() ); paint.setPen( palette().midlight().color() );
paint.drawLine( x + 1, 1 + boxheight, x + width, 1 + boxheight ); paint.drawLine( x + 1, 1 + boxheight, x + width, 1 + boxheight );
paint.drawLine( x + width, 1 + boxheight, x + width, 1 ); paint.drawLine( x + width, 1 + boxheight, x + width, 1 );
} }
void JoySlider::paintEvent( QPaintEvent* ) void JoySlider::paintEvent( QPaintEvent* )
{ {
//when we need to redraw, //when we need to redraw,
//start by making our boxes //start by making our boxes
if (throttle == 0) { if (throttle == 0) {
drawBox( lboxstart, boxwidth ); drawBox( lboxstart, boxwidth );
drawBox( rboxstart, boxwidth ); drawBox( rboxstart, boxwidth );
} }
//or box, if we are in throttle mode. //or box, if we are in throttle mode.
else { else {
drawBox( lboxstart, twidth ); drawBox( lboxstart, twidth );
} }
//if this is disabled, that's enough of that. //if this is disabled, that's enough of that.
if (!isEnabled()) return; if (!isEnabled()) return;
//now we need to draw. //now we need to draw.
QPainter paint( this ); QPainter paint( this );
//prepare to draw a bar of the appropriate color //prepare to draw a bar of the appropriate color
QColor bar; QColor bar;
if (abs(JoyVal) < DeadZone) bar = gray; if (abs(JoyVal) < DeadZone) bar = Qt::gray;
else if (abs(JoyVal) < XZone) bar = blue; else if (abs(JoyVal) < XZone) bar = Qt::blue;
else bar = red; else bar = Qt::red;
paint.setPen( bar ); paint.setPen( bar );
paint.setBrush( bar ); paint.setBrush( bar );
//find out the dimensions of the bar, then draw it //find out the dimensions of the bar, then draw it
int width = (throttle == 0)?boxwidth:twidth; int width = (throttle == 0)?boxwidth:twidth;
int barlen = abs(((width - 4) * JoyVal) / JOYMAX); int barlen = abs(((width - 4) * JoyVal) / JOYMAX);
if (JoyVal > 0) if (JoyVal > 0)
paint.drawRect( ((throttle == 0)?rboxstart:lboxstart) + 2, 3, barlen, boxheight - 3 ); paint.drawRect( ((throttle == 0)?rboxstart:lboxstart) + 2, 3, barlen, boxheight - 3 );
else if (JoyVal < 0) else if (JoyVal < 0)
paint.drawRect( lboxstart + width - 2 - barlen, 3, barlen, boxheight - 3 ); paint.drawRect( lboxstart + width - 2 - barlen, 3, barlen, boxheight - 3 );
//and now draw the tabs! We only need one set if we're doing a throttle mode //and now draw the tabs! We only need one set if we're doing a throttle mode
//but we need two if we're not. However, it's important to draw the right //but we need two if we're not. However, it's important to draw the right
//set of tabs depending on the mode! Negative throttle gets negative tabs. //set of tabs depending on the mode! Negative throttle gets negative tabs.
int point; int point;
QPointArray shape; QPolygon shape;
paint.setPen( black ); paint.setPen( Qt::black );
paint.setBrush( blue ); paint.setBrush( Qt::blue );
if (throttle >= 0) { if (throttle >= 0) {
point = pointFor(DeadZone, false); point = pointFor(DeadZone, false);
shape.putPoints(0,5, shape.putPoints(0,5,
point, boxheight - 4, point, boxheight - 4,
point + 3, boxheight - 1, point + 3, boxheight - 1,
point + 3, boxheight + 2, point + 3, boxheight + 2,
point - 3, boxheight + 2, point - 3, boxheight + 2,
point - 3, boxheight - 1); point - 3, boxheight - 1);
paint.drawPolygon(shape); paint.drawPolygon(shape);
} }
if (throttle <= 0) { if (throttle <= 0) {
point = pointFor(DeadZone, true); point = pointFor(DeadZone, true);
shape.putPoints(0,5, shape.putPoints(0,5,
point, boxheight - 4, point, boxheight - 4,
point + 3, boxheight - 1, point + 3, boxheight - 1,
point + 3, boxheight + 2, point + 3, boxheight + 2,
point - 3, boxheight + 2, point - 3, boxheight + 2,
point - 3, boxheight - 1); point - 3, boxheight - 1);
paint.drawPolygon(shape); paint.drawPolygon(shape);
} }
paint.setBrush( red ); paint.setBrush( Qt::red );
if (throttle >= 0) { if (throttle >= 0) {
point = pointFor(XZone, false); point = pointFor(XZone, false);
shape.putPoints(0,5, shape.putPoints(0,5,
point, boxheight - 4, point, boxheight - 4,
point + 3, boxheight - 1, point + 3, boxheight - 1,
point + 3, boxheight + 2, point + 3, boxheight + 2,
point - 3, boxheight + 2, point - 3, boxheight + 2,
point - 3, boxheight - 1); point - 3, boxheight - 1);
paint.drawPolygon(shape); paint.drawPolygon(shape);
} }
if (throttle <= 0) { if (throttle <= 0) {
point = pointFor(XZone, true); point = pointFor(XZone, true);
shape.putPoints(0,5, shape.putPoints(0,5,
point, boxheight - 4, point, boxheight - 4,
point + 3, boxheight - 1, point + 3, boxheight - 1,
point + 3, boxheight + 2, point + 3, boxheight + 2,
point - 3, boxheight + 2, point - 3, boxheight + 2,
point - 3, boxheight - 1); point - 3, boxheight - 1);
paint.drawPolygon(shape); paint.drawPolygon(shape);
} }
} }
void JoySlider::mousePressEvent( QMouseEvent* e ) void JoySlider::mousePressEvent( QMouseEvent* e )
{ {
//store the x coordinate. //store the x coordinate.
int xpt = e->x(); int xpt = e->x();
int result = 0; int result = 0;
//see if this happened near one of the tabs. If so, start dragging that tab. //see if this happened near one of the tabs. If so, start dragging that tab.
if (throttle <= 0 && abs( xpt - pointFor( XZone, true )) < 5) result = DRAG_XZ; if (throttle <= 0 && abs( xpt - pointFor( XZone, true )) < 5) result = DRAG_XZ;
else if (throttle <= 0 && abs( xpt - pointFor( DeadZone, true )) < 5) result = DRAG_DZ; else if (throttle <= 0 && abs( xpt - pointFor( DeadZone, true )) < 5) result = DRAG_DZ;
else if (throttle >= 0 && abs( xpt - pointFor( XZone, false )) < 5) result = DRAG_XZ; else if (throttle >= 0 && abs( xpt - pointFor( XZone, false )) < 5) result = DRAG_XZ;
else if (throttle >= 0 && abs( xpt - pointFor( DeadZone, false )) < 5) result = DRAG_DZ; else if (throttle >= 0 && abs( xpt - pointFor( DeadZone, false )) < 5) result = DRAG_DZ;
dragging = result; dragging = result;
}; };
void JoySlider::mouseReleaseEvent( QMouseEvent* ) void JoySlider::mouseReleaseEvent( QMouseEvent* )
{ {
//when the mouse releases, all dragging stops. //when the mouse releases, all dragging stops.
dragging = 0; dragging = 0;
} }
void JoySlider::mouseMoveEvent( QMouseEvent* e ) void JoySlider::mouseMoveEvent( QMouseEvent* e )
{ {
//get the x coordinate //get the x coordinate
int xpt = e->x(); int xpt = e->x();
//if we're dragging, move the appropriate tab! //if we're dragging, move the appropriate tab!
if (dragging == DRAG_XZ) if (dragging == DRAG_XZ)
{ {
XZone = valueFrom( xpt ); XZone = valueFrom( xpt );
} }
else if (dragging == DRAG_DZ) else if (dragging == DRAG_DZ)
{ {
DeadZone = valueFrom( xpt ); DeadZone = valueFrom( xpt );
} }
else return; else return;
//if we moved a tab, redraw! //if we moved a tab, redraw!
update(); update();
} }

View File

@ -2,12 +2,17 @@
#define Q_JOYSLIDER_H #define Q_JOYSLIDER_H
//the parent of this //the parent of this
#include <qwidget.h>
//for drawing the widget :)
#include <qpainter.h>
//for abs()
#include <stdlib.h>
#include <stdlib.h>
#include <QResizeEvent>
#include <QPaintEvent>
#include <QMouseEvent>
#include <QPainter>
#include <QFrame>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QComboBox>
#include <QSpinBox>
#include "constant.h" #include "constant.h"
//dragging constants. //dragging constants.

View File

@ -1,13 +1,13 @@
#include "keycode.h" #include "keycode.h"
#include "getkey.h"
const QString ktos( int keycode ) const QString ktos( int keycode )
{ {
if (keycode > MAXKEY || keycode < 0) keycode = 0; if (keycode > MAXKEY || keycode < 0) keycode = 0;
if (keycode == 0) return "[NO KEY]"; if (keycode == 0) return "[NO KEY]";
QString xname = XKeysymToString(XKeycodeToKeysym(display, keycode,0)); QString xname = XKeysymToString(XKeycodeToKeysym(display, keycode,0));
//this section of code converts standard X11 keynames into much nicer names //this section of code converts standard X11 keynames into much nicer names
//which are prettier, fit the dialogs better, and are more readily understandable. //which are prettier, fit the dialogs better, and are more readily understandable.
@ -15,155 +15,90 @@ const QString ktos( int keycode )
//is a config option to define PLAIN_KEYS and drop this whole section of code, //is a config option to define PLAIN_KEYS and drop this whole section of code,
//instead using the default names for keys. //instead using the default names for keys.
#ifndef PLAIN_KEYS #ifndef PLAIN_KEYS
//the following code assumes xname is system independent and always //the following code assumes xname is system independent and always
//in the same exact format. //in the same exact format.
QRegExp rx; QRegExp rx;
rx.setPattern("^\\w$"); rx.setPattern("^\\w$");
//"a-z" -> "A-Z" //"a-z" -> "A-Z"
if (rx.exactMatch(xname)) return xname.upper(); if (rx.exactMatch(xname)) return xname.toUpper();
rx.setPattern("(.*)_(.*)"); rx.setPattern("(.*)_(.*)");
if (rx.exactMatch(xname)) { if (rx.exactMatch(xname)) {
QString first = rx.cap(1); QString first = rx.cap(1);
QString second = rx.cap(2); QString second = rx.cap(2);
rx.setPattern("^[RL]$"); rx.setPattern("^[RL]$");
//"Control_R" -> "R Control" //"Control_R" -> "R Control"
if (rx.exactMatch(second)) return second + " " + first; if (rx.exactMatch(second)) return second + " " + first;
rx.setPattern("^(Lock|Enter)$"); rx.setPattern("^(Lock|Enter)$");
//"Caps_Lock" -> "Caps Lock" //"Caps_Lock" -> "Caps Lock"
//"KP_Enter" -> "KP Enter" //"KP_Enter" -> "KP Enter"
if (rx.exactMatch(second)) return first + " " + second; if (rx.exactMatch(second)) return first + " " + second;
//the following assumes all number pads are laid out alike. //the following assumes all number pads are laid out alike.
if (xname == "KP_Home") return "KP 7"; if (xname == "KP_Home") return "KP 7";
if (xname == "KP_Up") return "KP 8"; if (xname == "KP_Up") return "KP 8";
if (xname == "KP_Prior") return "KP 9"; if (xname == "KP_Prior") return "KP 9";
if (xname == "KP_Subtract") return "KP -"; if (xname == "KP_Subtract") return "KP -";
if (xname == "KP_Left") return "KP 4"; if (xname == "KP_Left") return "KP 4";
if (xname == "KP_Begin") return "KP 5"; if (xname == "KP_Begin") return "KP 5";
if (xname == "KP_Right") return "KP 6"; if (xname == "KP_Right") return "KP 6";
if (xname == "KP_Add") return "KP +"; if (xname == "KP_Add") return "KP +";
if (xname == "KP_End") return "KP 1"; if (xname == "KP_End") return "KP 1";
if (xname == "KP_Down") return "KP 2"; if (xname == "KP_Down") return "KP 2";
if (xname == "KP_Next") return "KP 3"; if (xname == "KP_Next") return "KP 3";
if (xname == "KP_Insert") return "KP 0"; if (xname == "KP_Insert") return "KP 0";
if (xname == "KP_Delete") return "KP ."; if (xname == "KP_Delete") return "KP .";
if (xname == "KP_Multiply") return "KP *"; if (xname == "KP_Multiply") return "KP *";
if (xname == "KP_Divide") return "KP /"; if (xname == "KP_Divide") return "KP /";
return xname; return xname;
} }
if (xname == "minus") return "-"; if (xname == "minus") return "-";
if (xname == "equal") return "="; if (xname == "equal") return "=";
if (xname == "bracketleft") return "["; if (xname == "bracketleft") return "[";
if (xname == "bracketright") return "]"; if (xname == "bracketright") return "]";
if (xname == "semicolon") return ";"; if (xname == "semicolon") return ";";
if (xname == "apostrophe") return "'"; if (xname == "apostrophe") return "'";
if (xname == "grave") return "`"; if (xname == "grave") return "`";
if (xname == "backslash") return "\\"; if (xname == "backslash") return "\\";
if (xname == "comma") return ","; if (xname == "comma") return ",";
if (xname == "period") return "."; if (xname == "period") return ".";
if (xname == "slash") return "/"; if (xname == "slash") return "/";
if (xname == "space") return "Space"; if (xname == "space") return "Space";
if (xname == "Prior") return "PageUp"; if (xname == "Prior") return "PageUp";
if (xname == "Next") return "PageDown"; if (xname == "Next") return "PageDown";
#endif #endif
//if none of that succeeded, //if none of that succeeded,
return xname; return xname;
} }
GetKey::GetKey( QString button, bool m )
:QDialog( )
{
//prepare the dialog
mouse = m;
setCaption( "Choose a key" );
setIcon(QPixmap(ICON24));
//I'd use a QLabel, but that steals x11Events!
//So, I'll draw the text directly. That means
//I need to resolve the size of the dialog by hand:
Text = "Choose a new key ";
if (mouse) Text += "or mouse button ";
Text += "for " + button;
QRect rect = fontMetrics().boundingRect( Text );
//I calculate the size based on the first line of text, which is longer.
//The fontMetrics function is dumb and would treat the string with a
//newline in it as a continues flow of characters if I did the whole string
//at once.
Text += "\n(Ctrl-X for no key)";
//now I add 20 pixels of padding and double the height to make room for
//two lines.
setFixedSize( QSize( rect.width() + 20, rect.height()*2 + 20 ) );
}
bool GetKey::x11Event( XEvent* e )
{
//keep Qt from closing the dialog upon seeing Esc pressed.
if (e->type == KeyPress) return true;
//On a key press, return the key and quit
//Ctrl+X == [No Key]
if (e->type == KeyRelease) {
if (XKeycodeToKeysym(display,e->xkey.keycode,0) == XK_x ) {
if (e->xkey.state & ControlMask) done( 0 );
else done( e->xkey.keycode );
}
else done( e->xkey.keycode );
return true;
}
//if we're accepting mouse clicks and a mouse button was clicked...
if (mouse && e->type == ButtonRelease) {
done ( e->xbutton.button + MOUSE_OFFSET);
return true;
}
//any other events we will pass on to the dialog. This allows for closing
//the window and easy redrawing :)
return false;
}
void GetKey::paintEvent ( QPaintEvent * ) {
//whenever we need to repaint, draw in our text.
QPainter paint( this );
paint.drawText( rect(), AlignCenter, Text );
}
KeyButton::KeyButton( QString name, int val, QWidget* parent, bool m, bool nowMouse) KeyButton::KeyButton( QString name, int val, QWidget* parent, bool m, bool nowMouse)
:QPushButton(nowMouse?"Mouse " + QString::number(val):QString(ktos(val)), parent) { :QPushButton(nowMouse?"Mouse " + QString::number(val):QString(ktos(val)), parent) {
mouse = m; mouse = m;
mouseClicked = nowMouse; mouseClicked = nowMouse;
buttonname = name; buttonname = name;
value = val; value = val;
connect( this, SIGNAL( clicked() ), SLOT( onClick() )); connect( this, SIGNAL( clicked() ), SLOT( onClick() ));
} }
void KeyButton::onClick() { void KeyButton::onClick() {
//when clicked, ask for a key! //when clicked, ask for a key!
value = GetKey( buttonname, mouse ).exec(); value = GetKey( buttonname, mouse ).exec();
//if the return value was a mouse click... //if the return value was a mouse click...
if (value > MOUSE_OFFSET) { if (value > MOUSE_OFFSET) {
mouseClicked = true; mouseClicked = true;
value -= MOUSE_OFFSET; value -= MOUSE_OFFSET;
setText( "Mouse " + QString::number(value)); setText( "Mouse " + QString::number(value));
} }
//otherwise, it was a key press! //otherwise, it was a key press!
else { else {
mouseClicked = false; mouseClicked = false;
setText( ktos(value)); setText( ktos(value));
} }
} }

View File

@ -2,21 +2,11 @@
#define KEYCODE_H #define KEYCODE_H
//To create the "press a key" dialog: //To create the "press a key" dialog:
#include <qdialog.h> #include <QPushButton>
#include <qpainter.h> #include <QDialog>
#include <QPaintEvent>
#include <QPainter>
//For the KeyButton widget
#include <qpushbutton.h>
//For converting X Windows key names to something nicer.
#include <qregexp.h>
//Defines constants needed for x11Event
#include <X11/Xlib.h>
//The KeySym for "x"
#define XK_x 0x078
#define MOUSE_OFFSET 400
#include "constant.h" #include "constant.h"
@ -26,23 +16,6 @@ const QString ktos( int keycode );
//The X11 display, taken from main.cpp //The X11 display, taken from main.cpp
extern Display* display; extern Display* display;
//a keycode dialog box
class GetKey : public QDialog {
Q_OBJECT
public:
GetKey( QString button, bool m = false );
protected:
//to filter through every event this thing sees, before QT does.
bool x11Event( XEvent* e );
//to avoid focus issues, there is only the dialog widget, all the
//rest is painted on. So, I need to know when to repaint.
void paintEvent ( QPaintEvent * );
private:
//the dialog's message
QString Text;
//does this dialog accept mouse clicks?
bool mouse;
};
//a button that requests a keycode from the user when clicked. //a button that requests a keycode from the user when clicked.
class KeyButton : public QPushButton { class KeyButton : public QPushButton {

View File

@ -1,22 +1,6 @@
#ifndef JOY_LAYOUT_H #ifndef JOY_LAYOUT_H
#define JOY_LAYOUT_H #define JOY_LAYOUT_H
//for file i/o
#include <qdir.h>
#include <qfile.h>
#include <qtextstream.h>
#include <qstringlist.h>
//to get a name for a new layout
#include <qinputdialog.h>
//qpopup is a REAL pain to include ;) This is because of some
//odd complications and reciprocalities in QT... unfortunately, this is the
//best way I've found to get around it.
#ifndef MAIN
//the layout manager is responsible for the tray icon and its popup
#include <qpopupmenu.h>
#endif
//to allow for interprocess communications (ie, signaling a running instance of //to allow for interprocess communications (ie, signaling a running instance of
//qjoypad by running "qjoypad layout-name", etc.) QJoyPad uses signals to //qjoypad by running "qjoypad layout-name", etc.) QJoyPad uses signals to
@ -24,6 +8,14 @@
//the joystick device list. //the joystick device list.
#include <signal.h> #include <signal.h>
#include <QAction>
#include <QDir>
#include <QMenu>
#include <QApplication>
#include <QDialog>
#include <QInputDialog>
#include <poll.h>
//a layout handles several joypads //a layout handles several joypads
#include "joypad.h" #include "joypad.h"
//for errors //for errors
@ -41,7 +33,7 @@
#define NL "[NO LAYOUT]" #define NL "[NO LAYOUT]"
//where QJoyPad saves its settings! //where QJoyPad saves its settings!
const QString settingsDir(QDir::homeDirPath() + "/.qjoypad3/"); const QString settingsDir(QDir::homePath() + "/.qjoypad3/");
//handles loading, saving, and changing of layouts //handles loading, saving, and changing of layouts
class LayoutManager : public QObject { class LayoutManager : public QObject {
@ -74,7 +66,7 @@ class LayoutManager : public QObject {
//when the tray icon is clicked //when the tray icon is clicked
void trayClick(); void trayClick();
//when the user selects an item on the tray's popup menu //when the user selects an item on the tray's popup menu
void trayMenu(int id); void trayMenu(QAction* menuItemAction);
//rebuild the popup menu with the current information //rebuild the popup menu with the current information
void fillPopup(); void fillPopup();
//update the list of available joystick devices //update the list of available joystick devices
@ -87,7 +79,7 @@ class LayoutManager : public QObject {
//the layout that is currently in use //the layout that is currently in use
QString CurrentLayout; QString CurrentLayout;
//the popup menu from the tray/floating icon //the popup menu from the tray/floating icon
QPopupMenu* Popup; QMenu* Popup;
//if there is a LayoutEdit open, this points to it. Otherwise, NULL. //if there is a LayoutEdit open, this points to it. Otherwise, NULL.
LayoutEdit* le; LayoutEdit* le;

View File

@ -1,65 +0,0 @@
#include "loop.h"
JoyLoop::JoyLoop() {
//I like to start from zero, though, in all honesty, this doesn't matter.
tick = 0;
}
bool JoyLoop::processEvents( ProcessEventsFlags ) {
//standard event processing, except we get to throw in a few things of
//our own!
int joydev;
JoyPad* pad;
js_event msg;
int len;
//go through the currently plugged-in joysticks
QIntDictIterator<JoyPad> it( available );
for ( ; it.current(); ++it ) {
pad = it.current();
//get the file descriptor for the device
joydev = pad->joydev;
//and try reading an event, non-blocking
len = read( joydev, &msg, sizeof(js_event));
//if there was a real event waiting,
if (len == (int) sizeof(js_event)) {
//pass that event on to the joypad!
pad->jsevent(msg);
}
}
//sleep for a moment. This is just to keep us from throwing all the
//available processer power into madly checking for new events.
usleep(1);
//now we can let QT process all of its events, like GUI events and timers.
return QEventLoop::processEvents(AllEvents);
}
void JoyLoop::takeTimer( Component* c ) {
//if this is the first Component asking for a timer, then we can start
//up the timer! It isn't running unless someone needs it.
if (timerList.isEmpty()) startTimer( MSEC );
//remember this Component so we can signal it.
timerList.append( c );
}
void JoyLoop::tossTimer( Component* c ) {
//forget that Component, it doesn't NEED us any more :(
timerList.remove( c );
//if that means there are no longer any Components listening for timer
//events, then we can go ahead and stop timing.
if (timerList.isEmpty()) killTimers();
}
void JoyLoop::timerEvent( QTimerEvent* ) {
//ever MSEC miliseconds...
//increment the counter (used for timing in axis.cpp and button.cpp)
++tick;
//and notify every Component in the list.
for ( Component* c = timerList.first(); c; c = timerList.next() ) {
c->timer(tick);
}
}

View File

@ -1,39 +0,0 @@
#ifndef JOY_LOOP_H
#define JOY_LOOP_H
//this is an event loop
#include <qeventloop.h>
//for reading events from the joysticks
#include <unistd.h>
#include <linux/joystick.h>
//to pass events on to the joypads
#include "joypad.h"
//to know which devices need to be checked for joystick events
#include "device.h"
//A Component is either an Axis or a Button
class Component;
//the main event loop of QJoyPad; its main distinction from a regular event loop
//is that it reads joystick events on every iteration and also provides a timer
//to any Components that need it.
class JoyLoop : public QEventLoop {
public:
JoyLoop();
bool processEvents( ProcessEventsFlags );
//provide a timer to the requesting Component
void takeTimer( Component* c );
//stop providing a timer to the given Component
void tossTimer( Component* c );
protected:
//happens ever MSEC miliseconds :)
virtual void timerEvent( QTimerEvent* );
//just a counter, nothing more.
int tick;
//a list of the Components that need a timer
QPtrList<Component> timerList;
};
#endif

View File

@ -1,184 +0,0 @@
Log for qt3to4 on Fri Dec 26 18:59:56 2008. Number of log entries: 101
In file /home/john/qjoypad-3.4.1/src/axis.cpp at line 21 column 28: QTextStream -> Q3TextStream
In file /home/john/qjoypad-3.4.1/src/axis.cpp at line 115 column 29: QTextStream -> Q3TextStream
In file /home/john/qjoypad-3.4.1/src/axis.cpp: Added the following include directives:
#include <Q3TextStream>
In file /home/john/qjoypad-3.4.1/src/axis_edit.cpp at line 22 column 12: QVBoxLayout -> Q3VBoxLayout
In file /home/john/qjoypad-3.4.1/src/axis_edit.cpp at line 22 column 33: QVBoxLayout -> Q3VBoxLayout
In file /home/john/qjoypad-3.4.1/src/axis_edit.cpp at line 24 column 12: QHBoxLayout -> Q3HBoxLayout
In file /home/john/qjoypad-3.4.1/src/axis_edit.cpp at line 24 column 33: QHBoxLayout -> Q3HBoxLayout
In file /home/john/qjoypad-3.4.1/src/axis_edit.cpp at line 25 column 13: QVBoxLayout -> Q3VBoxLayout
In file /home/john/qjoypad-3.4.1/src/axis_edit.cpp at line 25 column 35: QVBoxLayout -> Q3VBoxLayout
In file /home/john/qjoypad-3.4.1/src/axis_edit.cpp at line 41 column 23: QFrame -> Q3Frame
In file /home/john/qjoypad-3.4.1/src/axis_edit.cpp at line 42 column 33: QFrame -> Q3Frame
In file /home/john/qjoypad-3.4.1/src/axis_edit.cpp at line 42 column 47: QFrame -> Q3Frame
In file /home/john/qjoypad-3.4.1/src/axis_edit.cpp at line 43 column 22: QVBoxLayout -> Q3VBoxLayout
In file /home/john/qjoypad-3.4.1/src/axis_edit.cpp at line 54 column 20: QFrame -> Q3Frame
In file /home/john/qjoypad-3.4.1/src/axis_edit.cpp at line 55 column 30: QFrame -> Q3Frame
In file /home/john/qjoypad-3.4.1/src/axis_edit.cpp at line 55 column 44: QFrame -> Q3Frame
In file /home/john/qjoypad-3.4.1/src/axis_edit.cpp at line 56 column 20: QHBoxLayout -> Q3HBoxLayout
In file /home/john/qjoypad-3.4.1/src/axis_edit.cpp at line 70 column 20: QHBoxLayout -> Q3HBoxLayout
In file /home/john/qjoypad-3.4.1/src/axis_edit.cpp: Added the following include directives:
#include <QPixmap> #include <Q3HBoxLayout> #include <Q3VBoxLayout> #include <QLabel> #include <Q3Frame>
In file /home/john/qjoypad-3.4.1/src/axisw.cpp: Added the following include directives:
#include <QMouseEvent>
In file /home/john/qjoypad-3.4.1/src/button.cpp at line 18 column 30: QTextStream -> Q3TextStream
In file /home/john/qjoypad-3.4.1/src/button.cpp at line 64 column 31: QTextStream -> Q3TextStream
In file /home/john/qjoypad-3.4.1/src/button.cpp: Added the following include directives:
#include <Q3TextStream>
In file /home/john/qjoypad-3.4.1/src/button_edit.cpp at line 14 column 12: QVBoxLayout -> Q3VBoxLayout
In file /home/john/qjoypad-3.4.1/src/button_edit.cpp at line 14 column 33: QVBoxLayout -> Q3VBoxLayout
In file /home/john/qjoypad-3.4.1/src/button_edit.cpp at line 19 column 12: QHBoxLayout -> Q3HBoxLayout
In file /home/john/qjoypad-3.4.1/src/button_edit.cpp at line 19 column 33: QHBoxLayout -> Q3HBoxLayout
In file /home/john/qjoypad-3.4.1/src/button_edit.cpp at line 28 column 20: QHBoxLayout -> Q3HBoxLayout
In file /home/john/qjoypad-3.4.1/src/button_edit.cpp: Added the following include directives:
#include <Q3VBoxLayout> #include <QPixmap> #include <Q3HBoxLayout>
In file /home/john/qjoypad-3.4.1/src/buttonw.cpp: Added the following include directives:
#include <QMouseEvent>
No changes made to file /home/john/qjoypad-3.4.1/src/event.cpp
In file /home/john/qjoypad-3.4.1/src/flash.cpp at line 56 column 25: QHBoxLayout -> Q3HBoxLayout
In file /home/john/qjoypad-3.4.1/src/flash.cpp at line 58 column 25: QVBoxLayout -> Q3VBoxLayout
In file /home/john/qjoypad-3.4.1/src/flash.cpp: Added the following include directives:
#include <Q3VBoxLayout> #include <Q3HBoxLayout>
In file /home/john/qjoypad-3.4.1/src/icon.cpp at line 7 column 20: qpopupmenu.h -> q3popupmenu.h
In file /home/john/qjoypad-3.4.1/src/icon.cpp at line 9 column 59: QPopupMenu -> Q3PopupMenu
In file /home/john/qjoypad-3.4.1/src/icon.cpp: Added the following include directives:
#include <QPixmap> #include <QCloseEvent> #include <QMouseEvent>
In file /home/john/qjoypad-3.4.1/src/joypad.cpp at line 42 column 26: QIntDictIterator -> Q3IntDictIterator
In file /home/john/qjoypad-3.4.1/src/joypad.cpp at line 44 column 26: QIntDictIterator -> Q3IntDictIterator
In file /home/john/qjoypad-3.4.1/src/joypad.cpp at line 50 column 26: QIntDictIterator -> Q3IntDictIterator
In file /home/john/qjoypad-3.4.1/src/joypad.cpp at line 52 column 26: QIntDictIterator -> Q3IntDictIterator
In file /home/john/qjoypad-3.4.1/src/joypad.cpp at line 57 column 30: QTextStream -> Q3TextStream
In file /home/john/qjoypad-3.4.1/src/joypad.cpp at line 114 column 31: QTextStream -> Q3TextStream
In file /home/john/qjoypad-3.4.1/src/joypad.cpp at line 117 column 12: QTextStream -> Q3TextStream
In file /home/john/qjoypad-3.4.1/src/joypad.cpp at line 117 column 33: QTextStream -> Q3TextStream
In file /home/john/qjoypad-3.4.1/src/joypad.cpp at line 117 column 55: IO_WriteOnly -> QIODevice::WriteOnly
In file /home/john/qjoypad-3.4.1/src/joypad.cpp at line 119 column 26: QIntDictIterator -> Q3IntDictIterator
In file /home/john/qjoypad-3.4.1/src/joypad.cpp at line 126 column 26: QIntDictIterator -> Q3IntDictIterator
In file /home/john/qjoypad-3.4.1/src/joypad.cpp at line 139 column 26: QIntDictIterator -> Q3IntDictIterator
In file /home/john/qjoypad-3.4.1/src/joypad.cpp at line 142 column 26: QIntDictIterator -> Q3IntDictIterator
In file /home/john/qjoypad-3.4.1/src/joypad.cpp: Added the following include directives:
#include <Q3TextStream>
In file /home/john/qjoypad-3.4.1/src/joypadw.cpp at line 10 column 24: QGridLayout -> Q3GridLayout
In file /home/john/qjoypad-3.4.1/src/joypadw.cpp: Added the following include directives:
#include <Q3GridLayout>
In file /home/john/qjoypad-3.4.1/src/joyslider.cpp at line 156 column 12: QPointArray -> Q3PointArray
In file /home/john/qjoypad-3.4.1/src/joyslider.cpp: Added the following include directives:
#include <QResizeEvent> #include <Q3PointArray> #include <QMouseEvent> #include <QPaintEvent>
In file /home/john/qjoypad-3.4.1/src/keycode.cpp: Added the following include directives:
#include <QPixmap> #include <QPaintEvent>
In file /home/john/qjoypad-3.4.1/src/layout.cpp at line 13 column 26: QPopupMenu -> Q3PopupMenu
In file /home/john/qjoypad-3.4.1/src/layout.cpp at line 54 column 27: IO_ReadOnly -> QIODevice::ReadOnly
In file /home/john/qjoypad-3.4.1/src/layout.cpp at line 63 column 20: QIntDictIterator -> Q3IntDictIterator
In file /home/john/qjoypad-3.4.1/src/layout.cpp at line 69 column 12: QTextStream -> Q3TextStream
In file /home/john/qjoypad-3.4.1/src/layout.cpp at line 115 column 26: IO_ReadOnly -> QIODevice::ReadOnly
In file /home/john/qjoypad-3.4.1/src/layout.cpp at line 116 column 13: QTextStream -> Q3TextStream
In file /home/john/qjoypad-3.4.1/src/layout.cpp at line 137 column 22: QIntDictIterator -> Q3IntDictIterator
In file /home/john/qjoypad-3.4.1/src/layout.cpp at line 154 column 27: IO_WriteOnly -> QIODevice::WriteOnly
In file /home/john/qjoypad-3.4.1/src/layout.cpp at line 155 column 13: QTextStream -> Q3TextStream
In file /home/john/qjoypad-3.4.1/src/layout.cpp at line 157 column 23: QIntDictIterator -> Q3IntDictIterator
In file /home/john/qjoypad-3.4.1/src/layout.cpp at line 194 column 27: IO_WriteOnly -> QIODevice::WriteOnly
In file /home/john/qjoypad-3.4.1/src/layout.cpp at line 195 column 13: QTextStream -> Q3TextStream
In file /home/john/qjoypad-3.4.1/src/layout.cpp at line 276 column 17: QIntDictIterator -> Q3IntDictIterator
In file /home/john/qjoypad-3.4.1/src/layout.cpp: Added the following include directives:
#include <QPixmap> #include <Q3TextStream> #include <Q3PopupMenu>
In file /home/john/qjoypad-3.4.1/src/layout_edit.cpp at line 17 column 24: QVBoxLayout -> Q3VBoxLayout
In file /home/john/qjoypad-3.4.1/src/layout_edit.cpp at line 19 column 7: QFrame -> Q3Frame
In file /home/john/qjoypad-3.4.1/src/layout_edit.cpp at line 19 column 27: QFrame -> Q3Frame
In file /home/john/qjoypad-3.4.1/src/layout_edit.cpp at line 20 column 28: QFrame -> Q3Frame
In file /home/john/qjoypad-3.4.1/src/layout_edit.cpp at line 20 column 42: QFrame -> Q3Frame
In file /home/john/qjoypad-3.4.1/src/layout_edit.cpp at line 21 column 12: QGridLayout -> Q3GridLayout
In file /home/john/qjoypad-3.4.1/src/layout_edit.cpp at line 21 column 33: QGridLayout -> Q3GridLayout
In file /home/john/qjoypad-3.4.1/src/layout_edit.cpp at line 42 column 28: QWidgetStack -> Q3WidgetStack
In file /home/john/qjoypad-3.4.1/src/layout_edit.cpp at line 43 column 31: QFrame -> Q3Frame
In file /home/john/qjoypad-3.4.1/src/layout_edit.cpp at line 43 column 45: QFrame -> Q3Frame
In file /home/john/qjoypad-3.4.1/src/layout_edit.cpp at line 52 column 20: QIntDictIterator -> Q3IntDictIterator
In file /home/john/qjoypad-3.4.1/src/layout_edit.cpp at line 77 column 12: QHBoxLayout -> Q3HBoxLayout
In file /home/john/qjoypad-3.4.1/src/layout_edit.cpp at line 77 column 33: QHBoxLayout -> Q3HBoxLayout
In file /home/john/qjoypad-3.4.1/src/layout_edit.cpp at line 112 column 17: QIntDictIterator -> Q3IntDictIterator
In file /home/john/qjoypad-3.4.1/src/layout_edit.cpp: Added the following include directives:
#include <QPixmap> #include <Q3GridLayout> #include <Q3HBoxLayout> #include <Q3VBoxLayout> #include <Q3Frame>
In file /home/john/qjoypad-3.4.1/src/loop.cpp at line 21 column 17: QIntDictIterator -> Q3IntDictIterator
In file /home/john/qjoypad-3.4.1/src/loop.cpp: Added the following include directives:
#include <QTimerEvent> #include <QEventLoop>
In file /home/john/qjoypad-3.4.1/src/main.cpp at line 34 column 8: QIntDict -> Q3IntDict
In file /home/john/qjoypad-3.4.1/src/main.cpp at line 35 column 8: QIntDict -> Q3IntDict
In file /home/john/qjoypad-3.4.1/src/main.cpp at line 36 column 8: QPtrList -> Q3PtrList
In file /home/john/qjoypad-3.4.1/src/main.cpp at line 56 column 20: QIntDictIterator -> Q3IntDictIterator
In file /home/john/qjoypad-3.4.1/src/main.cpp at line 192 column 28: IO_WriteOnly -> QIODevice::WriteOnly
In file /home/john/qjoypad-3.4.1/src/main.cpp at line 194 column 14: QTextStream -> Q3TextStream
In file /home/john/qjoypad-3.4.1/src/main.cpp at line 210 column 33: IO_ReadOnly -> QIODevice::ReadOnly
In file /home/john/qjoypad-3.4.1/src/main.cpp at line 213 column 14: QTextStream -> Q3TextStream
In file /home/john/qjoypad-3.4.1/src/main.cpp at line 235 column 31: IO_WriteOnly -> QIODevice::WriteOnly
In file /home/john/qjoypad-3.4.1/src/main.cpp at line 237 column 13: QTextStream -> Q3TextStream
In file /home/john/qjoypad-3.4.1/src/main.cpp: Added the following include directives:
#include <Q3TextStream> #include <Q3PtrList>
In file /home/john/qjoypad-3.4.1/src/quickset.cpp at line 12 column 12: QVBoxLayout -> Q3VBoxLayout
In file /home/john/qjoypad-3.4.1/src/quickset.cpp at line 12 column 37: QVBoxLayout -> Q3VBoxLayout
In file /home/john/qjoypad-3.4.1/src/quickset.cpp: Added the following include directives:
#include <Q3VBoxLayout> #include <QLabel>
Log for qt3to4 on Fri Dec 26 19:23:39 2008. Number of log entries: 47
In file /home/john/qjoypad-3.4.1/src/axis.h at line 30 column 24: QTextStream -> Q3TextStream
In file /home/john/qjoypad-3.4.1/src/axis.h at line 32 column 25: QTextStream -> Q3TextStream
In file /home/john/qjoypad-3.4.1/src/axis.h: Added the following include directives:
#include <Q3TextStream>
In file /home/john/qjoypad-3.4.1/src/axis_edit.h at line 8 column 16: qframe.h -> q3frame.h
In file /home/john/qjoypad-3.4.1/src/axis_edit.h at line 40 column 8: QFrame -> Q3Frame
In file /home/john/qjoypad-3.4.1/src/axisw.h: Added the following include directives:
#include <QMouseEvent>
In file /home/john/qjoypad-3.4.1/src/button.h at line 23 column 24: QTextStream -> Q3TextStream
In file /home/john/qjoypad-3.4.1/src/button.h at line 25 column 25: QTextStream -> Q3TextStream
In file /home/john/qjoypad-3.4.1/src/button.h: Added the following include directives:
#include <Q3TextStream>
No changes made to file /home/john/qjoypad-3.4.1/src/button_edit.h
In file /home/john/qjoypad-3.4.1/src/buttonw.h: Added the following include directives:
#include <QMouseEvent>
In file /home/john/qjoypad-3.4.1/src/component.h at line 7 column 21: qtextstream.h -> q3textstream.h
In file /home/john/qjoypad-3.4.1/src/component.h at line 21 column 32: QTextStream -> Q3TextStream
In file /home/john/qjoypad-3.4.1/src/component.h at line 22 column 33: QTextStream -> Q3TextStream
No changes made to file /home/john/qjoypad-3.4.1/src/constant.h
In file /home/john/qjoypad-3.4.1/src/device.h at line 4 column 18: qintdict.h -> q3intdict.h
In file /home/john/qjoypad-3.4.1/src/device.h at line 11 column 15: QIntDict -> Q3IntDict
In file /home/john/qjoypad-3.4.1/src/device.h at line 15 column 15: QIntDict -> Q3IntDict
In file /home/john/qjoypad-3.4.1/src/error.h at line 10 column 39: QMessageBox -> Qt
No changes made to file /home/john/qjoypad-3.4.1/src/event.h
In file /home/john/qjoypad-3.4.1/src/flash.h at line 75 column 12: QBoxLayout -> Q3BoxLayout
In file /home/john/qjoypad-3.4.1/src/flash.h: Added the following include directives:
#include <Q3BoxLayout>
In file /home/john/qjoypad-3.4.1/src/icon.h at line 16 column 16: QPopupMenu -> Q3PopupMenu
In file /home/john/qjoypad-3.4.1/src/icon.h at line 21 column 47: QPopupMenu -> Q3PopupMenu
In file /home/john/qjoypad-3.4.1/src/icon.h at line 28 column 12: QPopupMenu -> Q3PopupMenu
In file /home/john/qjoypad-3.4.1/src/icon.h: Added the following include directives:
#include <QCloseEvent> #include <Q3PopupMenu> #include <QMouseEvent>
In file /home/john/qjoypad-3.4.1/src/joypad.h at line 7 column 18: qintdict.h -> q3intdict.h
In file /home/john/qjoypad-3.4.1/src/joypad.h at line 38 column 24: QTextStream -> Q3TextStream
In file /home/john/qjoypad-3.4.1/src/joypad.h at line 40 column 25: QTextStream -> Q3TextStream
In file /home/john/qjoypad-3.4.1/src/joypad.h at line 71 column 10: QIntDict -> Q3IntDict
In file /home/john/qjoypad-3.4.1/src/joypad.h at line 72 column 10: QIntDict -> Q3IntDict
In file /home/john/qjoypad-3.4.1/src/joypad.h: Added the following include directives:
#include <Q3TextStream>
In file /home/john/qjoypad-3.4.1/src/joypadw.h at line 58 column 13: QGridLayout -> Q3GridLayout
In file /home/john/qjoypad-3.4.1/src/joypadw.h: Added the following include directives:
#include <Q3GridLayout>
In file /home/john/qjoypad-3.4.1/src/joyslider.h: Added the following include directives:
#include <QPaintEvent> #include <QResizeEvent> #include <QMouseEvent>
In file /home/john/qjoypad-3.4.1/src/keycode.h: Added the following include directives:
#include <QPaintEvent>
In file /home/john/qjoypad-3.4.1/src/layout.h at line 7 column 21: qtextstream.h -> q3textstream.h
In file /home/john/qjoypad-3.4.1/src/layout.h at line 18 column 21: qpopupmenu.h -> q3popupmenu.h
In file /home/john/qjoypad-3.4.1/src/layout.h at line 90 column 12: QPopupMenu -> Q3PopupMenu
In file /home/john/qjoypad-3.4.1/src/layout_edit.h at line 10 column 22: qwidgetstack.h -> q3widgetstack.h
In file /home/john/qjoypad-3.4.1/src/layout_edit.h at line 39 column 13: QVBoxLayout -> Q3VBoxLayout
In file /home/john/qjoypad-3.4.1/src/layout_edit.h at line 40 column 14: QWidgetStack -> Q3WidgetStack
In file /home/john/qjoypad-3.4.1/src/layout_edit.h: Added the following include directives:
#include <Q3VBoxLayout>
In file /home/john/qjoypad-3.4.1/src/loop.h at line 39 column 10: QPtrList -> Q3PtrList
In file /home/john/qjoypad-3.4.1/src/loop.h: Added the following include directives:
#include <Q3PtrList> #include <QTimerEvent>
No changes made to file /home/john/qjoypad-3.4.1/src/quickset.h
No changes made to file /home/john/qjoypad-3.4.1/src/timer.h
Log for qt3to4 on Fri Dec 26 19:24:31 2008. Number of log entries: 1
No changes made to file /home/john/qjoypad-3.4.1/src/Makefile

View File

@ -27,8 +27,8 @@ doc.extra = cp ../README.txt ../LICENSE.txt $${doc.path}
##### Setup Compile ##### ##### Setup Compile #####
DEFINES += DEVDIR='"$$DEVDIR"' DEFINES += DEVDIR='"$$DEVDIR"'
DEFINES += ICON24='"$${icons.path}/icon24.png"' DEFINES += ICON24='\"$${icons.path}/icon24.png\"'
DEFINES += ICON64='"$${icons.path}/icon64.png"' DEFINES += ICON64='\"$${icons.path}/icon64.png\"'
TEMPLATE = app TEMPLATE = app
DEPENDPATH += trayicon DEPENDPATH += trayicon
@ -42,7 +42,6 @@ HEADERS += axis.h \
button.h \ button.h \
button_edit.h \ button_edit.h \
buttonw.h \ buttonw.h \
component.h \
constant.h \ constant.h \
device.h \ device.h \
error.h \ error.h \
@ -54,10 +53,9 @@ HEADERS += axis.h \
joyslider.h \ joyslider.h \
keycode.h \ keycode.h \
layout.h \ layout.h \
getkey.h \
layout_edit.h \ layout_edit.h \
loop.h \
quickset.h \ quickset.h \
timer.h \
trayicon/trayicon.h trayicon/trayicon.h
SOURCES += axis.cpp \ SOURCES += axis.cpp \
axis_edit.cpp \ axis_edit.cpp \
@ -74,9 +72,9 @@ SOURCES += axis.cpp \
keycode.cpp \ keycode.cpp \
layout.cpp \ layout.cpp \
layout_edit.cpp \ layout_edit.cpp \
loop.cpp \
main.cpp \ main.cpp \
quickset.cpp \ quickset.cpp \
getkey.cpp \
trayicon/trayicon.cpp \ trayicon/trayicon.cpp \
trayicon/trayicon_x11.cpp trayicon/trayicon_x11.cpp

View File

@ -2,12 +2,14 @@
#define QUICKSET_H #define QUICKSET_H
//for building the dialog //for building the dialog
#include <qlayout.h> #include <QLayout>
#include <qlabel.h> #include <QLabel>
#include <qpushbutton.h> #include <QPushButton>
#include <linux/joystick.h>
//to request new keycodes //to request new keycodes
#include "keycode.h" //#include "keycode.h"
//to actually set the joypad //to actually set the joypad
#include "joypad.h" #include "joypad.h"

View File

@ -1,11 +0,0 @@
#ifndef JTIMER_H
#define JTIMER_H
#include "component.h"
//the purpose of this file is to make a list of Components that need timer
//notification available to JoyLoop, Axis, and Buttons
extern void takeTimer( Component* ); //taken from main.cpp
extern void tossTimer( Component* ); //taken from main.cpp
#endif

View File

@ -19,7 +19,6 @@
*/ */
#include "trayicon.h" #include "trayicon.h"
#include "qpopupmenu.h"
/*! /*!
\class TrayIcon qtrayicon.h \class TrayIcon qtrayicon.h
@ -33,9 +32,9 @@
\sa show \sa show
*/ */
TrayIcon::TrayIcon( QObject *parent, const char *name ) TrayIcon::TrayIcon( QObject *parent, const char *name )
: QObject(parent, name), pop(0), d(0) : QObject(parent/*, name*/), pop(0), d(0)
{ {
v_isWMDock = FALSE; v_isWMDock = FALSE;
} }
/*! /*!
@ -45,10 +44,10 @@ TrayIcon::TrayIcon( QObject *parent, const char *name )
\sa show \sa show
*/ */
TrayIcon::TrayIcon( const QPixmap &icon, const QString &tooltip, QPopupMenu *popup, QObject *parent, const char *name ) TrayIcon::TrayIcon( const QPixmap &icon, const QString &tooltip, QMenu *popup, QObject *parent, const char *name )
: QObject(parent, name), pop(popup), pm(icon), tip(tooltip), d(0) : QObject(parent/*, name*/), pop(popup), pm(icon), tip(tooltip), d(0)
{ {
v_isWMDock = FALSE; v_isWMDock = FALSE;
} }
/*! /*!
@ -63,7 +62,7 @@ TrayIcon::~TrayIcon()
Sets the context menu to \a popup. The context menu will pop up when the Sets the context menu to \a popup. The context menu will pop up when the
user clicks the system tray entry with the right mouse button. user clicks the system tray entry with the right mouse button.
*/ */
void TrayIcon::setPopup( QPopupMenu* popup ) void TrayIcon::setPopup( QMenu* popup )
{ {
pop = popup; pop = popup;
} }
@ -73,7 +72,7 @@ void TrayIcon::setPopup( QPopupMenu* popup )
\sa setPopup \sa setPopup
*/ */
QPopupMenu* TrayIcon::popup() const QMenu* TrayIcon::popup() const
{ {
return pop; return pop;
} }
@ -139,22 +138,22 @@ bool TrayIcon::event( QEvent *e )
{ {
switch ( e->type() ) { switch ( e->type() ) {
case QEvent::MouseMove: case QEvent::MouseMove:
mouseMoveEvent( (QMouseEvent*)e ); mouseMoveEvent( (QMouseEvent*)e );
break; break;
case QEvent::MouseButtonPress: case QEvent::MouseButtonPress:
mousePressEvent( (QMouseEvent*)e ); mousePressEvent( (QMouseEvent*)e );
break; break;
case QEvent::MouseButtonRelease: case QEvent::MouseButtonRelease:
mouseReleaseEvent( (QMouseEvent*)e ); mouseReleaseEvent( (QMouseEvent*)e );
break; break;
case QEvent::MouseButtonDblClick: case QEvent::MouseButtonDblClick:
mouseDoubleClickEvent( (QMouseEvent*)e ); mouseDoubleClickEvent( (QMouseEvent*)e );
break; break;
default: default:
return QObject::event( e ); return QObject::event( e );
} }
return TRUE; return TRUE;
@ -183,22 +182,22 @@ void TrayIcon::mousePressEvent( QMouseEvent *e )
#ifndef Q_WS_WIN #ifndef Q_WS_WIN
// This is for X11, menus appear on mouse press // This is for X11, menus appear on mouse press
// I'm not sure whether Mac should be here or below.. Somebody check? // I'm not sure whether Mac should be here or below.. Somebody check?
switch ( e->button() ) { switch ( e->button() ) {
case RightButton: case Qt::RightButton:
if ( pop ) { if ( pop ) {
pop->popup( e->globalPos() ); pop->popup( e->globalPos() );
e->accept(); e->accept();
} }
break; break;
case LeftButton: case Qt::LeftButton:
case MidButton: case Qt::MidButton:
emit clicked( e->globalPos(), e->button() ); emit clicked( e->globalPos(), e->button() );
break; break;
default: default:
break; break;
} }
#endif #endif
e->ignore(); e->ignore();
} }
/*! /*!
@ -215,26 +214,26 @@ void TrayIcon::mouseReleaseEvent( QMouseEvent *e )
{ {
#ifdef Q_WS_WIN #ifdef Q_WS_WIN
// This is for Windows, where menus appear on mouse release // This is for Windows, where menus appear on mouse release
switch ( e->button() ) { switch ( e->button() ) {
case RightButton: case Qt::RightButton:
if ( pop ) { if ( pop ) {
// Necessary to make keyboard focus // Necessary to make keyboard focus
// and menu closing work on Windows. // and menu closing work on Windows.
pop->setActiveWindow(); pop->setActiveWindow();
pop->popup( e->globalPos() ); pop->popup( e->globalPos() );
pop->setActiveWindow(); pop->setActiveWindow();
e->accept(); e->accept();
} }
break; break;
case LeftButton: case Qt::LeftButton:
case MidButton: case Qt::MidButton:
emit clicked( e->globalPos(), e->button() ); emit clicked( e->globalPos(), e->button() );
break; break;
default: default:
break; break;
} }
#endif #endif
e->ignore(); e->ignore();
} }
/*! /*!
@ -249,9 +248,9 @@ void TrayIcon::mouseReleaseEvent( QMouseEvent *e )
*/ */
void TrayIcon::mouseDoubleClickEvent( QMouseEvent *e ) void TrayIcon::mouseDoubleClickEvent( QMouseEvent *e )
{ {
if ( e->button() == LeftButton ) if ( e->button() == Qt::LeftButton )
emit doubleClicked( e->globalPos() ); emit doubleClicked( e->globalPos() );
e->accept(); e->accept();
} }
/*! /*!
@ -272,5 +271,5 @@ void TrayIcon::mouseDoubleClickEvent( QMouseEvent *e )
void TrayIcon::gotCloseEvent() void TrayIcon::gotCloseEvent()
{ {
closed(); closed();
} }

View File

@ -23,8 +23,12 @@
#include <qobject.h> #include <qobject.h>
#include <qimage.h> #include <qimage.h>
#include <QPixmap>
#include <QDir>
#include <QMenu>
#include <QMouseEvent>
class QPopupMenu;
class TrayIcon : public QObject class TrayIcon : public QObject
{ {
@ -35,7 +39,7 @@ class TrayIcon : public QObject
public: public:
TrayIcon( QObject *parent = 0, const char *name = 0 ); TrayIcon( QObject *parent = 0, const char *name = 0 );
TrayIcon( const QPixmap &, const QString &, QPopupMenu *popup = 0, QObject *parent = 0, const char *name = 0 ); TrayIcon( const QPixmap &, const QString &, QMenu *popup = 0, QObject *parent = 0, const char *name = 0 );
~TrayIcon(); ~TrayIcon();
// use WindowMaker dock mode. ignored on non-X11 platforms // use WindowMaker dock mode. ignored on non-X11 platforms
@ -43,8 +47,8 @@ public:
bool isWMDock() { return v_isWMDock; } bool isWMDock() { return v_isWMDock; }
// Set a popup menu to handle RMB // Set a popup menu to handle RMB
void setPopup( QPopupMenu * ); void setPopup( QMenu * );
QPopupMenu* popup() const; QMenu* popup() const;
QPixmap icon() const; QPixmap icon() const;
QString toolTip() const; QString toolTip() const;
@ -71,7 +75,7 @@ protected:
virtual void mouseDoubleClickEvent( QMouseEvent *e ); virtual void mouseDoubleClickEvent( QMouseEvent *e );
private: private:
QPopupMenu *pop; QMenu *pop;
QPixmap pm; QPixmap pm;
QString tip; QString tip;
bool v_isWMDock; bool v_isWMDock;

View File

@ -21,18 +21,15 @@
#include "trayicon.h" #include "trayicon.h"
#include<qapplication.h> #include <QX11Info>
#include<qimage.h> #include <QApplication>
#include<qpixmap.h> #include <QPainter>
#include<qtooltip.h>
#include<qpainter.h>
#include<X11/Xlib.h> #include<X11/Xlib.h>
#include<X11/Xutil.h> #include<X11/Xutil.h>
#include<X11/Xatom.h> #include<X11/Xatom.h>
//#if QT_VERSION < 0x030200 //#if QT_VERSION < 0x030200
extern Time qt_x_time; //extern Time;// qt_x_time;
//#endif //#endif
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -44,47 +41,47 @@ static XErrorHandler old_handler = 0;
static int dock_xerror = 0; static int dock_xerror = 0;
extern "C" int dock_xerrhandler(Display* dpy, XErrorEvent* err) extern "C" int dock_xerrhandler(Display* dpy, XErrorEvent* err)
{ {
dock_xerror = err->error_code; dock_xerror = err->error_code;
return old_handler(dpy, err); return old_handler(dpy, err);
} }
static void trap_errors() static void trap_errors()
{ {
dock_xerror = 0; dock_xerror = 0;
old_handler = XSetErrorHandler(dock_xerrhandler); old_handler = XSetErrorHandler(dock_xerrhandler);
} }
static bool untrap_errors() static bool untrap_errors()
{ {
XSetErrorHandler(old_handler); XSetErrorHandler(old_handler);
return (dock_xerror == 0); return (dock_xerror == 0);
} }
static bool send_message( static bool send_message(
Display* dpy, /* display */ Display* dpy, /* display */
Window w, /* sender (tray icon window) */ Window w, /* sender (tray icon window) */
long message, /* message opcode */ long message, /* message opcode */
long data1, /* message data 1 */ long data1, /* message data 1 */
long data2, /* message data 2 */ long data2, /* message data 2 */
long data3 /* message data 3 */ long data3 /* message data 3 */
) { ) {
XEvent ev; XEvent ev;
memset(&ev, 0, sizeof(ev)); memset(&ev, 0, sizeof(ev));
ev.xclient.type = ClientMessage; ev.xclient.type = ClientMessage;
ev.xclient.window = w; ev.xclient.window = w;
ev.xclient.message_type = XInternAtom (dpy, "_NET_SYSTEM_TRAY_OPCODE", False ); ev.xclient.message_type = XInternAtom (dpy, "_NET_SYSTEM_TRAY_OPCODE", False );
ev.xclient.format = 32; ev.xclient.format = 32;
ev.xclient.data.l[0] = CurrentTime; ev.xclient.data.l[0] = CurrentTime;
ev.xclient.data.l[1] = message; ev.xclient.data.l[1] = message;
ev.xclient.data.l[2] = data1; ev.xclient.data.l[2] = data1;
ev.xclient.data.l[3] = data2; ev.xclient.data.l[3] = data2;
ev.xclient.data.l[4] = data3; ev.xclient.data.l[4] = data3;
trap_errors(); trap_errors();
XSendEvent(dpy, w, False, NoEventMask, &ev); XSendEvent(dpy, w, False, NoEventMask, &ev);
XSync(dpy, False); XSync(dpy, False);
return untrap_errors(); return untrap_errors();
} }
#define SYSTEM_TRAY_REQUEST_DOCK 0 #define SYSTEM_TRAY_REQUEST_DOCK 0
@ -98,123 +95,125 @@ static bool send_message(
class TrayIcon::TrayIconPrivate : public QWidget class TrayIcon::TrayIconPrivate : public QWidget
{ {
public: public:
TrayIconPrivate(TrayIcon *object, int size); TrayIconPrivate(TrayIcon *object, int size);
~TrayIconPrivate() { } ~TrayIconPrivate() { }
virtual void initWM(WId icon); virtual void initWM(WId icon);
virtual void setPixmap(const QPixmap &pm); virtual void setPixmap(const QPixmap &pm);
virtual void paintEvent(QPaintEvent *); virtual void paintEvent(QPaintEvent *);
virtual void enterEvent(QEvent *); virtual void enterEvent(QEvent *);
virtual void mouseMoveEvent(QMouseEvent *e); virtual void mouseMoveEvent(QMouseEvent *e);
virtual void mousePressEvent(QMouseEvent *e); virtual void mousePressEvent(QMouseEvent *e);
virtual void mouseReleaseEvent(QMouseEvent *e); virtual void mouseReleaseEvent(QMouseEvent *e);
virtual void mouseDoubleClickEvent(QMouseEvent *e); virtual void mouseDoubleClickEvent(QMouseEvent *e);
virtual void closeEvent(QCloseEvent *e); virtual void closeEvent(QCloseEvent *e);
private: private:
TrayIcon *iconObject; TrayIcon *iconObject;
QPixmap pix; QPixmap pix;
int size; int size;
}; };
TrayIcon::TrayIconPrivate::TrayIconPrivate(TrayIcon *object, int _size) TrayIcon::TrayIconPrivate::TrayIconPrivate(TrayIcon *object, int _size)
: QWidget(0, object->name(), WRepaintNoErase) : QWidget(0/*, object->name(), Qt::WRepaintNoErase*/)
{ {
iconObject = object; iconObject = object;
size = _size; size = _size;
setAttribute(Qt::WA_NoBackground);
setFocusPolicy(Qt::NoFocus);
//setBackgroundMode(X11ParentRelative);
setFocusPolicy(NoFocus); setMinimumSize(size, size);
setBackgroundMode(X11ParentRelative); setMaximumSize(size, size);
setMinimumSize(size, size);
setMaximumSize(size, size);
} }
// This base stuff is required by both FreeDesktop specification and WindowMaker // This base stuff is required by both FreeDesktop specification and WindowMaker
void TrayIcon::TrayIconPrivate::initWM(WId icon) void TrayIcon::TrayIconPrivate::initWM(WId icon)
{ {
Display *dsp = x11Display(); Display *dsp = x11Info().display();
WId leader = winId(); WId leader = winId();
// set the class hint // set the class hint
XClassHint classhint; XClassHint classhint;
classhint.res_name = (char*)"psidock"; classhint.res_name = (char*)"psidock";
classhint.res_class = (char*)"Psi"; classhint.res_class = (char*)"Psi";
XSetClassHint(dsp, leader, &classhint); XSetClassHint(dsp, leader, &classhint);
// set the Window Manager hints // set the Window Manager hints
XWMHints *hints; XWMHints *hints;
hints = XGetWMHints(dsp, leader); // init hints hints = XGetWMHints(dsp, leader); // init hints
hints->flags = WindowGroupHint | IconWindowHint | StateHint; // set the window group hint hints->flags = WindowGroupHint | IconWindowHint | StateHint; // set the window group hint
hints->window_group = leader; // set the window hint hints->window_group = leader; // set the window hint
hints->initial_state = WithdrawnState; // initial state hints->initial_state = WithdrawnState; // initial state
hints->icon_window = icon; // in WM, this should be winId() of separate widget hints->icon_window = icon; // in WM, this should be winId() of separate widget
hints->icon_x = 0; hints->icon_x = 0;
hints->icon_y = 0; hints->icon_y = 0;
XSetWMHints(dsp, leader, hints); // set the window hints for WM to use. XSetWMHints(dsp, leader, hints); // set the window hints for WM to use.
XFree( hints ); XFree( hints );
} }
void TrayIcon::TrayIconPrivate::setPixmap(const QPixmap &pm) void TrayIcon::TrayIconPrivate::setPixmap(const QPixmap &pm)
{ {
pix = pm; pix = pm;
setIcon(pix); setWindowIcon(pix);
repaint(); repaint();
} }
void TrayIcon::TrayIconPrivate::paintEvent(QPaintEvent *) void TrayIcon::TrayIconPrivate::paintEvent(QPaintEvent *)
{ {
QPainter p(this); QPainter p(this);
p.drawPixmap((width() - pix.width())/2, (height() - pix.height())/2, pix); p.drawPixmap((width() - pix.width())/2, (height() - pix.height())/2, pix);
} }
void TrayIcon::TrayIconPrivate::enterEvent(QEvent *e) void TrayIcon::TrayIconPrivate::enterEvent(QEvent *e)
{ {
// Taken from KSystemTray.. // Taken from KSystemTray..
//#if QT_VERSION < 0x030200 //#if QT_VERSION < 0x030200
//if ( !qApp->focusWidget() ) { //if ( !qApp->focusWidget() ) {
XEvent ev; XEvent ev;
memset(&ev, 0, sizeof(ev)); memset(&ev, 0, sizeof(ev));
ev.xfocus.display = qt_xdisplay(); ev.xfocus.display = x11Info().display();//qt_xdisplay();
ev.xfocus.type = FocusIn; ev.xfocus.type = FocusIn;
ev.xfocus.window = winId(); ev.xfocus.window = winId();
ev.xfocus.mode = NotifyNormal; ev.xfocus.mode = NotifyNormal;
ev.xfocus.detail = NotifyAncestor; ev.xfocus.detail = NotifyAncestor;
Time time = qt_x_time; Time time = x11Info().appTime();//qt_x_time;
qt_x_time = 1; //qt_x_time = 1;
qApp->x11ProcessEvent( &ev ); x11Info().setAppTime(1);
qt_x_time = time; qApp->x11ProcessEvent( &ev );
//} //qt_x_time = time;
x11Info().setAppTime(time);
//}
//#endif //#endif
QWidget::enterEvent(e); QWidget::enterEvent(e);
} }
void TrayIcon::TrayIconPrivate::mouseMoveEvent(QMouseEvent *e) void TrayIcon::TrayIconPrivate::mouseMoveEvent(QMouseEvent *e)
{ {
QApplication::sendEvent(iconObject, e); QApplication::sendEvent(iconObject, e);
} }
void TrayIcon::TrayIconPrivate::mousePressEvent(QMouseEvent *e) void TrayIcon::TrayIconPrivate::mousePressEvent(QMouseEvent *e)
{ {
QApplication::sendEvent(iconObject, e); QApplication::sendEvent(iconObject, e);
} }
void TrayIcon::TrayIconPrivate::mouseReleaseEvent(QMouseEvent *e) void TrayIcon::TrayIconPrivate::mouseReleaseEvent(QMouseEvent *e)
{ {
QApplication::sendEvent(iconObject, e); QApplication::sendEvent(iconObject, e);
} }
void TrayIcon::TrayIconPrivate::mouseDoubleClickEvent(QMouseEvent *e) void TrayIcon::TrayIconPrivate::mouseDoubleClickEvent(QMouseEvent *e)
{ {
QApplication::sendEvent(iconObject, e); QApplication::sendEvent(iconObject, e);
} }
void TrayIcon::TrayIconPrivate::closeEvent(QCloseEvent *e) void TrayIcon::TrayIconPrivate::closeEvent(QCloseEvent *e)
{ {
iconObject->gotCloseEvent(); iconObject->gotCloseEvent();
e->accept(); e->accept();
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -224,43 +223,43 @@ void TrayIcon::TrayIconPrivate::closeEvent(QCloseEvent *e)
class TrayIconFreeDesktop : public TrayIcon::TrayIconPrivate class TrayIconFreeDesktop : public TrayIcon::TrayIconPrivate
{ {
public: public:
TrayIconFreeDesktop(TrayIcon *object, const QPixmap &pm); TrayIconFreeDesktop(TrayIcon *object, const QPixmap &pm);
}; };
TrayIconFreeDesktop::TrayIconFreeDesktop(TrayIcon *object, const QPixmap &pm) TrayIconFreeDesktop::TrayIconFreeDesktop(TrayIcon *object, const QPixmap &pm)
: TrayIconPrivate(object, 22) : TrayIconPrivate(object, 22)
{ {
initWM( winId() ); initWM( winId() );
// initialize NetWM // initialize NetWM
Display *dsp = x11Display(); Display *dsp = x11Info().display();//x11Display();
// dock the widget (adapted from SIM-ICQ) // dock the widget (adapted from SIM-ICQ)
Screen *screen = XDefaultScreenOfDisplay(dsp); // get the screen Screen *screen = XDefaultScreenOfDisplay(dsp); // get the screen
int screen_id = XScreenNumberOfScreen(screen); // and it's number int screen_id = XScreenNumberOfScreen(screen); // and it's number
char buf[32]; char buf[32];
snprintf(buf, sizeof(buf), "_NET_SYSTEM_TRAY_S%d", screen_id); snprintf(buf, sizeof(buf), "_NET_SYSTEM_TRAY_S%d", screen_id);
Atom selection_atom = XInternAtom(dsp, buf, false); Atom selection_atom = XInternAtom(dsp, buf, false);
XGrabServer(dsp); XGrabServer(dsp);
Window manager_window = XGetSelectionOwner(dsp, selection_atom); Window manager_window = XGetSelectionOwner(dsp, selection_atom);
if ( manager_window != None ) if ( manager_window != None )
XSelectInput(dsp, manager_window, StructureNotifyMask); XSelectInput(dsp, manager_window, StructureNotifyMask);
XUngrabServer(dsp); XUngrabServer(dsp);
XFlush(dsp); XFlush(dsp);
if ( manager_window != None ) if ( manager_window != None )
send_message(dsp, manager_window, SYSTEM_TRAY_REQUEST_DOCK, winId(), 0, 0); send_message(dsp, manager_window, SYSTEM_TRAY_REQUEST_DOCK, winId(), 0, 0);
// some KDE mumbo-jumbo... why is it there? anybody? // some KDE mumbo-jumbo... why is it there? anybody?
Atom kwm_dockwindow_atom = XInternAtom(dsp, "KWM_DOCKWINDOW", false); Atom kwm_dockwindow_atom = XInternAtom(dsp, "KWM_DOCKWINDOW", false);
Atom kde_net_system_tray_window_for_atom = XInternAtom(dsp, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false); Atom kde_net_system_tray_window_for_atom = XInternAtom(dsp, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
long data = 0; long data = 0;
XChangeProperty(dsp, winId(), kwm_dockwindow_atom, kwm_dockwindow_atom, 32, PropModeReplace, (uchar*)&data, 1); XChangeProperty(dsp, winId(), kwm_dockwindow_atom, kwm_dockwindow_atom, 32, PropModeReplace, (uchar*)&data, 1);
XChangeProperty(dsp, winId(), kde_net_system_tray_window_for_atom, XA_WINDOW, 32, PropModeReplace, (uchar*)&data, 1); XChangeProperty(dsp, winId(), kde_net_system_tray_window_for_atom, XA_WINDOW, 32, PropModeReplace, (uchar*)&data, 1);
setPixmap(pm); setPixmap(pm);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -270,58 +269,58 @@ TrayIconFreeDesktop::TrayIconFreeDesktop(TrayIcon *object, const QPixmap &pm)
class TrayIconWharf : public TrayIcon::TrayIconPrivate class TrayIconWharf : public TrayIcon::TrayIconPrivate
{ {
public: public:
TrayIconWharf(TrayIcon *object, const QPixmap &pm) TrayIconWharf(TrayIcon *object, const QPixmap &pm)
: TrayIconPrivate(object, 64) : TrayIconPrivate(object, 64)
{ {
setPixmap(pm); setPixmap(pm);
} }
void setPixmap(const QPixmap &_pm) void setPixmap(const QPixmap &_pm)
{ {
QPixmap pm; QPixmap pm;
QImage i = _pm.convertToImage(); QImage i = _pm.toImage();
i = i.scale(i.width() * 2, i.height() * 2); i = i.scaled(i.width() * 2, i.height() * 2);
pm.convertFromImage(i); pm = QPixmap::fromImage(i);
TrayIconPrivate::setPixmap(pm); TrayIconPrivate::setPixmap(pm);
// thanks to Robert Spier for this: // thanks to Robert Spier for this:
// for some reason the repaint() isn't being honored, or isn't for // for some reason the repaint() isn't being honored, or isn't for
// the icon. So force one on the widget behind the icon // the icon. So force one on the widget behind the icon
erase(); //erase();
QPaintEvent pe( rect() ); QPaintEvent pe( rect() );
paintEvent(&pe); paintEvent(&pe);
} }
}; };
class TrayIconWindowMaker : public TrayIcon::TrayIconPrivate class TrayIconWindowMaker : public TrayIcon::TrayIconPrivate
{ {
public: public:
TrayIconWindowMaker(TrayIcon *object, const QPixmap &pm); TrayIconWindowMaker(TrayIcon *object, const QPixmap &pm);
~TrayIconWindowMaker(); ~TrayIconWindowMaker();
void setPixmap(const QPixmap &pm); void setPixmap(const QPixmap &pm);
private: private:
TrayIconWharf *wharf; TrayIconWharf *wharf;
}; };
TrayIconWindowMaker::TrayIconWindowMaker(TrayIcon *object, const QPixmap &pm) TrayIconWindowMaker::TrayIconWindowMaker(TrayIcon *object, const QPixmap &pm)
: TrayIconPrivate(object, 32) : TrayIconPrivate(object, 32)
{ {
wharf = new TrayIconWharf(object, pm); wharf = new TrayIconWharf(object, pm);
initWM( wharf->winId() ); initWM( wharf->winId() );
} }
TrayIconWindowMaker::~TrayIconWindowMaker() TrayIconWindowMaker::~TrayIconWindowMaker()
{ {
delete wharf; delete wharf;
} }
void TrayIconWindowMaker::setPixmap(const QPixmap &pm) void TrayIconWindowMaker::setPixmap(const QPixmap &pm)
{ {
wharf->setPixmap(pm); wharf->setPixmap(pm);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -330,43 +329,46 @@ void TrayIconWindowMaker::setPixmap(const QPixmap &pm)
void TrayIcon::sysInstall() void TrayIcon::sysInstall()
{ {
if ( d ) if ( d )
return; return;
if ( v_isWMDock ) if ( v_isWMDock )
d = (TrayIconPrivate *)(new TrayIconWindowMaker(this, pm)); d = (TrayIconPrivate *)(new TrayIconWindowMaker(this, pm));
else else
d = (TrayIconPrivate *)(new TrayIconFreeDesktop(this, pm)); d = (TrayIconPrivate *)(new TrayIconFreeDesktop(this, pm));
sysUpdateToolTip(); sysUpdateToolTip();
d->show(); d->show();
} }
void TrayIcon::sysRemove() void TrayIcon::sysRemove()
{ {
if ( !d ) if ( !d )
return; return;
delete d; delete d;
d = 0; d = 0;
} }
void TrayIcon::sysUpdateIcon() void TrayIcon::sysUpdateIcon()
{ {
if ( !d ) if ( !d )
return; return;
QPixmap pix = pm; QPixmap pix = pm;
d->setPixmap(pix); d->setPixmap(pix);
} }
void TrayIcon::sysUpdateToolTip() void TrayIcon::sysUpdateToolTip()
{ {
if ( !d ) if ( !d )
return; return;
if ( tip.isEmpty() ) if ( tip.isEmpty() ) {
QToolTip::remove(d); //QToolTip::remove(d);
else d->setToolTip(QString());
QToolTip::add(d, tip); } else {
//QToolTip::add(d, tip);
d->setToolTip(tip);
}
} }