First step to unite Layout and main windows.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2015-05-12 15:42:19 +03:00
parent 641e718a04
commit 3cb7e5a393
11 changed files with 350 additions and 114 deletions

View File

@ -19,7 +19,8 @@ SOURCES += \
$$PWD/tablewindow.cpp \
$$PWD/stable.cpp \
$$PWD/version.cpp \
$$PWD/options.cpp
$$PWD/options.cpp \
$$PWD/mainwindowsnogui.cpp
# Some header files
HEADERS += \
@ -27,7 +28,8 @@ HEADERS += \
$$PWD/options.h \
$$PWD/tablewindow.h \
$$PWD/stable.h \
$$PWD/version.h
$$PWD/version.h \
$$PWD/mainwindowsnogui.h
# Main forms
FORMS += \

View File

@ -118,9 +118,6 @@ int main(int argc, char *argv[])
MainWindow w;
app.setWindowIcon(QIcon(":/icon/64x64/icon64x64.png"));
app.setMainWindow(&w);
TableWindow table;
QObject::connect(&w, &MainWindow::ModelChosen, &table, &TableWindow::ModelChosen);
QObject::connect(&table, &TableWindow::closed, &w, &MainWindow::tableClosed);
QCommandLineParser parser;
parser.setApplicationDescription(QCoreApplication::translate("main", "Pattern making program."));

View File

@ -73,8 +73,8 @@ Q_LOGGING_CATEGORY(vMainWindow, "v.mainwindow")
* @param parent parent widget.
*/
MainWindow::MainWindow(QWidget *parent)
:QMainWindow(parent), ui(new Ui::MainWindow), pattern(nullptr), doc(nullptr), currentTool(Tool::Arrow),
lastUsedTool(Tool::Arrow), currentScene(nullptr), sceneDraw(nullptr), sceneDetails(nullptr),
:MainWindowsNoGUI(parent), ui(new Ui::MainWindow), doc(nullptr), currentTool(Tool::Arrow),
lastUsedTool(Tool::Arrow), sceneDraw(nullptr), sceneDetails(nullptr),
mouseCoordinate(nullptr), helpLabel(nullptr), isInitialized(false), dialogTable(nullptr), dialogTool(nullptr),
dialogHistory(nullptr), comboBoxDraws(nullptr), curFile(QString()), mode(Draw::Calculation), currentDrawIndex(0),
currentToolBoxIndex(0), drawMode(true), recentFileActs(),
@ -95,33 +95,13 @@ MainWindow::MainWindow(QWidget *parent)
CreateMenus();
ToolBarDraws();
InitToolButtons();
sceneDraw = new VMainGraphicsScene();
currentScene = sceneDraw;
qApp->setCurrentScene(currentScene);
connect(this, &MainWindow::EnableItemMove, sceneDraw, &VMainGraphicsScene::EnableItemMove);
connect(sceneDraw, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove);
sceneDetails = new VMainGraphicsScene();
connect(sceneDetails, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove);
ui->view->setScene(currentScene);
sceneDraw->setTransform(ui->view->transform());
sceneDetails->setTransform(ui->view->transform());
connect(ui->view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor);
QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding);
policy.setHorizontalStretch(12);
ui->view->setSizePolicy(policy);
qApp->setSceneView(ui->view);
InitScenes();
helpLabel = new QLabel(QObject::tr("Create new pattern piece to start working."));
ui->statusBar->addWidget(helpLabel);
ToolBarTools();
pattern = new VContainer();
doc = new VPattern(pattern, &mode, sceneDraw, sceneDetails);
connect(doc, &VPattern::ClearMainWindow, this, &MainWindow::Clear);
connect(doc, &VPattern::patternChanged, this, &MainWindow::PatternWasModified);
@ -221,6 +201,29 @@ void MainWindow::AddPP(const QString &PPName, const QString &path)
ui->actionNewDraw->setEnabled(true);
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::InitScenes()
{
sceneDraw = new VMainGraphicsScene();
currentScene = sceneDraw;
qApp->setCurrentScene(currentScene);
connect(this, &MainWindow::EnableItemMove, sceneDraw, &VMainGraphicsScene::EnableItemMove);
connect(sceneDraw, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove);
sceneDetails = new VMainGraphicsScene();
connect(sceneDetails, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove);
ui->view->setScene(currentScene);
sceneDraw->setTransform(ui->view->transform());
sceneDetails->setTransform(ui->view->transform());
connect(ui->view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor);
QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding);
policy.setHorizontalStretch(12);
ui->view->setSizePolicy(policy);
qApp->setSceneView(ui->view);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief OptionDraw help change name of pattern piece.
@ -704,16 +707,6 @@ void MainWindow::ShowToolTip(const QString &toolTip)
helpLabel->setText(toolTip);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief tableClosed handle after close layout window.
*/
void MainWindow::tableClosed()
{
ui->actionDetails->setChecked(true);
show();
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::OpenRecentFile()
{
@ -1124,6 +1117,8 @@ void MainWindow::keyPressEvent ( QKeyEvent * event )
* @brief SaveCurrentScene save scene options before set another.
*/
void MainWindow::SaveCurrentScene()
{
if (mode == Draw::Calculation || mode == Draw::Modeling)
{
/*Save transform*/
currentScene->setTransform(ui->view->transform());
@ -1133,6 +1128,7 @@ void MainWindow::SaveCurrentScene()
QScrollBar *verScrollBar = ui->view->verticalScrollBar();
currentScene->setVerScrollBar(verScrollBar->value());
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
@ -1160,11 +1156,13 @@ void MainWindow::ActionDraw(bool checked)
{
qCDebug(vMainWindow, "Show draw scene");
ui->actionDetails->setChecked(false);
ui->actionLayout->setChecked(false);
SaveCurrentScene();
currentScene = sceneDraw;
ui->view->setScene(currentScene);
connect(ui->view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor);
connect(ui->view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor,
Qt::UniqueConnection);
RestoreCurrentScene();
mode = Draw::Calculation;
@ -1180,6 +1178,8 @@ void MainWindow::ActionDraw(bool checked)
ui->actionOptionDraw->setEnabled(true);
ui->actionNewDraw->setEnabled(true);
ui->dockWidgetLayoutPages->setVisible(false);
ui->dockWidgetToolOptions->setVisible(true);
}
else
{
@ -1198,11 +1198,12 @@ void MainWindow::ActionDetails(bool checked)
{
qCDebug(vMainWindow, "Show details scene");
ui->actionDraw->setChecked(false);
ui->actionLayout->setChecked(false);
SaveCurrentScene();
currentScene = sceneDetails;
ui->view->itemClicked(nullptr);
ui->view->setScene(sceneDetails);
ui->view->setScene(currentScene);
disconnect(ui->view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor);
RestoreCurrentScene();
@ -1211,16 +1212,20 @@ void MainWindow::ActionDetails(bool checked)
comboBoxDraws->setCurrentIndex(comboBoxDraws->count()-1);
comboBoxDraws->setEnabled(false);
if (mode == Draw::Calculation)
{
currentToolBoxIndex = ui->toolBox->currentIndex();
}
mode = Draw::Modeling;
SetEnableTool(true);
currentToolBoxIndex = ui->toolBox->currentIndex();
ui->toolBox->setCurrentIndex(4);
ui->actionHistory->setEnabled(false);
ui->actionOptionDraw->setEnabled(false);
ui->actionNewDraw->setEnabled(false);
ui->dockWidgetLayoutPages->setVisible(false);
ui->dockWidgetToolOptions->setVisible(true);
}
else
{
@ -1228,6 +1233,60 @@ void MainWindow::ActionDetails(bool checked)
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ActionLayout begin creation layout.
* @param checked true - button checked.
*/
void MainWindow::ActionLayout(bool checked)
{
if (checked)
{
qCDebug(vMainWindow, "Show layout scene");
ui->actionDraw->setChecked(false);
ui->actionDetails->setChecked(false);
SaveCurrentScene();
const QHash<quint32, VDetail> *details = pattern->DataDetails();
if (details->count() == 0)
{
Layout();
return;
}
PrepareDetailsForLayout(details);
currentScene = tempSceneLayout;
ui->view->itemClicked(nullptr);
ui->view->setScene(currentScene);
disconnect(ui->view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor);
drawMode = false;
currentDrawIndex = comboBoxDraws->currentIndex();//save current pattern peace
comboBoxDraws->setCurrentIndex(-1);
comboBoxDraws->setEnabled(false);
if (mode == Draw::Calculation)
{
currentToolBoxIndex = ui->toolBox->currentIndex();
}
mode = Draw::Layout;
SetEnableTool(true);
ui->toolBox->setCurrentIndex(5);
ui->actionHistory->setEnabled(false);
ui->actionOptionDraw->setEnabled(false);
ui->actionNewDraw->setEnabled(false);
ui->dockWidgetLayoutPages->setVisible(true);
ui->dockWidgetToolOptions->setVisible(false);
}
else
{
ui->actionLayout->setChecked(true);
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief SaveAs save as pattern file.
@ -1644,16 +1703,17 @@ void MainWindow::ClickEndVisualization()
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::Layout()
{
const QHash<quint32, VDetail> *details = pattern->DataDetails();
if (details->size() > 0)
if (pattern->DataDetails()->size() > 0)
{
ui->actionDetails->setEnabled(true);
ui->actionLayout->setEnabled(true);
}
else
{
listDetails.clear();
ui->actionDetails->setEnabled(false);
ui->actionLayout->setEnabled(false);
ui->actionDraw->setChecked(true);
}
}
@ -1898,41 +1958,6 @@ void MainWindow::ActionCurveDetailsMode(bool checked)
sceneDraw->EnableDetailsMode(checked);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ActionLayout begin creation layout.
* @param checked true - button checked.
*/
void MainWindow::ActionLayout(bool checked)
{
Q_UNUSED(checked);
ActionDetails(true);//Get all list of details.
QVector<VLayoutDetail> listDetails;
const QHash<quint32, VDetail> *details = pattern->DataDetails();
if (details->count() == 0)
{
return;
}
hide();//Now we can hide window
QHashIterator<quint32, VDetail> idetail(*details);
while (idetail.hasNext())
{
idetail.next();
VLayoutDetail det = VLayoutDetail();
det.SetCountourPoints(idetail.value().ContourPoints(pattern));
det.SetSeamAllowencePoints(idetail.value().SeamAllowancePoints(pattern), idetail.value().getSeamAllowance());
det.setName(idetail.value().getName());
det.setWidth(qApp->toPixel(idetail.value().getWidth()));
listDetails.append(det);
}
QString description = doc->GetDescription();
QString fileName;
curFile.isEmpty() ? fileName = "unnamed" : fileName = curFile;
emit ModelChosen(listDetails, fileName, description);
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ClosedActionHistory actions after closing history window with variables.
@ -1952,14 +1977,23 @@ void MainWindow::SetEnableTool(bool enable)
{
bool drawTools = false;
bool modelingTools = false;
if (mode == Draw::Calculation)
bool layoutTools = false;
switch (mode)
{
case Draw::Calculation:
drawTools = enable;
}
else
{
break;
case Draw::Modeling:
modelingTools = enable;
break;
case Draw::Layout:
layoutTools = enable;
break;
default:
break;
}
//Drawing Tools
ui->toolButtonEndLine->setEnabled(drawTools);
ui->toolButtonLine->setEnabled(drawTools);
@ -1987,6 +2021,9 @@ void MainWindow::SetEnableTool(bool enable)
//Modeling Tools
ui->toolButtonUnionDetails->setEnabled(modelingTools);
//Layout tools
ui->toolButtonLayoutSettings->setEnabled(layoutTools);
}
//---------------------------------------------------------------------------------------------------------------------
@ -2456,7 +2493,6 @@ MainWindow::~MainWindow()
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
delete lock; // Unlock pattern file
#endif
delete pattern;
delete doc;
delete sceneDetails;
delete sceneDraw;

View File

@ -29,15 +29,14 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "widgets/vmaingraphicsscene.h"
#include "mainwindowsnogui.h"
#include "widgets/vmaingraphicsview.h"
#include "dialogs/dialogs.h"
#include "tools/vtooldetail.h"
#include "tools/vtooluniondetails.h"
#include "tools/drawTools/drawtools.h"
#include "xml/vdomdocument.h"
#include "../libs/vlayout/vlayoutdetail.h"
namespace Ui
{
@ -49,7 +48,7 @@ class VToolOptionsPropertyBrowser;
/**
* @brief The MainWindow class main windows.
*/
class MainWindow : public QMainWindow
class MainWindow : public MainWindowsNoGUI
{
Q_OBJECT
public:
@ -70,7 +69,6 @@ public slots:
void ActionCurveDetailsMode(bool checked);
void DrawOption();
void tableClosed();
void ClosedActionTable();
void ClosedActionHistory();
@ -141,13 +139,6 @@ public slots:
void WindowsLocale();
void ToolBarStyles();
signals:
/**
* @brief ModelChosen emit after calculation all details.
* @param listDetails list of details.
* @param description pattern description.
*/
void ModelChosen(QVector<VLayoutDetail> listDetails, const QString &curFile,
const QString &description);
void RefreshHistory();
void EnableItemMove(bool move);
protected:
@ -160,9 +151,6 @@ private:
/** @brief ui keeps information about user interface */
Ui::MainWindow *ui;
/** @brief pattern container with data (points, arcs, splines, spline paths, variables) */
VContainer *pattern;
/** @brief doc dom document container */
VPattern *doc;
@ -172,9 +160,6 @@ private:
/** @brief tool last used tool */
Tool lastUsedTool;
/** @brief currentScene pointer to current scene. */
VMainGraphicsScene *currentScene;
/** @brief sceneDraw draw scene. */
VMainGraphicsScene *sceneDraw;
@ -284,6 +269,8 @@ private:
void ToolBarStyle(QToolBar *bar);
void AddPP(const QString &PPName, const QString &path);
void InitScenes();
};
#endif // MAINWINDOW_H

View File

@ -40,7 +40,7 @@
<string/>
</property>
<property name="currentIndex">
<number>4</number>
<number>5</number>
</property>
<widget class="QWidget" name="page">
<property name="geometry">
@ -734,6 +734,32 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="page_6">
<attribute name="label">
<string>Layout</string>
</attribute>
<layout class="QFormLayout" name="formLayout_6">
<item row="0" column="0">
<widget class="QToolButton" name="toolButtonLayoutSettings">
<property name="text">
<string>Settings</string>
</property>
<property name="icon">
<iconset theme="emblem-system"/>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
@ -990,6 +1016,40 @@
</attribute>
<addaction name="actionArrowTool"/>
</widget>
<widget class="QDockWidget" name="dockWidgetLayoutPages">
<property name="features">
<set>QDockWidget::NoDockWidgetFeatures</set>
</property>
<property name="allowedAreas">
<set>Qt::RightDockWidgetArea</set>
</property>
<property name="windowTitle">
<string>Layout pages</string>
</property>
<attribute name="dockWidgetArea">
<number>2</number>
</attribute>
<widget class="QWidget" name="dockWidgetContents">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="listWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="iconSize">
<size>
<width>150</width>
<height>200</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<action name="actionNew">
<property name="icon">
<iconset theme="document-new">
@ -1202,6 +1262,9 @@
</property>
</action>
<action name="actionLayout">
<property name="checkable">
<bool>true</bool>
</property>
<property name="enabled">
<bool>false</bool>
</property>

View File

@ -0,0 +1,81 @@
/************************************************************************
**
** @file mainwindowsnogui.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 12 5, 2015
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2015 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "mainwindowsnogui.h"
#include "../core/vapplication.h"
#include "../container/vcontainer.h"
#include <QGraphicsScene>
//---------------------------------------------------------------------------------------------------------------------
MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent)
: QMainWindow(parent), listDetails(QVector<VLayoutDetail>()), currentScene(nullptr), tempSceneLayout(nullptr),
pattern(new VContainer())
{
InitTempLayoutScene();
}
//---------------------------------------------------------------------------------------------------------------------
MainWindowsNoGUI::~MainWindowsNoGUI()
{
delete tempSceneLayout;
delete pattern;
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindowsNoGUI::PrepareDetailsForLayout(const QHash<quint32, VDetail> *details)
{
SCASSERT(details != nullptr)
if (details->count() == 0)
{
listDetails.clear();
return;
}
listDetails.clear();
QHashIterator<quint32, VDetail> idetail(*details);
while (idetail.hasNext())
{
idetail.next();
VLayoutDetail det = VLayoutDetail();
det.SetCountourPoints(idetail.value().ContourPoints(pattern));
det.SetSeamAllowencePoints(idetail.value().SeamAllowancePoints(pattern),
idetail.value().getSeamAllowance());
det.setName(idetail.value().getName());
det.setWidth(qApp->toPixel(idetail.value().getWidth()));
listDetails.append(det);
}
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindowsNoGUI::InitTempLayoutScene()
{
tempSceneLayout = new VMainGraphicsScene();
tempSceneLayout->setBackgroundBrush( QBrush(QColor(Qt::gray), Qt::SolidPattern) );
}

View File

@ -0,0 +1,65 @@
/************************************************************************
**
** @file mainwindowsnogui.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 12 5, 2015
**
** @brief
** @copyright
** This source code is part of the Valentine project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2015 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef MAINWINDOWSNOGUI_H
#define MAINWINDOWSNOGUI_H
#include <QMainWindow>
#include "../geometry/vdetail.h"
#include "../libs/vlayout/vlayoutdetail.h"
#include "../widgets/vmaingraphicsscene.h"
class MainWindowsNoGUI : public QMainWindow
{
Q_OBJECT
public:
MainWindowsNoGUI(QWidget *parent = nullptr);
virtual ~MainWindowsNoGUI();
protected:
QVector<VLayoutDetail> listDetails;
/** @brief currentScene pointer to current scene. */
VMainGraphicsScene *currentScene;
VMainGraphicsScene *tempSceneLayout;
/** @brief pattern container with data (points, arcs, splines, spline paths, variables) */
VContainer *pattern;
void PrepareDetailsForLayout(const QHash<quint32, VDetail> *details);
void InitTempLayoutScene();
private:
Q_DISABLE_COPY(MainWindowsNoGUI)
};
#endif // MAINWINDOWSNOGUI_H

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -5,7 +5,7 @@ Inherits=gnome,hicolor
Example=x-directory-normal
#Directories
Directories=16x16/actions,24x24/actions,32x32/actions
Directories=16x16/actions,24x24/actions,32x32/actions,32x32/emblems
[16x16/actions]
Size=16
@ -22,4 +22,8 @@ Size=32
Context=Actions
Type=Fixed
[32x32/emblemss]
Size=32
Context=Emblems
Type=Fixed

View File

@ -67,5 +67,6 @@
<file alias="16x16/actions/document-print-preview.png">icons/win.icon.theme/16x16/actions/document-print-preview.png</file>
<file alias="24x24/actions/document-print-preview.png">icons/win.icon.theme/24x24/actions/document-print-preview.png</file>
<file alias="32x32/actions/document-print-preview.png">icons/win.icon.theme/32x32/actions/document-print-preview.png</file>
<file alias="32x32/emblems/emblem-system.png">icons/win.icon.theme/32x32/emblems/emblem-system.png</file>
</qresource>
</RCC>

View File

@ -31,7 +31,7 @@
#include <QString>
enum class Draw : char { Calculation, Modeling };
enum class Draw : char { Calculation, Modeling, Layout };
enum class GOType : char { Point, Arc, Spline, SplinePath, Unknown };
enum class SplinePointPosition : char { FirstPoint, LastPoint };