Sun, 10 Jun 2018 12:12:50 +0300
separated the color button into a new widget
--- a/CMakeLists.txt Fri Jun 08 23:06:56 2018 +0300 +++ b/CMakeLists.txt Sun Jun 10 12:12:50 2018 +0300 @@ -63,6 +63,7 @@ src/algorithms/invert.cpp src/dialogs/colorselector.cpp src/dialogs/configdialog.cpp + src/dialogs/cylindereditor.cpp src/dialogs/externalprogrampathdialog.cpp src/dialogs/generateprimitivedialog.cpp src/dialogs/ldrawpathdialog.cpp @@ -96,6 +97,7 @@ src/types/boundingbox.cpp src/types/matrix.cpp src/types/vertex.cpp + src/widgets/colorbutton.cpp src/widgets/doublespinbox.cpp src/widgets/headeredit.cpp src/widgets/matrixeditor.cpp @@ -136,6 +138,7 @@ src/algorithms/invert.h src/dialogs/colorselector.h src/dialogs/configdialog.h + src/dialogs/cylindereditor.h src/dialogs/externalprogrampathdialog.h src/dialogs/generateprimitivedialog.h src/dialogs/ldrawpathdialog.h @@ -177,6 +180,7 @@ src/types/library.h src/types/matrix.h src/types/vertex.h + src/widgets/colorbutton.h src/widgets/doublespinbox.h src/widgets/headeredit.h src/widgets/matrixeditor.h @@ -188,6 +192,7 @@ src/dialogs/colorselector.ui src/dialogs/configdialog.ui src/dialogs/covererdialog.ui + src/dialogs/cylindereditor.ui src/dialogs/edger2dialog.ui src/dialogs/editrawdialog.ui src/dialogs/externalprogrampathdialog.ui
--- a/src/dialogs/cylindereditor.cpp Fri Jun 08 23:06:56 2018 +0300 +++ b/src/dialogs/cylindereditor.cpp Sun Jun 10 12:12:50 2018 +0300 @@ -1,14 +1,14 @@ #include "cylindereditor.h" #include "ui_cylindereditor.h" -CylinderEditor::CylinderEditor(QWidget *parent) : - QDialog(parent), - ui(new Ui::CylinderEditor) +CylinderEditor::CylinderEditor(QWidget* parent) : + QDialog {parent}, + ui {*new Ui_CylinderEditor} { - ui->setupUi(this); + ui.setupUi(this); } CylinderEditor::~CylinderEditor() { - delete ui; + delete &ui; }
--- a/src/dialogs/cylindereditor.h Fri Jun 08 23:06:56 2018 +0300 +++ b/src/dialogs/cylindereditor.h Sun Jun 10 12:12:50 2018 +0300 @@ -1,22 +1,14 @@ -#ifndef CYLINDEREDITOR_H -#define CYLINDEREDITOR_H - +#pragma once #include <QDialog> -namespace Ui { -class CylinderEditor; -} - class CylinderEditor : public QDialog { Q_OBJECT public: - explicit CylinderEditor(QWidget *parent = 0); + explicit CylinderEditor(QWidget* parent = nullptr); ~CylinderEditor(); private: - Ui::CylinderEditor *ui; + class Ui_CylinderEditor& ui; }; - -#endif // CYLINDEREDITOR_H
--- a/src/dialogs/cylindereditor.ui Fri Jun 08 23:06:56 2018 +0300 +++ b/src/dialogs/cylindereditor.ui Sun Jun 10 12:12:50 2018 +0300 @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>400</width> - <height>300</height> + <width>656</width> + <height>659</height> </rect> </property> <property name="windowTitle"> @@ -16,8 +16,8 @@ <widget class="QDialogButtonBox" name="buttonBox"> <property name="geometry"> <rect> - <x>30</x> - <y>240</y> + <x>190</x> + <y>570</y> <width>341</width> <height>32</height> </rect> @@ -29,7 +29,107 @@ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> </property> </widget> + <widget class="QGroupBox" name="groupBox"> + <property name="geometry"> + <rect> + <x>130</x> + <y>270</y> + <width>381</width> + <height>251</height> + </rect> + </property> + <property name="title"> + <string>Transformation</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="MatrixEditor" name="matrixEditor" native="true"/> + </item> + </layout> + </widget> + <widget class="QComboBox" name="divisions"> + <property name="geometry"> + <rect> + <x>200</x> + <y>110</y> + <width>76</width> + <height>25</height> + </rect> + </property> + <item> + <property name="text"> + <string>8</string> + </property> + </item> + <item> + <property name="text"> + <string>16</string> + </property> + </item> + <item> + <property name="text"> + <string>48</string> + </property> + </item> + </widget> + <widget class="QLabel" name="label"> + <property name="geometry"> + <rect> + <x>80</x> + <y>110</y> + <width>81</width> + <height>17</height> + </rect> + </property> + <property name="text"> + <string>Divisions:</string> + </property> + </widget> + <widget class="QLabel" name="label_2"> + <property name="geometry"> + <rect> + <x>90</x> + <y>70</y> + <width>63</width> + <height>17</height> + </rect> + </property> + <property name="text"> + <string>Segments:</string> + </property> + </widget> + <widget class="QSpinBox" name="segments"> + <property name="geometry"> + <rect> + <x>200</x> + <y>60</y> + <width>47</width> + <height>27</height> + </rect> + </property> + </widget> + <widget class="QLabel" name="label_3"> + <property name="geometry"> + <rect> + <x>90</x> + <y>150</y> + <width>63</width> + <height>17</height> + </rect> + </property> + <property name="text"> + <string>Colour:</string> + </property> + </widget> </widget> + <customwidgets> + <customwidget> + <class>MatrixEditor</class> + <extends>QWidget</extends> + <header>widgets/matrixeditor.h</header> + <container>1</container> + </customwidget> + </customwidgets> <resources/> <connections> <connection>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/widgets/colorbutton.cpp Sun Jun 10 12:12:50 2018 +0300 @@ -0,0 +1,90 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2013 - 2018 Teemu Piippo + * + * This program 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. + * + * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "colorbutton.h" +#include "../dialogs/colorselector.h" + +/* + * Initializes the color button and sets the default color + */ +ColorButton::ColorButton(LDColor color, QWidget* parent) : + ColorButton (parent) +{ + setColor(color); +} + +/* + * Initializes the color button + */ +ColorButton::ColorButton(QWidget* parent) : + QPushButton (parent) +{ + connect( + this, + &QPushButton::clicked, + [&]() + { + // The dialog must not have the button as the parent or the dialog inherits the stylesheet. + ColorSelector dialog {qobject_cast<QWidget*>(this->parent()), _color}; + + if (dialog.exec() and dialog.selectedColor().isValid()) + setColor(dialog.selectedColor()); + } + ); + + connect( + this, + &ColorButton::colorChanged, + [&](LDColor) + { + if (_color.isValid()) + { + setFlat(true); + setText(_color.name()); + setStyleSheet(format( + "background-color: %1; color: %2; border:none;", + _color.hexcode(), + _color.edgeColor().name() + )); + } + else + { + setFlat(false); + setText(""); + setStyleSheet(""); + } + } + ); +} + +/* + * Returns the currently selected color. + */ +LDColor ColorButton::color() const +{ + return _color; +} + +/* + * Sets the currently selected color. + */ +void ColorButton::setColor(LDColor color) +{ + _color = color; + emit colorChanged(color); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/widgets/colorbutton.h Sun Jun 10 12:12:50 2018 +0300 @@ -0,0 +1,40 @@ +/* + * LDForge: LDraw parts authoring CAD + * Copyright (C) 2013 - 2018 Teemu Piippo + * + * This program 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. + * + * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#pragma once +#include "../main.h" +#include "../colors.h" +#include <QPushButton> + +class ColorButton : public QPushButton +{ + Q_OBJECT + +public: + explicit ColorButton(LDColor color, QWidget* parent = nullptr); + explicit ColorButton(QWidget* parent = nullptr); + + LDColor color() const; + void setColor(LDColor color); + +signals: + void colorChanged(LDColor color); + +private: + LDColor _color; +};
--- a/src/widgets/vertexobjecteditor.cpp Fri Jun 08 23:06:56 2018 +0300 +++ b/src/widgets/vertexobjecteditor.cpp Sun Jun 10 12:12:50 2018 +0300 @@ -31,18 +31,7 @@ { this->ui.setupUi(this); this->ui.verticesContainer->setLayout(this->vertexGrid); - this->currentColor = this->object->color(); - setColorButton(this->ui.color, this->currentColor); - - connect( - this->ui.color, - &QPushButton::clicked, - [&]() - { - if (ColorSelector::selectColor(this, this->currentColor, this->currentColor)) - ::setColorButton(this->ui.color, this->currentColor); - } - ); + this->ui.colorButton->setColor(object->color()); for (int i : range(0, 1, object->numVertices() - 1)) { @@ -96,6 +85,6 @@ this->object->setVertex(i, vertex); } - this->object->setColor(this->currentColor); + this->object->setColor(ui.colorButton->color()); QDialog::accept(); }
--- a/src/widgets/vertexobjecteditor.h Fri Jun 08 23:06:56 2018 +0300 +++ b/src/widgets/vertexobjecteditor.h Sun Jun 10 12:12:50 2018 +0300 @@ -36,5 +36,4 @@ class Ui_VertexObjectEditor& ui; class QGridLayout* vertexGrid; LDObject* const object; - LDColor currentColor; };
--- a/src/widgets/vertexobjecteditor.ui Fri Jun 08 23:06:56 2018 +0300 +++ b/src/widgets/vertexobjecteditor.ui Sun Jun 10 12:12:50 2018 +0300 @@ -44,7 +44,7 @@ </widget> </item> <item> - <widget class="QPushButton" name="color"> + <widget class="ColorButton" name="colorButton"> <property name="text"> <string/> </property> @@ -64,6 +64,13 @@ </item> </layout> </widget> + <customwidgets> + <customwidget> + <class>ColorButton</class> + <extends>QPushButton</extends> + <header>widgets/colorbutton.h</header> + </customwidget> + </customwidgets> <resources/> <connections> <connection>