Changeset 223
- Timestamp:
- 02/02/06 03:33:35 (3 years ago)
- Location:
- trunk/src/gui/bwgraph
- Files:
-
- 5 modified
-
bwgraph.cpp (modified) (13 diffs)
-
bwgraph.h (modified) (4 diffs)
-
bwgraph.ui (modified) (4 diffs)
-
graphframe.cpp (modified) (9 diffs)
-
graphframe.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gui/bwgraph/bwgraph.cpp
r216 r223 27 27 #define DATETIME_FMT "MMM dd hh:mm:ss:zzz" 28 28 29 /** Default constructor * */29 /** Default constructor */ 30 30 BandwidthGraph::BandwidthGraph(TorControl *torControl, QWidget *parent, Qt::WFlags f) 31 31 : QDialog(parent, f) 32 32 { 33 /* *Invoke Qt Designer generated QObject setup routine */33 /* Invoke Qt Designer generated QObject setup routine */ 34 34 ui.setupUi(this); 35 35 36 /* *Create Bandwidth Graph related QObjects */36 /* Create Bandwidth Graph related QObjects */ 37 37 _settings = new VidaliaSettings(); 38 _timer = new QTimer(this); 39 40 /** Bind events to actions */ 38 39 /* Bind events to actions */ 41 40 createActions(); 42 41 43 /* *Ask Tor to notify us about bandwidth updates */42 /* Ask Tor to notify us about bandwidth updates */ 44 43 _torControl = torControl; 45 44 _torControl->setEvent(TorEvents::Bandwidth, this, true); 46 47 /** Start the update timer **/ 48 _timer->start(REFRESH_RATE); 49 50 /** Initialize Sent/Receive data counters */ 45 46 /* Initialize Sent/Receive data counters */ 51 47 reset(); 52 53 /* *Hide Bandwidth Graph Settings frame */48 49 /* Hide Bandwidth Graph Settings frame */ 54 50 showSettingsFrame(false); 55 51 56 /* *Turn off opacity group on unsupported platforms */52 /* Turn off opacity group on unsupported platforms */ 57 53 #if defined(Q_WS_WIN) 58 54 if(!(QSysInfo::WV_2000 <= QSysInfo::WindowsVersion <= QSysInfo::WV_2003)) { … … 66 62 } 67 63 68 /** Default destructor * */64 /** Default destructor */ 69 65 BandwidthGraph::~BandwidthGraph() 70 66 { … … 72 68 delete _settings; 73 69 } 74 /* Unregister this object for bandwidth update events */75 _torControl->setEvent(TorEvents::Bandwidth, this, false);76 70 } 77 71 … … 79 73 Custom event handler. Checks if the event is a bandwidth update event. If it 80 74 is, it will add the data point to the history and updates the graph. 81 * */75 */ 82 76 void 83 77 BandwidthGraph::customEvent(QEvent *event) … … 91 85 /** 92 86 Binds events to actions 93 * */87 */ 94 88 void 95 89 BandwidthGraph::createActions() 96 90 { 97 // connect(_timer, SIGNAL(timeout()),98 // this, SLOT(updateGraph()));99 100 91 connect(ui.btnToggleSettings, SIGNAL(toggled(bool)), 101 92 this, SLOT(showSettingsFrame(bool))); … … 115 106 116 107 /** 117 Fetches new statistics and plots them on the graph 118 and adds them to the data counters 119 **/ 108 Adds new data to the graph and the counters 109 */ 120 110 void 121 111 BandwidthGraph::updateGraph(quint64 bytesRead, quint64 bytesWritten) 122 112 { 123 // add data points to graph 124 // add data value to counters 125 126 /* Obviously this isn't what you're going to do with the data, but this lets 127 * you see that it's working in the meantime. */ 128 ui.lblSent->setText(QString::number(bytesRead)); 129 ui.lblReceived->setText(QString::number(bytesWritten)); 113 /* Send the data in kilobits */ 114 ui.frmGraph->addPoints(bytesRead/1000.0, bytesWritten/1000.0); 115 ui.lblSent->setText(addDataToStr(bytesWritten, _totalSent)); 116 ui.lblReceived->setText(addDataToStr(bytesRead, _totalReceived)); 117 } 118 119 /** 120 Adds data to the total counters and returns a correctly 121 formatted string with the correct size suffix 122 */ 123 QString 124 BandwidthGraph::addDataToStr(quint64 data, quint64 &total) 125 { 126 total += data; 127 128 /* Determine the correct size suffix */ 129 if (total < 1000) { 130 /* Use bytes suffix */ 131 return tr("%1 bytes").arg(total, 0); 132 } else if (total < 1000000) { 133 /* Use KB suffix */ 134 return tr("%1 KB").arg(total/1000.0, 0, 'f', 2); 135 } else if (total < 1000000000) { 136 /* Use MB suffix */ 137 return tr("%1 MB").arg(total/1000000.0, 0, 'f', 2); 138 } else { 139 /* Use GB suffix */ 140 return tr("%1 MB").arg(total/1000000000.0, 0, 'f', 2); 141 } 130 142 } 131 143 132 144 /** 133 145 Loads the saved Bandwidth Graph settings 134 * */146 */ 135 147 void 136 148 BandwidthGraph::loadSettings() 137 149 { 138 /* * Set window opacity slider widget **/150 /* Set window opacity slider widget */ 139 151 ui.sldrOpacity->setValue(_settings->getBWGraphOpacity()); 140 152 141 /* * Set the line filter checkboxes accordingly **/153 /* Set the line filter checkboxes accordingly */ 142 154 uint filter = _settings->getBWGraphFilter(); 143 155 ui.chkReceiveRate->setChecked(filter & BWGRAPH_REC); 144 156 ui.chkSendRate->setChecked(filter & BWGRAPH_SEND); 145 157 146 /* * Set graph frame settings **/158 /* Set graph frame settings */ 147 159 ui.frmGraph->setShowCounters(ui.chkReceiveRate->isChecked(), 148 160 ui.chkSendRate->isChecked()); … … 151 163 /** 152 164 Resets the Sent/Received data counters and the log start time 153 * */165 */ 154 166 void 155 167 BandwidthGraph::reset() 156 168 { 157 /** Reset the data counter labels **/ 158 ui.lblSent->setText(tr("0.0 MB")); 159 ui.lblReceived->setText(tr("0.0 MB")); 160 161 /** Reset the log start timer **/ 169 /* Reset the data total counters */ 170 _totalSent = 0; 171 _totalReceived = 0; 172 173 /* Reset the data counter labels */ 174 ui.lblSent->setText(tr("0 bytes")); 175 ui.lblReceived->setText(tr("0 bytes")); 176 177 /* Reset the data counter clock */ 162 178 ui.lblStartTime->setText(QDateTime::currentDateTime().toString(DATETIME_FMT)); 163 179 164 /* * Reset the graph **/180 /* Reset the graph */ 165 181 ui.frmGraph->resetGraph(); 166 182 } … … 168 184 /** 169 185 Saves the Bandwidth Graph settings and adjusts the graph if necessary 170 * */186 */ 171 187 void 172 188 BandwidthGraph::saveChanges() 173 189 { 174 /* * Hide the settings frame and reset toggle button **/190 /* Hide the settings frame and reset toggle button */ 175 191 showSettingsFrame(false); 176 192 177 /* * Save the opacity **/193 /* Save the opacity */ 178 194 _settings->setBWGraphOpacity(ui.sldrOpacity->value()); 179 195 180 /* * Save the line filter values **/196 /* Save the line filter values */ 181 197 _settings->setBWGraphFilter(BWGRAPH_REC, ui.chkReceiveRate->isChecked()); 182 198 _settings->setBWGraphFilter(BWGRAPH_SEND, ui.chkSendRate->isChecked()); 183 199 184 /* * Update the graph frame settings **/200 /* Update the graph frame settings */ 185 201 ui.frmGraph->setShowCounters(ui.chkReceiveRate->isChecked(), 186 202 ui.chkSendRate->isChecked()); … … 189 205 /** 190 206 Simply restores the previously saved settings 191 * */207 */ 192 208 void 193 209 BandwidthGraph::cancelChanges() … … 202 218 /** 203 219 Toggles the Settings pane on and off, changes toggle button text 204 * */220 */ 205 221 void 206 222 BandwidthGraph::showSettingsFrame(bool show) … … 219 235 /** 220 236 Sets the opacity of the Bandwidth Graph window 221 * */237 */ 222 238 void 223 239 BandwidthGraph::setOpacity(int value) … … 225 241 qreal newValue = value / 100.0; 226 242 227 /* * Opacity only supported by Mac and Win32 **/243 /* Opacity only supported by Mac and Win32 */ 228 244 #if defined(Q_WS_MAC) 229 245 this->setWindowOpacity(newValue); … … 239 255 /** 240 256 Overloads the default show() slot so we can set opacity 241 * */257 */ 242 258 void 243 259 BandwidthGraph::show() -
trunk/src/gui/bwgraph/bwgraph.h
r216 r223 26 26 27 27 #include <QDateTime> 28 #include <QTimer>29 28 #include <QEvent> 30 29 … … 43 42 44 43 public: 45 /** Default constructor * */44 /** Default constructor */ 46 45 BandwidthGraph(TorControl *torControl, QWidget *parent = 0, Qt::WFlags f = 0); 47 /** Default destructor * */46 /** Default destructor */ 48 47 ~BandwidthGraph(); 49 48 … … 57 56 58 57 private slots: 59 /** Adds new data to the graph and counters * */58 /** Adds new data to the graph and counters */ 60 59 void updateGraph(quint64 bytesRead, quint64 bytesWritten); 61 60 /** Called when settings button is toggled */ … … 73 72 /** Create and bind actions to events **/ 74 73 void createActions(); 75 /** Loads the saved Bandwidth Graph settings * */74 /** Loads the saved Bandwidth Graph settings */ 76 75 void loadSettings(); 76 /** Adds the new data values to the total and returns a formatted string */ 77 QString addDataToStr(quint64 data, quint64 &total); 77 78 78 79 /** A TorControl object used to talk to Tor. */ 79 80 TorControl* _torControl; 80 /** A QTimer object that handles calling the draw function **/ 81 QTimer* _timer; 82 /** A VidaliaSettings object that handles getting/saving settings **/ 81 /** A VidaliaSettings object that handles getting/saving settings */ 83 82 VidaliaSettings* _settings; 83 /** Counters that keep track of the total data sent/received */ 84 quint64 _totalSent; 85 quint64 _totalReceived; 84 86 85 /** Qt Designer generated object * */87 /** Qt Designer generated object */ 86 88 Ui::BandwidthGraph ui; 87 89 }; -
trunk/src/gui/bwgraph/bwgraph.ui
r213 r223 9 9 <x>0</x> 10 10 <y>0</y> 11 <width>35 7</width>12 <height> 304</height>11 <width>359</width> 12 <height>282</height> 13 13 </rect> 14 14 </property> … … 404 404 </property> 405 405 <item> 406 <layout class="QHBoxLayout" > 407 <property name="margin" > 408 <number>0</number> 409 </property> 410 <property name="spacing" > 411 <number>6</number> 412 </property> 413 <item> 414 <layout class="QHBoxLayout" > 415 <property name="margin" > 416 <number>0</number> 417 </property> 418 <property name="spacing" > 419 <number>0</number> 420 </property> 421 <item> 422 <widget class="QLabel" name="label_3" > 423 <property name="maximumSize" > 424 <size> 425 <width>16777215</width> 426 <height>27</height> 427 </size> 428 </property> 429 <property name="font" > 430 <font> 431 <family>Arial</family> 432 <pointsize>10</pointsize> 433 <weight>50</weight> 434 <italic>false</italic> 435 <bold>false</bold> 436 <underline>false</underline> 437 <strikeout>false</strikeout> 438 </font> 439 </property> 440 <property name="contextMenuPolicy" > 441 <enum>Qt::NoContextMenu</enum> 442 </property> 443 <property name="text" > 444 <string><html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:Arial; font-size:8pt; font-weight:400; font-style:normal; text-decoration:none;"><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;">Sent:</p></body></html></string> 445 </property> 446 </widget> 447 </item> 448 <item> 449 <widget class="QLabel" name="lblSent" > 450 <property name="maximumSize" > 451 <size> 452 <width>16777215</width> 453 <height>27</height> 454 </size> 455 </property> 456 <property name="font" > 457 <font> 458 <family>Arial</family> 459 <pointsize>10</pointsize> 460 <weight>50</weight> 461 <italic>false</italic> 462 <bold>false</bold> 463 <underline>false</underline> 464 <strikeout>false</strikeout> 465 </font> 466 </property> 467 <property name="contextMenuPolicy" > 468 <enum>Qt::NoContextMenu</enum> 469 </property> 470 <property name="frameShape" > 471 <enum>QFrame::Panel</enum> 472 </property> 473 <property name="frameShadow" > 474 <enum>QFrame::Sunken</enum> 475 </property> 476 <property name="text" > 477 <string><html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:Arial; font-size:8pt; font-weight:400; font-style:normal; text-decoration:none;"><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;">679.07 MB</p></body></html></string> 478 </property> 479 <property name="scaledContents" > 480 <bool>false</bool> 481 </property> 482 </widget> 483 </item> 484 </layout> 485 </item> 486 <item> 487 <layout class="QHBoxLayout" > 488 <property name="margin" > 489 <number>0</number> 490 </property> 491 <property name="spacing" > 492 <number>0</number> 493 </property> 494 <item> 495 <widget class="QLabel" name="label_2" > 496 <property name="maximumSize" > 497 <size> 498 <width>16777215</width> 499 <height>27</height> 500 </size> 501 </property> 502 <property name="font" > 503 <font> 504 <family>Arial</family> 505 <pointsize>10</pointsize> 506 <weight>50</weight> 507 <italic>false</italic> 508 <bold>false</bold> 509 <underline>false</underline> 510 <strikeout>false</strikeout> 511 </font> 512 </property> 513 <property name="contextMenuPolicy" > 514 <enum>Qt::NoContextMenu</enum> 515 </property> 516 <property name="text" > 517 <string><html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:Arial; font-size:10pt; font-weight:400; font-style:normal; text-decoration:none;"><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Received:</p></body></html></string> 518 </property> 519 </widget> 520 </item> 521 <item> 522 <widget class="QLabel" name="lblReceived" > 523 <property name="maximumSize" > 524 <size> 525 <width>16777215</width> 526 <height>27</height> 527 </size> 528 </property> 529 <property name="font" > 530 <font> 531 <family>Arial</family> 532 <pointsize>10</pointsize> 533 <weight>50</weight> 534 <italic>false</italic> 535 <bold>false</bold> 536 <underline>false</underline> 537 <strikeout>false</strikeout> 538 </font> 539 </property> 540 <property name="contextMenuPolicy" > 541 <enum>Qt::NoContextMenu</enum> 542 </property> 543 <property name="toolTip" > 544 <string/> 545 </property> 546 <property name="frameShape" > 547 <enum>QFrame::Panel</enum> 548 </property> 549 <property name="frameShadow" > 550 <enum>QFrame::Sunken</enum> 551 </property> 552 <property name="text" > 553 <string><html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:Arial; font-size:10pt; font-weight:400; font-style:normal; text-decoration:none;"><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">435.38 MB</p></body></html></string> 554 </property> 555 <property name="scaledContents" > 556 <bool>false</bool> 557 </property> 558 </widget> 559 </item> 560 </layout> 561 </item> 562 </layout> 406 <widget class="QLabel" name="label_3" > 407 <property name="maximumSize" > 408 <size> 409 <width>16777215</width> 410 <height>27</height> 411 </size> 412 </property> 413 <property name="font" > 414 <font> 415 <family>Arial</family> 416 <pointsize>10</pointsize> 417 <weight>50</weight> 418 <italic>false</italic> 419 <bold>false</bold> 420 <underline>false</underline> 421 <strikeout>false</strikeout> 422 </font> 423 </property> 424 <property name="contextMenuPolicy" > 425 <enum>Qt::NoContextMenu</enum> 426 </property> 427 <property name="text" > 428 <string><html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:Arial; font-size:8pt; font-weight:400; font-style:normal; text-decoration:none;"><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;">Sent:</p></body></html></string> 429 </property> 430 </widget> 431 </item> 432 <item> 433 <widget class="QLabel" name="lblSent" > 434 <property name="maximumSize" > 435 <size> 436 <width>16777215</width> 437 <height>18</height> 438 </size> 439 </property> 440 <property name="font" > 441 <font> 442 <family>Arial</family> 443 <pointsize>10</pointsize> 444 <weight>50</weight> 445 <italic>false</italic> 446 <bold>false</bold> 447 <underline>false</underline> 448 <strikeout>false</strikeout> 449 </font> 450 </property> 451 <property name="contextMenuPolicy" > 452 <enum>Qt::NoContextMenu</enum> 453 </property> 454 <property name="frameShape" > 455 <enum>QFrame::Panel</enum> 456 </property> 457 <property name="frameShadow" > 458 <enum>QFrame::Sunken</enum> 459 </property> 460 <property name="text" > 461 <string><html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:Arial; font-size:8pt; font-weight:400; font-style:normal; text-decoration:none;"><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;">679.07 MB</p></body></html></string> 462 </property> 463 <property name="scaledContents" > 464 <bool>false</bool> 465 </property> 466 </widget> 467 </item> 468 <item> 469 <widget class="QLabel" name="label_2" > 470 <property name="maximumSize" > 471 <size> 472 <width>16777215</width> 473 <height>27</height> 474 </size> 475 </property> 476 <property name="font" > 477 <font> 478 <family>Arial</family> 479 <pointsize>10</pointsize> 480 <weight>50</weight> 481 <italic>false</italic> 482 <bold>false</bold> 483 <underline>false</underline> 484 <strikeout>false</strikeout> 485 </font> 486 </property> 487 <property name="contextMenuPolicy" > 488 <enum>Qt::NoContextMenu</enum> 489 </property> 490 <property name="text" > 491 <string><html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:Arial; font-size:10pt; font-weight:400; font-style:normal; text-decoration:none;"><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Received:</p></body></html></string> 492 </property> 493 </widget> 494 </item> 495 <item> 496 <widget class="QLabel" name="lblReceived" > 497 <property name="maximumSize" > 498 <size> 499 <width>16777215</width> 500 <height>18</height> 501 </size> 502 </property> 503 <property name="font" > 504 <font> 505 <family>Arial</family> 506 <pointsize>10</pointsize> 507 <weight>50</weight> 508 <italic>false</italic> 509 <bold>false</bold> 510 <underline>false</underline> 511 <strikeout>false</strikeout> 512 </font> 513 </property> 514 <property name="contextMenuPolicy" > 515 <enum>Qt::NoContextMenu</enum> 516 </property> 517 <property name="toolTip" > 518 <string/> 519 </property> 520 <property name="frameShape" > 521 <enum>QFrame::Panel</enum> 522 </property> 523 <property name="frameShadow" > 524 <enum>QFrame::Sunken</enum> 525 </property> 526 <property name="text" > 527 <string><html><head><meta name="qrichtext" content="1" /></head><body style=" white-space: pre-wrap; font-family:Arial; font-size:10pt; font-weight:400; font-style:normal; text-decoration:none;"><p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">435.38 MB</p></body></html></string> 528 </property> 529 <property name="scaledContents" > 530 <bool>false</bool> 531 </property> 532 </widget> 563 533 </item> 564 534 <item> … … 569 539 <property name="sizeHint" > 570 540 <size> 571 <width> 82</width>572 <height> 20</height>541 <width>54</width> 542 <height>31</height> 573 543 </size> 574 544 </property> … … 588 558 <font> 589 559 <family>Arial</family> 590 <pointsize> 8</pointsize>560 <pointsize>10</pointsize> 591 561 <weight>50</weight> 592 562 <italic>false</italic> -
trunk/src/gui/bwgraph/graphframe.cpp
r214 r223 29 29 { 30 30 /* Create Graph Frame related objects */ 31 _recvData = new QList<q uint64>();32 _sendData = new QList<q uint64>();31 _recvData = new QList<qreal>(); 32 _sendData = new QList<qreal>(); 33 33 34 34 /* Initialize graph values */ … … 60 60 QDesktopWidget *desktop = QApplication::desktop(); 61 61 int width = desktop->width(); 62 delete desktop;63 62 return width; 64 63 } … … 68 67 **/ 69 68 void 70 GraphFrame::addPoints(q uint64 send, quint64recv)69 GraphFrame::addPoints(qreal send, qreal recv) 71 70 { 72 71 /* If maximum number of points plotted, remove oldest */ … … 120 119 121 120 /* Fill in the background */ 122 painter->fillRect(this->frameRect(), QBrush(Qt:: white));121 painter->fillRect(this->frameRect(), QBrush(Qt::black)); 123 122 painter->drawRect(this->frameRect()); 124 123 … … 163 162 GraphFrame::paintRates(QPainter* painter) 164 163 { 164 int rateX = SCALE_WIDTH + FONT_SIZE
