Skip to content

Commit

Permalink
Functions to show qt dialogs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Müller committed Dec 7, 2014
1 parent 81c45b3 commit ca410f7
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/SConscript
Expand Up @@ -155,6 +155,11 @@ libcampaignd_sources = Split("""
""")
libcampaignd = env.Library("campaignd", libcampaignd_sources, OBJPREFIX = "campaignd_")

libwesnoth_qt_sources = Split("""
qt/utils.cpp
""")
libwesnoth_qt = client_env.Library("wesnoth_qt", libwesnoth_qt_sources, CCFLAGS = ["-fPIC"])

libwesnoth_sdl_sources = Split("""
sdl/utils.cpp
sdl/alpha.cpp
Expand Down Expand Up @@ -630,7 +635,7 @@ for env in [test_env, client_env, env]:
env.AddMethod(WesnothProgram)

wesnoth_objects = ["wesnoth.cpp", libwesnoth_extras, libwesnoth_core, libwesnoth,
libwesnoth_sdl, libwesnoth_extras, env["wesnoth_res"]]
libwesnoth_sdl, libwesnoth_qt, libwesnoth_extras, env["wesnoth_res"]]
if env["host"] in ["x86_64-nacl", "i686-nacl"]:
wesnoth_objects += [SConscript("nacl/SConscript")]
client_env.WesnothProgram("wesnoth", wesnoth_objects, have_client_prereqs)
Expand Down
31 changes: 31 additions & 0 deletions src/qt/utils.cpp
@@ -0,0 +1,31 @@
#include "qt/utils.hpp"

#include <qt5/QtQuick/QQuickView>
// #include <qt5/QtCore/QObject>
#include <qt5/QtGui/QGuiApplication>
#include <qt5/QtQml/QQmlApplicationEngine>
// #include <qt5/QtCore/QList>
// #include <qt5/QtGui/QPixmap>
// #include <qt5/QtWidgets/QLabel>
#include <qt5/QtCore/QString>

namespace qt {

int show_application(const std::string& qml_file_path, int argc, char** argv) {

QGuiApplication app(argc, argv);
QQmlApplicationEngine engine(QString(qml_file_path.c_str()));

return app.exec();
}

void show_quick(const std::string& qml_file_path) {

QQuickView view;
view.setSource(QUrl::fromLocalFile(QString(qml_file_path.c_str())));
view.show();
}


} // End namespace qt

37 changes: 37 additions & 0 deletions src/qt/utils.hpp
@@ -0,0 +1,37 @@
/*
Copyright (C) 2014 - 2015 by Fabian Mueller <fabianmueller5@gmx.de>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/

#ifndef QT_UTILS_INCLUDED
#define QT_UTILS_INCLUDED

#include <string>

namespace qt {

/**
* Helper function to display QML Applications.
* @param qml_file_path containing the application definition.
* @return the exit status of the Qt application.
*/
int show_application(const std::string& qml_file_path, int argc = 0, char** argv = NULL);

/**
* Helper function to display QMLQuick dialogs.
* @param qml_file_path containing the gui element definition.
*/
void show_quick(const std::string& qml_file_path);

}

#endif

0 comments on commit ca410f7

Please sign in to comment.