Changeset 2980 for vidalia/trunk/src
- Timestamp:
- 08/17/08 00:14:25 (3 months ago)
- Location:
- vidalia/trunk/src/vidalia/bwgraph
- Files:
-
- 2 modified
-
graphframe.cpp (modified) (5 diffs)
-
graphframe.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vidalia/trunk/src/vidalia/bwgraph/graphframe.cpp
r2362 r2980 37 37 _showSend = true; 38 38 _maxValue = MIN_SCALE; 39 _scaleWidth = 0; 39 40 } 40 41 … … 181 182 for (int i = 0; i < list->size(); i++) { 182 183 currValue = y - (list->at(i) * scale); 183 if (x - SCROLL_STEP < SCALE_WIDTH) {184 points << QPointF( SCALE_WIDTH, currValue);184 if (x - SCROLL_STEP < _scaleWidth) { 185 points << QPointF(_scaleWidth, currValue); 185 186 break; 186 187 } … … 188 189 x -= SCROLL_STEP; 189 190 } 190 points << QPointF( SCALE_WIDTH, y);191 points << QPointF(_scaleWidth, y); 191 192 return points; 192 193 } … … 222 223 GraphFrame::paintTotals() 223 224 { 224 int x = SCALE_WIDTH+ FONT_SIZE, y = 0;225 int x = _scaleWidth + FONT_SIZE, y = 0; 225 226 int rowHeight = FONT_SIZE; 226 227 … … 266 267 } 267 268 269 /** Returns the width in pixels of <b>label</b> using the current painter's 270 * font. */ 271 int 272 GraphFrame::labelWidth(const QString &label) 273 { 274 int width = 0; 275 QFontMetrics fm = fontMetrics(); 276 277 for (int i = 0; i < label.length(); i++) 278 width += fm.charWidth(label, i); 279 return width; 280 } 281 268 282 /** Paints the scale on the graph. */ 269 283 void 270 284 GraphFrame::paintScale() 271 285 { 272 qreal markStep = _maxValue * .25; 286 QString label[4]; 287 int width[4]; 273 288 int top = _rec.y(); 274 289 int bottom = _rec.height(); 275 qreal paintStep = (bottom - (bottom/10)) / 4; 276 277 /* Draw the other marks in their correctly scaled locations */ 278 qreal scale; 290 int scaleWidth = 0; 279 291 qreal pos; 280 for (int i = 1; i < 5; i++) { 281 pos = bottom - (i * paintStep); 282 scale = i * markStep; 292 qreal markStep = _maxValue * .25; 293 qreal paintStep = (bottom - (bottom/8)) / 4; 294 295 /* Compute each of the y-axis labels */ 296 for (int i = 0; i < 4; i++) { 297 pos = bottom - ((i+1) * paintStep); 298 label[i] = tr("%1 KB/s").arg(markStep*(i+1), 0, 'f', 2); 299 width[i] = labelWidth(label[i]); 300 scaleWidth = qMax(scaleWidth, 2+width[i]); 301 } 302 303 /* Include a 5px margin between the y-axis and its labels */ 304 _scaleWidth = scaleWidth + 5; 305 306 /* Draw the y-axis labels and horizontal marks in their correctly scaled 307 * locations */ 308 for (int i = 0; i < 4; i++) { 309 pos = bottom - ((i+1) * paintStep); 283 310 _painter->setPen(SCALE_COLOR); 284 _painter->drawText(QPoint F(5, pos+FONT_SIZE),285 tr("%1 KB/s").arg(scale, 0, 'f', 2)); 311 _painter->drawText(QPoint(_scaleWidth-width[i]-5, pos), label[i]); 312 286 313 _painter->setPen(GRID_COLOR); 287 _painter->drawLine(QPointF( SCALE_WIDTH, pos),314 _painter->drawLine(QPointF(_scaleWidth, pos), 288 315 QPointF(_rec.width(), pos)); 289 316 } 290 291 /* Draw vertical separator*/292 _painter->drawLine( SCALE_WIDTH, top, SCALE_WIDTH, bottom);293 } 294 317 318 /* Draw the y-axis */ 319 _painter->drawLine(_scaleWidth, top, _scaleWidth, bottom); 320 } 321 -
vidalia/trunk/src/vidalia/bwgraph/graphframe.h
r2362 r2980 26 26 27 27 #define HOR_SPC 2 /** Space between data points */ 28 #define SCALE_WIDTH 75 /** Width of the scale */ 29 #define MIN_SCALE 10 /** 10 kB/s is the minimum scale */ 28 #define MIN_SCALE 10 /** 10 kB/s is the minimum scale */ 30 29 #define SCROLL_STEP 4 /** Horizontal change on graph update */ 31 30 … … 69 68 70 69 private: 70 /** Returns the width in pixels of <b>label</b> using the current painter's 71 * font. */ 72 int labelWidth(const QString &label); 71 73 /** Gets the width of the desktop, the max # of points. */ 72 74 int getNumPoints(); 73 74 75 /** Paints an integral and an outline of that integral for each data set 75 76 * (send and/or receive) that is to be displayed. */ … … 110 111 bool _showRecv; 111 112 bool _showSend; 113 /** Width (in pixels) of the scale marker area on the left side of the 114 * graph. */ 115 int _scaleWidth; 112 116 }; 113 117
