Experimenting with plugin and main app communication.
This commit is contained in:
@@ -332,3 +332,9 @@ void CalculatorPlugin::multiplicativeOperatorClicked()
|
|||||||
pendingMultiplicativeOperator = clickedOperator;
|
pendingMultiplicativeOperator = clickedOperator;
|
||||||
waitingForOperand = true;
|
waitingForOperand = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CalculatorPlugin::connectToHost(QObject* host)
|
||||||
|
{
|
||||||
|
Q_UNUSED(host);
|
||||||
|
// Calculator plugin doesn't need host signals
|
||||||
|
}
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ public:
|
|||||||
QString pname() override;
|
QString pname() override;
|
||||||
QString pdesc() override;
|
QString pdesc() override;
|
||||||
QWidget *pcontent() override;
|
QWidget *pcontent() override;
|
||||||
|
void connectToHost(QObject* host) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QLineEdit *display;
|
QLineEdit *display;
|
||||||
enum { NumDigitButtons = 10 };
|
enum { NumDigitButtons = 10 };
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ void FileExplorerPlugin::onDirSelected(const QModelIndex &index) {
|
|||||||
// Show contents of selected dir on the right
|
// Show contents of selected dir on the right
|
||||||
QModelIndex fileRoot = fileModel->setRootPath(path);
|
QModelIndex fileRoot = fileModel->setRootPath(path);
|
||||||
fileList->setRootIndex(fileRoot);
|
fileList->setRootIndex(fileRoot);
|
||||||
|
emit fileSelected(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------- Double-click / activate on file: open editor for text files ----------
|
// ---------- Double-click / activate on file: open editor for text files ----------
|
||||||
@@ -127,8 +128,9 @@ void FileExplorerPlugin::onFileActivated(const QModelIndex &index) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Try to open text files in simple editor; binary files will fail to load as text
|
// Try to open text files in simple editor; binary files will fail to load as text
|
||||||
editFile(path);
|
//editFile(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------- Context menu: right pane (files + folders) ----------
|
// ---------- Context menu: right pane (files + folders) ----------
|
||||||
@@ -391,3 +393,9 @@ void FileExplorerPlugin::editFile(const QString &path) {
|
|||||||
fileList->setRootIndex(fileModel->index(cur));
|
fileList->setRootIndex(fileModel->index(cur));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileExplorerPlugin::connectToHost(QObject* host)
|
||||||
|
{
|
||||||
|
Q_UNUSED(host);
|
||||||
|
// Calculator plugin doesn't need host signals
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ public:
|
|||||||
QString pname() override;
|
QString pname() override;
|
||||||
QString pdesc() override;
|
QString pdesc() override;
|
||||||
QWidget *pcontent() override;
|
QWidget *pcontent() override;
|
||||||
|
void connectToHost(QObject* host) override;
|
||||||
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onDirSelected(const QModelIndex &index);
|
void onDirSelected(const QModelIndex &index);
|
||||||
@@ -51,6 +53,9 @@ private:
|
|||||||
void editFile(const QString &path);
|
void editFile(const QString &path);
|
||||||
bool removePath(const QString &path);
|
bool removePath(const QString &path);
|
||||||
bool renamePath(const QString &oldPath, const QString &newName);
|
bool renamePath(const QString &oldPath, const QString &newName);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void fileSelected(const QString& path);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -267,3 +267,9 @@ void IrcClientPlugin::append(const QString &line)
|
|||||||
{
|
{
|
||||||
msgs->append(line);
|
msgs->append(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IrcClientPlugin::connectToHost(QObject* host)
|
||||||
|
{
|
||||||
|
Q_UNUSED(host);
|
||||||
|
// Calculator plugin doesn't need host signals
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ public:
|
|||||||
QString pname() override;
|
QString pname() override;
|
||||||
QString pdesc() override;
|
QString pdesc() override;
|
||||||
QWidget *pcontent() override;
|
QWidget *pcontent() override;
|
||||||
|
void connectToHost(QObject* host) override;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void append(const QString& line);
|
void append(const QString& line);
|
||||||
|
|||||||
@@ -155,3 +155,9 @@ void ScreenShotPlugin::updateceheck()
|
|||||||
hideThisWindowCheckBox->setDisabled(false);
|
hideThisWindowCheckBox->setDisabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScreenShotPlugin::connectToHost(QObject* host)
|
||||||
|
{
|
||||||
|
Q_UNUSED(host);
|
||||||
|
// Calculator plugin doesn't need host signals
|
||||||
|
}
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ public:
|
|||||||
QString pname() override;
|
QString pname() override;
|
||||||
QString pdesc() override;
|
QString pdesc() override;
|
||||||
QWidget *pcontent() override ;
|
QWidget *pcontent() override ;
|
||||||
|
void connectToHost(QObject* host) override;
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateceheck();
|
void updateceheck();
|
||||||
|
|||||||
@@ -20,8 +20,10 @@ QWidget* TerminalPlugin::pcontent()
|
|||||||
QWidget *test = new QWidget();
|
QWidget *test = new QWidget();
|
||||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||||
|
|
||||||
|
chdir(path.toUtf8().constData());
|
||||||
console = new QTermWidget(test);
|
console = new QTermWidget(test);
|
||||||
|
|
||||||
|
|
||||||
QFont font = QApplication::font();
|
QFont font = QApplication::font();
|
||||||
font.setFamily("Monospace");
|
font.setFamily("Monospace");
|
||||||
font.setPointSize(12);
|
font.setPointSize(12);
|
||||||
@@ -31,6 +33,7 @@ QWidget* TerminalPlugin::pcontent()
|
|||||||
console->setColorScheme("WhiteOnBlack");
|
console->setColorScheme("WhiteOnBlack");
|
||||||
|
|
||||||
console->setContextMenuPolicy(Qt::CustomContextMenu);
|
console->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
|
||||||
connect(console, &QWidget::customContextMenuRequested, this, [=](const QPoint &pos) {
|
connect(console, &QWidget::customContextMenuRequested, this, [=](const QPoint &pos) {
|
||||||
QMenu menu;
|
QMenu menu;
|
||||||
|
|
||||||
@@ -57,6 +60,7 @@ QWidget* TerminalPlugin::pcontent()
|
|||||||
menu.exec(globalPos);
|
menu.exec(globalPos);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
test->setWindowTitle(tr("Terminal Plugin"));
|
test->setWindowTitle(tr("Terminal Plugin"));
|
||||||
test->resize(600, 400);
|
test->resize(600, 400);
|
||||||
mainLayout->addWidget(console);
|
mainLayout->addWidget(console);
|
||||||
@@ -64,3 +68,18 @@ QWidget* TerminalPlugin::pcontent()
|
|||||||
|
|
||||||
return test;
|
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()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,12 +4,14 @@
|
|||||||
|
|
||||||
#include <../../src/interface.h>
|
#include <../../src/interface.h>
|
||||||
#include <qtermwidget6/qtermwidget.h>
|
#include <qtermwidget6/qtermwidget.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QtPlugin>
|
#include <QtPlugin>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
class TerminalPlugin : public QObject, public Interface
|
class TerminalPlugin : public QObject, public Interface
|
||||||
{
|
{
|
||||||
@@ -21,9 +23,15 @@ public:
|
|||||||
QString pname() override;
|
QString pname() override;
|
||||||
QString pdesc() override;
|
QString pdesc() override;
|
||||||
QWidget *pcontent() override;
|
QWidget *pcontent() override;
|
||||||
|
void connectToHost(QObject* host) override;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTermWidget *console;
|
QTermWidget *console;
|
||||||
|
QString path;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onHostPathChanged(const QString &newpath);
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -76,3 +76,9 @@ void WebBrowserPlugin::forwardpage()
|
|||||||
{
|
{
|
||||||
view->forward();
|
view->forward();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebBrowserPlugin::connectToHost(QObject* host)
|
||||||
|
{
|
||||||
|
Q_UNUSED(host);
|
||||||
|
// Calculator plugin doesn't need host signals
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ public:
|
|||||||
QString pname() override;
|
QString pname() override;
|
||||||
QString pdesc() override;
|
QString pdesc() override;
|
||||||
QWidget *pcontent() override;
|
QWidget *pcontent() override;
|
||||||
|
void connectToHost(QObject* host) override;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QGroupBox *horizontalGroupBox;
|
QGroupBox *horizontalGroupBox;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ void MainWindow::createActions()
|
|||||||
connect(exitAct, &QAction::triggered, this, &QWidget::close);
|
connect(exitAct, &QAction::triggered, this, &QWidget::close);
|
||||||
|
|
||||||
settingsAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::WeatherSnow),
|
settingsAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::WeatherSnow),
|
||||||
tr("&Settings"), this);
|
tr("&Settings"), this);
|
||||||
connect(settingsAct, &QAction::triggered, this, &MainWindow::settings);
|
connect(settingsAct, &QAction::triggered, this, &MainWindow::settings);
|
||||||
|
|
||||||
aboutAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::HelpAbout),
|
aboutAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::HelpAbout),
|
||||||
@@ -36,7 +36,7 @@ void MainWindow::createActions()
|
|||||||
connect(aboutAct, &QAction::triggered, this, &MainWindow::about);
|
connect(aboutAct, &QAction::triggered, this, &MainWindow::about);
|
||||||
|
|
||||||
aboutQtAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::HelpAbout),
|
aboutQtAct = new QAction(QIcon::fromTheme(QIcon::ThemeIcon::HelpAbout),
|
||||||
tr("About &Qt"), this);
|
tr("About &Qt"), this);
|
||||||
connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt);
|
connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,15 +63,18 @@ void MainWindow::about()
|
|||||||
|
|
||||||
void MainWindow::initSettings()
|
void MainWindow::initSettings()
|
||||||
{
|
{
|
||||||
QSettings settings("SOM", "SOM");
|
QSettings settings("som", "som");
|
||||||
|
|
||||||
if (!settings.contains("window/geometry")) {
|
if (!settings.contains("window/geometry")) {
|
||||||
this->resize(QSize(800, 600));
|
this->resize(QSize(800, 600));
|
||||||
this->move(this->screen()->geometry().center() - this->frameGeometry().center());
|
this->move(this->screen()->geometry().center() - this->frameGeometry().center());
|
||||||
settings.setValue("window/geometry", this->saveGeometry());
|
settings.setValue("window/geometry", this->saveGeometry());
|
||||||
|
projdir = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/som-projects";
|
||||||
|
settings.setValue("window/projdir", this->projdir);
|
||||||
settings.sync();
|
settings.sync();
|
||||||
}
|
}
|
||||||
this->restoreGeometry(settings.value("window/geometry").toByteArray());
|
this->restoreGeometry(settings.value("window/geometry").toByteArray());
|
||||||
|
this->projdir = settings.value("window/projdir").toString();
|
||||||
|
|
||||||
settings.beginGroup("Plugins");
|
settings.beginGroup("Plugins");
|
||||||
for (const QString &group : settings.childGroups()) {
|
for (const QString &group : settings.childGroups()) {
|
||||||
@@ -111,7 +114,7 @@ void MainWindow::initSettings()
|
|||||||
|
|
||||||
void MainWindow::saveSettings()
|
void MainWindow::saveSettings()
|
||||||
{
|
{
|
||||||
QSettings settings("SOM", "SOM");
|
QSettings settings("som", "som");
|
||||||
settings.setValue("window/geometry", this->saveGeometry());
|
settings.setValue("window/geometry", this->saveGeometry());
|
||||||
|
|
||||||
settings.beginGroup("Plugins");
|
settings.beginGroup("Plugins");
|
||||||
@@ -141,9 +144,41 @@ void MainWindow::settings()
|
|||||||
QWidget *settingsWin = new QWidget();
|
QWidget *settingsWin = new QWidget();
|
||||||
settingsWin->setWindowTitle("Settings");
|
settingsWin->setWindowTitle("Settings");
|
||||||
settingsWin->resize(300, 200);
|
settingsWin->resize(300, 200);
|
||||||
|
|
||||||
|
QVBoxLayout *layout = new QVBoxLayout(settingsWin);
|
||||||
|
|
||||||
|
QLabel *dirLabel = new QLabel(projdir, settingsWin);
|
||||||
|
layout->addWidget(dirLabel);
|
||||||
|
|
||||||
|
QPushButton *browseButton = new QPushButton("Browse...", settingsWin);
|
||||||
|
layout->addWidget(browseButton);
|
||||||
|
|
||||||
|
// Connect the button to open the directory dialog
|
||||||
|
connect(browseButton, &QPushButton::clicked, this,
|
||||||
|
[this, dirLabel, settingsWin]() {
|
||||||
|
|
||||||
|
QString selectedDir = QFileDialog::getExistingDirectory(
|
||||||
|
this,
|
||||||
|
tr("Select Directory"),
|
||||||
|
projdir,
|
||||||
|
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!selectedDir.isEmpty()) {
|
||||||
|
dirLabel->setText(selectedDir);
|
||||||
|
|
||||||
|
QSettings settings("som", "som");
|
||||||
|
settings.setValue("window/projdir", selectedDir);
|
||||||
|
|
||||||
|
settingsWin->close(); // Close the settings window
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
settingsWin->setLayout(layout);
|
||||||
settingsWin->show();
|
settingsWin->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::loadPlugins()
|
void MainWindow::loadPlugins()
|
||||||
{
|
{
|
||||||
#if DEV_BUILD
|
#if DEV_BUILD
|
||||||
@@ -160,6 +195,15 @@ void MainWindow::loadPlugins()
|
|||||||
QObject *plugin = loader.instance();
|
QObject *plugin = loader.instance();
|
||||||
if (plugin) {
|
if (plugin) {
|
||||||
|
|
||||||
|
auto iPlugin = qobject_cast<Interface*>(plugin);
|
||||||
|
if (iPlugin) {
|
||||||
|
|
||||||
|
iPlugin->connectToHost(this);
|
||||||
|
// *** NEW: connect plugin.signal → MainWindow.slot ***
|
||||||
|
connect(plugin, SIGNAL(fileSelected(QString)),
|
||||||
|
this, SLOT(fileSelected(QString)));
|
||||||
|
}
|
||||||
|
|
||||||
populateMenu(plugin);
|
populateMenu(plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -195,9 +239,16 @@ void MainWindow::populateMenu(QObject *plugin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::addToMenu(QObject *plugin, const QString &text,
|
void MainWindow::addToMenu(QObject *plugin, const QString &text,
|
||||||
QMenu *menu, Member member)
|
QMenu *menu, Member member)
|
||||||
{
|
{
|
||||||
auto action = new QAction(text, plugin);
|
auto action = new QAction(text, plugin);
|
||||||
connect(action, &QAction::triggered, this, member);
|
connect(action, &QAction::triggered, this, member);
|
||||||
menu->addAction(action);
|
menu->addAction(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::fileSelected(const QString &path)
|
||||||
|
{
|
||||||
|
emit currentPathChanged(path);
|
||||||
|
QMessageBox::about(this, tr("About SOM"),
|
||||||
|
tr(path.toUtf8().constData()));
|
||||||
|
}
|
||||||
|
|||||||
@@ -43,14 +43,22 @@ private:
|
|||||||
QAction *settingsAct;
|
QAction *settingsAct;
|
||||||
QDir pluginsDir;
|
QDir pluginsDir;
|
||||||
QMdiArea *mdi;
|
QMdiArea *mdi;
|
||||||
|
QString projdir;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void about();
|
void about();
|
||||||
void settings();
|
void settings();
|
||||||
void changePlugin();
|
void changePlugin();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void fileSelected(const QString& path);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *event) override;
|
void closeEvent(QCloseEvent *event) override;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void currentPathChanged(const QString& path);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|||||||
Reference in New Issue
Block a user