# HG changeset patch # User Teemu Piippo # Date 1528621970 -10800 # Node ID 23551de3da36ecff88dcc015896b2d5a780aecd1 # Parent 8d9d0532b3df86e17fce60f3b437ad624132a645 separated the color button into a new widget diff -r 8d9d0532b3df -r 23551de3da36 CMakeLists.txt --- 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 diff -r 8d9d0532b3df -r 23551de3da36 src/dialogs/cylindereditor.cpp --- 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; } diff -r 8d9d0532b3df -r 23551de3da36 src/dialogs/cylindereditor.h --- 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 -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 diff -r 8d9d0532b3df -r 23551de3da36 src/dialogs/cylindereditor.ui --- 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 @@ 0 0 - 400 - 300 + 656 + 659 @@ -16,8 +16,8 @@ - 30 - 240 + 190 + 570 341 32 @@ -29,7 +29,107 @@ QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + 130 + 270 + 381 + 251 + + + + Transformation + + + + + + + + + + + 200 + 110 + 76 + 25 + + + + + 8 + + + + + 16 + + + + + 48 + + + + + + + 80 + 110 + 81 + 17 + + + + Divisions: + + + + + + 90 + 70 + 63 + 17 + + + + Segments: + + + + + + 200 + 60 + 47 + 27 + + + + + + + 90 + 150 + 63 + 17 + + + + Colour: + + + + + MatrixEditor + QWidget +
widgets/matrixeditor.h
+ 1 +
+
diff -r 8d9d0532b3df -r 23551de3da36 src/widgets/colorbutton.cpp --- /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 . + */ + +#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(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); +} diff -r 8d9d0532b3df -r 23551de3da36 src/widgets/colorbutton.h --- /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 . + */ + +#pragma once +#include "../main.h" +#include "../colors.h" +#include + +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; +}; diff -r 8d9d0532b3df -r 23551de3da36 src/widgets/vertexobjecteditor.cpp --- 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(); } diff -r 8d9d0532b3df -r 23551de3da36 src/widgets/vertexobjecteditor.h --- 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; }; diff -r 8d9d0532b3df -r 23551de3da36 src/widgets/vertexobjecteditor.ui --- 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 @@ - + @@ -64,6 +64,13 @@ + + + ColorButton + QPushButton +
widgets/colorbutton.h
+
+