fixes and improvements
[Sak.git] / sak.h
blob24c382e9b03c19694efed532fe71d04d2968b41d
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 Task loadTaskFromFile(const QString& filePath);
48 void flush();
49 void flushSettings();
50 void open(const QStringList& filePaths = QStringList());
51 // void saveAsDb();
52 void exportDbCsv();
53 void logInGmail();
54 void saveToGmail();
55 void importFromGmail();
56 protected slots:
57 void init();
58 void destroy();
59 // tasks
60 void addDefaultTask();
61 void exportHits();
62 void populateTasks();
63 // commit changes on current tasks for temporary previews
64 void commitCurrentTask();
65 // permanentely save changes on tasks
66 void saveTaskChanges();
67 // permanentely save changes on hits
68 void saveHitChanges();
69 void selectedTask();
70 void doubleClickedTask(QTreeWidgetItem* i, int column);
71 void selectColor();
72 void grabKeyboard(); // delayed grab of keayboard
73 // popup task selection
74 void popup();
75 // popup subtask selection
76 void popupSubtasks(const QString& taskname);
77 // save current selected hit (after popup)
78 void workingOnTask(const QString& taskname, const QString& subtask);
79 void focusedSubTask();
80 void clearView();
81 void trayIconActivated(QSystemTrayIcon::ActivationReason);
82 // create a list of hits merging tasks
83 QList<HitElement> createHitsList(const QDateTime& from = QDateTime(), const QDateTime& to = QDateTime());
84 QMap<double, QPair<Task*, QString> > createSummaryList(const QList<HitElement>& hits);
85 void selectedStartDate(const QDate& date);
86 void selectedEndDate(const QDate& date);
87 void hitsListItemChanged(QTreeWidgetItem*, int column);
88 void hitsSelectedInList(QTreeWidgetItem*, QTreeWidgetItem*);
89 void hitsSelectedInTimeline(HitItem*);
90 void populateHitsList(const QList<HitElement>&, QTreeWidget* t = 0);
91 void populateHitsTimeline(const QList<HitElement>&, Timeline* t = 0);
92 void addDefaultHit();
93 void interactiveMergeHits();
94 private:
95 int m_timerId, m_timeoutPopup, m_autoSaveTimer, m_getFocusTimer;
96 bool m_stopped;
97 QDateTime m_nextTimerEvent;
98 QMainWindow* m_settings;
99 QHash<QString, Task> m_tasks;
100 QHash<QString, Task> m_editedTasks;
101 QMultiMap<int, SakWidget*> m_widgets;
102 QMultiMap<int, SakSubWidget*> m_subwidgets;
103 class QGraphicsEllipseItem* m_marker;
104 QMap<int, SakWidget*>::iterator m_widgetsIterator;
105 QMap<int, SakSubWidget*>::iterator m_subwidgetsIterator;
106 int m_subWidgetRank;
107 QList<QString> m_taskSelectionHistory;
108 QHash< QString, QList< QString > > m_subtaskSelectionHistory;
109 QCompleter* m_subtaskCompleter;
110 int m_currentInterval;
111 QRect m_desktopRect;
113 bool m_previewing;
114 bool m_changedHit, m_changedTask;
115 bool m_subtaskView;
116 static int taskCounter;
118 QAction* m_addTaskAction;
119 QMenu* m_addTaskMenu;
121 QMenu* m_addHitMenu;
122 QAction* m_addHitAction;
123 QAction* m_exportDataAction;
124 QString currentTask, currentSubtask;
125 class GView* m_view;
126 class Backupper* m_backupper;
127 class Incremental* m_incremental;
128 class GmailPyInterface* m_gmail;
130 //BEGIN Settings data:
131 public:
132 void setVisible(bool visible);
133 private:
134 QRect Layouting( const QList<SakWidget*>& sortedWidgets);
135 void layoutSubTasks( const QMap<int, SakSubWidget*> sortedWidgets, int currentRank);
137 QTreeWidget* newHitsList();
138 QTreeWidget* newTaskSummaryList();
139 void setupSettingsWidget();
140 void createActions();
142 void scrollTasks(int npos);
143 void scrollSubTasks(int npos);
145 QTabWidget* tabs;
146 QWidget* tab1;
147 QWidget* tab2;
148 QWidget* tab3;
149 QWidget* tab4;
150 QPushButton* previewButton;
151 QPushButton* bgColorButton;
152 QPushButton* fgColorButton;
154 QLabel *durationLabel, *durationLabel1;
155 QLabel *durationWarningLabel;
156 QLabel *bodyLabel;
157 QSpinBox *durationSpinBox;
158 QTextEdit *bodyEdit;
159 PixmapViewer* askingLady;
160 PixmapViewer* viewBackground;
163 QTreeWidget* tasksTree;
164 QComboBox* taskSelector;
165 QTreeWidget* hitsList, *summaryList;
166 Timeline* hitsTimeline;
167 QCalendarWidget* cal1, *cal2, *cal3, *cal4;
168 PixmapViewer* taskPixmapViewer;
169 QTextEdit* taskTextEditor;
170 QLineEdit* taskTitleEditor;
171 QLineEdit* taskTagsEditor;
172 QSpinBox* estimatedHoursEditor;
173 QDateEdit* dueEditor;
174 QGraphicsView* summaryView;
175 class TaskSummaryPieChart* summaryChart;
177 QAction *minimizeAction;
178 QAction *maximizeAction;
179 QAction *restoreAction;
180 QAction *startAction;
181 QAction *stopAction;
182 QAction *flushAction;
183 QAction *quitAction;
184 QAction *saveAsDbAction;
185 QAction *openAction;
186 QAction *exportDbCsvAction;
187 QAction *gmailLoginAction;
188 QAction *saveToGmailAction;
189 QAction *sendByEmailAction;
191 QSystemTrayIcon *trayIcon;
192 QMenu *trayIconMenu;
196 class MyDateItemDelegate : public QItemDelegate
198 public:
199 MyDateItemDelegate(QObject *parent = 0);
201 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
202 const QModelIndex &index) const;
204 void setEditorData(QWidget *editor, const QModelIndex &index) const;
205 void setModelData(QWidget *editor, QAbstractItemModel *model,
206 const QModelIndex &index) const;
208 void updateEditorGeometry(QWidget *editor,
209 const QStyleOptionViewItem &option, const QModelIndex &index) const;
212 class TaskItemDelegate : public QItemDelegate
214 public:
215 TaskItemDelegate(Sak* sak, QObject *parent = 0);
217 QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
218 const QModelIndex &index) const;
220 void setEditorData(QWidget *editor, const QModelIndex &index) const;
221 void setModelData(QWidget *editor, QAbstractItemModel *model,
222 const QModelIndex &index) const;
224 void updateEditorGeometry(QWidget *editor,
225 const QStyleOptionViewItem &option, const QModelIndex &index) const;
226 private:
227 Sak* m_sak;
231 class SubTaskItemDelegate : public QItemDelegate
233 public:
234 SubTaskItemDelegate(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;
251 #endif