# HG changeset patch # User unc0rr # Date 1543693921 -3600 # Node ID 20178fa3a74aa20e3f1f7298737a542548853c82 # Parent 5cc671f988e7f4d5da79c7b7908f4461cf7c67ef - Ban more stuff from src tarball - Remove some obsolete tools diff -r 5cc671f988e7 -r 20178fa3a74a cmake_modules/cpackvars.cmake --- a/cmake_modules/cpackvars.cmake Sat Dec 01 20:38:45 2018 +0100 +++ b/cmake_modules/cpackvars.cmake Sat Dec 01 20:52:01 2018 +0100 @@ -82,7 +82,6 @@ "[rR]elease$" "CPack" "CTestTestfile.cmake" - "gameServer2" "cmake_install\\\\.cmake$" "cmake_uninstall\\\\.cmake$" "CMakeCache\\\\.txt$" @@ -104,6 +103,9 @@ "^${CMAKE_CURRENT_SOURCE_DIR}/install_manifest.txt" "^${CMAKE_CURRENT_SOURCE_DIR}/CMakeCache.txt" "^${CMAKE_CURRENT_SOURCE_DIR}/hedgewars\\\\." + "^${CMAKE_CURRENT_SOURCE_DIR}/gameServer2" + "^${CMAKE_CURRENT_SOURCE_DIR}/rust" + "^${CMAKE_CURRENT_SOURCE_DIR}/qmlfrontend" ) include(CPack) diff -r 5cc671f988e7 -r 20178fa3a74a tools/drawMapTest/drawMapTest.pro --- a/tools/drawMapTest/drawMapTest.pro Sat Dec 01 20:38:45 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -# ------------------------------------------------- -# Project created by QtCreator 2010-11-27T22:18:20 -# ------------------------------------------------- -TARGET = drawMapTest -TEMPLATE = app -SOURCES += main.cpp \ - mainwindow.cpp \ - drawmapscene.cpp \ - qaspectratiolayout.cpp \ - drawmapwidget.cpp -HEADERS += mainwindow.h \ - drawmapscene.h \ - qaspectratiolayout.h \ - drawmapwidget.h -FORMS += mainwindow.ui diff -r 5cc671f988e7 -r 20178fa3a74a tools/drawMapTest/drawmapscene.cpp --- a/tools/drawMapTest/drawmapscene.cpp Sat Dec 01 20:38:45 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,187 +0,0 @@ -#include -#include -#include -#include - -#include "drawmapscene.h" - -template T sqr(const T & x) -{ - return x*x; -} - -DrawMapScene::DrawMapScene(QObject *parent) : - QGraphicsScene(parent), - m_pen(Qt::yellow), - m_brush(Qt::yellow) -{ - setSceneRect(0, 0, 4096, 2048); - - QLinearGradient gradient(0, 0, 0, 2048); - gradient.setColorAt(0, QColor(60, 60, 155)); - gradient.setColorAt(1, QColor(155, 155, 60)); - setBackgroundBrush(QBrush(gradient)); - - m_pen.setWidth(67); - m_pen.setJoinStyle(Qt::RoundJoin); - m_pen.setCapStyle(Qt::RoundCap); - m_currPath = 0; -} - -void DrawMapScene::mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent) -{ - - qDebug() << "move" << mouseEvent->scenePos(); - - if(m_currPath && (mouseEvent->buttons() & Qt::LeftButton)) - { - QPainterPath path = m_currPath->path(); - path.lineTo(mouseEvent->scenePos()); - paths.first().append(mouseEvent->scenePos().toPoint()); - m_currPath->setPath(path); - - emit pathChanged(); - } -} - -void DrawMapScene::mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent) -{ - qDebug() << "press" << mouseEvent->scenePos(); - - m_currPath = addPath(QPainterPath(), m_pen); - - QPainterPath path = m_currPath->path(); - QPointF p = mouseEvent->scenePos(); - p += QPointF(0.01, 0.01); - path.moveTo(p); - path.lineTo(mouseEvent->scenePos()); - paths.prepend(QList() << mouseEvent->scenePos().toPoint()); - m_currPath->setPath(path); - - emit pathChanged(); -} - -void DrawMapScene::mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent) -{ - qDebug() << "release" << mouseEvent->scenePos(); - - simplifyLast(); - - m_currPath = 0; -} - -void DrawMapScene::undo() -{ - if(items().size()) - { - removeItem(items().first()); - paths.removeFirst(); - - emit pathChanged(); - } -} - -QByteArray DrawMapScene::encode() -{ - QByteArray b; - - foreach(QList points, paths) - { - int cnt = 0; - foreach(QPoint point, points) - { - qint16 px = qToBigEndian((qint16)point.x()); - qint16 py = qToBigEndian((qint16)point.y()); - quint8 flags = 2; - if(!cnt) flags |= 0x80; - b.append((const char *)&px, 2); - b.append((const char *)&py, 2); - b.append((const char *)&flags, 1); - - ++cnt; - } - - } - - return b; -} - -void DrawMapScene::decode(QByteArray data) -{ - clear(); - paths.clear(); - - QList points; - - while(data.size() >= 5) - { - qint16 px = qFromBigEndian(*(qint16 *)data.data()); - data.remove(0, 2); - qint16 py = qFromBigEndian(*(qint16 *)data.data()); - data.remove(0, 2); - quint8 flags = *(quint8 *)data.data(); - data.remove(0, 1); - - //last chunk or first point - if((data.size() < 5) || (flags & 0x80)) - { - if(points.size()) - { - qDebug() << points; - addPath(pointsToPath(points), m_pen); - paths.prepend(points); - - points.clear(); - } - } - - points.append(QPoint(px, py)); - } -} - -void DrawMapScene::simplifyLast() -{ - QList points = paths[0]; - - QPoint prevPoint = points.first(); - int i = 1; - while(i < points.size()) - { - if( (i != points.size() - 1) - && (sqr(prevPoint.x() - points[i].x()) + sqr(prevPoint.y() - points[i].y()) < 1000) - ) - points.removeAt(i); - else - { - prevPoint = points[i]; - ++i; - } - } - - paths[0] = points; - - - // redraw path - { - QGraphicsPathItem * pathItem = static_cast(items()[0]); - pathItem->setPath(pointsToPath(paths[0])); - } - - emit pathChanged(); -} - -QPainterPath DrawMapScene::pointsToPath(const QList points) -{ - QPainterPath path; - - if(points.size()) - { - QPointF p = points[0] + QPointF(0.01, 0.01); - path.moveTo(p); - - foreach(QPoint p, points) - path.lineTo(p); - } - - return path; -} diff -r 5cc671f988e7 -r 20178fa3a74a tools/drawMapTest/drawmapscene.h --- a/tools/drawMapTest/drawmapscene.h Sat Dec 01 20:38:45 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -#ifndef DRAWMAPSCENE_H -#define DRAWMAPSCENE_H - -#include -#include - -class QGraphicsPathItem; - -typedef QList > Paths; - -class DrawMapScene : public QGraphicsScene -{ -Q_OBJECT -public: - explicit DrawMapScene(QObject *parent = 0); - - QByteArray encode(); - void decode(QByteArray data); - -signals: - void pathChanged(); - -public slots: - void undo(); - void simplifyLast(); - -private: - QPen m_pen; - QBrush m_brush; - QGraphicsPathItem * m_currPath; - Paths paths; - - virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent); - virtual void mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent); - virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * mouseEvent); - - QPainterPath pointsToPath(const QList points); -}; - -#endif // DRAWMAPSCENE_H diff -r 5cc671f988e7 -r 20178fa3a74a tools/drawMapTest/drawmapwidget.cpp --- a/tools/drawMapTest/drawmapwidget.cpp Sat Dec 01 20:38:45 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -#include "drawmapwidget.h" - -DrawMapWidget::DrawMapWidget(QWidget *parent) : - QWidget(parent), - ui(new Ui::DrawMapWidget) -{ - ui->setupUi(this); -} - -DrawMapWidget::~DrawMapWidget() -{ - delete ui; -} - -void DrawMapWidget::changeEvent(QEvent *e) -{ - QWidget::changeEvent(e); - switch (e->type()) { - case QEvent::LanguageChange: - ui->retranslateUi(this); - break; - default: - break; - } -} - -void DrawMapWidget::setScene(DrawMapScene * scene) -{ - ui->graphicsView->setScene(scene); -} - -void DrawMapWidget::resizeEvent(QResizeEvent * event) -{ - Q_UNUSED(event); - - if(ui->graphicsView && ui->graphicsView->scene()) - ui->graphicsView->fitInView(ui->graphicsView->scene()->sceneRect(), Qt::KeepAspectRatio); -} diff -r 5cc671f988e7 -r 20178fa3a74a tools/drawMapTest/drawmapwidget.h --- a/tools/drawMapTest/drawmapwidget.h Sat Dec 01 20:38:45 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -#ifndef DRAWMAPWIDGET_H -#define DRAWMAPWIDGET_H - -#include -#include -#include -#include -#include - -#include "qaspectratiolayout.h" -#include "drawmapscene.h" - -namespace Ui { - class Ui_DrawMapWidget - { - public: - QGraphicsView *graphicsView; - QPushButton *pbUndo; - - void setupUi(QWidget *drawMapWidget) - { - QAspectRatioLayout * arLayout = new QAspectRatioLayout(drawMapWidget); - arLayout->setMargin(0); - - graphicsView = new QGraphicsView(drawMapWidget); - arLayout->addWidget(graphicsView); - - retranslateUi(drawMapWidget); - - QMetaObject::connectSlotsByName(drawMapWidget); - } // setupUi - - void retranslateUi(QWidget *drawMapWidget) - { - Q_UNUSED(drawMapWidget); - } // retranslateUi - - }; - - class DrawMapWidget: public Ui_DrawMapWidget {}; -} - -class DrawMapWidget : public QWidget -{ - Q_OBJECT - -public: - explicit DrawMapWidget(QWidget *parent = 0); - ~DrawMapWidget(); - - void setScene(DrawMapScene * scene); - -protected: - void changeEvent(QEvent *e); - virtual void resizeEvent(QResizeEvent * event); - -private: - Ui::DrawMapWidget *ui; -}; - -#endif // DRAWMAPWIDGET_H diff -r 5cc671f988e7 -r 20178fa3a74a tools/drawMapTest/main.cpp --- a/tools/drawMapTest/main.cpp Sat Dec 01 20:38:45 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -#include -#include "mainwindow.h" - -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - MainWindow w; - w.show(); - return a.exec(); -} diff -r 5cc671f988e7 -r 20178fa3a74a tools/drawMapTest/mainwindow.cpp --- a/tools/drawMapTest/mainwindow.cpp Sat Dec 01 20:38:45 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -#include - -#include "mainwindow.h" -#include "ui_mainwindow.h" -#include "drawmapscene.h" - -MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::MainWindow) -{ - ui->setupUi(this); - - scene = new DrawMapScene(this); - //ui->graphicsView->setScene(scene); - ui->drawMapWidget->setScene(scene); - - connect(ui->pbUndo, SIGNAL(clicked()), scene, SLOT(undo())); - connect(scene, SIGNAL(pathChanged()), this, SLOT(scene_pathChanged())); -} - -MainWindow::~MainWindow() -{ - delete ui; -} - -void MainWindow::changeEvent(QEvent *e) -{ - QMainWindow::changeEvent(e); - switch (e->type()) { - case QEvent::LanguageChange: - ui->retranslateUi(this); - break; - default: - break; - } -} - -void MainWindow::scene_pathChanged() -{ - QString str = scene->encode().toBase64(); - ui->plainTextEdit->setPlainText(str); - ui->sbBytes->setValue(str.size()); -} - -void MainWindow::on_pbSave_clicked() -{ - QString fileName = QFileDialog::getSaveFileName(this, tr("Save map"), "."); - - if(!fileName.isEmpty()) - { - QFile f(fileName); - - f.open(QIODevice::WriteOnly); - f.write(scene->encode()); - } -} - -void MainWindow::on_pbLoad_clicked() -{ - QString fileName = QFileDialog::getOpenFileName(this, tr("Open map file"), "."); - - if(!fileName.isEmpty()) - { - QFile f(fileName); - - f.open(QIODevice::ReadOnly); - QByteArray data = f.readAll(); - scene->decode(data); - } -} diff -r 5cc671f988e7 -r 20178fa3a74a tools/drawMapTest/mainwindow.h --- a/tools/drawMapTest/mainwindow.h Sat Dec 01 20:38:45 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include - -namespace Ui { - class MainWindow; -} - -class DrawMapScene; - -class MainWindow : public QMainWindow { - Q_OBJECT -public: - MainWindow(QWidget *parent = 0); - ~MainWindow(); - -protected: - void changeEvent(QEvent *e); - -private: - Ui::MainWindow *ui; - DrawMapScene * scene; - -private slots: - void on_pbLoad_clicked(); - void on_pbSave_clicked(); - void scene_pathChanged(); -}; - -#endif // MAINWINDOW_H diff -r 5cc671f988e7 -r 20178fa3a74a tools/drawMapTest/mainwindow.ui --- a/tools/drawMapTest/mainwindow.ui Sat Dec 01 20:38:45 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 600 - 400 - - - - MainWindow - - - - - - - - - - - - Undo - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Save - - - - - - - Load - - - - - - - true - - - QAbstractSpinBox::NoButtons - - - bytes - - - 999999 - - - - - - - - - - - - - - - DrawMapWidget - QWidget -
drawmapwidget.h
- 1 -
-
- - -
diff -r 5cc671f988e7 -r 20178fa3a74a tools/drawMapTest/qaspectratiolayout.cpp --- a/tools/drawMapTest/qaspectratiolayout.cpp Sat Dec 01 20:38:45 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,206 +0,0 @@ -/* - * Copyright (c) 2009 Nokia Corporation. - */ - -#include "qaspectratiolayout.h" - -QAspectRatioLayout::QAspectRatioLayout(QWidget* parent, int spacing) : QLayout(parent) { - init(spacing); -} - -QAspectRatioLayout::QAspectRatioLayout(int spacing) { - init(spacing); -} - -QAspectRatioLayout::~QAspectRatioLayout() { - delete item; - delete lastReceivedRect; - delete _geometry; -} - -void QAspectRatioLayout::init(int spacing) { - item = 0; - lastReceivedRect = new QRect(0, 0, 0, 0); - _geometry = new QRect(0, 0, 0, 0); - setSpacing(spacing); -} - - -/* Adds item if place isn't already taken. */ -void QAspectRatioLayout::add(QLayoutItem* item) { - if(!hasItem()) { - replaceItem(item); - } -} - -/* Adds item if place isn't already taken. */ -void QAspectRatioLayout::addItem(QLayoutItem* item) { - if(!hasItem()) { - replaceItem(item); - } -} - -/* Adds widget if place isn't already taken. */ -void QAspectRatioLayout::addWidget(QWidget* widget) { - if(!hasItem()) { - replaceItem(new QWidgetItem(widget)); - } -} - -/* Returns the item pointer and dereferences it here. */ -QLayoutItem* QAspectRatioLayout::take() { - QLayoutItem* item = 0; - if(this->hasItem()) { - item = this->item; - this->item = 0; - } - return item; -} - -/* Returns the item pointer and dereferences it here. */ -QLayoutItem* QAspectRatioLayout::takeAt(int index) { - if(index != 0) { - return 0; - } - return this->take(); -} - -/* Returns the item pointer. */ -QLayoutItem* QAspectRatioLayout::itemAt(int index) const { - if(index != 0) { - return 0; - } - if(hasItem()) { - return this->item; - } - return 0; -} - -/* Checks if we have an item. */ -bool QAspectRatioLayout::hasItem() const { - return this->item != 0; -} - -/* Returns the count of items which can be either 0 or 1. */ -int QAspectRatioLayout::count() const { - int returnValue = 0; - if(hasItem()) { - returnValue = 1; - } - return returnValue; -} - -/* Replaces the item with the new and returns the old. */ -QLayoutItem* QAspectRatioLayout::replaceItem(QLayoutItem* item) { - QLayoutItem* old = 0; - if(this->hasItem()) { - old = this->item; - } - this->item = item; - setGeometry(*this->_geometry); - return old; -} - -/* Tells which way layout expands. */ -Qt::Orientations QAspectRatioLayout::expandingDirections() const { - return Qt::Horizontal | Qt::Vertical; -} - -/* Tells which size is preferred. */ -QSize QAspectRatioLayout::sizeHint() const { - return this->item->minimumSize(); -} - -/* Tells minimum size. */ -QSize QAspectRatioLayout::minimumSize() const { - return this->item->minimumSize(); -} - -/* - * Tells if heightForWidth calculations is handled. - * It isn't since width isn't enough to calculate - * proper size. - */ -bool QAspectRatioLayout::hasHeightForWidth() const { - return false; -} - -/* Replaces lastReceivedRect. */ -void QAspectRatioLayout::setLastReceivedRect(const QRect& rect) { - QRect* oldRect = this->lastReceivedRect; - this->lastReceivedRect = new QRect(rect.topLeft(), rect.size()); - delete oldRect; -} - -/* Returns geometry */ -QRect QAspectRatioLayout::geometry() { - return QRect(*this->_geometry); -} - -/* Sets geometry to given size. */ -void QAspectRatioLayout::setGeometry(const QRect& rect) { - /* - * We check if the item is set and - * if size is the same previously received. - * If either is false nothing is done. - */ - if(!this->hasItem() || - areRectsEqual(*this->lastReceivedRect, rect)) { - return; - } - /* Replace the last received rectangle. */ - setLastReceivedRect(rect); - /* Calculate proper size for the item relative to the received size. */ - QSize properSize = calculateProperSize(rect.size()); - /* Calculate center location in the rect and with item size. */ - QPoint properLocation = calculateCenterLocation(rect.size(), properSize); - /* Set items geometry */ - this->item->setGeometry(QRect(properLocation, properSize)); - QRect* oldRect = this->_geometry; - /* Cache the calculated geometry. */ - this->_geometry = new QRect(properLocation, properSize); - delete oldRect; - /* Super classes setGeometry */ - QLayout::setGeometry(*this->_geometry); -} - -/* Takes the shortest side and creates QSize - * with the shortest side as width and height. */ -QSize QAspectRatioLayout::calculateProperSize(QSize from) const { - QSize properSize; - if(from.height() * 2 < from.width()) { - properSize.setHeight(from.height() - this->margin()); - properSize.setWidth(from.height() * 2 - this->margin()); - } - else { - properSize.setWidth(from.width() - this->margin()); - properSize.setHeight(from.width() / 2 - this->margin()); - } - return properSize; -} - -/* Calculates center location from the given height and width for item size. */ -QPoint QAspectRatioLayout::calculateCenterLocation(QSize from, - QSize itemSize) const { - QPoint centerLocation; - if((from.width() - itemSize.width()) > 0) { - centerLocation.setX((from.width() - itemSize.width())/2); - } - if((from.height() - itemSize.height()) > 0) { - centerLocation.setY((from.height() - itemSize.height())/2); - } - return centerLocation; -} - -/* Compares if two QRects are equal. */ -bool QAspectRatioLayout::areRectsEqual(const QRect& a, - const QRect& b) const { - bool result = false; - if(a.x() == b.x() && - a.y() == b.y() && - a.height() == b.height() && - a.width() == b.width()) { - result = true; - } - return result; -} diff -r 5cc671f988e7 -r 20178fa3a74a tools/drawMapTest/qaspectratiolayout.h --- a/tools/drawMapTest/qaspectratiolayout.h Sat Dec 01 20:38:45 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2009 Nokia Corporation. - */ - -#ifndef QASPECTRATIOLAYOUT_H_ -#define QASPECTRATIOLAYOUT_H_ - -#include -#include -#include -#include -#include - - -class QAspectRatioLayout : public QLayout -{ - Q_OBJECT - -public: - QAspectRatioLayout(QWidget* parent, int spacing =-1); - QAspectRatioLayout(int spacing = -1); - ~QAspectRatioLayout(); - - /* Convenience method */ - virtual void add(QLayoutItem* item); - -/* http://doc.trolltech.com/qlayout.html#addItem */ - virtual void addItem(QLayoutItem* item); - /* http://doc.trolltech.com/qlayout.html#addWidget */ - virtual void addWidget(QWidget* widget); - /* http://doc.trolltech.com/qlayout.html#takeAt */ - virtual QLayoutItem* takeAt(int index); - /* http://doc.trolltech.com/qlayout.html#itemAt */ - virtual QLayoutItem* itemAt(int index) const; - /* http://doc.trolltech.com/qlayout.html#count */ - virtual int count() const; - - /* - * These are ours since we do have only one item. - */ - virtual QLayoutItem* replaceItem(QLayoutItem* item); - virtual QLayoutItem* take(); - virtual bool hasItem() const; - -/* http://doc.trolltech.com/qlayout.html#expandingDirections */ - virtual Qt::Orientations expandingDirections() const; - - /* - * This method contains most of the juice of this article. - * http://doc.trolltech.com/qlayoutitem.html#setGeometry - */ - virtual void setGeometry(const QRect& rect); - /* http://doc.trolltech.com/qlayoutitem.html#geometry */ - virtual QRect geometry(); - - /* http://doc.trolltech.com/qlayoutitem.html#sizeHint */ - virtual QSize sizeHint() const; - /* http://doc.trolltech.com/qlayout.html#minimumSize */ - virtual QSize minimumSize() const; - /* http://doc.trolltech.com/qlayoutitem.html#hasHeightForWidth */ - virtual bool hasHeightForWidth() const; - -private: - /* Saves the last received rect. */ - void setLastReceivedRect(const QRect& rect); - /* Used to initialize the object. */ - void init(int spacing); - /* Calculates the maximum size for the item from the assigned size. */ - QSize calculateProperSize(QSize from) const; - /* Calculates the center location from the assigned size and - * the items size. */ - QPoint calculateCenterLocation(QSize from, QSize itemSize) const; - /* Check if two QRects are equal */ - bool areRectsEqual(const QRect& a, const QRect& b) const; - /* Contains item reference */ - QLayoutItem* item; - /* - * Used for caching so we won't do calculations every time - * setGeometry is called. - */ - QRect* lastReceivedRect; - /* Contains geometry */ - QRect* _geometry; - -}; - -#endif /* QASPECTRATIOLAYOUT_H_ */ diff -r 5cc671f988e7 -r 20178fa3a74a tools/templates/main.cpp --- a/tools/templates/main.cpp Sat Dec 01 20:38:45 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -#include - -#include "mainform.h" - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - MyWindow *mainWin = new MyWindow; - mainWin->show(); - return app.exec(); -} diff -r 5cc671f988e7 -r 20178fa3a74a tools/templates/mainform.cpp --- a/tools/templates/mainform.cpp Sat Dec 01 20:38:45 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,110 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include "mainform.h" - -MyWindow::MyWindow(QWidget * parent, Qt::WFlags flags) - : QMainWindow(parent, flags) - -{ - QWidget * centralWidget = new QWidget(this); - QGridLayout * mainlayout = new QGridLayout(centralWidget); - mainlayout->setMargin(1); - mainlayout->setSpacing(1); - - sa_xy = new QScrollArea(centralWidget); - xy = new PixLabel(); - xy->setFixedSize(1024, 512); - sa_xy->setWidget(xy); - - mainlayout->addWidget(sa_xy, 0, 0, 1, 4); - - setCentralWidget(centralWidget); - - buttAdd = new QPushButton(centralWidget); - buttAdd->setText(tr("Add")); - mainlayout->addWidget(buttAdd, 1, 0); - - buttCode = new QPushButton(centralWidget); - buttCode->setText(tr("Code")); - mainlayout->addWidget(buttCode, 1, 1); - - buttSave = new QPushButton(centralWidget); - buttSave->setText(tr("Save")); - mainlayout->addWidget(buttSave, 1, 3); - - buttLoad = new QPushButton(centralWidget); - buttLoad->setText(tr("Load")); - mainlayout->addWidget(buttLoad, 1, 2); - - connect(buttAdd, SIGNAL(clicked()), xy, SLOT(AddRect())); - connect(buttCode, SIGNAL(clicked()), this, SLOT(Code())); - connect(buttSave, SIGNAL(clicked()), this, SLOT(Save())); - connect(buttLoad, SIGNAL(clicked()), this, SLOT(Load())); -} - -void MyWindow::Code() -{ - if (xy->rects.size()) - { - QFile f("template.pas"); - if (!f.open(QIODevice::WriteOnly)) - { - QMessageBox::information(this, tr("Error"), - tr("Cannot save")); - return ; - } - - QTextStream stream(&f); - stream << QString("const Template0Points: array[0..%1] of TSDL_Rect =").arg(xy->rects.size() - 1) << endl; - stream << " (" << endl; - for(int i = 0; i < xy->rects.size(); i++) - { - QRect r = xy->rects[i].normalized(); - stream << QString(" (x: %1; y: %2; w: %3; h: %4),"). - arg(r.x() * 4, 4).arg(r.y() * 4, 4).arg(r.width() * 4, 4).arg(r.height() * 4, 4) << endl; - } - stream << " );" << endl; - f.close(); - } -} - -void MyWindow::Save() -{ - Code(); -} - -void MyWindow::Load() -{ - QFile f("template.pas"); - if (!f.open(QIODevice::ReadOnly)) - { - QMessageBox::information(this, tr("Error"), - tr("Cannot open file")); - return ; - } - - QTextStream stream(&f); - QStringList sl; - while (!stream.atEnd()) - { - sl << stream.readLine(); - } - xy->rects.clear(); - for (int i = 0; i < sl.size(); ++i) - { - QRegExp re("x:\\s*(\\d+);\\sy:\\s*(\\d+);\\sw:\\s*(\\d+);\\sh:\\s*(\\d+)"); - re.indexIn(sl.at(i)); - QStringList coords = re.capturedTexts(); - qDebug() << sl.at(i) << coords; - if ((coords.size() == 5) && (coords[0].size())) - xy->rects.push_back(QRect(coords[1].toInt() / 4, coords[2].toInt() / 4, coords[3].toInt() / 4, coords[4].toInt() / 4)); - } - f.close(); - xy->repaint(); -} diff -r 5cc671f988e7 -r 20178fa3a74a tools/templates/mainform.h --- a/tools/templates/mainform.h Sat Dec 01 20:38:45 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -#include -#include -#include -#include -#include -#include "pixlabel.h" - -class MyWindow : public QMainWindow -{ - Q_OBJECT - -public: - - MyWindow(QWidget * parent = 0, Qt::WFlags flags = 0); - -private: - - QScrollArea * sa_xy; - PixLabel * xy; - QPushButton * buttAdd; - QPushButton * buttCode; - QPushButton * buttSave; - QPushButton * buttLoad; - -private slots: - void Code(); - void Save(); - void Load(); -}; diff -r 5cc671f988e7 -r 20178fa3a74a tools/templates/pixlabel.cpp --- a/tools/templates/pixlabel.cpp Sat Dec 01 20:38:45 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -#include -#include -#include "pixlabel.h" - -PixLabel::PixLabel() - : QLabel(0) -{ - -} - -void PixLabel::paintEvent(QPaintEvent * event) -{ - QLabel::paintEvent(event); - QPainter p(this); - - p.fillRect(QRect(0, 0, 1024, 512), QBrush(Qt::black)); - - if (rects.size()) - { - p.setPen(QPen(Qt::lightGray)); - QVector centers; - for(QList::const_iterator it = rects.begin(); it != rects.end(); ++it) - centers.push_back((*it).center()); - p.drawPolyline(QPolygon(centers)); - - p.setPen(QPen(Qt::white)); - p.drawRects(rects.toVector()); - - p.setPen(QPen(Qt::yellow)); - p.drawRect(rects.last()); - } -} - -void PixLabel::mousePressEvent(QMouseEvent * e) -{ - if (!rects.empty()) - { - if (e->button() == Qt::LeftButton) - rects[rects.size() - 1].moveTopLeft(QPoint(e->x(), e->y())); - else - if (e->button() == Qt::RightButton) - rects[rects.size() - 1].setBottomRight(QPoint(e->x(), e->y())); - repaint(); - } -} - -void PixLabel::AddRect() -{ - rects.push_back(QRect(0, 0, 1, 1)); - repaint(); -} diff -r 5cc671f988e7 -r 20178fa3a74a tools/templates/pixlabel.h --- a/tools/templates/pixlabel.h Sat Dec 01 20:38:45 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -#include -#include -#include -#include - -class PixLabel : public QLabel -{ - Q_OBJECT - -public: - - PixLabel(); - QList rects; - -public slots: - void AddRect(); - -private: - void paintEvent(QPaintEvent * event); - void mousePressEvent(QMouseEvent * e); -}; diff -r 5cc671f988e7 -r 20178fa3a74a tools/templates/templates.pro --- a/tools/templates/templates.pro Sat Dec 01 20:38:45 2018 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -###################################################################### -# Automatically generated by qmake (2.01a) ?? 23. ??? 20:44:46 2007 -###################################################################### - -TEMPLATE = app -TARGET = -DEPENDPATH += . -INCLUDEPATH += . - -# Input -HEADERS += mainform.h pixlabel.h -SOURCES += main.cpp mainform.cpp pixlabel.cpp