diff options
author | Clinton Stimpson <clinton@elemtech.com> | 2007-11-13 05:17:10 (GMT) |
---|---|---|
committer | Clinton Stimpson <clinton@elemtech.com> | 2007-11-13 05:17:10 (GMT) |
commit | 073b10950802755d0c53748f693deab64ab152f4 (patch) | |
tree | 0c7ff68ef32ddcd90f2708ced4fb9f09ecc0dbf4 /Source/QtDialog/QCMakeCacheView.cxx | |
parent | 05f4f0e3e61c5e5bfd8bdbe83285f6eaab12dd80 (diff) | |
download | CMake-073b10950802755d0c53748f693deab64ab152f4.zip CMake-073b10950802755d0c53748f693deab64ab152f4.tar.gz CMake-073b10950802755d0c53748f693deab64ab152f4.tar.bz2 |
ENH: Allow clicking anywhere in field to toggle check boxes.
Diffstat (limited to 'Source/QtDialog/QCMakeCacheView.cxx')
-rw-r--r-- | Source/QtDialog/QCMakeCacheView.cxx | 50 |
1 files changed, 48 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<QKeyEvent*>(event)->key() != Qt::Key_Space && + static_cast<QKeyEvent*>(event)->key() != Qt::Key_Select) + { + return false; + } + } + else + { + return false; + } + + Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked + ? Qt::Unchecked : Qt::Checked); + return model->setData(index, state, Qt::CheckStateRole); +} + QCMakeCacheFileEditor::QCMakeCacheFileEditor(QWidget* p) : QLineEdit(p) { |