Commit d02047f7 authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

Add a GUI for AFP's use case.

	* lazzara/afp/photos/gui/gui.pro,
	* lazzara/afp/photos/gui/gui.qrc,
	* lazzara/afp/photos/gui/icons/next.png,
	* lazzara/afp/photos/gui/icons/ok.png,
	* lazzara/afp/photos/gui/icons/photos.png,
	* lazzara/afp/photos/gui/icons/prev.png,
	* lazzara/afp/photos/gui/icons/remove.png,
	* lazzara/afp/photos/gui/src/custom_delegate.cc,
	* lazzara/afp/photos/gui/src/custom_delegate.hh,
	* lazzara/afp/photos/gui/src/launch_dialog.cc,
	* lazzara/afp/photos/gui/src/launch_dialog.hh,
	* lazzara/afp/photos/gui/src/main.cc,
	* lazzara/afp/photos/gui/src/main_window.cc,
	* lazzara/afp/photos/gui/src/main_window.hh,
	* lazzara/afp/photos/gui/ui/launch_dialog.ui,
	* lazzara/afp/photos/gui/ui/main_window.ui: New files. GUI meant
	to display the results of text finding in pictures.
parent 8d47be15
2010-02-16 Guillaume Lazzara <z@lrde.epita.fr>
Add a GUI for AFP's use case.
* lazzara/afp/photos/gui/gui.pro,
* lazzara/afp/photos/gui/gui.qrc,
* lazzara/afp/photos/gui/icons/next.png,
* lazzara/afp/photos/gui/icons/ok.png,
* lazzara/afp/photos/gui/icons/photos.png,
* lazzara/afp/photos/gui/icons/prev.png,
* lazzara/afp/photos/gui/icons/remove.png,
* lazzara/afp/photos/gui/src/custom_delegate.cc,
* lazzara/afp/photos/gui/src/custom_delegate.hh,
* lazzara/afp/photos/gui/src/launch_dialog.cc,
* lazzara/afp/photos/gui/src/launch_dialog.hh,
* lazzara/afp/photos/gui/src/main.cc,
* lazzara/afp/photos/gui/src/main_window.cc,
* lazzara/afp/photos/gui/src/main_window.hh,
* lazzara/afp/photos/gui/ui/launch_dialog.ui,
* lazzara/afp/photos/gui/ui/main_window.ui: New files. GUI meant
to display the results of text finding in pictures.
2010-03-22 Guillaume Lazzara <z@lrde.epita.fr>
Add new benchs.
......
######################################################################
# Automatically generated by qmake (2.01a) Wed Nov 25 13:42:17 2009
######################################################################
TEMPLATE = app
TARGET =
DEPENDPATH += . src ui
INCLUDEPATH += . src
CONFIG += release
# Input
HEADERS += src/main_window.hh src/custom_delegate.hh src/launch_dialog.hh
FORMS += ui/main_window.ui ui/launch_dialog.ui
SOURCES += src/main.cc src/main_window.cc src/custom_delegate.cc src/launch_dialog.cc
RESOURCES = gui.qrc
<RCC>
<qresource prefix="/" >
<file>icons/next.png</file>
<file>icons/ok.png</file>
<file>icons/photos.png</file>
<file>icons/prev.png</file>
<file>icons/remove.png</file>
</qresource>
</RCC>
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
// Olena 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, version 2 of the License.
//
// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
//
// As a special exception, you may use this file as part of a free
// software project without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to produce
// an executable, this file does not by itself cause the resulting
// executable to be covered by the GNU General Public License. This
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
#include <src/custom_delegate.hh>
#include <QtCore/QtCore>
namespace mln
{
namespace demo
{
custom_delegate::custom_delegate(QObject * parent)
: QItemDelegate(parent),
bg_(Qt::black, Qt::SolidPattern),
selected_bg_(QColor(255, 100, 0), Qt::Dense5Pattern)
{
display_rect_.setSize(QSize(149, 30));
decoration_rect_.setSize(QSize(150, 150));
}
custom_delegate::~custom_delegate()
{
}
void
custom_delegate::drawDecoration(QPainter *painter,
const QStyleOptionViewItem& option,
const QRect& rect,
const QPixmap& pixmap) const
{
decoration_rect_.moveTo(option.rect.x() + 10, option.rect.y() + 10);
painter->fillRect(decoration_rect_, bg_);
super_::drawDecoration(painter, option, decoration_rect_, pixmap);
}
void
custom_delegate::drawBackground(QPainter *painter,
const QStyleOptionViewItem& option,
const QModelIndex& index) const
{
super_::drawBackground(painter, option, index);
}
void
custom_delegate::drawCheck(QPainter *painter,
const QStyleOptionViewItem& option,
const QRect& rect,
Qt::CheckState state) const
{
super_::drawCheck(painter, option, rect, state);
}
void
custom_delegate::drawDisplay(QPainter* painter,
const QStyleOptionViewItem& option,
const QRect& rect,
const QString& text) const
{
display_rect_.moveTo(option.rect.x() + 10,
option.rect.y() + 155);
super_::drawDisplay(painter, option, display_rect_, text);
painter->drawRect(display_rect_);
}
void
custom_delegate::drawFocus(QPainter* painter,
const QStyleOptionViewItem& option,
const QRect& rect ) const
{
super_::drawFocus(painter, option, display_rect_);
}
} // end of namespace mln::demo
} // end of namespace mln
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
// Olena 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, version 2 of the License.
//
// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
//
// As a special exception, you may use this file as part of a free
// software project without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to produce
// an executable, this file does not by itself cause the resulting
// executable to be covered by the GNU General Public License. This
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
# include <QtGui/QtGui>
namespace mln
{
namespace demo
{
class custom_delegate : public QItemDelegate
{
typedef QItemDelegate super_;
public:
custom_delegate(QObject * parent = 0);
~custom_delegate();
void
drawDecoration(QPainter *painter,
const QStyleOptionViewItem& option,
const QRect& rect,
const QPixmap& pixmap) const;
void drawBackground(QPainter *painter,
const QStyleOptionViewItem& option,
const QModelIndex& index) const;
void drawCheck(QPainter *painter,
const QStyleOptionViewItem& option,
const QRect& rect,
Qt::CheckState state) const;
void
drawDisplay(QPainter* painter,
const QStyleOptionViewItem& option,
const QRect& rect,
const QString& text) const;
void
drawFocus(QPainter* painter,
const QStyleOptionViewItem& option,
const QRect& rect ) const;
private:
mutable QRect display_rect_;
mutable QRect decoration_rect_;
QBrush bg_;
QBrush selected_bg_;
};
} // end of namespace mln::demo
} // end of namespace mln
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
// Olena 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, version 2 of the License.
//
// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
//
// As a special exception, you may use this file as part of a free
// software project without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to produce
// an executable, this file does not by itself cause the resulting
// executable to be covered by the GNU General Public License. This
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
#include <QtCore>
#include <QtGui>
#include <src/launch_dialog.hh>
#include <src/custom_delegate.hh>
namespace mln
{
namespace demo
{
launch_dialog::launch_dialog(QWidget *parent)
: QDialog(parent)
{
setupUi(this);
}
launch_dialog::~launch_dialog()
{
}
void
launch_dialog::on_browseBtn_clicked(bool)
{
QString dirname = QFileDialog::getExistingDirectory(this, "");
if (!dirname.isEmpty())
{
pathToPics->setText(dirname);
}
}
void
launch_dialog::on_dialogBtnBox_accepted()
{
emit ok_clicked(pathToPics->text(), checkBox->isChecked());
}
void
launch_dialog::on_pathToPics_textChanged(const QString& str)
{
dialogBtnBox->button(QDialogButtonBox::Ok)->setEnabled(!str.isEmpty());
}
} // end of namespace scribo::demo
} // end of namespace scribo
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
// Olena 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, version 2 of the License.
//
// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
//
// As a special exception, you may use this file as part of a free
// software project without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to produce
// an executable, this file does not by itself cause the resulting
// executable to be covered by the GNU General Public License. This
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
#ifndef MLN_DEMO_SRC_LAUNCH_DIALOG_HH
# include <QtGui>
# include <ui_launch_dialog.h>
namespace mln
{
namespace demo
{
class launch_dialog : public QDialog, private Ui::LaunchDialog
{
Q_OBJECT
public:
launch_dialog(QWidget *parent = 0);
~launch_dialog();
private slots:
void on_dialogBtnBox_accepted();
void on_browseBtn_clicked(bool);
void on_pathToPics_textChanged(const QString& str);
signals:
void ok_clicked(const QString& path, bool fgbg);
};
} // end of namespace mln::demo
} // end of namespace mln
#endif // ! MLN_DEMO_SRC_LAUNCH_DIALOG_HH
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
// Olena 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, version 2 of the License.
//
// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
//
// As a special exception, you may use this file as part of a free
// software project without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to produce
// an executable, this file does not by itself cause the resulting
// executable to be covered by the GNU General Public License. This
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
#include <QApplication>
#include <QtGui>
#include <src/main_window.hh>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
if (argc < 2)
{
qDebug() << "Usage: " << argv[0] << " <path/text_in_photo_ppm>";
return 1;
}
mln::demo::main_window win(argv[1]);
win.show();
return app.exec();
}
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
// Olena 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, version 2 of the License.
//
// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
//
// As a special exception, you may use this file as part of a free
// software project without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to produce
// an executable, this file does not by itself cause the resulting
// executable to be covered by the GNU General Public License. This
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
#include <QtCore>
#include <QtGui>
#include <src/main_window.hh>
#include <src/launch_dialog.hh>
#include <src/custom_delegate.hh>
namespace mln
{
namespace demo
{
main_window::main_window(const QString& text_in_photo_ppm, QWidget *parent)
: QMainWindow(parent), text_in_photo_ppm_(text_in_photo_ppm)
{
setupUi(this);
// Temporary output directory
output_dir_ = "/tmp/";
// Setup directory listing
QStringList filters;
filters << "*.ppm";
dir_.setNameFilters(filters);
dir_.setFilter(QDir::Files);
dir_.setSorting(QDir::Name);
// Setup Signal/Slots connections
connect(&process_, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(process__error_slot(QProcess::ProcessError)));
connect(&process_,
SIGNAL(finished(int, QProcess::ExitStatus)),
this,
SLOT(process__finished_slot(int, QProcess::ExitStatus)));
// Setup graphicsView
graphicsView->setScene(new QGraphicsScene());
// Setup StatusBar
QStatusBar *status = new QStatusBar();
setStatusBar(status);
status->addWidget(&progressLabel_);
status->addWidget(&progressBar_);
QPushButton *cancelBtn = new QPushButton(tr("Cancel"));
connect(cancelBtn, SIGNAL(clicked(bool)),
this, SLOT(cancel_clicked(bool)));
status->addWidget(cancelBtn);
statusBar()->hide();
// Customize item view delegate for picture with text.
withTextListWidget->setItemDelegate(new custom_delegate());
// Setup Toolbar.
toolbar_ = new QToolBar(tr("Action"));
toolbar_->setToolButtonStyle(Qt::ToolButtonIconOnly);
QAction *removeImage = new QAction(QIcon(":/icons/remove.png"),
tr("Tag as image without text"),
toolbar_);
connect(removeImage, SIGNAL(triggered(bool)),
this, SLOT(remove_image(bool)));
toolbar_->addAction(removeImage);
addToolBar(toolbar_);
// Hide visualization buttons
textOnlyButton->hide();
fullImageButton->hide();
textBoxesButton->hide();
textMaskButton->hide();
// Set default visualization.
textBoxesButton->setChecked(true);
actionText_Boxes->setChecked(true);
QActionGroup * actionGroup = new QActionGroup(this);
actionGroup->addAction(actionText_Boxes);
actionGroup->addAction(actionFull_Image);
actionGroup->addAction(action_Text_Only);
actionGroup->addAction(actionText_Mask);
actionGroup->setExclusive(true);
}
main_window::~main_window()
{
if (process_.state() == QProcess::Running)
{
process_.disconnect();
process_.close();
}
}
void
main_window::on_actionScan_directory_triggered()
{
launch_dialog *dialog = new launch_dialog(this);
connect(dialog, SIGNAL(ok_clicked(const QString&, bool)),
this, SLOT(init_and_start_process(const QString&, bool)));
dialog->show();
}
void
main_window::init_and_start_process(const QString& dirname, bool bgfg)
{
dir_.setPath(dirname);
file_list_ = dir_.entryInfoList();
current_file_ = 0;
withTextListWidget->clear();
withoutTextListWidget->clear();
statusBar()->show();
progressLabel_.setText(tr("Processing images..."));
progressBar_.setRange(0, file_list_.size());
progressBar_.setValue(0);
bgfg_ = bgfg;
start_process();
}
void
main_window::next_process()
{
++current_file_;
progressBar_.setValue(current_file_);
tabWidget->setTabText(0,
QString(tr("With text (%1)"))
.arg(withTextListWidget->count()));
tabWidget->setTabText(1,
QString(tr("Without text (%1)"))