Subversion Repositories Scribus

Rev

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