Home · All Classes · Main Classes · Deprecated
Public Slots | Public Member Functions | Properties

MImageWidget Class Reference

MImageWidget is a simple widget to show image. More...

Inheritance diagram for MImageWidget:
Inheritance graph
[legend]
Collaboration diagram for MImageWidget:
Collaboration graph
[legend]

List of all members.

Public Slots

void setImage (const QString &id)
void setImage (const QImage &image)
void setPixmap (const QPixmap &pixmap)

Public Member Functions

 MImageWidget (QGraphicsItem *parent=0)
 MImageWidget (const QString &id, QGraphicsItem *parent=0)
 MImageWidget (const QImage *image, QGraphicsItem *parent=0)
 MImageWidget (const QPixmap *pixmap, QGraphicsItem *parent=0)
 MImageWidget (const MImageWidget &)
MImageWidgetoperator= (const MImageWidget &)
virtual ~MImageWidget ()
void setImage (const QString &id, const QSize &size)
QString image () const
QString imageId () const
QSize imageSize () const
const QPixmappixmap () const
void setZoomFactor (qreal factor)
void setZoomFactor (qreal fx, qreal fy)
void zoomFactor (qreal *fx, qreal *fy) const
void zoomIn ()
void zoomOut ()
void setAspectRatioMode (Qt::AspectRatioMode mode)
Qt::AspectRatioMode aspectRatioMode () const
void setCrop (const QRectF &rect)
QRectF crop () const

Properties

QRectF crop
Qt::AspectRatioMode aspectRatioMode
QString image

Detailed Description

MImageWidget is a simple widget to show image.

Overview

Image allows the placement of images onto the UI. Images are generally non-interactive elements. Various single and multiple touch interactions can be added to an Image component if so wanted.

Image supports scale, crop, zoom operations.

Usage guidelines

Images can be used by themselves to decorate the UI (background images, frames etc.) and also combined as part of other components (grids, lists, buttons etc.).

If the Image has interactive elements, the touch area size of the interactive element needs to be specified. The area can occupy the entire Image, and/or it can also fall outside the Image: for instance in the case of an Image with a label, they are combined to form one interactive area. An Image can be on top or below of other images and other components (determined by the z-order).

MImageWidget provides sizeHint(), default size will be the size which defined in CSS. If not defined in CSS, will be the size of image which added into MImage.

MImageWidget can show border around the image, you can custom border in CSS. The border will work as a decoration and hint. Any cropped side will have no border.

Example codes

MImageWidget can show image from theme:

        MImageWidget* image = new MImageWidget("icon");

Also can get image with request size from theme:

        MImageWidget* image = new MImageWidget();
        image->setImage("icon", QSize(64,64));

Or set image directly

        QImage img(path);
        MImageWidget* image = new MImageWidget(&img);
Attention:
By default image will be shown full of the widget in Qt::KeepAspectRatio mode. You can change the mode use setAspectRatioMode(Qt::IgnoreAspectRatio)
        QImage img(path);
        MImageWidget* image = new MImageWidget(&img);
        image->setAspectRatioMode(Qt::IgnoreAspectRatio);
See also:
MImageWidgetModel MImageWidgetStyle

Definition at line 88 of file corelib/widgets/mimagewidget.h.


Constructor & Destructor Documentation

MImageWidget::MImageWidget ( QGraphicsItem parent = 0  ) 

Constructs a image with a parent.

Parameters:
parent Parent object.

Definition at line 103 of file mimagewidget.cpp.

                                                :
    MWidgetController(new MImageWidgetPrivate(), new MImageWidgetModel(), parent)
{
}

MImageWidget::MImageWidget ( const QString id,
QGraphicsItem parent = 0 
) [explicit]

Definition at line 108 of file mimagewidget.cpp.

                                                                   :
    MWidgetController(new MImageWidgetPrivate(), new MImageWidgetModel(), parent)
{
    setImage(id);
}

Here is the call graph for this function:

MImageWidget::MImageWidget ( const QImage image,
QGraphicsItem parent = 0 
) [explicit]

Definition at line 114 of file mimagewidget.cpp.

                                                                     :
    MWidgetController(new MImageWidgetPrivate(), new MImageWidgetModel(), parent)
{
    Q_D(MImageWidget);
    d->image = *image;
}

MImageWidget::MImageWidget ( const QPixmap pixmap,
QGraphicsItem parent = 0 
) [explicit]

Definition at line 121 of file mimagewidget.cpp.

                                                                       :
    MWidgetController(new MImageWidgetPrivate(), new MImageWidgetModel(), parent)
{
    Q_D(MImageWidget);
    d->pixmap = new QPixmap(*pixmap);
}

MImageWidget::MImageWidget ( const MImageWidget other  ) 

Copy constructor.

Definition at line 128 of file mimagewidget.cpp.

                                                    :
    MWidgetController(new MImageWidgetPrivate(), new MImageWidgetModel(), 0)
{
    *this = other;
}

MImageWidget::~MImageWidget (  )  [virtual]

Destroys the image.

Definition at line 161 of file mimagewidget.cpp.

{
}


Member Function Documentation

Qt::AspectRatioMode MImageWidget::aspectRatioMode (  )  const

Get image aspect ratio mode.

QRectF MImageWidget::crop (  )  const

Get the crop rectangle.

Deprecated:
There is no replacing functionality
QString MImageWidget::image (  )  const

Get the image id.

Deprecated:
Use the MImageWidget::imageId();
QString MImageWidget::imageId (  )  const

Get the image id.

Definition at line 183 of file mimagewidget.cpp.

{
    return model()->imageId();
}

Here is the call graph for this function:

QSize MImageWidget::imageSize (  )  const

Get the origin size of the image.

Definition at line 188 of file mimagewidget.cpp.

{
    Q_D(const MImageWidget);
    if (d->pixmap)
        return d->pixmap->size();
    else
        return d->image.size();
}

MImageWidget & MImageWidget::operator= ( const MImageWidget other  ) 

Assigns other to this MImageWidget and returns a reference to this MImageWidget.

Definition at line 134 of file mimagewidget.cpp.

{
    Q_D(MImageWidget);

    d->cleanUp();

    if (other.d_func()->ownPixmap) {
        if (other.d_func()->pixmap)
            d->pixmap = new QPixmap(*(other.d_func()->pixmap));
    } else
        setImage(other.model()->imageId(), other.model()->imageSize());

    d->ownPixmap = other.d_func()->ownPixmap;

    d->image = other.d_func()->image;

    qreal fx(0), fy(0);

    other.zoomFactor(&fx, &fy);
    setZoomFactor(fx, fy);

    model()->setCrop(other.crop());
    model()->setAspectRatioMode(other.aspectRatioMode());

    return *this;
}

Here is the call graph for this function:

const QPixmap * MImageWidget::pixmap (  )  const

Get the pointer of pixmap.

Deprecated:

Definition at line 197 of file mimagewidget.cpp.

{
    Q_D(const MImageWidget);
    if (d->pixmap)
        return d->pixmap;
    else {
        d->imagePlaceHolder = QPixmap::fromImage(d->image);
        return &d->imagePlaceHolder;
    }
}

Here is the call graph for this function:

void MImageWidget::setAspectRatioMode ( Qt::AspectRatioMode  mode  ) 

Set image zoom AspectRatioMode.

Parameters:
mode defines what happens to the aspect ratio when zoom image.

Definition at line 277 of file mimagewidget.cpp.

{
    if (model()->aspectRatioMode() == mode)
        return;
    model()->setAspectRatioMode(mode);
}

Here is the call graph for this function:

void MImageWidget::setCrop ( const QRectF rect  ) 

Set image cropped to this recangle.

Parameters:
size crop section rectangle
Deprecated:
There is no replacing functionality

Definition at line 289 of file mimagewidget.cpp.

{
    Q_D(MImageWidget);
    if (d->pixmap == 0 && d->image.isNull())
        return;

    if (!rect.isValid())
        return;

    model()->setCrop(rect);
}

Here is the call graph for this function:

void MImageWidget::setImage ( const QString id,
const QSize size 
)

Sets the logical ID associated with this image to id.

The graphics specified by the ID will be exactly of the specified size, and will stretch to fill the image widget.

Definition at line 165 of file mimagewidget.cpp.

{
    model()->beginTransaction();
    model()->setImageId(id);
    model()->setImageSize(s);
    model()->commitTransaction();

    model()->setCrop(QRect());

    updateGeometry();
    update();
}

Here is the call graph for this function:

void MImageWidget::setImage ( const QString id  )  [slot]

Sets the logical ID associated with this image to id.

Whatever size the graphics happens to be in the theme will be used. The graphics is then scaled to fit the image widget. Unless you know that the themed graphic is exactly of the right size, you must use the setImage(const QString &id, const QSize &size) method instead.

Definition at line 306 of file mimagewidget.cpp.

{
    setImage(id, QSize());
}

Here is the call graph for this function:

void MImageWidget::setImage ( const QImage image  )  [slot]

Set a QImage into MImage.

Definition at line 311 of file mimagewidget.cpp.

{
    Q_D(MImageWidget);
    setImage(QString(), QSize());

    d->setImage(image);

    model()->setCrop(QRect());

    updateGeometry();
    update();
}

Here is the call graph for this function:

void MImageWidget::setPixmap ( const QPixmap pixmap  )  [slot]

Set a QPixmap into MImage.

Definition at line 324 of file mimagewidget.cpp.

{
    Q_D(MImageWidget);
    setImage(QString(), QSize());

    QPixmap* newPixmap = new QPixmap(pixmap);
    d->setPixmap(newPixmap, true);

    model()->setCrop(QRect());

    updateGeometry();
    update();
}

Here is the call graph for this function:

void MImageWidget::setZoomFactor ( qreal  fx,
qreal  fy 
)

Set image width and height zoom factor.

Parameters:
fx image width zoom factor
fy image height zoom factor If fx not equals fy, will set zoom ratio mode to Qt::IgnoreAspectRatio automatic

Definition at line 216 of file mimagewidget.cpp.

{
    if (fx >= 0.0)
        model()->setZoomFactorX(fx);

    if (fy >= 0.0)
        model()->setZoomFactorY(fy);

    // If zoomFactorX not equals zoomFactorY, set mode to Qt::IgnoreAspectRatio automatic
    if (fx != fy)
        model()->setAspectRatioMode(Qt::IgnoreAspectRatio);
}

Here is the call graph for this function:

void MImageWidget::setZoomFactor ( qreal  factor  ) 

Set image two aspect ratio factors to one value.

Parameters:
factor image zoom factor

Definition at line 208 of file mimagewidget.cpp.

{
    if (factor < 0.0) return;

    model()->setZoomFactorX(factor);
    model()->setZoomFactorY(factor);
}

Here is the call graph for this function:

void MImageWidget::zoomFactor ( qreal *  fx,
qreal *  fy 
) const

This function get image zoom factor The parameters point to values stored in float.

If any of the pointers is 0, that value will not be updated.

Deprecated:
There is no replacing functionality

Definition at line 229 of file mimagewidget.cpp.

{
    Q_D(const MImageWidget);

    if(fx)
        *fx = model()->zoomFactorX();
    if(fy)
        *fy = model()->zoomFactorY();

    if ((fx && *fx == 0) || (fy && *fy == 0)) {
        // If the zoom factor is 0, calculate it with imageSize, targetSize and widgetSize
        QSizeF buffer;
        QSizeF imageSize = d->imageDataSize(model()->crop());

        if (imageSize.isEmpty())
            return;

        buffer = imageSize;

        QSizeF marginSize = QSizeF(style()->marginLeft() + style()->marginRight(), style()->marginTop() + style()->marginBottom());
        QSizeF widgetSize = size() - marginSize;

        buffer.scale(widgetSize, model()->aspectRatioMode());

        if (fx && *fx == 0)
            *fx = buffer.width() / imageSize.width();

        if (fy && *fy == 0)
            *fy = buffer.height() / imageSize.height();
    }
}

Here is the call graph for this function:

void MImageWidget::zoomIn (  ) 

Zoom in image.

Deprecated:
There is no replacing functionality

Definition at line 261 of file mimagewidget.cpp.

{
    qreal fx(0), fy(0);

    zoomFactor(&fx, &fy);
    setZoomFactor(fx * 2.0, fy * 2.0);
}

Here is the call graph for this function:

void MImageWidget::zoomOut (  ) 

Zoom out image.

Deprecated:
There is no replacing functionality

Definition at line 269 of file mimagewidget.cpp.

{
    qreal fx(0), fy(0);

    zoomFactor(&fx, &fy);
    setZoomFactor(fx / 2.0, fy / 2.0);
}

Here is the call graph for this function:


Property Documentation

Qt::AspectRatioMode MImageWidget::aspectRatioMode [read, write]

Definition at line 103 of file corelib/widgets/mimagewidget.h.

MImageWidget::crop [read, write]

See MImageWidgetModel::crop.

Definition at line 97 of file corelib/widgets/mimagewidget.h.

QString MImageWidget::image [read, write]

Definition at line 108 of file corelib/widgets/mimagewidget.h.


Copyright © 2010 Nokia Corporation Generated on Thu Nov 4 2010 18:14:25 (PDT)
Doxygen 1.7.1
MeeGo Touch