From e9bd4608ed90b28b5676b741a83223b92aebf941 Mon Sep 17 00:00:00 2001 From: "konstantin.kukharenko" <konstantin.kukharenko@demlabs.net> Date: Thu, 6 Feb 2020 20:56:10 +0300 Subject: [PATCH] [+]New class --- controls/CustomLineHeightLabel.cpp | 37 ++++++++++++++++++++++++++++++ controls/CustomLineHeightLabel.h | 20 ++++++++++++++++ controls/controls.pri | 2 ++ 3 files changed, 59 insertions(+) create mode 100644 controls/CustomLineHeightLabel.cpp create mode 100644 controls/CustomLineHeightLabel.h diff --git a/controls/CustomLineHeightLabel.cpp b/controls/CustomLineHeightLabel.cpp new file mode 100644 index 0000000..f45fe23 --- /dev/null +++ b/controls/CustomLineHeightLabel.cpp @@ -0,0 +1,37 @@ +#include "CustomLineHeightLabel.h" +#include "AppStyleSheetHandler.h" + +CustomLineHeightLabel::CustomLineHeightLabel(QWidget *a_parent) + :QLabel (a_parent) +{ +} + +void CustomLineHeightLabel::setText(const QString &text) +{ + if(m_HightLine.isEmpty())m_HightLine = "100"; + QString textToHtml = QString("<p style = 'line-height:%1;'>").arg(m_HightLine); + textToHtml += text; + textToHtml += "</p>"; + + QLabel::setText(textToHtml); + +} + +void CustomLineHeightLabel::setObjectName(const QString &name) +{ + QObject::setObjectName(name); + + updateStyleSheets(); +} + +void CustomLineHeightLabel::updateStyleSheets() +{ + + StyleSheatSearchPar searchPar; + searchPar.widgetName = "#"+ parent()->objectName() + " #" + this->objectName(); + + QString stylesheet = AppStyleSheetHandler::getWidgetStyleSheet(searchPar); + //line-height: + m_HightLine = AppStyleSheetHandler::getValueFromStylesheet(stylesheet, "line-height"); + +} diff --git a/controls/CustomLineHeightLabel.h b/controls/CustomLineHeightLabel.h new file mode 100644 index 0000000..91f640f --- /dev/null +++ b/controls/CustomLineHeightLabel.h @@ -0,0 +1,20 @@ +#ifndef CUSTOMLINEHEIGHTLABEL_H +#define CUSTOMLINEHEIGHTLABEL_H + +#include <QLabel> + +class CustomLineHeightLabel: public QLabel +{ +public: + explicit CustomLineHeightLabel(QWidget *a_parent = Q_NULLPTR); + + void setText(const QString &text); + void setObjectName(const QString &name); + + void updateStyleSheets(); + +private: + QString m_HightLine; +}; + +#endif // CUSTOMLINEHEIGHTLABEL_H diff --git a/controls/controls.pri b/controls/controls.pri index 457e390..d098b54 100644 --- a/controls/controls.pri +++ b/controls/controls.pri @@ -1,6 +1,7 @@ SOURCES += \ $$PWD/AnimationChangingWidget.cpp \ $$PWD/ComboBoxDelegate.cpp \ + $$PWD/CustomLineHeightLabel.cpp \ $$PWD/CustomPlacementButton.cpp \ $$PWD/ServersComboBox.cpp \ $$PWD/AnimatedLineEdit.cpp \ @@ -11,6 +12,7 @@ SOURCES += \ HEADERS += \ $$PWD/AnimationChangingWidget.h \ $$PWD/ComboBoxDelegate.h \ + $$PWD/CustomLineHeightLabel.h \ $$PWD/CustomPlacementButton.h \ $$PWD/ServersComboBox.h \ $$PWD/AnimatedLineEdit.h \ -- GitLab