Commit 7c25ed51 authored by Sebastian Baginski's avatar Sebastian Baginski
Browse files

visual feedback from vclicklabel when "pressed"

parent 13280e49
Loading
Loading
Loading
Loading

changes/bug5766

0 → 100644
+3 −0
Original line number Original line Diff line number Diff line
  New Features:
  o Add visual feedback from VClickLabel when in "pressed" state.
    Resolves ticket 5766.
+25 −7
Original line number Original line Diff line number Diff line
@@ -25,6 +25,7 @@ VClickLabel::VClickLabel(QWidget *parent)
{
{
  setCursor(Qt::PointingHandCursor);
  setCursor(Qt::PointingHandCursor);
  _flashToggle = false;
  _flashToggle = false;
  _isPressed = false;
}
}


/** Returns the current size hint for this widget's current contents. */
/** Returns the current size hint for this widget's current contents. */
@@ -50,7 +51,7 @@ VClickLabel::paintEvent(QPaintEvent *e)
  QPainter p(this);
  QPainter p(this);
  QRect rect = this->rect();
  QRect rect = this->rect();


  if(_flashToggle) {
  if (_flashToggle || _isPressed) {
    p.setBrush(QColor(150,150,150));
    p.setBrush(QColor(150,150,150));
    rect.setX(rect.x()+1);
    rect.setX(rect.x()+1);
    rect.setY(rect.y()+1);
    rect.setY(rect.y()+1);
@@ -61,20 +62,35 @@ VClickLabel::paintEvent(QPaintEvent *e)


  rect = this->rect();
  rect = this->rect();
  
  
  // when label is in "pressed" state, we will translate the pixmap and text
  // a bit, just like regular buttons do
  const int d = _isPressed ? 2 : 0;

  if (vApp->isLeftToRight()) {
  if (vApp->isLeftToRight()) {
    if (!_pixmap.isNull())
    if (!_pixmap.isNull())
      p.drawPixmap(0, qMax((rect.height()-_pixmap.height())/2, 0), _pixmap);
      p.drawPixmap(d, qMax((rect.height()-_pixmap.height())/2+d, 0), _pixmap);
    if (!_text.isEmpty())
    if (!_text.isEmpty())
      p.drawText(_pixmap.width()+2, (rect.height()+fontInfo().pixelSize())/2, _text);
      p.drawText(_pixmap.width()+2+d, (rect.height()+fontInfo().pixelSize())/2+d, _text);
  } else {
  } else {
    if (!_pixmap.isNull())
    if (!_pixmap.isNull())
      p.drawPixmap(qMax(rect.right()-_pixmap.width(), 0),
      p.drawPixmap(qMax(rect.right()-_pixmap.width()-d, d),
                   qMax((rect.height()-_pixmap.height())/2, 0), _pixmap);
                   qMax((rect.height()-_pixmap.height())/2-d, d), _pixmap);
    if (!_text.isEmpty()) {
    if (!_text.isEmpty()) {
      int textWidth  = fontMetrics().width(_text);
      int textWidth  = fontMetrics().width(_text);
      p.drawText(qMax(rect.right()-_pixmap.width()-textWidth-2, 0),
      p.drawText(qMax(rect.right()-_pixmap.width()-textWidth-2-d, d),
                 (rect.height()+fontInfo().pixelSize())/2, _text);
                 (rect.height()+fontInfo().pixelSize())/2-d, _text);
    }
  }
  }
  e->accept();
}

/** Overloaded mouse event to remember click state. */
void
VClickLabel::mousePressEvent(QMouseEvent * e)
{
  if (e->button() == Qt::LeftButton) {
    _isPressed = true;
    update();
  }
  }
  e->accept();
  e->accept();
}
}
@@ -84,6 +100,8 @@ void
VClickLabel::mouseReleaseEvent(QMouseEvent *e)
VClickLabel::mouseReleaseEvent(QMouseEvent *e)
{
{
  if (e->button() == Qt::LeftButton) {
  if (e->button() == Qt::LeftButton) {
    _isPressed = false;
    update();
    emit clicked();
    emit clicked();
  }
  }
  e->accept();
  e->accept();
+3 −0
Original line number Original line Diff line number Diff line
@@ -59,6 +59,8 @@ signals:
protected:
protected:
  /** Overloaded paint event to draw a pixmap and a text label. */
  /** Overloaded paint event to draw a pixmap and a text label. */
  virtual void paintEvent(QPaintEvent *e);
  virtual void paintEvent(QPaintEvent *e);
  /** Overloaded mouse event to remember click state. */
  virtual void mousePressEvent(QMouseEvent * e);
  /** Overloaded mouse event to catch left mouse button clicks. */
  /** Overloaded mouse event to catch left mouse button clicks. */
  virtual void mouseReleaseEvent(QMouseEvent *e);
  virtual void mouseReleaseEvent(QMouseEvent *e);


@@ -66,6 +68,7 @@ private:
  QString _text;    /**< Text label to display in the widget. */
  QString _text;    /**< Text label to display in the widget. */
  QPixmap _pixmap;  /**< Image to display in the widget. */
  QPixmap _pixmap;  /**< Image to display in the widget. */
  bool _flashToggle;/**< Bool toggle for flashing the button. */
  bool _flashToggle;/**< Bool toggle for flashing the button. */
  bool _isPressed;  /**< Remember if label is currently pressed. */
};
};


#endif
#endif