buttondelegate.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package ArmarXCore::core
19  * @author Cedric Seehausen (usdnr at kit dot edu)
20  * @date 2016
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 
26 #pragma once
27 
28 #include "scenariomodel.h"
29 
30 #include <QStyledItemDelegate>
31 #include <QList>
32 #include <QFlags>
33 #include <QPixmap>
34 #include <map>
35 
36 /**
37 * @class ButtonDelegate
38 * @brief Manages a button.
39 */
40 class ButtonDelegate : public QStyledItemDelegate
41 {
42  Q_OBJECT
43 public:
44  /**
45  * Constructor which doesn't do anything.
46  */
47  ButtonDelegate(QWidget* parent = 0);
48 
49  virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const;
50  virtual void setEditorData(QWidget* editor, const QModelIndex& index) const;
51  virtual void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
52 
53  /**
54  * Sets button style and draws it.
55  * @param painter Painter that does the drawing
56  * @param option Describes the parameter used to draw the button
57  * @param index Used to locate the button
58  */
59  void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
60 
61  /**
62  * Calculates and returns the size of the button
63  * @param option Used to get the height and width of the item
64  * @param index Used to locate the button (not used currently)
65  */
66  QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;
67 
68 
69  int getScenarioIconSize() const;
70  void setScenarioIconSize(int value);
71 
72  int getAppIconSize() const;
73  void setAppIconSize(int value);
74 
75 signals:
76  void buttonClicked(int row, int column, QModelIndex parent);
77  void comboBoxButtonClicked(int row, int column, QModelIndex parent, QString text);
78 
79 protected:
80  bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index) override;
81 
82 private slots:
83  void onComboBoxRelease(QString text, const QAbstractItemModel* model, const QString& scenarioName);
84 
85 private:
86  std::map<const QModelIndex, QFlags<QStyle::StateFlag>> buttonStates;
87  QPixmap startPixmap;
88  QPixmap stopPixmap;
89  QPixmap restartPixmap;
90 
91  int scenarioIconSize = 24;
92  int appIconSize = 16;
93 };
94 
95 
ButtonDelegate::createEditor
virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
Definition: buttondelegate.cpp:51
scenariomodel.h
ButtonDelegate::buttonClicked
void buttonClicked(int row, int column, QModelIndex parent)
ButtonDelegate::setScenarioIconSize
void setScenarioIconSize(int value)
Definition: buttondelegate.cpp:247
index
uint8_t index
Definition: EtherCATFrame.h:59
ButtonDelegate::sizeHint
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
Calculates and returns the size of the button.
Definition: buttondelegate.cpp:252
ButtonDelegate::setEditorData
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const
Definition: buttondelegate.cpp:111
ButtonDelegate::getAppIconSize
int getAppIconSize() const
Definition: buttondelegate.cpp:232
ButtonDelegate::editorEvent
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override
Definition: buttondelegate.cpp:207
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
ButtonDelegate
Manages a button.
Definition: buttondelegate.h:40
option
#define option(type, fn)
ButtonDelegate::setAppIconSize
void setAppIconSize(int value)
Definition: buttondelegate.cpp:237
ButtonDelegate::paint
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Sets button style and draws it.
Definition: buttondelegate.cpp:143
ButtonDelegate::getScenarioIconSize
int getScenarioIconSize() const
Definition: buttondelegate.cpp:242
ButtonDelegate::ButtonDelegate
ButtonDelegate(QWidget *parent=0)
Constructor which doesn't do anything.
Definition: buttondelegate.cpp:44
ButtonDelegate::setModelData
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
Definition: buttondelegate.cpp:130
ButtonDelegate::comboBoxButtonClicked
void comboBoxButtonClicked(int row, int column, QModelIndex parent, QString text)