Skip to content

Commit

Permalink
Wordcount visibility handling on Keyboard devices
Browse files Browse the repository at this point in the history
  • Loading branch information
datluong committed Aug 2, 2013
1 parent ce3ce14 commit 119cb2a
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Writer.pro
Original file line number Diff line number Diff line change
@@ -1,7 1,7 @@
APP_NAME = Writer

CONFIG = qt warn_on cascades10
LIBS = -lbbdevice
LIBS = -lbbdevice -lbb

include(config.pri)

Expand Down
86 changes: 75 additions & 11 deletions assets/Editor.qml
Original file line number Diff line number Diff line change
@@ -1,15 1,21 @@
import bb.cascades 1.0
import QtQuick 1.0
import my.timer 1.0

Page {
id: editorPage
objectName: "editorPage"
actionBarAutoHideBehavior: ActionBarAutoHideBehavior.Disabled
actionBarVisibility: ChromeVisibility.Hidden

property string documentTitle: '';
property string documentPath: '';
property bool readyForEditing: false;
property bool documentChanged: false;
property bool compactWordCountView: false;
property bool wordCountBarHidden: false;
property bool timerActive: false;
property double lastStrokeTime: 0;
property double wordCountBarIdleTime: 2500;

signal documentTitleUpdated(string newTitle);

Expand Down Expand Up @@ -44,7 50,6 @@ Page {
onTextChanging: {
documentChanged = true;
if (text.length > 0 && text.indexOf("\n") == text.length-1) {
console.log('enter key detected');
// remove the enterKey
titleTextArea.text = text.substring(0, text.length-1) ;
focusEditor();
Expand Down Expand Up @@ -75,7 80,11 @@ Page {
implicitLayoutAnimationsEnabled: false
onTextChanging: {
documentChanged = true;
updateWordCount(wordCount(text));
updateWordCount(wordCount(text));

if (compactWordCountView && readyForEditing) {
hideWordCountBar();
}
}
onFocusedChanged: {
if (focused)
Expand All @@ -92,7 101,7 @@ Page {
} // end Editor Container
} // end ScrollView
Container {
id: controllerContainer
id: wordCountBar

preferredHeight: 52
rightPadding: 8
Expand Down Expand Up @@ -133,10 142,21 @@ Page {
}
}
} // end Controller Container
} // end Root Container
} // end Root Container

attachedObjects: [
QTimer {
id: editorTimer
singleShot: false
interval: 1000
onTimeout: {
updateWordCountBarVisibility();
}
}
]

function updateWordCount(count) {
var t = '' count ( compactWordCountView? ' w' : (count < 2 ? ' word' : ' words'));
var t = '' count (count < 2 ? ' word' : ' words');
wordCountLabel.setText( t );
}

Expand All @@ -149,15 169,58 @@ Page {
}

onCreationCompleted: {
// compactWordCountView = writerApp.isPhysicalKeyboardDevice();
if (compactWordCountView) {
// wordCountIcon.visible = false;
// controllerContainer.rightPadding = 6;
compactWordCountView = writerApp.isPhysicalKeyboardDevice();
if (compactWordCountView) {
editorTimer.start();
timerActive = true;
}

updateWordCount( wordCount(editorTextArea.text) );
updateWordCount( wordCount(editorTextArea.text) );
}

///////////////////////////////////////////////////////////////////////////
// Q10/Q5 WordCountBar visibility handling
function onFullscreen() {
if (compactWordCountView && timerActive === false) {
timerActive = true;
editorTimer.start();
console.log('editorTimer is started');
}
}

function onThumbnailed() {
if (compactWordCountView && timerActive) {
timerActive = false;
editorTimer.stop();
console.log('editorTimer is stopped');
}
}

function hideWordCountBar() {
var now = new Date();
lastStrokeTime = now.getTime();
if (wordCountBarHidden) return;

wordCountBarHidden = true;
wordCountBar.opacity = 0;
}

function updateWordCountBarVisibility() {
if (wordCountBarHidden === false) return;

var now = (new Date()).getTime();
if (now > lastStrokeTime wordCountBarIdleTime) {
// show wordCountBar
wordCountBarHidden = false;
wordCountBar.opacity = 1;
}
else if (now < lastStrokeTime) {
lastStrokeTime = now;
}

}
///////////////////////////////////////////////////////////////////////////

function textFieldGotFocus() {
if (editorPage.actionBarVisibility != ChromeVisibility.Hidden)
editorPage.actionBarVisibility = ChromeVisibility.Hidden;
Expand Down Expand Up @@ -187,6 250,7 @@ Page {

function beginEditing() {
documentChanged = false;
readyForEditing = true;
}
/**
* Save document
Expand Down
30 changes: 21 additions & 9 deletions src/writely/WriterUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 26,7 @@ WriterUI::WriterUI(bb::cascades::Application *app)

// filesystem initialization
initializeDocumentFolder();
qmlRegisterType<QTimer>("my.timer", 1, 0, "QTimer");

// create scene document from main.qml asset
// set parent to created document to ensure it exists for the whole application lifetime
Expand All @@ -40,6 41,8 @@ WriterUI::WriterUI(bb::cascades::Application *app)
qDebug() << "rootPane" << (mRootNavigationPane!=NULL);

connect( app, SIGNAL(aboutToQuit()), this, SLOT(onAppAboutToQuit()) );
connect( app, SIGNAL(thumbnail()), this, SLOT(onAppThumbnailed()) );
connect( app, SIGNAL(fullscreen()), this, SLOT(onAppFullscreen()) );

initializeAutosave();
}
Expand Down Expand Up @@ -446,20 449,28 @@ bool WriterUI::isPhysicalKeyboardDevice() {

void WriterUI::onAppAboutToQuit() {
qDebug() << "WriterUI::onAppAboutToQuit()";
// qDebug() << "Pages Count:" << mRootNavigationPane->count();
// if (mRootNavigationPane->count() > 0) {
// Page* page = mRootNavigationPane->at( mRootNavigationPane->count()-1 );
// if (page) {
// if ( page->objectName() == "editorPage" ) {
// QMetaObject::invokeMethod(page, "handleAppExitEvent" );
// }
// }
// }
Page* page = currentEditorPage();
if (page)
QMetaObject::invokeMethod(page, "handleAppExitEvent" );
}

//connect( app, SIGNAL(thumbnail()), this, SLOT(onAppThumbnailed()) );
//connect( app, SIGNAL(fullscreen()), this, SLOT(onAppFullscreen()) );

void WriterUI::onAppThumbnailed() {
qDebug() << "WriterUI::onAppThumbnailed()";
Page* page = currentEditorPage();
if (page)
QMetaObject::invokeMethod(page, "onThumbnailed" );
}

void WriterUI::onAppFullscreen() {
qDebug() << "WriterUI::onAppFullscreen";
Page* page = currentEditorPage();
if (page)
QMetaObject::invokeMethod(page, "onFullscreen" );
}

/**
* Fire after a certain period of time
*/
Expand All @@ -469,4 480,5 @@ void WriterUI::onAutosaveTimerTimeout() {
QMetaObject::invokeMethod(page, "handleAutoSaveEvent" );
}


} // end namespace
2 changes: 2 additions & 0 deletions src/writely/WriterUI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 59,8 @@ class WriterUI : public QObject
private slots:
void onAppAboutToQuit();
void onAutosaveTimerTimeout();
void onAppThumbnailed();
void onAppFullscreen();

};

Expand Down

0 comments on commit 119cb2a

Please sign in to comment.