Commit b24643cc authored by Philipp Erhardt's avatar Philipp Erhardt
Browse files

Implement command line options

Currently supported options are:
	- page NUM
	- fullscreen
	- help
parent bdb25128
......@@ -13,7 +13,7 @@ using namespace std;
#define SMOOTH_SCROLL_DELTA 30 // pixel scroll offset
Canvas::Canvas(Viewer *v, QWidget *parent) :
Canvas::Canvas(Viewer *v, int start_page, QWidget *parent) :
QWidget(parent),
viewer(v),
draw_overlay(true),
......@@ -21,6 +21,7 @@ Canvas::Canvas(Viewer *v, QWidget *parent) :
setFocusPolicy(Qt::StrongFocus);
layout = new PresentationLayout(viewer->get_res());
layout->scroll_page(start_page, false); // apply start option
// prints the string representation of a key
// cerr << QKeySequence(Qt::Key_Equal).toString().toUtf8().constData() << endl;
......
......@@ -30,7 +30,7 @@ class Canvas : public QWidget {
typedef void (Canvas::*func_t)();
public:
Canvas(Viewer *v, QWidget *parent = 0);
Canvas(Viewer *v, int start_page = 0, QWidget *parent = 0);
~Canvas();
bool is_valid() const;
......
......@@ -10,7 +10,7 @@ katarakt - a simple PDF viewer with two layouts
SYNOPSIS
--------
*katarakt* 'FILE'
*katarakt* ['OPTIONS'] 'FILE'
DESCRIPTION
-----------
......@@ -25,6 +25,15 @@ The 'grid layout' is much more advanced and offers continuous (smooth, per
pixel) scrolling, zooming and adjusting the column count. Pages keep their
correct relative size and are shown in a grid.
OPTIONS
-------
*-p*, *--page* 'NUM'::
Start showing page 'NUM'.
*-f*, *--fullscreen*::
Start in fullscreen mode.
*-h*, *--help*::
Print help and exit.
KEY BINDINGS
------------
*q* ::
......
#include <QApplication>
#include <QString>
#include <iostream>
#include <getopt.h>
#include "resourcemanager.h"
#include "viewer.h"
using namespace std;
static void print_help(char *name) {
cout << "Usage:" << endl;
cout << " " << name << " [OPTIONS] FILE" << endl;
cout << endl;
cout << "Options:" << endl;
cout << " -p, --page NUM Start showing page NUM" << endl;
cout << " -f, --fullscreen Start in fullscreen mode" << endl;
cout << " -h, --help Print this help and exit" << endl;
}
int main(int argc, char *argv[]) {
using namespace std;
QApplication app(argc, argv);
if (argc != 2) {
cerr << "usage: " << argv[0] << " <path>" << endl;
// parse command line options
int start_page = 0;
bool fullscreen = false;
struct option long_options[] = {
{"page", required_argument, NULL, 'p'},
{"fullscreen", no_argument, NULL, 'f'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}
};
int c;
int option_index = 0;
while (1) {
c = getopt_long(argc, argv, "+p:fh", long_options, &option_index);
if (c == -1) {
break;
}
switch (c) {
case 'p':
// currently no warning message on wrong input
start_page = atoi(optarg) - 1;
break;
case 'f':
fullscreen = true;
break;
case 'h':
print_help(argv[0]);
return 0;
default:
// getopt prints an error message
return 1;
}
}
if (argv[optind] == NULL) {
cerr << "Not enough arguments" << endl;
return 1;
}
Viewer katarakt(QString::fromUtf8(argv[1]));
Viewer katarakt(QString::fromUtf8(argv[optind]), start_page, fullscreen);
if (!katarakt.is_valid()) {
return 1;
}
......
......@@ -13,8 +13,7 @@ using namespace std;
int Viewer::sig_fd[2];
//Viewer::Viewer(ResourceManager *res, QWidget *parent) :
Viewer::Viewer(QString _file, QWidget *parent) :
Viewer::Viewer(QString _file, int start_page, bool fullscreen, QWidget *parent) :
QWidget(parent),
file(_file),
res(NULL),
......@@ -29,7 +28,7 @@ Viewer::Viewer(QString _file, QWidget *parent) :
return;
}
canvas = new Canvas(this, this);
canvas = new Canvas(this, start_page, this);
if (!canvas->is_valid()) {
valid = false;
return;
......@@ -82,6 +81,11 @@ Viewer::Viewer(QString _file, QWidget *parent) :
resize(500, 500);
show();
search_bar->hide();
// apply start options
if (fullscreen) {
toggle_fullscreen();
}
}
Viewer::~Viewer() {
......
......@@ -3,7 +3,6 @@
#include <QWidget>
#include <QVBoxLayout>
//#include <QLineEdit>
#include <QKeySequence>
#include <QSocketNotifier>
#include <map>
......@@ -20,8 +19,7 @@ class Viewer : public QWidget {
typedef void (Viewer::*func_t)();
public:
// Viewer(ResourceManager *res, QWidget *parent = 0);
Viewer(QString _file, QWidget *parent = 0);
Viewer(QString _file, int start_page, bool fullscreen, QWidget *parent = 0);
~Viewer();
bool is_valid() const;
......@@ -47,7 +45,6 @@ private:
ResourceManager *res;
Canvas *canvas;
SearchBar *search_bar;
// QLineEdit *search_bar;
QVBoxLayout *layout;
// signal handling
......
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