Subversion Repositories Scribus

Rev

Rev 18326 | Rev 18897 | 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
*/
10192 cbradney 7
 
10223 cbradney 8
 
12358 cbradney 9
#include <QApplication>
10859 cbradney 10
#include <QEvent>
9803 fschmid 11
#include <QList>
16546 jghali 12
#include <QPainter>
17513 jghali 13
#include <QStackedWidget>
10192 cbradney 14
 
6715 cbradney 15
#include "commonstrings.h"
3560 fschmid 16
#include "pagelayout.h"
12358 cbradney 17
#include "pagepalette.h"
17513 jghali 18
#include "pagepalette_masterpages.h"
19
#include "pagepalette_pages.h"
20
#include "pagepalette_widgets.h"
3560 fschmid 21
#include "sccombobox.h"
16736 jghali 22
#include "scpage.h"
10223 cbradney 23
#include "scribus.h"
24
#include "scribusview.h"
10200 cbradney 25
#include "util_icon.h"
10192 cbradney 26
 
17513 jghali 27
PagePalette::PagePalette(QWidget* parent) : ScDockPalette(parent, "PagePalette", 0)
3 paul 28
{
17513 jghali 29
        m_scMW = (ScribusMainWindow*) parent;
30
        m_view = 0;
3 paul 31
 
17513 jghali 32
        setObjectName(QString::fromLocal8Bit("PagePalette"));
3623 cbradney 33
 
17513 jghali 34
        QStackedWidget* stackedWidget = new QStackedWidget(this);
35
        stackedWidget->setObjectName(QString::fromLocal8Bit("stackedWidget"));
3 paul 36
 
17513 jghali 37
        PagePalette_Pages* pageWidget = new PagePalette_Pages(stackedWidget);
38
        pageWidget->setObjectName(QString::fromLocal8Bit("PagePalette_Pages"));
39
        stackedWidget->addWidget(pageWidget);
3 paul 40
 
17513 jghali 41
        setWidget(stackedWidget);
3 paul 42
 
18893 craig 43
        connect(pageWidget, SIGNAL(gotoMasterPage(QString)), m_scMW, SLOT(editMasterPagesStart(QString)));
17513 jghali 44
 
45
        Rebuild();
46
        languageChange();
3 paul 47
}
48
 
17513 jghali 49
QWidget* PagePalette::currentWidget()
3 paul 50
{
17513 jghali 51
        QStackedWidget* sw = dynamic_cast<QStackedWidget*>(this->widget());
52
        if (sw)
53
                return sw->currentWidget();
54
        return 0;
3 paul 55
}
56
 
17513 jghali 57
PagePalette_MasterPages* PagePalette::masterpageWidget() const
12358 cbradney 58
{
17513 jghali 59
        if (this->stackedWidget()->count() >= 2)
60
                return dynamic_cast<PagePalette_MasterPages*>(this->stackedWidget()->widget(1));
61
        return 0;
12358 cbradney 62
}
63
 
17513 jghali 64
PagePalette_Pages* PagePalette::pageWidget() const
3 paul 65
{
17513 jghali 66
        if (this->stackedWidget()->count() >= 1)
67
                return dynamic_cast<PagePalette_Pages*>(this->stackedWidget()->widget(0));
68
        return 0;
3 paul 69
}
70
 
17513 jghali 71
QStackedWidget* PagePalette::stackedWidget() const
3 paul 72
{
17513 jghali 73
        QStackedWidget* sw = dynamic_cast<QStackedWidget*>(this->widget());
74
        return sw;
3 paul 75
}
76
 
17513 jghali 77
void PagePalette::enablePalette(const bool enabled)
3 paul 78
{
17513 jghali 79
        PagePalette_Pages* pageWidget = dynamic_cast<PagePalette_Pages*>(this->currentWidget());
80
        if (pageWidget)
81
                pageWidget->enablePalette(enabled);
3 paul 82
}
83
 
17513 jghali 84
void PagePalette::rebuildMasters()
3 paul 85
{
17513 jghali 86
        if (m_scMW->scriptIsRunning())
87
                return;
3 paul 88
 
17513 jghali 89
        PagePalette_Pages* pageWidget = dynamic_cast<PagePalette_Pages*>(this->currentWidget());
90
        if (pageWidget)
91
                pageWidget->rebuildMasters();
3 paul 92
}
93
 
17513 jghali 94
void PagePalette::rebuildPages()
3 paul 95
{
17513 jghali 96
        if (m_scMW->scriptIsRunning())
97
                return;
98
 
99
        PagePalette_Pages* pageWidget = dynamic_cast<PagePalette_Pages*>(this->currentWidget());
100
        if (pageWidget)
101
                pageWidget->rebuildPages();
3 paul 102
}
103
 
17513 jghali 104
void PagePalette::Rebuild()
3 paul 105
{
17513 jghali 106
        rebuildMasters();
107
        rebuildPages();
108
        enablePalette(m_view != 0);
3 paul 109
}
110
 
17513 jghali 111
void PagePalette::markPage(uint nr)
3 paul 112
{
17513 jghali 113
        PagePalette_Pages* pageWidget = dynamic_cast<PagePalette_Pages*>(this->currentWidget());
114
        if (pageWidget)
115
                pageWidget->markPage(nr);
3 paul 116
}
117
 
17513 jghali 118
void PagePalette::setView(ScribusView *view)
3 paul 119
{
17513 jghali 120
        PagePalette_Pages* pageWidget = dynamic_cast<PagePalette_Pages*>(this->currentWidget());
121
        if (pageWidget)
122
                pageWidget->setView(view);
123
        PagePalette_MasterPages* mpWidget = dynamic_cast<PagePalette_MasterPages*>(this->currentWidget());
124
        if (mpWidget)
125
                mpWidget->setView(view);
126
        m_view = view;
17517 jghali 127
 
128
        if (!m_view)
129
                return;
130
 
131
        ScribusDoc* doc = m_view->Doc;
132
        if (doc->masterPageMode())
133
        {
134
                QString pageName = doc->currentPage()->pageName();
135
                startMasterPageMode(pageName);
136
        }
137
        else if (masterPageMode())
138
        {
139
                endMasterPageMode();
140
        }
3 paul 141
}
142
 
17513 jghali 143
void PagePalette::updateMasterPageList()
12358 cbradney 144
{
17513 jghali 145
        PagePalette_Pages* pageWidget = dynamic_cast<PagePalette_Pages*>(this->currentWidget());
146
        if (pageWidget)
147
                pageWidget->rebuildMasters();
3436 fschmid 148
        else
167 Franz 149
        {
17513 jghali 150
                PagePalette_MasterPages* mpWidget = dynamic_cast<PagePalette_MasterPages*>(this->currentWidget());
151
                if (mpWidget)
152
                        mpWidget->updateMasterPageList();
167 Franz 153
        }
3 paul 154
}
155
 
17513 jghali 156
bool PagePalette::masterPageMode()
3 paul 157
{
17513 jghali 158
        PagePalette_MasterPages* mpWidget = dynamic_cast<PagePalette_MasterPages*>(this->currentWidget());
159
        return (mpWidget != NULL);
3 paul 160
}
161
 
17513 jghali 162
void PagePalette::startMasterPageMode(QString masterPage)
3 paul 163
{
17513 jghali 164
        m_view->Deselect(true);
3 paul 165
 
17513 jghali 166
        QStackedWidget* stackedWidget = this->stackedWidget();
167
        if (stackedWidget->count() < 2)
167 Franz 168
        {
17513 jghali 169
                PagePalette_MasterPages* mpWidget = new PagePalette_MasterPages(stackedWidget, m_view, masterPage);
170
                mpWidget->setObjectName(QString::fromLocal8Bit("PagePalette_MasterPages"));
171
                stackedWidget->addWidget(mpWidget);
3 paul 172
 
17513 jghali 173
                connect(mpWidget, SIGNAL(removePage(int )), m_scMW, SLOT(deletePage2(int )));
174
                connect(mpWidget, SIGNAL(finished())      , m_scMW, SLOT(manageMasterPagesEnd()));
167 Franz 175
        }
3 paul 176
        else
167 Franz 177
        {
17513 jghali 178
                ScribusDoc* doc = m_view->Doc;
179
                PagePalette_MasterPages* mpWidget = this->masterpageWidget();
18326 jghali 180
                if (mpWidget->m_view != m_view)
17513 jghali 181
                        mpWidget->setView(m_view, masterPage);
182
                mpWidget->updateMasterPageList(masterPage);
183
                if (doc->currentPage()->pageName() != masterPage)
184
                        mpWidget->selectMasterPage(masterPage);
3429 fschmid 185
        }
3 paul 186
 
17513 jghali 187
        // Set focus to page palette or focus may be set to wrong document window
188
        this->setFocus();
189
        stackedWidget->setCurrentIndex(1);
3 paul 190
}
191
 
17513 jghali 192
void PagePalette::endMasterPageMode()
7541 fschmid 193
{
17513 jghali 194
        if (this->stackedWidget()->currentIndex() > 0)
7541 fschmid 195
        {
17513 jghali 196
                // Set focus to page palette or focus may be set to wrong document window
197
                this->setFocus();
198
                this->stackedWidget()->setCurrentIndex(0);
7541 fschmid 199
        }
200
 
17513 jghali 201
        PagePalette_Pages* pageWidget = dynamic_cast<PagePalette_Pages*>(this->currentWidget());
202
        pageWidget->setView(m_view);
203
        pageWidget->Rebuild();
3 paul 204
}
205
 
10859 cbradney 206
void PagePalette::changeEvent(QEvent *e)
207
{
208
        if (e->type() == QEvent::LanguageChange)
209
        {
210
                languageChange();
17513 jghali 211
                return;
10859 cbradney 212
        }
17513 jghali 213
 
214
        ScDockPalette::changeEvent(e);
10859 cbradney 215
}
216
 
3623 cbradney 217
void PagePalette::languageChange()
2195 cbradney 218
{
10495 cbradney 219
        setWindowTitle( tr( "Arrange Pages" ) );
2219 fschmid 220
}