| 274 | } |
| 275 | |
| 276 | bool MessageComponent::createCodeEdit(const MessageData &newData) |
| 277 | { |
| 278 | QStringList newLines = newData.messageLines(); |
| 279 | QStringList oldLines = messageData.messageLines(); |
| 280 | QStringList addedLines = newLines.mid(oldLines.count()); |
| 281 | |
| 282 | for (int i = 0; i < addedLines.count(); ++i) { |
| 283 | QString addedLine = addedLines.at(i).trimmed(); |
| 284 | if (addedLine.contains("`") || addedLine.isEmpty()) { |
| 285 | if (i != 0) { |
| 286 | MessageData addedMsgData = messageData; |
| 287 | addedMsgData.appendData(addedLines.mid(0, i)); |
| 288 | updateMessage(addedMsgData); |
| 289 | } |
| 290 | |
| 291 | QRegExp re("```([a-z]*|[A-Z]*)"); |
| 292 | if (re.exactMatch(addedLine) && currentUpdateState == Label) { |
| 293 | // create new code edit component |
| 294 | messageData.appendData({ addedLine }); |
| 295 | currentUpdateState = CodeEdit; |
| 296 | curUpdateEdit = new CodeEditComponent(this); |
| 297 | curUpdateEdit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding); |
| 298 | curUpdateEdit->setReadOnly(true); |
| 299 | curUpdateEdit->setUpdateHeight(true); |
| 300 | curUpdateEdit->showButtons(CodeEditComponent::CopyAndInsert); |
| 301 | msgLayout->addWidget(curUpdateEdit); |
| 302 | return true; |
| 303 | } else if (addedLine == "```" && currentUpdateState == CodeEdit) { |
| 304 | // end the code edit component update |
| 305 | messageData.appendData({ addedLine }); |
| 306 | currentUpdateState = Label; |
| 307 | curUpdateLabel = new DLabel(this); |
| 308 | curUpdateLabel->setTextInteractionFlags(Qt::TextSelectableByMouse); |
| 309 | curUpdateLabel->setWordWrap(true); |
| 310 | msgLayout->addWidget(curUpdateLabel); |
| 311 | if (i != (addedLines.count() - 1)) |
| 312 | updateMessage(newData); |
| 313 | |
| 314 | return false; |
| 315 | } else if (addedLine.size() > 4) { // addedline starts with ` but not ```. eg: `123` |
| 316 | return true; |
| 317 | } |
| 318 | return false; |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | return true; |
| 323 | } |
| 324 | |
| 325 | void MessageComponent::showWebsitesReferences() |
| 326 | { |
nothing calls this directly
no test coverage detected