diff --git a/.hgignore b/.hgignore new file mode 100644 index 000000000..6f58ef173 --- /dev/null +++ b/.hgignore @@ -0,0 +1,24 @@ +syntax: glob +# This line is a comment, and will be skipped. +# Empty lines are skipped too. + +# Backup files left behind by the Emacs editor. +*~ + +# Lock files used by the Emacs editor. +# Notice that the "#" character is quoted with a backslash. +# This prevents it from being interpreted as starting a comment. +.\#* + +# Temporary files used by the vim editor. +.*.swp + +# A hidden file created by the Mac OS X Finder. +.DS_Store + +# Ignore this directory. +html/ +latex/ + +# Ignore file used QtCreator for user profile. +*.pro.user diff --git a/Valentina.pro b/Valentina.pro index 620921789..0a3e5acd1 100644 --- a/Valentina.pro +++ b/Valentina.pro @@ -13,8 +13,18 @@ TEMPLATE = app SOURCES += main.cpp\ - mainwindow.cpp + mainwindow.cpp \ + widgets/vmaingraphicsscene.cpp \ + dialogs/dialogsinglepoint.cpp -HEADERS += mainwindow.h +HEADERS += mainwindow.h \ + widgets/vmaingraphicsscene.h \ + dialogs/dialogsinglepoint.h \ + options.h -FORMS += mainwindow.ui +FORMS += mainwindow.ui \ + dialogs/dialogsinglepoint.ui + +RESOURCES += \ + icon.qrc \ + cursor.qrc diff --git a/cursor.qrc b/cursor.qrc new file mode 100644 index 000000000..bacb46320 --- /dev/null +++ b/cursor.qrc @@ -0,0 +1,5 @@ + + + cursor/spoint_cursor.png + + diff --git a/cursor/spoint_cursor.png b/cursor/spoint_cursor.png new file mode 100644 index 000000000..6aaeb759e Binary files /dev/null and b/cursor/spoint_cursor.png differ diff --git a/dialogs/dialogsinglepoint.cpp b/dialogs/dialogsinglepoint.cpp new file mode 100644 index 000000000..43687e9dd --- /dev/null +++ b/dialogs/dialogsinglepoint.cpp @@ -0,0 +1,61 @@ +#include "dialogsinglepoint.h" +#include "ui_dialogsinglepoint.h" +#include +#include + +#include "../options.h" + +DialogSinglePoint::DialogSinglePoint(QWidget *parent) : + QDialog(parent), + ui(new Ui::DialogSinglePoint) +{ + ui->setupUi(this); + isInitialized = false; + ui->spinBoxX->setRange(0,(qint32)(PaperSize*PrintDPI/25.4)); + ui->spinBoxY->setRange(0,(qint32)(PaperSize*PrintDPI/25.4)); + QPushButton* pOkButton = ui->buttonBox->button(QDialogButtonBox::Ok); + pOkButton->setEnabled(false); + connect(ui->lineEditName, &QLineEdit::textChanged, this, &DialogSinglePoint::NameChanged); +} + +void DialogSinglePoint::mousePress(QPointF scenePos){ + if(isInitialized == false){ + ui->spinBoxX->setValue((qint32)(scenePos.x()*PrintDPI/25.4)); + ui->spinBoxY->setValue((qint32)(scenePos.y()*PrintDPI/25.4)); + this->show(); + } else { + ui->spinBoxX->setValue((qint32)(scenePos.x()*PrintDPI/25.4)); + ui->spinBoxY->setValue((qint32)(scenePos.y()*PrintDPI/25.4)); + } +} + +void DialogSinglePoint::showEvent( QShowEvent *event ){ + QDialog::showEvent( event ); + if( event->spontaneous() ){ + return; + } + + if(isInitialized){ + return; + } + + // do your init stuff here + + isInitialized = true;//перший показ вікна вже відбувся +} + +void DialogSinglePoint::NameChanged(){ + QString name = ui->lineEditName->text(); + if(name.isEmpty() || name.contains(" ")){ + QPushButton* pOkButton = ui->buttonBox->button(QDialogButtonBox::Ok); + pOkButton->setEnabled(false); + } else { + QPushButton* pOkButton = ui->buttonBox->button(QDialogButtonBox::Ok); + pOkButton->setEnabled(true); + } +} + +DialogSinglePoint::~DialogSinglePoint() +{ + delete ui; +} diff --git a/dialogs/dialogsinglepoint.h b/dialogs/dialogsinglepoint.h new file mode 100644 index 000000000..70d861d2c --- /dev/null +++ b/dialogs/dialogsinglepoint.h @@ -0,0 +1,27 @@ +#ifndef DIALOGSINGLEPOINT_H +#define DIALOGSINGLEPOINT_H + +#include + +namespace Ui { +class DialogSinglePoint; +} + +class DialogSinglePoint : public QDialog +{ + Q_OBJECT + +public: + explicit DialogSinglePoint(QWidget *parent = 0); + ~DialogSinglePoint(); +protected: + void showEvent( QShowEvent *event ); +public slots: + void mousePress(QPointF scenePos); + void NameChanged(); +private: + Ui::DialogSinglePoint *ui; + bool isInitialized; +}; + +#endif // DIALOGSINGLEPOINT_H diff --git a/dialogs/dialogsinglepoint.ui b/dialogs/dialogsinglepoint.ui new file mode 100644 index 000000000..a57a23848 --- /dev/null +++ b/dialogs/dialogsinglepoint.ui @@ -0,0 +1,132 @@ + + + DialogSinglePoint + + + Qt::WindowModal + + + + 0 + 0 + 249 + 202 + + + + Параметри точки + + + false + + + + + 10 + 40 + 241 + 129 + + + + Координати + + + + + + + + + Y координата + + + + + + + + + + Х координата + + + + + + + + + 170 + 10 + 72 + 17 + + + + Ім'я точки + + + + + + 15 + 9 + 146 + 27 + + + + + + + 20 + 170 + 221 + 27 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + buttonBox + accepted() + DialogSinglePoint + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DialogSinglePoint + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/icon.qrc b/icon.qrc new file mode 100644 index 000000000..257b236f6 --- /dev/null +++ b/icon.qrc @@ -0,0 +1,9 @@ + + + icon/64x64/icon64x64.png + icon/32x32/draw.png + icon/32x32/kontur.png + icon/32x32/spoint.png + icon/32x32/arrow_cursor.png + + diff --git a/icon/32x32/arrow_cursor.png b/icon/32x32/arrow_cursor.png new file mode 100644 index 000000000..b0df739d1 Binary files /dev/null and b/icon/32x32/arrow_cursor.png differ diff --git a/icon/32x32/draw.png b/icon/32x32/draw.png new file mode 100644 index 000000000..db49026c4 Binary files /dev/null and b/icon/32x32/draw.png differ diff --git a/icon/32x32/kontur.png b/icon/32x32/kontur.png new file mode 100644 index 000000000..f38e07dc2 Binary files /dev/null and b/icon/32x32/kontur.png differ diff --git a/icon/32x32/spoint.png b/icon/32x32/spoint.png new file mode 100644 index 000000000..6b632689a Binary files /dev/null and b/icon/32x32/spoint.png differ diff --git a/icon/64x64/icon64x64.png b/icon/64x64/icon64x64.png new file mode 100644 index 000000000..d6cc04903 Binary files /dev/null and b/icon/64x64/icon64x64.png differ diff --git a/main.cpp b/main.cpp index 9e2d83c83..4d7f46b0d 100644 --- a/main.cpp +++ b/main.cpp @@ -1,11 +1,13 @@ #include "mainwindow.h" #include +#include int main(int argc, char *argv[]) { - QApplication a(argc, argv); + QApplication app(argc, argv); MainWindow w; + app.setWindowIcon(QIcon(":/icon/64x64/icon64x64.png")); w.show(); - return a.exec(); + return app.exec(); } diff --git a/mainwindow.cpp b/mainwindow.cpp index 39c3d43de..d4035deac 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -2,21 +2,167 @@ #include "ui_mainwindow.h" #include +#include +#include +#include +#include + +#include "options.h" MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::MainWindow) + QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); + tool = Tools::ArrayTool; + isInitialized = false; + ToolBarOption(); + ToolBarDraws(); + QRectF sceneRect = QRectF(0, 0, PaperSize*PrintDPI/25.4, PaperSize*PrintDPI/25.4); + scene = new VMainGraphicsScene(sceneRect); + ui->graphicsView->setScene(scene); + + connect(scene, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove); + connect(ui->toolButtonSinglePoint, &QToolButton::clicked, this, + &MainWindow::clickedToolButtonSinglePoint); + helpLabel = new QLabel("Створіть новий файл для початку роботи."); + ui->statusBar->addWidget(helpLabel); + + connect(ui->actionArrowTool, &QAction::triggered, this, &MainWindow::triggeredActionAroowTool); +} + +/* + * Інструмет базова точка креслення. + */ +void MainWindow::clickedToolButtonSinglePoint(){ + tool = Tools::SinglePointTool; + QPixmap pixmap(":/cursor/spoint_cursor.png"); + QCursor cur(pixmap, 2, 3); + ui->graphicsView->setCursor(cur); + helpLabel->setText("Виберіть розташування для точки."); + dialogSinglePoint = new DialogSinglePoint; + connect(scene, &VMainGraphicsScene::mousePress, dialogSinglePoint, &DialogSinglePoint::mousePress); +} + +void MainWindow::showEvent( QShowEvent *event ){ + QMainWindow::showEvent( event ); + if( event->spontaneous() ){ + return; + } + + if(isInitialized){ + return; + } + + // do your init stuff here + QScrollBar *horScrollBar = ui->graphicsView->horizontalScrollBar(); + horScrollBar->setValue(horScrollBar->minimum()); + QScrollBar *verScrollBar = ui->graphicsView->verticalScrollBar(); + verScrollBar->setValue(verScrollBar->minimum()); + + isInitialized = true;//перший показ вікна вже відбувся +} + +void MainWindow::ToolBarOption(){ + QLabel * labelGrowth = new QLabel; + labelGrowth->setText("Зріст: "); + ui->toolBarOption->addWidget(labelGrowth); + QStringList list; + list << "104"<<"110"<<"116"<<"122"<<"128"<<"134"<<"140"<<"146"<<"152"<<"158"<<"164"<<"170"<<"176" + << "182" << "188"; + QComboBox* comboBoxGrow = new QComboBox; + comboBoxGrow->clear(); + comboBoxGrow->addItems(list); + comboBoxGrow->setCurrentIndex(12); + ui->toolBarOption->addWidget(comboBoxGrow); + + QLabel * labelSize = new QLabel; + labelSize->setText(" Розмір: "); + ui->toolBarOption->addWidget(labelSize); + + list.clear(); list << "28"<<"30"<<"32"<<"34"<<"36"<<"38"<<"40"<<"42"<<"44"<<"46"<<"48"<<"50" << "52" << "54" << "56"; QComboBox* comboBoxSize = new QComboBox; - comboBoxSize ->clear(); + comboBoxSize->clear(); comboBoxSize->addItems(list); + comboBoxSize->setCurrentIndex(11); ui->toolBarOption->addWidget(comboBoxSize); + + ui->toolBarOption->addSeparator(); + + mouseCoordinate = new QLabel; + mouseCoordinate ->setText("0, 0"); + ui->toolBarOption->addWidget(mouseCoordinate); + +} + +void MainWindow::ToolBarDraws(){ + QLabel * labelNameDraw = new QLabel; + labelNameDraw ->setText("Креслення: "); + ui->toolBarDraws->addWidget(labelNameDraw); + + QComboBox* comboBoxDraws = new QComboBox; + ui->toolBarDraws->addWidget(comboBoxDraws); + + ui->toolBarDraws->addSeparator(); + + QLabel* labelTranslateX = new QLabel; + labelTranslateX ->setText(" Зміщення по Х: "); + ui->toolBarDraws->addWidget(labelTranslateX); + + QSpinBox* spinBoxTranslateX = new QSpinBox; + spinBoxTranslateX->setRange(0,(qint32)(PaperSize*PrintDPI/25.4)); + spinBoxTranslateX->setFixedSize(80,25); + ui->toolBarDraws->addWidget(spinBoxTranslateX); + + QLabel* labelTranslateY = new QLabel; + labelTranslateY ->setText(" Зміщення по Y: "); + ui->toolBarDraws->addWidget(labelTranslateY); + + QSpinBox* spinBoxTranslateY = new QSpinBox; + spinBoxTranslateY->setRange(0,(qint32)(PaperSize*PrintDPI/25.4)); + spinBoxTranslateY->setFixedSize(80,25); + ui->toolBarDraws->addWidget(spinBoxTranslateY); + + QPushButton* pushButtonTranslate = new QPushButton; + pushButtonTranslate->setText("Застосувати"); + ui->toolBarDraws->addWidget(pushButtonTranslate); +} + +void MainWindow::mouseMove(QPointF scenePos){ + QString string = QString("%1, %2") + .arg((qint32)(scenePos.x()*PrintDPI/25.4)) + .arg((qint32)(scenePos.y()*PrintDPI/25.4)); + mouseCoordinate->setText(string); +} + +void MainWindow::CanselTool(){ + switch( tool ) + { + case Tools::ArrowTool: + //Покищо нічого тут не робимо. + break; + case Tools::SinglePointTool: + //Знищимо діалогове вікно. + delete dialogSinglePoint; + break; + } +} + +void MainWindow::ArrowTool(){ + CanselTool(); + tool = Tools::ArrowTool; + QCursor cur(Qt::ArrowCursor); + ui->graphicsView->setCursor(cur); + helpLabel->setText(""); +} + +void MainWindow::triggeredActionAroowTool(){ + ArrowTool(); } MainWindow::~MainWindow() { + CanselTool(); delete ui; } diff --git a/mainwindow.h b/mainwindow.h index 112fda1c4..1fadc45c5 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -2,21 +2,46 @@ #define MAINWINDOW_H #include +#include + +#include "widgets/vmaingraphicsscene.h" +#include "dialogs/dialogsinglepoint.h" namespace Ui { class MainWindow; } +namespace Tools{ + enum Enum + { + ArrowTool, + SinglePointTool + }; +} + class MainWindow : public QMainWindow { - Q_OBJECT - + Q_OBJECT public: - explicit MainWindow(QWidget *parent = 0); - ~MainWindow(); - + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); +public slots: + void mouseMove(QPointF scenePos); + void showEvent( QShowEvent *event ); + void clickedToolButtonSinglePoint(); + void triggeredActionAroowTool(); private: - Ui::MainWindow *ui; + Ui::MainWindow *ui; + Tools::Enum tool; + VMainGraphicsScene *scene; + QLabel *mouseCoordinate; + QLabel *helpLabel; + bool isInitialized; + DialogSinglePoint *dialogSinglePoint; + void ToolBarOption(); + void ToolBarDraws(); + void CanselTool(); + void ArrowTool(); }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index d9f56532d..300d96322 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -6,7 +6,7 @@ 0 0 - 1000 + 1100 700 @@ -14,9 +14,37 @@ Valentina - - + + + + + + 6 + 0 + + + + + 922 + 582 + + + + true + + + Qt::AlignBottom|Qt::AlignRight|Qt::AlignTrailing + + + + + + + 1 + 0 + + 0 @@ -25,42 +53,72 @@ 0 0 - 117 - 111 + 154 + 81 + + + 0 + 0 + + Точка - - - + + + - PushButton + ... - - buttonGroup - - - + + - PushButton + ... - - buttonGroup - - - + + - PushButton + ... + + + + + + + Точка + + + + + + Точка + + + + :/icon/32x32/spoint.png:/icon/32x32/spoint.png + + + + 24 + 24 + + + + true + + + + + + + ... - - buttonGroup - @@ -70,15 +128,21 @@ 0 0 - 117 + 154 111 + + + 0 + 0 + + Лінія - - + + PushButton @@ -88,7 +152,7 @@ - + PushButton @@ -98,7 +162,7 @@ - + PushButton @@ -115,15 +179,21 @@ 0 0 - 117 - 73 + 154 + 45 + + + 0 + 0 + + Сплайн - - + + PushButton @@ -137,15 +207,21 @@ 0 0 - 117 - 73 + 154 + 45 + + + 0 + 0 + + Дуга - - + + PushButton @@ -156,16 +232,6 @@ - - - - - 2 - 0 - - - - @@ -173,7 +239,7 @@ 0 0 - 1000 + 1100 25 @@ -203,6 +269,7 @@ + @@ -223,7 +290,7 @@ BottomToolBarArea - true + false @@ -282,6 +349,16 @@ true + + true + + + true + + + + :/icon/32x32/draw.png:/icon/32x32/draw.png + Креслення @@ -290,6 +367,13 @@ + + true + + + + :/icon/32x32/kontur.png:/icon/32x32/kontur.png + Деталі @@ -297,9 +381,29 @@ Режим деталі + + + true + + + true + + + + :/icon/32x32/arrow_cursor.png:/icon/32x32/arrow_cursor.png + + + Інструмент вказівник + + + Інструмент вказівник + + - + + + @@ -307,10 +411,5 @@ false - - - false - - diff --git a/options.h b/options.h new file mode 100644 index 000000000..25772ccc6 --- /dev/null +++ b/options.h @@ -0,0 +1,7 @@ +#ifndef OPTIONS_H +#define OPTIONS_H + +#define PrintDPI 96 +#define PaperSize 50000 + +#endif // OPTIONS_H diff --git a/widgets/vmaingraphicsscene.cpp b/widgets/vmaingraphicsscene.cpp new file mode 100644 index 000000000..1633c1d6d --- /dev/null +++ b/widgets/vmaingraphicsscene.cpp @@ -0,0 +1,21 @@ +#include "vmaingraphicsscene.h" + + +VMainGraphicsScene::VMainGraphicsScene():QGraphicsScene() +{ +} + + +VMainGraphicsScene::VMainGraphicsScene(const QRectF & sceneRect, QObject * parent):QGraphicsScene ( sceneRect, parent ) +{ +} + +void VMainGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* event){ + emit mouseMove(event->scenePos()); + QGraphicsScene::mouseMoveEvent(event); +} + +void VMainGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event){ + emit mousePress(event->scenePos()); + QGraphicsScene::mousePressEvent(event); +} diff --git a/widgets/vmaingraphicsscene.h b/widgets/vmaingraphicsscene.h new file mode 100644 index 000000000..1a7a2bf39 --- /dev/null +++ b/widgets/vmaingraphicsscene.h @@ -0,0 +1,21 @@ +#ifndef VMAINGRAPHICSSCENE_H +#define VMAINGRAPHICSSCENE_H + +#include +#include + +class VMainGraphicsScene : public QGraphicsScene +{ + Q_OBJECT +public: + VMainGraphicsScene(); + VMainGraphicsScene(const QRectF & sceneRect, QObject * parent = 0); +private: + void mouseMoveEvent(QGraphicsSceneMouseEvent* event); + void mousePressEvent(QGraphicsSceneMouseEvent *event); +signals: + void mouseMove(QPointF scenePos); + void mousePress(QPointF scenePos); +}; + +#endif // VMAINGRAPHICSSCENE_H