diff options
| author | Tannin <devnull@localhost> | 2015-01-03 15:58:52 +0100 |
|---|---|---|
| committer | Tannin <devnull@localhost> | 2015-01-03 15:58:52 +0100 |
| commit | a16e25380f088dc310fbed24d2dcef603357e99a (patch) | |
| tree | 40fc3b5254f2797eb20bfac1d54a22652d469fa2 /src/viewmarkingscrollbar.cpp | |
| parent | 459816ab71ae6b350847cc93f1e03e49ecf75ade (diff) | |
| parent | f2f9e11fdd876821107cff0c1c5b9d8ecf66691f (diff) | |
Merge with branch1.2
Diffstat (limited to 'src/viewmarkingscrollbar.cpp')
| -rw-r--r-- | src/viewmarkingscrollbar.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/viewmarkingscrollbar.cpp b/src/viewmarkingscrollbar.cpp new file mode 100644 index 00000000..f1b1ba34 --- /dev/null +++ b/src/viewmarkingscrollbar.cpp @@ -0,0 +1,42 @@ +#include "viewmarkingscrollbar.h"
+#include <QStyle>
+#include <QStyleOptionSlider>
+#include <QPainter>
+
+ViewMarkingScrollBar::ViewMarkingScrollBar(QAbstractItemModel *model, QWidget *parent, int role)
+ : QScrollBar(parent)
+ , m_Model(model)
+ , m_Role(role)
+{
+ // not implemented for horizontal sliders
+ Q_ASSERT(this->orientation() == Qt::Vertical);
+}
+
+void ViewMarkingScrollBar::paintEvent(QPaintEvent *event)
+{
+ if (m_Model == NULL) {
+ return;
+ }
+ QScrollBar::paintEvent(event);
+
+ QStyleOptionSlider styleOption;
+ initStyleOption(&styleOption);
+
+ QPainter painter(this);
+
+ QRect handleRect = style()->subControlRect(QStyle::CC_ScrollBar, &styleOption, QStyle::SC_ScrollBarSlider, this);
+ QRect innerRect = style()->subControlRect(QStyle::CC_ScrollBar, &styleOption, QStyle::SC_ScrollBarGroove, this);
+
+ painter.translate(innerRect.topLeft() + QPoint(0, 3));
+ qreal scale = static_cast<qreal>(innerRect.height() - 3) / static_cast<qreal>(m_Model->rowCount());
+
+ for (int i = 0; i < m_Model->rowCount(); ++i) {
+ QVariant data = m_Model->data(m_Model->index(i, 0), m_Role);
+ if (data.isValid()) {
+ QColor col = data.value<QColor>();
+ painter.setPen(col);
+ painter.setBrush(col);
+ painter.drawRect(QRect(2, i * scale - 2, handleRect.width() - 5, 3));
+ }
+ }
+}
|
