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 <map>
29 
30 #include <QFlags>
31 #include <QList>
32 #include <QPixmap>
33 #include <QStyledItemDelegate>
34 
35 #include "scenariomodel.h"
36 
37 /**
38 * @class ButtonDelegate
39 * @brief Manages a button.
40 */
41 class ButtonDelegate : public QStyledItemDelegate
42 {
43  Q_OBJECT
44 public:
45  /**
46  * Constructor which doesn't do anything.
47  */
48  ButtonDelegate(QWidget* parent = 0);
49 
50  virtual void setEditorData(QWidget* editor, const QModelIndex& index) const;
51  virtual void
52  setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
53 
54  /**
55  * Sets button style and draws it.
56  * @param painter Painter that does the drawing
57  * @param option Describes the parameter used to draw the button
58  * @param index Used to locate the button
59  */
60  void paint(QPainter* painter,
61  const QStyleOptionViewItem& option,
62  const QModelIndex& index) const override;
63 
64  /**
65  * Calculates and returns the size of the button
66  * @param option Used to get the height and width of the item
67  * @param index Used to locate the button (not used currently)
68  */
69  QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;
70 
71 
72  int getScenarioIconSize() const;
73  void setScenarioIconSize(int value);
74 
75  int getAppIconSize() const;
76  void setAppIconSize(int value);
77 
78 signals:
79  void buttonClicked(int row, int column, QModelIndex parent);
80 
81 protected:
82  bool editorEvent(QEvent* event,
83  QAbstractItemModel* model,
84  const QStyleOptionViewItem& option,
85  const QModelIndex& index) override;
86 
87 
88 private:
89  std::map<const QModelIndex, QFlags<QStyle::StateFlag>> buttonStates;
90  QPixmap startPixmap;
91  QPixmap stopPixmap;
92  QPixmap restartPixmap;
93 
94  int scenarioIconSize = 24;
95  int appIconSize = 16;
96 };
scenariomodel.h
ButtonDelegate::buttonClicked
void buttonClicked(int row, int column, QModelIndex parent)
ButtonDelegate::setScenarioIconSize
void setScenarioIconSize(int value)
Definition: buttondelegate.cpp:171
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:177
ButtonDelegate::setEditorData
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const
Definition: buttondelegate.cpp:52
ButtonDelegate::getAppIconSize
int getAppIconSize() const
Definition: buttondelegate.cpp:153
ButtonDelegate::editorEvent
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override
Definition: buttondelegate.cpp:123
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
ButtonDelegate
Manages a button.
Definition: buttondelegate.h:41
option
#define option(type, fn)
ButtonDelegate::setAppIconSize
void setAppIconSize(int value)
Definition: buttondelegate.cpp:159
ButtonDelegate::paint
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Sets button style and draws it.
Definition: buttondelegate.cpp:66
ButtonDelegate::getScenarioIconSize
int getScenarioIconSize() const
Definition: buttondelegate.cpp:165
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:58