1 /***************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the documentation of Qt Creator.
9 ** You may use this file under the terms of the BSD license as follows:
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
14 ** * Redistributions of source code must retain the above copyright
15 ** notice, this list of conditions and the following disclaimer.
16 ** * Redistributions in binary form must reproduce the above copyright
17 ** notice, this list of conditions and the following disclaimer in
18 ** the documentation and/or other materials provided with the
20 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
21 ** the names of its contributors may be used to endorse or promote
22 ** products derived from this software without specific prior written
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
37 ****************************************************************************/
39 #include "loggermodewidget.h"
40 #include<QTableWidget>
41 #include <QFileDialog>
50 #include<QCalendarWidget>
54 #include<QApplication>
58 struct LoggerModeWidgetData
60 QLabel *progressLabel;
61 QLabel *hoursWorkedLabel;
63 QLabel *descriptionLabel;
64 QCalendarWidget *calendar;
65 QComboBox *progressComboBox;
66 QLineEdit *hoursWorkedLineEdit;
67 QPushButton *startTimerButton;
68 QPushButton *stopTimerButton;
69 QPushButton *saveButton;
76 LoggerModeWidget::LoggerModeWidget(const QString projectName, QWidget* parent)
79 d = new LoggerModeWidgetData;
80 d->projectName = projectName;
83 // Catch hold of the plugin-manager
84 ExtensionSystem::PluginManager* pm = ExtensionSystem::PluginManager::instance();
86 // Look for the ProjectExplorerPlugin object
87 ProjectExplorer::ProjectExplorerPlugin* projectExplorerPlugin
88 = pm->getObject<ProjectExplorer::ProjectExplorerPlugin>();
90 // Fetch a list of all open projects
91 QList<ProjectExplorer::Project*> projects =projectExplorerPlugin->session()->projects();
92 Q_FOREACH(ProjectExplorer::Project* project, projects)
93 d->projectExplorerCombo->addItem( project->name());
95 QStringList percentList;
96 percentList <<"10%" <<"20%" <<"30%" <<"40%" <<"50%"
97 <<"60%" <<"70%" <<"80%" <<"90%" <<"100%" ;
98 d->progressLabel = new QLabel("Progress:");
99 d->hoursWorkedLabel = new QLabel("Hours Worked:");
100 d->dateLabel = new QLabel("Date:");
101 d->descriptionLabel = new QLabel("Description :");
102 d->hoursWorkedLineEdit = new QLineEdit;
103 d->hoursWorkedLineEdit->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
104 d->progressComboBox = new QComboBox;
105 d->progressComboBox->addItems(percentList);
106 d->progressComboBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
107 d->startTimerButton = new QPushButton(tr("Start Timer"));
108 d->startTimerButton->setFixedWidth(80);
109 d->stopTimerButton = new QPushButton(tr("Pause Timer"));
110 d->stopTimerButton->setFixedWidth(80);
111 d->stopTimerButton->setCheckable(true);
112 d->textEdit = new QTextEdit(this);
113 d->textEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
114 d->calendar = new QCalendarWidget;
115 d->saveButton = new QPushButton(tr("Save To File"));
116 d->saveButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
118 QGroupBox *timeLoggerBox = new QGroupBox(tr("Time Logger"));
120 QGridLayout *gLayout = new QGridLayout;
121 gLayout->addWidget(d->dateLabel, 0, 0, 1, 1);
122 gLayout->addWidget(d->calendar, 1, 0, 1, 3);
123 gLayout->addWidget(d->progressLabel, 2, 0, 1, 1);
124 gLayout->addWidget(d->progressComboBox, 2, 1, 1, 1);
125 gLayout->addWidget(d->hoursWorkedLabel, 3, 0, 1, 1);
126 gLayout->addWidget(d->hoursWorkedLineEdit, 3, 1, 1, 1);
127 gLayout->addWidget(d->startTimerButton, 4, 1, 1, 1);
128 gLayout->addWidget(d->stopTimerButton, 4, 2, 1, 1);
129 timeLoggerBox->setLayout(gLayout);
131 d->timer = new QTimer(this);
132 //d->time.setHMS(0,0,0);
134 // connection of SIGNALS and SLOTS
136 connect(d->timer, SIGNAL(timeout()), this, SLOT(updateTime()));
137 connect(d->startTimerButton,SIGNAL(clicked()),this,SLOT(startTimeLog()));
138 connect(d->stopTimerButton,SIGNAL(clicked()),this,SLOT(endTimeLog()));
139 connect(d->saveButton, SIGNAL(clicked()), this, SLOT(saveToFile()));
142 QVBoxLayout *vLayout = new QVBoxLayout;
143 vLayout->addWidget(d->descriptionLabel);
144 vLayout->addWidget(d->textEdit);
146 QHBoxLayout * hLayout = new QHBoxLayout;
147 hLayout->addWidget(timeLoggerBox);
148 hLayout->addLayout(vLayout);
150 QHBoxLayout *bLayout = new QHBoxLayout;
151 bLayout->addStretch(1);
152 bLayout->addWidget(d->saveButton);
154 QVBoxLayout *mainLayout = new QVBoxLayout(this);
155 mainLayout->addLayout(hLayout);
156 mainLayout->addLayout(bLayout);
157 mainLayout->addStretch(1);
161 LoggerModeWidget::~LoggerModeWidget()
166 bool LoggerModeWidget::saveToFile()
168 QString fileName = QFileDialog::getSaveFileName(this);
169 if (fileName.isEmpty())
172 QFile file(fileName);
173 if (!file.open(QFile::WriteOnly | QFile::Text)) {
174 QMessageBox::critical(this, tr("Application"),
175 tr("Unable to open file %1 for writing :\n%2.")
177 .arg(file.errorString()));
181 QTextStream out(&file);
184 QApplication::setOverrideCursor(Qt::WaitCursor);
186 out << "Project name : " << d->projectName << "\n";
187 out << "Date : " << d->calendar->selectedDate().toString() << "\n";
188 out << "Progress : " << d->progressComboBox->currentText() << "\n";
189 out << "Duration : " << d->hoursWorkedLineEdit->text() << "\n\n";
190 out << "Description : " << d->textEdit->toPlainText();
192 QApplication::restoreOverrideCursor();
198 void LoggerModeWidget::startTimeLog()
201 d->timer->start(1000);
204 void LoggerModeWidget::endTimeLog()
206 if(d->stopTimerButton->isChecked())
208 d->stopTimerButton->setText("Continue Timer");
213 d->stopTimerButton->setText("Pause Timer");
214 d->timer->start(1000);
218 void LoggerModeWidget::updateTime()
222 time = time.addSecs(d->totalTime);
223 d->hoursWorkedLineEdit->setText(time.toString());
226 void LoggerModeWidget::setProjectName(QString name)
228 d->projectName = name;