]>
vaikene.ee Git - evaf/blob - src/apps/ScosTime/gui.cpp
1ea9ba1d744866a62f2a58dc7c023536d78a4009
2 * @file ScosTime/gui.cpp
3 * @brief GUI for the ScosTime application
6 * Copyright (c) 2012 Enar Vaikene
8 * This file is part of the eVaf C++ cross-platform application development framework.
10 * This file can be used under the terms of the GNU General Public License
11 * version 3.0 as published by the Free Software Foundation and appearing in
12 * the file LICENSE included in the packaging of this file. Please review the
13 * the following information to ensure the GNU General Public License version
14 * 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
16 * Alternatively, this file may be used in accordance with the Commercial License
17 * Agreement provided with the Software.
23 #include <Common/Globals>
24 #include <Common/iLogger>
25 #include <Common/iRegistry>
26 #include <SdiWindow/iSdiWindow>
32 VER_EXPORT_VERSION_INFO()
33 Q_EXPORT_PLUGIN2(VER_MODULE_NAME_STR
, eVaf::ScosTime::Module
)
36 //-------------------------------------------------------------------
39 using namespace eVaf::ScosTime
;
45 setObjectName(QString("%1.%2").arg(VER_MODULE_NAME_STR
).arg(__FUNCTION__
));
47 EVAF_INFO("%s created", qPrintable(objectName()));
52 EVAF_INFO("%s destroyed", qPrintable(objectName()));
55 bool Module::init(QString
const & args
)
59 // Get the main window interface and fill it with the widgets
60 SdiWindow::iSdiWindow
* win
= evafQueryInterface
<SdiWindow::iSdiWindow
>("iSdiWindow");
61 EVAF_TEST_X(win
, "No iSdiWindow interface");
63 Gui::Panel
* panel
= new Gui::Panel
;
64 win
->addPanel("PswGen", panel
);
66 QVBoxLayout
* v
= new QVBoxLayout
;
69 QGridLayout
* g
= new QGridLayout
;
71 g
->setColumnStretch(1, 2);
73 QLabel
* l
= new QLabel(tr("&Epoch:", VER_MODULE_NAME_STR
));
74 l
->setAlignment(Qt::AlignRight
| Qt::AlignVCenter
);
75 g
->addWidget(l
, 0, 0);
77 wEpoch
= new QComboBox
;
79 wEpoch
->setEditable(true);
80 wEpoch
->addItems(QStringList() << "1970-01-01T00:00:00.000" << "1999-08-22T00:00:00.000");
81 g
->addWidget(wEpoch
, 0, 1);
82 panel
->setFocusProxy(wEpoch
);
84 l
= new QLabel(tr("&Date/time:", VER_MODULE_NAME_STR
));
85 l
->setAlignment(Qt::AlignRight
| Qt::AlignVCenter
);
86 g
->addWidget(l
, 1, 0);
88 wDateTime
= new QLineEdit
;
89 l
->setBuddy(wDateTime
);
90 QRegExp
rxDateTime("^\\d{4}\\.\\d{3}\\.\\d{2}\\.\\d{2}\\.\\d{2}(\\.\\d{3})?$");
91 wDateTime
->setValidator(new QRegExpValidator(rxDateTime
, wDateTime
));
92 g
->addWidget(wDateTime
, 1, 1);
94 QPushButton
* btn
= new QPushButton(tr("Convert", VER_MODULE_NAME_STR
));
95 g
->addWidget(btn
, 1, 2);
96 connect(btn
, SIGNAL(clicked()), this, SLOT(dateTimeClicked()));
98 l
= new QLabel(tr("&HEX:", VER_MODULE_NAME_STR
));
99 l
->setAlignment(Qt::AlignRight
| Qt::AlignVCenter
);
100 g
->addWidget(l
, 2, 0);
102 wHex
= new QLineEdit
;
104 wHex
->setMaxLength(12);
105 wHex
->setInputMask(">HHHHHHHHhhhh");
106 g
->addWidget(wHex
, 2, 1);
108 btn
= new QPushButton(tr("Convert", VER_MODULE_NAME_STR
));
109 g
->addWidget(btn
, 2, 2);
110 connect(btn
, SIGNAL(clicked()), this, SLOT(hexClicked()));
114 QHBoxLayout
* h
= new QHBoxLayout
;
118 QAction
* a
= new QAction(panel
);
119 a
->setShortcut(Qt::Key_Escape
);
120 connect(a
, SIGNAL(triggered()), qApp
, SLOT(quit()));
125 EVAF_INFO("%s initialized", qPrintable(objectName()));
134 EVAF_INFO("%s finalized", qPrintable(objectName()));
137 QDateTime
Module::strToDateTime(QString
const & s
) const
139 QStringList tok
= s
.split(QChar('.'));
144 int year
= tok
.at(0).toInt(&ok
);
147 int days
= tok
.at(1).toInt(&ok
);
150 int hours
= tok
.at(2).toInt(&ok
);
153 int minutes
= tok
.at(3).toInt(&ok
);
156 int secs
= tok
.at(4).toInt(&ok
);
160 if (tok
.size() > 5) {
161 msecs
= tok
.at(5).toInt(&ok
);
166 QDate
dt(year
, 1, 1);
167 dt
= dt
.addDays(days
- 1);
169 return QDateTime(dt
, QTime(hours
, minutes
, secs
, msecs
), Qt::UTC
);
172 void Module::dateTimeClicked()
174 QDateTime epoch
= QDateTime::fromString(wEpoch
->currentText(), Qt::ISODate
);
175 epoch
.setTimeSpec(Qt::UTC
);
176 QDateTime tm
= strToDateTime(wDateTime
->text());
177 qint64 msecs
= epoch
.msecsTo(tm
);
178 quint32 coarse
= quint32(msecs
/ 1000);
179 quint32 fine
= quint32(rint(1000.0 * double(msecs
% 1000) * 58.0 / 885.0));
180 wHex
->setText(QString("%1%2").arg(coarse
, 8, 16, QChar('0')).arg(fine
, 4, 16, QChar('0')));
183 void Module::hexClicked()
186 int coarse
= wHex
->text().left(8).toLong(&ok
, 16);
190 if (wHex
->text().size() > 8)
191 fine
= wHex
->text().mid(8, 4).toLong(&ok
, 16);
195 QDateTime epoch
= QDateTime::fromString(wEpoch
->currentText(), Qt::ISODate
);
196 epoch
.setTimeSpec(Qt::UTC
);
197 QDateTime tm
= epoch
.addSecs(coarse
);
198 tm
= tm
.addMSecs(rint((double(fine
) / 58.0 * 885.0) / 1000.0));
199 wDateTime
->setText(QString("%1.%2.%3.%4.%5.%6")
200 .arg(tm
.date().year(), 4, 10, QChar('0'))
201 .arg(tm
.date().dayOfYear(), 3, 10, QChar('0'))
202 .arg(tm
.time().hour(), 2, 10, QChar('0'))
203 .arg(tm
.time().minute(), 2, 10, QChar('0'))
204 .arg(tm
.time().second(), 2, 10, QChar('0'))
205 .arg(tm
.time().msec(), 3, 10, QChar('0')));