comparison widgets/ItemContainer.cpp @ 56:81921835ddf1

first layer list pre-version
author benoitrigolleau
date Wed, 23 May 2007 13:09:19 +0000
parents
children 57c85a9d9b4a
comparison
equal deleted inserted replaced
55:41f1491c841b 56:81921835ddf1
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Sound Access
5 EASAIER client application.
6 Silogic 2007. Benoit Rigolleau.
7
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version. See the file
12 COPYING included with this distribution for more information.
13 */
14
15 #include "ItemContainer.h"
16
17 #include <QtAlgorithms>
18 #include <iostream>
19 #include <QList>
20 #include <QPalette>
21
22 ItemContainer::ItemContainer(QWidget *parent) : QWidget(parent){
23
24 m_linkedList = new QLinkedList<int>();
25 m_map = new QMap<int,GenericItemList*>();
26
27 m_cpt=0;
28
29 QVBoxLayout *mainlayout = new QVBoxLayout();
30 m_itemLayout = new QVBoxLayout;
31 mainlayout->addLayout(m_itemLayout);
32 mainlayout->addStretch();
33
34 this->setLayout(mainlayout);
35
36 }
37
38 void ItemContainer::addItem(GenericItemList *item){
39 m_map->insert(m_cpt,item);
40 m_linkedList->append(m_cpt);
41 item->setIndex(m_cpt);
42
43 std::cerr << "add Item" << std::endl;
44 connect(item, SIGNAL(itemDropped(int, int)),
45 this, SLOT(moveItem(int, int)));
46 connect(item, SIGNAL(selected(int)),
47 this, SLOT(newItemSelected(int)));
48
49 m_itemLayout->addWidget(item);
50 m_cpt++;
51 }
52
53 void ItemContainer::setSelectedItem(QVariant &data){
54
55 }
56
57 void ItemContainer::removeSelectedItem(){
58 //QLindList<int>::iterator iter = m_linkedList->find(x);
59
60 }
61
62 void ItemContainer::reset()
63 {
64 QLayoutItem *child;
65 while ((child = m_itemLayout->takeAt(0)) != 0) {
66 delete child->widget();
67 }
68 }
69
70 void ItemContainer::removeAllItems(){
71 m_linkedList->clear();
72 reset();
73 m_map->clear();
74 m_cpt=0;
75
76 }
77
78 void ItemContainer::setCurrentIndex(int i){
79
80
81 }
82
83 QLinkedList<int>::iterator ItemContainer::find(int value)
84 {
85 QLinkedList<int>::iterator iter;
86 for(iter = m_linkedList->begin(); iter != m_linkedList->end(); iter++){
87 if(*iter == value)
88 return iter;
89 }
90 return m_linkedList->end();
91 }
92
93 void ItemContainer::reorganize(){
94 for (int i = 0; i < m_itemLayout->count(); ++i){
95 m_itemLayout->removeItem(m_itemLayout->itemAt(i));
96 }
97 QLinkedList<int>::iterator iter;
98 for(iter = m_linkedList->begin(); iter != m_linkedList->end(); iter++){
99 m_itemLayout->addWidget(m_map->value(*iter));
100 }
101 }
102
103 /********* SLOTS **************/
104 void ItemContainer::moveItem(int idItem1, int idItem2){
105 m_linkedList->removeAll(idItem1);
106 QLinkedList<int>::iterator iter = find( idItem2);
107 m_linkedList->insert(iter,idItem1);
108 reorganize();
109 }
110
111 void ItemContainer::newItemSelected(int idItem){
112
113 GenericItemList* item = m_map->value(m_currentItem);
114 if(item!=0){
115 item->setBackgroundRole(QPalette::Window);
116 item->setForegroundRole(QPalette::WindowText);
117 }
118
119 m_currentItem=idItem;
120
121 item = m_map->value(m_currentItem);
122 if(item!=0){
123 item->setAutoFillBackground(true);
124 item->setBackgroundRole(QPalette::Highlight);
125 item->setForegroundRole(QPalette::HighlightedText);
126 }
127
128 // il va faloir changer l'indice je pense.
129 // si ça plante lorsque l'on supprime un item, ça peut etre ça
130 emit currentChanged(m_currentItem);
131 }
132
133 void ItemContainer::upCurrentItem(){
134 //return if item count <=1
135 if (m_linkedList->count()<= 1){
136 return;
137 }
138 // return if current item is on top
139 QLinkedList<int>::iterator iter;
140 iter = m_linkedList->begin();
141 if(*iter==m_currentItem){
142 return;
143 }
144
145 // move item
146 for(iter = m_linkedList->begin()+1; iter != m_linkedList->end(); iter++){
147 if(*iter == m_currentItem){
148 int itemOnTop = *(iter-1);
149 *(iter-1)=m_currentItem;
150 *iter = itemOnTop;
151 }
152 }
153 reorganize();
154
155 }
156
157 void ItemContainer::downCurrentItem(){
158 //return if item count <=1
159 if (m_linkedList->count()<= 1){
160 return;
161 }
162 // return if current item is on bottom
163 QLinkedList<int>::iterator iter;
164 iter = m_linkedList->end();
165 if(*iter==m_currentItem){
166 return;
167 }
168
169 //move item
170 // It's crazy !!!!!! this line run ..... but, it's impossible !!!!
171 // the good line is this one : for(iter = m_linkedList->end()-1; iter != m_linkedList->begin(); iter--){
172 // but I don't handerstand why, it don't run.
173 // @##*$$# QT4 or C++ !!!!!!!!!
174 for(iter = m_linkedList->end()-2; iter != m_linkedList->begin()-1; iter--){
175 if(*iter == m_currentItem){
176 int itemOnBottom = *(iter+1);
177 *(iter+1)=m_currentItem;
178 *iter = itemOnBottom;
179 }
180 }
181 reorganize();
182 }
183
184 void ItemContainer::openConfigBoxForCurrentItem(){
185 GenericItemList* item = m_map->value(m_currentItem);
186 if(item!=0){
187 item->configAction();
188 }
189 }