void Font::init(const QString &n) { // check if font already parsed _data = _dict->find(n); if ( _data==0 ) { // kdDebug(30516) << "font " << n << endl; QString name = n; name.replace("oblique", "italic"); // check if known font _data = new Data; uint i = 0; while ( KNOWN_DATA[i].name!=0 ) { if ( name.find(KNOWN_DATA[i].name)!=-1 ) { // kdDebug(30516) << "found " << KNOWN_DATA[i].name // << " " << isBold(KNOWN_DATA[i].style) << endl; _data->family = FAMILY_DATA[KNOWN_DATA[i].family]; _data->style = KNOWN_DATA[i].style; _data->latex = KNOWN_DATA[i].latex; break; } i++; } if ( _data->family.isEmpty() ) { // let's try harder // simple heuristic kdDebug(30516) << "unknown font : " << n << endl; if ( name.find("times")!=-1 ) _data->family = FAMILY_DATA[Times]; else if ( name.find("helvetica")!=-1 ) _data->family = FAMILY_DATA[Helvetica]; else if ( name.find("courier")!=-1 ) _data->family = FAMILY_DATA[Courier]; else if ( name.find("symbol")!=-1 ) _data->family = FAMILY_DATA[Symbol]; else { // with Qt QFontDatabase fdb; QStringList list = fdb.families(); list = list.grep(name, false); if ( !list.isEmpty() ) { _data->family = list[0]; kdDebug(30516) << "in Qt database as " << list[0] << endl; } else { kdDebug(30516) << "really unknown font !" << endl; _data->family = name; } } bool italic = ( name.find("italic")!=-1 ); bool bold = ( name.find("bold")!=-1 ); _data->style = toStyle(bold, italic); _data->latex = false; } _dict->insert(name, _data); } // check if QFont already created if ( !_data->height.contains(_pointSize) ) { QFont font(_data->family, _pointSize, (isBold(_data->style) ? QFont::Bold : QFont::Normal), isItalic(_data->style)); QFontMetrics fm(font); _data->height.insert(_pointSize, fm.height()); } }
QVariant ToConfiguration::Editor::defaultValue(int option) const { switch (option) { case SyntaxHighlightingInt: return QVariant((int) 0); case EditorTypeInt: return QVariant((int) 0); case UseMaxTextWidthMarkBool: return QVariant((bool) false); case MaxTextWidthMarkInt: return QVariant((int)75); case KeywordUpperBool: return QVariant((bool) false); case ObjectNamesUpperBool: return QVariant((bool) false); case CodeCompleteBool: return QVariant((bool) true); case CompleteSortBool: return QVariant((bool) true); case UseEditorShortcutsBool: return QVariant((bool) false); case EditorShortcutsMap: return QVariant(QMap<QString, QVariant>()); case AutoIndentBool: return QVariant((bool) true); case UseSpacesForIndentBool: return QVariant((bool) false); case TabStopInt: return QVariant((int) 8); case ConfTextFont: return QVariant(QString("")); case ConfCodeFont: { QFont fo; QFont mono; #if defined(Q_OS_WIN) mono = QFont("Courier New", 10); #elif defined(Q_OS_MAC) mono = QFont("Courier", 12); #else // TODO #endif mono.setStyleHint(QFont::Monospace, QFont::NoAntialias); fo = mono.resolve(fo); QString fontName = fo.toString(); return QVariant(fontName); } case ListTextFont: return QVariant(QString("")); case Extensions: return QVariant(QString("SQL (*.sql *.pkg *.pkb), Text (*.txt), All (*)")); case EditStyleMap: { static toStylesMap retval; if (!retval.isEmpty()) return QVariant::fromValue(retval); QMetaEnum StyleNameEnum(ENUM_REF(toSyntaxAnalyzer,WordClassEnum)); QsciLexerSQL *l = new QsciLexerSQL(NULL); for (int idx = 0; idx < StyleNameEnum.keyCount(); idx++) { QColor fg = l->color((int)StyleNameEnum.value(idx)); QColor bg = l->paper((int)StyleNameEnum.value(idx)); QFont fo = Utils::toStringToFont(defaultValue(ConfCodeFont).toString()); QString styleName = StyleNameEnum.key(idx); int styleNameEnum = StyleNameEnum.value(idx); retval.insert(styleNameEnum, toStyle(fg, bg, fo)); } delete l; return QVariant::fromValue(retval); } default: Q_ASSERT_X( false, qPrintable(__QHERE__), qPrintable(QString("Context Editor un-registered enum value: %1").arg(option))); return QVariant(); } }