int main(int argc, char *argv[]) { QApplication app(argc, argv); QDeclarativeView view; QDeclarativeContext *context = view.rootContext(); context->setContextProperty("backgroundColor", QColor(Qt::yellow)); KDeclarative kdeclarative; kdeclarative.setDeclarativeEngine(view.engine()); kdeclarative.initialize(); //binds things like kconfig and icons kdeclarative.setupBindings(); //If all gone well, the QScriptEngine has been extracted QScriptEngine *scriptEngine = kdeclarative.scriptEngine(); Q_ASSERT(scriptEngine); //Bind a test QObject in the "QtScript way" QScriptValue global = scriptEngine->globalObject(); TestObject *testObject = new TestObject(); QScriptValue testValue = scriptEngine->newQObject(testObject); testValue.setScope(global); global.setProperty("testObject", testValue); view.setSource(QUrl::fromLocalFile("test.qml")); view.show(); return app.exec(); }
void KWin::DeclarativeScript::run() { if (running()) { return; } // add read config KDeclarative kdeclarative; kdeclarative.setDeclarativeEngine(m_engine); kdeclarative.initialize(); kdeclarative.setupBindings(); installScriptFunctions(kdeclarative.scriptEngine()); qmlRegisterType<DesktopThumbnailItem>("org.kde.kwin", 0, 1, "DesktopThumbnailItem"); qmlRegisterType<WindowThumbnailItem>("org.kde.kwin", 0, 1, "ThumbnailItem"); qmlRegisterType<KWin::ScriptingClientModel::ClientModel>(); qmlRegisterType<KWin::ScriptingClientModel::SimpleClientModel>("org.kde.kwin", 0, 1, "ClientModel"); qmlRegisterType<KWin::ScriptingClientModel::ClientModelByScreen>("org.kde.kwin", 0, 1, "ClientModelByScreen"); qmlRegisterType<KWin::ScriptingClientModel::ClientModelByScreenAndDesktop>("org.kde.kwin", 0, 1, "ClientModelByScreenAndDesktop"); qmlRegisterType<KWin::ScriptingClientModel::ClientFilterModel>("org.kde.kwin", 0, 1, "ClientFilterModel"); qmlRegisterType<KWin::Client>(); m_engine->rootContext()->setContextProperty("options", options); m_component->loadUrl(QUrl::fromLocalFile(scriptFile().fileName())); if (m_component->isLoading()) { connect(m_component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), SLOT(createComponent())); } else { createComponent(); } }
WelcomePageView::WelcomePageView(QWidget* parent) : QDeclarativeView(parent) { qRegisterMetaType<QObject*>("KDevelop::IProjectController*"); qRegisterMetaType<QObject*>("KDevelop::IPluginController*"); qRegisterMetaType<QObject*>("PatchReviewPlugin*"); qmlRegisterType<SessionsModel>("org.kdevelop.welcomepage", 4, 3, "SessionsModel"); QPalette p = palette(); p.setColor(QPalette::Active, QPalette::Text, QColor(Qt::black)); setPalette(p); //setup kdeclarative library KDeclarative kdeclarative; kdeclarative.setDeclarativeEngine(engine()); kdeclarative.initialize(); //binds things like kconfig and icons kdeclarative.setupBindings(); setResizeMode(QDeclarativeView::SizeRootObjectToView); UiHelper* helper = new UiHelper(this); rootContext()->setContextProperty("kdev", helper); rootContext()->setContextProperty("ICore", KDevelop::ICore::self()); areaChanged(ICore::self()->uiController()->activeArea()); setSource(QUrl("qrc:/main.qml")); if(!errors().isEmpty()) { kWarning() << "welcomepage errors:" << errors(); } areaChanged(Core::self()->uiControllerInternal()->activeSublimeWindow()->area()); connect(Core::self()->uiControllerInternal()->activeSublimeWindow(), SIGNAL(areaChanged(Sublime::Area*)), this, SLOT(areaChanged(Sublime::Area*))); }
void Application::setupDeclarativeBindings(QDeclarativeEngine* declarativeEngine) { KDeclarative kDeclarative; kDeclarative.setDeclarativeEngine(declarativeEngine); kDeclarative.initialize(); kDeclarative.setupBindings(); QScriptEngine* engine = kDeclarative.scriptEngine(); QScriptValue globalObject = engine->globalObject(); }
GreeterWindow::GreeterWindow(QWidget *parent) : QDeclarativeView(parent), m_greeter(new GreeterWrapper(this)) { setResizeMode(QDeclarativeView::SizeRootObjectToView); KDeclarative kdeclarative; kdeclarative.setDeclarativeEngine(engine()); kdeclarative.initialize(); //binds things like kconfig and icons kdeclarative.setupBindings(); KConfig config(LIGHTDM_CONFIG_DIR "/lightdm-kde-greeter.conf"); KConfigGroup configGroup = config.group("greeter"); QString theme = configGroup.readEntry("theme-name", "userbar"); QStringList dirs = KGlobal::dirs()->findDirs("appdata", "themes/"); Plasma::PackageStructure::Ptr packageStructure(new LightDMPackageStructure(this)); Plasma::Package package(dirs.last() + "/" + theme, packageStructure); if (!package.isValid()) { kError() << theme << " is not a valid theme. Falling back to \"userbar\" theme."; package = Plasma::Package(dirs.last() + "/" + "userbar", packageStructure); } if (!package.isValid()) { kFatal() << "Cannot find QML file for \"userbar\" theme. Something is wrong with this installation. Aborting."; } KGlobal::locale()->insertCatalog("lightdm_theme_" + theme); rootContext()->setContextProperty("config", new ConfigWrapper(package.filePath("configfile"), this)); rootContext()->setContextProperty("greeter", m_greeter); setSource(package.filePath("mainscript")); // Prevent screen flickering when the greeter starts up. This really needs to be sorted out in QML/Qt... setAttribute(Qt::WA_OpaquePaintEvent); setAttribute(Qt::WA_NoSystemBackground); // Shortcut to take a screenshot of the screen. Handy because it is not // possible to take a screenshot of the greeter in test mode without // including the cursor. QShortcut* cut = new QShortcut(this); cut->setKey(Qt::CTRL + Qt::ALT + Qt::Key_S); connect(cut, SIGNAL(activated()), SLOT(screenshot())); connect(m_greeter, SIGNAL(aboutToLogin()), SLOT(setRootImage())); QRect screen = QApplication::desktop()->rect(); setGeometry(screen); new PowerManagement(this); }
GtfsDatabaseTab::GtfsDatabaseTab( Project *project, QWidget *parent ) : AbstractTab(project, type(), parent), m_model(0), m_tabWidget(0), m_qmlView(0), m_tableChooser(0), m_tableView(0) { // Create a tab widget with tabs at the left, because it gets shown in a tab in timetablemate m_tabWidget = new KTabWidget( parent ); m_tabWidget->setTabPosition( QTabWidget::West ); m_tabWidget->setIconSize( QSize(24, 24) ); setWidget( m_tabWidget ); // Find the QML file used for the dashboard tab const QString fileName = KGlobal::dirs()->findResource( "data", "timetablemate/gtfs_dashboard.qml" ); if ( fileName.isEmpty() ) { kWarning() << "gtfs_dashboard.qml not found! Check installation"; return; } const QString svgFileName = KGlobal::dirs()->findResource( "data", "timetablemate/dashboard.svg" ); // Register classes in Qt's meta object system and for QML qRegisterMetaType< const ServiceProviderData* >( "const ServiceProviderData*" ); qRegisterMetaType< Project* >( "Project*" ); qmlRegisterType< ServiceProviderData, 1 >( "TimetableMate", 1, 0, "ServiceProviderData" ); qmlRegisterUncreatableType< Project >( "TimetableMate", 1, 0, "Project", "Cannot create new projects" ); qmlRegisterUncreatableType< Tabs >( "TimetableMate", 1, 0, "Tabs", "Only for enumerables" ); qmlRegisterUncreatableType< Enums >( "TimetableMate", 1, 0, "PublicTransport", "Only for enumerables" ); // Create dashboard widget QWidget *container = new QWidget( parent ); m_qmlView = new QDeclarativeView( container ); // Install a KDeclarative instance to allow eg. QIcon("icon"), i18n("translate") KDeclarative *kdeclarative = new KDeclarative(); kdeclarative->setDeclarativeEngine( m_qmlView->engine() ); kdeclarative->initialize(); kdeclarative->setupBindings(); m_qmlView->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); m_qmlView->setResizeMode( QDeclarativeView::SizeRootObjectToView ); // Expose the project itself to QML, // because the declarative engine runs in another thread, Project needs to be thread safe m_qmlView->rootContext()->setContextProperty( "project", project ); // Expose the name of the SVG to use m_qmlView->rootContext()->setContextProperty( "svgFileName", svgFileName ); // Add Plasma QML import paths const QStringList importPaths = KGlobal::dirs()->findDirs( "module", "imports" ); foreach( const QString &importPath, importPaths ) { m_qmlView->engine()->addImportPath( importPath ); }
WIView::WIView(QWidget *parent, ObsConditions *obs) : QWidget(parent), m_Obs(obs), m_CurCategorySelected(-1) { m_ModManager = new ModelManager(m_Obs); m_BaseView = new QDeclarativeView(); ///To use i18n() instead of qsTr() in qml/wiview.qml for translation KDeclarative kd; kd.setDeclarativeEngine(m_BaseView->engine()); kd.initialize(); kd.setupBindings(); m_Ctxt = m_BaseView->rootContext(); m_BaseView->setSource(KStandardDirs::locate("appdata","tools/whatsinteresting/qml/wiview.qml")); m_BaseObj = dynamic_cast<QObject *>(m_BaseView->rootObject()); //soTypeTextObj = m_BaseObj->findChild<QObject *>("soTypeTextObj"); m_ViewsRowObj = m_BaseObj->findChild<QObject *>("viewsRowObj"); connect(m_ViewsRowObj, SIGNAL(categorySelected(int)), this, SLOT(onCategorySelected(int))); m_SoListObj = m_BaseObj->findChild<QObject *>("soListObj"); connect(m_SoListObj, SIGNAL(soListItemClicked(int, QString, int)), this, SLOT(onSoListItemClicked(int, QString, int))); m_DetailsViewObj = m_BaseObj->findChild<QObject *>("detailsViewObj"); m_NextObj = m_BaseObj->findChild<QObject *>("nextObj"); connect(m_NextObj, SIGNAL(nextObjClicked()), this, SLOT(onNextObjClicked())); m_PrevObj = m_BaseObj->findChild<QObject *>("prevObj"); connect(m_PrevObj, SIGNAL(prevObjClicked()), this, SLOT(onPrevObjClicked())); m_SlewButtonObj = m_BaseObj->findChild<QObject *>("slewButtonObj"); connect(m_SlewButtonObj, SIGNAL(slewButtonClicked()), this, SLOT(onSlewButtonClicked())); m_DetailsButtonObj = m_BaseObj->findChild<QObject *>("detailsButtonObj"); connect(m_DetailsButtonObj, SIGNAL(detailsButtonClicked()), this, SLOT(onDetailsButtonClicked())); QObject *settingsIconObj = m_BaseObj->findChild<QObject *>("settingsIconObj"); connect(settingsIconObj, SIGNAL(settingsIconClicked()), this, SLOT(onSettingsIconClicked())); QObject *reloadIconObj = m_BaseObj->findChild<QObject *>("reloadIconObj"); connect(reloadIconObj, SIGNAL(reloadIconClicked()), this, SLOT(onReloadIconClicked())); m_BaseView->setResizeMode(QDeclarativeView::SizeRootObjectToView); m_BaseView->show(); }
WallpaperQml::WallpaperQml(QObject *parent, const QVariantList &args) : Plasma::Wallpaper(parent, args) , m_scene(new QGraphicsScene(this)) , m_item(0) , m_package(0) { m_engine = new QDeclarativeEngine(this); KDeclarative kdeclarative; kdeclarative.setDeclarativeEngine(m_engine); kdeclarative.initialize(); kdeclarative.setupBindings(); m_component = new QDeclarativeComponent(m_engine); connect(m_component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), SLOT(componentStatusChanged(QDeclarativeComponent::Status))); connect(this, SIGNAL(renderHintsChanged()), SLOT(resizeWallpaper())); connect(m_scene, SIGNAL(changed(QList<QRectF>)), SLOT(shouldRepaint(QList<QRectF>))); }