本文整理汇总了C++中BStringView::GetPreferredSize方法的典型用法代码示例。如果您正苦于以下问题:C++ BStringView::GetPreferredSize方法的具体用法?C++ BStringView::GetPreferredSize怎么用?C++ BStringView::GetPreferredSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BStringView
的用法示例。
在下文中一共展示了BStringView::GetPreferredSize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Bounds
void
TSignatureView::AttachedToWindow()
{
BRect rect = Bounds();
float name_text_length = StringWidth(kNameText);
float sig_text_length = StringWidth(kSigText);
float divide_length;
if (name_text_length > sig_text_length)
divide_length = name_text_length;
else
divide_length = sig_text_length;
rect.InsetBy(8,0);
rect.top+= 8;
fName = new TNameControl(rect, kNameText, new BMessage(NAME_FIELD));
AddChild(fName);
fName->SetDivider(divide_length + 10);
fName->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
rect.OffsetBy(0,fName->Bounds().Height()+5);
rect.bottom = rect.top + kSigHeight;
rect.left = fName->TextView()->Frame().left;
BRect text = rect;
text.OffsetTo(10,0);
fTextView = new TSigTextView(rect, text);
BScrollView *scroller = new BScrollView("SigScroller", fTextView, B_FOLLOW_ALL, 0, false, true);
AddChild(scroller);
scroller->ResizeBy(-1 * scroller->ScrollBar(B_VERTICAL)->Frame().Width() - 9, 0);
scroller->MoveBy(7,0);
/* back up a bit to make room for the label */
rect = scroller->Frame();
BStringView *stringView = new BStringView(rect, "SigLabel", kSigText);
AddChild(stringView);
float tWidth, tHeight;
stringView->GetPreferredSize(&tWidth, &tHeight);
/* the 5 is for the spacer in the TextView */
rect.OffsetBy(-1 *(tWidth) - 5, 0);
rect.right = rect.left + tWidth;
rect.bottom = rect.top + tHeight;
stringView->MoveTo(rect.LeftTop());
stringView->ResizeTo(rect.Width(), rect.Height());
/* Resize the View to the correct height */
scroller->SetResizingMode(B_FOLLOW_NONE);
ResizeTo(Frame().Width(), scroller->Frame().bottom + 8);
scroller->SetResizingMode(B_FOLLOW_ALL);
}
示例2: locker
//.........这里部分代码省略.........
const char *type = B_TRANSLATE("Unknown type");
switch (fEditor.Type()) {
case B_MINI_ICON_TYPE:
case B_LARGE_ICON_TYPE:
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
case B_VECTOR_ICON_TYPE:
#endif
type = B_TRANSLATE("Icon");
break;
case B_PNG_FORMAT:
type = B_TRANSLATE("PNG format");
break;
case B_MESSAGE_TYPE:
type = B_TRANSLATE("Flattened bitmap");
break;
default:
break;
}
const char *colorSpace;
switch (fBitmap->ColorSpace()) {
case B_GRAY1:
case B_GRAY8:
colorSpace = B_TRANSLATE("Grayscale");
break;
case B_CMAP8:
colorSpace = B_TRANSLATE("8 bit palette");
break;
case B_RGB32:
case B_RGBA32:
case B_RGB32_BIG:
case B_RGBA32_BIG:
colorSpace = B_TRANSLATE("32 bit");
break;
case B_RGB15:
case B_RGBA15:
case B_RGB15_BIG:
case B_RGBA15_BIG:
colorSpace = B_TRANSLATE("15 bit");
break;
case B_RGB16:
case B_RGB16_BIG:
colorSpace = B_TRANSLATE("16 bit");
break;
default:
colorSpace = B_TRANSLATE("Unknown format");
break;
}
snprintf(buffer, sizeof(buffer), "%s, %g x %g, %s", type,
fBitmap->Bounds().Width() + 1, fBitmap->Bounds().Height() + 1,
colorSpace);
fDescriptionView->SetText(buffer);
} else
fDescriptionView->SetText(B_TRANSLATE_COMMENT("Could not read image",
"Image means here a picture file, not a disk image."));
// Update the view size to match the image and its description
float width, height;
fDescriptionView->GetPreferredSize(&width, &height);
fDescriptionView->ResizeTo(width, height);
BRect rect = fDescriptionView->Bounds();
if (fBitmap != NULL) {
BRect bounds = fBitmap->Bounds();
rect.bottom += bounds.Height() + 5;
if (fScaleSlider != NULL && rect.Width() < fScaleSlider->Bounds().Width())
rect.right = fScaleSlider->Bounds().right;
if (bounds.Width() > rect.Width())
rect.right = bounds.right;
// center description below the bitmap
fDescriptionView->MoveTo((rect.Width() - fDescriptionView->Bounds().Width()) / 2,
bounds.Height() + 5);
if (fScaleSlider != NULL) {
// center slider below description
rect.bottom += fScaleSlider->Bounds().Height() + 5;
fScaleSlider->MoveTo((rect.Width() - fScaleSlider->Bounds().Width()) / 2,
fDescriptionView->Frame().bottom + 5);
if (fScaleSlider->IsHidden())
fScaleSlider->Show();
}
} else if (fScaleSlider != NULL && !fScaleSlider->IsHidden())
fScaleSlider->Hide();
ResizeTo(rect.Width(), rect.Height());
if (Parent()) {
// center within parent view
BRect parentBounds = Parent()->Bounds();
MoveTo((parentBounds.Width() - rect.Width()) / 2,
(parentBounds.Height() - rect.Height()) / 2);
}
Invalidate();
// restore old view size
fEditor.SetViewSize(viewSize);
}
示例3: BMessage
// --------------------------------------------------
JobSetupWindow::JobSetupWindow(BMessage *msg, const char * printerName)
: HWindow(BRect(0, 0, 320, 160), "Job Setup", B_TITLED_WINDOW_LOOK,
B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE |
B_NOT_ZOOMABLE)
{
fSetupMsg = msg;
fExitSem = create_sem(0, "JobSetup");
fResult = B_ERROR;
if (printerName) {
BString title;
title << printerName << " Job Setup";
SetTitle(title.String());
fPrinterName = printerName;
}
// ---- Ok, build a default job setup user interface
BRect r;
BBox *panel;
BBox *line;
BButton *ok;
BButton *cancel;
BStringView *sv;
float x, y, w, h;
float indent;
int32 copies;
int32 firstPage;
int32 lastPage;
bool allPages;
char buffer[80];
// PrinterDriver ensures that property exists
fSetupMsg->FindInt32("copies", &copies);
fSetupMsg->FindInt32("first_page", &firstPage);
fSetupMsg->FindInt32("last_page", &lastPage);
BMessage doc_info;
if (B_OK != fSetupMsg->FindMessage("doc_info", &doc_info)) {
// default fields
doc_info.AddString("Author", "");
doc_info.AddString("Subject", "");
doc_info.AddString("Keywords", "");
fSetupMsg->AddMessage("doc_info", &doc_info);
}
AddFields(&fDocInfo, fSetupMsg, NULL, includeKeys);
allPages = firstPage == 1 && lastPage == MAX_INT32;
r = Bounds();
// add a *dialog* background
panel = new BBox(r, "top_panel", B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
B_PLAIN_BORDER);
const int kMargin = 6;
//const char *kCopiesLabel = "Copies:";
const char *kCopiesLabelExtraSpace = "Copies:##";
const char *kPagesRangeLabel = "Pages:";
const char *kAllPagesLabel = "All";
const char *kPagesRangeSelectionLabel = "";
const char *kFromLabel = "From:";
const char *kFromLabelExtraSpace = "From:##";
const char *kToLabel = "To:";
const char *kToLabelExtraSpace = "To:##";
r = panel->Bounds();
x = r.left + kMargin;
y = r.top + kMargin;
// add a "copies" input field
/* Simon: temporarily removed this code
sprintf(buffer, "%d", (int)copies);
fCopies = new BTextControl(BRect(x, y, x+100, y+20), "copies", kCopiesLabel,
buffer, new BMessage(NB_COPIES_MSG));
fCopies->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT);
fCopies->ResizeToPreferred();
fCopies->GetPreferredSize(&w, &h);
panel->AddChild(fCopies);
y += h + kMargin; // "new line"
*/
// add a "pages" label
sv = new BStringView(BRect(x, y, x+100, y+20), "pages_range", kPagesRangeLabel);
panel->AddChild(sv);
sv->ResizeToPreferred();
sv->GetPreferredSize(&w, &h);
// align "copies" textcontrol field on the "allPages" radiobutton bellow...
indent = be_plain_font->StringWidth(kCopiesLabelExtraSpace);
w += kMargin;
if ( w > indent )
indent = w;
// fCopies->SetDivider(indent);
x += indent;
//.........这里部分代码省略.........