142 lines
3.3 KiB
C++
Executable File
142 lines
3.3 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* Bitfield Widget for bitwise displaying and editing of quint8 values
|
|
* Created by Christian Kaemmerer
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <QWidget>
|
|
#include <QMouseEvent>
|
|
|
|
#include "lts_widgets_export.h"
|
|
|
|
|
|
namespace LtsWidgets
|
|
{
|
|
|
|
class LTSWIDGETS_EXPORT LtsBitfieldWidget : public QWidget
|
|
{
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(quint8 value READ value WRITE setValue NOTIFY valueChanged)
|
|
Q_PROPERTY(bool isEditable READ isEditable WRITE setEditable NOTIFY isEditableChanged)
|
|
Q_PROPERTY(bool hasCaption READ hasCaption WRITE setHasCaption NOTIFY hasCaptionChanged)
|
|
Q_PROPERTY(QColor onColor READ onColor WRITE setOnColor)
|
|
Q_PROPERTY(QColor offColor READ offColor WRITE setOffColor)
|
|
|
|
public:
|
|
explicit LtsBitfieldWidget(QWidget *parent = nullptr, quint8 value = 0);
|
|
|
|
signals:
|
|
void valueChanged(quint8 newValue);
|
|
void isEditableChanged(bool option);
|
|
void hasCaptionChanged(bool option);
|
|
|
|
public slots:
|
|
/**
|
|
* @brief setvalue
|
|
* sets m_value to the given quint8
|
|
* @param quint8 value
|
|
*/
|
|
void setValue(quint8 value);
|
|
|
|
/**
|
|
* @brief setIsEditable
|
|
* sets m_isEditable to option.
|
|
* true meaning the value of the widget can be changed via mousePressEvent
|
|
* @param bool option
|
|
*/
|
|
void setEditable(bool editable);
|
|
|
|
/**
|
|
* @brief setHasCaption
|
|
* sets m_hasCaption to 0 or 1 which toggels if text should be
|
|
* drawn on each bitGraphic
|
|
* @param bool hasCaption
|
|
*/
|
|
void setHasCaption(bool hasCaption);
|
|
|
|
/**
|
|
* @brief setOnColor
|
|
* sets the onColor for m_bitGraphic
|
|
* @param QColor onColor
|
|
*/
|
|
void setOnColor(const QColor &onColor);
|
|
|
|
/**
|
|
* @brief setOffColor
|
|
* sets the offColor for m_bitGraphic
|
|
* @param QColor offColor
|
|
*/
|
|
void setOffColor(const QColor &offColor);
|
|
|
|
|
|
public:
|
|
/**
|
|
* @brief value
|
|
* get the current value
|
|
* @return quint8 of current value
|
|
*/
|
|
quint8 value() const { return m_value; }
|
|
|
|
/**
|
|
* @brief isEditable
|
|
* get the current state of editability
|
|
* @return bool of editability state
|
|
*/
|
|
bool isEditable() const { return m_isEditable; }
|
|
|
|
/**
|
|
* @brief hasCaption
|
|
* gets state of m_hasCaption
|
|
* @return bool hasCaption
|
|
*/
|
|
bool hasCaption() const { return m_hasCaption; }
|
|
|
|
/**
|
|
* @brief onColor
|
|
* gets the onColor for m_bitGraphic
|
|
* @return QColor m_onColor
|
|
*/
|
|
QColor onColor() const {return m_onColor;}
|
|
|
|
/**
|
|
* @brief offColor
|
|
* gets the offColor for m_bitGraphic
|
|
* @return QColor m_offColor
|
|
*/
|
|
QColor offColor() const {return m_offColor;}
|
|
|
|
private:
|
|
/**
|
|
* @brief mousePressEvent
|
|
* Checks if the click position falls within any of the bit rectangles. If there
|
|
* is a match the value of that bit gets flipped
|
|
* @param event QMouseEvent
|
|
*/
|
|
void mousePressEvent(QMouseEvent *event) override;
|
|
|
|
/**
|
|
* @brief paintEvent
|
|
* Draws m_bitGraphic.Size() rectangles and depending on the bit value of m_value draw either
|
|
* a onColor rectangle with a offColor 1 or a offColor rectangle with a onColor 0
|
|
* @param pe QPaintEvent (isn't used to do anything)
|
|
*/
|
|
void paintEvent(QPaintEvent *pe) override;
|
|
|
|
private:
|
|
quint8 m_value = 0;
|
|
|
|
bool m_isEditable = true;
|
|
bool m_hasCaption = true;
|
|
|
|
QColor m_onColor = Qt::black;
|
|
QColor m_offColor = Qt::white;
|
|
};
|
|
|
|
} // namespace LtsWidgets
|