| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright (C) 2024, KylinSoft Co., Ltd. |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Lesser General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 3 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this library. If not, see <https://www.gnu.org/licenses/>. |
| 17 |
* |
| 18 |
* Authors: Zhenyu Wang <[email protected]> |
| 19 |
* |
| 20 |
*/ |
| 21 |
|
| 22 |
#include "widget.h" |
| 23 |
#include "kclocktimer.h" |
| 24 |
#include <QBoxLayout> |
| 25 |
#include <QDebug> |
| 26 |
#include <QPushButton> |
| 27 |
|
| 28 |
using namespace kdk; |
| 29 |
|
| 30 |
Widget::Widget(QWidget *parent) |
| 31 |
: QWidget(parent) |
| 32 |
{ |
| 33 |
QVBoxLayout *vlayout = new QVBoxLayout(this); |
| 34 |
KClockTimer *clock = new KClockTimer(this); |
| 35 |
|
| 36 |
QHBoxLayout *hlayout = new QHBoxLayout(); |
| 37 |
QPushButton *btn1 = new QPushButton("开始"); |
| 38 |
QPushButton *btn2 = new QPushButton("停止"); |
| 39 |
QPushButton *btn3 = new QPushButton("复位"); |
| 40 |
QPushButton *btn4 = new QPushButton("继续"); |
| 41 |
QPushButton *btn5 = new QPushButton("计次"); |
| 42 |
|
| 43 |
hlayout->addWidget(btn1); |
| 44 |
hlayout->addWidget(btn2); |
| 45 |
vlayout->addWidget(clock); |
| 46 |
vlayout->addLayout(hlayout); |
| 47 |
|
| 48 |
hlayout = new QHBoxLayout(); |
| 49 |
hlayout->addWidget(btn3); |
| 50 |
hlayout->addWidget(btn4); |
| 51 |
vlayout->addLayout(hlayout); |
| 52 |
|
| 53 |
hlayout = new QHBoxLayout(); |
| 54 |
hlayout->addWidget(btn5); |
| 55 |
vlayout->addLayout(hlayout); |
| 56 |
|
| 57 |
connect(btn1, &QPushButton::clicked, clock, &KClockTimer::startStopwatch); |
| 58 |
connect(btn2, &QPushButton::clicked, clock, &KClockTimer::stopStopwatch); |
| 59 |
connect(btn3, &QPushButton::clicked, clock, &KClockTimer::resetStopwatch); |
| 60 |
connect(btn4, &QPushButton::clicked, clock, &KClockTimer::startStopwatch); |
| 61 |
connect(btn5, &QPushButton::clicked, this, [=] { |
| 62 |
qDebug() << clock->time(); |
| 63 |
}); |
| 64 |
|
| 65 |
// qint64 otherMilliseconds = stringToMilliseconds(otherTimeString); // 转换为毫秒数 |
| 66 |
|
| 67 |
// // 比较两个时间 |
| 68 |
// if (compareMilliseconds(currentMilliseconds, otherMilliseconds)) { |
| 69 |
// // currentMilliseconds小于otherMilliseconds |
| 70 |
// } else { |
| 71 |
// // currentMilliseconds大于或等于otherMilliseconds |
| 72 |
// } |
| 73 |
|
| 74 |
// setFixedSize(300,200); |
| 75 |
} |
| 76 |
|
| 77 |
Widget::~Widget() |
| 78 |
{ |
| 79 |
} |