added rescaling images
This commit is contained in:
parent
f24fc3da3c
commit
369144f03f
4 changed files with 104 additions and 11 deletions
16
Content.qml
16
Content.qml
|
@ -49,6 +49,8 @@ ScrollView {
|
|||
|
||||
MouseArea {
|
||||
onWheel: {
|
||||
// If we use the mouse wheel we don't want any
|
||||
// animation bahaviour because it slows it down
|
||||
wheel.accepted = false
|
||||
smoothScrolling.enabled = false
|
||||
}
|
||||
|
@ -135,20 +137,14 @@ ScrollView {
|
|||
width: parent.width
|
||||
color: "transparent"
|
||||
|
||||
Label {
|
||||
RescalingRichText {
|
||||
id: contentLabel
|
||||
text: post ? "<style>a { color: #555; }</style>" + post.content : ""
|
||||
textFormat: Text.RichText
|
||||
font.pointSize: textfontSize
|
||||
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
|
||||
text: post ? post.content : ""
|
||||
fontSize: textfontSize * 1.3
|
||||
width: parent.width
|
||||
renderType: Text.NativeRendering
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: 20
|
||||
anchors.topMargin: 0
|
||||
lineHeight: 1.3
|
||||
onLinkActivated: {
|
||||
Qt.openUrlExternally(link)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ Component {
|
|||
text: title
|
||||
color: read ? "gray" : this.color
|
||||
font.pointSize: headLinefontSize
|
||||
textFormat: Text.PlainText
|
||||
textFormat: Text.RichText
|
||||
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
|
||||
renderType: Text.NativeRendering
|
||||
width: parent.width
|
||||
|
|
96
RescalingRichText.qml
Normal file
96
RescalingRichText.qml
Normal file
|
@ -0,0 +1,96 @@
|
|||
import QtQuick 2.0
|
||||
import QtQuick.Controls 1.3
|
||||
|
||||
// from: https://github.com/pycage/tidings/blob/master/qml/pages/RescalingRichText.qml
|
||||
|
||||
/* Pretty fancy element for displaying rich text fitting the width.
|
||||
*
|
||||
* Images are scaled down to fit the width, or, technically speaking, the
|
||||
* rich text content is actually scaled down so the images fit, while the
|
||||
* font size is scaled up to keep the original font size.
|
||||
*/
|
||||
Item {
|
||||
id: root
|
||||
|
||||
property string text
|
||||
property color color
|
||||
property real fontSize
|
||||
property bool showSource: false
|
||||
property real lineHeight: 1
|
||||
|
||||
property real scaling: 1
|
||||
|
||||
property string _style: "<style>" +
|
||||
"a:link { color: gray }" +
|
||||
"</style>"
|
||||
|
||||
signal linkActivated(string link)
|
||||
|
||||
height: contentLabel.sourceComponent !== null ? contentLabel.height * scaling
|
||||
: 0
|
||||
clip: true
|
||||
|
||||
onWidthChanged: {
|
||||
rescaleTimer.restart();
|
||||
}
|
||||
|
||||
onTextChanged: {
|
||||
rescaleTimer.restart();
|
||||
}
|
||||
|
||||
Label {
|
||||
id: layoutLabel
|
||||
|
||||
visible: false
|
||||
width: parent.width
|
||||
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
|
||||
textFormat: Text.RichText
|
||||
|
||||
// tiny font so that only images are relevant
|
||||
text: "<style>* { font-size: 1px }</style>" + parent.text
|
||||
|
||||
onContentWidthChanged: {
|
||||
// console.log("contentWidth: " + contentWidth);
|
||||
rescaleTimer.restart();
|
||||
}
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: contentLabel
|
||||
sourceComponent: rescaleTimer.running ? null : labelComponent
|
||||
}
|
||||
|
||||
Component {
|
||||
id: labelComponent
|
||||
|
||||
Label {
|
||||
width: root.width / scaling
|
||||
scale: scaling
|
||||
|
||||
transformOrigin: Item.TopLeft
|
||||
color: root.color
|
||||
font.pixelSize: root.fontSize / scaling
|
||||
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
|
||||
textFormat: root.showSource ? Text.PlainText : Text.RichText
|
||||
smooth: true
|
||||
lineHeight: root.lineHeight * scaling
|
||||
|
||||
text: _style + root.text
|
||||
|
||||
onLinkActivated: {
|
||||
root.linkActivated(link);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: rescaleTimer
|
||||
interval: 100
|
||||
|
||||
onTriggered: {
|
||||
var contentWidth = Math.floor(layoutLabel.contentWidth);
|
||||
scaling = Math.min(1, parent.width / (layoutLabel.contentWidth + 0.0));
|
||||
// console.log("scaling: " + scaling);
|
||||
}
|
||||
}
|
||||
}
|
1
qml.qrc
1
qml.qrc
|
@ -6,5 +6,6 @@
|
|||
<file>Login.qml</file>
|
||||
<file>PostListItem.qml</file>
|
||||
<file>Sidebar.qml</file>
|
||||
<file>RescalingRichText.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue