diff options
author | Neil Hodgson <nyamatongwe@gmail.com> | 2014-07-15 12:04:54 +1000 |
---|---|---|
committer | Neil Hodgson <nyamatongwe@gmail.com> | 2014-07-15 12:04:54 +1000 |
commit | a4d36c2b76d188199d9b16b4556d9aa88c412731 (patch) | |
tree | b79d163e39dcfcc214e3c4c95111cba90b664203 /qt/ScintillaEditBase/ScintillaQt.cpp | |
parent | a04e3bb80fe893b98f7bd4d66d4bb44ad50b5b13 (diff) | |
download | scintilla-mirror-a4d36c2b76d188199d9b16b4556d9aa88c412731.tar.gz |
Implement separate timers for each type of periodic activity and turn them on and off
as required. This saves power as there are fewer wake ups.
A tolerance value is provided so that platforms that support coalescing timers,
Windows 8+ and OS X 10.9+, can use them.
The previous global 100 millisecond timer may still be used by non-core platforms.
Diffstat (limited to 'qt/ScintillaEditBase/ScintillaQt.cpp')
-rw-r--r-- | qt/ScintillaEditBase/ScintillaQt.cpp | 66 |
1 files changed, 42 insertions, 24 deletions
diff --git a/qt/ScintillaEditBase/ScintillaQt.cpp b/qt/ScintillaEditBase/ScintillaQt.cpp index 3d727900b..c2b250a3e 100644 --- a/qt/ScintillaEditBase/ScintillaQt.cpp +++ b/qt/ScintillaEditBase/ScintillaQt.cpp @@ -44,19 +44,20 @@ ScintillaQt::ScintillaQt(QAbstractScrollArea *parent) WndProc(SCI_SETBUFFEREDDRAW, false, 0); Initialise(); + + for (TickReason tr = tickCaret; tr <= tickDwell; tr = static_cast<TickReason>(tr + 1)) { + timers[tr] = 0; + } } ScintillaQt::~ScintillaQt() { - SetTicking(false); + for (TickReason tr = tickCaret; tr <= tickDwell; tr = static_cast<TickReason>(tr + 1)) { + FineTickerCancel(tr); + } SetIdle(false); } -void ScintillaQt::tick() -{ - Tick(); -} - void ScintillaQt::execCommand(QAction *action) { int command = action->data().toInt(); @@ -148,7 +149,9 @@ void ScintillaQt::Initialise() void ScintillaQt::Finalise() { - SetTicking(false); + for (TickReason tr = tickCaret; tr <= tickDwell; tr = static_cast<TickReason>(tr + 1)) { + FineTickerCancel(tr); + } ScintillaBase::Finalise(); } @@ -396,25 +399,31 @@ void ScintillaQt::NotifyParent(SCNotification scn) emit notifyParent(scn); } -void ScintillaQt::SetTicking(bool on) +/** +* Report that this Editor subclass has a working implementation of FineTickerStart. +*/ +bool ScintillaQt::FineTickerAvailable() { - QTimer *qTimer; - if (timer.ticking != on) { - timer.ticking = on; - if (timer.ticking) { - qTimer = new QTimer; - connect(qTimer, SIGNAL(timeout()), this, SLOT(tick())); - qTimer->start(timer.tickSize); - timer.tickerID = qTimer; - } else { - qTimer = static_cast<QTimer *>(timer.tickerID); - qTimer->stop(); - disconnect(qTimer, SIGNAL(timeout()), 0, 0); - delete qTimer; - timer.tickerID = 0; - } + return true; +} + +bool ScintillaQt::FineTickerRunning(TickReason reason) +{ + return timers[reason] != 0; +} + +void ScintillaQt::FineTickerStart(TickReason reason, int millis, int /* tolerance */) +{ + FineTickerCancel(reason); + timers[reason] = startTimer(millis); +} + +void ScintillaQt::FineTickerCancel(TickReason reason) +{ + if (timers[reason]) { + killTimer(timers[reason]); + timers[reason] = 0; } - timer.ticksToWait = caret.period; } void ScintillaQt::onIdle() @@ -740,3 +749,12 @@ void ScintillaQt::Drop(const Point &point, const QMimeData *data, bool move) DropAt(movePos, bytes, len, move, rectangular); } + +void ScintillaQt::timerEvent(QTimerEvent *event) +{ + for (TickReason tr=tickCaret; tr<=tickDwell; tr = static_cast<TickReason>(tr+1)) { + if (timers[tr] == event->timerId()) { + TickFor(tr); + } + } +} |