Commit 6d0a92e1 authored by Arthur Crepin-Leblond's avatar Arthur Crepin-Leblond Committed by Guillaume Lazzara
Browse files

Base 64 support in Qt interface (xmlc extension)

        * scribo/demo/viewer/step_widget.cc
        * scribo/demo/viewer/step_widget.hh
        * scribo/demo/viewer/browser_widget.cc,
        * scribo/demo/viewer/browser_widget.hh: Add .xmlc extension.

        * scribo/demo/viewer/image_scene.cc
        * scribo/demo/viewer/viewer.cc,
        * scribo/demo/viewer/viewer.hh: base 64 loading.
parent 07a17b94
2010-07-16 Arthur Crepin-Leblond <crepin@ptaouchnok.lrde.epita.fr>
Base 64 support in Qt interface (xmlc extension)
* demo/viewer/step_widget.cc
* demo/viewer/step_widget.hh
* demo/viewer/browser_widget.cc,
* demo/viewer/browser_widget.hh: Add .xmlc extension.
* demo/viewer/image_scene.cc
* demo/viewer/viewer.cc,
* demo/viewer/viewer.hh: base 64 loading.
2010-07-16 Arthur Crepin-Leblond <crepin@ptaouchnok.lrde.epita.fr>
Two new features in Qt interface.
* demo/viewer/browser_widget.cc,
* demo/viewer/browser_widget.hh: Add arrows to change image and keep
XML step.
* demo/viewer/browser_widget.hh: Add arrows to change image and
keep XML step.
* demo/viewer/key_widget.cc,
* demo/viewer/key_widget.hh: Change ListWidget to TreeWidget, Items can be
disabled/enabled in groups.
* demo/viewer/key_widget.hh: Change ListWidget to TreeWidget,
Items can be disabled/enabled in groups.
* demo/viewer/step_widget.cc,
* demo/viewer/step_widget.hh: Small changes to keep the step when next/prev.
picture is chosen.
* demo/viewer/step_widget.hh: Small changes to keep the step when
next/prev. picture is chosen.
* demo/viewer/viewer.cc,
* demo/viewer/xml_widget.cc: Layout adjustement.
2010-07-16 Arthur Crepin-Leblond <crepin@ptaouchnok.lrde.epita.fr>
ChangeLog mistake.
* scribo/ChangeLog: Move 2010-07-08 entry in...
* scribo/sandbox/ChangeLog:...this.
* ChangeLog: Move 2010-07-08 entry in...
* sandbox/ChangeLog:...this.
2010-06-30 Arthur Crepin-Leblond <crepin@stockholm.lrde.epita.fr>
......@@ -78,12 +90,12 @@
Small fix in Qt interface.
* scribo/demo/viewer/viewer.cc,
* scribo/demo/viewer/image_region.hxx: Disable item click if
* demo/viewer/viewer.cc,
* demo/viewer/image_region.hxx: Disable item click if
unchecked in item list.
* scribo/demo/viewer/key_widget.cc,
* scribo/demo/viewer/key_widget.hh: Add KeyWidget::checkAll.
* demo/viewer/key_widget.cc,
* demo/viewer/key_widget.hh: Add KeyWidget::checkAll.
2010-08-27 Guillaume Lazzara <z@lrde.epita.fr>
......
......@@ -66,7 +66,9 @@ BrowserWidget::BrowserWidget(QDirModel* files, QString dir)
QStringList files_filters;
files_filters << "*.png" << "*.jpg"
<< "*.tif" << "*.ppm" << "*.pgm" << "*.pbm" << "pnm";
<< "*.tif" << "*.ppm"
<< "*.pgm" << "*.pbm"
<< "*.pnm" << "*.xmle";
files->setNameFilters(files_filters);
}
......@@ -95,7 +97,10 @@ BrowserWidget::activate(const QModelIndex& index, bool b)
first_time_ = false;
emit activated(files_->filePath(index), b);
if (files_->filePath(index).endsWith(".xmlc"))
emit activated(files_->filePath(index), b, true);
else
emit activated(files_->filePath(index), b, false);
}
void
......
......@@ -33,7 +33,7 @@ public slots:
void prev() { change_pos(false); }
signals:
void activated(QString filename, bool b);
void activated(QString filename, bool b, bool x);
private:
void change_pos(bool next);
......
......@@ -40,7 +40,7 @@ ImageScene::mousePressEvent(QGraphicsSceneMouseEvent* event)
{
ImageRegion* item = dynamic_cast<ImageRegion*>(elt);
if (item)
{
{
if (item != selected_)
{
if (selected_)
......@@ -49,7 +49,7 @@ ImageScene::mousePressEvent(QGraphicsSceneMouseEvent* event)
{
int item_area = item->boundingRect().size().height() * item->boundingRect().size().width();
int selected_area = selected_->boundingRect().size().height() * selected_->boundingRect().size().width();
if (selected_area < item_area && selection_is_clicked)
return;
else
......@@ -66,15 +66,15 @@ ImageScene::mousePressEvent(QGraphicsSceneMouseEvent* event)
selected_ = 0;
}
}
selected_ = item;
selected_ = item;
item->select();
emit selected(item->index());
return;
return;
}
}
else
{
if ( (selected_)
if ( (selected_)
&& (items_list.size() == 1) )// no ImageRegion, only the picture
{
selected_->deselect();
......
......@@ -68,57 +68,64 @@ void StepWidget::activate(QListWidgetItem* item)
}
void StepWidget::fill_steps(QString file, bool step)
void StepWidget::fill_steps(QString file, bool step, bool container)
{
view_->clear();
map_.clear();
// image is loaded once
emit load_image(file);
if (container)
{
emit load_image(file, true);
emit load_xml(file);
}
else
{
// image is loaded once
emit load_image(file, false);
int cut = file.lastIndexOf(QChar('/'));
QString path = file.left(cut+1);
QString filename = file.mid(cut+1);
int cut = file.lastIndexOf(QChar('/'));
QString path = file.left(cut+1);
QString filename = file.mid(cut+1);
cut = filename.lastIndexOf(QChar('.'));
cut = filename.lastIndexOf(QChar('.'));
QString file_with_no_ext = filename.left(cut);
// view_->addItem(file_with_no_ext);
QString file_with_no_ext = filename.left(cut);
// view_->addItem(file_with_no_ext);
QDir dir(path);
QDir dir(path);
if (dir.isReadable())
{
QStringList filter;
filter << "*.xml";
QStringList xml_list = dir.entryList(filter);
for (int i = 0; i < xml_list.size(); ++i)
if (dir.isReadable())
{
if (xml_list.at(i).startsWith(file_with_no_ext))
QStringList filter;
filter << "*.xml";
QStringList xml_list = dir.entryList(filter);
for (int i = 0; i < xml_list.size(); ++i)
{
cut = xml_list.at(i).lastIndexOf(QChar('.'));
QString key = xml_list.at(i).left(cut);
key.replace(file_with_no_ext + QString("_"), QString(""));
key.replace(QRegExp("^step([0-9])"), "Step \\1");
key.replace(QRegExp("^Step ([0-9])_"), "Step \\1 : ");
key.replace("_", " ");
QString value = path;
map_.insertMulti(key, value.append(xml_list.at(i)));
view_->addItem(key);
if (xml_list.at(i).startsWith(file_with_no_ext))
{
cut = xml_list.at(i).lastIndexOf(QChar('.'));
QString key = xml_list.at(i).left(cut);
key.replace(file_with_no_ext + QString("_"), QString(""));
key.replace(QRegExp("^step([0-9])"), "Step \\1");
key.replace(QRegExp("^Step ([0-9])_"), "Step \\1 : ");
key.replace("_", " ");
QString value = path;
map_.insertMulti(key, value.append(xml_list.at(i)));
view_->addItem(key);
}
}
}
}
if ( (step && step_ != QString::Null()))
{
QList<QListWidgetItem*> list = view_->findItems(step_, Qt::MatchContains);
if (step && step_ != QString::Null())
{
QList<QListWidgetItem*> list = view_->findItems(step_, Qt::MatchContains);
if (!list.isEmpty())
emit activated(list.first());
if (!list.isEmpty())
emit activated(list.first());
}
else
step_ = QString::Null();
}
else
step_ = QString::Null();
}
void StepWidget::add_element(const QString& element)
......
......@@ -42,12 +42,12 @@ public:
void add_element(const QString& element);
signals:
void load_image(QString);
void load_image(QString, bool);
void load_xml(QString);
void activated(QListWidgetItem*);
public slots:
void fill_steps(QString file, bool = false);
void fill_steps(QString file, bool step = false, bool container = false);
void activate(QListWidgetItem* item);
private:
......
......@@ -169,11 +169,11 @@ Viewer::Viewer(int &argc, char** argv)
h_sizes << 200 << 700;
h_splitter->setSizes(h_sizes);
connect(browser_wgt, SIGNAL(activated(QString, bool)),
step_widget, SLOT(fill_steps(QString, bool)));
connect(browser_wgt, SIGNAL(activated(QString, bool, bool)),
step_widget, SLOT(fill_steps(QString, bool, bool)));
connect(step_widget, SIGNAL(load_image(QString)),
this, SLOT(load(QString)));
connect(step_widget, SIGNAL(load_image(QString, bool)),
this, SLOT(load(QString, bool)));
connect(step_widget, SIGNAL(load_xml(QString)),
this, SLOT(load_xml(QString)));
......@@ -429,18 +429,20 @@ Viewer::xml_to_layout()
}
void
Viewer::load(QString filename)
Viewer::load(QString filename, bool b)
{
app_->setOverrideCursor(QCursor(Qt::WaitCursor));
scene_->clear();
scene_->update();
image_ = 0;
// xml_file_ = "";
// Load the image in a pixmap that is directly shown on screen.
// This is very slow when used with the normal rendering system.
// OpenGL might speed up things a bit.
image_ = new QGraphicsPixmapItem(QPixmap(filename));
if (b)
image_ = new QGraphicsPixmapItem(load_base64(filename));
else
image_ = new QGraphicsPixmapItem(QPixmap(filename));
image_->setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
image_->setZValue(0);
scene_->addItem(image_);
......@@ -511,4 +513,48 @@ Viewer::useCache(bool b)
image_->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
}
QPixmap Viewer::load_base64(QString xml)
{
QPixmap pix;
QFile f_in(xml);
f_in.open(QIODevice::ReadOnly);
QDomDocument doc;
doc.setContent(&f_in);
f_in.close();
QDomElement root = doc.documentElement();
QDomNode child = root.firstChild();
while (!child.isNull() && !child.toElement().tagName().contains("page"))
child = child.nextSibling();
child = child.firstChild();
while (!child.isNull())
{
if (child.toElement().tagName().contains(QRegExp("image_region")))
{
QDomNode node = child.firstChild();
QString id = child.toElement().attribute("id", "none");
while (!node.isNull() && !node.toElement().tagName().contains("container"))
node = node.nextSibling();
if (!node.isNull())
{
QString data = node.firstChildElement("data").text();
QByteArray ba;
ba = ba.append(data);
QByteArray out_ba = QByteArray::fromBase64(ba);
pix.loadFromData(out_ba);
return pix;
}
}
child = child.nextSibling();
}
return pix;
}
// LocalWords: hh
......@@ -38,7 +38,7 @@ public:
public slots:
// Load the file as an image, load the layout if xml with the same
// name is found.
void load(QString filename);
void load(QString filename, bool b);
void help();
void load_xml(QString filename);
void maybeChangeCacheMode(qreal scale);
......@@ -59,6 +59,7 @@ private:
Viewer();
void xml_to_layout();
QPixmap load_base64(QString xml);
QApplication* app_;
QMainWindow* win_;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment