Commit 3eb8317c authored by Philipp Erhardt's avatar Philipp Erhardt
Browse files

Implement toggleable color inversion ('i' key)

parent 4fff3193
......@@ -91,6 +91,8 @@ KEY BINDINGS
Rotate pages left/right
*\^o*, *^i*, *Alt-Left*, *Alt-Right* ::
Move backward/forward through the jump list. Entries are added automatically when jumping
*i* ::
Toggle between normal and inverted color rendering
VARIABLES
---------
......
......@@ -49,6 +49,7 @@ rotate_left=,
rotate_right=.
jump_back=Ctrl+O, Alt+Left
jump_forward=Ctrl+I, Alt+Right
toggle_invert_colors=I
toggle_fullscreen=F
close_search=Esc
reload=R
......
......@@ -84,6 +84,7 @@ Canvas::Canvas(Viewer *v, QWidget *parent) :
add_action("rotate_right", SLOT(rotate_right()));
add_action("jump_back", SLOT(jump_back()));
add_action("jump_forward", SLOT(jump_forward()));
add_action("toggle_invert_colors", SLOT(invert_colors()));
// prints the string representation of a key
// cerr << QKeySequence(Qt::Key_Equal).toString().toUtf8().constData() << endl;
......@@ -169,6 +170,11 @@ void Canvas::jump_forward() {
}
}
void Canvas::invert_colors() {
viewer->get_res()->invert_colors();
update();
}
Layout *Canvas::get_layout() const {
return cur_layout;
}
......
......@@ -81,6 +81,7 @@ private slots:
void rotate_right();
void jump_back();
void jump_forward();
void invert_colors();
private:
void add_action(const char *action, const char *slot);
......
......@@ -68,6 +68,7 @@ CFG::CFG() :
keys["rotate_right"] = QStringList() << ".";
keys["jump_back"] = QStringList() << "Ctrl+O" << "Alt+Left";
keys["jump_forward"] = QStringList() << "Ctrl+I" << "Alt+Right";
keys["toggle_invert_colors"] = QStringList() << "i";
// viewer keys
keys["toggle_fullscreen"] = QStringList() << "F";
keys["close_search"] = QStringList() << "Esc";
......
......@@ -10,7 +10,8 @@ using namespace std;
//==[ Katarakt Page ]==========================================================
KPage::KPage() :
links(NULL) {
links(NULL),
inverted_colors(false) {
for (int i = 0; i < 3; i++) {
status[i] = 0;
rotation[i] = 0;
......@@ -138,11 +139,25 @@ void Worker::run() {
continue;
}
// invert to current color setting
if (res->inverted_colors) {
img.invertPixels();
}
// put page
res->k_page[page].mutex.lock();
if (!res->k_page[page].img[index].isNull()) {
res->k_page[page].img[index] = QImage(); // assign null image
}
// adjust all available images to current color setting
if (res->k_page[page].inverted_colors != res->inverted_colors) {
res->k_page[page].inverted_colors = res->inverted_colors;
for (int i = 0; i < 3; i++) {
res->k_page[page].img[i].invertPixels();
}
res->k_page[page].thumbnail.invertPixels();
}
res->k_page[page].img[index] = img;
res->k_page[page].status[index] = width;
res->k_page[page].rotation[index] = rotation;
......@@ -182,7 +197,8 @@ void Worker::run() {
ResourceManager::ResourceManager(QString file) :
doc(NULL),
center_page(0),
rotation(0) {
rotation(0),
inverted_colors(false) {
// load config options
CFG *config = CFG::get_instance();
smooth_downscaling = config->get_value("smooth_downscaling").toBool();
......@@ -305,6 +321,13 @@ const KPage *ResourceManager::get_page(int page, int width, int index) {
k_page[page].rotation[index] != rotation) {
enqueue(page, width, index);
}
if (inverted_colors != k_page[page].inverted_colors) {
k_page[page].inverted_colors = inverted_colors;
for (int i = 0; i < 3; i++) {
k_page[page].img[i].invertPixels();
}
k_page[page].thumbnail.invertPixels();
}
return &k_page[page];
}
......@@ -334,6 +357,7 @@ void ResourceManager::collect_garbage(int keep_min, int keep_max) {
// find the index of the rendered image
for (int i = 0; i < 3; i++) {
if (!k_page[page].img[i].isNull()) {
// k_page[page].inverted_colors = inverted_colors;
// scale
k_page[page].thumbnail = k_page[page].img[i].scaled(
QSize(thumbnail_size, thumbnail_size),
......@@ -391,6 +415,10 @@ void ResourceManager::unlock_page(int page) const {
k_page[page].mutex.unlock();
}
void ResourceManager::invert_colors() {
inverted_colors = !inverted_colors;
}
void ResourceManager::enqueue(int page, int width, int index) {
requestMutex.lock();
map<int,pair<int,int> >::iterator it = requests.find(page);
......
......@@ -36,6 +36,7 @@ private:
QMutex mutex;
int status[3];
char rotation[3];
bool inverted_colors; // img[]s and thumb must be consistent
friend class Worker;
friend class ResourceManager;
......@@ -86,6 +87,7 @@ public:
int get_rotation() const;
void rotate(int value, bool relative = true);
void unlock_page(int page) const;
void invert_colors();
void collect_garbage(int keep_min, int keep_max);
......@@ -123,6 +125,7 @@ private:
// config options
bool smooth_downscaling;
int thumbnail_size;
bool inverted_colors;
};
#endif
......
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