ZG  "1.00
 All Classes Namespaces Files Functions Variables Enumerator Friends Macros Pages
RosterWidget.h
Go to the documentation of this file.
1 #ifndef RosterWidget_h
2 #define RosterWidget_h
3 
4 #include <QPixmap>
5 #include <QWidget>
6 #include <QTimer>
7 
9 #include "zg/ZGPeerID.h"
10 #include "NoteAssignmentsMap.h"
11 
12 namespace choir {
13 
15 class RosterWidget : public QWidget
16 {
17 Q_OBJECT
18 
19 public:
21  RosterWidget(const ZGPeerID & localPeerID, QWidget * parent = NULL);
22 
24  ~RosterWidget();
25 
27  virtual void showEvent(QShowEvent *);
28 
30  virtual void paintEvent(QPaintEvent *);
31 
33  virtual void mousePressEvent(QMouseEvent *);
34 
36  virtual void mouseMoveEvent(QMouseEvent *);
37 
39  virtual void mouseReleaseEvent(QMouseEvent *);
40 
42  virtual void leaveEvent(QEvent *);
43 
45  virtual void wheelEvent(QWheelEvent *);
46 
51  void SetNotesUsedInMusicSheet(uint64 notesChord);
52 
59  void SetPeerIsOnline(const ZGPeerID & peerID, bool isOnline, const ConstMessageRef & optPeerInfo);
60 
65  void SetSeniorPeerID(const ZGPeerID & pid);
66 
71  void SetNoteAssignments(const ConstNoteAssignmentsMapRef & notesRef) {_assigns = notesRef; update();}
72 
74  int GetVerticalScrollOffset() const {return _scrollOffsetY;}
75 
77  int GetTotalContentHeight() const;
78 
82  void SetReadOnly(bool ro) {if (_readOnly != ro) {_readOnly = ro; update();}}
83 
85  bool IsReadOnl() const {return _readOnly;}
86 
87 signals:
92  void BellPositionClicked(const zg::ZGPeerID & peerID, uint32 noteIdx);
93 
96 
100  void WheelTurned(int dy);
101 
102 public slots:
106  void SetVerticalScrollOffset(int vso) {_scrollOffsetY = vso; update();}
107 
111  void AnimateLocalBells(quint64 notesChord);
112 
116  void SetLatenciesTable(Hashtable<ZGPeerID, uint64> & latenciesTable);
117 
118 private slots:
119  void ClearAnimatedLocalBells();
120 
121 private:
122  QString GetPeerNickname(const ZGPeerID & pid) const;
123 
124  int GetYForRow(uint32 rowIdx) const;
125  uint32 GetRowForY(int y) const;
126 
127  int GetXForColumn(uint32 colIdx) const;
128  uint32 GetColumnForX(int x) const;
129 
130  uint32 GetRowForPeerID(const ZGPeerID & pid) const {return (uint32) _onlinePeers.IndexOfKey(pid);}
131  const ZGPeerID & GetPeerIDForRow(uint32 row) const {return _onlinePeers.GetKeyAtWithDefault(row);}
132 
133  uint32 GetColumnForNoteIndex(uint32 noteIdx) const {return _noteIndexToColumnIndex.GetWithDefault(noteIdx, MUSCLE_NO_LIMIT);}
134  uint32 GetNoteIndexForColumn(uint32 colIdx) const {return _columnIndexToNoteIndex.GetWithDefault(colIdx, MUSCLE_NO_LIMIT);}
135 
136  int GetYForPeerID(const ZGPeerID & peerID) const {return GetYForRow(GetRowForPeerID(peerID));}
137  const ZGPeerID & GetPeerIDForY(int y) const {return GetPeerIDForRow(GetRowForY(y));}
138 
139  int GetXForNoteIndex(uint32 noteIndex) const {return GetXForColumn(GetColumnForNoteIndex(noteIndex));}
140  uint32 GetNoteIndexForX(int x) const {return GetNoteIndexForColumn(GetColumnForX(x));}
141 
142  void DrawShadedRow(QPainter & p, const ZGPeerID & peerID, const QColor & c);
143  void DrawBell(QPainter & p, uint32 rowIdx, uint32 colIdx, bool shakeIt) const;
144  void DrawBellAt(QPainter & p, int x, int y) const;
145 
146  void HandleMouseEvent(QMouseEvent * e, bool isPress);
147 
148  const ZGPeerID _localPeerID;
149  const QPixmap _bellPixmap;
150 
151  OrderedKeysHashtable<ZGPeerID, ConstMessageRef> _onlinePeers; // the rows we are currently showing
152  Hashtable<ZGPeerID, uint64> _peerNoteAssignments; // which peers should be doing which notes
153 
154  // our current column<->noteIndex mapping
155  uint64 _currentNotesChord;
156  Queue<uint32> _columnIndexToNoteIndex;
157  Hashtable<uint32, uint32> _noteIndexToColumnIndex;
158 
159  ConstNoteAssignmentsMapRef _assigns;
160  int _scrollOffsetY;
161 
162  QString _noteNames[NUM_CHOIR_NOTES];
163  int _draggingNoteIdx;
164  int _draggingNoteY; // widget-coords: only valid if (_draggingNoteIdx>=0)
165  int _draggingNoteYStart; // widget-coords: where the drag started
166  int _draggingNoteYOffset; // difference between where the user started the drag, and the middle of the cell
167 
168  bool _readOnly;
169  uint64 _animatedBells;
170 
171  Hashtable<ZGPeerID, uint64> _peerIDToLatency; // updated at a constant rate, just to make the GUI look better
172  ZGPeerID _seniorPeerID;
173 
174  QFont _drawFont;
175  QFont _italicizedFont;
176 };
177 
178 }; // end namespace choir
179 
180 #endif
void SetLatenciesTable(Hashtable< ZGPeerID, uint64 > &latenciesTable)
Sets the latency values we should display to the user at the right-hand side of the grid...
virtual void leaveEvent(QEvent *)
Called when the mouse pointer exits the RosterWidget's on-screen area.
virtual void wheelEvent(QWheelEvent *)
Called when the user turns the mouse-wheel while the mouse is over the RosterWidget.
~RosterWidget()
Destructor.
bool IsReadOnl() const
Returns true iff this view is currently in read-only mode.
Definition: RosterWidget.h:85
void TotalContentHeightChanged()
Emitted whenever rows are added or removed from this view's grid.
int GetVerticalScrollOffset() const
Returns how many pixels we have scrolled down from the top of the view.
Definition: RosterWidget.h:74
virtual void showEvent(QShowEvent *)
Called when the RosterWidget first appears on screen.
virtual void paintEvent(QPaintEvent *)
Called when it's time to repaint the RosterWidget.
void BellPositionClicked(const zg::ZGPeerID &peerID, uint32 noteIdx)
Emitted whenever a cell in the grid is clicked on by the user.
void SetVerticalScrollOffset(int vso)
Sets our vertical-scroll offset.
Definition: RosterWidget.h:106
void WheelTurned(int dy)
Emitted whenever the user turns his little mouse-wheel while hovering over this view.
void AnimateLocalBells(quint64 notesChord)
Causes the bells specified in the bit-chord to visually vibrate, as if they had been struck...
int GetTotalContentHeight() const
Returns The total height of the view's contents.
virtual void mousePressEvent(QMouseEvent *)
Called when the user presses down on the mouse button while over the RosterWidget.
void SetSeniorPeerID(const ZGPeerID &pid)
Called whenever the senior-peer of the system changes.
A ZGPeerID is a 128-bit integer that uniquely represents a particular peer in a ZG system...
Definition: ZGPeerID.h:18
void SetReadOnly(bool ro)
Set whether this widget should allow user input via mouse-clicks or not.
Definition: RosterWidget.h:82
RosterWidget(const ZGPeerID &localPeerID, QWidget *parent=NULL)
Constructor.
The choir namespace contains the code specific to the ZGChoir demonstration application.
Definition: ChoirNameSpace.h:7
void SetNoteAssignments(const ConstNoteAssignmentsMapRef &notesRef)
Called to set the NotesAssignmentMap that the RosterWidget should consult to render handbell icons...
Definition: RosterWidget.h:71
This widget displays the current table of note assignments, as contained in our NoteAssignmentsMap.
Definition: RosterWidget.h:15
virtual void mouseMoveEvent(QMouseEvent *)
Called when the user drags the mouse on the RosterWidget.
virtual void mouseReleaseEvent(QMouseEvent *)
Called when the user releases the mouse button while over the RosterWidget.
void SetPeerIsOnline(const ZGPeerID &peerID, bool isOnline, const ConstMessageRef &optPeerInfo)
Called when a peer comes online or goes offline.
void SetNotesUsedInMusicSheet(uint64 notesChord)
Called to tell the RosterWidget which notes are used in the current song.