首次提交
This commit is contained in:
@@ -0,0 +1,148 @@
|
||||
#ifndef BaseWidgetMenu_H
|
||||
#define BaseWidgetMenu_H
|
||||
#include "YSGraphic_Core/base/Node.hpp"
|
||||
#include "YSGraphic_Core/base/RollObject.h"
|
||||
#include "YSGraphic_Core/export.h"
|
||||
|
||||
#include <QMap>
|
||||
#include <QPushButton>
|
||||
#include <QWidget>
|
||||
|
||||
class QHBoxLayout;
|
||||
class QVBoxLayout;
|
||||
class AbstractTextButton;
|
||||
class AbstractMenuButton;
|
||||
|
||||
|
||||
class BaseWidgetMenu : public QWidget, public YSG::Node<BaseWidgetMenu> {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit BaseWidgetMenu(QWidget* parent);
|
||||
QVBoxLayout *mMainLayout;
|
||||
QHBoxLayout *mFirstLayout;
|
||||
QHBoxLayout *mSecondLayout;
|
||||
AbstractMenuButton *parentBtn{};
|
||||
YSG::RollObject<AbstractMenuButton> mRollObject;
|
||||
BaseWidgetMenu* createSubWidgetMenu(AbstractMenuButton * btn);
|
||||
void esc(BaseWidgetMenu* menu);
|
||||
void confirm();
|
||||
void addMenuButtonOnLayout1(const QVector<AbstractMenuButton *>& buttons, int stretch);
|
||||
void addMenuButtonOnLayout2(const QVector<AbstractMenuButton *>& buttons, int stretch);
|
||||
void addMenuButtonOnLayout1(const QVector<AbstractMenuButton *>& buttons);
|
||||
void addMenuButtonOnLayout2(const QVector<AbstractMenuButton *>& buttons);
|
||||
signals:
|
||||
void showThat();
|
||||
void hideThat();
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
void keyPressEvent(QKeyEvent *event) override;
|
||||
void showEvent(QShowEvent *event) override;
|
||||
void hideEvent(QHideEvent *event) override;
|
||||
};
|
||||
|
||||
class AbstractMenuButton : public QPushButton {
|
||||
public:
|
||||
AbstractMenuButton() = default;
|
||||
BaseWidgetMenu *mParentMenu{};
|
||||
BaseWidgetMenu *mOwnMenu{};
|
||||
bool mClickHide = true;
|
||||
void init(int fontSize){
|
||||
setFocusPolicy(Qt::NoFocus);
|
||||
setFlat(true);
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
setCheckable(true);
|
||||
setChecked(false);
|
||||
QFont font;
|
||||
font.setPixelSize(fontSize);
|
||||
setFont(font);
|
||||
}
|
||||
|
||||
void mousePressEvent(QMouseEvent *e) override {
|
||||
mParentMenu->mRollObject.setCur(this);
|
||||
mParentMenu->confirm();
|
||||
}
|
||||
|
||||
void hideRoot();
|
||||
};
|
||||
|
||||
class MenuButton : public AbstractMenuButton{
|
||||
public:
|
||||
std::function<void(void)> mClick = nullptr;
|
||||
MenuButton(const QString &text, int fontSize, const std::function<void(void)> &click){
|
||||
mClick = click;
|
||||
setText(text);
|
||||
init(fontSize);
|
||||
connect(this, &AbstractMenuButton::clicked, [this](){
|
||||
mClick();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
class DoubleTextMenuButton : public AbstractMenuButton{
|
||||
public:
|
||||
std::function<void(bool)> mSwitchClick = nullptr;
|
||||
QString mText1, mText2;
|
||||
bool mIsText1 = false;
|
||||
DoubleTextMenuButton(const QString &text1, const QString &text2, int fontSize, const std::function<void(bool)> &click){
|
||||
mClickHide = false;
|
||||
mText1 = text1;
|
||||
mText2 = text2;
|
||||
mSwitchClick = click;
|
||||
setText(text1);
|
||||
init(fontSize);
|
||||
connect(this, &AbstractMenuButton::clicked, [this](){
|
||||
mIsText1 = !mIsText1;
|
||||
mSwitchClick(mIsText1);
|
||||
if(mIsText1){
|
||||
setText(mText2);
|
||||
} else {
|
||||
setText(mText1);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
class ValueMenuButton : public AbstractMenuButton{
|
||||
public:
|
||||
double mValue{};
|
||||
QString mText;
|
||||
std::function<void(ValueMenuButton*, bool add)> mValueChanged;
|
||||
void setValue(double value){
|
||||
mValue = value;
|
||||
setText(mText.arg(mValue));
|
||||
}
|
||||
ValueMenuButton(const QString &text, int fontSize,
|
||||
const std::function<void(ValueMenuButton*,bool)> &valueChanged, double firstValue) {
|
||||
mText = text;
|
||||
init(fontSize);
|
||||
mValueChanged = valueChanged;
|
||||
setValue(firstValue);
|
||||
}
|
||||
};
|
||||
|
||||
// class ValueMenuButton : public AbstractMenuButton{
|
||||
// public:
|
||||
// std::function<void(ValueMenuButton*)> mHandleUp = nullptr;
|
||||
// std::function<void(ValueMenuButton*)> mHandleDown = nullptr;
|
||||
// QString mText;
|
||||
// double mValue{};
|
||||
// ValueMenuButton(const QString &text, int fontSize,
|
||||
// const std::function<void(ValueMenuButton*)> &handleUp,
|
||||
// const std::function<void(ValueMenuButton*)> &handleDown){
|
||||
// mClickHide = false;
|
||||
// mText = text;
|
||||
// mHandleUp = handleUp;
|
||||
// mHandleDown = handleDown;
|
||||
// setValue(mValue);
|
||||
// init(fontSize);
|
||||
// }
|
||||
// void setValue(double value){
|
||||
// mValue = value;
|
||||
// setText(mText.arg(mValue));
|
||||
// }
|
||||
// };
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user