text_controller.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "log.h"
00028 #include "text_tasks.h"
00029 #include "text_view.h"
00030 #include "text_controller.h"
00031
00032 namespace text
00033 {
00034
00035 TextController::TextController(TextModel *_model, TextView *_view)
00036 : model(_model)
00037 , view(_view)
00038 , pagination_paused(false)
00039 {
00040
00041 view->set_controller(this);
00042 }
00043
00044 TextController::~TextController()
00045 {
00046 }
00047
00048 void TextController::start()
00049 {
00050
00051 thread.start();
00052 }
00053
00054 void TextController::stop()
00055 {
00056
00057 thread.stop();
00058 }
00059
00060 void TextController::render(unsigned int id, unsigned int page_index, void *data, unsigned char* bmp)
00061 {
00062 Position start_pos;
00063 if (view->get_anchor_by_page(page_index, start_pos))
00064 {
00065 render(id, start_pos, data, bmp);
00066 }
00067 else
00068 {
00069 ERRORPRINTF("Can't render page %d because it does not exist.\n", page_index);
00070 }
00071 }
00072
00073 void TextController::render(unsigned int id, const Position& start_pos, void *data, unsigned char* bmp)
00074 {
00075 LOGPRINTF("About to launch render task.");
00076 view->check_page_table(start_pos);
00077 thread.prepend_task(new RenderTask(id, view, start_pos, data, bmp), true);
00078 }
00079
00080 void TextController::paginate(const Position& start, bool send_start_notification)
00081 {
00082 pagination_pending = true;
00083 PaginationTask *task = new PaginationTask(view, start, !send_start_notification);
00084 task->abort_signal.add_slot(this, &TextController::on_pagination_aborted);
00085 view->pagination_end_signal.add_slot(this, &TextController::on_pagination_finished);
00086 thread.append_task(task);
00087 }
00088
00089 void TextController::on_pagination_finished(unsigned int, unsigned int)
00090 {
00091 if (!pagination_paused)
00092 {
00093 pagination_pending = false;
00094 }
00095 }
00096
00097 void TextController::on_pagination_aborted(const Position& start)
00098 {
00099
00100
00101
00102
00103
00104
00105
00106 if ((!pagination_paused) && (!view->need_repagination()))
00107 {
00108 paginate(start, false );
00109 }
00110 }
00111
00112 void TextController::pause_pagination()
00113 {
00114 TRACEFUNCTION();
00115
00116 if (pagination_pending)
00117 {
00118 pagination_paused = true;
00119
00120 unsigned int total_pages = view->get_page_count();
00121 unsigned int current_page = view->get_current_page_index();
00122
00123
00124
00125
00126
00127
00128 view->pagination_end_signal.broadcast(current_page, total_pages);
00129
00130 PaginationAbortTask *task = new PaginationAbortTask(view);
00131 thread.prepend_task(task, true );
00132 }
00133 }
00134
00135 void TextController::restart_pagination()
00136 {
00137 TRACEFUNCTION();
00138
00139
00140
00141 if (pagination_pending)
00142 {
00143 pagination_paused = false;
00144
00145 Position start_pos;
00146 view->check_page_table(start_pos);
00147 paginate(start_pos, false );
00148 }
00149 }
00150
00151
00152 void TextController::search(SearchContext* search_context)
00153 {
00154 SearchTask* task = new SearchTask(model, search_context);
00155 task->abort_signal.add_slot(this, &TextController::on_search_aborted);
00156 thread.prepend_task(task, true);
00157 }
00158
00159 void TextController::on_search_aborted(SearchContext* sc)
00160 {
00161 SearchTask* task = new SearchTask(model, sc);
00162 task->abort_signal.add_slot(this, &TextController::on_search_aborted);
00163 thread.prepend_task(task, false);
00164 }
00165
00166 }
00167