--- a/src/hbcore/gui/hbbackgrounditem.cpp Thu Jul 15 14:03:49 2010 +0100
+++ b/src/hbcore/gui/hbbackgrounditem.cpp Thu Jul 22 16:36:53 2010 +0100
@@ -23,39 +23,31 @@
**
****************************************************************************/
-#include <QGraphicsSceneResizeEvent>
-#include <QPainter>
-#include <QObject>
-#include <QDebug>
-
#include "hbbackgrounditem_p.h"
#include "hbwidget_p.h"
#include "hbinstance.h"
#include "hbdeviceprofile.h"
#include "hbevent.h"
#include "hbmainwindow_p.h"
-
-#ifndef HB_NVG_CS_ICON
-#define ENABLE_FAST_PAINT_
-#endif
+#include <QGraphicsSceneResizeEvent>
+#include <QPainter>
+#include <QObject>
+#include <QDebug>
/*
\class HbBackgroundItem
- \brief HbBackgroundItem draws background
+ \brief Draws the background.
\internal
*/
HbBackgroundItem::HbBackgroundItem(HbMainWindow *mainWindow, QGraphicsWidget *parent) :
- HbWidget(parent),
- mMainWindow(mainWindow)
+ HbWidget(parent),
+ mMainWindow(mainWindow),
+ mImageMode(Hb::ScaleBackgroundToFit)
{
-#ifdef ENABLE_FAST_PAINT_
- setAttribute(Qt::WA_NoSystemBackground); // Disable clearing of background
-#endif
- setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Ignored );
-
+ setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
mPrtImageName = defaultImageName(Qt::Vertical);
mLscImageName = defaultImageName(Qt::Horizontal);
updateBackgroundImage();
@@ -92,8 +84,21 @@
QString HbBackgroundItem::defaultImageName(Qt::Orientation orientation) const
{
return orientation == Qt::Vertical
- ? QLatin1String("qtg_graf_screen_bg_prt")
- : QLatin1String("qtg_graf_screen_bg_lsc");
+ ? QLatin1String("qtg_graf_screen_bg_prt")
+ : QLatin1String("qtg_graf_screen_bg_lsc");
+}
+
+void HbBackgroundItem::setImageMode(Hb::BackgroundImageMode mode)
+{
+ if (mode != mImageMode) {
+ mImageMode = mode;
+ updateBackgroundImage();
+ }
+}
+
+Hb::BackgroundImageMode HbBackgroundItem::imageMode() const
+{
+ return mImageMode;
}
void HbBackgroundItem::updateBackgroundImage()
@@ -103,12 +108,20 @@
QSizeF size(HbDeviceProfile::profile(mMainWindow).logicalSize());
mBoundingRect.setWidth(size.width());
mBoundingRect.setHeight(size.height());
- mBackground.setSize(size);
if (mMainWindow->orientation() == Qt::Vertical) {
mBackground.setIconName(mPrtImageName);
} else {
mBackground.setIconName(mLscImageName);
}
+ if (mImageMode == Hb::KeepOriginalBackgroundSize
+ || mImageMode == Hb::KeepOriginalBackgroundSizeIfSmaller) {
+ QSizeF imageSize = mBackground.defaultSize();
+ if (mImageMode == Hb::KeepOriginalBackgroundSize
+ || (imageSize.width() <= size.width() && imageSize.height() <= size.height())) {
+ size = imageSize;
+ }
+ }
+ mBackground.setSize(size);
}
}
@@ -147,17 +160,28 @@
void HbBackgroundItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
- Q_UNUSED(widget)
- Q_UNUSED(option)
+ Q_UNUSED(widget);
+ Q_UNUSED(option);
+
+ if (mImageMode == Hb::DoNotDrawBackground) {
+ return;
+ }
+
+ // Note: No optimizations to disable alpha blending etc. The background
+ // image may be anything, it can have transparent parts too.
-#ifdef ENABLE_FAST_PAINT_
- QPainter::CompositionMode compositionMode = painter->compositionMode();
- painter->setCompositionMode( QPainter::CompositionMode_Source ); // Do not use alpha blending..
-#endif
+ Qt::AspectRatioMode aspRatMode;
+ switch (mImageMode) {
+ case Hb::ScaleBackgroundToFitWithoutExpanding:
+ aspRatMode = Qt::KeepAspectRatio;
+ break;
+ case Hb::StretchBackgroundToFit:
+ aspRatMode = Qt::IgnoreAspectRatio;
+ break;
+ default:
+ aspRatMode = Qt::KeepAspectRatioByExpanding;
+ break;
+ }
- mBackground.paint(painter, mBoundingRect, Qt::KeepAspectRatioByExpanding);
-
-#ifdef ENABLE_FAST_PAINT_
- painter->setCompositionMode( compositionMode ); // restore old composition mode
-#endif
+ mBackground.paint(painter, mBoundingRect, aspRatMode, Qt::AlignCenter);
}