widgets.h
Go to the documentation of this file.
1 // *****************************************************************************
2 //
3 // Copyright (c) 2014, Southwest Research Institute® (SwRI®)
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Southwest Research Institute® (SwRI®) nor the
14 // names of its contributors may be used to endorse or promote products
15 // derived from this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //
28 // *****************************************************************************
29 
30 #ifndef MAPVIZ_WIDGETS_H_
31 #define MAPVIZ_WIDGETS_H_
32 
33 // QT libraries
34 #include <QWidget>
35 #include <QListWidget>
36 #include <QListWidgetItem>
37 #include <QLabel>
38 #include <QMouseEvent>
39 #include <QDropEvent>
40 #include <QPainter>
41 #include <QPixmap>
42 
43 namespace mapviz
44 {
45  class PluginConfigList : public QListWidget
46  {
47  Q_OBJECT
48 
49  public:
50  explicit PluginConfigList(QWidget *parent = 0) : QListWidget(parent) {}
52 
54  {
55  for (size_t i = 0; i < count(); i++)
56  {
57  item(i)->setData(Qt::UserRole, QVariant((float)i));
58  }
59  }
60 
61  Q_SIGNALS:
62  void ItemsMoved();
63 
64  protected:
65  virtual void dropEvent(QDropEvent* event)
66  {
67  QListWidget::dropEvent(event);
68 
69  UpdateIndices();
70 
71  Q_EMIT ItemsMoved();
72  }
73  };
74 
75  class PluginConfigListItem : public QListWidgetItem
76  {
77 
78  public:
79  explicit PluginConfigListItem(QListWidget *parent = 0) : QListWidgetItem(parent) {}
80 
81  virtual bool operator< (const QListWidgetItem & other) const
82  {
83  return data(Qt::UserRole).toFloat() < other.data(Qt::UserRole).toFloat();
84  }
85  };
86 
87  class SingleClickLabel : public QLabel
88  {
89  Q_OBJECT
90 
91  public:
92  explicit SingleClickLabel(QWidget *parent = 0, Qt::WindowFlags flags = 0) :
93  QLabel(parent, flags) {}
94 
96 
97  Q_SIGNALS:
98  void Clicked();
99 
100  protected:
101  virtual void mousePressEvent(QMouseEvent* event)
102  {
103  Q_EMIT Clicked();
104  }
105  };
106 
107  class DoubleClickWidget : public QWidget
108  {
109  Q_OBJECT
110 
111  public:
112  explicit DoubleClickWidget(QWidget *parent = 0, Qt::WindowFlags flags = 0) :
113  QWidget(parent, flags) {}
114 
116 
117  Q_SIGNALS:
118  void DoubleClicked();
119  void RightClicked();
120 
121  protected:
122  virtual void mouseDoubleClickEvent(QMouseEvent* event)
123  {
124  if (event->button() == Qt::LeftButton)
125  {
126  Q_EMIT DoubleClicked();
127  }
128  }
129 
130  virtual void mouseReleaseEvent(QMouseEvent* event)
131  {
132  if (event->button() == Qt::RightButton)
133  {
134  Q_EMIT RightClicked();
135  }
136  }
137  };
138 
139  class IconWidget : public QWidget
140  {
141  Q_OBJECT
142 
143  public:
144  explicit IconWidget(QWidget *parent = 0, Qt::WindowFlags flags = 0) :
145  QWidget(parent, flags)
146  {
147  pixmap_ = QPixmap(16, 16);
148  pixmap_.fill(Qt::transparent);
149  }
150 
152 
153  void SetPixmap(QPixmap pixmap)
154  {
155  pixmap_ = pixmap;
156  update();
157  }
158 
159  protected:
160  virtual void paintEvent(QPaintEvent* e)
161  {
162  QPainter painter(this);
163  painter.fillRect(0, 0, width(), height(), palette().color(QPalette::Button));
164 
165  int x_offset = (width() - pixmap_.width()) / 2.0;
166  int y_offset = (height() - pixmap_.height()) / 2.0;
167 
168  painter.drawPixmap(x_offset, y_offset, pixmap_);
169  }
170 
171  QPixmap pixmap_;
172  };
173 }
174 
175 #endif // MAPVIZ_WIDGETS_H_
DoubleClickWidget(QWidget *parent=0, Qt::WindowFlags flags=0)
Definition: widgets.h:112
virtual void paintEvent(QPaintEvent *e)
Definition: widgets.h:160
PluginConfigListItem(QListWidget *parent=0)
Definition: widgets.h:79
data
QPixmap pixmap_
Definition: widgets.h:171
void SetPixmap(QPixmap pixmap)
Definition: widgets.h:153
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
PluginConfigList(QWidget *parent=0)
Definition: widgets.h:50
virtual void mouseReleaseEvent(QMouseEvent *event)
Definition: widgets.h:130
virtual void mouseDoubleClickEvent(QMouseEvent *event)
Definition: widgets.h:122
virtual void dropEvent(QDropEvent *event)
Definition: widgets.h:65
IconWidget(QWidget *parent=0, Qt::WindowFlags flags=0)
Definition: widgets.h:144
SingleClickLabel(QWidget *parent=0, Qt::WindowFlags flags=0)
Definition: widgets.h:92
virtual void mousePressEvent(QMouseEvent *event)
Definition: widgets.h:101


mapviz
Author(s): Marc Alban
autogenerated on Fri Dec 16 2022 03:59:30