void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { if (option.state & QStyle::State_Selected) { painter->fillRect(option.rect, option.palette.color(QPalette::Highlight)); painter->setPen(option.palette.color(QPalette::HighlightedText)); } QString text = index.data(Qt::DisplayRole).toString(); QRect r = option.rect.adjusted(option.rect.height() + 4, 0, -4 - option.rect.height(), 0); painter->drawText(r, Qt::AlignVCenter | Qt::AlignLeft, text, &r); QColor swatch_color = index.data(Qt::UserRole).value<QColor>(); if (!swatch_color.isValid()) { // Special cases for colors we want to come from the system QPalette defaultPalette; if (text == QString(tr("Background"))) { swatch_color = defaultPalette.base().color(); } else if (text == QString(tr("Foreground"))) { swatch_color = defaultPalette.windowText().color(); } else if (text == QString(tr("Selection Background"))) { swatch_color = defaultPalette.highlight().color(); } else if (text == QString(tr("Selection Foreground"))) { swatch_color = defaultPalette.highlightedText().color(); } } r = option.rect.adjusted(1, 1, option.rect.height() - option.rect.width(), -2); painter->setPen(Qt::black); painter->setBrush(swatch_color); painter->drawRect(r); }
void EditableLabel::stopEditing() { QPalette p = originalPalette; p.setBrush(QPalette::Base, p.window()); p.setBrush(QPalette::Text, p.windowText()); QLineEdit::setPalette(p); setReadOnly(true); setFrame(false); setTextMargins(-2, 0, 0, 0); deselect(); }
void EditableLabel::setPalette(const QPalette &nPalette) { originalPalette = nPalette; QPalette p = nPalette; if (!isEditing()) { p.setBrush(QPalette::Base, p.window()); p.setBrush(QPalette::Text, p.windowText()); } QLineEdit::setPalette(p); }
QColor FormatDescription::defaultForeground(TextStyle id) { if (id == C_LINE_NUMBER) { const QPalette palette = Utils::Theme::initialPalette(); const QColor bg = palette.window().color(); if (bg.value() < 128) return palette.windowText().color(); else return palette.dark().color(); } else if (id == C_CURRENT_LINE_NUMBER) { const QPalette palette = Utils::Theme::initialPalette(); const QColor bg = palette.window().color(); if (bg.value() < 128) return palette.windowText().color(); else return QColor(); } else if (id == C_PARENTHESES) { return QColor(Qt::red); } else if (id == C_AUTOCOMPLETE) { return QColor(Qt::darkBlue); } return QColor(); }
/*! \~russian * \brief Метод инициализирует элементы настройки цвета в соответствии с переданной палитрой. * \param palette - палитра для инициализации */ void Settings::initColorPickers(QPalette palette) { ui->Frame_Style_Window->setColor( palette.window().color() ); ui->Frame_Style_WindowText->setColor( palette.windowText().color() ); ui->Frame_Style_Base->setColor( palette.base().color() ); ui->Frame_Style_AlternateBase->setColor( palette.alternateBase().color() ); ui->Frame_Style_ToolTipBase->setColor( palette.toolTipBase().color() ); ui->Frame_Style_ToolTipText->setColor( palette.toolTipText().color() ); ui->Frame_Style_Text->setColor( palette.text().color() ); ui->Frame_Style_Button->setColor( palette.button().color() ); ui->Frame_Style_ButtonText->setColor( palette.buttonText().color() ); ui->Frame_Style_BrightText->setColor( palette.brightText().color() ); ui->Frame_Style_Link->setColor( palette.link().color() ); ui->Frame_Style_Highlight->setColor( palette.highlight().color() ); ui->Frame_Style_HighlightedText->setColor( palette.highlightedText().color() ); }
QVariantMap Bridge::get_palette() { QVariantMap colors; QPalette palette = qApp->palette(); colors.insert("window", palette.window().color().name()); colors.insert("window_text", palette.windowText().color().name()); colors.insert("base", palette.base().color().name()); colors.insert("alternate_base", palette.alternateBase().color().name()); colors.insert("text", palette.text().color().name()); colors.insert("button", palette.buttonText().color().name()); colors.insert("bright_text", palette.brightText().color().name()); colors.insert("light", palette.light().color().name()); colors.insert("midlight", palette.midlight().color().name()); colors.insert("dark", palette.dark().color().name()); colors.insert("mid", palette.mid().color().name()); colors.insert("shadow", palette.shadow().color().name()); colors.insert("highlight", palette.highlight().color().name()); colors.insert("highlight_text", palette.highlightedText().color().name()); colors.insert("link", palette.link().color().name()); colors.insert("link_visited", palette.linkVisited().color().name()); return colors; }
void AutoHideLabel::fade() { Q_D(AutoHideLabel); if (d->alpha <= 0) { d->fadeTimer->stop(); hide(); } else { d->alpha = qMax(0, d->alpha-FADE_STEP); int alpha = qMin(255, d->alpha); QPalette palette = QToolTip::palette(); QColor color1 = palette.window().color(); QColor color2 = palette.windowText().color(); color1.setAlpha(alpha); color2.setAlpha(alpha); palette.setBrush(QPalette::Window, color1); palette.setBrush(QPalette::WindowText, color2); setPalette(palette); } }
/* Fill a single protocol tree item with its string value and set its color. */ static void proto_tree_draw_node(proto_node *node, gpointer data) { field_info *fi = PNODE_FINFO(node); gchar label_str[ITEM_LABEL_LENGTH]; gchar *label_ptr; gboolean is_branch; /* dissection with an invisible proto tree? */ g_assert(fi); if (PROTO_ITEM_IS_HIDDEN(node) && !prefs.display_hidden_proto_items) return; // Fill in our label /* was a free format label produced? */ if (fi->rep) { label_ptr = fi->rep->representation; } else { /* no, make a generic label */ label_ptr = label_str; proto_item_fill_label(fi, label_str); } if (node->first_child != NULL) { is_branch = TRUE; g_assert(fi->tree_type >= 0 && fi->tree_type < num_tree_types); } else { is_branch = FALSE; } if (PROTO_ITEM_IS_GENERATED(node)) { if (PROTO_ITEM_IS_HIDDEN(node)) { label_ptr = g_strdup_printf("<[%s]>", label_ptr); } else { label_ptr = g_strdup_printf("[%s]", label_ptr); } } else if (PROTO_ITEM_IS_HIDDEN(node)) { label_ptr = g_strdup_printf("<%s>", label_ptr); } QTreeWidgetItem *parentItem = (QTreeWidgetItem *)data; QTreeWidgetItem *item; ProtoTree *proto_tree = qobject_cast<ProtoTree *>(parentItem->treeWidget()); item = new QTreeWidgetItem(parentItem, 0); // Set our colors. QPalette pal = QApplication::palette(); if (fi && fi->hfinfo) { if(fi->hfinfo->type == FT_PROTOCOL) { item->setData(0, Qt::BackgroundRole, pal.window()); item->setData(0, Qt::ForegroundRole, pal.windowText()); } if((fi->hfinfo->type == FT_FRAMENUM) || (FI_GET_FLAG(fi, FI_URL) && IS_FT_STRING(fi->hfinfo->type))) { QFont font = item->font(0); item->setData(0, Qt::ForegroundRole, pal.link()); font.setUnderline(true); item->setData(0, Qt::FontRole, font); if (fi->hfinfo->type == FT_FRAMENUM) { proto_tree->emitRelatedFrame(fi->value.value.uinteger); } } } // XXX - Add routines to get our severity colors. if(FI_GET_FLAG(fi, PI_SEVERITY_MASK)) { switch(FI_GET_FLAG(fi, PI_SEVERITY_MASK)) { case(PI_COMMENT): item->setData(0, Qt::BackgroundRole, expert_color_comment); break; case(PI_CHAT): item->setData(0, Qt::BackgroundRole, expert_color_chat); break; case(PI_NOTE): item->setData(0, Qt::BackgroundRole, expert_color_note); break; case(PI_WARN): item->setData(0, Qt::BackgroundRole, expert_color_warn); break; case(PI_ERROR): item->setData(0, Qt::BackgroundRole, expert_color_error); break; default: g_assert_not_reached(); } item->setData(0, Qt::ForegroundRole, expert_color_foreground); } item->setText(0, label_ptr); item->setData(0, Qt::UserRole, qVariantFromValue(fi)); if (PROTO_ITEM_IS_GENERATED(node) || PROTO_ITEM_IS_HIDDEN(node)) { g_free(label_ptr); } if (is_branch) { if (tree_expanded(fi->tree_type)) { item->setExpanded(true); } else { item->setExpanded(false); } proto_tree_children_foreach(node, proto_tree_draw_node, item); } }