📄 qfont.cpp
字号:
*/#ifndef QT_NO_DEBUGstatic void qt_font_thread_test(){ if (QApplication::instance() && QThread::currentThread() != QApplication::instance()->thread()) qWarning("QFont: It is not safe to use text and fonts outside the GUI thread");}#endif/*! Constructs a font from \a font for use on the paint device \a pd.*/QFont::QFont(const QFont &font, QPaintDevice *pd) : resolve_mask(font.resolve_mask){ Q_ASSERT(pd != 0); int dpi = pd->logicalDpiY();#ifdef Q_WS_X11 const QX11Info *info = qt_x11Info(pd); int screen = info ? info->screen() : 0;#else const int screen = 0;#endif if (font.d->dpi != dpi || font.d->screen != screen ) { d = new QFontPrivate(*font.d); d->dpi = dpi; d->screen = screen; } else { d = font.d; d->ref.ref(); }#ifdef Q_WS_WIN if (pd->devType() == QInternal::Printer && pd->getDC()) d->hdc = pd->getDC();#endif}/*! \internal*/QFont::QFont(QFontPrivate *data) : resolve_mask(QFontPrivate::Complete){#ifndef QT_NO_DEBUG qt_font_thread_test();#endif d = data; d->ref.ref();}/*! \internal Detaches the font object from common font data.*/void QFont::detach(){ if (d->ref == 1) { if (d->engineData) d->engineData->ref.deref(); d->engineData = 0; return; } qAtomicDetach(d);}/*! Constructs a font object that uses the application's default font. \sa QApplication::setFont(), QApplication::font()*/QFont::QFont() :d(QApplication::font().d), resolve_mask(0){ d->ref.ref();}/*! Constructs a font object with the specified \a family, \a pointSize, \a weight and \a italic settings. If \a pointSize is <= 0, it is set to 12. The \a family name may optionally also include a foundry name, e.g. "Helvetica [Cronyx]". If the \a family is available from more than one foundry and the foundry isn't specified, an arbitrary foundry is chosen. If the family isn't available a family will be set using the \l{QFont}{font matching} algorithm. \sa Weight, setFamily(), setPointSize(), setWeight(), setItalic(), setStyleHint() QApplication::font()*/QFont::QFont(const QString &family, int pointSize, int weight, bool italic) :d(new QFontPrivate){#ifndef QT_NO_DEBUG qt_font_thread_test();#endif resolve_mask = QFontPrivate::Family; if (pointSize <= 0) { pointSize = 12; } else { resolve_mask |= QFontPrivate::Size; } if (weight < 0) { weight = Normal; } else { resolve_mask |= QFontPrivate::Weight | QFontPrivate::Style; } d->request.family = family; d->request.pointSize = qreal(pointSize); d->request.pixelSize = -1; d->request.weight = weight; d->request.style = italic ? QFont::StyleItalic : QFont::StyleNormal;}/*! Constructs a font that is a copy of \a font.*/QFont::QFont(const QFont &font){ d = font.d; d->ref.ref(); resolve_mask = font.resolve_mask;}/*! Destroys the font object and frees all allocated resources.*/QFont::~QFont(){ if (!d->ref.deref()) delete d;}/*! Assigns \a font to this font and returns a reference to it.*/QFont &QFont::operator=(const QFont &font){ qAtomicAssign(d, font.d); resolve_mask = font.resolve_mask; return *this;}/*! Returns the requested font family name, i.e. the name set in the constructor or the last setFont() call. \sa setFamily() substitutes() substitute()*/QString QFont::family() const{ return d->request.family;}/*! Sets the family name of the font. The name is case insensitive and may include a foundry name. The \a family name may optionally also include a foundry name, e.g. "Helvetica [Cronyx]". If the \a family is available from more than one foundry and the foundry isn't specified, an arbitrary foundry is chosen. If the family isn't available a family will be set using the \l{QFont}{font matching} algorithm. \sa family(), setStyleHint(), QFontInfo*/void QFont::setFamily(const QString &family){ detach(); d->request.family = family;#if defined(Q_WS_X11) d->request.addStyle.clear();#endif // Q_WS_X11 resolve_mask |= QFontPrivate::Family;}/*! Returns the point size of the font. Returns -1 if the font size was specified in pixels. \sa setPointSize() pointSizeF()*/int QFont::pointSize() const{ return qRound(d->request.pointSize);}/*! Sets the point size to \a pointSize. The point size must be greater than zero. \sa pointSize() setPointSizeF()*/void QFont::setPointSize(int pointSize){ Q_ASSERT_X (pointSize > 0, "QFont::setPointSize", "point size must be greater than 0"); detach(); d->request.pointSize = qreal(pointSize); d->request.pixelSize = -1; resolve_mask |= QFontPrivate::Size;}/*! Sets the point size to \a pointSize. The point size must be greater than zero. The requested precision may not be achieved on all platforms. \sa pointSizeF() setPointSize() setPixelSize()*/void QFont::setPointSizeF(qreal pointSize){ Q_ASSERT_X(pointSize > 0.0, "QFont::setPointSizeF", "point size must be greater than 0"); detach(); d->request.pointSize = pointSize; d->request.pixelSize = -1; resolve_mask |= QFontPrivate::Size;}/*! Returns the point size of the font. Returns -1 if the font size was specified in pixels. \sa pointSize() setPointSizeF() pixelSize() QFontInfo::pointSize() QFontInfo::pixelSize()*/qreal QFont::pointSizeF() const{ return d->request.pointSize;}/*! Sets the font size to \a pixelSize pixels. Using this function makes the font device dependent. Use setPointSize() or setPointSizeF() to set the size of the font in a device independent manner. \sa pixelSize()*/void QFont::setPixelSize(int pixelSize){ if (pixelSize <= 0) { qWarning("QFont::setPixelSize: Pixel size <= 0 (%d)", pixelSize); return; } detach(); d->request.pixelSize = pixelSize; d->request.pointSize = -1; resolve_mask |= QFontPrivate::Size;}/*! Returns the pixel size of the font if it was set with setPixelSize(). Returns -1 if the size was set with setPointSize() or setPointSizeF(). \sa setPixelSize() pointSize() QFontInfo::pointSize() QFontInfo::pixelSize()*/int QFont::pixelSize() const{ return d->request.pixelSize;}#ifdef QT3_SUPPORT/*! \obsolete Sets the logical pixel height of font characters when shown on the screen to \a pixelSize.*/void QFont::setPixelSizeFloat(qreal pixelSize){ setPixelSize((int)pixelSize);}#endif/*! \fn bool QFont::italic() const Returns true if the style() of the font is not QFont::StyleNormal \sa setItalic() style()*//*! \fn void QFont::setItalic(bool enable) Sets the style() of the font to QFont::StyleItalic if \a enable is true; otherwise the style is set to QFont::StyleNormal. \sa italic() QFontInfo*//*! Returns the style of the font. \sa setStyle()*/QFont::Style QFont::style() const{ return (QFont::Style)d->request.style;}/*! Sets the style of the font to \a style. \sa italic(), QFontInfo*/void QFont::setStyle(Style style){ detach(); d->request.style = style; resolve_mask |= QFontPrivate::Style;}/*! Returns the weight of the font which is one of the enumerated values from \l{QFont::Weight}. \sa setWeight(), Weight, QFontInfo*/int QFont::weight() const{ return d->request.weight;}/*! \enum QFont::Weight Qt uses a weighting scale from 0 to 99 similar to, but not the same as, the scales used in Windows or CSS. A weight of 0 is ultralight, whilst 99 will be an extremely black. This enum contains the predefined font weights: \value Light 25 \value Normal 50 \value DemiBold 63 \value Bold 75 \value Black 87*//*! Sets the weight the font to \a weight, which should be a value from the \l QFont::Weight enumeration. \sa weight(), QFontInfo*/void QFont::setWeight(int weight){ Q_ASSERT_X(weight >= 0 && weight <= 99, "QFont::setWeight", "Weight must be between 0 and 99"); detach(); d->request.weight = weight; resolve_mask |= QFontPrivate::Weight;}/*! \fn bool QFont::bold() const Returns true if weight() is a value greater than \link Weight QFont::Normal \endlink; otherwise returns false. \sa weight(), setBold(), QFontInfo::bold()*//*! \fn void QFont::setBold(bool enable) If \a enable is true sets the font's weight to \link Weight QFont::Bold \endlink; otherwise sets the weight to \link Weight QFont::Normal\endlink. For finer boldness control use setWeight(). \sa bold(), setWeight()*//*! Returns true if underline has been set; otherwise returns false. \sa setUnderline()*/bool QFont::underline() const{ return d->underline;}/*! If \a enable is true, sets underline on; otherwise sets underline off. \sa underline(), QFontInfo*/void QFont::setUnderline(bool enable){ detach(); d->underline = enable; resolve_mask |= QFontPrivate::Underline;}/*! Returns true if overline has been set; otherwise returns false. \sa setOverline()*/bool QFont::overline() const{ return d->overline;}/*! If \a enable is true, sets overline on; otherwise sets overline off. \sa overline(), QFontInfo*/void QFont::setOverline(bool enable){ detach(); d->overline = enable; resolve_mask |= QFontPrivate::Overline;}/*! Returns true if strikeout has been set; otherwise returns false. \sa setStrikeOut()*/bool QFont::strikeOut() const{ return d->strikeOut;}/*! If \a enable is true, sets strikeout on; otherwise sets strikeout off. \sa strikeOut(), QFontInfo*/void QFont::setStrikeOut(bool enable){ detach(); d->strikeOut = enable; resolve_mask |= QFontPrivate::StrikeOut;}/*! Returns true if fixed pitch has been set; otherwise returns false. \sa setFixedPitch(), QFontInfo::fixedPitch()*/bool QFont::fixedPitch() const{ return d->request.fixedPitch;}/*! If \a enable is true, sets fixed pitch on; otherwise sets fixed
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -