update style functions to work without selection
This commit is contained in:
parent
2f6b7d44d8
commit
a609d4f413
@ -223,13 +223,11 @@ void MainWindow::setBold(){
|
|||||||
|
|
||||||
if (plainTextEdit) {
|
if (plainTextEdit) {
|
||||||
QTextCursor cursor = plainTextEdit->textCursor();
|
QTextCursor cursor = plainTextEdit->textCursor();
|
||||||
if (cursor.hasSelection()) {
|
|
||||||
QTextCharFormat format;
|
QTextCharFormat format;
|
||||||
QFont font = plainTextEdit->currentCharFormat().font();
|
QFont font = cursor.charFormat().font();
|
||||||
font.setBold(!font.bold());
|
font.setBold(!font.bold());
|
||||||
format.setFont(font);
|
format.setFont(font);
|
||||||
cursor.mergeCharFormat(format);
|
plainTextEdit->mergeCurrentCharFormat(format);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,13 +244,11 @@ void MainWindow::setItalic(){
|
|||||||
|
|
||||||
if (plainTextEdit) {
|
if (plainTextEdit) {
|
||||||
QTextCursor cursor = plainTextEdit->textCursor();
|
QTextCursor cursor = plainTextEdit->textCursor();
|
||||||
if (cursor.hasSelection()) {
|
|
||||||
QTextCharFormat format;
|
QTextCharFormat format;
|
||||||
QFont font = plainTextEdit->currentCharFormat().font();
|
QFont font = cursor.charFormat().font();
|
||||||
font.setItalic(!font.italic());
|
font.setItalic(!font.italic());
|
||||||
format.setFont(font);
|
format.setFont(font);
|
||||||
cursor.mergeCharFormat(format);
|
plainTextEdit->mergeCurrentCharFormat(format);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,13 +264,11 @@ void MainWindow::setUnderline(){
|
|||||||
|
|
||||||
if (plainTextEdit) {
|
if (plainTextEdit) {
|
||||||
QTextCursor cursor = plainTextEdit->textCursor();
|
QTextCursor cursor = plainTextEdit->textCursor();
|
||||||
if (cursor.hasSelection()) {
|
|
||||||
QTextCharFormat format;
|
QTextCharFormat format;
|
||||||
QFont font = plainTextEdit->currentCharFormat().font();
|
QFont font = cursor.charFormat().font();
|
||||||
font.setUnderline(!font.underline());
|
font.setUnderline(!font.underline());
|
||||||
format.setFont(font);
|
format.setFont(font);
|
||||||
cursor.mergeCharFormat(format);
|
plainTextEdit->mergeCurrentCharFormat(format);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,12 +286,10 @@ void MainWindow::setColor(){
|
|||||||
if (plainTextEdit) {
|
if (plainTextEdit) {
|
||||||
QColor color = QColorDialog::getColor(Qt::black, this, "Choisir une couleur");
|
QColor color = QColorDialog::getColor(Qt::black, this, "Choisir une couleur");
|
||||||
QTextCursor cursor = plainTextEdit->textCursor();
|
QTextCursor cursor = plainTextEdit->textCursor();
|
||||||
if (cursor.hasSelection()) {
|
|
||||||
if (color.isValid()) {
|
if (color.isValid()) {
|
||||||
QTextCharFormat format;
|
QTextCharFormat format;
|
||||||
format.setForeground(color);
|
format.setForeground(color);
|
||||||
cursor.mergeCharFormat(format);
|
plainTextEdit->mergeCurrentCharFormat(format);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -313,13 +305,11 @@ void MainWindow::setOverline(){
|
|||||||
|
|
||||||
if (plainTextEdit) {
|
if (plainTextEdit) {
|
||||||
QTextCursor cursor = plainTextEdit->textCursor();
|
QTextCursor cursor = plainTextEdit->textCursor();
|
||||||
if (cursor.hasSelection()) {
|
|
||||||
QTextCharFormat format;
|
QTextCharFormat format;
|
||||||
QFont font = plainTextEdit->currentCharFormat().font();
|
QFont font = cursor.charFormat().font();
|
||||||
font.setOverline(!font.overline());
|
font.setOverline(!font.overline());
|
||||||
format.setFont(font);
|
format.setFont(font);
|
||||||
cursor.mergeCharFormat(format);
|
plainTextEdit->mergeCurrentCharFormat(format);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void MainWindow::on_actionOverline_triggered()
|
void MainWindow::on_actionOverline_triggered()
|
||||||
@ -333,7 +323,6 @@ void MainWindow::setSize(){
|
|||||||
|
|
||||||
if (plainTextEdit) {
|
if (plainTextEdit) {
|
||||||
QTextCursor cursor = plainTextEdit->textCursor();
|
QTextCursor cursor = plainTextEdit->textCursor();
|
||||||
if (cursor.hasSelection()) {
|
|
||||||
bool ok;
|
bool ok;
|
||||||
int size = QInputDialog::getInt(this, "Taille de la police", "Entrez la taille de la police:", cursor.charFormat().font().pointSize(), 1, 100, 1, &ok);
|
int size = QInputDialog::getInt(this, "Taille de la police", "Entrez la taille de la police:", cursor.charFormat().font().pointSize(), 1, 100, 1, &ok);
|
||||||
|
|
||||||
@ -342,8 +331,7 @@ void MainWindow::setSize(){
|
|||||||
QFont font = cursor.charFormat().font();
|
QFont font = cursor.charFormat().font();
|
||||||
font.setPointSize(size);
|
font.setPointSize(size);
|
||||||
format.setFont(font);
|
format.setFont(font);
|
||||||
cursor.mergeCharFormat(format);
|
plainTextEdit->mergeCurrentCharFormat(format);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -358,14 +346,12 @@ void MainWindow::setFont(){
|
|||||||
|
|
||||||
if (plainTextEdit) {
|
if (plainTextEdit) {
|
||||||
QTextCursor cursor = plainTextEdit->textCursor();
|
QTextCursor cursor = plainTextEdit->textCursor();
|
||||||
if (cursor.hasSelection()) {
|
|
||||||
bool ok;
|
bool ok;
|
||||||
QFont font = QFontDialog::getFont(&ok, cursor.charFormat().font(), this, "Choisir une police");
|
QFont font = QFontDialog::getFont(&ok, cursor.charFormat().font(), this, "Choisir une police");
|
||||||
if (ok) {
|
if (ok) {
|
||||||
QTextCharFormat format;
|
QTextCharFormat format;
|
||||||
format.setFont(font);
|
format.setFont(font);
|
||||||
cursor.mergeCharFormat(format);
|
plainTextEdit->mergeCurrentCharFormat(format);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user