File: TjGanttZoomStep.cpp

package info (click to toggle)
taskjuggler 2.3.0-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 8,764 kB
  • ctags: 3,700
  • sloc: cpp: 36,852; sh: 12,761; xml: 5,541; perl: 5,207; makefile: 269; python: 258; lisp: 67
file content (133 lines) | stat: -rw-r--r-- 3,043 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
 * The TaskJuggler Project Management Software
 *
 * Copyright (c) 2001, 2002, 2003, 2004, 2005 by Chris Schlaeger <cs@kde.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * $Id: TjGanttZoomStep.cpp 1307 2006-07-19 13:09:16Z cs $
 */

#include "TjGanttZoomStep.h"

#include <assert.h>

#include <qfontmetrics.h>

#include "Utility.h"

int
TjGanttZoomStep::getPixelsPerYear() const
{
    switch (stepUnit2)
    {
        case hour:
            return stepSize * 24 * 365;
        case day:
            return stepSize * 365;
        case week:
            return stepSize * 52;
        case month:
            return stepSize * 12;
        case quarter:
            return stepSize * 4;
        case year:
            return stepSize;
        default:
            assert(0);
    }

    return 0;
}
int
TjGanttZoomStep::calcStepSize(int ppyHint)
{
    QFontMetrics fm(font);
    int margin = (int) (0.2 * fm.height());
    int widthPattern1 = fm.width(pattern1) + 2 * margin + 1;
    int widthPattern2 = fm.width(pattern2) + 2 * margin + 1;

    // Now pick the wider one.
    int minWidth = widthPattern1 / ratio > widthPattern2 ?
        widthPattern1 / ratio : widthPattern2;

    int scaleFactor;
    switch (stepUnit2)
    {
        case hour:
            scaleFactor = 24 * 365;
            break;
        case day:
            scaleFactor = 365;
            break;
        case week:
            scaleFactor = 52;
            break;
        case month:
            scaleFactor = 12;
            break;
        case quarter:
            scaleFactor = 4;
            break;
        case year:
            scaleFactor = 1;
            break;
        default:
            assert(0);
    }
    stepSize = ppyHint / scaleFactor > minWidth ?
        ppyHint / scaleFactor : minWidth;

    return stepSize * scaleFactor;
}

time_t
TjGanttZoomStep::intervalStart(bool firstRow, time_t t)
{
    switch (firstRow ? stepUnit1 : stepUnit2)
    {
        case hour:
            return midnight(t);
        case day:
            return midnight(t);
        case week:
            return beginOfWeek(t, weekStartsMonday);
        case month:
            return beginOfMonth(t);
        case quarter:
            return beginOfQuarter(t);
        case year:
            return beginOfYear(t);
        default:
            assert(0);
    }

    return 0;
}

time_t
TjGanttZoomStep::nextIntervalStart(bool firstRow, time_t t)
{
    switch (firstRow ? stepUnit1 : stepUnit2)
    {
        case hour:
            return hoursLater(1, t);
        case day:
            return sameTimeNextDay(t);
        case week:
            return sameTimeNextWeek(t);
        case month:
            return sameTimeNextMonth(t);
        case quarter:
            return sameTimeNextQuarter(t);
        case year:
            return sameTimeNextYear(t);
        default:
            assert(0);
    }

    return 0;
}