00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "MainMenubar.h"
00023 #include <qaccel.h>
00024 #include "../pics/done.xpm"
00025 #include "../pics/grid.xpm"
00026 #include "../pics/datawindow.xpm"
00027 #include "../pics/indicator.xpm"
00028 #include "../pics/quotes.xpm"
00029 #include "../pics/configure.xpm"
00030 #include "../pics/scaletoscreen.xpm"
00031 #include "../pics/nav.xpm"
00032 #include "../pics/co.xpm"
00033 #include "../pics/help.xpm"
00034 #include "../pics/qtstalker.xpm"
00035 #include "../pics/crosshair.xpm"
00036 #include "../pics/papertrade.xpm"
00037 #include "RcFile.h"
00038
00039
00040 MainMenubar::MainMenubar (QMainWindow *mw) : QMenuBar (mw, "mainMenubar")
00041 {
00042 actions.setAutoDelete(FALSE);
00043
00044 RcFile rcfile;
00045
00046 QPixmap icon(finished);
00047 QAction *action = new QAction(this, "actionExit");
00048 action->setMenuText(tr("E&xit"));
00049 action->setIconSet(icon);
00050 action->setAccel(CTRL+Key_Q);
00051 action->setStatusTip(tr("Quit Qtstalker (Ctrl+Q)"));
00052 action->setToolTip(tr("Quit Qtstalker (Ctrl+Q)"));
00053 connect(action, SIGNAL(activated()), this, SIGNAL(signalExit()));
00054 actions.replace(Exit, action);
00055
00056 icon = indicator;
00057 action = new QAction(this, "actionNewIndicator");
00058 action->setMenuText(tr("New &Indicator"));
00059 action->setIconSet(icon);
00060 action->setStatusTip(tr("Add a new indicator to chart (Ctrl+2)"));
00061 action->setToolTip(tr("Add a new indicator to chart (Ctrl+2)"));
00062 connect(action, SIGNAL(activated()), this, SIGNAL(signalNewIndicator()));
00063 actions.replace(NewIndicator, action);
00064
00065 icon = configure;
00066 action = new QAction(this, "actionOptions");
00067 action->setMenuText(tr("Edit &Preferences"));
00068 action->setIconSet(icon);
00069 action->setStatusTip(tr("Modify user preferences (Ctrl+3)"));
00070 action->setToolTip(tr("Modify user preferences (Ctrl+3)"));
00071 connect(action, SIGNAL(activated()), mw, SLOT(slotOptions()));
00072 actions.replace(Options, action);
00073
00074 icon = gridicon;
00075 bool b;
00076 rcfile.loadData(RcFile::Grid, b);
00077 action = new QAction(this, "actionGrid");
00078 action->setMenuText(tr("Chart &Grid"));
00079 action->setIconSet(icon);
00080 action->setStatusTip(tr("Toggle the chart grid (Ctrl+4)"));
00081 action->setToolTip(tr("Toggle the chart grid (Ctrl+4)"));
00082 action->setToggleAction(TRUE);
00083 action->setOn(b);
00084 connect(action, SIGNAL(toggled(bool)), this, SIGNAL(signalGrid(bool)));
00085 actions.replace(Grid, action);
00086
00087 icon = quotes;
00088 action = new QAction(this, "actionQuote");
00089 action->setMenuText(tr("Load Quotes"));
00090 action->setIconSet(icon);
00091 action->setStatusTip(tr("Load Quotes (Ctrl+Y)"));
00092 action->setToolTip(tr("Load Quotes (Ctrl+Y)"));
00093 connect(action, SIGNAL(activated()), mw, SLOT(slotQuotes()));
00094 actions.replace(Quotes, action);
00095
00096 icon = datawindow;
00097 action = new QAction(this, "actionDataWindow");
00098 action->setMenuText(tr("&Data Window"));
00099 action->setIconSet(icon);
00100 action->setAccel(ALT+Key_1);
00101 action->setStatusTip(tr("Show the data window (Alt+1)"));
00102 action->setToolTip(tr("Show the data window (Alt+1)"));
00103 connect(action, SIGNAL(activated()), mw, SLOT(slotDataWindow()));
00104 actions.replace(DataWindow, action);
00105
00106 icon = qtstalker;
00107 action = new QAction(this, "actionAbout");
00108 action->setMenuText(tr("&About"));
00109 action->setIconSet(icon);
00110 action->setStatusTip(tr("About Qtstalker."));
00111 action->setToolTip(tr("About Qtstalker."));
00112 connect(action, SIGNAL(activated()), mw, SLOT(slotAbout()));
00113 actions.replace(About, action);
00114
00115 icon = scaletoscreen;
00116 rcfile.loadData(RcFile::ScaleToScreen, b);
00117 action = new QAction(this, "actionScale");
00118 action->setMenuText(tr("&Scale To Screen"));
00119 action->setIconSet(icon);
00120 action->setStatusTip(tr("Scale chart to current screen data (Ctrl+5)"));
00121 action->setToolTip(tr("Scale chart to current screen data (Ctrl+5)"));
00122 action->setToggleAction(TRUE);
00123 action->setOn(b);
00124 connect(action, SIGNAL(toggled(bool)), this, SIGNAL(signalScale(bool)));
00125 actions.replace(ScaleToScreen, action);
00126
00127 icon = nav;
00128 rcfile.loadData(RcFile::ShowSidePanel, b);
00129 action = new QAction(this, "actionPanel");
00130 action->setMenuText(tr("Side Pa&nel"));
00131 action->setIconSet(icon);
00132 action->setStatusTip(tr("Toggle the side panel area from view (Ctrl+7)"));
00133 action->setToolTip(tr("Toggle the side panel area from view (Ctrl+7)"));
00134 action->setToggleAction(TRUE);
00135 action->setOn(b);
00136 connect(action, SIGNAL(toggled(bool)), mw, SLOT(slotHideNav(bool)));
00137 actions.replace(SidePanel, action);
00138
00139 icon = co;
00140 rcfile.loadData(RcFile::DrawMode, b);
00141 action = new QAction(this, "actionDraw");
00142 action->setMenuText(tr("Toggle Dra&w Mode"));
00143 action->setIconSet(icon);
00144 action->setStatusTip(tr("Toggle drawing mode (Ctrl+0)"));
00145 action->setToolTip(tr("Toggle drawing mode (Ctrl+0)"));
00146 action->setToggleAction(TRUE);
00147 action->setOn(b);
00148 connect(action, SIGNAL(toggled(bool)), this, SIGNAL(signalDraw(bool)));
00149 actions.replace(DrawMode, action);
00150
00151 icon = crosshair;
00152 rcfile.loadData(RcFile::Crosshairs, b);
00153 action = new QAction(this, "actionCrosshairs");
00154 action->setMenuText(tr("Toggle Cross&hairs"));
00155 action->setIconSet(icon);
00156 action->setStatusTip(tr("Toggle crosshairs (Ctrl+6)"));
00157 action->setToolTip(tr("Toggle crosshairs (Ctrl+6)"));
00158 action->setToggleAction(TRUE);
00159 action->setOn(b);
00160 connect(action, SIGNAL(toggled(bool)), this, SIGNAL(signalCrosshairs(bool)));
00161 actions.replace(Crosshairs, action);
00162
00163 icon = papertrade;
00164 rcfile.loadData(RcFile::PaperTradeMode, b);
00165 action = new QAction(this, "actionPaperTrade");
00166 action->setMenuText(tr("Paper Trade Mode"));
00167 action->setIconSet(icon);
00168 action->setStatusTip(tr("Toggle the paper trade mode"));
00169 action->setToolTip(tr("Toggle the paper trade mode"));
00170 action->setToggleAction(TRUE);
00171 action->setOn(b);
00172 connect(action, SIGNAL(toggled(bool)), this, SIGNAL(signalPaperTrade(bool)));
00173 actions.replace(PaperTrade, action);
00174
00175 icon = help;
00176 action = new QAction(this, "actionHelp");
00177 action->setMenuText(tr("&Help"));
00178 action->setIconSet(icon);
00179 action->setAccel(ALT+Key_3);
00180 action->setStatusTip(tr("Display Help Dialog (Alt+3)"));
00181 action->setToolTip(tr("Display Help Dialog (Alt+3)"));
00182 connect(action, SIGNAL(activated()), mw, SLOT(slotHelp()));
00183 actions.replace(Help, action);
00184
00185 action = new QAction(this, "actionAdvancePaperTrade");
00186 action->setAccel(CTRL+Key_Right);
00187 connect(action, SIGNAL(activated()), this, SIGNAL(signalAdvancePaperTrade()));
00188 actions.replace(AdvancePaperTrade, action);
00189
00190 action = new QAction(this, "actionIndicatorSummary");
00191 action->setMenuText(tr("Indicator Summary"));
00192 action->setStatusTip(tr("Indicator Summary"));
00193 action->setToolTip(tr("Indicator Summary"));
00194 connect(action, SIGNAL(activated()), mw, SLOT(slotIndicatorSummary()));
00195 actions.replace(IndicatorSummary, action);
00196
00197 QAccel *a = new QAccel(mw);
00198 connect(a, SIGNAL(activated(int)), this, SLOT(slotAccel(int)));
00199 a->insertItem(CTRL+Key_2, NewIndicator);
00200 a->insertItem(CTRL+Key_3, Options);
00201 a->insertItem(CTRL+Key_4, Grid);
00202 a->insertItem(CTRL+Key_5, ScaleToScreen);
00203 a->insertItem(CTRL+Key_6, Crosshairs);
00204 a->insertItem(CTRL+Key_7, SidePanel);
00205 a->insertItem(CTRL+Key_0, DrawMode);
00206 a->insertItem(CTRL+Key_Y, Quotes);
00207 a->insertItem(CTRL+Key_Right, AdvancePaperTrade);
00208
00209 a->insertItem(CTRL+Key_Escape, 8);
00210
00211 createMenus();
00212
00213 rcfile.loadData(RcFile::ShowMenuBar, b);
00214 if (!b)
00215 hide();
00216 }
00217
00218 MainMenubar::~MainMenubar ()
00219 {
00220 }
00221
00222 void MainMenubar::createMenus ()
00223 {
00224 fileMenu = new QPopupMenu();
00225 actions[Exit]->addTo(fileMenu);
00226
00227 editMenu = new QPopupMenu();
00228 actions[NewIndicator]->addTo(editMenu);
00229 actions[Options]->addTo(editMenu);
00230
00231 viewMenu = new QPopupMenu();
00232 viewMenu->setCheckable(true);
00233 actions[Grid]->addTo(viewMenu);
00234 actions[ScaleToScreen]->addTo(viewMenu);
00235 actions[SidePanel]->addTo(viewMenu);
00236 actions[DrawMode]->addTo(viewMenu);
00237 actions[Crosshairs]->addTo(viewMenu);
00238 actions[PaperTrade]->addTo(viewMenu);
00239
00240 toolMenu = new QPopupMenu();
00241 actions[DataWindow]->addTo(toolMenu);
00242 actions[IndicatorSummary]->addTo(toolMenu);
00243 actions[Quotes]->addTo(toolMenu);
00244
00245 helpMenu = new QPopupMenu();
00246 actions[About]->addTo(helpMenu);
00247 actions[Help]->addTo(helpMenu);
00248
00249 insertItem(tr("&File"), fileMenu);
00250 insertItem(tr("&Edit"), editMenu);
00251 insertItem(tr("&View"), viewMenu);
00252 insertItem(tr("&Tools"), toolMenu);
00253 insertSeparator();
00254 insertItem(tr("&Help"), helpMenu);
00255 }
00256
00257 QAction * MainMenubar::getAction (int d)
00258 {
00259 return actions[d];
00260 }
00261
00262 bool MainMenubar::getStatus (int d)
00263 {
00264 return actions[d]->isOn();
00265 }
00266
00267 void MainMenubar::setStatus (int d, bool f)
00268 {
00269 actions[d]->setOn(f);
00270 }
00271
00272 void MainMenubar::saveSettings ()
00273 {
00274 RcFile rcfile;
00275 rcfile.saveData(RcFile::DrawMode, getStatus(DrawMode));
00276 rcfile.saveData(RcFile::ScaleToScreen, getStatus(ScaleToScreen));
00277 rcfile.saveData(RcFile::Grid, getStatus(Grid));
00278 rcfile.saveData(RcFile::Crosshairs, getStatus(Crosshairs));
00279 rcfile.saveData(RcFile::PaperTradeMode, getStatus(PaperTrade));
00280 rcfile.saveData(RcFile::ShowSidePanel, getStatus(SidePanel));
00281 }
00282
00283 void MainMenubar::slotAccel (int id)
00284 {
00285 switch (id)
00286 {
00287 case NewIndicator:
00288 emit signalNewIndicator();
00289 break;
00290 case Options:
00291 emit signalOptions();
00292 break;
00293 case Grid:
00294 getAction(Grid)->toggle();
00295 break;
00296 case Quotes:
00297 emit signalQuotes();
00298 break;
00299 case ScaleToScreen:
00300 getAction(ScaleToScreen)->toggle();
00301 break;
00302 case SidePanel:
00303 getAction(SidePanel)->toggle();
00304 break;
00305 case DrawMode:
00306 getAction(DrawMode)->toggle();
00307 break;
00308 case Crosshairs:
00309 getAction(Crosshairs)->toggle();
00310 break;
00311 case AdvancePaperTrade:
00312 emit signalAdvancePaperTrade();
00313 break;
00314 default:
00315 break;
00316 }
00317 }
00318
00319 void MainMenubar::doKeyPress (QKeyEvent *key)
00320 {
00321 key->accept();
00322
00323 if (key->state() == Qt::ControlButton)
00324 {
00325 switch (key->key())
00326 {
00327 case Qt::Key_2:
00328 slotAccel(NewIndicator);
00329 break;
00330 case Qt::Key_3:
00331 slotAccel(Options);
00332 break;
00333 case Qt::Key_4:
00334 slotAccel(Grid);
00335 break;
00336 case Qt::Key_5:
00337 slotAccel(ScaleToScreen);
00338 break;
00339 case Qt::Key_7:
00340 slotAccel(SidePanel);
00341 break;
00342 case Qt::Key_0:
00343 slotAccel(DrawMode);
00344 break;
00345 case Qt::Key_6:
00346 slotAccel(Crosshairs);
00347 break;
00348 case Qt::Key_Y:
00349 slotAccel(Quotes);
00350 break;
00351 case Qt::Key_Right:
00352 slotAccel(AdvancePaperTrade);
00353 break;
00354 default:
00355 break;
00356 }
00357 }
00358 }
00359