StyledEdit: Add cmd +, cmd - shortcuts for font size
Change-Id: I540ed130322fa1ce7eba62c4a1d1de36b12ccf9a Reviewed-on: https://review.haiku-os.org/c/haiku/+/2303 Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
19733b44fa
commit
619b2670b1
@@ -1,10 +1,11 @@
|
||||
/*
|
||||
* Copyright 2002-2010, Haiku, Inc. All Rights Reserved.
|
||||
* Copyright 2002-2020, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Mattias Sundblad
|
||||
* Andrew Bachmann
|
||||
* Pascal R. G. Abresch
|
||||
*/
|
||||
#ifndef CONSTANTS_H
|
||||
#define CONSTANTS_H
|
||||
@@ -53,6 +54,8 @@ const uint32 FONT_STYLE = 'FSch';
|
||||
const uint32 FONT_COLOR = 'Fcol';
|
||||
const uint32 kMsgSetItalic = 'Fita';
|
||||
const uint32 kMsgSetBold = 'Fbld';
|
||||
const uint32 kMsgSetFontDown = 'Fsdw';
|
||||
const uint32 kMsgSetFontUp = 'Fsup';
|
||||
|
||||
const rgb_color palette[] = {
|
||||
{ 220, 0, 0, 255 }, // red
|
||||
@@ -93,5 +96,8 @@ const uint32 UPDATE_STATUS_REF = 'UPSr';
|
||||
const uint32 UNLOCK_FILE = 'UNLk';
|
||||
const uint32 UPDATE_LINE_SELECTION = 'UPls';
|
||||
|
||||
// fontSize constant
|
||||
const int32 fontSizes[] = {9, 10, 11, 12, 14, 18, 24, 36, 48, 72};
|
||||
|
||||
#endif // CONSTANTS_H
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012, Haiku, Inc. All Rights Reserved.
|
||||
* Copyright 2002-2020, Haiku, Inc. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@@ -10,6 +10,7 @@
|
||||
* Ryan Leavengood
|
||||
* Vlad Slepukhin
|
||||
* Sarzhuk Zharski
|
||||
* Pascal R. G. Abresch
|
||||
*/
|
||||
|
||||
|
||||
@@ -397,6 +398,42 @@ StyledEditWindow::MessageReceived(BMessage* message)
|
||||
_SetFontStyle(fontFamily, fontStyle);
|
||||
break;
|
||||
}
|
||||
case kMsgSetFontUp:
|
||||
{
|
||||
uint32 sameProperties;
|
||||
BFont font;
|
||||
|
||||
fTextView->GetFontAndColor(&font, &sameProperties);
|
||||
//GetFont seems to return a constant size for font.Size(),
|
||||
//thus not used here (maybe that is a bug)
|
||||
int32 cur_size = font.Size();
|
||||
|
||||
for (unsigned int a = 0;
|
||||
a < sizeof(fontSizes)/sizeof(fontSizes[0]); a++) {
|
||||
if (fontSizes[a] > cur_size) {
|
||||
_SetFontSize(fontSizes[a]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case kMsgSetFontDown:
|
||||
{
|
||||
uint32 sameProperties;
|
||||
BFont font;
|
||||
|
||||
fTextView->GetFontAndColor(&font, &sameProperties);
|
||||
int32 cur_size = font.Size();
|
||||
|
||||
for (unsigned int a = 1;
|
||||
a < sizeof(fontSizes)/sizeof(fontSizes[0]); a++) {
|
||||
if (fontSizes[a] >= cur_size) {
|
||||
_SetFontSize(fontSizes[a-1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case kMsgSetItalic:
|
||||
{
|
||||
uint32 sameProperties;
|
||||
@@ -1212,7 +1249,6 @@ StyledEditWindow::_InitWindow(uint32 encoding)
|
||||
fFontSizeMenu->SetRadioMode(true);
|
||||
fFontMenu->AddItem(fFontSizeMenu);
|
||||
|
||||
const int32 fontSizes[] = {9, 10, 11, 12, 14, 18, 24, 36, 48, 72};
|
||||
for (uint32 i = 0; i < sizeof(fontSizes) / sizeof(fontSizes[0]); i++) {
|
||||
BMessage* fontMessage = new BMessage(FONT_SIZE);
|
||||
fontMessage->AddFloat("size", fontSizes[i]);
|
||||
@@ -1234,6 +1270,15 @@ StyledEditWindow::_InitWindow(uint32 encoding)
|
||||
|
||||
fFontMenu->AddSeparatorItem();
|
||||
|
||||
BMenuItem* fontSizeUpItem = new BMenuItem(B_TRANSLATE("Increase size"),
|
||||
new BMessage(kMsgSetFontUp));
|
||||
BMenuItem* fontSizeDownItem = new BMenuItem(B_TRANSLATE("Decrease size"),
|
||||
new BMessage(kMsgSetFontDown));
|
||||
fFontMenu->AddItem(fontSizeUpItem);
|
||||
fFontMenu->AddItem(fontSizeDownItem);
|
||||
fontSizeUpItem->SetShortcut('+', 0);
|
||||
fontSizeDownItem->SetShortcut('-', 0);
|
||||
|
||||
// "Bold" & "Italic" menu items
|
||||
fFontMenu->AddItem(fBoldItem = new BMenuItem(B_TRANSLATE("Bold"),
|
||||
new BMessage(kMsgSetBold)));
|
||||
|
||||
Reference in New Issue
Block a user