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 void getInputExtraOptions(
00082   RCP<ParameterList> validParameters,
00083   RCP<DependencySheet> dependencySheet,
00084   std::string styleSheetFilePath,
00085   std::string iconFilePath,
00086   void (*customFunc)(RCP<const ParameterList>)){  
00087   {
00088     using namespace Qt;
00089     int argNum=1;
00090     char* args[1];
00091     std::string appName ="Optika";
00092     args[0] = &appName[0];
00093     QApplication a(argNum,args);
00094     std::string submitText = "Submit and save XML";
00095     std::string submitNoSaveText = "Submit";
00096     MetaWindow theWindow(validParameters, dependencySheet, customFunc, "", submitText, submitNoSaveText);
00097     if(iconFilePath != ""){
00098       QIcon windowIcon(QString::fromStdString(iconFilePath));
00099       a.setWindowIcon(windowIcon);
00100     }
00101     if(styleSheetFilePath != ""){
00102       QString str;
00103       QFile file(QString::fromStdString(styleSheetFilePath));
00104       if (file.open(QIODevice::ReadOnly | QIODevice::Text)){
00105         QTextStream in(&file);
00106         while (!in.atEnd()) {
00107           str += in.readLine();
00108         }
00109         a.setStyleSheet(str);
00110       }
00111     }
00112 
00113     theWindow.show();
00114     a.exec();
00115   }
00116 }
00117 
00118 void getInputExtraOptions(
00119   const std::string& nameOfXmlFile,
00120   RCP<ParameterList>& userInput,
00121   std::string styleSheetFilePath,
00122   std::string iconFilePath,
00123   void (*customFunc)(RCP<const ParameterList>))
00124 {
00125   {
00126     using namespace Qt;
00127     RCP<DependencySheet> depSheet = rcp(new DependencySheet());
00128     userInput = getParametersFromXmlFile(nameOfXmlFile, depSheet);
00129     int argNum=1;
00130     char* args[1];
00131     std::string appName ="Optika";
00132     args[0] = &appName[0];
00133     QApplication a(argNum,args);
00134     std::string submitText = "Submit and save XML";
00135     std::string submitNoSaveText = "Submit";
00136     MetaWindow theWindow(userInput, depSheet, customFunc, "", submitText, submitNoSaveText);
00137     if(iconFilePath != ""){
00138       QIcon windowIcon(QString::fromStdString(iconFilePath));
00139       a.setWindowIcon(windowIcon);
00140     }
00141     if(styleSheetFilePath != ""){
00142       QString str;
00143       QFile file(QString::fromStdString(styleSheetFilePath));
00144       if (file.open(QIODevice::ReadOnly | QIODevice::Text)){
00145         QTextStream in(&file);
00146         while (!in.atEnd()) {
00147           str += in.readLine();
00148         }
00149         a.setStyleSheet(str);
00150       }
00151     }
00152 
00153     theWindow.show();
00154     a.exec();
00155   }
00156 }
00157 
00158 
00159 OptikaGUI::OptikaGUI(
00160   RCP<ParameterList> validParameters,
00161   RCP<DependencySheet> dependencySheet,
00162   void (*customFunc)(RCP<const ParameterList>)):
00163   validParameters(validParameters),
00164   dependencySheet(dependencySheet),
00165   customFunc(customFunc)
00166   {}
00167 
00168 OptikaGUI::OptikaGUI(
00169   const std::string& xmlFileName,
00170   void (*customFunc)(RCP<const ParameterList>)):
00171   customFunc(customFunc)
00172 {
00173   dependencySheet = rcp(new DependencySheet);
00174   validParameters = getParametersFromXmlFile(xmlFileName, dependencySheet);
00175 }
00176 
00177 void OptikaGUI::exec(){
00178   {
00179     using namespace Qt;
00180     int argNum=1;
00181     char* args[1];
00182     std::string appName ="Optika";
00183     args[0] = &appName[0];
00184     QApplication a(argNum,args);
00185     MetaWindow *theWindow;
00186     theWindow = new MetaWindow(validParameters, dependencySheet, customFunc);
00187     if(title != ""){
00188       theWindow->setWindowTitle(QString::fromStdString(title));
00189     }
00190     if(iconFilePath != ""){
00191       QIcon windowIcon(QString::fromStdString(iconFilePath));
00192       QApplication::setWindowIcon(windowIcon);
00193     }
00194     if(styleSheetFilePath != ""){
00195       QString str;
00196       QFile file(QString::fromStdString(styleSheetFilePath));
00197       if (file.open(QIODevice::ReadOnly | QIODevice::Text)){
00198         QTextStream in(&file);
00199         while (!in.atEnd()) {
00200           str += in.readLine();
00201         }
00202         a.setStyleSheet(str);
00203       }
00204     }
00205     if(aboutInfo != ""){
00206       theWindow->setAboutInfo(QString::fromStdString(aboutInfo));
00207     }
00208     theWindow->setActionButtonText(QString::fromStdString(actionButtonText));
00209     theWindow->show();
00210     theWindow->activateWindow();
00211     a.exec();
00212     delete theWindow;
00213   }
00214   
00215 }
00216 
00217 void OptikaGUI::setWindowTitle(const std::string& title){
00218   this->title = title;
00219 }
00220 
00221 void OptikaGUI::setWindowIcon(const std::string& filePath){
00222   this->iconFilePath = filePath;
00223 }
00224 
00225 void OptikaGUI::setStyleSheet(const std::string& filePath){
00226   this->styleSheetFilePath = filePath;
00227 } 
00228 
00229 void OptikaGUI::setCustomFunction(void (*customFunc)(RCP<const ParameterList>)){
00230   this->customFunc = customFunc;
00231 }
00232 
00233 void OptikaGUI::setAboutInfo(const std::string& aboutInfo){
00234   this->aboutInfo = aboutInfo;
00235 }
00236 
00237 void OptikaGUI::setActionButtonText(const std::string& text){
00238   actionButtonText = text;
00239 }
00240 
00241 std::string OptikaGUI::getWindowTitle(){
00242   return title;
00243 }
00244 
00245 std::string OptikaGUI::getWindowIcon(){
00246   return iconFilePath;
00247 }
00248 
00249 std::string OptikaGUI::getStyleSheet(){
00250   return styleSheetFilePath;
00251 }
00252 
00253 std::string  OptikaGUI::getAboutInfo(){
00254   return aboutInfo;
00255 }
00256 
00257 }
00258 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines