objectlistpalette.cpp
1/*
2 * Kivio - Visual Modelling and Flowcharting
3 * Copyright (C) 2005 Peter Simonsson
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (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 Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19#include "objectlistpalette.h"
20
21#include <tqlayout.h>
22#include <tqheader.h>
23#include <tqptrlist.h>
24
25#include <tdelistview.h>
26#include <kdebug.h>
27#include <tdelocale.h>
28
29#include "kivio_view.h"
30#include "kivio_stencil.h"
31#include "kivio_layer.h"
32#include "kivio_stencil_spawner.h"
33#include "kivio_stencil_spawner_info.h"
34#include "kivio_page.h"
35#include "kivioglobal.h"
36#include "kivio_doc.h"
37
38namespace Kivio {
39
40class ObjectListItem : public TDEListViewItem
41{
42 public:
43 ObjectListItem(TDEListView* parent, KivioStencil* _stencil)
44 : TDEListViewItem(parent, "")
45 {
46 m_stencil = _stencil;
47 setPixmap(0, Kivio::generatePixmapFromStencil(22, 22, m_stencil));
48
49 TQString type;
50 TQString name;
51
52 switch(m_stencil->type()) {
53 case kstGroup:
54 type = i18n("Group");
55 name = type;
56 break;
57 case kstConnector:
58 type = i18n("Connector");
59 name = _stencil->spawner()->info()->title();
60 break;
61 case kstText:
62 type = i18n("Text Area");
63 name = type;
64 break;
65 case kstNormal:
66 default:
67 type = i18n("Stencil");
68 name = _stencil->spawner()->info()->title();
69 break;
70 }
71
72 setText(0, name);
73 setText(1, type);
74 setSelected(m_stencil->isSelected());
75 }
76
77 KivioStencil* stencil() const { return m_stencil; }
78
79 private:
80 KivioStencil* m_stencil;
81};
82
83ObjectListPalette::ObjectListPalette(KivioView* parent, const char* name)
84 : TQWidget(parent, name), m_view(parent)
85{
86 m_blockUpdate = false;
87
88 TQVBoxLayout* layout = new TQVBoxLayout(this, 0, 2);
89
90 m_objectList = new TDEListView(this);
91 m_objectList->setFullWidth(true);
92 m_objectList->setAllColumnsShowFocus(true);
93 m_objectList->setSorting(-1);
94 m_objectList->setSelectionMode(TQListView::Extended);
95 m_objectList->addColumn(i18n("Name"));
96 m_objectList->addColumn(i18n("Type"));
97
98 layout->addWidget(m_objectList);
99
100 connect(m_objectList, TQ_SIGNAL(selectionChanged()), this, TQ_SLOT(updateSelection()));
101}
102
103ObjectListPalette::~ObjectListPalette()
104{
105}
106
107void ObjectListPalette::updateObjectList()
108{
109 if(m_blockUpdate) {
110 m_blockUpdate = false;
111 return;
112 }
113
114 KivioPage* page = m_view->activePage();
115
116 if(!page)
117 return;
118
119 m_objectList->clear();
120
121 TQPtrList<KivioLayer>* layers = page->layers();
122
123 KivioLayer* layer = layers->first();
124 KivioStencil* stencil;
125 m_objectList->blockSignals(true);
126
127 while(layer) {
128 stencil = layer->firstStencil();
129
130 while(stencil) {
131 new ObjectListItem(m_objectList, stencil);
132 stencil = layer->nextStencil();
133 }
134
135 layer = layers->next();
136 }
137
138 m_objectList->blockSignals(false);
139}
140
141void ObjectListPalette::updateSelection()
142{
143 KivioPage* page = m_view->activePage();
144
145 if(!page)
146 return;
147
148 page->unselectAllStencils();
149
150 TQPtrList<TQListViewItem> selectedItems = m_objectList->selectedItems();
151 TQPtrListIterator<TQListViewItem> it(selectedItems);
152 ObjectListItem* item = 0;
153
154 while((item = static_cast<ObjectListItem*>(it.current())) != 0) {
155 page->selectStencil(item->stencil());
156 ++it;
157 }
158
159 m_blockUpdate = true;
160 m_view->doc()->updateView(page);
161}
162
163}
164
165#include "objectlistpalette.moc"