Merge branch 'feature/editTool' into 'main'
Feature/edit tool See merge request p2406187/sae201!10
This commit is contained in:
commit
f8cac1aeff
@ -11,6 +11,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
, undoStack(new QUndoStack(this))
|
||||
, Clipboard(QGuiApplication::clipboard())
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
@ -170,3 +171,44 @@ void MainWindow::on_actionopenFile_triggered()
|
||||
{
|
||||
this->loadPath();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionEditCopy_triggered()
|
||||
{
|
||||
QWidget *focused = QApplication::focusWidget();
|
||||
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(focused);
|
||||
|
||||
if(lineEdit) {
|
||||
Clipboard->setText(lineEdit->selectedText());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_actionEditPaste_triggered()
|
||||
{
|
||||
QWidget *focused = QApplication::focusWidget();
|
||||
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(focused);
|
||||
|
||||
if(lineEdit) {
|
||||
QString text = lineEdit->text();
|
||||
int pos = lineEdit->cursorPosition();
|
||||
text.insert(pos, Clipboard->text());
|
||||
lineEdit->setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_actionEditCut_triggered()
|
||||
{
|
||||
QWidget *focused = QApplication::focusWidget();
|
||||
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(focused);
|
||||
|
||||
if(lineEdit) {
|
||||
QString text = lineEdit->text();
|
||||
QString selectedText = lineEdit->selectedText();
|
||||
int pos = lineEdit->selectionStart();
|
||||
text.remove(pos, selectedText.length());
|
||||
Clipboard->setText(selectedText);
|
||||
lineEdit->setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QUndoStack>
|
||||
#include <QClipboard>
|
||||
#include "path.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
@ -36,6 +37,12 @@ private slots:
|
||||
void on_actionopenFile_triggered();
|
||||
|
||||
|
||||
void on_actionEditCopy_triggered();
|
||||
|
||||
void on_actionEditPaste_triggered();
|
||||
|
||||
void on_actionEditCut_triggered();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
QString currentFile;
|
||||
@ -44,5 +51,6 @@ private:
|
||||
Path* currentPath;
|
||||
void loadImage(QString fileName);
|
||||
QUndoStack *undoStack;
|
||||
QClipboard* Clipboard;
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
||||
|
||||
@ -375,7 +375,7 @@
|
||||
<normaloff>:/data/images/data/images/new.png</normaloff>:/data/images/data/images/new.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>NewFile</string>
|
||||
<string>New File</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
@ -387,7 +387,7 @@
|
||||
<normaloff>:/data/images/data/images/save_as.png</normaloff>:/data/images/data/images/save_as.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>SaveFile</string>
|
||||
<string>Save</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
@ -399,7 +399,7 @@
|
||||
<normaloff>:/data/images/data/images/save.png</normaloff>:/data/images/data/images/save.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>SaveAsFile</string>
|
||||
<string>Save as</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
@ -411,7 +411,7 @@
|
||||
<normaloff>:/data/images/data/images/print.png</normaloff>:/data/images/data/images/print.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>PrintFile</string>
|
||||
<string>Print</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
@ -423,7 +423,7 @@
|
||||
<normaloff>:/data/images/data/images/copy.png</normaloff>:/data/images/data/images/copy.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>EditCopy</string>
|
||||
<string>Copy</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
@ -435,7 +435,7 @@
|
||||
<normaloff>:/data/images/data/images/paste.png</normaloff>:/data/images/data/images/paste.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>EditPaste</string>
|
||||
<string>Paste</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
@ -447,7 +447,7 @@
|
||||
<normaloff>:/data/images/data/images/cut.png</normaloff>:/data/images/data/images/cut.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>EditCut</string>
|
||||
<string>Cut</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
@ -459,7 +459,7 @@
|
||||
<normaloff>:/data/images/data/images/edit_undo.png</normaloff>:/data/images/data/images/edit_undo.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>EditUndo</string>
|
||||
<string>Undo</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
@ -471,7 +471,7 @@
|
||||
<normaloff>:/data/images/data/images/edit_redo.png</normaloff>:/data/images/data/images/edit_redo.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>EditRedo</string>
|
||||
<string>Redo</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
@ -483,7 +483,7 @@
|
||||
<normaloff>:/data/images/data/images/open.png</normaloff>:/data/images/data/images/open.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>openFile</string>
|
||||
<string>Open file</string>
|
||||
</property>
|
||||
<property name="menuRole">
|
||||
<enum>QAction::MenuRole::NoRole</enum>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user