Commit 07a17b94 authored by Arthur Crepin-Leblond's avatar Arthur Crepin-Leblond Committed by Guillaume Lazzara
Browse files

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/key_widget.cc,
        * 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/viewer.cc,
        * demo/viewer/xml_widget.cc: Layout adjustement.
parent f7ae8c2d
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/key_widget.cc,
* 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/viewer.cc,
* demo/viewer/xml_widget.cc: Layout adjustement.
2010-07-16 Arthur Crepin-Leblond <crepin@ptaouchnok.lrde.epita.fr>
ChangeLog mistake.
......
......@@ -17,16 +17,28 @@
BrowserWidget::BrowserWidget(QDirModel* files, QString dir)
: files_(files),
view_(new QListView()),
path_(new QLineEdit(""))
path_(new QLineEdit("")),
first_time_(true)
{
QToolButton* next= new QToolButton();
QToolButton* prev= new QToolButton();
next->setArrowType(Qt::RightArrow);
prev->setArrowType(Qt::LeftArrow);
QLabel* title = new QLabel(tr("Images"));
title->setAlignment(Qt::AlignHCenter);
QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(title);
QHBoxLayout *hlayout = new QHBoxLayout;
hlayout->addWidget(prev);
hlayout->addWidget(title);
hlayout->addWidget(next);
layout->addLayout(hlayout);
layout->addWidget(path_);
layout->addWidget(view_);
//setLayout(hlayout);
setLayout(layout);
view_->setModel(files);
......@@ -34,19 +46,28 @@ BrowserWidget::BrowserWidget(QDirModel* files, QString dir)
| QDir::Readable | QDir::Drives);
view_->setRootIndex(files->index(QDir::currentPath()));
QDir d(dir);
if (d.isReadable())
view_->setRootIndex(files->index(d.absolutePath()));
view_->setRowHidden(0, true);
path_->setText(files->filePath(view_->rootIndex()));
connect(view_, SIGNAL(activated(const QModelIndex&)),
this, SLOT(activate(const QModelIndex&)));
connect(next, SIGNAL(released ()),
this, SLOT(next()));
connect(prev, SIGNAL(released ()),
this, SLOT(prev()));
connect(path_, SIGNAL(returnPressed()),
this, SLOT(path_return_pressed()));
QStringList files_filters;
files_filters << "*.png" << "*.jpg"
<< "*.tif" << "*.ppm" << "*.pgm" << "*.pbm";
<< "*.tif" << "*.ppm" << "*.pgm" << "*.pbm" << "pnm";
files->setNameFilters(files_filters);
}
......@@ -57,20 +78,43 @@ BrowserWidget::path_return_pressed()
QDir d(path);
if (d.isReadable())
activate(files_->index(QString(path)));
activate(files_->index(QString(path)), false);
}
void
BrowserWidget::activate(const QModelIndex& index)
BrowserWidget::activate(const QModelIndex& index, bool b)
{
if (files_->isDir(index))
{
view_->setRootIndex(index);
view_->setRowHidden(0, true);
path_->setText(files_->filePath(view_->rootIndex()));
first_time_ = true;
return;
}
emit activated(files_->filePath(index));
first_time_ = false;
emit activated(files_->filePath(index), b);
}
void
BrowserWidget::change_pos(bool next)
{
QModelIndex index = view_->currentIndex();
if(next)
index = files_->index(index.row() + 1, index.column(), index.parent());
else
index = files_->index(index.row() - 1, index.column(), index.parent());
if (index.isValid())
{
if (!files_->isDir(index))
if (!first_time_)
activate(index, true);
view_->setCurrentIndex(index);
}
}
BrowserWidget::~BrowserWidget()
......
......@@ -27,16 +27,20 @@ public:
~BrowserWidget();
public slots:
void activate(const QModelIndex& index);
void activate(const QModelIndex& index, bool b = false);
void path_return_pressed();
void next() { change_pos(true); }
void prev() { change_pos(false); }
signals:
void activated(QString filename);
void activated(QString filename, bool b);
private:
void change_pos(bool next);
QDirModel* files_;
QListView* view_;
QLineEdit* path_;
bool first_time_;
};
#endif /* !BROWSER_WIDGET_HH_ */
......@@ -16,82 +16,127 @@
#include "common.hh"
KeyWidget::KeyWidget(const region::KeyMap& key_map)
: items_(new QListWidget())
: items_(new QTreeWidget()),
text_(new QTreeWidgetItem(QStringList("Text"))),
regions_(new QTreeWidgetItem(QStringList("Regions")))
{
QLabel* title = new QLabel(tr("Key"));
title->setAlignment(Qt::AlignHCenter);
items_->addTopLevelItem(text_);
items_->addTopLevelItem(regions_);
items_->setHeaderHidden(true);
text_->setCheckState(0, Qt::Checked);
regions_->setCheckState(0, Qt::Checked);
regions_->setExpanded(true);
text_->setExpanded(true);
for (int i = 0; i < 3; ++i)
add_item_(key_map.at(i).first, key_map.at(i).second,
i == region::Line ||
i == region::Paragraph, text_);
for (int i = 3; i < key_map.size(); ++i)
add_item_(key_map.at(i).first, key_map.at(i).second, false, regions_);
QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(title);
layout->addWidget(items_);
for (int i = 0; i < key_map.size(); ++i)
add_item_(key_map[i].first, key_map[i].second,
(i == region::Paragraph) ||
(i == region::Line) );
setLayout(layout);
connect(items_, SIGNAL(itemChanged(QListWidgetItem*)),
this, SLOT(update(QListWidgetItem*)));
connect(items_, SIGNAL(itemChanged(QTreeWidgetItem*, int)),
this, SLOT(update(QTreeWidgetItem*)));
}
void KeyWidget::update_all()
{
for (int i = 0; i < text_->childCount(); ++i)
update(text_->child(i));
for (int i = 0; i < regions_->childCount(); ++i)
update(regions_->child(i));
}
void KeyWidget::checkAll()
void KeyWidget::setAllCheck(QTreeWidgetItem* parent)
{
for (int i = 0; i < items_->count(); ++i)
for (int i = 0; i < parent->childCount(); ++i)
{
items_->item(i)->setCheckState(Qt::Checked);
emit updated(i, true);
if (parent->checkState(0) == Qt::Checked)
parent->child(i)->setCheckState(0, Qt::Checked);
else
parent->child(i)->setCheckState(0, Qt::Unchecked);
update(parent->child(i));
}
}
void
void
KeyWidget::change_mode(bool b)
{
int id_region = region::Paragraph;
int id_line = region::Line;
if (b)
{
items_->item(id_region)->setCheckState(Qt::Checked);
items_->item(id_region)->setHidden(false);
items_->item(id_line)->setCheckState(Qt::Checked);
items_->item(id_line)->setHidden(false);
text_->child(id_region)->setCheckState(0, Qt::Checked);
text_->child(id_region)->setHidden(false);
text_->child(id_line)->setCheckState(0, Qt::Checked);
text_->child(id_line)->setHidden(false);
}
else
{
items_->item(id_region)->setCheckState(Qt::Unchecked);
items_->item(id_region)->setHidden(true);
items_->item(id_line)->setCheckState(Qt::Unchecked);
items_->item(id_line)->setHidden(true);
text_->child(id_region)->setCheckState(0, Qt::Unchecked);
text_->child(id_region)->setHidden(true);
text_->child(id_line)->setCheckState(0, Qt::Unchecked);
text_->child(id_line)->setHidden(true);
}
}
void
KeyWidget::add_item_(QString text, QColor color, bool b)
KeyWidget::add_item_(QString text, QColor color, bool b, QTreeWidgetItem* parent)
{
QListWidgetItem* item = new QListWidgetItem(text);
QTreeWidgetItem* item = new QTreeWidgetItem(QStringList(text));
QPixmap pixmap(10, 6);
pixmap.fill(color);
item->setIcon(QIcon(pixmap));
item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
item->setCheckState(Qt::Checked);
items_->addItem(item);
int id = items_->row(item);
items_->item(id)->setHidden(b);
item->setIcon(0, QIcon(pixmap));
item->setCheckState(0, Qt::Checked);
parent->addChild(item);
item->setHidden(b);
}
bool
bool
KeyWidget::isChecked(region::RegionId id)
{
return items_->item(id)->checkState() == Qt::Checked;
QTreeWidgetItem* item = text_->child(id);
if (item)
return item->checkState(0) == Qt::Checked;
else
{
item = regions_->child(id);
if(item)
return item->checkState(0) == Qt::Checked;
else
return false;
}
}
void
KeyWidget::update(QListWidgetItem* item)
KeyWidget::update(QTreeWidgetItem* item)
{
int id = items_->row(item);
int id;
id = text_->indexOfChild(item);
if (id == -1)
id = regions_->indexOfChild(item) + 3;
emit updated(id, item->checkState(0) == Qt::Checked);
emit updated(id, item->checkState() == Qt::Checked);
if (item == text_ || item == regions_)
{
setAllCheck(item);
return;
}
}
KeyWidget::~KeyWidget()
......
......@@ -27,20 +27,24 @@ public:
KeyWidget(const region::KeyMap& key_map);
~KeyWidget();
void checkAll();
bool isChecked(region::RegionId id);
QTreeWidget* items() { return items_; };
void update_all();
signals:
void updated(int key, bool checked);
private slots:
void update(QListWidgetItem* slot);
void change_mode(bool b);
void update(QTreeWidgetItem* item);
void setAllCheck(QTreeWidgetItem* parent);
private:
void add_item_(QString text, QColor color, bool b);
void add_item_(QString text, QColor color, bool b, QTreeWidgetItem* parent);
QListWidget* items_;
QTreeWidget* items_;
QTreeWidgetItem* text_;
QTreeWidgetItem* regions_;
};
#endif /* !KEY_WIDGET_HH_ */
......@@ -26,7 +26,8 @@
# include "step_widget.hh"
StepWidget::StepWidget()
: view_(new QListWidget())
: view_(new QListWidget()),
step_(QString::Null())
{
QLabel* title = new QLabel(tr("Steps"));
title->setAlignment(Qt::AlignHCenter);
......@@ -42,6 +43,9 @@ StepWidget::StepWidget()
connect(view_, SIGNAL(itemActivated(QListWidgetItem*)),
this, SLOT(activate(QListWidgetItem*)));
connect(this, SIGNAL(activated(QListWidgetItem*)),
this, SLOT(activate(QListWidgetItem*)));
}
void StepWidget::activate(QListWidgetItem* item)
......@@ -49,18 +53,22 @@ void StepWidget::activate(QListWidgetItem* item)
QString key, value;
StepQMap::iterator iter = map_.find(item->text());
view_->setCurrentItem(item);
if (iter != map_.end())
{
step_ = item->text();
key = iter.key();
value = iter.value();
emit load_xml(value);
}
emit load_xml(value);
else
qDebug() << "Step not found!";
}
void StepWidget::fill_steps(QString file)
void StepWidget::fill_steps(QString file, bool step)
{
view_->clear();
map_.clear();
......@@ -69,13 +77,14 @@ void StepWidget::fill_steps(QString file)
emit load_image(file);
int cut = file.lastIndexOf(QChar('/'));
QString path = file.left(cut+1);
QString path = file.left(cut+1);
QString filename = file.mid(cut+1);
cut = filename.lastIndexOf(QChar('.'));
QString file_with_no_ext = filename.left(cut);
// view_->addItem(file_with_no_ext);
QDir dir(path);
if (dir.isReadable())
......@@ -84,7 +93,7 @@ void StepWidget::fill_steps(QString file)
filter << "*.xml";
QStringList xml_list = dir.entryList(filter);
for (int i = 0; i < xml_list.size(); ++i)
{
{
if (xml_list.at(i).startsWith(file_with_no_ext))
{
cut = xml_list.at(i).lastIndexOf(QChar('.'));
......@@ -99,6 +108,17 @@ void StepWidget::fill_steps(QString file)
}
}
}
if (step && step_ != QString::Null())
{
QList<QListWidgetItem*> list = view_->findItems(step_, Qt::MatchContains);
if (!list.isEmpty())
emit activated(list.first());
}
else
step_ = QString::Null();
}
void StepWidget::add_element(const QString& element)
......
......@@ -44,14 +44,16 @@ public:
signals:
void load_image(QString);
void load_xml(QString);
void activated(QListWidgetItem*);
public slots:
void fill_steps(QString file);
void fill_steps(QString file, bool = false);
void activate(QListWidgetItem* item);
private:
QListWidget* view_;
StepQMap map_;
QString step_;
};
#endif /* !STEP_WIDGET_HH_ */
......@@ -44,6 +44,7 @@ Viewer::Viewer(int &argc, char** argv)
key_map_[region::Text] = qMakePair(tr("Text Region"), QColor(0, 200, 0));
key_map_[region::Paragraph] = qMakePair(tr("Paragraph"), QColor(0, 0, 255));
key_map_[region::Line] = qMakePair(tr("Text line"), QColor(255, 0, 0));
key_map_[region::Image] = qMakePair(tr("Image"), QColor(255, 120, 0));
key_map_[region::Noise] = qMakePair(tr("Noise"), QColor(43, 39, 128));
key_map_[region::Separator] = qMakePair(tr("Separator"), QColor(0, 0, 255));
......@@ -70,7 +71,7 @@ Viewer::Viewer(int &argc, char** argv)
// Layout
win_->resize(1024, 768);
win_->resize(1152, 864);
win_->statusBar();
QMenu* file_menu = win_->menuBar()->addMenu(tr("File"));
......@@ -157,7 +158,7 @@ Viewer::Viewer(int &argc, char** argv)
win_->setCentralWidget(h_splitter);
QList<int> v_sizes;
v_sizes << 300 << 200 << 200 << 300;
v_sizes << 200 << 200 << 300 << 400;
v_splitter->setSizes(v_sizes);
QList<int> v_sizes2;
......@@ -168,8 +169,8 @@ Viewer::Viewer(int &argc, char** argv)
h_sizes << 200 << 700;
h_splitter->setSizes(h_sizes);
connect(browser_wgt, SIGNAL(activated(QString)),
step_widget, SLOT(fill_steps(QString)));
connect(browser_wgt, SIGNAL(activated(QString, bool)),
step_widget, SLOT(fill_steps(QString, bool)));
connect(step_widget, SIGNAL(load_image(QString)),
this, SLOT(load(QString)));
......@@ -252,6 +253,11 @@ Viewer::load_xml(QString filename)
void
Viewer::xml_to_layout()
{
/* /!\ XML parsing is VERY UGLY /!\
TO DO: use same parsing as xml_transfrom. */
// Add layout info to the scene.
if (doc_layout_)
{
......@@ -284,6 +290,7 @@ Viewer::xml_to_layout()
doc_layout_->data(point, Qt::UserRole).toMap();
int x = data["x"].toInt();
int y = data["y"].toInt();
points << QPoint(x, y);
}
......@@ -396,8 +403,8 @@ Viewer::xml_to_layout()
attributes_line, points_line,
outline_action_->isChecked(),
fill_action_->isChecked(),
precise_action_->isChecked(),
key_wgt_->isChecked(id_line));
precise_action_->isChecked(),
key_wgt_->isChecked(id_line));
connect(this, SIGNAL(key_updated(int, bool)),
r_line, SLOT(setDrawIfSameId(int, bool)));
......@@ -417,6 +424,7 @@ Viewer::xml_to_layout()
}
emit updated(doc_layout_);
key_wgt_->update_all();
}
}
......@@ -427,7 +435,7 @@ Viewer::load(QString filename)
scene_->clear();
scene_->update();
image_ = 0;
xml_file_ = "";
// 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.
......@@ -482,7 +490,7 @@ Viewer::maybeChangeCacheMode(qreal scale)
void Viewer::useExtended(bool b)
{
extended_mode_ = b;
key_wgt_->checkAll();
key_wgt_->update_all();
if (xml_file_ != QString(""))
load_xml(xml_file_);
......
......@@ -24,6 +24,7 @@ XmlWidget::XmlWidget()
title->setAlignment(Qt::AlignHCenter);
QVBoxLayout* layout = new QVBoxLayout;
layout->addWidget(title);
layout->addWidget(view_);
......@@ -34,7 +35,7 @@ void
XmlWidget::update(DomModel* model)
{
view_->setModel(model);
view_->resizeColumnToContents(2);
// view_->resizeColumnToContents(2);
}
void
......
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