Debian Codegraph @

avogadro/qtplugins/selectiontool/selectiontoolwidget.cpp

raw
1 /******************************************************************************
2 This source file is part of the Avogadro project.
3 This source code is released under the 3-Clause BSD License, (see "LICENSE").
4 ******************************************************************************/
5
6 #include "selectiontoolwidget.h"
7 #include "ui_selectiontoolwidget.h"
8
9 #include <QtWidgets/QColorDialog>
10
11 namespace Avogadro::QtPlugins {
12
13 SelectionToolWidget::SelectionToolWidget(QWidget* parent)
14 : QWidget(parent), m_ui(new Ui::SelectionToolWidget)
15 {
16 m_ui->setupUi(this);
17 setDropDown(0, 1);
18 connect(m_ui->applyColorButton, SIGNAL(clicked()), this,
19 SLOT(userClickedColor()));
20 }
21
22 SelectionToolWidget::~SelectionToolWidget()
23 {
24 delete m_ui;
25 }
26
27 void SelectionToolWidget::setDropDown(size_t current, size_t max)
28 {
29 // disconnect the signal so we don't send it accidentally
30 disconnect(m_ui->changeLayerDropDown, nullptr, nullptr, nullptr);
31 m_ui->changeLayerDropDown->clear();
32 for (size_t i = 0; i < max; ++i) {
33 m_ui->changeLayerDropDown->addItem(QString::number(i + 1));
34 }
35 m_ui->changeLayerDropDown->addItem(tr("New Layer"));
36 if (current != static_cast<size_t>(m_ui->changeLayerDropDown->currentIndex()))
37 m_ui->changeLayerDropDown->setCurrentIndex(static_cast<int>(current));
38
39 // reconnect the signal
40 connect(m_ui->changeLayerDropDown, SIGNAL(currentIndexChanged(int)), this,
41 SIGNAL(changeLayer(int)));
42 }
43
44 void SelectionToolWidget::userClickedColor()
45 {
46 QColorDialog dlg(this);
47
48 QPalette pal = m_ui->applyColorButton->palette();
49 dlg.setCurrentColor(pal.color(QPalette::Button));
50
51 if (dlg.exec()) {
52 QColor new_color = dlg.currentColor();
53 pal.setColor(QPalette::Button, new_color);
54 m_ui->applyColorButton->setPalette(pal);
55 m_ui->applyColorButton->update();
56
57 Vector3ub color;
58 color[0] = static_cast<unsigned char>(new_color.red());
59 color[1] = static_cast<unsigned char>(new_color.green());
60 color[2] = static_cast<unsigned char>(new_color.blue());
61
62 emit colorApplied(color);
63 }
64 }
65
66 } // namespace Avogadro::QtPlugins