src/hbcore/gui/hbscreen.cpp
branchGCC_SURGE
changeset 15 f378acbc9cfb
parent 7 923ff622b8b9
child 21 4633027730f5
child 34 ed14f46c0e55
equal deleted inserted replaced
9:730c025d4b77 15:f378acbc9cfb
    30 #include "hbdockwidget.h"
    30 #include "hbdockwidget.h"
    31 #include "hbdockwidget_p.h"
    31 #include "hbdockwidget_p.h"
    32 #include "hbview.h"
    32 #include "hbview.h"
    33 #include "hbcontentwidget_p.h"
    33 #include "hbcontentwidget_p.h"
    34 #include "hbmainwindow.h"
    34 #include "hbmainwindow.h"
       
    35 #include "hbtooltip.h"
       
    36 #include "hbgraphicsscene.h"
    35 #include "hbevent.h"
    37 #include "hbevent.h"
    36 #include "hbmainwindow_p.h"
    38 #include "hbmainwindow_p.h"
    37 #include <QGraphicsLayout>
    39 #include <QGraphicsLayout>
    38 #include <qcoreapplication.h>
    40 #include <qcoreapplication.h>
    39 
    41 
    44   graphics items excluding the background.
    46   graphics items excluding the background.
    45 
    47 
    46   \internal
    48   \internal
    47 */
    49 */
    48 
    50 
    49 HbScreen::HbScreen() : 
    51 HbScreen::HbScreen() :
    50     HbWidget(), 
    52     HbWidget(),
    51     mStack(0),
    53     mStack(0),
    52     mTb(0),
    54     mTb(0),
    53     mDock(0),
    55     mDock(0),
    54     mToolBarOrientation(0),
    56     mToolBarOrientation(0),
    55     mDelayedConstructionHandled(false),
    57     mDelayedConstructionHandled(false),
    56     mScreenPolished(false)
    58     mScreenPolished(false)
    57 {
    59 {
    58 }
    60 }
    59 
    61 
    60 void HbScreen::setStackWidget(HbContentWidget *stack) 
    62 void HbScreen::setStackWidget(HbContentWidget *stack)
    61 {
    63 {
    62     if (mStack != stack) {
    64     if (mStack != stack) {
    63         if (mStack) {
    65         if (mStack) {
    64             HbStyle::setItemName(mTb, QString());
    66             HbStyle::setItemName(mTb, QString());
    65             HbStyle::setItemName(mDock, QString());
    67             HbStyle::setItemName(mDock, QString());
    66         }
    68         }
    67         mStack = stack; 
    69         mStack = stack;
    68     }
    70     }
    69 }
    71 }
    70 
    72 
    71 void HbScreen::setToolBar(HbToolBar *tb)
    73 void HbScreen::setToolBar(HbToolBar *tb)
    72 {
    74 {
    73     if (mTb != tb) {
    75     if (mTb != tb) {
    74         if (mTb) {
    76         if (mTb) {
    75             disconnect(&HbToolBarPrivate::d_ptr(mTb)->core, 0, this, 0);
    77             disconnect(&HbToolBarPrivate::d_ptr(mTb)->core, 0, this, 0);
    76             HbStyle::setItemName(mTb, QString());
    78             HbStyle::setItemName(mTb, QString());
    77         }
    79         }
    78         mTb = tb; 
    80         mTb = tb;
    79         if (mTb) {
    81         if (mTb) {
    80             setToolBarOrientation(mTb->orientation()); 
    82             setToolBarOrientation(mTb->orientation());
    81             if (mDelayedConstructionHandled){
    83             if (mDelayedConstructionHandled) {
    82                 connect(&HbToolBarPrivate::d_ptr(mTb)->core, SIGNAL(orientationChanged()), this, SLOT(toolBarOrientationChanged()));
    84                 connect(&HbToolBarPrivate::d_ptr(mTb)->core, SIGNAL(orientationChanged()), this, SLOT(toolBarOrientationChanged()));
    83                 connect(&HbToolBarPrivate::d_ptr(mTb)->core, SIGNAL(visibilityChanged()), this, SLOT(decoratorVisibilityChanged()));
    85                 connect(&HbToolBarPrivate::d_ptr(mTb)->core, SIGNAL(visibilityChanged()), this, SLOT(decoratorVisibilityChanged()));
    84             }
    86             }
    85         } else {
    87         } else {
    86             mToolBarOrientation = 0;
    88             mToolBarOrientation = 0;
    93     if (mDock != dock) {
    95     if (mDock != dock) {
    94         if (mDock) {
    96         if (mDock) {
    95             disconnect(&HbDockWidgetPrivate::d_ptr(mDock)->core, 0, this, 0);
    97             disconnect(&HbDockWidgetPrivate::d_ptr(mDock)->core, 0, this, 0);
    96             HbStyle::setItemName(mDock, QString());
    98             HbStyle::setItemName(mDock, QString());
    97         }
    99         }
    98         mDock = dock; 
   100         mDock = dock;
    99         if (mDock && mDelayedConstructionHandled) {
   101         if (mDock && mDelayedConstructionHandled) {
   100             connect(&HbDockWidgetPrivate::d_ptr(mDock)->core, SIGNAL(visibilityChanged()), this, SLOT(decoratorVisibilityChanged()));
   102             connect(&HbDockWidgetPrivate::d_ptr(mDock)->core, SIGNAL(visibilityChanged()), this, SLOT(decoratorVisibilityChanged()));
   101         }
   103         }
   102     }
   104     }
   103 }
   105 }
   115 {
   117 {
   116     //we handle toolbar as a special case to
   118     //we handle toolbar as a special case to
   117     //avoid unnecessary complications in setName function.
   119     //avoid unnecessary complications in setName function.
   118     if ((mTb->isVisible() || forced) && mTb->actions().count()) {
   120     if ((mTb->isVisible() || forced) && mTb->actions().count()) {
   119         HbStyle::setItemName(mTb, "toolbar");
   121         HbStyle::setItemName(mTb, "toolbar");
   120     }
   122     } else {
   121     else {
       
   122         HbStyle::setItemName(mTb, QString());
   123         HbStyle::setItemName(mTb, QString());
   123     }
   124     }
   124 }
   125 }
   125 
   126 
   126 void HbScreen::polish(HbStyleParameters& params)
   127 void HbScreen::polish(HbStyleParameters &params)
   127 {
   128 {
   128     if (!mScreenPolished) {
   129     if (!mScreenPolished) {
   129         mScreenOrientation = mainWindow()->orientation();
   130         mScreenOrientation = mainWindow()->orientation();
   130         connect(mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(screenOrientationChanged(Qt::Orientation)));
   131         connect(mainWindow(), SIGNAL(orientationChanged(Qt::Orientation)), this, SLOT(screenOrientationChanged(Qt::Orientation)));
   131     }
   132     }
   132 
   133 
   133     if (mStack) {
   134     if (mStack) {
   134         HbView *currentView = qobject_cast<HbView*>(mStack->currentWidget());
   135         HbView *currentView = qobject_cast<HbView *>(mStack->currentWidget());
   135         if (currentView && currentView->isContentFullScreen()) {
   136         if (currentView && currentView->isContentFullScreen()) {
   136             setName(mStack, "mainfull");
   137             setName(mStack, "mainfull");
   137         } else { 
   138         } else {
   138             setName(mStack, "main");
   139             setName(mStack, "main");
   139         }
   140         }
   140     }
   141     }
   141 
   142 
   142     if (mTb) {
   143     if (mTb) {
   143         bool hiddenForEffects = HbToolBarPrivate::d_ptr(mTb)->mOrientationEffectsRunning;
   144         bool hiddenForEffects = HbToolBarPrivate::d_ptr(mTb)->mOrientationEffectsRunning;
   144         setToolBarName(hiddenForEffects);
   145         setToolBarName(hiddenForEffects);
   145     }
   146     }
   146 
   147 
   147     if (mDock) {
   148     if (mDock) {
   148         setName(mDock,"dock");
   149         setName(mDock, "dock");
   149     }
   150     }
   150 
   151 
   151     mScreenPolished = true;
   152     mScreenPolished = true;
   152     HbWidget::polish(params);
   153     HbWidget::polish(params);
   153 
   154 
   156     }
   157     }
   157     if (layout()) {
   158     if (layout()) {
   158         layout()->activate();
   159         layout()->activate();
   159     }
   160     }
   160     HbMainWindow *w = mainWindow();
   161     HbMainWindow *w = mainWindow();
   161     HbMainWindowPrivate::d_ptr(w)->postIdleEvent(HbMainWindowPrivate::IdleOrientationEvent);   
   162     HbMainWindowPrivate::d_ptr(w)->postIdleEvent(HbMainWindowPrivate::IdleOrientationEvent);
   162 }
   163 }
   163 
   164 
   164 void HbScreen::delayedConstruction()
   165 void HbScreen::delayedConstruction()
   165 {
   166 {
   166     if (mDelayedConstructionHandled)
   167     if (mDelayedConstructionHandled) {
   167         return;
   168         return;
       
   169     }
   168     mDelayedConstructionHandled = true;
   170     mDelayedConstructionHandled = true;
   169     if (mTb) {
   171     if (mTb) {
   170         connect( &HbToolBarPrivate::d_ptr ( mTb )->core, SIGNAL(orientationChanged()), this, SLOT(toolBarOrientationChanged()));
   172         connect(&HbToolBarPrivate::d_ptr(mTb)->core, SIGNAL(orientationChanged()), this, SLOT(toolBarOrientationChanged()));
   171         connect( &HbToolBarPrivate::d_ptr ( mTb )->core, SIGNAL(visibilityChanged()), this, SLOT(decoratorVisibilityChanged()));
   173         connect(&HbToolBarPrivate::d_ptr(mTb)->core, SIGNAL(visibilityChanged()), this, SLOT(decoratorVisibilityChanged()));
   172         HbToolBarPrivate::d_ptr(mTb)->delayedConstruction();
   174         HbToolBarPrivate::d_ptr(mTb)->delayedConstruction();
   173     }
   175     }
   174     if (mDock) {
   176     if (mDock) {
   175         connect(&HbDockWidgetPrivate::d_ptr(mDock)->core, SIGNAL(visibilityChanged()), this, SLOT(decoratorVisibilityChanged()));
   177         connect(&HbDockWidgetPrivate::d_ptr(mDock)->core, SIGNAL(visibilityChanged()), this, SLOT(decoratorVisibilityChanged()));
   176     }
   178     }
   177 }
   179 }
   178 
   180 
   179 void HbScreen::setGeometry (const QRectF & rect)
       
   180 {
       
   181     prepareGeometryChange();
       
   182     HbWidget::setGeometry(rect);
       
   183 }
       
   184 
       
   185 
       
   186 Qt::Orientation HbScreen::toolBarOrientation() const
   181 Qt::Orientation HbScreen::toolBarOrientation() const
   187 {
   182 {
   188     return (Qt::Orientation)mToolBarOrientation;
   183     return (Qt::Orientation)mToolBarOrientation;
   189 }
   184 }
   190 
   185 
   195 
   190 
   196 bool HbScreen::contentUnderTitleBar() const
   191 bool HbScreen::contentUnderTitleBar() const
   197 {
   192 {
   198     bool contentUnderTitleBar = false;
   193     bool contentUnderTitleBar = false;
   199     if (mStack) {
   194     if (mStack) {
   200         HbView *currentView = qobject_cast<HbView*>(mStack->currentWidget());
   195         HbView *currentView = qobject_cast<HbView *>(mStack->currentWidget());
   201         if (currentView && (currentView->viewFlags() 
   196         if (currentView && !(currentView->viewFlags() & HbView::ViewDisableRelayout)) {
   202                             & (HbView::ViewTitleBarMinimized | HbView::ViewTitleBarFloating 
   197             if (currentView->viewFlags() & (HbView::ViewTitleBarMinimized
   203                             | HbView::ViewTitleBarHidden))) {
   198                                             | HbView::ViewTitleBarFloating | HbView::ViewTitleBarHidden)) {
   204             contentUnderTitleBar = true;
   199                 contentUnderTitleBar = true;
       
   200             }
   205         }
   201         }
   206     }
   202     }
   207     return contentUnderTitleBar;
   203     return contentUnderTitleBar;
   208 }
   204 }
   209 
   205 
   210 bool HbScreen::contentUnderStatusBar() const
   206 bool HbScreen::contentUnderStatusBar() const
   211 {
   207 {
   212     bool contentUnderStatusBar = false;
   208     bool contentUnderStatusBar = false;
   213     if (mStack) {
   209     if (mStack) {
   214         HbView *currentView = qobject_cast<HbView*>(mStack->currentWidget());
   210         HbView *currentView = qobject_cast<HbView *>(mStack->currentWidget());
   215         if (currentView && (currentView->viewFlags() 
   211         if (currentView && !(currentView->viewFlags() & HbView::ViewDisableRelayout)) {
   216                             & (HbView::ViewStatusBarFloating | HbView::ViewStatusBarHidden))) {
   212             if (currentView->viewFlags() & (HbView::ViewStatusBarFloating
   217             contentUnderStatusBar = true;
   213                                             | HbView::ViewStatusBarHidden)) {
       
   214                 contentUnderStatusBar = true;
       
   215             }
   218         }
   216         }
   219     }
   217     }
   220     return contentUnderStatusBar;
   218     return contentUnderStatusBar;
   221 }
   219 }
   222 
   220 
   223 bool HbScreen::titleBarMinimizable() const
   221 bool HbScreen::titleBarMinimizable() const
   224 {
   222 {
   225     bool titleBarMinimizable = false;
   223     bool titleBarMinimizable = false;
   226     if (mStack) {
   224     if (mStack) {
   227         HbView *currentView = qobject_cast<HbView*>(mStack->currentWidget());
   225         HbView *currentView = qobject_cast<HbView *>(mStack->currentWidget());
   228         if (currentView && (currentView->viewFlags() & (HbView::ViewTitleBarMinimizable))) {
   226         if (currentView && (currentView->viewFlags() & (HbView::ViewTitleBarMinimizable))) {
   229             titleBarMinimizable = true;
   227             titleBarMinimizable = true;
   230         }
   228         }
   231     }
   229     }
   232     return titleBarMinimizable;
   230     return titleBarMinimizable;
   247 }
   245 }
   248 
   246 
   249 void HbScreen::setToolBarOrientation(Qt::Orientation orientation)
   247 void HbScreen::setToolBarOrientation(Qt::Orientation orientation)
   250 {
   248 {
   251     if (orientation != mToolBarOrientation) {
   249     if (orientation != mToolBarOrientation) {
   252         if (mTb){
   250         if (mTb) {
   253             HbToolBarPrivate::d_ptr(mTb)->mDoLayout = false;
   251             HbToolBarPrivate::d_ptr(mTb)->mDoLayout = false;
   254             repolish();
   252             repolish();
   255         }
   253         }
   256         mToolBarOrientation = orientation;
   254         mToolBarOrientation = orientation;
   257     }
   255     }
   258 }
   256 }
   259 
   257 
   260 void HbScreen::decoratorVisibilityChanged()
   258 void HbScreen::decoratorVisibilityChanged()
   261 {
   259 {
       
   260     HbMainWindow *window = mainWindow();
       
   261     // Do not repolish if orientation is about to change
       
   262     if (window && HbMainWindowPrivate::d_ptr(window)->mOrientationChangeOngoing
       
   263             && mScreenOrientation != HbMainWindowPrivate::d_ptr(window)->mOrientation) {
       
   264         return;
       
   265     }
   262     if (mTb) {
   266     if (mTb) {
   263         HbToolBarPrivate::d_ptr(mTb)->mDoLayout = false;
   267         HbToolBarPrivate::d_ptr(mTb)->mDoLayout = false;
   264     }
   268     }
   265     repolish();
   269     repolish();
   266     QCoreApplication::sendPostedEvents(this, QEvent::Polish);
   270     QCoreApplication::sendPostedEvents(this, QEvent::Polish);
   267 }
   271 }
   268 
   272 
   269 void HbScreen::currentViewChanged(HbView* view)
   273 void HbScreen::currentViewChanged(HbView *view)
   270 {
   274 {
   271     Q_UNUSED(view);
   275     Q_UNUSED(view);
       
   276     HbToolTip::hideText(qobject_cast<HbGraphicsScene *>(scene()));
   272     repolish();
   277     repolish();
   273 }
   278 }
   274 
   279 
   275 bool HbScreen::event(QEvent *e)
   280 bool HbScreen::event(QEvent *e)
   276 {
   281 {
   277     if (e->type() == HbEvent::DeviceProfileChanged) {
   282     if (e->type() == HbEvent::DeviceProfileChanged) {
   278         // supress polishEvent() [which is called in HbWidget::event()] into repolish()
   283         // suppress polishEvent() [which is called in HbWidget::event()] into repolish()
   279         repolish();
   284         repolish();
   280         return QGraphicsWidget::event(e);
   285         return QGraphicsWidget::event(e);
   281     } else {
   286     } else {
   282         return HbWidget::event(e);
   287         return HbWidget::event(e);
   283     }
   288     }