| 17 | QString text; |
| 18 | bool save = false; |
| 19 | public: |
| 20 | QTextDialog(bool editable = false, const QString& title = QString(), const QIcon& icon = QIcon()) : editable(editable) |
| 21 | { |
| 22 | setWindowFlags(Qt::WindowCloseButtonHint); |
| 23 | setWindowIcon(icon.isNull() ? QApplication::windowIcon() : icon); |
| 24 | setGeometry(QRect(100, 100, 500, 380)); |
| 25 | setStyleSheet("color:black"); |
| 26 | |
| 27 | textEdit = new QPlainTextEdit(this); |
| 28 | textEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
| 29 | textEdit->setTabStopDistance(QFontMetrics(QFont("Microsoft YaHei")).horizontalAdvance(" ")); |
| 30 | |
| 31 | saveButton = new QPushButton(this); |
| 32 | saveButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); |
| 33 | saveButton->setMinimumSize(QSize(60, 24)); |
| 34 | saveButton->setMaximumSize(QSize(60, 24)); |
| 35 | saveButton->setText(lang_trans("保存")); |
| 36 | |
| 37 | layout = new QVBoxLayout(this); |
| 38 | layout->setContentsMargins(8, 8, 8, 8); |
| 39 | |
| 40 | buttonLayout = new QHBoxLayout(); |
| 41 | buttonLayout->setContentsMargins(0, 0, 0, 0); |
| 42 | |
| 43 | buttonLayout->addItem(new QSpacerItem(2, 2, QSizePolicy::Expanding, QSizePolicy::Minimum)); |
| 44 | buttonLayout->addWidget(saveButton); |
| 45 | |
| 46 | layout->addWidget(textEdit); |
| 47 | layout->addLayout(buttonLayout); |
| 48 | |
| 49 | if (editable) |
| 50 | { |
| 51 | setWindowTitle(title.isEmpty() ? QString("TextEdit") : title); |
| 52 | textEdit->setReadOnly(false); |
| 53 | saveButton->setHidden(false); |
| 54 | } |
| 55 | else |
| 56 | { |
| 57 | setWindowTitle(title.isEmpty() ? QString("TextView") : title); |
| 58 | textEdit->setReadOnly(true); |
| 59 | saveButton->setHidden(true); |
| 60 | } |
| 61 | } |
| 62 | QPlainTextEdit* edit() |
| 63 | { |
nothing calls this directly
no test coverage detected