/*========================================================================= medInria Copyright (c) INRIA 2013. All rights reserved. See LICENSE.txt for details in the root of the sources or: https://github.com/medInria/medInria-public/blob/master/LICENSE.txt This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. =========================================================================*/ #include "medApplication.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class medApplicationPrivate { public: medMainWindow *mainWindow; QStringList systemOpenInstructions; QSplashScreen *splashScreen; }; // ///////////////////////////////////////////////////////////////// // medApplication // ///////////////////////////////////////////////////////////////// medApplication::medApplication(int & argc, char**argv) : QtSingleApplication(argc,argv), d(new medApplicationPrivate) { d->mainWindow = nullptr; d->splashScreen = new QSplashScreen(QPixmap(":/pixmaps/medInria-splash.png"), Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint); d->splashScreen->setAttribute(Qt::WA_DeleteOnClose, true); d->splashScreen->show(); this->processEvents(); this->setApplicationName("medInria"); this->setApplicationVersion(MEDINRIA_VERSION); this->setOrganizationName("inria"); this->setOrganizationDomain("fr"); this->setWindowIcon(QIcon(":/medInria.ico")); medLogger::initialize(); qInfo() << "####################################"; qInfo() << "Version: " << MEDINRIA_VERSION; qInfo() << "Build Date: " << MEDINRIA_BUILD_DATE; QApplication::setStyle(QStyleFactory::create("fusion")); medStyleSheetParser parser(dtkReadFile(":/medInria.qss")); this->setStyleSheet(parser.result()); this->initialize(); } medApplication::~medApplication(void) { delete d; d = nullptr; } bool medApplication::event(QEvent *event) { switch (event->type()) { // Handle file system open requests, but only if the main window has been created and set case QEvent::FileOpen: if (d->mainWindow) emit messageReceived(QString("/open ") + static_cast(event)->file()); else d->systemOpenInstructions.append(QString("/open ") + static_cast(event)->file()); return true; default: return QtSingleApplication::event(event); } } void medApplication::setMainWindow(medMainWindow *mw) { d->mainWindow = mw; QVariant var = QVariant::fromValue((QObject*)d->mainWindow); this->setProperty("MainWindow",var); d->systemOpenInstructions.clear(); // Wait until the app is displayed to close itself d->splashScreen->finish(d->mainWindow); } void medApplication::redirectMessageToSplash(const QString &message) { emit showMessage(message); } void medApplication::open(const medDataIndex & index) { d->mainWindow->open(index); } void medApplication::open(QString path) { d->mainWindow->open(path); } void medApplication::initialize() { qRegisterMetaType("medDataIndex"); // Registering different workspaces medWorkspaceFactory * viewerWSpaceFactory = medWorkspaceFactory::instance(); viewerWSpaceFactory->registerWorkspace(); viewerWSpaceFactory->registerWorkspace(); viewerWSpaceFactory->registerWorkspace(); //Register settingsWidgets medSettingsWidgetFactory* settingsWidgetFactory = medSettingsWidgetFactory::instance(); settingsWidgetFactory->registerSettingsWidget(); settingsWidgetFactory->registerSettingsWidget(); settingsWidgetFactory->registerSettingsWidget(); //Register annotations medAbstractDataFactory * datafactory = medAbstractDataFactory::instance(); datafactory->registerDataType(); // process layer: QString pluginsPath = getenv("MEDINRIA_PLUGINS_DIR"); QString defaultPath; QDir plugins_dir; #ifdef Q_OS_MAC plugins_dir = qApp->applicationDirPath() + "/../PlugIns"; #elif defined(Q_OS_WIN) plugins_dir = qApp->applicationDirPath() + "/plugins"; #else plugins_dir = qApp->applicationDirPath() + "/plugins"; #endif defaultPath = plugins_dir.absolutePath(); if ( !pluginsPath.isEmpty() ) medCore::pluginManager::initialize(pluginsPath); else medCore::pluginManager::initialize(defaultPath); }