Optika GUI Toolik Version of the Day
Optika_GUI.cpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //         Optika: A Tool For Developing Parameter Obtaining GUIs
00005 //                Copyright (2009) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, with Sandia Corporation, the 
00008 // U.S. Government retains certain rights in this software.
00009 // 
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 #include <QApplication>
00042 #include <QtGui>
00043 #include <QString>
00044 #include "Optika_GUI.hpp"
00045 namespace Optika{
00046 
00047 void getInput(RCP<ParameterList> validParameters, RCP<DependencySheet> dependencySheet, void (*customFunc)(RCP<const ParameterList>)){  
00048   {
00049     using namespace Qt;
00050     int argNum=1;
00051     char* args[1];
00052     std::string appName ="Optika";
00053     args[0] = &appName[0];
00054     QApplication a(argNum,args);
00055     MetaWindow theWindow(validParameters, dependencySheet, customFunc);
00056     theWindow.show();
00057     a.exec();
00058   }
00059 }
00060 
00061 void getInput(
00062   const std::string& nameOfXmlFile,
00063   RCP<ParameterList>& userInput,
00064   void (*customFunc)(RCP<const ParameterList>))
00065 {
00066   {
00067     using namespace Qt;
00068     RCP<DependencySheet> depSheet = rcp(new DependencySheet());
00069     userInput = getParametersFromXmlFile(nameOfXmlFile, depSheet);
00070     int argNum=1;
00071     char* args[1];
00072     std::string appName ="Optika";
00073     args[0] = &appName[0];
00074     QApplication a(argNum,args);
00075     MetaWindow theWindow(userInput, depSheet, customFunc);
00076     theWindow.show();
00077     a.exec();
00078   }
00079 }
00080 
00081 OptikaGUI::OptikaGUI(
00082   RCP<ParameterList> validParameters,
00083   RCP<DependencySheet> dependencySheet,
00084   void (*customFunc)(RCP<const ParameterList>)):
00085   validParameters(validParameters),
00086   dependencySheet(dependencySheet),
00087   customFunc(customFunc)
00088   {}
00089 
00090 OptikaGUI::OptikaGUI(
00091   const std::string& xmlFileName,
00092   void (*customFunc)(RCP<const ParameterList>)):
00093   customFunc(customFunc)
00094 {
00095   dependencySheet = rcp(new DependencySheet);
00096   validParameters = getParametersFromXmlFile(xmlFileName, dependencySheet);
00097 }
00098 
00099 void OptikaGUI::exec(){
00100   {
00101     using namespace Qt;
00102     int argNum=1;
00103     char* args[1];
00104     std::string appName ="Optika";
00105     args[0] = &appName[0];
00106     QApplication a(argNum,args);
00107     MetaWindow *theWindow;
00108     theWindow = new MetaWindow(validParameters, dependencySheet, customFunc);
00109     if(title != ""){
00110       theWindow->setWindowTitle(QString::fromStdString(title));
00111     }
00112     if(iconFilePath != ""){
00113       QIcon windowIcon(QString::fromStdString(iconFilePath));
00114       QApplication::setWindowIcon(windowIcon);
00115     }
00116     if(styleSheetFilePath != ""){
00117       QString str;
00118       QFile file(QString::fromStdString(styleSheetFilePath));
00119       if (file.open(QIODevice::ReadOnly | QIODevice::Text)){
00120         QTextStream in(&file);
00121         while (!in.atEnd()) {
00122           str += in.readLine();
00123         }
00124         a.setStyleSheet(str);
00125       }
00126     }
00127     if(aboutInfo != ""){
00128       theWindow->setAboutInfo(QString::fromStdString(aboutInfo));
00129     }
00130     theWindow->setActionButtonText(QString::fromStdString(actionButtonText));
00131     theWindow->show();
00132     theWindow->activateWindow();
00133     a.exec();
00134     delete theWindow;
00135   }
00136   
00137 }
00138 
00139 void OptikaGUI::setWindowTitle(const std::string& title){
00140   this->title = title;
00141 }
00142 
00143 void OptikaGUI::setWindowIcon(const std::string& filePath){
00144   this->iconFilePath = filePath;
00145 }
00146 
00147 void OptikaGUI::setStyleSheet(const std::string& filePath){
00148   this->styleSheetFilePath = filePath;
00149 } 
00150 
00151 void OptikaGUI::setCustomFunction(void (*customFunc)(RCP<const ParameterList>)){
00152   this->customFunc = customFunc;
00153 }
00154 
00155 void OptikaGUI::setAboutInfo(const std::string& aboutInfo){
00156   this->aboutInfo = aboutInfo;
00157 }
00158 
00159 void OptikaGUI::setActionButtonText(const std::string& text){
00160   actionButtonText = text;
00161 }
00162 
00163 std::string OptikaGUI::getWindowTitle(){
00164   return title;
00165 }
00166 
00167 std::string OptikaGUI::getWindowIcon(){
00168   return iconFilePath;
00169 }
00170 
00171 std::string OptikaGUI::getStyleSheet(){
00172   return styleSheetFilePath;
00173 }
00174 
00175 std::string  OptikaGUI::getAboutInfo(){
00176   return aboutInfo;
00177 }
00178 
00179 }
00180 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines