Changeset View
Changeset View
Standalone View
Standalone View
src/context/applets/analyzer/plugin/BlockWorker.cpp
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Line(s) | 48 | { | |||
---|---|---|---|---|---|
56 | const double PRO = 1; //PRO allows us to restrict the range somewhat | 56 | const double PRO = 1; //PRO allows us to restrict the range somewhat | ||
57 | 57 | | |||
58 | for( int z = 0; z < m_rows; ++z ) | 58 | for( int z = 0; z < m_rows; ++z ) | ||
59 | m_yscale[z] = 1 - log10( m_rows - z ) / log10( m_rows + PRO ); | 59 | m_yscale[z] = 1 - log10( m_rows - z ) / log10( m_rows + PRO ); | ||
60 | 60 | | |||
61 | m_mutex.unlock(); | 61 | m_mutex.unlock(); | ||
62 | } | 62 | } | ||
63 | 63 | | |||
64 | void BlockWorker::setColumns(int columns) | 64 | void BlockWorker::setColumns( int columns ) | ||
65 | { | 65 | { | ||
66 | if( m_columns == columns ) | 66 | if( m_columns == columns ) | ||
67 | return; | 67 | return; | ||
68 | 68 | | |||
69 | m_columns = columns; | 69 | m_columns = columns; | ||
70 | } | 70 | } | ||
71 | 71 | | |||
72 | void BlockWorker::analyze() | 72 | void BlockWorker::analyze() | ||
73 | { | 73 | { | ||
74 | int timeElapsed = m_lastUpdate.elapsed(); | 74 | int timeElapsed = m_lastUpdate.elapsed(); | ||
75 | 75 | | |||
76 | // only analyze if screen is fast enough | 76 | // only analyze if screen is fast enough | ||
77 | if( timeElapsed < m_refreshTime - 1 ) | 77 | if( timeElapsed < m_refreshTime - 1 ) | ||
78 | QThread::currentThread()->msleep( m_refreshTime - timeElapsed - 1 ); | 78 | QThread::currentThread()->msleep( m_refreshTime - timeElapsed - 1 ); | ||
79 | 79 | | |||
80 | const auto scopeData = scope(); | 80 | const auto scopeData = scope(); | ||
81 | const int scopeSize = scopeData.size(); | 81 | const int scopeSize = scopeData.size(); | ||
82 | 82 | | |||
83 | timeElapsed = m_lastUpdate.restart(); | 83 | timeElapsed = m_lastUpdate.restart(); | ||
84 | 84 | | |||
85 | const qreal step = m_step * timeElapsed / 1000.0; | 85 | const qreal step = m_step * timeElapsed / 1000.0; | ||
86 | const qreal fadeStep = (qreal)timeElapsed / 20.0; | 86 | const qreal fadeStep = (qreal)timeElapsed / 20.0; | ||
87 | 87 | | |||
88 | // block m_store and m_fadebars | 88 | // lock m_store and m_fadebars | ||
89 | QMutexLocker locker(&m_mutex); | 89 | QMutexLocker locker( &m_mutex ); | ||
90 | 90 | | |||
91 | m_store.resize( scopeSize ); | 91 | m_store.resize( scopeSize ); | ||
92 | m_fadebars.resize( scopeSize ); | 92 | m_fadebars.resize( scopeSize ); | ||
93 | 93 | | |||
94 | for( int x = 0; x < scopeSize; ++x ) | 94 | for( int x = 0; x < scopeSize; ++x ) | ||
95 | { | 95 | { | ||
96 | // determine y | 96 | // determine y | ||
97 | int y = 0; | 97 | int y = 0; | ||
98 | while( y < m_yscale.size() && scopeData.at(x) > m_yscale.at(y) ) | 98 | while( y < m_yscale.size() && scopeData.at(x) > m_yscale.at(y) ) | ||
99 | y++; | 99 | y++; | ||
100 | 100 | | |||
101 | auto &fadebars = m_fadebars[x]; | 101 | auto &fadebars = m_fadebars[x]; | ||
102 | auto &store = m_store[x]; | 102 | auto &store = m_store[x]; | ||
103 | 103 | | |||
104 | // remove obscured fadebars | 104 | // remove obscured fadebars | ||
105 | while( !fadebars.isEmpty() && fadebars.last().y >= y ) | 105 | while( !fadebars.isEmpty() && fadebars.last().y <= y ) | ||
106 | fadebars.removeLast(); | 106 | fadebars.removeLast(); | ||
107 | 107 | | |||
108 | // remove completely faded fadebars | 108 | // remove completely faded fadebars | ||
109 | while( !fadebars.isEmpty() && fadebars.first().intensity <= fadeStep ) | 109 | while( !fadebars.isEmpty() && fadebars.first().intensity <= fadeStep ) | ||
110 | fadebars.removeFirst(); | 110 | fadebars.removeFirst(); | ||
111 | 111 | | |||
112 | // fade the rest | 112 | // fade the rest | ||
113 | for( auto &fadebar : fadebars ) | 113 | for( auto &fadebar : fadebars ) | ||
Show All 16 Lines |