summaryrefslogtreecommitdiff
path: root/core
authorkergoth <kergoth>2002-06-07 18:53:14 (UTC)
committer kergoth <kergoth>2002-06-07 18:53:14 (UTC)
commit640d964cfdc7467f6cacb513087cd3acda2c04f0 (patch) (unidiff)
tree9a784686c1795f8b1f81eb344598f3b549d43467 /core
parentdfb9c76738bb68e235114c5ad43dbd26a59b98ab (diff)
downloadopie-640d964cfdc7467f6cacb513087cd3acda2c04f0.zip
opie-640d964cfdc7467f6cacb513087cd3acda2c04f0.tar.gz
opie-640d964cfdc7467f6cacb513087cd3acda2c04f0.tar.bz2
Backing out unintentional merge from TT branch.
Diffstat (limited to 'core') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/layoutmanager.cpp177
-rw-r--r--core/pim/datebook/layoutmanager.h78
2 files changed, 0 insertions, 255 deletions
diff --git a/core/pim/datebook/layoutmanager.cpp b/core/pim/datebook/layoutmanager.cpp
deleted file mode 100644
index 23058ed..0000000
--- a/core/pim/datebook/layoutmanager.cpp
+++ b/dev/null
@@ -1,177 +0,0 @@
1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3**
4** This file is part of the Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "layoutmanager.h"
22
23static const int min_height = 15;
24
25LayoutItem::LayoutItem( const EffectiveEvent e ) : eevent(e) { }
26
27LayoutManager::LayoutManager(int w, int h) : width(w), height(h), maxWidth(w) { }
28
29LayoutManager::~LayoutManager() { }
30
31void LayoutManager::setSize(int w, int h)
32{
33 height = h;
34 maxWidth = width = w;
35 // with changed, re-init, re-layout items.
36 for (uint i = 0; i < mItems.count(); i++)
37 initializeGeometry(mItems.at(i));
38}
39
40void LayoutManager::setOccurances(QValueList<EffectiveEvent> &events)
41{
42 mItems.clear();
43
44 QValueListIterator<EffectiveEvent> it;
45 for ( it = events.begin(); it != events.end(); ++it ) {
46 addOccurance(*it);
47 }
48 layoutItems(TRUE);
49}
50
51void LayoutManager::addOccurance(EffectiveEvent &event)
52{
53 LayoutItem *i = new LayoutItem(event);
54 initializeGeometry(i);
55 addItem(i);
56}
57
58void LayoutManager::addItem(LayoutItem *i)
59{
60 mItems.resize(mItems.size() + 1);
61 mItems.insert(mItems.size() - 1, i);
62}
63
64void LayoutManager::layoutItems(bool resetMaxWidth)
65{
66 if (resetMaxWidth)
67 maxWidth = width;
68
69 int iCount = mItems.count();
70 int itemWidth = QMIN(width, maxWidth);
71 int n = 1;
72
73 if (width < 1)
74 return;
75 if (iCount < (width/4)) {
76 int i = 0;
77 while (i < iCount) {
78 LayoutItem *item = mItems.at(i);
79 int x = 0;
80 int xp = 0;
81 QRect geom = item->geometry();
82 geom.setX( x );
83 geom.setWidth(itemWidth);
84 while ( xp < n && intersects(item, geom)) {
85 x += itemWidth;
86 xp++;
87 geom.moveBy(itemWidth, 0);
88 }
89 if (xp >= n) {
90 n++;
91 itemWidth = QMIN(width / n, maxWidth);
92 i = 0; // Start again.
93 } else {
94 item->setGeometry( geom );
95 i++;
96 }
97 }
98 } else {
99 // alturnate algorithm. // same as above, but just overlap
100 // if fail.
101 itemWidth = 4;
102 n = width / itemWidth;
103 int i = 0;
104 int rovingXp = 0;
105 while (i < iCount) {
106 LayoutItem *item = mItems.at(i);
107 int x = 0;
108 int xp = 0;
109 QRect geom = item->geometry();
110 geom.setX( x );
111 geom.setWidth(itemWidth);
112 while ( xp < n && intersects(item, geom)) {
113 x += itemWidth;
114 xp++;
115 geom.moveBy(itemWidth, 0);
116 }
117 if (xp >= n) {
118 geom.setX(rovingXp * itemWidth);
119 geom.setWidth(itemWidth);
120 rovingXp++;
121 item->setGeometry( geom );
122 } else {
123 item->setGeometry( geom );
124 }
125 i++;
126 }
127 }
128 if (itemWidth < maxWidth)
129 maxWidth = itemWidth;
130}
131
132int LayoutManager::timeToHeight( const QTime &time ) const
133{
134 int y = time.hour() * 60 + time.minute();
135 if (y)
136 y = (y * (height / 24)) / 60;
137 return y;
138}
139
140QTime LayoutManager::heightToTime( int h ) const
141{
142 // broken
143 return QTime(0,0,0);
144}
145
146LayoutItem *LayoutManager::intersects(LayoutItem *item, QRect geom) const
147{
148 int i = 0;
149 // allow overlapping
150 geom.moveBy(1,1);
151 geom.setSize( geom.size() - QSize(2,2) );
152
153 LayoutItem *it = mItems.at(i);
154 int count = mItems.count();
155 while (i < count && it != item) {
156 if (it->geometry().intersects( geom ) )
157 return it;
158 it = mItems.at(++i);
159 }
160 return 0;
161}
162
163void LayoutManager::initializeGeometry(LayoutItem *item)
164{
165 int y = timeToHeight(item->occurance().start());
166 int yend = timeToHeight(item->occurance().end());
167
168 int h = yend - y;
169 if (h < min_height)
170 h = min_height;
171 if (y + min_height > height) {
172 y = height - min_height;
173 h = min_height;
174 }
175
176 item->setGeometry(QRect(0, y, width, h));
177}
diff --git a/core/pim/datebook/layoutmanager.h b/core/pim/datebook/layoutmanager.h
deleted file mode 100644
index 128f927..0000000
--- a/core/pim/datebook/layoutmanager.h
+++ b/dev/null
@@ -1,78 +0,0 @@
1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3**
4** This file is part of the Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include <qvector.h>
22#include <qvaluelist.h>
23#include <qrect.h>
24#include <qdatetime.h>
25#include <qpe/event.h>
26
27class LayoutItem
28{
29public:
30 LayoutItem( const EffectiveEvent e );
31
32 void setGeometry(const QRect &rect) { r = rect; }
33 void setGeometry(int x, int y, int w, int h)
34 { setGeometry(QRect(x,y,w,h)); }
35 QRect geometry() const { return r; }
36
37 EffectiveEvent occurance() const { return eevent; }
38 Event event() const { return eevent.event(); }
39
40private:
41 EffectiveEvent eevent;
42 QRect r;
43};
44
45class LayoutManager
46{
47public:
48 LayoutManager(int w, int h);
49 virtual ~LayoutManager();
50
51 void setSize(int w, int h);
52 void setMaximumColumnWidth(int x) { maxWidth = x; };
53 int maximumColumnWidth() const { return maxWidth; };
54 void setOccurances(QValueList<EffectiveEvent> &events);
55 virtual void addOccurance(EffectiveEvent &event);
56
57 void clear() { mItems.clear(); }
58
59 QVector<LayoutItem> items() const { return mItems; }
60 QSize size() const { return QSize(width, height); }
61 int count() const { return mItems.count(); }
62
63 virtual void layoutItems(bool resetMaxWidth = FALSE);
64
65 virtual int timeToHeight(const QTime &) const;
66 virtual QTime heightToTime(int) const;
67
68protected:
69 void initializeGeometry(LayoutItem *);
70 LayoutItem *intersects(LayoutItem *, QRect) const;
71 void addItem(LayoutItem *);
72
73private:
74 QVector<LayoutItem> mItems;
75 int width;
76 int height;
77 int maxWidth;
78};