Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
+ fixes #1049: Sketcher preferences in preferences editor
  • Loading branch information
wwmayer committed Mar 14, 2014
1 parent f0b54d3 commit 06239e9
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 30 deletions.
5 changes: 4 additions & 1 deletion src/Mod/Part/Gui/ViewProvider2DObject.cpp
Expand Up @@ -37,6 +37,7 @@
/// Here the FreeCAD includes sorted by Base,App,Gui......
#include <Base/Parameter.h>
#include <Base/ViewProj.h>
#include <App/Application.h>

#include "ViewProvider2DObject.h"
#include <Mod/Part/App/PartFeature.h>
Expand Down Expand Up @@ -143,9 +144,11 @@ SoSeparator* ViewProvider2DObject::createGrid(void)
mycolor->rgb.setValue(0.7f, 0.7f ,0.7f);
parent->addChild(mycolor);

ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Part");
int pattern = hGrp->GetInt("GridLinePattern", 0x0f0f);
SoDrawStyle* DefaultStyle = new SoDrawStyle;
DefaultStyle->lineWidth = 1;
DefaultStyle->linePattern = 0x0f0f;
DefaultStyle->linePattern = pattern;

SoMaterial* LightStyle = new SoMaterial;
LightStyle->transparency = 0.7f;
Expand Down
12 changes: 9 additions & 3 deletions src/Mod/Sketcher/Gui/CommandConstraints.cpp
Expand Up @@ -26,6 +26,7 @@
# include <QMessageBox>
#endif

#include <App/Application.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/Selection.h>
Expand Down Expand Up @@ -73,10 +74,15 @@ void finishDistanceConstraint(Gui::Command* cmd, Sketcher::SketchObject* sketch)
vp->draw(); // Redraw
}

ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher/General");
bool show = hGrp->GetBool("ShowDialogOnDistanceConstraint", true);

// Ask for the value of the distance immediately
EditDatumDialog *editDatumDialog = new EditDatumDialog(sketch, ConStr.size() - 1);
editDatumDialog->exec(false);
delete editDatumDialog;
if (show) {
EditDatumDialog *editDatumDialog = new EditDatumDialog(sketch, ConStr.size() - 1);
editDatumDialog->exec(false);
delete editDatumDialog;
}

//updateActive();
cmd->getSelection().clearSelection();
Expand Down
48 changes: 46 additions & 2 deletions src/Mod/Sketcher/Gui/SketcherSettings.cpp
Expand Up @@ -24,11 +24,13 @@
#include "PreCompiled.h"

#ifndef _PreComp_
# include <QPixmap>
#endif

#include "SketcherSettings.h"
#include "ui_SketcherSettings.h"
#include "TaskSketcherGeneral.h"
#include <App/Application.h>
#include <Gui/PrefWidgets.h>

using namespace SketcherGui;
Expand All @@ -39,8 +41,13 @@ SketcherSettings::SketcherSettings(QWidget* parent)
: PreferencePage(parent), ui(new Ui_SketcherSettings)
{
ui->setupUi(this);
form = new SketcherGeneralWidget(ui->groupBox);
ui->gridLayout->addWidget(form, 1, 0, 1, 1);
QGroupBox* groupBox = new QGroupBox(this);
QGridLayout* gridLayout = new QGridLayout(groupBox);
gridLayout->setSpacing(0);
gridLayout->setMargin(0);
form = new SketcherGeneralWidget(groupBox);
gridLayout->addWidget(form, 0, 0, 1, 1);
ui->gridLayout_3->addWidget(groupBox, 2, 0, 1, 1);

// Don't need them at the moment
ui->label_16->hide();
Expand All @@ -49,6 +56,30 @@ SketcherSettings::SketcherSettings(QWidget* parent)
ui->DefaultSketcherVertexWidth->hide();
ui->label_13->hide();
ui->DefaultSketcherLineWidth->hide();

QList < QPair<Qt::PenStyle, int> > styles;
styles << qMakePair(Qt::SolidLine, 0xffff)
<< qMakePair(Qt::DashLine, 0x0f0f)
<< qMakePair(Qt::DotLine, 0xaaaa);
// << qMakePair(Qt::DashDotLine, 0x????)
// << qMakePair(Qt::DashDotDotLine, 0x????);
ui->comboBox->setIconSize (QSize(80, 12));
for (QList < QPair<Qt::PenStyle, int> >::iterator it = styles.begin(); it != styles.end(); ++it) {
QPixmap px(ui->comboBox->iconSize());
px.fill(Qt::transparent);
QBrush brush(Qt::black);
QPen pen(it->first);
pen.setBrush(brush);
pen.setWidth(2);

QPainter painter(&px);
painter.setPen(pen);
double mid = ui->comboBox->iconSize().height() / 2.0;
painter.drawLine(0, mid, ui->comboBox->iconSize().width(), mid);
painter.end();

ui->comboBox->addItem(QIcon(px), QString(), QVariant(it->second));
}
}

/**
Expand Down Expand Up @@ -82,7 +113,13 @@ void SketcherSettings::saveSettings()

// Sketch editing
ui->EditSketcherFontSize->onSave();
ui->dialogOnDistanceConstraint->onSave();
form->saveSettings();

ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Part");
QVariant data = ui->comboBox->itemData(ui->comboBox->currentIndex());
int pattern = data.toInt();
hGrp->SetInt("GridLinePattern", pattern);
}

void SketcherSettings::loadSettings()
Expand All @@ -107,7 +144,14 @@ void SketcherSettings::loadSettings()

// Sketch editing
ui->EditSketcherFontSize->onRestore();
ui->dialogOnDistanceConstraint->onRestore();
form->loadSettings();

ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Part");
int pattern = hGrp->GetInt("GridLinePattern", 0x0f0f);
int index = ui->comboBox->findData(QVariant(pattern));
if (index <0) index = 1;
ui->comboBox->setCurrentIndex(index);
}

/**
Expand Down
61 changes: 37 additions & 24 deletions src/Mod/Sketcher/Gui/SketcherSettings.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>359</width>
<height>544</height>
<height>586</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -456,19 +456,6 @@
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>74</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -517,18 +504,39 @@
</item>
</layout>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Grid line pattern</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox">
<property name="currentIndex">
<number>-1</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="Gui::PrefCheckBox" name="dialogOnDistanceConstraint">
<property name="text">
<string>Ask for value after creating a distance constraint</string>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>71</width>
<height>20</height>
</size>
<property name="checked">
<bool>true</bool>
</property>
</spacer>
<property name="prefEntry" stdset="0">
<cstring>ShowDialogOnDistanceConstraint</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Sketcher</cstring>
</property>
</widget>
</item>
</layout>
</widget>
Expand Down Expand Up @@ -564,6 +572,11 @@
<extends>Gui::ColorButton</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefCheckBox</class>
<extends>QCheckBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>CursorTextColor</tabstop>
Expand Down

0 comments on commit 06239e9

Please sign in to comment.