1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
/*
* Copyright (c) 2003 Patrick Julien <freak@codepimps.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <koIconChooser.h>
#include "kdebug.h"
#include "kis_icon_item.h"
#include "kis_resource.h"
#include "kis_itemchooser.h"
#include "kis_resourceserver.h"
#include "kis_resource_mediator.h"
KisResourceMediator::KisResourceMediator(KisItemChooser *chooser,
TQObject *parent,
const char *name) : super(parent, name), m_chooser(chooser)
{
Q_ASSERT(chooser);
m_activeItem = 0;
connect(m_chooser, TQT_SIGNAL(selected(KoIconItem*)), TQT_SLOT(setActiveItem(KoIconItem*)));
}
KisResourceMediator::~KisResourceMediator()
{
}
void KisResourceMediator::connectServer(KisResourceServerBase* rServer)
{
// Add the initially loaded items
TQValueList<KisResource*> resources = rServer->resources();
TQValueList<KisResource*>::iterator it;
for ( it = resources.begin(); it != resources.end(); ++it )
rServerAddedResource( *it );
// And connect to the server permanently, so that we may recieve updates afterwards
connect(rServer, TQT_SIGNAL(resourceAdded(KisResource*)),
this, TQT_SLOT(rServerAddedResource(KisResource*)));
}
KisResource *KisResourceMediator::currentResource() const
{
if (m_activeItem) {
Q_ASSERT(dynamic_cast<KisIconItem*>(m_activeItem));
return static_cast<KisIconItem*>(m_activeItem)->resource();
}
return 0;
}
KisIconItem *KisResourceMediator::itemFor(KisResource *r) const
{
if(m_items.contains(r))
{
return m_items[r];
}
return 0;
}
KisResource *KisResourceMediator::resourceFor(KoIconItem *item) const
{
KisIconItem *kisitem = dynamic_cast<KisIconItem*>(item);
return kisitem ? kisitem->resource() : 0;
}
KisResource *KisResourceMediator::resourceFor(KisIconItem *item) const
{
return item ? item->resource() : 0;
}
TQWidget *KisResourceMediator::chooserWidget() const
{
return m_chooser;
}
void KisResourceMediator::setActiveItem(KoIconItem *item)
{
KisIconItem *kisitem = dynamic_cast<KisIconItem*>(item);
if (kisitem) {
m_activeItem = kisitem;
m_chooser->setCurrent(item);
emit activatedResource(kisitem ? kisitem->resource() : 0);
}
}
void KisResourceMediator::rServerAddedResource(KisResource *resource)
{
if (resource && resource->valid()) {
KisIconItem *item = new KisIconItem(resource);
TQ_CHECK_PTR(item);
m_items[resource] = item;
m_chooser->addItem(item);
if (m_activeItem == 0) setActiveItem(item);
}
}
#include "kis_resource_mediator.moc"
|