Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions qtfred/source_groups.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ add_file_folder("Source/UI/Widgets"
src/ui/widgets/PersonaColorComboBox.h
src/ui/widgets/renderwidget.cpp
src/ui/widgets/renderwidget.h
src/ui/widgets/sexp_data_menu.cpp
src/ui/widgets/sexp_data_menu.h
src/ui/widgets/data_list_menu.cpp
src/ui/widgets/data_list_menu.h
src/ui/widgets/sexp_tree_view.cpp
src/ui/widgets/sexp_tree_view.h
src/ui/widgets/ShipFlagCheckbox.h
Expand Down
10 changes: 6 additions & 4 deletions qtfred/src/mission/EditorViewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,11 @@ void EditorViewport::loadSettings() {
// Handles its own group, since main.cpp reads it before the viewport exists.
Theme_mode = readThemeModeSetting();
{
const int rawStyle = settings.value("sexp_data_menu_style", static_cast<int>(Sexp_data_menu_style)).toInt();
if (rawStyle >= 0 && rawStyle <= static_cast<int>(SexpDataMenuStyle::Searchable)) {
Sexp_data_menu_style = static_cast<SexpDataMenuStyle>(rawStyle);
// Fall back to the pre-rename key so an existing choice carries over.
const int legacyStyle = settings.value("sexp_data_menu_style", static_cast<int>(Data_menu_style)).toInt();
const int rawStyle = settings.value("data_menu_style", legacyStyle).toInt();
if (rawStyle >= 0 && rawStyle <= static_cast<int>(DataMenuStyle::Searchable)) {
Data_menu_style = static_cast<DataMenuStyle>(rawStyle);
}
}

Expand Down Expand Up @@ -198,7 +200,7 @@ void EditorViewport::saveSettings() const {
settings.setValue("show_sexp_help_ship_editor", Show_sexp_help_ship_editor);
settings.setValue("show_sexp_help_wing_editor", Show_sexp_help_wing_editor);
writeThemeModeSetting(Theme_mode);
settings.setValue("sexp_data_menu_style", static_cast<int>(Sexp_data_menu_style));
settings.setValue("data_menu_style", static_cast<int>(Data_menu_style));

settings.setValue("view_universal_heading", view.Universal_heading);
settings.setValue("view_show_stars", view.Show_stars);
Expand Down
4 changes: 2 additions & 2 deletions qtfred/src/mission/EditorViewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ enum class OtherKind {
JumpNode,
};

enum class SexpDataMenuStyle {
enum class DataMenuStyle {
Auto = 0,
Columns = 1,
Searchable = 2,
Expand Down Expand Up @@ -239,7 +239,7 @@ class EditorViewport {

ThemeMode Theme_mode = ThemeMode::System;

SexpDataMenuStyle Sexp_data_menu_style = SexpDataMenuStyle::Auto;
DataMenuStyle Data_menu_style = DataMenuStyle::Auto;

void saveSettings() const;

Expand Down
8 changes: 4 additions & 4 deletions qtfred/src/mission/dialogs/PreferencesDialogModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ PreferencesDialogModel::PreferencesDialogModel(QObject* parent, EditorViewport*
, _showSexpHelpShipEditor(viewport->Show_sexp_help_ship_editor)
, _showSexpHelpWingEditor(viewport->Show_sexp_help_wing_editor)
, _themeMode(viewport->Theme_mode)
, _sexpDataMenuStyle(viewport->Sexp_data_menu_style)
, _dataMenuStyle(viewport->Data_menu_style)
, _toolbarIconSize(viewport->toolbar_icon_size)
, _outlineLod(viewport->view.Outline_lod)
, _invertOrbitX(viewport->camera.getInvertOrbitX())
Expand Down Expand Up @@ -65,7 +65,7 @@ bool PreferencesDialogModel::apply() {
_viewport->Show_sexp_help_ship_editor = _showSexpHelpShipEditor;
_viewport->Show_sexp_help_wing_editor = _showSexpHelpWingEditor;
_viewport->Theme_mode = _themeMode;
_viewport->Sexp_data_menu_style = _sexpDataMenuStyle;
_viewport->Data_menu_style = _dataMenuStyle;
_viewport->toolbar_icon_size = _toolbarIconSize;
_viewport->view.Outline_lod = _outlineLod;
_viewport->camera.setInvertOrbitX(_invertOrbitX);
Expand Down Expand Up @@ -171,8 +171,8 @@ void PreferencesDialogModel::setShowSexpHelpWingEditor(bool value) { modify(_sho
ThemeMode PreferencesDialogModel::getThemeMode() const { return _themeMode; }
void PreferencesDialogModel::setThemeMode(ThemeMode value) { modify(_themeMode, value); }

SexpDataMenuStyle PreferencesDialogModel::getSexpDataMenuStyle() const { return _sexpDataMenuStyle; }
void PreferencesDialogModel::setSexpDataMenuStyle(SexpDataMenuStyle value) { modify(_sexpDataMenuStyle, value); }
DataMenuStyle PreferencesDialogModel::getDataMenuStyle() const { return _dataMenuStyle; }
void PreferencesDialogModel::setDataMenuStyle(DataMenuStyle value) { modify(_dataMenuStyle, value); }

int PreferencesDialogModel::getToolbarIconSize() const { return _toolbarIconSize; }
void PreferencesDialogModel::setToolbarIconSize(int size) { modify(_toolbarIconSize, size); }
Expand Down
6 changes: 3 additions & 3 deletions qtfred/src/mission/dialogs/PreferencesDialogModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class PreferencesDialogModel : public AbstractDialogModel {
ThemeMode getThemeMode() const;
void setThemeMode(ThemeMode value);

SexpDataMenuStyle getSexpDataMenuStyle() const;
void setSexpDataMenuStyle(SexpDataMenuStyle value);
DataMenuStyle getDataMenuStyle() const;
void setDataMenuStyle(DataMenuStyle value);

int getToolbarIconSize() const;
void setToolbarIconSize(int size);
Expand Down Expand Up @@ -105,7 +105,7 @@ class PreferencesDialogModel : public AbstractDialogModel {
bool _showSexpHelpShipEditor;
bool _showSexpHelpWingEditor;
ThemeMode _themeMode;
SexpDataMenuStyle _sexpDataMenuStyle;
DataMenuStyle _dataMenuStyle;
int _toolbarIconSize;
int _outlineLod;

Expand Down
38 changes: 19 additions & 19 deletions qtfred/src/ui/FredView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
#include "missioneditor/missionsave.h"

#include "widgets/ObjectComboBox.h"
#include "widgets/data_list_menu.h"

#include "util.h"
#include "mission/object.h"
Expand Down Expand Up @@ -1971,21 +1972,20 @@ void FredView::initializePopupMenus() {

_createSubmenu = new QMenu(tr("Create"), _viewPopup);

// Rebuilt on every open so a changed menu style preference takes effect.
_createShipSubmenu = new QMenu(tr("Ship"), _createSubmenu);
_createShipSubmenu->setStyleSheet("QMenu { menu-scrollable: 1; }");
connect(_createShipSubmenu, &QMenu::aboutToShow, this, [this]() {
if (_createShipSubmenu->actions().isEmpty()) {
populateCreateShipSubmenu();
}
_createShipSubmenu->clear();
populateCreateShipSubmenu();
});
_createSubmenu->addMenu(_createShipSubmenu);

_createPropSubmenu = new QMenu(tr("Prop"), _createSubmenu);
_createPropSubmenu->setStyleSheet("QMenu { menu-scrollable: 1; }");
connect(_createPropSubmenu, &QMenu::aboutToShow, this, [this]() {
if (_createPropSubmenu->actions().isEmpty()) {
populateCreatePropSubmenu();
}
_createPropSubmenu->clear();
populateCreatePropSubmenu();
});
_createSubmenu->addMenu(_createPropSubmenu);

Expand Down Expand Up @@ -2080,32 +2080,32 @@ void FredView::initializePopupMenus() {
}

void FredView::populateCreateShipSubmenu() {
std::vector<util::SelectMenuEntry> entries;
for (int i = 0; i < (int)Ship_info.size(); ++i) {
if (Ship_info[i].flags[Ship::Info_Flags::No_fred]) {
continue;
}
auto* action = new QAction(QString::fromUtf8(Ship_info[i].name), _createShipSubmenu);
connect(action, &QAction::triggered, this, [this, i]() {
_viewport->createShipAtScreenPos(_lastContextMenuLocalPos.x() * this->devicePixelRatio(),
_lastContextMenuLocalPos.y() * this->devicePixelRatio(), i);
});
_createShipSubmenu->addAction(action);
entries.push_back({QString::fromUtf8(Ship_info[i].name), i});
}
populateDataListMenu(_createShipSubmenu, entries, _viewport->Data_menu_style, [this](int shipClass) {
_viewport->createShipAtScreenPos(_lastContextMenuLocalPos.x() * this->devicePixelRatio(),
_lastContextMenuLocalPos.y() * this->devicePixelRatio(), shipClass);
});
}

void FredView::populateCreatePropSubmenu() {
std::vector<util::SelectMenuEntry> entries;
for (int i = 0; i < prop_info_size(); ++i) {
if (Prop_info[i].flags[Prop::Info_Flags::No_fred]) {
continue;
}
auto* action = new QAction(QString::fromStdString(Prop_info[i].name), _createPropSubmenu);
connect(action, &QAction::triggered, this, [this, i]() {
_viewport->createPropAtScreenPos(_lastContextMenuLocalPos.x() * this->devicePixelRatio(),
_lastContextMenuLocalPos.y() * this->devicePixelRatio(),
i);
});
_createPropSubmenu->addAction(action);
entries.push_back({QString::fromStdString(Prop_info[i].name), i});
}
populateDataListMenu(_createPropSubmenu, entries, _viewport->Data_menu_style, [this](int propClass) {
_viewport->createPropAtScreenPos(_lastContextMenuLocalPos.x() * this->devicePixelRatio(),
_lastContextMenuLocalPos.y() * this->devicePixelRatio(),
propClass);
});
}

void FredView::populateMoveToLayerMenu(int targetObject, QMenu* targetMenu) {
Expand Down
1 change: 1 addition & 0 deletions qtfred/src/ui/dialogs/JumpNodeEditorDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ JumpNodeEditorDialog::JumpNodeEditorDialog(FredView* parent, EditorViewport* vie
Editor* editor = viewport->editor;
util::installSelectMenu(
this,
viewport,
[]() {
std::vector<util::SelectMenuEntry> entries;
for (const auto& jn : Jump_nodes) {
Expand Down
6 changes: 3 additions & 3 deletions qtfred/src/ui/dialogs/PreferencesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void PreferencesDialog::updateUi() {
ui->checkPotentialIssues->setChecked(_model->getCheckPotentialIssues());
ui->applyAutoCorrections->setChecked(_model->getApplyAutoCorrections());
ui->themeCombo->setCurrentIndex(themeModeToIndex(_model->getThemeMode()));
ui->sexpDataMenuStyleCombo->setCurrentIndex(static_cast<int>(_model->getSexpDataMenuStyle()));
ui->dataMenuStyleCombo->setCurrentIndex(static_cast<int>(_model->getDataMenuStyle()));

const int iconSize = _model->getToolbarIconSize();
ui->toolbarIconSizeCombo->setCurrentIndex(iconSize <= 16 ? 0 : iconSize >= 32 ? 2 : 1);
Expand Down Expand Up @@ -202,8 +202,8 @@ void PreferencesDialog::on_themeCombo_currentIndexChanged(int index) {
_model->setThemeMode(themeModeFromIndex(index));
}

void PreferencesDialog::on_sexpDataMenuStyleCombo_currentIndexChanged(int index) {
_model->setSexpDataMenuStyle(static_cast<SexpDataMenuStyle>(index));
void PreferencesDialog::on_dataMenuStyleCombo_currentIndexChanged(int index) {
_model->setDataMenuStyle(static_cast<DataMenuStyle>(index));
}

void PreferencesDialog::on_showSexpHelpMissionEvents_toggled(bool checked) {
Expand Down
2 changes: 1 addition & 1 deletion qtfred/src/ui/dialogs/PreferencesDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private slots:
void on_toolbarIconSizeCombo_currentIndexChanged(int index);
void on_outlineLodCombo_currentIndexChanged(int index);
void on_themeCombo_currentIndexChanged(int index);
void on_sexpDataMenuStyleCombo_currentIndexChanged(int index);
void on_dataMenuStyleCombo_currentIndexChanged(int index);
void on_showSexpHelpMissionEvents_toggled(bool checked);
void on_showSexpHelpMissionGoals_toggled(bool checked);
void on_showSexpHelpMissionCutscenes_toggled(bool checked);
Expand Down
1 change: 1 addition & 0 deletions qtfred/src/ui/dialogs/PropEditorDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ PropEditorDialog::PropEditorDialog(FredView* parent, EditorViewport* viewport)
Editor* editor = viewport->editor;
util::installSelectMenu(
this,
viewport,
[]() {
std::vector<util::SelectMenuEntry> entries;
for (auto* ptr = GET_FIRST(&obj_used_list); ptr != END_OF_LIST(&obj_used_list); ptr = GET_NEXT(ptr)) {
Expand Down
1 change: 1 addition & 0 deletions qtfred/src/ui/dialogs/ShipEditor/ShipEditorDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ ShipEditorDialog::ShipEditorDialog(FredView* parent, EditorViewport* viewport)
Editor* editor = viewport->editor;
util::installSelectMenu(
this,
viewport,
[]() {
std::vector<util::SelectMenuEntry> entries;
for (auto* ptr = GET_FIRST(&obj_used_list); ptr != END_OF_LIST(&obj_used_list); ptr = GET_NEXT(ptr)) {
Expand Down
1 change: 1 addition & 0 deletions qtfred/src/ui/dialogs/WaypointEditorDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ WaypointEditorDialog::WaypointEditorDialog(FredView* parent, EditorViewport* vie
auto* model = _model.get();
util::installSelectMenu(
this,
viewport,
[]() {
std::vector<util::SelectMenuEntry> entries;
entries.reserve(Waypoint_lists.size());
Expand Down
1 change: 1 addition & 0 deletions qtfred/src/ui/dialogs/WingEditorDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ WingEditorDialog::WingEditorDialog(FredView* parent, EditorViewport* viewport)
Editor* editor = viewport->editor;
util::installSelectMenu(
this,
viewport,
[]() {
std::vector<util::SelectMenuEntry> entries;
for (int i = 0; i < MAX_WINGS; i++) {
Expand Down
25 changes: 6 additions & 19 deletions qtfred/src/ui/util/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

#include "menu.h"

#include <ui/widgets/data_list_menu.h>

#include <QAction>
#include <QFont>
#include <QLayout>
#include <QMenuBar>
#include <QWidget>
Expand Down Expand Up @@ -36,6 +37,7 @@ int propagate_disabled_status(QMenu* top) {
}

void installSelectMenu(QWidget* dialog,
EditorViewport* viewport,
std::function<std::vector<SelectMenuEntry>()> gather,
std::function<int()> currentId,
std::function<void(int)> onChosen,
Expand All @@ -58,26 +60,11 @@ void installSelectMenu(QWidget* dialog,

// Rebuild the list from the live scene every time the menu opens.
QObject::connect(menu, &QMenu::aboutToShow, menu,
[menu, gather = std::move(gather), currentId = std::move(currentId), onChosen = std::move(onChosen)]() {
[menu, viewport, gather = std::move(gather), currentId = std::move(currentId), onChosen = std::move(onChosen)]() {
menu->clear();
const int current = currentId ? currentId() : -1;
QAction* currentAct = nullptr;
for (const auto& entry : gather()) {
QAction* act = menu->addAction(entry.name);
if (entry.id == current) {
// Highlight the current object with a bold font
QFont font = act->font();
font.setBold(true);
act->setFont(font);
currentAct = act;
}
const int id = entry.id;
QObject::connect(act, &QAction::triggered, menu, [onChosen, id]() { onChosen(id); });
}
// Open with the current item pre-highlighted.
if (currentAct != nullptr) {
menu->setActiveAction(currentAct);
}
const DataMenuStyle style = viewport ? viewport->Data_menu_style : DataMenuStyle::Columns;
populateDataListMenu(menu, gather(), style, onChosen, 0, current);
});
}

Expand Down
7 changes: 6 additions & 1 deletion qtfred/src/ui/util/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class QWidget;

namespace fso {
namespace fred {

class EditorViewport;

namespace util {

int propagate_disabled_status(QMenu* top);
Expand All @@ -21,8 +24,10 @@ struct SelectMenuEntry {

// Adds a "Select" menu to an object-editor dialog's menu bar, creating a slim
// menu bar via the dialog's top-level layout if one isn't already present and
// reusing an existing bar otherwise.
// reusing an existing bar otherwise. The list is presented with the viewport's
// preferred data menu style (columns vs. searchable).
void installSelectMenu(QWidget* dialog,
EditorViewport* viewport,
std::function<std::vector<SelectMenuEntry>()> gather,
std::function<int()> currentId,
std::function<void(int)> onChosen,
Expand Down
Loading
Loading