(#641) Use color in QListView to indicate input point mode

This commit is contained in:
Magne Sjaastad 2015-11-30 15:12:00 +01:00
parent 512701ce11
commit 709d993cc6
5 changed files with 67 additions and 3 deletions

View File

@ -39,6 +39,7 @@
#include "cafCmdFeature.h"
#include "cafCmdFeatureManager.h"
#include "cafPdmUiListEditor.h"
#include "cafPdmUiPushButtonEditor.h"
@ -515,6 +516,14 @@ void RimCrossSection::defineEditorAttribute(const caf::PdmFieldHandle* field, QS
attrib->m_buttonText = "Start picking points";
}
}
else if (field == &m_userPolyline)
{
caf::PdmUiListEditorAttribute* myAttr = dynamic_cast<caf::PdmUiListEditorAttribute*>(attribute);
if (myAttr && inputFromViewerEnabled)
{
myAttr->m_baseColor.setRgb(255, 220, 255);
}
}
}
//--------------------------------------------------------------------------------------------------

View File

@ -1,5 +1,7 @@
#include "TapCvfSpecialization.h"
#include "cafPdmUiListEditor.h"
CAF_PDM_SOURCE_INIT(TapCvfSpecialization, "TapCvfSpecialization");
@ -20,3 +22,30 @@ TapCvfSpecialization::TapCvfSpecialization()
m_vecArrayField.v().push_back(cvf::Vec3d(1, 2, 3));
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void TapCvfSpecialization::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue)
{
if (changedField == &m_colorField)
{
updateConnectedEditors();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void TapCvfSpecialization::defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute)
{
if (field == &m_vecArrayField)
{
caf::PdmUiListEditorAttribute* myAttr = dynamic_cast<caf::PdmUiListEditorAttribute*>(attribute);
if (myAttr)
{
myAttr->m_backgroundColor.setRgbF(m_colorField().r(), m_colorField().g(), m_colorField().b());
}
}
}

View File

@ -24,6 +24,7 @@ public:
TapCvfSpecialization();
caf::PdmField<QString> m_testField;
caf::PdmField<cvf::Color3f> m_colorField;
@ -31,5 +32,11 @@ public:
caf::PdmField<cvf::Mat4d> m_matrixField;
caf::PdmField< std::vector< cvf::Vec3d> > m_vecArrayField;
public:
virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue);
protected:
virtual void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute);
};

View File

@ -139,9 +139,17 @@ void PdmUiListEditor::configureAndUpdateUi(const QString& uiConfigName)
m_listView->setEnabled(!field()->isUiReadOnly(uiConfigName));
m_listView->setToolTip(field()->uiToolTip(uiConfigName));
/// Demo code Not used yet
// PdmUiListEditorAttribute attributes;
// field()->ownerObject()->editorAttribute(field(), uiConfigName, &attributes);
PdmUiListEditorAttribute attributes;
caf::PdmUiObjectHandle* uiObject = uiObj(field()->fieldHandle()->ownerObject());
if (uiObject)
{
uiObject->editorAttribute(field()->fieldHandle(), uiConfigName, &attributes);
QPalette myPalette(m_listView->palette());
myPalette.setColor(QPalette::Base, attributes.m_baseColor);
m_listView->setPalette(myPalette);
}
MyStringListModel* strListModel = dynamic_cast<MyStringListModel*>(m_model.data());

View File

@ -54,6 +54,17 @@ namespace caf
//==================================================================================================
class PdmUiListEditorAttribute : public PdmUiEditorAttribute
{
public:
PdmUiListEditorAttribute()
: m_baseColor(Qt::white)
{
QPalette myPalette;
m_baseColor = myPalette.color(QPalette::Active, QPalette::Base);
}
public:
QColor m_baseColor;
};