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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
#include "loggermodewidget.h"
#include<QTableWidget>
#include <QFileDialog>
#include<QLabel>
#include<QGroupBox>
#include<QComboBox>
#include<QPushButton>
#include<QLineEdit>
#include<QTime>
#include<QTimer>
#include<QTextEdit>
#include<QCalendarWidget>
#include<QComboBox>
#include<QGridLayout>
#include<QMessageBox>
#include<QApplication>
#include<QTextStream>
#include<QCloseEvent>
struct LoggerModeWidgetData
{
QLabel *progressLabel;
QLabel *hoursWorkedLabel;
QLabel *dateLabel;
QLabel *descriptionLabel;
QCalendarWidget *calendar;
QComboBox *progressComboBox;
QLineEdit *hoursWorkedLineEdit;
QPushButton *startTimerButton;
QPushButton *stopTimerButton;
QPushButton *saveButton;
QTimer *timer;
QTextEdit *textEdit;
QString projectName;
int totalTime;
};
LoggerModeWidget::LoggerModeWidget(const QString projectName, QWidget* parent)
:QWidget(parent)
{
d = new LoggerModeWidgetData;
d->projectName = projectName;
d->totalTime = 0;
/*
// Catch hold of the plugin-manager
ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
// Look for the ProjectExplorerPlugin object
ProjectExplorer::ProjectExplorerPlugin* projectExplorerPlugin
= pm->getObject<ProjectExplorer::ProjectExplorerPlugin>();
// Fetch a list of all open projects
QList<ProjectExplorer::Project*> projects =projectExplorerPlugin->session()->projects();
Q_FOREACH(ProjectExplorer::Project* project, projects)
d->projectExplorerCombo->addItem( project->name());
*/
QStringList percentList;
percentList <<"10%" <<"20%" <<"30%" <<"40%" <<"50%"
<<"60%" <<"70%" <<"80%" <<"90%" <<"100%" ;
d->progressLabel = new QLabel("Progress:");
d->hoursWorkedLabel = new QLabel("Hours Worked:");
d->dateLabel = new QLabel("Date:");
d->descriptionLabel = new QLabel("Description :");
d->hoursWorkedLineEdit = new QLineEdit;
d->hoursWorkedLineEdit->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
d->progressComboBox = new QComboBox;
d->progressComboBox->addItems(percentList);
d->progressComboBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
d->startTimerButton = new QPushButton(tr("Start Timer"));
d->startTimerButton->setFixedWidth(80);
d->stopTimerButton = new QPushButton(tr("Pause Timer"));
d->stopTimerButton->setFixedWidth(80);
d->stopTimerButton->setCheckable(true);
d->textEdit = new QTextEdit(this);
d->textEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
d->calendar = new QCalendarWidget;
d->saveButton = new QPushButton(tr("Save To File"));
d->saveButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
QGroupBox *timeLoggerBox = new QGroupBox(tr("Time Logger"));
QGridLayout *gLayout = new QGridLayout;
gLayout->addWidget(d->dateLabel, 0, 0, 1, 1);
gLayout->addWidget(d->calendar, 1, 0, 1, 3);
gLayout->addWidget(d->progressLabel, 2, 0, 1, 1);
gLayout->addWidget(d->progressComboBox, 2, 1, 1, 1);
gLayout->addWidget(d->hoursWorkedLabel, 3, 0, 1, 1);
gLayout->addWidget(d->hoursWorkedLineEdit, 3, 1, 1, 1);
gLayout->addWidget(d->startTimerButton, 4, 1, 1, 1);
gLayout->addWidget(d->stopTimerButton, 4, 2, 1, 1);
timeLoggerBox->setLayout(gLayout);
d->timer = new QTimer(this);
//d->time.setHMS(0,0,0);
// connection of SIGNALS and SLOTS
connect(d->timer, SIGNAL(timeout()), this, SLOT(updateTime()));
connect(d->startTimerButton,SIGNAL(clicked()),this,SLOT(startTimeLog()));
connect(d->stopTimerButton,SIGNAL(clicked()),this,SLOT(endTimeLog()));
connect(d->saveButton, SIGNAL(clicked()), this, SLOT(saveToFile()));
QVBoxLayout *vLayout = new QVBoxLayout;
vLayout->addWidget(d->descriptionLabel);
vLayout->addWidget(d->textEdit);
QHBoxLayout * hLayout = new QHBoxLayout;
hLayout->addWidget(timeLoggerBox);
hLayout->addLayout(vLayout);
QHBoxLayout *bLayout = new QHBoxLayout;
bLayout->addStretch(1);
bLayout->addWidget(d->saveButton);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->addLayout(hLayout);
mainLayout->addLayout(bLayout);
mainLayout->addStretch(1);
}
LoggerModeWidget::~LoggerModeWidget()
{
delete d;
}
bool LoggerModeWidget::saveToFile()
{
QString fileName = QFileDialog::getSaveFileName(this);
if (fileName.isEmpty())
return false;
QFile file(fileName);
if (!file.open(QFile::WriteOnly | QFile::Text)) {
QMessageBox::critical(this, tr("Application"),
tr("Unable to open file %1 for writing :\n%2.")
.arg(fileName)
.arg(file.errorString()));
return false;
}
QTextStream out(&file);
#ifndef QT_NO_CURSOR
QApplication::setOverrideCursor(Qt::WaitCursor);
#endif
out << "Project name : " << d->projectName << "\n";
out << "Date : " << d->calendar->selectedDate().toString() << "\n";
out << "Progress : " << d->progressComboBox->currentText() << "\n";
out << "Duration : " << d->hoursWorkedLineEdit->text() << "\n\n";
out << "Description : " << d->textEdit->toPlainText();
#ifndef QT_NO_CURSOR
QApplication::restoreOverrideCursor();
#endif
return true;
}
void LoggerModeWidget::startTimeLog()
{
d->totalTime = 0;
d->timer->start(1000);
}
void LoggerModeWidget::endTimeLog()
{
if(d->stopTimerButton->isChecked())
{
d->stopTimerButton->setText("Continue Timer");
d->timer->stop();
}
else
{
d->stopTimerButton->setText("Pause Timer");
d->timer->start(1000);
}
}
void LoggerModeWidget::updateTime()
{
d->totalTime++;
QTime time(0,0,0);
time = time.addSecs(d->totalTime);
d->hoursWorkedLineEdit->setText(time.toString());
}
/*
void LoggerModeWidget::setProjectName(QString name)
{
d->projectName = name;
}
*/
|