* Based on Adrien's idea to use special unicode characters, I've added rating
and checkbox as new display_as types - editing, however, works the same as before. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38864 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -251,8 +251,12 @@ WidgetAttributeText::NewWidgetText(const Model* model,
|
||||
return new OriginalPathAttributeText(model, column);
|
||||
|
||||
if (column->DisplayAs() != NULL) {
|
||||
if (!strncmp(column->DisplayAs(), "checkbox", 8))
|
||||
return new CheckboxAttributeText(model, column);
|
||||
if (!strncmp(column->DisplayAs(), "duration", 8))
|
||||
return new DurationAttributeText(model, column);
|
||||
if (!strncmp(column->DisplayAs(), "rating", 6))
|
||||
return new RatingAttributeText(model, column);
|
||||
}
|
||||
|
||||
return new GenericAttributeText(model, column);
|
||||
@@ -1731,6 +1735,157 @@ DurationAttributeText::FitValue(BString* result, const BPoseView* view)
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - display as: checkbox
|
||||
|
||||
|
||||
CheckboxAttributeText::CheckboxAttributeText(const Model* model,
|
||||
const BColumn* column)
|
||||
:
|
||||
GenericAttributeText(model, column),
|
||||
fOnChar("✖"),
|
||||
fOffChar("-")
|
||||
{
|
||||
// TODO: better have common data in the column object!
|
||||
if (const char* separator = strchr(column->DisplayAs(), ':')) {
|
||||
BString chars(separator + 1);
|
||||
int32 length;
|
||||
const char* c = chars.CharAt(0, &length);
|
||||
fOnChar.SetTo(c, length);
|
||||
if (c[length]) {
|
||||
c = chars.CharAt(1, &length);
|
||||
fOffChar.SetTo(c, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CheckboxAttributeText::SetUpEditing(BTextView* view)
|
||||
{
|
||||
// TODO: support editing for real!
|
||||
BString result;
|
||||
GenericAttributeText::FitValue(&result, NULL);
|
||||
GenericAttributeText::SetUpEditing(view);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CheckboxAttributeText::FitValue(BString* result, const BPoseView* view)
|
||||
{
|
||||
if (fValueDirty)
|
||||
ReadValue(&fFullValueText);
|
||||
|
||||
fOldWidth = fColumn->Width();
|
||||
fDirty = false;
|
||||
|
||||
if (!fValueIsDefined) {
|
||||
*result = fOffChar;
|
||||
fTruncatedWidth = TruncString(result, fFullValueText.String(),
|
||||
fFullValueText.Length(), view, fOldWidth);
|
||||
return;
|
||||
}
|
||||
|
||||
bool checked = false;
|
||||
|
||||
switch (fColumn->AttrType()) {
|
||||
case B_BOOL_TYPE:
|
||||
checked = fValue.boolt;
|
||||
break;
|
||||
|
||||
case B_INT8_TYPE:
|
||||
case B_UINT8_TYPE:
|
||||
checked = fValue.int8t != 0;
|
||||
break;
|
||||
|
||||
case B_INT16_TYPE:
|
||||
case B_UINT16_TYPE:
|
||||
checked = fValue.int16t != 0;
|
||||
break;
|
||||
|
||||
case B_INT32_TYPE:
|
||||
case B_UINT32_TYPE:
|
||||
checked = fValue.int32t != 0;
|
||||
break;
|
||||
}
|
||||
|
||||
fFullValueText = checked ? fOnChar : fOffChar;
|
||||
|
||||
fTruncatedWidth = TruncString(result, fFullValueText.String(),
|
||||
fFullValueText.Length(), view, fOldWidth);
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - display as: rating
|
||||
|
||||
|
||||
RatingAttributeText::RatingAttributeText(const Model* model,
|
||||
const BColumn* column)
|
||||
:
|
||||
GenericAttributeText(model, column),
|
||||
fCount(5),
|
||||
fMax(10)
|
||||
{
|
||||
// TODO: support different star counts/max via specifier
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RatingAttributeText::SetUpEditing(BTextView* view)
|
||||
{
|
||||
// TODO: support editing for real!
|
||||
BString result;
|
||||
GenericAttributeText::FitValue(&result, NULL);
|
||||
GenericAttributeText::SetUpEditing(view);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
RatingAttributeText::FitValue(BString* result, const BPoseView* view)
|
||||
{
|
||||
if (fValueDirty)
|
||||
ReadValue(&fFullValueText);
|
||||
|
||||
fOldWidth = fColumn->Width();
|
||||
fDirty = false;
|
||||
|
||||
int64 rating = 0;
|
||||
|
||||
if (fValueIsDefined) {
|
||||
switch (fColumn->AttrType()) {
|
||||
case B_INT8_TYPE:
|
||||
rating = fValue.int8t;
|
||||
break;
|
||||
|
||||
case B_INT16_TYPE:
|
||||
rating = fValue.int16t;
|
||||
break;
|
||||
|
||||
case B_INT32_TYPE:
|
||||
rating = fValue.int32t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (rating > fMax)
|
||||
rating = fMax;
|
||||
if (rating < 0)
|
||||
rating = 0;
|
||||
|
||||
int32 steps = fMax / fCount;
|
||||
fFullValueText = "";
|
||||
|
||||
for (int32 i = 0; i < fCount; i++) {
|
||||
if (rating > i * steps)
|
||||
fFullValueText += "★";
|
||||
else
|
||||
fFullValueText += "☆";
|
||||
}
|
||||
|
||||
fTruncatedWidth = TruncString(result, fFullValueText.String(),
|
||||
fFullValueText.Length(), view, fOldWidth);
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
|
||||
@@ -249,6 +249,42 @@ private:
|
||||
};
|
||||
|
||||
|
||||
//! Used for the display-as type "checkbox"
|
||||
class CheckboxAttributeText : public GenericAttributeText {
|
||||
public:
|
||||
CheckboxAttributeText(const Model* model,
|
||||
const BColumn* column);
|
||||
|
||||
virtual void SetUpEditing(BTextView* view);
|
||||
|
||||
private:
|
||||
virtual void FitValue(BString* result,
|
||||
const BPoseView* view);
|
||||
|
||||
private:
|
||||
BString fOnChar;
|
||||
BString fOffChar;
|
||||
};
|
||||
|
||||
|
||||
//! Used for the display-as type "rating"
|
||||
class RatingAttributeText : public GenericAttributeText {
|
||||
public:
|
||||
RatingAttributeText(const Model* model,
|
||||
const BColumn* column);
|
||||
|
||||
virtual void SetUpEditing(BTextView* view);
|
||||
|
||||
private:
|
||||
virtual void FitValue(BString* result,
|
||||
const BPoseView* view);
|
||||
|
||||
private:
|
||||
int32 fCount;
|
||||
int32 fMax;
|
||||
};
|
||||
|
||||
|
||||
class TimeAttributeText : public ScalarAttributeText {
|
||||
public:
|
||||
TimeAttributeText(const Model *, const BColumn *);
|
||||
|
||||
@@ -26,9 +26,11 @@ const struct type_map kTypeMap[] = {
|
||||
// as well as a nice GUI for them.
|
||||
const struct display_as_map kDisplayAsMap[] = {
|
||||
{"Default", NULL, {}},
|
||||
{"Rating", "rating", {B_INT32_TYPE, B_INT8_TYPE, B_INT16_TYPE}},
|
||||
{"Checkbox", "checkbox",
|
||||
{B_BOOL_TYPE, B_INT8_TYPE, B_INT16_TYPE, B_INT32_TYPE}},
|
||||
{"Duration", "duration",
|
||||
{B_TIME_TYPE, B_INT8_TYPE, B_INT16_TYPE, B_INT32_TYPE, B_INT64_TYPE}},
|
||||
{"Rating", "rating", {B_INT8_TYPE, B_INT16_TYPE, B_INT32_TYPE}},
|
||||
{NULL, NULL, {}}
|
||||
};
|
||||
|
||||
@@ -40,7 +42,7 @@ add_display_as(BString& string, const char* displayAs)
|
||||
return;
|
||||
|
||||
BString base(displayAs);
|
||||
int32 end = base.FindFirst(": ");
|
||||
int32 end = base.FindFirst(':');
|
||||
if (end > 0)
|
||||
base.Truncate(end);
|
||||
|
||||
|
||||
@@ -68,9 +68,9 @@ compare_display_as(const char* a, const char* b)
|
||||
if (emptyA || emptyB)
|
||||
return false;
|
||||
|
||||
const char* end = strstr(a, ": ");
|
||||
const char* end = strchr(a, ':');
|
||||
int32 lengthA = end ? end - a : strlen(a);
|
||||
end = strstr(b, ": ");
|
||||
end = strchr(b, ':');
|
||||
int32 lengthB = end ? end - b : strlen(b);
|
||||
|
||||
if (lengthA != lengthB)
|
||||
@@ -83,9 +83,9 @@ compare_display_as(const char* a, const char* b)
|
||||
static const char*
|
||||
display_as_parameter(const char* special)
|
||||
{
|
||||
const char* parameter = strstr(special, ": ");
|
||||
const char* parameter = strchr(special, ':');
|
||||
if (parameter != NULL)
|
||||
return parameter + 2;
|
||||
return parameter + 1;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -392,7 +392,7 @@ AttributeWindow::_NewItemFromCurrent()
|
||||
displayAs = identifier;
|
||||
|
||||
if (fSpecialControl->Text() && fSpecialControl->Text()[0]) {
|
||||
displayAs += ": ";
|
||||
displayAs += ":";
|
||||
displayAs += fSpecialControl->Text();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user