123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- /*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
- #include "EditorCommon.h"
- #include "AlignToolbarSection.h"
- ModeToolbar::ModeToolbar(EditorWindow* parent)
- : QToolBar("Mode Toolbar", parent)
- , m_group(nullptr)
- , m_previousAction(nullptr)
- , m_alignToolbarSection(new AlignToolbarSection)
- {
- setObjectName("ModeToolbar"); // needed to save state
- setFloatable(false);
- AddModes(parent);
- m_alignToolbarSection->AddButtons(this);
- parent->addToolBar(this);
- }
- void ModeToolbar::SetCheckedItem(int index)
- {
- if (m_group)
- {
- for (auto action : m_group->actions())
- {
- if (action->data().toInt() == index)
- {
- m_previousAction->setChecked(false);
- m_previousAction = action;
- m_previousAction->setChecked(true);
- return;
- }
- }
- }
- }
- void ModeToolbar::AddModes(EditorWindow* parent)
- {
- m_group = new QActionGroup(this);
- int i = 0;
- for (const auto m : ViewportInteraction::InteractionMode())
- {
- int key = (Qt::Key_1 + i++);
- int mode = static_cast<int>(m);
- QString nodeName = ViewportHelpers::InteractionModeToString(mode);
- QString iconImageDefault = QString(":/Icons/Mode%1Default.png").arg(nodeName);
- QIcon icon(iconImageDefault);
- QAction* action = new QAction(icon,
- (QString("%1 (%2)").arg(ViewportHelpers::InteractionModeToString(mode), QString(static_cast<char>(key)))),
- this);
- action->setData(mode);
- action->setShortcut(QKeySequence(key));
- action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
- action->setCheckable(true); // Give it the behavior of a toggle button.
- QObject::connect(action,
- &QAction::triggered,
- this,
- [ this, parent, action ]([[maybe_unused]] bool checked)
- {
- if (m_previousAction == action)
- {
- // Nothing to do.
- return;
- }
- parent->GetViewport()->GetViewportInteraction()->SetMode((ViewportInteraction::InteractionMode)action->data().toInt());
- m_previousAction = action;
- });
- m_group->addAction(action);
- }
- // Give it the behavior of radio buttons.
- m_group->setExclusive(true);
- // Set the first action as the default.
- m_previousAction = m_group->actions().constFirst();
- m_previousAction->setChecked(true);
- addActions(m_group->actions());
- }
- #include <moc_ModeToolbar.cpp>
|