Commit 272f7772 authored by Philipp Erhardt's avatar Philipp Erhardt
Browse files

Implement freezing the projector window

parent 01a9f7ee
......@@ -26,7 +26,7 @@ pixel) scrolling, zooming and adjusting the column count. Pages keep their
correct relative size and are shown in a grid.
The 'presenter layout' is for giving a presentation. It opens a second window,
to be viewed on the beamer, and shows the current and next slide in the main
to be viewed on the projector, and shows the current and next slide in the main
window.
For every file passed on the command line a separate process is spawned.
......@@ -73,7 +73,7 @@ KEY BINDINGS
*3* ::
Switch to 'presenter layout'. Views the current page and a smaller preview
of the next page. Also, opens a second window that shows only the current
page for displaying on a beamer.
page for displaying on a projector.
*Up*, *Down*, *Left*, *Right*, *k*, *j*, *h*, *l* ::
Move around (up/down/left/right).
......@@ -138,6 +138,9 @@ KEY BINDINGS
Show a file dialog to save the current document.
*F9* ::
Toggle the table of contents.
*x* ::
Toggle freezing the slide currently displayed in the projector window. When
frozen, scrolling only affects the main window.
VARIABLES
---------
......
......@@ -75,3 +75,4 @@ reload=R
open=O
save=S
toggle_toc=F9
freeze_presentation=X
......@@ -14,6 +14,7 @@ using namespace std;
BeamerWindow::BeamerWindow(Viewer *v, QWidget *parent) :
QWidget(parent),
viewer(v),
frozen(false),
valid(false) {
setFocusPolicy(Qt::StrongFocus);
......@@ -38,6 +39,15 @@ BeamerWindow::~BeamerWindow() {
delete layout;
}
void BeamerWindow::freeze(bool f) {
frozen = f;
viewer->get_canvas()->update_page_overlay();
}
bool BeamerWindow::is_frozen() const {
return frozen;
}
bool BeamerWindow::is_valid() const {
return valid;
}
......
......@@ -15,6 +15,9 @@ public:
BeamerWindow(Viewer *v, QWidget *parent = 0);
~BeamerWindow();
void freeze(bool f);
bool is_frozen() const;
bool is_valid() const;
Layout *get_layout() const;
......@@ -43,6 +46,7 @@ private:
Qt::MouseButton click_link_button;
bool frozen;
bool valid;
};
......
......@@ -168,10 +168,14 @@ Layout *Canvas::get_layout() const {
}
void Canvas::update_page_overlay() {
QString frozen_text;
if (viewer->get_beamer()->is_frozen()) {
frozen_text = QString("Frozen: %1, ").arg(viewer->get_beamer()->get_layout()->get_page() + 1);
}
QString overlay_text = CFG::get_instance()->get_value("Settings/page_overlay_text").toString()
.arg(cur_layout->get_page() + 1)
.arg(viewer->get_res()->get_page_count());
page_overlay->setText(overlay_text);
page_overlay->setText(frozen_text + overlay_text);
page_overlay->adjustSize();
page_overlay->move(width() - page_overlay->width(), height() - page_overlay->height());
}
......@@ -371,7 +375,9 @@ void Canvas::set_presenter_layout() {
// int cur_screen = desktop->screenNumber(viewer);
// cout << "primary: " << primary_screen << ", current: " << cur_screen << endl;
// }
viewer->get_beamer()->get_layout()->scroll_page(cur_layout->get_page(), false);
if (!viewer->get_beamer()->is_frozen()) {
viewer->get_beamer()->get_layout()->scroll_page(cur_layout->get_page(), false);
}
viewer->get_beamer()->show();
viewer->show_progress(true);
}
......
......@@ -101,6 +101,7 @@ void CFG::init_defaults() {
vk.push_back("Keys/open"); keys[vk.back()] = QStringList() << "O";
vk.push_back("Keys/save"); keys[vk.back()] = QStringList() << "S";
vk.push_back("Keys/toggle_toc"); keys[vk.back()] = QStringList() << "F9";
vk.push_back("Keys/freeze_presentation"); keys[vk.back()] = QStringList() << "X";
// tmp values
tmp_values["start_page"] = 0;
......
......@@ -420,7 +420,7 @@ void GridLayout::render(QPainter *painter) {
}
last_visible_page = last_page;
res->collect_garbage(page + horizontal_page - grid->get_offset() - prefetch_count * 3, last_page + prefetch_count * 3);
res->collect_garbage(page + horizontal_page - grid->get_offset() - prefetch_count * 3, last_page + prefetch_count * 3, render_index);
// prefetch
int prefetch_first = page + horizontal_page - grid->get_offset() - 1;
......
......@@ -190,7 +190,9 @@ void PresenterLayout::render(QPainter *painter) {
res->unlock_page(page - count);
}
}
res->collect_garbage(page - prefetch_count * 3, page + 1 + prefetch_count * 3);
for (int i = 0; i < 2; i++) {
res->collect_garbage(page - prefetch_count * 3, page + 1 + prefetch_count * 3, render_index + i);
}
}
void PresenterLayout::advance_invisible_hit(bool forward) {
......
......@@ -112,7 +112,7 @@ void SingleLayout::render(QPainter *painter) {
res->unlock_page(page - count);
}
}
res->collect_garbage(page - prefetch_count * 3, page + prefetch_count * 3);
res->collect_garbage(page - prefetch_count * 3, page + prefetch_count * 3, render_index);
}
void SingleLayout::advance_invisible_hit(bool forward) {
......
......@@ -132,7 +132,9 @@ void ResourceManager::shutdown() {
join_threads();
}
garbageMutex.lock();
garbage.clear();
for (int i = 0; i < 3; i++) {
garbage[i].clear();
}
garbageMutex.unlock();
requests.clear();
requestSemaphore.acquire(requestSemaphore.available());
......@@ -217,29 +219,29 @@ bool ResourceManager::are_colors_inverted() const {
return inverted_colors;
}
void ResourceManager::collect_garbage(int keep_min, int keep_max) {
void ResourceManager::collect_garbage(int keep_min, int keep_max, int index) {
requestMutex.lock();
center_page = (keep_min + keep_max) / 2;
if (index == 0) { // make a separate center_page for each index?
center_page = (keep_min + keep_max) / 2;
}
requestMutex.unlock();
// free distant pages
garbageMutex.lock();
for (set<int>::iterator it = garbage.begin(); it != garbage.end(); /* empty */) {
for (set<int>::iterator it = garbage[index].begin(); it != garbage[index].end(); /* empty */) {
int page = *it;
if (page >= keep_min && page <= keep_max) {
++it; // move on
continue;
}
garbage.erase(it++); // erase and move on (iterator becomes invalid)
garbage[index].erase(it++); // erase and move on (iterator becomes invalid)
#ifdef DEBUG
cerr << " removing page " << page << endl;
#endif
k_page[page].mutex.lock();
for (int i = 0; i < 3; i++) {
k_page[page].img[i] = QImage();
k_page[page].img_other[i] = QImage();
k_page[page].status[i] = 0;
k_page[page].rotation[i] = 0;
}
k_page[page].img[index] = QImage();
k_page[page].img_other[index] = QImage();
k_page[page].status[index] = 0;
k_page[page].rotation[index] = 0;
k_page[page].mutex.unlock();
}
garbageMutex.unlock();
......
......@@ -60,7 +60,7 @@ public:
void invert_colors();
bool are_colors_inverted() const;
void collect_garbage(int keep_min, int keep_max);
void collect_garbage(int keep_min, int keep_max, int index);
void connect_canvas() const;
......
......@@ -444,6 +444,15 @@ void Viewer::toggle_toc() {
toc->setFocus(Qt::OtherFocusReason); // only works if shown
}
void Viewer::freeze_presentation() {
if (beamer->is_frozen()) {
beamer->freeze(false);
beamer->get_layout()->scroll_page(canvas->get_layout()->get_page(), false);
} else {
beamer->freeze(true);
}
}
void Viewer::update_info_widget() {
if (!res->is_valid() || !search_bar->is_valid()) {
QIcon icon;
......@@ -499,7 +508,7 @@ BeamerWindow *Viewer::get_beamer() const {
void Viewer::layout_updated(int new_page, bool page_changed) {
if (page_changed) {
canvas->get_layout()->scroll_page(new_page, false);
if (beamer->isVisible()) {
if (beamer->isVisible() && !beamer->is_frozen()) {
beamer->get_layout()->scroll_page(new_page, false);
}
// TODO unfold toc tree to show current entry?
......@@ -584,5 +593,6 @@ void Viewer::setup_keys(QWidget *base) {
add_action(base, "Keys/open", SLOT(open()), this);
add_action(base, "Keys/save", SLOT(save()), this);
add_action(base, "Keys/toggle_toc", SLOT(toggle_toc()), this);
add_action(base, "Keys/freeze_presentation", SLOT(freeze_presentation()), this);
}
......@@ -83,6 +83,7 @@ private slots:
void open(); // ask user for filename
void save();
void toggle_toc();
void freeze_presentation();
private:
void update_info_widget();
......
......@@ -84,7 +84,7 @@ void Worker::run() {
// open page
#ifdef DEBUG
cerr << " rendering page " << page << " for index " << index << endl;
cerr << " rendering page " << page << " for index " << index << ", center: " << res->center_page << endl;
#endif
Poppler::Page *p = NULL;
if (render_new) {
......@@ -153,7 +153,7 @@ void Worker::run() {
kp.mutex.unlock();
res->garbageMutex.lock();
res->garbage.insert(page); // TODO add index information?
res->garbage[index].insert(page);
res->garbageMutex.unlock();
emit page_rendered(page);
......
Markdown is supported
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