fix: 增加粘贴的右键菜单和适配设置的风格变更

Description: 增加粘贴的右键菜单和适配设置的风格变更

Log: 增加粘贴的右键菜单和适配设置的风格变更
Change-Id: Ibf3c9ba853bf5c8b33f630690d9902c95fd9eafe
This commit is contained in:
liuminghang 2021-06-25 15:25:42 +08:00
parent 203c55548f
commit 7a2b905bc6
3 changed files with 22 additions and 4 deletions

View File

@ -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);

View File

@ -1,6 +1,8 @@
#include "resulttextview.h"
#include <QDebug>
#include <QScroller>
#include <QClipboard>
#include <QApplication>
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());
}

View File

@ -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