Skip to content

Commit

Permalink
Use layout management, added localization
Browse files Browse the repository at this point in the history
Added de.catkeys and en.catkeys
  • Loading branch information
humdingerb committed Dec 9, 2023
1 parent 5c82f8b commit 640b485
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 95 deletions.
70 changes: 35 additions & 35 deletions preflet/ModifierBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,58 +12,58 @@
#include "ModifierBox.h"
#include "ModifierView.h"

#include <Catalog.h>
#include <LayoutBuilder.h>

#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "ModifierBox"


const ModifierBox::MaskListType ModifierBox::ModifierList[] =
{
{ B_SHIFT_KEY, "Shift" },
{ B_CONTROL_KEY, "Control" },
{ B_COMMAND_KEY, "Command" },
{ B_OPTION_KEY, "Option" },
{ B_MENU_KEY, "Menu" }
{ B_SHIFT_KEY, B_TRANSLATE("Shift") },
{ B_CONTROL_KEY, B_TRANSLATE("Control") },
{ B_COMMAND_KEY, B_TRANSLATE("Command") },
{ B_OPTION_KEY, B_TRANSLATE("Option") },
{ B_MENU_KEY, B_TRANSLATE("Menu") }
};


ModifierBox::ModifierBox(BRect frame, const char* label, uint32 modifier, uint32 /*button*/)
ModifierBox::ModifierBox(const char* label, uint32 modifier, uint32 /*button*/)
:
BBox(frame),
BBox(label),
fDefaultModifier(0)
{
if (label)
SetLabel(label);

float right = 0;
float bottom;
BRect rect(10, 15, 10, 15);

fModifierViewList = new ModifierView*[5];

BFont f = be_plain_font;
float width = f.StringWidth("Command");
width += 20;

fModifierViewList[0] = new ModifierView(BRect(10, 15, 10 + width, 15), ModifierList[0].mask,
fModifierViewList[0] = new ModifierView(ModifierList[0].mask,
ModifierList[0].label, ModifierList[0].mask & modifier, new BMessage(MODIFIER_CHANGED));
fModifierViewList[1] = new ModifierView(BRect(10, 35, 10 + width, 45), ModifierList[1].mask,
fModifierViewList[1] = new ModifierView(ModifierList[1].mask,
ModifierList[1].label, ModifierList[1].mask & modifier, new BMessage(MODIFIER_CHANGED));
fModifierViewList[2] = new ModifierView(BRect(10, 55, 10 + width, 65), ModifierList[2].mask,
fModifierViewList[2] = new ModifierView(ModifierList[2].mask,
ModifierList[2].label, ModifierList[2].mask & modifier, new BMessage(MODIFIER_CHANGED));
fModifierViewList[3]
= new ModifierView(BRect(15 + width, 15, 75 + width, 15), ModifierList[3].mask,
ModifierList[3].label, ModifierList[3].mask & modifier, new BMessage(MODIFIER_CHANGED));
fModifierViewList[4]
= new ModifierView(BRect(15 + width, 35, 75 + width, 45), ModifierList[4].mask,
ModifierList[4].label, ModifierList[4].mask & modifier, new BMessage(MODIFIER_CHANGED));

for (int32 i = 0; i < 5; i++) {
fModifierViewList[i]->ResizeToPreferred();
AddChild(fModifierViewList[i]);

right = max_c(right, fModifierViewList[i]->Frame().right);
rect.OffsetTo(rect.left, fModifierViewList[i]->Frame().bottom + 5);
}

bottom = fModifierViewList[5 - 1]->Frame().bottom;
ResizeTo(right + 10, bottom + 30);
fModifierViewList[3] = new ModifierView(ModifierList[3].mask,
ModifierList[3].label, ModifierList[3].mask & modifier, new BMessage(MODIFIER_CHANGED));
fModifierViewList[4] = new ModifierView(ModifierList[4].mask,
ModifierList[4].label, ModifierList[4].mask & modifier, new BMessage(MODIFIER_CHANGED));

BLayoutBuilder::Group<>(this, B_HORIZONTAL, B_USE_DEFAULT_SPACING)
.SetInsets(B_USE_ITEM_INSETS)
.AddGroup(B_VERTICAL, 0)
.SetInsets(0, B_USE_DEFAULT_SPACING, 0, 0)
.Add(fModifierViewList[0])
.Add(fModifierViewList[1])
.Add(fModifierViewList[2])
.End()
.AddGroup(B_VERTICAL, 0)
.SetInsets(0, B_USE_DEFAULT_SPACING, 0, 0)
.Add(fModifierViewList[3])
.Add(fModifierViewList[4])
.AddGlue()
.End();
}


Expand Down
5 changes: 2 additions & 3 deletions preflet/ModifierBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class ModifierView;
class ModifierBox : public BInvoker, public BBox
{
public:
ModifierBox(BRect frame, const char* label = 0, uint32 modifier = 0,
uint32 button = 0);
ModifierBox(const char* label = 0, uint32 modifier = 0, uint32 button = 0);
~ModifierBox();

virtual void MessageReceived(BMessage* message);
Expand All @@ -35,7 +34,7 @@ class ModifierBox : public BInvoker, public BBox
private:
struct MaskListType
{
uint32 mask;
uint32 mask;
const char* label;
};

Expand Down
5 changes: 2 additions & 3 deletions preflet/ModifierView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
#include "ModifierView.h"


ModifierView::ModifierView(
BRect frame, uint32 modifierMask, const char* label, bool initialValue, BMessage* msg)
ModifierView::ModifierView(uint32 modifierMask, const char* label, bool initialValue, BMessage* msg)
:
BCheckBox(frame, "", label, msg),
BCheckBox(NULL, label, msg),
fModifierMask(modifierMask)
{
SetValue(initialValue);
Expand Down
3 changes: 1 addition & 2 deletions preflet/ModifierView.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
class ModifierView : public BCheckBox
{
public:
ModifierView(BRect frame, uint32 modifierMask, const char* label,
bool initialValue, BMessage* msg);
ModifierView(uint32 modifierMask, const char* label, bool initialValue, BMessage* msg);
~ModifierView();

uint32 GetMask();
Expand Down
81 changes: 32 additions & 49 deletions preflet/SettingsWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

#include <Application.h>
#include <Box.h>
#include <Catalog.h>
#include <LayoutBuilder.h>
#include <Screen.h>
#include <SeparatorView.h>
#include <Slider.h>
#include <String.h>
#include <TextView.h>
Expand All @@ -23,73 +26,53 @@
#include <stdlib.h>


#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "SettingsWindow"

SettingsWin::SettingsWin()
:
BWindow(BRect(100, 100, 400, 300), "KeyCursor Settings", B_TITLED_WINDOW,
B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
BWindow(BRect(100, 100, 500, 300), B_TRANSLATE("KeyCursor settings"), B_TITLED_WINDOW,
B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS)
{
fBGView = new BView(BRect(Bounds()), "", B_FOLLOW_ALL_SIDES, B_WILL_DRAW);
fBGView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(fBGView);

fEnabled = new BCheckBox(
BRect(10, 5, 10, 10), "fEnabled", "Enable KeyCursor", new BMessage(ENABLED_CHANGED));
fEnabled = new BCheckBox("enable", B_TRANSLATE("Enable KeyCursor"),
new BMessage(ENABLED_CHANGED));
fEnabled->SetValue(fPrefs.GetEnabled());
fEnabled->ResizeToPreferred();
fBGView->AddChild(fEnabled);

fEnabled->MakeFocus(true);

float right;
float bottom;
BRect frame;

frame = BRect(10, fEnabled->Frame().bottom + 10, 10, fEnabled->Frame().bottom + 10);

fModBox = new ModifierBox(
frame, "Toggle Keys", fPrefs.GetToggleModMask(), fPrefs.GetClickKeyMask());
fModBox = new ModifierBox(B_TRANSLATE("Toggle keys"), fPrefs.GetToggleModMask(),
fPrefs.GetClickKeyMask());
fModBox->SetDefaultModifierMask(fPrefs.GetDefaultClickKeyMask());

fModBox->SetMessage(new BMessage(TOGGLE_CHANGED));
fModBox->SetTarget(this);
fBGView->AddChild(fModBox);

fModBox->SetEnabled(fPrefs.GetEnabled());

bottom = fModBox->Frame().bottom;
right = fModBox->Frame().right;

fAccelSlider
= new BSlider(BRect(10, fModBox->Frame().bottom + 10, 10, fModBox->Frame().bottom + 10),
"accel_slider", "Acceleration Factor", new BMessage(ACCEL_CHANGED), 0, 40);
fAccelSlider = new BSlider("accel_slider", B_TRANSLATE("Acceleration"),
new BMessage(ACCEL_CHANGED), 0, 40, B_HORIZONTAL);

fAccelSlider->SetKeyIncrementValue(10);
fAccelSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
fAccelSlider->SetHashMarkCount(5);
fAccelSlider->SetValue(fPrefs.GetAcceleration());
fAccelSlider->SetLimitLabels("Mix", "Max");

fAccelSlider->ResizeToPreferred();
fAccelSlider->ResizeTo(fModBox->Frame().Width() - 2, fAccelSlider->Frame().Height());

fBGView->AddChild(fAccelSlider);

fAccelSlider->SetLimitLabels(B_TRANSLATE("Min"), B_TRANSLATE("Max"));
fAccelSlider->SetEnabled(fPrefs.GetEnabled());

bottom = fAccelSlider->Frame().bottom;
ResizeTo(right + 10, bottom);

MoveTo(fPrefs.WindowCorner());

// Code to make sure that the window doesn't get drawn off screen...
{
BScreen screen;

if (!(screen.Frame().right >= Frame().right && screen.Frame().bottom >= Frame().bottom)) {
MoveTo((screen.Frame().right - Bounds().right) * 0.5,
(screen.Frame().bottom - Bounds().bottom) * 0.5);
}
}
BFont font = *be_plain_font;
fAccelSlider->SetExplicitMinSize(
BSize(font.StringWidth("Quite a long string as window min width"),B_SIZE_UNSET));

BLayoutBuilder::Group<>(this, B_VERTICAL)
.AddGroup(B_VERTICAL)
.SetInsets(B_USE_WINDOW_INSETS, B_USE_WINDOW_INSETS, B_USE_WINDOW_INSETS, 0)
.Add(fEnabled)
.End()
.Add(new BSeparatorView(B_HORIZONTAL))
.AddGroup(B_VERTICAL)
.SetInsets(B_USE_WINDOW_INSETS, 0, B_USE_WINDOW_INSETS, B_USE_WINDOW_INSETS)
.Add(fModBox)
.Add(fAccelSlider)
.End();

CenterOnScreen();
}


Expand Down
12 changes: 12 additions & 0 deletions preflet/locales/de.catkeys
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
1 English application/x-vnd.OscarL-KeyCursorSettings 77331839
Command ModifierBox ALT
Min SettingsWindow Min
Control ModifierBox STRG
Menu ModifierBox Menü
KeyCursor settings SettingsWindow KeyCursor Einstellungen
Shift ModifierBox Shift
Acceleration SettingsWindow Beschleunigung
Option ModifierBox OPT
Max SettingsWindow Max
Toggle keys SettingsWindow Ein-/Ausschalttasten
Enable KeyCursor SettingsWindow KeyCursor aktivieren
12 changes: 12 additions & 0 deletions preflet/locales/en.catkeys
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
1 English application/x-vnd.OscarL-KeyCursorSettings 77331839
Command ModifierBox Command
Min SettingsWindow Min
Control ModifierBox Control
Menu ModifierBox Menu
KeyCursor settings SettingsWindow KeyCursor settings
Shift ModifierBox Shift
Acceleration SettingsWindow Acceleration
Option ModifierBox Option
Max SettingsWindow Max
Toggle keys SettingsWindow Toggle keys
Enable KeyCursor SettingsWindow Enable KeyCursor
6 changes: 3 additions & 3 deletions preflet/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ NAME = ../KeyCursor
TYPE =

# If you plan to use localization, specify the application's MIME signature.
APP_MIME_SIG =
APP_MIME_SIG = application/x-vnd.OscarL-KeyCursorSettings

# The following lines tell Pe and Eddie where the SRCS, RDEFS, and RSRCS are
# so that Pe and Eddie can fill them in for you.
Expand Down Expand Up @@ -62,7 +62,7 @@ RSRCS = KeyCursor.rsrc
# - if your library does not follow the standard library naming scheme,
# you need to specify the path to the library and it's name.
# (e.g. for mylib.a, specify "mylib.a" or "path/mylib.a")
LIBS = be $(STDCPPLIBS)
LIBS = be localestub $(STDCPPLIBS)

# Specify additional paths to directories following the standard libXXX.so
# or libXXX.a naming scheme. You can specify full paths or paths relative
Expand Down Expand Up @@ -90,7 +90,7 @@ OPTIMIZE := FULL
# will recreate only the "locales/en.catkeys" file. Use it as a template
# for creating catkeys for other languages. All localization files must be
# placed in the "locales" subdirectory.
LOCALES =
LOCALES = de en

# Specify all the preprocessor symbols to be defined. The symbols will not
# have their values set automatically; you must supply the value (if any) to
Expand Down

0 comments on commit 640b485

Please sign in to comment.