mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 19:11:39 -06:00
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
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user