diff --git a/src/editor/C4ConsoleQtPropListViewer.cpp b/src/editor/C4ConsoleQtPropListViewer.cpp index 701357f90..a04ebf709 100644 --- a/src/editor/C4ConsoleQtPropListViewer.cpp +++ b/src/editor/C4ConsoleQtPropListViewer.cpp @@ -1588,6 +1588,40 @@ bool C4PropertyDelegateFactory::CheckCurrentEditor(C4PropertyDelegate *d, QWidge } +/* Property name view */ + +void C4PropertyNameDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + // Paint icon on the right + QStyleOptionViewItem override_option = option; + override_option.decorationPosition = QStyleOptionViewItem::Right; + QStyledItemDelegate::paint(painter, override_option, index); +} + +bool C4PropertyNameDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) +{ + // Mouse move over a cell: Display tooltip if over help button + if (event->type() == QEvent::MouseMove) + { + QVariant help_btn = property_model->data(index, Qt::DecorationRole); + if (!help_btn.isNull()) + { + QMouseEvent *mevent = static_cast(event); + if (option.rect.contains(mevent->localPos().toPoint())) + { + if (mevent->localPos().x() >= option.rect.x() + option.rect.width() - option.rect.height()) + { + QString tooltip_text = property_model->data(index, Qt::ToolTipRole).toString(); + QToolTip::showText(mevent->globalPos(), tooltip_text); + } + } + + } + } + return QStyledItemDelegate::editorEvent(event, model, option, index); +} + + /* Proplist table view */ C4ConsoleQtPropListModel::C4ConsoleQtPropListModel(C4PropertyDelegateFactory *delegate_factory) @@ -1633,8 +1667,9 @@ bool C4ConsoleQtPropListModel::AddPropertyGroup(C4PropList *add_proplist, int32_ C4String *prop_id = new_properties[i]; if (default_selection == prop_id) *default_selection_index = i; // Property data - prop->key = NULL; - prop->display_name = NULL; + prop->key = nullptr; + prop->display_name = nullptr; + prop->help_text = nullptr; prop->delegate_info.Set0(); // default C4Value delegate prop->group_idx = group_index; C4Value published_prop_val; @@ -1644,6 +1679,7 @@ bool C4ConsoleQtPropListModel::AddPropertyGroup(C4PropList *add_proplist, int32_ { prop->key = published_prop->GetPropertyStr(P_Key); prop->display_name = published_prop->GetPropertyStr(P_Name); + prop->help_text = published_prop->GetPropertyStr(P_EditorInfo); prop->delegate_info.SetPropList(published_prop); } if (!prop->key) properties.props[i].key = prop_id; @@ -1857,6 +1893,7 @@ int32_t C4ConsoleQtPropListModel::UpdateValuePropList(C4PropList *target_proplis internal_properties.props[i].property_path = target_path; internal_properties.props[i].key = new_properties[i]; internal_properties.props[i].display_name = new_properties[i]; + internal_properties.props[i].help_text = nullptr; internal_properties.props[i].delegate_info.Set0(); // default C4Value delegate internal_properties.props[i].delegate = NULL; // init when needed internal_properties.props[i].group_idx = num_groups; @@ -1891,6 +1928,7 @@ int32_t C4ConsoleQtPropListModel::UpdateValueArray(C4ValueArray *target_array, i prop.property_path = C4PropertyPath(target_path, i); prop.parent_value = target_value; prop.display_name = ::Strings.RegString(FormatString("%d", (int)i).getData()); + prop.help_text = nullptr; prop.key = nullptr; prop.delegate_info = elements_delegate_value; prop.delegate = item_delegate; @@ -2005,6 +2043,19 @@ QVariant C4ConsoleQtPropListModel::data(const QModelIndex & index, int role) con QColor txtclr = prop->delegate->GetDisplayTextColor(v, target_value.getObj()); if (txtclr.isValid()) return txtclr; } + else if (role == Qt::DecorationRole && index.column() == 0 && prop->help_text) + { + // Help icons in left column + return QIcon(":/editor/res/Help.png"); + } + else if (role == Qt::ToolTipRole && index.column() == 0) + { + // Tooltip from property description. Default to display name in case it got truncated. + if (prop->help_text) + return QString(prop->help_text->GetCStr()); + else + return QString(prop->display_name->GetCStr()); + } // Nothing to show return QVariant(); } diff --git a/src/editor/C4ConsoleQtPropListViewer.h b/src/editor/C4ConsoleQtPropListViewer.h index 1bb1cadce..1aa51b223 100644 --- a/src/editor/C4ConsoleQtPropListViewer.h +++ b/src/editor/C4ConsoleQtPropListViewer.h @@ -479,12 +479,30 @@ protected: void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; }; +class C4PropertyNameDelegate : public QStyledItemDelegate +{ + Q_OBJECT + + class C4ConsoleQtPropListModel *property_model; + +public: + C4PropertyNameDelegate() : property_model(nullptr) { } + + void SetPropertyModel(class C4ConsoleQtPropListModel *new_property_model) { property_model = new_property_model; } +protected: + // Model callbacks forwarded to actual delegates + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override { return nullptr; } // no editing + bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override; + void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; +}; + // One property in the prop list model view struct C4ConsoleQtPropListModelProperty { C4PropertyPath property_path; C4Value parent_value; C4RefCntPointer display_name; + C4RefCntPointer help_text; C4RefCntPointer key; C4Value delegate_info; C4PropertyDelegate *delegate; diff --git a/src/editor/C4ConsoleQtState.cpp b/src/editor/C4ConsoleQtState.cpp index 17a741986..6de9e6b89 100644 --- a/src/editor/C4ConsoleQtState.cpp +++ b/src/editor/C4ConsoleQtState.cpp @@ -535,10 +535,14 @@ bool C4ConsoleGUIState::CreateConsoleWindow(C4AbstractApp *app) ui.propertyEditAscendPathButton->setMaximumWidth(ui.propertyEditAscendPathButton->fontMetrics().boundingRect(ui.propertyEditAscendPathButton->text()).width() + 10); ui.propertyTable->setDropIndicatorShown(true); ui.propertyTable->setAcceptDrops(true); + property_name_delegate.reset(new C4PropertyNameDelegate()); + ui.propertyTable->setItemDelegateForColumn(0, property_name_delegate.get()); + ui.propertyTable->setMouseTracking(true); // View models property_model.reset(new C4ConsoleQtPropListModel(property_delegate_factory.get())); property_delegate_factory->SetPropertyModel(property_model.get()); + property_name_delegate->SetPropertyModel(property_model.get()); QItemSelectionModel *m = ui.propertyTable->selectionModel(); ui.propertyTable->setModel(property_model.get()); delete m; diff --git a/src/editor/C4ConsoleQtState.h b/src/editor/C4ConsoleQtState.h index 05f6f6faa..aea95c1d3 100644 --- a/src/editor/C4ConsoleQtState.h +++ b/src/editor/C4ConsoleQtState.h @@ -157,6 +157,7 @@ public: std::unique_ptr window; std::unique_ptr property_model; std::unique_ptr property_delegate_factory; + std::unique_ptr property_name_delegate; std::unique_ptr object_list_model; std::unique_ptr definition_list_model; std::list viewports; diff --git a/src/editor/resource.qrc b/src/editor/resource.qrc index 01594670b..7a68f40c0 100644 --- a/src/editor/resource.qrc +++ b/src/editor/resource.qrc @@ -1,5 +1,6 @@ + ../res/Help.png ../res/StaticFlat_Trans.png ../res/CreateObj_Trans.png ../res/Brush_Trans.png diff --git a/src/res/Help.png b/src/res/Help.png new file mode 100644 index 000000000..dc5df5c3c Binary files /dev/null and b/src/res/Help.png differ