242 lines
6.1 KiB
C++
242 lines
6.1 KiB
C++
#pragma once
|
|
|
|
#include "qtcommon.h"
|
|
#include "contclasses.h"
|
|
#include "settings.h"
|
|
|
|
class MeterSlider;
|
|
|
|
enum SpawnPos {
|
|
LEFT = (1 << 1),
|
|
RIGHT = (0 << 1),
|
|
UP = (1 << 0),
|
|
DOWN = (0 << 0)
|
|
};
|
|
|
|
enum CustomQEvent {
|
|
EndpointWidgetObsolete = 1001,
|
|
EndpointWidgetCreated = 1002,
|
|
EndpointDefaultChange = 1003,
|
|
SessionWidgetCreated = 1004,
|
|
SessionWidgetObsolete = 1005,
|
|
RecomposeMainWindow = 1006,
|
|
EndpointRoleChange = 1007
|
|
};
|
|
|
|
class DarkModeEventFilter : public QAbstractNativeEventFilter {
|
|
|
|
public:
|
|
bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *) override;
|
|
};
|
|
|
|
template <typename T>
|
|
class CustomWidgetEvent : public QEvent {
|
|
|
|
public:
|
|
CustomWidgetEvent(QEvent::Type type, T payload);
|
|
T payload;
|
|
};
|
|
//Q_DECLARE_METATYPE(EndpointWidgetEvent)
|
|
|
|
class ExtendedCheckBox : public QCheckBox {
|
|
Q_OBJECT
|
|
protected:
|
|
void customEvent(QEvent* ev) override;
|
|
|
|
public:
|
|
//c++11: this inherits all parent's constructors unconditionally
|
|
using QCheckBox::QCheckBox;
|
|
//alternative being calling parent ctor directly after declaring child ctor:
|
|
//B(int x) : A(x) { }
|
|
};
|
|
|
|
class SessionWidget : public QWidget {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent /* = nullptr */);
|
|
~SessionWidget();
|
|
void calculateSize(uint64_t width, uint64_t height);
|
|
std::wstring getName();
|
|
|
|
public slots:
|
|
void updateMainVolume(int newValue);
|
|
void updateMute(int checked);
|
|
|
|
private:
|
|
QLabel *mainLabel = nullptr;
|
|
MeterSlider *mainSlider = nullptr;
|
|
uint64_t idx;
|
|
QHBoxLayout *widgetLayout = nullptr;
|
|
QCheckBox *muteButton = nullptr;
|
|
SessionHandler* sh;
|
|
QTimer* volumePoller = nullptr;
|
|
QSpacerItem* widthSpacer;
|
|
};
|
|
|
|
class ChannelWidget : public QWidget {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
ChannelWidget(uint32_t channelCount, EndpointHandler* eph, QWidget *parent = nullptr);
|
|
//QSize minimumSizeHint() const override;
|
|
//void setMinimum(QSize minimum);
|
|
void updateChannel(int channel);
|
|
uint32_t getChannelCount() const;
|
|
|
|
private:
|
|
const double roundingFactor = 0.005;
|
|
EndpointHandler* eph;
|
|
uint32_t channelCount;
|
|
std::vector<QSlider*> channelSliders;
|
|
std::vector<QLabel*> channelLabels;
|
|
QGridLayout *widgetLayout;
|
|
QSize minimum;
|
|
};
|
|
|
|
class EndpointWidget : public QWidget {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
EndpointWidget(EndpointHandler* eph, QWidget *parent = nullptr, uint64_t idx = INT_MAX);
|
|
//QSize minimumSizeHint() const override;
|
|
//void setMinimum(uint64_t height, double heightRatio);
|
|
void updateChannelsVisibility();
|
|
EndpointHandler* getEndpointHandler();
|
|
std::map<Roles, ExtendedCheckBox*> getDefaultRolesWidgets();
|
|
|
|
void setIndex(uint64_t idx);
|
|
uint64_t getIndex();
|
|
//void setVolume(int channel, float volume);
|
|
void calculateSize(uint64_t width, uint64_t height);
|
|
|
|
~EndpointWidget();
|
|
//void updateMainVolume(float newValue);
|
|
//void updateVolume(uint32_t channel, float newValue);
|
|
//void updateMute(bool muted);
|
|
|
|
//void populateEndpointWidget(EndpointHandler *eph);
|
|
//void setEndpointHandlers(std::vector<EndpointHandler*> *ephs);
|
|
|
|
//protected:
|
|
//bool event(QEvent* ev) override;
|
|
|
|
public slots:
|
|
void updateMainVolume(int newValue);
|
|
void updateMute(int checked);
|
|
|
|
protected:
|
|
void customEvent(QEvent* ev) override;
|
|
|
|
private slots:
|
|
void addSessionWidget(CustomWidgetEvent<SessionHandler*>* ev);
|
|
void removeSessionWidget(CustomWidgetEvent<SessionHandler*>* ev);
|
|
|
|
private:
|
|
int row;
|
|
const int sessionCol = 2;
|
|
QCheckBox *muteButton = nullptr;
|
|
QLabel *mainLabel = nullptr;
|
|
QLabel *mainVolumeLabel = nullptr;
|
|
MeterSlider *mainSlider = nullptr;
|
|
std::vector<QSlider*> channelSliders;
|
|
std::vector<QLabel*> channelLabels;
|
|
QGridLayout *widgetLayout = nullptr;
|
|
QGridLayout *mainMuteLayout = nullptr;
|
|
std::map<Roles, ExtendedCheckBox*> defaultRolesCheckBoxes;
|
|
|
|
EndpointHandler* eph;
|
|
size_t defaultRolesVectorSize = 4;
|
|
QTimer* timer = nullptr;
|
|
uint64_t idx;
|
|
ChannelWidget* cw = nullptr;
|
|
std::vector<SessionWidget*> sessionWidgets;
|
|
QSize minimum;
|
|
//std::vector<EndpointHandler*> *ephs;
|
|
//std::vector<QSlider> *sliders;
|
|
|
|
//signals:
|
|
//void valueChanged(int value);
|
|
|
|
};
|
|
|
|
class HeaderWidget : public QWidget {
|
|
Q_OBJECT
|
|
|
|
public:
|
|
HeaderWidget(QWidget *parent = nullptr);
|
|
|
|
private:
|
|
QGridLayout *widgetLayout;
|
|
//QPushButton *about;
|
|
#ifdef WIN32
|
|
QPushButton *openCP;
|
|
QCheckBox *startup;
|
|
QCheckBox *channels;
|
|
#endif
|
|
};
|
|
|
|
class MainWindow : public QMainWindow {
|
|
Q_OBJECT
|
|
//QWidget *centralWidget;
|
|
|
|
public:
|
|
MainWindow(QWidget *parent = nullptr);
|
|
void reloadEndpointWidgets();
|
|
void compose();
|
|
void updateColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
|
|
|
|
protected:
|
|
void closeEvent(QCloseEvent *event) override;
|
|
void customEvent(QEvent* ev) override;
|
|
QRect setSizePosition(QScreen* screen, int width, int height);
|
|
QScreen* getCurrentScreen();
|
|
void createLayout(QGridLayout *newLayout);
|
|
|
|
private slots:
|
|
void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
|
|
void removeEndpointWidget(CustomWidgetEvent<uint64_t>* ev);
|
|
void addEndpointWidget(CustomWidgetEvent<EndpointHandler*>* ev);
|
|
void reorderEndpointWidgetCollection();
|
|
//TODO: destroy/empty existing EndpointWidgets
|
|
//void setEndpointHandlers(std::vector<EndpointHandler*> *ephs);
|
|
|
|
private:
|
|
//std::vector<EndpointHandler*> *ephs;
|
|
bool eventFilter(QObject *object, QEvent *event) override;
|
|
void flushRoleChanges();
|
|
void changeFrontDefaults(Roles role, EndpointWidget* newDef, EndpointWidget* oldDef);
|
|
|
|
std::vector<EndpointWidget*> ews;
|
|
std::vector<std::pair<Roles, std::wstring>> roleBucketList;
|
|
QWidget *containerWidget;
|
|
QGridLayout *widgetLayout;
|
|
|
|
QSystemTrayIcon *trayIcon;
|
|
QMenu *trayIconMenu;
|
|
QAction *trayIconMenuQuit;
|
|
QAction *trayIconMenuOpenCP;
|
|
QTimer *ewsUpdateTimer;
|
|
static constexpr uint64_t ewsUpdateTimerFrequency = 500;
|
|
double widthRatio = 0.28;
|
|
double dpr = 1.0;
|
|
bool recentlyClosed = false;
|
|
uint8_t recentlyClosedTimerFrequency = 1000;
|
|
QTimer *recentlyClosedTimer;
|
|
|
|
QScrollArea *scrollArea;
|
|
HeaderWidget* hw;
|
|
QToolBar *mainMenuBar;
|
|
QScreen *screen;
|
|
QSpacerItem* lastRowSpacer;
|
|
QLabel* noEndpoints = nullptr;
|
|
|
|
QFont font;
|
|
friend class EndpointWidget;
|
|
//public slots:
|
|
// void setEndpointHandlers(std::vector<EndpointHandler*> *ephs);
|
|
|
|
//signals:
|
|
//void valueChanged(int value);
|
|
|
|
};
|