123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- #include "AddSchemeWidget.h"
- #include <Widgets/Button.h>
- #include <Widgets/LineEdit.h>
- #include <QBoxLayout>
- #include <QLabel>
- #include <QDebug>
- #include <QFileDialog>
- AddSchemeWidget::AddSchemeWidget(QWidget *parent) : QDialog(parent)
- {
- initWindow();
- initialize();
- initLayout();
- connectSignalsAndSlots();
- }
- void AddSchemeWidget::clearInputs()
- {
- m_nameEdit->clear();
- m_schemeEdit->clear();
- }
- void AddSchemeWidget::initWindow()
- {
- setWindowTitle("新建方案");
- setModal(true);
- setWindowFlags(Qt::Dialog);
- setWindowFlag(Qt::WindowContextHelpButtonHint, false);
- resize(370, 350);
- }
- void AddSchemeWidget::initialize()
- {
- m_vBoxLayout = new QVBoxLayout(this);
- m_gridLayout = new QGridLayout();
- m_nameLabel = new QLabel("方案名称:", this);
- m_nameLabel->setFixedHeight(44);
- m_nameEdit = new LineEdit(this);
- m_nameEdit->setFixedWidth(250);
- m_schemeLabel = new QLabel("方案描述:", this);
- m_schemeLabel->setFixedHeight(35);
- m_schemeEdit = new TextEdit(this);
- m_schemeEdit->setFixedWidth(250);
- m_schemeEdit->setFixedHeight(150);
- m_picButton = new PushButton("方案图片", this);
- m_picLine = new LineEdit(this);
- m_picLine->setFixedWidth(250);
- m_picLine->setEnabled(false);
- m_hBoxLayout = new QHBoxLayout();
- m_confirButton = new PushButton("生成", this);
- m_confirButton->setEnabled(false);
- }
- void AddSchemeWidget::initLayout()
- {
- m_vBoxLayout->setMargin(15);
- m_vBoxLayout->addLayout(m_gridLayout);
- m_gridLayout->addWidget(m_nameLabel, 0, 0, 1, 1, Qt::AlignRight);
- m_gridLayout->addWidget(m_nameEdit, 0, 1, 1, 2, Qt::AlignLeft);
- m_gridLayout->addWidget(m_schemeLabel, 1, 0, 1, 1, Qt::AlignRight | Qt::AlignTop);
- m_gridLayout->addWidget(m_schemeEdit, 1, 1, 1, 2, Qt::AlignLeft);
- m_gridLayout->addWidget(m_picButton, 2, 0, 1, 1, Qt::AlignRight);
- m_gridLayout->addWidget(m_picLine, 2, 1, 1, 2, Qt::AlignLeft);
- m_vBoxLayout->addSpacing(20);
- m_vBoxLayout->addStretch();
- m_vBoxLayout->addLayout(m_hBoxLayout);
- m_hBoxLayout->addStretch();
- m_hBoxLayout->addWidget(m_confirButton);
- }
- void AddSchemeWidget::connectSignalsAndSlots()
- {
- connect(m_picButton, &QPushButton::clicked, this, &AddSchemeWidget::slotSelectPic);
- connect(m_nameEdit, &LineEdit::textChanged, this, &AddSchemeWidget::slotContentChanged);
- connect(m_schemeEdit, &TextEdit::textChanged, this, &AddSchemeWidget::slotContentChanged);
- connect(m_picLine, &LineEdit::textChanged, this, &AddSchemeWidget::slotContentChanged);
- connect(m_confirButton, &PushButton::clicked, this, &AddSchemeWidget::slotConfirmed);
- }
- void AddSchemeWidget::slotSelectPic()
- {
- qDebug() << __FUNCTION__ << __LINE__ << endl;
- QFileDialog::Options options;
- options |= QFileDialog::DontUseNativeDialog;
- QString selectedFilter;
- QString fileName = QFileDialog::getOpenFileName(this, "选择图片", "", "图片(*.jpg *.png *jpeg *bmp)",
- &selectedFilter, options);
- bool fileValid = true;
- if (fileName.isEmpty() || fileName.size() <= 0) {
- fileValid = false;
- return;
- }
- m_picLine->setText(fileName);
- }
- void AddSchemeWidget::slotContentChanged()
- {
- bool valid = m_nameEdit->text().length() > 0 && m_schemeEdit->toPlainText().length() > 0
- && m_picLine->text().length() > 0;
- m_confirButton->setEnabled(valid);
- }
- void AddSchemeWidget::slotConfirmed()
- {
- emit sigSchemeInfoConfirmed(m_nameEdit->text(), m_schemeEdit->toPlainText(), m_picLine->text());
- close();
- }
|