86 lines
2.0 KiB
C++
86 lines
2.0 KiB
C++
#include "TerminalPlugin.h"
|
|
#include <QVBoxLayout>
|
|
#include <QWidget>
|
|
#include <QApplication>
|
|
#include <QMenu>
|
|
#include <QAction>
|
|
|
|
QString TerminalPlugin::pname()
|
|
{
|
|
return "Terminal Plugin";
|
|
}
|
|
|
|
QString TerminalPlugin::pdesc()
|
|
{
|
|
return "Simple Terminal Plugin.";
|
|
}
|
|
|
|
QWidget* TerminalPlugin::pcontent()
|
|
{
|
|
QWidget *test = new QWidget();
|
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
|
|
|
chdir(path.toUtf8().constData());
|
|
console = new QTermWidget(test);
|
|
|
|
|
|
QFont font = QApplication::font();
|
|
font.setFamily("Monospace");
|
|
font.setPointSize(12);
|
|
console->setTerminalFont(font);
|
|
|
|
console->setScrollBarPosition(QTermWidget::ScrollBarRight);
|
|
console->setColorScheme("WhiteOnBlack");
|
|
|
|
console->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
connect(console, &QWidget::customContextMenuRequested, this, [=](const QPoint &pos) {
|
|
QMenu menu;
|
|
|
|
QAction *copyAct = new QAction(tr("Copy"), &menu);
|
|
QAction *pasteAct = new QAction(tr("Paste"), &menu);
|
|
|
|
if (console->selectedText().isEmpty()) {
|
|
copyAct->setEnabled(false);
|
|
}
|
|
|
|
connect(copyAct, &QAction::triggered, [=]() {
|
|
console->copyClipboard();
|
|
});
|
|
|
|
connect(pasteAct, &QAction::triggered, [=]() {
|
|
console->pasteClipboard();
|
|
});
|
|
|
|
menu.addAction(copyAct);
|
|
menu.addAction(pasteAct);
|
|
|
|
|
|
QPoint globalPos = console->mapToGlobal(pos);
|
|
menu.exec(globalPos);
|
|
});
|
|
|
|
|
|
test->setWindowTitle(tr("Terminal Plugin"));
|
|
test->resize(600, 400);
|
|
mainLayout->addWidget(console);
|
|
test->setLayout(mainLayout);
|
|
|
|
return test;
|
|
}
|
|
|
|
void TerminalPlugin::connectToHost(QObject* host)
|
|
{
|
|
connect(host, SIGNAL(currentPathChanged(QString)),
|
|
this, SLOT(onHostPathChanged(QString)));
|
|
}
|
|
|
|
void TerminalPlugin::onHostPathChanged(const QString &newpath)
|
|
{
|
|
path = newpath;
|
|
|
|
QMessageBox::about(pcontent(), tr("About Terminal"),
|
|
tr(newpath.toUtf8().constData()));
|
|
|
|
}
|