void init_font() { NormalFont = QApplication::font(); if (! hasCodec()) NormalFont.setFamily("Helvetica"); BoldFont = NormalFont; BoldFont.setBold(TRUE); ItalicFont = NormalFont; ItalicFont.setItalic(TRUE); BoldItalicFont = ItalicFont; BoldItalicFont.setBold(TRUE); UnderlineFont = NormalFont; UnderlineFont.setUnderline(TRUE); BoldUnderlineFont = BoldFont; BoldUnderlineFont.setUnderline(TRUE); StrikeOutFont = NormalFont; StrikeOutFont.setStrikeOut(TRUE); }
bool fromString(const QString & szValue, QFont & buffer) { KviCString str = szValue; KviCString family, pointSize, styleHint, weight, options; str.getToken(family, ','); str.getToken(pointSize, ','); str.getToken(styleHint, ','); str.getToken(weight, ','); if(!family.isEmpty()) buffer.setFamily(family.ptr()); int i; bool bOk; i = pointSize.toInt(&bOk); if(bOk && (i > 0)) buffer.setPointSize(i); i = styleHint.toInt(&bOk); if(bOk && (i >= 0)) buffer.setStyleHint((QFont::StyleHint)i); i = weight.toInt(&bOk); if(bOk && (i >= 0)) buffer.setWeight(i); buffer.setBold(str.contains("b")); buffer.setItalic(str.contains("i")); buffer.setUnderline(str.contains("u")); buffer.setStrikeOut(str.contains("s")); buffer.setFixedPitch(str.contains("f")); return true; }
/** * Called when context menu on the contact list has been clicked. * Calls methods to respond to clicked action. * @brief MainWindow::contactsMenuClicked */ void MainWindow::contactsMenuClicked(QAction *action) { QString sel(ui->lstContacts->selectedItems().at(0)->data(Qt::DisplayRole).toString()); if(action->text().compare(STR_ADD_TO_CONVO) == 0) //Add contact to conversation { contextAddToConvo(sel); } if(action->text().compare(STR_REMOVE) == 0) //Remove contact from list { ui->lstContacts->takeItem(ui->lstContacts->currentRow()); controller->removeExtContact(sel); } if(action->text().compare(STR_BLOCK_UNBLK) == 0) //Block contact { // Indicate a blocked contact with grey text and strikethrough. QFont f = ui->lstContacts->selectedItems().at(0)->font(); if(f.strikeOut()) { ui->lstContacts->selectedItems().at(0)->setTextColor(Qt::black); controller->unblockContact(sel); } else { ui->lstContacts->selectedItems().at(0)->setTextColor(Qt::gray); controller->blockContact(sel); } f.setStrikeOut(!f.strikeOut()); ui->lstContacts->selectedItems().at(0)->setFont(f); } }
void tst_QStaticText::drawStruckOutText() { QPixmap imageDrawText(1000, 1000); QPixmap imageDrawStaticText(1000, 1000); imageDrawText.fill(Qt::white); imageDrawStaticText.fill(Qt::white); QString s = QString::fromLatin1("Foobar"); QFont font; font.setStrikeOut(true); { QPainter p(&imageDrawText); p.setFont(font); p.drawText(QPointF(50, 50), s); } { QPainter p(&imageDrawStaticText); QStaticText text = QStaticText(s); p.setFont(font); p.drawStaticText(QPointF(50, 50 - QFontMetricsF(p.font()).ascent()), text); } #if defined(DEBUG_SAVE_IMAGE) imageDrawText.save("drawStruckOutText_imageDrawText.png"); imageDrawStaticText.save("drawStruckOutText_imageDrawStaticText.png"); #endif QCOMPARE(imageDrawText, imageDrawStaticText); }
void SgListDlg::RecalcBragg() { const QListWidgetItem* pItem = listSGs->currentItem(); if(!pItem) return; const int h = spinH->value(); const int k = spinK->value(); const int l = spinL->value(); //std::cout << h << k << l << std::endl; std::shared_ptr<const SpaceGroups<t_real>> sgs = SpaceGroups<t_real>::GetInstance(); const SpaceGroups<t_real>::t_vecSpaceGroups* pvecSG = sgs->get_space_groups_vec(); const unsigned int iSG = pItem->data(Qt::UserRole).toUInt(); if(iSG >= pvecSG->size()) return; const SpaceGroup<t_real>* psg = pvecSG->at(iSG); const bool bForbidden = !psg->HasReflection(h,k,l);; QFont font = spinH->font(); font.setStrikeOut(bForbidden); for(QSpinBox* pSpin : {spinH, spinK, spinL}) pSpin->setFont(font); }
QFont stripStyleName(QFont &f, QFontDatabase &db) { const QString &styleName = f.styleName(); if (styleName.isEmpty()) { return f; } else { QFont g = (db.styleString(f) != styleName) ? db.font(f.family(), styleName, f.pointSize()) : QFont(f.family(), f.pointSize(), f.weight()); if (auto s = f.pixelSize() > 0) { g.setPixelSize(s); } g.setStyleHint(f.styleHint(), f.styleStrategy()); g.setStyle(f.style()); if (f.underline()) { g.setUnderline(true); } if (f.strikeOut()) { g.setStrikeOut(true); } if (f.fixedPitch()) { g.setFixedPitch(true); } return g; } }
//对字体的支持 QFont obs_data_get_qfont(obs_data_t *data, const char *name){ obs_data_t *font_obj = obs_data_get_obj(data, name); const char *face = obs_data_get_string(font_obj, "face"); const char *style = obs_data_get_string(font_obj, "style"); int size = (int)obs_data_get_int(font_obj, "size"); uint32_t flags = (uint32_t)obs_data_get_int(font_obj, "flags"); QFont font; if (face) { font.setFamily(face); font.setStyleName(style); } if (size) font.setPointSize(size); if (flags & OBS_FONT_BOLD) font.setBold(true); if (flags & OBS_FONT_ITALIC) font.setItalic(true); if (flags & OBS_FONT_UNDERLINE) font.setUnderline(true); if (flags & OBS_FONT_STRIKEOUT) font.setStrikeOut(true); return font; }
QFont QFontDialog::font() const { int pSize = d->sizeEdit->text().toInt(); QFont f = d->fdb.font( d->familyList->currentText(), d->style, pSize ); f.setStrikeOut( d->strikeout->isChecked() ); f.setUnderline( d->underline->isChecked() ); return f; }
static inline QFont adapt( QFont font, bool it, bool b, bool strike ) { if ( it ) font.setItalic( true ); if ( b ) font.setBold( true ); if ( strike ) font.setStrikeOut( true ); return font; }
/*! * Returns a QFont object based on font data contained in the format. */ QFont Format::font() const { QFont font; font.setFamily(fontName()); if (fontSize() > 0) font.setPointSize(fontSize()); font.setBold(fontBold()); font.setItalic(fontItalic()); font.setUnderline(fontUnderline()!=FontUnderlineNone); font.setStrikeOut(fontStrikeOut()); return font; }
static QEFont *qt_open_font(QEditScreen *s, int style, int size) { qDebug() << Q_FUNC_INFO << style << size; QEQtContext *ctx = (QEQtContext *)s->priv_data; QEFont *font; font = qe_mallocz(QEFont); if (!font) return NULL; QFont *f; switch (style & QE_FAMILY_MASK) { case QE_FAMILY_SANS: qDebug() << Q_FUNC_INFO << "Sans font requested"; f = new QFont(); f->setStyleHint(QFont::SansSerif); break; case QE_FAMILY_SERIF: qDebug() << Q_FUNC_INFO << "Serif font requested"; f = new QFont(); f->setStyleHint(QFont::Serif); break; case QE_FAMILY_FIXED: default: qDebug() << Q_FUNC_INFO << "Monospace font requested"; f = new QFont("Consolas"); f->setStyleHint(QFont::Monospace); f->setFixedPitch(true); break; } f->setStyleStrategy(QFont::ForceIntegerMetrics); f->setPointSize(size); if (style & QE_STYLE_BOLD) f->setBold(true); if (style & QE_STYLE_ITALIC) f->setItalic(true); if (style & QE_STYLE_UNDERLINE) f->setUnderline(true); if (style & QE_STYLE_LINE_THROUGH) f->setStrikeOut(true); QFontMetrics fm(*f, &ctx->image); font->ascent = fm.ascent(); font->descent = fm.descent(); font->priv_data = f; QFontInfo fi(*f); qDebug() << Q_FUNC_INFO << "Resolved" << fi.family() << fi.pointSize() << fi.fixedPitch(); return font; }
void InputWidget::setCustomFont(const QVariant &v) { QFont font = v.value<QFont>(); if (font.family().isEmpty()) font = QApplication::font(); // we don't want font styles as this conflics with mirc code richtext editing font.setBold(false); font.setItalic(false); font.setUnderline(false); font.setStrikeOut(false); ui.inputEdit->setCustomFont(font); }
void QgsFieldConditionalFormatWidget::saveRule() { QList<QgsConditionalStyle> styles = getStyles(); QgsConditionalStyle style = QgsConditionalStyle(); style.setRule( mRuleEdit->text() ); style.setName( mNameEdit->text() ); QColor backColor = btnBackgroundColor->color(); QColor fontColor = btnTextColor->color(); QFont font = mFontFamilyCmbBx->currentFont(); font.setBold( mFontBoldBtn->isChecked() ); font.setItalic( mFontItalicBtn->isChecked() ); font.setStrikeOut( mFontStrikethroughBtn->isChecked() ); font.setUnderline( mFontUnderlineBtn->isChecked() ); style.setFont( font ); style.setBackgroundColor( backColor ); style.setTextColor( fontColor ); if ( mSymbol && checkIcon->isChecked() ) { style.setSymbol( mSymbol ); } else { style.setSymbol( 0 ); } if ( mEditing ) { styles.replace( mEditIndex, style ); } else { styles.append( style ); } QString fieldName; if ( fieldRadio->isChecked() ) { fieldName = mFieldCombo->currentField(); mLayer->conditionalStyles()->setFieldStyles( fieldName, styles ); } if ( rowRadio->isChecked() ) { mLayer->conditionalStyles()->setRowStyles( styles ); } pages->setCurrentIndex( 0 ); reloadStyles(); emit rulesUpdated( fieldName ); reset(); }
void LegendWidget::restore(Graph *g, const QStringList& lst) { QColor backgroundColor = Qt::white; double x = 0.0, y = 0.0; QStringList::const_iterator line; LegendWidget *l = new LegendWidget(g); for (line = lst.begin(); line != lst.end(); line++){ QString s = *line; if (s.contains("<Frame>")) l->setFrameStyle((s.remove("<Frame>").remove("</Frame>").toInt())); else if (s.contains("<Color>")) l->setFrameColor(QColor(s.remove("<Color>").remove("</Color>"))); else if (s.contains("<FrameWidth>")) l->setFrameWidth(s.remove("<FrameWidth>").remove("</FrameWidth>").toInt()); else if (s.contains("<LineStyle>")) l->setFrameLineStyle(PenStyleBox::penStyle(s.remove("<LineStyle>").remove("</LineStyle>").toInt())); else if (s.contains("<x>")) x = s.remove("<x>").remove("</x>").toDouble(); else if (s.contains("<y>")) y = s.remove("<y>").remove("</y>").toDouble(); else if (s.contains("<Text>")){ QStringList txt; while ( s != "</Text>" ){ s = *(++line); txt << s; } txt.pop_back(); l->setText(txt.join("\n")); } else if (s.contains("<Font>")){ QStringList lst = s.remove("<Font>").remove("</Font>").split("\t"); QFont f = QFont(lst[0], lst[1].toInt(), lst[2].toInt(), lst[3].toInt()); f.setUnderline(lst[4].toInt()); f.setStrikeOut(lst[5].toInt()); l->setFont(f); } else if (s.contains("<TextColor>")) l->setTextColor(QColor(s.remove("<TextColor>").remove("</TextColor>"))); else if (s.contains("<Background>")) backgroundColor = QColor(s.remove("<Background>").remove("</Background>")); else if (s.contains("<Alpha>")) backgroundColor.setAlpha(s.remove("<Alpha>").remove("</Alpha>").toInt()); else if (s.contains("<Angle>")) l->setAngle(s.remove("<Angle>").remove("</Angle>").toInt()); else if (s.contains("<AutoUpdate>")) l->setAutoUpdate(s.remove("<AutoUpdate>").remove("</AutoUpdate>").toInt()); } if (l){ l->setBackgroundColor(backgroundColor); l->setOriginCoord(x, y); g->add(l, false); } }
void VirtualClusterLineEdit::setStrikeOut(bool enable) { if (font().strikeOut() == enable) return; QFont font = this->font(); font.setStrikeOut(enable); setFont(font); if (enable) connect(this, SIGNAL(textEdited(QString)), this, SLOT(setStrikeOut())); else disconnect(this, SIGNAL(textEdited(QString)), this, SLOT(setStrikeOut())); }
void ConvertDialogTest::convert_addText_fontPx() { EffectsScrollArea *effectsScrollArea = convertDialog->effectsScrollArea; QGroupBox *textGroupBox = effectsScrollArea->textGroupBox; textGroupBox->setChecked(true); QLineEdit *textLineEdit = effectsScrollArea->textLineEdit; QString testText = "Test Text"; textLineEdit->setText(testText); QComboBox *fontSizeComboBox = effectsScrollArea->textFontSizeComboBox; int px = 1; fontSizeComboBox->setCurrentIndex(px); QFont font = effectsScrollArea->textFontComboBox->currentFont(); int fontSize = 20; font.setPixelSize(fontSize); font.setBold(true); font.setItalic(true); font.setUnderline(true); font.setStrikeOut(true); effectsScrollArea->textFontSizeSpinBox->setValue(fontSize); effectsScrollArea->textBoldPushButton->setChecked(font.bold()); effectsScrollArea->textItalicPushButton->setChecked(font.italic()); effectsScrollArea->textUnderlinePushButton->setChecked(font.underline()); effectsScrollArea->textStrikeOutPushButton->setChecked(font.strikeOut()); QColor color = Qt::green; effectsScrollArea->textColorFrame->setColor(color); effectsScrollArea->textOpacitySpinBox->setValue(0.5); effectsScrollArea->textPositionComboBox->setCurrentIndex(TopRightCorner); QPoint position = QPoint(4, 3); effectsScrollArea->textXSpinBox->setValue(position.x()); effectsScrollArea->textYSpinBox->setValue(position.y()); convertDialog->convert(); SharedInformation *sharedInfo = convertDialog->sharedInfo; EffectsConfiguration conf = sharedInfo->effectsConfiguration(); QCOMPARE(conf.getTextString(), testText); QCOMPARE(conf.getTextFont(), font); QCOMPARE(conf.getTextColor(), color); QCOMPARE(conf.getTextOpacity(), 0.5); QCOMPARE(conf.getTextPosModifier(), TopRightCorner); QCOMPARE(conf.getTextPos(), position); QCOMPARE(conf.getTextUnitPair(), PosUnitPair(Pixel, Pixel)); QCOMPARE(conf.getTextFrame(), false); QCOMPARE(conf.getTextRotation(), 0); }
QVariant EntryModel::data(const QModelIndex& index, int role) const { if (!index.isValid()) { return QVariant(); } Entry* entry = entryFromIndex(index); if (role == Qt::DisplayRole) { switch (index.column()) { case ParentGroup: if (entry->group()) { return entry->group()->name(); } break; case Title: return entry->title(); case Username: return entry->username(); case Url: return entry->url(); } } else if (role == Qt::DecorationRole) { switch (index.column()) { case ParentGroup: if (entry->group()) { return entry->group()->iconScaledPixmap(); } break; case Title: if (entry->isExpired()) { return databaseIcons()->iconPixmap(DatabaseIcons::ExpiredIconIndex); } else { return entry->iconScaledPixmap(); } } } else if (role == Qt::FontRole) { QFont font; if (entry->isExpired()) { font.setStrikeOut(true); } return font; } return QVariant(); }
QFont State::font(QFont base) { if (bold()) base.setBold(true); if (italic()) base.setItalic(true); if (underline()) base.setUnderline(true); if (strikeOut()) base.setStrikeOut(true); if (!fontName().isEmpty()) base.setFamily(fontName()); if (fontSize() > 0) base.setPointSize(fontSize()); return base; }
void tst_QFont::resolve() { QFont font; font.setPointSize(font.pointSize() * 2); font.setItalic(false); font.setWeight(QFont::Normal); font.setUnderline(false); font.setStrikeOut(false); font.setOverline(false); font.setStretch(QFont::Unstretched); QFont font1; font1.setWeight(QFont::Bold); QFont font2 = font1.resolve(font); QVERIFY(font2.weight() == font1.weight()); QVERIFY(font2.pointSize() == font.pointSize()); QVERIFY(font2.italic() == font.italic()); QVERIFY(font2.underline() == font.underline()); QVERIFY(font2.overline() == font.overline()); QVERIFY(font2.strikeOut() == font.strikeOut()); QVERIFY(font2.stretch() == font.stretch()); QFont font3; font3.setStretch(QFont::UltraCondensed); QFont font4 = font3.resolve(font1).resolve(font); QVERIFY(font4.stretch() == font3.stretch()); QVERIFY(font4.weight() == font.weight()); QVERIFY(font4.pointSize() == font.pointSize()); QVERIFY(font4.italic() == font.italic()); QVERIFY(font4.underline() == font.underline()); QVERIFY(font4.overline() == font.overline()); QVERIFY(font4.strikeOut() == font.strikeOut()); QFont f1,f2,f3; f2.setPointSize(45); f3.setPointSize(55); QFont f4 = f1.resolve(f2); QCOMPARE(f4.pointSize(), 45); f4 = f4.resolve(f3); QCOMPARE(f4.pointSize(), 55); }
void KInvestmentListItem::paintCell(QPainter * p, const QColorGroup & cg, int column, int width, int align) { bool bPaintRed = false; if((column == COLUMN_RAWGAIN_INDEX && bColumn5Negative) || (column == COLUMN_1WEEKGAIN_INDEX && bColumn6Negative) || (column == COLUMN_4WEEKGAIN_INDEX && bColumn7Negative) || (column == COLUMN_3MONGAIN_INDEX && bColumn8Negative) || (column == COLUMN_YTDGAIN_INDEX && bColumn9Negative)) { bPaintRed = true; } p->save(); QColorGroup cg2(cg); if(isAlternate()) cg2.setColor(QColorGroup::Base, KMyMoneyGlobalSettings::listColor()); else cg2.setColor(QColorGroup::Base, KMyMoneyGlobalSettings::listBGColor()); #ifndef KMM_DESIGNER QFont font = KMyMoneyGlobalSettings::listCellFont(); // strike out closed accounts if(m_account.isClosed()) font.setStrikeOut(true); p->setFont(font); #endif if(bPaintRed) { QColorGroup _cg( cg2); QColor c = _cg.text(); _cg.setColor(QColorGroup::Text, Qt::red); QListViewItem::paintCell(p, _cg, column, width, align); _cg.setColor(QColorGroup::Text, c); } else { QListViewItem::paintCell(p, cg2, column, width, align); } p->restore(); }
void ChronoShareGui::checkFileAction(const std::string& filename, int action, int index) { filesystem::path realPathToFolder(m_dirPath.toStdString()); realPathToFolder /= m_sharedFolderName.toStdString(); realPathToFolder /= filename; QString fullPath = realPathToFolder.string().c_str(); QFileInfo fileInfo(fullPath); if (fileInfo.exists()) { // This is a hack, we just use some field to store the path m_fileActions[index]->setToolTip(fileInfo.absolutePath()); m_fileActions[index]->setEnabled(true); } else { // after half an hour frustrating test and search around, // I think it's the problem of Qt. // According to the Qt doc, the action cannot be clicked // and the area would be grey, but it didn't happen // User can still trigger the action, and not greyed // added check in SLOT to see if the action is "enalbed" // as a remedy // Give up at least for now m_fileActions[index]->setEnabled(false); // UPDATE, file not fetched yet if (action == 0) { QFont font; // supposed by change the font, didn't happen font.setWeight(QFont::Light); m_fileActions[index]->setFont(font); m_fileActions[index]->setToolTip(tr("Fetching...")); } // DELETE else { QFont font; // supposed by change the font, didn't happen font.setStrikeOut(true); m_fileActions[index]->setFont(font); m_fileActions[index]->setToolTip(tr("Deleted...")); } } m_fileActions[index]->setText(fileInfo.fileName()); m_fileActions[index]->setVisible(true); }
//![data] QVariant TodosModel::data(const QModelIndex &index, int role) const { if (role == Qt::FontRole) { bool completed = EnginioModel::data(index, CompletedRole).value<QJsonValue>().toBool(); QFont font; font.setPointSize(20); font.setStrikeOut(completed); return font; } if (role == Qt::TextColorRole) { bool completed = EnginioModel::data(index, CompletedRole).value<QJsonValue>().toBool(); return completed ? QColor("#999") : QColor("#333"); } if (role == CompletedRole) return EnginioModel::data(index, CompletedRole).value<QJsonValue>().toBool(); // fallback to base class return EnginioModel::data(index, role); }
QVariant pEnvironmentVariablesModel::data( const QModelIndex& index, int role ) const { if ( !index.isValid() || index.row() < 0 || index.row() >= mRowCount || index.column() < 0 || index.column() >= 2 ) { return QVariant(); } pEnvironmentVariablesModel::Variable* variable = static_cast<pEnvironmentVariablesModel::Variable*>( index.internalPointer() ); switch ( role ) { case Qt::DisplayRole: { switch ( index.column() ) { case 0: return variable->name; case 1: return variable->value; } } case Qt::ToolTipRole: { const QStringList entries = QStringList() << tr( "Name: %1" ).arg( variable->name ) << tr( "Value: %1" ).arg( variable->value ) << tr( "Enabled: %1" ).arg( variable->enabled ? tr( "true" ) : tr( "false" ) ); return entries.join( QSL( "\n" ) ); } case Qt::FontRole: { QFont font; font.setStrikeOut( !variable->enabled ); return font; } case Qt::CheckStateRole: { if ( index.column() == 0 ) { return variable->enabled ? Qt::Checked : Qt::Unchecked; } break; } } return QVariant(); }
void Setting::updateFont(QFont &font, QString entry) { // do font stuff QString s = readEntry(entry); if (!s) return; #ifdef Q_WS_X11_xxx font.setRawName(s); #else QString fs = element(s, 0, "-"); font.setFamily(fs); // qDebug("FAMILY: %s", fs.latin1()); for (int i=1; i<6; i++) { int n = element(s, i, "-").toInt(); switch (i) { case 1: font.setPointSize(n); break; case 2: font.setWeight(n); break; case 3: font.setItalic(n); break; case 4: font.setUnderline(n); break; case 5: font.setStrikeOut(n); break; default: qWarning("Unknown font attribut!"); } } #endif }
void QPicturePaintEngine::drawTextItem(const QPointF &p , const QTextItem &ti) { Q_D(QPicturePaintEngine); #ifdef QT_PICTURE_DEBUG qDebug() << " -> drawTextItem():" << p << ti.text(); #endif const QTextItemInt &si = static_cast<const QTextItemInt &>(ti); if (si.chars == 0) QPaintEngine::drawTextItem(p, ti); // Draw as path if (d->pic_d->formatMajor >= 9) { int pos; SERIALIZE_CMD(QPicturePrivate::PdcDrawTextItem); QFont fnt = ti.font(); fnt.setUnderline(false); fnt.setStrikeOut(false); fnt.setOverline(false); qreal justificationWidth = 0; if (si.justified) justificationWidth = si.width.toReal(); d->s << p << ti.text() << fnt << ti.renderFlags() << double(fnt.d->dpi)/qt_defaultDpi() << justificationWidth; writeCmdLength(pos, /*brect=*/QRectF(), /*corr=*/false); } else if (d->pic_d->formatMajor >= 8) { // old old (buggy) format int pos; SERIALIZE_CMD(QPicturePrivate::PdcDrawTextItem); d->s << QPointF(p.x(), p.y() - ti.ascent()) << ti.text() << ti.font() << ti.renderFlags(); writeCmdLength(pos, /*brect=*/QRectF(), /*corr=*/false); } else { // old (buggy) format int pos; SERIALIZE_CMD(QPicturePrivate::PdcDrawText2); d->s << p << ti.text(); writeCmdLength(pos, QRectF(p, QSizeF(1,1)), true); } }
QFont Calligra::Sheets::NativeFormat::toFont(KoXmlElement & element) { QFont f; f.setFamily(element.attribute("family")); bool ok; const int size = element.attribute("size").toInt(&ok); if (ok) f.setPointSize(size); const int weight = element.attribute("weight").toInt(&ok); if (!ok) f.setWeight(weight); if (element.hasAttribute("italic") && element.attribute("italic") == "yes") f.setItalic(true); if (element.hasAttribute("bold") && element.attribute("bold") == "yes") f.setBold(true); if (element.hasAttribute("underline") && element.attribute("underline") == "yes") f.setUnderline(true); if (element.hasAttribute("strikeout") && element.attribute("strikeout") == "yes") f.setStrikeOut(true); /* Uncomment when charset is added to kspread_dlg_layout + save a document-global charset if ( element.hasAttribute( "charset" ) ) KGlobal::charsets()->setQFont( f, element.attribute("charset") ); else */ // ######## Not needed anymore in 3.0? //KGlobal::charsets()->setQFont( f, KGlobal::locale()->charset() ); return f; }
// Based on kconfigbase.cpp static QFont Str2Font(const QString &aValue) { uint nFontBits; QFont aRetFont; QString chStr; QStringList sl = QStringList::split(QString::fromLatin1(","), aValue); if(sl.count() == 1) { /* X11 font spec */ aRetFont = QFont(aValue); aRetFont.setRawMode(true); } else if(sl.count() == 10) { /* qt3 font spec */ aRetFont.fromString(aValue); } else if(sl.count() == 6) { /* backward compatible kde2 font spec */ aRetFont = QFont(sl[0], sl[1].toInt(), sl[4].toUInt()); aRetFont.setStyleHint((QFont::StyleHint)sl[2].toUInt()); nFontBits = sl[5].toUInt(); aRetFont.setItalic((nFontBits & 0x01) != 0); aRetFont.setUnderline((nFontBits & 0x02) != 0); aRetFont.setStrikeOut((nFontBits & 0x04) != 0); aRetFont.setFixedPitch((nFontBits & 0x08) != 0); aRetFont.setRawMode((nFontBits & 0x20) != 0); } aRetFont.setStyleStrategy((QFont::StyleStrategy)(QFont::PreferMatch | (_antiAliasing ? QFont::PreferAntialias : QFont::NoAntialias))); return aRetFont; }
void tst_QFont::compare() { QFont font; { QFont font2 = font; font2.setPointSize( 24 ); QVERIFY( font != font2 ); QCOMPARE(font < font2,!(font2 < font)); } { QFont font2 = font; font2.setPixelSize( 24 ); QVERIFY( font != font2 ); QCOMPARE(font < font2,!(font2 < font)); } font.setPointSize(12); font.setItalic(false); font.setWeight(QFont::Normal); font.setUnderline(false); font.setStrikeOut(false); font.setOverline(false); { QFont font2 = font; font2.setPointSize( 24 ); QVERIFY( font != font2 ); QCOMPARE(font < font2,!(font2 < font)); } { QFont font2 = font; font2.setPixelSize( 24 ); QVERIFY( font != font2 ); QCOMPARE(font < font2,!(font2 < font)); } { QFont font2 = font; font2.setItalic(true); QVERIFY( font != font2 ); QCOMPARE(font < font2,!(font2 < font)); font2.setItalic(false); QVERIFY( font == font2 ); QVERIFY(!(font < font2)); font2.setWeight(QFont::Bold); QVERIFY( font != font2 ); QCOMPARE(font < font2,!(font2 < font)); font2.setWeight(QFont::Normal); QVERIFY( font == font2 ); QVERIFY(!(font < font2)); font.setUnderline(true); QVERIFY( font != font2 ); QCOMPARE(font < font2,!(font2 < font)); font.setUnderline(false); QVERIFY( font == font2 ); QVERIFY(!(font < font2)); font.setStrikeOut(true); QVERIFY( font != font2 ); QCOMPARE(font < font2,!(font2 < font)); font.setStrikeOut(false); QVERIFY( font == font2 ); QVERIFY(!(font < font2)); font.setOverline(true); QVERIFY( font != font2 ); QCOMPARE(font < font2,!(font2 < font)); font.setOverline(false); QVERIFY( font == font2 ); QVERIFY(!(font < font2)); font.setCapitalization(QFont::SmallCaps); QVERIFY( font != font2 ); QCOMPARE(font < font2,!(font2 < font)); font.setCapitalization(QFont::MixedCase); QVERIFY( font == font2 ); QVERIFY(!(font < font2)); } #if defined(Q_WS_X11) { QFont font1, font2; font1.setRawName("-Adobe-Helvetica-medium-r-normal--12-120-75-75-p-67-iso8859-1"); font2.setRawName("-Adobe-Helvetica-medium-r-normal--24-240-75-75-p-130-iso8859-1"); QVERIFY(font1 != font2); } #endif }
QtnPropertyDelegateQFont::QtnPropertyDelegateQFont(QtnPropertyQFontBase& owner) : QtnPropertyDelegateTypedEx<QtnPropertyQFontBase>(owner) { QtnPropertyQStringCallback* propertyFamily = new QtnPropertyQStringCallback(0); addSubProperty(propertyFamily); propertyFamily->setName(owner.tr("Family")); propertyFamily->setDescription(owner.tr("Font Family for %1.").arg(owner.name())); propertyFamily->setCallbackValueGet([&owner]()->QString { return owner.value().family(); }); propertyFamily->setCallbackValueSet([&owner](QString value) { QFont font = owner.value(); font.setFamily(value); owner.setValue(font); }); QtnPropertyDelegateInfo delegate; delegate.name = "List"; QFontDatabase fDB; delegate.attributes["items"] = fDB.families(); propertyFamily->setDelegate(delegate); QtnPropertyUIntCallback* propertyPointSize = new QtnPropertyUIntCallback(0); addSubProperty(propertyPointSize); propertyPointSize->setName(owner.tr("PointSize")); propertyPointSize->setDescription(owner.tr("Point size for %1.").arg(owner.name())); propertyPointSize->setCallbackValueGet([&owner]()->quint32 { int ps = owner.value().pointSize(); return ps != -1 ? ps : 1; }); propertyPointSize->setCallbackValueSet([&owner](quint32 value) { QFont font = owner.value(); font.setPointSize((int)value); owner.setValue(font); }); propertyPointSize->setMinValue(1); propertyPointSize->setMaxValue((quint32)std::numeric_limits<int>::max()); QtnPropertyBoolCallback* propertyBold = new QtnPropertyBoolCallback(0); addSubProperty(propertyBold); propertyBold->setName(owner.tr("Bold")); propertyBold->setDescription(owner.tr("Bold flag for %1").arg(owner.name())); propertyBold->setCallbackValueGet([&owner]()->bool { return owner.value().bold(); }); propertyBold->setCallbackValueSet([&owner](bool value) { QFont font = owner.value(); font.setBold(value); owner.setValue(font); }); QtnPropertyBoolCallback* propertyItalic = new QtnPropertyBoolCallback(0); addSubProperty(propertyItalic); propertyItalic->setName(owner.tr("Italic")); propertyItalic->setDescription(owner.tr("Italic flag for %1").arg(owner.name())); propertyItalic->setCallbackValueGet([&owner]()->bool { return owner.value().italic(); }); propertyItalic->setCallbackValueSet([&owner](bool value) { QFont font = owner.value(); font.setItalic(value); owner.setValue(font); }); QtnPropertyBoolCallback* propertyUnderline = new QtnPropertyBoolCallback(0); addSubProperty(propertyUnderline); propertyUnderline->setName(owner.tr("Underline")); propertyUnderline->setDescription(owner.tr("Underline flag for %1").arg(owner.name())); propertyUnderline->setCallbackValueGet([&owner]()->bool { return owner.value().underline(); }); propertyUnderline->setCallbackValueSet([&owner](bool value) { QFont font = owner.value(); font.setUnderline(value); owner.setValue(font); }); QtnPropertyBoolCallback* propertyStrikeout = new QtnPropertyBoolCallback(0); addSubProperty(propertyStrikeout); propertyStrikeout->setName(owner.tr("Strikeout")); propertyStrikeout->setDescription(owner.tr("Strikeout flag for %1").arg(owner.name())); propertyStrikeout->setCallbackValueGet([&owner]()->bool { return owner.value().strikeOut(); }); propertyStrikeout->setCallbackValueSet([&owner](bool value) { QFont font = owner.value(); font.setStrikeOut(value); owner.setValue(font); }); QtnPropertyBoolCallback* propertyKerning = new QtnPropertyBoolCallback(0); addSubProperty(propertyKerning); propertyKerning->setName(owner.tr("Kerning")); propertyKerning->setDescription(owner.tr("Kerning flag for %1").arg(owner.name())); propertyKerning->setCallbackValueGet([&owner]()->bool { return owner.value().kerning(); }); propertyKerning->setCallbackValueSet([&owner](bool value) { QFont font = owner.value(); font.setKerning(value); owner.setValue(font); }); QtnPropertyEnumCallback* propertyAntialiasing = new QtnPropertyEnumCallback(0); addSubProperty(propertyAntialiasing); propertyAntialiasing->setName(owner.tr("Antialiasing")); propertyAntialiasing->setDescription(owner.tr("Antialiasing flag for %1.").arg(owner.name())); propertyAntialiasing->setEnumInfo(styleStrategyEnum()); propertyAntialiasing->setCallbackValueGet([&owner]()->QtnEnumValueType { return owner.value().styleStrategy(); }); propertyAntialiasing->setCallbackValueSet([&owner](QtnEnumValueType value) { QFont font = owner.value(); font.setStyleStrategy((QFont::StyleStrategy)value); owner.setValue(font); }); }
QFont QgsMapToolLabel::labelFontCurrentFeature() { QFont font; QgsVectorLayer* vlayer = currentLayer(); bool labelSettingsOk; QgsPalLayerSettings& labelSettings = currentLabelSettings( &labelSettingsOk ); if ( labelSettingsOk && vlayer ) { font = labelSettings.textFont; QgsFeature f; if ( vlayer->getFeatures( QgsFeatureRequest().setFilterFid( mCurrentLabelPos.featureId ).setFlags( QgsFeatureRequest::NoGeometry ) ).nextFeature( f ) ) { //size int sizeIndx = dataDefinedColumnIndex( QgsPalLayerSettings::Size, vlayer ); if ( sizeIndx != -1 ) { if ( labelSettings.fontSizeInMapUnits ) { font.setPixelSize( labelSettings.sizeToPixel( f.attribute( sizeIndx ).toDouble(), QgsRenderContext(), QgsPalLayerSettings::MapUnits, true ) ); } else { font.setPointSizeF( f.attribute( sizeIndx ).toDouble() ); } } //family int fmIndx = dataDefinedColumnIndex( QgsPalLayerSettings::Family, vlayer ); if ( fmIndx != -1 ) { font.setFamily( f.attribute( fmIndx ).toString() ); } //underline int ulIndx = dataDefinedColumnIndex( QgsPalLayerSettings::Underline, vlayer ); if ( ulIndx != -1 ) { font.setUnderline( f.attribute( ulIndx ).toBool() ); } //strikeout int soIndx = dataDefinedColumnIndex( QgsPalLayerSettings::Strikeout, vlayer ); if ( soIndx != -1 ) { font.setStrikeOut( f.attribute( soIndx ).toBool() ); } //bold int boIndx = dataDefinedColumnIndex( QgsPalLayerSettings::Bold, vlayer ); if ( boIndx != -1 ) { font.setBold( f.attribute( boIndx ).toBool() ); } //italic int itIndx = dataDefinedColumnIndex( QgsPalLayerSettings::Italic, vlayer ); if ( itIndx != -1 ) { font.setItalic( f.attribute( itIndx ).toBool() ); } // TODO: Add other font data defined values (word spacing, etc.) } } return font; }