summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2009-02-02 19:34:03 +0100
committerYorhel <git@yorhel.nl>2009-02-02 19:34:03 +0100
commit385ed9346cd87eeb2645cf0e217d59718844293f (patch)
tree1aa8b5e4afb39ac52aa981442c03aaf421c8592f
parent1c4fa45b62fe5a5026597e164cd0ec48c309e69c (diff)
Started on utfScriptModel and using a QTableView to display the lines
It works, kind of... I have no clue as to what the hell I am doing, as I'm really just playing around. C++ isn't my thing... Don't be surprised if everything I've written just now will be completely rewritten in a next commit.
-rw-r--r--.gitignore6
-rw-r--r--seentl.cpp5
-rw-r--r--seentl.h3
-rw-r--r--seentl.pro21
-rw-r--r--seentl.ui68
-rw-r--r--utfscriptmodel.cpp105
-rw-r--r--utfscriptmodel.h30
7 files changed, 212 insertions, 26 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..94f0664
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,6 @@
+Makefile*
+*.utf
+debug/
+qtc-gdbmacros/
+seentl
+ui_seentl.h
diff --git a/seentl.cpp b/seentl.cpp
index 08ddbab..c84d412 100644
--- a/seentl.cpp
+++ b/seentl.cpp
@@ -5,6 +5,11 @@ SEENTL::SEENTL(QWidget *parent)
: QMainWindow(parent), ui(new Ui::SEENTLClass)
{
ui->setupUi(this);
+
+ script.openScript("SEEN0517.utf");
+
+ ui->lines->setModel(&script);
+
}
SEENTL::~SEENTL()
diff --git a/seentl.h b/seentl.h
index 91889fc..c082ca5 100644
--- a/seentl.h
+++ b/seentl.h
@@ -2,6 +2,7 @@
#define SEENTL_H
#include <QtGui/QMainWindow>
+#include "utfscriptmodel.h"
namespace Ui
{
@@ -18,6 +19,8 @@ public:
private:
Ui::SEENTLClass *ui;
+ utfScriptModel script;
+
};
#endif // SEENTL_H
diff --git a/seentl.pro b/seentl.pro
index 79b08d5..f1482c9 100644
--- a/seentl.pro
+++ b/seentl.pro
@@ -1,16 +1,11 @@
-#-------------------------------------------------
-#
+# -------------------------------------------------
# Project created by QtCreator 2009-02-02T14:14:07
-#
-#-------------------------------------------------
-
+# -------------------------------------------------
TARGET = seentl
TEMPLATE = app
-
-
-SOURCES += main.cpp\
- seentl.cpp
-
-HEADERS += seentl.h
-
-FORMS += seentl.ui
+SOURCES += main.cpp \
+ seentl.cpp \
+ utfscriptmodel.cpp
+HEADERS += seentl.h \
+ utfscriptmodel.h
+FORMS += seentl.ui
diff --git a/seentl.ui b/seentl.ui
index fae4998..536e094 100644
--- a/seentl.ui
+++ b/seentl.ui
@@ -1,10 +1,8 @@
-<ui version="4.0" stdsetdef="1" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
<class>SEENTLClass</class>
- <widget class="QMainWindow" name="SEENTLClass" >
- <property name="objectName" >
- <cstring>SEENTLClass</cstring>
- </property>
- <property name="geometry" >
+ <widget class="QMainWindow" name="SEENTLClass">
+ <property name="geometry">
<rect>
<x>0</x>
<y>0</y>
@@ -12,16 +10,60 @@
<height>400</height>
</rect>
</property>
- <property name="windowTitle" >
+ <property name="windowTitle">
<string>SEENTL</string>
</property>
- <widget class="QMenuBar" name="menuBar" />
- <widget class="QToolBar" name="mainToolBar" />
- <widget class="QWidget" name="centralWidget" />
- <widget class="QStatusBar" name="statusBar" />
+ <widget class="QWidget" name="centralWidget">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QTableView" name="lines">
+ <property name="selectionMode">
+ <enum>QAbstractItemView::SingleSelection</enum>
+ </property>
+ <property name="selectionBehavior">
+ <enum>QAbstractItemView::SelectRows</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menuBar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>600</width>
+ <height>23</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="menu_File">
+ <property name="title">
+ <string>&amp;File</string>
+ </property>
+ <addaction name="actionOpen"/>
+ <addaction name="actionSave"/>
+ </widget>
+ <addaction name="menu_File"/>
+ </widget>
+ <widget class="QStatusBar" name="statusBar"/>
+ <action name="actionOpen">
+ <property name="text">
+ <string>Open</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+O</string>
+ </property>
+ </action>
+ <action name="actionSave">
+ <property name="text">
+ <string>Save</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+S</string>
+ </property>
+ </action>
</widget>
- <layoutDefault spacing="6" margin="11" />
- <pixmapfunction></pixmapfunction>
+ <layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
diff --git a/utfscriptmodel.cpp b/utfscriptmodel.cpp
new file mode 100644
index 0000000..d7ef114
--- /dev/null
+++ b/utfscriptmodel.cpp
@@ -0,0 +1,105 @@
+#include <QRegExp>
+#include <QDebug>
+#include "utfscriptmodel.h"
+
+utfScriptModel::utfScriptModel()
+{
+ fl = new QFile(this);
+ rows = 0;
+ positions = NULL;
+}
+
+utfScriptModel::utfScriptModel(const QString &file)
+{
+ utfScriptModel();
+ openScript(file);
+}
+
+utfScriptModel::~utfScriptModel()
+{
+ fl->close();
+ delete fl;
+ if(positions != NULL)
+ delete [] positions;
+}
+
+void utfScriptModel::openScript(const QString &file)
+{
+ QTextStream str;
+ fl->setFileName(file);
+ fl->open(QIODevice::ReadWrite | QIODevice::Text);
+ str.setDevice(fl);
+ str.setCodec("UTF-8");
+ str.seek(0);
+ // let's hog some memory, baby!
+ while(!str.atEnd())
+ lines.append(str.readLine());
+ calcPositions();
+}
+
+// updates int rows and int *positions
+void utfScriptModel::calcPositions()
+{
+ if(positions != NULL)
+ delete [] positions;
+
+ // lines.size() is actually way too much, but at least we can be
+ // sure it's enough without having to calculate the actual size
+ positions = new qint64[lines.size()+1];
+
+ rows = 0;
+ int i;
+ for(i=0; i<lines.size(); i++)
+ if(lines.at(i).contains(QRegExp("^<\\d{4}>")))
+ positions[rows++] = i;
+ positions[rows] = i;
+}
+
+int utfScriptModel::rowCount(const QModelIndex &parent) const
+{
+ if(!fl->isOpen())
+ return 0;
+ return rows;
+}
+
+int utfScriptModel::columnCount(const QModelIndex &parent) const
+{
+ return 4; // #line, original, translation, comments
+}
+
+QVariant utfScriptModel::data(const QModelIndex &index, int role) const
+{
+ if(!index.isValid() || index.row() >= rows || index.column() > 3 || role != Qt::DisplayRole)
+ return QVariant();
+
+ QRegExp tra("<(\\d{4})>\\s*(.+)");
+ QRegExp ori("//\\s*<(\\d{4})>\\s*(.+)");
+ QRegExp com("//(.+)");
+
+ QString ln, num, orig, trans, comm;
+ for(int i = positions[index.row()]; i < positions[index.row()+1]; i++) {
+ ln = lines.at(i);
+ if(tra.exactMatch(ln)) {
+ num = tra.cap(1);
+ trans = tra.cap(2);
+ } else if(ori.exactMatch(ln)) {
+ orig = ori.cap(2);
+ if(orig == trans)
+ trans = "";
+ } else if(com.exactMatch(ln)) {
+ if(comm != "")
+ comm += "\n";
+ comm += com.cap(1);
+ } else
+ break;
+ }
+
+ return index.column() == 0 ? num : index.column() == 1 ? orig : index.column() == 2 ? trans : comm;
+}
+
+QVariant utfScriptModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ if(orientation == Qt::Vertical || role != Qt::DisplayRole)
+ return QVariant();
+ return QString(section == 0 ? "Line" : section == 1 ? "Original" : section == 2 ? "Translation" : "Comments");
+}
diff --git a/utfscriptmodel.h b/utfscriptmodel.h
new file mode 100644
index 0000000..c107c52
--- /dev/null
+++ b/utfscriptmodel.h
@@ -0,0 +1,30 @@
+#ifndef UTFSCRIPTMODEL_H
+#define UTFSCRIPTMODEL_H
+
+#include <QAbstractTableModel>
+#include <QFile>
+#include <QStringList>
+
+class utfScriptModel : public QAbstractTableModel
+{
+public:
+ utfScriptModel();
+ utfScriptModel(const QString&);
+ ~utfScriptModel();
+ void openScript(const QString&);
+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ int columnCount(const QModelIndex &parent = QModelIndex()) const;
+ QVariant data(const QModelIndex &index, int role) const;
+ QVariant headerData(int section, Qt::Orientation orientation,
+ int role = Qt::DisplayRole) const;
+
+private:
+ QFile *fl;
+ QStringList lines;
+ int rows;
+ qint64 *positions;
+
+ void calcPositions();
+};
+
+#endif // UTFSCRIPTMODEL_H