本文整理汇总了C++中QFontDatabase::smoothSizes方法的典型用法代码示例。如果您正苦于以下问题:C++ QFontDatabase::smoothSizes方法的具体用法?C++ QFontDatabase::smoothSizes怎么用?C++ QFontDatabase::smoothSizes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QFontDatabase
的用法示例。
在下文中一共展示了QFontDatabase::smoothSizes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fontChanged
void ThemeDialog::fontChanged()
{
QFontDatabase db;
QFont font = m_font_names->currentFont();
QList<int> font_sizes = db.smoothSizes(font.family(), QString());
if (font_sizes.isEmpty()) {
font_sizes = db.standardSizes();
}
qreal font_size = m_font_sizes->currentText().toDouble();
if (font_size < 0.1) {
font_size = std::lround(m_theme.textFont().pointSizeF() * 10.0) * 0.1;
}
m_font_sizes->blockSignals(true);
m_font_sizes->clear();
int index = 0;
for (int i = 0; i < font_sizes.count(); ++i) {
int size = font_sizes.at(i);
if (size <= font_size) {
index = i;
}
m_font_sizes->addItem(QString::number(size));
}
m_font_sizes->setCurrentIndex(index);
m_font_sizes->setEditText(QString::number(font_size));
m_font_sizes->setValidator(new QDoubleValidator(font_sizes.first(), font_sizes.last(), 1, m_font_sizes));
m_font_sizes->blockSignals(false);
}
示例2: loadFontSizeComboBox
// Load the list of font sizes
void EditorButtonBar::loadFontSizeComboBox(QString name) {
QFontDatabase fdb;
fontSizes->clear();
QList<int> sizes = fdb.smoothSizes(name, "Normal");
for (int i=0; i<sizes.size(); i++) {
fontSizes->addItem(QString::number(sizes[i]), sizes[i]);
}
if (sizes.size() == 0) {
fontSizes->addItem("8", 8);
fontSizes->addItem("9", 9);
fontSizes->addItem("10", 10);
fontSizes->addItem("11", 11);
fontSizes->addItem("12", 12);
fontSizes->addItem("14", 14);
fontSizes->addItem("15", 15);
fontSizes->addItem("16", 16);
fontSizes->addItem("17", 17);
fontSizes->addItem("18", 18);
fontSizes->addItem("19", 19);
fontSizes->addItem("20", 20);
fontSizes->addItem("21", 21);
fontSizes->addItem("22", 22);
}
}
示例3: smooth_font_size
void smooth_font_size(QFont &font) {
QFontDatabase fdb;
#if QT_VERSION < QT_VERSION_CHECK(4, 8, 0)
QList<int> size_list = fdb.smoothSizes(font.family(), "");
#else
QList<int> size_list = fdb.smoothSizes(font.family(), font.styleName());
#endif
if (size_list.size() < 2) return;
int last_size = size_list.takeFirst();
foreach (int cur_size, size_list) {
if (font.pointSize() > last_size && font.pointSize() <= cur_size) {
font.setPointSize(cur_size);
return;
}
last_size = cur_size;
}
}
示例4: __updateFontSize
void PreferenceDialog::__updateFontSize(const QFont& font)
{
QFontDatabase fontdatabase;
QList<int> sizeList = fontdatabase.smoothSizes(font.family(), "");
if (sizeList.empty()) sizeList = fontdatabase.pointSizes(font.family(), "");
if (sizeList.empty()) sizeList = fontdatabase.standardSizes();
if (!sizeList.contains(font.pointSize())) sizeList.append(font.pointSize());
fontSize->clear();
for (int size : sizeList) fontSize->addItem(QString::number(size), size);
fontSize->setCurrentIndex(sizeList.indexOf(fontFamilly->currentFont().pointSize()));
}
示例5: update
void Font::update( QPaintDeviceMetrics* devMetrics ) const
{
f.setFamily( fontDef.family.isEmpty() ? KHTMLFactory::defaultHTMLSettings()->stdFontName() : fontDef.family );
f.setItalic( fontDef.italic );
f.setWeight( fontDef.weight );
QFontDatabase db;
int size = fontDef.size;
int lDpiY = kMax(devMetrics->logicalDpiY(), 96);
// ok, now some magic to get a nice unscaled font
// all other font properties should be set before this one!!!!
if( !db.isSmoothlyScalable(f.family(), db.styleString(f)) )
{
QValueList<int> pointSizes = db.smoothSizes(f.family(), db.styleString(f));
// lets see if we find a nice looking font, which is not too far away
// from the requested one.
// kdDebug(6080) << "khtml::setFontSize family = " << f.family() << " size requested=" << size << endl;
QValueList<int>::Iterator it;
float diff = 1; // ### 100% deviation
float bestSize = 0;
for( it = pointSizes.begin(); it != pointSizes.end(); ++it )
{
float newDiff = ((*it)*(lDpiY/72.) - float(size))/float(size);
//kdDebug( 6080 ) << "smooth font size: " << *it << " diff=" << newDiff << endl;
if(newDiff < 0) newDiff = -newDiff;
if(newDiff < diff)
{
diff = newDiff;
bestSize = *it;
}
}
//kdDebug( 6080 ) << "best smooth font size: " << bestSize << " diff=" << diff << endl;
if ( bestSize != 0 && diff < 0.2 ) // 20% deviation, otherwise we use a scaled font...
size = (int)((bestSize*lDpiY) / 72);
}
// make sure we don't bust up X11
size = KMAX(0, KMIN(255, size));
// qDebug("setting font to %s, italic=%d, weight=%d, size=%d", fontDef.family.latin1(), fontDef.italic,
// fontDef.weight, size );
f.setPixelSize( size );
fm = QFontMetrics( f );
fontDef.hasNbsp = fm.inFont( 0xa0 );
}
示例6: smooth_font_size
void smooth_font_size(QFont &font) {
QFontDatabase fdb;
QList<int> size_list = fdb.smoothSizes(font.family(), font.styleName());
if (size_list.size() < 2) return;
int last_size = size_list.takeFirst();
foreach (int cur_size, size_list) {
if (font.pointSize() > last_size && font.pointSize() <= cur_size) {
font.setPointSize(cur_size);
return;
}
last_size = cur_size;
}
}