~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to korganizer/views/monthview/monthgraphicsitems.h

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
  This file is part of KOrganizer.
3
 
 
4
 
  Copyright (c) 2008 Bruno Virlet <bruno.virlet@gmail.com>
5
 
  Copyright (c) 2008 Thomas Thrainer <tom_t@gmx.at>
6
 
 
7
 
  This program is free software; you can redistribute it and/or modify
8
 
  it under the terms of the GNU General Public License as published by
9
 
  the Free Software Foundation; either version 2 of the License, or
10
 
  (at your option) any later version.
11
 
 
12
 
  This program is distributed in the hope that it will be useful,
13
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 
  GNU General Public License for more details.
16
 
 
17
 
  You should have received a copy of the GNU General Public License along
18
 
  with this program; if not, write to the Free Software Foundation, Inc.,
19
 
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
 
 
21
 
  As a special exception, permission is given to link this program
22
 
  with any edition of Qt, and distribute the resulting executable,
23
 
  without including the source code for Qt in the source distribution.
24
 
*/
25
 
 
26
 
#ifndef MONTHGRAPHICSITEMS_H
27
 
#define MONTHGRAPHICSITEMS_H
28
 
 
29
 
#include <QHash>
30
 
#include <QGraphicsItem>
31
 
#include <QRect>
32
 
#include <QDate>
33
 
 
34
 
class QGraphicsScene;
35
 
class QStyleOptionGraphicsItem;
36
 
class QPainterPath;
37
 
 
38
 
namespace KOrg {
39
 
 
40
 
class MonthItem;
41
 
 
42
 
/**
43
 
 * Graphics items which indicates that the view can be scrolled to display
44
 
 * more events.
45
 
 */
46
 
class ScrollIndicator : public QGraphicsItem
47
 
{
48
 
  public:
49
 
    enum ArrowDirection {
50
 
      UpArrow,
51
 
      DownArrow
52
 
    };
53
 
 
54
 
    ScrollIndicator( ArrowDirection direction );
55
 
 
56
 
    QRectF boundingRect() const;
57
 
    void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget );
58
 
 
59
 
    ArrowDirection direction() { return mDirection; }
60
 
 
61
 
  private:
62
 
    ArrowDirection mDirection;
63
 
 
64
 
    static const int mWidth = 30;
65
 
    static const int mHeight = 10;
66
 
};
67
 
 
68
 
/**
69
 
 * Keeps information about a month cell.
70
 
 */
71
 
class MonthCell
72
 
{
73
 
  public:
74
 
    MonthCell( int id, QDate date, QGraphicsScene *scene );
75
 
    ~MonthCell();
76
 
 
77
 
    /**
78
 
      This is used to get the height of the minimum height (vertical position)
79
 
      in the month cells.
80
 
    */
81
 
    QList<MonthItem *> mMonthItemList;
82
 
 
83
 
    QHash<int, MonthItem *> mHeightHash;
84
 
 
85
 
    int firstFreeSpace();
86
 
    void addMonthItem( MonthItem *manager, int height );
87
 
 
88
 
    int id() const { return mId; }
89
 
    QDate date() const { return mDate; }
90
 
 
91
 
    int x() const {
92
 
      return mId % 7;
93
 
    }
94
 
 
95
 
    int y() const {
96
 
      return mId / 7;
97
 
    }
98
 
 
99
 
    static int topMargin();
100
 
    // returns true if the cell contains events below the height @p height
101
 
    bool hasEventBelow( int height );
102
 
 
103
 
    // TODO : move this to a new GUI class (monthcell could be GraphicsItems)
104
 
    ScrollIndicator *upArrow() { return mUpArrow; }
105
 
    ScrollIndicator *downArrow() { return mDownArrow; }
106
 
 
107
 
  private:
108
 
    int mId;
109
 
    QDate mDate;
110
 
 
111
 
    QGraphicsScene *mScene;
112
 
 
113
 
    ScrollIndicator *mUpArrow;
114
 
    ScrollIndicator *mDownArrow;
115
 
};
116
 
 
117
 
/**
118
 
 * A MonthGraphicsItem representing a part of an event. There should be
119
 
 * one part per row = week
120
 
 */
121
 
class MonthGraphicsItem : public QObject, public QGraphicsItem
122
 
{
123
 
  Q_OBJECT
124
 
  Q_INTERFACES(QGraphicsItem)
125
 
 
126
 
  public:
127
 
    typedef QList<MonthGraphicsItem *> List;
128
 
 
129
 
    MonthGraphicsItem( MonthItem *manager );
130
 
    ~MonthGraphicsItem();
131
 
 
132
 
    /**
133
 
      Change QGraphicsItem pos and boundingRect in the scene
134
 
      according to the incidence start and end date.
135
 
    */
136
 
    void updateGeometry();
137
 
 
138
 
    /**
139
 
      Returns the associated MonthItem.
140
 
    */
141
 
    MonthItem *monthItem() const { return mMonthItem; }
142
 
 
143
 
    /**
144
 
      Returns the starting date of this item.
145
 
    */
146
 
    QDate startDate() const;
147
 
 
148
 
    /**
149
 
      Returns the number of day this item spans on minus one
150
 
      to be compatible with QDate::addDays().
151
 
    */
152
 
    int daySpan() const;
153
 
 
154
 
    /**
155
 
      Computed from startDate() and daySpan().
156
 
    */
157
 
    QDate endDate() const;
158
 
 
159
 
    void setStartDate( const QDate &d );
160
 
    void setDaySpan( int span );
161
 
 
162
 
    /**
163
 
      Returns true if this item is currently being moved (ie. the
164
 
      associated MonthItem is being moved).
165
 
    */
166
 
    bool isMoving() const;
167
 
 
168
 
    /**
169
 
      Returns true if this item is currently being resized (ie. the
170
 
      associated MonthItem is being moved).
171
 
    */
172
 
    bool isResizing() const;
173
 
 
174
 
    /**
175
 
      Returns true if this MonthGraphicsItem is the first one of the
176
 
      MonthItem ones.
177
 
    */
178
 
    bool isBeginItem() const;
179
 
 
180
 
    /**
181
 
      Returns true if this MonthGraphicsItem is the last one of the
182
 
      MonthItem ones.
183
 
    */
184
 
    bool isEndItem() const;
185
 
 
186
 
    /**
187
 
      Reimplemented from QGraphicsItem
188
 
    */
189
 
    virtual QRectF boundingRect() const;
190
 
    virtual void paint( QPainter *, const QStyleOptionGraphicsItem *, QWidget * );
191
 
    virtual QPainterPath shape() const;
192
 
 
193
 
  private:
194
 
    // Shape of the item, see shape()
195
 
    QPainterPath widgetPath( bool border ) const;
196
 
 
197
 
    // See startDate()
198
 
    QDate mStartDate;
199
 
 
200
 
    // See daySpan()
201
 
    int mDaySpan;
202
 
 
203
 
    // The current item is part of a MonthItem
204
 
    MonthItem *mMonthItem;
205
 
};
206
 
 
207
 
}
208
 
 
209
 
#endif //MONTHGRAPHICSITEMS_H