homescreenapp/hsdomainmodel/src/hspage.cpp
author hgs
Wed, 18 Aug 2010 10:33:57 +0300
changeset 81 7dd137878ff8
parent 69 87476091b3f5
child 86 e4f038c420f7
permissions -rw-r--r--
201033
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/*
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     8
*
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    11
*
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    12
* Contributors:
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    13
*
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    14
* Description:
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    15
*
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    16
*/
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
81
hgs
parents: 69
diff changeset
    18
#include <QHash>
hgs
parents: 69
diff changeset
    19
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    20
#include <HbInstance>
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    21
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
    22
#include "hsdomainmodeldatastructures.h"
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    23
#include "hspage.h"
69
hgs
parents: 63
diff changeset
    24
#include "hspagevisual.h"
62
hgs
parents: 55
diff changeset
    25
#include "hspagetoucharea.h"
hgs
parents: 55
diff changeset
    26
#include "hspagenewwidgetlayout.h"
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    27
#include "hsscene.h"
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    28
#include "hsdatabase.h"
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    29
#include "hswidgethost.h"
69
hgs
parents: 63
diff changeset
    30
#include "hswidgethostvisual.h"
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    31
#include "hswallpaper.h"
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    32
#include "hswidgetpositioningonwidgetadd.h"
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
    33
#include "hswidgetpositioningonorientationchange.h"
62
hgs
parents: 55
diff changeset
    34
#include "hsconfiguration.h"
69
hgs
parents: 63
diff changeset
    35
#include "hsgui.h"
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    36
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    37
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    38
/*!
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    39
    \class HsPage
62
hgs
parents: 55
diff changeset
    40
    \ingroup group_hsdomainmodel
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    41
    \brief Represents a page in the framework.
62
hgs
parents: 55
diff changeset
    42
    HsPage contains group of widgets. HsPage can have a wallpaper.
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    43
*/
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    44
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    45
/*!
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    46
    Constructor.
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    47
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    48
    \a parent Owner.
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    49
    \a aFlags Window flags.
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    50
*/
69
hgs
parents: 63
diff changeset
    51
HsPage::HsPage(QObject* parent)
hgs
parents: 63
diff changeset
    52
    : QObject(parent),
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    53
      mDatabaseId(-1),
69
hgs
parents: 63
diff changeset
    54
      mPageVisual(new HsPageVisual), 
62
hgs
parents: 55
diff changeset
    55
      mWallpaper(0),
hgs
parents: 55
diff changeset
    56
      mRemovable(true),
63
hgs
parents: 62
diff changeset
    57
      mPageMargin(0.0)
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    58
{
69
hgs
parents: 63
diff changeset
    59
 
63
hgs
parents: 62
diff changeset
    60
    //Page margin
hgs
parents: 62
diff changeset
    61
    mPageMargin = HSCONFIGURATION_GET(pageMargin);
hgs
parents: 62
diff changeset
    62
    connect(HsConfiguration::instance(), SIGNAL(propertyChanged(QString)), SLOT(onPageMarginChanged(QString)));
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    63
}
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    64
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    65
/*!
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    66
    Destructor.
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    67
*/
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    68
HsPage::~HsPage()
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    69
{
69
hgs
parents: 63
diff changeset
    70
    // visuals are owned by widget host, detach those from page visual
hgs
parents: 63
diff changeset
    71
    HsWidgetHostVisual *visual(0);
hgs
parents: 63
diff changeset
    72
    foreach (HsWidgetHost *widget, mWidgets) {
hgs
parents: 63
diff changeset
    73
        visual = widget->visual();
hgs
parents: 63
diff changeset
    74
        visual->setParent(0);
hgs
parents: 63
diff changeset
    75
        if (visual->scene()) {
hgs
parents: 63
diff changeset
    76
            visual->scene()->removeItem(visual);
hgs
parents: 63
diff changeset
    77
        }
hgs
parents: 63
diff changeset
    78
    }
hgs
parents: 63
diff changeset
    79
   
hgs
parents: 63
diff changeset
    80
    foreach (HsWidgetHost *widget, mNewWidgets) {
hgs
parents: 63
diff changeset
    81
        visual = widget->visual();
hgs
parents: 63
diff changeset
    82
        visual->setParent(0);
hgs
parents: 63
diff changeset
    83
        if (visual->scene()) {
hgs
parents: 63
diff changeset
    84
            visual->scene()->removeItem(visual);
hgs
parents: 63
diff changeset
    85
        }
hgs
parents: 63
diff changeset
    86
    }
hgs
parents: 63
diff changeset
    87
   
hgs
parents: 63
diff changeset
    88
    foreach (HsWidgetHost *widget, mUnavailableWidgets) {
hgs
parents: 63
diff changeset
    89
        visual = widget->visual();
hgs
parents: 63
diff changeset
    90
        visual->setParent(0);
hgs
parents: 63
diff changeset
    91
        if (visual->scene()) {
hgs
parents: 63
diff changeset
    92
            visual->scene()->removeItem(visual);
hgs
parents: 63
diff changeset
    93
        }
hgs
parents: 63
diff changeset
    94
    }
hgs
parents: 63
diff changeset
    95
    qDeleteAll(mWidgets);
hgs
parents: 63
diff changeset
    96
    qDeleteAll(mNewWidgets);
hgs
parents: 63
diff changeset
    97
    qDeleteAll(mUnavailableWidgets);
hgs
parents: 63
diff changeset
    98
hgs
parents: 63
diff changeset
    99
    delete mPageVisual;
62
hgs
parents: 55
diff changeset
   100
    delete mWallpaper;
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   101
}
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   102
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   103
/*!
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   104
    Returns the database id.
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   105
*/
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   106
int HsPage::databaseId() const
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   107
{
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   108
    return mDatabaseId;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   109
}
46
23b5d6a29cce Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 39
diff changeset
   110
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   111
/*!
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   112
    Sets the database id to \a id.
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   113
*/
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   114
void HsPage::setDatabaseId(int id)
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   115
{
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   116
    mDatabaseId = id;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   117
}
69
hgs
parents: 63
diff changeset
   118
/*
62
hgs
parents: 55
diff changeset
   119
void HsPage::setGeometry(const QRectF &rect)
hgs
parents: 55
diff changeset
   120
{
hgs
parents: 55
diff changeset
   121
    if (mTouchArea) {
hgs
parents: 55
diff changeset
   122
        mTouchArea->resize(rect.size());
hgs
parents: 55
diff changeset
   123
    }
hgs
parents: 55
diff changeset
   124
hgs
parents: 55
diff changeset
   125
    HbWidget::setGeometry(rect);
hgs
parents: 55
diff changeset
   126
}
69
hgs
parents: 63
diff changeset
   127
*/
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   128
/*!
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   129
    Loads widgets.
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   130
*/
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   131
bool HsPage::load()
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   132
{
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   133
    if (mDatabaseId < 0) {
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   134
        return false;
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   135
    }
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   136
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   137
    HsDatabase *db = HsDatabase::instance();
46
23b5d6a29cce Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 39
diff changeset
   138
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   139
    QList<HsWidgetData> datas;
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   140
    if (!db->widgets(mDatabaseId, datas)) {
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   141
        return false;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   142
    }
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   143
62
hgs
parents: 55
diff changeset
   144
    if (HSCONFIGURATION_GET(sceneType) == HsConfiguration::PageWallpapers) {
hgs
parents: 55
diff changeset
   145
        mWallpaper = new HsPageWallpaper(this);
hgs
parents: 55
diff changeset
   146
    }
hgs
parents: 55
diff changeset
   147
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   148
    foreach (HsWidgetData data, datas) {
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   149
        HsWidgetHost *widget = new HsWidgetHost(data.id);
69
hgs
parents: 63
diff changeset
   150
        if (!widget->loadPresentation(Qt::Horizontal) &&
hgs
parents: 63
diff changeset
   151
            !widget->loadPresentation(Qt::Vertical)) {
hgs
parents: 63
diff changeset
   152
            widget->setPage(this);
hgs
parents: 63
diff changeset
   153
            widget->visual()->hide();
hgs
parents: 63
diff changeset
   154
            connectWidget(widget);
hgs
parents: 63
diff changeset
   155
            mNewWidgets << widget;            
hgs
parents: 63
diff changeset
   156
        }
hgs
parents: 63
diff changeset
   157
        else {
hgs
parents: 63
diff changeset
   158
            mWidgets.append(widget);
hgs
parents: 63
diff changeset
   159
            connectWidget(widget);
hgs
parents: 63
diff changeset
   160
            widget->setPage(this);
hgs
parents: 63
diff changeset
   161
            widget->visual()->setParentItem(this->visual());
hgs
parents: 63
diff changeset
   162
            widget->startWidget(isDefaultPage());
hgs
parents: 63
diff changeset
   163
        }
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   164
    }
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   165
69
hgs
parents: 63
diff changeset
   166
    connect(HsGui::instance(),
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   167
        SIGNAL(orientationChanged(Qt::Orientation)),
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   168
        SLOT(onOrientationChanged(Qt::Orientation)));
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   169
46
23b5d6a29cce Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 39
diff changeset
   170
    return true;
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   171
}
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   172
62
hgs
parents: 55
diff changeset
   173
/*!
63
hgs
parents: 62
diff changeset
   174
    Return wallpaper.
62
hgs
parents: 55
diff changeset
   175
*/
hgs
parents: 55
diff changeset
   176
HsWallpaper *HsPage::wallpaper() const
hgs
parents: 55
diff changeset
   177
{
hgs
parents: 55
diff changeset
   178
    return mWallpaper;
hgs
parents: 55
diff changeset
   179
}
hgs
parents: 55
diff changeset
   180
/*!
hgs
parents: 55
diff changeset
   181
    Add given existing \a widgetHost to a page. Returns true if successful
hgs
parents: 55
diff changeset
   182
*/
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   183
bool HsPage::addExistingWidget(HsWidgetHost *widgetHost)
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   184
{
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   185
    if (!widgetHost) {
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   186
        return false;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   187
    }
46
23b5d6a29cce Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 39
diff changeset
   188
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   189
    if (mWidgets.contains(widgetHost)) {
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   190
        return true;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   191
    }
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   192
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   193
    if (!widgetHost->setPage(this)) {
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   194
        return false;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   195
    }
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   196
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   197
    connectWidget(widgetHost);
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   198
    mWidgets << widgetHost;
69
hgs
parents: 63
diff changeset
   199
    widgetHost->visual()->setParentItem(visual());
46
23b5d6a29cce Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 39
diff changeset
   200
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   201
    return true;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   202
 }
63
hgs
parents: 62
diff changeset
   203
62
hgs
parents: 55
diff changeset
   204
/*!
hgs
parents: 55
diff changeset
   205
    Remove given \a widgetHost from a page. Widget is not deleted. 
hgs
parents: 55
diff changeset
   206
    Returns true if successful
hgs
parents: 55
diff changeset
   207
*/
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   208
bool HsPage::removeWidget(HsWidgetHost *widgetHost)
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   209
{
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   210
    if (!widgetHost || !widgetHost->setPage(0)) {
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   211
        return false;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   212
    }
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   213
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   214
    disconnectWidget(widgetHost);
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   215
    mWidgets.removeOne(widgetHost);
69
hgs
parents: 63
diff changeset
   216
    widgetHost->visual()->setParentItem(0);
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   217
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   218
    return true;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   219
}
63
hgs
parents: 62
diff changeset
   220
62
hgs
parents: 55
diff changeset
   221
/*!
hgs
parents: 55
diff changeset
   222
    Returns list of new widgets belonging to a page. Widgets which are
hgs
parents: 55
diff changeset
   223
    not yet layouted are considered as new widgets. 
hgs
parents: 55
diff changeset
   224
*/
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   225
QList<HsWidgetHost *> HsPage::newWidgets()
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   226
{
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   227
    return mNewWidgets;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   228
}
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   229
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   230
/*!
46
23b5d6a29cce Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 39
diff changeset
   231
    Adds new widget into a page. Returns true if successfull.
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   232
*/
62
hgs
parents: 55
diff changeset
   233
bool HsPage::addNewWidget(HsWidgetHost* widgetHost, const QPointF &touchPoint)
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   234
{
62
hgs
parents: 55
diff changeset
   235
    mTouchPoint = touchPoint;
hgs
parents: 55
diff changeset
   236
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   237
    if (!widgetHost || mWidgets.contains(widgetHost)) {
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   238
        return false;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   239
    }
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   240
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   241
    if (mNewWidgets.contains(widgetHost)) {
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   242
        return true;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   243
    }
69
hgs
parents: 63
diff changeset
   244
    
hgs
parents: 63
diff changeset
   245
    widgetHost->setPage(this);    
46
23b5d6a29cce Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 39
diff changeset
   246
69
hgs
parents: 63
diff changeset
   247
    widgetHost->visual()->hide();
46
23b5d6a29cce Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 39
diff changeset
   248
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   249
    connectWidget(widgetHost);
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   250
    mNewWidgets << widgetHost;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   251
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   252
    return true;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   253
}
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   254
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   255
/*!
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   256
    Layouts all the new widgets
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   257
*/
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   258
void HsPage::layoutNewWidgets()
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   259
{
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   260
    if (mNewWidgets.isEmpty()) {
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   261
        return;
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   262
    }
46
23b5d6a29cce Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 39
diff changeset
   263
69
hgs
parents: 63
diff changeset
   264
    HsPageNewWidgetLayout *newWidgetLayout = static_cast<HsPageNewWidgetLayout *>(visual()->layout());
62
hgs
parents: 55
diff changeset
   265
    if (!newWidgetLayout) {
hgs
parents: 55
diff changeset
   266
        newWidgetLayout = new HsPageNewWidgetLayout(mTouchPoint);
69
hgs
parents: 63
diff changeset
   267
        visual()->setLayout(newWidgetLayout);
62
hgs
parents: 55
diff changeset
   268
    }    
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   269
    updateZValues();
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   270
    HsWidgetHost *widget = 0;
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   271
    for (int i = 0; i < mNewWidgets.count(); ++i) {
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   272
        widget = mNewWidgets.at(i);
62
hgs
parents: 55
diff changeset
   273
        newWidgetLayout->addItem(widget);
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   274
        widget->setPage(this);
69
hgs
parents: 63
diff changeset
   275
        widget->visual()->setParentItem(visual());
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   276
        widget->showWidget();
69
hgs
parents: 63
diff changeset
   277
        widget->visual()->show();
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   278
    }
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   279
    mWidgets << mNewWidgets;
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   280
    mNewWidgets.clear();
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   281
}
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   282
62
hgs
parents: 55
diff changeset
   283
/*!
63
hgs
parents: 62
diff changeset
   284
    Clears new widgets list and resets layout.
hgs
parents: 62
diff changeset
   285
*/
hgs
parents: 62
diff changeset
   286
void HsPage::resetNewWidgets()
hgs
parents: 62
diff changeset
   287
{
hgs
parents: 62
diff changeset
   288
    mNewWidgets.clear();
69
hgs
parents: 63
diff changeset
   289
    visual()->setLayout(0);
63
hgs
parents: 62
diff changeset
   290
}
hgs
parents: 62
diff changeset
   291
hgs
parents: 62
diff changeset
   292
/*!
62
hgs
parents: 55
diff changeset
   293
    Remove page and all it's contained widgets from database 
hgs
parents: 55
diff changeset
   294
*/
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   295
bool HsPage::deleteFromDatabase()
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   296
{
69
hgs
parents: 63
diff changeset
   297
    
hgs
parents: 63
diff changeset
   298
    HsWidgetHostVisual *visual(0);
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   299
    foreach (HsWidgetHost *widget, mWidgets) {
69
hgs
parents: 63
diff changeset
   300
        visual = widget->visual();
hgs
parents: 63
diff changeset
   301
        visual->setParent(0);
hgs
parents: 63
diff changeset
   302
        if (visual->scene()) {
hgs
parents: 63
diff changeset
   303
            visual->scene()->removeItem(visual);
hgs
parents: 63
diff changeset
   304
        }
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   305
        widget->remove();
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   306
    }
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   307
    mWidgets.clear();
69
hgs
parents: 63
diff changeset
   308
    
62
hgs
parents: 55
diff changeset
   309
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   310
    foreach (HsWidgetHost *widget, mNewWidgets) {
69
hgs
parents: 63
diff changeset
   311
        visual = widget->visual();
hgs
parents: 63
diff changeset
   312
        visual->setParent(0);
hgs
parents: 63
diff changeset
   313
        if (visual->scene()) {
hgs
parents: 63
diff changeset
   314
            visual->scene()->removeItem(visual);
hgs
parents: 63
diff changeset
   315
        }
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   316
        widget->remove();
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   317
    }
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   318
    mNewWidgets.clear();
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   319
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   320
    foreach (HsWidgetHost *widget, mUnavailableWidgets) {
69
hgs
parents: 63
diff changeset
   321
        visual = widget->visual();
hgs
parents: 63
diff changeset
   322
        visual->setParent(0);
hgs
parents: 63
diff changeset
   323
        if (visual->scene()) {
hgs
parents: 63
diff changeset
   324
            visual->scene()->removeItem(visual);
hgs
parents: 63
diff changeset
   325
        }
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   326
        widget->remove();
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   327
    }
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   328
    mUnavailableWidgets.clear();
63
hgs
parents: 62
diff changeset
   329
    
hgs
parents: 62
diff changeset
   330
    if (mWallpaper) {
hgs
parents: 62
diff changeset
   331
        mWallpaper->remove();
hgs
parents: 62
diff changeset
   332
    }
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   333
    return HsDatabase::instance()->deletePage(mDatabaseId);
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   334
}
63
hgs
parents: 62
diff changeset
   335
62
hgs
parents: 55
diff changeset
   336
/*!
hgs
parents: 55
diff changeset
   337
    Return list of widgets belonging to a page 
hgs
parents: 55
diff changeset
   338
*/
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   339
QList<HsWidgetHost *> HsPage::widgets() const
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   340
{
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   341
    return mWidgets;
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   342
}
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   343
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   344
/*!
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   345
    Returns true if the page can be removed. Otherwise,
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   346
    returns false.
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   347
*/
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   348
bool HsPage::isRemovable() const
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   349
{
46
23b5d6a29cce Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 39
diff changeset
   350
    return mRemovable;
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   351
}
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   352
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   353
/*!
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   354
    Sets removable flag to \a removable.
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   355
*/
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   356
void HsPage::setRemovable(bool removable)
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   357
{
46
23b5d6a29cce Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 39
diff changeset
   358
    mRemovable = removable;
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   359
}
63
hgs
parents: 62
diff changeset
   360
62
hgs
parents: 55
diff changeset
   361
/*!
hgs
parents: 55
diff changeset
   362
    Return true if page is default page.
hgs
parents: 55
diff changeset
   363
*/
hgs
parents: 55
diff changeset
   364
bool HsPage::isDefaultPage() const
hgs
parents: 55
diff changeset
   365
{
hgs
parents: 55
diff changeset
   366
    return mDatabaseId == HSCONFIGURATION_GET(defaultPageId);
hgs
parents: 55
diff changeset
   367
}
63
hgs
parents: 62
diff changeset
   368
62
hgs
parents: 55
diff changeset
   369
/*!
hgs
parents: 55
diff changeset
   370
    Return true if page is active page.
hgs
parents: 55
diff changeset
   371
*/
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   372
bool HsPage::isActivePage() const
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   373
{
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   374
    return this == HsScene::instance()->activePage();
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   375
}
63
hgs
parents: 62
diff changeset
   376
62
hgs
parents: 55
diff changeset
   377
/*!
hgs
parents: 55
diff changeset
   378
    Create page into database and return instance of a new page.
hgs
parents: 55
diff changeset
   379
*/
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   380
HsPage *HsPage::createInstance(const HsPageData &pageData)
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   381
{
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   382
    HsDatabase *db = HsDatabase::instance();
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   383
    Q_ASSERT(db);
46
23b5d6a29cce Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 39
diff changeset
   384
23b5d6a29cce Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 39
diff changeset
   385
    HsPageData data(pageData);
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   386
    if (db->insertPage(data)) {
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   387
        HsPage *page = new HsPage;
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   388
        page->setDatabaseId(data.id);
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   389
        return page;
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   390
    }
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   391
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   392
    return 0;
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   393
}
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   394
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   395
/*!
63
hgs
parents: 62
diff changeset
   396
    The widget is bounded in the rectangle which is smaller by pageMargin on all sides of page.
hgs
parents: 62
diff changeset
   397
*/
hgs
parents: 62
diff changeset
   398
QPointF HsPage::adjustedWidgetPosition(const QRectF &origWidgetRect)
hgs
parents: 62
diff changeset
   399
{
hgs
parents: 62
diff changeset
   400
    QRectF widgetAreaRect = contentGeometry();
hgs
parents: 62
diff changeset
   401
    qreal widgetX = qBound(widgetAreaRect.left(), origWidgetRect.x(), widgetAreaRect.right() - origWidgetRect.width());
hgs
parents: 62
diff changeset
   402
    qreal widgetY = qBound(widgetAreaRect.top(), origWidgetRect.y(), widgetAreaRect.bottom() - origWidgetRect.height());
hgs
parents: 62
diff changeset
   403
hgs
parents: 62
diff changeset
   404
    return QPointF(widgetX, widgetY);
hgs
parents: 62
diff changeset
   405
}
hgs
parents: 62
diff changeset
   406
hgs
parents: 62
diff changeset
   407
/*!
hgs
parents: 62
diff changeset
   408
    Returns rect of rectangular where widgets are allowed to be placed in the page.
hgs
parents: 62
diff changeset
   409
*/
hgs
parents: 62
diff changeset
   410
QRectF HsPage::contentGeometry()
hgs
parents: 62
diff changeset
   411
{
69
hgs
parents: 63
diff changeset
   412
    return contentGeometry(HsGui::instance()->orientation());
63
hgs
parents: 62
diff changeset
   413
}
hgs
parents: 62
diff changeset
   414
hgs
parents: 62
diff changeset
   415
/*!
hgs
parents: 62
diff changeset
   416
    Returns rect of rectangular where widgets are allowed to be placed in the page.
hgs
parents: 62
diff changeset
   417
*/
hgs
parents: 62
diff changeset
   418
QRectF HsPage::contentGeometry(Qt::Orientation orientation)
hgs
parents: 62
diff changeset
   419
{
69
hgs
parents: 63
diff changeset
   420
    QRectF pageRect = HsGui::instance()->layoutRect();
63
hgs
parents: 62
diff changeset
   421
69
hgs
parents: 63
diff changeset
   422
    if (orientation != HsGui::instance()->orientation()) {
63
hgs
parents: 62
diff changeset
   423
        qreal width = pageRect.width();
hgs
parents: 62
diff changeset
   424
        qreal height = pageRect.height();
hgs
parents: 62
diff changeset
   425
        pageRect.setWidth(height);
hgs
parents: 62
diff changeset
   426
        pageRect.setHeight(width);
hgs
parents: 62
diff changeset
   427
    }
hgs
parents: 62
diff changeset
   428
hgs
parents: 62
diff changeset
   429
    //Take care of chrome in both orientation
hgs
parents: 62
diff changeset
   430
    pageRect.setTop(64);
hgs
parents: 62
diff changeset
   431
hgs
parents: 62
diff changeset
   432
    //Shrink by page margins at each side
hgs
parents: 62
diff changeset
   433
    return pageRect.adjusted(mPageMargin, mPageMargin, -mPageMargin, -mPageMargin);
hgs
parents: 62
diff changeset
   434
}
hgs
parents: 62
diff changeset
   435
hgs
parents: 62
diff changeset
   436
/*!
hgs
parents: 62
diff changeset
   437
    Returns rect of rectangular where widgets are allowed to be placed in the page.
hgs
parents: 62
diff changeset
   438
*/
hgs
parents: 62
diff changeset
   439
QRectF HsPage::contentRect()
hgs
parents: 62
diff changeset
   440
{
69
hgs
parents: 63
diff changeset
   441
    return contentRect(HsGui::instance()->orientation());
63
hgs
parents: 62
diff changeset
   442
}
hgs
parents: 62
diff changeset
   443
hgs
parents: 62
diff changeset
   444
/*!
hgs
parents: 62
diff changeset
   445
    Returns rect of rectangular where widgets are allowed to be placed in the page.
hgs
parents: 62
diff changeset
   446
*/
hgs
parents: 62
diff changeset
   447
QRectF HsPage::contentRect(Qt::Orientation orientation)
hgs
parents: 62
diff changeset
   448
{
hgs
parents: 62
diff changeset
   449
    QRectF rect = contentGeometry(orientation);
hgs
parents: 62
diff changeset
   450
    rect.moveTopLeft(QPointF(0,0));
hgs
parents: 62
diff changeset
   451
    return rect;
hgs
parents: 62
diff changeset
   452
}
hgs
parents: 62
diff changeset
   453
69
hgs
parents: 63
diff changeset
   454
HsPageVisual *HsPage::visual() const
hgs
parents: 63
diff changeset
   455
{
hgs
parents: 63
diff changeset
   456
    return mPageVisual;
hgs
parents: 63
diff changeset
   457
}
63
hgs
parents: 62
diff changeset
   458
/*!
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   459
    Calls onShow() for contained widgets.
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   460
*/
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   461
void HsPage::showWidgets()
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   462
{
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   463
    foreach (HsWidgetHost *widget, mWidgets) {
69
hgs
parents: 63
diff changeset
   464
        if (widget->visual()->parentItem() == visual()) {
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   465
            widget->showWidget();
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   466
        }
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   467
    }
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   468
}
46
23b5d6a29cce Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 39
diff changeset
   469
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   470
/*!
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   471
    Calls onHide() for contained widgets.
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   472
*/
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   473
void HsPage::hideWidgets()
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   474
{
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   475
    foreach (HsWidgetHost *widget, mWidgets) {
69
hgs
parents: 63
diff changeset
   476
        if (widget->visual()->parentItem() == visual()) {
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   477
            widget->hideWidget();
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   478
        }
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   479
    }
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   480
}
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   481
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   482
/*!
63
hgs
parents: 62
diff changeset
   483
    Propagate online state to widgets.
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   484
*/
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   485
void HsPage::setOnline(bool online)
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   486
{
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   487
    foreach (HsWidgetHost *widget, mNewWidgets) {
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   488
        widget->setOnline(online);
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   489
    }
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   490
    foreach (HsWidgetHost *widget, mWidgets) {
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   491
        widget->setOnline(online);
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   492
    }
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   493
}
63
hgs
parents: 62
diff changeset
   494
62
hgs
parents: 55
diff changeset
   495
/*!
hgs
parents: 55
diff changeset
   496
    Update widgets z-values and persist those. Active widget has top most 
hgs
parents: 55
diff changeset
   497
    z-value.
hgs
parents: 55
diff changeset
   498
*/
39
4e8ebe173323 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 36
diff changeset
   499
void HsPage::updateZValues()
4e8ebe173323 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 36
diff changeset
   500
{
4e8ebe173323 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 36
diff changeset
   501
    int z = 0;
4e8ebe173323 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 36
diff changeset
   502
81
hgs
parents: 69
diff changeset
   503
    QHash<int, qreal> widgetZValues;
hgs
parents: 69
diff changeset
   504
39
4e8ebe173323 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 36
diff changeset
   505
    if (!mWidgets.isEmpty()) {
4e8ebe173323 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 36
diff changeset
   506
        QMultiMap<qreal, HsWidgetHost *> map;
4e8ebe173323 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 36
diff changeset
   507
        foreach (HsWidgetHost *widget, mWidgets) {
69
hgs
parents: 63
diff changeset
   508
            map.insert(widget->visual()->zValue(), widget);
39
4e8ebe173323 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 36
diff changeset
   509
        }
46
23b5d6a29cce Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 39
diff changeset
   510
39
4e8ebe173323 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 36
diff changeset
   511
        QList<HsWidgetHost *> sortedWidgets = map.values();
46
23b5d6a29cce Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 39
diff changeset
   512
23b5d6a29cce Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 39
diff changeset
   513
        HsWidgetHost *activeWidget = HsScene::instance()->activeWidget();
39
4e8ebe173323 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 36
diff changeset
   514
        if (sortedWidgets.contains(activeWidget)) {
4e8ebe173323 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 36
diff changeset
   515
            sortedWidgets.removeOne(activeWidget);
46
23b5d6a29cce Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 39
diff changeset
   516
            sortedWidgets.append(activeWidget);
39
4e8ebe173323 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 36
diff changeset
   517
        }
46
23b5d6a29cce Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 39
diff changeset
   518
39
4e8ebe173323 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 36
diff changeset
   519
        foreach (HsWidgetHost *widget, sortedWidgets) {
81
hgs
parents: 69
diff changeset
   520
            widgetZValues.insert(widget->databaseId(), z);
69
hgs
parents: 63
diff changeset
   521
            widget->visual()->setZValue(z++);
39
4e8ebe173323 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 36
diff changeset
   522
        }
4e8ebe173323 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 36
diff changeset
   523
    }
4e8ebe173323 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 36
diff changeset
   524
4e8ebe173323 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 36
diff changeset
   525
    if (!mNewWidgets.isEmpty()) {
4e8ebe173323 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 36
diff changeset
   526
        foreach (HsWidgetHost *widget, mNewWidgets) {
81
hgs
parents: 69
diff changeset
   527
            widgetZValues.insert(widget->databaseId(), z);
69
hgs
parents: 63
diff changeset
   528
            widget->visual()->setZValue(z++);
39
4e8ebe173323 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 36
diff changeset
   529
        }
4e8ebe173323 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 36
diff changeset
   530
    }
81
hgs
parents: 69
diff changeset
   531
hgs
parents: 69
diff changeset
   532
    if (!widgetZValues.isEmpty()) {
hgs
parents: 69
diff changeset
   533
        HsDatabase::instance()->updateWidgetZValues(
hgs
parents: 69
diff changeset
   534
            widgetZValues, HsGui::instance()->orientation());
hgs
parents: 69
diff changeset
   535
    }
39
4e8ebe173323 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 36
diff changeset
   536
}
62
hgs
parents: 55
diff changeset
   537
/*!
hgs
parents: 55
diff changeset
   538
    Return this page's index.
hgs
parents: 55
diff changeset
   539
*/
51
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 46
diff changeset
   540
int HsPage::pageIndex()
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 46
diff changeset
   541
{
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 46
diff changeset
   542
    return HsScene::instance()->pages().indexOf(this);
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 46
diff changeset
   543
}
62
hgs
parents: 55
diff changeset
   544
/*!
hgs
parents: 55
diff changeset
   545
    Create touch area for page.
hgs
parents: 55
diff changeset
   546
*/
69
hgs
parents: 63
diff changeset
   547
/*void HsPage::setupTouchArea()
62
hgs
parents: 55
diff changeset
   548
{
hgs
parents: 55
diff changeset
   549
    mTouchArea = new HsPageTouchArea(this);
hgs
parents: 55
diff changeset
   550
    mTouchArea->setZValue(-1);
69
hgs
parents: 63
diff changeset
   551
}*/
62
hgs
parents: 55
diff changeset
   552
/*!
hgs
parents: 55
diff changeset
   553
    Utility to connect widget signals to page.
hgs
parents: 55
diff changeset
   554
*/
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   555
void HsPage::connectWidget(HsWidgetHost *widget)
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   556
{
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   557
    connect(widget, SIGNAL(finished()), SLOT(onWidgetFinished()));
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   558
    connect(widget, SIGNAL(faulted()), SLOT(onWidgetFaulted()));
69
hgs
parents: 63
diff changeset
   559
    connect(widget->visual(), SIGNAL(resized()), SLOT(onWidgetResized()));
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   560
    connect(widget, SIGNAL(available()), SLOT(onWidgetAvailable()));
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   561
    connect(widget, SIGNAL(unavailable()), SLOT(onWidgetUnavailable()));
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   562
}
62
hgs
parents: 55
diff changeset
   563
/*!
hgs
parents: 55
diff changeset
   564
    Disconnect widget signals from page
hgs
parents: 55
diff changeset
   565
*/
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   566
void HsPage::disconnectWidget(HsWidgetHost *widget)
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   567
{
69
hgs
parents: 63
diff changeset
   568
    widget->visual()->disconnect(this);
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   569
    widget->disconnect(this);
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   570
}
81
hgs
parents: 69
diff changeset
   571
62
hgs
parents: 55
diff changeset
   572
/*!
hgs
parents: 55
diff changeset
   573
    Disconnect and remove widget
hgs
parents: 55
diff changeset
   574
*/
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   575
void HsPage::onWidgetFinished()
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   576
{
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   577
    HsWidgetHost *widget = qobject_cast<HsWidgetHost *>(sender());
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   578
36
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   579
    // It can be in new widget list if we haven't layouted it yet
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   580
    // or layouted new widget and widget list
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   581
    if (!mNewWidgets.removeOne(widget)) {
cdae8c6c3876 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 35
diff changeset
   582
        mWidgets.removeOne(widget);
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   583
    }
69
hgs
parents: 63
diff changeset
   584
    if (widget){     
hgs
parents: 63
diff changeset
   585
        HsWidgetHostVisual *visual = widget->visual();
hgs
parents: 63
diff changeset
   586
        visual->setParentItem(0);
hgs
parents: 63
diff changeset
   587
        if (visual->scene()) {
hgs
parents: 63
diff changeset
   588
            visual->scene()->removeItem(visual);
hgs
parents: 63
diff changeset
   589
        }
81
hgs
parents: 69
diff changeset
   590
        disconnectWidget(widget);
hgs
parents: 69
diff changeset
   591
        widget->remove();
69
hgs
parents: 63
diff changeset
   592
    }
81
hgs
parents: 69
diff changeset
   593
}
46
23b5d6a29cce Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 39
diff changeset
   594
62
hgs
parents: 55
diff changeset
   595
/*!
hgs
parents: 55
diff changeset
   596
    Remove widget if it faulted
hgs
parents: 55
diff changeset
   597
*/
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   598
void HsPage::onWidgetFaulted()
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   599
{
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   600
    onWidgetFinished();
35
f9ce957a272c Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   601
}
46
23b5d6a29cce Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 39
diff changeset
   602
23b5d6a29cce Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 39
diff changeset
   603
/*!
62
hgs
parents: 55
diff changeset
   604
    Calculates new widget position on page when widget size changes. If page has layout then there are new widgets
hgs
parents: 55
diff changeset
   605
    and we use layout to calculate new widget positions.
46
23b5d6a29cce Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 39
diff changeset
   606
*/
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   607
void HsPage::onWidgetResized()
46
23b5d6a29cce Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 39
diff changeset
   608
{
69
hgs
parents: 63
diff changeset
   609
    if (!visual()->layout()) {
hgs
parents: 63
diff changeset
   610
        HsWidgetHostVisual *widgetVisual = qobject_cast<HsWidgetHostVisual *>(sender());
hgs
parents: 63
diff changeset
   611
        widgetVisual->setPos(adjustedWidgetPosition(widgetVisual->geometry()));
62
hgs
parents: 55
diff changeset
   612
    } else {
69
hgs
parents: 63
diff changeset
   613
        visual()->layout()->invalidate();
62
hgs
parents: 55
diff changeset
   614
    }
hgs
parents: 55
diff changeset
   615
}
hgs
parents: 55
diff changeset
   616
/*!
hgs
parents: 55
diff changeset
   617
    Show widget if it came available
hgs
parents: 55
diff changeset
   618
*/
hgs
parents: 55
diff changeset
   619
void HsPage::onWidgetAvailable()
hgs
parents: 55
diff changeset
   620
{
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   621
    HsWidgetHost *widget = qobject_cast<HsWidgetHost *>(sender());
69
hgs
parents: 63
diff changeset
   622
    HsWidgetHostVisual *widgetVisual(widget->visual());
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   623
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   624
    mUnavailableWidgets.removeOne(widget);
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   625
    mWidgets.append(widget);
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   626
69
hgs
parents: 63
diff changeset
   627
    widgetVisual->setParentItem(visual());
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   628
    widget->startWidget(isActivePage());
69
hgs
parents: 63
diff changeset
   629
    widgetVisual->show();
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   630
}
62
hgs
parents: 55
diff changeset
   631
/*!
hgs
parents: 55
diff changeset
   632
    Update internal bookkeeping and hide widget
hgs
parents: 55
diff changeset
   633
*/
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   634
void HsPage::onWidgetUnavailable()
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   635
{
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   636
    HsWidgetHost *widget = qobject_cast<HsWidgetHost *>(sender());
69
hgs
parents: 63
diff changeset
   637
    HsWidgetHostVisual *widgetVisual(widget->visual());
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   638
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   639
    if (mWidgets.contains(widget)) {
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   640
        mWidgets.removeOne(widget);
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   641
    } else if (mNewWidgets.contains(widget)) {
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   642
        mNewWidgets.removeOne(widget);
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   643
    } else {
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   644
        return;
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   645
    }
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   646
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   647
    mUnavailableWidgets.append(widget);
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   648
69
hgs
parents: 63
diff changeset
   649
    widgetVisual->hide();
hgs
parents: 63
diff changeset
   650
    widgetVisual->setParentItem(0);
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   651
}
63
hgs
parents: 62
diff changeset
   652
62
hgs
parents: 55
diff changeset
   653
/*!
hgs
parents: 55
diff changeset
   654
    Run positioning algorithm for widgets which don't have position on 
hgs
parents: 55
diff changeset
   655
    target orientation. Otherwise set orientation positions for widgets.
hgs
parents: 55
diff changeset
   656
*/
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   657
void HsPage::onOrientationChanged(Qt::Orientation orientation)
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   658
{
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   659
    HsWidgetPositioningOnOrientationChange *converter =
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   660
        HsWidgetPositioningOnOrientationChange::instance();
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   661
63
hgs
parents: 62
diff changeset
   662
    Qt::Orientation orientationFrom = orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical;
hgs
parents: 62
diff changeset
   663
    QRectF from = contentGeometry(orientationFrom);
hgs
parents: 62
diff changeset
   664
    QRectF to = contentGeometry(orientation);
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   665
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   666
    HsWidgetPresentationData presentation;
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   667
    presentation.orientation = orientation;
69
hgs
parents: 63
diff changeset
   668
    
hgs
parents: 63
diff changeset
   669
    HsWidgetHostVisual *visual(0);
hgs
parents: 63
diff changeset
   670
#ifdef HSWIDGETORGANIZER_ALGORITHM
hgs
parents: 63
diff changeset
   671
    QList<HsWidgetHost*> newWidgets;
hgs
parents: 63
diff changeset
   672
#endif //HSWIDGETORGANIZER_ALGORITHM    
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   673
    foreach (HsWidgetHost *widget, mWidgets) {
69
hgs
parents: 63
diff changeset
   674
        visual = widget->visual();
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   675
        if (!widget->getPresentation(presentation)) {
69
hgs
parents: 63
diff changeset
   676
#ifndef HSWIDGETORGANIZER_ALGORITHM
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   677
            QList<QRectF> geometries = converter->convert(
69
hgs
parents: 63
diff changeset
   678
                from, QList<QRectF>() << visual->geometry(), to);
hgs
parents: 63
diff changeset
   679
            visual->setGeometry(geometries.first());
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   680
            widget->savePresentation();
69
hgs
parents: 63
diff changeset
   681
#else //HSWIDGETORGANIZER_ALGORITHM
hgs
parents: 63
diff changeset
   682
            newWidgets << widget;
hgs
parents: 63
diff changeset
   683
#endif //HSWIDGETORGANIZER_ALGORITHM
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   684
        } else {
63
hgs
parents: 62
diff changeset
   685
            QRectF adjustWidgetPosition;
69
hgs
parents: 63
diff changeset
   686
            adjustWidgetPosition = visual->geometry();
63
hgs
parents: 62
diff changeset
   687
            adjustWidgetPosition.moveTopLeft(presentation.pos());
69
hgs
parents: 63
diff changeset
   688
            visual->setPos(adjustedWidgetPosition(adjustWidgetPosition));
hgs
parents: 63
diff changeset
   689
            visual->setZValue(presentation.zValue);
63
hgs
parents: 62
diff changeset
   690
            widget->savePresentation(); //Needed to follow pageMargin dynamic change
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   691
        }
62
hgs
parents: 55
diff changeset
   692
    }
69
hgs
parents: 63
diff changeset
   693
    
hgs
parents: 63
diff changeset
   694
#ifdef HSWIDGETORGANIZER_ALGORITHM
hgs
parents: 63
diff changeset
   695
    // sort new widgets in order
hgs
parents: 63
diff changeset
   696
    if (newWidgets.count()) {
hgs
parents: 63
diff changeset
   697
        // TODO: read from configuration? or just use height for portrait and width for landscape (currently only height is used)
hgs
parents: 63
diff changeset
   698
        sortOrder order(height);
hgs
parents: 63
diff changeset
   699
        if(orientation == Qt::Horizontal) {
hgs
parents: 63
diff changeset
   700
            order = width;
hgs
parents: 63
diff changeset
   701
        } 
hgs
parents: 63
diff changeset
   702
        sortWidgets(order, newWidgets);
hgs
parents: 63
diff changeset
   703
        // get rects for new widgets
hgs
parents: 63
diff changeset
   704
        QList<QRectF> newRects;
hgs
parents: 63
diff changeset
   705
        foreach (HsWidgetHost *newWidget, newWidgets) {
hgs
parents: 63
diff changeset
   706
            newRects << QRectF(QPointF(), newWidget->visual()->preferredSize());
hgs
parents: 63
diff changeset
   707
        }
hgs
parents: 63
diff changeset
   708
        
hgs
parents: 63
diff changeset
   709
        // get page rect
hgs
parents: 63
diff changeset
   710
        QRectF pageRect = contentGeometry();
hgs
parents: 63
diff changeset
   711
hgs
parents: 63
diff changeset
   712
        // scan existing widgets rects
hgs
parents: 63
diff changeset
   713
        QList<QRectF> existingRects;
hgs
parents: 63
diff changeset
   714
        foreach (HsWidgetHost *widget, mWidgets) {
hgs
parents: 63
diff changeset
   715
            if (!newWidgets.contains(widget)) {
hgs
parents: 63
diff changeset
   716
                existingRects << QRectF(widget->visual()->pos(), widget->visual()->preferredSize());
hgs
parents: 63
diff changeset
   717
            }
hgs
parents: 63
diff changeset
   718
        }
hgs
parents: 63
diff changeset
   719
         
hgs
parents: 63
diff changeset
   720
        // calculate new widget positions with "stuck 'em all"-algorithm
hgs
parents: 63
diff changeset
   721
        HsWidgetPositioningOnWidgetAdd *algorithm =
hgs
parents: 63
diff changeset
   722
            HsWidgetPositioningOnWidgetAdd::instance();
hgs
parents: 63
diff changeset
   723
        QList<QRectF> calculatedRects =
hgs
parents: 63
diff changeset
   724
            algorithm->convert(pageRect, existingRects, newRects, QPointF());
hgs
parents: 63
diff changeset
   725
hgs
parents: 63
diff changeset
   726
        for ( int i=0; i<newWidgets.count(); i++) {            
hgs
parents: 63
diff changeset
   727
            int j = mWidgets.indexOf(newWidgets.at(i));
hgs
parents: 63
diff changeset
   728
            mWidgets.at(j)->visual()->setGeometry(calculatedRects.at(i));
hgs
parents: 63
diff changeset
   729
            mWidgets.at(j)->savePresentation();            
hgs
parents: 63
diff changeset
   730
        }               
hgs
parents: 63
diff changeset
   731
    }    
hgs
parents: 63
diff changeset
   732
#endif //HSWIDGETORGANIZER_ALGORITHM
hgs
parents: 63
diff changeset
   733
    
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
   734
}
62
hgs
parents: 55
diff changeset
   735
63
hgs
parents: 62
diff changeset
   736
void HsPage::onPageMarginChanged(const QString &value)
62
hgs
parents: 55
diff changeset
   737
{
63
hgs
parents: 62
diff changeset
   738
    if (value == "pageMargin") {
hgs
parents: 62
diff changeset
   739
        mPageMargin = HSCONFIGURATION_GET(pageMargin);
69
hgs
parents: 63
diff changeset
   740
        HsWidgetHostVisual *visual(0);
63
hgs
parents: 62
diff changeset
   741
        if (!mWidgets.isEmpty()) {
hgs
parents: 62
diff changeset
   742
            foreach (HsWidgetHost *widget, mWidgets) {
69
hgs
parents: 63
diff changeset
   743
                visual = widget->visual();
hgs
parents: 63
diff changeset
   744
                visual->setPos(adjustedWidgetPosition(visual->geometry()));
63
hgs
parents: 62
diff changeset
   745
                widget->savePresentation();
hgs
parents: 62
diff changeset
   746
            }
hgs
parents: 62
diff changeset
   747
        }
hgs
parents: 62
diff changeset
   748
hgs
parents: 62
diff changeset
   749
        if (!mNewWidgets.isEmpty()) {
hgs
parents: 62
diff changeset
   750
            foreach (HsWidgetHost *widget, mNewWidgets) {
69
hgs
parents: 63
diff changeset
   751
                visual = widget->visual();
hgs
parents: 63
diff changeset
   752
                visual->setPos(adjustedWidgetPosition(visual->geometry()));
63
hgs
parents: 62
diff changeset
   753
                widget->savePresentation();
hgs
parents: 62
diff changeset
   754
            }
hgs
parents: 62
diff changeset
   755
        }
hgs
parents: 62
diff changeset
   756
    }
62
hgs
parents: 55
diff changeset
   757
}
69
hgs
parents: 63
diff changeset
   758
#ifdef HSWIDGETORGANIZER_ALGORITHM
hgs
parents: 63
diff changeset
   759
// TODO: sorting should be done in algorithm class, make widget<->rect mapping here and move sortWidgets function to algorithm side
hgs
parents: 63
diff changeset
   760
/*!
hgs
parents: 63
diff changeset
   761
    Sorts widgets in height/width order
hgs
parents: 63
diff changeset
   762
*/
hgs
parents: 63
diff changeset
   763
void HsPage::sortWidgets(sortOrder order, QList<HsWidgetHost*> &widgets)
hgs
parents: 63
diff changeset
   764
{
hgs
parents: 63
diff changeset
   765
    QList<HsWidgetHost*> tmpWidgets;
hgs
parents: 63
diff changeset
   766
hgs
parents: 63
diff changeset
   767
    for ( int i = 0; i < widgets.count(); i++) {
hgs
parents: 63
diff changeset
   768
        int index = 0;
hgs
parents: 63
diff changeset
   769
        // add first widget to sorted list
hgs
parents: 63
diff changeset
   770
        if (i == 0) {
hgs
parents: 63
diff changeset
   771
            tmpWidgets << widgets.at(i);
hgs
parents: 63
diff changeset
   772
        } else {
hgs
parents: 63
diff changeset
   773
            // go through existing widgets in the sorted list
hgs
parents: 63
diff changeset
   774
            for ( int j = 0; j < tmpWidgets.count(); j++) {
hgs
parents: 63
diff changeset
   775
                // sort widgets in height order
hgs
parents: 63
diff changeset
   776
                if (order == height) {
hgs
parents: 63
diff changeset
   777
                    /* if widgets heigth is smaller on already
hgs
parents: 63
diff changeset
   778
                       existing ones in the list -> increment index
hgs
parents: 63
diff changeset
   779
                    */
hgs
parents: 63
diff changeset
   780
                    if (widgets.at(i)->visual()->preferredHeight() <= tmpWidgets.at(j)->visual()->preferredHeight()) {
hgs
parents: 63
diff changeset
   781
                        index++;
hgs
parents: 63
diff changeset
   782
                    }
hgs
parents: 63
diff changeset
   783
                // sort widgets in width order
hgs
parents: 63
diff changeset
   784
                } else {
hgs
parents: 63
diff changeset
   785
                    /* if widgets width is smaller on already
hgs
parents: 63
diff changeset
   786
                       existing ones in the sorted list -> increment index
hgs
parents: 63
diff changeset
   787
                    */
hgs
parents: 63
diff changeset
   788
                    if (widgets.at(i)->visual()->preferredWidth() <= tmpWidgets.at(j)->visual()->preferredWidth()) {
hgs
parents: 63
diff changeset
   789
                        index++;
hgs
parents: 63
diff changeset
   790
                    }
hgs
parents: 63
diff changeset
   791
                }
hgs
parents: 63
diff changeset
   792
            }
hgs
parents: 63
diff changeset
   793
            // add widget to its correct index in sorted list
hgs
parents: 63
diff changeset
   794
            tmpWidgets.insert(index, widgets.at(i));
hgs
parents: 63
diff changeset
   795
        }
hgs
parents: 63
diff changeset
   796
    }
hgs
parents: 63
diff changeset
   797
    widgets = tmpWidgets;    
hgs
parents: 63
diff changeset
   798
}
hgs
parents: 63
diff changeset
   799
#endif //HSWIDGETORGANIZER_ALGORITHM