-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add filter view: the GUI side, no actually filtering
* Add BMenu to choose a time period to filter, e.g. "This month". * Add BTextControls to filter for payee, category, memo, amount. * Add BMenu to choose <= or = or >= for the amount filtering. * Add BButtons to "Clear" the filter or "Filter" with the current settings. * When filtering is invoked, send a BMessage to the RegisterView with all the filter settings. For the fPeriodMenu and fCompareMenus, the index of the marked menu item is added to the BMessage. The order of the fPeriodMenu items should reflect filter_period_field in RegisterView.h. Those will be used when parsing the BMessage for the actual filtering. As the fCompareMenu only holds 3 items, we'll just test for 0, 1, 2. * Removed GetAccountViewWidth() because the new filter view will determine the width of the left sidebar, not the widest account name.
- Loading branch information
1 parent
7d56c53
commit d817ec5
Showing
5 changed files
with
263 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
#include <Catalog.h> | ||
#include <GridLayout.h> | ||
#include <LayoutBuilder.h> | ||
#include <Messenger.h> | ||
#include <String.h> | ||
#include <StringView.h> | ||
#include <Window.h> | ||
#include <stdlib.h> | ||
|
||
#include "FilterView.h" | ||
#include "RegisterView.h" | ||
|
||
|
||
#undef B_TRANSLATION_CONTEXT | ||
#define B_TRANSLATION_CONTEXT "FilterView" | ||
|
||
|
||
FilterView::FilterView(const char* name, int32 flags) | ||
: BView(name, flags | B_FRAME_EVENTS), | ||
fMessenger(NULL) | ||
{ | ||
BMenu* fPeriodMenu = new BMenu("timeperiod"); | ||
// Important: keep the order according to filter_period_field in RegisterView.h | ||
fPeriodMenu->AddItem(new BMenuItem(B_TRANSLATE("All transactions"), new BMessage(M_FILTER_CHANGED))); | ||
fPeriodMenu->AddItem(new BMenuItem(B_TRANSLATE("This month"), new BMessage(M_FILTER_CHANGED))); | ||
fPeriodMenu->AddItem(new BMenuItem(B_TRANSLATE("Last month"), new BMessage(M_FILTER_CHANGED))); | ||
fPeriodMenu->AddItem(new BMenuItem(B_TRANSLATE("This quarter"), new BMessage(M_FILTER_CHANGED))); | ||
fPeriodMenu->AddItem(new BMenuItem(B_TRANSLATE("Last quarter"), new BMessage(M_FILTER_CHANGED))); | ||
fPeriodMenu->AddItem(new BMenuItem(B_TRANSLATE("This year"), new BMessage(M_FILTER_CHANGED))); | ||
fPeriodMenu->AddItem(new BMenuItem(B_TRANSLATE("Last year"), new BMessage(M_FILTER_CHANGED))); | ||
|
||
fPeriodMenu->SetLabelFromMarked(true); | ||
fPeriodMenu->SetRadioMode(true); | ||
fPeriodMenu->ItemAt(0L)->SetMarked(true); | ||
|
||
BMenuField* periodField = new BMenuField("periodfield", B_TRANSLATE("Period:"), fPeriodMenu); | ||
|
||
float maxwidth = 0; | ||
for (int32 i = 0; i < fPeriodMenu->CountItems(); i++) { | ||
BMenuItem* item = fPeriodMenu->ItemAt(i); | ||
float labelwidth = StringWidth(item->Label()); | ||
maxwidth = MAX(labelwidth, maxwidth); | ||
} | ||
fPeriodMenu->SetExplicitSize(BSize(maxwidth + 20, B_SIZE_UNSET)); | ||
|
||
BString label(B_TRANSLATE_CONTEXT("Payee", "CommonTerms")); | ||
label << ":"; | ||
fPayee = new BTextControl("payee", label, NULL, new BMessage(M_FILTER_CHANGED)); | ||
|
||
label = B_TRANSLATE_CONTEXT("Category", "CommonTerms"); | ||
label << ":"; | ||
fCategory = new BTextControl("category", label, NULL, new BMessage(M_FILTER_CHANGED)); | ||
|
||
label = B_TRANSLATE_CONTEXT("Memo", "CommonTerms"); | ||
label << ":"; | ||
fMemo = new BTextControl("memo", label, NULL, new BMessage(M_FILTER_CHANGED)); | ||
|
||
fCompareMenu = new BMenu(""); | ||
fCompareMenu->AddItem(new BMenuItem("≦", new BMessage(M_FILTER_CHANGED))); | ||
fCompareMenu->AddItem(new BMenuItem("≧", new BMessage(M_FILTER_CHANGED))); | ||
|
||
fCompareMenu->SetLabelFromMarked(true); | ||
fCompareMenu->SetRadioMode(true); | ||
fCompareMenu->ItemAt(0L)->SetMarked(true); | ||
|
||
BMenuField* compareField = new BMenuField("compareField", "", fCompareMenu); | ||
compareField->SetExplicitSize(BSize(StringWidth("≦") * 2, B_SIZE_UNSET)); | ||
|
||
label = B_TRANSLATE_CONTEXT("Amount", "CommonTerms"); | ||
label << ":"; | ||
fAmount = new BTextControl("amount", label, NULL, new BMessage(M_FILTER_CHANGED)); | ||
|
||
fClear = new BButton("clearbutton", B_TRANSLATE("Clear"), new BMessage(M_CLEAR_FILTER)); | ||
fFilter = new BButton("startbutton", B_TRANSLATE("Filter"), new BMessage(M_START_FILTER)); | ||
|
||
// clang-format off | ||
BView* amountWidget = new BView("amountWidget", B_WILL_DRAW); | ||
BLayoutBuilder::Group<>(amountWidget, B_HORIZONTAL, -2) | ||
.Add(compareField) | ||
.Add(fAmount->CreateTextViewLayoutItem()) | ||
.End(); | ||
|
||
BLayoutBuilder::Group<>(this, B_VERTICAL, 0) | ||
.SetInsets(0) | ||
.AddGrid(0.0, B_USE_SMALL_SPACING) | ||
.Add(periodField->CreateLabelLayoutItem(), 0, 0) | ||
.Add(periodField->CreateMenuBarLayoutItem(), 1, 0) | ||
.Add(fPayee->CreateLabelLayoutItem(), 0, 1) | ||
.Add(fPayee->CreateTextViewLayoutItem(), 1, 1) | ||
.Add(fCategory->CreateLabelLayoutItem(), 0, 2) | ||
.Add(fCategory->CreateTextViewLayoutItem(), 1, 2) | ||
.Add(fMemo->CreateLabelLayoutItem(), 0, 3) | ||
.Add(fMemo->CreateTextViewLayoutItem(),1, 3) | ||
.Add(new BStringView("amountlabel", label), 0, 4) | ||
.Add(amountWidget, 1, 4) | ||
.End() | ||
.AddStrut(B_USE_BIG_SPACING) | ||
.AddGroup(B_HORIZONTAL) | ||
.Add(fClear) | ||
.Add(fFilter) | ||
.End() | ||
.End(); | ||
// clang-format on | ||
} | ||
|
||
|
||
FilterView::~FilterView(void) | ||
{ | ||
} | ||
|
||
|
||
void | ||
FilterView::AttachedToWindow(void) | ||
{ | ||
// fPeriodMenu->SetTargetForItems(this); | ||
fCompareMenu->SetTargetForItems(this); | ||
fPayee->SetTarget(this); | ||
fCategory->SetTarget(this); | ||
fMemo->SetTarget(this); | ||
fAmount->SetTarget(this); | ||
fClear->SetTarget(this); | ||
fFilter->SetTarget(this); | ||
} | ||
|
||
|
||
void | ||
FilterView::MessageReceived(BMessage* msg) | ||
{ | ||
int32 start; | ||
BString string; | ||
switch (msg->what) { | ||
case M_START_FILTER: | ||
case M_FILTER_CHANGED: | ||
{ | ||
BMessage filterMsg(M_FILTER); | ||
filterMsg.AddString("payee", fPayee->Text()); | ||
filterMsg.AddString("category", fCategory->Text()); | ||
filterMsg.AddString("memo", fMemo->Text()); | ||
filterMsg.AddString("amount", fAmount->Text()); | ||
filterMsg.AddInt32("moreless", fCompareMenu->FindMarkedIndex()); | ||
filterMsg.AddInt32("period", fPeriodMenu->FindMarkedIndex()); | ||
|
||
fMessenger->SendMessage(&filterMsg); | ||
break; | ||
} | ||
case M_CLEAR_FILTER: | ||
{ | ||
fPayee->SetText(""); | ||
fCategory->SetText(""); | ||
fMemo->SetText(""); | ||
fAmount->SetText(""); | ||
fCompareMenu->ItemAt(0)->SetMarked(true); | ||
// fPeriodMenu->ItemAt(0)->SetMarked(true); | ||
break; | ||
} | ||
default: | ||
{ | ||
BView::MessageReceived(msg); | ||
} | ||
} | ||
} | ||
|
||
|
||
void | ||
FilterView::MakeEmpty(void) | ||
{ | ||
fPeriodMenu->ItemAt(0L)->SetMarked(true); | ||
fPayee->SetText(""); | ||
fCategory->SetText(""); | ||
fMemo->SetText(""); | ||
fCompareMenu->ItemAt(0L)->SetMarked(true); | ||
fAmount->SetText(""); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#ifndef FILTERVIEW_H | ||
#define FILTERVIEW_H | ||
|
||
#include <Button.h> | ||
#include <Menu.h> | ||
#include <TextControl.h> | ||
#include <View.h> | ||
|
||
|
||
enum { | ||
M_FILTER_CHANGED = 'flch', | ||
M_CLEAR_FILTER = 'clar', | ||
M_START_FILTER = 'strt', | ||
}; | ||
|
||
|
||
class FilterView : public BView { | ||
public: | ||
FilterView(const char* name, int32 flags); | ||
~FilterView(void); | ||
|
||
void AttachedToWindow(void); | ||
void MessageReceived(BMessage* msg); | ||
|
||
void SetMessenger(BMessenger* msgr) { fMessenger = msgr; }; | ||
|
||
private: | ||
void MakeEmpty(void); | ||
|
||
BMenu* fPeriodMenu; | ||
BMenu* fCompareMenu; | ||
|
||
BTextControl* fPayee; | ||
BTextControl* fCategory; | ||
BTextControl* fMemo; | ||
BTextControl* fAmount; | ||
|
||
BButton* fClear; | ||
BButton* fFilter; | ||
|
||
BMessenger* fMessenger; | ||
}; | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d817ec5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few headscratcher ATM: