HaikuDepot: BGroupView for the controls defining list contents

This commit is contained in:
Stephan Aßmus 2013-07-27 22:21:58 +02:00
parent d9512848e4
commit 8608501abb
2 changed files with 124 additions and 0 deletions

View File

@ -0,0 +1,95 @@
/*
* Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "FilterView.h"
#include <algorithm>
#include <stdio.h>
#include <Catalog.h>
#include <LayoutBuilder.h>
#include <MenuField.h>
#include <MenuItem.h>
#include <Messenger.h>
#include <PopUpMenu.h>
#include <TextControl.h>
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "FilterView"
enum {
MSG_CATEGORY_SELECTED = 'ctsl',
MSG_REPOSITORY_SELECTED = 'rpsl',
MSG_SEARCH_TERMS_MODIFIED = 'stmd',
};
FilterView::FilterView()
:
BGroupView("filter view")
{
// Contruct category popup
BPopUpMenu* categoryMenu = new BPopUpMenu(B_TRANSLATE("Category"));
fCategoryField = new BMenuField("category", B_TRANSLATE("Category:"),
categoryMenu);
// Construct repository popup
BPopUpMenu* repositoryMenu = new BPopUpMenu(B_TRANSLATE("Depot"));
fRepositoryField = new BMenuField("repository", B_TRANSLATE("Depot:"),
repositoryMenu);
// Construct search terms field
fSearchTermsText = new BTextControl("search terms",
B_TRANSLATE("Search terms:"), "", NULL);
fSearchTermsText->SetModificationMessage(
new BMessage(MSG_SEARCH_TERMS_MODIFIED));
BSize minSearchSize = fSearchTermsText->MinSize();
float minSearchWidth
= be_plain_font->StringWidth(fSearchTermsText->Label())
+ be_plain_font->StringWidth("XXX") * 6;
minSearchWidth = std::max(minSearchSize.width, minSearchWidth);
minSearchSize.width = minSearchWidth;
fSearchTermsText->SetExplicitMinSize(minSearchSize);
float maxSearchWidth = minSearchWidth * 2;
fSearchTermsText->SetExplicitMaxSize(BSize(maxSearchWidth, B_SIZE_UNSET));
// Build layout
BLayoutBuilder::Group<>(this)
.Add(fCategoryField, 0.0f)
.Add(fRepositoryField, 0.0f)
.AddGlue(0.5f)
.Add(fSearchTermsText, 1.0f)
.SetInsets(B_USE_DEFAULT_SPACING)
;
}
FilterView::~FilterView()
{
}
void
FilterView::AttachedToWindow()
{
fCategoryField->Menu()->SetTargetForItems(this);
fRepositoryField->Menu()->SetTargetForItems(this);
fSearchTermsText->SetTarget(this);
}
void
FilterView::MessageReceived(BMessage* message)
{
switch (message->what) {
default:
BGroupView::MessageReceived(message);
break;
}
}

View File

@ -0,0 +1,29 @@
/*
* Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef FILTER_VIEW_H
#define FILTER_VIEW_H
#include <GroupView.h>
class BMenuField;
class BTextControl;
class FilterView : public BGroupView {
public:
FilterView();
virtual ~FilterView();
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage* message);
private:
BMenuField* fCategoryField;
BMenuField* fRepositoryField;
BTextControl* fSearchTermsText;
};
#endif // FILTER_VIEW_H