update code #1

master
UnknownObject 3 years ago
parent b2938ff0a7
commit 99b5ad0cb9

@ -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()
{}
{
}

@ -1,28 +1,215 @@
<UI version="4.0" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ClockCounterClass</class>
<widget class="QMainWindow" name="ClockCounterClass">
<property name="objectName" >
<string notr="true">ClockCounterClass</string>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>400</height>
<width>980</width>
<height>269</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>ClockCounter</string>
</property> <widget class="QMenuBar" name="menuBar" />
<widget class="QToolBar" name="mainToolBar" />
<widget class="QWidget" name="centralWidget" />
<widget class="QStatusBar" name="statusBar" />
</property>
<widget class="QWidget" name="centralWidget">
<widget class="LcdNumber" name="NumHour01">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>81</width>
<height>141</height>
</rect>
</property>
</widget>
<widget class="LcdNumber" name="NumHour02">
<property name="geometry">
<rect>
<x>90</x>
<y>20</y>
<width>81</width>
<height>141</height>
</rect>
</property>
</widget>
<widget class="UDateTimeSpliter" name="SpliterHourMinute" native="true">
<property name="geometry">
<rect>
<x>170</x>
<y>20</y>
<width>81</width>
<height>141</height>
</rect>
</property>
</widget>
<widget class="UDateTimeSpliter" name="SpliterMinuteSecond" native="true">
<property name="geometry">
<rect>
<x>410</x>
<y>20</y>
<width>81</width>
<height>141</height>
</rect>
</property>
</widget>
<widget class="LcdNumber" name="NumMinute02">
<property name="geometry">
<rect>
<x>330</x>
<y>20</y>
<width>81</width>
<height>141</height>
</rect>
</property>
</widget>
<widget class="LcdNumber" name="NumMinute01">
<property name="geometry">
<rect>
<x>250</x>
<y>20</y>
<width>81</width>
<height>141</height>
</rect>
</property>
</widget>
<widget class="UDateTimeSpliter" name="SpliterSecondMS" native="true">
<property name="geometry">
<rect>
<x>650</x>
<y>20</y>
<width>81</width>
<height>141</height>
</rect>
</property>
</widget>
<widget class="LcdNumber" name="NumSecond01">
<property name="geometry">
<rect>
<x>490</x>
<y>20</y>
<width>81</width>
<height>141</height>
</rect>
</property>
</widget>
<widget class="LcdNumber" name="NumSecond02">
<property name="geometry">
<rect>
<x>570</x>
<y>20</y>
<width>81</width>
<height>141</height>
</rect>
</property>
</widget>
<widget class="LcdNumber" name="NumMillSec03">
<property name="geometry">
<rect>
<x>890</x>
<y>20</y>
<width>81</width>
<height>141</height>
</rect>
</property>
</widget>
<widget class="LcdNumber" name="NumMillSec01">
<property name="geometry">
<rect>
<x>730</x>
<y>20</y>
<width>81</width>
<height>141</height>
</rect>
</property>
</widget>
<widget class="LcdNumber" name="NumMillSec02">
<property name="geometry">
<rect>
<x>810</x>
<y>20</y>
<width>81</width>
<height>141</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="BtnStartTimer">
<property name="geometry">
<rect>
<x>20</x>
<y>190</y>
<width>181</width>
<height>61</height>
</rect>
</property>
<property name="text">
<string>开始计时</string>
</property>
</widget>
<widget class="QPushButton" name="BtnStopTimer">
<property name="geometry">
<rect>
<x>290</x>
<y>190</y>
<width>181</width>
<height>61</height>
</rect>
</property>
<property name="text">
<string>停止计时</string>
</property>
</widget>
<widget class="QPushButton" name="BtnGetPreclickPos">
<property name="geometry">
<rect>
<x>540</x>
<y>190</y>
<width>181</width>
<height>61</height>
</rect>
</property>
<property name="text">
<string>获取预点击坐标</string>
</property>
</widget>
<widget class="QPushButton" name="BtnClearPreclickPos">
<property name="geometry">
<rect>
<x>780</x>
<y>190</y>
<width>181</width>
<height>61</height>
</rect>
</property>
<property name="text">
<string>清除预点击坐标</string>
</property>
</widget>
</widget>
</widget>
<layoutDefault spacing="6" margin="11" />
<pixmapfunction></pixmapfunction>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>LcdNumber</class>
<extends>QWidget</extends>
<header>lcdnumber.h</header>
</customwidget>
<customwidget>
<class>UDateTimeSpliter</class>
<extends>QWidget</extends>
<header>udatetimespliter.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="ClockCounter.qrc"/>
</resources>
<connections/>
</UI>
</ui>

@ -15,8 +15,7 @@
<Keyword>QtVS_v304</Keyword>
<WindowsTargetPlatformVersion Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">10.0.22621.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">10.0.22621.0</WindowsTargetPlatformVersion>
<QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')"
>$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild>
<QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')">$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="Configuration">
@ -41,11 +40,8 @@
<QtModules>core;gui;widgets</QtModules>
<QtBuildConfig>release</QtBuildConfig>
</PropertyGroup>
<Target Name="QtMsBuildNotFound"
BeforeTargets="CustomBuild;ClCompile"
Condition="!Exists('$(QtMsBuild)\qt.targets') or !Exists('$(QtMsBuild)\qt.props')">
<Message Importance="High"
Text="QtMsBuild: could not locate qt.targets, qt.props; project may not build correctly." />
<Target Name="QtMsBuildNotFound" BeforeTargets="CustomBuild;ClCompile" Condition="!Exists('$(QtMsBuild)\qt.targets') or !Exists('$(QtMsBuild)\qt.props')">
<Message Importance="High" Text="QtMsBuild: could not locate qt.targets, qt.props; project may not build correctly." />
</Target>
<ImportGroup Label="ExtensionSettings" />
<ImportGroup Label="Shared" />
@ -61,7 +57,14 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<IncludePath>F:\QtGUIlib\qucsdk\include;$(IncludePath)</IncludePath>
<LibraryPath>F:\QtGUIlib\qucsdk\bin;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Link>
<AdditionalDependencies>quc.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="Configuration">
<ClCompile>
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
@ -89,12 +92,20 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="PreClick.cpp" />
<ClCompile Include="UDateTimeSpliter.cpp" />
<QtRcc Include="ClockCounter.qrc" />
<QtUic Include="ClockCounter.ui" />
<QtMoc Include="ClockCounter.h" />
<ClCompile Include="ClockCounter.cpp" />
<ClCompile Include="main.cpp" />
<QtUic Include="PreClick.ui" />
</ItemGroup>
<ItemGroup>
<QtMoc Include="PreClick.h" />
</ItemGroup>
<ItemGroup>
<QtMoc Include="UDateTimeSpliter.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')">

@ -35,14 +35,29 @@
<ClCompile Include="ClockCounter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ResourceCompile Include="$pro_name$.rc">
</ResourceCompile>
<None Include="$pro_name$.ico">
<Filter>Resource Files</Filter>
</None>
<None Include="$pro_name$.def">
<Filter>Resource Files</Filter>
</None>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PreClick.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="UDateTimeSpliter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<QtUic Include="PreClick.ui">
<Filter>Form Files</Filter>
</QtUic>
</ItemGroup>
<ItemGroup>
<QtMoc Include="PreClick.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="UDateTimeSpliter.h">
<Filter>Header Files</Filter>
</QtMoc>
</ItemGroup>
</Project>

@ -0,0 +1,10 @@
#include "PreClick.h"
PreClick::PreClick(QWidget* parent) : QMainWindow(parent)
{
ui.setupUi(this);
}
PreClick::~PreClick()
{
}

@ -0,0 +1,16 @@
#pragma once
#include <QtWidgets/QMainWindow>
#include "ui_PreClick.h"
class PreClick : public QMainWindow
{
Q_OBJECT;
public:
PreClick(QWidget* parent = nullptr);
~PreClick();
private:
Ui::PreClickWindow ui;
};

@ -0,0 +1,151 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PreClickWindow</class>
<widget class="QMainWindow" name="PreClickWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>323</width>
<height>382</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QGroupBox" name="PosGetter">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>301</width>
<height>181</height>
</rect>
</property>
<property name="title">
<string>预点击坐标</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<widget class="QTextEdit" name="PosX">
<property name="geometry">
<rect>
<x>70</x>
<y>30</y>
<width>111</width>
<height>41</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>20</x>
<y>40</y>
<width>31</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>X</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QTextEdit" name="PosY">
<property name="geometry">
<rect>
<x>70</x>
<y>100</y>
<width>111</width>
<height>41</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>20</x>
<y>110</y>
<width>31</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Y</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QPushButton" name="BtnGetPos">
<property name="geometry">
<rect>
<x>200</x>
<y>30</y>
<width>75</width>
<height>111</height>
</rect>
</property>
<property name="text">
<string>获取坐标</string>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="CountGetter">
<property name="geometry">
<rect>
<x>10</x>
<y>210</y>
<width>301</width>
<height>101</height>
</rect>
</property>
<property name="title">
<string>预点击次数</string>
</property>
<widget class="QSpinBox" name="ClickCount">
<property name="geometry">
<rect>
<x>20</x>
<y>30</y>
<width>261</width>
<height>51</height>
</rect>
</property>
</widget>
</widget>
<widget class="QPushButton" name="BtnOK">
<property name="geometry">
<rect>
<x>20</x>
<y>330</y>
<width>91</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>确定</string>
</property>
</widget>
<widget class="QPushButton" name="BtnCancel">
<property name="geometry">
<rect>
<x>210</x>
<y>330</y>
<width>91</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>取消</string>
</property>
</widget>
</widget>
</widget>
<resources/>
<connections/>
</ui>

@ -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;
}

@ -0,0 +1,57 @@
#pragma once
#include <QWidget.h>
#include <QPainter>
#include <QColor>
#include <QRect>
#include <QLinearGradient>
#include <QPolygon>
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;
};
Loading…
Cancel
Save