wfview/controllersetup.h

224 wiersze
5.6 KiB
C

2022-10-22 19:55:08 +00:00
#ifndef CONTROLLERSETUP_H
#define CONTROLLERSETUP_H
#include <QDialog>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsTextItem>
#include <QGraphicsPixmapItem>
2023-04-09 22:53:51 +00:00
#include <QGraphicsRectItem>
2022-04-22 10:11:21 +00:00
#include <QPoint>
#include <QGraphicsSceneMouseEvent>
2022-04-25 16:40:41 +00:00
#include <QVector>
#include <QRect>
#include <QComboBox>
#include <QLabel>
2022-04-25 16:44:32 +00:00
#include <QGraphicsProxyWidget>
#include <QAbstractItemView>
2023-03-17 23:35:40 +00:00
#include <QHBoxLayout>
#include <QGridLayout>
#include <QPushButton>
#include <QScopedPointer>
#include <QCheckBox>
#include <QFileDialog>
2023-03-29 22:33:18 +00:00
#include <QMessageBox>
#include <QLayoutItem>
#include <QDebug>
2022-04-25 16:40:41 +00:00
#include <QObject>
2023-02-12 16:45:21 +00:00
#include <QColorDialog>
2023-03-17 23:35:40 +00:00
#include <QWidget>
#include <QSpinBox>
#include <QCheckBox>
2022-04-22 10:11:21 +00:00
#include "usbcontroller.h"
2023-03-17 23:35:40 +00:00
class controllerScene : public QGraphicsScene
{
Q_OBJECT
QGraphicsLineItem* item = Q_NULLPTR;
signals:
2023-04-09 22:53:51 +00:00
void showMenu(controllerScene* scene, QPoint p);
void buttonAction(bool pressed, QPoint p);
2023-03-17 23:35:40 +00:00
protected:
void mousePressEvent(QGraphicsSceneMouseEvent* event) {
if (event->button() == Qt::RightButton)
{
2023-04-09 22:53:51 +00:00
emit showMenu(this, event->scenePos().toPoint());
}
else if (event->button() == Qt::LeftButton)
{
// Simulate a button press
emit buttonAction(true,event->scenePos().toPoint());
2023-03-17 23:35:40 +00:00
}
else
{
QGraphicsScene::mousePressEvent(event);
}
}
2023-04-09 22:53:51 +00:00
void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) {
if (event->button() == Qt::LeftButton)
{
// Simulate a button release
emit buttonAction(false,event->scenePos().toPoint());
}
else
{
QGraphicsScene::mouseReleaseEvent(event);
}
}
2023-03-17 23:35:40 +00:00
};
struct tabContent {
2023-04-15 10:25:35 +00:00
QWidget* tab;
QVBoxLayout* mainLayout;
QHBoxLayout* topLayout;
QWidget* widget;
QVBoxLayout* layout;
QCheckBox* disabled;
QLabel* message;
QGraphicsView* view;
QLabel* pageLabel;
QSpinBox* page;
QHBoxLayout* sensLayout;
QLabel* sensLabel;
QSlider* sens;
QImage* image;
QGraphicsItem* bgImage = Q_NULLPTR;
controllerScene* scene = Q_NULLPTR;
2023-04-15 10:25:35 +00:00
QGridLayout* grid;
QLabel* brightLabel;
QComboBox* brightness;
QLabel* speedLabel;
QComboBox* speed;
QLabel* orientLabel;
QComboBox* orientation;
QLabel* colorLabel;
QPushButton* color;
QLabel* timeoutLabel;
QSpinBox* timeout;
QLabel* pagesLabel;
QSpinBox* pages;
QLabel* helpText;
};
namespace Ui {
2022-10-22 19:55:08 +00:00
class controllerSetup;
}
2022-10-22 19:55:08 +00:00
class controllerSetup : public QDialog
{
Q_OBJECT
public:
2022-10-22 19:55:08 +00:00
explicit controllerSetup(QWidget* parent = 0);
~controllerSetup();
2022-05-17 07:53:24 +00:00
signals:
void started();
2023-04-09 22:53:51 +00:00
void sendRequest(USBDEVICE* dev, usbFeatureType request, int val=0, QString text="", QImage* img=Q_NULLPTR, QColor* color=Q_NULLPTR);
void programDisable(USBDEVICE* dev, bool disable);
void programPages(USBDEVICE* dev, int pages);
2023-04-09 22:53:51 +00:00
void backup(USBDEVICE* dev, QString path);
void restore(USBDEVICE *dev, QString path);
2022-05-17 07:53:24 +00:00
public slots:
void init(usbDevMap* dev, QVector<BUTTON>* but, QVector<KNOB>* kb, QVector<COMMAND>* cmd, QMutex* mut);
void newDevice(USBDEVICE* dev);
2023-03-17 23:35:40 +00:00
void removeDevice(USBDEVICE* dev);
2023-04-09 22:53:51 +00:00
void showMenu(controllerScene *scene,QPoint p);
2022-04-22 10:11:21 +00:00
void onEventIndexChanged(int index);
void offEventIndexChanged(int index);
2023-02-09 13:21:51 +00:00
void knobEventIndexChanged(int index);
void ledNumberChanged(int index);
void sensitivityMoved(USBDEVICE* dev, int val);
void brightnessChanged(USBDEVICE* dev, int index);
void orientationChanged(USBDEVICE* dev, int index);
void speedChanged(USBDEVICE* dev, int index);
void colorPicker(USBDEVICE* dev, QPushButton* btn, QColor color);
void buttonOnColorClicked();
void buttonOffColorClicked();
void buttonIconClicked();
void latchStateChanged(int state);
void timeoutChanged(USBDEVICE* dev, int val);
void pageChanged(USBDEVICE* dev, int val);
void pagesChanged(USBDEVICE* dev, int val);
void disableClicked(USBDEVICE* dev, bool clicked, QWidget* widget);
void setConnected(USBDEVICE* dev);
2023-03-25 16:58:28 +00:00
void hideEvent(QHideEvent *event);
2023-03-28 18:07:54 +00:00
void on_tabWidget_currentChanged(int index);
2023-03-29 22:33:18 +00:00
void on_backupButton_clicked();
void on_restoreButton_clicked();
private:
2022-09-18 20:00:44 +00:00
usbDeviceType type = usbNone;
2022-10-22 19:55:08 +00:00
Ui::controllerSetup* ui;
QGraphicsTextItem* textItem;
2022-04-22 10:11:21 +00:00
QLabel* imgLabel;
unsigned char currentDevice = 0;
QVector<BUTTON>* buttons;
2023-02-09 13:21:51 +00:00
QVector<KNOB>* knobs;
2022-04-25 16:40:41 +00:00
QVector<COMMAND>* commands;
usbDevMap* devices;
2023-02-09 13:21:51 +00:00
BUTTON* currentButton = Q_NULLPTR;
KNOB* currentKnob = Q_NULLPTR;
// Update Dialog
2023-03-28 18:07:54 +00:00
QDialog * updateDialog = Q_NULLPTR;
QComboBox* onEvent;
QComboBox* offEvent;
QComboBox* knobEvent;
QLabel* onLabel;
QLabel* offLabel;
QLabel* knobLabel;
QPushButton* buttonOnColor;
QPushButton* buttonOffColor;
QCheckBox *buttonLatch;
QPushButton* buttonIcon;
QLabel* iconLabel;
QSpinBox* ledNumber;
2022-05-17 07:53:24 +00:00
QString deviceName;
2023-02-10 15:23:57 +00:00
QMutex* mutex;
2023-02-12 16:45:21 +00:00
QColor initialColor = Qt::white;
2022-04-22 10:11:21 +00:00
2023-03-17 23:35:40 +00:00
QLabel* noControllersText;
int numTabs=0;
QMap<QString,tabContent*> tabs;
2023-03-17 23:35:40 +00:00
// Below are used for each tab:
/*
QList<QWidget *> tabs;
QList<QVBoxLayout *> layouts;
QList<QWidget *> widgets;
QList<QGraphicsView *> graphicsViews;
QList<QGraphicsScene*> scenes;
QList<QGraphicsItem*> bgImages;
QList<QSlider *>sensitivitys;
// Just used for QuickKeys device
QList<QComboBox *>brightCombos;
QList<QComboBox *>speedCombos;
QList<QComboBox *>orientCombos;
QList<QPushButton *>colorButtons;
QList<QSpinBox *>timeoutSpins;
*/
};
2022-04-22 10:11:21 +00:00
2022-04-22 10:11:21 +00:00
2023-03-17 23:35:40 +00:00
#endif