-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TIMOB-8821: BlackBerry: Implement UI.Label #61
Changes from 4 commits
468be2b
18b31bb
9348a1a
9dbb4bb
eed13ee
f49859d
e3f9c8a
1385d39
6c24e4b
acacbf9
7b8bc2e
24443a6
1ca0600
27868f2
a9cd856
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
/** | ||
* Appcelerator Titanium Mobile | ||
* Copyright (c) 2009-2012 by Appcelerator, Inc. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
|
||
#include "NativeAbstractTextControlObject.h" | ||
#include <bb/cascades/controls/abstracttextcontrol.h> | ||
#include <QMap> | ||
#include <QString> | ||
|
||
static const char* FONT_FAMILY = "fontFamily"; | ||
static const char* FONT_SIZE = "fontSize"; | ||
static const char* FONT_STYLE = "fontStyle"; | ||
static const char* FONT_STYLE_NORMAL = "normal"; | ||
static const char* FONT_STYLE_ITALIC = "italic"; | ||
static const char* FONT_WEIGHT = "fontWeight"; | ||
static const char* FONT_WEIGHT_NORMAL = "normal"; | ||
static const char* FONT_WEIGHT_BOLD = "bold"; | ||
|
||
NativeAbstractTextControlObject::NativeAbstractTextControlObject() | ||
{ | ||
textControl_ = NULL; | ||
} | ||
|
||
NativeAbstractTextControlObject::~NativeAbstractTextControlObject() | ||
{ | ||
} | ||
|
||
bb::cascades::AbstractTextControl* NativeAbstractTextControlObject::getTextControl() const | ||
{ | ||
return textControl_; | ||
} | ||
|
||
void NativeAbstractTextControlObject::setTextControl(bb::cascades::AbstractTextControl* textControl) | ||
{ | ||
textControl_ = textControl; | ||
setControl((bb::cascades::Control*)textControl_); | ||
} | ||
|
||
int NativeAbstractTextControlObject::setText(TiObject* obj) | ||
{ | ||
QString str; | ||
int error = NativeControlObject::getString(obj, str); | ||
if (error != NATIVE_ERROR_OK) | ||
{ | ||
return error; | ||
} | ||
textControl_->setText(str); | ||
return NATIVE_ERROR_OK; | ||
} | ||
|
||
int NativeAbstractTextControlObject::setColor(TiObject* obj) | ||
{ | ||
float r; | ||
float g; | ||
float b; | ||
float a; | ||
|
||
int error = NativeControlObject::getColorComponents(obj, &r, &g, &b, &a); | ||
if (error != NATIVE_ERROR_OK) | ||
{ | ||
return error; | ||
} | ||
bb::cascades::Color cscolor = bb::cascades::Color::fromRGBA(r, g, b, a); | ||
textControl_->textStyle()->setColor(cscolor); | ||
return NATIVE_ERROR_OK; | ||
} | ||
|
||
int NativeAbstractTextControlObject::setTextAlign(TiObject* obj) | ||
{ | ||
int value; | ||
int error = NativeControlObject::getInteger(obj, &value); | ||
if (error != NATIVE_ERROR_OK) | ||
{ | ||
return error; | ||
} | ||
|
||
switch (value) | ||
{ | ||
case TEXT_ALIGNMENT_LEFT: | ||
textControl_->textStyle()->setAlignment(bb::cascades::TextAlignment::ForceLeft); | ||
break; | ||
case TEXT_ALIGNMENT_CENTER: | ||
textControl_->textStyle()->setAlignment(bb::cascades::TextAlignment::Center); | ||
break; | ||
case TEXT_ALIGNMENT_RIGHT: | ||
textControl_->textStyle()->setAlignment(bb::cascades::TextAlignment::ForceRight); | ||
break; | ||
default: | ||
qDebug() << "Unknown value recieved: " << value; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/recieved/received/ Also log the class name and method name, so the origin of the log can be found easily. Goes for all logging messages |
||
break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the event of an unrecognized alignment value, is this the intended behaviour? Or should the alignment not change instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In these cases where we silently ignore unknown values, it would be good to log a line saying that we received unknown value and log what the received value was. Same goes for setFont There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||
} | ||
|
||
return NATIVE_ERROR_OK; | ||
} | ||
|
||
int NativeAbstractTextControlObject::setFont(TiObject* obj) | ||
{ | ||
QMap<QString, QString> font; | ||
int error = NativeControlObject::getMapObject(obj, font); | ||
if (error != NATIVE_ERROR_OK) | ||
{ | ||
return error; | ||
} | ||
|
||
QMap<QString, QString>::const_iterator it = font.begin(); | ||
for (; it != font.end(); ++it) | ||
{ | ||
if (it.key().compare(FONT_FAMILY) == 0) | ||
{ | ||
textControl_->textStyle()->setFontFamily(it.value()); | ||
} | ||
else if (it.key().compare(FONT_SIZE) == 0) | ||
{ | ||
bool bSucceeded; | ||
float size = it.value().toFloat(&bSucceeded); | ||
if (bSucceeded) | ||
{ | ||
textControl_->textStyle()->setSize(size); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if bSucceeded is false, that should be logged too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
} | ||
else if (it.key().compare(FONT_STYLE) == 0) | ||
{ | ||
if (it.value().compare(FONT_STYLE_NORMAL) == 0) | ||
{ | ||
textControl_->textStyle()->setFontStyle(bb::cascades::FontStyle::Normal); | ||
} | ||
else if (it.value().compare(FONT_STYLE_ITALIC) == 0) | ||
{ | ||
textControl_->textStyle()->setFontStyle(bb::cascades::FontStyle::Italic); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the else clause should be logged too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
} | ||
else if (it.key().compare(FONT_WEIGHT) == 0) | ||
{ | ||
if (it.value().compare(FONT_WEIGHT_NORMAL) == 0) | ||
{ | ||
textControl_->textStyle()->setFontWeight(bb::cascades::FontWeight::Normal); | ||
} | ||
else if (it.value().compare(FONT_WEIGHT_BOLD) == 0) | ||
{ | ||
textControl_->textStyle()->setFontWeight(bb::cascades::FontWeight::Bold); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the else clause should be logged too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
} | ||
else | ||
{ | ||
qDebug() << "Unknown key:value recieved: " << qPrintable(it.key()) << ":" << qPrintable(it.value()); | ||
} | ||
} | ||
|
||
return NATIVE_ERROR_OK; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a more general behaviour note, please verify how badly formatted fonts behave on other platforms. are errors/exceptions raised or are they silently ignored? This goes for both the key string and the value string There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In cases something went wrong default style will be used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not answer the question. is you're answer relating to Android or Iphone or BB? Please specify. Have you tried it on another platform? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found no documentation on that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not asking for documentation, i'm asking you to try it out and report your findings. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Appcelerator Titanium Mobile | ||
* Copyright (c) 2009-2012 by Appcelerator, Inc. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
|
||
#ifndef NATIVEABSTRACTTEXTCONTROLOBJECT_H_ | ||
#define NATIVEABSTRACTTEXTCONTROLOBJECT_H_ | ||
|
||
#include "NativeControlObject.h" | ||
|
||
//forward declaration | ||
namespace bb | ||
{ | ||
namespace cascades | ||
{ | ||
class AbstractTextControl; | ||
} | ||
} | ||
|
||
// Text alignment constants | ||
enum N_TEXT_ALIGNMENT | ||
{ | ||
TEXT_ALIGNMENT_LEFT, | ||
TEXT_ALIGNMENT_CENTER, | ||
TEXT_ALIGNMENT_RIGHT | ||
}; | ||
|
||
/* | ||
* NativeAbstractTextControlObject | ||
* | ||
* UI: Abstract Text Control | ||
*/ | ||
|
||
class NativeAbstractTextControlObject : public NativeControlObject | ||
{ | ||
public: | ||
virtual int setText(TiObject* obj); | ||
virtual int setFont(TiObject* obj); | ||
virtual int setColor(TiObject* obj); | ||
virtual int setTextAlign(TiObject* obj); | ||
|
||
protected: | ||
explicit NativeAbstractTextControlObject(); | ||
virtual ~NativeAbstractTextControlObject(); | ||
virtual bb::cascades::AbstractTextControl* getTextControl() const; | ||
virtual void setTextControl(bb::cascades::AbstractTextControl* textControl); | ||
|
||
private: | ||
// Disable copy ctor & assignment operator | ||
NativeAbstractTextControlObject(const NativeAbstractTextControlObject& textControl); | ||
NativeAbstractTextControlObject& operator=(const NativeAbstractTextControlObject& textControl); | ||
bb::cascades::AbstractTextControl* textControl_; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also disable the copy ctor and assignment operator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
|
||
#endif /* NATIVEABSTRACTTEXTCONTROLOBJECT_H_ */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to update the Font apidoc as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cannot found documentation for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apidoc/Titanium/UI/Font.yml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't meant that. For example for Android it says: "On Android, use the font file name, minus the
.otf
or.ttf
extension.For example, if you are using the Chantelli Antiqua font and the file is
named
Chantelli_Antiqua.ttf
, specifyfontFamily: 'Chantelli_Antiqua'
on Android."
Cannot find appropriate documentation for BB.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you're looking at is for custom fonts. Can you install custom fonts on the BB? If you can't find the answer through investigation or documentation, then ask suavek.
The Font doc still needs to be updated to reflect the work of this PR.
If you've tested your work you should already know most of these answers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there are still things that need to be updated but need to wait for R6 to find the answers then add them to the JIra Issue for reworking label/font after R6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you confirm that the jira issue has been updated with the information above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still awaiting confirmation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Jira updated:
https://jira.appcelerator.org/browse/TIMOB-8821
https://jira.appcelerator.org/browse/TIMOB-9413