HaikuDepot: BGroupView for the controls defining list contents
This commit is contained in:
@@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013, Stephan Aßmus <[email protected]>.
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013, Stephan Aßmus <[email protected]>.
|
||||||
|
* 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
|
||||||
Reference in New Issue
Block a user