Add .gitignore
[qcomicbook-oblomov] / src / pagenumberedit.cpp
1 /*
2  * This file is a part of QComicBook.
3  *
4  * Copyright (C) 2005-2006 Pawel Stolowski <yogin@linux.bydg.org>
5  *
6  * QComicBook is free software; you can redestribute it and/or modify it
7  * under terms of GNU General Public License by Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY. See GPL for more details.
11  */
12
13 #include "pagenumberedit.h"
14 #include <qvalidator.h>
15
16 using namespace QComicBook;
17
18 PageNumberEdit::PageNumberEdit(QWidget *parent, int val, int max): QLineEdit(parent)
19 {
20         //setMaxLength(3);
21         //setFocusPolicy(QWidget::ClickFocus);
22         validator = new QIntValidator(1, max, this);
23         setValidator(validator);
24         if (val<1)
25                 val = 1;
26         else if (val>max)
27                 val = max;
28         setText(QString::number(val));
29         connect(this, SIGNAL(returnPressed()), this, SLOT(onReturn()));
30 }
31
32 PageNumberEdit::~PageNumberEdit()
33 {
34 }
35
36 void PageNumberEdit::setMax(int n)
37 {
38         validator->setTop(n);
39 }
40
41 void PageNumberEdit::onReturn()
42 {
43         emit pageSelected(pageNumber());
44 }
45
46 int PageNumberEdit::pageNumber() const
47 {
48         return text().toInt() - 1;
49 }
50
51 void PageNumberEdit::selectAll()
52 {
53         //do nothing - just override default QLineEdit behavior
54 }
55