📄 qicon.cpp
字号:
return QSize(); return d->engine->actualSize(size, mode, state);}/*! Uses the \a painter to paint the icon with specified \a alignment, required \a mode, and \a state into the rectangle \a rect. \sa actualSize(), pixmap()*/void QIcon::paint(QPainter *painter, const QRect &rect, Qt::Alignment alignment, Mode mode, State state) const{ if (!d || !painter) return; QRect alignedRect = QStyle::alignedRect(painter->layoutDirection(), alignment, d->engine->actualSize(rect.size(), mode, state), rect); d->engine->paint(painter, alignedRect, mode, state);}/*! \fn void QIcon::paint(QPainter *painter, int x, int y, int w, int h, Qt::Alignment alignment, Mode mode, State state) const \overload Paints the icon into the rectangle QRect(\a x, \a y, \a w, \a h).*//*! Returns true if the icon is empty; otherwise returns false. An icon is empty if it has neither a pixmap nor a filename. Note: Even a non-null icon might not be able to create valid pixmaps, eg. if the file does not exist or cannot be read.*/bool QIcon::isNull() const{ return !d;}/*!\internal */bool QIcon::isDetached() const{ return !d || d->ref == 1;}/*! \internal */void QIcon::detach(){ if (d) { if (d->ref != 1) { QIconPrivate *x = new QIconPrivate; if (d->engine_version > 1) { QIconEngineV2 *engine = static_cast<QIconEngineV2 *>(d->engine); x->engine = engine->clone(); } else { x->engine = d->engine; } x->engine_version = d->engine_version; x = qAtomicSetPtr(&d, x); if (!x->ref.deref()) delete x; } ++d->detach_no; }}/*! Adds \a pixmap to the icon, as a specialization for \a mode and \a state. Custom icon engines are free to ignore additionally added pixmaps. \sa addFile()*/void QIcon::addPixmap(const QPixmap &pixmap, Mode mode, State state){ if (pixmap.isNull()) return; if (!d) { d = new QIconPrivate; d->engine = new QPixmapIconEngine; } else { detach(); } d->engine->addPixmap(pixmap, mode, state);}/*! Adds a pixmap from the file with the given \a fileName to the icon, as a specialization for \a size, \a mode and \a state. The file will be loaded on demand. Note: custom icon engines are free to ignore additionally added pixmaps. If \a fileName contains a relative path (e.g. the filename only) the relevant file must be found relative to the runtime working directory. The file name can be either refer to an actual file on disk or to one of the application's embedded resources. See the \l{resources.html}{Resource System} overview for details on how to embed images and other resource files in the application's executable. Use the QImageReader::supportedImageFormats() and QImageWriter::supportedImageFormats() functions to retrieve a complete list of the supported file formats. \sa addPixmap() */void QIcon::addFile(const QString &fileName, const QSize &size, Mode mode, State state){ if (fileName.isEmpty()) return; if (!d) { d = new QIconPrivate; d->engine = new QPixmapIconEngine; } else { detach(); } d->engine->addFile(fileName, size, mode, state);}/***************************************************************************** QIcon stream functions *****************************************************************************/#if !defined(QT_NO_DATASTREAM)/*! \fn QDataStream &operator<<(QDataStream &stream, const QIcon &icon) \relates QIcon \since 4.2 Writes the given \a icon to the the given \a stream as a PNG image. If the icon contains more than one image, all images will be written to the stream. Note that writing the stream to a file will not produce a valid image file.*/QDataStream &operator<<(QDataStream &s, const QIcon &icon){ if (s.version() >= QDataStream::Qt_4_3) { if (icon.isNull()) { s << QString(); } else { if (icon.d->engine_version > 1) { QIconEngineV2 *engine = static_cast<QIconEngineV2 *>(icon.d->engine); s << engine->key(); engine->write(s); } else { // not really supported qWarning("QIcon: Cannot stream QIconEngine. Use QIconEngineV2 instead."); } } } else if (s.version() == QDataStream::Qt_4_2) { if (icon.isNull()) { s << 0; } else { QPixmapIconEngine *engine = static_cast<QPixmapIconEngine *>(icon.d->engine); int num_entries = engine->pixmaps.size(); s << num_entries; for (int i=0; i < num_entries; ++i) { s << engine->pixmaps.at(i).pixmap; s << engine->pixmaps.at(i).fileName; s << engine->pixmaps.at(i).size; s << (uint) engine->pixmaps.at(i).mode; s << (uint) engine->pixmaps.at(i).state; } } } else { s << QPixmap(icon.pixmap(22,22)); } return s;}/*! \fn QDataStream &operator>>(QDataStream &stream, QIcon &icon) \relates QIcon \since 4.2 Reads an image, or a set of images, from the given \a stream into the given \a icon.*/QDataStream &operator>>(QDataStream &s, QIcon &icon){ if (s.version() >= QDataStream::Qt_4_3) { icon = QIcon(); QString key; s >> key; if (key == QLatin1String("QPixmapIconEngine")) { icon.d = new QIconPrivate; QIconEngineV2 *engine = new QPixmapIconEngine; icon.d->engine = engine; engine->read(s);#ifndef QT_NO_LIBRARY } else if (QIconEngineFactoryInterfaceV2 *factory = qobject_cast<QIconEngineFactoryInterfaceV2*>(loaderV2()->instance(key))) { if (QIconEngineV2 *engine= factory->create()) { icon.d = new QIconPrivate; icon.d->engine = engine; engine->read(s); }#endif } } else if (s.version() == QDataStream::Qt_4_2) { icon = QIcon(); int num_entries; QPixmap pm; QString fileName; QSize sz; uint mode; uint state; s >> num_entries; for (int i=0; i < num_entries; ++i) { s >> pm; s >> fileName; s >> sz; s >> mode; s >> state; if (pm.isNull()) icon.addFile(fileName, sz, QIcon::Mode(mode), QIcon::State(state)); else icon.addPixmap(pm, QIcon::Mode(mode), QIcon::State(state)); } } else { QPixmap pm; s >> pm; icon.addPixmap(pm); } return s;}#endif //QT_NO_DATASTREAM#ifdef QT3_SUPPORTstatic int widths[2] = { 22, 32 };static int heights[2] = { 22, 32 };static QSize pixmapSize(QIcon::Size which) { int i = 0; if (which == QIcon::Large) i = 1; return QSize(widths[i], heights[i]);}/*! \enum QIcon::Size \compat \value Small Use QStyle::pixelMetric(QStyle::PM_SmallIconSize) instead. \value Large Use QStyle::pixelMetric(QStyle::PM_LargeIconSize) instead. \value Automatic N/A.*//*! Use pixmap(QSize(...), \a mode, \a state), where the first argument is an appropriate QSize instead of a \l Size value. \sa pixmapSize()*/QPixmap QIcon::pixmap(Size size, Mode mode, State state) const{ return pixmap(::pixmapSize(size), mode, state); }/*! Use pixmap(QSize(...), mode, \a state), where the first argument is an appropriate QSize instead of a \l Size value, and the second argument is QIcon::Normal or QIcon::Disabled, depending on the value of \a enabled. \sa pixmapSize()*/QPixmap QIcon::pixmap(Size size, bool enabled, State state) const{ return pixmap(::pixmapSize(size), enabled ? Normal : Disabled, state); }/*! Use one of the other pixmap() overloads.*/QPixmap QIcon::pixmap() const{ return pixmap(::pixmapSize(Small), Normal, Off); }/*! The pixmap() function now takes a QSize instead of a QIcon::Size, so there is no need for this function in new code.*/void QIcon::setPixmapSize(Size which, const QSize &size){ int i = 0; if (which == Large) i = 1; widths[i] = size.width(); heights[i] = size.height();}/*! Use QStyle::pixelMetric() with QStyle::PM_SmallIconSize or QStyle::PM_LargeIconSize as the first argument, depending on \a which.*/QSize QIcon::pixmapSize(Size which){ return ::pixmapSize(which);}/*! \fn void QIcon::reset(const QPixmap &pixmap, Size size) Use the constructor that takes a QPixmap and operator=().*//*! \fn void QIcon::setPixmap(const QPixmap &pixmap, Size size, Mode mode, State state) Use addPixmap(\a pixmap, \a mode, \a state) instead. The \a size parameter is ignored.*//*! \fn void QIcon::setPixmap(const QString &fileName, Size size, Mode mode, State state) Use addFile(\a fileName, \a mode, \a state) instead. The \a size parameter is ignored.*/#endif // QT3_SUPPORT/*! \fn DataPtr &QIcon::data_ptr() \internal*//*! \typedef QIcon::DataPtr \internal*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -