Skip to content

Commit

Permalink
Layout tweaks to Split transaction
Browse files Browse the repository at this point in the history
* Use a checkbox instead of a button for "Show/Hide split".

* Add a horizontal separator as a visual to the "Split" part.

* Keep all text fields a fixed size, only grow the Payee and Memo
  fields when the window is resized.

* Add labels above the text fields in the "Split" view, too.

* Remove the "frame" variable when creating the TransactionEditWindow.
  As we use layout management, there's no need to supply a window size.
  This has the nice consequence that wen opened with the "Split" hidden,
  the window isn't taller than needed.
  Unfortunately, the window doesn't auto-shrink when hiding the "Split"
  again...
  Also: For some reason the window is only horizontally resizable when
  the "Split" is shown. Why?

* Removed unneeded member variables for labels and the help button.

* Removed no longer needed Zeta work-around.
  • Loading branch information
humdingerb committed May 22, 2024
1 parent 3bd9289 commit b2f3ad3
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 76 deletions.
5 changes: 1 addition & 4 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,7 @@ MainWindow::MessageReceived(BMessage* msg)

TransactionData data;
gDatabase.GetTransaction(acc->CurrentTransaction(), data);
BRect r(Frame());
r.right = r.left + 400;
r.bottom = r.top + 300;
TransactionEditWindow* transwin = new TransactionEditWindow(r, data);
TransactionEditWindow* transwin = new TransactionEditWindow(data);
transwin->CenterIn(Frame());
transwin->Show();
break;
Expand Down
163 changes: 98 additions & 65 deletions src/SplitView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <LayoutBuilder.h>
#include <MessageFilter.h>
#include <Messenger.h>
#include <SeparatorView.h>
#include <StringView.h>
#include <Window.h>

Expand Down Expand Up @@ -39,78 +40,101 @@ SplitView::SplitView(const char* name, const TransactionData& trans, const int32
fStartExpanded = false;
fCheckNum = fTransaction.GetAccount()->LastCheckNumber();

fDateLabel = new BStringView("datelabel", B_TRANSLATE("Date"));
// Date
BStringView* dateLabel = new BStringView("datelabel", B_TRANSLATE("Date"));
dateLabel->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));

fDate = new DateBox("dateentry", "", "text", new BMessage(M_DATE_CHANGED));
// fDate->SetEscapeCancel(true);
fDate->SetDate(trans.Date());

BString tempstr;
gDefaultLocale.DateToString(fTransaction.Date(), tempstr);
fDate->SetText(tempstr.String());

fType = new CheckNumBox("typeentry", "", NULL, new BMessage(M_TYPE_CHANGED));
// Type
BStringView* typeLabel = new BStringView("typelabel", B_TRANSLATE("Type"));
typeLabel->SetExplicitSize(BSize(StringWidth("ShortType"), B_SIZE_UNSET));

fType = new CheckNumBox("typeentry", "", NULL, new BMessage(M_TYPE_CHANGED));
fType->SetText(fTransaction.Type().Type());

fTypeLabel = new BStringView("typelabel", B_TRANSLATE("Type"));
// Payee
BStringView* payeeLabel = new BStringView("payeelabel", B_TRANSLATE("Payee"));
payeeLabel->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));

fPayee = new PayeeBox("payeeentry", "", fTransaction.Payee(), new BMessage(M_PAYEE_CHANGED));
fPayee->SetExplicitMinSize(BSize(StringWidth("QuiteLongPayeesName"), B_SIZE_UNSET));

fPayeeLabel = new BStringView("payeelabel", B_TRANSLATE("Payee"));
// Amount
BStringView* amountLabel = new BStringView("amountlabel", B_TRANSLATE("Amount"));
amountLabel->SetExplicitSize(BSize(StringWidth("$10,000,000,000.00"), B_SIZE_UNSET));

fAmount = new CurrencyBox("amountentry", "", NULL, new BMessage(M_AMOUNT_CHANGED));

gCurrentLocale.CurrencyToString(
(fTransaction.Amount() < 0) ? fTransaction.Amount().InvertAsCopy() : fTransaction.Amount(),
tempstr);
fAmount->SetText(tempstr.String());

fAmountLabel = new BStringView("amountlabel", B_TRANSLATE("Amount"));

fCategoryLabel = new BStringView("categorylabel", B_TRANSLATE("Category"));
// Category
BStringView* categoryLabel = new BStringView("categorylabel", B_TRANSLATE("Category"));
categoryLabel->SetExplicitSize(BSize(StringWidth("aVeryLongCategoryName"), B_SIZE_UNSET));

fCategory = new CategoryBox(
"categoryentry", "", fTransaction.NameAt(0), new BMessage(M_CATEGORY_CHANGED));

fMemoLabel = new BStringView("memolabel", B_TRANSLATE("Memo"));
// Memo
BStringView* memoLabel = new BStringView("memolabel", B_TRANSLATE("Memo"));
memoLabel->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));

fMemo = new NavTextBox("memoentry", "", fTransaction.Memo(), new BMessage(M_MEMO_CHANGED));

fSplit = new BButton(
"expander", B_TRANSLATE("Show Split"), new BMessage(M_EXPANDER_CHANGED), B_WILL_DRAW);
// Controls
fSplit = new BCheckBox(
"expander", B_TRANSLATE("Show split"), new BMessage(M_EXPANDER_CHANGED), B_WILL_DRAW);
fSplit->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));

fHelpButton = new HelpButton(B_TRANSLATE("Help: Transaction editor"), "Transaction Editor.txt");
HelpButton* helpButton = new HelpButton(B_TRANSLATE("Help: Transaction editor"),
"Transaction Editor.txt");

// SplitContainer
fSplitContainer = new BView("splitcontainer", B_WILL_DRAW);
fSplitContainer->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
fSplitContainer->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
fSplitContainer->Hide();

fAddSplit = new BButton("addsplit", B_TRANSLATE("Add item"), new BMessage(M_ADD_SPLIT));

fRemoveSplit =
new BButton("removesplit", B_TRANSLATE("Remove item"), new BMessage(M_REMOVE_SPLIT));

fSplitCategory = new BTextControl("splitcategory", NULL, NULL, NULL, B_WILL_DRAW);
BString totalLabel(B_TRANSLATE("Total:"));
totalLabel << " " << fTransaction.Amount().AbsoluteValue().AsFloat();
fSplitTotal = new BStringView("splittotal", totalLabel.String());
fSplitTotal->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));

fEnter = new BButton("enterbutton", B_TRANSLATE("Enter"), new BMessage(M_ENTER_TRANSACTION));

#ifndef ENTER_NAVIGATION
fEnter->MakeDefault(true);
#endif

// Split category
BStringView* splitCategoryLabel = new BStringView("categorylabel", B_TRANSLATE("Category"));
splitCategoryLabel->SetExplicitSize(BSize(StringWidth("aVeryLongCategoryName"), B_SIZE_UNSET));
fSplitCategory = new BTextControl("splitcategory", NULL, NULL, NULL, B_WILL_DRAW);

// Split amount
BStringView* splitAmountLabel = new BStringView("amountlabel", B_TRANSLATE("Amount"));
splitAmountLabel->SetExplicitSize(BSize(StringWidth("$10,000,000,000.00"), B_SIZE_UNSET));
fSplitAmount = new BTextControl("splitamount", NULL, NULL, NULL, B_WILL_DRAW);

// Split memo
BStringView* splitMemoLabel = new BStringView("memolabel", B_TRANSLATE("Memo"));
splitMemoLabel->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
fSplitMemo = new BTextControl("splitmemo", NULL, NULL, NULL, B_WILL_DRAW);

// Split list
fSplitItems = new BListView("splititems");
fSplitItems->SetSelectionMessage(new BMessage(M_SELECT_SPLIT));
fSplitScroller = new BScrollView("split scroller", fSplitItems, 0, false, true);

BString totallabel(B_TRANSLATE("Total:"));
totallabel << " " << fTransaction.Amount().AbsoluteValue().AsFloat();
fSplitTotal = new BStringView("splittotal", totallabel.String());
fSplitContainer->Hide();

fEnter = new BButton("enterbutton", B_TRANSLATE("Enter"), new BMessage(M_ENTER_TRANSACTION));

#ifndef ENTER_NAVIGATION
fEnter->MakeDefault(true);
#endif
fSplitScroller->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));

fKeyFilter = new SplitViewFilter(this);

Expand All @@ -128,7 +152,6 @@ SplitView::SplitView(const char* name, const TransactionData& trans, const int32
fSplitItems->AddItem(item);
}


if (fTransaction.CountCategories() > 1 ||
strcmp(fTransaction.NameAt(0), B_TRANSLATE("Split")) == 0) {
fCategory->SetText(B_TRANSLATE("Split transaction"));
Expand All @@ -137,42 +160,56 @@ SplitView::SplitView(const char* name, const TransactionData& trans, const int32

BLayoutBuilder::Group<>(fSplitContainer, B_VERTICAL, 0)
.SetInsets(0)
.Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER))
.AddStrut(B_USE_SMALL_SPACING)
.AddGrid(1.0f, 0.0f)
.Add(fAddSplit, 0, 0)
.Add(fRemoveSplit, 1, 0)
.AddGlue(2, 0)
.Add(fSplitTotal, 3, 0)
.AddGlue(4, 0)
.End()
.Add(fAddSplit, 0, 0)
.Add(fRemoveSplit, 1, 0)
.AddGlue(2, 0)
.Add(fSplitTotal, 3, 0)
.AddGlue(4, 0)
.End()
.AddStrut(B_USE_SMALL_SPACING)
.AddGrid(1.0f, 0.0f)
.Add(fSplitCategory, 0, 0)
.Add(fSplitAmount, 1, 0)
.Add(fSplitMemo, 3, 0)
.End()
.SetColumnWeight(2, 2.0f)
.Add(splitCategoryLabel, 0, 0)
.Add(fSplitCategory, 0, 1)
.Add(splitAmountLabel, 1, 0)
.Add(fSplitAmount, 1, 1)
.Add(splitMemoLabel, 2, 0)
.Add(fSplitMemo, 2, 1)
.End()
.Add(fSplitScroller)
.End();
BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
.SetInsets(10)

BLayoutBuilder::Group<>(this, B_VERTICAL, B_USE_DEFAULT_SPACING)
.SetInsets(B_USE_WINDOW_SPACING)
.AddGrid(1.0f, 0.0f)
.Add(fDateLabel, 0, 0)
.Add(fDate, 0, 1, 2)
.Add(fTypeLabel, 2, 0)
.Add(fType, 2, 1)
.Add(fPayeeLabel, 3, 0)
.Add(fPayee, 3, 1, 2)
.Add(fAmountLabel, 5, 0)
.Add(fAmount, 5, 1, 2)
.Add(fCategoryLabel, 0, 2)
.Add(fCategory, 0, 3, 3)
.Add(fMemoLabel, 3, 2)
.Add(fMemo, 3, 3, 4)
.Add(fSplit, 0, 5)
.Add(fHelpButton, 1, 5)
.Add(fEnter, 6, 5)
.End()
// .SetColumnWeight(1, 0.5f)
.SetColumnWeight(2, 2.0f)
.SetColumnWeight(3, 1.0f)
.Add(dateLabel, 0, 0)
.Add(fDate, 0, 1)
.Add(typeLabel, 1, 0)
.Add(fType, 1, 1)
.Add(payeeLabel, 2, 0)
.Add(fPayee, 2, 1)
.Add(amountLabel, 3, 0)
.Add(fAmount, 3, 1)
.Add(categoryLabel, 0, 2)
.Add(fCategory, 0, 3)
.Add(memoLabel, 1, 2, 3)
.Add(fMemo, 1, 3, 3)
.End()
.AddGroup(B_HORIZONTAL)
.Add(fSplit)
.AddGlue()
.Add(helpButton)
.Add(fEnter)
.End()
.AddGroup(B_VERTICAL, 0.0f)
.Add(fSplitContainer)
.End()
.Add(fSplitContainer)
.End()
.End();
}

Expand Down Expand Up @@ -683,18 +720,14 @@ void
SplitView::ToggleSplit(void)
{
if (fSplitContainer->IsHidden()) {
fSplit->SetLabel(B_TRANSLATE("Hide split"));
fSplit->SetValue(B_CONTROL_ON);

fSplitContainer->Show();
fCategory->SetEnabled(false);
if (fCategory->ChildAt(0)->IsFocus())
fMemo->MakeFocus();

// These calls are needed because of some stupid resize-related bugs in Zeta. :/
Invalidate();
fEnter->Invalidate();
} else {
fSplit->SetLabel(B_TRANSLATE("Show split"));
fSplit->SetValue(B_CONTROL_OFF);

fSplitContainer->Hide();
fCategory->SetEnabled(true);
Expand Down
5 changes: 2 additions & 3 deletions src/SplitView.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ class SplitView : public BView, public Observer {
CurrencyBox* fAmount;
CategoryBox* fCategory;
NavTextBox* fMemo;
BStringView *fDateLabel, *fTypeLabel, *fPayeeLabel, *fAmountLabel, *fCategoryLabel, *fMemoLabel;
SplitViewFilter* fKeyFilter;
BMessenger* fMessenger;
BButton *fEnter, *fTransfer, *fSplit;
BButton *fEnter, *fTransfer;
BCheckBox* fSplit;

BView* fSplitContainer;
BTextControl *fSplitCategory, *fSplitAmount, *fSplitMemo;
Expand All @@ -86,7 +86,6 @@ class SplitView : public BView, public Observer {
BButton *fAddSplit, *fRemoveSplit;
BStringView* fSplitTotal;
BCheckBox* fReconciled;
HelpButton* fHelpButton;

time_t fCurrentDate;
bool fStartExpanded;
Expand Down
9 changes: 6 additions & 3 deletions src/TransactionEditWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
#define M_TOGGLE_SPLIT 'tspl'


TransactionEditWindow::TransactionEditWindow(const BRect& frame, const TransactionData& trans)
: BWindow(frame, B_TRANSLATE("Edit transaction"), B_DOCUMENT_WINDOW_LOOK,
TransactionEditWindow::TransactionEditWindow(const TransactionData& trans)
: BWindow(BRect(), B_TRANSLATE("Edit transaction"), B_DOCUMENT_WINDOW_LOOK,
B_FLOATING_APP_WINDOW_FEEL, B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE)
{
fSplitView = new SplitView("splitview", trans, B_WILL_DRAW);
BLayoutBuilder::Group<>(this, B_VERTICAL, 0).SetInsets(0).Add(fSplitView).End();
BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
.SetInsets(0)
.Add(fSplitView)
.End();

AddShortcut('S', B_COMMAND_KEY, new BMessage(M_TOGGLE_SPLIT));
AddShortcut('A', B_COMMAND_KEY, new BMessage(M_ADD_SPLIT));
Expand Down
2 changes: 1 addition & 1 deletion src/TransactionEditWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TransactionData;

class TransactionEditWindow : public BWindow {
public:
TransactionEditWindow(const BRect& frame, const TransactionData& trans);
TransactionEditWindow(const TransactionData& trans);
void MessageReceived(BMessage* msg);

private:
Expand Down

0 comments on commit b2f3ad3

Please sign in to comment.