A stars assessment widget. More...
#include <qxtstars.h>
Public Member Functions | |
QxtStars (QWidget *parent=0) | |
virtual | ~QxtStars () |
bool | isReadOnly () const |
void | setReadOnly (bool readOnly) |
QSize | starSize () const |
void | setStarSize (const QSize &size) |
virtual QSize | sizeHint () const |
virtual QSize | minimumSizeHint () const |
Protected Member Functions | |
virtual void | keyPressEvent (QKeyEvent *event) |
virtual void | mousePressEvent (QMouseEvent *event) |
virtual void | mouseMoveEvent (QMouseEvent *event) |
virtual void | mouseReleaseEvent (QMouseEvent *event) |
virtual void | paintEvent (QPaintEvent *event) |
Properties | |
bool | readOnly |
This property holds whether stars are adjustable. | |
QSize | starSize |
This property holds the size of star icons. | |
Friends | |
class | QxtStarsPrivate |
A stars assessment widget.
QxtStars is an optionally interactive stars assessment widget.
By default, orientation is Qt::Horizonal and range is from 0 to 5.
The stars are rendered accoring to palette with the following color roles:
ColorRole | Element |
QPalette::Text | outlines |
QPalette::Base | unselected stars |
QPalette::Highlight | selected stars |
QxtStars in action.
Definition at line 34 of file qxtstars.h.
QxtStars::QxtStars | ( | QWidget * | parent = 0 ) |
[explicit] |
Constructs a new QxtStars with parent.
Definition at line 156 of file qxtstars.cpp.
References QXT_INIT_PRIVATE.
: QAbstractSlider(parent) { QXT_INIT_PRIVATE(QxtStars); setOrientation(Qt::Horizontal); setFocusPolicy(Qt::FocusPolicy(style()->styleHint(QStyle::SH_Button_FocusPolicy))); setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); setRange(0, 5); }
QxtStars::~QxtStars | ( | ) | [virtual] |
bool QxtStars::isReadOnly | ( | ) | const |
Definition at line 178 of file qxtstars.cpp.
{
return qxt_d().readOnly;
}
void QxtStars::keyPressEvent | ( | QKeyEvent * | event ) | [protected, virtual] |
Definition at line 292 of file qxtstars.cpp.
References readOnly.
{ if (qxt_d().readOnly) { event->ignore(); return; } QAbstractSlider::keyPressEvent(event); }
QSize QxtStars::minimumSizeHint | ( | ) | const [virtual] |
Definition at line 227 of file qxtstars.cpp.
Referenced by sizeHint().
{ QSize size = qxt_d().getStarSize(); size.rwidth() *= maximum() - minimum(); if (orientation() == Qt::Vertical) size.transpose(); return size; }
void QxtStars::mouseMoveEvent | ( | QMouseEvent * | event ) | [protected, virtual] |
Definition at line 335 of file qxtstars.cpp.
References readOnly.
{ if (qxt_d().readOnly) { event->ignore(); return; } QAbstractSlider::mouseMoveEvent(event); event->accept(); int newPosition = qxt_d().pixelPosToRangeValue(qxt_d().pick(event->pos())); QStyleOptionSlider opt = qxt_d().getStyleOption(); int m = style()->pixelMetric(QStyle::PM_MaximumDragDistance, &opt, this); if (m >= 0) { QRect r = rect(); r.adjust(-m, -m, m, m); if (!r.contains(event->pos())) newPosition = qxt_d().snapBackPosition; } setSliderPosition(newPosition); }
void QxtStars::mousePressEvent | ( | QMouseEvent * | event ) | [protected, virtual] |
Definition at line 305 of file qxtstars.cpp.
References readOnly.
{ if (qxt_d().readOnly) { event->ignore(); return; } QAbstractSlider::mousePressEvent(event); if (maximum() == minimum() || (event->buttons() ^ event->button())) { event->ignore(); return; } event->accept(); QStyleOptionSlider opt = qxt_d().getStyleOption(); const QRect sliderRect = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this); const QPoint center = sliderRect.center() - sliderRect.topLeft(); const int pos = qxt_d().pixelPosToRangeValue(qxt_d().pick(event->pos() - center)); setSliderPosition(pos); triggerAction(SliderMove); setRepeatAction(SliderNoAction); qxt_d().snapBackPosition = pos; update(); }
void QxtStars::mouseReleaseEvent | ( | QMouseEvent * | event ) | [protected, virtual] |
Definition at line 361 of file qxtstars.cpp.
References readOnly.
{ if (qxt_d().readOnly) { event->ignore(); return; } QAbstractSlider::mouseReleaseEvent(event); if (event->buttons()) { event->ignore(); return; } event->accept(); setRepeatAction(SliderNoAction); }
void QxtStars::paintEvent | ( | QPaintEvent * | event ) | [protected, virtual] |
Definition at line 239 of file qxtstars.cpp.
References sizeHint().
{ QAbstractSlider::paintEvent(event); QPainter painter(this); painter.save(); painter.setPen(palette().color(QPalette::Text)); painter.setRenderHint(QPainter::Antialiasing); const bool invert = invertedAppearance(); const QSize size = qxt_d().getStarSize(); const QRectF star = qxt_d().star.boundingRect(); painter.scale(size.width() / star.width(), size.height() / star.height()); const int count = maximum() - minimum(); if (orientation() == Qt::Horizontal) { painter.translate(-star.x(), -star.y()); if (invert != isRightToLeft()) painter.translate((count - 1) * star.width(), 0); } else { painter.translate(-star.x(), -star.y()); if (!invert) painter.translate(0, (count - 1) * star.height()); } for (int i = 0; i < count; ++i) { if (value() > minimum() + i) painter.setBrush(palette().highlight()); else painter.setBrush(palette().base()); painter.drawPath(qxt_d().star); if (orientation() == Qt::Horizontal) painter.translate(invert != isRightToLeft() ? -star.width() : star.width(), 0); else painter.translate(0, invert ? star.height() : -star.height()); } painter.restore(); if (hasFocus()) { QStyleOptionFocusRect opt; opt.initFrom(this); opt.rect.setSize(sizeHint()); style()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, &painter, this); } }
void QxtStars::setReadOnly | ( | bool | readOnly ) |
void QxtStars::setStarSize | ( | const QSize & | size ) |
Definition at line 206 of file qxtstars.cpp.
References starSize().
{ if (qxt_d().starSize != size) { qxt_d().starSize = size; updateGeometry(); update(); } }
QSize QxtStars::sizeHint | ( | ) | const [virtual] |
Definition at line 219 of file qxtstars.cpp.
References minimumSizeHint().
Referenced by paintEvent().
{ return minimumSizeHint(); }
QSize QxtStars::starSize | ( | ) | const |
Referenced by setStarSize().
friend class QxtStarsPrivate [friend] |
Definition at line 37 of file qxtstars.h.
QxtStars::readOnly [read, write] |
This property holds whether stars are adjustable.
In read-only mode, the user is not able to change the value. The default value is false.
Definition at line 37 of file qxtstars.h.
Referenced by keyPressEvent(), mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), and setReadOnly().
QSize QxtStars::starSize [read, write] |
This property holds the size of star icons.
The default value is QStyle::PM_SmallIconSize.
Definition at line 39 of file qxtstars.h.