Work in progress: converting the terminal preference window to the layout api
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34160 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <Button.h>
|
||||
#include <GroupLayoutBuilder.h>
|
||||
#include <LayoutBuilder.h>
|
||||
#include <Menu.h>
|
||||
#include <MenuField.h>
|
||||
#include <MenuItem.h>
|
||||
@@ -25,9 +27,9 @@
|
||||
|
||||
|
||||
|
||||
AppearancePrefView::AppearancePrefView(BRect frame, const char *name,
|
||||
AppearancePrefView::AppearancePrefView(const char *name,
|
||||
BMessenger messenger)
|
||||
: PrefView(frame, name),
|
||||
: PrefView(name),
|
||||
fAppearancePrefViewMessenger(messenger)
|
||||
{
|
||||
const char *color_tbl[] = {
|
||||
@@ -58,33 +60,38 @@ AppearancePrefView::AppearancePrefView(BRect frame, const char *name,
|
||||
float greenDividerSize = StringWidth("Green:") + 8.0;
|
||||
float colorDividerSize = StringWidth("Color:") + 8.0;
|
||||
|
||||
BRect r(5, 5, 261, 25);
|
||||
|
||||
BMenu *menu = _MakeFontMenu(MSG_HALF_FONT_CHANGED,
|
||||
SetLayout(new BGroupLayout(B_HORIZONTAL));
|
||||
|
||||
BMenu *fontMenu = _MakeFontMenu(MSG_HALF_FONT_CHANGED,
|
||||
PrefHandler::Default()->getString(PREF_HALF_FONT_FAMILY),
|
||||
PrefHandler::Default()->getString(PREF_HALF_FONT_STYLE));
|
||||
fFont = new BMenuField(r, "font", "Font:", menu);
|
||||
fFont->SetDivider(colorDividerSize);
|
||||
fFont->SetAlignment(B_ALIGN_RIGHT);
|
||||
AddChild(fFont);
|
||||
|
||||
r.OffsetBy(r.Width() + 10, 0);
|
||||
menu = _MakeSizeMenu(MSG_HALF_SIZE_CHANGED,
|
||||
|
||||
BMenu *sizeMenu = _MakeSizeMenu(MSG_HALF_SIZE_CHANGED,
|
||||
PrefHandler::Default()->getInt32(PREF_HALF_FONT_SIZE));
|
||||
fFontSize = new BMenuField(r, "size", "Size:", menu);
|
||||
fFontSize->SetDivider(greenDividerSize);
|
||||
|
||||
BView *layoutView = BLayoutBuilder::Group<>()
|
||||
.SetInsets(10, 10, 10, 10)
|
||||
.AddGroup(B_VERTICAL)
|
||||
.Add(fFont = new BMenuField("font", "Font:", fontMenu))
|
||||
.Add(fFontSize = new BMenuField("size", "Size:", sizeMenu))
|
||||
.Add(fColorField = new BMenuField("color", "Color:",
|
||||
MakeMenu(MSG_COLOR_FIELD_CHANGED, color_tbl,
|
||||
color_tbl[0])))
|
||||
.Add(fColorControl = new BColorControl(BPoint(10, 10),
|
||||
B_CELLS_32x8, 8.0, "", new BMessage(MSG_COLOR_CHANGED)))
|
||||
.End();
|
||||
|
||||
AddChild(layoutView);
|
||||
|
||||
//fFont->SetDivider(colorDividerSize);
|
||||
fFont->SetAlignment(B_ALIGN_RIGHT);
|
||||
|
||||
//fFontSize->SetDivider(greenDividerSize);
|
||||
fFontSize->SetAlignment(B_ALIGN_RIGHT);
|
||||
AddChild(fFontSize);
|
||||
|
||||
r.OffsetBy(-r.Width() - 10,r.Height() + 10);
|
||||
fColorField = new BMenuField(r, "color", "Color:",
|
||||
MakeMenu(MSG_COLOR_FIELD_CHANGED, color_tbl, color_tbl[0]));
|
||||
fColorField->SetDivider(colorDividerSize);
|
||||
//fColorField->SetDivider(colorDividerSize);
|
||||
fColorField->SetAlignment(B_ALIGN_RIGHT);
|
||||
AddChild(fColorField);
|
||||
|
||||
fColorControl = SetupColorControl(BPoint(r.left, r.bottom + 10),
|
||||
B_CELLS_32x8, 8.0, MSG_COLOR_CHANGED);
|
||||
fColorControl->SetValue(PrefHandler::Default()->getRGB(PREF_TEXT_FORE_COLOR));
|
||||
|
||||
BTextControl* redInput = (BTextControl*)fColorControl->ChildAt(0);
|
||||
@@ -95,9 +102,9 @@ AppearancePrefView::AppearancePrefView(BRect frame, const char *name,
|
||||
greenInput->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
|
||||
blueInput->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
|
||||
|
||||
redInput->SetDivider(greenDividerSize);
|
||||
/*redInput->SetDivider(greenDividerSize);
|
||||
greenInput->SetDivider(greenDividerSize);
|
||||
blueInput->SetDivider(greenDividerSize);
|
||||
blueInput->SetDivider(greenDividerSize);*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,8 +19,7 @@ class TTextControl;
|
||||
|
||||
class AppearancePrefView : public PrefView {
|
||||
public:
|
||||
AppearancePrefView(BRect frame, const char *name,
|
||||
BMessenger messenger);
|
||||
AppearancePrefView(const char *name, BMessenger messenger);
|
||||
|
||||
virtual void Revert();
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
|
||||
@@ -40,8 +40,8 @@
|
||||
#include <String.h>
|
||||
|
||||
|
||||
PrefView::PrefView(BRect frame, const char *name)
|
||||
:BView(frame, name, B_FOLLOW_ALL_SIDES, B_WILL_DRAW)
|
||||
PrefView::PrefView(const char *name)
|
||||
:BView(name, B_WILL_DRAW)
|
||||
{
|
||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
}
|
||||
@@ -86,15 +86,3 @@ PrefView::MessageReceived(BMessage* msg)
|
||||
BView::MessageReceived(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BColorControl *
|
||||
PrefView::SetupColorControl(BPoint point, color_control_layout layout,
|
||||
float cellSize, ulong message)
|
||||
{
|
||||
BColorControl *control = new BColorControl(point, layout, cellSize,
|
||||
"", new BMessage(message));
|
||||
AddChild(control);
|
||||
return control;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
#ifndef PREFVIEW_H_INCLUDED
|
||||
#define PREFVIEW_H_INCLUDED
|
||||
|
||||
#include <View.h>
|
||||
#include <ColorControl.h>
|
||||
#include <String.h>
|
||||
@@ -79,13 +80,11 @@ const ulong MSG_PREF_MODIFIED = 'mpmo';
|
||||
|
||||
class PrefView : public BView {
|
||||
public:
|
||||
PrefView(BRect frame, const char *name);
|
||||
PrefView(const char *name);
|
||||
virtual ~PrefView();
|
||||
virtual bool CanApply();
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
|
||||
BColorControl* SetupColorControl(BPoint p, color_control_layout layout, float cell_size, ulong msg);
|
||||
|
||||
};
|
||||
|
||||
#endif //PREFVIEW_H_INCLUDED
|
||||
|
||||
@@ -16,57 +16,46 @@
|
||||
#include <Box.h>
|
||||
#include <Button.h>
|
||||
#include <FilePanel.h>
|
||||
#include <GroupLayoutBuilder.h>
|
||||
#include <LayoutBuilder.h>
|
||||
#include <Path.h>
|
||||
#include <Screen.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
PrefWindow::PrefWindow(BMessenger messenger)
|
||||
: BWindow(_CenteredRect(BRect(0, 0, 375, 185)), "Terminal Preferences",
|
||||
: BWindow(BRect(0, 0, 375, 185), "Terminal Preferences",
|
||||
B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
||||
B_NOT_RESIZABLE|B_NOT_ZOOMABLE),
|
||||
B_NOT_RESIZABLE|B_NOT_ZOOMABLE|B_AUTO_UPDATE_SIZE_LIMITS),
|
||||
fPreviousPref(new PrefHandler(PrefHandler::Default())),
|
||||
fSavePanel(NULL),
|
||||
fDirty(false),
|
||||
fPrefDlgMessenger(messenger)
|
||||
{
|
||||
BView *top = new BView(Bounds(), "topview", B_FOLLOW_NONE, B_WILL_DRAW);
|
||||
top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
AddChild(top);
|
||||
BLayoutBuilder::Group<>(this, B_VERTICAL)
|
||||
.AddGroup(B_VERTICAL, 1)
|
||||
.SetInsets(10, 10, 10, 10)
|
||||
.Add(new AppearancePrefView("Appearance", fPrefDlgMessenger))
|
||||
.AddGroup(B_HORIZONTAL)
|
||||
.Add(fSaveAsFileButton = new BButton("savebutton",
|
||||
"Save to File" B_UTF8_ELLIPSIS,
|
||||
new BMessage(MSG_SAVEAS_PRESSED), B_WILL_DRAW))
|
||||
.AddGlue()
|
||||
.Add(fRevertButton = new BButton("revertbutton",
|
||||
"Cancel", new BMessage(MSG_REVERT_PRESSED),
|
||||
B_WILL_DRAW))
|
||||
.Add(fSaveButton = new BButton("okbutton", "OK",
|
||||
new BMessage(MSG_SAVE_PRESSED), B_WILL_DRAW))
|
||||
.End()
|
||||
.End();
|
||||
|
||||
|
||||
BRect rect = top->Bounds();
|
||||
rect.bottom *= .75;
|
||||
AppearancePrefView *prefView
|
||||
= new AppearancePrefView(rect, "Appearance", fPrefDlgMessenger);
|
||||
top->AddChild(prefView);
|
||||
|
||||
fSaveAsFileButton = new BButton(BRect(0, 0, 1, 1), "savebutton", "Save to File" B_UTF8_ELLIPSIS,
|
||||
new BMessage(MSG_SAVEAS_PRESSED), B_FOLLOW_TOP, B_WILL_DRAW);
|
||||
fSaveAsFileButton->ResizeToPreferred();
|
||||
fSaveAsFileButton->MoveTo(5, top->Bounds().Height() - 5 -
|
||||
fSaveAsFileButton->Bounds().Height());
|
||||
top->AddChild(fSaveAsFileButton);
|
||||
|
||||
fSaveButton = new BButton(BRect(0, 0, 1, 1), "okbutton", "OK",
|
||||
new BMessage(MSG_SAVE_PRESSED), B_FOLLOW_TOP, B_WILL_DRAW);
|
||||
fSaveButton->ResizeToPreferred();
|
||||
fSaveButton->MoveTo(top->Bounds().Width() - 5 - fSaveButton->Bounds().Width(),
|
||||
top->Bounds().Height() - 5 - fSaveButton->Bounds().Height());
|
||||
fSaveButton->MakeDefault(true);
|
||||
top->AddChild(fSaveButton);
|
||||
|
||||
fRevertButton = new BButton(BRect(0, 0, 1, 1), "revertbutton",
|
||||
"Cancel", new BMessage(MSG_REVERT_PRESSED), B_FOLLOW_TOP, B_WILL_DRAW);
|
||||
fRevertButton->ResizeToPreferred();
|
||||
fRevertButton->MoveTo(fSaveButton->Frame().left - 10 -
|
||||
fRevertButton->Bounds().Width(), top->Bounds().Height() - 5 -
|
||||
fRevertButton->Bounds().Height());
|
||||
top->AddChild(fRevertButton);
|
||||
|
||||
|
||||
AddShortcut('Q', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
|
||||
AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
|
||||
|
||||
CenterOnScreen();
|
||||
Show();
|
||||
}
|
||||
|
||||
@@ -199,19 +188,3 @@ PrefWindow::MessageReceived(BMessage *msg)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BRect
|
||||
PrefWindow::_CenteredRect(BRect rect)
|
||||
{
|
||||
BRect screenRect = BScreen().Frame();
|
||||
|
||||
screenRect.InsetBy(10,10);
|
||||
|
||||
float x = screenRect.left + (screenRect.Width() - rect.Width()) / 2;
|
||||
float y = screenRect.top + (screenRect.Height() - rect.Height()) / 3;
|
||||
|
||||
rect.OffsetTo(x, y);
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user