r19532 by jghali - #12662: fixed several crashes and issues related to deletion of colors with keypress
scribus-commit
scribus-commit at lists.scribus.net
Wed Sep 24 00:02:20 UTC 2014
Author: jghali
Date: Wed Sep 24 00:02:20 2014
New Revision: 19532
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=19532
Log:
#12662: fixed several crashes and issues related to deletion of colors with keypress
Modified:
trunk/Scribus/scribus/ui/paintmanager.cpp
trunk/Scribus/scribus/ui/paintmanager.h
Modified: trunk/Scribus/scribus/ui/paintmanager.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19532&path=/trunk/Scribus/scribus/ui/paintmanager.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/paintmanager.cpp (original)
+++ trunk/Scribus/scribus/ui/paintmanager.cpp Wed Sep 24 00:02:20 2014
@@ -334,9 +334,8 @@
if ((it->parent() == colorItems) || (it->parent() == gradientItems))
{
QString curCol = it->text(0);
- ScColor tmpColor = m_colorList[curCol];
- bool enableDel = (curCol != "Black" && curCol != "White" && !tmpColor.isRegistrationColor()) && (m_colorList.count() > 1);
- bool enableEdit = (curCol != "Black" && curCol != "White" && !tmpColor.isRegistrationColor());
+ bool enableDel = (!isMandatoryColor(curCol)) && (m_colorList.count() > 1);
+ bool enableEdit = (!isMandatoryColor(curCol));
duplicateButton->setEnabled(curCol != "Registration");
deleteButton->setEnabled(enableDel);
editButton->setEnabled(enableEdit);
@@ -370,8 +369,8 @@
{
QString curCol = it->text(0);
ScColor tmpColor = m_colorList[curCol];
- bool enableDel = (curCol != "Black" && curCol != "White" && !tmpColor.isRegistrationColor()) && (m_colorList.count() > 1);
- bool enableEdit = (curCol != "Black" && curCol != "White" && !tmpColor.isRegistrationColor());
+ bool enableDel = (!isMandatoryColor(curCol)) && (m_colorList.count() > 1);
+ bool enableEdit = (!isMandatoryColor(curCol));
duplicateButton->setEnabled(curCol != "Registration");
deleteButton->setEnabled(enableDel);
editButton->setEnabled(enableEdit);
@@ -715,11 +714,7 @@
continue;
if (it == patternItems)
continue;
- if (it->text(0) == "Black")
- continue;
- if (it->text(0) == "White")
- continue;
- if (m_colorList[it->text(0)].isRegistrationColor())
+ if (isMandatoryColor(it->text(0)))
continue;
if (it->parent() == gradientItems)
gradients.append(it->text(0));
@@ -842,7 +837,7 @@
else
{
QString dColor = it->text(0);
- if (dColor == "Black" || dColor == "White" || m_colorList[dColor].isRegistrationColor())
+ if (isMandatoryColor(dColor))
return;
ColorList UsedCG = getGradientColors();
if (inDocUsedColors.contains(dColor) || UsedCG.contains(dColor))
@@ -1393,6 +1388,16 @@
UndoManager::instance()->setUndoEnabled(true);
}
+bool PaintManagerDialog::isMandatoryColor(QString colorName)
+{
+ if (colorName == "Black" || colorName == "White")
+ return true;
+ ScColor color = m_colorList.value(colorName, ScColor());
+ if (color.isRegistrationColor())
+ return true;
+ return false;
+}
+
ColorList PaintManagerDialog::getGradientColors()
{
ColorList colorList;
@@ -1925,17 +1930,26 @@
void PaintManagerDialog::keyPressEvent(QKeyEvent* k)
{
+ if (k->modifiers()!=Qt::NoModifier || (k->key()!=Qt::Key_Delete && k->key()!=Qt::Key_Backspace))
+ return;
+
+ QString belowText;
QList<QTreeWidgetItem *> selItems = dataTree->selectedItems();
- QString belowText = dataTree->itemBelow(selItems[selItems.count()-1])->text(0);
-
- // Prevent deletion of Black, White and Registration color
- if (!deleteButton->isEnabled())
- return;
-
- if (k->modifiers()==Qt::NoModifier && (k->key()==Qt::Key_Delete || k->key()==Qt::Key_Backspace))
- removeColorItem();
-
- QList<QTreeWidgetItem *> belowItems=dataTree->findItems(belowText, Qt::MatchFixedString|Qt::MatchCaseSensitive|Qt::MatchRecursive);
- if(belowItems.count()>0)
- belowItems[0]->setSelected(true);
-}
+ if (selItems.count() > 0)
+ {
+ QTreeWidgetItem* belowItem = dataTree->itemBelow(selItems.last());
+ if (belowItem)
+ belowText = belowItem->text(0);
+ }
+
+ removeColorItem();
+
+ QList<QTreeWidgetItem *> belowItems = dataTree->findItems(belowText, Qt::MatchFixedString|Qt::MatchCaseSensitive|Qt::MatchRecursive);
+ if (belowItems.count() > 0)
+ {
+ // In case non deletable colors have been selected, some items
+ //may still be selected, so clear selection first
+ dataTree->selectionModel()->clearSelection();
+ dataTree->setCurrentItem(belowItems[0]);
+ }
+}
Modified: trunk/Scribus/scribus/ui/paintmanager.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19532&path=/trunk/Scribus/scribus/ui/paintmanager.h
==============================================================================
--- trunk/Scribus/scribus/ui/paintmanager.h (original)
+++ trunk/Scribus/scribus/ui/paintmanager.h Wed Sep 24 00:02:20 2014
@@ -90,6 +90,7 @@
QTreeWidgetItem* updateGradientList(QString addedName = "");
QTreeWidgetItem* updateColorList(QString addedName = "");
ColorList getGradientColors();
+ bool isMandatoryColor(QString colorName);
void loadPatternDir();
void loadVectors(QString data);
void updateGradientColors(QString newName, QString oldName);
More information about the scribus-commit
mailing list