rock_widget_collection  0.1
Signals | Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
SlideBarItem Class Reference

#include <SlideBarItem.h>

Inherits QObject, and QGraphicsItem.

Signals

void bookmarkClicked (int idx)
 

Public Member Functions

 SlideBarItem (unsigned startIndex, unsigned steps, unsigned stepSize, QGraphicsItem *parent=0)
 
void reconfigure (unsigned startIndex, unsigned steps, unsigned stepSize)
 
QRectF boundingRect () const
 
void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
 
unsigned getStartIndex () const
 
qreal getBookmarkHeight () const
 
void setBookmarkHeight (qreal height)
 
void setIndexSliderHeight (int height)
 
void addTimeMarker (BoundarySlider *marker)
 
const QList< BoundarySlider * > & getTimeMarkers ()
 
const QList< Slider * > & getAllSliders ()
 
BoundarySlidermarkerOverlap (BoundarySlider *marker)
 
bool markerContainsPoint (BoundarySlider *marker, const QPointF &point)
 
unsigned markerIndex (Slider *marker)
 
int markerPositionForIndex (unsigned index)
 
IndexSlidergetIndexSlider ()
 
void updateBookmarks (QVector< int > &bookmarks)
 
void setWidth (int width)
 
void setHeight (int width)
 
int getWidth () const
 
int getHeight () const
 

Static Public Attributes

static const int HEIGHT = 3
 

Protected Member Functions

void mousePressEvent (QGraphicsSceneMouseEvent *event)
 

Detailed Description

Definition at line 8 of file SlideBarItem.h.

Constructor & Destructor Documentation

◆ SlideBarItem()

SlideBarItem::SlideBarItem ( unsigned  startIndex,
unsigned  steps,
unsigned  stepSize,
QGraphicsItem *  parent = 0 
)

Definition at line 9 of file SlideBarItem.cc.

9  :
10  QGraphicsItem(parent),height(10),width(100), color(QColor(Qt::gray))
11 {
12  reconfigure(startIndex, steps, stepSize);
13  slider = new IndexSlider(this, startIndex);
14  allSliders.append(slider);
15 }
void reconfigure(unsigned startIndex, unsigned steps, unsigned stepSize)
Definition: SlideBarItem.cc:17

Member Function Documentation

◆ addTimeMarker()

void SlideBarItem::addTimeMarker ( BoundarySlider marker)

Definition at line 72 of file SlideBarItem.cc.

72  {
73  timeMarkers.append(marker);
74  allSliders.append(marker);
75  marker->setLastIndex(markerIndex(marker));
76 }
unsigned markerIndex(Slider *marker)
void setLastIndex(unsigned index)
Definition: Slider.cc:55

◆ bookmarkClicked

void SlideBarItem::bookmarkClicked ( int  idx)
signal

◆ boundingRect()

QRectF SlideBarItem::boundingRect ( ) const

Definition at line 24 of file SlideBarItem.cc.

24  {
25  return QRectF(0, 0, getWidth(), getHeight());
26 }
int getWidth() const
Definition: SlideBarItem.cc:64
int getHeight() const
Definition: SlideBarItem.cc:68

◆ getAllSliders()

const QList< Slider * > & SlideBarItem::getAllSliders ( )

Definition at line 82 of file SlideBarItem.cc.

82  {
83  return allSliders;
84 }

◆ getBookmarkHeight()

qreal SlideBarItem::getBookmarkHeight ( ) const

Definition at line 48 of file SlideBarItem.cc.

48  {
49  return bookmark_height;
50 }

◆ getHeight()

int SlideBarItem::getHeight ( ) const

Definition at line 68 of file SlideBarItem.cc.

68  {
69  return height;
70 }

◆ getIndexSlider()

IndexSlider * SlideBarItem::getIndexSlider ( )

Definition at line 141 of file SlideBarItem.cc.

141  {
142  return slider;
143 }

◆ getStartIndex()

unsigned SlideBarItem::getStartIndex ( ) const

Definition at line 43 of file SlideBarItem.cc.

43  {
44  return startIndex;
45 }

◆ getTimeMarkers()

const QList< BoundarySlider * > & SlideBarItem::getTimeMarkers ( )

Definition at line 78 of file SlideBarItem.cc.

78  {
79  return timeMarkers;
80 }

◆ getWidth()

int SlideBarItem::getWidth ( ) const

Definition at line 64 of file SlideBarItem.cc.

64  {
65  return width;
66 }

◆ markerContainsPoint()

bool SlideBarItem::markerContainsPoint ( BoundarySlider marker,
const QPointF &  point 
)

Definition at line 119 of file SlideBarItem.cc.

119  {
120  Q_FOREACH(BoundarySlider* otherMarker, timeMarkers) {
121  if(otherMarker == marker) {
122  continue;
123  }
124  if(otherMarker->contains(point)) {
125  return true;
126  }
127  }
128  return false;
129 }

◆ markerIndex()

unsigned SlideBarItem::markerIndex ( Slider marker)

Definition at line 131 of file SlideBarItem.cc.

131  {
132  //std::cout << "slidebar pos.x()" << pos().x() << std::endl;
133  //std::cout << "marker pos.x()" << marker->pos().x()
134  return (unsigned) QStyle::sliderValueFromPosition(startIndex, steps*stepSize, marker->pos().x(), getWidth());
135 }
int getWidth() const
Definition: SlideBarItem.cc:64

◆ markerOverlap()

BoundarySlider * SlideBarItem::markerOverlap ( BoundarySlider marker)

Definition at line 86 of file SlideBarItem.cc.

86  {
87  Q_FOREACH(BoundarySlider* otherMarker, timeMarkers) {
88  if(otherMarker == marker) {
89  continue;
90  }
91 
92  bool overlap = false;
93 
94  switch(marker->leftRight(otherMarker)) {
95  case RIGHT :
96  // marker is right hand side
97  if(marker->pos().x() < otherMarker->pos().x()) {
98  overlap = true;
99  }
100  break;
101  case LEFT :
102  // marker is left hand side or right on top
103  if(marker->pos().x() >= otherMarker->pos().x()) {
104  overlap = true;
105  }
106  break;
107  default :
108  std::cerr << "Unknown direction!" << std::endl;
109  exit(EXIT_FAILURE);
110  }
111 
112  if(marker->collidesWithItem(otherMarker) || overlap) {
113  return otherMarker;
114  }
115  }
116  return NULL;
117 }
Direction leftRight(BoundarySlider *otherMarker)

◆ markerPositionForIndex()

int SlideBarItem::markerPositionForIndex ( unsigned  index)

Definition at line 137 of file SlideBarItem.cc.

137  {
138  return QStyle::sliderPositionFromValue(startIndex, steps*stepSize, index, getWidth());
139 }
int getWidth() const
Definition: SlideBarItem.cc:64

◆ mousePressEvent()

void SlideBarItem::mousePressEvent ( QGraphicsSceneMouseEvent *  event)
protected

Definition at line 150 of file SlideBarItem.cc.

150  {
151  // Check if bookmark was clicked
152  Q_FOREACH(int bookmark, bookmarks) {
153  // Define click region for bookmarks
154  QRectF clickRegion(markerPositionForIndex(bookmark)-2, pos().y() - (getBookmarkHeight()/2.0), 5, getBookmarkHeight());
155  if(clickRegion.contains(event->pos())) {
156  // Bookmark clicked!
157  emit bookmarkClicked(bookmark);
158  break;
159  }
160  }
161 }
int markerPositionForIndex(unsigned index)
qreal getBookmarkHeight() const
Definition: SlideBarItem.cc:48
void bookmarkClicked(int idx)

◆ paint()

void SlideBarItem::paint ( QPainter *  painter,
const QStyleOptionGraphicsItem *  option,
QWidget *  widget 
)

Definition at line 28 of file SlideBarItem.cc.

28  {
29  Q_UNUSED(option);
30  Q_UNUSED(widget);
31  painter->setPen(QPen(Qt::black, 1));
32  painter->setBrush(QBrush(color));
33  int center = getHeight() * 0.5;
34  painter->fillRect(0, center, getWidth(), HEIGHT, color);
35  Q_FOREACH(unsigned bookmark, bookmarks) {
36  int x_pos = markerPositionForIndex(bookmark);
37  int y_top = center-(getBookmarkHeight()/2)+SlideBarItem::HEIGHT/2;
38  int y_bottom = y_top + getBookmarkHeight();
39  painter->drawLine(x_pos, y_top, x_pos, y_bottom);
40  }
41 }
int markerPositionForIndex(unsigned index)
qreal getBookmarkHeight() const
Definition: SlideBarItem.cc:48
static const int HEIGHT
Definition: SlideBarItem.h:15
int getWidth() const
Definition: SlideBarItem.cc:64
int getHeight() const
Definition: SlideBarItem.cc:68

◆ reconfigure()

void SlideBarItem::reconfigure ( unsigned  startIndex,
unsigned  steps,
unsigned  stepSize 
)

Definition at line 17 of file SlideBarItem.cc.

17  {
18  LOG_DEBUG("Reconfiguring slidebar: startIndex=%d, steps=%d, stepSize=%d\n", startIndex, steps, stepSize);
19  this->startIndex = startIndex;
20  this->steps = steps;
21  this->stepSize = stepSize;
22 }

◆ setBookmarkHeight()

void SlideBarItem::setBookmarkHeight ( qreal  height)

Definition at line 52 of file SlideBarItem.cc.

52  {
53  this->bookmark_height = bookmark_height;
54 }

◆ setHeight()

void SlideBarItem::setHeight ( int  width)

Definition at line 60 of file SlideBarItem.cc.

60  {
61  this->height = height;
62 }

◆ setIndexSliderHeight()

void SlideBarItem::setIndexSliderHeight ( int  height)

◆ setWidth()

void SlideBarItem::setWidth ( int  width)

Definition at line 56 of file SlideBarItem.cc.

56  {
57  this->width = width;
58 }

◆ updateBookmarks()

void SlideBarItem::updateBookmarks ( QVector< int > &  bookmarks)

Definition at line 145 of file SlideBarItem.cc.

145  {
146  this->bookmarks = bookmarks;
147  update();
148 }

Member Data Documentation

◆ HEIGHT

const int SlideBarItem::HEIGHT = 3
static

Definition at line 15 of file SlideBarItem.h.


The documentation for this class was generated from the following files: