Subversion Repositories Scribus

Rev

Rev 19312 | Rev 19949 | Go to most recent revision | 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
 
10469 cbradney 26
PageSelector::PageSelector( QWidget* parent, int maxPg ) : QWidget( parent, 0 )
199 Franz 27
{
13243 pierre 28
        PageCountString = "%1" ;
18976 craig 29
        m_lastPage = maxPg;
30
        m_currentPage = 1;
9878 fschmid 31
        PageSelectorLayout = new QHBoxLayout( this );
32
        PageSelectorLayout->setMargin(0);
33
        PageSelectorLayout->setSpacing(1);
199 Franz 34
 
3053 avox 35
#if OPTION_USE_QTOOLBUTTON
18976 craig 36
        startButton = new QToolButton( this );
37
        startButton->setAutoRaise(OPTION_FLAT_BUTTON);
38
        backButton = new QToolButton( this );
39
        backButton->setAutoRaise(OPTION_FLAT_BUTTON);
40
        forwardButton = new QToolButton( this );
41
        forwardButton->setAutoRaise(OPTION_FLAT_BUTTON);
42
        lastButton = new QToolButton( this );
43
        lastButton->setAutoRaise(OPTION_FLAT_BUTTON);
3053 avox 44
#else
19009 craig 45
        startButton = new QPushButton( this );
46
        startButton->setDefault( false );
47
        startButton->setAutoDefault( false );
48
        startButton->setFlat(OPTION_FLAT_BUTTON);
49
        backButton = new QPushButton( this );
50
        backButton->setDefault( false );
51
        backButton->setAutoDefault( false );
52
        backButton->setFlat(OPTION_FLAT_BUTTON);
53
        forwardButton->setDefault( false );
54
        forwardButton->setAutoDefault( false );
55
        forwardButton->setFlat(OPTION_FLAT_BUTTON);
56
        lastButton = new QPushButton( this );
57
        lastButton->setDefault( false );
58
        lastButton->setAutoDefault( false );
59
        lastButton->setFlat(OPTION_FLAT_BUTTON);
3053 avox 60
#endif
18976 craig 61
        startButton->setIcon(QIcon(loadIcon("16/go-first.png")));
62
        startButton->setFocusPolicy(Qt::NoFocus);
63
        PageSelectorLayout->addWidget( startButton );
199 Franz 64
 
18976 craig 65
        backButton->setIcon(QIcon(loadIcon("16/go-previous.png")));
66
        backButton->setFocusPolicy(Qt::NoFocus);
67
        backButton->setAutoRepeat(true);
68
        PageSelectorLayout->addWidget( backButton );
199 Franz 69
 
18976 craig 70
        m_validator = new QIntValidator(1, m_lastPage, this);
71
        m_pageCombo = new ScComboBox( this );
72
        m_pageCombo->setEditable(true);
73
        m_pageCombo->setDuplicatesEnabled( false );
19312 jghali 74
        m_pageCombo->setInsertPolicy(QComboBox::NoInsert);
18976 craig 75
        m_pageCombo->lineEdit()->setAlignment(Qt::AlignHCenter);
76
        for (int i = 0; i < m_lastPage; ++i)
3695 cbradney 77
        {
18976 craig 78
                m_pageCombo->addItem(QString::number(i+1));
3695 cbradney 79
        }
18976 craig 80
        m_pageCombo->setValidator(m_validator);
19303 craig 81
        m_pageCombo->setMinimumSize(fontMetrics().width( "9999" )+20, 20);
18976 craig 82
        m_pageCombo->setFocusPolicy(Qt::ClickFocus);
83
        PageSelectorLayout->addWidget( m_pageCombo );
3053 avox 84
 
18976 craig 85
        pageCountLabel = new QLabel(PageCountString.arg(m_lastPage), this);
86
        PageSelectorLayout->addWidget(pageCountLabel);
13243 pierre 87
 
18976 craig 88
        forwardButton->setIcon(QIcon(loadIcon("16/go-next.png")));
89
        forwardButton->setFocusPolicy(Qt::NoFocus);
90
        forwardButton->setAutoRepeat(true);
91
        PageSelectorLayout->addWidget( forwardButton );
199 Franz 92
 
18976 craig 93
        lastButton->setIcon(QIcon(loadIcon("16/go-last.png")));
94
        lastButton->setFocusPolicy(Qt::NoFocus);
95
        PageSelectorLayout->addWidget( lastButton );
96
        forwardButton->setEnabled(true);
97
        lastButton->setEnabled(true);
98
        backButton->setEnabled(false);
99
        startButton->setEnabled(false);
100
        if (m_currentPage == m_lastPage)
199 Franz 101
        {
18976 craig 102
                forwardButton->setEnabled(false);
103
                lastButton->setEnabled(false);
199 Franz 104
        }
105
 
2199 cbradney 106
        languageChange();
199 Franz 107
        // signals and slots connections
18976 craig 108
        connect( m_pageCombo, SIGNAL( activated(int) ), this, SLOT( GotoPgE(int) ) );
109
        connect( backButton, SIGNAL( clicked() ), this, SLOT( goBackward()) );
110
        connect( startButton, SIGNAL( clicked() ), this, SLOT( goToStart() ) );
111
        connect( forwardButton, SIGNAL( clicked() ), this, SLOT( goForward() ) );
112
        connect( lastButton, SIGNAL( clicked() ), this, SLOT( goToEnd() ) );
199 Franz 113
}
114
 
3613 cbradney 115
bool PageSelector::hasFocus()
3053 avox 116
{
18976 craig 117
        return m_pageCombo->hasFocus();
3053 avox 118
}
119
 
18976 craig 120
void PageSelector::clearFocus()
121
{
122
        m_pageCombo->clearFocus();
123
}
3053 avox 124
 
8501 cbradney 125
void PageSelector::focusPolicy(Qt::FocusPolicy policy)
3053 avox 126
{
18976 craig 127
        m_pageCombo->setFocusPolicy(policy);
3053 avox 128
}
129
 
13244 cbradney 130
void PageSelector::setFont ( const QFont &fo )
131
{
18976 craig 132
        pageCountLabel->setFont(fo);
13244 cbradney 133
        QWidget::setFont(fo);
134
}
3053 avox 135
 
17885 fschmid 136
int PageSelector::getCurrentPage()
137
{
18976 craig 138
        return m_currentPage;
17885 fschmid 139
}
140
 
18976 craig 141
void PageSelector::GotoPgE(int i)
18972 craig 142
{
9878 fschmid 143
        clearFocus();
18976 craig 144
        setGUIForPage(i);
145
        emit GotoPage(i+1);
199 Franz 146
}
147
 
3053 avox 148
void PageSelector::GotoPage()
149
{
150
        static QRegExp rx("^([0-9])+.*");
151
        int p = rx.cap(1).toInt();
152
        if (p < 1)
153
                p=1;
18976 craig 154
        if (p > m_lastPage)
155
                p = m_lastPage;
156
        setGUIForPage(p-1);
3053 avox 157
        emit GotoPage(p);
158
}
159
 
18976 craig 160
void PageSelector::setGUIForPage(int i)
199 Franz 161
{
18976 craig 162
        m_pageCombo->blockSignals(true);
163
        m_pageCombo->setCurrentIndex(i);
164
        setCurrentComboItem(m_pageCombo, QString::number(i+1));
165
        m_currentPage = i+1;
166
        backButton->setEnabled(i != 0);
167
        startButton->setEnabled(i != 0);
168
        forwardButton->setEnabled(i != m_lastPage-1);
169
        lastButton->setEnabled(i != m_lastPage-1);
170
        m_pageCombo->blockSignals(false);
199 Franz 171
}
172
 
18976 craig 173
void PageSelector::setMaximum(int i)
199 Franz 174
{
18976 craig 175
        m_pageCombo->blockSignals(true);
176
        m_pageCombo->clear();
177
        m_lastPage = i;
178
        m_validator->setRange(1, m_lastPage);
179
        for (int b = 0; b < m_lastPage; ++b)
199 Franz 180
        {
18976 craig 181
                m_pageCombo->addItem(QString::number(b+1));
199 Franz 182
        }
18976 craig 183
        setCurrentComboItem(m_pageCombo, QString::number(m_currentPage));
184
        pageCountLabel->setText(PageCountString.arg(m_lastPage));
185
        m_pageCombo->blockSignals(false);
199 Franz 186
}
187
 
18976 craig 188
void PageSelector::goToStart()
199 Franz 189
{
18976 craig 190
        if (m_currentPage == 1)
199 Franz 191
                return;
192
        GotoPgE(0);
193
}
194
 
18976 craig 195
void PageSelector::goToEnd()
199 Franz 196
{
18976 craig 197
        if (m_currentPage == m_lastPage)
199 Franz 198
                return;
18976 craig 199
        GotoPgE(m_lastPage-1);
199 Franz 200
}
201
 
18976 craig 202
void PageSelector::goBackward()
199 Franz 203
{
18976 craig 204
        m_currentPage--;
205
        if (m_currentPage < 1)
206
                m_currentPage = 1;
207
        GotoPgE(m_currentPage-1);
199 Franz 208
}
209
 
18976 craig 210
void PageSelector::goForward()
199 Franz 211
{
18976 craig 212
        m_currentPage++;
213
        if (m_currentPage > m_lastPage)
214
                m_currentPage = m_lastPage;
215
        GotoPgE(m_currentPage-1);
199 Franz 216
}
2199 cbradney 217
 
10859 cbradney 218
void PageSelector::changeEvent(QEvent *e)
219
{
220
        if (e->type() == QEvent::LanguageChange)
221
                languageChange();
10903 cbradney 222
        else
223
                QWidget::changeEvent(e);
10859 cbradney 224
}
225
 
2199 cbradney 226
void PageSelector::languageChange()
227
{
18976 craig 228
        startButton->setToolTip( tr("Go to the first page") );
229
        backButton->setToolTip( tr("Go to the previous page") );
230
        forwardButton->setToolTip( tr("Go to the next page") );
231
        lastButton->setToolTip( tr("Go to the last page") );
232
        m_pageCombo->setToolTip( tr("Select the current page") );
13244 cbradney 233
        PageCountString =  tr(" of %1", "number of pages in document");
18976 craig 234
        pageCountLabel->setText(PageCountString.arg(m_lastPage));
235
        setCurrentComboItem(m_pageCombo, QString::number(m_currentPage));
2199 cbradney 236
}
3613 cbradney 237