示例#1
0
void TabBar::setTheme(const Theme* theme) {
  qDebug("TabBar theme is changed");
  if (!theme) {
    qWarning("theme is null");
    return;
  }

  if (theme->tabBarSettings != nullptr) {
    QString style;
    ColorSettings* tabBarSettings = theme->tabBarSettings.get();

    style = QString(
                "TabBar { background-color: %1; }"
                "TabBar::tab {"
                "background-color: %1;"
                "color: %2;"
                "}")
                .arg(Util::qcolorForStyleSheet(tabBarSettings->value("background")))
                .arg(Util::qcolorForStyleSheet(tabBarSettings->value("foreground")));

    style += QString(
                 "TabBar::tab:selected {"
                 "background-color: %1;"
                 "color: %2;"
                 "border-bottom: 2px solid;"
                 "border-color: %3;"
                 "}")
                 .arg(Util::qcolorForStyleSheet(tabBarSettings->value("selected")))
                 .arg(Util::qcolorForStyleSheet(tabBarSettings->value("foreground")))
                 .arg(Util::qcolorForStyleSheet(tabBarSettings->value("selectedBorder")));

    this->setStyleSheet(style);
  }
}
示例#2
0
void FindReplaceView::setTheme(core::Theme* theme) {
  ui->prevButton->setIcon(QIcon(":/images/prevButton-black.svg"));
  ui->nextButton->setIcon(QIcon(":/images/nextButton-black.svg"));

  qDebug("FindReplaceView theme is changed");
  if (!theme) {
    qWarning("theme is null");
    return;
  }

  if (theme->findReplaceViewSettings != nullptr) {
    ColorSettings* findReplaceViewSettings = theme->findReplaceViewSettings.get();

    QString defaultIconColor = QStringLiteral("black");
    QString checkedIconColor = QStringLiteral("white");

    if (theme->isDarkTheme()) {
      defaultIconColor = "white";
      checkedIconColor = "black";
      ui->prevButton->setIcon(QIcon(":/images/prevButton-white.svg"));
      ui->nextButton->setIcon(QIcon(":/images/nextButton-white.svg"));
    }

    QList<QCheckBox*> allCkButtons = this->findChildren<QCheckBox*>();
    for (int i = 0; i < allCkButtons.size(); i++) {
      const QString& style = QStringLiteral(
                                 "#%1::indicator {"
                                 "image: url(:/images/%1-%2);"
                                 "}"
                                 "#%1::indicator:checked {"
                                 "image: url(:/images/%1-%3);"
                                 "}")
                                 .arg(allCkButtons.at(i)->objectName())
                                 .arg(defaultIconColor)
                                 .arg(checkedIconColor);
      allCkButtons.at(i)->setStyleSheet(style);
    };

    const QString& style =
        QStringLiteral(
            "#%1 {"
            "background-color: %2;"
            "}")
            .arg(this->objectName())
            .arg(Util::qcolorForStyleSheet(findReplaceViewSettings->value("background"))) +
        QStringLiteral(
            "#%1 QPushButton {"
            "color: %2;"
            "outline: 0;"
            "}"
            "#%1 QCheckBox:checked {"
            "background-color: %3;"
            "}")
            .arg(this->objectName())
            .arg(defaultIconColor)
            .arg(Util::qcolorForStyleSheet(
                findReplaceViewSettings->value("buttonCheckedBackgroundColor"))) +
        QStringLiteral(
            "#%1 QPushButton:focus, #%1 QLineEdit:focus {"
            "border-color: %2;"
            "}")
            .arg(this->objectName())
            .arg(Util::qcolorForStyleSheet(findReplaceViewSettings->value("focusColor"))) +
        QStringLiteral(
            "#%1 QPushButton:hover, "
            "#%1 QCheckBox:unchecked:hover {"
            "background:%2;"
            "}"
            "#%1 QPushButton:pressed, "
            "#%1 QCheckBox:unchecked:pressed {"
            "background:%3;"
            "}")
            .arg(this->objectName())
            .arg(Util::qcolorForStyleSheet(findReplaceViewSettings->value("hoverColor")))
            .arg(Util::qcolorForStyleSheet(findReplaceViewSettings->value("pressedColor")));

    this->setStyleSheet(style);
  }
}