#include "mcheaddialog.h" #include "ui_mcheaddialog.h" const QString strOr = "background-color: qlineargradient(spread:pad, x1:0.5 y1:0, x2:0.5, y2:1, stop:0 rgb(247, 180, 61), stop:1 rgb(222, 162, 55));border-radius:10px;color:rgb(255,255,255);"; const QString strBlack = "background-color: qlineargradient(spread:pad, x1:0.5 y1:0, x2:0.5, y2:1, stop:0 rgb(100, 100, 100), stop:1 rgb(100, 100, 100));border-radius:10px;color:rgb(234, 234, 234);"; McHeadDialog::McHeadDialog(QWidget *parent) : QDialog(parent), ui(new Ui::McHeadDialog) { ui->setupUi(this); setWindowFlags (Qt::Window | Qt::FramelessWindowHint); setWindowModality(Qt::ApplicationModal); setAttribute(Qt::WA_TranslucentBackground, true);//设置窗体背景透明 initWidget(); initControl(); } McHeadDialog::~McHeadDialog() { delete ui; } void McHeadDialog::on_buttonOk_clicked() { done(1); } void McHeadDialog::on_buttonCancel_clicked() { done(0); } void McHeadDialog::updataUi(int btnIndex, MyButton *button) { if(btnIndex > 8 || btnIndex < 0) return; bitset<8> charBit(m_mcHeadSw); m_mcHeadSw = setBit(m_mcHeadSw, btnIndex, !charBit[btnIndex]); bitset<8> charBitFan(m_mcHeadSw); cout << charBitFan << endl; SetControlStyle setControlStyle; setControlStyle.setUiName(this->objectName()); if(charBitFan.test(btnIndex)) {button->setStyleSheet(strOr);} else {button->setStyleSheet(strBlack);} } void McHeadDialog::refreshUi() { bitset<8> charBit(m_mcHeadSw); if(charBit[0] == 1) {ui->pushButton->setStyleSheet(strOr);} else{ui->pushButton->setStyleSheet(strBlack);} if(charBit[1] == 1) {ui->pushButton_2->setStyleSheet(strOr);} else{ui->pushButton_2->setStyleSheet(strBlack);} if(charBit[2] == 1) {ui->pushButton_3->setStyleSheet(strOr);} else{ui->pushButton_3->setStyleSheet(strBlack);} if(charBit[3] == 1) {ui->pushButton_4->setStyleSheet(strOr);} else{ui->pushButton_4->setStyleSheet(strBlack);} if(charBit[4] == 1) {ui->pushButton_5->setStyleSheet(strOr);} else{ui->pushButton_5->setStyleSheet(strBlack);} if(charBit[5] == 1) {ui->pushButton_6->setStyleSheet(strOr);} else{ui->pushButton_6->setStyleSheet(strBlack);} if(charBit[6] == 1) {ui->pushButton_7->setStyleSheet(strOr);} else{ui->pushButton_7->setStyleSheet(strBlack);} if(charBit[7] == 1) {ui->pushButton_8->setStyleSheet(strOr);} else{ui->pushButton_8->setStyleSheet(strBlack);} qDebug()<< QString::fromStdString(charBit.to_string()); } char McHeadDialog::setBit(char data, int setoff, bool value) { bitset<8> charBit(data); charBit.set(setoff, value); char res = (char)charBit.to_ulong(); return res; } void McHeadDialog::setChar(char data) { m_mcHeadSw = data; refreshUi(); } unsigned char McHeadDialog::getChar() { return m_mcHeadSw; } void McHeadDialog::on_pushButton_clicked() { MyButton *button = (MyButton*) this->sender() ; QMetaObject::invokeMethod(this, "updataUi", Qt::DirectConnection, Q_ARG(int , 0), Q_ARG(MyButton *, button)); } void McHeadDialog::on_pushButton_2_clicked() { MyButton *button = (MyButton*) this->sender() ; QMetaObject::invokeMethod(this, "updataUi", Qt::DirectConnection, Q_ARG(int , 1), Q_ARG(MyButton *, button)); } void McHeadDialog::on_pushButton_3_clicked() { MyButton *button = (MyButton*) this->sender() ; QMetaObject::invokeMethod(this, "updataUi", Qt::DirectConnection, Q_ARG(int , 2), Q_ARG(MyButton *, button)); } void McHeadDialog::on_pushButton_4_clicked() { MyButton *button = (MyButton*) this->sender() ; QMetaObject::invokeMethod(this, "updataUi", Qt::DirectConnection, Q_ARG(int , 3), Q_ARG(MyButton *, button)); } void McHeadDialog::on_pushButton_5_clicked() { MyButton *button = (MyButton*) this->sender() ; QMetaObject::invokeMethod(this, "updataUi", Qt::DirectConnection, Q_ARG(int , 4), Q_ARG(MyButton *, button)); } void McHeadDialog::on_pushButton_6_clicked() { MyButton *button = (MyButton*) this->sender() ; QMetaObject::invokeMethod(this, "updataUi", Qt::DirectConnection, Q_ARG(int , 5), Q_ARG(MyButton *, button)); } void McHeadDialog::on_pushButton_7_clicked() { MyButton *button = (MyButton*) this->sender() ; QMetaObject::invokeMethod(this, "updataUi", Qt::DirectConnection, Q_ARG(int , 6), Q_ARG(MyButton *, button)); } void McHeadDialog::on_pushButton_8_clicked() { MyButton *button = (MyButton*) this->sender() ; QMetaObject::invokeMethod(this, "updataUi", Qt::DirectConnection, Q_ARG(int , 7), Q_ARG(MyButton *, button)); } void McHeadDialog::initWidget() { m_sheetBtnList.append(ui->pushButton); m_sheetBtnList.append(ui->pushButton_2); m_sheetBtnList.append(ui->pushButton_3); m_sheetBtnList.append(ui->pushButton_4); m_sheetBtnList.append(ui->pushButton_5); // m_sheetBtnList.append(ui->pushButton_6); // m_sheetBtnList.append(ui->pushButton_7); // m_sheetBtnList.append(ui->pushButton_8); ui->pushButton_6->setVisible(false); ui->pushButton_7->setVisible(false); ui->pushButton_8->setVisible(false); // QList btns = this->findChildren(); } void McHeadDialog::initControl() { //根据不同分辨率设置控件的位置和尺寸 switch (g_emResolut) { case resolution1910: initResolution1910(); break; case resolution1006: initResolution1006(); break; default: this->resize(1920,1080); break; } initControlStyle();//初始化窗体控件样式 } void McHeadDialog::initResolution1910() { double factoryX = 1.875; //缩放比例系数 double factoryY = 1.8; this->resize(1024*factoryX,600*factoryY); ui->framePageBtn->setGeometry(489*factoryX,545*factoryY,600*factoryX,40*factoryY); ui->buttonOk->setGeometry(318*factoryX,0*factoryY,96*factoryX,40*factoryY); ui->buttonCancel->setGeometry(424*factoryX,0*factoryY,96*factoryX,40*factoryY); ui->frameBack->setGeometry(0*factoryX, 0*factoryY, 1024*factoryX, 600*factoryY); for(int i = 0; i < m_sheetBtnList.size(); i++){ m_sheetBtnList[i]->setGeometry((110+i*100)*factoryX, 300*factoryY, 72*factoryX, 40*factoryY); m_sheetBtnList[i]->setText(QString("%1").arg(i+1)); m_sheetBtnList[i]->setFont(fontNormal_1); m_sheetBtnList[i]->setStyleSheet(LABELWHITESTYLE); } } void McHeadDialog::initResolution1006() { this->resize(1024,600); ui->framePageBtn->setGeometry(489,545,600,40); ui->buttonOk->setGeometry(318,0,96,40); ui->buttonCancel->setGeometry(424,0,96,40); ui->frameBack->setGeometry(0, 0, 1024, 600); for(int i = 0; i < m_sheetBtnList.size(); i++){ m_sheetBtnList[i]->setGeometry(110+i*100, 300, 72, 40); m_sheetBtnList[i]->setText(QString("%1").arg(i+1)); } } void McHeadDialog::initControlStyle() { SetControlStyle setControlStyle; setControlStyle.setUiName(this->objectName()); ui->frameBack->setStyleSheet(TRANSPARENTSTYLE); ui->frameBack->setStyleSheet(setControlStyle.getStyleSheet(this->objectName())); ui->buttonOk->setOrangeGradientBottomStyle(BORDER_RADIUS2); ui->buttonOk->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonOk->objectName()),12); ui->buttonCancel->setOrangeGradientBottomStyle(BORDER_RADIUS2); ui->buttonCancel->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonCancel->objectName()),12); }