diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore index d12b305..e77d7e7 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,7 @@ Core/QGraphicsview_test/.vs/QGraphicsview_test/v14/.suo Core/QGraphicsview_test/QGraphicsview_test/GeneratedFiles/Debug/moc_QGraphicsviewTest.cpp Core/QGraphicsview_test/QGraphicsview_test/GeneratedFiles/qrc_QGraphicsviewTest.cpp Core/QGraphicsview_test/QGraphicsview_test.VC.db +Project/QtGuiApplication/.vs/QtGuiApplication/v15/Browse.VC.db +Project/QtGuiApplication/.vs/QtGuiApplication/v15/.suo +Project/QtGuiApplication/.vs/QtGuiApplication/v15/ipch/AutoPCH/6b0420b2d8bc96cf/MAIN.ipch +*.ipch diff --git a/Project/QtGuiApplication/CallBackTest/CallBackTest.qrc b/Project/QtGuiApplication/CallBackTest/CallBackTest.qrc new file mode 100644 index 0000000..b1132f2 --- /dev/null +++ b/Project/QtGuiApplication/CallBackTest/CallBackTest.qrc @@ -0,0 +1,4 @@ + + + + diff --git a/Project/QtGuiApplication/CallBackTest/CallBackTest.vcxproj b/Project/QtGuiApplication/CallBackTest/CallBackTest.vcxproj new file mode 100644 index 0000000..8c6d0ac --- /dev/null +++ b/Project/QtGuiApplication/CallBackTest/CallBackTest.vcxproj @@ -0,0 +1,143 @@ + + + + + Debug + x64 + + + Release + x64 + + + + {B12702AD-ABFB-343A-A199-8E24837244A3} + Qt4VSv1.0 + 10.0.17134.0 + + + + Application + v141 + + + Application + v141 + + + + $(MSBuildProjectDirectory)\QtMsBuild + + + $(SolutionDir)$(Platform)\$(Configuration)\ + + + $(SolutionDir)$(Platform)\$(Configuration)\ + + + + + + + + + + + + + + + + + + + true + UNICODE;_UNICODE;WIN32;WIN64;QT_DLL;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB;%(PreprocessorDefinitions) + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;%(AdditionalIncludeDirectories) + Disabled + ProgramDatabase + MultiThreadedDebugDLL + true + + + Windows + $(OutDir)\$(ProjectName).exe + $(QTDIR)\lib;%(AdditionalLibraryDirectories) + true + qtmaind.lib;Qt5Cored.lib;Qt5Guid.lib;Qt5Widgetsd.lib;%(AdditionalDependencies) + + + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + Moc'ing %(Identity)... + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName)\.;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + UNICODE;_UNICODE;WIN32;WIN64;QT_DLL;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB + + + Uic'ing %(Identity)... + .\GeneratedFiles\ui_%(Filename).h + + + Rcc'ing %(Identity)... + .\GeneratedFiles\qrc_%(Filename).cpp + + + + + true + UNICODE;_UNICODE;WIN32;WIN64;QT_DLL;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB;%(PreprocessorDefinitions) + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets;%(AdditionalIncludeDirectories) + + MultiThreadedDLL + true + + + Windows + $(OutDir)\$(ProjectName).exe + $(QTDIR)\lib;%(AdditionalLibraryDirectories) + false + qtmain.lib;Qt5Core.lib;Qt5Gui.lib;Qt5Widgets.lib;%(AdditionalDependencies) + + + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + Moc'ing %(Identity)... + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName)\.;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtANGLE;$(QTDIR)\include\QtWidgets + UNICODE;_UNICODE;WIN32;WIN64;QT_DLL;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB + + + Uic'ing %(Identity)... + .\GeneratedFiles\ui_%(Filename).h + + + Rcc'ing %(Identity)... + .\GeneratedFiles\qrc_%(Filename).cpp + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Project/QtGuiApplication/CallBackTest/MainWindow.cpp b/Project/QtGuiApplication/CallBackTest/MainWindow.cpp new file mode 100644 index 0000000..73a91aa --- /dev/null +++ b/Project/QtGuiApplication/CallBackTest/MainWindow.cpp @@ -0,0 +1,45 @@ +#include "MainWindow.h" +#include "ui_MainWindow.h" + +QLineEdit * MainWindow::line1; +QLineEdit * MainWindow::line2; + +MainWindow::MainWindow(QWidget *parent) + : QWidget(parent) +{ + ui = new Ui::MainWindow(); + ui->setupUi(this); + + // ³õʼ»¯QLineEdit + line1 = new QLineEdit(); + line2 = new QLineEdit(); + + // °ÑÁ½¸öline ·Å½øgridLayout + ui->gridLayout->addWidget(line1, 0, 1); + ui->gridLayout->addWidget(line2, 0, 2); + + m_scene = new QGraphicsScene(); // ³õʼ»¯Í¼Ðγ¡¾° + ui->graphicsView->setScene(m_scene); // ÉèÖó¡¾°µ½ graphicsView + m_scene->setSceneRect(0, 0, 300, 300); + m_square = new Square(); + m_square->setCallbackFunc(getPosition); // ½«getPositionÉèÖûص÷ ½ÓÊÕm_square´«ÈëµÄÊý¾Ý + m_square->setPos(100, 100); + m_scene->addItem(m_square); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +/** + * @fn MainWindow::getPosition + * @brief »Øµ÷º¯Êý½ÓÊÕÕý·½ÐÎλÖà дÈëÁ½¸ölineEdit + * @param QPointF point + * @return void + */ +void MainWindow::getPosition(QPointF point) +{ + line1->setText(QString::number(point.x())); + line2->setText(QString::number(point.y())); +} diff --git a/Project/QtGuiApplication/CallBackTest/MainWindow.h b/Project/QtGuiApplication/CallBackTest/MainWindow.h new file mode 100644 index 0000000..756d84a --- /dev/null +++ b/Project/QtGuiApplication/CallBackTest/MainWindow.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include +#include "Square.h" +namespace Ui { class MainWindow; }; + +class MainWindow : public QWidget +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = Q_NULLPTR); + ~MainWindow(); + +private: + Ui::MainWindow* ui; + + QGraphicsScene* m_scene; + Square *m_square; // We declare the square, which will transmit the callback function + static QLineEdit *line1; // We declare a static QLineEdit, which will run the callback function + static QLineEdit *line2; // We declare a static QLineEdit, which will run the callback function + +private: + // ÉùÃ÷Ò»¸ö»Øµ÷º¯Êý + static void getPosition(QPointF point); +}; diff --git a/Project/QtGuiApplication/CallBackTest/MainWindow.ui b/Project/QtGuiApplication/CallBackTest/MainWindow.ui new file mode 100644 index 0000000..42d991b --- /dev/null +++ b/Project/QtGuiApplication/CallBackTest/MainWindow.ui @@ -0,0 +1,32 @@ + + + MainWindow + + + + 0 + 0 + 400 + 300 + + + + MainWindow + + + + + + + + + + + + + + + + + + diff --git a/Project/QtGuiApplication/CallBackTest/Square.cpp b/Project/QtGuiApplication/CallBackTest/Square.cpp new file mode 100644 index 0000000..a4446f2 --- /dev/null +++ b/Project/QtGuiApplication/CallBackTest/Square.cpp @@ -0,0 +1,57 @@ +#include "Square.h" +#include + +Square::Square(QObject *parent) + : QObject(parent), QGraphicsItem() +{ + m_timer = new QTimer(); + connect(m_timer, &QTimer::timeout, this, &Square::slotTimer); + m_timer->start(1000 / 33); +} + +Square::~Square() +{ +} + +void Square::setCallbackFunc(void(*func) (QPointF point)) +{ + m_callbackFunc = func; +} + +QRectF Square::boundingRect() const +{ + return QRectF(-15, -15, 30, 30); +} + +void Square::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + painter->setPen(Qt::black); + painter->setBrush(Qt::green); + painter->drawRect(-15, -15, 30, 30); + + Q_UNUSED(option); + Q_UNUSED(widget); +} + +void Square::slotTimer() +{ + // ¸ù¾Ý°´Å¥´¥·¢Çé¿öÒƶ¯Õý·½ÐÎ + if (GetAsyncKeyState('A')) + { + this->setX(this->x() - 2); + } + if (GetAsyncKeyState('D')) + { + this->setX(this->x() + 2); + } + if (GetAsyncKeyState('W')) + { + this->setY(this->y() - 2); + } + if (GetAsyncKeyState('S')) + { + this->setY(this->y() + 2); + } + // µ÷Óûص÷º¯Êý´«µÝÕý·½ÐÎλÖà + m_callbackFunc(this->pos()); +} diff --git a/Project/QtGuiApplication/CallBackTest/Square.h b/Project/QtGuiApplication/CallBackTest/Square.h new file mode 100644 index 0000000..601111b --- /dev/null +++ b/Project/QtGuiApplication/CallBackTest/Square.h @@ -0,0 +1,31 @@ +#pragma once + +#include +#include +#include +#include +#include + +class Square : public QObject, public QGraphicsItem +{ + Q_OBJECT + +public: + explicit Square(QObject *parent = 0); + ~Square(); + + // ÉèÖûص÷º¯ÊýµÄº¯Êý + void setCallbackFunc(void(*func) (QPointF point)); + +protected: + QRectF boundingRect() const; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + +private: + QTimer * m_timer; + + void(*m_callbackFunc)(QPointF point); + +private slots: + void slotTimer(); +}; diff --git a/Project/QtGuiApplication/CallBackTest/main.cpp b/Project/QtGuiApplication/CallBackTest/main.cpp new file mode 100644 index 0000000..2a84972 --- /dev/null +++ b/Project/QtGuiApplication/CallBackTest/main.cpp @@ -0,0 +1,10 @@ +#include "MainWindow.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/Project/QtGuiApplication/QtGuiApplication.sln b/Project/QtGuiApplication/QtGuiApplication.sln new file mode 100644 index 0000000..bf3f693 --- /dev/null +++ b/Project/QtGuiApplication/QtGuiApplication.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27703.2035 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CallBackTest", "CallBackTest\CallBackTest.vcxproj", "{B12702AD-ABFB-343A-A199-8E24837244A3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B12702AD-ABFB-343A-A199-8E24837244A3}.Debug|x64.ActiveCfg = Debug|x64 + {B12702AD-ABFB-343A-A199-8E24837244A3}.Debug|x64.Build.0 = Debug|x64 + {B12702AD-ABFB-343A-A199-8E24837244A3}.Release|x64.ActiveCfg = Release|x64 + {B12702AD-ABFB-343A-A199-8E24837244A3}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0BB066DD-85F6-427D-B187-90E842B7B61E} + EndGlobalSection +EndGlobal