add of setbold, setItalic, setUnderlined and setFontColor functions
This commit is contained in:
parent
f8cac1aeff
commit
65e391412e
1
data.qrc
1
data.qrc
@ -19,5 +19,6 @@
|
||||
<file>data/images/save_as.png</file>
|
||||
<file>data/images/underline.png</file>
|
||||
<file>data/images/add.png</file>
|
||||
<file>data/images/font-color.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
BIN
data/images/font-color.png
Normal file
BIN
data/images/font-color.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.3 KiB |
@ -6,6 +6,7 @@
|
||||
#include <QMessageBox>
|
||||
#include <QLineEdit>
|
||||
#include <QTimer>
|
||||
#include <QTextEdit>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
@ -212,3 +213,91 @@ void MainWindow::on_actionEditCut_triggered()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::setBold(){
|
||||
QWidget *focused = QApplication::focusWidget();
|
||||
QTextEdit* textEdit = qobject_cast<QTextEdit*>(focused);
|
||||
|
||||
if (textEdit) {
|
||||
QTextCursor cursor = textEdit->textCursor();
|
||||
if (cursor.hasSelection()) {
|
||||
QTextCharFormat format;
|
||||
QFont font = textEdit->currentFont();
|
||||
font.setBold(!font.bold());
|
||||
format.setFont(font);
|
||||
cursor.mergeCharFormat(format);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_actionBold_triggered()
|
||||
{
|
||||
this->setBold();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MainWindow::setItalic(){
|
||||
QWidget *focused = QApplication::focusWidget();
|
||||
QTextEdit* textEdit = qobject_cast<QTextEdit*>(focused);
|
||||
|
||||
if (textEdit) {
|
||||
QTextCursor cursor = textEdit->textCursor();
|
||||
if (cursor.hasSelection()) {
|
||||
QTextCharFormat format;
|
||||
QFont font = textEdit->currentFont();
|
||||
font.setItalic(!font.italic());
|
||||
format.setFont(font);
|
||||
cursor.mergeCharFormat(format);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_actionItalic_triggered()
|
||||
{
|
||||
this->setItalic();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::setUnderline(){
|
||||
QWidget *focused = QApplication::focusWidget();
|
||||
QTextEdit* textEdit = qobject_cast<QTextEdit*>(focused);
|
||||
|
||||
if (textEdit) {
|
||||
QTextCursor cursor = textEdit->textCursor();
|
||||
if (cursor.hasSelection()) {
|
||||
QTextCharFormat format;
|
||||
QFont font = textEdit->currentFont();
|
||||
font.setUnderline(!font.underline());
|
||||
format.setFont(font);
|
||||
cursor.mergeCharFormat(format);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_actionUnderline_triggered()
|
||||
{
|
||||
this->setUnderline();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MainWindow::setColor(){
|
||||
QWidget *focused = QApplication::focusWidget();
|
||||
QTextEdit* textEdit = qobject_cast<QTextEdit*>(focused);
|
||||
|
||||
if (textEdit) {
|
||||
QTextCursor cursor = textEdit->textCursor();
|
||||
if (cursor.hasSelection()) {
|
||||
QTextCharFormat format;
|
||||
format.setForeground(QBrush(QColor(255,0,0)));
|
||||
cursor.mergeCharFormat(format);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::on_actionColor_triggered()
|
||||
{
|
||||
this->setColor();
|
||||
}
|
||||
|
||||
|
||||
12
mainwindow.h
12
mainwindow.h
@ -26,6 +26,10 @@ public:
|
||||
void addNewPath();
|
||||
void addNewStep();
|
||||
void exportHTMLMap();
|
||||
void setBold();
|
||||
void setItalic();
|
||||
void setUnderline();
|
||||
void setColor();
|
||||
|
||||
private slots:
|
||||
void on_pushButton_clicked();
|
||||
@ -43,6 +47,14 @@ private slots:
|
||||
|
||||
void on_actionEditCut_triggered();
|
||||
|
||||
void on_actionBold_triggered();
|
||||
|
||||
void on_actionItalic_triggered();
|
||||
|
||||
void on_actionUnderline_triggered();
|
||||
|
||||
void on_actionColor_triggered();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
QString currentFile;
|
||||
|
||||
@ -38,9 +38,6 @@
|
||||
<property name="text">
|
||||
<string>Path information</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@ -52,10 +49,7 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Raised</enum>
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<widget class="QSpinBox" name="spinBox">
|
||||
<property name="geometry">
|
||||
@ -279,19 +273,23 @@
|
||||
<property name="text">
|
||||
<string>Step information</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame_2">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Raised</enum>
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<widget class="QTextEdit" name="textEdit">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>250</x>
|
||||
<y>100</y>
|
||||
<width>391</width>
|
||||
<height>121</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
@ -302,7 +300,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>23</height>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
@ -344,6 +342,10 @@
|
||||
<addaction name="actionEditUndo"/>
|
||||
<addaction name="actionEditRedo"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionColor"/>
|
||||
<addaction name="actionBold"/>
|
||||
<addaction name="actionItalic"/>
|
||||
<addaction name="actionUnderline"/>
|
||||
</widget>
|
||||
<action name="actionOpen">
|
||||
<property name="text">
|
||||
@ -378,7 +380,7 @@
|
||||
<string>New File</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
<enum>QAction::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSaveFile">
|
||||
@ -390,7 +392,7 @@
|
||||
<string>Save</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
<enum>QAction::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSaveAsFile">
|
||||
@ -402,7 +404,7 @@
|
||||
<string>Save as</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
<enum>QAction::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionPrintFile">
|
||||
@ -414,7 +416,7 @@
|
||||
<string>Print</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
<enum>QAction::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionEditCopy">
|
||||
@ -426,7 +428,7 @@
|
||||
<string>Copy</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
<enum>QAction::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionEditPaste">
|
||||
@ -438,7 +440,7 @@
|
||||
<string>Paste</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
<enum>QAction::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionEditCut">
|
||||
@ -450,7 +452,7 @@
|
||||
<string>Cut</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
<enum>QAction::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionEditUndo">
|
||||
@ -462,7 +464,7 @@
|
||||
<string>Undo</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
<enum>QAction::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionEditRedo">
|
||||
@ -474,7 +476,7 @@
|
||||
<string>Redo</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
<enum>QAction::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionopenFile">
|
||||
@ -486,7 +488,43 @@
|
||||
<string>Open file</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
<enum>QAction::NoRole</enum>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionBold">
|
||||
<property name="icon">
|
||||
<iconset resource="data.qrc">
|
||||
<normaloff>:/data/images/data/images/bold.png</normaloff>:/data/images/data/images/bold.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Bold</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionItalic">
|
||||
<property name="icon">
|
||||
<iconset resource="data.qrc">
|
||||
<normaloff>:/data/images/data/images/italic.png</normaloff>:/data/images/data/images/italic.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Italic</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionUnderline">
|
||||
<property name="icon">
|
||||
<iconset resource="data.qrc">
|
||||
<normaloff>:/data/images/data/images/underline.png</normaloff>:/data/images/data/images/underline.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Underline</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionColor">
|
||||
<property name="icon">
|
||||
<iconset resource="data.qrc">
|
||||
<normaloff>:/data/images/data/images/font-color.png</normaloff>:/data/images/data/images/font-color.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Color</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user