fix: 增加粘贴的右键菜单和适配设置的风格变更
Description: 增加粘贴的右键菜单和适配设置的风格变更 Log: 增加粘贴的右键菜单和适配设置的风格变更 Change-Id: Ibf3c9ba853bf5c8b33f630690d9902c95fd9eafe
This commit is contained in:
parent
203c55548f
commit
7a2b905bc6
|
@ -199,6 +199,8 @@ void MainWidget::setupUi(QWidget *Widget)
|
||||||
void MainWidget::setupConnect()
|
void MainWidget::setupConnect()
|
||||||
{
|
{
|
||||||
initShortcut();
|
initShortcut();
|
||||||
|
//增加适配运行时的风格切换
|
||||||
|
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &MainWidget::setIcons);
|
||||||
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::paletteTypeChanged, this, &MainWidget::setIcons);
|
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::paletteTypeChanged, this, &MainWidget::setIcons);
|
||||||
connect(m_exportBtn, &DIconButton::clicked, this, &MainWidget::slotExport);
|
connect(m_exportBtn, &DIconButton::clicked, this, &MainWidget::slotExport);
|
||||||
connect(m_copyBtn, &DIconButton::clicked, this, &MainWidget::slotCopy);
|
connect(m_copyBtn, &DIconButton::clicked, this, &MainWidget::slotCopy);
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include "resulttextview.h"
|
#include "resulttextview.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QScroller>
|
#include <QScroller>
|
||||||
|
#include <QClipboard>
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
ResultTextView::ResultTextView(QWidget *parent)
|
ResultTextView::ResultTextView(QWidget *parent)
|
||||||
: m_Menu(nullptr), m_actCopy(nullptr), m_actCut(nullptr), m_actSelectAll(nullptr)
|
: 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_actCopy->setText(tr("Copy"));
|
||||||
m_actCut = new QAction(this);
|
m_actCut = new QAction(this);
|
||||||
m_actCut->setText(tr("Cut"));
|
m_actCut->setText(tr("Cut"));
|
||||||
|
m_actPaste = new QAction(this);
|
||||||
|
m_actPaste->setText(tr("Paste"));
|
||||||
m_actSelectAll = new QAction(this);
|
m_actSelectAll = new QAction(this);
|
||||||
m_actSelectAll->setText(tr("SelectAll"));
|
m_actSelectAll->setText(tr("SelectAll"));
|
||||||
|
|
||||||
m_Menu->addAction(m_actSelectAll);
|
m_Menu->addAction(m_actSelectAll);
|
||||||
m_Menu->addAction(m_actCopy);
|
m_Menu->addAction(m_actCopy);
|
||||||
|
m_Menu->addAction(m_actPaste);
|
||||||
m_Menu->addAction(m_actCut);
|
m_Menu->addAction(m_actCut);
|
||||||
|
|
||||||
connect(m_actSelectAll, &QAction::triggered, this, [ = ]() {
|
connect(m_actSelectAll, &QAction::triggered, this, [ = ]() {
|
||||||
|
@ -29,6 +34,9 @@ ResultTextView::ResultTextView(QWidget *parent)
|
||||||
connect(m_actCut, &QAction::triggered, this, [ = ]() {
|
connect(m_actCut, &QAction::triggered, this, [ = ]() {
|
||||||
emit this->cut();
|
emit this->cut();
|
||||||
});
|
});
|
||||||
|
connect(m_actPaste, &QAction::triggered, this, [ = ]() {
|
||||||
|
emit this->paste();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResultTextView::contextMenuEvent(QContextMenuEvent *e)
|
void ResultTextView::contextMenuEvent(QContextMenuEvent *e)
|
||||||
|
@ -43,6 +51,13 @@ void ResultTextView::contextMenuEvent(QContextMenuEvent *e)
|
||||||
m_actCopy->setEnabled(true);
|
m_actCopy->setEnabled(true);
|
||||||
m_actCut->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());
|
m_Menu->exec(QCursor::pos());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,10 +21,11 @@ protected:
|
||||||
signals:
|
signals:
|
||||||
void sigChangeSize();
|
void sigChangeSize();
|
||||||
private:
|
private:
|
||||||
QMenu *m_Menu;
|
QMenu *m_Menu{nullptr};
|
||||||
QAction *m_actCopy;
|
QAction *m_actCopy{nullptr};
|
||||||
QAction *m_actCut;
|
QAction *m_actCut{nullptr};
|
||||||
QAction *m_actSelectAll;
|
QAction *m_actPaste{nullptr};
|
||||||
|
QAction *m_actSelectAll{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RESULTTEXTVIEW_H
|
#endif // RESULTTEXTVIEW_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user