lib/SymbolButton.cpp

Go to the documentation of this file.
00001 /*
00002  *  Qtstalker stock charter
00003  *
00004  *  Copyright (C) 2001-2007 Stefan S. Stratigakos
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00019  *  USA.
00020  */
00021 
00022 #include "SymbolButton.h"
00023 #include "SymbolDialog.h"
00024 #include "Config.h"
00025 #include <qfileinfo.h>
00026 
00027 SymbolButton::SymbolButton (QWidget *w, QString &d, QString &s) : QPushButton (w)
00028 {
00029   Config config;
00030   config.getData(Config::DataPath, baseDir);
00031   QObject::connect(this, SIGNAL(clicked()), this, SLOT(fileDialog()));
00032   setMaximumHeight(25);
00033   setToggleButton(FALSE);
00034   setSymbol(s);
00035   dirPath = d;
00036 }
00037 
00038 SymbolButton::~SymbolButton ()
00039 {
00040 }
00041 
00042 void SymbolButton::getSymbol (QString &d)
00043 {
00044   d = symbol;
00045 }
00046 
00047 void SymbolButton::getPath (QString &d)
00048 {
00049   d = path;
00050 }
00051 
00052 void SymbolButton::fileDialog ()
00053 {
00054   QString s("*");
00055   QString s2 = baseDir;
00056   if (path.length())
00057   {
00058     QFileInfo fi(path);
00059     s2 = fi.dirPath();
00060   }
00061   SymbolDialog *dialog = new SymbolDialog(this,
00062                                           baseDir,
00063                                           s2,
00064                                           s,
00065                                           QFileDialog::ExistingFiles);
00066   dialog->setCaption(tr("Select Symbol"));
00067 
00068   int rc = dialog->exec();
00069 
00070   if (rc == QDialog::Accepted)
00071   {
00072     QStringList l = dialog->selectedFiles();
00073     if (l.count())
00074     {
00075       setSymbol(l[0]);
00076       emit symbolChanged();
00077     }
00078   }
00079 
00080   delete dialog;
00081 }
00082 
00083 void SymbolButton::setSymbol (QString &d)
00084 {
00085   if (! d.length())
00086   {
00087     setText(d);
00088     path = d;
00089     return;
00090   }
00091   
00092   QStringList l = QStringList::split("/", d, FALSE);
00093   symbol = l[l.count() - 1];
00094   setText(symbol);
00095   path = d;
00096 }
00097 
00098 
00099