📄 qapplication_x11.cpp
字号:
if (codec) QTextCodec::setCodecForTr(codec); } int w = settings.value(QLatin1String("globalStrut/width")).toInt(); int h = settings.value(QLatin1String("globalStrut/height")).toInt(); QSize strut(w, h); if (strut.isValid()) QApplication::setGlobalStrut(strut); QStringList effects = settings.value(QLatin1String("GUIEffects")).toStringList(); QApplication::setEffectEnabled(Qt::UI_General, effects.contains(QLatin1String("general"))); QApplication::setEffectEnabled(Qt::UI_AnimateMenu, effects.contains(QLatin1String("animatemenu"))); QApplication::setEffectEnabled(Qt::UI_FadeMenu, effects.contains(QLatin1String("fademenu"))); QApplication::setEffectEnabled(Qt::UI_AnimateCombo, effects.contains(QLatin1String("animatecombo"))); QApplication::setEffectEnabled(Qt::UI_AnimateTooltip, effects.contains(QLatin1String("animatetooltip"))); QApplication::setEffectEnabled(Qt::UI_FadeTooltip, effects.contains(QLatin1String("fadetooltip"))); QApplication::setEffectEnabled(Qt::UI_AnimateToolBox, effects.contains(QLatin1String("animatetoolbox"))); settings.beginGroup(QLatin1String("Font Substitutions")); QStringList fontsubs = settings.childKeys(); if (!fontsubs.isEmpty()) { QStringList::Iterator it = fontsubs.begin(); for (; it != fontsubs.end(); ++it) { QString fam = *it; QStringList subs = settings.value(fam).toStringList(); QFont::insertSubstitutions(fam, subs); } } settings.endGroup(); qt_use_rtl_extensions = settings.value(QLatin1String("useRtlExtensions"), false).toBool();#ifndef QT_NO_XIM if (qt_xim_preferred_style == 0) { QString ximInputStyle = settings.value(QLatin1String("XIMInputStyle"), QVariant(QLatin1String("on the spot"))).toString().toLower(); if (ximInputStyle == QLatin1String("on the spot")) qt_xim_preferred_style = XIMPreeditCallbacks | XIMStatusNothing; else if (ximInputStyle == QLatin1String("over the spot")) qt_xim_preferred_style = XIMPreeditPosition | XIMStatusNothing; else if (ximInputStyle == QLatin1String("off the spot")) qt_xim_preferred_style = XIMPreeditArea | XIMStatusArea; else if (ximInputStyle == QLatin1String("root")) qt_xim_preferred_style = XIMPreeditNothing | XIMStatusNothing; }#endif QStringList inputMethods = QInputContextFactory::keys(); if (inputMethods.size() > 2 && inputMethods.contains(QLatin1String("imsw-multi"))) { X11->default_im = QLatin1String("imsw-multi"); } else { X11->default_im = settings.value(QLatin1String("DefaultInputMethod"), QLatin1String("xim")).toString(); } settings.endGroup(); // Qt return true;}/*! \internal Resets the QApplication::instance() pointer to zero*/void QApplicationPrivate::reset_instance_pointer(){ QApplication::self = 0; }// read the _QT_INPUT_ENCODING property and apply the settings to// the applicationstatic void qt_set_input_encoding(){ Atom type; int format; ulong nitems, after = 1; unsigned char *data = 0; int e = XGetWindowProperty(X11->display, QX11Info::appRootWindow(), ATOM(_QT_INPUT_ENCODING), 0, 1024, False, XA_STRING, &type, &format, &nitems, &after, &data); if (e != Success || !nitems || type == XNone) { // Always use the locale codec, since we have no examples of non-local // XIMs, and since we cannot get a sensible answer about the encoding // from the XIM. qt_input_mapper = QTextCodec::codecForLocale(); } else { if (!qstricmp((char *)data, "locale")) qt_input_mapper = QTextCodec::codecForLocale(); else qt_input_mapper = QTextCodec::codecForName((char *)data); // make sure we have an input codec if(!qt_input_mapper) qt_input_mapper = QTextCodec::codecForName("ISO 8859-1"); } if (qt_input_mapper && qt_input_mapper->mibEnum() == 11) // 8859-8 qt_input_mapper = QTextCodec::codecForName("ISO 8859-8-I"); if(data) XFree((char *)data);}// set font, foreground and background from x11 resources. The// arguments may override the resource settings.static void qt_set_x11_resources(const char* font = 0, const char* fg = 0, const char* bg = 0, const char* button = 0){ QString resFont, resFG, resBG, resButton, resEF, sysFont, selectBackground, selectForeground; QApplication::setEffectEnabled(Qt::UI_General, false); QApplication::setEffectEnabled(Qt::UI_AnimateMenu, false); QApplication::setEffectEnabled(Qt::UI_FadeMenu, false); QApplication::setEffectEnabled(Qt::UI_AnimateCombo, false); QApplication::setEffectEnabled(Qt::UI_AnimateTooltip, false); QApplication::setEffectEnabled(Qt::UI_FadeTooltip, false); QApplication::setEffectEnabled(Qt::UI_AnimateToolBox, false); bool paletteAlreadySet = false; if (QApplication::desktopSettingsAware()) { // first, read from settings QApplicationPrivate::x11_apply_settings(); // the call to QApplication::style() below creates the system // palette, which breaks the logic after the RESOURCE_MANAGER // loop... so I have to save this value to be able to use it later paletteAlreadySet = (QApplicationPrivate::sys_pal != 0); // second, parse the RESOURCE_MANAGER property int format; ulong nitems, after = 1; QString res; long offset = 0; Atom type = XNone; while (after > 0) { uchar *data = 0; if (XGetWindowProperty(X11->display, QX11Info::appRootWindow(0), ATOM(RESOURCE_MANAGER), offset, 8192, False, AnyPropertyType, &type, &format, &nitems, &after, &data) != Success) { res = QString(); break; } if (type == XA_STRING) res += QString::fromLatin1((char*)data); else res += QString::fromLocal8Bit((char*)data); offset += 2048; // offset is in 32bit quantities... 8192/4 == 2048 if (data) XFree((char *)data); } QString key, value; int l = 0, r; QString apn = QString::fromLocal8Bit(appName); QString apc = QString::fromLocal8Bit(appClass); int apnl = apn.length(); int apcl = apc.length(); int resl = res.length(); while (l < resl) { r = res.indexOf(QLatin1Char('\n'), l); if (r < 0) r = resl; while (res.at(l).isSpace()) l++; bool mine = false; QChar sc = res.at(l + 1); if (res.at(l) == QLatin1Char('*') && (sc == QLatin1Char('f') || sc == QLatin1Char('b') || sc == QLatin1Char('g') || sc == QLatin1Char('F') || sc == QLatin1Char('B') || sc == QLatin1Char('G') || sc == QLatin1Char('s') || sc == QLatin1Char('S') // capital T only, since we're looking for "Text.selectSomething" || sc == QLatin1Char('T'))) { // OPTIMIZED, since we only want "*[fbgsT].." QString item = res.mid(l, r - l).simplified(); int i = item.indexOf(QLatin1Char(':')); key = item.left(i).trimmed().mid(1).toLower(); value = item.right(item.length() - i - 1).trimmed(); mine = true; } else if (apnl && res.at(l) == apn.at(0) || (appClass && apcl && res.at(l) == apc.at(0))) { if (res.mid(l,apnl) == apn && (res.at(l+apnl) == QLatin1Char('.') || res.at(l+apnl) == QLatin1Char('*'))) { QString item = res.mid(l, r - l).simplified(); int i = item.indexOf(QLatin1Char(':')); key = item.left(i).trimmed().mid(apnl+1).toLower(); value = item.right(item.length() - i - 1).trimmed(); mine = true; } else if (res.mid(l,apcl) == apc && (res.at(l+apcl) == QLatin1Char('.') || res.at(l+apcl) == QLatin1Char('*'))) { QString item = res.mid(l, r - l).simplified(); int i = item.indexOf(QLatin1Char(':')); key = item.left(i).trimmed().mid(apcl+1).toLower(); value = item.right(item.length() - i - 1).trimmed(); mine = true; } } if (mine) { if (!font && key == QLatin1String("systemfont")) sysFont = value.left(value.lastIndexOf(QLatin1Char(':'))); if (!font && key == QLatin1String("font")) resFont = value; else if (!fg && !paletteAlreadySet) { if (key == QLatin1String("foreground")) resFG = value; else if (!bg && key == QLatin1String("background")) resBG = value; else if (!bg && !button && key == QLatin1String("button.background")) resButton = value; else if (key == QLatin1String("text.selectbackground")) { selectBackground = value; } else if (key == QLatin1String("text.selectforeground")) { selectForeground = value; } } else if (key == QLatin1String("guieffects")) resEF = value; // NOTE: if you add more, change the [fbg] stuff above } l = r + 1; } } if (!sysFont.isEmpty()) resFont = sysFont; if (resFont.isEmpty()) resFont = QString::fromLocal8Bit(font); if (resFG.isEmpty()) resFG = QString::fromLocal8Bit(fg); if (resBG.isEmpty()) resBG = QString::fromLocal8Bit(bg); if (resButton.isEmpty()) resButton = QString::fromLocal8Bit(button); if (!resFont.isEmpty() && !X11->has_fontconfig) { // set application font QFont fnt; fnt.setRawName(resFont); // the font we get may actually be an alias for another font, // so we reset the application font to the real font info. if (! fnt.exactMatch()) { QFontInfo fontinfo(fnt); fnt.setFamily(fontinfo.family()); fnt.setRawMode(fontinfo.rawMode()); if (! fnt.rawMode()) { fnt.setItalic(fontinfo.italic()); fnt.setWeight(fontinfo.weight()); fnt.setUnderline(fontinfo.underline()); fnt.setStrikeOut(fontinfo.strikeOut()); fnt.setStyleHint(fontinfo.styleHint()); if (fnt.pointSize() <= 0 && fnt.pixelSize() <= 0) { // size is all wrong... fix it qreal pointSize = fontinfo.pixelSize() * 72. / (float) QX11Info::appDpiY(); if (pointSize <= 0) pointSize = 12; fnt.setPointSize(qRound(pointSize)); } } } QApplicationPrivate::setSystemFont(fnt); } if ((button || !resBG.isEmpty() || !resFG.isEmpty())) {// set app colors bool allowX11ColorNames = QColor::allowX11ColorNames(); QColor::setAllowX11ColorNames(true); (void) QApplication::style(); // trigger creation of application style and system palettes QColor btn; QColor bg; QColor fg; if (!resBG.isEmpty()) bg = QColor(resBG); if (!bg.isValid()) bg = QApplicationPrivate::sys_pal->color(QPalette::Active, QPalette::Window); if (!resFG.isEmpty()) fg = QColor(resFG); if (!fg.isValid()) fg = QApplicationPrivate::sys_pal->color(QPalette::Active, QPalette::WindowText); if (!resButton.isEmpty()) btn = QColor(resButton); else if (!resBG.isEmpty()) btn = bg; if (!btn.isValid()) btn = QApplicationPrivate::sys_pal->color(QPalette::Active, QPalette::Button); int h,s,v; fg.getHsv(&h,&s,&v); QColor base = Qt::white; bool bright_mode = false; if (v >= 255 - 50) { base = btn.darker(150); bright_mode = true; } QPalette pal(fg, btn, btn.lighter(125), btn.darker(130), btn.darker(120), fg, Qt::white, base, bg); QColor disabled((fg.red() + btn.red()) / 2, (fg.green() + btn.green())/ 2, (fg.blue() + btn.blue()) / 2); pal.setColorGroup(QPalette::Disabled, disabled, btn, btn.lighter(125), btn.darker(130), btn.darker(150), disabled, Qt::white, Qt::white, bg); QColor highlight, highlightText; if (!selectBackground.isEmpty() && !selectForeground.isEmpty()) { highlight = QColor(selectBackground); highlightText = QColor(selectForeground); } if (highlight.isValid() && highlightText.isValid()) { pal.setColor(QPalette::Highlight, highlight); pal.setColor(QPalette::HighlightedText, highlightText); // calculate disabled colors by removing saturation highlight.setHsv(highlight.hue(), 0, highlight.value(), highlight.alpha()); highlightText.setHsv(highlightText.hue(), 0, highlightText.value(), highlightText.alpha()); pal.setColor(QPalette::Disabled, QPalette::Highlight, highlight); pal.setColor(QPalette::Disabled, QPalette::HighlightedText, highlightText); } else if (bright_mode) { pal.setColor(QPalette::HighlightedText, base); pal.setColor(QPalette::Highlight, Qt::white); pal.setColor(QPalette::Disabled, QPalette::HighlightedText, base); pal.setColor(QPalette::Disabled, QPalette::Highlight, Qt::white); } else { pal.setColor(QPalette::HighlightedText, Qt::white); pal.setColor(QPalette::Highlight, Qt::darkBlue); pal.setColor(QPalette::Disabled, QPalette::HighlightedText, Qt::white); pal.setColor(QPalette::Disabled, QPalette::Highlight, Qt::darkBlue); } QApplicationPrivate::setSystemPalette(pal); QColor::setAllowX11ColorNames(allowX11ColorNames); } if (!resEF.isEmpty()) { QStringList effects = resEF.split(QLatin1Char(' ')); QApplication::setEffectEnabled(Qt::UI_General, effects.contains(QLatin1String("general"))); QApplication::setEffectEnabled(Qt::UI_AnimateMenu, effects.contains(QLatin1String("animatemenu"))); QApplication::setEffectEnabled(Qt::UI_FadeMenu, effects.contains(QLatin1String("fademenu"))); QApplication::setEffectEnabled(Qt::UI_AnimateCombo, effects.contains(QLatin1String("animatecombo"))); QApplication::setEffectEnabled(Qt::UI_AnimateTooltip, effects.contains(QLatin1String("animatetooltip"))); QApplication::setEffectEnabled(Qt::UI_FadeTooltip,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -