lyx_mirror/src/lyxled/LayoutEditor.cpp
André Pönitz 7677e9487c simplify Lexer use a bit
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24098 a592a061-630c-0410-9148-cb99ea01b6c8
2008-04-02 22:14:45 +00:00

127 lines
2.7 KiB
C++

#include "LayoutEditor.h"
#include "ui_MainWindowUi.h"
#include <QDebug>
#include <QFile>
#include <QList>
#include <QStandardItem>
#include <QStandardItemModel>
#include <QString>
#include <QTreeView>
namespace lyx {
/////////////////////////////////////////////////////////////////////////
//
// LayoutTree
//
/////////////////////////////////////////////////////////////////////////
LayoutTree::LayoutTree(QWidget * parent)
: QTreeView(parent)
{}
/////////////////////////////////////////////////////////////////////////
//
// LayoutEditor
//
/////////////////////////////////////////////////////////////////////////
LayoutEditor::LayoutEditor(QWidget * parent)
: QWidget(parent)
{}
/////////////////////////////////////////////////////////////////////////
//
// MainWindow
//
/////////////////////////////////////////////////////////////////////////
MainWindow::MainWindow()
{
ui_ = new Ui::MainWindow;
ui_->setupUi(this);
model_ = new QStandardItemModel(this);
view_ = new LayoutTree(this);
view_->setModel(model_);
//setCentralWidget(view_);
ui_->dockLayoutTree->setWidget(view_);
}
MainWindow::~MainWindow()
{
delete ui_;
}
static bool isInsensitivelyEqual(QString const & s1, QString const & s2)
{
return s1.compare(s2, Qt::CaseInsensitive) == 0;
}
void MainWindow::loadLayoutFile(QString const & fileName)
{
loadLayoutFile(fileName, model_->invisibleRootItem());
view_->expandAll();
}
void MainWindow::loadLayoutFile(QString const & fileName,
QStandardItem * parent)
{
QFile file(fileName);
#if 0
file.open(QIODevice::ReadOnly);
QString contents = file.readAll();
file.close();
qDebug() << "contents: " << contents;
#endif
file.open(QIODevice::ReadOnly);
QTextStream ts(&file);
while (!ts.atEnd()) {
QList<QStandardItem *> row;
QString code;
ts >> code;
//qDebug() << "CODE: " << code;
if (code.startsWith('#')) {
QString line = code + ' ' + ts.readLine();
//row.append(new QStandardItem("Comment"));
//row.append(new QStandardItem(code + ' ' + ts.readLine()));
//parent->appendRow(row);
} else if (isInsensitivelyEqual(code, "Input")) {
QString inputFile;
ts >> inputFile;
QStandardItem * item = new QStandardItem(inputFile);
row.append(item);
parent->appendRow(row);
inputFile = fileName.left(fileName.lastIndexOf('/')) + '/' + inputFile;
qDebug() << "INPUT: " << inputFile;
loadLayoutFile(inputFile, item);
} else if (isInsensitivelyEqual(code, "Style")) {
QString style;
ts >> style;
//while (!ts.atEnd() && !isInsensitivelyEqual(code, "EndStyle"))
// ts >> code;
QStandardItem * item = new QStandardItem(style);
row.append(item);
parent->appendRow(row);
} else {
//row.append(new QStandardItem(code));
//parent->appendRow(row);
}
}
file.close();
}
} // namespace lyx