PenStyleComboBox.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2015 by Ralf Kaestner *
3  * ralf.kaestner@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the Lesser GNU General Public License as published by*
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * Lesser GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the Lesser GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ******************************************************************************/
18 
19 #include <QPainter>
20 #include <QPaintEvent>
21 #include <QPen>
22 
24 
26 
27 namespace rqt_multiplot {
28 
29 /*****************************************************************************/
30 /* Constructors and Destructor */
31 /*****************************************************************************/
32 
34  QComboBox(parent) {
35  setItemDelegate(new PenStyleItemDelegate(this));
36 
37  for (int style = Qt::SolidLine; style < Qt::CustomDashLine; ++style)
38  addItem("", style);
39 
40  connect(this, SIGNAL(currentIndexChanged(int)), this,
41  SLOT(currentIndexChanged(int)));
42 }
43 
45 }
46 
47 /*****************************************************************************/
48 /* Accessors */
49 /*****************************************************************************/
50 
51 void PenStyleComboBox::setCurrentStyle(Qt::PenStyle style) {
52  setCurrentIndex(style-Qt::SolidLine);
53 }
54 
55 Qt::PenStyle PenStyleComboBox::getCurrentStyle() const {
56  return static_cast<Qt::PenStyle>(Qt::SolidLine+currentIndex());
57 }
58 
59 /*****************************************************************************/
60 /* Methods */
61 /*****************************************************************************/
62 
63 void PenStyleComboBox::paintEvent(QPaintEvent* event) {
64  QComboBox::paintEvent(event);
65 
66  QVariant data = itemData(currentIndex(), Qt::UserRole);
67 
68  if (data.isValid()) {
69  QPainter painter(this);
70  QPen pen;
71 
72  pen.setColor(palette().color(QPalette::Text));
73  pen.setWidth(1);
74  pen.setStyle(static_cast<Qt::PenStyle>(data.toInt()));
75 
76  painter.setPen(pen);
77  painter.drawLine(event->rect().left()+5, event->rect().center().y(),
78  event->rect().right()-20, event->rect().center().y());
79  }
80 }
81 
82 /*****************************************************************************/
83 /* Slots */
84 /*****************************************************************************/
85 
87  if (index >= 0)
88  emit currentStyleChanged(static_cast<Qt::PenStyle>(Qt::SolidLine+index));
89 }
90 
91 }
Qt::PenStyle getCurrentStyle() const
void setCurrentStyle(Qt::PenStyle style)
void currentStyleChanged(int style)
void paintEvent(QPaintEvent *event)


rqt_multiplot_plugin
Author(s): Ralf Kaestner
autogenerated on Fri Jan 15 2021 03:47:53