Subversion Repositories Scribus

Rev

Rev 17163 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
199 Franz 7
#include "pageselector.h"
8
 
10859 cbradney 9
#include <QEvent>
9878 fschmid 10
#include <QLineEdit>
3053 avox 11
#if OPTION_USE_QTOOLBUTTON
9878 fschmid 12
    #include <QToolButton>
3053 avox 13
#else
9878 fschmid 14
    #include <QPushButton>
3053 avox 15
#endif
13243 pierre 16
#include <QLabel>
9878 fschmid 17
#include <QToolTip>
18
#include <QRegExp>
19
#include <QPixmap>
20
#include <QHBoxLayout>
21
#include <QValidator>
3457 avox 22
#include "sccombobox.h"
10200 cbradney 23
#include "util_icon.h"
10648 fschmid 24
#include "util.h"
199 Franz 25
 
12724 subik 26
// QIntValidator does it better for us... PV
27
// class PageValidator : public QValidator
28
// {
29
// public:
30
//      PageValidator(int min, int max, QObject * parent);
31
//      void fixup(QString & input) const;
32
//      State validate(QString & input, int & pos) const;
33
// private:
34
//      QRegExp rx;
35
//      QRegExp rx2;
36
//      PageSelector * pageSelector;
37
// };
38
// 
39
// PageValidator::PageValidator(int /* min */, int /* max */, QObject * parent) : QValidator
40
// (parent), rx("^([0-9]+).*"), rx2("^[0-9]+$") 
41
// {
42
//      pageSelector = static_cast<PageSelector*>(parent);
43
// }
44
// 
45
// QValidator::State PageValidator::validate(QString & input, int & /* pos */) const
46
// {
47
//      if (rx2.indexIn(input) == 0 && pageSelector->PageCombo->itemText(input.toInt()-1) == input)
48
//              return Acceptable;
49
//      else
50
//              return Intermediate;
51
// }
52
// 
53
// void PageValidator::fixup(QString & input) const
54
// {
55
//      if (rx.indexIn(input) == 0)
56
//              input = const_cast<QRegExp &>(rx).cap(1);
57
// }
58
//      
3053 avox 59
 
10469 cbradney 60
PageSelector::PageSelector( QWidget* parent, int maxPg ) : QWidget( parent, 0 )
199 Franz 61
{
13243 pierre 62
        PageCountString = "%1" ;
199 Franz 63
        LastPG = maxPg;
64
        APage = 1;
9878 fschmid 65
        PageSelectorLayout = new QHBoxLayout( this );
66
        PageSelectorLayout->setMargin(0);
67
        PageSelectorLayout->setSpacing(1);
199 Franz 68
 
3053 avox 69
#if OPTION_USE_QTOOLBUTTON
10469 cbradney 70
        Start = new QToolButton( this );
3053 avox 71
        Start->setAutoRaise(OPTION_FLAT_BUTTON);
10469 cbradney 72
        Back = new QToolButton( this );
3053 avox 73
        Back->setAutoRaise(OPTION_FLAT_BUTTON);
10469 cbradney 74
        Forward = new QToolButton( this );
3053 avox 75
        Forward->setAutoRaise(OPTION_FLAT_BUTTON);
10469 cbradney 76
        Last = new QToolButton( this );
3053 avox 77
        Last->setAutoRaise(OPTION_FLAT_BUTTON);
78
#else
10469 cbradney 79
        Start = new QPushButton( this );
199 Franz 80
        Start->setDefault( false );
81
        Start->setAutoDefault( false );
3053 avox 82
        Start->setFlat(OPTION_FLAT_BUTTON);
10469 cbradney 83
        Back = new QPushButton( this );
3053 avox 84
        Back->setDefault( false );
85
        Back->setAutoDefault( false );
86
        Back->setFlat(OPTION_FLAT_BUTTON);
10469 cbradney 87
        Forward = new QPushButton( this );
3053 avox 88
        Forward->setDefault( false );
89
        Forward->setAutoDefault( false );
90
        Forward->setFlat(OPTION_FLAT_BUTTON);
10469 cbradney 91
        Last = new QPushButton( this );
3053 avox 92
        Last->setDefault( false );
93
        Last->setAutoDefault( false );
94
        Last->setFlat(OPTION_FLAT_BUTTON);
95
#endif
9878 fschmid 96
        Start->setIcon(QIcon(loadIcon("16/go-first.png")));
8547 cbradney 97
        Start->setFocusPolicy(Qt::NoFocus);
199 Franz 98
        PageSelectorLayout->addWidget( Start );
99
 
9878 fschmid 100
        Back->setIcon(QIcon(loadIcon("16/go-previous.png")));
8547 cbradney 101
        Back->setFocusPolicy(Qt::NoFocus);
3238 avox 102
        Back->setAutoRepeat(true);
199 Franz 103
        PageSelectorLayout->addWidget( Back );
104
 
12724 subik 105
//      v = new PageValidator(1, LastPG, this);
106
        m_validator = new QIntValidator(1, LastPG, this);
10508 cbradney 107
        PageCombo = new ScComboBox( this );
108
        PageCombo->setEditable(true);
199 Franz 109
        PageCombo->setDuplicatesEnabled( false );
19313 jghali 110
        PageCombo->setInsertPolicy(QComboBox::NoInsert);
3238 avox 111
        PageCombo->lineEdit()->setAlignment(Qt::AlignHCenter);
199 Franz 112
        for (int a = 0; a < LastPG; ++a)
3695 cbradney 113
        {
13243 pierre 114
                PageCombo->addItem(QString::number(a+1));
3695 cbradney 115
        }
12724 subik 116
        PageCombo->setValidator(m_validator);
13243 pierre 117
        PageCombo->setMinimumSize(fontMetrics().width( "999" )+20, 20);
8547 cbradney 118
        PageCombo->setFocusPolicy(Qt::ClickFocus);
199 Franz 119
        PageSelectorLayout->addWidget( PageCombo );
3053 avox 120
 
13244 cbradney 121
        PageCount = new QLabel(PageCountString.arg(LastPG), this);
13243 pierre 122
        PageSelectorLayout->addWidget(PageCount);
123
 
9878 fschmid 124
        Forward->setIcon(QIcon(loadIcon("16/go-next.png")));
8547 cbradney 125
        Forward->setFocusPolicy(Qt::NoFocus);
3238 avox 126
        Forward->setAutoRepeat(true);
199 Franz 127
        PageSelectorLayout->addWidget( Forward );
128
 
9878 fschmid 129
        Last->setIcon(QIcon(loadIcon("16/go-last.png")));
8547 cbradney 130
        Last->setFocusPolicy(Qt::NoFocus);
199 Franz 131
        PageSelectorLayout->addWidget( Last );
132
        Forward->setEnabled(true);
133
        Last->setEnabled(true);
134
        Back->setEnabled(false);
135
        Start->setEnabled(false);
136
        if (APage == LastPG)
137
        {
138
                Forward->setEnabled(false);
139
                Last->setEnabled(false);
140
        }
141
 
2199 cbradney 142
        languageChange();
199 Franz 143
        // signals and slots connections
144
        connect( PageCombo, SIGNAL( activated(int) ), this, SLOT( GotoPgE(int) ) );
145
        connect( Back, SIGNAL( clicked() ), this, SLOT( goBk() ) );
146
        connect( Start, SIGNAL( clicked() ), this, SLOT( ToStart() ) );
147
        connect( Forward, SIGNAL( clicked() ), this, SLOT( goFw() ) );
148
        connect( Last, SIGNAL( clicked() ), this, SLOT( ToEnd() ) );
149
}
150
 
3613 cbradney 151
bool PageSelector::hasFocus()
3053 avox 152
{
153
        return PageCombo->hasFocus();
154
}
155
 
156
 
8501 cbradney 157
void PageSelector::focusPolicy(Qt::FocusPolicy policy)
3053 avox 158
{
159
        PageCombo->setFocusPolicy(policy);
160
}
161
 
13244 cbradney 162
void PageSelector::setFont ( const QFont &fo )
163
{
164
        PageCount->setFont(fo);
165
        QWidget::setFont(fo);
166
}
3053 avox 167
 
199 Franz 168
void PageSelector::GotoPgE(int a)
169
{
9878 fschmid 170
        clearFocus();
199 Franz 171
        GotoPg(a);
172
        emit GotoPage(a+1);
173
}
174
 
3053 avox 175
 
176
void PageSelector::GotoPage()
177
{
178
        static QRegExp rx("^([0-9])+.*");
179
        int p = rx.cap(1).toInt();
180
        if (p < 1)
181
                p=1;
182
        if (p > LastPG)
183
                p = LastPG;
184
        GotoPg(p-1);
185
        emit GotoPage(p);
186
}
187
 
188
 
199 Franz 189
void PageSelector::GotoPg(int a)
190
{
191
        disconnect( PageCombo, SIGNAL( activated(int) ), this, SLOT( GotoPgE(int) ) );
10469 cbradney 192
        PageCombo->setCurrentIndex(a);
13243 pierre 193
        setCurrentComboItem(PageCombo, QString::number(a+1));
199 Franz 194
        APage = a+1;
195
        Back->setEnabled(true);
196
        Start->setEnabled(true);
197
        Forward->setEnabled(true);
198
        Last->setEnabled(true);
199
        if (a == 0)
200
        {
201
                Back->setEnabled(false);
202
                Start->setEnabled(false);
203
        }
204
        if (a == LastPG-1)
205
        {
206
                Forward->setEnabled(false);
207
                Last->setEnabled(false);
208
        }
209
        connect( PageCombo, SIGNAL( activated(int) ), this, SLOT( GotoPgE(int) ) );
210
}
211
 
10469 cbradney 212
void PageSelector::setMaximum(int a)
199 Franz 213
{
214
        disconnect( PageCombo, SIGNAL( activated(int) ), this, SLOT( GotoPgE(int) ) );
3053 avox 215
        PageCombo->clear();
199 Franz 216
        LastPG = a;
3238 avox 217
//      v->setTop(LastPG);
12724 subik 218
        m_validator->setRange(1, LastPG);
199 Franz 219
        for (int b = 0; b < LastPG; ++b)
220
        {
13243 pierre 221
                PageCombo->addItem(QString::number(b+1));
199 Franz 222
        }
13243 pierre 223
        setCurrentComboItem(PageCombo, QString::number(APage));
224
        PageCount->setText(PageCountString.arg(LastPG));
199 Franz 225
        connect( PageCombo, SIGNAL( activated(int) ), this, SLOT( GotoPgE(int) ) );
226
}
227
 
228
void PageSelector::ToStart()
229
{
230
        if (APage == 1)
231
                return;
232
        GotoPgE(0);
233
}
234
 
235
void PageSelector::ToEnd()
236
{
5225 cbradney 237
        if (APage == LastPG)
199 Franz 238
                return;
239
        GotoPgE(LastPG-1);
240
}
241
 
242
void PageSelector::goBk()
243
{
244
        APage--;
245
        if (APage < 1)
246
                APage = 1;
247
        GotoPgE(APage-1);
248
}
249
 
250
void PageSelector::goFw()
251
{
252
        APage++;
253
        if (APage > LastPG)
254
                APage = LastPG;
255
        GotoPgE(APage-1);
256
}
2199 cbradney 257
 
10859 cbradney 258
void PageSelector::changeEvent(QEvent *e)
259
{
260
        if (e->type() == QEvent::LanguageChange)
261
                languageChange();
10903 cbradney 262
        else
263
                QWidget::changeEvent(e);
10859 cbradney 264
}
265
 
2199 cbradney 266
void PageSelector::languageChange()
267
{
13407 cbradney 268
        Start->setToolTip( tr("Go to the first page") );
269
        Back->setToolTip( tr("Go to the previous page") );
270
        Forward->setToolTip( tr("Go to the next page") );
271
        Last->setToolTip( tr("Go to the last page") );
272
        PageCombo->setToolTip( tr("Select the current page") );
13244 cbradney 273
        PageCountString =  tr(" of %1", "number of pages in document");
13243 pierre 274
        PageCount->setText(PageCountString.arg(LastPG));
3332 avox 275
        disconnect( PageCombo, SIGNAL( activated(int) ), this, SLOT( GotoPgE(int) ) );
13243 pierre 276
        setCurrentComboItem(PageCombo, QString::number(APage));
3332 avox 277
        connect( PageCombo, SIGNAL( activated(int) ), this, SLOT( GotoPgE(int) ) );
2199 cbradney 278
}
3613 cbradney 279
 
280
void PageSelector::clearFocus()
281
{
282
        PageCombo->clearFocus();       
283
}