void TextOutput::loadColorStyleScheme() { bool useColorShceme = m_liteApp->settings()->value(TEXTOUTPUT_USECOLORSCHEME,true).toBool(); const ColorStyleScheme *colorScheme = m_liteApp->editorManager()->colorStyleScheme(); const ColorStyle *text = colorScheme->findStyle("Text"); const ColorStyle *selection = colorScheme->findStyle("Selection"); const ColorStyle *keyword = colorScheme->findStyle("Keyword"); const ColorStyle *error = colorScheme->findStyle("Error"); QPalette p = this->m_defPalette; if (useColorShceme && text) { if (text->foregound().isValid()) { p.setColor(QPalette::Text,text->foregound()); p.setColor(QPalette::Foreground, text->foregound()); } if (text->background().isValid()) { p.setColor(QPalette::Base, text->background()); } } if (useColorShceme && selection) { if (selection->foregound().isValid()) { p.setColor(QPalette::HighlightedText, selection->foregound()); } if (selection->background().isValid()) { p.setColor(QPalette::Highlight, selection->background()); } p.setBrush(QPalette::Inactive, QPalette::Highlight, p.highlight()); p.setBrush(QPalette::Inactive, QPalette::HighlightedText, p.highlightedText()); } QString sheet = QString("QPlainTextEdit{color:%1;background-color:%2;selection-color:%3;selection-background-color:%4;}") .arg(p.text().color().name()) .arg(p.base().color().name()) .arg(p.highlightedText().color().name()) .arg(p.highlight().color().name()); this->setPalette(p); this->setStyleSheet(sheet); m_clrText = p.text().color(); m_fmt.setForeground(p.text().color()); m_fmt.setBackground(p.base().color()); if (useColorShceme && keyword && keyword->foregound().isValid()) { m_clrTag = keyword->foregound(); } else { m_clrTag = Qt::darkBlue; } if (useColorShceme && error && error->foregound().isValid()) { m_clrError = error->foregound(); } else { m_clrError = Qt::red; } this->updateExistsTextColor(); }
void KstMatrixTable::paintCell( QPainter* painter, int row, int col, const QRect& cr, bool selected, const QPalette &palette ) { KstMatrixPtr matrix = *KST::matrixList.findTag(_strMatrix); QString str; double value; painter->eraseRect( 0, 0, cr.width(), cr.height() ); if (selected) { painter->fillRect( 0, 0, cr.width(), cr.height(), palette.highlight() ); painter->setPen(palette.highlightedText().color()); } else { painter->fillRect( 0, 0, cr.width(), cr.height(), palette.base() ); painter->setPen(palette.text().color()); } if (matrix) { bool ok; value = matrix->valueRaw(col, row, &ok); if (ok) { str.setNum(value, 'g', 16); } else { str = "-"; } } painter->drawText(0, 0, cr.width(), cr.height(), Qt::AlignLeft, str); }
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 FormStyle::GlobalColorButtonCliked() { QColor initialColor; if ( focusWidget()->objectName() == "bC1_1" ) initialColor = applicationPalette.button().color().rgba(); else if ( focusWidget()->objectName() == "bC1_2" ) initialColor = applicationPalette.window().color().rgba(); else if ( focusWidget()->objectName() == "bC1_3" ) initialColor = applicationPalette.shadow().color().rgba(); else if ( focusWidget()->objectName() == "bC1_4" ) initialColor = applicationPalette.highlight().color().rgba(); else if ( focusWidget()->objectName() == "bC1_5" ) initialColor = applicationPalette.base().color().rgba(); else if ( focusWidget()->objectName() == "bC1_6" ) initialColor = applicationPalette.text().color().rgba(); else if ( focusWidget()->objectName() == "bC1_7" ) initialColor = applicationPalette.highlightedText().color().rgba(); else if ( focusWidget()->objectName() == "bC1_8" ) initialColor = sliderButtonColor.rgb(); else initialColor = Qt::white; QColor color = QColorDialog::getColor( initialColor, this, Texts[ 119 ] /*Wybierz kolor*/, QColorDialog::DontUseNativeDialog ); if ( !color.isValid() ) return; if ( focusWidget()->objectName() == "bC1_1" ) applicationPalette.setBrush( QPalette::Button, color ); else if ( focusWidget()->objectName() == "bC1_2" ) applicationPalette.setBrush( QPalette::Window, color ); else if ( focusWidget()->objectName() == "bC1_3" ) { applicationPalette.setBrush( QPalette::Shadow, color ); applicationPalette.setBrush( QPalette::Light, color ); applicationPalette.setBrush( QPalette::Dark, color ); } else if ( focusWidget()->objectName() == "bC1_4" ) applicationPalette.setBrush( QPalette::Highlight, color ); else if ( focusWidget()->objectName() == "bC1_5" ) applicationPalette.setBrush( QPalette::Base, color ); else if ( focusWidget()->objectName() == "bC1_6" ) { applicationPalette.setBrush( QPalette::Text, color ); applicationPalette.setBrush( QPalette::WindowText, color ); applicationPalette.setBrush( QPalette::ButtonText, color ); } else if ( focusWidget()->objectName() == "bC1_7" ) applicationPalette.setBrush( QPalette::HighlightedText, color ); else if ( focusWidget()->objectName() == "bC1_8" ) sliderButtonColor = color; setButtonsColor(); }
/*! \~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() ); }
void FormStyle::setButtonsColor() { if ( ui.ccB->isChecked() ) { QPalette tmpPalette; tmpPalette.setBrush( QPalette::Button, applicationPalette.button() ); ui.bC1_1->setPalette( tmpPalette ); tmpPalette.setBrush( QPalette::Button, applicationPalette.window() ); ui.bC1_2->setPalette( tmpPalette ); tmpPalette.setBrush( QPalette::Button, applicationPalette.shadow() ); ui.bC1_3->setPalette( tmpPalette ); tmpPalette.setBrush( QPalette::Button, applicationPalette.highlight() ); ui.bC1_4->setPalette( tmpPalette ); tmpPalette.setBrush( QPalette::Button, applicationPalette.base() ); ui.bC1_5->setPalette( tmpPalette ); tmpPalette.setBrush( QPalette::Button, applicationPalette.text() ); ui.bC1_6->setPalette( tmpPalette ); tmpPalette.setBrush( QPalette::Button, applicationPalette.highlightedText() ); ui.bC1_7->setPalette( tmpPalette ); tmpPalette.setBrush( QPalette::Button, sliderButtonColor ); ui.bC1_8->setPalette( tmpPalette ); if ( !mainWindowPixmap.isNull() ) { QBrush brushW( mainWindowPixmap.scaled( ui.bP2_2->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) ); tmpPalette.setBrush( QPalette::Button, brushW ); ui.bP2_2->setPalette( tmpPalette ); } else ui.bP2_2->setPalette( qApp->palette() ); } else { ui.bC1_1->setPalette( qApp->palette() ); ui.bC1_2->setPalette( qApp->palette() ); ui.bC1_3->setPalette( qApp->palette() ); ui.bC1_4->setPalette( qApp->palette() ); ui.bC1_5->setPalette( qApp->palette() ); ui.bC1_6->setPalette( qApp->palette() ); ui.bC1_7->setPalette( qApp->palette() ); ui.bC1_8->setPalette( qApp->palette() ); ui.bP2_2->setPalette( qApp->palette() ); } }
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; }
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 MiamStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { switch (element) { case CE_MenuBarItem: { const QStyleOptionMenuItem *somi = static_cast<const QStyleOptionMenuItem*>(option); const bool act = somi->state & (State_Sunken | State_Selected); QPalette palette = QApplication::palette(); QBrush brush; //bool dirtyHackMnemonic = widget->property("dirtyHackMnemonic").toBool(); if (act/* || dirtyHackMnemonic && option->rect.x() == 0*/) { painter->setPen(palette.highlight().color()); brush = palette.highlight().color().light(); painter->setBrush(brush); painter->drawRect(option->rect.adjusted(0, 0, -1, -1)); } else { brush = palette.window(); painter->fillRect(option->rect, palette.window()); } uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; if (/*dirtyHackMnemonic == false &&*/ !styleHint(SH_UnderlineShortcut, somi, widget)) { alignment |= Qt::TextHideMnemonic; } if (qAbs(palette.text().color().value() - brush.color().value()) < 128) { painter->setPen(palette.highlightedText().color()); } else { painter->setPen(palette.text().color()); } painter->drawText(option->rect, alignment, somi->text); break; } case CE_MenuBarEmptyArea: { painter->fillRect(option->rect, QApplication::palette().window()); break; } default: QProxyStyle::drawControl(element, option, painter, widget); } }
void QgisAppStyleSheet::buildStyleSheet( const QMap<QString, QVariant> &opts ) { QString ss; // QgisApp-wide font QString fontSize = opts.value( QStringLiteral( "fontPointSize" ) ).toString(); QgsDebugMsg( QStringLiteral( "fontPointSize: %1" ).arg( fontSize ) ); if ( fontSize.isEmpty() ) { return; } QString fontFamily = opts.value( QStringLiteral( "fontFamily" ) ).toString(); QgsDebugMsg( QStringLiteral( "fontFamily: %1" ).arg( fontFamily ) ); if ( fontFamily.isEmpty() ) { return; } const QString defaultSize = QString::number( mDefaultFont.pointSize() ); const QString defaultFamily = mDefaultFont.family(); if ( fontSize != defaultSize || fontFamily != defaultFamily ) ss += QStringLiteral( "* { font: %1pt \"%2\"} " ).arg( fontSize, fontFamily ); // Fix for macOS Qt 5.9+, where close boxes do not show on document mode tab bar tabs // See: https://bugreports.qt.io/browse/QTBUG-61092 // https://bugreports.qt.io/browse/QTBUG-61742 // Setting any stylesheet makes the default close button disappear. // Specifically setting a custom close button temporarily works around issue. // TODO: Remove when regression is fixed (Qt 5.9.3 or 5.10?); though hard to tell, // since we are overriding the default close button image now. if ( mMacStyle ) { ss += QLatin1String( "QTabBar::close-button{ image: url(:/images/themes/default/mIconCloseTab.svg); }" ); ss += QLatin1String( "QTabBar::close-button:hover{ image: url(:/images/themes/default/mIconCloseTabHover.svg); }" ); } // QGroupBox and QgsCollapsibleGroupBox, mostly for Ubuntu and Mac bool gbxCustom = opts.value( QStringLiteral( "groupBoxCustom" ) ).toBool(); QgsDebugMsg( QStringLiteral( "groupBoxCustom: %1" ).arg( gbxCustom ) ); ss += QLatin1String( "QGroupBox{" ); // doesn't work for QGroupBox::title ss += QStringLiteral( "color: rgb(%1,%1,%1);" ).arg( mMacStyle ? 25 : 60 ); ss += QLatin1String( "font-weight: bold;" ); if ( gbxCustom ) { ss += QStringLiteral( "background-color: rgba(0,0,0,%1%);" ) .arg( mWinOS && mStyle.startsWith( QLatin1String( "windows" ) ) ? 0 : 3 ); ss += QLatin1String( "border: 1px solid rgba(0,0,0,20%);" ); ss += QLatin1String( "border-radius: 5px;" ); ss += QLatin1String( "margin-top: 2.5ex;" ); ss += QStringLiteral( "margin-bottom: %1ex;" ).arg( mMacStyle ? 1.5 : 1 ); } ss += QLatin1String( "} " ); if ( gbxCustom ) { ss += QLatin1String( "QGroupBox:flat{" ); ss += QLatin1String( "background-color: rgba(0,0,0,0);" ); ss += QLatin1String( "border: rgba(0,0,0,0);" ); ss += QLatin1String( "} " ); ss += QLatin1String( "QGroupBox::title{" ); ss += QLatin1String( "subcontrol-origin: margin;" ); ss += QLatin1String( "subcontrol-position: top left;" ); ss += QLatin1String( "margin-left: 6px;" ); if ( !( mWinOS && mStyle.startsWith( QLatin1String( "windows" ) ) ) && !mOxyStyle ) { ss += QLatin1String( "background-color: rgba(0,0,0,0);" ); } ss += QLatin1String( "} " ); } //sidebar style QString style = "QListWidget#mOptionsListWidget {" " background-color: rgb(69, 69, 69, 0);" " outline: 0;" "}" "QFrame#mOptionsListFrame {" " background-color: rgb(69, 69, 69, 220);" "}" "QListWidget#mOptionsListWidget::item {" " color: white;" " padding: 3px;" "}" "QListWidget#mOptionsListWidget::item::selected {" " color: black;" " background-color:palette(Window);" " padding-right: 0px;" "}"; ss += style; // Fix selection color on losing focus (Windows) const QPalette palette = qApp->palette(); ss += QString( "QTableView {" "selection-background-color: %1;" "selection-color: %2;" "}" ) .arg( palette.highlight().color().name(), palette.highlightedText().color().name() ); QString toolbarSpacing = opts.value( QStringLiteral( "toolbarSpacing" ), QString() ).toString(); if ( !toolbarSpacing.isEmpty() ) { bool ok = false; int toolbarSpacingInt = toolbarSpacing.toInt( &ok ); if ( ok ) { ss += QStringLiteral( "QToolBar > QToolButton { padding: %1px; } " ).arg( toolbarSpacingInt ); } } QgsDebugMsg( QStringLiteral( "Stylesheet built: %1" ).arg( ss ) ); emit appStyleSheetChanged( ss ); }
void FileView::paint(QPainter* painter, const QRect& rect, const QPalette& palette, DisplayMode displayMode) const { painter->save(); painter->setRenderHint(QPainter::Antialiasing, true); painter->translate(rect.x(), rect.y()); if(displayMode == DM_Selected) painter->setBrush(palette.highlightedText()); else painter->setBrush(palette.foreground()); painter->setPen(QPen(painter->brush(), 1)); int textFlags = Qt::AlignLeft | Qt::AlignVCenter; QFont font(painter->font()); font.setBold(true); painter->setFont(font); QString nameDisplay = (mode == TM_Send) ? tr("To: ") : tr("From: "); nameDisplay.append(userName); QRect textRect = QRect(54, 0, rect.width() - 58, 18); QString text = painter->fontMetrics().elidedText(nameDisplay, Qt::ElideRight, textRect.width()); painter->drawText(textRect, textFlags, text); font.setBold(false); painter->setFont(font); textRect = QRect(54, 18, rect.width() - 58, 18); text = painter->fontMetrics().elidedText(fileDisplay, Qt::ElideMiddle, textRect.width()); painter->drawText(textRect, textFlags, text); bool drawProgress = false; QString stateDisplay; switch(state) { case TS_Send: stateDisplay = timeDisplay + " left - " + posDisplay + " of " + sizeDisplay + " (" + speedDisplay + ")"; drawProgress = true; break; case TS_Receive: stateDisplay = timeDisplay + " left - " + posDisplay + " of " + sizeDisplay + " (" + speedDisplay + ")"; drawProgress = true; break; case TS_Complete: stateDisplay = tr("Completed"); break; case TS_Cancel: stateDisplay = tr("Canceled"); break; case TS_Abort: stateDisplay = tr("Interrupted"); break; default: break; } textRect = QRect(54, 36, rect.width() - 58, 18); text = painter->fontMetrics().elidedText(stateDisplay, Qt::ElideRight, textRect.width()); painter->drawText(textRect, textFlags, text); if(drawProgress) { int spanAngle = ((double)position / (double)fileSize) * 360; painter->setBrush(QBrush(QColor(230, 230, 230))); painter->setPen(QPen(QColor(230, 230, 230))); painter->drawPie(4, 4, 46, 46, (90 - spanAngle) * 16, -(360 - spanAngle) * 16); painter->setBrush(QBrush(QColor(150, 225, 110))); painter->setPen(QPen(QColor(150, 225, 110))); painter->drawPie(4, 4, 46, 46, 90 * 16, -spanAngle * 16); painter->setBrush(QBrush(QColor(255, 255, 255))); painter->setPen(QPen(QColor(255, 255, 255), 2)); painter->drawLine(27, 5, 27, 49); painter->drawLine(5, 27, 49, 27); painter->drawLine(11, 11, 42, 42); painter->drawLine(42, 11, 11, 42); } QRect imageRect(11, 11, 32, 32); painter->drawPixmap(imageRect, icon); painter->restore(); }
/** 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(); } } }
QWidget *MemcheckErrorDelegate::createDetailsWidget(const QModelIndex &errorIndex, QWidget *parent) const { QWidget *widget = new QWidget(parent); QVBoxLayout *layout = new QVBoxLayout; // code + white-space:pre so the padding (see below) works properly // don't include frameName here as it should wrap if required and pre-line is not supported // by Qt yet it seems const QString displayTextTemplate = QString("<code style='white-space:pre'>%1:</code> %2"); QString relativeTo = relativeToPath(); const Error error = errorIndex.data(ErrorListModel::ErrorRole).value<Error>(); QLabel *errorLabel = new QLabel(); errorLabel->setWordWrap(true); errorLabel->setContentsMargins(0, 0, 0, 0); errorLabel->setMargin(0); errorLabel->setIndent(0); QPalette p = errorLabel->palette(); QColor lc = p.color(QPalette::Text); QString linkStyle = QString("style=\"color:rgba(%1, %2, %3, %4);\"") .arg(lc.red()).arg(lc.green()).arg(lc.blue()).arg(int(0.7 * 255)); p.setBrush(QPalette::Text, p.highlightedText()); errorLabel->setPalette(p); errorLabel->setText(QString("%1 <span %4>%2</span>") .arg(error.what(), errorLocation(errorIndex, error, true, linkStyle), linkStyle)); connect(errorLabel, SIGNAL(linkActivated(QString)), SLOT(openLinkInEditor(QString))); layout->addWidget(errorLabel); const QVector<Stack> stacks = error.stacks(); for (int i = 0; i < stacks.count(); ++i) { const Stack &stack = stacks.at(i); // auxwhat for additional stacks if (i > 0) { QLabel *stackLabel = new QLabel(stack.auxWhat()); stackLabel->setWordWrap(true); stackLabel->setContentsMargins(0, 0, 0, 0); stackLabel->setMargin(0); stackLabel->setIndent(0); QPalette p = stackLabel->palette(); p.setBrush(QPalette::Text, p.highlightedText()); stackLabel->setPalette(p); layout->addWidget(stackLabel); } int frameNr = 1; foreach (const Frame &frame, stack.frames()) { QString frameName = makeFrameName(frame, relativeTo); QTC_ASSERT(!frameName.isEmpty(), qt_noop()); QLabel *frameLabel = new QLabel(widget); frameLabel->setAutoFillBackground(true); if (frameNr % 2 == 0) { // alternating rows QPalette p = frameLabel->palette(); p.setBrush(QPalette::Base, p.alternateBase()); frameLabel->setPalette(p); } frameLabel->setFont(QFont("monospace")); connect(frameLabel, SIGNAL(linkActivated(QString)), SLOT(openLinkInEditor(QString))); // pad frameNr to 2 chars since only 50 frames max are supported by valgrind const QString displayText = displayTextTemplate .arg(frameNr++, 2).arg(frameName); frameLabel->setText(displayText); frameLabel->setToolTip(Valgrind::XmlProtocol::toolTipForFrame(frame)); frameLabel->setWordWrap(true); frameLabel->setContentsMargins(0, 0, 0, 0); frameLabel->setMargin(0); frameLabel->setIndent(10); layout->addWidget(frameLabel); } } layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); widget->setLayout(layout); return widget; }
QString ExportPreview::PrepareHTML(){ using namespace std; QString lipsum; lipsum.append("<p style=\"color: blue; font-size: smaller\"><b>FYI:</b> This is the classic <em>Lorem Ipsum</em> text that has been used" " for placeholder purposes throughout the print industry since the 1500s." " Its purpose here is to test how large blocks of text will look with the fonts and sizes you have selected." " These results are generally consistent but may vary slightly depending on which browser you use (This example is rendered with Webkit).</p>"); lipsum.append("<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque laoreet vestibulum libero vitae accumsan. "); lipsum.append("Nullam et nulla nunc, non luctus elit. Etiam aliquam, turpis nec pellentesque interdum, purus nulla dictum tortor, "); lipsum.append("nec lacinia orci turpis ac lectus. Suspendisse dignissim, lectus nec posuere consectetur, massa quam rhoncus velit, "); lipsum.append("eu viverra est risus ac enim. Nullam augue lacus, imperdiet ac iaculis eu, scelerisque quis nulla. Donec tempor "); lipsum.append("lacus molestie arcu aliquam scelerisque. Proin vitae augue quis quam imperdiet porttitor id sed magna. Nulla non "); lipsum.append("urna purus. Vivamus dui diam, eleifend a laoreet sit amet, dignissim vel odio. Pellentesque adipiscing sodales ante "); lipsum.append("at tempor. Vestibulum libero risus, malesuada vel scelerisque ut, facilisis ac nulla. Nam congue urna non diam pretium "); lipsum.append("dapibus.</p>"); lipsum.append("<p>Proin viverra odio a dolor lacinia tincidunt. Nunc tempor adipiscing dolor, id condimentum leo facilisis a. Aliquam "); lipsum.append("erat volutpat. Cras vitae ligula mauris. Etiam nec orci ac velit mattis semper vel ut metus. Pellentesque sagittis "); lipsum.append("ultricies nisi, at commodo metus posuere a. Sed neque nunc, sagittis non elementum ut, imperdiet eget purus. "); lipsum.append("Nulla non tortor sit amet ipsum porttitor suscipit. Maecenas ipsum erat, porta id porta ac, convallis sit amet erat. "); lipsum.append("Nunc libero felis, blandit id vehicula dapibus, vehicula quis erat. Nam feugiat, elit a vestibulum sagittis, diam "); lipsum.append("metus faucibus nulla, hendrerit ullamcorper mi nulla sit amet tellus. Praesent placerat velit quis lectus lacinia "); lipsum.append("sed laoreet magna sagittis. Maecenas lacinia, metus at ultrices sodales, quam orci ullamcorper neque, viverra "); lipsum.append("molestie metus dolor vel velit. Mauris ligula orci, ullamcorper at adipiscing ornare, euismod sed augue. Praesent "); lipsum.append("nec leo arcu, id elementum leo. Aliquam fringilla semper nulla, eget congue turpis volutpat sed.</p>"); QString css_header_spec; if(use_em_header){ css_header_spec=header_size + "em"; } else{ css_header_spec=header_size + "pt"; } QString css_body_spec; if(use_em_body){ css_body_spec=body_size + "em"; } else{ css_body_spec=body_size + "pt"; } QString bgcolor; QString datebox_color; if(use_system_colors){ // use system colors for datebox QPalette pal; QColor bg=pal.highlight().color(); QColor fg=pal.highlightedText().color(); bgcolor=bg.name(); datebox_color=fg.name(); } else{ bgcolor="#e2e2e2"; datebox_color="#000000"; } QString output; output.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"" "\"http://www.w3.org/TR/html4/strict.dtd\">\n"); output.append("<html>\n"); output.append("<head>\n"); output.append("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">\n"); output.append("<title>Sample Entry</title>\n"); output.append("<style type=\"text/css\">\n"); output.append("\tbody{\n\t\tbackground-color: #ffffff;\n\t}\n\n\n"); output.append("\tp{\n\t\tfont-family: " + body_font + "; \n\t\tfont-size: " + css_body_spec + "; \n\t\tmargin-bottom: 1em;\n\t}\n\n\n"); output.append("\th1{\n\t\tfont-family: " + header_font + "; \n\t\tfont-size: " + css_header_spec + ";\n\t}\n\n\n"); if(use_rounded){ output.append("\t.datebox{\n\t\tbackground-color: " + bgcolor + "; \n\t\tcolor: " + datebox_color + ";\n\t\tpadding: 5px; \n\t\tborder-radius: 10px; \n\t\tborder: solid 1px gray;\n\t}\n\n\n"); } else{ output.append("\t.datebox{\n\t\tbackground-color: " + bgcolor + "; \n\t\tcolor: " + datebox_color + ";\n\t\tpadding: 5px; \n\t\tborder: solid 1px gray;\n\t}\n\n\n"); } output.append("\thr{\n\t\tbackground-color:silver;\n\t\tcolor: silver;\n\t\theight: 1px;\n\t\twidth:100%;\n\t\tborder: 0px;\n\t}\n\n\n"); output.append("</style>\n"); output.append("</head>\n"); output.append("<body>\n"); output.append("<h1>Sample Entry</h1>\n"); output.append("<div class=\"datebox\"> On [date] at [time], [user] wrote:</div>\n"); output.append(lipsum); output.append("<hr>\n"); output.append("<p><i><small>This file was generated by RoboJournal " + Buffer::version +" on [export date & timestamp].</small></i></p>"); output.append("</body>\n"); output.append("</html>"); return output; }
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 * ))); }
void DateTimeEditor::paintEvent(QPaintEvent* /*event*/) { QPainter painter(this); QStyleOptionFrame panel; initStyleOption(&panel); style()->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, &painter, this); QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); const int margin = 2; r.setX(r.x() + margin); r.setY(r.y() + margin); r.setRight(r.right() - margin); r.setBottom(r.bottom() - margin); painter.setClipRect(r); QPalette pal = style()->standardPalette(); if (m_selectedPosition >= 0) { const GroupInfo& g = m_groups[m_selectedGroup]; for (auto p: g.positions) { const QRect r = getCharacterRect(p); painter.fillRect(r, pal.alternateBase()); } const QRect r = getCharacterRect(m_selectedPosition); if (g.invalid) { painter.fillRect(r, Qt::red); } else { painter.fillRect(r, pal.highlight()); } } painter.setRenderHint(QPainter::Antialiasing); for (const CharacterInfo& c : m_characters) { const QRect r = getCharacterRect(c.m_position); if (c.m_position == m_selectedPosition) { painter.setPen(pal.highlightedText().color()); } else { const GroupInfo& g = m_groups[c.m_group]; if (g.invalid) { painter.setPen(Qt::red); } else { painter.setPen(pal.text().color()); } } painter.drawText(r, Qt::AlignCenter, c.m_character); } }
void QgisAppStyleSheet::buildStyleSheet( const QMap<QString, QVariant>& opts ) { QString ss = QString( "" ); // QgisApp-wide font QString fontSize = opts.value( "fontPointSize" ).toString(); QgsDebugMsg( QString( "fontPointSize: %1" ).arg( fontSize ) ); if ( fontSize.isEmpty() ) { return; } QString fontFamily = opts.value( "fontFamily" ).toString(); QgsDebugMsg( QString( "fontFamily: %1" ).arg( fontFamily ) ); if ( fontFamily.isEmpty() ) { return; } ss += QString( "* { font: %1pt \"%2\"} " ).arg( fontSize ).arg( fontFamily ); // QGroupBox and QgsCollapsibleGroupBox, mostly for Ubuntu and Mac bool gbxCustom = opts.value( "groupBoxCustom" ).toBool(); QgsDebugMsg( QString( "groupBoxCustom: %1" ).arg( gbxCustom ) ); bool gbxBoldTitle = opts.value( "groupBoxBoldTitle" ).toBool(); QgsDebugMsg( QString( "groupBoxBoldTitle: %1" ).arg( gbxBoldTitle ) ); bool sidebar = opts.value( "sidebarStyle" ).toBool(); if ( gbxCustom || gbxBoldTitle ) { ss += "QGroupBox{"; if ( gbxBoldTitle ) { // doesn't work for QGroupBox::title ss += QString( "color: rgb(%1,%1,%1);" ).arg( mMacStyle ? 25 : 60 ); ss += "font-weight: bold;"; } if ( gbxCustom ) { ss += QString( "background-color: rgba(0,0,0,%1%);" ) .arg( mWinOS && mStyle.startsWith( "windows" ) ? 0 : 3 ); ss += "border: 1px solid rgba(0,0,0,20%);"; ss += "border-radius: 5px;"; ss += "margin-top: 2.5ex;"; ss += QString( "margin-bottom: %1ex;" ).arg( mMacStyle ? 1.5 : 1 ); } ss += "} "; if ( gbxCustom ) { ss += "QGroupBox:flat{"; ss += "background-color: rgba(0,0,0,0);"; ss += "border: rgba(0,0,0,0);"; ss += "} "; ss += "QGroupBox::title{"; ss += "subcontrol-origin: margin;"; ss += "subcontrol-position: top left;"; ss += "margin-left: 6px;"; if ( !( mWinOS && mStyle.startsWith( "windows" ) ) && !mOxyStyle ) { ss += "background-color: rgba(0,0,0,0);"; } ss += "} "; } } if ( sidebar ) { QString style = "QListWidget#mOptionsListWidget {" " background-color: rgb(69, 69, 69, 220);" " outline: 0;" "}" "QListWidget#mOptionsListWidget::item {" " color: white;" " padding: 3px;" "}" "QListWidget#mOptionsListWidget::item::selected {" " color: black;" " background-color:palette(Window);" " padding-right: 0px;" "}"; ss += style; } //fix background issue for gnome desktop if ( mLinuxOS && mGtkStyle && !sidebar ) { ss += "QListWidget#mOptionsListWidget{"; ss += "background-color: white;"; ss += "} "; } // Fix selection color on loosing focus (Windows) const QPalette palette = qApp->palette(); ss += QString( "QTableView {" "selection-background-color: %1;" "selection-color: %2;" "}" ) .arg( palette.highlight().color().name() ) .arg( palette.highlightedText().color().name() ); QgsDebugMsg( QString( "Stylesheet built: %1" ).arg( ss ) ); emit appStyleSheetChanged( ss ); }
void MiamStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { switch (element) { #if !defined(Q_OS_OSX) case CE_Splitter: break; #endif case CE_MenuBarItem:{ const QStyleOptionMenuItem *somi = static_cast<const QStyleOptionMenuItem*>(option); const bool act = somi->state & (State_Sunken | State_Selected); QPalette palette = QApplication::palette(); QBrush brush; if (act) { painter->setPen(palette.highlight().color()); brush = palette.highlight().color().lighter(); painter->setBrush(brush); painter->drawRect(option->rect.adjusted(0, 0, -1, -1)); } else { brush = palette.window(); painter->fillRect(option->rect, palette.window()); } uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; if (!styleHint(SH_UnderlineShortcut, somi, widget)) { alignment |= Qt::TextHideMnemonic; } if (somi->state.testFlag(QStyle::State_Enabled)) { if (SettingsPrivate::instance()->isCustomTextColorOverriden()) { if (act) { painter->setPen(palette.highlightedText().color()); } else { painter->setPen(palette.text().color()); } } else { if (qAbs(palette.text().color().value() - brush.color().value()) < 128) { painter->setPen(palette.highlightedText().color()); } else { painter->setPen(palette.text().color()); } } } /*else if (act) { painter->setPen(palette.mid().color()); }*/ painter->drawText(option->rect, alignment, somi->text); break; } case CE_MenuItem: if (const QStyleOptionMenuItem *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) { QGuiApplication *app = static_cast<QGuiApplication*>(QGuiApplication::instance()); qreal checkcol = 25 / app->devicePixelRatio(); qreal gutterWidth = 3 / app->devicePixelRatio(); QRect rect = option->rect; //draw vertical menu line if (option->direction == Qt::LeftToRight) checkcol += rect.x(); int x, y, w, h; menuitem->rect.getRect(&x, &y, &w, &h); int tab = menuitem->tabWidth; bool dis = !(menuitem->state & State_Enabled); bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable ? menuitem->checked : false; bool act = menuitem->state & State_Selected; QPalette palette = QApplication::palette(); if (menuitem->menuItemType == QStyleOptionMenuItem::Separator) { int yoff = y - 1 + h / 2; qreal separatorSize = 6 / app->devicePixelRatio(); QPoint p1 = QPoint(x + checkcol, yoff); QPoint p2 = QPoint(x + w + separatorSize, yoff); painter->save(); painter->fillRect(menuitem->rect, palette.window()); painter->setPen(palette.mid().color()); painter->drawLine(p1, p2); painter->restore(); return; } QString s = menuitem->text; QBrush fill; if (act) { fill = palette.highlight().color().lighter(); } else { fill = palette.window(); } painter->fillRect(menuitem->rect, fill); QRect vCheckRect = visualRect(option->direction, menuitem->rect, QRect(menuitem->rect.x(), menuitem->rect.y(), checkcol - (gutterWidth + menuitem->rect.x()), menuitem->rect.height())); if (checked) { QStyleOptionMenuItem newMi = *menuitem; int windowsItemFrame = 2; newMi.rect = visualRect(option->direction, menuitem->rect, QRect(menuitem->rect.x() + windowsItemFrame, menuitem->rect.y() + windowsItemFrame, checkcol - 2 * windowsItemFrame, menuitem->rect.height() - 2 * windowsItemFrame) ); painter->setRenderHint(QPainter::Antialiasing, true); proxy()->drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, painter, widget); painter->setRenderHint(QPainter::Antialiasing, false); } if (!menuitem->icon.isNull()) { QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal; if (act && !dis) { mode = QIcon::Active; } QPixmap pixmap; if (checked) { pixmap = menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, option, widget), mode, QIcon::On); } else { pixmap = menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, option, widget), mode); } const int pixw = pixmap.width() / pixmap.devicePixelRatio(); const int pixh = pixmap.height() / pixmap.devicePixelRatio(); QRect pmr(0, 0, pixw, pixh); pmr.moveCenter(vCheckRect.center()); painter->setPen(palette.text().color()); painter->drawPixmap(pmr.topLeft(), pixmap); } //painter->setPen(palette.buttonText().color()); QColor textColor = palette.text().color(); if (dis) { textColor = palette.mid().color(); painter->setPen(textColor); } else if (act && SettingsPrivate::instance()->isCustomTextColorOverriden()) { textColor = palette.highlightedText().color(); painter->setPen(textColor); } int xm = checkcol + 2 + (gutterWidth - menuitem->rect.x()) - 1; int xpos = menuitem->rect.x() + xm; /// int windowsItemVMargin = 3, windowsRightBorder = 3; QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin); QRect vTextRect = visualRect(option->direction, menuitem->rect, textRect); if (!s.isEmpty()) { // draw text painter->save(); int t = s.indexOf(QLatin1Char('\t')); int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; if (!proxy()->styleHint(SH_UnderlineShortcut, menuitem, widget)) { text_flags |= Qt::TextHideMnemonic; } text_flags |= Qt::AlignLeft; if (t >= 0) { QRect vShortcutRect = visualRect(option->direction, menuitem->rect, QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom()))); painter->drawText(vShortcutRect, text_flags, s.mid(t + 1)); s = s.left(t); } QFont font = menuitem->font; if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem) { font.setBold(true); } painter->setFont(font); painter->setPen(textColor); painter->drawText(vTextRect, text_flags, s.left(t)); painter->restore(); } if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow int dim = (h - 2 * 5) / 2; PrimitiveElement arrow; arrow = (option->direction == Qt::RightToLeft) ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight; xpos = x + w - 2 - 2 - dim; QRect vSubMenuRect = visualRect(option->direction, menuitem->rect, QRect(xpos, y + h / 2 - dim / 2, dim, dim)); QStyleOptionMenuItem newMI = *menuitem; newMI.rect = vSubMenuRect; newMI.state = dis ? State_None : State_Enabled; proxy()->drawPrimitive(arrow, &newMI, painter, widget); } } break; case CE_MenuBarEmptyArea:{ painter->fillRect(option->rect, QApplication::palette().window()); break; } default: QProxyStyle::drawControl(element, option, painter, widget); } }
/** Redefined. */ void AddressBarButton::paintEvent(QPaintEvent *) { QStylePainter p(this); QRect r = rect().adjusted(0, 1, -1, -(1 + extra)); static const int arrowWidth = r.height(); QPalette palette = QApplication::palette(); QLinearGradient g(rect().topLeft(), rect().bottomLeft()); g.setColorAt(0, palette.base().color()); g.setColorAt(1, palette.window().color()); p.fillRect(r, g); // Compute size of rectangles to display text and right arrow if (_atLeastOneSubDir) { if (isLeftToRight()) { _arrowRect = QRect(r.width() - arrowWidth, r.y(), arrowWidth, r.height()); _textRect = QRect(r.x(), r.y(), r.width() - arrowWidth, r.height()); } else { _arrowRect = QRect(r.x(), r.y(), arrowWidth, r.height()); _textRect = QRect(r.x() + arrowWidth, r.y(), r.width() - arrowWidth, r.height()); } } else { _textRect = r.adjusted(0, 0, -5, 0); } // Highlight button if mouse is over QPoint pos = mapFromGlobal(QCursor::pos()); p.save(); QBrush brush; if (_addressBar->isDown()) { brush = palette.highlight().color().lighter(); } else { brush = palette.highlight().color().lighter(lighterValue); } if (_highlighted) { p.setPen(palette.highlight().color()); p.setBrush(brush); p.drawRect(_textRect); if (_atLeastOneSubDir) { p.drawRect(_arrowRect); } } else { if (_atLeastOneSubDir) { if (_textRect.contains(pos) || _arrowRect.contains(pos)) { p.setPen(palette.highlight().color()); p.setBrush(brush); p.drawRect(_textRect); p.drawRect(_arrowRect); } else { p.setPen(Qt::NoPen); p.setBrush(Qt::NoBrush); p.drawRect(_textRect); p.drawRect(_arrowRect); } } else { if (_textRect.contains(pos)) { p.setPen(palette.highlight().color()); p.setBrush(brush); p.drawRect(_textRect); } } } p.restore(); // Draw folder's name QColor lighterBG = palette.highlight().color().lighter(); QColor highlightedText = palette.highlightedText().color(); if (rect().contains(pos) && SettingsPrivate::instance()->isCustomTextColorOverriden()) { p.setPen(palette.highlightedText().color()); } else if (qAbs(lighterBG.value() - highlightedText.value()) > 128 && _highlighted) { p.setPen(highlightedText); } else { p.setPen(palette.text().color()); } // Special case for root and drives bool root = false; if (_path.isRoot()) { QPixmap pixmap = QFileIconProvider().icon(QFileIconProvider::Computer).pixmap(20, 20); QString drive; if (_isAbsoluteRoot) { pixmap = QFileIconProvider().icon(QFileIconProvider::Computer).pixmap(20, 20); if (isLeftToRight()) { p.drawPixmap(2, 3, 20, 20, pixmap); } else { p.drawPixmap(18, 3, 20, 20, pixmap); } } else { drive = AddressBar::getVolumeInfo(_path.absolutePath()); if (!_isAbsoluteRoot && !drive.isEmpty()) { // Add a small offset to simulate a pressed button if (_highlighted) { p.translate(1, 1); } p.drawText(_textRect.adjusted(5, 0, 0, 0), Qt::AlignCenter, drive); } pixmap = QFileIconProvider().icon(QFileIconProvider::Drive).pixmap(20, 20); } } else { if (!_path.dirName().isEmpty()) { // Add a small offset to simulate a pressed button if (_highlighted) { p.translate(1, 1); } p.drawText(_textRect.adjusted(0, 0, 0, 0), Qt::AlignCenter, _path.dirName()); } } if (_atLeastOneSubDir) { QStyleOptionButton o; o.initFrom(this); p.save(); p.setPen(Qt::NoPen); p.setBrush(o.palette.mid()); if (root && _addressBar->hasHiddenFolders()) { /// Right To Left QPoint p1(o.rect.x() + 32, o.rect.y() + 11), p2(o.rect.x() + 29, o.rect.y() + 14), p2b(o.rect.x() + 29, o.rect.y() + 13), p3(o.rect.x() + 32, o.rect.y() + 16); p.save(); p.setPen(Qt::black); p.setRenderHint(QPainter::Antialiasing); p.drawLine(p1, p2); p.drawLine(p2b, p3); p.translate(4, 0); p.drawLine(p1, p2); p.drawLine(p2b, p3); p.restore(); } else { int w = _arrowRect.width() / 3; int h = this->rect().height() / 3; QRect indicatorArrow(_arrowRect.x() + w + 1, _arrowRect.y() + h, w, h); o.rect = indicatorArrow; p.setRenderHint(QPainter::Antialiasing); p.save(); QPen pen(palette.mid().color()); pen.setWidthF(1.5); pen.setJoinStyle(Qt::MiterJoin); p.setPen(pen); QPolygon pol; QPoint p1, p2, p3; if (_highlighted) { p.translate(0, -1); p1 = QPoint(o.rect.x(), o.rect.y() + o.rect.height() / 2); p2 = QPoint(o.rect.x() + o.rect.width(), o.rect.y() + o.rect.height() / 2); p3 = QPoint(o.rect.x() + o.rect.width() / 2, o.rect.y() + o.rect.height()); } else if (isLeftToRight()) { p1 = QPoint(o.rect.x(), o.rect.y()); p2 = QPoint(o.rect.x(), o.rect.y() + o.rect.height()); p3 = QPoint(o.rect.x() + o.rect.width(), o.rect.y() + o.rect.height() / 2); } else { p1 = QPoint(o.rect.x() + o.rect.width(), o.rect.y()); p2 = QPoint(o.rect.x() + o.rect.width(), o.rect.y() + o.rect.height()); p3 = QPoint(o.rect.x(), o.rect.y() + o.rect.height() / 2); } pol.append(p1); pol.append(p2); pol.append(p3); p.drawPolygon(pol); p.restore(); p.setRenderHint(QPainter::Antialiasing, false); } p.restore(); } }