changeset 273:b6c2fa8457b6

Added new list item delegate for drawing a separator.
author Raimund Renkert <rrenkert@intevation.de>
date Wed, 02 Apr 2014 13:38:10 +0200
parents abac76b855b2
children 90432cb1f374
files ui/CMakeLists.txt ui/separatoritemdelegate.cpp ui/separatoritemdelegate.h
diffstat 3 files changed, 63 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ui/CMakeLists.txt	Wed Apr 02 13:37:30 2014 +0200
+++ b/ui/CMakeLists.txt	Wed Apr 02 13:38:10 2014 +0200
@@ -21,6 +21,7 @@
     ${CMAKE_CURRENT_SOURCE_DIR}/aboutdialog.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/statusdialog.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/certificateitemdelegate.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/separatoritemdelegate.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/installwrapper.cpp
     ${CERTIFICATELIST_SOURCES}
     ${DOWNLOADER_SOURCES}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/separatoritemdelegate.cpp	Wed Apr 02 13:38:10 2014 +0200
@@ -0,0 +1,34 @@
+#include <QtWidgets>
+
+#include "separatoritemdelegate.h"
+
+void SeparatorItemDelegate::paint(QPainter *painter,
+    const QStyleOptionViewItem &option, const QModelIndex &index) const
+{
+    // Save the current painter.
+    painter->save();
+
+    // Get the position for separator line.
+    int topLeftY = option.rect.topLeft().y();
+    int height = option.rect.height();
+    int middle = topLeftY + (height / 2);
+
+    // Draw the first part.
+    QPen linePen(Qt::black, 2, Qt::SolidLine);
+    painter->setPen(linePen);
+    painter->drawLine(10, middle, 80, middle);
+
+    // Draw the text.
+    QString text = index.data().toString();
+    QRect rect = option.rect.adjusted(85, -2, 0, -2);
+    painter->drawText(rect.left(), rect.top(), rect.width(), rect.height(),
+        Qt::AlignVCenter|Qt::AlignLeft, text, &rect);
+
+    // Draw the second part.
+    painter->drawLine(rect.topRight().x() + 5, middle, rect.topRight().x() + 75, middle);
+
+    // Restore the painter to have an unmodified painter for the next draw
+    // action.
+    painter->restore();
+    return;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/separatoritemdelegate.h	Wed Apr 02 13:38:10 2014 +0200
@@ -0,0 +1,28 @@
+#ifndef SEPARATORITEMDELEGATE_H
+#define SEPARATORITEMDELEGATE_H
+/**
+ * @file separatoritemdelegate.h
+ * @brief Item delegate drawing a separator in list widgets.
+ *
+ */
+
+#include <QStyledItemDelegate>
+
+class SeparatorItemDelegate : public QStyledItemDelegate
+{
+Q_OBJECT
+
+public:
+    SeparatorItemDelegate(QWidget *parent = 0) : QStyledItemDelegate(parent){}
+
+    /**
+     * @brief Renders the delegate using the given painter and options.
+     *
+     * @param painter   The painter to draw the item.
+     * @param option    The style options.
+     * @param index     The model index of the item to draw.
+     */
+    void paint(QPainter *painter, const QStyleOptionViewItem &option,
+        const QModelIndex &index) const;
+};
+#endif

http://wald.intevation.org/projects/trustbridge/