From b8e96379a749ef9369ab739feceb2d5f54ca9cf4 Mon Sep 17 00:00:00 2001 From: mgrojo Date: Sat, 3 Feb 2018 16:14:30 +0100 Subject: [PATCH] Set disabled palette for the cell text editor when read-only In this way the user gets a hint about the text being read-only while still being able to select text with keyboard and mouse. See issue #1123 --- src/EditDialog.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/EditDialog.cpp b/src/EditDialog.cpp index 2def845d..75d004f7 100644 --- a/src/EditDialog.cpp +++ b/src/EditDialog.cpp @@ -754,21 +754,40 @@ void EditDialog::setFocus() } -// Enables or disables the Apply, Null, & Import buttons in the Edit Cell dock +// Enables or disables the Apply, Null, & Import buttons in the Edit Cell dock. +// Sets or unsets read-only properties for the editors. void EditDialog::setReadOnly(bool ro) { isReadOnly = ro; + QPalette textEditPalette = ui->editorText->palette(); ui->buttonApply->setEnabled(!ro); ui->buttonNull->setEnabled(!ro); ui->buttonImport->setEnabled(!ro); ui->editorText->setReadOnly(ro); + sciEdit->setReadOnly(ro); + // We disable the entire hex editor here instead of setting it to read only because it doesn't have a setReadOnly() method + ui->editorBinary->setEnabled(!ro); + + // This makes the caret being visible for selection, although the editor is read-only. Qt::TextInteractionFlags textFlags = ro? Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard : Qt::TextEditorInteraction; ui->editorText->setTextInteractionFlags(textFlags); - ui->editorBinary->setEnabled(!ro); // We disable the entire hex editor here instead of setting it to read only because it doesn't have a setReadOnly() method - sciEdit->setReadOnly(ro); + // If read-only, set the Disabled palette settings for the (in)active groups, so the user gets a hint about the text being read-only. + // This should be set also for the Scintilla widget, but it isn't working for that. + if (ro) { + textEditPalette.setColor(QPalette::Active, QPalette::Base, textEditPalette.color(QPalette::Disabled, QPalette::Base)); + textEditPalette.setColor(QPalette::Inactive, QPalette::Base, textEditPalette.color(QPalette::Disabled, QPalette::Base)); + textEditPalette.setColor(QPalette::Active, QPalette::Highlight, textEditPalette.color(QPalette::Disabled, QPalette::Highlight)); + textEditPalette.setColor(QPalette::Inactive, QPalette::Highlight, textEditPalette.color(QPalette::Disabled, QPalette::Highlight)); + textEditPalette.setColor(QPalette::Active, QPalette::HighlightedText, textEditPalette.color(QPalette::Disabled, QPalette::HighlightedText)); + textEditPalette.setColor(QPalette::Inactive, QPalette::HighlightedText, textEditPalette.color(QPalette::Disabled, QPalette::HighlightedText)); + ui->editorText->setPalette(textEditPalette); + } else { + // Restore default palette + ui->editorText->setPalette(QPalette()); + } } // Update the information labels in the bottom left corner of the dialog