Home · All Classes · Main Classes · Deprecated
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions

MStylableWidget Class Reference

MStylableWidget is a convenience class to create simple, non-MVC widgets. More...

Inherits MWidgetController.

Inherited by MEditorToolbar, and MListIndexTooltip.

List of all members.

Public Member Functions

 MStylableWidget (QGraphicsItem *parent=0)
virtual ~MStylableWidget ()
virtual const char * styleType () const

Static Public Member Functions

static const char * staticStyleType ()

Protected Member Functions

virtual void applyStyle ()
virtual void drawBackground (QPainter *painter, const QStyleOptionGraphicsItem *option) const
virtual void drawContents (QPainter *painter, const QStyleOptionGraphicsItem *option) const
virtual void drawForeground (QPainter *painter, const QStyleOptionGraphicsItem *option) const
virtual MWidgetStyleContainercreateStyleContainer () const

Static Protected Member Functions

static void registerStylableWidgetType (const QMetaObject *metaObject, const char *widgetAssemblyName, M::AssemblyType widgetAssemblyType)

Detailed Description

MStylableWidget is a convenience class to create simple, non-MVC widgets.

MStylableWidget class implements basic functionality to support simple, non-MVC widgets which can be stylable at the same time.

In order to use it, a new class should be inherited from MStylableWidget and the M_STYLABLE_WIDGET macro should be used to define the style class for this widget.

The Q_OBJECT macro must be used too.

        class MyStylableClass : public MStylableWidget
        {
            Q_OBJECT
            M_STYLABLE_WIDGET(MyStyle)

        public:
            MyStylableClass();

        protected:
            // Method to be overridden for custom painting operations.
            virtual void drawContents(QPainter* painter, const QStyleOptionGraphicsItem* option) const;
        };

MyStyle class should follow typical style declaration:

        #include <MWidgetStyle>

        class M_CORE_EXPORT MyStyle : public MWidgetStyle
        {
            Q_OBJECT
            M_STYLE(MyStyle)

            M_STYLE_ATTRIBUTE(bool,    drawTiledHorizontal, DrawTiledHorizontal)
            M_STYLE_ATTRIBUTE(QString, imageHorizontal, ImageHorizontal)
            M_STYLE_ATTRIBUTE(QString, imageVertical, ImageVertical)
        };

        class M_CORE_EXPORT MyStyleContainer : public MWidgetStyleContainer
        {
            M_STYLE_CONTAINER(MyStyle)
        };

Please note, that paint() should NOT be overridden in order to draw the contents of the widget. Following methods should be used instead: drawBackground() drawContents() drawForeground().

When calculating the area to which the widget should be drawn, please take margins into consideration:

     QRectF paintingRect = QRectF( QPointF(style()->marginLeft(), style()->marginTop()),
                                   size() - QSizeF(style()->marginRight(),style()->marginBottom()));

Constructor & Destructor Documentation

MStylableWidget::MStylableWidget ( QGraphicsItem parent = 0  )  [explicit]

Constructor that sets up the widget.

Parameters:
parent Parent widget.
MStylableWidget::~MStylableWidget (  )  [virtual]

Destructor.


Member Function Documentation

void MStylableWidget::applyStyle (  )  [protected, virtual]

Notification for derived classes. This method gets called when a new style is applied for this widget. This happens e.g. when the object is constructed and when a new object name is given to the widget.

virtual MWidgetStyleContainer* MStylableWidget::createStyleContainer (  )  const [inline, protected, virtual]

This method should only be overridden by M_STYLABLE_WIDGET macro. It provides widget style container to be used in derived classes.

void MStylableWidget::drawBackground ( QPainter painter,
const QStyleOptionGraphicsItem option 
) const [protected, virtual]

Draws the background for this widget. This method should be overridden in order to provide background drawing functionality. The base implementation uses background-image css attribute to draw a background beneath the widget.

void MStylableWidget::drawContents ( QPainter painter,
const QStyleOptionGraphicsItem option 
) const [protected, virtual]

Draws the contents for this widget. This method should be overridden to draw contents of the widget.

void MStylableWidget::drawForeground ( QPainter painter,
const QStyleOptionGraphicsItem option 
) const [protected, virtual]

Draws the foreground for this widget. This method should be overridden to draw the foreground overlay of the widget.

void MStylableWidget::registerStylableWidgetType ( const QMetaObject metaObject,
const char *  widgetAssemblyName,
M::AssemblyType  widgetAssemblyType 
) [static, protected]

Creates a record about the stylable widget type which is then used to match the widget to the proper style. Note: This method should not be called directly, it is going to be used by M_STYLABLE_WIDGET macro definition.

static const char* MStylableWidget::staticStyleType (  )  [inline, static]
virtual const char* MStylableWidget::styleType (  )  const [inline, virtual]

Copyright © 2010 Nokia Corporation
MeeGo Touch