MCPcopy Create free account
hub / github.com/KDE/labplot / updateBackground

Method updateBackground

src/frontend/widgets/LabelWidget.cpp:303–329  ·  view source on GitHub ↗

! * this function keeps the background color of the TextEdit in LabelWidget in sync with * the background color of the parent aspect. This is to avoid the situations where the * text wouldn't be readable anymore if the foreground color is close or equal to the * background color of TextEdit - e.g., a label with white foreground color on a dark worksheet * and with white background color in Te

Source from the content-addressed store, hash-verified

301 * Called if the background color of the parent aspect has changed.
302 */
303void LabelWidget::updateBackground() const {
304 // if latex or markdown mode is used, use the default palette from the desktop theme
305 // since we have additional highlighting for latex and markdown and we don't want it to
306 // collide with the modified background color of QTextEdit. Modify it only for rich-text.
307 const auto mode = static_cast<TextLabel::Mode>(ui.cbMode->currentIndex());
308 if (mode != TextLabel::Mode::Text) {
309 ui.teLabel->setPalette(QPalette());
310 return;
311 }
312
313 QColor color(Qt::white);
314 const auto type = m_label->parentAspect()->type();
315 if (type == AspectType::Worksheet)
316 color = static_cast<const Worksheet*>(m_label->parentAspect())->background()->firstColor();
317 else if (type == AspectType::CartesianPlot)
318 color = static_cast<CartesianPlot*>(m_label->parentAspect())->plotArea()->background()->firstColor();
319 else if (type == AspectType::CartesianPlotLegend)
320 color = static_cast<const CartesianPlotLegend*>(m_label->parentAspect())->background()->firstColor();
321 else if (type == AspectType::InfoElement || type == AspectType::Axis)
322 color = static_cast<CartesianPlot*>(m_label->parentAspect()->parentAspect())->plotArea()->background()->firstColor();
323 else
324 DEBUG(Q_FUNC_INFO << ", Not handled type:" << static_cast<int>(type));
325
326 QString style;
327 style = QString(QLatin1String("QTextEdit{background-color: rgb(%1, %2, %3);}")).arg(color.red()).arg(color.green()).arg(color.blue());
328 ui.teLabel->setStyleSheet(style);
329}
330
331void LabelWidget::initConnections() {
332 while (!m_connections.isEmpty())

Callers

nothing calls this directly

Calls 7

parentAspectMethod · 0.80
plotAreaMethod · 0.80
argMethod · 0.80
QStringClass · 0.50
currentIndexMethod · 0.45
typeMethod · 0.45
backgroundMethod · 0.45

Tested by

no test coverage detected