PropertyEditor: improve editing experience
This commit is contained in:
@@ -53,6 +53,9 @@ PropertyEditor::PropertyEditor(QWidget *parent)
|
||||
QStyleOptionViewItem opt = viewOptions();
|
||||
this->background = opt.palette.dark();
|
||||
this->groupColor = opt.palette.color(QPalette::BrightText);
|
||||
|
||||
connect(this, SIGNAL(activated(const QModelIndex &)), this, SLOT(onItemActivated(const QModelIndex &)));
|
||||
connect(this, SIGNAL(clicked(const QModelIndex &)), this, SLOT(onItemActivated(const QModelIndex &)));
|
||||
}
|
||||
|
||||
PropertyEditor::~PropertyEditor()
|
||||
@@ -127,8 +130,17 @@ void PropertyEditor::currentChanged ( const QModelIndex & current, const QModelI
|
||||
QTreeView::currentChanged(current, previous);
|
||||
if (previous.isValid())
|
||||
closePersistentEditor(model()->buddy(previous));
|
||||
if (current.isValid())
|
||||
openPersistentEditor(model()->buddy(current));
|
||||
|
||||
// DO NOT activate editor here, use onItemActivate() which response to
|
||||
// signals of activated and clicked.
|
||||
//
|
||||
// if (current.isValid())
|
||||
// openPersistentEditor(model()->buddy(current));
|
||||
}
|
||||
|
||||
void PropertyEditor::onItemActivated ( const QModelIndex & index )
|
||||
{
|
||||
openPersistentEditor(model()->buddy(index));
|
||||
}
|
||||
|
||||
void PropertyEditor::reset()
|
||||
|
||||
@@ -81,6 +81,9 @@ public:
|
||||
QColor groupTextColor() const;
|
||||
void setGroupTextColor(const QColor& c);
|
||||
|
||||
public Q_SLOTS:
|
||||
void onItemActivated(const QModelIndex &index);
|
||||
|
||||
protected:
|
||||
virtual void closeEditor (QWidget * editor, QAbstractItemDelegate::EndEditHint hint);
|
||||
virtual void commitData (QWidget * editor);
|
||||
|
||||
@@ -38,6 +38,8 @@ using namespace Gui::PropertyEditor;
|
||||
PropertyItemDelegate::PropertyItemDelegate(QObject* parent)
|
||||
: QItemDelegate(parent), pressed(false)
|
||||
{
|
||||
connect(this, SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)),
|
||||
this, SLOT(editorClosed(QWidget*)));
|
||||
}
|
||||
|
||||
PropertyItemDelegate::~PropertyItemDelegate()
|
||||
@@ -112,6 +114,10 @@ bool PropertyItemDelegate::editorEvent (QEvent * event, QAbstractItemModel* mode
|
||||
return QItemDelegate::editorEvent(event, model, option, index);
|
||||
}
|
||||
|
||||
void PropertyItemDelegate::editorClosed(QWidget *editor) {
|
||||
editor->close();
|
||||
}
|
||||
|
||||
QWidget * PropertyItemDelegate::createEditor (QWidget * parent, const QStyleOptionViewItem & /*option*/,
|
||||
const QModelIndex & index ) const
|
||||
{
|
||||
@@ -126,8 +132,14 @@ QWidget * PropertyItemDelegate::createEditor (QWidget * parent, const QStyleOpti
|
||||
editor->setAutoFillBackground(true);
|
||||
if (editor && childItem->isReadOnly())
|
||||
editor->setDisabled(true);
|
||||
else if (editor && this->pressed)
|
||||
// else if (editor && this->pressed)
|
||||
else if(editor) {
|
||||
// We changed the way editor is activated in PropertyEditor (in response
|
||||
// of signal activated and clicked), so now we should grab focus
|
||||
// regardless of "preseed" or not (e.g. when activated by keyboard
|
||||
// enter)
|
||||
editor->setFocus();
|
||||
}
|
||||
this->pressed = false;
|
||||
return editor;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ public:
|
||||
|
||||
public Q_SLOTS:
|
||||
void valueChanged();
|
||||
void editorClosed(QWidget *);
|
||||
|
||||
private:
|
||||
mutable bool pressed;
|
||||
|
||||
Reference in New Issue
Block a user