[fondue-commits] [SCM] Fondue Font Editor branch, master, updated. b1caf07308702e22ef91a8a2a35791cb17878b87

Eugeniy Meshcheryakov eugen at debian.org
Thu Aug 23 18:37:43 UTC 2007


The branch, master has been updated
       via  b1caf07308702e22ef91a8a2a35791cb17878b87 (commit)
       via  dab32b1e2e7d40ed2e4483b1d0a535624b0fed73 (commit)
       via  80f55272a26041310d8032e865a2f286dc3f45c2 (commit)
       via  364439ebb8550aeae119ecf97e07c0eaf26e2109 (commit)
       via  9e01d7e05aed8286e566ddd7a9b761ffd59da42b (commit)
       via  05d35efc2e55663d8a36ba05bfe411bce7c781a3 (commit)
       via  1d032fba6874d73a9394987e2a6a116b569b19b9 (commit)
       via  aea609df31993ec5462937cf1deed3aa7a0e8462 (commit)
       via  19693c5fbc6c2b490b62f1c89219ac4a30d2725c (commit)
       via  4eb78fabf3ca83b4e611748ab1ea366c3cc152b9 (commit)
      from  44d05812243572a0021db9dbc00bcbf63b397a77 (commit)


- Log -----------------------------------------------------------------
commit b1caf07308702e22ef91a8a2a35791cb17878b87
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Thu Aug 23 20:37:34 2007 +0200

    make cvt model editable

commit dab32b1e2e7d40ed2e4483b1d0a535624b0fed73
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Thu Aug 23 20:37:09 2007 +0200

    add setter functions

commit 80f55272a26041310d8032e865a2f286dc3f45c2
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Thu Aug 23 20:23:55 2007 +0200

    add operator ==

commit 364439ebb8550aeae119ecf97e07c0eaf26e2109
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Thu Aug 23 20:09:23 2007 +0200

    add "Edit cvt Table..." menu

commit 9e01d7e05aed8286e566ddd7a9b761ffd59da42b
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Thu Aug 23 20:02:57 2007 +0200

    swap rowCount <-> columnCount()

commit 05d35efc2e55663d8a36ba05bfe411bce7c781a3
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Thu Aug 23 19:54:33 2007 +0200

    add a CVT editor dialog

commit 1d032fba6874d73a9394987e2a6a116b569b19b9
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Thu Aug 23 19:42:57 2007 +0200

    create CVT model on document open

commit aea609df31993ec5462937cf1deed3aa7a0e8462
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Thu Aug 23 19:40:31 2007 +0200

    add model for CVT

commit 19693c5fbc6c2b490b62f1c89219ac4a30d2725c
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Thu Aug 23 19:39:44 2007 +0200

    move models initialization into separate function

commit 4eb78fabf3ca83b4e611748ab1ea366c3cc152b9
Author: Eugeniy Meshcheryakov <eugen at debian.org>
Date:   Thu Aug 23 15:44:08 2007 +0200

    add an about box

-----------------------------------------------------------------------

Summary of changes:
 src/ufondue.cxx => gui/cvteditor.cxx    |   33 +++++----
 ruby/ascii85.h => gui/cvteditor.h       |   14 +++--
 gui/gui.rules                           |    6 +-
 gui/mainwindow.cxx                      |   37 ++++++++--
 gui/mainwindow.h                        |    5 ++
 nongui/cvtentry.h                       |    6 ++
 nongui/cvtmodel.cxx                     |  119 +++++++++++++++++++++++++++++++
 gui/controlpoint.h => nongui/cvtmodel.h |   33 ++++-----
 nongui/fontdocument.cxx                 |    9 +++
 nongui/fontdocument.h                   |    1 +
 nongui/nongui.rules                     |    6 +-
 11 files changed, 220 insertions(+), 49 deletions(-)
 copy src/ufondue.cxx => gui/cvteditor.cxx (64%)
 copy ruby/ascii85.h => gui/cvteditor.h (81%)
 create mode 100644 nongui/cvtmodel.cxx
 copy gui/controlpoint.h => nongui/cvtmodel.h (53%)

diff --git a/src/ufondue.cxx b/gui/cvteditor.cxx
similarity index 64%
copy from src/ufondue.cxx
copy to gui/cvteditor.cxx
index c2c9a04..34819a6 100644
--- a/src/ufondue.cxx
+++ b/gui/cvteditor.cxx
@@ -14,23 +14,24 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
-#include <QCoreApplication>
-#include <ruby.h>
+#include "cvteditor.h"
+#include <QHBoxLayout>
+#include <QTableView>
 
-#include "ruby_bindings.h"
-
-int main(int argc, char **argv)
+CVTEditor::CVTEditor(class QAbstractItemModel *model, QWidget *parent) : QDialog(parent)
 {
-	QCoreApplication app(argc, argv);
-	int state;
+	Q_ASSERT(model);
 
-	RUBY_INIT_STACK;
-	ruby_init();
-	ruby_init_loadpath();
-	addRubyBindings();
-	ruby_script("conv");
-	rb_load_protect(rb_str_new2("conv.rb"), 0, &state);
-	ruby_cleanup(state);
-	return 0;
-}
+	setAttribute(Qt::WA_DeleteOnClose);
+
+	Qt::WindowFlags flags = windowFlags();
+	setWindowFlags(flags & ~Qt::Dialog | Qt::Window);
 
+	QHBoxLayout *hbox = new QHBoxLayout;
+
+	QTableView *table = new QTableView;
+	table->setModel(model);
+	hbox->addWidget(table);
+
+	setLayout(hbox);
+}
diff --git a/ruby/ascii85.h b/gui/cvteditor.h
similarity index 81%
copy from ruby/ascii85.h
copy to gui/cvteditor.h
index abd58fb..0f300b1 100644
--- a/ruby/ascii85.h
+++ b/gui/cvteditor.h
@@ -14,12 +14,16 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
-#ifndef ASCII85_H
-#define ASCII85_H
+#ifndef CVTEDITOR_H
+#define CVTEDITOR_H
+#include <QDialog>
 
-#include <QByteArray>
-#include <QDataStream>
+class QAbstractItemModel;
 
-QByteArray decodeAscii85(QDataStream &buf, int data_size);
+class CVTEditor : public QDialog
+{
+public:
+	CVTEditor(QAbstractItemModel *model, QWidget *parent = 0);
+};
 
 #endif
diff --git a/gui/gui.rules b/gui/gui.rules
index 091e9e5..0983bb1 100644
--- a/gui/gui.rules
+++ b/gui/gui.rules
@@ -15,7 +15,8 @@ libfonduegui_a_SOURCES =		\
 	gui/glyphpropertieseditor.cxx	\
 	gui/colorcombobox.cxx		\
 	gui/unicodevalueeditor.cxx	\
-	gui/unicodeproxymodel.cxx
+	gui/unicodeproxymodel.cxx	\
+	gui/cvteditor.cxx
 
 nodist_libfonduegui_a_SOURCES =			\
 	gui/ttihighlighter.moc.cxx		\
@@ -52,7 +53,8 @@ noinst_HEADERS += 			\
 	gui/glyphpropertieseditor.h	\
 	gui/unicodevalueeditor.h	\
 	gui/colorcombobox.h		\
-	gui/unicodeproxymodel.h
+	gui/unicodeproxymodel.h		\
+	gui/cvteditor.h
 
 CLEANFILES += gui/*.moc.cxx gui/*.tbl.cxx
 EXTRA_DIST += gui/instnames.xsl
diff --git a/gui/mainwindow.cxx b/gui/mainwindow.cxx
index 3478155..940beed 100644
--- a/gui/mainwindow.cxx
+++ b/gui/mainwindow.cxx
@@ -32,6 +32,10 @@
 #include "glyphsmodel.h"
 #include <QSettings>
 #include "unicodeproxymodel.h"
+#include "cvtmodel.h"
+#include "cvteditor.h"
+
+#include "config.h"
 
 MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
 	model(0), unicodeProxy(0)
@@ -90,6 +94,9 @@ void MainWindow::createActions()
 	editFpgmAction = new QAction("Edit fpgm Table...", this);
 	connect(editFpgmAction, SIGNAL(triggered()), this, SLOT(editFpgm()));
 
+	editCvtAction = new QAction("Edit cvt Table...", this);
+	connect(editCvtAction, SIGNAL(triggered()), this, SLOT(editCvt()));
+
 	aboutAction = new QAction("About Fondue...", this);
 	connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
 
@@ -97,11 +104,13 @@ void MainWindow::createActions()
 	saveAsAction->setEnabled(false);
 	editPrepAction->setEnabled(false);
 	editFpgmAction->setEnabled(false);
+	editCvtAction->setEnabled(false);
 
 	connect(this, SIGNAL(documentAvailable(bool)), saveAction, SLOT(setEnabled(bool)));
 	connect(this, SIGNAL(documentAvailable(bool)), saveAsAction, SLOT(setEnabled(bool)));
 	connect(this, SIGNAL(documentAvailable(bool)), editPrepAction, SLOT(setEnabled(bool)));
 	connect(this, SIGNAL(documentAvailable(bool)), editFpgmAction, SLOT(setEnabled(bool)));
+	connect(this, SIGNAL(documentAvailable(bool)), editCvtAction, SLOT(setEnabled(bool)));
 }
 
 void MainWindow::createMenus()
@@ -122,6 +131,7 @@ void MainWindow::createMenus()
 	instructionsMenu = menuBar()->addMenu("&Instructions");
 	instructionsMenu->addAction(editPrepAction);
 	instructionsMenu->addAction(editFpgmAction);
+	instructionsMenu->addAction(editCvtAction);
 
 	menuBar()->addSeparator();
 
@@ -167,10 +177,7 @@ void MainWindow::loadFile(const QString &fileName)
 
 	connect(m_doc, SIGNAL(documentChanged()), this, SLOT(documentChanged()));
 
-	model = new GlyphsModel(this);
-	model->setDocument(m_doc);
-	unicodeProxy = new UnicodeProxyModel(model);
-	unicodeProxy->setSourceModel(model);
+	setupModels();
 	glyphsView->setModel(unicodeProxy);
 
 	setCurrentFile(fileName);
@@ -180,6 +187,16 @@ void MainWindow::loadFile(const QString &fileName)
 	statusBar()->showMessage("File loaded", 2000);
 }
 
+void MainWindow::setupModels()
+{
+	model = new GlyphsModel(this);
+	model->setDocument(m_doc);
+	unicodeProxy = new UnicodeProxyModel(model);
+	unicodeProxy->setSourceModel(model);
+
+	cvtModel = new CVTModel(m_doc, this);
+}
+
 void MainWindow::changeDocumentName(const QString &name)
 {
 	if (!name.isEmpty())
@@ -298,9 +315,19 @@ void MainWindow::editFpgm()
 	// TODO
 }
 
+void MainWindow::editCvt()
+{
+	CVTEditor *editor = new CVTEditor(cvtModel, this);
+	editor->setWindowTitle(QString("CVT in %1").arg(m_doc->fontName()));
+	editor->show();
+}
+
 void MainWindow::about()
 {
-	// TODO
+	// TODO add some information
+	QMessageBox::about(this, "Fondue Font Editor",
+			"<center><h3>Fondue Font Editor</h3>"
+			"<p>Version " VERSION "</p></center>");
 }
 
 void MainWindow::editGlyph(const QModelIndex &index)
diff --git a/gui/mainwindow.h b/gui/mainwindow.h
index 0f6ce45..b30e91d 100644
--- a/gui/mainwindow.h
+++ b/gui/mainwindow.h
@@ -27,6 +27,7 @@ class GlyphsModel;
 class QModelIndex;
 class QActionGroup;
 class UnicodeProxyModel;
+class CVTModel;
 
 class MainWindow: public QMainWindow {
 	Q_OBJECT
@@ -44,6 +45,7 @@ public slots:
 
 	void editPrep();
 	void editFpgm();
+	void editCvt();
 
 	void about();
 
@@ -63,6 +65,7 @@ private:
 	void createDockWindows();
 	void createStatusBar();
 	bool saveFile(const QString &fileName);
+	void setupModels();
 
 	void closeEvent(QCloseEvent *event);
 
@@ -90,11 +93,13 @@ private:
 
 	QAction *editPrepAction;
 	QAction *editFpgmAction;
+	QAction *editCvtAction;
 	QAction *aboutAction;
 
 	GlyphsGridWidget *glyphsView;
 	GlyphsModel *model;
 	UnicodeProxyModel *unicodeProxy;
+	CVTModel *cvtModel;
 };
 
 #endif
diff --git a/nongui/cvtentry.h b/nongui/cvtentry.h
index d7ca4fc..2d702bd 100644
--- a/nongui/cvtentry.h
+++ b/nongui/cvtentry.h
@@ -40,6 +40,12 @@ public:
 	 * @return comment or empty string if not set.
 	 */
 	QString comment() const {return m_comment;}
+
+	void setValue(qint16 value) {m_value = value;}
+	void setVariableName(const QString &name) {m_variableName = name;}
+	void setComment(const QString &comment) {m_comment = comment;}
+
+	bool operator ==(const CVTEntry &other) const {return m_value == other.m_value && m_variableName == other.m_variableName && m_comment == other.m_comment;}
 private:
 	qint16 m_value;
 	QString m_variableName;
diff --git a/nongui/cvtmodel.cxx b/nongui/cvtmodel.cxx
new file mode 100644
index 0000000..74994dd
--- /dev/null
+++ b/nongui/cvtmodel.cxx
@@ -0,0 +1,119 @@
+/* Copyright (C) 2007 Євгеній Мещеряков <eugen at debian.org>
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+#include "cvtmodel.h"
+#include "fontdocument.h"
+
+CVTModel::CVTModel(FontDocument *doc, QObject *parent) : QAbstractTableModel(parent),
+	m_doc(doc)
+{
+	Q_ASSERT(doc);
+}
+
+int CVTModel::columnCount(const QModelIndex &parent) const
+{
+	if (!parent.isValid())
+		return NColumns;
+	return 0;
+}
+
+int CVTModel::rowCount(const QModelIndex &parent) const
+{
+	Q_ASSERT(m_doc);
+	if (!parent.isValid())
+		return m_doc->cvt().size();
+	return 0;
+}
+
+QVariant CVTModel::data(const QModelIndex &index, int role) const
+{
+	if (!index.isValid())
+		return QVariant();
+
+	if (role == Qt::DisplayRole) {
+		Q_ASSERT(index.row() >= 0 && index.row() < m_doc->cvt().size());
+		switch (index.column()) {
+		case ValueColumn:
+			return m_doc->cvt().at(index.row()).value();
+		case VariableColumn:
+			return m_doc->cvt().at(index.row()).variableName();
+		case CommentColumn:
+			return m_doc->cvt().at(index.row()).comment();
+		default:
+			break;
+		}
+	}
+	return QVariant();
+}
+
+QVariant CVTModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+	if (role == Qt::DisplayRole) {
+		if (orientation == Qt::Horizontal) {
+			switch (section) {
+			case ValueColumn: return "Value";
+			case VariableColumn: return "Variable Name";
+			case CommentColumn: return "Comment";
+			default:
+				break;
+			}
+		}
+		else if (orientation == Qt::Vertical) {
+			return section;
+		}
+	}
+	return QVariant();
+}
+
+bool CVTModel::setData(const QModelIndex &index, const QVariant &value, int role)
+{
+	if (!index.isValid())
+		return false;
+
+	Q_ASSERT(index.row() >= 0 && index.row() < m_doc->cvt().size());
+
+	if (role == Qt::EditRole) {
+		CVTEntry newEntry = m_doc->cvt().at(index.row());
+
+		switch (index.column()) {
+		case ValueColumn:
+			if (!value.canConvert<int>())
+				return false;
+			newEntry.setValue(value.toInt());
+			return m_doc->changeCvtEntry(index.row(), newEntry);
+		case VariableColumn:
+			if (!value.canConvert<QString>())
+				return false;
+			newEntry.setVariableName(value.toString());
+			return m_doc->changeCvtEntry(index.row(), newEntry);
+		case CommentColumn:
+			if (!value.canConvert<QString>())
+				return false;
+			newEntry.setComment(value.toString());
+			return m_doc->changeCvtEntry(index.row(), newEntry);
+		default:
+			break;
+		}
+	}
+	return false;
+}
+
+Qt::ItemFlags CVTModel::flags(const QModelIndex &index) const
+{
+	if (!index.isValid())
+		return 0;
+	return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
+}
diff --git a/gui/controlpoint.h b/nongui/cvtmodel.h
similarity index 53%
copy from gui/controlpoint.h
copy to nongui/cvtmodel.h
index 51373e3..4b582f9 100644
--- a/gui/controlpoint.h
+++ b/nongui/cvtmodel.h
@@ -14,29 +14,24 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
-#ifndef CONTROLPOINT_H
-#define CONTROLPOINT_H
-#include <QGraphicsItem>
-#include "glyphgraphics.h"
+#ifndef CVTMODEL_H
+#define CVTMODEL_H
+#include <QAbstractTableModel>
 
-class GlyphPoint;
-class GlyphCell;
+class FontDocument;
 
-class ControlPoint: public QGraphicsItem
-{
+class CVTModel : public QAbstractTableModel {
 public:
-	ControlPoint(GlyphCell *cell, const GlyphGraphics::PointIndex &idx);
-	enum {Type = UserType + 1};
-	int type() const {return Type;}
-	QRectF boundingRect() const;
-	QPainterPath shape() const;
-	void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
-	GlyphGraphics::PointIndex idx() const {return m_idx;}
-protected:
-	QVariant itemChange(GraphicsItemChange change, const QVariant &value);
+	enum {ValueColumn, VariableColumn, CommentColumn, NColumns};
+	CVTModel(FontDocument *doc, QObject *parent = 0);
+	int rowCount(const QModelIndex &parent = QModelIndex()) const;
+	int columnCount(const QModelIndex &parent = QModelIndex()) const;
+	QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+	QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
+	bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
+	Qt::ItemFlags flags(const QModelIndex &index) const;
 private:
-	GlyphCell *m_cell;
-	GlyphGraphics::PointIndex m_idx;
+	FontDocument *m_doc;
 };
 
 #endif
diff --git a/nongui/fontdocument.cxx b/nongui/fontdocument.cxx
index 54c2178..b151e6f 100644
--- a/nongui/fontdocument.cxx
+++ b/nongui/fontdocument.cxx
@@ -122,3 +122,12 @@ bool FontDocument::changeInstructions(Glyph *glyph, const QString &newInstructio
 	setChanged();
 	return true;
 }
+
+bool FontDocument::changeCvtEntry(int index, const CVTEntry &newEntry)
+{
+	if (newEntry == m_cvt.at(index))
+		return true;
+	m_cvt[index] = newEntry;
+	setChanged();
+	return true;
+}
diff --git a/nongui/fontdocument.h b/nongui/fontdocument.h
index f8f7107..aa3c309 100644
--- a/nongui/fontdocument.h
+++ b/nongui/fontdocument.h
@@ -122,6 +122,7 @@ public:
 	void removeGlyphs(int first, int count);
 
 	bool changeInstructions(Glyph *glyph, const QString &newInstructions);
+	bool changeCvtEntry(int index, const CVTEntry &newEntry);
 signals:
 	void documentChanged();
 private:
diff --git a/nongui/nongui.rules b/nongui/nongui.rules
index d4a656b..3996943 100644
--- a/nongui/nongui.rules
+++ b/nongui/nongui.rules
@@ -5,7 +5,8 @@ libfonduenongui_a_SOURCES =		\
 	nongui/fontdocumentreader.cxx	\
 	nongui/fontdocumentwriter.cxx	\
 	nongui/fontdocument.cxx		\
-	nongui/ttfencode.cxx
+	nongui/ttfencode.cxx		\
+	nongui/cvtmodel.cxx
 
 nodist_libfonduenongui_a_SOURCES = 	\
 	nongui/decodertable.tbl.cxx	\
@@ -35,7 +36,8 @@ noinst_HEADERS +=			\
 	nongui/cvtentry.h		\
 	nongui/lookup.h			\
 	nongui/script.h			\
-	nongui/ttfencode.h
+	nongui/ttfencode.h		\
+	nongui/cvtmodel.h
 
 EXTRA_DIST +=			\
 	nongui/decodertable.xsl	\

-- 
Fondue Font Editor



More information about the fondue-commits mailing list