lib/COBase.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 "COBase.h"
00023 #include "../pics/delete.xpm"
00024 #include "../pics/edit.xpm"
00025 //#include "../pics/rename.xpm"
00026 #include "BuyArrow.h"
00027 #include "Cycle.h"
00028 #include "FiboLine.h"
00029 #include "HorizontalLine.h"
00030 #include "SellArrow.h"
00031 #include "Text.h"
00032 #include "TrendLine.h"
00033 #include "VerticalLine.h"
00034 #include <qcursor.h>
00035 
00036 COBase::COBase ()
00037 {
00038   data = 0;
00039   menu = new QPopupMenu();
00040   status = None;
00041   saveFlag = FALSE;
00042   grabHandles.setAutoDelete(TRUE);
00043   selectionArea.setAutoDelete(TRUE);
00044   date = QDateTime::currentDateTime();
00045 
00046   dateFormat = "yyyyMMddhhmmss";
00047   dateLabel = "Date";
00048   valueLabel = "Value";
00049   colorLabel = "Color";
00050   plotLabel = "Plot";
00051   nameLabel = "Name";
00052   typeLabel = "Type";
00053 
00054   menu->insertItem(QPixmap(edit), tr("&Edit Object"), this, SLOT(prefDialog()), CTRL+Key_E);
00055 //  menu->insertItem(QPixmap(renam), tr("&Move Object"), this, SLOT(moveObject()), CTRL+Key_M);
00056   menu->insertItem(QPixmap(deleteitem), tr("&Delete Object"), this, SLOT(removeObject()), CTRL+Key_D);
00057 }
00058 
00059 COBase::~COBase ()
00060 {
00061   delete menu;
00062 }
00063 
00064 void COBase::draw (QPixmap &, Scaler &, int, int, int)
00065 {
00066 }
00067 
00068 void COBase::prefDialog ()
00069 {
00070 }
00071 
00072 void COBase::showMenu ()
00073 {
00074   menu->exec(QCursor::pos());
00075 }
00076 
00077 void COBase::setData (BarData *d)
00078 {
00079   data = d;
00080 }
00081 
00082 void COBase::newObject (QString &, QString &)
00083 {
00084 }
00085 
00086 COBase::Status COBase::pointerClick (QPoint &, QDateTime &, double)
00087 {
00088   return COBase::None;
00089 }
00090 
00091 void COBase::pointerMoving (QPixmap &, QPoint &, QDateTime &, double)
00092 {
00093 }
00094 
00095 void COBase::keyEvent (QKeyEvent *key)
00096 {
00097   switch (key->key())
00098   {
00099     case Qt::Key_M:
00100       if (key->state() == Qt::ControlButton)
00101         moveObject();
00102       break;
00103     case Qt::Key_E:
00104       if (key->state() == Qt::ControlButton)
00105         prefDialog();
00106       break;
00107     case Qt::Key_D:
00108       if (key->state() == Qt::ControlButton)
00109         removeObject();
00110       break;
00111     default:
00112       key->ignore();
00113       break;
00114   }
00115 }
00116 
00117 void COBase::getSettings (Setting &)
00118 {
00119 }
00120 
00121 void COBase::setSettings (Setting &)
00122 {
00123 }
00124 
00125 double COBase::getHigh ()
00126 {
00127   return value;
00128 }
00129 
00130 double COBase::getLow ()
00131 {
00132   return value;
00133 }
00134 
00135 QString COBase::getHelpFile ()
00136 {
00137   return helpFile;
00138 }
00139 
00140 void COBase::setSaveFlag (bool d)
00141 {
00142   saveFlag = d;
00143 }
00144 
00145 bool COBase::getSaveFlag ()
00146 {
00147   return saveFlag;
00148 }
00149 
00150 void COBase::clearGrabHandles ()
00151 {
00152   grabHandles.clear();
00153 }
00154 
00155 void COBase::setGrabHandle (QRegion *d)
00156 {
00157   grabHandles.append(d);
00158 }
00159 
00160 void COBase::clearSelectionArea ()
00161 {
00162   selectionArea.clear();
00163 }
00164 
00165 void COBase::setSelectionArea (QRegion *d)
00166 {
00167   selectionArea.append(d);
00168 }
00169 
00170 QString COBase::getName ()
00171 {
00172   return name;
00173 }
00174 
00175 void COBase::setDate (QDateTime &d)
00176 {
00177   date = d;
00178 }
00179 
00180 void COBase::getDate (QDateTime &d)
00181 {
00182   d = date;
00183 }
00184 
00185 void COBase::setColor (QColor d)
00186 {
00187   color =d;
00188 }
00189 
00190 QColor COBase::getColor ()
00191 {
00192   return color;
00193 }
00194 
00195 void COBase::setValue (double d)
00196 {
00197   value = d;
00198 }
00199 
00200 double COBase::getValue ()
00201 {
00202   return value;
00203 }
00204 
00205 void COBase::setStatus (Status d)
00206 {
00207   status = d;
00208 }
00209 
00210 COBase::Status COBase::getStatus ()
00211 {
00212   return status;
00213 }
00214 
00215 bool COBase::isSelected (QPoint point)
00216 {
00217   int loop;
00218   for (loop = 0; loop < (int) selectionArea.count(); loop++)
00219   {
00220     QRegion *r = selectionArea.at(loop);
00221     if (r->contains(point))
00222       return TRUE;
00223   }
00224   
00225   return FALSE;
00226 }
00227 
00228 bool COBase::isGrabSelected (QPoint point)
00229 {
00230   int loop;
00231   for (loop = 0; loop < (int) grabHandles.count(); loop++)
00232   {
00233     QRegion *r = grabHandles.at(loop);
00234     if (r->contains(point))
00235       return TRUE;
00236   }
00237   
00238   return FALSE;
00239 }
00240 
00241 void COBase::removeObject ()
00242 {
00243   emit signalObjectDeleted(name);
00244 }
00245 
00246 void COBase::moveObject ()
00247 {
00248   status = Moving;
00249 }
00250 
00251 void COBase::addObject (Setting &set)
00252 {
00253   setSettings(set);
00254 }
00255 
00256 void COBase::adjustForSplit (QDateTime &, double)
00257 {
00258 }
00259 
00260 COBase * COBase::getCO (Setting &set)
00261 {
00262   QString s;
00263   set.getData(typeLabel, s);
00264   return getCO(s);
00265 }
00266 
00267 COBase * COBase::getCO (QString &s)
00268 {
00269   COBase *t = 0;
00270 
00271   if (! s.compare("BuyArrow"))
00272     t = new BuyArrow();
00273   else
00274   {
00275     if (! s.compare("Cycle"))
00276       t = new Cycle();
00277     else
00278     {
00279       if (! s.compare("FiboLine"))
00280         t = new FiboLine();
00281       else
00282       {
00283         if (! s.compare("HorizontalLine"))
00284           t = new HorizontalLine();
00285         else
00286         {
00287           if (! s.compare("SellArrow"))
00288             t = new SellArrow();
00289           else
00290           {
00291             if (! s.compare("Text"))
00292               t = new Text();
00293             else
00294             {
00295               if (! s.compare("TrendLine"))
00296                 t = new TrendLine();
00297               else
00298               {
00299                 if (! s.compare("VerticalLine"))
00300                   t = new VerticalLine();
00301               }
00302             }
00303           }
00304         }
00305       }
00306     }
00307   }
00308 
00309   return t;
00310 }
00311