create a QObject wrapper around InteractiveConsole

this now allows the dialog to be used from QML without crashes. hooha!
wilder-5.14
Aaron Seigo 12 years ago
parent 1c7e0dbcde
commit 32f294d29f
  1. 3
      components/interactiveconsole/interactiveconsole.cpp
  2. 52
      components/interactiveconsole/interactiveconsole.h
  3. 2
      components/shellprivateplugin.cpp

@ -278,8 +278,8 @@ void InteractiveConsole::showEvent(QShowEvent *)
m_editor->setFocus();
}
emit visibilityChanged();
KWindowSystem::setOnDesktop(winId(), KWindowSystem::currentDesktop());
emit visibleChanged(true);
}
void InteractiveConsole::closeEvent(QCloseEvent *event)
@ -289,6 +289,7 @@ void InteractiveConsole::closeEvent(QCloseEvent *event)
m_closeWhenCompleted = true;
saveScript(QUrl::fromLocalFile(path));
QDialog::closeEvent(event);
emit visibleChanged(false);
}
void InteractiveConsole::reject()

@ -51,9 +51,6 @@ class ScriptEngine;
class InteractiveConsole : public QDialog
{
Q_OBJECT
Q_PROPERTY(QObject *scriptEngine READ scriptEngine WRITE setScriptInterface NOTIFY scriptEngineChanged)
Q_PROPERTY(QString mode READ mode WRITE setMode NOTIFY modeChanged)
Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibilityChanged)
public:
InteractiveConsole(QWidget *parent = 0);
@ -70,13 +67,12 @@ public:
void setScriptInterface(QObject *obj);
QObject *scriptEngine() const;
public Q_SLOTS:
void loadScript(const QString &path);
Q_SIGNALS:
void scriptEngineChanged();
void modeChanged();
void visibilityChanged();
void visibleChanged(bool);
protected:
void showEvent(QShowEvent *);
@ -127,5 +123,51 @@ private:
QPointer<QObject> m_scriptEngine;
};
class InteractiveConsoleItem : public QObject
{
Q_OBJECT
Q_PROPERTY(QObject *scriptEngine READ scriptEngine WRITE setScriptInterface NOTIFY scriptEngineChanged)
Q_PROPERTY(QString mode READ mode WRITE setMode NOTIFY modeChanged)
Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
public:
InteractiveConsoleItem()
: QObject(0),
m_dialog(new InteractiveConsole(0))
{
connect(m_dialog, &InteractiveConsole::scriptEngineChanged,
this, &InteractiveConsoleItem::scriptEngineChanged);
connect(m_dialog, &InteractiveConsole::modeChanged,
this, &InteractiveConsoleItem::modeChanged);
connect(m_dialog, &InteractiveConsole::visibleChanged,
this, &InteractiveConsoleItem::visibleChanged);
}
~InteractiveConsoleItem()
{
m_dialog->deleteLater();
}
void setMode(const QString &mode) { m_dialog->setMode(mode); }
QString mode() const { return m_dialog->mode(); }
void setScriptInterface(QObject *obj) { m_dialog->setScriptInterface(obj); }
QObject *scriptEngine() const { return m_dialog->scriptEngine(); }
void setVisible(bool visible) const { visible ? m_dialog->show() : m_dialog->hide(); }
bool isVisible() const { return m_dialog->isVisible(); }
public Q_SLOTS:
void loadScript(const QString &path) { m_dialog->loadScript(path); }
Q_SIGNALS:
void scriptEngineChanged();
void modeChanged();
void visibleChanged(bool);
private:
InteractiveConsole *m_dialog;
};
#endif

@ -34,5 +34,5 @@ void PlasmaShellPrivatePlugin::registerTypes(const char *uri)
qmlRegisterType<Plasma::Containment>();
qmlRegisterType<WidgetExplorer>(uri, 2, 0, "WidgetExplorer");
qmlRegisterType<InteractiveConsole>(uri, 2, 0, "InteractiveConsoleWindow");
qmlRegisterType<InteractiveConsoleItem>(uri, 2, 0, "InteractiveConsoleWindow");
}

Loading…
Cancel
Save