add of fontSize and font functions
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
#include <QTextEdit>
|
||||
#include <QColorDialog>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QInputDialog>
|
||||
#include <QFontDialog>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
@@ -325,3 +327,50 @@ void MainWindow::on_actionOverline_triggered()
|
||||
this->setOverline();
|
||||
}
|
||||
|
||||
void MainWindow::setSize(){
|
||||
QWidget *focused = QApplication::focusWidget();
|
||||
QPlainTextEdit* plainTextEdit = qobject_cast<QPlainTextEdit*>(focused);
|
||||
|
||||
if (plainTextEdit) {
|
||||
QTextCursor cursor = plainTextEdit->textCursor();
|
||||
if (cursor.hasSelection()) {
|
||||
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);
|
||||
|
||||
if (ok) {
|
||||
QTextCharFormat format;
|
||||
QFont font = cursor.charFormat().font();
|
||||
font.setPointSize(size);
|
||||
format.setFont(font);
|
||||
cursor.mergeCharFormat(format);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void MainWindow::on_actionSize_triggered()
|
||||
{
|
||||
this->setSize();
|
||||
}
|
||||
|
||||
void MainWindow::setFont(){
|
||||
QWidget *focused = QApplication::focusWidget();
|
||||
QPlainTextEdit* plainTextEdit = qobject_cast<QPlainTextEdit*>(focused);
|
||||
|
||||
if (plainTextEdit) {
|
||||
QTextCursor cursor = plainTextEdit->textCursor();
|
||||
if (cursor.hasSelection()) {
|
||||
bool ok;
|
||||
QFont font = QFontDialog::getFont(&ok, cursor.charFormat().font(), this, "Choisir une police");
|
||||
if (ok) {
|
||||
QTextCharFormat format;
|
||||
format.setFont(font);
|
||||
cursor.mergeCharFormat(format);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void MainWindow::on_actionFont_triggered()
|
||||
{
|
||||
this->setFont();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user