Skip to content

Commit

Permalink
Created basis for JoyMix slot - AntiMicroX#93
Browse files Browse the repository at this point in the history
JoyMix slot holds many other slots
  • Loading branch information
juliagoda committed Mar 19, 2020
1 parent 0f30ba0 commit c2a10b2
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 10 deletions.
38 changes: 29 additions & 9 deletions src/advancebuttondialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,22 +539,27 @@ void AdvanceButtonDialog::joinSlot()
QListWidgetItem* firstSelected = ui->slotListWidget->selectedItems().at(0);
QString text = "";
int index = ui->slotListWidget->row(firstSelected);
bool firstTime = true;
bool firstTime = true;
SimpleKeyGrabberButton *blankButton = new SimpleKeyGrabberButton(this);
QList<JoyButtonSlot*>* joinedBtnSlots = new QList<JoyButtonSlot*>();


for(auto item : ui->slotListWidget->selectedItems())
{
if (!firstTime) text += "+";
firstTime = false;
SimpleKeyGrabberButton* firstGrabBtn = item->data(Qt::UserRole).value<SimpleKeyGrabberButton*>();

// blankButton->getValue()->getMixSlots()->append(firstGrabBtn->getValue());
QListWidgetItem* it = ui->slotListWidget->takeItem(ui->slotListWidget->row(item));
SimpleKeyGrabberButton* firstGrabBtn = it->data(Qt::UserRole).value<SimpleKeyGrabberButton*>();
joinedBtnSlots->append(firstGrabBtn->getValue());
text += firstGrabBtn->getValue()->getSlotString();
}

qDebug() << "Joined slot has " << joinedBtnSlots->count() << " slots in";
// it can be used as reusable code
deleteSlot();
// deleteSlot();

SimpleKeyGrabberButton *blankButton = new SimpleKeyGrabberButton(this);
QListWidgetItem *joinedItem = new QListWidgetItem();

ui->slotListWidget->insertItem(index, joinedItem);
Expand All @@ -569,16 +574,31 @@ void AdvanceButtonDialog::joinSlot()
ui->slotListWidget->setItemWidget(joinedItem, widget);
ui->slotListWidget->setCurrentItem(joinedItem);
blankButton->setText(text); // temporarily
connectButtonEvents(blankButton);
blankButton->setValues(text, joinedBtnSlots, JoyButtonSlot::JoyMix);
//blankButton->getValue()->setMixSlots(joinedBtnSlots);
//connectButtonEvents(blankButton);
//blankButton->refreshButtonLabel(); // instead of blankButton->setText(text);

//QMetaObject::invokeMethod(&helper, "insertAssignedSlot", Qt::BlockingQueuedConnection,
// Q_ARG(int, 0), Q_ARG(uint, 0),
// Q_ARG(int, current));
//QMetaObject::invokeMethod(&helper, "setAssignedSlot", Qt::BlockingQueuedConnection,
// Q_ARG(JoyButtonSlot*, blankButton->getValue()),
// Q_ARG(int, index));

updateSlotsScrollArea(0);

//


// track for multiple keys in one slot:

// connectButtonEvents
// setAssignedSlot
// insertAssignedSlot
// releaseActiveSlots
// buildActiveZoneSummary
// getActiveZoneList
// slot->getSlotMode() should be marked as mix and contain mini slots in

// generally to know where to put changes find places of JoySlotInputAction::JoyCycle for example
// and add adequate changes next to other input actions
}


Expand Down
37 changes: 37 additions & 0 deletions src/joybuttonslot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ JoyButtonSlot::JoyButtonSlot(QObject *parent) :
previousDistance = 0.0;
qkeyaliasCode = 0;
easingActive = false;
mix_slots = new QList<JoyButtonSlot*>();
}

JoyButtonSlot::JoyButtonSlot(int code, JoySlotInputAction mode, QObject *parent) :
Expand All @@ -56,6 +57,7 @@ JoyButtonSlot::JoyButtonSlot(int code, JoySlotInputAction mode, QObject *parent)
m_mode = mode;
m_distance = 0.0;
easingActive = false;
mix_slots = new QList<JoyButtonSlot*>();
}

JoyButtonSlot::JoyButtonSlot(int code, int alias, JoySlotInputAction mode, QObject *parent) :
Expand All @@ -74,6 +76,7 @@ JoyButtonSlot::JoyButtonSlot(int code, int alias, JoySlotInputAction mode, QObje
m_mode = mode;
m_distance = 0.0;
easingActive = false;
mix_slots = new QList<JoyButtonSlot*>();
}

JoyButtonSlot::JoyButtonSlot(JoyButtonSlot *slot, QObject *parent) :
Expand All @@ -89,6 +92,7 @@ JoyButtonSlot::JoyButtonSlot(JoyButtonSlot *slot, QObject *parent) :
easingActive = false;
m_textData = slot->getTextData();
extraData = slot->getExtraData();
mix_slots = slot->getMixSlots();
}

JoyButtonSlot::JoyButtonSlot(QString text, JoySlotInputAction mode, QObject *parent) :
Expand All @@ -102,6 +106,7 @@ JoyButtonSlot::JoyButtonSlot(QString text, JoySlotInputAction mode, QObject *par
m_mode = mode;
m_distance = 0.0;
easingActive = false;
mix_slots = new QList<JoyButtonSlot*>();

if ((mode == JoyLoadProfile) ||
(mode == JoyTextEntry) ||
Expand Down Expand Up @@ -431,6 +436,19 @@ QString JoyButtonSlot::getSlotString()

newlabel.append(tr("[Exec] %1").arg(temp));

break;
}
case JoyMix:
{
if (!m_textData.isEmpty())
{
newlabel.append(tr("Mix %1").arg(m_textData));
}
else
{
qDebug() << "text data of JoyMix slot is empty!";
}

break;
}
}
Expand Down Expand Up @@ -520,6 +538,19 @@ QVariant JoyButtonSlot::getExtraData()
return extraData;
}


QList<JoyButtonSlot*> *JoyButtonSlot::getMixSlots()
{
return mix_slots;
}


void JoyButtonSlot::setMixSlots(QList<JoyButtonSlot*> *mixSlots)
{
mix_slots = mixSlots;
}


bool JoyButtonSlot::isValidSlot()
{
qInstallMessageHandler(MessageHandler::myMessageOutput);
Expand All @@ -542,6 +573,12 @@ bool JoyButtonSlot::isValidSlot()

break;
}
case JoyMix:
{
if (mix_slots->count() == 0) return false;

break;
}
default:
{
break;
Expand Down
6 changes: 5 additions & 1 deletion src/joybuttonslot.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class JoyButtonSlot : public QObject
enum JoySlotInputAction {JoyKeyboard=0, JoyMouseButton, JoyMouseMovement,
JoyPause, JoyHold, JoyCycle, JoyDistance,
JoyRelease, JoyMouseSpeedMod, JoyKeyPress, JoyDelay,
JoyLoadProfile, JoySetChange, JoyTextEntry, JoyExecute};
JoyLoadProfile, JoySetChange, JoyTextEntry, JoyExecute, JoyMix};

enum JoySlotMouseDirection {MouseUp=1, MouseDown, MouseLeft, MouseRight};
enum JoySlotMouseWheelButton {MouseWheelUp=4, MouseWheelDown=5,
Expand Down Expand Up @@ -77,12 +77,16 @@ class JoyButtonSlot : public QObject
void setExtraData(QVariant data);
QVariant getExtraData();

void setMixSlots(QList<JoyButtonSlot*>* slots);
QList<JoyButtonSlot*>* getMixSlots();

bool isValidSlot();

private:
int deviceCode;
int qkeyaliasCode;
JoySlotInputAction m_mode;
QList<JoyButtonSlot*>* mix_slots;
double m_distance;
double previousDistance;
QElapsedTimer mouseInterval;
Expand Down
28 changes: 28 additions & 0 deletions src/simplekeygrabberbutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,34 @@ void SimpleKeyGrabberButton::setValue(QString value, JoyButtonSlot::JoySlotInput
edited = true;
break;
}
case JoyButtonSlot::JoyMix:
{
break;
}
default:
{
break;
}
}

setText(buttonslot.getSlotString());
}

void SimpleKeyGrabberButton::setValues(QString value, QList<JoyButtonSlot *> *jbtn, JoyButtonSlot::JoySlotInputAction mode)
{
qInstallMessageHandler(MessageHandler::myMessageOutput);

switch (mode)
{
case JoyButtonSlot::JoyMix:
{
buttonslot.setSlotCode(-1);
buttonslot.setTextData(value);
buttonslot.setSlotMode(JoyButtonSlot::JoyMix);
buttonslot.setMixSlots(jbtn);
edited = true;
break;
}
default:
{
break;
Expand Down
2 changes: 2 additions & 0 deletions src/simplekeygrabberbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ class SimpleKeyGrabberButton : public QPushButton
void setValue(int value, int alias, JoyButtonSlot::JoySlotInputAction mode=JoyButtonSlot::JoyKeyboard); // (.., unsigned)
void setValue(int value, JoyButtonSlot::JoySlotInputAction mode=JoyButtonSlot::JoyKeyboard);
void setValue(QString value, JoyButtonSlot::JoySlotInputAction mode=JoyButtonSlot::JoyLoadProfile);
void setValues(QString value, QList<JoyButtonSlot *> *jbtn, JoyButtonSlot::JoySlotInputAction mode=JoyButtonSlot::JoyMix);
JoyButtonSlot* getValue();
bool isEdited();
bool isGrabbing();


protected:
virtual void keyPressEvent(QKeyEvent *event);
virtual bool eventFilter(QObject *obj, QEvent *event);
Expand Down

0 comments on commit c2a10b2

Please sign in to comment.