diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..0752aa8 --- /dev/null +++ b/main.cpp @@ -0,0 +1,22 @@ +#include "qtsgraph.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + QTSGraph w(1024,768); + w.show(); + return a.exec(); +} + +void QTSGraph::slotstarttimer() +{ + // Тут рисовать + + putpixel(100,100); + delay(2000); + putpixel(300,100); + + // Конец рисования + starttimer->stop(); +} diff --git a/qtSimpleGraph.pro b/qtSimpleGraph.pro new file mode 100644 index 0000000..ef5a993 --- /dev/null +++ b/qtSimpleGraph.pro @@ -0,0 +1,27 @@ +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 + +# You can make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + main.cpp \ + qtsgraph.cpp + +HEADERS += \ + qtsgraph.h + +FORMS += \ + qtsgraph.ui + +TRANSLATIONS += \ + qtSimpleGraph_ru_RU.ts + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/qtSimpleGraph.pro.user b/qtSimpleGraph.pro.user new file mode 100644 index 0000000..9cc3bc3 --- /dev/null +++ b/qtSimpleGraph.pro.user @@ -0,0 +1,356 @@ + + + + + + EnvironmentId + {05f74a09-f8dc-44d7-b276-0cdf5e994b4e} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + *.md, *.MD, Makefile + false + true + + + + ProjectExplorer.Project.PluginSettings + + + true + true + true + true + true + + + 0 + true + + true + Builtin.Questionable + + true + Builtin.DefaultTidyAndClazy + 4 + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop + Desktop + {1639e0f7-0173-409e-a3e8-eff2678b1555} + 0 + 0 + 0 + + true + 0 + /home/tema/temp/build-qtSimpleGraph-Desktop-Debug + /home/tema/temp/build-qtSimpleGraph-Desktop-Debug + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Отладка + Qt4ProjectManager.Qt4BuildConfiguration + 2 + 2 + 2 + + + true + 2 + /home/tema/temp/build-qtSimpleGraph-Desktop-Release + /home/tema/temp/build-qtSimpleGraph-Desktop-Release + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Выпуск + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 2 + + + true + 0 + /home/tema/temp/build-qtSimpleGraph-Desktop-Profile + /home/tema/temp/build-qtSimpleGraph-Desktop-Profile + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Сборка + Сборка + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Очистка + Очистка + ProjectExplorer.BuildSteps.Clean + + 2 + false + + + Профилирование + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + 3 + + + 0 + Развёртывание + Развёртывание + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + + 2 + + qtSimpleGraph2 + Qt4ProjectManager.Qt4RunConfiguration:/home/tema/github/qtSimpleGraph/qtSimpleGraph.pro + /home/tema/github/qtSimpleGraph/qtSimpleGraph.pro + + false + + false + true + true + false + false + true + + /home/tema/temp/build-qtSimpleGraph-Desktop-Debug + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/qtSimpleGraph_ru_RU.ts b/qtSimpleGraph_ru_RU.ts new file mode 100644 index 0000000..892d343 --- /dev/null +++ b/qtSimpleGraph_ru_RU.ts @@ -0,0 +1,3 @@ + + + diff --git a/qtsgraph.cpp b/qtsgraph.cpp new file mode 100644 index 0000000..1bb0fbe --- /dev/null +++ b/qtsgraph.cpp @@ -0,0 +1,62 @@ +#include "qtsgraph.h" +#include "ui_qtsgraph.h" + +void QTSGraph::delay(int ms) +{ + QTime dieTime= QTime::currentTime().addMSecs(ms); + while (QTime::currentTime() < dieTime) + QCoreApplication::processEvents(QEventLoop::AllEvents, 100); +} + +QTSGraph::QTSGraph(int w, int h, int x, int y, QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::QTSGraph) +{ + ui->setupUi(this); + if(x < 0 || y < 0) + { + QDesktopWidget desktop; + QRect rect = desktop.availableGeometry(desktop.primaryScreen()); // прямоугольник с размерами экрана + QPoint center = rect.center(); //координаты центра экрана + x = center.x() - w / 2; + y = center.y() - h / 2; + } + this->setGeometry(x, y, w, h); + this->setWindowTitle("Рисунок"); + m_Pixmap = QPixmap(w, h); + m_Pixmap.fill(Qt::white); + starttimer = new QTimer(); + connect(starttimer, SIGNAL(timeout()), this, SLOT(slotstarttimer())); + starttimer->start(500); +} + +QTSGraph::~QTSGraph() +{ + delete ui; +} + +void QTSGraph::putpixel(int x, int y, Qt::GlobalColor c) +{ + QPainter painter(&m_Pixmap); + painter.setPen(QPen(QBrush(QColor(c)), 5 )); + painter.drawPoint( x, y ); + update(); +} + +void QTSGraph::paintEvent(QPaintEvent *event) +{ + QPainter p(this); + p.drawPixmap(0, 0,m_Pixmap); +} + +void QTSGraph::mousePressEvent(QMouseEvent *event) +{ + if (event->buttons() & Qt::LeftButton) + { + // Левая кнопка + } + else if (event->buttons() & Qt::RightButton) + { + // Правая кнопка + } +} diff --git a/qtsgraph.h b/qtsgraph.h new file mode 100644 index 0000000..209c395 --- /dev/null +++ b/qtsgraph.h @@ -0,0 +1,37 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +namespace Ui { class QTSGraph; } +QT_END_NAMESPACE + +class QTSGraph : public QMainWindow +{ + Q_OBJECT + +public: + QTSGraph(int w = 640, int h = 480, int x = -1, int y = -1, QWidget *parent = nullptr); + ~QTSGraph(); + void putpixel(int x, int y, Qt::GlobalColor c = Qt::red); + void delay(int ms = 1000); + +private slots: + void slotstarttimer(); + +private: + Ui::QTSGraph *ui; + QPixmap m_Pixmap; + QTimer *starttimer; + +protected: + void paintEvent(QPaintEvent *event) override; + void mousePressEvent(QMouseEvent *event); +}; diff --git a/qtsgraph.ui b/qtsgraph.ui new file mode 100644 index 0000000..d9ee13a --- /dev/null +++ b/qtsgraph.ui @@ -0,0 +1,22 @@ + + + QTSGraph + + + + 0 + 0 + 800 + 600 + + + + QTSGraph + + + + + + + +