PenStyleItemDelegate.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * Copyright (C) 2015 by Ralf Kaestner                                        *
00003  * ralf.kaestner@gmail.com                                                    *
00004  *                                                                            *
00005  * This program is free software; you can redistribute it and/or modify       *
00006  * it under the terms of the Lesser GNU General Public License as published by*
00007  * the Free Software Foundation; either version 3 of the License, or          *
00008  * (at your option) any later version.                                        *
00009  *                                                                            *
00010  * This program is distributed in the hope that it will be useful,            *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the               *
00013  * Lesser GNU General Public License for more details.                        *
00014  *                                                                            *
00015  * You should have received a copy of the Lesser GNU General Public License   *
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>.       *
00017  ******************************************************************************/
00018 
00019 #include <QPainter>
00020 
00021 #include "rqt_multiplot/PenStyleItemDelegate.h"
00022 
00023 namespace rqt_multiplot {
00024 
00025 /*****************************************************************************/
00026 /* Constructors and Destructor                                               */
00027 /*****************************************************************************/
00028 
00029 PenStyleItemDelegate::PenStyleItemDelegate(QWidget* parent) :
00030   QItemDelegate(parent) {
00031 }
00032 
00033 PenStyleItemDelegate::~PenStyleItemDelegate() {
00034 }
00035 
00036 /*****************************************************************************/
00037 /* Methods                                                                   */
00038 /*****************************************************************************/
00039 
00040 void PenStyleItemDelegate::paint(QPainter* painter, const
00041     QStyleOptionViewItem& option, const QModelIndex& index) const {
00042   QVariant data = index.model()->data(index, Qt::UserRole);
00043 
00044   if (option.state & QStyle::State_Selected)
00045     painter->fillRect(option.rect, option.palette.highlight());
00046   
00047   if (data.isValid()) {
00048     painter->save();
00049 
00050     QPen pen = painter->pen();
00051 
00052     if (option.state & QStyle::State_Selected)
00053       pen.setColor(option.palette.color(QPalette::HighlightedText));
00054     else
00055       pen.setColor(option.palette.color(QPalette::Text));
00056     
00057     pen.setWidth(1);
00058     pen.setStyle(static_cast<Qt::PenStyle>(data.toInt()));
00059     
00060     painter->setPen(pen);
00061     painter->drawLine(option.rect.left(), option.rect.center().y(),
00062       option.rect.right(), option.rect.center().y());
00063 
00064     painter->restore();
00065   }
00066   else
00067     QItemDelegate::paint(painter, option, index);
00068 }
00069 
00070 }


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Thu Jun 6 2019 21:49:11