r15061 by fschmid - First version of "Symbol" items similar to Illustrator. Missing files in first committ.

scribus-commit scribus-commit at lists.scribus.net
Mon May 10 23:52:41 CEST 2010


Revision: 15061
Author: fschmid
Date: 2010-05-10T21:45:41.766262Z
Commit message: First version of "Symbol" items similar to Illustrator. Missing files in first committ.

Changeset: 
A  /trunk/Scribus/scribus/pageitem_symbol.cpp
A  /trunk/Scribus/scribus/ui/symbolpalette.cpp
A  /trunk/Scribus/scribus/pageitem_symbol.h
A  /trunk/Scribus/scribus/ui/symbolpalette.h

Diffs:
Index: scribus/pageitem_symbol.cpp
===================================================================
--- scribus/pageitem_symbol.cpp	(revision 0)
+++ scribus/pageitem_symbol.cpp	(revision 15061)
@@ -0,0 +1,205 @@
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+/***************************************************************************
+                          pageitem_symbol.cpp  -  description
+                             -------------------
+    begin                : Sat May 8 2010
+    copyright            : (C) 2010 by Franz Schmid
+    email                : Franz.Schmid at altmuehlnet.de
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include <cmath>
+#include <cassert>
+
+#include "commonstrings.h"
+#include "page.h"
+#include "pageitem.h"
+#include "pageitem_symbol.h"
+#include "prefsmanager.h"
+#include "scpainter.h"
+#include "scpaths.h"
+#include "scraction.h"
+#include "scribus.h"
+#include "scribusstructs.h"
+#include "scribusdoc.h"
+
+#include "undomanager.h"
+#include "undostate.h"
+#include "scconfig.h"
+
+#include "util.h"
+
+using namespace std;
+
+PageItem_Symbol::PageItem_Symbol(ScribusDoc *pa, double x, double y, double w, double h, double w2, QString fill, QString outline)
+	: PageItem(pa, PageItem::Symbol, x, y, w, h, 0, CommonStrings::None, CommonStrings::None)
+{
+}
+
+void PageItem_Symbol::DrawObj_Item(ScPainter *p, QRectF /*e*/)
+{
+	if (!m_Doc->RePos)
+	{
+		if ((!patternVal.isEmpty()) && (m_Doc->docPatterns.contains(patternVal)))
+		{
+			p->save();
+			if ((maskType() == 1) || (maskType() == 2) || (maskType() == 4) || (maskType() == 5))
+			{
+				if ((maskType() == 1) || (maskType() == 2))
+					p->setMaskMode(1);
+				else
+					p->setMaskMode(3);
+				if ((!gradientMask().isEmpty()) && (!m_Doc->docGradients.contains(gradientMask())))
+					gradientMaskVal = "";
+				if (!(gradientMask().isEmpty()) && (m_Doc->docGradients.contains(gradientMask())))
+					mask_gradient = m_Doc->docGradients[gradientMask()];
+				p->mask_gradient = mask_gradient;
+				if ((maskType() == 1) || (maskType() == 4))
+					p->setGradientMask(VGradient::linear, FPoint(GrMaskStartX, GrMaskStartY), FPoint(GrMaskEndX, GrMaskEndY), FPoint(GrMaskStartX, GrMaskStartY), GrMaskScale, GrMaskSkew);
+				else
+					p->setGradientMask(VGradient::radial, FPoint(GrMaskStartX, GrMaskStartY), FPoint(GrMaskEndX, GrMaskEndY), FPoint(GrMaskFocalX, GrMaskFocalY), GrMaskScale, GrMaskSkew);
+			}
+			else if ((maskType() == 3) || (maskType() == 6))
+			{
+				if ((patternMask().isEmpty()) || (!m_Doc->docPatterns.contains(patternMask())))
+					p->setMaskMode(0);
+				else
+				{
+					p->setPatternMask(&m_Doc->docPatterns[patternMask()], patternMaskScaleX, patternMaskScaleY, patternMaskOffsetX + xPos(), patternMaskOffsetY + yPos(), patternMaskRotation, patternMaskSkewX, patternMaskSkewY, patternMaskMirrorX, patternMaskMirrorY);
+					if (maskType() == 3)
+						p->setMaskMode(2);
+					else
+						p->setMaskMode(4);
+				}
+			}
+			else
+				p->setMaskMode(0);
+			p->beginLayer(1.0 - fillTransparency(), fillBlendmode(), &PoLine);
+			p->setMaskMode(0);
+			ScPattern pat = m_Doc->docPatterns[patternVal];
+			p->scale(Width / pat.width, Height / pat.height);
+			p->translate(pat.items.at(0)->gXpos, pat.items.at(0)->gYpos);
+			QStack<PageItem*> groupStack;
+			groupStack.clear();
+			for (int em = 0; em < pat.items.count(); ++em)
+			{
+				PageItem* embedded = pat.items.at(em);
+				if (embedded->isGroupControl)
+				{
+					p->save();
+					QTransform mm;
+					mm.translate(embedded->gXpos, embedded->gYpos);
+					mm.rotate(embedded->rotation());
+					if ((embedded->GrMask == 1) || (embedded->GrMask == 2) || (embedded->GrMask == 4) || (embedded->GrMask == 5))
+					{
+						if ((embedded->GrMask == 1) || (embedded->GrMask == 2))
+							p->setMaskMode(1);
+						else
+							p->setMaskMode(3);
+						if ((!embedded->gradientMaskVal.isEmpty()) && (!m_Doc->docGradients.contains(embedded->gradientMaskVal)))
+							embedded->gradientMaskVal = "";
+						if (!(embedded->gradientMaskVal.isEmpty()) && (m_Doc->docGradients.contains(embedded->gradientMaskVal)))
+							embedded->mask_gradient = m_Doc->docGradients[embedded->gradientMaskVal];
+						p->mask_gradient = embedded->mask_gradient;
+						if ((embedded->GrMask == 1) || (embedded->GrMask == 4))
+							p->setGradientMask(VGradient::linear, FPoint(embedded->GrMaskStartX, embedded->GrMaskStartY).transformPoint(mm, false), FPoint(embedded->GrMaskEndX, embedded->GrMaskEndY).transformPoint(mm, false), FPoint(embedded->GrMaskStartX, embedded->GrMaskStartY).transformPoint(mm, false), embedded->GrMaskScale, embedded->GrMaskSkew);
+						else
+							p->setGradientMask(VGradient::radial, FPoint(embedded->GrMaskStartX, embedded->GrMaskStartY).transformPoint(mm, false), FPoint(embedded->GrMaskEndX, embedded->GrMaskEndY).transformPoint(mm, false), FPoint(embedded->GrMaskFocalX, embedded->GrMaskFocalY).transformPoint(mm, false), embedded->GrMaskScale, embedded->GrMaskSkew);
+					}
+					else if ((embedded->GrMask == 3) || (embedded->GrMask == 6))
+					{
+						if ((embedded->patternMaskVal.isEmpty()) || (!m_Doc->docPatterns.contains(embedded->patternMaskVal)))
+							p->setMaskMode(0);
+						else
+						{
+							p->setPatternMask(&m_Doc->docPatterns[embedded->patternMask()], embedded->patternMaskScaleX, embedded->patternMaskScaleY, embedded->patternMaskOffsetX + embedded->xPos(), embedded->patternMaskOffsetY + embedded->yPos(), embedded->patternMaskRotation, embedded->patternMaskSkewX, embedded->patternMaskSkewY, embedded->patternMaskMirrorX, embedded->patternMaskMirrorY);
+							if (embedded->GrMask == 3)
+								p->setMaskMode(2);
+							else
+								p->setMaskMode(4);
+						}
+					}
+					else
+						p->setMaskMode(0);
+					FPointArray cl = embedded->PoLine.copy();
+					cl.map( mm );
+					p->beginLayer(1.0 - embedded->fillTransparency(), embedded->fillBlendmode(), &cl);
+					groupStack.push(embedded->groupsLastItem);
+					continue;
+				}
+				p->save();
+				p->translate(embedded->gXpos, embedded->gYpos);
+				embedded->isEmbedded = true;
+				embedded->invalid = true;
+				embedded->DrawObj(p, QRectF());
+				embedded->isEmbedded = false;
+				p->restore();
+				if (groupStack.count() != 0)
+				{
+					while (embedded == groupStack.top())
+					{
+						p->endLayer();
+						p->restore();
+						groupStack.pop();
+						if (groupStack.count() == 0)
+							break;
+					}
+				}
+			}
+			for (int em = 0; em < pat.items.count(); ++em)
+			{
+				PageItem* embedded = pat.items.at(em);
+				if (!embedded->isTableItem)
+					continue;
+				p->save();
+				p->translate(embedded->gXpos, embedded->gYpos);
+				p->rotate(embedded->rotation());
+				embedded->isEmbedded = true;
+				embedded->invalid = true;
+				if ((embedded->lineColor() != CommonStrings::None) && (embedded->lineWidth() != 0.0))
+				{
+					QColor tmp;
+					embedded->SetQColor(&tmp, embedded->lineColor(), embedded->lineShade());
+					if ((embedded->TopLine) || (embedded->RightLine) || (embedded->BottomLine) || (embedded->LeftLine))
+					{
+						p->setPen(tmp, embedded->lineWidth(), embedded->PLineArt, Qt::SquareCap, embedded->PLineJoin);
+						if (embedded->TopLine)
+							p->drawLine(FPoint(0.0, 0.0), FPoint(embedded->width(), 0.0));
+						if (embedded->RightLine)
+							p->drawLine(FPoint(embedded->width(), 0.0), FPoint(embedded->width(), embedded->height()));
+						if (embedded->BottomLine)
+							p->drawLine(FPoint(embedded->width(), embedded->height()), FPoint(0.0, embedded->height()));
+						if (embedded->LeftLine)
+							p->drawLine(FPoint(0.0, embedded->height()), FPoint(0.0, 0.0));
+					}
+				}
+				embedded->isEmbedded = false;
+				p->restore();
+			}
+			p->endLayer();
+			p->restore();
+		}
+	}
+}
+
+void PageItem_Symbol::applicableActions(QStringList & actionList)
+{
+}
+
+QString PageItem_Symbol::infoDescription()
+{
+	return QString();
+}
Index: scribus/pageitem_symbol.h
===================================================================
--- scribus/pageitem_symbol.h	(revision 0)
+++ scribus/pageitem_symbol.h	(revision 15061)
@@ -0,0 +1,54 @@
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+/***************************************************************************
+                          pageitem_symbol.h  -  description
+                             -------------------
+    copyright            : Scribus Team
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef PAGEITEM_SYMBOL_H
+#define PAGEITEM_SYMBOL_H
+
+#include <QString>
+#include <QRectF>
+
+#include "scribusapi.h"
+#include "pageitem.h"
+class ScPainter;
+class ScribusDoc;
+
+
+class SCRIBUS_API PageItem_Symbol : public PageItem
+{
+	Q_OBJECT
+
+public:
+	PageItem_Symbol(ScribusDoc *pa, double x, double y, double w, double h, double w2, QString fill, QString outline);
+	PageItem_Symbol(const PageItem & p) : PageItem(p) {}
+	~PageItem_Symbol() {};
+
+	virtual PageItem_Symbol * asSymbolFrame() { return this; }
+	virtual bool isSymbol() const { return true; }
+	virtual ItemType realItemType() const { return PageItem::Symbol; }
+	virtual void applicableActions(QStringList& actionList);
+	virtual QString infoDescription();
+	
+protected:
+	virtual void DrawObj_Item(ScPainter *p, QRectF e);
+
+};
+
+#endif 
Index: scribus/ui/symbolpalette.cpp
===================================================================
--- scribus/ui/symbolpalette.cpp	(revision 0)
+++ scribus/ui/symbolpalette.cpp	(revision 15061)
@@ -0,0 +1,162 @@
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+/***************************************************************************
+                          symbolpalette.cpp  -  description
+                             -------------------
+    begin                : Sat May 8 2010
+    copyright            : (C) 2010 by Franz Schmid
+    email                : Franz.Schmid at altmuehlnet.de
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+#include "symbolpalette.h"
+#include <QPainter>
+#include <QByteArray>
+#include "scpattern.h"
+#include "scribusdoc.h"
+#include "scribus.h"
+
+SymbolView::SymbolView(QWidget* parent) : QListWidget(parent)
+{
+	setDragEnabled(true);
+	setViewMode(QListView::IconMode);
+	setFlow(QListView::LeftToRight);
+	setSortingEnabled(true);
+	setWrapping(true);
+	setAcceptDrops(true);
+	setDropIndicatorShown(true);
+	setDragDropMode(QAbstractItemView::DragDrop);
+	setResizeMode(QListView::Adjust);
+	setSelectionMode(QAbstractItemView::SingleSelection);
+	setContextMenuPolicy(Qt::CustomContextMenu);
+	setIconSize(QSize(48, 48));
+}
+
+void SymbolView::dragEnterEvent(QDragEnterEvent *e)
+{
+	if (e->source() == this)
+		e->ignore();
+	else
+		e->acceptProposedAction();
+}
+
+void SymbolView::dragMoveEvent(QDragMoveEvent *e)
+{
+	if (e->source() == this)
+		e->ignore();
+	else
+		e->acceptProposedAction();
+}
+
+void SymbolView::dropEvent(QDropEvent *e)
+{
+	if (e->mimeData()->hasText())
+	{
+		e->acceptProposedAction();
+		if (e->source() == this)
+			return;
+	}
+	else
+		e->ignore();
+}
+
+ void SymbolView::startDrag(Qt::DropActions supportedActions)
+ {
+	QMimeData *mimeData = new QMimeData;
+	QByteArray data = currentItem()->text().toLocal8Bit();
+	mimeData->setData("text/symbol", data);
+	QDrag *drag = new QDrag(this);
+	drag->setMimeData(mimeData);
+	drag->setPixmap(currentItem()->icon().pixmap(48, 48));
+//	drag->setDragCursor(currentItem()->icon().pixmap(48, 48), Qt::CopyAction);
+	drag->exec(Qt::CopyAction);
+	clearSelection();
+}
+
+SymbolPalette::SymbolPalette( QWidget* parent) : ScrPaletteBase( parent, "Symb", false, 0 )
+{
+	setMinimumSize( QSize( 220, 240 ) );
+	setMaximumSize( QSize( 800, 600 ) );
+	SymbolViewWidget = new SymbolView(this);
+	SymbolViewWidget->clear();
+
+	QVBoxLayout* PaletteLayout = new QVBoxLayout;
+	PaletteLayout->addWidget(SymbolViewWidget);
+	setLayout( PaletteLayout );
+
+	unsetDoc();
+	m_scMW  = NULL;
+	languageChange();
+}
+
+void SymbolPalette::setMainWindow(ScribusMainWindow *mw)
+{
+	m_scMW = mw;
+	if (m_scMW == NULL)
+		SymbolViewWidget->clear();
+}
+
+void SymbolPalette::setDoc(ScribusDoc *newDoc)
+{
+	if (m_scMW == NULL)
+		currDoc = NULL;
+	else
+		currDoc = newDoc;
+	if (currDoc == NULL)
+		SymbolViewWidget->clear();
+	else
+		updateSymbolList();
+}
+
+void SymbolPalette::unsetDoc()
+{
+	currDoc = NULL;
+	SymbolViewWidget->clear();
+}
+
+void SymbolPalette::updateSymbolList()
+{
+	SymbolViewWidget->clear();
+	SymbolViewWidget->setWordWrap(true);
+	for (QMap<QString, ScPattern>::Iterator it = currDoc->docPatterns.begin(); it != currDoc->docPatterns.end(); ++it)
+	{
+		QPixmap pm;
+		if (it.value().getPattern()->width() >= it.value().getPattern()->height())
+			pm = QPixmap::fromImage(it.value().getPattern()->scaledToWidth(48, Qt::SmoothTransformation));
+		else
+			pm = QPixmap::fromImage(it.value().getPattern()->scaledToHeight(48, Qt::SmoothTransformation));
+		QPixmap pm2(48, 48);
+		pm2.fill(palette().color(QPalette::Base));
+		QPainter p;
+		p.begin(&pm2);
+		p.drawPixmap(24 - pm.width() / 2, 24 - pm.height() / 2, pm);
+		p.end();
+		new QListWidgetItem(pm2, it.key(), SymbolViewWidget);
+	}
+}
+
+void SymbolPalette::changeEvent(QEvent *e)
+{
+	if (e->type() == QEvent::LanguageChange)
+	{
+		languageChange();
+	}
+	else
+		QWidget::changeEvent(e);
+}
+
+void SymbolPalette::languageChange()
+{
+	setWindowTitle( tr( "Symbols" ) );
+}
Index: scribus/ui/symbolpalette.h
===================================================================
--- scribus/ui/symbolpalette.h	(revision 0)
+++ scribus/ui/symbolpalette.h	(revision 15061)
@@ -0,0 +1,84 @@
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+/***************************************************************************
+                          symbolpalette.h  -  description
+                             -------------------
+    copyright            : Scribus Team
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef SYMBOLPAL_H
+#define SYMBOLPAL_H
+
+#include <QDragEnterEvent>
+#include <QDragLeaveEvent>
+#include <QDragMoveEvent>
+#include <QDropEvent>
+#include <QImage>
+#include <QListWidget>
+#include <QMouseEvent>
+#include <QPixmap>
+#include <QToolTip>
+#include <QVBoxLayout>
+
+
+class QEvent;
+class ScribusMainWindow;
+class ScribusDoc;
+
+
+#include "scribusapi.h"
+#include "scrpalettebase.h"
+
+class SCRIBUS_API SymbolView : public QListWidget
+{
+	Q_OBJECT
+
+public:
+	SymbolView( QWidget* parent);
+	~SymbolView() {};
+
+protected:
+	void dragEnterEvent(QDragEnterEvent *e);
+	void dragMoveEvent(QDragMoveEvent *e);
+	void dropEvent(QDropEvent *e);
+	void startDrag(Qt::DropActions supportedActions);
+};
+
+class SCRIBUS_API SymbolPalette : public ScrPaletteBase
+{
+	Q_OBJECT
+
+public:
+	SymbolPalette(QWidget* parent);
+	~SymbolPalette() {};
+	void setMainWindow(ScribusMainWindow *mw);
+	void setDoc(ScribusDoc *);
+	void unsetDoc();
+	void updateSymbolList();
+	
+	virtual void changeEvent(QEvent *e);
+
+public slots:
+	void languageChange();
+
+protected:
+	SymbolView *SymbolViewWidget;
+	QVBoxLayout* PaletteLayout;
+	ScribusDoc *currDoc;
+	ScribusMainWindow *m_scMW;
+};
+
+#endif
\ No newline at end of file




More information about the scribus-commit mailing list