Skip to content
Snippets Groups Projects
Commit 4e9291ad authored by alexandr.mruchok's avatar alexandr.mruchok
Browse files

[+] CustomPlacementButton_New

[*] Changed CustomWidget
[+] Properties::HOVER, CHECKED
parent 910d8463
No related branches found
No related tags found
2 merge requests!17Develop old,!11Feature 3131
...@@ -4,9 +4,10 @@ ...@@ -4,9 +4,10 @@
#include <QString> #include <QString>
namespace Properties { namespace Properties {
static const QString TEXT = "text"; static const QString TEXT = "text" ;
static const QString STATE = "state"; static const QString STATE = "state" ;
static const QString HOVER = "hover" ;
static const QString CHECKED = "checked";
} }
......
...@@ -27,7 +27,7 @@ CustomComboBoxPopup::CustomComboBoxPopup(const QString &a_caption,ListModel *mod ...@@ -27,7 +27,7 @@ CustomComboBoxPopup::CustomComboBoxPopup(const QString &a_caption,ListModel *mod
for(int i = 0; i < m_model->getData().size();i++) for(int i = 0; i < m_model->getData().size();i++)
{ {
m_lvwList->setIndexWidget(m_model->index(i),new CustomWidget(i,m_model->getData().at(i),m_lvwList)); m_lvwList->setIndexWidget(m_model->index(i),new CustomWidget("", "", m_lvwList));
} }
m_layout = new QVBoxLayout; m_layout = new QVBoxLayout;
......
#include "CustomPlacementButton_New.h"
#include "AppStyleSheetHandler.h"
#include "defines.h"
/** @brief constructor
* @param a_parent object parent
*/
CustomPlacementButton_New::CustomPlacementButton_New(QWidget *a_parent)
:QPushButton (a_parent),
m_layout (new QHBoxLayout(this)),
m_lbLeftSpacing (this),
m_lbImage (this),
m_lbText (this),
m_lbRightSpacing(this)
{
m_lbLeftSpacing .setObjectName("leftSpacing");
m_lbImage .setObjectName("image");
m_lbText .setObjectName("text");
m_lbRightSpacing.setObjectName("rightSpacing");
m_subcontrols.append(&m_lbImage);
m_subcontrols.append(&m_lbText);
// Set up subcontroll object names:
//Setup layout
m_layout->setMargin(0);
m_layout->setSpacing(0);
//Setup spacing setSizePolicy
m_lbLeftSpacing .setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
m_lbRightSpacing.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
//Adding subcontrols to layout
m_layout->addWidget(&m_lbLeftSpacing);
for (QLabel *subcontrol: m_subcontrols){
// Set up subcontroll ScaledContents:
subcontrol->setScaledContents(true);
m_layout->addWidget(subcontrol);
}
m_layout->addWidget(&m_lbRightSpacing);
setLayout(m_layout);
// on toggled update Appearance
connect(this, &QAbstractButton::toggled, [=](bool a_checked) {
this->setState(this->underMouse(), a_checked);
});
}
/** @brief Reimplemented QPushButton::setText method. Sets text property of text subcontrol.
* @param text Text
*/
void CustomPlacementButton_New::setText(const QString &text)
{
m_lbText.setText(text);
}
///** @brief Reimplemented QPushButton::setObjectName method. Updates stylesheets.
// * @param text Text
// */
//void CustomPlacementButton_New::setObjectName(const QString &name)
//{
// QObject::setObjectName(name);
// updateStyleSheets();
//}
//void CustomPlacementButton_New::setCheckable(bool checkable)
//{
// QPushButton::setCheckable(checkable);
// updateStyleSheets();
//}
///** @brief Initialization of image and text stylesheets
// */
//void CustomPlacementButton_New::updateStyleSheets()
//{
// for (StyledSubcontrol_New *subcontrol: m_subcontrols){
// subcontrol->updateStylesheets();
// }
// updateAppearance();
//}
/** @brief Updates appearance of image and text
*/
void CustomPlacementButton_New::setState(bool isHover, bool isChecked)
{
const char* hoverProperty = qPrintable(Properties::HOVER);
const char* checkedProperty = qPrintable(Properties::CHECKED);
if (isHover != this->property(hoverProperty) && isChecked != this->property(checkedProperty))
{
for (QLabel *subcontrol: m_subcontrols)
{
subcontrol->setProperty(hoverProperty , isHover );
subcontrol->setProperty(checkedProperty, isChecked);
subcontrol->style()->unpolish(subcontrol);
subcontrol->style()->polish(subcontrol);
}
}
}
/** @brief add new subcontrol and place it in layout
* @param a_id text id of subcontrol wich is using in CSS file
*/
void CustomPlacementButton_New::addSubcontrol(QString a_id)
{
// StyledSubcontrol_New *newSubcontrol = new StyledSubcontrol_New(a_id, this);
QLabel *newSubcontrol = new QLabel((QPushButton*)this);
newSubcontrol->setObjectName(a_id);
// newSubcontrol->widget()->setScaledContents(true);
//add to list and layout
m_subcontrols.append(newSubcontrol);
m_layout->insertWidget(m_layout->count() - 1, newSubcontrol);
}
/** @brief Set image position relative to text (left or right)
* @param a_position image position relatife to text (Left/Right)
*/
void CustomPlacementButton_New::setImagePosition(ImagePos a_position /*= ImagePos::Left*/)
{
int imageIndex = m_layout->indexOf(&m_lbImage);
if (a_position == ImagePos::Left && imageIndex == 2)
{
m_layout->removeWidget(&m_lbImage);
m_layout->insertWidget(1, &m_lbImage);
}
else if (a_position == ImagePos::Right && imageIndex == 1)
{
m_layout->removeWidget(&m_lbImage);
m_layout->insertWidget(2, &m_lbImage);
}
}
/** @brief event is sent to the widget when the mouse cursor enters the widget.
* @param event
*/
void CustomPlacementButton_New::enterEvent(QEvent *event)
{
Q_UNUSED(event);
if (isEnabled())
setState(true, isChecked());
}
/** @brief A leave event is sent to the widget when the mouse cursor leaves the widget.
* @param event
*/
void CustomPlacementButton_New::leaveEvent(QEvent *event)
{
Q_UNUSED(event);
if (isEnabled())
setState(false, isChecked());
}
///** @brief Reimplemented QWidget::changeEvent is sent to the widget when "enabled" changed.
// * @param event
// */
//void CustomPlacementButton_New::changeEvent(QEvent *event)
//{
// if (event->type() == QEvent::EnabledChange) {
// updateAppearance();
// return QWidget::changeEvent(event);
// }
// return QWidget::changeEvent(event);
//}
#ifndef CUSTOMPLACEMENTBUTTON_NEW_H
#define CUSTOMPLACEMENTBUTTON_NEW_H
#include <QPushButton>
#include <QHBoxLayout>
#include <QStyle>
#include <QDebug>
#include <QEvent>
#include <QLabel>
enum class ImagePos {Left, Right};
/** @brief QPushButton with subControls "text" and "image"
*
* @details Places image and text from left to right in QHBoxLayout.
* Set style in .css file in format
*> #buttonName #leftSpacing {
*> ...; //if max-width==0, left alinment
*> }
*> #buttonName::text {
*> ...
*> }
*> #buttonName::text:hover {
*> ...
*> }
*> #buttonName::text:checked {
*> ...
*> }
*> #buttonName::text:checked:hover {
*> ...
*> }
*> #buttonName::image {
*> ...
*> }
*> #buttonName::image:hover {
*> ...
*> }
*> #buttonName::image:checked {
*> ...
*> }
*> #buttonName::image:checked:hover {
*> ...
*> }
*> #buttonName #rightSpacing {
*> ...//if max-width==0, right alignment
*> }
* @todo Is searching style in comments also!
*/
class CustomPlacementButton_New : public QPushButton
{
Q_OBJECT
public:
explicit CustomPlacementButton_New(QWidget *a_parent = Q_NULLPTR);
void setText(const QString &text);
// void setObjectName(const QString &name);
// void setCheckable(bool checkable);
void setState(bool isHover, bool isChecked);
void addSubcontrol(QString a_id);
void setImagePosition(ImagePos a_position = ImagePos::Left);
private:
protected:
void enterEvent(QEvent *event);
void leaveEvent(QEvent *event);
// void changeEvent(QEvent * event);
QHBoxLayout *m_layout;
QLabel m_lbLeftSpacing; ///<label for left spacing
QList<QLabel*> m_subcontrols;
QLabel m_lbImage; ///<label with image
QLabel m_lbText; ///<label with text
QLabel m_lbRightSpacing; ///<label for right spacing
};
#endif // CUSTOMPLACEMENTBUTTON_NEW_H
...@@ -10,12 +10,12 @@ CustomWidget::CustomWidget(QWidget *parent) ...@@ -10,12 +10,12 @@ CustomWidget::CustomWidget(QWidget *parent)
} }
CustomWidget::CustomWidget(int index,DataModel model,QListView *listView, QWidget *parent) CustomWidget::CustomWidget(QString iconPath/* = ""*/, QString text/* = ""*/, QWidget *parent/* = nullptr*/)
: QWidget (parent) : QWidget (parent)
{ {
m_index = index; // m_index = index;
m_data = &model; // m_data = &model;
m_listView = listView; // m_listView = listView;
setObjectName("wgtDelegate"); setObjectName("wgtDelegate");
setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Fixed); setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Fixed);
...@@ -98,3 +98,13 @@ void CustomWidget::setStyle(int state) ...@@ -98,3 +98,13 @@ void CustomWidget::setStyle(int state)
setGraphicsEffect(m_styledshadow); setGraphicsEffect(m_styledshadow);
} }
} }
bool CustomWidget::selected() const
{
return m_selected;
}
void CustomWidget::setSelected(bool selected)
{
m_selected = selected;
}
...@@ -7,11 +7,15 @@ ...@@ -7,11 +7,15 @@
#include "StyledDropShadowEffect.h" #include "StyledDropShadowEffect.h"
#include "ListModel.h" #include "ListModel.h"
#include <QListView> #include <QListView>
class CustomWidget:public QWidget class CustomWidget: public QWidget
{ {
public: public:
CustomWidget(QWidget *parent = nullptr); CustomWidget(QWidget *parent = nullptr);
CustomWidget(int index, DataModel model,QListView *listView = nullptr, QWidget *parent = nullptr); CustomWidget(QString iconPath = "", QString text = "", QWidget *parent = nullptr);
bool selected() const;
void setSelected(bool selected);
protected: protected:
void enterEvent(QEvent *event); void enterEvent(QEvent *event);
void leaveEvent(QEvent *event); void leaveEvent(QEvent *event);
...@@ -21,6 +25,13 @@ private: ...@@ -21,6 +25,13 @@ private:
//Updates styles on mouseover and on setting activity of an element. //Updates styles on mouseover and on setting activity of an element.
void setStyle(int state); void setStyle(int state);
bool m_selected;
/////////////////////////////////////////
QLabel *m_lblFlag; QLabel *m_lblFlag;
QLabel *m_lblText; QLabel *m_lblText;
QLabel *m_lblCheckIcon; QLabel *m_lblCheckIcon;
......
...@@ -6,6 +6,7 @@ SOURCES += \ ...@@ -6,6 +6,7 @@ SOURCES += \
$$PWD/CustomComboBoxPopup.cpp \ $$PWD/CustomComboBoxPopup.cpp \
$$PWD/CustomLineHeightLabel.cpp \ $$PWD/CustomLineHeightLabel.cpp \
$$PWD/CustomPlacementButton.cpp \ $$PWD/CustomPlacementButton.cpp \
$$PWD/CustomPlacementButton_New.cpp \
$$PWD/CustomWidget.cpp \ $$PWD/CustomWidget.cpp \
$$PWD/ListModel.cpp \ $$PWD/ListModel.cpp \
$$PWD/ServersComboBox.cpp \ $$PWD/ServersComboBox.cpp \
...@@ -22,6 +23,7 @@ HEADERS += \ ...@@ -22,6 +23,7 @@ HEADERS += \
$$PWD/CustomComboBoxPopup.h \ $$PWD/CustomComboBoxPopup.h \
$$PWD/CustomLineHeightLabel.h \ $$PWD/CustomLineHeightLabel.h \
$$PWD/CustomPlacementButton.h \ $$PWD/CustomPlacementButton.h \
$$PWD/CustomPlacementButton_New.h \
$$PWD/CustomWidget.h \ $$PWD/CustomWidget.h \
$$PWD/ListModel.h \ $$PWD/ListModel.h \
$$PWD/ServersComboBox.h \ $$PWD/ServersComboBox.h \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment