From 4a2ffc83f8c1cff1e03b86d4f4824c23631624df Mon Sep 17 00:00:00 2001 From: Bernhard Roider Date: Wed, 9 May 2007 20:09:03 +0000 Subject: [PATCH] Problem: A crash when no color is selected and the "alter" button is pressed. Solution: Disable the alter button if no item is selected and add an additional test for a valid index. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18247 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/QPrefs.cpp | 14 +++++++++++++- src/frontends/qt4/QPrefs.h | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/frontends/qt4/QPrefs.cpp b/src/frontends/qt4/QPrefs.cpp index cbc9a373c0..8566d7868b 100644 --- a/src/frontends/qt4/QPrefs.cpp +++ b/src/frontends/qt4/QPrefs.cpp @@ -545,6 +545,8 @@ PrefColors::PrefColors(QPrefs * form, QWidget * parent) connect(colorChangePB, SIGNAL(clicked()), this, SLOT(change_color())); + connect(lyxObjectsLW, SIGNAL(itemSelectionChanged()), + this, SLOT(change_lyxObjects_selection())); connect(lyxObjectsLW, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(change_color())); } @@ -570,12 +572,17 @@ void PrefColors::apply(LyXRC & /*rc*/) const // problem here. void PrefColors::update(LyXRC const & /*rc*/) { + change_lyxObjects_selection(); } void PrefColors::change_color() { int const row = lyxObjectsLW->currentRow(); - QString color = newcolors_[row]; + + // just to be sure + if (row < 0) return; + + QString const color = newcolors_[row]; QColor c(QColorDialog::getColor(QColor(color), qApp->focusWidget())); if (c.isValid() && c.name() != color) { @@ -588,6 +595,11 @@ void PrefColors::change_color() } } +void PrefColors::change_lyxObjects_selection() +{ + colorChangePB->setDisabled(lyxObjectsLW->currentRow() < 0); +} + ///////////////////////////////////////////////////////////////////// // diff --git a/src/frontends/qt4/QPrefs.h b/src/frontends/qt4/QPrefs.h index 6efdcadbdc..0757813e9e 100644 --- a/src/frontends/qt4/QPrefs.h +++ b/src/frontends/qt4/QPrefs.h @@ -156,6 +156,7 @@ public: private Q_SLOTS: void change_color(); + void change_lyxObjects_selection(); private: std::vector lcolors_;