File: SampleToolBar.cpp

package info (click to toggle)
bornagain 1.19.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 91,912 kB
  • sloc: cpp: 518,586; python: 42,512; xml: 805; awk: 630; sh: 470; ansic: 37; makefile: 25
file content (144 lines) | stat: -rw-r--r-- 5,905 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//  ************************************************************************************************
//
//  BornAgain: simulate and fit reflection and scattering
//
//! @file      GUI/coregui/Views/SampleDesigner/SampleToolBar.cpp
//! @brief     Implements class SampleToolBar
//!
//! @homepage  http://www.bornagainproject.org
//! @license   GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
//  ************************************************************************************************

#include "GUI/coregui/Views/SampleDesigner/SampleToolBar.h"
#include "GUI/coregui/Views/MaterialEditor/MaterialItemUtils.h"
#include "GUI/coregui/Views/SampleDesigner/DesignerView.h"
#include "GUI/coregui/Views/SampleView.h"
#include <QAction>
#include <QButtonGroup>
#include <QComboBox>
#include <QIcon>
#include <QLabel>
#include <QMenu>
#include <QPushButton>
#include <QToolButton>

//! main tool bar on top of SampleView window
SampleToolBar::SampleToolBar(SampleView* parent) : StyledToolBar(parent), m_sampleView(parent)
{
    // Select & Pan
    auto selectionPointerButton = new QToolButton;
    selectionPointerButton->setCheckable(true);
    selectionPointerButton->setChecked(true);
    selectionPointerButton->setIcon(QIcon(":/SampleDesigner/images/arrow-top-left.svg"));
    selectionPointerButton->setToolTip("Edit mode.");

    auto handPointerButton = new QToolButton;
    handPointerButton->setCheckable(true);
    handPointerButton->setIcon(QIcon(":/SampleDesigner/images/hand-right.svg"));
    handPointerButton->setToolTip("Pan mode (space).");

    m_pointerModeGroup = new QButtonGroup(this);
    m_pointerModeGroup->addButton(selectionPointerButton, DesignerView::RUBBER_SELECTION);
    m_pointerModeGroup->addButton(handPointerButton, DesignerView::HAND_DRAG);
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
    connect(m_pointerModeGroup, &QButtonGroup::idClicked, this, &SampleToolBar::selectionMode);
#else
    connect(m_pointerModeGroup,
            static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), this,
            &SampleToolBar::selectionMode);
#endif
    addWidget(selectionPointerButton);
    addWidget(handPointerButton);

    addStyledSeparator();

    // Remove item
    m_removeButton = new QToolButton;
    m_removeButton->setText("Remove item");
    m_removeButton->setIcon(QIcon(":/SampleDesigner/images/delete.svg"));
    m_removeButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
    m_removeButton->setToolTip("Remove selected items and they child items (del).");
    connect(m_removeButton, &QToolButton::clicked, this, &SampleToolBar::deleteItems);
    addWidget(m_removeButton);

    addStyledSeparator();

    // Center view
    m_centerViewButton = new QToolButton;
    m_centerViewButton->setText("Center view");
    m_centerViewButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
    m_centerViewButton->setIcon(QIcon(":/SampleDesigner/images/camera-metering-center.svg"));
    m_centerViewButton->setToolTip("Center view.");
    connect(m_centerViewButton, &QToolButton::clicked, this, &SampleToolBar::centerView);
    addWidget(m_centerViewButton);

    // Zoom
    addWidget(new QLabel(" "));
    m_scaleCombo = new QComboBox;
    QStringList scales = QStringList() << "25%"
                                       << "50%"
                                       << "75%"
                                       << "100%"
                                       << "125%"
                                       << "150%";
    m_scaleCombo->addItems(scales);
    m_scaleCombo->setCurrentIndex(3);
#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
    connect(m_scaleCombo,
            static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentTextChanged), this,
            &SampleToolBar::onScaleComboChanged);
#else
    connect(m_scaleCombo,
            static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged), this,
            &SampleToolBar::onScaleComboChanged);
#endif

    addWidget(m_scaleCombo);
    addWidget(new QLabel(" Zoom "));

    // MaterialEditor
    addWidget(new QLabel(" "));
    m_materialEditorButton = new QToolButton;
    m_materialEditorButton->setText("Material Editor");
    m_materialEditorButton->setIcon(QIcon(":/SampleDesigner/images/alpha-m-box.svg"));
    m_materialEditorButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
    m_materialEditorButton->setToolTip("Open material editor (m).");
    m_materialEditorButton->setShortcut(Qt::Key_M);
    connect(m_materialEditorButton, &QToolButton::clicked, this,
            &SampleToolBar::onMaterialEditorCall);
    addWidget(m_materialEditorButton);

    addStyledSeparator();

    // RealSpace 3D Viewer
    addWidget(new QLabel(" "));
    addWidget(new QLabel(" "));
    m_RealSpaceViewerButton = new QToolButton;
    m_RealSpaceViewerButton->setIcon(QIcon(":/SampleDesigner/images/rotate-3d.svg"));
    m_RealSpaceViewerButton->setText("3D Viewer");
    m_RealSpaceViewerButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
    m_RealSpaceViewerButton->setToolTip("Open real space 3D viewer.");
    connect(m_RealSpaceViewerButton, &QToolButton::clicked, m_sampleView,
            &SampleView::toggleRealSpaceView);
    addWidget(m_RealSpaceViewerButton);
}

void SampleToolBar::onViewSelectionMode(int mode)
{
    if (mode == DesignerView::RUBBER_SELECTION || mode == DesignerView::HAND_DRAG)
        m_pointerModeGroup->button(mode)->setChecked(true);
}

void SampleToolBar::onScaleComboChanged(const QString& scale_string)
{
    double scale = scale_string.left(scale_string.indexOf("%")).toDouble() / 100.0;
    emit changeScale(scale);
}

void SampleToolBar::onMaterialEditorCall()
{
    ExternalProperty mp = MaterialItemUtils::selectMaterialProperty();
}