r15662 by fschmid - Fixed Bug #612: "the order of the colors", you can sort now by right-clicking onto the colorlist.

scribus-commit scribus-commit at lists.scribus.net
Wed Oct 27 21:08:28 CEST 2010


Author: fschmid
Date: Wed Oct 27 19:08:28 2010
New Revision: 15662

URL: http://scribus.info/websvn/listing.php?repname=Scribus&sc=1&rev=15662
Log:
Fixed Bug #612: "the order of the colors", you can sort now by right-clicking onto the colorlist.

Modified:
    trunk/Scribus/scribus/ui/colorlistbox.cpp
    trunk/Scribus/scribus/ui/colorlistbox.h
    trunk/Scribus/scribus/ui/paintmanager.cpp
    trunk/Scribus/scribus/ui/paintmanager.h

Modified: trunk/Scribus/scribus/ui/colorlistbox.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15662&path=/trunk/Scribus/scribus/ui/colorlistbox.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/colorlistbox.cpp (original)
+++ trunk/Scribus/scribus/ui/colorlistbox.cpp Wed Oct 27 19:08:28 2010
@@ -12,6 +12,8 @@
 #include <QToolTip>
 #include <QEvent>
 #include <QHelpEvent>
+#include <QMenu>
+#include <QCursor>
 
 #include "commonstrings.h"
 #include "sccolorengine.h"
@@ -190,7 +192,9 @@
 	: QListWidget(parent)
 {
 	cList = NULL;
+	sortRule = 0;
 	setItemDelegate(new ColorWideItemDelegate());
+	connect(this, SIGNAL(showContextMenue()), this, SLOT(slotRightClick()));
 }
 
 
@@ -202,17 +206,58 @@
 		return CommonStrings::tr_NoneColor;
 }
 
+void ColorListBox::slotRightClick()
+{
+	blockSignals(true);
+	QString currentSel = QString();
+	QListWidgetItem* itc = currentItem();
+	if (itc)
+		currentSel = itc->text();
+	QListWidgetItem* it = item(0);
+	if (it)
+	{
+		QString first = QString();
+		QMenu *pmen = new QMenu();
+		qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+		pmen->addAction( tr("Sort by Name"));
+		pmen->addAction( tr("Sort by Color"));
+		pmen->addAction( tr("Sort by Type"));
+		sortRule = pmen->actions().indexOf(pmen->exec(QCursor::pos()));
+		delete pmen;
+		if (it->text() == CommonStrings::None || it->text() == CommonStrings::tr_NoneColor)
+			first = it->text();
+		clear();
+		reset();
+		if (!first.isEmpty())
+			addItem(first);
+		if (m_type == ColorListBox::fancyPixmap)
+			insertFancyPixmapItems( *cList );
+		else if (m_type == ColorListBox::widePixmap)
+			insertWidePixmapItems( *cList );
+		else if (m_type == ColorListBox::smallPixmap)
+			insertSmallPixmapItems( *cList );
+		if (!currentSel.isEmpty())
+		{
+			QList<QListWidgetItem *> items = findItems(currentSel, Qt::MatchExactly);
+			if (items.count() > 0)
+				setCurrentItem(items[0]);
+		}
+	}
+	blockSignals(false);
+}
 
 void ColorListBox::updateBox(ColorList& list, ColorListBox::PixmapType type)
 {
 	clear();
 	reset();
+	m_type = type;
 	insertItems(list, type);
 }
 
 void ColorListBox::insertItems(ColorList& list, ColorListBox::PixmapType type)
 {
 	cList = &list;
+	m_type = type;
 	if (type == ColorListBox::fancyPixmap)
 		insertFancyPixmapItems( list );
 	else if (type == ColorListBox::widePixmap)
@@ -248,11 +293,46 @@
 {
 	ColorList::Iterator it;
 	ScribusDoc* doc = list.document();
-	for (it = list.begin(); it != list.end(); ++it)
-	{
-		if (it.key() == CommonStrings::None || it.key() == CommonStrings::tr_NoneColor)
-			continue;
-		addItem( new ColorPixmapItem(it.value(), doc, it.key()) );
+	if (sortRule > 0)
+	{
+		QMap<QString, QString> sortMap;
+		for (it = list.begin(); it != list.end(); ++it)
+		{
+			if (it.key() == CommonStrings::None || it.key() == CommonStrings::tr_NoneColor)
+				continue;
+			if (sortRule == 1)
+			{
+				QColor c = it.value().getRawRGBColor();
+				QString sortString = QString("%1-%2-%3-%4").arg(c.hue(), 3, 10, QChar('0')).arg(c.saturation(), 3, 10, QChar('0')).arg(c.value(), 3, 10, QChar('0')).arg(it.key());
+				sortMap.insert(sortString, it.key());
+			}
+			else if (sortRule == 2)
+			{
+				QString sortString = QString("%1-%2");
+				if (it.value().isRegistrationColor())
+					sortMap.insert(sortString.arg("A").arg(it.key()), it.key());
+				else if (it.value().isSpotColor())
+					sortMap.insert(sortString.arg("B").arg(it.key()), it.key());
+				else if (it.value().getColorModel() == colorModelCMYK)
+					sortMap.insert(sortString.arg("C").arg(it.key()), it.key());
+				else
+					sortMap.insert(sortString.arg("D").arg(it.key()), it.key());
+			}
+		}
+		QMap<QString, QString>::Iterator itc;
+		for (itc = sortMap.begin(); itc != sortMap.end(); ++itc)
+		{
+			addItem( new ColorPixmapItem(list[itc.value()], doc, itc.value()) );
+		}
+	}
+	else
+	{
+		for (it = list.begin(); it != list.end(); ++it)
+		{
+			if (it.key() == CommonStrings::None || it.key() == CommonStrings::tr_NoneColor)
+				continue;
+			addItem( new ColorPixmapItem(it.value(), doc, it.key()) );
+		}
 	}
 	if (itemDelegate())
 		delete itemDelegate();
@@ -263,11 +343,46 @@
 {
 	ColorList::Iterator it;
 	ScribusDoc* doc = list.document();
-	for (it = list.begin(); it != list.end(); ++it)
-	{
-		if (it.key() == CommonStrings::None || it.key() == CommonStrings::tr_NoneColor)
-			continue;
-		addItem( new ColorPixmapItem(it.value(), doc, it.key()) );
+	if (sortRule > 0)
+	{
+		QMap<QString, QString> sortMap;
+		for (it = list.begin(); it != list.end(); ++it)
+		{
+			if (it.key() == CommonStrings::None || it.key() == CommonStrings::tr_NoneColor)
+				continue;
+			if (sortRule == 1)
+			{
+				QColor c = it.value().getRawRGBColor();
+				QString sortString = QString("%1-%2-%3-%4").arg(c.hue(), 3, 10, QChar('0')).arg(c.saturation(), 3, 10, QChar('0')).arg(c.value(), 3, 10, QChar('0')).arg(it.key());
+				sortMap.insert(sortString, it.key());
+			}
+			else if (sortRule == 2)
+			{
+				QString sortString = QString("%1-%2");
+				if (it.value().isRegistrationColor())
+					sortMap.insert(sortString.arg("A").arg(it.key()), it.key());
+				else if (it.value().isSpotColor())
+					sortMap.insert(sortString.arg("B").arg(it.key()), it.key());
+				else if (it.value().getColorModel() == colorModelCMYK)
+					sortMap.insert(sortString.arg("C").arg(it.key()), it.key());
+				else
+					sortMap.insert(sortString.arg("D").arg(it.key()), it.key());
+			}
+		}
+		QMap<QString, QString>::Iterator itc;
+		for (itc = sortMap.begin(); itc != sortMap.end(); ++itc)
+		{
+			addItem( new ColorPixmapItem(list[itc.value()], doc, itc.value()) );
+		}
+	}
+	else
+	{
+		for (it = list.begin(); it != list.end(); ++it)
+		{
+			if (it.key() == CommonStrings::None || it.key() == CommonStrings::tr_NoneColor)
+				continue;
+			addItem( new ColorPixmapItem(it.value(), doc, it.key()) );
+		}
 	}
 	if (itemDelegate())
 		delete itemDelegate();
@@ -278,18 +393,53 @@
 {
 	ColorList::Iterator it;
 	ScribusDoc* doc = list.document();
-	for (it = list.begin(); it != list.end(); ++it)
-	{
-		if (it.key() == CommonStrings::None || it.key() == CommonStrings::tr_NoneColor)
-			continue;
-		addItem( new ColorPixmapItem(it.value(), doc, it.key()) );
+	if (sortRule > 0)
+	{
+		QMap<QString, QString> sortMap;
+		for (it = list.begin(); it != list.end(); ++it)
+		{
+			if (it.key() == CommonStrings::None || it.key() == CommonStrings::tr_NoneColor)
+				continue;
+			if (sortRule == 1)
+			{
+				QColor c = it.value().getRawRGBColor();
+				QString sortString = QString("%1-%2-%3-%4").arg(c.hue(), 3, 10, QChar('0')).arg(c.saturation(), 3, 10, QChar('0')).arg(c.value(), 3, 10, QChar('0')).arg(it.key());
+				sortMap.insert(sortString, it.key());
+			}
+			else if (sortRule == 2)
+			{
+				QString sortString = QString("%1-%2");
+				if (it.value().isRegistrationColor())
+					sortMap.insert(sortString.arg("A").arg(it.key()), it.key());
+				else if (it.value().isSpotColor())
+					sortMap.insert(sortString.arg("B").arg(it.key()), it.key());
+				else if (it.value().getColorModel() == colorModelCMYK)
+					sortMap.insert(sortString.arg("C").arg(it.key()), it.key());
+				else
+					sortMap.insert(sortString.arg("D").arg(it.key()), it.key());
+			}
+		}
+		QMap<QString, QString>::Iterator itc;
+		for (itc = sortMap.begin(); itc != sortMap.end(); ++itc)
+		{
+			addItem( new ColorPixmapItem(list[itc.value()], doc, itc.value()) );
+		}
+	}
+	else
+	{
+		for (it = list.begin(); it != list.end(); ++it)
+		{
+			if (it.key() == CommonStrings::None || it.key() == CommonStrings::tr_NoneColor)
+				continue;
+			addItem( new ColorPixmapItem(it.value(), doc, it.key()) );
+		}
 	}
 	if (itemDelegate())
 		delete itemDelegate();
 	setItemDelegate(new ColorFancyItemDelegate());
 }
 
-bool ColorListBox::event(QEvent *event)
+bool ColorListBox::viewportEvent(QEvent *event)
 {
 	if (event->type() == QEvent::ToolTip)
 	{
@@ -322,5 +472,20 @@
 			}
 		}
 	}
-	return QListWidget::event(event);
-}
+	else if (event->type() == QEvent::MouseButtonPress)
+	{
+		QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
+		if (mouseEvent->button() == Qt::RightButton)
+			return true;
+	}
+	else if (event->type() == QEvent::MouseButtonRelease)
+	{
+		QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
+		if (mouseEvent->button() == Qt::RightButton)
+		{
+			emit showContextMenue();
+			return true;
+		}
+	}
+	return QListWidget::viewportEvent(event);
+}

Modified: trunk/Scribus/scribus/ui/colorlistbox.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15662&path=/trunk/Scribus/scribus/ui/colorlistbox.h
==============================================================================
--- trunk/Scribus/scribus/ui/colorlistbox.h (original)
+++ trunk/Scribus/scribus/ui/colorlistbox.h Wed Oct 27 19:08:28 2010
@@ -81,12 +81,12 @@
 		Just there are initialized pixmaps for icon drawing. */
 		ColorListBox(QWidget * parent = 0);
 
-		QString currentColor() const; 
+		QString currentColor() const;
 
 		/*! \brief Fill the list box with values taken from list.
 		The list is cleared itself. Then is rendered an icon with
 		color attributes (RGB/CMYK/Spot etc.).
-		\param list a ColorList to present. 
+		\param list a ColorList to present.
 		\param the pixmap type to use */
 		void updateBox(ColorList& list, ColorListBox::PixmapType type);
 
@@ -114,10 +114,15 @@
 				
 		/*! \brief Pointer to the color list displayed by this box */
 		ColorList *cList;
-protected:
-		bool event(QEvent *event);
-		
+	private slots:
+		void slotRightClick();
+	signals:
+		void showContextMenue();
+	protected:
+		bool viewportEvent(QEvent *event);
+		int sortRule;
 		int m_selectedRow;
+		ColorListBox::PixmapType m_type;
 };
 
 #endif

Modified: trunk/Scribus/scribus/ui/paintmanager.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15662&path=/trunk/Scribus/scribus/ui/paintmanager.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/paintmanager.cpp (original)
+++ trunk/Scribus/scribus/ui/paintmanager.cpp Wed Oct 27 19:08:28 2010
@@ -28,6 +28,8 @@
 #include <QCheckBox>
 #include <QMessageBox>
 #include <QDomDocument>
+#include <QMenu>
+#include <QCursor>
 #include "cmykfw.h"
 #include "colorlistbox.h"
 #include "commonstrings.h"
@@ -51,16 +53,19 @@
 #include "util_color.h"
 #include "util_formats.h"
 #include "util_icon.h"
+#include <QDebug>
 
 PaintManagerDialog::PaintManagerDialog(QWidget* parent, QMap<QString, VGradient> *docGradients, ColorList doco, QString docColSet, QStringList custColSet, ScribusDoc *doc, ScribusMainWindow *scMW) : QDialog(parent)
 {
 	setupUi(this);
 	setModal(true);
 	paletteLocked = false;
+	sortRule = 0;
 	m_doc = doc;
 	m_colorList = doco;
 	mainWin = scMW;
 	setWindowIcon(QIcon(loadIcon ( "AppIcon.png" )));
+	dataTree->setContextMenuPolicy(Qt::CustomContextMenu);
 	dataTree->setIconSize(QSize(60, 15));
 	colorItems = new QTreeWidgetItem(dataTree);
 	colorItems->setText(0, tr("Solid Colors"));
@@ -117,6 +122,7 @@
 	connect(dataTree, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(itemSelected(QTreeWidgetItem*)));
 	connect(dataTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(selEditColor(QTreeWidgetItem*)));
 	connect(dataTree, SIGNAL(itemSelectionChanged()), this, SLOT(itemSelectionChanged()));
+	connect(dataTree, SIGNAL(customContextMenuRequested (const QPoint &)), this, SLOT(slotRightClick(QPoint)));
 	connect(newButton, SIGNAL(clicked()), this, SLOT(createNew()));
 	connect(editButton, SIGNAL(clicked()), this, SLOT(editColorItem()));
 	connect(duplicateButton, SIGNAL(clicked()), this, SLOT(duplicateColorItem()));
@@ -174,18 +180,77 @@
 		delete lg[a];
 	}
 	QTreeWidgetItem* ret = 0;
-	ColorList::Iterator it;
-	for (it = m_colorList.begin(); it != m_colorList.end(); ++it)
-	{
-		QTreeWidgetItem *item = new QTreeWidgetItem(colorItems);
-		item->setText(0, it.key());
-		if (it.key() == addedName)
-			ret = item;
-		QPixmap* pPixmap = getFancyPixmap(it.value(), m_doc);
-		item->setIcon(0, *pPixmap);
-		item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
+	if (sortRule > 0)
+	{
+		QMap<QString, QString> sortMap;
+		ColorList::Iterator it;
+		for (it = m_colorList.begin(); it != m_colorList.end(); ++it)
+		{
+			if (sortRule == 1)
+			{
+				QColor c = it.value().getRawRGBColor();
+				QString sortString = QString("%1-%2-%3-%4").arg(c.hue(), 3, 10, QChar('0')).arg(c.saturation(), 3, 10, QChar('0')).arg(c.value(), 3, 10, QChar('0')).arg(it.key());
+				sortMap.insert(sortString, it.key());
+			}
+			else if (sortRule == 2)
+			{
+				QString sortString = QString("%1-%2");
+				if (it.value().isRegistrationColor())
+					sortMap.insert(sortString.arg("A").arg(it.key()), it.key());
+				else if (it.value().isSpotColor())
+					sortMap.insert(sortString.arg("B").arg(it.key()), it.key());
+				else if (it.value().getColorModel() == colorModelCMYK)
+					sortMap.insert(sortString.arg("C").arg(it.key()), it.key());
+				else
+					sortMap.insert(sortString.arg("D").arg(it.key()), it.key());
+			}
+		}
+		QMap<QString, QString>::Iterator itc;
+		for (itc = sortMap.begin(); itc != sortMap.end(); ++itc)
+		{
+			QTreeWidgetItem *item = new QTreeWidgetItem(colorItems);
+			item->setText(0, itc.value());
+			if (itc.value() == addedName)
+				ret = item;
+			QPixmap* pPixmap = getFancyPixmap(m_colorList[itc.value()], m_doc);
+			item->setIcon(0, *pPixmap);
+			item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
+		}
+	}
+	else
+	{
+		ColorList::Iterator it;
+		for (it = m_colorList.begin(); it != m_colorList.end(); ++it)
+		{
+			QTreeWidgetItem *item = new QTreeWidgetItem(colorItems);
+			item->setText(0, it.key());
+			if (it.key() == addedName)
+				ret = item;
+			QPixmap* pPixmap = getFancyPixmap(it.value(), m_doc);
+			item->setIcon(0, *pPixmap);
+			item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
+		}
 	}
 	return ret;
+}
+
+void PaintManagerDialog::slotRightClick(QPoint p)
+{
+	QTreeWidgetItem* it = dataTree->itemAt(p);
+	if (it)
+	{
+		if ((it->parent() == colorItems) || (it == colorItems))
+		{
+			QMenu *pmen = new QMenu();
+			qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+			pmen->addAction( tr("Sort by Name"));
+			pmen->addAction( tr("Sort by Color"));
+			pmen->addAction( tr("Sort by Type"));
+			sortRule = pmen->actions().indexOf(pmen->exec(QCursor::pos()));
+			delete pmen;
+			updateColorList();
+		}
+	}
 }
 
 void PaintManagerDialog::selEditColor(QTreeWidgetItem *it)

Modified: trunk/Scribus/scribus/ui/paintmanager.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15662&path=/trunk/Scribus/scribus/ui/paintmanager.h
==============================================================================
--- trunk/Scribus/scribus/ui/paintmanager.h (original)
+++ trunk/Scribus/scribus/ui/paintmanager.h Wed Oct 27 19:08:28 2010
@@ -63,6 +63,7 @@
 		QStringList customColSet;
 		bool hasImportedColors;
 	private slots:
+		void slotRightClick(QPoint p);
 		void selEditColor(QTreeWidgetItem *it);
 		void itemSelectionChanged();
 		void itemSelected(QTreeWidgetItem* it);
@@ -84,6 +85,7 @@
 		void loadScribusFormat(QString fileName);
 		ColorSetManager csm;
 		bool paletteLocked;
+		int sortRule;
 		QTreeWidgetItem *colorItems;
 		QTreeWidgetItem *gradientItems;
 		QTreeWidgetItem *systemSwatches;




More information about the scribus-commit mailing list