| 194 | } |
| 195 | |
| 196 | void CodeEditComponent::initUI() |
| 197 | { |
| 198 | setAutoFillBackground(true); |
| 199 | |
| 200 | QVBoxLayout *layout = new QVBoxLayout; |
| 201 | layout->setSpacing(0); |
| 202 | layout->setMargin(0); |
| 203 | setLayout(layout); |
| 204 | |
| 205 | titleWidget = new DWidget(this); |
| 206 | titleWidget->setFixedHeight(36); |
| 207 | layout->addWidget(titleWidget); |
| 208 | initTitleWidgets(); |
| 209 | titleWidget->setVisible(false); |
| 210 | |
| 211 | initButton(); |
| 212 | |
| 213 | editFrame = new DFrame(this); |
| 214 | editFrame->setFrameRounded(true); |
| 215 | editFrame->setLineWidth(2); |
| 216 | auto editLayout = new QVBoxLayout(editFrame); |
| 217 | editLayout->setContentsMargins(3, 0, 3, 3); |
| 218 | editFrame->setLayout(editLayout); |
| 219 | |
| 220 | auto buttonLayout = new QHBoxLayout; |
| 221 | buttonLayout->setSpacing(10); |
| 222 | buttonLayout->setContentsMargins(0, 5, 10, 5); |
| 223 | buttonLayout->setAlignment(Qt::AlignRight); |
| 224 | |
| 225 | buttonLayout->addWidget(copyButton); |
| 226 | buttonLayout->addWidget(insertButton); |
| 227 | |
| 228 | codeEdit = new QTextEdit(this); |
| 229 | codeEdit->setFrameShape(QFrame::NoFrame); |
| 230 | codeEdit->setWordWrapMode(QTextOption::WrapMode::NoWrap); |
| 231 | codeEdit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding); |
| 232 | |
| 233 | //默认为C++语言高亮 |
| 234 | highLighter = new KSyntaxHighlighting::SyntaxHighlighter(codeEdit->document()); |
| 235 | def = rep.definitionForName("C++"); |
| 236 | highLighter->setDefinition(def); |
| 237 | if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType) |
| 238 | highLighter->setTheme(rep.defaultTheme(KSyntaxHighlighting::Repository::LightTheme)); |
| 239 | else |
| 240 | highLighter->setTheme(rep.defaultTheme(KSyntaxHighlighting::Repository::DarkTheme)); |
| 241 | |
| 242 | hLine = new DHorizontalLine; |
| 243 | hLine->setVisible(false); |
| 244 | |
| 245 | editLayout->setSpacing(0); |
| 246 | editLayout->addLayout(buttonLayout); |
| 247 | editLayout->addWidget(hLine); |
| 248 | editLayout->addWidget(codeEdit); |
| 249 | |
| 250 | layout->addWidget(editFrame); |
| 251 | } |
| 252 | |
| 253 | void CodeEditComponent::initTitleWidgets() |
nothing calls this directly
no test coverage detected