Subversion Repositories Scribus

Rev

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

Rev Author Line No. Line
13808 pierre 1
/***************************************************************************
2
 *   Copyright (C) 2009 by Pierre Marchand                                 *
3
 *   pierre@oep-h.com                                                      *
4
 *                                                                         *
5
 *   This program is free software; you can redistribute it and/or modify  *
6
 *   it under the terms of the GNU General Public License as published by  *
7
 *   the Free Software Foundation; either version 2 of the License, or     *
8
 *   (at your option) any later version.                                   *
9
 *                                                                         *
10
 *   This program is distributed in the hope that it will be useful,       *
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13
 *   GNU General Public License for more details.                          *
14
 *                                                                         *
15
 *   You should have received a copy of the GNU General Public License     *
16
 *   along with this program; if not, write to the                         *
17
 *   Free Software Foundation, Inc.,                                       *
18122 mrdocs 18
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
13808 pierre 19
 ***************************************************************************/
20
 
21
#include "pageitemsettersmanager.h"
22
#include "ui/pageitemsetterbase.h"
23
#include "pageitem.h"
24
#include "selection.h"
25
#include "scribusdoc.h"
26
 
27
#include <QCoreApplication>
28
 
29
 
30
 
31
PageItemSettersManager * PageItemSettersManager::instance = 0;
32
 
33
PageItemSettersManager::PageItemSettersManager(QObject * parent)
34
                :QObject(parent), selection(0), doc(0)
35
{
36
}
37
 
38
PageItemSettersManager * PageItemSettersManager::that()
39
{
40
        if(!instance)
41
        {
42
                instance = new PageItemSettersManager(QCoreApplication::instance());
43
                Q_ASSERT(instance);
44
        }
45
        return instance;
46
}
47
 
48
void PageItemSettersManager::registerSetter(PageItemSetterBase * base)
49
{
50
        if(base && !that()->setters.contains(base))
51
        {
52
                that()->setters.append(base);
53
                if(that()->selection)
54
                        base->changeItem(that()->selection);
55
                connect(base, SIGNAL(destroyed()), that(), SLOT(UnRegisterSetter()));
56
        }
57
}
58
 
59
void PageItemSettersManager::UnRegisterSetter()
60
{
61
        PageItemSetterBase * base = reinterpret_cast<PageItemSetterBase*>(sender());
13809 pierre 62
        setters.removeAll(base);
13808 pierre 63
}
64
 
65
void PageItemSettersManager::setSelection(Selection * sel)
66
{
67
        if(that()->selection)
68
                disconnect(that()->selection, SIGNAL(selectionChanged()), that(), SLOT(updateSelection()));
69
        if(that()->doc)
70
                disconnect(that()->doc, SIGNAL(rotationMode(int)), that(), SLOT(rotationModeChanged(int)));
71
 
72
        that()->selection = sel;
73
        that()->doc = (sel && (sel->count() > 0)) ? sel->itemAt(0)->m_Doc : 0;
74
 
75
        if(that()->selection)
76
                connect(that()->selection, SIGNAL(selectionChanged()), that(), SLOT(updateSelection()));
77
        if(that()->doc)
78
                connect(that()->doc, SIGNAL(rotationMode(int)), that(), SLOT(rotationModeChanged(int)));
79
 
80
        foreach(PageItemSetterBase * base, that()->setters)
81
        {
82
                base->changeItem(sel);
83
        }
84
}
85
 
13809 pierre 86
PageItemSetterBase* PageItemSettersManager::getClone(const QString& type)
13808 pierre 87
{
88
        foreach(PageItemSetterBase* base, that()->setters)
89
        {
13809 pierre 90
                if(base->objectName() == type)
13808 pierre 91
                        return base->clone();
92
        }
93
        return 0;
94
}
95
 
96
void PageItemSettersManager::rotationModeChanged(int)
97
{
98
        Selection * s = that()->selection ;
99
        foreach(PageItemSetterBase * base, that()->setters)
100
        {
101
                base->changeItem(s);
102
        }
103
}
104
 
105
void PageItemSettersManager::updateSelection()
106
{
107
        Selection * s = that()->selection ;
108
        foreach(PageItemSetterBase * base, that()->setters)
109
        {
110
                base->changeItem(s);
111
        }
112
}