kivio
objectlistpalette.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "objectlistpalette.h"
00020
00021 #include <qlayout.h>
00022 #include <qheader.h>
00023 #include <qptrlist.h>
00024
00025 #include <klistview.h>
00026 #include <kdebug.h>
00027 #include <klocale.h>
00028
00029 #include "kivio_view.h"
00030 #include "kivio_stencil.h"
00031 #include "kivio_layer.h"
00032 #include "kivio_stencil_spawner.h"
00033 #include "kivio_stencil_spawner_info.h"
00034 #include "kivio_page.h"
00035 #include "kivioglobal.h"
00036 #include "kivio_doc.h"
00037
00038 namespace Kivio {
00039
00040 class ObjectListItem : public KListViewItem
00041 {
00042 public:
00043 ObjectListItem(KListView* parent, KivioStencil* _stencil)
00044 : KListViewItem(parent, "")
00045 {
00046 m_stencil = _stencil;
00047 setPixmap(0, Kivio::generatePixmapFromStencil(22, 22, m_stencil));
00048
00049 QString type;
00050 QString name;
00051
00052 switch(m_stencil->type()) {
00053 case kstGroup:
00054 type = i18n("Group");
00055 name = type;
00056 break;
00057 case kstConnector:
00058 type = i18n("Connector");
00059 name = _stencil->spawner()->info()->title();
00060 break;
00061 case kstText:
00062 type = i18n("Text Area");
00063 name = type;
00064 break;
00065 case kstNormal:
00066 default:
00067 type = i18n("Stencil");
00068 name = _stencil->spawner()->info()->title();
00069 break;
00070 }
00071
00072 setText(0, name);
00073 setText(1, type);
00074 setSelected(m_stencil->isSelected());
00075 }
00076
00077 KivioStencil* stencil() const { return m_stencil; }
00078
00079 private:
00080 KivioStencil* m_stencil;
00081 };
00082
00083 ObjectListPalette::ObjectListPalette(KivioView* parent, const char* name)
00084 : QWidget(parent, name), m_view(parent)
00085 {
00086 m_blockUpdate = false;
00087
00088 QVBoxLayout* layout = new QVBoxLayout(this, 0, 2);
00089
00090 m_objectList = new KListView(this);
00091 m_objectList->setFullWidth(true);
00092 m_objectList->setAllColumnsShowFocus(true);
00093 m_objectList->setSorting(-1);
00094 m_objectList->setSelectionMode(QListView::Extended);
00095 m_objectList->addColumn(i18n("Name"));
00096 m_objectList->addColumn(i18n("Type"));
00097
00098 layout->addWidget(m_objectList);
00099
00100 connect(m_objectList, SIGNAL(selectionChanged()), this, SLOT(updateSelection()));
00101 }
00102
00103 ObjectListPalette::~ObjectListPalette()
00104 {
00105 }
00106
00107 void ObjectListPalette::updateObjectList()
00108 {
00109 if(m_blockUpdate) {
00110 m_blockUpdate = false;
00111 return;
00112 }
00113
00114 KivioPage* page = m_view->activePage();
00115
00116 if(!page)
00117 return;
00118
00119 m_objectList->clear();
00120
00121 QPtrList<KivioLayer>* layers = page->layers();
00122
00123 KivioLayer* layer = layers->first();
00124 KivioStencil* stencil;
00125 m_objectList->blockSignals(true);
00126
00127 while(layer) {
00128 stencil = layer->firstStencil();
00129
00130 while(stencil) {
00131 new ObjectListItem(m_objectList, stencil);
00132 stencil = layer->nextStencil();
00133 }
00134
00135 layer = layers->next();
00136 }
00137
00138 m_objectList->blockSignals(false);
00139 }
00140
00141 void ObjectListPalette::updateSelection()
00142 {
00143 KivioPage* page = m_view->activePage();
00144
00145 if(!page)
00146 return;
00147
00148 page->unselectAllStencils();
00149
00150 QPtrList<QListViewItem> selectedItems = m_objectList->selectedItems();
00151 QPtrListIterator<QListViewItem> it(selectedItems);
00152 ObjectListItem* item = 0;
00153
00154 while((item = static_cast<ObjectListItem*>(it.current())) != 0) {
00155 page->selectStencil(item->stencil());
00156 ++it;
00157 }
00158
00159 m_blockUpdate = true;
00160 m_view->doc()->updateView(page);
00161 }
00162
00163 }
00164
00165 #include "objectlistpalette.moc"
|