]>
vaikene.ee Git - evaf/blob - src/apps/ScosTime/gui.cpp
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.
22 #include <Common/Globals>
23 #include <Common/iLogger>
24 #include <Common/iRegistry>
25 #include <SdiWindow/iSdiWindow>
31 VER_EXPORT_VERSION_INFO()
34 //-------------------------------------------------------------------
37 using namespace eVaf::ScosTime
;
43 setObjectName(QString("%1.%2").arg(VER_MODULE_NAME_STR
).arg(__FUNCTION__
));
45 EVAF_INFO("%s created", qPrintable(objectName()));
50 EVAF_INFO("%s destroyed", qPrintable(objectName()));
53 bool Module::init(QString
const & args
)
57 // Get the main window interface and fill it with the widgets
58 SdiWindow::iSdiWindow
* win
= evafQueryInterface
<SdiWindow::iSdiWindow
>("iSdiWindow");
59 EVAF_TEST_X(win
, "No iSdiWindow interface");
61 Gui::Panel
* panel
= new Gui::Panel
;
62 win
->addPanel("PswGen", panel
);
64 QVBoxLayout
* v
= new QVBoxLayout
;
67 QGridLayout
* g
= new QGridLayout
;
69 g
->setColumnStretch(1, 2);
71 QLabel
* l
= new QLabel(tr("&Epoch:", VER_MODULE_NAME_STR
));
72 l
->setAlignment(Qt::AlignRight
| Qt::AlignVCenter
);
73 g
->addWidget(l
, 0, 0);
75 wEpoch
= new QComboBox
;
77 wEpoch
->setEditable(true);
78 wEpoch
->addItems(QStringList() << "1970-01-01T00:00:00.000" << "1999-08-22T00:00:00.000");
79 g
->addWidget(wEpoch
, 0, 1);
80 panel
->setFocusProxy(wEpoch
);
82 l
= new QLabel(tr("&Date/time:", VER_MODULE_NAME_STR
));
83 l
->setAlignment(Qt::AlignRight
| Qt::AlignVCenter
);
84 g
->addWidget(l
, 1, 0);
86 wDateTime
= new QLineEdit
;
87 l
->setBuddy(wDateTime
);
88 QRegExp
rxDateTime("^\\d{4}\\.\\d{3}\\.\\d{2}\\.\\d{2}\\.\\d{2}(\\.\\d{3})?$");
89 wDateTime
->setValidator(new QRegExpValidator(rxDateTime
, wDateTime
));
90 g
->addWidget(wDateTime
, 1, 1);
92 QPushButton
* btn
= new QPushButton(tr("Convert", VER_MODULE_NAME_STR
));
93 g
->addWidget(btn
, 1, 2);
94 connect(btn
, SIGNAL(clicked()), this, SLOT(dateTimeClicked()));
96 l
= new QLabel(tr("&HEX:", VER_MODULE_NAME_STR
));
97 l
->setAlignment(Qt::AlignRight
| Qt::AlignVCenter
);
98 g
->addWidget(l
, 2, 0);
100 wHex
= new QLineEdit
;
102 wHex
->setMaxLength(12);
103 wHex
->setInputMask(">HHHHHHHHhhhh");
104 g
->addWidget(wHex
, 2, 1);
106 btn
= new QPushButton(tr("Convert", VER_MODULE_NAME_STR
));
107 g
->addWidget(btn
, 2, 2);
108 connect(btn
, SIGNAL(clicked()), this, SLOT(hexClicked()));
112 QHBoxLayout
* h
= new QHBoxLayout
;
116 QAction
* a
= new QAction(panel
);
117 a
->setShortcut(Qt::Key_Escape
);
118 connect(a
, SIGNAL(triggered()), qApp
, SLOT(quit()));
123 EVAF_INFO("%s initialized", qPrintable(objectName()));
132 EVAF_INFO("%s finalized", qPrintable(objectName()));
135 QDateTime
Module::strToDateTime(QString
const & s
) const
137 QStringList tok
= s
.split(QChar('.'));
142 int year
= tok
.at(0).toInt(&ok
);
145 int days
= tok
.at(1).toInt(&ok
);
148 int hours
= tok
.at(2).toInt(&ok
);
151 int minutes
= tok
.at(3).toInt(&ok
);
154 int secs
= tok
.at(4).toInt(&ok
);
158 if (tok
.size() > 5) {
159 msecs
= tok
.at(5).toInt(&ok
);
164 QDate
dt(year
, 1, 1);
165 dt
= dt
.addDays(days
- 1);
167 return QDateTime(dt
, QTime(hours
, minutes
, secs
, msecs
), Qt::UTC
);
170 void Module::dateTimeClicked()
172 QDateTime epoch
= QDateTime::fromString(wEpoch
->currentText(), Qt::ISODate
);
173 epoch
.setTimeSpec(Qt::UTC
);
174 QDateTime tm
= strToDateTime(wDateTime
->text());
175 qint64 msecs
= epoch
.msecsTo(tm
);
176 quint32 coarse
= quint32(msecs
/ 1000);
177 quint32 fine
= quint32(rint(1000.0 * double(msecs
% 1000) * 58.0 / 885.0));
178 wHex
->setText(QString("%1%2").arg(coarse
, 8, 16, QChar('0')).arg(fine
, 4, 16, QChar('0')));
181 void Module::hexClicked()
184 int coarse
= wHex
->text().left(8).toLong(&ok
, 16);
188 if (wHex
->text().size() > 8)
189 fine
= wHex
->text().mid(8, 4).toLong(&ok
, 16);
193 QDateTime epoch
= QDateTime::fromString(wEpoch
->currentText(), Qt::ISODate
);
194 epoch
.setTimeSpec(Qt::UTC
);
195 QDateTime tm
= epoch
.addSecs(coarse
);
196 tm
= tm
.addMSecs(rint((double(fine
) / 58.0 * 885.0) / 1000.0));
197 wDateTime
->setText(QString("%1.%2.%3.%4.%5.%6")
198 .arg(tm
.date().year(), 4, 10, QChar('0'))
199 .arg(tm
.date().dayOfYear(), 3, 10, QChar('0'))
200 .arg(tm
.time().hour(), 2, 10, QChar('0'))
201 .arg(tm
.time().minute(), 2, 10, QChar('0'))
202 .arg(tm
.time().second(), 2, 10, QChar('0'))
203 .arg(tm
.time().msec(), 3, 10, QChar('0')));