125 lines
4.2 KiB
C++
125 lines
4.2 KiB
C++
#include "ServerSettingWidget.h"
|
|
#include <QPainter>
|
|
#include <QLabel>
|
|
#include <QLineEdit>
|
|
#include <QStyleOption>
|
|
#include "../component/ExpandInput.h"
|
|
#include "../component/ShowHelpInfo.h"
|
|
#include "../BackEnd/MainWidget.h"
|
|
#include "../BaseWidget.h"
|
|
|
|
|
|
ServerSettingWidget::ServerSettingWidget(QWidget *parent) : QWidget(parent) {
|
|
|
|
|
|
setObjectName("服务端设置界面");
|
|
hide();
|
|
auto mainLayout = new QVBoxLayout(this);
|
|
mainLayout->setAlignment(Qt::AlignTop);
|
|
mRigNameLabel = createLabel("Rig Name");
|
|
mUserNameLabel = createLabel("User Name");
|
|
mPasswordLabel = createLabel("Password");
|
|
mCtrlPortLabel = createLabel("Ctrl Port");
|
|
mCivPortLabel = createLabel("Civ Port");
|
|
mAudioPortLabel = createLabel("Audio Port");
|
|
|
|
mRigNameEdit = new ExpandInput();
|
|
mUserNameEdit = new ExpandInput();
|
|
mPasswordEdit = new ExpandInput();
|
|
mCtrlPortEdit = new ExpandInput();
|
|
mCivPortEdit = new ExpandInput();
|
|
mAudioPortEdit = new ExpandInput();
|
|
|
|
mainLayout->addLayout(createHBoxLayout({mRigNameLabel, mRigNameEdit}), 1);
|
|
mainLayout->addLayout(createHBoxLayout({mUserNameLabel, mUserNameEdit}), 1);
|
|
mainLayout->addLayout(createHBoxLayout({mPasswordLabel, mPasswordEdit}), 1);
|
|
mainLayout->addLayout(createHBoxLayout({mCtrlPortLabel, mCtrlPortEdit}), 1);
|
|
mainLayout->addLayout(createHBoxLayout({mCivPortLabel, mCivPortEdit}), 1);
|
|
mainLayout->addLayout(createHBoxLayout({mAudioPortLabel, mAudioPortEdit}), 1);
|
|
mShowHelpInfo = new ShowHelpInfo;
|
|
mShowHelpInfo->mFont.setPixelSize(40);
|
|
mainLayout->addWidget(mShowHelpInfo, 3);
|
|
int fontSize = 40;
|
|
mStartButton = createClickButton("Start", fontSize, [&]() {
|
|
mShowHelpInfo->setText("Start 帮助信息");
|
|
mShowHelpInfo->update();
|
|
}, &mRollObject);
|
|
mDefaultButton = createClickButton("Default", fontSize, [&]() {
|
|
mShowHelpInfo->setText("Default 帮助信息");
|
|
mShowHelpInfo->update();
|
|
}, &mRollObject);
|
|
mClearButton = createClickButton("Clear", fontSize, [&]() {
|
|
mShowHelpInfo->setText("Clear 帮助信息");
|
|
mShowHelpInfo->update();
|
|
}, &mRollObject);
|
|
mSaveButton = createClickButton("Save", fontSize, [&]() {
|
|
mShowHelpInfo->setText("Save 帮助信息");
|
|
mShowHelpInfo->update();
|
|
}, &mRollObject);
|
|
mExitButton = createClickButton("Exit", fontSize, [&]() {
|
|
MainWidget::instance()->hideCurHoverWidget();
|
|
MainWidget::instance()->getCurrentBaseWidget()->setFocus();
|
|
}, &mRollObject);
|
|
mRollObject.mWidgets = {mStartButton, mDefaultButton, mClearButton, mSaveButton, mExitButton};
|
|
mRollObject.mEnterFunc = [](QPushButton* btn){
|
|
btn->setChecked(true);
|
|
};
|
|
mRollObject.mLeaveFunc = [](QPushButton* btn){
|
|
btn->setChecked(false);
|
|
};
|
|
mainLayout->addLayout(mRollObject.hBoxLayout(8), 2);
|
|
}
|
|
|
|
void ServerSettingWidget::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();
|
|
}
|
|
|
|
QLabel *ServerSettingWidget::createLabel(const QString& text) {
|
|
auto ret = new QLabel(text);
|
|
QFont font;
|
|
font.setBold(true);
|
|
font.setPixelSize(Global::instance()->adaptHeight(50));
|
|
ret->setFont(font);
|
|
QPalette pe;
|
|
pe.setColor(QPalette::WindowText, Qt::black);
|
|
ret->setPalette(pe);
|
|
return ret;
|
|
}
|
|
|
|
void ServerSettingWidget::keyPressEvent(QKeyEvent *event) {
|
|
if (event->type() == QEvent::KeyPress) {
|
|
BackEnd* g = BackEnd::instance();
|
|
auto *keyEvent = dynamic_cast<QKeyEvent *>(event);
|
|
if(g->match(keyEvent, "左移")){
|
|
mRollObject.rollLeft();
|
|
event->accept();
|
|
return;
|
|
}
|
|
if(g->match(keyEvent, "右移")){
|
|
mRollObject.rollRight();
|
|
event->accept();
|
|
return;
|
|
}
|
|
if(g->match(keyEvent, "确定")){
|
|
mRollObject.cur()->emit clicked();
|
|
event->accept();
|
|
return;
|
|
}
|
|
}
|
|
event->ignore();
|
|
}
|
|
|
|
void ServerSettingWidget::showEvent(QShowEvent *event) {
|
|
mRollObject.mEnterFunc(mRollObject.cur());
|
|
event->accept();
|
|
}
|
|
|
|
|
|
|