commit 7c25ed518387ec31df516af1fe98ef121beb0f56 Author: Sebastian Baginski sebthestampede@gmail.com Date: Mon May 14 16:25:43 2012 +0200
visual feedback from vclicklabel when "pressed" --- changes/bug5766 | 3 +++ src/vidalia/VClickLabel.cpp | 32 +++++++++++++++++++++++++------- src/vidalia/VClickLabel.h | 3 +++ 3 files changed, 31 insertions(+), 7 deletions(-)
diff --git a/changes/bug5766 b/changes/bug5766 new file mode 100644 index 0000000..6332721 --- /dev/null +++ b/changes/bug5766 @@ -0,0 +1,3 @@ + New Features: + o Add visual feedback from VClickLabel when in "pressed" state. + Resolves ticket 5766. diff --git a/src/vidalia/VClickLabel.cpp b/src/vidalia/VClickLabel.cpp index 0165de4..a20df07 100644 --- a/src/vidalia/VClickLabel.cpp +++ b/src/vidalia/VClickLabel.cpp @@ -25,6 +25,7 @@ VClickLabel::VClickLabel(QWidget *parent) { setCursor(Qt::PointingHandCursor); _flashToggle = false; + _isPressed = false; }
/** Returns the current size hint for this widget's current contents. */ @@ -50,7 +51,7 @@ VClickLabel::paintEvent(QPaintEvent *e) QPainter p(this); QRect rect = this->rect();
- if(_flashToggle) { + if (_flashToggle || _isPressed) { p.setBrush(QColor(150,150,150)); rect.setX(rect.x()+1); rect.setY(rect.y()+1); @@ -60,30 +61,47 @@ VClickLabel::paintEvent(QPaintEvent *e) }
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 (!_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()) - 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 { if (!_pixmap.isNull()) - p.drawPixmap(qMax(rect.right()-_pixmap.width(), 0), - qMax((rect.height()-_pixmap.height())/2, 0), _pixmap); + p.drawPixmap(qMax(rect.right()-_pixmap.width()-d, d), + qMax((rect.height()-_pixmap.height())/2-d, d), _pixmap); if (!_text.isEmpty()) { int textWidth = fontMetrics().width(_text); - p.drawText(qMax(rect.right()-_pixmap.width()-textWidth-2, 0), - (rect.height()+fontInfo().pixelSize())/2, _text); + p.drawText(qMax(rect.right()-_pixmap.width()-textWidth-2-d, d), + (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(); +} + /** Overloaded mouse event to catch left mouse button clicks. */ void VClickLabel::mouseReleaseEvent(QMouseEvent *e) { if (e->button() == Qt::LeftButton) { + _isPressed = false; + update(); emit clicked(); } e->accept(); diff --git a/src/vidalia/VClickLabel.h b/src/vidalia/VClickLabel.h index c9c0766..acdc58e 100644 --- a/src/vidalia/VClickLabel.h +++ b/src/vidalia/VClickLabel.h @@ -59,6 +59,8 @@ signals: protected: /** Overloaded paint event to draw a pixmap and a text label. */ 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. */ virtual void mouseReleaseEvent(QMouseEvent *e);
@@ -66,6 +68,7 @@ private: QString _text; /**< Text label to display in the widget. */ QPixmap _pixmap; /**< Image to display in the widget. */ bool _flashToggle;/**< Bool toggle for flashing the button. */ + bool _isPressed; /**< Remember if label is currently pressed. */ };
#endif
tor-commits@lists.torproject.org