How can I do QTextEdit page numbering? - qt

How can I do page numbering in QTextEdit?
sourceTextEdit = new QTextEdit();
QString lorem="Lorem ipsum tellus, eros ipsum lectus justo malesuada massa enim"
" urna ipsum adipiscing in elementum porttitor arcu quisque "
"curabitur justo sit eros orci. Rutrum, sit nec cursus et malesuada"
" diam odio proin at tempus non.";
QTextCursor cursor = sourceTextEdit->textCursor();
cursor.insertText(lorem);
textDocument = sourceTextEdit->document();
QTextDocumentWriter writer;
writer.setFormat("odf");
writer.setFileName("report.odt");
writer.write(textDocument);
I want the report.odt file to have page numbering. How to do it?

Related

Simplest way to get overlapping text in an Rmd presentation slide to automatically go onto a new slide?

This seems like a straightforward thing to do but I can't find any related questions in my search queries.
Dummy .Rmd script:
---
title: "Untitled"
author: "Me"
date: "22/11/2022"
output: powerpoint_presentation
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## R Markdown
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam odio lacus, consectetur pellentesque ex non, commodo vulputate mi. Fusce blandit consectetur varius. Etiam eu urna venenatis, elementum justo ac, elementum purus. Vestibulum ultricies sit amet urna ullamcorper congue. Vestibulum odio leo, ultrices sed dolor aliquam, ultricies tempor odio. In velit odio, sagittis quis enim eu, molestie dignissim arcu. Phasellus luctus vulputate tortor, sit amet ullamcorper sapien fringilla nec.
Quisque vulputate vehicula dolor, ac cursus ipsum tristique a. Curabitur viverra risus vel velit fringilla, sed rhoncus magna rhoncus. Vivamus et ex justo. Nulla fermentum viverra lacinia. Maecenas tempus posuere nisl, at fringilla odio iaculis sed. Nulla sapien erat, dignissim eget pretium et, consectetur et eros. Ut a vestibulum orci, vehicula aliquet nisi. Proin at fermentum erat. Nam ut orci gravida neque eleifend tincidunt. Donec et mauris diam. Cras ut lacinia diam. Ut tristique lorem quis nulla fermentum mattis. Quisque id orci vitae odio lacinia interdum.
Output:
I don't want to manually specify breaks or new slides as in my real document the text can be any number of paragraphs or words long so I need it done automatically.
I can't see any option to do this in the reference doc.

How to trigger CSS keyframe animation based on scroll position?

I want to trigger a circle fadeIn animation based on the user scroll position.
With every scroll down, the circle gets bigger.
With every scroll up, the circle gets smaller.
The animation would stop if the user is not scrolling anymore - so the user has to scroll a few times for the animation to be complete. If the scrolling stops, the circle would remain at a certain width (depending on how much he scrolled up/down).
I only have it running with basic CSS and HTML at the moment. I am missing JS the scroll function that would trigger the circle getting bigger/smaller depending on how much the user scrolls in the background.
.section {
animation: 3s fadeInAnimation reverse;
animation-delay:0s;
animation-timing-function: ease-in-out;
animation-iteration-count: 1;
background: yellow;
height: 100vh;
}
#keyframes fadeInAnimation {
0% {
clip-path: circle(75%);
}
100% {
clip-path: circle(0%);
}
}
<div class="section">
<h1>
Section Title
</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut tincidunt commodo lacus vitae porttitor. Morbi lobortis diam lorem, sed faucibus leo gravida ac. Curabitur ex velit, consectetur vitae ligula in, fringilla tincidunt turpis. Curabitur sem turpis, scelerisque et pretium in, ornare at dui. Morbi pellentesque viverra rhoncus.
</p>
</div>
Fiddle Here
This is a perfect scenario for using a CSS Custom Property and updating its value via JavaScript whenever the window is scrolled.
If we initially set the following custom property:
:root { --clip-circle: 0% }
We can then update the value of that custom property at any time by:
re-calculating clipCircleValue
document.documentElement.style.setProperty('--clip-circle', clipCircleValue);
Working Example (click Full Page) :
const updateClipCircleValue = () => {
let documentScrollHeight = document.documentElement.scrollHeight;
let documentScrollPosition = window.scrollY;
let documentScrollPercentage = ((documentScrollPosition / documentScrollHeight) * 100);
let clipCircleValue = documentScrollPercentage + '%';
document.documentElement.style.setProperty('--clip-circle', clipCircleValue);
}
window.addEventListener('scroll', updateClipCircleValue);
:root {
--clip-circle: 0%;
}
body {
min-height: 400vh;
}
.section {
position: fixed;
top: 0;
left: 0;
background-color: rgb(255, 255, 0);
clip-path: circle(var(--clip-circle));
}
<div class="section">
<h1>
Section Title
</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut tincidunt commodo lacus vitae porttitor. Morbi lobortis diam lorem, sed faucibus leo gravida ac. Curabitur ex velit, consectetur vitae ligula in, fringilla tincidunt turpis. Curabitur sem turpis, scelerisque et pretium in, ornare at dui. Morbi pellentesque viverra rhoncus.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut tincidunt commodo lacus vitae porttitor. Morbi lobortis diam lorem, sed faucibus leo gravida ac. Curabitur ex velit, consectetur vitae ligula in, fringilla tincidunt turpis. Curabitur sem turpis, scelerisque et pretium in, ornare at dui. Morbi pellentesque viverra rhoncus.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut tincidunt commodo lacus vitae porttitor. Morbi lobortis diam lorem, sed faucibus leo gravida ac. Curabitur ex velit, consectetur vitae ligula in, fringilla tincidunt turpis. Curabitur sem turpis, scelerisque et pretium in, ornare at dui. Morbi pellentesque viverra rhoncus.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut tincidunt commodo lacus vitae porttitor. Morbi lobortis diam lorem, sed faucibus leo gravida ac. Curabitur ex velit, consectetur vitae ligula in, fringilla tincidunt turpis. Curabitur sem turpis, scelerisque et pretium in, ornare at dui. Morbi pellentesque viverra rhoncus.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut tincidunt commodo lacus vitae porttitor. Morbi lobortis diam lorem, sed faucibus leo gravida ac. Curabitur ex velit, consectetur vitae ligula in, fringilla tincidunt turpis. Curabitur sem turpis, scelerisque et pretium in, ornare at dui. Morbi pellentesque viverra rhoncus.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut tincidunt commodo lacus vitae porttitor. Morbi lobortis diam lorem, sed faucibus leo gravida ac. Curabitur ex velit, consectetur vitae ligula in, fringilla tincidunt turpis. Curabitur sem turpis, scelerisque et pretium in, ornare at dui. Morbi pellentesque viverra rhoncus.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut tincidunt commodo lacus vitae porttitor. Morbi lobortis diam lorem, sed faucibus leo gravida ac. Curabitur ex velit, consectetur vitae ligula in, fringilla tincidunt turpis. Curabitur sem turpis, scelerisque et pretium in, ornare at dui. Morbi pellentesque viverra rhoncus.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut tincidunt commodo lacus vitae porttitor. Morbi lobortis diam lorem, sed faucibus leo gravida ac. Curabitur ex velit, consectetur vitae ligula in, fringilla tincidunt turpis. Curabitur sem turpis, scelerisque et pretium in, ornare at dui. Morbi pellentesque viverra rhoncus.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut tincidunt commodo lacus vitae porttitor. Morbi lobortis diam lorem, sed faucibus leo gravida ac. Curabitur ex velit, consectetur vitae ligula in, fringilla tincidunt turpis. Curabitur sem turpis, scelerisque et pretium in, ornare at dui. Morbi pellentesque viverra rhoncus.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut tincidunt commodo lacus vitae porttitor. Morbi lobortis diam lorem, sed faucibus leo gravida ac. Curabitur ex velit, consectetur vitae ligula in, fringilla tincidunt turpis. Curabitur sem turpis, scelerisque et pretium in, ornare at dui. Morbi pellentesque viverra rhoncus.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut tincidunt commodo lacus vitae porttitor. Morbi lobortis diam lorem, sed faucibus leo gravida ac. Curabitur ex velit, consectetur vitae ligula in, fringilla tincidunt turpis. Curabitur sem turpis, scelerisque et pretium in, ornare at dui. Morbi pellentesque viverra rhoncus.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut tincidunt commodo lacus vitae porttitor. Morbi lobortis diam lorem, sed faucibus leo gravida ac. Curabitur ex velit, consectetur vitae ligula in, fringilla tincidunt turpis. Curabitur sem turpis, scelerisque et pretium in, ornare at dui. Morbi pellentesque viverra rhoncus.
</p>
</div>

How to keep text with prior div (eliminate newline)

I have a project in which I'm parsing some text and reformatting it with divs wrapped around key sections. I'm using divs because I specifically need to outdent the first line of each section, for which I'm using left-padding along with negative text-indent. Everything is working fine, except for one issue: due to the nature of the text and the way I need to parse it, many sections will need to end with a comma which cannot be included in the prior div. So I end up with a comma that floats on its own line. I'd like to find a way to make the comma stay with the prior div instead of appearing on a new line. Note: changing the parsing routine to move the comma inside the prior div will be complex; I'm specifically looking for a way to do this in CSS without moving the comma inside the prior div.
Here's a simplified example of the output of what my parse-to-html routine produces (JSFiddle):
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<style>
.inner {
padding-left: 8ch;
text-indent: -6ch;
}
</style>
</head>
<body>
<div class="container">
<div class="inner">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam quis leo diam. Donec mattis erat eget augue pellentesque sodales. Aliquam et augue eget libero mollis hendrerit eu a purus. Morbi bibendum, nunc eget lobortis porttitor, tortor velit posuere ex, at tempor eros orci auctor magna. Praesent maximus malesuada sodales. Integer convallis eget orci eget cursus</div>,
<div class="inner">Mauris aliquam luctus sem, non cursus libero cursus non. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vestibulum dignissim nisi eu elit placerat, vel euismod quam elementum. Nam fringilla tristique nibh a mattis. Duis finibus lacus libero, quis efficitur sem egestas vitae. Nunc auctor enim lectus, non finibus est tincidunt ut. Nulla commodo odio ut nisl ullamcorper vehicula.</div>
</div>
</body>
</html>
If you view the rendered output, you'll see that between the two inner divs, there's a comma that appears on its own line. I'd like it at the end of the final line of the previous div. In order to get the outdenting, I need to use div instead of span. Is there any way to make that comma appear at the end of the prior div, without moving it inside the div?
Also: I'm targeting Electron.js, so I don't need an every-browser solution. Something that works in latest Chrome is sufficient.
Edit to add: if it helps, assume I can wrap additional tags around the content, including around the div + comma. It's moving the comma that is expensive (for my value of expensive).
It's not the cleanest solution, but since you can't put the comma in the div you will need to set the div to display as inline (or switch it to a span) so that the comma appears next to the text and handle the line break with wrapping the comma and adding a pseudo element. E.g.:
.container {
padding-left: 8ch;
}
.inner {
display: inline;
margin-left: -6ch;
}
.comma:after {
display: block;
content: " ";
}
See this update to your JS Fiddle for an example.
I have come with this solution for you if you don't want to change the HTML code at all!
CSS will add a comma after the div.inner while javaScript will remove the existing comma.
let comma = document.querySelectorAll('.inner');
for (let i = 0; i < comma.length; i++){
comma[i].nextSibling.textContent = '';
}
.inner {
padding-left: 8ch;
text-indent: -6ch;
margin-bottom:15px;/*adds extra space at bottom*/
}
.inner:after{
content: ",";
}
.inner:last-child::after{
content: "";
}
<div class="container">
<div class="inner">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam quis leo diam. Donec mattis erat eget augue pellentesque sodales. Aliquam et augue eget libero mollis hendrerit eu a purus. Morbi bibendum, nunc eget lobortis porttitor, tortor velit posuere ex, at tempor eros orci auctor magna. Praesent maximus malesuada sodales. Integer convallis eget orci eget cursus</div>,
<div class="inner">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam quis leo diam. Donec mattis erat eget augue pellentesque sodales. Aliquam et augue eget libero mollis hendrerit eu a purus. Morbi bibendum, nunc eget lobortis porttitor, tortor velit posuere ex, at tempor eros orci auctor magna. Praesent maximus malesuada sodales. Integer convallis eget orci eget cursus</div>,
<div class="inner">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam quis leo diam. Donec mattis erat eget augue pellentesque sodales. Aliquam et augue eget libero mollis hendrerit eu a purus. Morbi bibendum, nunc eget lobortis porttitor, tortor velit posuere ex, at tempor eros orci auctor magna. Praesent maximus malesuada sodales. Integer convallis eget orci eget cursus</div>,
<div class="inner">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam quis leo diam. Donec mattis erat eget augue pellentesque sodales. Aliquam et augue eget libero mollis hendrerit eu a purus. Morbi bibendum, nunc eget lobortis porttitor, tortor velit posuere ex, at tempor eros orci auctor magna. Praesent maximus malesuada sodales. Integer convallis eget orci eget cursus</div>,
<div class="inner">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam quis leo diam. Donec mattis erat eget augue pellentesque sodales. Aliquam et augue eget libero mollis hendrerit eu a purus. Morbi bibendum, nunc eget lobortis porttitor, tortor velit posuere ex, at tempor eros orci auctor magna. Praesent maximus malesuada sodales. Integer convallis eget orci eget cursus</div>,
<div class="inner">Mauris aliquam luctus sem, non cursus libero cursus non. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vestibulum dignissim nisi eu elit placerat, vel euismod quam elementum. Nam fringilla tristique nibh a mattis. Duis finibus lacus libero, quis efficitur sem egestas vitae. Nunc auctor enim lectus, non finibus est tincidunt ut. Nulla commodo odio ut nisl ullamcorper vehicula.</div>
</div>

carriage return in strwrap in R

I'm having trouble figuring out how to modify my input text in order to get strwrap to start a new line at a given place without an extra line in between (a paragraph break).
My desired output:
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Vivamus malesuada ante eget lacus aliquam aliquet. Morbi a
nulla in tortor rutrum pulvinar.
Duis auctor condimentum magna ac commodo. Phasellus quis
elementum purus, at ornare magna. Quisque sit amet vehicula
risus. Suspendisse et et scelerisque velit:
item #1
item #2
item #3
I can use \n to get the paragraph break, which works fine, but how do I get a new line without the paragraph break, as in the list of items at the bottom? When I use \r...
txt <- "Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Vivamus malesuada ante eget lacus aliquam aliquet. Morbi a nulla
in tortor rutrum pulvinar.
\n
Duis auctor condimentum magna ac commodo. Phasellus quis elementum purus,
at ornare magna. Quisque sit amet vehicula risus. Suspendisse et
scelerisque velit:
\r
item #1
item #2
item #3"
writeLines(strwrap(txt, width=60))
... I get an unexpected result: a line break but with an extra space indent and some juxtaposition and deletion of text:
#Lorem ipsum dolor sit amet, consectetur adipiscing elit.
#Vivamus malesuada ante eget lacus aliquam aliquet. Morbi a
#nulla in tortor rutrum pulvinar.
#
#Duis auctor condimentum magna ac commodo. Phasellus quis
#elementum purus, at ornare magna. Quisque sit amet vehicula
# item #1 item #2se et scelerisque velit:
#item #3
What do I need to replace /r with in order to get a single line break, like between "velit:" and "item #1" in the desired output above? I've read the strwrap documentation and worked through its example, but haven't found the answer. Thanks for your help.
On the off-change that someone else finds this question in the future, I'll share the solution I used here. As Wiktor points out above, strwrap does not have this functionality. What I ended up doing was simply a workaround that edits the text after it goes through strwrap.
I add an arbitrary character sequence to the beginning of each line in the input which I want to start with a carriage return. Below I use "/r" for this. I send the input through strwrap, add two empty lines to the end, and then parse each line of the output, deleting "/r" and removing the empty preceding line (paragraph break). Here's the code:
txt <- "Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Vivamus malesuada ante eget lacus aliquam aliquet. Morbi a nulla
in tortor rutrum pulvinar.
\n
Duis auctor condimentum magna ac commodo. Phasellus quis elementum purus,
at ornare magna. Quisque sit amet vehicula risus. Suspendisse et
scelerisque velit:
\n\r item #1
\n\r item #2
\n\r item #3"
sink("output.txt")
lines <- append(strwrap(txt, width=100), c("",""), after = length(lines))
invisible(lapply(seq_along(lines), function(index) {
if (index != 1) { #skip first line
if (!grepl("\r ", lines[index])) {
writeLines(gsub("\r ", "", lines[index-1]))
}
}
}))
sink()
This produces a .txt file with the output text formatted as desired, where the list of items at the bottom is separated by carriage returns/newlines but paragraph breaks marked in the input with just "/n" are treated normally.

CSS Overflow Auto in Mountain Lion: Scrollbars not appearing

Test this JS Fiddle in Chrome or Safari on Lion and Mountain Lion.
What should be displayed is a box that scrolls. Once you start scrolling, the bar should appear, and disappear once again when you stop scrolling. In Lion and Mountain Lion, it doesn't. Anyone know of a fix to show the scrollbars?
HTML:
<div id="box">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus facilisis scelerisque aliquam. Nulla consequat justo malesuada mi imperdiet sodales. Morbi rhoncus, diam nec egestas sagittis, ipsum eros sollicitudin urna, quis ornare erat nisl scelerisque eros. Nulla eleifend posuere tempus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum in diam commodo sapien mollis cursus. Integer vitae lacus augue. Proin a velit augue. Quisque at mi augue, a sagittis metus. Aenean id bibendum nunc. Nulla quis eros odio. Sed non leo diam, et sollicitudin leo. Cras ut nibh diam, a mattis felis. Proin lectus massa, fermentum sit amet aliquet id, posuere a dui. Morbi vulputate elit elit. Proin in mi turpis.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus facilisis scelerisque aliquam. Nulla consequat justo malesuada mi imperdiet sodales. Morbi rhoncus, diam nec egestas sagittis, ipsum eros sollicitudin urna, quis ornare erat nisl scelerisque eros. Nulla eleifend posuere tempus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum in diam commodo sapien mollis cursus. Integer vitae lacus augue. Proin a velit augue. Quisque at mi augue, a sagittis metus. Aenean id bibendum nunc. Nulla quis eros odio. Sed non leo diam, et sollicitudin leo. Cras ut nibh diam, a mattis felis. Proin lectus massa, fermentum sit amet aliquet id, posuere a dui. Morbi vulputate elit elit. Proin in mi turpis.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus facilisis scelerisque aliquam. Nulla consequat justo malesuada mi imperdiet sodales. Morbi rhoncus, diam nec egestas sagittis, ipsum eros sollicitudin urna, quis ornare erat nisl scelerisque eros. Nulla eleifend posuere tempus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum in diam commodo sapien mollis cursus. Integer vitae lacus augue. Proin a velit augue. Quisque at mi augue, a sagittis metus. Aenean id bibendum nunc. Nulla quis eros odio. Sed non leo diam, et sollicitudin leo. Cras ut nibh diam, a mattis felis. Proin lectus massa, fermentum sit amet aliquet id, posuere a dui. Morbi vulputate elit elit. Proin in mi turpis.</p>
</div>​
CSS:
#box {
height: 300px;
overflow: auto;
margin: 10px;
}​
This problem is "real" in that previous posters have shown a real difference in appearance in Apple's Mountain Lion operating system.
But the scroll behavior still works, in other examples I see on the internet and on the "Test this" link of the opening post.
The problem is that the default user setup in Mountain Lion causes the scroll bars to be hidden so the user does not see them. And the default "natural" scroll wheel or track pad (Magic Pad) direction is opposite of older systems or PC's. These two aspects lead to confusion.
With the default settings, the scrolling region will scroll if the mouse arrow is over the block (even though the scroll bars are not present), and will appear if one moves in the proper direction. The default "natural" (as Apple calls it) direction is that the scroll wheel or the track pad moves the object itself in the "natural" direction (as opposed to the window moving on the object). There is a setting on the Mac to reverse this, but that will make the Mac's direction opposite of the direction on Apple's touch tablets.
The real problem is the confusion to the user caused by the hiding of the scroll bars, so they don't realize that they CAN move the area with a scroll wheel if mouse cursor is over. And furthermore the user must have a track pad or scroll wheel for it to even work, but that is needed for the most part to even navigate the Mountain Lion operating system itself.
The user can change the Mac's setting in the Personal General setting to "Show scroll bars: Always". But that is of little help to the CSS or website developer.
I suggest we complain to Apple about this. Main alternative is just not use the feature of scrollable area in a window of a website.
Here is a jQuery plugIn that does what you need.
http://naeka.github.com/jquery-scrollbar/
you'll need
<script type="text/javascript" src="jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="jquery-ui-1.8.16.custom.min.js"></script>
<script type="text/javascript" src="jquery.scrollbar.min.js"></script>
<script type="text/javascript" src="demo.js"></script>
Use classes <div id="page"> <div class="scrollBox"><div id="scroll1"><p class="left">
Example: http://jsfiddle.net/pullapooh/3aGDK/
Seems to work for me on linux mint, how about trying:
overflow:scroll;

Resources