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