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 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 #include <QApplication>
00029 #include <QtGui>
00030 #include <QString>
00031 #include "Optika_GUI.hpp"
00032 namespace Optika{
00033 
00034 void getInput(RCP<ParameterList> validParameters, RCP<DependencySheet> dependencySheet, void (*customFunc)(RCP<const ParameterList>)){  
00035   {
00036     using namespace Qt;
00037     int argNum=1;
00038     char* args[1];
00039     std::string appName ="Optika";
00040     args[0] = &appName[0];
00041     QApplication a(argNum,args);
00042     MetaWindow theWindow(validParameters, dependencySheet, customFunc);
00043     theWindow.show();
00044     a.exec();
00045   }
00046 }
00047 
00048 void getInput(
00049   const std::string& nameOfXmlFile,
00050   RCP<ParameterList>& userInput,
00051   void (*customFunc)(RCP<const ParameterList>))
00052 {
00053   {
00054     using namespace Qt;
00055     RCP<DependencySheet> depSheet = rcp(new DependencySheet());
00056     userInput = getParametersFromXmlFile(nameOfXmlFile, depSheet);
00057     int argNum=1;
00058     char* args[1];
00059     std::string appName ="Optika";
00060     args[0] = &appName[0];
00061     QApplication a(argNum,args);
00062     MetaWindow theWindow(userInput, depSheet, customFunc);
00063     theWindow.show();
00064     a.exec();
00065   }
00066 }
00067 
00068 OptikaGUI::OptikaGUI(
00069   RCP<ParameterList> validParameters,
00070   RCP<DependencySheet> dependencySheet,
00071   void (*customFunc)(RCP<const ParameterList>)):
00072   validParameters(validParameters),
00073   dependencySheet(dependencySheet),
00074   customFunc(customFunc)
00075   {}
00076 
00077 OptikaGUI::OptikaGUI(
00078   const std::string& xmlFileName,
00079   void (*customFunc)(RCP<const ParameterList>)):
00080   customFunc(customFunc)
00081 {
00082   dependencySheet = rcp(new DependencySheet);
00083   validParameters = getParametersFromXmlFile(xmlFileName, dependencySheet);
00084 }
00085 
00086 void OptikaGUI::exec(){
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     MetaWindow *theWindow;
00095     theWindow = new MetaWindow(validParameters, dependencySheet, customFunc);
00096     if(title != ""){
00097       theWindow->setWindowTitle(QString::fromStdString(title));
00098     }
00099     if(iconFilePath != ""){
00100       QIcon windowIcon(QString::fromStdString(iconFilePath));
00101       QApplication::setWindowIcon(windowIcon);
00102     }
00103     if(styleSheetFilePath != ""){
00104       QString str;
00105       QFile file(QString::fromStdString(styleSheetFilePath));
00106       if (file.open(QIODevice::ReadOnly | QIODevice::Text)){
00107         QTextStream in(&file);
00108         while (!in.atEnd()) {
00109           str += in.readLine();
00110         }
00111         a.setStyleSheet(str);
00112       }
00113     }
00114     if(aboutInfo != ""){
00115       theWindow->setAboutInfo(QString::fromStdString(aboutInfo));
00116     }
00117     theWindow->setActionButtonText(QString::fromStdString(actionButtonText));
00118     theWindow->show();
00119     theWindow->activateWindow();
00120     a.exec();
00121     delete theWindow;
00122   }
00123   
00124 }
00125 
00126 void OptikaGUI::setWindowTitle(const std::string& title){
00127   this->title = title;
00128 }
00129 
00130 void OptikaGUI::setWindowIcon(const std::string& filePath){
00131   this->iconFilePath = filePath;
00132 }
00133 
00134 void OptikaGUI::setStyleSheet(const std::string& filePath){
00135   this->styleSheetFilePath = filePath;
00136 } 
00137 
00138 void OptikaGUI::setCustomFunction(void (*customFunc)(RCP<const ParameterList>)){
00139   this->customFunc = customFunc;
00140 }
00141 
00142 void OptikaGUI::setAboutInfo(const std::string& aboutInfo){
00143   this->aboutInfo = aboutInfo;
00144 }
00145 
00146 void OptikaGUI::setActionButtonText(const std::string& text){
00147   actionButtonText = text;
00148 }
00149 
00150 std::string OptikaGUI::getWindowTitle(){
00151   return title;
00152 }
00153 
00154 std::string OptikaGUI::getWindowIcon(){
00155   return iconFilePath;
00156 }
00157 
00158 std::string OptikaGUI::getStyleSheet(){
00159   return styleSheetFilePath;
00160 }
00161 
00162 std::string  OptikaGUI::getAboutInfo(){
00163   return aboutInfo;
00164 }
00165 
00166 }
00167 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines