diff --git a/auxiliary/defines.h b/auxiliary/defines.h index cfd3d707998f289b018191dc8a366fc3de333c37..f97d405576a1a295f92e77647cac1580a4842bc5 100644 --- a/auxiliary/defines.h +++ b/auxiliary/defines.h @@ -3,11 +3,13 @@ #include <QString> -namespace Properties { +namespace Properties +{ static const QString TEXT = "text"; static const QString STATE = "state"; static const QString ENABLED = "enabled"; - + static const QString HOVER = "hover" ; + static const QString CHECKED = "checked"; } diff --git a/controls/CustomComboBoxPopup.cpp b/controls/CustomComboBoxPopup.cpp index 041398261951110f87bf2b036b5c3ffb9b3b4a9f..c559fe87e389f55c6e49ba317de7efbaf6db1161 100644 --- a/controls/CustomComboBoxPopup.cpp +++ b/controls/CustomComboBoxPopup.cpp @@ -27,7 +27,7 @@ CustomComboBoxPopup::CustomComboBoxPopup(const QString &a_caption,ListModel *mod 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; diff --git a/controls/CustomLineHeightTextEdit.cpp b/controls/CustomLineHeightTextEdit.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4ada3bc828f0aebef5096978d15781dd74198986 --- /dev/null +++ b/controls/CustomLineHeightTextEdit.cpp @@ -0,0 +1,81 @@ +#include "CustomLineHeightTextEdit.h" + + +CustomLineHeightTextEdit::CustomLineHeightTextEdit(QWidget *a_parent) + :QTextEdit (a_parent) +{ +} + +void CustomLineHeightTextEdit::setPlaceholderText(const QString &placeholderText) +{ + setProperty("state",STATE_DEFAULT); + style()->unpolish(this); + style()->polish(this); + update(); + m_placeholderText = placeholderText; + QTextEdit::setText(textToHtml(placeholderText)); + //setReadOnly(true); +} + +void CustomLineHeightTextEdit::mousePressEvent(QMouseEvent *e) +{ + if(property("state").toString()==STATE_DEFAULT) + { + setProperty("state",STATE_HOVER); + style()->unpolish(this); + style()->polish(this); + update(); + QString htmlText = QString("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0//EN' 'http://www.w3.org/TR/REC-html40/strict.dtd'>" + "<html><head><meta name='qrichtext' content='1' /><style type='text/css'>" + "p, li { white-space: pre-wrap; }" + "</style></head><body>" + "<p style='line-height:%1;'></p></body></html>").arg(m_lineHeight); + + QTextEdit::setText(htmlText); + } + QTextEdit::mousePressEvent(e); +} + +void CustomLineHeightTextEdit::focusOutEvent(QFocusEvent *e) +{ + if(toPlainText().isEmpty()) + { + setProperty("state",STATE_DEFAULT); + style()->unpolish(this); + style()->polish(this); + update(); + QTextEdit::setText(textToHtml(m_placeholderText)); + } + QTextEdit::focusOutEvent(e); +} + +QString CustomLineHeightTextEdit::toPlainText() const +{ + if(property("state").toString()==STATE_DEFAULT) + return QString(""); + + return QTextEdit::toPlainText(); + +} + +void CustomLineHeightTextEdit::setObjectName(const QString &name) +{ + QObject::setObjectName(name); + + updateStyleSheets(); +} + +void CustomLineHeightTextEdit::updateStyleSheets() +{ + StyleSheatSearchPar searchPar; + searchPar.widgetName = "#" + this->objectName(); + + QString stylesheet = AppStyleSheetHandler::getWidgetStyleSheet(searchPar); + m_lineHeight = AppStyleSheetHandler::getValueFromStylesheet(stylesheet, "line-height"); +} + +QString CustomLineHeightTextEdit::textToHtml(const QString &text) +{ + if(m_lineHeight.isEmpty())m_lineHeight = "100"; + return QString("<p style = 'line-height:%1;'> %2 </p>").arg(m_lineHeight).arg(text); +} diff --git a/controls/CustomLineHeightTextEdit.h b/controls/CustomLineHeightTextEdit.h new file mode 100644 index 0000000000000000000000000000000000000000..d7453eb87507c4d210a9cfb099b50a399c4f8d1b --- /dev/null +++ b/controls/CustomLineHeightTextEdit.h @@ -0,0 +1,77 @@ +#ifndef CUSTOMLINEHEIGHTTEXTEDIT_H +#define CUSTOMLINEHEIGHTTEXTEDIT_H + +#include <QTextEdit> +#include "AppStyleSheetHandler.h" +#include <QStyle> + +/** @brief QGraphicsDropShadowEffect that can be adjusted from css + * + * @details Set style in .css file in format + * + *> #elementName + *> { + *> + *> line-height: 100%; (100% or 100) + *>} + * To specify PlaceholderText parameters + *> #elementName[state="0"] + *> { + *> color:#A1A1A1; + *> + *>} + * To specify text parameters + *> #elementName[state="1"] + *> { + *>color:#000000; + *> + *>} + * +*/ + +class CustomLineHeightTextEdit: public QTextEdit +{ +public: + explicit CustomLineHeightTextEdit(QWidget *a_parent = Q_NULLPTR); + /** @brief Sets the object name and updates the styles. + * @param placeholderText + */ + void setObjectName(const QString &name); + /** @brief Updates the styles. + */ + void updateStyleSheets(); + /** @brief The redefined method returns plain text as html for setting the line spacing. + * @param placeholderText + */ + void setPlaceholderText(const QString &placeholderText); + /** @brief Returns text or empty string. + */ + QString toPlainText() const; +protected: + /** @brief The redefined method returns plain text as html for setting the line spacing. + * @param e + */ + void focusOutEvent(QFocusEvent *e); + /** @brief By clicking the mouse button, removes text from the screen and updates the settings for text. + * @param e + */ + void mousePressEvent(QMouseEvent *e); + + const QString STATE_HOVER = "hover"; + const QString STATE_DEFAULT = "default"; + +private: + /** @brief Adds a style to the text from the html line height. + * @param text + */ + QString textToHtml(const QString &text); + /** @brief The value of the row height from the style sheet. + */ + QString m_lineHeight; + /** @brief Default text. + */ + QString m_placeholderText; + +}; + +#endif // CUSTOMLINEHEIGHTTEXTEDIT_H diff --git a/controls/CustomPlacementButton_New.cpp b/controls/CustomPlacementButton_New.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d33a243732992711902248836f7066ed83b8fa3f --- /dev/null +++ b/controls/CustomPlacementButton_New.cpp @@ -0,0 +1,176 @@ +#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); +//} diff --git a/controls/CustomPlacementButton_New.h b/controls/CustomPlacementButton_New.h new file mode 100644 index 0000000000000000000000000000000000000000..df59a309f8b9577bd9e07afa5ba790db02e026db --- /dev/null +++ b/controls/CustomPlacementButton_New.h @@ -0,0 +1,79 @@ +#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 diff --git a/controls/CustomWidget.cpp b/controls/CustomWidget.cpp index c9b48d9b64d1cbefce0ab123fa213b3e36f82646..9ba78b78aca6b052b4b7d6384fc00ebfd81cbd8f 100644 --- a/controls/CustomWidget.cpp +++ b/controls/CustomWidget.cpp @@ -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) { - m_index = index; - m_data = &model; - m_listView = listView; +// m_index = index; +// m_data = &model; +// m_listView = listView; setObjectName("wgtDelegate"); setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Fixed); @@ -98,3 +98,13 @@ void CustomWidget::setStyle(int state) setGraphicsEffect(m_styledshadow); } } + +bool CustomWidget::selected() const +{ + return m_selected; +} + +void CustomWidget::setSelected(bool selected) +{ + m_selected = selected; +} diff --git a/controls/CustomWidget.h b/controls/CustomWidget.h index 6a61787a4abfd74ef955857957ca942ba6141ffc..4bd0f9708c6845a45d195c8a43f280ebeb9f2f93 100644 --- a/controls/CustomWidget.h +++ b/controls/CustomWidget.h @@ -7,11 +7,15 @@ #include "StyledDropShadowEffect.h" #include "ListModel.h" #include <QListView> -class CustomWidget:public QWidget +class CustomWidget: public QWidget { public: 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: void enterEvent(QEvent *event); void leaveEvent(QEvent *event); @@ -21,6 +25,13 @@ private: //Updates styles on mouseover and on setting activity of an element. void setStyle(int state); + bool m_selected; + + + + + + ///////////////////////////////////////// QLabel *m_lblFlag; QLabel *m_lblText; QLabel *m_lblCheckIcon; diff --git a/controls/controls.pri b/controls/controls.pri index 60ea7401a948fdb22a3c3fc03d757c23ab464eb6..94d2eb4c5aea69efa296cff8ee01804aefa1a9bf 100644 --- a/controls/controls.pri +++ b/controls/controls.pri @@ -5,7 +5,9 @@ SOURCES += \ $$PWD/CustomComboBox.cpp \ $$PWD/CustomComboBoxPopup.cpp \ $$PWD/CustomLineHeightLabel.cpp \ + $$PWD/CustomLineHeightTextEdit.cpp \ $$PWD/CustomPlacementButton.cpp \ + $$PWD/CustomPlacementButton_New.cpp \ $$PWD/CustomWidget.cpp \ $$PWD/ListModel.cpp \ $$PWD/ServersComboBox.cpp \ @@ -21,7 +23,9 @@ HEADERS += \ $$PWD/CustomComboBox.h \ $$PWD/CustomComboBoxPopup.h \ $$PWD/CustomLineHeightLabel.h \ + $$PWD/CustomLineHeightTextEdit.h \ $$PWD/CustomPlacementButton.h \ + $$PWD/CustomPlacementButton_New.h \ $$PWD/CustomWidget.h \ $$PWD/ListModel.h \ $$PWD/ServersComboBox.h \