void Plotter::setPlotCount(int count) { for (int i = 0; i < m_plotCount; ++i) { m_plotter->removePlot(0); } m_plotCount = count; Plasma::Theme* theme = Plasma::Theme::defaultTheme(); QColor text = theme->color(Plasma::Theme::TextColor); QColor bg = theme->color(Plasma::Theme::BackgroundColor); for (int i = 0; i < m_plotCount; ++i) { QColor color = KColorUtils::tint(text, bg, 0.4 + ((double)i / 2.5)); m_plotter->addPlot(color); } }
void ShellRunner::createRunOptions(QWidget *parent) { //TODO: for multiple runners? //TODO: sync palette on theme changes ShellConfig *configWidget = new ShellConfig(config(), parent); QPalette pal = configWidget->palette(); Plasma::Theme *theme = new Plasma::Theme(this); pal.setColor(QPalette::Normal, QPalette::Window, theme->color(Plasma::Theme::BackgroundColor)); pal.setColor(QPalette::Normal, QPalette::WindowText, theme->color(Plasma::Theme::TextColor)); configWidget->setPalette(pal); connect(configWidget->m_ui.cbRunAsOther, SIGNAL(clicked(bool)), this, SLOT(setRunAsOtherUser(bool))); connect(configWidget->m_ui.cbRunInTerminal, SIGNAL(clicked(bool)), this, SLOT(setRunInTerminal(bool))); connect(configWidget->m_ui.leUsername, SIGNAL(textChanged(QString)), this, SLOT(setUsername(QString))); connect(configWidget->m_ui.lePassword, SIGNAL(textChanged(QString)), this, SLOT(setPassword(QString))); }
void Hdd::applyTheme(Plasma::Meter *w) { if (!w) { return; } Plasma::Theme* theme = Plasma::Theme::defaultTheme(); QColor text = theme->color(Plasma::Theme::TextColor); QColor bg = theme->color(Plasma::Theme::BackgroundColor); QColor darkerText = KColorUtils::tint(text, bg, 0.4); w->setLabelColor(0, text); w->setLabelColor(1, darkerText); w->setLabelColor(2, darkerText); QFont font = theme->font(Plasma::Theme::DefaultFont); font.setPointSize(9); w->setLabelFont(0, font); font.setPointSizeF(7.5); w->setLabelFont(1, font); w->setLabelFont(2, font); }
void EmergingPlasmoid::themeChanged() { Plasma::Theme * theme = Plasma::Theme::defaultTheme(); QColor text = theme->color(Plasma::Theme::TextColor); QColor bg = theme->color(Plasma::Theme::BackgroundColor); QColor darkerText = KColorUtils::tint(text, bg, 0.4); totalJobMeter.setLabelColor(0, text); totalJobMeter.setLabelColor(1, darkerText); currentJobMeter.setLabelColor(0, text); currentJobMeter.setLabelColor(1, darkerText); QFont font = theme->font(Plasma::Theme::DefaultFont); font.setPointSizeF(9.0); totalJobMeter.setLabelFont(0, font); currentJobMeter.setLabelFont(0, font); font.setPointSizeF(7.5); totalJobMeter.setLabelFont(1, font); currentJobMeter.setLabelFont(1, font); }
void Flags::drawLabel(QPainter& painter, const QString& layoutText, bool flagShown) { QFont font = painter.font(); QRect rect = painter.window(); // int fontSize = layoutText.length() == 2 // ? height * 7 / 10 // : height * 5 / 10; int fontSize = rect.height();// * 7 /10; font.setPixelSize(fontSize); font.setWeight(QFont::DemiBold); QFontMetrics fm = painter.fontMetrics(); int width = fm.width(layoutText); if( width > rect.width() * 2 / 3 ) { fontSize = round( (double)fontSize * ((double)rect.width()*2/3) / width ); } int smallestReadableSize = KGlobalSettings::smallestReadableFont().pixelSize(); if( fontSize < smallestReadableSize ) { fontSize = smallestReadableSize; } font.setPixelSize(fontSize); #ifdef DONT_USE_PLASMA painter.setFont(font); painter.setPen(Qt::white); painter.drawText(QRect(rect).adust(1,1,0,0), Qt::AlignCenter | Qt::AlignHCenter, layoutText); painter.setPen(Qt::black); painter.drawText(rect, Qt::AlignCenter | Qt::AlignHCenter, layoutText); #else // we init svg so that we get notification about theme change getSvg(); Plasma::Theme theme; QColor textColor = flagShown ? Qt::black : theme.color(Plasma::Theme::TextColor); QPoint offset = QPoint(0, 0); auto shadowText = [&font, &textColor, &offset](QString text) { //don't try to paint stuff on a future null pixmap because the text is empty if (text.isEmpty()) { return QPixmap(); } // Draw text QFontMetrics fm(font); QRect textRect = fm.boundingRect(text); QPixmap textPixmap(textRect.width(), fm.height()); textPixmap.fill(Qt::transparent); QPainter p(&textPixmap); p.setPen(textColor); p.setFont(font); // FIXME: the center alignment here is odd: the rect should be the size needed by // the text, but for some fonts and configurations this is off by a pixel or so // and "centering" the text painting 'fixes' that. Need to research why // this is the case and determine if we should be painting it differently here, // doing soething different with the boundingRect call or if it's a problem // in Qt itself p.drawText(textPixmap.rect(), Qt::AlignCenter, text); p.end(); return textPixmap; }; // QPixmap pixmap = Plasma::PaintUtils::texturedText(layoutText, font, svg); QPixmap labelPixmap = shadowText(layoutText); int y = round((rect.height() - labelPixmap.height()) / 2.0); int x = round((rect.width() - labelPixmap.width()) / 2.0); painter.drawPixmap(QPoint(x, y), labelPixmap); #endif }