Skip to content

Commit

Permalink
Some color adjusts added to settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Denvi committed Sep 20, 2015
1 parent cb11d27 commit dca75b2
Show file tree
Hide file tree
Showing 16 changed files with 555 additions and 156 deletions.
41 changes: 41 additions & 0 deletions colorpicker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "colorpicker.h"

ColorPicker::ColorPicker(QWidget *parent) :
QWidget(parent)
{
m_layout = new QHBoxLayout(this);
m_frame = new QFrame(this);
m_button = new QToolButton(this);

m_frame->setFrameShape(QFrame::Box);

m_button->setText("...");

m_layout->setMargin(0);
m_layout->addWidget(m_frame, 1);
m_layout->addWidget(m_button);

connect(m_button, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
}

QColor ColorPicker::color() const
{
return m_color;
}

void ColorPicker::setColor(const QColor &color)
{
m_color = color;
m_frame->setStyleSheet(QString("background-color: %1").arg(color.name()));
}

void ColorPicker::onButtonClicked()
{
QColor color = QColorDialog::getColor(m_color, this);

if (color.isValid()) {
setColor(color);
emit colorSelected(color);
}
}

34 changes: 34 additions & 0 deletions colorpicker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef COLORPICKER_H
#define COLORPICKER_H

#include <QWidget>
#include <QHBoxLayout>
#include <QFrame>
#include <QToolButton>
#include <QColorDialog>

class ColorPicker : public QWidget
{
Q_OBJECT
public:
explicit ColorPicker(QWidget *parent = 0);

QColor color() const;
void setColor(const QColor &color);

signals:
void colorSelected(QColor color);

public slots:

private slots:
void onButtonClicked();

private:
QHBoxLayout *m_layout;
QFrame *m_frame;
QToolButton *m_button;
QColor m_color;
};

#endif // COLORPICKER_H
23 changes: 22 additions & 1 deletion frmmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ void frmMain::loadSettings()
ui->cboHeightMapInterpolationType->setCurrentIndex(set.value("heightmapInterpolationType", 0).toInt());
ui->chkHeightMapInterpolationShow->setChecked(set.value("heightmapInterpolationShow", false).toBool());

foreach (ColorPicker* pick, m_frmSettings.colors()) {
pick->setColor(QColor(set.value(pick->objectName().mid(3), "black").toString()));
}

updateRecentFilesMenu();

ui->tblProgram->horizontalHeader()->restoreState(set.value("header", QByteArray()).toByteArray());
Expand Down Expand Up @@ -352,6 +356,10 @@ void frmMain::saveSettings()
set.setValue("heightmapInterpolationType", ui->cboHeightMapInterpolationType->currentIndex());
set.setValue("heightmapInterpolationShow", ui->chkHeightMapInterpolationShow->isChecked());

foreach (ColorPicker* pick, m_frmSettings.colors()) {
set.setValue(pick->objectName().mid(3), pick->color().name());
}

QStringList list;

for (int i = 0; i < ui->cboCommand->count(); i++) list.append(ui->cboCommand->itemText(i));
Expand Down Expand Up @@ -1480,7 +1488,9 @@ void frmMain::on_actServiceSettings_triggered()
{
QList<double> storedValues;
QList<bool> storedChecks;
QList<QString> storedCombos;
QList<QString> storedCombos;

// TODO: store colors

foreach (QAbstractSpinBox* sb, m_frmSettings.findChildren<QAbstractSpinBox*>())
{
Expand Down Expand Up @@ -1548,15 +1558,21 @@ void frmMain::applySettings() {
m_safeZ = m_frmSettings.safeZ();
m_rapidSpeed = m_frmSettings.rapidSpeed();
m_timerStateQuery.setInterval(m_frmSettings.queryStateTime());

m_toolDrawer.setToolAngle(m_frmSettings.toolType() == 0 ? 180 : m_frmSettings.toolAngle());
m_toolDrawer.setColor(m_frmSettings.colors("Tool"));
m_toolDrawer.update();

ui->glwVisualizer->setAntialiasing(m_frmSettings.antialiasing());
ui->glwVisualizer->setMsaa(m_frmSettings.msaa());
ui->glwVisualizer->setZBuffer(m_frmSettings.zBuffer());
ui->glwVisualizer->setFps(m_frmSettings.fps());

ui->txtSpindleSpeed->setMinimum(m_frmSettings.spindleSpeedMin());
ui->txtSpindleSpeed->setMaximum(m_frmSettings.spindleSpeedMax());
ui->sliSpindleSpeed->setMinimum(ui->txtSpindleSpeed->minimum() / 100);
ui->sliSpindleSpeed->setMaximum(ui->txtSpindleSpeed->maximum() / 100);

ui->grpHeightMap->setVisible(m_frmSettings.panelHeightmap());
ui->grpSpindle->setVisible(m_frmSettings.panelSpindle());
ui->grpFeed->setVisible(m_frmSettings.panelFeed());
Expand All @@ -1566,8 +1582,13 @@ void frmMain::applySettings() {
|| m_frmSettings.panelJog() || m_frmSettings.panelSpindle());

ui->cboCommand->setAutoCompletion(m_frmSettings.autoCompletion());

m_codeDrawer->setSimplify(m_frmSettings.simplify());
m_codeDrawer->setSimplifyPrecision(m_frmSettings.simplifyPrecision());
m_codeDrawer->setColorNormal(m_frmSettings.colors("ToolpathNormal"));
m_codeDrawer->setColorDrawn(m_frmSettings.colors("ToolpathDrawn"));
m_codeDrawer->setColorHighlight(m_frmSettings.colors("ToolpathHighlight"));
m_codeDrawer->setColorZMovement(m_frmSettings.colors("ToolpathZMovement"));
m_codeDrawer->update();
}

Expand Down
57 changes: 57 additions & 0 deletions frmsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <QtSerialPort/QSerialPortInfo>
#include <QDebug>
#include <QScrollBar>
#include <QColorDialog>

frmSettings::frmSettings(QWidget *parent) :
QDialog(parent),
Expand Down Expand Up @@ -345,6 +346,17 @@ void frmSettings::setPanelJog(bool panelJog)
ui->chkPanelJog->setChecked(panelJog);
}

QList<ColorPicker *> frmSettings::colors()
{
return this->findChildren<ColorPicker*>();
}

QColor frmSettings::colors(QString name)
{
ColorPicker *pick = this->findChildren<ColorPicker*>("clp" + name).at(0);
if (pick) return pick->color(); else return QColor();
}

void frmSettings::showEvent(QShowEvent *se)
{
ui->scrollSettings->updateMinimumWidth();
Expand Down Expand Up @@ -380,3 +392,48 @@ void frmSettings::on_cboToolType_currentIndexChanged(int index)
ui->lblToolAngle->setEnabled(index == 1);
ui->txtToolAngle->setEnabled(index == 1);
}

void frmSettings::on_cmdDefaults_clicked()
{
setPort("");
setBaud(115200);

setQueryStateTime(40);
setSafeZ(10.0);
setRapidSpeed(2000);
setAcceleration(100);
setSpindleSpeedMin(0);
setSpindleSpeedMax(10000);
setTouchCommand("");
setHeightmapProbingFeed(10);
setUnits(0);

setArcPrecision(0.0);

setLineWidth(1.5);
setAntialiasing(true);
setMsaa(true);
setSimplify(true);
setSimplifyPrecision(0.0);
setFps(60);
setZBuffer(false);

setToolType(1);
setToolAngle(15.0);
setToolDiameter(3.0);
setToolLength(30.0);

setShowAllCommands(false);
setAutoCompletion(true);

setPanelFeed(true);
setPanelHeightmap(true);
setPanelJog(true);
setPanelSpindle(true);

ui->clpTool->setColor(QColor(255, 153, 0));
ui->clpToolpathNormal->setColor(QColor(0, 0, 0));
ui->clpToolpathDrawn->setColor(QColor(217, 217, 217));
ui->clpToolpathHighlight->setColor(QColor(145, 130, 230));
ui->clpToolpathZMovement->setColor(QColor(255, 0, 0));
}
5 changes: 5 additions & 0 deletions frmsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <QDialog>
#include <QListWidgetItem>
#include "colorpicker.h"

namespace Ui {
class frmSettings;
Expand Down Expand Up @@ -77,6 +78,8 @@ class frmSettings : public QDialog
void setPanelFeed(bool panelFeed);
bool panelJog();
void setPanelJog(bool panelJog);
QList<ColorPicker*> colors();
QColor colors(QString name);

protected:
void showEvent(QShowEvent *se);
Expand All @@ -90,6 +93,8 @@ private slots:
void on_cboToolType_currentIndexChanged(int index);
void on_listCategories_currentRowChanged(int currentRow);

void on_cmdDefaults_clicked();

private:
Ui::frmSettings *ui;
void searchPorts();
Expand Down
86 changes: 78 additions & 8 deletions frmsettings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ QScrollArea QScrollBar::sub-line:vertical {
<property name="geometry">
<rect>
<x>0</x>
<y>-572</y>
<y>-486</y>
<width>344</width>
<height>1009</height>
<height>923</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
Expand Down Expand Up @@ -945,15 +945,72 @@ padding-top: 3;</string>
</item>
<item>
<widget class="GroupBox" name="grpColors">
<property name="minimumSize">
<size>
<width>0</width>
<height>200</height>
</size>
</property>
<property name="title">
<string>Colors</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<layout class="QGridLayout" name="gridLayout_6" columnstretch="0,0,0,0">
<item row="2" column="0">
<widget class="QLabel" name="label_23">
<property name="text">
<string>Normal:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_21">
<property name="text">
<string>Toolpath</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="label_16">
<property name="text">
<string>Drawn:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="ColorPicker" name="clpTool" native="true"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_19">
<property name="text">
<string>Tool:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_25">
<property name="text">
<string>Highlight:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="ColorPicker" name="clpToolpathNormal" native="true"/>
</item>
<item row="3" column="1">
<widget class="ColorPicker" name="clpToolpathHighlight" native="true"/>
</item>
<item row="2" column="3">
<widget class="ColorPicker" name="clpToolpathDrawn" native="true"/>
</item>
<item row="3" column="2">
<widget class="QLabel" name="label_20">
<property name="text">
<string>Z-movement:</string>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="ColorPicker" name="clpToolpathZMovement" native="true"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
Expand All @@ -964,6 +1021,13 @@ padding-top: 3;</string>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="cmdDefaults">
<property name="text">
<string>Set to defaults</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
Expand Down Expand Up @@ -1014,6 +1078,12 @@ padding-top: 3;</string>
<header>groupbox.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ColorPicker</class>
<extends>QWidget</extends>
<header>colorpicker.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>listCategories</tabstop>
Expand Down
Loading

0 comments on commit dca75b2

Please sign in to comment.