diff --git a/ClockCounter/ClockCounter.cpp b/ClockCounter/ClockCounter.cpp index 2519d81..ce88718 100644 --- a/ClockCounter/ClockCounter.cpp +++ b/ClockCounter/ClockCounter.cpp @@ -1,10 +1,13 @@ #include "ClockCounter.h" -ClockCounter::ClockCounter(QWidget *parent) - : QMainWindow(parent) +ClockCounter::ClockCounter(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); + ui.SpliterHourMinute->Init(UDateTimeSpliter::Type::Time); + ui.SpliterMinuteSecond->Init(UDateTimeSpliter::Type::Time); + ui.SpliterSecondMS->Init(UDateTimeSpliter::Type::Dots); } ClockCounter::~ClockCounter() -{} +{ +} \ No newline at end of file diff --git a/ClockCounter/ClockCounter.ui b/ClockCounter/ClockCounter.ui index a05338c..a64b635 100644 --- a/ClockCounter/ClockCounter.ui +++ b/ClockCounter/ClockCounter.ui @@ -1,28 +1,215 @@ - + + ClockCounterClass - - - ClockCounterClass - - + + 0 0 - 600 - 400 + 980 + 269 - + + + 0 + 0 + + + ClockCounter - - - - + + + + + + 10 + 20 + 81 + 141 + + + + + + + 90 + 20 + 81 + 141 + + + + + + + 170 + 20 + 81 + 141 + + + + + + + 410 + 20 + 81 + 141 + + + + + + + 330 + 20 + 81 + 141 + + + + + + + 250 + 20 + 81 + 141 + + + + + + + 650 + 20 + 81 + 141 + + + + + + + 490 + 20 + 81 + 141 + + + + + + + 570 + 20 + 81 + 141 + + + + + + + 890 + 20 + 81 + 141 + + + + + + + 730 + 20 + 81 + 141 + + + + + + + 810 + 20 + 81 + 141 + + + + + + + 20 + 190 + 181 + 61 + + + + 开始计时 + + + + + + 290 + 190 + 181 + 61 + + + + 停止计时 + + + + + + 540 + 190 + 181 + 61 + + + + 获取预点击坐标 + + + + + + 780 + 190 + 181 + 61 + + + + 清除预点击坐标 + + + - - + + + + LcdNumber + QWidget +
lcdnumber.h
+
+ + UDateTimeSpliter + QWidget +
udatetimespliter.h
+ 1 +
+
- + -
+
diff --git a/ClockCounter/ClockCounter.vcxproj b/ClockCounter/ClockCounter.vcxproj index d8ff441..ff49810 100644 --- a/ClockCounter/ClockCounter.vcxproj +++ b/ClockCounter/ClockCounter.vcxproj @@ -15,8 +15,7 @@ QtVS_v304 10.0.22621.0 10.0.22621.0 - $(MSBuildProjectDirectory)\QtMsBuild + $(MSBuildProjectDirectory)\QtMsBuild @@ -41,11 +40,8 @@ core;gui;widgets release - - + + @@ -61,7 +57,14 @@ + F:\QtGUIlib\qucsdk\include;$(IncludePath) + F:\QtGUIlib\qucsdk\bin;$(LibraryPath) + + + quc.lib;%(AdditionalDependencies) + + true @@ -89,12 +92,20 @@ - - - - - - + + + + + + + + + + + + + + diff --git a/ClockCounter/ClockCounter.vcxproj.filters b/ClockCounter/ClockCounter.vcxproj.filters index f2b8a34..c8175d2 100644 --- a/ClockCounter/ClockCounter.vcxproj.filters +++ b/ClockCounter/ClockCounter.vcxproj.filters @@ -35,14 +35,29 @@ Source Files - - - - Resource Files - - - Resource Files - - - + + + Source Files + + + Source Files + + + Source Files + + + + + Form Files + + + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/ClockCounter/PreClick.cpp b/ClockCounter/PreClick.cpp new file mode 100644 index 0000000..75fa961 --- /dev/null +++ b/ClockCounter/PreClick.cpp @@ -0,0 +1,10 @@ +#include "PreClick.h" + +PreClick::PreClick(QWidget* parent) : QMainWindow(parent) +{ + ui.setupUi(this); +} + +PreClick::~PreClick() +{ +} diff --git a/ClockCounter/PreClick.h b/ClockCounter/PreClick.h new file mode 100644 index 0000000..2cd6b27 --- /dev/null +++ b/ClockCounter/PreClick.h @@ -0,0 +1,16 @@ +#pragma once +#include +#include "ui_PreClick.h" + +class PreClick : public QMainWindow +{ + Q_OBJECT; + +public: + PreClick(QWidget* parent = nullptr); + ~PreClick(); + +private: + Ui::PreClickWindow ui; +}; + diff --git a/ClockCounter/PreClick.ui b/ClockCounter/PreClick.ui new file mode 100644 index 0000000..8cac106 --- /dev/null +++ b/ClockCounter/PreClick.ui @@ -0,0 +1,151 @@ + + + PreClickWindow + + + + 0 + 0 + 323 + 382 + + + + MainWindow + + + + + + 10 + 10 + 301 + 181 + + + + 预点击坐标 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + 70 + 30 + 111 + 41 + + + + + + + 20 + 40 + 31 + 16 + + + + X + + + Qt::AlignCenter + + + + + + 70 + 100 + 111 + 41 + + + + + + + 20 + 110 + 31 + 16 + + + + Y + + + Qt::AlignCenter + + + + + + 200 + 30 + 75 + 111 + + + + 获取坐标 + + + + + + + 10 + 210 + 301 + 101 + + + + 预点击次数 + + + + + 20 + 30 + 261 + 51 + + + + + + + + 20 + 330 + 91 + 41 + + + + 确定 + + + + + + 210 + 330 + 91 + 41 + + + + 取消 + + + + + + + diff --git a/ClockCounter/UDateTimeSpliter.cpp b/ClockCounter/UDateTimeSpliter.cpp new file mode 100644 index 0000000..727d9c9 --- /dev/null +++ b/ClockCounter/UDateTimeSpliter.cpp @@ -0,0 +1,140 @@ +#include "UDateTimeSpliter.h" + +UDateTimeSpliter::UDateTimeSpliter(QWidget* parent) : QWidget(parent) +{ + ItemType = Type::Empty; + TextColor1 = QColor(100, 184, 255, 255); + TextColor2 = QColor(79, 148, 205, 255); + Background1 = QColor(100, 100, 100, 255); + Background2 = QColor(60, 60, 60, 255); + return; +} + +UDateTimeSpliter::Triangle UDateTimeSpliter::GetTriangle(QPoint start, bool left, int xsize, int ysize) +{ + QPolygon triangle; + int y_half = ysize / 2; + QPoint top((left ? start.x() + xsize : start.x() - xsize), start.y() + y_half); + QPoint bottom((left ? start.x() + xsize : start.x() - xsize), start.y() - y_half); + triangle.setPoints(3, start.x(), start.y(), top.x(), top.y(), bottom.x(), bottom.y()); + QRect equ_rect(QPoint(start.x(), top.y()), bottom); + return { triangle,equ_rect }; +} + +void UDateTimeSpliter::setTextColor1(QColor color) +{ + TextColor1 = color; + return; +} + +void UDateTimeSpliter::setTextColor2(QColor color) +{ + TextColor2 = color; + return; +} + +void UDateTimeSpliter::setBackground1(QColor color) +{ + Background1 = color; + return; +} + +void UDateTimeSpliter::setBackground2(QColor color) +{ + Background2 = color; + return; +} + +void UDateTimeSpliter::DrawBackground(QPainter& painter) +{ + QLinearGradient qlg(rect().topLeft(), rect().bottomRight()); + qlg.setColorAt(0, Background1); + qlg.setColorAt(1, Background2); + qlg.setSpread(QGradient::PadSpread); + painter.setBrush(qlg); + painter.drawRect(rect()); + return; +} + +void UDateTimeSpliter::DrawDateSpliter(QPainter& painter) +{ + QPoint text_start(rect().left() + DateSpace, rect().top() + DateSpace); + QPoint text_end(rect().right() - DateSpace, rect().bottom() - DateSpace); + QRect text(text_start, text_end); + QPoint text_y_center_left(text.topLeft().x(), text.topLeft().y() + (text.height() / 2)); + QPoint text_y_center_right(text.topRight().x(), text.topRight().y() + (text.height() / 2)); + Triangle left_triangle = GetTriangle(text_y_center_left, true, DateSpliterTriangleSize, DateSpliterLineSize); + Triangle right_triangle = GetTriangle(text_y_center_right, false, DateSpliterTriangleSize, DateSpliterLineSize); + QPolygon full_shape; + full_shape.setPoints(6, left_triangle.Shape.point(1).x(), left_triangle.Shape.point(1).y(), left_triangle.Shape.point(0).x(), left_triangle.Shape.point(0).y(), left_triangle.Shape.point(2).x(), left_triangle.Shape.point(2).y(), right_triangle.Shape.point(2).x(), right_triangle.Shape.point(2).y(), right_triangle.Shape.point(0).x(), right_triangle.Shape.point(0).y(), right_triangle.Shape.point(1).x(), right_triangle.Shape.point(1).y()); + QLinearGradient linear(left_triangle.EquallyRect.topLeft(), right_triangle.EquallyRect.bottomRight()); + linear.setColorAt(0, TextColor1); + linear.setColorAt(1, TextColor2); + linear.setSpread(QGradient::PadSpread); + painter.setBrush(linear); + painter.drawPolygon(full_shape); + return; +} + +void UDateTimeSpliter::DrawDotsSpliter(QPainter& painter) +{ + QPoint text_start(rect().left() + DotSpace, rect().top() + DotSpace); + QPoint text_end(rect().right() - DotSpace, rect().bottom() - DotSpace); + QRect text(text_start, text_end); + QPoint dot_center(text.left() + (text.width() / 2), text.bottom() - DotSpace); + QLinearGradient linear(text.topLeft(), text.bottomRight()); + linear.setColorAt(0, TextColor1); + linear.setColorAt(1, TextColor2); + linear.setSpread(QGradient::PadSpread); + painter.setBrush(linear); + painter.drawEllipse(dot_center, DotSpliterCircleSize, DotSpliterCircleSize); + return; +} + +void UDateTimeSpliter::DrawTimeSpliter(QPainter& painter) +{ + QPoint text_start(rect().left() + TimeSpace, rect().top() + TimeSpace); + QPoint text_end(rect().right() - TimeSpace, rect().bottom() - TimeSpace); + QRect text(text_start, text_end); + QPoint text_center(text.left() + (text.width() / 2), text.top() + (text.height() / 2)); + QPoint top_circle_center(text_center.x(), text_center.y() + TimeSpliterCircleSpace); + QPoint bottom_circle_center(text_center.x(), text_center.y() - TimeSpliterCircleSpace); + QLinearGradient linear(text.topLeft(), text.bottomRight()); + linear.setColorAt(0, TextColor1); + linear.setColorAt(1, TextColor2); + linear.setSpread(QGradient::PadSpread); + painter.setBrush(linear); + painter.drawEllipse(top_circle_center, TimeSpliterCircleSize, TimeSpliterCircleSize); + painter.drawEllipse(bottom_circle_center, TimeSpliterCircleSize, TimeSpliterCircleSize); + return; +} + +void UDateTimeSpliter::Init(Type type, QColor tc1, QColor tc2, QColor bg1, QColor bg2) +{ + ItemType = type; + if (tc1 != QColor()) + TextColor1 = tc1; + if (tc2 != QColor()) + TextColor2 = tc2; + if (bg1 != QColor()) + Background1 = bg1; + if (bg2 != QColor()) + Background2 = bg2; + return; +} + +void UDateTimeSpliter::paintEvent(QPaintEvent* event) +{ + Q_UNUSED(event); + QPainter painter(this); + painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);//设置抗锯齿 + painter.setPen(Qt::NoPen); + DrawBackground(painter); + if (ItemType == Type::Date) + DrawDateSpliter(painter); + else if (ItemType == Type::Time) + DrawTimeSpliter(painter); + else if (ItemType == Type::Dots) + DrawDotsSpliter(painter); + return; +} \ No newline at end of file diff --git a/ClockCounter/UDateTimeSpliter.h b/ClockCounter/UDateTimeSpliter.h new file mode 100644 index 0000000..5f9fdee --- /dev/null +++ b/ClockCounter/UDateTimeSpliter.h @@ -0,0 +1,57 @@ +#pragma once +#include +#include +#include +#include +#include +#include + +class UDateTimeSpliter : public QWidget +{ + Q_OBJECT; +public: + enum class Type + { + Date, + Dots, + Time, + Empty + }; + + struct Triangle + { + QPolygon Shape; + QRect EquallyRect; + }; +private: + Type ItemType; + QColor TextColor1; + QColor TextColor2; + QColor Background1; + QColor Background2; + const int DotSpace = 20; + const int DateSpace = 20; + const int TimeSpace = 20; + const int DateSpliterLineSize = 10; + const int DotSpliterCircleSize = 6; + const int TimeSpliterCircleSize = 7; + const int TimeSpliterCircleSpace = 25; + const int DateSpliterTriangleSize = 6; +private: + Triangle GetTriangle(QPoint start, bool left, int xsize, int ysize); + void DrawBackground(QPainter& painter); + void DrawDateSpliter(QPainter& painter); + void DrawDotsSpliter(QPainter& painter); + void DrawTimeSpliter(QPainter& painter); +public: + UDateTimeSpliter(QWidget* parent = nullptr); +public: + void Init(Type type, QColor tc1 = QColor(), QColor tc2 = QColor(), QColor bg1 = QColor(), QColor bg2 = QColor()); + void setTextColor1(QColor color); + void setTextColor2(QColor color); + void setBackground1(QColor color); + void setBackground2(QColor color); +protected: + virtual void paintEvent(QPaintEvent* event) override; +}; +