28 |
28 |
29 #include <QGraphicsView> |
29 #include <QGraphicsView> |
30 #include <QGraphicsWidget> |
30 #include <QGraphicsWidget> |
31 #include <QGraphicsItem> |
31 #include <QGraphicsItem> |
32 #include <QGraphicsScene> |
32 #include <QGraphicsScene> |
33 |
33 #include <QApplication> |
34 #include "hbaction.h" |
34 #include "hbaction.h" |
35 #include "hbbackgrounditem_p.h" |
35 #include "hbbackgrounditem_p.h" |
|
36 #include "hbscreenshotitem_p.h" |
36 #include "hbdeviceprofile_p.h" |
37 #include "hbdeviceprofile_p.h" |
37 #include "hbindicatorgroup_p.h" |
38 #include "hbindicatorgroup_p.h" |
38 #include "hbinstance.h" |
39 #include "hbinstance.h" |
39 #include "hbinstance_p.h" |
40 #include "hbinstance_p.h" |
40 #include "hbgraphicsscene.h" |
41 #include "hbgraphicsscene.h" |
61 #include "hbmainwindoworientation_p.h" |
62 #include "hbmainwindoworientation_p.h" |
62 #include "hbfeaturemanager_r.h" |
63 #include "hbfeaturemanager_r.h" |
63 #include "hboogmwatcher_p.h" |
64 #include "hboogmwatcher_p.h" |
64 #include "hbwindowobscured_p.h" |
65 #include "hbwindowobscured_p.h" |
65 #include "hbsleepmodelistener_p.h" |
66 #include "hbsleepmodelistener_p.h" |
|
67 #include "hbforegroundwatcher_p.h" |
66 |
68 |
67 #ifdef Q_OS_SYMBIAN |
69 #ifdef Q_OS_SYMBIAN |
68 #include <coecntrl.h> |
70 #include <coecntrl.h> |
69 #include <w32std.h> |
71 #include <w32std.h> |
70 #include "hbnativewindow_sym_p.h" |
72 #include "hbnativewindow_sym_p.h" |
285 Q_D(HbMainWindow); |
287 Q_D(HbMainWindow); |
286 d->q_ptr = this; |
288 d->q_ptr = this; |
287 |
289 |
288 // No need for any default (e.g. blank white) background for this window. |
290 // No need for any default (e.g. blank white) background for this window. |
289 setAttribute(Qt::WA_NoSystemBackground); |
291 setAttribute(Qt::WA_NoSystemBackground); |
|
292 viewport()->setAttribute(Qt::WA_NoSystemBackground); |
290 setOptimizationFlag(QGraphicsView::DontSavePainterState); |
293 setOptimizationFlag(QGraphicsView::DontSavePainterState); |
291 |
294 |
292 // Continue with basic initialization. Note: Prefer doing everything that is |
295 // Continue with basic initialization. Note: Prefer doing everything that is |
293 // not absolutely compulsory in _q_delayedConstruction instead. |
296 // not absolutely compulsory in _q_delayedConstruction instead. |
294 |
297 |
324 } else { |
327 } else { |
325 d->mOrientation = d->mDefaultOrientation; |
328 d->mOrientation = d->mDefaultOrientation; |
326 d->mAutomaticOrientationSwitch = false; |
329 d->mAutomaticOrientationSwitch = false; |
327 } |
330 } |
328 |
331 |
329 #if defined(Q_WS_S60) || defined(HB_Q_WS_MAEMO) |
332 #if defined(Q_OS_SYMBIAN) || defined(HB_Q_WS_MAEMO) |
330 setWindowState(Qt::WindowFullScreen); |
333 setWindowState(Qt::WindowFullScreen); |
331 #endif//Q_WS_S60 |
334 #endif |
332 |
335 |
333 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
336 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
334 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
337 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
335 setFrameStyle(QFrame::NoFrame); |
338 setFrameStyle(QFrame::NoFrame); |
336 |
339 |
353 d->addBackgroundItem(); |
356 d->addBackgroundItem(); |
354 } |
357 } |
355 |
358 |
356 // add clipping item |
359 // add clipping item |
357 d->mClippingItem = new HbScreen; |
360 d->mClippingItem = new HbScreen; |
|
361 //makes sure clipiingItem layout is activated before any of its childitems. |
|
362 QApplication::postEvent(d->mClippingItem, new QEvent(QEvent::LayoutRequest)); |
358 d->mClippingItem->setParentItem(d->mRootItem); |
363 d->mClippingItem->setParentItem(d->mRootItem); |
359 d->mClippingItem->setZValue(HbPrivate::ContentZValue); |
364 d->mClippingItem->setZValue(HbPrivate::ContentZValue); |
360 |
365 |
361 // create content (stacked) widget |
366 // create content (stacked) widget |
362 d->mViewStackWidget = new HbContentWidget(this, d->mClippingItem); |
367 d->mViewStackWidget = new HbContentWidget(this, d->mClippingItem); |
395 // are routed to it properly). |
400 // are routed to it properly). |
396 HbOogmWatcher::instance(); |
401 HbOogmWatcher::instance(); |
397 |
402 |
398 // Make sure the sleep mode listener instance is created. |
403 // Make sure the sleep mode listener instance is created. |
399 HbSleepModeListener::instance(); |
404 HbSleepModeListener::instance(); |
|
405 |
|
406 // Have also the foregroundwatcher up and running. |
|
407 HbForegroundWatcher::instance(); |
400 |
408 |
401 HbWindowObscured::installWindowEventFilter(); |
409 HbWindowObscured::installWindowEventFilter(); |
402 |
410 |
403 #ifdef HB_GESTURE_FW |
411 #ifdef HB_GESTURE_FW |
404 // @todo remove after view auto-subscribes to gestures |
412 // @todo remove after view auto-subscribes to gestures |
629 Q_D(HbMainWindow); |
637 Q_D(HbMainWindow); |
630 HbView *oldView = currentView(); |
638 HbView *oldView = currentView(); |
631 // Switching to null view or to the one that is current will do nothing. |
639 // Switching to null view or to the one that is current will do nothing. |
632 if (view && oldView != view) { |
640 if (view && oldView != view) { |
633 emit aboutToChangeView(oldView, view); |
641 emit aboutToChangeView(oldView, view); |
|
642 if (isObscured()) { |
|
643 animate = false; |
|
644 } |
634 if (oldView && animate) { |
645 if (oldView && animate) { |
635 if (flags & Hb::ViewSwitchFullScreen) { |
646 if (flags & Hb::ViewSwitchFullScreen) { |
636 flags |= Hb::ViewSwitchSequential; |
647 flags |= Hb::ViewSwitchSequential; |
637 } |
648 } |
638 if (flags & Hb::ViewSwitchUseBackAnim) { |
649 if (flags & Hb::ViewSwitchUseBackAnim) { |
936 if (currentView()) { |
947 if (currentView()) { |
937 action = currentView()->navigationAction(); |
948 action = currentView()->navigationAction(); |
938 } |
949 } |
939 event->accept(); |
950 event->accept(); |
940 break; |
951 break; |
|
952 |
|
953 #ifdef __WINSCW__ |
|
954 // Support for testing orientation change on the winscw emulator: When enabled, |
|
955 // pressing '9' will toggle (and force) the orientation. |
|
956 case Qt::Key_9: |
|
957 if (QFile::exists("c:/resource/hb_ori_simu")) { |
|
958 if (orientation() == Qt::Horizontal) { |
|
959 setOrientation(Qt::Vertical); |
|
960 } else { |
|
961 setOrientation(Qt::Horizontal); |
|
962 } |
|
963 } |
|
964 QGraphicsView::keyPressEvent(event); |
|
965 break; |
|
966 #endif |
941 |
967 |
942 default: |
968 default: |
943 QGraphicsView::keyPressEvent(event); |
969 QGraphicsView::keyPressEvent(event); |
944 break; |
970 break; |
945 } |
971 } |
979 QSize newSize(event->size()); |
1005 QSize newSize(event->size()); |
980 setSceneRect(0, 0, newSize.width(), newSize.height()); |
1006 setSceneRect(0, 0, newSize.width(), newSize.height()); |
981 d->mClippingItem->resize(newSize); |
1007 d->mClippingItem->resize(newSize); |
982 if (d->mBgItem) { |
1008 if (d->mBgItem) { |
983 d->mBgItem->resize(newSize); |
1009 d->mBgItem->resize(newSize); |
|
1010 } |
|
1011 if (d->mScreenshotItem) { |
|
1012 d->mScreenshotItem->resize(newSize); |
984 } |
1013 } |
985 } |
1014 } |
986 } |
1015 } |
987 |
1016 |
988 /*! |
1017 /*! |
1078 { |
1107 { |
1079 #ifdef Q_OS_SYMBIAN |
1108 #ifdef Q_OS_SYMBIAN |
1080 // Enable surface transparency if QWidget did not do it already. This is a |
1109 // Enable surface transparency if QWidget did not do it already. This is a |
1081 // workaround for having non-transparent surfaces filled automatically with |
1110 // workaround for having non-transparent surfaces filled automatically with |
1082 // black color. The showEvent is a suitable place because the native control |
1111 // black color. The showEvent is a suitable place because the native control |
1083 // is already created at this point, but it is not too late either. |
1112 // is already created at this point, but it is not too late either. Note |
|
1113 // that while this is meant to be a workaround, the system transition |
|
1114 // effects may actually rely on (and require) this behavior. |
1084 if (!testAttribute(Qt::WA_TranslucentBackground)) { |
1115 if (!testAttribute(Qt::WA_TranslucentBackground)) { |
|
1116 // The Qt::WA_TranslucentBackground attribute cannot be used here |
|
1117 // because that can only be enabled, disabling does not seem to be |
|
1118 // supported. |
1085 RWindow *const window = static_cast<RWindow *>(effectiveWinId()->DrawableWindow()); |
1119 RWindow *const window = static_cast<RWindow *>(effectiveWinId()->DrawableWindow()); |
1086 window->SetSurfaceTransparency(true); |
1120 window->SetSurfaceTransparency(true); |
1087 } |
1121 } |
1088 #endif |
1122 #endif |
1089 |
1123 |
1129 |
1163 |
1130 return d->mObscuredState; |
1164 return d->mObscuredState; |
1131 } |
1165 } |
1132 |
1166 |
1133 /* |
1167 /* |
1134 // reimplemented from QWidget |
1168 \reimp |
1135 */ |
1169 */ |
1136 bool HbMainWindow::event(QEvent *event) |
1170 bool HbMainWindow::event(QEvent *event) |
1137 { |
1171 { |
1138 Q_D(HbMainWindow); |
1172 Q_D(HbMainWindow); |
1139 if (event->type() == HbEvent::WindowObscuredChanged) { |
1173 if (event->type() == HbEvent::WindowObscuredChanged) { |
1140 HbWindowObscuredChangedEvent *wosEvent = static_cast<HbWindowObscuredChangedEvent *>(event); |
1174 HbWindowObscuredChangedEvent *wosEvent = static_cast<HbWindowObscuredChangedEvent *>(event); |
1141 d->setObscuredState(wosEvent->obscuredState()); |
1175 d->setObscuredState(wosEvent->obscuredState()); |
1142 } |
1176 } |
1143 return QGraphicsView::event(event); |
1177 return QGraphicsView::event(event); |
|
1178 } |
|
1179 |
|
1180 /* |
|
1181 \reimp |
|
1182 */ |
|
1183 void HbMainWindow::drawBackground(QPainter *painter, const QRectF &rect) |
|
1184 { |
|
1185 QGraphicsView::drawBackground(painter, rect); |
|
1186 // The background item's paint() does not get called automatically so call |
|
1187 // it directly and optimize it by setting a proper clipping rectangle. |
|
1188 Q_D(HbMainWindow); |
|
1189 if (d->mBgItem) { |
|
1190 // No need to save/restore the painter state here. |
|
1191 if (d->mBgItem->imageMode() != Hb::DoNotDrawBackground && |
|
1192 (!qFuzzyCompare(rect.height(), d->mBgItem->boundingRect().height()) || |
|
1193 !qFuzzyCompare(rect.width(), d->mBgItem->boundingRect().width()))) { |
|
1194 painter->setClipRect(rect, Qt::ReplaceClip); |
|
1195 } |
|
1196 d->mBgItem->paint(painter, 0, 0); |
|
1197 } |
1144 } |
1198 } |
1145 |
1199 |
1146 HbRootItem::HbRootItem(QGraphicsItem *parent) |
1200 HbRootItem::HbRootItem(QGraphicsItem *parent) |
1147 : HbWidget(parent) |
1201 : HbWidget(parent) |
1148 { |
1202 { |