Skip to content
Snippets Groups Projects
Commit 1ffeb943 authored by konstantin.kukharenko's avatar konstantin.kukharenko Committed by Alexandr Mruchok
Browse files

[+]Add signal

parent 64b98528
No related branches found
No related tags found
2 merge requests!17Develop old,!11Feature 3131
#include "CustomComboBox.h"
#include <QDebug>
/** @brief constructor
* @param a_parent object parent
*/
......@@ -19,6 +19,10 @@ void CustomComboBox::setObjectName(const QString &name)
setGraphicsEffect(m_styledshadow);
}
void CustomComboBox::showPopup()
{
emit showCustomWindow();
}
/** @brief Reimplemented QComboBox::enterEvent is sent to the widget when the mouse cursor enters the widget.
* @param event
*/
......
......@@ -22,6 +22,9 @@ class CustomComboBox : public QComboBox
public:
CustomComboBox(QWidget *parent = Q_NULLPTR);
void setObjectName(const QString &name);
void showPopup();
signals:
void showCustomWindow();
protected:
void enterEvent(QEvent *event);
void leaveEvent(QEvent *event);
......
#include "CustomComboBoxPopup.h"
CustomComboBoxPopup::CustomComboBoxPopup(const QString &a_caption,ListModel *model, QWidget *parent)
: QWidget (parent)
{
setFixedSize(parent->width(),parent->height());
setObjectName("wgtComboBoxPopup");
if(model != nullptr)
{
m_model = model;
}
else
{
m_model = new ListModel(this);
}
m_lblCaption = new QLabel(this);
m_lblCaption->setObjectName("lblCaption");
m_lblCaption->setText(a_caption);
m_lblCaption->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Fixed);
m_lvwList = new QListView(this);
m_lvwList->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
m_lvwList->setObjectName("lvwList");
m_lvwList->setModel(m_model);
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_layout = new QVBoxLayout;
m_layout->setSpacing(0);
m_layout->setMargin(0);
m_layout->addWidget(m_lblCaption);
m_layout->addWidget(m_lvwList);
m_layout->setAlignment(m_lblCaption,Qt::AlignHCenter);
m_layout->setAlignment(m_lvwList,Qt::AlignHCenter);
this->setLayout(m_layout);
connect(m_lvwList,&QListView::clicked,[=]{
setVisible(false);
});
}
#ifndef CUSTOMCOMBOBOXPOPUP_H
#define CUSTOCOMBOBOXPOPUP_H
#include <QMdiArea>
#include <QLabel>
#include <QListView>
#include <QVBoxLayout>
#include "ListModel.h"
#include "CustomWidget.h"
class CustomComboBoxPopup: public QWidget
{
public:
CustomComboBoxPopup(const QString &a_Caption,ListModel *model = nullptr, QWidget *parent = nullptr);
private:
QVBoxLayout *m_layout;
QLabel *m_lblCaption;
QListView *m_lvwList;
ListModel *m_model;
};
#endif // CUSTOMCOMBOBOXPOPUP_H
#include "CustomWidget.h"
#include <QDebug>
#include <QPixmap>
#include <QStyle>
#include <QModelIndex>
CustomWidget::CustomWidget(QWidget *parent)
: QWidget (parent)
{
}
CustomWidget::CustomWidget(int index,DataModel model,QListView *listView, QWidget *parent)
: QWidget (parent)
{
m_index = index;
m_data = &model;
m_listView = listView;
setObjectName("wgtDelegate");
setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Fixed);
m_lblFlag = new QLabel(this);
m_lblFlag->setObjectName("lblFlag");
m_lblFlag->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Fixed);
QPixmap pixmap(m_data->iconPath);
m_lblFlag->setPixmap(pixmap);
m_lblText = new QLabel(this);
m_lblText->setObjectName("lblText");
m_lblText->setText(m_data->text);
m_lblText->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Fixed);
m_lblCheckIcon = new QLabel(this);
m_lblCheckIcon->setObjectName("lblCheckIcon");
m_lblCheckIcon->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Fixed);
m_mainLayout = new QHBoxLayout();
m_mainLayout->setSpacing(0);
m_mainLayout->setMargin(0);
m_mainLayout->addWidget(m_lblFlag);
m_mainLayout->addWidget(m_lblText);
m_mainLayout->addWidget(m_lblCheckIcon);
this->setLayout(m_mainLayout);
m_styledshadow = new StyledDropShadowEffect(this);
show();
}
void CustomWidget::enterEvent(QEvent *event)
{
Q_UNUSED(event)
setStyle(1);
}
void CustomWidget::leaveEvent(QEvent *event)
{
Q_UNUSED(event)
if(m_listView->currentIndex().row()!=m_index)
setStyle(0);
}
void CustomWidget::hideEvent(QHideEvent *event)
{
Q_UNUSED(event)
if(m_listView->currentIndex().row()==m_index)
{
setStyle(1);
}
else
setStyle(0);
}
void CustomWidget::setStyle(int state)
{
setProperty("state",state);
style()->unpolish(this);
style()->polish(this);
m_lblCheckIcon->setProperty("state",state);
style()->unpolish(m_lblCheckIcon);
style()->polish(m_lblCheckIcon);
m_lblText->setProperty("state",state);
style()->unpolish(m_lblText);
style()->polish(m_lblText);
update();
if(!state)
{
m_styledshadow->updateStyle(DEFAULT_SHADOW);
setGraphicsEffect(m_styledshadow);
}
else
{
m_styledshadow->updateStyle(HOVER_SHADOW);
setGraphicsEffect(m_styledshadow);
}
}
#ifndef CUSTOMWIDGET_H
#define CUSTOMWIDGET_H
#include <QWidget>
#include <QLabel>
#include <QHBoxLayout>
#include "StyledDropShadowEffect.h"
#include "ListModel.h"
#include <QListView>
class CustomWidget:public QWidget
{
public:
CustomWidget(QWidget *parent = nullptr);
CustomWidget(int index, DataModel model,QListView *listView = nullptr, QWidget *parent = nullptr);
protected:
void enterEvent(QEvent *event);
void leaveEvent(QEvent *event);
void hideEvent(QHideEvent *event);
private:
//Updates styles on mouseover and on setting activity of an element.
void setStyle(int state);
QLabel *m_lblFlag;
QLabel *m_lblText;
QLabel *m_lblCheckIcon;
QHBoxLayout *m_mainLayout;
StyledDropShadowEffect *m_styledshadow;
DataModel *m_data;
int m_index;
QListView *m_listView;
};
#endif // CUSTOMWIDGET_H
#include "ListModel.h"
ListModel::ListModel(QObject *parent):QAbstractListModel(parent)
{
DataModel tmpModel;
for(int i = 0;i<6;i++)
{
tmpModel.text = "kelvin-testnet.Cellframe";
tmpModel.iconPath ="img1";
m_data.append(tmpModel);
}
}
ListModel::ListModel(QList<DataModel> *list_model,QObject *parent)
{
Q_UNUSED(parent)
for(int i = 0;i<list_model->size();i++)
m_data.append(list_model->at(i));
}
int ListModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid()) {
return 0;
}
return m_data.size();
}
QVariant ListModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) {
return QVariant();
}
return QVariant();
}
QHash<int, QByteArray> ListModel::roleNames() const
{
QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();
return roles;
}
QList<DataModel> ListModel::getData()
{
return m_data;
}
#ifndef LISTMODEL_H
#define LISTMODEL_H
#include <QAbstractListModel>
#include <QDebug>
#include <QString>
#include <QStringList>
//class ListModel
//{
//public:
// ListModel();
//};
struct DataModel
{
QString iconPath;
QString text;
};
class ListModel : public QAbstractListModel
{
Q_OBJECT
public:
ListModel(QObject *parent = nullptr);
ListModel(QList<DataModel> *list_model,QObject *parent = nullptr);
virtual int rowCount(const QModelIndex &parent) const;
virtual QVariant data(const QModelIndex &index, int role) const;
virtual QHash<int, QByteArray> roleNames() const;
QList<DataModel> getData();
private:
QList<DataModel> m_data;
};
#endif // LISTMODEL_H
......@@ -2,8 +2,11 @@ SOURCES += \
$$PWD/AnimationChangingWidget.cpp \
$$PWD/ComboBoxDelegate.cpp \
$$PWD/CustomComboBox.cpp \
$$PWD/CustomComboBoxPopup.cpp \
$$PWD/CustomLineHeightLabel.cpp \
$$PWD/CustomPlacementButton.cpp \
$$PWD/CustomWidget.cpp \
$$PWD/ListModel.cpp \
$$PWD/ServersComboBox.cpp \
$$PWD/AnimatedLineEdit.cpp \
$$PWD/ScreenOverlaying.cpp \
......@@ -14,8 +17,11 @@ HEADERS += \
$$PWD/AnimationChangingWidget.h \
$$PWD/ComboBoxDelegate.h \
$$PWD/CustomComboBox.h \
$$PWD/CustomComboBoxPopup.h \
$$PWD/CustomLineHeightLabel.h \
$$PWD/CustomPlacementButton.h \
$$PWD/CustomWidget.h \
$$PWD/ListModel.h \
$$PWD/ServersComboBox.h \
$$PWD/AnimatedLineEdit.h \
$$PWD/ScreenOverlaying.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