Commit 24e8f9ea authored by Matthias Möller's avatar Matthias Möller

use custom progressbars for memory alloc.

- disables the progressbar animation under windows
- use colors indicating free memory space

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@17990 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 1e53c361
......@@ -111,12 +111,12 @@ void MemInfoPlugin::pluginsInitialized() {
// emit log(LOGINFO,"Main Memory monitoring supported, installing main memory monitor into status bar");
mainMemBar_= new QProgressBar();
mainMemBar_->setFixedWidth(260);
mainMemBar_->setFormat( "Mem %p% %v/%m MB" );
emit addWidgetToStatusbar(mainMemBar_);
connect(updateTimer_,SIGNAL(timeout()),this,SLOT(cpuMemoryInfoUpdate()));
mainMemBar_->setFixedWidth(260);
mainMemBar_->setFormat( "Mem %p% %v/%m MB" );
emit addWidgetToStatusbar(mainMemBar_);
connect(updateTimer_,SIGNAL(timeout()),this,SLOT(cpuMemoryInfoUpdate()));
updateTimer_->start(4000);
......@@ -148,12 +148,13 @@ void MemInfoPlugin::nvidiaMemoryInfoUpdate() {
// get currently available memory on gpu
GLint cur_avail_mem_kb = 0;
glGetIntegerv(GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &cur_avail_mem_kb);
gpuMemBar_->setRange( 0 , total_mem_kb/1024 );
gpuMemBar_->setValue( (total_mem_kb-cur_avail_mem_kb)/1024);
}
}
gpuMemBar_->setRange( 0 , total_mem_kb/1024 );
gpuMemBar_->setValue( (total_mem_kb-cur_avail_mem_kb)/1024);
setProgressBarStyleSheet(gpuMemBar_);
}
}
void MemInfoPlugin::cpuMemoryInfoUpdate() {
if (mainMemBar_) {
......@@ -188,12 +189,31 @@ void MemInfoPlugin::cpuMemoryInfoUpdate() {
freeRamMB = sys_info.freeram / 1024 / 1024 * sys_info.mem_unit;
bufferRamMB = sys_info.bufferram / 1024 / 1024 * sys_info.mem_unit; // Buffers get freed, if we don't have enough free ram
#endif
mainMemBar_->setRange( 0 , totalRamMB );
mainMemBar_->setValue( totalRamMB-freeRamMB-bufferRamMB);
setProgressBarStyleSheet(mainMemBar_);
}
}
mainMemBar_->setRange( 0 , totalRamMB );
mainMemBar_->setValue( totalRamMB-freeRamMB-bufferRamMB);
}
}
void MemInfoPlugin::setProgressBarStyleSheet(QProgressBar* _bar)
{
const int val = _bar->value();
const int maxVal = _bar->maximum();
// red starts with 50% mem alloc with 0 and is 1 at 100% mem alloc
double redPerc = (val > 0.5*maxVal) ? 2.0*(val-0.5*maxVal) : 0.0;
const unsigned red = 255.0*redPerc/maxVal;
std::cout << red << std::endl;
const unsigned green = 255-red;
const unsigned blue = 0;
//save color in a 32bit integer
const unsigned color = (red<<16)+(green<<8)+blue;
_bar->setStyleSheet(QString(" QProgressBar { border: 2px solid grey; border-radius: 2px; text-align: center; } QProgressBar::chunk {background-color: #%1; width: 1px;}").arg(color,0,16));
}
#if QT_VERSION < 0x050000
Q_EXPORT_PLUGIN2( meminfoplugin , MemInfoPlugin );
......
......@@ -88,6 +88,9 @@ private slots:
private:
/// Sets the Qt Stylesheet for the progress bars
void setProgressBarStyleSheet(QProgressBar* _bar);
/// Status bar for GPU memory
QProgressBar* gpuMemBar_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment