Skip to content
Snippets Groups Projects
Commit 96488416 authored by Matthias Puchner's avatar Matthias Puchner
Browse files

improve unit switching (two auto-exclusive actions)

parent 2f7ee5d5
No related branches found
No related tags found
1 merge request!415Unit handling in layer oriented sample editor
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "GUI/Views/SampleDesigner/MultiLayerForm.h" #include "GUI/Views/SampleDesigner/MultiLayerForm.h"
#include "GUI/Views/SampleDesigner/SampleEditorController.h" #include "GUI/Views/SampleDesigner/SampleEditorController.h"
#include "GUI/Application/Application.h"
#include <QBoxLayout> #include <QBoxLayout>
#include <QScrollArea> #include <QScrollArea>
...@@ -29,7 +30,7 @@ LayerOrientedSampleEditor::LayerOrientedSampleEditor(QWidget* parent) ...@@ -29,7 +30,7 @@ LayerOrientedSampleEditor::LayerOrientedSampleEditor(QWidget* parent)
, m_undoAction(nullptr) , m_undoAction(nullptr)
, m_redoAction(nullptr) , m_redoAction(nullptr)
, m_showInlineEditButtonsAction(nullptr) , m_showInlineEditButtonsAction(nullptr)
, m_asAngstrom(nullptr) , m_asAngstromAction(nullptr)
, m_currentMultiLayerItem(nullptr) , m_currentMultiLayerItem(nullptr)
{ {
setAttribute(Qt::WA_StyledBackground, true); setAttribute(Qt::WA_StyledBackground, true);
...@@ -55,11 +56,27 @@ LayerOrientedSampleEditor::LayerOrientedSampleEditor(QWidget* parent) ...@@ -55,11 +56,27 @@ LayerOrientedSampleEditor::LayerOrientedSampleEditor(QWidget* parent)
m_showInlineEditButtonsAction->setChecked(false); m_showInlineEditButtonsAction->setChecked(false);
m_toolbar->addAction(m_showInlineEditButtonsAction); m_toolbar->addAction(m_showInlineEditButtonsAction);
m_asAngstrom = new QAction("A", this); m_asAngstromAction = new QAction("A", this); // #baLayerEditor use icon, not text
connect(m_asAngstrom, &QAction::toggled, this, &LayerOrientedSampleEditor::onAsAngstromToggled); m_asAngstromAction->setToolTip("Use \303\205ngstrom as unit (where applicable)");
m_asAngstrom->setCheckable(true); connect(m_asAngstromAction, &QAction::toggled, this,
m_asAngstrom->setChecked(false); &LayerOrientedSampleEditor::onUnitActionToggled);
m_toolbar->addAction(m_asAngstrom); m_asAngstromAction->setCheckable(true);
auto* asNanometerAction = new QAction("nm", this); // #baLayerEditor use icon, not text
asNanometerAction->setToolTip("Use nanometer as unit (where applicable)");
connect(asNanometerAction, &QAction::toggled, this,
&LayerOrientedSampleEditor::onUnitActionToggled);
asNanometerAction->setCheckable(true);
auto* ag = new QActionGroup(this);
ag->addAction(asNanometerAction);
ag->addAction(m_asAngstromAction);
if (baApp->settings().defaultUnitIsAngstrom())
m_asAngstromAction->setChecked(true);
else
asNanometerAction->setChecked(true);
m_toolbar->addActions(ag->actions());
} }
LayerOrientedSampleEditor::~LayerOrientedSampleEditor() LayerOrientedSampleEditor::~LayerOrientedSampleEditor()
...@@ -108,6 +125,7 @@ void LayerOrientedSampleEditor::setCurrentSample(MultiLayerItem* multiLayerItem) ...@@ -108,6 +125,7 @@ void LayerOrientedSampleEditor::setCurrentSample(MultiLayerItem* multiLayerItem)
m_currentMultiLayerWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); m_currentMultiLayerWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
m_scrollArea->setWidget(m_currentMultiLayerWidget); m_scrollArea->setWidget(m_currentMultiLayerWidget);
m_currentMultiLayerWidget->showInlineEditButtons(m_showInlineEditButtonsAction->isChecked()); m_currentMultiLayerWidget->showInlineEditButtons(m_showInlineEditButtonsAction->isChecked());
m_currentMultiLayerWidget->useAngstrom(m_asAngstromAction->isChecked());
updateActionEnabling(); updateActionEnabling();
} }
...@@ -123,10 +141,10 @@ void LayerOrientedSampleEditor::onShowInlineEditButtonsToggled(bool checked) ...@@ -123,10 +141,10 @@ void LayerOrientedSampleEditor::onShowInlineEditButtonsToggled(bool checked)
m_currentMultiLayerWidget->showInlineEditButtons(checked); m_currentMultiLayerWidget->showInlineEditButtons(checked);
} }
void LayerOrientedSampleEditor::onAsAngstromToggled() void LayerOrientedSampleEditor::onUnitActionToggled()
{ {
if (m_currentMultiLayerWidget) if (m_currentMultiLayerWidget)
m_currentMultiLayerWidget->useAngstrom(m_asAngstrom->isChecked()); m_currentMultiLayerWidget->useAngstrom(m_asAngstromAction->isChecked());
} }
void LayerOrientedSampleEditor::createLayerColors() // #baLayerEditor move to better place void LayerOrientedSampleEditor::createLayerColors() // #baLayerEditor move to better place
......
...@@ -36,7 +36,7 @@ public: ...@@ -36,7 +36,7 @@ public:
private: private:
void updateActionEnabling(); void updateActionEnabling();
void onShowInlineEditButtonsToggled(bool checked); void onShowInlineEditButtonsToggled(bool checked);
void onAsAngstromToggled(); void onUnitActionToggled();
void createLayerColors(); void createLayerColors();
QWidget* createEmptyWidget(); QWidget* createEmptyWidget();
...@@ -48,7 +48,7 @@ private: ...@@ -48,7 +48,7 @@ private:
QAction* m_undoAction; // dedicated to the current sample QAction* m_undoAction; // dedicated to the current sample
QAction* m_redoAction; QAction* m_redoAction;
QAction* m_showInlineEditButtonsAction; QAction* m_showInlineEditButtonsAction;
QAction* m_asAngstrom; // #baLayerEditor better two autoexclusive actions? QAction* m_asAngstromAction;
MultiLayerItem* m_currentMultiLayerItem = nullptr; MultiLayerItem* m_currentMultiLayerItem = nullptr;
QMap<MultiLayerItem*, SampleEditorController*> m_editControllers; QMap<MultiLayerItem*, SampleEditorController*> m_editControllers;
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment