widgets.h
Go to the documentation of this file.
00001 // *****************************************************************************
00002 //
00003 // Copyright (c) 2014, Southwest Research Institute® (SwRI®)
00004 // All rights reserved.
00005 //
00006 // Redistribution and use in source and binary forms, with or without
00007 // modification, are permitted provided that the following conditions are met:
00008 //     * Redistributions of source code must retain the above copyright
00009 //       notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above copyright
00011 //       notice, this list of conditions and the following disclaimer in the
00012 //       documentation and/or other materials provided with the distribution.
00013 //     * Neither the name of Southwest Research Institute® (SwRI®) nor the
00014 //       names of its contributors may be used to endorse or promote products
00015 //       derived from this software without specific prior written permission.
00016 //
00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020 // ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
00021 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00024 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 //
00028 // *****************************************************************************
00029 
00030 #ifndef MAPVIZ_WIDGETS_H_
00031 #define MAPVIZ_WIDGETS_H_
00032 
00033 // QT libraries
00034 #include <QWidget>
00035 #include <QListWidget>
00036 #include <QListWidgetItem>
00037 #include <QLabel>
00038 #include <QMouseEvent>
00039 #include <QDropEvent>
00040 #include <QPainter>
00041 #include <QPixmap>
00042 
00043 namespace mapviz
00044 {
00045   class PluginConfigList : public QListWidget
00046   {
00047     Q_OBJECT
00048 
00049   public:
00050     explicit PluginConfigList(QWidget *parent = 0) : QListWidget(parent) {}
00051     PluginConfigList();
00052     
00053     void UpdateIndices()
00054     {
00055       for (int i = 0; i < count(); i++)
00056       {
00057         item(i)->setData(Qt::UserRole, QVariant((float)i));
00058       }
00059     }
00060 
00061   Q_SIGNALS:
00062     void ItemsMoved();
00063 
00064   protected:
00065     virtual void dropEvent(QDropEvent* event)
00066     {
00067       QListWidget::dropEvent(event);
00068 
00069       UpdateIndices();
00070 
00071       Q_EMIT ItemsMoved();
00072     }
00073   };
00074   
00075   class PluginConfigListItem : public QListWidgetItem
00076   {
00077    
00078   public:
00079     explicit PluginConfigListItem(QListWidget *parent = 0) : QListWidgetItem(parent) {}
00080     
00081     virtual bool operator< (const QListWidgetItem & other) const 
00082     {
00083       return data(Qt::UserRole).toFloat() < other.data(Qt::UserRole).toFloat();
00084     }
00085   };
00086 
00087   class SingleClickLabel : public QLabel
00088   {
00089     Q_OBJECT
00090 
00091   public:
00092     explicit SingleClickLabel(QWidget *parent = 0, Qt::WFlags flags = 0) :
00093       QLabel(parent, flags) {}
00094 
00095     ~SingleClickLabel() {}
00096 
00097   Q_SIGNALS:
00098     void Clicked();
00099 
00100   protected:
00101     virtual void mousePressEvent(QMouseEvent* event)
00102     {
00103       Q_EMIT Clicked();
00104     }
00105   };
00106 
00107   class DoubleClickWidget : public QWidget
00108   {
00109     Q_OBJECT
00110 
00111   public:
00112     explicit DoubleClickWidget(QWidget *parent = 0, Qt::WFlags flags = 0) :
00113       QWidget(parent, flags) {}
00114 
00115     ~DoubleClickWidget() {}
00116 
00117   Q_SIGNALS:
00118     void DoubleClicked();
00119     void RightClicked();
00120 
00121   protected:
00122     virtual void mouseDoubleClickEvent(QMouseEvent* event)
00123     {
00124       if (event->button() == Qt::LeftButton)
00125       {
00126         Q_EMIT DoubleClicked();
00127       }
00128     }
00129     
00130     virtual void mouseReleaseEvent(QMouseEvent* event)
00131     {
00132       if (event->button() == Qt::RightButton)
00133       {
00134         Q_EMIT RightClicked();
00135       }
00136     }
00137   };
00138   
00139   class IconWidget : public QWidget
00140   {
00141     Q_OBJECT
00142 
00143   public:
00144     explicit IconWidget(QWidget *parent = 0, Qt::WFlags flags = 0) :
00145       QWidget(parent, flags)
00146     {
00147       pixmap_ = QPixmap(16, 16);
00148       pixmap_.fill(Qt::transparent);
00149     }
00150 
00151     ~IconWidget() {}
00152     
00153     void SetPixmap(QPixmap pixmap)
00154     {
00155       pixmap_ = pixmap;
00156       update();
00157     }
00158 
00159   protected:
00160     virtual void paintEvent(QPaintEvent* e)
00161     {
00162       QPainter painter(this);
00163       painter.fillRect(0, 0, width(), height(), palette().color(QPalette::Button));
00164       
00165       int x_offset = (width() - pixmap_.width()) / 2.0;
00166       int y_offset = (height() - pixmap_.height()) / 2.0;
00167       
00168       painter.drawPixmap(x_offset, y_offset, pixmap_);
00169     }
00170     
00171     QPixmap pixmap_;
00172   };
00173 }
00174 
00175 #endif  // MAPVIZ_WIDGETS_H_


mapviz
Author(s): Marc Alban
autogenerated on Thu Jun 6 2019 18:50:58