⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 q3mimefactory.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        // handle absolute file names directly        r = dataInternal(abs_name, d->extensions);    }    else { // check list of paths        for (it = d->path.begin(); !r && it != d->path.end(); ++it) {            QString filename = *it;            if (filename[(int)filename.length()-1] != QLatin1Char('/'))                filename += QLatin1Char('/');            filename += abs_name;            r = dataInternal(filename, d->extensions);        }    }    static bool looping = false;    if (!r && this == defaultFactory()) {        // we found no mime-source and we are the default factory, so        // we know all the other installed mime-source factories, so        // ask them        if (!looping) {            // to avoid endless recustions, don't enter the loop below            // if data() got called from within the loop below            looping = true;            for (int i = 0; i < d->factories.size(); ++i) {                const Q3MimeSourceFactory *f = d->factories.at(i);                if (f == this)                    continue;                r = static_cast<const QMimeSource *>(f->data(abs_name));                if (r) {                    looping = false;                    return r;                }            }            looping = false;        }    } else if (!r) {        // we are not the default mime-source factory, so ask the        // default one for the mime-source, as this one will loop over        // all installed mime-source factories and ask these        r = static_cast<const QMimeSource *>(defaultFactory()->data(abs_name));    }    return r;}/*!    \fn void Q3MimeSourceFactory::setFilePath(const QStringList &path)    \fn void Q3MimeSourceFactory::setFilePath(const QString &path)    Sets the list of directories that will be searched when named data    is requested to those given in the string list \a path.    \sa filePath()*/void Q3MimeSourceFactory::setFilePath(const QStringList& path){    d->path = path;}/*!    Returns the currently set search paths.*/QStringList Q3MimeSourceFactory::filePath() const{    return d->path;}/*!    Adds another search path, \a p to the existing search paths.    \sa setFilePath()*/void Q3MimeSourceFactory::addFilePath(const QString& p){    d->path += p;}/*!    Sets the mime-type to be associated with the file name extension,    \a ext to \a mimetype. This determines the mime-type for files    found via the paths set by setFilePath().*/void Q3MimeSourceFactory::setExtensionType(const QString& ext, const char* mimetype){    d->extensions.insert(ext, QLatin1String(mimetype));}/*!    Converts the absolute or relative data item name \a    abs_or_rel_name to an absolute name, interpreted within the    context (path) of the data item named \a context (this must be an    absolute name).*/QString Q3MimeSourceFactory::makeAbsolute(const QString& abs_or_rel_name, const QString& context) const{    if (context.isNull() ||         !(context[0] == QLatin1Char('/')#ifdef Q_WS_WIN         || (context[0].isLetter() && context[1] == QLatin1Char(':'))#endif          ))        return abs_or_rel_name;    if (abs_or_rel_name.isEmpty())        return context;    QFileInfo c(context);    if (!c.isDir()) {        QFileInfo r(c.dir(true), abs_or_rel_name);        return r.absFilePath();    } else {        QDir d(context);        QFileInfo r(d, abs_or_rel_name);        return r.absFilePath();    }}/*!    \overload    A convenience function. See data(const QString& abs_name). The    file name is given in \a abs_or_rel_name and the path is in \a    context.*/const QMimeSource* Q3MimeSourceFactory::data(const QString& abs_or_rel_name, const QString& context) const{    const QMimeSource* r = data(makeAbsolute(abs_or_rel_name,context));    if (!r && !d->path.isEmpty())        r = data(abs_or_rel_name);    return r;}/*!    Sets \a text to be the data item associated with the absolute name    \a abs_name.    Equivalent to setData(abs_name, new Q3TextDrag(text)).*/void Q3MimeSourceFactory::setText(const QString& abs_name, const QString& text){    setData(abs_name, new Q3TextDrag(text));}/*!    Sets \a image to be the data item associated with the absolute    name \a abs_name.    Equivalent to setData(abs_name, new Q3ImageDrag(image)).*/void Q3MimeSourceFactory::setImage(const QString& abs_name, const QImage& image){    setData(abs_name, new Q3ImageDrag(image));}/*!    Sets \a pixmap to be the data item associated with the absolute    name \a abs_name.*/void Q3MimeSourceFactory::setPixmap(const QString& abs_name, const QPixmap& pixmap){    setData(abs_name, new Q3ImageDrag(pixmap.convertToImage()));}/*!  Sets \a data to be the data item associated with  the absolute name \a abs_name. Note that the ownership of \a data is  transferred to the factory: do not delete or access the pointer after  passing it to this function.  Passing 0 for data removes previously stored data.*/void Q3MimeSourceFactory::setData(const QString& abs_name, QMimeSource* data){    if (d->stored.contains(abs_name))        delete d->stored[abs_name];    d->stored.insert(abs_name,data);}/*!    Returns the application-wide default mime source factory. This    factory is used by rich text rendering classes such as    QSimpleRichText, QWhatsThis and QMessageBox to resolve named    references within rich text documents. It serves also as the    initial factory for the more complex render widgets, QTextEdit and    QTextBrowser.    \sa setDefaultFactory()*/Q3MimeSourceFactory* Q3MimeSourceFactory::defaultFactory(){    if (!defaultfactory)    {        defaultfactory = new Q3MimeSourceFactory();        qmime_cleanup_factory.set(&defaultfactory);        QTextImageHandler::externalLoader = richTextImageLoader;    }    return defaultfactory;}/*!    Sets the default \a factory, destroying any previously set mime    source provider. The ownership of the factory is transferred to    Qt.    \sa defaultFactory()*/void Q3MimeSourceFactory::setDefaultFactory(Q3MimeSourceFactory* factory){    if (!defaultfactory)        qmime_cleanup_factory.set(&defaultfactory);    else if (defaultfactory != factory)        delete defaultfactory;    defaultfactory = factory;}/*!    Sets the defaultFactory() to 0 and returns the previous one.*/Q3MimeSourceFactory* Q3MimeSourceFactory::takeDefaultFactory(){    Q3MimeSourceFactory *f = defaultfactory;    defaultfactory = 0;    return f;}/*!    Adds the Q3MimeSourceFactory \a f to the list of available    mimesource factories. If the defaultFactory() can't resolve a    data() it iterates over the list of installed mimesource factories    until the data can be resolved.    \sa removeFactory()*/void Q3MimeSourceFactory::addFactory(Q3MimeSourceFactory *f){    Q3MimeSourceFactory::defaultFactory()->d->factories.append(f);}/*!    Removes the mimesource factory \a f from the list of available    mimesource factories.    \sa addFactory()*/void Q3MimeSourceFactory::removeFactory(Q3MimeSourceFactory *f){    Q3MimeSourceFactory::defaultFactory()->d->factories.removeAll(f);}QPixmap qPixmapFromMimeSource(const QString &abs_name){    const QMimeSource *m = Q3MimeSourceFactory::defaultFactory()->data(abs_name);    if (!m) {        if (QFile::exists(abs_name))            return QPixmap(abs_name);        if (!abs_name.isEmpty())            qWarning("QPixmap::fromMimeSource: Cannot find pixmap \"%s\" in the mime source factory",                      abs_name.latin1());        return QPixmap();    }    QPixmap pix;    Q3ImageDrag::decode(m, pix);    return pix;}QImage qImageFromMimeSource(const QString &abs_name){    const QMimeSource *m = Q3MimeSourceFactory::defaultFactory()->data(abs_name);    if (!m) {        qWarning("QImage::fromMimeSource: Cannot find image \"%s\" in the mime source factory", abs_name.latin1());        return QImage();    }    QImage img;    Q3ImageDrag::decode(m, img);    return img;}#endif // QT_NO_MIME

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -