当前位置: 首页>>代码示例>>C++>>正文


C++ BView::GetPreferredSize方法代码示例

本文整理汇总了C++中BView::GetPreferredSize方法的典型用法代码示例。如果您正苦于以下问题:C++ BView::GetPreferredSize方法的具体用法?C++ BView::GetPreferredSize怎么用?C++ BView::GetPreferredSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BView的用法示例。


在下文中一共展示了BView::GetPreferredSize方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: BOutlineListView

TestWindow::TestWindow(BApplication* myApp)
	: BWindow(BRect(20,20,100,100),
	  "Code Profile", B_TITLED_WINDOW, 0)
{
	BRect frm = Bounds();

	BView* myview = new BView(BRect(),"testView",0,0);
	
	BOutlineListView* olist =
		new BOutlineListView(BRect(),"MyList",
							B_SINGLE_SELECTION_LIST,B_FOLLOW_NONE);
	if( myview && olist ) {
		myview->AddChild(olist);
		BView* vw = olist;
		vw->SetViewColor(0xc0,0xc0,0xc0);
		vw->Invalidate();
		vw->SetLowColor(0xc0,0xc0,0xc0);
		vw->Invalidate();
		vw->SetHighColor(0x00,0x00,0x00);
		vw->Invalidate();
		vw->SetFont(be_bold_font);
		this->AddChild(myview);
		BRect frm = vw->Frame();
		vw->ResizeTo(1,1);
		vw->Draw(vw->Bounds());
		vw->ResizeToPreferred();
		float w=0,h=0;
		vw->GetPreferredSize(&w,&h);
		printf("Preferred size = %f x %f\n",w,h);
	}
	
	string = new BStringView(BRect(0,0,100,20),"String",
								"Ready to profile...");	
	
	if( string ) {
		string->SetViewColor(0xc0,0xc0,0xc0);
		this->AddChild(string);
		float w=0, h=0;
		string->GetPreferredSize(&w,&h);
		MoveTo(30,30);
		ResizeTo(w,h);
	}
	
	BMenuBar* menu = new BMenuBar(BRect(),"MainMenu",B_FOLLOW_NONE);
	if( menu ) {
		this->AddChild(menu);
		float w=0, h=0;
		menu->GetPreferredSize(&w,&h);
		printf("Preferred Size = (%f,%f)\n",w,h);
		menu->SetFont(be_plain_font);
		menu->GetPreferredSize(&w,&h);
		printf("Preferred Size = (%f,%f)\n",w,h);
		menu->SetFont(be_bold_font);
		menu->GetPreferredSize(&w,&h);
		printf("Preferred Size = (%f,%f)\n",w,h);
		menu->SetFont(be_fixed_font);
		menu->GetPreferredSize(&w,&h);
		printf("Preferred Size = (%f,%f)\n",w,h);
	}
}
开发者ID:HaikuArchives,项目名称:Sequitur,代码行数:60,代码来源:Profile.cpp

示例2: CSelectTeamWindowView

CSelectTeamWindow::CSelectTeamWindow() :
	CSingletonWindow(
		BRect(0,0,10,10), 
		B_TRANSLATE("Select Team"), 
		B_TITLED_WINDOW, 
		B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS, 
		B_CURRENT_WORKSPACE)
{
	static const float windowWidth = 200;
	float windowHeight;

	BView *view = new CSelectTeamWindowView(BRect(0, 0, windowWidth, 10));
	
	view->GetPreferredSize(NULL, &windowHeight);
	view->ResizeToPreferred();

	BRect screenRect = BScreen(this).Frame();
	
	// center window
	float wx = (screenRect.Width()-windowWidth)/2;
	float wy = (screenRect.Height()-windowHeight)/2;

	MoveTo(wx, wy);
	ResizeTo(windowWidth, windowHeight);

	AddChild(view);
	
	Show();
}
开发者ID:HaikuArchives,项目名称:TaskManager,代码行数:29,代码来源:SelectTeamWindow.cpp

示例3: FrameResized

void CSettingsGroup::FrameResized(float width, float height)
{
	CBox::FrameResized(width, height);

	BRect clientRect = ClientRect();

	float ypos = clientRect.top+dist;
	float columnWidth = (clientRect.Width() - numColumns*dist - dist) / numColumns;
	
	for(int32 i=0 ; i<CountChildren() ; i++) {
		BView *child = ChildAt(i);
		
		float childWidth, childHeight;
		
		child->GetPreferredSize(&childWidth, &childHeight);
		
		int32 column = i%numColumns;
		
		child->MoveTo(clientRect.left+column*(columnWidth+dist)+dist, ypos);
		child->ResizeTo(columnWidth, childHeight);
		
		if(((i+1)%numColumns) == 0)
			ypos += childHeight+dist;
	}
}
开发者ID:HaikuArchives,项目名称:TaskManager,代码行数:25,代码来源:SettingsView.cpp

示例4: GetPreferredSize

void ArpConfigurePanel::GetPreferredSize(float* width, float* height)
{
	float maxw=0, maxh=0;
	size_t i;
	
	// Get dimensions of all configuration views.
	for( i=0; i<mConfigViews->size(); i++ ) {
		BView* view = 0;
		if( (view=mConfigViews->at(i)) != 0 ) {
			ArpD(cdb << ADH << "Processing dimens for view #" << i
							<< ", name="
							<< view->Name() << endl);
			float vwidth=0, vheight=0;
			// If this view is not attached to the window (i.e., it
			// is not currently displayed by the tab view), then it
			// may not be able to report correct dimensions.  To fix
			// this, we temporarily add it to your view.
			if( !view->Window() ) {
				ArpD(cdb << ADH << "Temporarily attaching view to window."
							<< endl);
				bool hidden = view->IsHidden();
				view->Hide();
				AddChild(view);
				view->GetPreferredSize(&vwidth, &vheight);
				RemoveChild(view);
				if( !hidden ) view->Show();
			} else {
				view->GetPreferredSize(&vwidth, &vheight);
			}
			ArpD(cdb << ADH << "Preferred width=" << vwidth
							<< ", height=" << vheight << endl);
			if( vwidth > maxw ) maxw = vwidth;
			if( vheight > maxh ) maxh = vheight;
		}
	}
	
	ArpD(cdb << ADH << "Final size=(" << (maxw+mTabWidth)
				<< ", " << (maxh+mTabHeight) << ")" << endl);
				
	if( width ) *width = maxw + mTabWidth + 2;
	if( height ) *height = maxh + mTabHeight + 2;
}
开发者ID:HaikuArchives,项目名称:Sequitur,代码行数:42,代码来源:ArpConfigurePanel.cpp

示例5: ChildAt

void
ToolSelectionWindow::FrameResized(float width, float height)
{
    BView* matrix = ChildAt(0);
    if (matrix != NULL) {
        float tmpHeight;
        matrix->GetPreferredSize(&width, &tmpHeight);
        if ((width != Bounds().Width()) || (tmpHeight != Bounds().Height()))
            ResizeTo(width, height);
    }
}
开发者ID:puckipedia,项目名称:ArtPaint,代码行数:11,代码来源:ToolSelectionWindow.cpp

示例6: rect

void
ScreenshotWindow::_ShowSettings(bool activate)
{
	if (!fSettingsWindow && !activate)
		return;

	// Find a translator
	translator_id translator;
	if (fUtility.FindTranslator(fImageFileType, translator) != B_OK)
		return;

	// Create a window with a configuration view
	BView* view;
	BRect rect(0, 0, 239, 239);

	status_t status = BTranslatorRoster::Default()->MakeConfigurationView(
		translator, NULL, &view, &rect);
	if (status != B_OK || view == NULL) {
		// TODO: proper translation, better error dialog
		BAlert* alert = new BAlert(NULL, strerror(status), "OK");
		alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
		alert->Go();
	} else if (fSettingsWindow != NULL) {
		fSettingsWindow->RemoveChild(fSettingsWindow->ChildAt(0));
		float width, height;
		view->GetPreferredSize(&width, &height);
		fSettingsWindow->ResizeTo(width, height);
		fSettingsWindow->AddChild(view);
		if (activate)
			fSettingsWindow->Activate();
	} else {
		fSettingsWindow = new BWindow(rect,
			B_TRANSLATE("Translator Settings"),
			B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
			B_NOT_ZOOMABLE | B_NOT_RESIZABLE);
		fSettingsWindow->AddFilter(new QuitMessageFilter(this));
		fSettingsWindow->AddChild(view);
		fSettingsWindow->CenterOnScreen();
		fSettingsWindow->Show();
	}
}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:41,代码来源:ScreenshotWindow.cpp

示例7: rect

void
ScreenshotWindow::_ShowSettings(bool activate)
{
	if (!fSettingsWindow && !activate)
		return;

	// Find a translator
	translator_id translator = 0;
	BTranslatorRoster *roster = BTranslatorRoster::Default();
	translator_id* translators = NULL;
	int32 numTranslators = 0;
	if (roster->GetAllTranslators(&translators, &numTranslators) != B_OK)
		return;
	bool foundTranslator = false;
	for (int32 x = 0; x < numTranslators; x++) {
		const translation_format* formats = NULL;
		int32 numFormats;
		if (roster->GetOutputFormats(translators[x], &formats,
			&numFormats) == B_OK) {
			for (int32 i = 0; i < numFormats; ++i) {
				if (formats[i].type == static_cast<uint32>(fImageFileType)) {
					translator = translators[x];
					foundTranslator = true;
					break;
				}
			}
		}
		if (foundTranslator)
			break;
	}
	delete [] translators;
	if (!foundTranslator)
		return;

	// Create a window with a configuration view
	BView *view;
	BRect rect(0, 0, 239, 239);

	status_t err = roster->MakeConfigurationView(translator, NULL, &view,
		&rect);
	if (err < B_OK || view == NULL) {
		BAlert *alert = new BAlert(NULL, strerror(err), "OK");
		alert->Go();
	} else {
		if (fSettingsWindow) {
			fSettingsWindow->RemoveChild(fSettingsWindow->ChildAt(0));
			float width, height;
			view->GetPreferredSize(&width, &height);
			fSettingsWindow->ResizeTo(width, height);
			fSettingsWindow->AddChild(view);
			if (activate)
				fSettingsWindow->Activate();
		} else {
			fSettingsWindow = new BWindow(rect,
				B_TRANSLATE("Translator Settings"),
				B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
				B_NOT_ZOOMABLE | B_NOT_RESIZABLE);
			fSettingsWindow->AddFilter(new QuitMessageFilter(this));
			fSettingsWindow->AddChild(view);
			fSettingsWindow->CenterOnScreen();
			fSettingsWindow->Show();
		}
	}
}
开发者ID:mmadia,项目名称:Haiku-services-branch,代码行数:64,代码来源:ScreenshotWindow.cpp

示例8: BuildGUI


//.........这里部分代码省略.........
					name, _T(desc), enabling);
			
				if (active) ((BCheckBox*)control)->SetValue(B_CONTROL_ON);
				
			} break;			
			default: {
				continue;
			};
		};
		
		if (!value) value = "";
		
		if (!control) {
			if (freeText) {
				if (multiLine == false) {
					control = new BTextControl(
						BRect(0, 0, kControlWidth, fFontHeight), name,
						_T(desc), value, NULL);
					if (secret) {
						((BTextControl *)control)->TextView()->HideTyping(true);
						((BTextControl *)control)->SetText(_T(value));
					};
					((BTextControl *)control)->SetDivider(kDividerWidth);
				} else 
				{
					BRect rect;
					BRect textRect;
					if (desc) //andrea: add description only if available.
					{
						BRect labelRect(0, 0, kDividerWidth, fFontHeight);
						BStringView *label = new BStringView(labelRect, "NA", _T(desc),
							B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
						view->AddChild(label);
						label->MoveTo(kEdgeOffset, yOffset);

						rect = BRect(0, 0, kControlWidth - kDividerWidth, fFontHeight * 4);
						rect.right -= B_V_SCROLL_BAR_WIDTH + kEdgeOffset + kControlOffset;
						xOffset = kEdgeOffset + kDividerWidth;
					}
					else
					{
						rect = BRect(0, 0, kControlWidth, fFontHeight * 4);
						rect.right -= B_V_SCROLL_BAR_WIDTH + kControlOffset;
						xOffset = 0;
					}
					
					textRect = rect;
					textRect.InsetBy(kEdgeOffset, kEdgeOffset);
					textRect.OffsetTo(1.0, 1.0);
						
					BTextView *textView = new BTextView(rect, name, textRect,
						B_FOLLOW_ALL_SIDES, B_WILL_DRAW);

					control = new BScrollView("NA", textView, B_FOLLOW_ALL_SIDES,
						B_WILL_DRAW | B_NAVIGABLE, false, true);
					textView->SetText(_T(value));			
				};
			} else {
				control = new BMenuField(BRect(0, 0, kControlWidth, fFontHeight),
					name, _T(desc), menu);
				
				float size=kDividerWidth;
				if(control->StringWidth(_T(desc)) > kDividerWidth)
					size=control->StringWidth(_T(desc)) + 20;
				
				((BMenuField *)control)->SetDivider(size);
			};
		};
		
		
		view->AddChild(control);
		
		if(enabling)
			 ((BCheckBox*)control)->SetTarget(this);
					
		float h, w = 0;
		control->GetPreferredSize(&w, &h);
		
		if (h < control->Bounds().Height()) 
			h = control->Bounds().Height();
			
		control->MoveTo(kEdgeOffset + xOffset, yOffset);
		yOffset += kControlOffset + h ;
		xOffset = 0;
	};

	for (int j = 0; postAdded.FindString("disable", j); j++) 
	{
			const char* name=postAdded.FindString("disable", j);
			BView*	viewz=view->FindView(name);
			if(viewz)
				((BControl*)viewz)->SetEnabled(false);
			
	}
	
	//if ( yOffset < view->Bounds().Height() )
	//	yOffset = view->Bounds().Height();
	
	return yOffset;//view->ResizeTo( view->Bounds().Width(), yOffset 
}
开发者ID:Haikeek,项目名称:BePodder,代码行数:101,代码来源:PBox.cpp

示例9: MakeTermSettings

void TestWindow::MakeTermSettings()
{
	BView* settings = 0;
	BView* root = 0;
	BWindow* win = 0;
	
	try {
		// Pick some arbitrary initial frame for the window.
		BRect initFrame(0,0,100,100);
		
		// Create our three objects: the settings view, the top-level view
		// in the window, and the window itself.
		settings = GetTermSettings(BMessenger(), BMessage());
		root = new BView(initFrame, "root", B_FOLLOW_ALL, B_WILL_DRAW);
		win = new BWindow(initFrame, "Terminal Settings",
							B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
							B_ASYNCHRONOUS_CONTROLS);
		
		// Set the background color of the root view and add it to the window.
		root->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
		win->AddChild(root);
		
		// Set the size and position of the settings view -- inset a little
		// from the root -- and add it.
		float fw = be_plain_font->StringWidth("W");
		font_height fhs;
		be_plain_font->GetHeight(&fhs);
		float fh = fhs.ascent+fhs.descent+fhs.leading;
		
		settings->MoveTo(fw, fh);
		settings->ResizeTo(initFrame.right-fw*2, initFrame.bottom-fh*2);
		root->AddChild(settings);
		
		win->Run();
		mTermWin = win;
		mTermSet = settings;
		
		if( root ) {
			// Send a message to the view with our current global settings.
			// If the view is an ArpRootView, it will get the message and
			// know what to do with it.
			const BMessage* curGlobs = this->root->Globals()->GlobalValues();
			if( curGlobs ) {
				BMessage globals(*curGlobs);
				globals.what = ARP_PREF_MSG;
				BMessage ret;
				mTermSet.SendMessage(&globals, &ret);
			}
		}
		
		// Get preferred size of settings view, and make final window dimensions
		// from this.
		float width=0, height=0;
		settings->GetPreferredSize(&width, &height);
		width += fw*2;
		height += fh*2;
		
		float minw=0,minh=0,maxw=0,maxh=0;
		win->GetSizeLimits(&minw,&maxw,&minh,&maxh);
		win->SetSizeLimits(width,maxw,height,maxh);
		
		BRect frm = Frame();
		win->ResizeTo(width, height);
		BRect cfrm = Frame();
		win->MoveTo( frm.left
					+ (frm.Width()-cfrm.Width())/2,
				 	frm.top
				 	+ (frm.Height()-cfrm.Height())/2);
		
		win->Show();
		mTermWin = win;
		mTermSet = settings;
	} catch(...) {
		delete settings;
		delete root;
		delete win;
	}
}
开发者ID:HaikuArchives,项目名称:Sequitur,代码行数:78,代码来源:LayoutTest.cpp


注:本文中的BView::GetPreferredSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。