1 //=========================================================
2 //  MusE
3 //  Linux Music Editor
4 //    $Id: citem.cpp,v 1.2.2.3 2008/01/26 07:23:21 terminator356 Exp $
5 //  (C) Copyright 1999 Werner Schweer (ws@seh.de)
6 //
7 //  This program is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU General Public License
9 //  as published by the Free Software Foundation; version 2 of
10 //  the License, or (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU General Public License for more details.
16 //
17 //  You should have received a copy of the GNU General Public License
18 //  along with this program; if not, write to the Free Software
19 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 //=========================================================
22 
23 #include "citem.h"
24 #include "undo.h"
25 #include "song.h"
26 #include <stdio.h>
27 
28 // Forwards from header:
29 #include "part.h"
30 #include "pos.h"
31 
32 namespace MusEGui {
33 
34 //---------------------------------------------------------
35 //   CItem
36 //---------------------------------------------------------
37 
CItem()38 CItem::CItem()
39       {
40       _isSelected = false;
41       _isMoving = false;
42       }
43 
44 //---------------------------------------------------------
45 //   BItem
46 //---------------------------------------------------------
47 
BItem(const QPoint & p,const QRect & r)48 BItem::BItem(const QPoint&p, const QRect& r) : CItem()
49       {
50       _pos   = p;
51       _bbox  = r;
52       }
53 
54 //---------------------------------------------------------
55 //   PItem
56 //---------------------------------------------------------
57 
PItem(const QPoint & p,const QRect & r)58 PItem::PItem(const QPoint& p, const QRect& r) : BItem(p, r)
59 {
60   _part = NULL;
61 }
62 
PItem()63 PItem::PItem() : BItem()
64 {
65   _part = NULL;
66 }
67 
PItem(MusECore::Part * p)68 PItem::PItem(MusECore::Part* p) : BItem()
69 {
70   _part = p;
71 }
72 
objectIsSelected() const73 bool PItem::objectIsSelected() const
74 {
75   return _part->selected();
76 }
77 
78 //---------------------------------------------------------
79 //   EItem
80 //---------------------------------------------------------
81 
EItem(const QPoint & p,const QRect & r)82 EItem::EItem(const QPoint&p, const QRect& r) : PItem(p, r)
83       {
84       }
85 
EItem(const MusECore::Event & e,MusECore::Part * p)86 EItem::EItem(const MusECore::Event& e, MusECore::Part* p) : PItem(p)
87       {
88       _event = e;
89       }
90 
isObjectInRange(const MusECore::Pos & p0,const MusECore::Pos & p1) const91 bool EItem::isObjectInRange(const MusECore::Pos& p0, const MusECore::Pos& p1) const
92 {
93   MusECore::Pos pos = _event.pos();
94   if(_part)
95     pos += (*_part);
96   return pos >= p0 && pos < p1;
97 }
98 
99 //---------------------------------------------------------
100 //   CItemMap
101 //---------------------------------------------------------
102 
find(const QPoint & pos) const103 CItem* CItemMap::find(const QPoint& pos) const
104       {
105       CItem* item = 0;
106       for (rciCItem i = rbegin(); i != rend(); ++i) {
107             if (i->second->contains(pos))
108             {
109               if(i->second->isSelected())
110                   return i->second;
111 
112               else
113               {
114                 if(!item)
115                   item = i->second;
116               }
117             }
118           }
119       return item;
120       }
121 
122 //---------------------------------------------------------
123 //   CItemMap
124 //---------------------------------------------------------
125 
add(CItem * item)126 void CItemMap::add(CItem* item)
127       {
128       std::multimap<int, CItem*, std::less<int> >::insert(std::pair<const int, CItem*> (item->bbox().x(), item));
129       }
130 
131 } // namespace MusEGui
132