From 073b10950802755d0c53748f693deab64ab152f4 Mon Sep 17 00:00:00 2001 From: Clinton Stimpson Date: Tue, 13 Nov 2007 00:17:10 -0500 Subject: ENH: Allow clicking anywhere in field to toggle check boxes. --- Source/QtDialog/QCMakeCacheView.cxx | 50 +++++++++++++++++++++++++++++++++++-- Source/QtDialog/QCMakeCacheView.h | 2 ++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/Source/QtDialog/QCMakeCacheView.cxx b/Source/QtDialog/QCMakeCacheView.cxx index 3ded470..cfc1b11 100644 --- a/Source/QtDialog/QCMakeCacheView.cxx +++ b/Source/QtDialog/QCMakeCacheView.cxx @@ -314,11 +314,14 @@ bool QCMakeCacheModel::setData (const QModelIndex& idx, const QVariant& value, i return false; } -QModelIndex QCMakeCacheModel::buddy ( const QModelIndex& idx ) const +QModelIndex QCMakeCacheModel::buddy(const QModelIndex& idx) const { if(idx.column() == 0) { - return this->index(idx.row(), 1); + if(this->Properties[idx.row()].Type != QCMakeCacheProperty::BOOL) + { + return this->index(idx.row(), 1); + } } return idx; } @@ -387,6 +390,49 @@ QWidget* QCMakeCacheModelDelegate::createEditor(QWidget* p, return new QLineEdit(p); } +bool QCMakeCacheModelDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, + const QStyleOptionViewItem& option, const QModelIndex& index) +{ + Qt::ItemFlags flags = model->flags(index); + if (!(flags & Qt::ItemIsUserCheckable) || !(option.state & QStyle::State_Enabled) + || !(flags & Qt::ItemIsEnabled)) + { + return false; + } + + QVariant value = index.data(Qt::CheckStateRole); + if (!value.isValid()) + { + return false; + } + + if ((event->type() == QEvent::MouseButtonRelease) + || (event->type() == QEvent::MouseButtonDblClick)) + { + // eat the double click events inside the check rect + if (event->type() == QEvent::MouseButtonDblClick) + { + return true; + } + } + else if (event->type() == QEvent::KeyPress) + { + if(static_cast(event)->key() != Qt::Key_Space && + static_cast(event)->key() != Qt::Key_Select) + { + return false; + } + } + else + { + return false; + } + + Qt::CheckState state = (static_cast(value.toInt()) == Qt::Checked + ? Qt::Unchecked : Qt::Checked); + return model->setData(index, state, Qt::CheckStateRole); +} + QCMakeCacheFileEditor::QCMakeCacheFileEditor(QWidget* p) : QLineEdit(p) { diff --git a/Source/QtDialog/QCMakeCacheView.h b/Source/QtDialog/QCMakeCacheView.h index b427af5..fcf73cf 100644 --- a/Source/QtDialog/QCMakeCacheView.h +++ b/Source/QtDialog/QCMakeCacheView.h @@ -105,6 +105,8 @@ public: /// create our own editors for cache properties QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const; + bool editorEvent (QEvent* event, QAbstractItemModel* model, + const QStyleOptionViewItem& option, const QModelIndex& index); }; /// Editor widget for editing paths or file paths -- cgit v0.12