src/guiutilities.cpp

changeset 1297
389516787a4c
parent 1252
db1d4917626f
child 1298
dbc8bb2a4d84
equal deleted inserted replaced
1296:aee618d087ff 1297:389516787a4c
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19 #include <QComboBox> 19 #include <QComboBox>
20 #include <QPainter> 20 #include <QPainter>
21 #include <QPushButton>
21 #include "colors.h" 22 #include "colors.h"
22 #include "guiutilities.h" 23 #include "guiutilities.h"
23 #include "lddocument.h" 24 #include "lddocument.h"
25 #include "dialogs/colorselector.h"
24 #include "mainwindow.h" 26 #include "mainwindow.h"
25 27
26 GuiUtilities::GuiUtilities (QObject* parent) : 28 GuiUtilities::GuiUtilities (QObject* parent) :
27 QObject (parent), 29 QObject (parent),
28 HierarchyElement (parent) {} 30 HierarchyElement (parent) {}
144 } 146 }
145 } 147 }
146 148
147 return colors; 149 return colors;
148 } 150 }
151
152
153 void setColorButton(QPushButton* button, LDColor color)
154 {
155 if (color.isValid())
156 {
157 button->setFlat(true);
158 button->setText(color.name());
159 button->setStyleSheet(format("background-color: %1", color.hexcode()));
160 button->setStyleSheet(format("color: %1", color.edgeColor().name()));
161 }
162 else
163 {
164 button->setFlat(false);
165 button->setText("");
166 button->setStyleSheet("");
167 }
168 }
169
170 void setupColorButton(QWidget* parent, QPushButton* button, LDColor* color)
171 {
172 QObject::connect(
173 button,
174 &QPushButton::clicked,
175 [&]()
176 {
177 if (ColorSelector::selectColor(parent, *color, *color))
178 ::setColorButton(button, *color);
179 }
180 );
181 setColorButton(button, *color);
182 }

mercurial