summaryrefslogtreecommitdiffstats
path: root/digikam/digikam/timelinewidget.h
blob: bc865aeaf3380394d756475f65610e6568225d27 (plain)
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* ============================================================
 *
 * This file is a part of digiKam project
 * http://www.digikam.org
 *
 * Date        : 2007-12-08
 * Description : a widget to display date and time statistics of pictures
 *
 * Copyright (C) 2007-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
 *
 * This program is free software; you can redistribute it
 * and/or modify it under the terms of the GNU General
 * Public License as published by the Free Software Foundation;
 * either version 2, or (at your option)
 * any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * ============================================================ */

#ifndef TIMELINEWIDGET_H
#define TIMELINEWIDGET_H

// TQt includes.

#include <tqstring.h>
#include <tqwidget.h>
#include <tqdatetime.h>

// Local includes.

#include "ddebug.h"

namespace Digikam
{

typedef TQPair<TQDateTime, TQDateTime> DateRange;    // Range of a contigue dates selection <start date, end date>.
typedef TQValueList<DateRange> DateRangeList;      // List of dates range selected.

class TimeLineWidgetPriv;

class TimeLineWidget : public TQWidget
{
Q_OBJECT

public:

    enum TimeUnit 
    {
        Day = 0,
        Week,
        Month,
        Year
    };

    enum SelectionMode
    {
        Unselected=0,      // No selection.
        FuzzySelection,    // Partially selected.
        Selected           // Fully selected.
    };

    enum ScaleMode
    {
        LinScale=0,        // Linear scale.
        LogScale           // Logarithmic scale.
    };

public:

    TimeLineWidget(TQWidget *parent=0);
    ~TimeLineWidget();

    void      setTimeUnit(TimeUnit timeUnit);
    TimeUnit  timeUnit() const;

    void      setScaleMode(ScaleMode scaleMode);
    ScaleMode scaleMode() const;

    void      setCursorDateTime(const TQDateTime& dateTime);
    TQDateTime cursorDateTime() const;
    int       cursorInfo(TQString& infoDate);

    /** Return a list of Date-Range based on selection performed on days-map */
    DateRangeList selectedDateRange(int& totalCount);
    void          setSelectedDateRange(const DateRangeList& list);

    int  totalIndex();
    int  indexForRefDateTime();
    int  indexForCursorDateTime();
    void setCurrentIndex(int index);

signals:

    void signalCursorPositionChanged();
    void signalSelectionChanged();
    void signalRefDateTimeChanged();
    void signalDateMapChanged();

public slots:

    void slotDatesMap(const TQMap<TQDateTime, int>&);
    void slotPrevious();
    void slotNext();
    void slotBackward();
    void slotForward();
    void slotResetSelection();

private slots:

    void slotThemeChanged();

private:

    TQDateTime     prevDateTime(const TQDateTime& dt);
    TQDateTime     nextDateTime(const TQDateTime& dt);

    int           maxCount();
    int           indexForDateTime(const TQDateTime& date);
    int           statForDateTime(const TQDateTime& dt, SelectionMode& selected);
    void          setRefDateTime(const TQDateTime& dateTime);

    void          updatePixmap();
    void          paintEvent(TQPaintEvent*);
    void          resizeEvent(TQResizeEvent*);
    void          wheelEvent(TQWheelEvent*); 

    void          mousePressEvent(TQMouseEvent*);
    void          mouseMoveEvent(TQMouseEvent*);
    void          mouseReleaseEvent(TQMouseEvent*);

    TQDateTime     dateTimeForPoint(const TQPoint& pt, bool &isOnSelectionArea);
    TQDateTime     firstDayOfWeek(int year, int weekNumber);

    void          resetSelection();
    void          setDateTimeSelected(const TQDateTime& dt, SelectionMode selected);
    void          setDaysRangeSelection(const TQDateTime dts, const TQDateTime dte, SelectionMode selected);
    SelectionMode checkSelectionForDaysRange(const TQDateTime dts, const TQDateTime dte);
    void          updateWeekSelection(const TQDateTime dts, const TQDateTime dte);
    void          updateMonthSelection(const TQDateTime dts, const TQDateTime dte);
    void          updateYearSelection(const TQDateTime dts, const TQDateTime dte);
    void          updateAllSelection();

private:

    TimeLineWidgetPriv* d;
};

}  // NameSpace Digikam

#endif // TIMELINEWIDGET_H