00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "SellArrow.h"
00023 #include "PrefDialog.h"
00024 #include <qpainter.h>
00025 #include <qsettings.h>
00026
00027 SellArrow::SellArrow ()
00028 {
00029 defaultColor.setNamedColor("red");
00030 helpFile = "sellarrow.html";
00031 identifierLabel = "Identifier";
00032 priceLabel = "Price";
00033 type = "SellArrow";
00034
00035 loadDefaults();
00036 }
00037
00038 SellArrow::~SellArrow ()
00039 {
00040 }
00041
00042 void SellArrow::draw (QPixmap &buffer, Scaler &scaler, int startIndex, int pixelspace, int startX)
00043 {
00044 QPainter painter;
00045 painter.begin(&buffer);
00046
00047 int x2 = data->getX(date);
00048 if (x2 == -1)
00049 return;
00050
00051 int x = startX + (x2 * pixelspace) - (startIndex * pixelspace);
00052 if (x == -1)
00053 return;
00054
00055 int y = scaler.convertToY(getValue());
00056
00057 arrow.putPoints(0, 7, x, y,
00058 x + 5, y - 5,
00059 x + 2, y - 5,
00060 x + 2, y - 11,
00061 x - 2, y - 11,
00062 x - 2, y - 5,
00063 x - 5, y - 5);
00064 painter.setBrush(getColor());
00065 painter.drawPolygon(arrow, TRUE, 0, -1);
00066
00067 clearSelectionArea();
00068 setSelectionArea(new QRegion(arrow));
00069
00070 if (getStatus() == COBase::Selected)
00071 {
00072 clearGrabHandles();
00073
00074 setGrabHandle(new QRegion(x - (HANDLE_WIDTH / 2),
00075 y + 1,
00076 HANDLE_WIDTH,
00077 HANDLE_WIDTH,
00078 QRegion::Rectangle));
00079
00080 painter.fillRect(x - (HANDLE_WIDTH / 2), y + 1, HANDLE_WIDTH, HANDLE_WIDTH, getColor());
00081 }
00082
00083 painter.end();
00084 }
00085
00086 void SellArrow::prefDialog ()
00087 {
00088 QString pl = tr("Details");
00089 QString cl = tr("Color");
00090 QString vl = tr("Value");
00091 QString il = tr("Identifier");
00092 QString bl = tr("Price");
00093 QString sd = tr("Set Default");
00094
00095 PrefDialog *dialog = new PrefDialog();
00096 dialog->setCaption(tr("Edit SellArrow"));
00097 dialog->createPage (pl);
00098 dialog->setHelpFile (helpFile);
00099 dialog->addColorPrefItem(cl, pl, color);
00100 dialog->addDoubleItem(vl, pl, getValue());
00101 dialog->addTextItem(il, pl, identifier);
00102 dialog->addTextItem(bl, pl, price);
00103 dialog->addCheckItem(sd, pl, FALSE);
00104
00105 int rc = dialog->exec();
00106
00107 if (rc == QDialog::Accepted)
00108 {
00109 dialog->getColor(cl, color);
00110 value = dialog->getDouble(vl);
00111 dialog->getText(il, identifier);
00112 dialog->getText(bl, price);
00113
00114 setSaveFlag(TRUE);
00115
00116 bool f = dialog->getCheck(sd);
00117 if (f)
00118 {
00119 defaultColor = color;
00120 saveDefaults();
00121 }
00122
00123 emit signalDraw();
00124 }
00125
00126 delete dialog;
00127 }
00128
00129 void SellArrow::newObject (QString &ind, QString &n)
00130 {
00131 indicator = ind;
00132 plot = ind;
00133 name = n;
00134 status = ClickWait;
00135 emit message(tr("Select point to place SellArrow..."));
00136 }
00137
00138 COBase::Status SellArrow::pointerClick (QPoint &point, QDateTime &x, double y)
00139 {
00140 switch (status)
00141 {
00142 case None:
00143 if (isSelected(point))
00144 {
00145 status = Selected;
00146 emit signalDraw();
00147 }
00148 break;
00149 case Selected:
00150 if (isGrabSelected(point))
00151 status = Moving;
00152 else
00153 {
00154 if (! isSelected(point))
00155 {
00156 status = None;
00157 emit signalDraw();
00158 }
00159 }
00160 break;
00161 case Moving:
00162 status = Selected;
00163 break;
00164 case ClickWait:
00165 setDate(x);
00166 setValue(y);
00167 setSaveFlag(TRUE);
00168 setColor(defaultColor);
00169 emit signalDraw();
00170 status = None;
00171 emit message("");
00172 emit signalSave(name);
00173 break;
00174 default:
00175 break;
00176 }
00177
00178 return status;
00179 }
00180
00181 void SellArrow::pointerMoving (QPixmap &, QPoint &, QDateTime &x, double y)
00182 {
00183 if (status != Moving)
00184 return;
00185
00186 setDate(x);
00187 setValue(y);
00188 setSaveFlag(TRUE);
00189 emit signalDraw();
00190 QString s = x.toString("yyyy-MM-dd hh:mm:ss") + " " + QString::number(y);
00191 emit message(s);
00192 }
00193
00194 void SellArrow::loadDefaults ()
00195 {
00196 QSettings settings;
00197
00198 QString s = "/Qtstalker/DefaultSellArrowColor";
00199 s = settings.readEntry(s);
00200 if (s.length())
00201 defaultColor.setNamedColor(s);
00202 }
00203
00204 void SellArrow::saveDefaults ()
00205 {
00206 QSettings settings;
00207
00208 QString s = "/Qtstalker/DefaultSellArrowColor";
00209 settings.writeEntry(s, defaultColor.name());
00210 }
00211
00212 void SellArrow::getSettings (Setting &set)
00213 {
00214 QString s = date.toString(dateFormat);
00215 set.setData(dateLabel, s);
00216 s = QString::number(value);
00217 set.setData(valueLabel, s);
00218 s = color.name();
00219 set.setData(colorLabel, s);
00220 set.setData(identifierLabel, identifier);
00221 set.setData(priceLabel, price);
00222 set.setData(plotLabel, plot);
00223 set.setData(nameLabel, name);
00224 set.setData(typeLabel, type);
00225 }
00226
00227 void SellArrow::setSettings (Setting &set)
00228 {
00229 QString s;
00230 set.getData(dateLabel, s);
00231 Bar bar;
00232 bar.setDate(s);
00233 bar.getDate(date);
00234 value = set.getDouble(valueLabel);
00235 set.getData(colorLabel, s);
00236 color.setNamedColor(s);
00237 set.getData(plotLabel, plot);
00238 set.getData(identifierLabel, identifier);
00239 set.getData(priceLabel, price);
00240 set.getData(nameLabel, name);
00241 }
00242
00243 void SellArrow::adjustForSplit (QDateTime &dt, double d)
00244 {
00245 if (date < dt)
00246 value = value * d;
00247 }
00248