Skip to content
This repository was archived by the owner on Aug 15, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion OutputView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <FilePanel.h>
#include <LayoutBuilder.h>
#include <MessageRunner.h>
#include <NumberFormat.h>

Check warning

Code scanning / Cppcheck (reported by Codacy)

Include file: <NumberFormat.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Include file: <NumberFormat.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <RadioButton.h>
#include <Screen.h>
#include <TextControl.h>
Expand Down Expand Up @@ -332,7 +333,7 @@ OutputView::_LayoutView()
fFilePanelButton->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT, B_ALIGN_MIDDLE));

fScaleSlider = new SliderTextControl("scale_slider", B_TRANSLATE("Scale"),
new BMessage(kScaleChanged), 25, 200, 25, "%", B_HORIZONTAL);
new BMessage(kScaleChanged), 25, 200, 25, "", B_HORIZONTAL, true);

fBorderSlider = new SliderTextControl("border_slider", B_TRANSLATE("Window edges"),
new BMessage(kWindowBorderFrameChanged), 0, 40, 1, B_TRANSLATE("pixels"), B_HORIZONTAL);
Expand Down
51 changes: 32 additions & 19 deletions SliderTextControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@ const int32 kSliderModificationMessage = '9SMM';
class SizeSlider : public BSlider {
public:
SizeSlider(const char* name, const char* label,
BMessage* message, int32 minValue,
int32 maxValue, int32 stepValue,
orientation posture,
thumb_style thumbType = B_BLOCK_THUMB,
uint32 flags = B_NAVIGABLE | B_WILL_DRAW
| B_FRAME_EVENTS);
BMessage* message, int32 minValue, int32 maxValue, int32 stepValue,
orientation posture, thumb_style thumbType = B_BLOCK_THUMB,
uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS);

virtual void SetValue(int32 value);
private:
Expand All @@ -35,17 +32,16 @@ class SizeSlider : public BSlider {


SliderTextControl::SliderTextControl(const char* name, const char* label,
BMessage* message, int32 minValue,
int32 maxValue, int32 stepValue, const char* unit,
orientation posture,
thumb_style thumbType,
uint32 flags)
BMessage* message, int32 minValue, int32 maxValue, int32 stepValue,
const char* unit, orientation posture, bool isPercent,
thumb_style thumbType, uint32 flags)
:
BControl(name, label, message, flags),
fSizeSlider(NULL),
fSizeTextControl(NULL),
fTextModificationRunner(NULL),
fWhat(message->what)
fWhat(message->what),

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule

MISRA 12.3 rule
fIsPercent(isPercent)
{
fSizeSlider = new SizeSlider("size_slider", label,
new BMessage(*message), minValue, maxValue, stepValue, B_HORIZONTAL);
Expand All @@ -54,12 +50,25 @@ SliderTextControl::SliderTextControl(const char* name, const char* label,
fSizeSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
fSizeSlider->SetHashMarkCount(8);

BString minLabel;
minLabel << minValue << " " << unit;
BString maxLabel;
maxLabel << maxValue << " " << unit;
if (isPercent) {
BString minData;
BString maxData;

if (fNumberFormat.FormatPercent(minData, (minValue / 100)) != B_OK)
minData.SetToFormat("%d%%", minValue);

if (fNumberFormat.FormatPercent(maxData, (maxValue / 100)) != B_OK)
minData.SetToFormat("%d%%", maxValue);

fSizeSlider->SetLimitLabels(minData.String(), maxData.String());
} else {
BString minLabel;
minLabel << minValue << " " << unit;
BString maxLabel;
maxLabel << maxValue << " " << unit;
fSizeSlider->SetLimitLabels(minLabel.String(), maxLabel.String());
}

fSizeSlider->SetLimitLabels(minLabel.String(), maxLabel.String());
fSizeTextControl = new BTextControl("", "", new BMessage(kTextControlMessage));
fTextLabel = new BStringView("label", unit);

Expand Down Expand Up @@ -122,7 +131,6 @@ SliderTextControl::MessageReceived(BMessage* message)
value = std::max(value, min);
value = std::min(value, max);
BControl::SetValue(value);

fSizeSlider->SetValue(value);

BString text;
Expand Down Expand Up @@ -165,8 +173,13 @@ SliderTextControl::SetValue(int32 value)
fSizeSlider->SetValue(value);
BString sizeString;
sizeString << (int32)fSizeSlider->Value();
fSizeTextControl->SetText(sizeString);

if (fIsPercent) {
if (fNumberFormat.FormatPercent(sizeString, fSizeSlider->Value() / 100) != B_OK)
sizeString.SetToFormat("%d%%", (int32)fSizeSlider->Value());
}

fSizeTextControl->SetText(sizeString);
BControl::SetValue(value);
}

Expand Down
11 changes: 6 additions & 5 deletions SliderTextControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define SLIDERTEXTCONTROL_H


#include <NumberFormat.h>

Check warning

Code scanning / Cppcheck (reported by Codacy)

Include file: <NumberFormat.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Include file: <NumberFormat.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <Slider.h>
#include <SupportDefs.h>

Expand All @@ -16,12 +17,10 @@ class BTextControl;
class SliderTextControl : public BControl {
public:
SliderTextControl(const char* name, const char* label,
BMessage* message, int32 minValue,
int32 maxValue, int32 stepValue = 1,
BMessage* message, int32 minValue, int32 maxValue, int32 stepValue = 1,

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 17.8 rule

MISRA 17.8 rule
const char* unit = "", orientation posture = B_HORIZONTAL,
thumb_style thumbType = B_BLOCK_THUMB,
uint32 flags = B_NAVIGABLE | B_WILL_DRAW
| B_FRAME_EVENTS);
bool isPercent = false, thumb_style thumbType = B_BLOCK_THUMB,

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 17.8 rule

MISRA 17.8 rule
uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS);

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 17.8 rule

MISRA 17.8 rule

virtual void AttachedToWindow();
virtual void MessageReceived(BMessage* message);
Expand All @@ -32,7 +31,9 @@ class SliderTextControl : public BControl {
BTextControl* fSizeTextControl;
BStringView* fTextLabel;
BMessageRunner* fTextModificationRunner;
BNumberFormat fNumberFormat;
uint32 fWhat;
bool fIsPercent;

Check warning

Code scanning / Cppcheck (reported by Codacy)

class member 'SliderTextControl::fIsPercent' is never used.

class member 'SliderTextControl::fIsPercent' is never used.
};


Expand Down