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