Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libdap-qt-ui
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
cellframe
libdap-qt-ui
Commits
a07180b9
Commit
a07180b9
authored
5 years ago
by
konstantin.kukharenko
Committed by
Alexandr Mruchok
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[+]New custom QEditText
parent
910d8463
No related branches found
No related tags found
1 merge request
!17
Develop old
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
controls/CustomLineHeightTextEdit.cpp
+81
-0
81 additions, 0 deletions
controls/CustomLineHeightTextEdit.cpp
controls/CustomLineHeightTextEdit.h
+77
-0
77 additions, 0 deletions
controls/CustomLineHeightTextEdit.h
controls/controls.pri
+2
-0
2 additions, 0 deletions
controls/controls.pri
with
160 additions
and
0 deletions
controls/CustomLineHeightTextEdit.cpp
0 → 100644
+
81
−
0
View file @
a07180b9
#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
);
}
This diff is collapsed.
Click to expand it.
controls/CustomLineHeightTextEdit.h
0 → 100644
+
77
−
0
View file @
a07180b9
#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
This diff is collapsed.
Click to expand it.
controls/controls.pri
+
2
−
0
View file @
a07180b9
...
...
@@ -5,6 +5,7 @@ SOURCES += \
$$PWD/CustomComboBox.cpp \
$$PWD/CustomComboBoxPopup.cpp \
$$PWD/CustomLineHeightLabel.cpp \
$$PWD/CustomLineHeightTextEdit.cpp \
$$PWD/CustomPlacementButton.cpp \
$$PWD/CustomWidget.cpp \
$$PWD/ListModel.cpp \
...
...
@@ -21,6 +22,7 @@ HEADERS += \
$$PWD/CustomComboBox.h \
$$PWD/CustomComboBoxPopup.h \
$$PWD/CustomLineHeightLabel.h \
$$PWD/CustomLineHeightTextEdit.h \
$$PWD/CustomPlacementButton.h \
$$PWD/CustomWidget.h \
$$PWD/ListModel.h \
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment