aboutsummaryrefslogtreecommitdiffhomepage
path: root/qt/ScintillaEditBase/ScintillaQt.cpp
diff options
context:
space:
mode:
authorNeil Hodgson <nyamatongwe@gmail.com>2014-07-15 12:04:54 +1000
committerNeil Hodgson <nyamatongwe@gmail.com>2014-07-15 12:04:54 +1000
commitbaf2d31068737bf24102cee6a7fed33e0d00d1f3 (patch)
treef814f1a39637d7711ab0ce709fef0b2468fbb270 /qt/ScintillaEditBase/ScintillaQt.cpp
parent7b7865ca3062d57ebe990468a9275180f0d60569 (diff)
downloadscintilla-mirror-baf2d31068737bf24102cee6a7fed33e0d00d1f3.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.cpp66
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);
+ }
+ }
+}