159 lines
4.2 KiB
C++
159 lines
4.2 KiB
C++
#include "BaseWidgetMenu.h"
|
|
#include "../BaseWidget.h"
|
|
#include <QWheelEvent>
|
|
#include "../BackEnd/MainWidget.h"
|
|
|
|
|
|
|
|
BaseWidgetMenu::BaseWidgetMenu(QWidget* parent) : QWidget(parent){
|
|
setObjectName("BaseWidgetMenu");
|
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
|
mMainLayout = new QVBoxLayout(this);
|
|
mFirstLayout = new QHBoxLayout();
|
|
mMainLayout->addLayout(mFirstLayout, 1);
|
|
mSecondLayout = new QHBoxLayout();
|
|
mMainLayout->addLayout(mSecondLayout, 1);
|
|
mRollObject.mEnterFunc = [](AbstractMenuButton* btn){
|
|
btn->setChecked(true);
|
|
};
|
|
mRollObject.mLeaveFunc = [](AbstractMenuButton* btn){
|
|
btn->setChecked(false);
|
|
};
|
|
hide();
|
|
}
|
|
|
|
void BaseWidgetMenu::paintEvent(QPaintEvent *event) {
|
|
QPainter painter(this);
|
|
painter.setPen(Qt::NoPen);
|
|
QPalette palette = QApplication::style()->standardPalette();
|
|
const QBrush& base1Brush = palette.brush(QPalette::Window);
|
|
painter.setBrush(base1Brush);
|
|
painter.drawRect(rect());
|
|
painter.end();
|
|
}
|
|
|
|
void BaseWidgetMenu::hideEvent(QHideEvent *event) {
|
|
for(auto btn : sons){
|
|
btn->hide();
|
|
}
|
|
emit hideThat();
|
|
event->accept();
|
|
}
|
|
|
|
void BaseWidgetMenu::showEvent(QShowEvent *event) {
|
|
if(!mRollObject.mWidgets.empty()) mRollObject.mEnterFunc(mRollObject.cur());
|
|
emit showThat();
|
|
event->accept();
|
|
}
|
|
|
|
void BaseWidgetMenu::addMenuButtonOnLayout1(const QVector<AbstractMenuButton *>& buttons, int stretch) {
|
|
for(AbstractMenuButton* btn : buttons){
|
|
mFirstLayout->addWidget(btn, 1);
|
|
mRollObject.mWidgets.push_back(btn);
|
|
btn->mParentMenu = this;
|
|
}
|
|
if(stretch != 0) {
|
|
mFirstLayout->addStretch(stretch);
|
|
mFirstLayout->addSpacing(mSecondLayout->spacing() * stretch);
|
|
};
|
|
}
|
|
|
|
void BaseWidgetMenu::addMenuButtonOnLayout2(const QVector<AbstractMenuButton *>& buttons, int stretch) {
|
|
for(AbstractMenuButton* btn : buttons){
|
|
mSecondLayout->addWidget(btn, 1);
|
|
mRollObject.mWidgets.push_back(btn);
|
|
btn->mParentMenu = this;
|
|
}
|
|
|
|
if(stretch != 0) {
|
|
mSecondLayout->addStretch(stretch);
|
|
mSecondLayout->addSpacing(mSecondLayout->spacing() * stretch);
|
|
};
|
|
}
|
|
|
|
void BaseWidgetMenu::addMenuButtonOnLayout1(const QVector<AbstractMenuButton *>& buttons) {
|
|
addMenuButtonOnLayout1(buttons, 5 - buttons.size());
|
|
}
|
|
|
|
void BaseWidgetMenu::addMenuButtonOnLayout2(const QVector<AbstractMenuButton *>& buttons) {
|
|
addMenuButtonOnLayout2(buttons, 5 - buttons.size());
|
|
}
|
|
|
|
BaseWidgetMenu* BaseWidgetMenu::createSubWidgetMenu(AbstractMenuButton *btn) {
|
|
auto ret = new BaseWidgetMenu(parentWidget());
|
|
ret->parentBtn = btn;
|
|
ret->hide();
|
|
ret->father = this;
|
|
sons.push_back(ret);
|
|
btn->mOwnMenu = ret;
|
|
return ret;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BaseWidgetMenu::keyPressEvent(QKeyEvent *event) {
|
|
BackEnd* g = BackEnd::instance();
|
|
if (g->match(event, "右移")) {
|
|
mRollObject.rollRight();
|
|
}
|
|
else if (g->match(event, "左移")) {
|
|
mRollObject.rollLeft();
|
|
}
|
|
else if (g->match(event, "增加")) {
|
|
auto v = dynamic_cast<ValueMenuButton*>(mRollObject.cur());
|
|
if(v){
|
|
v->mValueChanged(v, true);
|
|
}
|
|
}
|
|
else if (g->match(event, "减小")) {
|
|
auto v = dynamic_cast<ValueMenuButton*>(mRollObject.cur());
|
|
if(v){
|
|
v->mValueChanged(v, false);
|
|
}
|
|
}
|
|
else if (g->match(event, "确定")){
|
|
confirm();
|
|
}
|
|
else if (g->match(event, "退出")){
|
|
esc(this);
|
|
return;
|
|
}
|
|
event->ignore();
|
|
}
|
|
|
|
|
|
|
|
void BaseWidgetMenu::confirm() {
|
|
BaseWidgetMenu* m = mRollObject.cur()->mOwnMenu;
|
|
if(m){
|
|
m->resize(size());
|
|
m->move(geometry().topLeft() + QPoint(0, -height()));
|
|
m->raise();
|
|
m->setFocus();
|
|
m->show();
|
|
} else {
|
|
mRollObject.cur()->emit clicked();
|
|
if(mRollObject.cur()->mClickHide){
|
|
rootNode()->hide();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void BaseWidgetMenu::esc(BaseWidgetMenu* menu){
|
|
if(menu->root()){
|
|
MainWidget::instance()->getCurrentBaseWidget()->setFocus();
|
|
} else {
|
|
menu->father->setFocus();
|
|
}
|
|
menu->hide();
|
|
}
|
|
|
|
|
|
void AbstractMenuButton::hideRoot() {
|
|
MainWidget::instance()->getCurrentBaseWidget()->setFocus();
|
|
mParentMenu->rootNode()->hide();
|
|
}
|