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 void setEditorData(QWidget* editor, const QModelIndex& index) const;
50  virtual void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
51 
52  /**
53  * Sets button style and draws it.
54  * @param painter Painter that does the drawing
55  * @param option Describes the parameter used to draw the button
56  * @param index Used to locate the button
57  */
58  void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
59 
60  /**
61  * Calculates and returns the size of the button
62  * @param option Used to get the height and width of the item
63  * @param index Used to locate the button (not used currently)
64  */
65  QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;
66 
67 
68  int getScenarioIconSize() const;
69  void setScenarioIconSize(int value);
70 
71  int getAppIconSize() const;
72  void setAppIconSize(int value);
73 
74 signals:
75  void buttonClicked(int row, int column, QModelIndex parent);
76 
77 protected:
78  bool editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index) override;
79 
80 
81 private:
82  std::map<const QModelIndex, QFlags<QStyle::StateFlag>> buttonStates;
83  QPixmap startPixmap;
84  QPixmap stopPixmap;
85  QPixmap restartPixmap;
86 
87  int scenarioIconSize = 24;
88  int appIconSize = 16;
89 };
90 
91 
scenariomodel.h
ButtonDelegate::buttonClicked
void buttonClicked(int row, int column, QModelIndex parent)
ButtonDelegate::setScenarioIconSize
void setScenarioIconSize(int value)
Definition: buttondelegate.cpp:153
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:158
ButtonDelegate::setEditorData
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const
Definition: buttondelegate.cpp:50
ButtonDelegate::getAppIconSize
int getAppIconSize() const
Definition: buttondelegate.cpp:138
ButtonDelegate::editorEvent
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override
Definition: buttondelegate.cpp:113
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:143
ButtonDelegate::paint
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Sets button style and draws it.
Definition: buttondelegate.cpp:60
ButtonDelegate::getScenarioIconSize
int getScenarioIconSize() const
Definition: buttondelegate.cpp:148
ButtonDelegate::ButtonDelegate
ButtonDelegate(QWidget *parent=0)
Constructor which doesn't do anything.
Definition: buttondelegate.cpp:43
ButtonDelegate::setModelData
virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
Definition: buttondelegate.cpp:55