LineEdit::LineEdit(QWidget *parent) : SearchBar(parent), _timer(new QTimer(this)), _fps(0) { this->setAttribute(Qt::WA_MacShowFocusRect, false); _timer->setInterval(40); connect(_timer, &QTimer::timeout, [=]() { _fps++; if (_fps == 25) { _fps = 0; } this->repaint(); }); _fade.setEasingCurve(QEasingCurve::Linear); QPalette p = QApplication::palette(); _fade.setStartValue(p.text().color()); _fade.setKeyValueAt(0.5, p.base().color()); _fade.setEndValue(p.text().color()); _fade.setDuration(1000); connect(qApp, &QApplication::paletteChanged, this, [=](const QPalette &p) { _fade.setStartValue(p.text().color()); _fade.setKeyValueAt(0.5, p.base().color()); _fade.setEndValue(p.text().color()); }); }
void CurrentTrack::paletteChanged( const QPalette &palette ) { m_title->setBrush( palette.text() ); m_artist->setBrush( palette.text() ); m_album->setBrush( palette.text() ); m_byText->setBrush( palette.text() ); m_onText->setBrush( palette.text() ); }
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 Document::paintEvent(QPaintEvent *event) { QRegion paintRegion = event->region(); QPainter painter(this); QPalette pal = palette(); for (int i = 0; i < m_shapeList.count(); ++i) { const Shape &shape = m_shapeList.at(i); if (!paintRegion.contains(shape.rect())) continue; QPen pen = pal.text().color(); pen.setWidth(i == m_currentIndex ? 2 : 1); painter.setPen(pen); painter.setBrush(gradient(shape.color(), shape.rect())); QRect rect = shape.rect(); rect.adjust(1, 1, -resizeHandleWidth/2, -resizeHandleWidth/2); // paint the shape switch (shape.type()) { case Shape::Rectangle: painter.drawRect(rect); break; case Shape::Circle: painter.setRenderHint(QPainter::Antialiasing); painter.drawEllipse(rect); painter.setRenderHint(QPainter::Antialiasing, false); break; case Shape::Triangle: painter.setRenderHint(QPainter::Antialiasing); painter.drawPolygon(triangle(rect)); painter.setRenderHint(QPainter::Antialiasing, false); break; } // paint the resize handle painter.setPen(pal.text().color()); painter.setBrush(Qt::white); painter.drawRect(shape.resizeHandle().adjusted(0, 0, -1, -1)); // paint the shape name painter.setBrush(pal.text()); if (shape.type() == Shape::Triangle) rect.adjust(0, rect.height()/2, 0, 0); painter.drawText(rect, Qt::AlignCenter, shape.name()); } }
void SavestateButton::paintEvent(QPaintEvent*) { QPainter painter(this); QRect frame(0, 0, width(), height()); QRect full(1, 1, width() - 2, height() - 2); QPalette palette = QApplication::palette(this); painter.setPen(Qt::black); QLinearGradient grad(0, 0, 0, 1); grad.setCoordinateMode(QGradient::ObjectBoundingMode); QColor shadow = palette.color(QPalette::Shadow); QColor dark = palette.color(QPalette::Dark); shadow.setAlpha(128); dark.setAlpha(128); grad.setColorAt(0, shadow); grad.setColorAt(1, dark); painter.setBrush(grad); painter.drawRect(frame); painter.setPen(Qt::NoPen); if (!icon().isNull()) { painter.drawPixmap(full, icon().pixmap(full.size())); } if (hasFocus()) { QColor highlight = palette.color(QPalette::Highlight); highlight.setAlpha(128); painter.fillRect(full, highlight); } painter.setPen(QPen(palette.text(), 0)); painter.drawText(full, Qt::AlignCenter, text()); }
void ItemText::highlight(const QRegExp &re, const QFont &highlightFont, const QPalette &highlightPalette) { QList<QTextBrowser::ExtraSelection> selections; if ( !re.isEmpty() ) { QTextBrowser::ExtraSelection selection; selection.format.setBackground( highlightPalette.base() ); selection.format.setForeground( highlightPalette.text() ); selection.format.setFont(highlightFont); QTextCursor cur = m_textDocument.find(re); int a = cur.position(); while ( !cur.isNull() ) { if ( cur.hasSelection() ) { selection.cursor = cur; selections.append(selection); } else { cur.movePosition(QTextCursor::NextCharacter); } cur = m_textDocument.find(re, cur); int b = cur.position(); if (a == b) { cur.movePosition(QTextCursor::NextCharacter); cur = m_textDocument.find(re, cur); b = cur.position(); if (a == b) break; } a = b; } } setExtraSelections(selections); update(); }
/** Redefined to display user input like closable "bubbles". */ void TagLineEdit::paintEvent(QPaintEvent *) { QStylePainter p(this); // Draw frame QStyleOptionFrameV3 frame; this->initStyleOption(&frame); QPalette palette = QApplication::palette(); p.setPen(palette.mid().color()); p.setBrush(palette.base()); p.drawRect(this->rect().adjusted(0, 0, -1, -1)); // Compute cursor position QRect contentsRect = this->style()->subElementRect(QStyle::SE_LineEditContents, &frame); QRect rText = contentsRect.adjusted(2, 0, 0, 0); if (!_tags.isEmpty() || (placeholderText().isEmpty() || (!placeholderText().isEmpty() && hasFocus()))) { p.setPen(palette.text().color()); p.drawText(rText, Qt::AlignLeft | Qt::AlignVCenter, text()); // Animate cursor is focus is owned by this widget bool overlap = false; for (TagButton *t : _tags) { if (t->frameGeometry().contains(cursorRect().center())) { overlap = true; break; } } if (!overlap && hasFocus()) { this->drawCursor(&p, rText.adjusted(0, 1, 0, -1)); } } else { p.setPen(palette.mid().color()); p.drawText(rText, Qt::AlignLeft | Qt::AlignVCenter, placeholderText()); } }
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 MyTabBar::slotToggleActive(int state) { QString buttonName = this->sender()->objectName(); int index = buttonName.right(1).toInt() - 1; QPalette palette = QApplication::palette(); setTabTextColor(index, state == Qt::Checked ? palette.text().color() : palette.dark().color()); // setTabEnabled(index, state == Qt::Checked); emit toggledEnable(index + 1, state == Qt::Checked); }
// A ctor. QsciStyle::QsciStyle(int style) { init(style); QPalette pal = QApplication::palette(); setColor(pal.text().color()); setPaper(pal.base().color()); setFont(QApplication::font()); setEolFill(false); }
void ConsoleWindow::addNewConsoleItem(QStandardItem *item) { QSettings settings; settings.beginGroup("Console"); QPalette palette = settings.value(QString("log-level-%1-palette").arg(item->data(Qt::UserRole).toInt())).value<QPalette>(); QFont font = settings.value(QString("log-level-%1-font").arg(item->data(Qt::UserRole).toInt())).value<QFont>(); item->setBackground(palette.base()); item->setForeground(palette.text()); item->setFont(font); sourceModel->appendRow(item); }
void setApplicable(int column, bool applicable = false) { QPalette palette = wsApp->palette(); if (applicable) { setText(column, QString()); } else { palette.setCurrentColorGroup(QPalette::Disabled); setText(column, UTF8_EM_DASH); } setTextColor(column, palette.text().color()); }
ChannelView::ChannelView(QWidget *parent) : QListView(parent), showUpdated(false), sortBy(SortByName) { setItemDelegate(new ChannelItemDelegate(this)); setSelectionMode(QAbstractItemView::NoSelection); // layout setSpacing(15); setFlow(QListView::LeftToRight); setWrapping(true); setResizeMode(QListView::Adjust); setMovement(QListView::Static); setUniformItemSizes(true); // cosmetics setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); setFrameShape(QFrame::NoFrame); setAttribute(Qt::WA_MacShowFocusRect, false); QPalette p = palette(); /* p.setColor(QPalette::Base, p.window().color()); p.setColor(QPalette::Text, p.windowText().color()); */ p.setColor(QPalette::Disabled, QPalette::Base, p.base().color()); p.setColor(QPalette::Disabled, QPalette::Text, p.text().color()); setPalette(p); verticalScrollBar()->setPageStep(3); verticalScrollBar()->setSingleStep(1); setMouseTracking(true); connect(this, SIGNAL(clicked(const QModelIndex &)), SLOT(itemActivated(const QModelIndex &))); connect(this, SIGNAL(entered(const QModelIndex &)), SLOT(itemEntered(const QModelIndex &))); channelsModel = new ChannelModel(this); setModel(channelsModel); connect(this, SIGNAL(viewportEntered()), channelsModel, SLOT(clearHover())); setupActions(); connect(ChannelAggregator::instance(), SIGNAL(channelChanged(YTChannel*)), channelsModel, SLOT(updateChannel(YTChannel*))); connect(ChannelAggregator::instance(), SIGNAL(unwatchedCountChanged(int)), SLOT(unwatchedCountChanged(int))); unwatchedCountChanged(ChannelAggregator::instance()->getUnwatchedCount()); }
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(); }
void ItemWidget::setHighlight(const QRegExp &re, const QFont &highlightFont, const QPalette &highlightPalette) { QPalette palette( widget()->palette() ); palette.setColor(QPalette::Highlight, highlightPalette.base().color()); palette.setColor(QPalette::HighlightedText, highlightPalette.text().color()); widget()->setPalette(palette); if (m_re == re) return; m_re = re; highlight(re, highlightFont, highlightPalette); }
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); } }
/*! \~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 SimplePartWidget::slotMarkupPlainText() { // NOTICE "single shot", we get a recursion otherwise! disconnect(this, &QWebView::loadFinished, this, &SimplePartWidget::slotMarkupPlainText); // If there's no data, don't try to "fix it up" if (!m_partIndex.isValid() || !m_partIndex.data(Imap::Mailbox::RoleIsFetched).toBool()) return; QPalette palette = QApplication::palette(); // and finally set the marked up page. page()->mainFrame()->setHtml(UiUtils::htmlizedTextPart(m_partIndex, QFontDatabase::systemFont(QFontDatabase::FixedFont), palette.base().color(), palette.text().color(), palette.link().color(), palette.linkVisited().color())); }
void lmcUserTreeWidgetDelegate::drawCheckBox(QPainter *painter, const QPalette& palette, const QRect &checkBoxRect, Qt::CheckState checkState) const { painter->setPen(QPen(palette.color(QPalette::Shadow))); painter->setBrush(palette.base()); painter->drawRect(checkBoxRect); if(checkState == Qt::Checked) { painter->setPen(QPen(palette.text(), 1)); painter->drawLine(checkBoxRect.left() + 2, checkBoxRect.top() + 6, checkBoxRect.left() + 4, checkBoxRect.top() + 8); painter->drawLine(checkBoxRect.left() + 2, checkBoxRect.top() + 7, checkBoxRect.left() + 4, checkBoxRect.top() + 9); painter->drawLine(checkBoxRect.left() + 2, checkBoxRect.top() + 8, checkBoxRect.left() + 4, checkBoxRect.top() + 10); painter->drawLine(checkBoxRect.left() + 4, checkBoxRect.top() + 8, checkBoxRect.left() + 10, checkBoxRect.top() + 2); painter->drawLine(checkBoxRect.left() + 4, checkBoxRect.top() + 9, checkBoxRect.left() + 10, checkBoxRect.top() + 3); painter->drawLine(checkBoxRect.left() + 4, checkBoxRect.top() + 10, checkBoxRect.left() + 10, checkBoxRect.top() + 4); } }
void PreferenceDialog::saveAppearance(QSettings &settings) { QFont font = ui->sampleEdit->font(); QPalette palette = ui->sampleEdit->palette(); settings.setValue(IniKey_BoxColorBg, palette.base().color()); settings.setValue(IniKey_BoxColorFg, palette.text().color()); settings.setValue(IniKey_BoxFont, font); settings.setValue(IniKey_ViewColorBgMark, m_colorMap["clrBgMark"]); settings.setValue(IniKey_ViewColorBgNormal, m_colorMap["clrBgNormal"]); settings.setValue(IniKey_ViewColorFgHidden, m_colorMap["clrFgHidden"]); settings.setValue(IniKey_ViewColorFgMark, m_colorMap["clrFgMark"]); settings.setValue(IniKey_ViewColorFgNormal, m_colorMap["clrFgNormal"]); settings.setValue(IniKey_ViewColorFgReadonly, m_colorMap["clrFgReadonly"]); settings.setValue(IniKey_ViewColorFgSystem, m_colorMap["clrFgSystem"]); settings.setValue(IniKey_ViewFont, m_model.font()); }
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() ); } }
void StartMainPage::applyPalette(const QPalette& newPalette) { QColor fgColor = newPalette.text().color(); QPalette pal = palette(); pal.setBrush(backgroundRole(), newPalette.base()); pal.setBrush(QPalette::Button, newPalette.base()); pal.setBrush(QPalette::WindowText, fgColor); pal.setBrush(QPalette::ButtonText, fgColor); pal.setBrush(QPalette::Text, fgColor); setPalette(pal); initViewPalette(d->mBookmarksView, fgColor); initViewPalette(d->mTagView, fgColor); initViewPalette(d->mRecentFoldersView, fgColor); initViewPalette(d->mRecentUrlsView, fgColor); }
static inline QTextFormat standardFormat(StandardFormat format) { QTextCharFormat result; switch (format) { case PreeditFormat: result.setUnderlineStyle(QTextCharFormat::DashUnderline); break; case SelectionFormat: { // TODO: Should be that of the widget? const QPalette palette = QGuiApplication::palette(); const QColor background = palette.text().color(); result.setBackground(QBrush(background)); result.setForeground(palette.background()); break; } } return result; }
void KWidgetListbox::setItemColors(int index, bool even) { QWidget* itm = item(index); // KDE4 add QPalette p = palette(); if ( !itm){ kDebug()<<"no widget at index "<<index; return; } /* if(index == selected()) { itm->setPaletteBackgroundColor(KGlobalSettings::highlightColor()); itm->setPaletteForegroundColor(KGlobalSettings::highlightedTextColor()); }*/ if(even) p.setColor(backgroundRole(), p.base().color() ); else p.setColor(backgroundRole(), p.alternateBase().color() ); p.setColor(foregroundRole(), p.text().color() ); itm->setPalette(p); }
void ItemText::highlight(const QRegExp &re, const QFont &highlightFont, const QPalette &highlightPalette) { m_searchTextDocument.clear(); if ( re.isEmpty() ) { setDocument(&m_textDocument); } else { bool plain = m_textFormat == Qt::PlainText; const QString &text = plain ? m_textDocument.toPlainText() : m_textDocument.toHtml(); if (plain) m_searchTextDocument.setPlainText(text); else m_searchTextDocument.setHtml(text); QTextCursor cur = m_searchTextDocument.find(re); int a = cur.position(); while ( !cur.isNull() ) { QTextCharFormat fmt = cur.charFormat(); if ( cur.hasSelection() ) { fmt.setBackground( highlightPalette.base() ); fmt.setForeground( highlightPalette.text() ); fmt.setFont(highlightFont); cur.setCharFormat(fmt); } else { cur.movePosition(QTextCursor::NextCharacter); } cur = m_searchTextDocument.find(re, cur); int b = cur.position(); if (a == b) { cur.movePosition(QTextCursor::NextCharacter); cur = m_searchTextDocument.find(re, cur); b = cur.position(); if (a == b) break; } a = b; } setDocument(&m_searchTextDocument); } update(); }
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 PreferenceDialog::selectViewerColor() { QColor color; QPalette palette = ui->viewerSample->palette(); if (sender() == ui->viewerClrBg) { color = palette.background().color(); } else if (sender() == ui->viewerClrFg) { color = palette.text().color(); } color = QColorDialog::getColor(color, this, tr("色選択")); if (!color.isValid()) { return; } if (sender() == ui->viewerClrBg) { palette.setColor(QPalette::Base, color); } else if (sender() == ui->viewerClrFg) { palette.setColor(QPalette::Text, color); } ui->viewerSample->setPalette(palette); }
/** 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 KviTopicWidget::paintColoredText(QPainter *p, QString text,const QPalette& cg,const QRect & rect) { QFontMetrics fm(p->fontMetrics()); bool curBold = false; bool curUnderline = false; unsigned char curFore = KVI_LABEL_DEF_FORE; //default fore unsigned char curBack = KVI_LABEL_DEF_BACK; //default back int baseline = rect.top() + rect.height() - fm.descent() -1; int curX = rect.x() + 1; // is the margin int maxX = rect.width() - 2; // 2 is 1*margin unsigned int idx = 0; while((idx < (unsigned int)text.length()) && (curX < maxX)) { unsigned short c = text[(int)idx].unicode(); unsigned int start = idx; while((idx < (unsigned int)text.length()) && (c != KviControlCodes::Color) && (c != KviControlCodes::Bold) && (c != KviControlCodes::Underline) && (c != KviControlCodes::Reverse) && (c != KviControlCodes::Reset) && (c != KviControlCodes::Icon) ) { idx++; c = text[(int)idx].unicode(); } int len = idx - start; int wdth; if(len > 0) { QString szText = text.mid(start,len); wdth = fm.width(szText); if(curFore == KVI_LABEL_DEF_FORE) { p->setPen(cg.text().color()); } else { if(curFore > 16)p->setPen(cg.background().color()); else p->setPen(KVI_OPTION_MIRCCOLOR(curFore)); } if(curBack != KVI_LABEL_DEF_BACK) { if(curBack > 16) { p->fillRect(curX,rect.y() + 2,wdth,rect.height() - 4, cg.text()); } else { p->fillRect(curX,rect.y() + 2,wdth,rect.height() - 4, KVI_OPTION_MIRCCOLOR(curBack)); } } p->drawText(curX,baseline,szText.left(len)); if(curBold)p->drawText(curX+1,baseline,szText.left(len)); if(curUnderline) { p->drawLine(curX,baseline + 1,curX+wdth,baseline + 1); } } else { wdth = 0; } curX += wdth; switch(c) { case KviControlCodes::Bold: curBold = !curBold; ++idx; break; case KviControlCodes::Underline: curUnderline = !curUnderline; ++idx; break; case KviControlCodes::Reverse: { char auxBack = curBack; curBack = curFore; curFore = auxBack; } ++idx; break; case KviControlCodes::Reset: curFore = KVI_LABEL_DEF_FORE; curBack = KVI_LABEL_DEF_BACK; curBold = false; curUnderline = false; ++idx; break; case KviControlCodes::Color: { ++idx; unsigned char fore; unsigned char back; idx = KviControlCodes::getUnicodeColorBytes(text,idx,&fore,&back); if(fore != KviControlCodes::NoChange) { curFore = fore; if(back != KviControlCodes::NoChange) curBack = back; } else { // only a CTRL+K curBack = KVI_LABEL_DEF_BACK; curFore = KVI_LABEL_DEF_FORE; } } break; case KviControlCodes::Icon: { ++idx; unsigned int icoStart = idx; while((idx < (unsigned int)text.length()) && (text[(int)idx].unicode() > 32))idx++; KviCString lookupString = text.mid(icoStart,idx - icoStart); KviTextIcon * icon = g_pTextIconManager->lookupTextIcon(lookupString.ptr()); if(icon) { QPixmap * pigzmap = icon->pixmap(); p->drawPixmap(curX,(baseline + 2) - pigzmap->height(),*(pigzmap)); curX += pigzmap->width(); } else { idx = icoStart; } } break; } } }
void qDrawItem(QPainter *p, Qt::GUIStyle gs, int x, int y, int w, int h, int flags, const QPalette &pal, bool enabled, const QPixmap *pixmap, const QString& text, int len , const QColor* penColor) { p->setPen(penColor?*penColor:pal.foreground().color()); if (pixmap) { QPixmap pm(*pixmap); bool clip = (flags & Qt::TextDontClip) == 0; if (clip) { if (pm.width() < w && pm.height() < h) clip = false; else p->setClipRect(x, y, w, h); } if ((flags & Qt::AlignVCenter) == Qt::AlignVCenter) y += h/2 - pm.height()/2; else if ((flags & Qt::AlignBottom) == Qt::AlignBottom) y += h - pm.height(); if ((flags & Qt::AlignRight) == Qt::AlignRight) x += w - pm.width(); else if ((flags & Qt::AlignHCenter) == Qt::AlignHCenter) x += w/2 - pm.width()/2; else if (((flags & Qt::AlignLeft) != Qt::AlignLeft) && QApplication::isRightToLeft()) // Qt::AlignAuto && rightToLeft x += w - pm.width(); if (!enabled) { if (pm.hasAlphaChannel()) { // pixmap with a mask pm = pm.mask(); } else if (pm.depth() == 1) { // monochrome pixmap, no mask ; #ifndef QT_NO_IMAGE_HEURISTIC_MASK } else { // color pixmap, no mask QString k; k.sprintf("$qt-drawitem-%llx", pm.cacheKey()); if (!QPixmapCache::find(k, pm)) { pm = pm.createHeuristicMask(); pm.setMask((QBitmap&)pm); QPixmapCache::insert(k, pm); } #endif } if (gs == Qt::WindowsStyle) { p->setPen(pal.light().color()); p->drawPixmap(x+1, y+1, pm); p->setPen(pal.text().color()); } } p->drawPixmap(x, y, pm); if (clip) p->setClipping(false); } else if (!text.isNull()) { if (gs == Qt::WindowsStyle && !enabled) { p->setPen(pal.light().color()); p->drawText(x+1, y+1, w, h, flags, text.left(len)); p->setPen(pal.text().color()); } p->drawText(x, y, w, h, flags, text.left(len)); } }