Exemplo n.º 1
0
/*!
    Copies the contents of \a from to this QContent.

    Returns true is successful, otherwise false.
 */
bool QContent::copyContent(const QContent &from)
{
    QFile source( from.fileName() );

    if( source.copy( fileName() ) )
        return true;

    return false;
}
Exemplo n.º 2
0
ImageIO::Status ImageIO::load( const QContent& lnk, int levels )
{
    static const int maxSize = 2097152;
    static const int maxArea = 1920000;
    _lnk = lnk;

    QImageReader reader( lnk.fileName() );

    _format = reader.format();

    QImage image;

    if( reader.supportsOption( QImageIOHandler::Size ) )
    {
        QSize size = reader.size();

        if( size.width() * size.height() > maxArea )
        {
            _status = SIZE_ERROR;

            return _status;
        }
    }
    else if( QFileInfo( lnk.file() ).size() > maxSize )
    {
        _status = SIZE_ERROR;

        return _status;
    }

    if( reader.read( &image ) )
        _status = load( image, levels );
    else
        _status = LOAD_ERROR;

    return _status;
}
Exemplo n.º 3
0
/*!
    Constructs a new WheelBrowserScreen instance with the given \a parent and
    widget \a flags.
*/
WheelBrowserScreen::WheelBrowserScreen(QWidget *parent, Qt::WFlags flags)
: QAbstractBrowserScreen(parent, flags),
  m_fillAlpha(0), m_hiding(false), m_wheel(0), m_fillTimeline(0)
{
    QPalette pal = palette();
    pal.setColor(QPalette::Window, QColor(100, 100, 100, 0));
    setPalette(pal);

    QVBoxLayout * layout = new QVBoxLayout(this);
    setLayout(layout);

    m_wheel = new QPixmapWheel(this);
    QFont f = font();
    f.setBold(true);
    m_wheel->setFont(f);
    m_wheel->setMaximumVisibleIcons(7);

    QObject::connect(m_wheel, SIGNAL(moveToCompleted()),
                     this, SLOT(moveToCompleted()));
    QObject::connect(m_wheel, SIGNAL(itemSelected(QString)),
                     this, SLOT(clicked(QString)));
    setFocusProxy(m_wheel);

    layout->addStretch(1);
    layout->addWidget(m_wheel, 5);
    layout->addStretch(1);

    m_data = new QPixmapWheelData;

    // Load apps
    QSettings cfg(Qtopia::defaultButtonsFile(), QSettings::IniFormat);
    cfg.beginGroup("Menu"); // No tr
    const int menur = cfg.value("Rows",3).toInt();
    const int menuc = cfg.value("Columns",3).toInt();
    QString menuKeyMap = cfg.value("Map","123456789").toString();

    for (int i = 0; i < menur*menuc; i++) {
        QChar key = menuKeyMap[i];
        QStringList entries = cfg.value(QString(key)).toStringList();

        if(!entries.isEmpty()) {
            QContent *app = readLauncherMenuItem(entries.first());

            if(app) {
                QString file = app->fileName();
                QString name = app->name();
                if(app->type().startsWith("Folder/") )
                    file = app->type();
                QPixmap pix = app->icon().pixmap(QSize(48, 48));
                if(file.isEmpty())
                    file = app->type();

                if(!file.isEmpty() && !name.isEmpty() && !pix.isNull()) {
                    m_data->appendItem(file, pix, name);
                }
                delete app;
            }
        }
    }

    m_fillTimeline = new QTimeLine(2000, this);
    QObject::connect(m_fillTimeline, SIGNAL(valueChanged(qreal)),
                     this, SLOT(timelineStep(qreal)));
}
Exemplo n.º 4
0
/*!
    Loads a thumbnail representation of \a content.  The thumbnail will be scaled to \a size
    according to the given aspect ratio mode.
*/
QImage QContentStore::thumbnail(const QContent &content, const QSize &size, Qt::AspectRatioMode mode)
{
    QImage thumbnail;

    QString thumbPath = thumbnailPath(content.fileName());

    QFileInfo thumbInfo(thumbPath);

    if (thumbInfo.exists()) {
        if (thumbInfo.lastModified() > content.lastUpdated())
            thumbnail = readThumbnail(thumbPath, size, mode);
    } else {
        thumbnail = QContentFactory::thumbnail(content, size, mode);
    }

    if (thumbnail.isNull()) {
        if (QIODevice *device = content.open()) {
            QImageReader reader(device);

            if (reader.canRead()) {
                QSize scaledSize = reader.size();

                reader.setQuality(25);
                if (scaledSize.width() > 128 || scaledSize.height() > 128) {
                    scaledSize.scale(QSize(128, 128), Qt::KeepAspectRatio);

                    reader.setQuality( 49 ); // Otherwise Qt smooth scales
                    reader.setScaledSize(scaledSize);
                    reader.read(&thumbnail);

                    if (!thumbnail.isNull()) {
                        QImageWriter writer(thumbPath, QByteArray::fromRawData("PNG", 3));
                        writer.setQuality(25);
                        writer.write(thumbnail);

                        if (size.isValid())
                            thumbnail = thumbnail.scaled(size, mode);
                    }
                } else {
                    if (size.isValid()) {
                        scaledSize.scale(size, mode);
                        reader.setQuality( 49 ); // Otherwise Qt smooth scales
                        reader.setScaledSize(scaledSize);
                    }
                    reader.read(&thumbnail);
                }
            }

            delete device;
        }
    }

    if (thumbnail.isNull() && content.type().startsWith(m_audioPrefix)) {
        QDir dir = QFileInfo(content.fileName()).absoluteDir();

        foreach (const QString &fileName, m_folderThumbnails) {
            if (dir.exists(fileName)) {
                thumbnail = readThumbnail(dir.absoluteFilePath(fileName), size, mode);
                break;
            }
        }
    }
Exemplo n.º 5
0
void MainWindow::documentSelected(QContent const& content)
{
    d->mediaObject->setCurrentSource(content.fileName());
    d->mediaObject->play();
}