limit subtask list
[Sak.git] / sak.h
blobb9f47e08205ec35279432cc42b7f74fb206cbdcb
1 /***************************************************************************
2 * Copyright (C) 2007 by Arrigo Zanette *
3 * zanettea@gmail.com *
4 ***************************************************************************/
7 #ifndef __SAK_H__
8 #define __SAK_H__
10 #include <QtGui>
11 #include <QFont>
12 #include <QList>
13 #include <QHash>
14 #include <QPair>
15 #include <QObject>
16 #include <QDateTime>
17 #include <QPixmap>
18 #include <QRectF>
19 #include <QDebug>
21 #include "task.h"
24 class SakWidget;
25 class SakSubWidget;
26 class SakMessageItem;
27 class PixmapViewer;
28 class Timeline;
29 class HitItem;
31 class Sak : public QObject
33 Q_OBJECT;
34 public:
35 Sak(QObject* parent = 0);
36 virtual ~Sak();
37 QHash<QString, Task>* tasks() { return &m_tasks; }
38 protected:
39 void timerEvent(QTimerEvent* e);
40 bool eventFilter(QObject* obj, QEvent* e);
41 bool taskTreeEventFilter(QEvent* e);
42 bool hitsListEventFilter(QEvent* e);
43 public slots:
44 void start();
45 void pause();
46 void stop();
47 void workingOn();
48 Task loadTaskFromFile(const QString& filePath, bool tryRecover=true);
49 // recover from error using backup file for given file taskXmlFile
50 Task recoverTaskFromBackup(QFile& taskXmlFile, const QString& error);
51 void flush();
52 void flushSettings();
53 void open(const QStringList& filePaths = QStringList());
54 // void saveAsDb();
55 void exportDbCsv();
56 void logInGmail();
57 void saveToGmail();
58 void importFromGmail();
59 void selectTodayDate();
60 void selectThisWeeDate();
61 void selectThisMonthDate();
62 void selectLastWeekDate();
63 void selectLastMonthDate();
64 protected slots:
65 void init();
66 void destroy();
67 // tasks
68 void addDefaultTask();
69 void exportHits();
70 void populateTasks();
71 // commit changes on current tasks for temporary previews
72 void commitCurrentTask();
73 // permanentely save changes on tasks
74 void saveTaskChanges();
75 // permanentely save changes on hits
76 void saveHitChanges();
77 void selectedTask();
78 void doubleClickedTask(QTreeWidgetItem* i, int column);
79 void selectColor();
80 void grabKeyboard(); // delayed grab of keayboard
81 // popup task selection
82 void popup();
83 // popup subtask selection
84 void popupSubtasks(const QString& taskname);
85 // save current selected hit (after popup)
86 void workingOnTask(const QString& taskname, const QString& subtask);
87 void focusedSubTask();
88 void clearView();
89 void trayIconActivated(QSystemTrayIcon::ActivationReason);
90 // create a list of hits merging tasks
91 QList<HitElement> createHitsList(const QDateTime& from = QDateTime(), const QDateTime& to = QDateTime());
92 QMap<double, QPair<Task*, QString> > createSummaryList(const QList<HitElement>& hits);
93 void selectedStartDate(const QDate& date);
94 void selectedEndDate(const QDate& date);
95 void hitsListItemChanged(QTreeWidgetItem*, int column);
96 void hitsSelectedInList(QTreeWidgetItem*, QTreeWidgetItem*);
97 void hitsSelectedInTimeline(HitItem*);
98 void populateHitsList(const QList<HitElement>&, QTreeWidget* t = 0);
99 void populateHitsTimeline(const QList<HitElement>&, Timeline* t = 0);
100 void addDefaultHit();
101 void interactiveMergeHits();
102 private:
103 int m_timerId, m_timeoutPopup, m_autoSaveTimer, m_getFocusTimer;
104 bool m_stopped;
105 QDateTime m_nextTimerEvent;
106 QMainWindow* m_settings;
107 QHash<QString, Task> m_tasks;
108 QHash<QString, Task> m_editedTasks;
109 QMultiMap<int, SakWidget*> m_widgets;
110 QMultiMap<int, SakSubWidget*> m_subwidgets;
111 class QGraphicsEllipseItem* m_marker;
112 QMap<int, SakWidget*>::iterator m_widgetsIterator;
113 QMap<int, SakSubWidget*>::iterator m_subwidgetsIterator;
114 int m_subWidgetRank;
115 QList<QString> m_taskSelectionHistory;
116 QHash< QString, QList< QString > > m_subtaskSelectionHistory;
117 QCompleter* m_subtaskCompleter;
118 int m_currentInterval;
119 QRect m_desktopRect;
121 double workingOnDeclared;
122 bool m_previewing;
123 bool m_changedHit, m_changedTask;
124 bool m_subtaskView;
125 static int taskCounter;
126 bool m_yesToBackup;
127 bool m_fakeClicking;
129 QAction* m_addTaskAction;
130 QMenu* m_addTaskMenu;
132 QMenu* m_addHitMenu;
133 QAction* m_addHitAction;
134 QAction* m_exportDataAction;
135 QString currentTask, currentSubtask;
136 class GView* m_view;
137 class Backupper* m_backupper;
138 class Incremental* m_incremental;
139 class GmailPyInterface* m_gmail;
141 //BEGIN Settings data:
142 public:
143 void setVisible(bool visible);
144 private:
145 QRect Layouting( const QList<SakWidget*>& sortedWidgets);
146 void layoutSubTasks( const QMap<int, SakSubWidget*> sortedWidgets, int currentRank);
148 QTreeWidget* newHitsList();
149 QTreeWidget* newTaskSummaryList();
150 void setupSettingsWidget();
151 void createActions();
153 void scrollTasks(int npos);
154 void scrollSubTasks(int npos);
156 QTabWidget* tabs;
157 QWidget* tab1;
158 QWidget* tab2;
159 QWidget* tab3;
160 QWidget* tab4;
161 QPushButton* previewButton;
162 QPushButton* bgColorButton;
163 QPushButton* fgColorButton;
165 QLabel *durationLabel, *durationLabel1;
166 QLabel *durationWarningLabel;
167 QLabel *bodyLabel;
168 QSpinBox *durationSpinBox;
169 QTextEdit *bodyEdit;
170 PixmapViewer* askingLady;
171 PixmapViewer* viewBackground;
174 QTreeWidget* tasksTree;
175 QComboBox* taskSelector;
176 QTreeWidget* hitsList, *summaryList;
177 Timeline* hitsTimeline;
178 QCalendarWidget* cal1, *cal2, *cal3, *cal4;
179 QPushButton* today1, *thisWeek1, *thisMonth1, *lastWeek1, *lastMonth1;
180 QPushButton* today2, *thisWeek2, *thisMonth2, *lastWeek2, *lastMonth2;
181 PixmapViewer* taskPixmapViewer;
182 QTextEdit* taskTextEditor;
183 QLineEdit* taskTitleEditor;
184 QLineEdit* taskTagsEditor;
185 QLineEdit* taskUrlEditor;
186 QSpinBox* estimatedHoursEditor;
187 QDateEdit* dueEditor;
188 QGraphicsView* summaryView;
189 class TaskSummaryPieChart* summaryChart;
191 QAction *minimizeAction;
192 QAction *maximizeAction;
193 QAction *restoreAction;
194 QAction *startAction;
195 QAction *stopAction;
196 QAction *workingOnAction;
197 QAction *flushAction;
198 QAction *quitAction;
199 QAction *saveAsDbAction;
200 QAction *openAction;
201 QAction *exportDbCsvAction;
202 QAction *gmailLoginAction;
203 QAction *saveToGmailAction;
204 QAction *sendByEmailAction;
206 QSystemTrayIcon *trayIcon;
207 QMenu *trayIconMenu;
209 QTimer *workingOnTimer;
211 /*! Avoids recursion and crash when updating hitList as a result of updating timeline */
212 bool m_updatingFromTimeline;
215 class MyDateItemDelegate : public QItemDelegate
217 public:
218 MyDateItemDelegate(QObject *parent = 0);
220 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
221 const QModelIndex &index) const;
223 void setEditorData(QWidget *editor, const QModelIndex &index) const;
224 void setModelData(QWidget *editor, QAbstractItemModel *model,
225 const QModelIndex &index) const;
227 void updateEditorGeometry(QWidget *editor,
228 const QStyleOptionViewItem &option, const QModelIndex &index) const;
231 class TaskItemDelegate : public QItemDelegate
233 public:
234 TaskItemDelegate(Sak* sak, QObject *parent = 0);
236 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
237 const QModelIndex &index) const;
239 void setEditorData(QWidget *editor, const QModelIndex &index) const;
240 void setModelData(QWidget *editor, QAbstractItemModel *model,
241 const QModelIndex &index) const;
243 void updateEditorGeometry(QWidget *editor,
244 const QStyleOptionViewItem &option, const QModelIndex &index) const;
245 private:
246 Sak* m_sak;
250 class SubTaskItemDelegate : public QItemDelegate
252 public:
253 SubTaskItemDelegate(Sak* sak, QObject *parent = 0);
255 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
256 const QModelIndex &index) const;
258 void setEditorData(QWidget *editor, const QModelIndex &index) const;
259 void setModelData(QWidget *editor, QAbstractItemModel *model,
260 const QModelIndex &index) const;
262 void updateEditorGeometry(QWidget *editor,
263 const QStyleOptionViewItem &option, const QModelIndex &index) const;
264 private:
265 Sak* m_sak;
270 #endif