lib/FileButton.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 "FileButton.h"
00023 #include <qfiledialog.h>
00024 #include <qfileinfo.h>
00025 
00026 FileButton::FileButton (QWidget *w, QStringList &l, QString &p) : QPushButton (w)
00027 {
00028   QObject::connect(this, SIGNAL(clicked()), this, SLOT(fileDialog()));
00029   setMaximumHeight(25);
00030   setToggleButton(FALSE);
00031   fileList = l;
00032   
00033   path = QDir::homeDirPath();
00034   if (p.length())
00035     path = p;
00036   
00037   updateButtonText();
00038 }
00039 
00040 FileButton::~FileButton ()
00041 {
00042 }
00043 
00044 void FileButton::getFile (QStringList &l)
00045 {
00046   l.clear();
00047   l = fileList;
00048 }
00049 
00050 void FileButton::setFile (QStringList &l)
00051 {
00052   fileList = l;
00053   updateButtonText();
00054 }
00055 
00056 void FileButton::fileDialog ()
00057 {
00058   if (fileList.count())
00059   {
00060     QFileInfo fi(fileList[0]);
00061     path = fi.dirPath(TRUE);
00062   }
00063   
00064   QStringList l = QFileDialog::getOpenFileNames("*", path, this, "file dialog");
00065   if (l.count())
00066     fileList = l;
00067   
00068   updateButtonText();
00069 }
00070 
00071 void FileButton::updateButtonText ()
00072 {
00073   QString s = QString::number(fileList.count());
00074   s.append(" ");
00075   s.append(tr("Files"));
00076   setText(s);
00077 }
00078