Mercurial > hg > easaier-soundaccess
comparison widgets/ItemContainer.cpp @ 59:57c85a9d9b4a
(none)
author | benoitrigolleau |
---|---|
date | Mon, 28 May 2007 08:14:40 +0000 |
parents | 81921835ddf1 |
children | afcf540ae3a2 |
comparison
equal
deleted
inserted
replaced
58:b3c3a5fa185f | 59:57c85a9d9b4a |
---|---|
35 | 35 |
36 } | 36 } |
37 | 37 |
38 void ItemContainer::addItem(GenericItemList *item){ | 38 void ItemContainer::addItem(GenericItemList *item){ |
39 m_map->insert(m_cpt,item); | 39 m_map->insert(m_cpt,item); |
40 m_linkedList->append(m_cpt); | 40 m_linkedList->prepend(m_cpt); |
41 item->setIndex(m_cpt); | 41 item->setIndex(m_cpt); |
42 if(m_cpt==0){ | |
43 item->setAcceptDrag(false); | |
44 } | |
42 | 45 |
43 std::cerr << "add Item" << std::endl; | 46 std::cerr << "add Item" << std::endl; |
44 connect(item, SIGNAL(itemDropped(int, int)), | 47 connect(item, SIGNAL(itemDropped(int, int)), |
45 this, SLOT(moveItem(int, int))); | 48 this, SLOT(moveItem(int, int))); |
46 connect(item, SIGNAL(selected(int)), | 49 connect(item, SIGNAL(selected(int)), |
47 this, SLOT(newItemSelected(int))); | 50 this, SLOT(newItemSelected(int))); |
48 | 51 |
49 m_itemLayout->addWidget(item); | 52 m_itemLayout->insertWidget(0,item); |
50 m_cpt++; | 53 m_cpt++; |
51 } | 54 } |
52 | 55 |
53 void ItemContainer::setSelectedItem(QVariant &data){ | 56 void ItemContainer::setSelectedItem(QVariant &data){ |
54 | 57 |
80 | 83 |
81 } | 84 } |
82 | 85 |
83 QLinkedList<int>::iterator ItemContainer::find(int value) | 86 QLinkedList<int>::iterator ItemContainer::find(int value) |
84 { | 87 { |
85 QLinkedList<int>::iterator iter; | 88 QLinkedList<int>::iterator i = m_linkedList->begin(); |
86 for(iter = m_linkedList->begin(); iter != m_linkedList->end(); iter++){ | 89 while (i != m_linkedList->end() && *i != value){ |
87 if(*iter == value) | 90 ++i; |
88 return iter; | |
89 } | 91 } |
90 return m_linkedList->end(); | 92 return i; |
91 } | 93 } |
92 | 94 |
93 void ItemContainer::reorganize(){ | 95 void ItemContainer::reorganize(){ |
94 for (int i = 0; i < m_itemLayout->count(); ++i){ | 96 for (int i = 0; i < m_itemLayout->count(); i++){ |
95 m_itemLayout->removeItem(m_itemLayout->itemAt(i)); | 97 m_itemLayout->removeItem(m_itemLayout->itemAt(i)); |
96 } | 98 } |
97 QLinkedList<int>::iterator iter; | 99 QLinkedList<int>::iterator iter; |
98 for(iter = m_linkedList->begin(); iter != m_linkedList->end(); iter++){ | 100 for(iter = m_linkedList->begin(); iter != m_linkedList->end(); iter++){ |
99 m_itemLayout->addWidget(m_map->value(*iter)); | 101 m_itemLayout->addWidget(m_map->value(*iter)); |
133 void ItemContainer::upCurrentItem(){ | 135 void ItemContainer::upCurrentItem(){ |
134 //return if item count <=1 | 136 //return if item count <=1 |
135 if (m_linkedList->count()<= 1){ | 137 if (m_linkedList->count()<= 1){ |
136 return; | 138 return; |
137 } | 139 } |
140 | |
141 QLinkedList<int>::iterator iter; | |
142 // return if current item is the first | |
143 iter = m_linkedList->end()-1; | |
144 if(*iter==m_currentItem){ | |
145 return; | |
146 } | |
138 // return if current item is on top | 147 // return if current item is on top |
139 QLinkedList<int>::iterator iter; | |
140 iter = m_linkedList->begin(); | 148 iter = m_linkedList->begin(); |
141 if(*iter==m_currentItem){ | 149 if(*iter==m_currentItem){ |
142 return; | 150 return; |
143 } | 151 } |
152 | |
144 | 153 |
145 // move item | 154 // move item |
146 for(iter = m_linkedList->begin()+1; iter != m_linkedList->end(); iter++){ | 155 for(iter = m_linkedList->begin()+1; iter != m_linkedList->end(); iter++){ |
147 if(*iter == m_currentItem){ | 156 if(*iter == m_currentItem){ |
148 int itemOnTop = *(iter-1); | 157 int itemOnTop = *(iter-1); |
159 if (m_linkedList->count()<= 1){ | 168 if (m_linkedList->count()<= 1){ |
160 return; | 169 return; |
161 } | 170 } |
162 // return if current item is on bottom | 171 // return if current item is on bottom |
163 QLinkedList<int>::iterator iter; | 172 QLinkedList<int>::iterator iter; |
164 iter = m_linkedList->end(); | 173 iter = m_linkedList->end()-1; |
165 if(*iter==m_currentItem){ | 174 if(*iter==m_currentItem || *(iter-1)==m_currentItem){ |
166 return; | 175 return; |
167 } | 176 } |
168 | 177 |
169 //move item | 178 //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--){ | 179 for(iter = m_linkedList->end()-2; iter != m_linkedList->begin()-1; iter--){ |
175 if(*iter == m_currentItem){ | 180 if(*iter == m_currentItem){ |
176 int itemOnBottom = *(iter+1); | 181 int itemOnBottom = *(iter+1); |
177 *(iter+1)=m_currentItem; | 182 *(iter+1)=m_currentItem; |
178 *iter = itemOnBottom; | 183 *iter = itemOnBottom; |