00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
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