diff --git a/src/mainwidget.cpp b/src/mainwidget.cpp index a3d8d79..1869377 100644 --- a/src/mainwidget.cpp +++ b/src/mainwidget.cpp @@ -199,6 +199,8 @@ void MainWidget::setupUi(QWidget *Widget) void MainWidget::setupConnect() { initShortcut(); + //增加适配运行时的风格切换 + connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &MainWidget::setIcons); connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::paletteTypeChanged, this, &MainWidget::setIcons); connect(m_exportBtn, &DIconButton::clicked, this, &MainWidget::slotExport); connect(m_copyBtn, &DIconButton::clicked, this, &MainWidget::slotCopy); diff --git a/src/resulttextview.cpp b/src/resulttextview.cpp index 88908f0..ee2927c 100644 --- a/src/resulttextview.cpp +++ b/src/resulttextview.cpp @@ -1,6 +1,8 @@ #include "resulttextview.h" #include #include +#include +#include ResultTextView::ResultTextView(QWidget *parent) : m_Menu(nullptr), m_actCopy(nullptr), m_actCut(nullptr), m_actSelectAll(nullptr) @@ -13,11 +15,14 @@ ResultTextView::ResultTextView(QWidget *parent) m_actCopy->setText(tr("Copy")); m_actCut = new QAction(this); m_actCut->setText(tr("Cut")); + m_actPaste = new QAction(this); + m_actPaste->setText(tr("Paste")); m_actSelectAll = new QAction(this); m_actSelectAll->setText(tr("SelectAll")); m_Menu->addAction(m_actSelectAll); m_Menu->addAction(m_actCopy); + m_Menu->addAction(m_actPaste); m_Menu->addAction(m_actCut); connect(m_actSelectAll, &QAction::triggered, this, [ = ]() { @@ -29,6 +34,9 @@ ResultTextView::ResultTextView(QWidget *parent) connect(m_actCut, &QAction::triggered, this, [ = ]() { emit this->cut(); }); + connect(m_actPaste, &QAction::triggered, this, [ = ]() { + emit this->paste(); + }); } void ResultTextView::contextMenuEvent(QContextMenuEvent *e) @@ -43,6 +51,13 @@ void ResultTextView::contextMenuEvent(QContextMenuEvent *e) m_actCopy->setEnabled(true); m_actCut->setEnabled(true); } + //判断剪切板的状态 + QString clip_str = QApplication::clipboard()->text(); + if (clip_str.isEmpty()) { + m_actPaste->setEnabled(false); + } else { + m_actPaste->setEnabled(true); + } m_Menu->exec(QCursor::pos()); } diff --git a/src/resulttextview.h b/src/resulttextview.h index b0f78a4..073ac70 100644 --- a/src/resulttextview.h +++ b/src/resulttextview.h @@ -21,10 +21,11 @@ protected: signals: void sigChangeSize(); private: - QMenu *m_Menu; - QAction *m_actCopy; - QAction *m_actCut; - QAction *m_actSelectAll; + QMenu *m_Menu{nullptr}; + QAction *m_actCopy{nullptr}; + QAction *m_actCut{nullptr}; + QAction *m_actPaste{nullptr}; + QAction *m_actSelectAll{nullptr}; }; #endif // RESULTTEXTVIEW_H