00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 #include "ExtraToolbar.h"
00023 #include "PrefDialog.h"
00024 #include <qtooltip.h>
00025 #include <qstringlist.h>
00026 
00027 
00028 
00029 
00030 
00031 ExtraToolbar::ExtraToolbar (QMainWindow *mw) : QToolBar ("", mw, mw, TRUE, "extraToolbar")
00032 {
00033   
00034   recentCombo = new QComboBox(this);
00035   QToolTip::add(recentCombo, tr("Recent charts"));
00036 
00037 
00038 
00039   recentCombo->setFixedWidth(260);
00040 
00041   connect(recentCombo, SIGNAL(activated(int)), this, SLOT(slotRecentChartSelected(int)));
00042 
00043   QString s;
00044   rcfile.loadData(RcFile::RecentChartsList, s);
00045   QStringList sl = QStringList::split(",", s);
00046   if (sl.count() > 0)
00047   {
00048     for (int loop = 0; loop < (int) sl.count(); loop++)
00049       recentCombo->insertItem(sl[loop]);
00050   }
00051 
00052   bool b;
00053   rcfile.loadData(RcFile::ShowExtraToolbar, b);
00054   if (!b)
00055     hide();
00056 
00057 
00058 
00059 
00060 
00061 
00062 
00063 }
00064 
00065 ExtraToolbar::~ExtraToolbar ()
00066 {
00067 }
00068 
00069 void ExtraToolbar::saveSettings ()
00070 {
00071   QString s;
00072   for (int loop = 0; loop < recentCombo->count(); loop++)
00073   {
00074     s += recentCombo->text(loop) + ",";
00075   }
00076   s.remove(s.length()-1,1); 
00077   rcfile.saveData(RcFile::RecentChartsList, s);
00078 }
00079 
00080 void ExtraToolbar::slotSetButtonView ()
00081 {
00082   bool tb;
00083   
00084   rcfile.loadData(RcFile::ShowRecentCharts, tb);
00085   if (tb) recentCombo->show();
00086   else recentCombo->hide();
00087 }
00088 
00089 void ExtraToolbar::slotRecentChartSelected (int)
00090 {
00091   QString chartSelected = recentCombo->currentText();
00092   sortRecentCharts(chartSelected);
00093   QString s;
00094   rcfile.loadData(RcFile::Home, s);
00095   s += "/" + chartSelected;
00096 
00097   QString chartName = chartSelected.section( '/', -1 );
00098   QString chartPath = chartSelected;
00099   int i = chartPath.findRev("/" + chartName, -1, TRUE);
00100   chartPath.remove(i, chartName.length()+1);
00101 
00102   QString chartDir;
00103   rcfile.loadData(RcFile::Home, chartDir);
00104   chartDir += "/" + chartPath;
00105 
00106   emit recentTab(chartSelected);
00107   if (chartPath.startsWith("group/"))
00108     emit signalSetGroupNavItem(chartDir, chartName);
00109   else
00110     emit signalSetChartNavItem(chartDir, chartName);
00111 
00112   emit fileSelected(s);
00113 }
00114 
00115 void ExtraToolbar::slotAddRecentChart (QString selection)
00116 {
00117   QString s;
00118   rcfile.loadData(RcFile::Home, s);
00119   s += "/";
00120   selection.remove(s); 
00121   sortRecentCharts(selection);
00122   if (recentCombo->count() > 10)
00123     recentCombo->removeItem(10);
00124 }
00125 
00126 void ExtraToolbar::slotRemoveRecentCharts (QStringList l)
00127 {
00128   QString s, sl;
00129   rcfile.loadData(RcFile::Home, s);
00130   s += "/";
00131   for (int i = 0; i < (int) l.count(); i++)
00132   {
00133     sl = l[i];
00134     sl.remove(s);
00135     for (int j = 0; j < recentCombo->count(); j++)
00136     {
00137       if (!QString::compare(recentCombo->text(j), sl))
00138         recentCombo->removeItem(j);
00139     }
00140   }
00141 }
00142 
00143 void ExtraToolbar::sortRecentCharts (QString s)
00144 {
00145   
00146   for (int loop = 0; loop < recentCombo->count(); loop++)
00147   {
00148     if (!QString::compare(recentCombo->text(loop), s))
00149       recentCombo->removeItem(loop);
00150   }
00151   recentCombo->insertItem(s, 0);
00152   recentCombo->setCurrentItem(0);
00153 }