Tool layout settings.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2015-05-12 18:15:10 +03:00
parent f4e511e825
commit c76718e9d0
47 changed files with 319 additions and 68 deletions

View file

@ -2068,14 +2068,14 @@ VSettings *VApplication::getSettings()
}
//---------------------------------------------------------------------------------------------------------------------
VMainGraphicsScene *VApplication::getCurrentScene() const
QGraphicsScene *VApplication::getCurrentScene() const
{
SCASSERT(currentScene != nullptr);
return currentScene;
}
//---------------------------------------------------------------------------------------------------------------------
void VApplication::setCurrentScene(VMainGraphicsScene *value)
void VApplication::setCurrentScene(QGraphicsScene *value)
{
currentScene = value;
}

View file

@ -38,7 +38,6 @@
class VApplication;// used in define
class QUndoStack;
class VMainGraphicsView;
class VMainGraphicsScene;
class VPattern;
class QFile;
#if QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)
@ -110,8 +109,8 @@ public:
void OpenSettings();
VSettings *getSettings();
VMainGraphicsScene *getCurrentScene() const;
void setCurrentScene(VMainGraphicsScene *value);
QGraphicsScene *getCurrentScene() const;
void setCurrentScene(QGraphicsScene *value);
void setCurrentDocument(VPattern *doc);
VPattern *getCurrentDocument()const;
@ -151,7 +150,7 @@ private:
QMap<QString, qmu::QmuTranslation> stDescriptions;
QUndoStack *undoStack;
VMainGraphicsView *sceneView;
VMainGraphicsScene *currentScene;
QGraphicsScene *currentScene;
QTimer *autoSaveTimer;
/**
* @brief mainWindow pointer to main window. Usefull if need create modal dialog. Without pointer to main window

View file

@ -117,7 +117,8 @@ void DialogAlongLine::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolAlongLine::SetFactor);
scene->addItem(line);
line->RefreshGeometry();

View file

@ -225,7 +225,8 @@ void DialogArc::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor);
scene->addItem(path);
path->RefreshGeometry();

View file

@ -126,7 +126,8 @@ void DialogBisector::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolBisector::SetFactor);
scene->addItem(line);
line->RefreshGeometry();

View file

@ -166,7 +166,7 @@ void DialogCurveIntersectAxis::ShowDialog(bool click)
if (click)
{
/*We will ignore click if poinet is in point circle*/
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr);
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(GetBasePointId());
QLineF line = QLineF(point->toQPointF(), scene->getScenePos());
@ -258,7 +258,8 @@ void DialogCurveIntersectAxis::ShowVisualization()
if (prepare == false)
{
//TODO move to parent class!
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolCurveIntersectAxis::SetFactor);
scene->addItem(line);
line->RefreshGeometry();

View file

@ -92,7 +92,8 @@ void DialogCutArc::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor);
scene->addItem(path);
path->RefreshGeometry();

View file

@ -196,7 +196,8 @@ void DialogCutSpline::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor);
scene->addItem(path);
path->RefreshGeometry();

View file

@ -196,7 +196,8 @@ void DialogCutSplinePath::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor);
scene->addItem(path);
path->RefreshGeometry();

View file

@ -261,7 +261,7 @@ void DialogEndLine::ShowDialog(bool click)
if (click)
{
/*We will ignore click if poinet is in point circle*/
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr);
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(GetBasePointId());
QLineF line = QLineF(point->toQPointF(), scene->getScenePos());
@ -287,7 +287,8 @@ void DialogEndLine::ShowVisualization()
if (prepare == false)
{
//TODO move to parent class!
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolEndLine::SetFactor);
scene->addItem(line);
line->RefreshGeometry();

View file

@ -254,7 +254,8 @@ void DialogHeight::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor);
scene->addItem(line);
line->RefreshGeometry();

View file

@ -145,7 +145,8 @@ void DialogLine::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolLine::SetFactor);
scene->addItem(line);
line->RefreshGeometry();

View file

@ -229,7 +229,8 @@ void DialogLineIntersect::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor);
scene->addItem(line);
line->RefreshGeometry();

View file

@ -187,7 +187,7 @@ void DialogLineIntersectAxis::ShowDialog(bool click)
if (click)
{
/*We will ignore click if poinet is in point circle*/
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr);
const QSharedPointer<VPointF> point = data->GeometricObject<VPointF>(GetBasePointId());
QLineF line = QLineF(point->toQPointF(), scene->getScenePos());
@ -322,7 +322,8 @@ void DialogLineIntersectAxis::ShowVisualization()
if (prepare == false)
{
//TODO move to parent class!
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisToolLineIntersectAxis::SetFactor);
scene->addItem(line);
line->RefreshGeometry();

View file

@ -116,7 +116,8 @@ void DialogNormal::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor);
scene->addItem(line);
line->RefreshGeometry();

View file

@ -133,7 +133,8 @@ void DialogPointOfContact::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor);
scene->addItem(line);
line->RefreshGeometry();

View file

@ -161,7 +161,8 @@ void DialogPointOfIntersection::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor);
line->RefreshGeometry();
}

View file

@ -126,7 +126,8 @@ void DialogShoulderPoint::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor);
scene->addItem(line);
line->RefreshGeometry();

View file

@ -185,7 +185,8 @@ void DialogSpline::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor);
scene->addItem(path);
path->RefreshGeometry();

View file

@ -267,7 +267,8 @@ void DialogSplinePath::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visPath, &Visualization::SetFactor);
scene->addItem(visPath);
visPath->setMode(Mode::Show);

View file

@ -200,7 +200,8 @@ void DialogTriangle::ShowVisualization()
{
if (prepare == false)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, line, &VisLine::SetFactor);
scene->addItem(line);
line->RefreshGeometry();

View file

@ -264,7 +264,11 @@ void MainWindow::SetToolButton(bool checked, Tool t, const QString &cursor, cons
helpLabel->setText(toolTip);
ui->view->setShowToolOptions(false);
dialogTool = new Dialog(pattern, 0, this);
connect(currentScene, &VMainGraphicsScene::ChoosedObject, dialogTool, &DialogTool::ChosenObject);
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(currentScene);
SCASSERT(scene != nullptr);
connect(scene, &VMainGraphicsScene::ChoosedObject, dialogTool, &DialogTool::ChosenObject);
connect(dialogTool, &DialogTool::DialogClosed, this, closeDialogSlot);
connect(dialogTool, &DialogTool::ToolTip, this, &MainWindow::ShowToolTip);
ui->view->itemClicked(nullptr);
@ -273,7 +277,6 @@ void MainWindow::SetToolButton(bool checked, Tool t, const QString &cursor, cons
{
if (QToolButton *tButton = qobject_cast< QToolButton * >(this->sender()))
{
SCASSERT(tButton != nullptr);
tButton->setChecked(true);
}
}
@ -304,7 +307,11 @@ void MainWindow::SetToolButtonWithApply(bool checked, Tool t, const QString &cur
ui->view->setShowToolOptions(false);
helpLabel->setText(toolTip);
dialogTool = new Dialog(pattern, 0, this);
connect(currentScene, &VMainGraphicsScene::ChoosedObject, dialogTool, &DialogTool::ChosenObject);
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(currentScene);
SCASSERT(scene != nullptr);
connect(scene, &VMainGraphicsScene::ChoosedObject, dialogTool, &DialogTool::ChosenObject);
connect(dialogTool, &DialogTool::DialogClosed, this, closeDialogSlot);
connect(dialogTool, &DialogTool::DialogApplied, this, applyDialogSlot);
connect(dialogTool, &DialogTool::ToolTip, this, &MainWindow::ShowToolTip);
@ -315,7 +322,6 @@ void MainWindow::SetToolButtonWithApply(bool checked, Tool t, const QString &cur
{
if (QToolButton *tButton = qobject_cast< QToolButton * >(this->sender()))
{
SCASSERT(tButton != nullptr);
tButton->setChecked(true);
}
}
@ -331,7 +337,10 @@ void MainWindow::ClosedDialog(int result)
SCASSERT(dialogTool != nullptr);
if (result == QDialog::Accepted)
{
QGraphicsItem *tool = dynamic_cast<QGraphicsItem *>(DrawTool::Create(dialogTool, currentScene, doc, pattern));
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(currentScene);
SCASSERT(scene != nullptr);
QGraphicsItem *tool = dynamic_cast<QGraphicsItem *>(DrawTool::Create(dialogTool, scene, doc, pattern));
ui->view->itemClicked(tool);
}
ArrowTool();
@ -351,8 +360,11 @@ void MainWindow::ClosedDialogWithApply(int result)
// Only create tool if not already created with apply
if (dialogTool->GetAssociatedTool() == nullptr)
{
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(currentScene);
SCASSERT(scene != nullptr);
dialogTool->SetAssociatedTool(
dynamic_cast<VAbstractTool * > (DrawTool::Create(dialogTool, currentScene, doc, pattern)));
dynamic_cast<VAbstractTool * > (DrawTool::Create(dialogTool, scene, doc, pattern)));
}
else
{ // Or update associated tool with data
@ -382,8 +394,11 @@ void MainWindow::ApplyDialog()
// Only create tool if not already created with apply
if (dialogTool->GetAssociatedTool() == nullptr)
{
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(currentScene);
SCASSERT(scene != nullptr);
dialogTool->SetAssociatedTool(
static_cast<VAbstractTool * > (DrawTool::Create(dialogTool, currentScene, doc, pattern)));
static_cast<VAbstractTool * > (DrawTool::Create(dialogTool, scene, doc, pattern)));
}
else
{ // Or update associated tool with data
@ -792,6 +807,33 @@ void MainWindow::customEvent(QEvent *event)
}
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::ClearLayout()
{
qDeleteAll (scenes);
scenes.clear();
shadows.clear();
papers.clear();
ui->listWidget->clear();
//EnableActions(false);
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::PrepareSceneList()
{
for (int i=1; i<=scenes.size(); ++i)
{
QListWidgetItem *item = new QListWidgetItem(ScenePreview(i-1), QString::number(i));
ui->listWidget->addItem(item);
}
if (not scenes.isEmpty())
{
ui->listWidget->setCurrentRow(0);
//EnableActions(true);
}
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief ToolBarOption enable option toolbar.
@ -944,6 +986,7 @@ void MainWindow::InitToolButtons()
connect(ui->toolButtonLineIntersectAxis, &QToolButton::clicked, this, &MainWindow::ToolLineIntersectAxis);
connect(ui->toolButtonCurveIntersectAxis, &QToolButton::clicked, this, &MainWindow::ToolCurveIntersectAxis);
connect(ui->toolButtonArcIntersectAxis, &QToolButton::clicked, this, &MainWindow::ToolCurveIntersectAxis);
connect(ui->toolButtonLayoutSettings, &QToolButton::clicked, this, &MainWindow::ToolLayoutSettings);
}
//---------------------------------------------------------------------------------------------------------------------
@ -1120,13 +1163,16 @@ void MainWindow::SaveCurrentScene()
{
if (mode == Draw::Calculation || mode == Draw::Modeling)
{
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(currentScene);
SCASSERT(scene != nullptr);
/*Save transform*/
currentScene->setTransform(ui->view->transform());
scene->setTransform(ui->view->transform());
/*Save scroll bars value for previous scene.*/
QScrollBar *horScrollBar = ui->view->horizontalScrollBar();
currentScene->setHorScrollBar(horScrollBar->value());
scene->setHorScrollBar(horScrollBar->value());
QScrollBar *verScrollBar = ui->view->verticalScrollBar();
currentScene->setVerScrollBar(verScrollBar->value());
scene->setVerScrollBar(verScrollBar->value());
}
}
@ -1136,13 +1182,16 @@ void MainWindow::SaveCurrentScene()
*/
void MainWindow::RestoreCurrentScene()
{
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(currentScene);
SCASSERT(scene != nullptr);
/*Set transform for current scene*/
ui->view->setTransform(currentScene->transform());
ui->view->setTransform(scene->transform());
/*Set value for current scene scroll bar.*/
QScrollBar *horScrollBar = ui->view->horizontalScrollBar();
horScrollBar->setValue(currentScene->getHorScrollBar());
horScrollBar->setValue(scene->getHorScrollBar());
QScrollBar *verScrollBar = ui->view->verticalScrollBar();
verScrollBar->setValue(currentScene->getVerScrollBar());
verScrollBar->setValue(scene->getVerScrollBar());
}
//---------------------------------------------------------------------------------------------------------------------

View file

@ -146,6 +146,9 @@ protected:
virtual void showEvent(QShowEvent *event);
virtual void closeEvent(QCloseEvent *event);
virtual void customEvent(QEvent * event);
virtual void ClearLayout();
virtual void PrepareSceneList();
private:
Q_DISABLE_COPY(MainWindow)
/** @brief ui keeps information about user interface */

View file

@ -24,6 +24,9 @@
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QToolBox" name="toolBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>2</horstretch>
@ -40,7 +43,7 @@
<string/>
</property>
<property name="currentIndex">
<number>5</number>
<number>4</number>
</property>
<widget class="QWidget" name="page">
<property name="geometry">
@ -685,6 +688,9 @@
<layout class="QFormLayout" name="formLayout_5">
<item row="0" column="0">
<widget class="QToolButton" name="toolButtonNewDetail">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Seam allowance tool</string>
</property>
@ -741,6 +747,9 @@
<layout class="QFormLayout" name="formLayout_6">
<item row="0" column="0">
<widget class="QToolButton" name="toolButtonLayoutSettings">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Settings</string>
</property>

View file

@ -29,13 +29,20 @@
#include "mainwindowsnogui.h"
#include "../core/vapplication.h"
#include "../container/vcontainer.h"
#include "../dialogs/app/dialoglayoutsettings.h"
#include "../../libs/vlayout/vlayoutgenerator.h"
#include "../dialogs/app/dialoglayoutprogress.h"
#include "../dialogs/app/dialogsavelayout.h"
#include "../../libs/vlayout/vposter.h"
#include <QGraphicsScene>
#include <QToolButton>
//---------------------------------------------------------------------------------------------------------------------
MainWindowsNoGUI::MainWindowsNoGUI(QWidget *parent)
: QMainWindow(parent), listDetails(QVector<VLayoutDetail>()), currentScene(nullptr), tempSceneLayout(nullptr),
pattern(new VContainer())
pattern(new VContainer()), papers(QList<QGraphicsItem *>()), shadows(QList<QGraphicsItem *>()),
scenes(QList<QGraphicsScene *>()), details(QList<QList<QGraphicsItem *> >())
{
InitTempLayoutScene();
}
@ -47,6 +54,60 @@ MainWindowsNoGUI::~MainWindowsNoGUI()
delete pattern;
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindowsNoGUI::ToolLayoutSettings(bool checked)
{
if (checked)
{
VLayoutGenerator lGenerator(this);
lGenerator.SetDetails(listDetails);
DialogLayoutSettings layout(&lGenerator, this);
if (layout.exec() == QDialog::Rejected)
{
return;
}
DialogLayoutProgress progress(listDetails.count(), this);
connect(&lGenerator, &VLayoutGenerator::Start, &progress, &DialogLayoutProgress::Start);
connect(&lGenerator, &VLayoutGenerator::Arranged, &progress, &DialogLayoutProgress::Arranged);
connect(&lGenerator, &VLayoutGenerator::Error, &progress, &DialogLayoutProgress::Error);
connect(&lGenerator, &VLayoutGenerator::Finished, &progress, &DialogLayoutProgress::Finished);
connect(&progress, &DialogLayoutProgress::Abort, &lGenerator, &VLayoutGenerator::Abort);
lGenerator.Generate();
switch (lGenerator.State())
{
case LayoutErrors::NoError:
ClearLayout();
papers = lGenerator.GetPapersItems();// Blank sheets
details = lGenerator.GetAllDetails();// All details
CreateShadows();
CreateScenes();
PrepareSceneList();
break;
case LayoutErrors::ProcessStoped:
break;
case LayoutErrors::PrepareLayoutError:
case LayoutErrors::PaperSizeError:
case LayoutErrors::EmptyPaperError:
ClearLayout();
break;
default:
break;
}
}
else
{
if (QToolButton *tButton = qobject_cast< QToolButton * >(this->sender()))
{
tButton->setChecked(true);
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindowsNoGUI::PrepareDetailsForLayout(const QHash<quint32, VDetail> *details)
{
@ -76,6 +137,83 @@ void MainWindowsNoGUI::PrepareDetailsForLayout(const QHash<quint32, VDetail> *de
//---------------------------------------------------------------------------------------------------------------------
void MainWindowsNoGUI::InitTempLayoutScene()
{
tempSceneLayout = new VMainGraphicsScene();
tempSceneLayout = new QGraphicsScene();
tempSceneLayout->setBackgroundBrush( QBrush(QColor(Qt::gray), Qt::SolidPattern) );
}
//---------------------------------------------------------------------------------------------------------------------
QIcon MainWindowsNoGUI::ScenePreview(int i) const
{
QImage image;
QGraphicsRectItem *paper = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
if (paper)
{
const QRectF r = paper->rect();
// Create the image with the exact size of the shrunk scene
image = QImage(QSize(static_cast<qint32>(r.width()), static_cast<qint32>(r.height())), QImage::Format_RGB32);
if (not image.isNull())
{
image.fill(Qt::white);
QPainter painter(&image);
painter.setFont( QFont( "Arial", 8, QFont::Normal ) );
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()), Qt::SolidLine, Qt::RoundCap,
Qt::RoundJoin));
painter.setBrush ( QBrush ( Qt::NoBrush ) );
scenes.at(i)->render(&painter);
painter.end();
}
else
{
qWarning()<<"Cannot create image. Size too big";
}
}
else
{
image = QImage(QSize(101, 146), QImage::Format_RGB32);
image.fill(Qt::white);
}
return QIcon(QBitmap::fromImage(image));
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindowsNoGUI::CreateShadows()
{
for (int i=0; i< papers.size(); ++i)
{
qreal x1=0, y1=0, x2=0, y2=0;
QGraphicsRectItem *item = qgraphicsitem_cast<QGraphicsRectItem *>(papers.at(i));
if (item)
{
item->rect().getCoords(&x1, &y1, &x2, &y2);
QGraphicsRectItem *shadowPaper = new QGraphicsRectItem(QRectF(x1+4, y1+4, x2+4, y2+4));
shadowPaper->setBrush(QBrush(Qt::black));
shadows.append(shadowPaper);
}
else
{
shadows.append(nullptr);
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void MainWindowsNoGUI::CreateScenes()
{
for (int i=0; i<papers.size(); ++i)
{
QGraphicsScene *scene = new QGraphicsScene();
scene->setBackgroundBrush(QBrush(QColor(Qt::gray), Qt::SolidPattern));
scene->addItem(shadows.at(i));
scene->addItem(papers.at(i));
QList<QGraphicsItem *> paperDetails = details.at(i);
for (int i=0; i < paperDetails.size(); ++i)
{
scene->addItem(paperDetails.at(i));
}
scenes.append(scene);
}
}

View file

@ -33,7 +33,8 @@
#include "../geometry/vdetail.h"
#include "../libs/vlayout/vlayoutdetail.h"
#include "../widgets/vmaingraphicsscene.h"
class QGraphicsScene;
class MainWindowsNoGUI : public QMainWindow
{
@ -42,24 +43,38 @@ public:
MainWindowsNoGUI(QWidget *parent = nullptr);
virtual ~MainWindowsNoGUI();
public slots:
void ToolLayoutSettings(bool checked);
protected:
QVector<VLayoutDetail> listDetails;
/** @brief currentScene pointer to current scene. */
VMainGraphicsScene *currentScene;
QGraphicsScene *currentScene;
VMainGraphicsScene *tempSceneLayout;
QGraphicsScene *tempSceneLayout;
/** @brief pattern container with data (points, arcs, splines, spline paths, variables) */
VContainer *pattern;
QList<QGraphicsItem *> papers;
QList<QGraphicsItem *> shadows;
QList<QGraphicsScene *> scenes;
QList<QList<QGraphicsItem *> > details;
void PrepareDetailsForLayout(const QHash<quint32, VDetail> *details);
void InitTempLayoutScene();
virtual void ClearLayout()=0;
virtual void PrepareSceneList()=0;
QIcon ScenePreview(int i) const;
private:
Q_DISABLE_COPY(MainWindowsNoGUI)
void CreateShadows();
void CreateScenes();
};
#endif // MAINWINDOWSNOGUI_H

View file

@ -189,7 +189,8 @@ void VToolAlongLine::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolAlongLine *visual = new VisToolAlongLine(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View file

@ -293,7 +293,8 @@ void VToolArc::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolArc * visual = new VisToolArc(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View file

@ -347,7 +347,8 @@ void VToolBisector::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolBisector * visual = new VisToolBisector(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View file

@ -227,7 +227,8 @@ void VToolCurveIntersectAxis::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolCurveIntersectAxis * visual = new VisToolCurveIntersectAxis(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View file

@ -192,7 +192,8 @@ void VToolCutArc::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolCutArc * visual = new VisToolCutArc(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View file

@ -202,7 +202,8 @@ void VToolCutSpline::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolCutSpline * visual = new VisToolCutSpline(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View file

@ -246,7 +246,8 @@ void VToolCutSplinePath::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolCutSplinePath *visual = new VisToolCutSplinePath(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View file

@ -287,7 +287,8 @@ void VToolEndLine::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolEndLine * visual = new VisToolEndLine(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View file

@ -291,7 +291,8 @@ void VToolHeight::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolHeight * visual = new VisToolHeight(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View file

@ -428,7 +428,8 @@ void VToolLine::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolLine * visual = new VisToolLine(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View file

@ -309,7 +309,8 @@ void VToolLineIntersect::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolLineIntersect * visual = new VisToolLineIntersect(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View file

@ -239,7 +239,8 @@ void VToolLineIntersectAxis::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolLineIntersectAxis * visual = new VisToolLineIntersectAxis(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View file

@ -324,7 +324,8 @@ void VToolNormal::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolNormal * visual = new VisToolNormal(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View file

@ -355,7 +355,8 @@ void VToolPointOfContact::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolPointOfContact * visual = new VisToolPointOfContact(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View file

@ -260,7 +260,8 @@ void VToolPointOfIntersection::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolPointOfIntersection * visual = new VisToolPointOfIntersection(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View file

@ -353,7 +353,8 @@ void VToolShoulderPoint::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolShoulderPoint * visual = new VisToolShoulderPoint(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View file

@ -237,7 +237,8 @@ void VToolSpline::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolSpline *visual = new VisToolSpline(getData(), this);
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
const QSharedPointer<VSpline> spl = VAbstractTool::data.GeometricObject<VSpline>(id);

View file

@ -318,7 +318,8 @@ void VToolSplinePath::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolSplinePath *visual = new VisToolSplinePath(getData(), this);
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
QSharedPointer<VSplinePath> splPath = VAbstractTool::data.GeometricObject<VSplinePath>(id);

View file

@ -325,7 +325,8 @@ void VToolTriangle::ShowVisualization(bool show)
if (vis == nullptr)
{
VisToolTriangle * visual = new VisToolTriangle(getData());
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr)
connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor);
scene->addItem(visual);

View file

@ -67,7 +67,7 @@ void Visualization::setScenePos(const QPointF &value)
//---------------------------------------------------------------------------------------------------------------------
void Visualization::VisualMode(const quint32 &pointId)
{
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr);
this->point1Id = pointId;

View file

@ -87,7 +87,7 @@ protected:
void AddItem(Item *item)
{
SCASSERT(item != nullptr);
VMainGraphicsScene *scene = qApp->getCurrentScene();
VMainGraphicsScene *scene = qobject_cast<VMainGraphicsScene *>(qApp->getCurrentScene());
SCASSERT(scene != nullptr);
scene->addItem(item);