PenStyleComboBox.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 #include <QPaintEvent>
00021 #include <QPen>
00022 
00023 #include <rqt_multiplot/PenStyleItemDelegate.h>
00024 
00025 #include "rqt_multiplot/PenStyleComboBox.h"
00026 
00027 namespace rqt_multiplot {
00028 
00029 /*****************************************************************************/
00030 /* Constructors and Destructor                                               */
00031 /*****************************************************************************/
00032 
00033 PenStyleComboBox::PenStyleComboBox(QWidget* parent) :
00034   QComboBox(parent) {
00035   setItemDelegate(new PenStyleItemDelegate(this));
00036     
00037   for (int style = Qt::SolidLine; style < Qt::CustomDashLine; ++style)
00038     addItem("", style);    
00039   
00040   connect(this, SIGNAL(currentIndexChanged(int)), this,
00041     SLOT(currentIndexChanged(int)));
00042 }
00043 
00044 PenStyleComboBox::~PenStyleComboBox() {
00045 }
00046 
00047 /*****************************************************************************/
00048 /* Accessors                                                                 */
00049 /*****************************************************************************/
00050 
00051 void PenStyleComboBox::setCurrentStyle(Qt::PenStyle style) {
00052   setCurrentIndex(style-Qt::SolidLine);
00053 }
00054 
00055 Qt::PenStyle PenStyleComboBox::getCurrentStyle() const {
00056   return static_cast<Qt::PenStyle>(Qt::SolidLine+currentIndex());
00057 }
00058 
00059 /*****************************************************************************/
00060 /* Methods                                                                   */
00061 /*****************************************************************************/
00062 
00063 void PenStyleComboBox::paintEvent(QPaintEvent* event) {
00064   QComboBox::paintEvent(event);
00065   
00066   QVariant data = itemData(currentIndex(), Qt::UserRole);
00067   
00068   if (data.isValid()) {
00069     QPainter painter(this);
00070     QPen pen;
00071     
00072     pen.setColor(palette().color(QPalette::Text));
00073     pen.setWidth(1);
00074     pen.setStyle(static_cast<Qt::PenStyle>(data.toInt()));
00075     
00076     painter.setPen(pen);
00077     painter.drawLine(event->rect().left()+5, event->rect().center().y(),
00078       event->rect().right()-20, event->rect().center().y());
00079   }
00080 }
00081 
00082 /*****************************************************************************/
00083 /* Slots                                                                     */
00084 /*****************************************************************************/
00085 
00086 void PenStyleComboBox::currentIndexChanged(int index) {
00087   if (index >= 0)
00088     emit currentStyleChanged(static_cast<Qt::PenStyle>(Qt::SolidLine+index));
00089 }
00090 
00091 }


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Tue May 9 2017 02:16:02