void qDrawWinPanel(QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, const QBrush *fill) { if (sunken) qDrawWinShades(p, x, y, w, h, pal.dark().color(), pal.light().color(), pal.shadow().color(), pal.midlight().color(), fill); else qDrawWinShades(p, x, y, w, h, pal.light().color(), pal.shadow().color(), pal.midlight().color(), pal.dark().color(), fill); }
void TimeTrackingView::PaintAttributes::initialize( const QPalette& palette ) { headerBrush = palette.mid(); taskBrushEven = palette.light(); taskBrushOdd = palette.midlight(); totalsRowBrush = headerBrush; totalsRowEvenDayBrush = QBrush( taskBrushEven.color().darker(125) ); headerEvenDayBrush = totalsRowEvenDayBrush; QColor dimHighlight = palette.highlight().color(); dim = 0.25; dimHighlight.setAlphaF( dim * dimHighlight.alphaF() ); const QBrush halfHighlight( dimHighlight ); runningTaskColor = palette.highlight().color(); }
/** Custom rendering. */ void SearchDialog::paintEvent(QPaintEvent *) { QStylePainter p(this); QPalette palette = QApplication::palette(); p.setPen(palette.mid().color()); p.setBrush(palette.base()); p.drawRect(rect().adjusted(0, 0, -1, -1)); p.setPen(palette.midlight().color()); p.drawLine(1, labelSearchMore->height() - 1, rect().width() - 2, labelSearchMore->height() - 1); int y = rect().y() + rect().height() - aggregated->height(); p.drawLine(39, rect().y() + labelSearchMore->height(), 39, y); p.drawLine(1, y, rect().width() - 2, y); }
QString Charm::reportStylesheet( const QPalette& palette ) { QString style; QFile stylesheet( ":/Charm/report_stylesheet.sty" ); if ( stylesheet.open( QIODevice::ReadOnly | QIODevice::Text ) ) { style = stylesheet.readAll(); style.replace(QLatin1String("@header_row_background_color@"), palette.highlight().color().name()); style.replace(QLatin1String("@header_row_foreground_color@"), palette.highlightedText().color().name()); style.replace(QLatin1String("@alternate_row_background_color@"), palette.alternateBase().color().name()); style.replace(QLatin1String("@event_attributes_row_background_color@"), palette.midlight().color().name()); if ( style.isEmpty() ) { qWarning() << "reportStylesheet: default style sheet is empty, too bad"; } } else { qCritical() << "reportStylesheet: cannot load report style sheet:" << stylesheet.errorString(); } return style; }
static void qtmDrawShadeRoundPanel(QPainter *p, const QRect &r, const QPalette &pal, bool sunken, int lineWidth, const QBrush *fill) { if (r.width() == 0 || r.height() == 0) return; if (!(r.width() > 0 && r.height() > 0 && lineWidth >= 0)) { qWarning("qtmDrawShadeRoundPanel: Invalid parameters"); } QColor shade = pal.dark().color(); QColor light = pal.light().color(); if (fill) { if (fill->color() == shade) shade = pal.shadow().color(); if (fill->color() == light) light = pal.midlight().color(); } QPen oldPen = p->pen(); // save pen QBrush oldBrush = p->brush(); // save brush QRect rect(r); int border = 8; p->setPen(Qt::NoPen); if (sunken) { p->setBrush(light); qtmDrawRoundedRect(p,rect,border,border, Qt::AbsoluteSize); // p->drawRoundedRect(rect,border,border, Qt::AbsoluteSize); rect.adjust(0,0,-1,-1); p->setBrush(shade); qtmDrawRoundedRect(p,rect,border,border, Qt::AbsoluteSize); // p->drawRoundedRect(rect,border,border, Qt::AbsoluteSize); rect.adjust(1,1,0,0); } p->setBrush(fill ? *fill : shade); qtmDrawRoundedRect(p,rect,border,border, Qt::AbsoluteSize); // p->drawRoundedRect(rect,border,border, Qt::AbsoluteSize); p->setPen(oldPen); // restore pen p->setBrush(oldBrush); // restore brush }
void KisCategorizedItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { painter->resetTransform(); if(!index.data(__CategorizedListModelBase::IsHeaderRole).toBool()) { QStyleOptionViewItem sovi(option); if (index.data(__CategorizedListModelBase::isLockableRole).toBool()) { bool locked = index.data(__CategorizedListModelBase::isLockedRole).toBool(); const QIcon icon = locked ? KisIconUtils::loadIcon(koIconName("locked")) : KisIconUtils::loadIcon(koIconName("unlocked")); const int iconSize = qMax(16, m_minimumItemHeight - 2); sovi.decorationPosition = QStyleOptionViewItem::Right; sovi.decorationAlignment = Qt::AlignRight; sovi.decorationSize = QSize(iconSize, iconSize); sovi.features |= QStyleOptionViewItem::HasDecoration; sovi.icon = icon; } QStyledItemDelegate::paint(painter, sovi, index); painter->setOpacity(1); } else { QPalette palette = QApplication::palette(); if(option.state & QStyle::State_MouseOver) painter->fillRect(option.rect, palette.midlight()); else painter->fillRect(option.rect, palette.button()); painter->setBrush(palette.buttonText()); painter->drawText(option.rect, index.data().toString(), QTextOption(Qt::AlignVCenter|Qt::AlignHCenter)); paintTriangle( painter, option.rect.x(), option.rect.y(), option.rect.height(), !index.data(__CategorizedListModelBase::ExpandCategoryRole).toBool() ); } painter->resetTransform(); }
// Channel strip activation/selection. void ChannelStrip::setSelected ( bool bSelected ) { if (bSelected) { if (g_pSelectedStrip == this) return; if (g_pSelectedStrip) g_pSelectedStrip->setSelected(false); g_pSelectedStrip = this; } else { if (g_pSelectedStrip == this) g_pSelectedStrip = NULL; } QPalette pal; if (bSelected) { const QColor& color = pal.midlight().color(); pal.setColor(QPalette::Background, color.dark(150)); pal.setColor(QPalette::Foreground, color.light(150)); } QWidget::setPalette(pal); }
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 qDrawShadePanel(QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, int lineWidth, const QBrush *fill) { if (w == 0 || h == 0) return; if (!(w > 0 && h > 0 && lineWidth >= 0)) { qWarning("qDrawShadePanel: Invalid parameters"); } QColor shade = pal.dark().color(); QColor light = pal.light().color(); if (fill) { if (fill->color() == shade) shade = pal.shadow().color(); if (fill->color() == light) light = pal.midlight().color(); } QPen oldPen = p->pen(); // save pen QVector<QLineF> lines; lines.reserve(2*lineWidth); if (sunken) p->setPen(shade); else p->setPen(light); int x1, y1, x2, y2; int i; x1 = x; y1 = y2 = y; x2 = x+w-2; for (i=0; i<lineWidth; i++) { // top shadow lines << QLineF(x1, y1++, x2--, y2++); } x2 = x1; y1 = y+h-2; for (i=0; i<lineWidth; i++) { // left shado lines << QLineF(x1++, y1, x2++, y2--); } p->drawLines(lines); lines.clear(); if (sunken) p->setPen(light); else p->setPen(shade); x1 = x; y1 = y2 = y+h-1; x2 = x+w-1; for (i=0; i<lineWidth; i++) { // bottom shadow lines << QLineF(x1++, y1--, x2, y2--); } x1 = x2; y1 = y; y2 = y+h-lineWidth-1; for (i=0; i<lineWidth; i++) { // right shadow lines << QLineF(x1--, y1++, x2--, y2); } p->drawLines(lines); if (fill) // fill with fill color p->fillRect(x+lineWidth, y+lineWidth, w-lineWidth*2, h-lineWidth*2, *fill); p->setPen(oldPen); // restore pen }
/** Redefined to be able to display items with the current theme. */ void AddressBarMenu::paintEvent(QPaintEvent *) { QStylePainter p(this->viewport()); // Vertical frame between icons and text p.save(); QPalette palette = QApplication::palette(); p.setPen(palette.midlight().color()); p.drawLine(33, 0, 33, rect().height()); p.restore(); int offsetSB = 0; if (verticalScrollBar()->isVisible()) { offsetSB = verticalScrollBar()->width() - 1; } // Subdirectories in the popup menu for (int i = 0; i < count(); i ++) { QListWidgetItem *it = item(i); QRect r = this->visualItemRect(it); /// FIXME //QSize s = it->sizeHint(); //QRect r(0, i * s.height(), ); //qDebug() << "r" << r; r.setWidth(r.width() - offsetSB); if (it->data(Qt::UserRole + 1).toBool()) { p.save(); p.setPen(palette.midlight().color()); p.drawLine(r.x(), r.y() + (it->sizeHint().height()) / 2, r.width(), r.y() + (it->sizeHint().height()) / 2); p.restore(); continue; } r.adjust(1, 1, -4, -1); bool isHighlighted = r.contains(mapFromGlobal(QCursor::pos())); // Draw: Highlight, Icon, Text if (r.isValid()) { QRect iconRect(r.x() + 6, r.y() + 2, 19, 19); bool itemIsEnabled = true; if (it->flags().testFlag(Qt::NoItemFlags)) { p.drawPixmap(iconRect, it->icon().pixmap(QSize(19, 19), QIcon::Disabled)); itemIsEnabled = false; } else { p.save(); if (isHighlighted) { p.setPen(palette.highlight().color()); p.setBrush(palette.highlight().color().lighter()); p.drawRect(r); p.setPen(QColor(192, 192, 192, 128)); p.drawLine(33, r.top() + 1, 33, r.bottom()); } p.restore(); p.drawPixmap(iconRect, it->icon().pixmap(QSize(19, 19))); } QRect textRect = r.adjusted(37, 0, 0, 0); QString text = fontMetrics().elidedText(it->text(), Qt::ElideRight, textRect.width()); p.save(); p.setFont(it->font()); QColor lighterBG = palette.highlight().color().lighter(); QColor highlightedText = palette.highlightedText().color(); if (itemIsEnabled && isHighlighted && qAbs(lighterBG.saturation() - highlightedText.saturation()) > 128) { p.setPen(highlightedText); } else { if (itemIsEnabled) { p.setPen(palette.text().color()); } else { p.setPen(palette.color(QPalette::Disabled, QPalette::WindowText)); } } p.drawText(textRect, text, Qt::AlignLeft | Qt::AlignVCenter); p.restore(); } } }
void KTThemeSelector::setupChooseColor() { DVHBox *hbox = new DVHBox(this, Qt::Horizontal); DVHBox *box1 = new DVHBox(hbox, Qt::Vertical); box1->boxLayout()->setMargin(10); m_general = new QGroupBox(tr("General"), box1); QGridLayout *layout1 = new QGridLayout(m_general); QStringList labels1 = QStringList() << tr("Text") << tr("Base") << tr("Foreground") << tr("Background") << tr("Button") << tr("Button Text"); QStringList names = QStringList() << "Text" << "Base" << "Foreground" << "Background" << "Button" << "ButtonText"; QPalette colorGroup = QApplication::palette(); QList<QColor> colors = QList<QColor>() << colorGroup.text ().color() << colorGroup.base().color() << colorGroup.foreground().color() << colorGroup.background().color() << colorGroup.button().color() << colorGroup.buttonText().color(); for(int i = 0; i < labels1.count(); i++) { layout1->addWidget(new QLabel(labels1[i], m_general), i, 0 ); DColorButton *button = new DColorButton(m_general); button->setObjectName(names[i]); QPalette pal = button->palette(); pal.setColor(QPalette::Button, colors[i]); button->setPalette(pal); m_generalButtonGroup.addButton(button); layout1->addWidget(button, i, 1); m_generalSection.insert(names[i], colors[i].name()); } m_effects = new QGroupBox(tr("Effects"), box1); QGridLayout *layout2 = new QGridLayout(m_effects); QStringList labels2 = QStringList() << tr("Light") << tr("Midlight") << tr("Dark") << tr("Mid"); QStringList names2 = QStringList() << "Light" << "Midlight" << "Dark" << "Mid"; colors.clear(); colors << colorGroup.light().color() << colorGroup.midlight().color() << colorGroup.dark().color() << colorGroup.mid().color(); for(int i = 0; i < labels2.count(); i++) { layout2->addWidget(new QLabel(labels2[i], m_effects), i, 0 ); DColorButton *button = new DColorButton(m_effects); button->setObjectName(names2[i]); QPalette pal = button->palette(); pal.setColor(QPalette::Button, colors[i]); button->setPalette(pal); m_effectsButtonGroup.addButton(button); layout2->addWidget(button, i, 1); m_effectsSection.insert(names2[i], colors[i].name()); } //////////// DVHBox *box2 = new DVHBox(hbox, Qt::Vertical); box2->boxLayout()->setMargin(10); m_selections = new QGroupBox(tr("Selections"), box2); QGridLayout *layout3 = new QGridLayout(m_selections); QStringList labels3 = QStringList() << tr("Highlight") << tr("Highlighted Text"); QStringList names3 = QStringList() << "Highlight" << "HighlightedText"; colors.clear(); colors << colorGroup.highlight().color() << colorGroup.highlightedText().color(); for(int i = 0; i < labels3.count(); i++) { layout3->addWidget(new QLabel(labels3[i], m_selections), i, 0 ); DColorButton *button = new DColorButton(m_selections); button->setObjectName(names3[i]); QPalette pal = button->palette(); pal.setColor(QPalette::Button, colors[i]); button->setPalette(pal); m_selectionsButtonGroup.addButton(button); layout3->addWidget(button, i, 1); m_selectionsSection.insert(names3[i], colors[i].name()); } m_textEffects = new QGroupBox(tr("Text effects"), box2); QGridLayout *layout4 = new QGridLayout(m_textEffects); QStringList labels4 = QStringList() << tr("Bright Text") << tr("Link") << tr("Link Visited"); QStringList names4 = QStringList() << "BrightText" << "Link" << "LinkVisited"; colors.clear(); colors << colorGroup.brightText().color() << colorGroup.link().color() << colorGroup.linkVisited().color(); for(int i = 0; i < labels4.count(); i++) { layout4->addWidget(new QLabel(labels4[i], m_textEffects), i, 0 ); DColorButton *button = new DColorButton(m_textEffects); button->setObjectName(names4[i]); QPalette pal = button->palette(); pal.setColor(QPalette::Button, colors[i]); button->setPalette(pal); m_textEffectsButtonGroup.addButton(button); layout4->addWidget(button, i, 1); m_textEffectsSection.insert(names4[i], colors[i].name()); } QGroupBox *schemeWidget = new QGroupBox(tr("Schema"), box2); // FIXME: add vertical layout QVBoxLayout *schemaLayout = new QVBoxLayout; m_allSchemes = new QTreeWidget; m_allSchemes->setHeaderLabels ( QStringList() << tr("Schema") << tr( "Owner" ) << tr( "Date" ) ); m_allSchemes->header()->setResizeMode(QHeaderView::Stretch); schemaLayout->addWidget(m_allSchemes); connect(m_allSchemes, SIGNAL(itemDoubleClicked (QTreeWidgetItem *, int )), this, SLOT(loadSchemaFromListView( QTreeWidgetItem *, int ))); QPushButton *saveSchemeButton = new QPushButton(tr("Save schema")); connect(saveSchemeButton, SIGNAL(clicked()), SLOT(saveSchema())); schemaLayout->addWidget(saveSchemeButton); schemeWidget->setLayout(schemaLayout); new DSeparator(this); new QLabel(tr("Style"), this); DStyleComboBox *styleComboBox = new DStyleComboBox(this); Q_UNUSED(styleComboBox); new DSeparator(this); m_useColors = new QCheckBox(tr("Use this colors"), this); connect(&m_generalButtonGroup, SIGNAL(buttonClicked(QAbstractButton * )), SLOT(chooseGeneralColor(QAbstractButton * ))); connect(&m_effectsButtonGroup, SIGNAL(buttonClicked(QAbstractButton * )), SLOT(chooseEffectsColor(QAbstractButton * ))); connect(&m_selectionsButtonGroup, SIGNAL(buttonClicked(QAbstractButton * )), SLOT(chooseSelectionsColor(QAbstractButton * ))); connect(&m_textEffectsButtonGroup, SIGNAL(buttonClicked(QAbstractButton * )), SLOT(chooseTextEffectsColor(QAbstractButton * ))); }
/** Redefined to be style-aware at runtime. */ void ExtendedTabBar::paintEvent(QPaintEvent *) { QStyleOptionTab lib, fe; initStyleOption(&lib, 0); initStyleOption(&fe, 1); QPalette pal = QApplication::palette(); QStylePainter p(this); // Library is selected if (currentIndex() == 0) { p.fillRect(lib.rect, lib.palette.base().color()); p.setPen(pal.text().color()); p.drawText(lib.rect, Qt::AlignCenter, fontMetrics().elidedText(lib.text, Qt::ElideRight, lib.rect.width())); // Draw Top and Right lines only p.setPen(pal.mid().color()); p.drawLine(lib.rect.x(), lib.rect.y(), lib.rect.x() + lib.rect.width(), lib.rect.y()); if (isLeftToRight()) { p.drawLine(lib.rect.x() + lib.rect.width(), lib.rect.y(), lib.rect.x() + lib.rect.width(), lib.rect.y() + lib.rect.height()); } else { p.drawLine(lib.rect.x(), lib.rect.y(), lib.rect.x(), lib.rect.y() + lib.rect.height()); } // Reduce the size of unselected tab fe.rect.adjust(3, 2, -3, 0); if (fe.state.testFlag(QStyle::State_MouseOver)) { p.fillRect(fe.rect, pal.highlight().color().light()); p.setPen(pal.text().color()); p.drawText(fe.rect, Qt::AlignCenter, fontMetrics().elidedText(fe.text, Qt::ElideRight, fe.rect.width())); p.setPen(fe.palette.highlight().color()); } else { p.fillRect(fe.rect, pal.light().color()); p.setPen(pal.mid().color()); p.drawText(fe.rect, Qt::AlignCenter, fontMetrics().elidedText(fe.text, Qt::ElideRight, fe.rect.width())); p.setPen(pal.midlight().color()); } // Draw Left, Top and Right lines p.drawLine(fe.rect.x(), fe.rect.y() + fe.rect.height(), fe.rect.x(), fe.rect.y()); p.drawLine(fe.rect.x(), fe.rect.y(), fe.rect.x() + fe.rect.width(), fe.rect.y()); p.drawLine(fe.rect.x() + fe.rect.width(), fe.rect.y(), fe.rect.x() + fe.rect.width(), fe.rect.y() + fe.rect.height()); // Draw bottom line p.setPen(pal.mid().color()); if (isLeftToRight()) { p.drawLine(rect().x() + rect().width() / 2, rect().y() + rect().height() - 1, rect().x() + rect().width(), rect().y() + rect().height() - 1); } else { p.drawLine(rect().x(), rect().y() + rect().height() - 1, rect().x() + rect().width() / 2, rect().y() + rect().height() - 1); } } else { p.fillRect(fe.rect, lib.palette.base().color()); p.setPen(pal.text().color()); p.drawText(fe.rect, Qt::AlignCenter, fontMetrics().elidedText(fe.text, Qt::ElideRight, fe.rect.width())); if (isLeftToRight()) { if (rect().width() % 2 == 0) { lib.rect.adjust(0, 0, -1, 0); fe.rect.adjust(-1, 0, -1, 0); } } else { if (rect().width() % 2 == 1) { lib.rect.adjust(0, 0, -1, 0); fe.rect.adjust(1, 0, -1, 0); } } // Draw Left, Top and Right lines p.setPen(pal.mid().color()); p.drawLine(fe.rect.x(), fe.rect.y() + fe.rect.height(), fe.rect.x(), fe.rect.y()); p.drawLine(fe.rect.x(), fe.rect.y(), fe.rect.x() + fe.rect.width(), fe.rect.y()); p.drawLine(fe.rect.x() + fe.rect.width(), fe.rect.y(), fe.rect.x() + fe.rect.width(), fe.rect.y() + fe.rect.height()); // Reduce the size of unselected tab lib.rect.adjust(2, 2, -3, 0); if (lib.state.testFlag(QStyle::State_MouseOver)) { p.fillRect(lib.rect, pal.highlight().color().light()); p.setPen(pal.text().color()); p.drawText(lib.rect, Qt::AlignCenter, fontMetrics().elidedText(lib.text, Qt::ElideRight, lib.rect.width())); p.setPen(lib.palette.highlight().color()); } else { p.fillRect(lib.rect, pal.light().color()); p.setPen(pal.mid().color()); p.drawText(lib.rect, Qt::AlignCenter, fontMetrics().elidedText(lib.text, Qt::ElideRight, lib.rect.width())); p.setPen(pal.midlight().color()); } // Draw Left, Top and Right lines p.drawLine(lib.rect.x(), lib.rect.y() + lib.rect.height(), lib.rect.x(), lib.rect.y()); p.drawLine(lib.rect.x(), lib.rect.y(), lib.rect.x() + lib.rect.width(), lib.rect.y()); p.drawLine(lib.rect.x() + lib.rect.width(), lib.rect.y(), lib.rect.x() + lib.rect.width(), lib.rect.y() + lib.rect.height()); } }