Promote VMainGraphicsView in Qt Designer.

--HG--
branch : develop
This commit is contained in:
dismine 2014-08-12 14:30:20 +03:00
parent 8ef62fc0ed
commit dc8d715814
4 changed files with 89 additions and 84 deletions

View File

@ -44,6 +44,8 @@ include(xml/xml.pri)
include(undocommands/undocommands.pri) include(undocommands/undocommands.pri)
include(visualization/visualization.pri) include(visualization/visualization.pri)
INCLUDEPATH += "$${PWD}/widgets"
SOURCES += \ SOURCES += \
main.cpp \ main.cpp \
mainwindow.cpp \ mainwindow.cpp \

View File

@ -62,7 +62,7 @@
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
:QMainWindow(parent), ui(new Ui::MainWindow), pattern(nullptr), doc(nullptr), tool(Tool::ArrowTool), :QMainWindow(parent), ui(new Ui::MainWindow), pattern(nullptr), doc(nullptr), tool(Tool::ArrowTool),
currentScene(nullptr), sceneDraw(nullptr), sceneDetails(nullptr), mouseCoordinate(nullptr), helpLabel(nullptr), currentScene(nullptr), sceneDraw(nullptr), sceneDetails(nullptr), mouseCoordinate(nullptr), helpLabel(nullptr),
view(nullptr), isInitialized(false), dialogTable(0), dialogTool(nullptr), dialogHistory(nullptr), isInitialized(false), dialogTable(0), dialogTool(nullptr), dialogHistory(nullptr),
comboBoxDraws(nullptr), curFile(QString()), mode(Draw::Calculation), currentDrawIndex(0), comboBoxDraws(nullptr), curFile(QString()), mode(Draw::Calculation), currentDrawIndex(0),
currentToolBoxIndex(0), drawMode(true), recentFileActs{nullptr, nullptr, nullptr, nullptr, nullptr}, currentToolBoxIndex(0), drawMode(true), recentFileActs{nullptr, nullptr, nullptr, nullptr, nullptr},
separatorAct(nullptr), autoSaveTimer(nullptr), guiEnabled(true), gradationHeights(nullptr), separatorAct(nullptr), autoSaveTimer(nullptr), guiEnabled(true), gradationHeights(nullptr),
@ -80,21 +80,17 @@ MainWindow::MainWindow(QWidget *parent)
sceneDetails = new VMainGraphicsScene(); sceneDetails = new VMainGraphicsScene();
connect(sceneDetails, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove); connect(sceneDetails, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove);
view = new VMainGraphicsView(); ui->view->setScene(currentScene);
view->setDisabled(true);
ui->LayoutView->addWidget(view);
view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
view->setScene(currentScene);
sceneDraw->setTransform(view->transform()); sceneDraw->setTransform(ui->view->transform());
sceneDetails->setTransform(view->transform()); sceneDetails->setTransform(ui->view->transform());
connect(view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor); connect(ui->view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor);
QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding); QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding);
policy.setHorizontalStretch(12); policy.setHorizontalStretch(12);
view->setSizePolicy(policy); ui->view->setSizePolicy(policy);
qApp->setSceneView(view); qApp->setSceneView(ui->view);
helpLabel = new QLabel(QObject::tr("Create new pattern piece to start working.")); helpLabel = new QLabel(QObject::tr("Create new pattern piece to start working."));
ui->statusBar->addWidget(helpLabel); ui->statusBar->addWidget(helpLabel);
@ -173,8 +169,8 @@ void MainWindow::ActionNewPP()
} }
//Set scene size to size scene view //Set scene size to size scene view
VAbstractTool::NewSceneRect(sceneDraw, view); VAbstractTool::NewSceneRect(sceneDraw, ui->view);
VAbstractTool::NewSceneRect(sceneDetails, view); VAbstractTool::NewSceneRect(sceneDetails, ui->view);
ToolBarOption(); ToolBarOption();
} }
else else
@ -255,7 +251,7 @@ void MainWindow::SetToolButton(bool checked, Tool t, const QString &cursor, cons
tool = t; tool = t;
QPixmap pixmap(cursor); QPixmap pixmap(cursor);
QCursor cur(pixmap, 2, 3); QCursor cur(pixmap, 2, 3);
view->setCursor(cur); ui->view->setCursor(cur);
helpLabel->setText(toolTip); helpLabel->setText(toolTip);
dialogTool = new Dialog(pattern, 0, this); dialogTool = new Dialog(pattern, 0, this);
connect(currentScene, &VMainGraphicsScene::ChoosedObject, dialogTool, &DialogTool::ChosenObject); connect(currentScene, &VMainGraphicsScene::ChoosedObject, dialogTool, &DialogTool::ChosenObject);
@ -293,7 +289,7 @@ void MainWindow::SetToolButtonWithApply(bool checked, Tool t, const QString &cur
tool = t; tool = t;
QPixmap pixmap(cursor); QPixmap pixmap(cursor);
QCursor cur(pixmap, 2, 3); QCursor cur(pixmap, 2, 3);
view->setCursor(cur); ui->view->setCursor(cur);
helpLabel->setText(toolTip); helpLabel->setText(toolTip);
dialogTool = new Dialog(pattern, 0, this); dialogTool = new Dialog(pattern, 0, this);
connect(currentScene, &VMainGraphicsScene::ChoosedObject, dialogTool, &DialogTool::ChosenObject); connect(currentScene, &VMainGraphicsScene::ChoosedObject, dialogTool, &DialogTool::ChosenObject);
@ -301,7 +297,7 @@ void MainWindow::SetToolButtonWithApply(bool checked, Tool t, const QString &cur
connect(dialogTool, &DialogTool::DialogApplied, this, applyDialogSlot); connect(dialogTool, &DialogTool::DialogApplied, this, applyDialogSlot);
connect(dialogTool, &DialogTool::ToolTip, this, &MainWindow::ShowToolTip); connect(dialogTool, &DialogTool::ToolTip, this, &MainWindow::ShowToolTip);
connect(doc, &VPattern::FullUpdateFromFile, dialogTool, &DialogTool::UpdateList); connect(doc, &VPattern::FullUpdateFromFile, dialogTool, &DialogTool::UpdateList);
connect(view, &VMainGraphicsView::MouseRelease, this, &MainWindow::ClickEndVisualization); connect(ui->view, &VMainGraphicsView::MouseRelease, this, &MainWindow::ClickEndVisualization);
} }
else else
{ {
@ -867,15 +863,15 @@ void MainWindow::ToolBarTools()
const QList<QKeySequence> zoomInShortcuts = {QKeySequence::ZoomIn, const QList<QKeySequence> zoomInShortcuts = {QKeySequence::ZoomIn,
Qt::ControlModifier + Qt::Key_Plus + Qt::KeypadModifier}; Qt::ControlModifier + Qt::Key_Plus + Qt::KeypadModifier};
ui->actionZoomIn->setShortcuts(zoomInShortcuts); ui->actionZoomIn->setShortcuts(zoomInShortcuts);
connect(ui->actionZoomIn, &QAction::triggered, view, &VMainGraphicsView::ZoomIn); connect(ui->actionZoomIn, &QAction::triggered, ui->view, &VMainGraphicsView::ZoomIn);
const QList<QKeySequence> zoomOutShortcuts = {QKeySequence::ZoomOut, const QList<QKeySequence> zoomOutShortcuts = {QKeySequence::ZoomOut,
Qt::ControlModifier + Qt::Key_Minus + Qt::KeypadModifier}; Qt::ControlModifier + Qt::Key_Minus + Qt::KeypadModifier};
ui->actionZoomOut->setShortcuts(zoomOutShortcuts); ui->actionZoomOut->setShortcuts(zoomOutShortcuts);
connect(ui->actionZoomOut, &QAction::triggered, view, &VMainGraphicsView::ZoomOut); connect(ui->actionZoomOut, &QAction::triggered, ui->view, &VMainGraphicsView::ZoomOut);
connect(ui->actionZoomOriginal, &QAction::triggered, view, &VMainGraphicsView::ZoomOriginal); connect(ui->actionZoomOriginal, &QAction::triggered, ui->view, &VMainGraphicsView::ZoomOriginal);
connect(ui->actionZoomFitBest, &QAction::triggered, view, &VMainGraphicsView::ZoomFitBest); connect(ui->actionZoomFitBest, &QAction::triggered, ui->view, &VMainGraphicsView::ZoomFitBest);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1059,7 +1055,7 @@ void MainWindow::ArrowTool()
ui->actionArrowTool->setChecked(true); ui->actionArrowTool->setChecked(true);
tool = Tool::ArrowTool; tool = Tool::ArrowTool;
QCursor cur(Qt::ArrowCursor); QCursor cur(Qt::ArrowCursor);
view->setCursor(cur); ui->view->setCursor(cur);
helpLabel->setText(""); helpLabel->setText("");
} }
@ -1103,11 +1099,11 @@ void MainWindow::keyPressEvent ( QKeyEvent * event )
void MainWindow::SaveCurrentScene() void MainWindow::SaveCurrentScene()
{ {
/*Save transform*/ /*Save transform*/
currentScene->setTransform(view->transform()); currentScene->setTransform(ui->view->transform());
/*Save scroll bars value for previous scene.*/ /*Save scroll bars value for previous scene.*/
QScrollBar *horScrollBar = view->horizontalScrollBar(); QScrollBar *horScrollBar = ui->view->horizontalScrollBar();
currentScene->setHorScrollBar(horScrollBar->value()); currentScene->setHorScrollBar(horScrollBar->value());
QScrollBar *verScrollBar = view->verticalScrollBar(); QScrollBar *verScrollBar = ui->view->verticalScrollBar();
currentScene->setVerScrollBar(verScrollBar->value()); currentScene->setVerScrollBar(verScrollBar->value());
} }
@ -1118,11 +1114,11 @@ void MainWindow::SaveCurrentScene()
void MainWindow::RestoreCurrentScene() void MainWindow::RestoreCurrentScene()
{ {
/*Set transform for current scene*/ /*Set transform for current scene*/
view->setTransform(currentScene->transform()); ui->view->setTransform(currentScene->transform());
/*Set value for current scene scroll bar.*/ /*Set value for current scene scroll bar.*/
QScrollBar *horScrollBar = view->horizontalScrollBar(); QScrollBar *horScrollBar = ui->view->horizontalScrollBar();
horScrollBar->setValue(currentScene->getHorScrollBar()); horScrollBar->setValue(currentScene->getHorScrollBar());
QScrollBar *verScrollBar = view->verticalScrollBar(); QScrollBar *verScrollBar = ui->view->verticalScrollBar();
verScrollBar->setValue(currentScene->getVerScrollBar()); verScrollBar->setValue(currentScene->getVerScrollBar());
} }
@ -1139,8 +1135,8 @@ void MainWindow::ActionDraw(bool checked)
SaveCurrentScene(); SaveCurrentScene();
currentScene = sceneDraw; currentScene = sceneDraw;
view->setScene(currentScene); ui->view->setScene(currentScene);
connect(view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor); connect(ui->view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor);
RestoreCurrentScene(); RestoreCurrentScene();
mode = Draw::Calculation; mode = Draw::Calculation;
@ -1175,8 +1171,8 @@ void MainWindow::ActionDetails(bool checked)
SaveCurrentScene(); SaveCurrentScene();
currentScene = sceneDetails; currentScene = sceneDetails;
view->setScene(sceneDetails); ui->view->setScene(sceneDetails);
disconnect(view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor); disconnect(ui->view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor);
RestoreCurrentScene(); RestoreCurrentScene();
drawMode = false; drawMode = false;
@ -1453,7 +1449,7 @@ void MainWindow::SetEnabledGUI(bool enabled)
guiEnabled = enabled; guiEnabled = enabled;
sceneDraw->SetDisable(!enabled); sceneDraw->SetDisable(!enabled);
view->setEnabled(enabled); ui->view->setEnabled(enabled);
SetEnableTool(enabled); SetEnableTool(enabled);
ui->toolBarOption->setEnabled(enabled); ui->toolBarOption->setEnabled(enabled);
@ -1613,7 +1609,7 @@ void MainWindow::SetEnableWidgets(bool enable)
ui->actionZoomFitBest->setEnabled(enable); ui->actionZoomFitBest->setEnabled(enable);
ui->actionZoomOriginal->setEnabled(enable); ui->actionZoomOriginal->setEnabled(enable);
//Now we want allow user call context menu //Now we want allow user call context menu
view->setEnabled(enable); ui->view->setEnabled(enable);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -1747,9 +1743,9 @@ void MainWindow::SetEnableTool(bool enable)
*/ */
void MainWindow::MinimumScrollBar() void MainWindow::MinimumScrollBar()
{ {
QScrollBar *horScrollBar = view->horizontalScrollBar(); QScrollBar *horScrollBar = ui->view->horizontalScrollBar();
horScrollBar->setValue(horScrollBar->minimum()); horScrollBar->setValue(horScrollBar->minimum());
QScrollBar *verScrollBar = view->verticalScrollBar(); QScrollBar *verScrollBar = ui->view->verticalScrollBar();
verScrollBar->setValue(verScrollBar->minimum()); verScrollBar->setValue(verScrollBar->minimum());
} }
@ -1848,8 +1844,8 @@ void MainWindow::ReadSettings()
// Scene antialiasing // Scene antialiasing
bool graphOutputValue = qApp->getSettings()->value("pattern/graphicalOutput", 1).toBool(); bool graphOutputValue = qApp->getSettings()->value("pattern/graphicalOutput", 1).toBool();
view->setRenderHint(QPainter::Antialiasing, graphOutputValue); ui->view->setRenderHint(QPainter::Antialiasing, graphOutputValue);
view->setRenderHint(QPainter::SmoothPixmapTransform, graphOutputValue); ui->view->setRenderHint(QPainter::SmoothPixmapTransform, graphOutputValue);
// Stack limit // Stack limit
bool ok = true; bool ok = true;
@ -2057,8 +2053,8 @@ MainWindow::~MainWindow()
void MainWindow::LoadPattern(const QString &fileName) void MainWindow::LoadPattern(const QString &fileName)
{ {
// On this stage scene empty. Fit scene size to view size // On this stage scene empty. Fit scene size to view size
VAbstractTool::NewSceneRect(sceneDraw, view); VAbstractTool::NewSceneRect(sceneDraw, ui->view);
VAbstractTool::NewSceneRect(sceneDetails, view); VAbstractTool::NewSceneRect(sceneDetails, ui->view);
qApp->setOpeningPattern();//Begin opening file qApp->setOpeningPattern();//Begin opening file
try try
@ -2196,8 +2192,8 @@ void MainWindow::ChangePP(int index, bool zoomBestFit)
ArrowTool(); ArrowTool();
if (zoomBestFit) if (zoomBestFit)
{ {
view->fitInView(doc->ActiveDrawBoundingRect(), Qt::KeepAspectRatio); ui->view->fitInView(doc->ActiveDrawBoundingRect(), Qt::KeepAspectRatio);
view->NewFactor(view->transform().m11()); ui->view->NewFactor(ui->view->transform().m11());
} }
} }
} }
@ -2222,17 +2218,17 @@ void MainWindow::ZoomFirstShow()
* pattern will be moved. Looks very ugly. It is best solution that i have now. * pattern will be moved. Looks very ugly. It is best solution that i have now.
*/ */
ActionDetails(true); ActionDetails(true);
view->ZoomFitBest(); ui->view->ZoomFitBest();
ActionDraw(true); ActionDraw(true);
view->ZoomFitBest(); ui->view->ZoomFitBest();
VAbstractTool::NewSceneRect(sceneDraw, view); VAbstractTool::NewSceneRect(sceneDraw, ui->view);
VAbstractTool::NewSceneRect(sceneDetails, view); VAbstractTool::NewSceneRect(sceneDetails, ui->view);
ActionDetails(true); ActionDetails(true);
view->ZoomFitBest(); ui->view->ZoomFitBest();
ActionDraw(true); ActionDraw(true);
view->ZoomFitBest(); ui->view->ZoomFitBest();
} }

View File

@ -162,9 +162,6 @@ private:
/** @brief helpLabel help show tooltip. */ /** @brief helpLabel help show tooltip. */
QLabel *helpLabel; QLabel *helpLabel;
/** @brief view show current scene. */
VMainGraphicsView *view;
/** @brief isInitialized true after first show window. */ /** @brief isInitialized true after first show window. */
bool isInitialized; bool isInitialized;

View File

@ -322,33 +322,7 @@
<string>Line</string> <string>Line</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0"> <item row="1" column="1">
<widget class="QToolButton" name="toolButtonLine">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Line between points</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="share/resources/icon.qrc">
<normaloff>:/icon/32x32/line.png</normaloff>:/icon/32x32/line.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QToolButton" name="toolButtonLineIntersect"> <widget class="QToolButton" name="toolButtonLineIntersect">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
@ -374,6 +348,32 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0">
<widget class="QToolButton" name="toolButtonLine">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Line between points</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="share/resources/icon.qrc">
<normaloff>:/icon/32x32/line.png</normaloff>:/icon/32x32/line.png</iconset>
</property>
<property name="iconSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="page_3"> <widget class="QWidget" name="page_3">
@ -656,14 +656,17 @@
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="LayoutView"> <widget class="VMainGraphicsView" name="view">
<property name="spacing"> <property name="enabled">
<number>10</number> <bool>false</bool>
</property> </property>
<property name="sizeConstraint"> <property name="verticalScrollBarPolicy">
<enum>QLayout::SetMaximumSize</enum> <enum>Qt::ScrollBarAlwaysOn</enum>
</property> </property>
</layout> <property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>
@ -1112,6 +1115,13 @@
</action> </action>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>VMainGraphicsView</class>
<extends>QGraphicsView</extends>
<header>vmaingraphicsview.h</header>
</customwidget>
</customwidgets>
<tabstops> <tabstops>
<tabstop>toolButtonEndLine</tabstop> <tabstop>toolButtonEndLine</tabstop>
<tabstop>toolButtonAlongLine</tabstop> <tabstop>toolButtonAlongLine</tabstop>