New Widget class FSpinBox to provide spin boxes

This commit is contained in:
Markus Gans 2019-11-16 15:16:44 +01:00
parent 5852c8129b
commit dedc1f3410
36 changed files with 1173 additions and 294 deletions

1
.gitignore vendored
View File

@ -39,6 +39,7 @@ examples/.libs/
examples/calculator examples/calculator
examples/dialog examples/dialog
examples/string-operations examples/string-operations
examples/background-color
examples/opti-move examples/opti-move
examples/termcap examples/termcap
examples/hello examples/hello

View File

@ -1,3 +1,6 @@
2019-11-16 Markus Gans <guru.mail@muenster.de>
* New Widget class FSpinBox to provide spin boxes
2019-11-06 Markus Gans <guru.mail@muenster.de> 2019-11-06 Markus Gans <guru.mail@muenster.de>
* Improved display of the NewFont midline * Improved display of the NewFont midline

View File

@ -178,36 +178,39 @@ Class digramm
: ┌--------┤ FString │ │ ┌──────────────┐ : ┌--------┤ FString │ │ ┌──────────────┐
: : └─────────┘ │ ┌────┤ FApplication │ : : └─────────┘ │ ┌────┤ FApplication │
: : *┌────────┐ │ │ └──────────────┘ : : *┌────────┐ │ │ └──────────────┘
: ┌--------┤ FPoint │ │ │ ┌─────────┐ : ┌--------┤ FPoint │ │ │ ┌────────┐
: : └────────┘ │ ├────┤ FButton │ : : └────────┘ │ ├────┤ FLabel │
: : *┌───────┐ │ │ └─────────┘
: ┌--------┤ FRect │ │ │ ┌────────┐
: : └───────┘ │ ├────┤ FLabel │
: : *┌───────┐ │ │ └────────┘ : : *┌───────┐ │ │ └────────┘
: ┌--------┤ FSize │ │ │ ┌───────────┐ : ┌--------┤ FRect │ │ │ ┌───────────┐
: : └───────┘ │ ├────┤ FLineEdit │ : : └───────┘ │ ├────┤ FLineEdit │
:1 :1 │ │ └───────────┘ : : *┌───────┐ │ │ └───────────┘
┌─┴──┴──┐ │ │ ┌──────────────┐ ┌──────────────┐ : ┌--------┤ FSize │ │ │ ┌──────────┐
│ FTerm │ │ ├────┤ FButtonGroup │ ┌──┤ FRadioButton │ : : └───────┘ │ ├────┤ FSpinBox │
└───┬───┘ ┌────────┐ │ │ └──────────────┘ │ └──────────────┘ :1 :1 │ │ └──────────┘
:1 │ FEvent │◄─────┘ │ ┌───────────────┐ │ ┌───────────┐ ┌─┴──┴──┐ │ │ ┌─────────┐
┌───┴────┐ └────┬───┘ ├────┤ FToggleButton │◄─┼──┤ FCheckBox │ │ FTerm │ │ ├────┤ FButton │
│ FVTerm │◄──┐ :1 │ └───────────────┘ │ └───────────┘ └───┬───┘ ┌────────┐ │ │ └─────────┘
└────────┘ │ ┌────┴────┐ │ ┌──────────────┐ │ ┌─────────┐ :1 │ FEvent │◄─────┘ │ ┌──────────────┐ ┌──────────────┐
├────┤ FWidget │◄───────┼────┤ FProgressbar │ └──┤ FSwitch │ ┌───┴────┐ └────┬───┘ ├────┤ FButtonGroup │ ┌──┤ FRadioButton │
┌─────────┐ │ └─────────┘ │ └──────────────┘ └─────────┘ │ FVTerm │◄──┐ :1 │ └──────────────┘ │ └──────────────┘
│ FObject │◄──┘ │ ┌────────────┐ └────────┘ │ ┌────┴────┐ │ ┌───────────────┐ │ ┌───────────┐
└─────────┘ ├────┤ FScrollbar │ ├────┤ FWidget │◄───────┼────┤ FToggleButton │◄─┼──┤ FCheckBox │
┌─────────┐ │ └─────────┘ │ └───────────────┘ │ └───────────┘
│ FObject │◄──┘ │ ┌──────────────┐ │ ┌─────────┐
└─────────┘ ├────┤ FProgressbar │ └──┤ FSwitch │
│ └──────────────┘ └─────────┘
│ ┌────────────┐
├────┤ FScrollbar │
│ └────────────┘ │ └────────────┘
│ ┌───────────┐ │ ┌───────────┐
├────┤ FTextView │ ├────┤ FTextView │
│ └───────────┘ │ └───────────┘
│ ┌──────────┐1 *┌──────────────┐ ┌─────────────┐1 │ ┌──────────┐1 *┌──────────────┐
├────┤ FListBox ├-------┤ FListBoxItem │ │ FTermBuffer ├----------------------├────┤ FListBox ├-------┤ FListBoxItem │
│ └──────────┘ └──────────────┘ └─────────────┘ │ └──────────┘ └──────────────┘
┌─────────────┐1 │ 1┌───────────┐1 *┌───────────────┐ │ 1┌───────────┐1 *┌───────────────┐
│ FTermBuffer ├----------------------├────┤ FListView ├------┤ FListViewItem │ ├────┤ FListView ├------┤ FListViewItem │
└─────────────┘ │ └───────────┘ └───────────────┘ │ └───────────┘ └───────────────┘
│ ┌─────────────┐ │ ┌─────────────┐
├────┤ FScrollView │ ├────┤ FScrollView │
│ └─────────────┘ │ └─────────────┘

View File

@ -44,36 +44,39 @@
: ┌--------┤ FString │ │ ┌──────────────┐ : ┌--------┤ FString │ │ ┌──────────────┐
: : └─────────┘ │ ┌────┤ FApplication │ : : └─────────┘ │ ┌────┤ FApplication │
: : *┌────────┐ │ │ └──────────────┘ : : *┌────────┐ │ │ └──────────────┘
: ┌--------┤ FPoint │ │ │ ┌─────────┐ : ┌--------┤ FPoint │ │ │ ┌────────┐
: : └────────┘ │ ├────┤ FButton │ : : └────────┘ │ ├────┤ FLabel │
: : *┌───────┐ │ │ └─────────┘
: ┌--------┤ FRect │ │ │ ┌────────┐
: : └───────┘ │ ├────┤ FLabel │
: : *┌───────┐ │ │ └────────┘ : : *┌───────┐ │ │ └────────┘
: ┌--------┤ FSize │ │ │ ┌───────────┐ : ┌--------┤ FRect │ │ │ ┌───────────┐
: : └───────┘ │ ├────┤ FLineEdit │ : : └───────┘ │ ├────┤ FLineEdit │
:1 :1 │ │ └───────────┘ : : *┌───────┐ │ │ └───────────┘
┌─┴──┴──┐ │ │ ┌──────────────┐ ┌──────────────┐ : ┌--------┤ FSize │ │ │ ┌──────────┐
│ FTerm │ │ ├────┤ FButtonGroup │ ┌──┤ FRadioButton │ : : └───────┘ │ ├────┤ FSpinBox │
└───┬───┘ ┌────────┐ │ │ └──────────────┘ │ └──────────────┘ :1 :1 │ │ └──────────┘
:1 │ FEvent │◄─────┘ │ ┌───────────────┐ │ ┌───────────┐ ┌─┴──┴──┐ │ │ ┌─────────┐
┌───┴────┐ └────┬───┘ ├────┤ FToggleButton │◄─┼──┤ FCheckBox │ │ FTerm │ │ ├────┤ FButton │
│ FVTerm │◄──┐ :1 │ └───────────────┘ │ └───────────┘ └───┬───┘ ┌────────┐ │ │ └─────────┘
└────────┘ │ ┌────┴────┐ │ ┌──────────────┐ │ ┌─────────┐ :1 │ FEvent │◄─────┘ │ ┌──────────────┐ ┌──────────────┐
├────┤ FWidget │◄───────┼────┤ FProgressbar │ └──┤ FSwitch │ ┌───┴────┐ └────┬───┘ ├────┤ FButtonGroup │ ┌──┤ FRadioButton │
┌─────────┐ │ └─────────┘ │ └──────────────┘ └─────────┘ │ FVTerm │◄──┐ :1 │ └──────────────┘ │ └──────────────┘
│ FObject │◄──┘ │ ┌────────────┐ └────────┘ │ ┌────┴────┐ │ ┌───────────────┐ │ ┌───────────┐
└─────────┘ ├────┤ FScrollbar │ ├────┤ FWidget │◄───────┼────┤ FToggleButton │◄─┼──┤ FCheckBox │
┌─────────┐ │ └─────────┘ │ └───────────────┘ │ └───────────┘
│ FObject │◄──┘ │ ┌──────────────┐ │ ┌─────────┐
└─────────┘ ├────┤ FProgressbar │ └──┤ FSwitch │
│ └──────────────┘ └─────────┘
│ ┌────────────┐
├────┤ FScrollbar │
│ └────────────┘ │ └────────────┘
│ ┌───────────┐ │ ┌───────────┐
├────┤ FTextView │ ├────┤ FTextView │
│ └───────────┘ │ └───────────┘
│ ┌──────────┐1 *┌──────────────┐ ┌─────────────┐1 │ ┌──────────┐1 *┌──────────────┐
├────┤ FListBox ├-------┤ FListBoxItem │ │ FTermBuffer ├----------------------├────┤ FListBox ├-------┤ FListBoxItem │
│ └──────────┘ └──────────────┘ └─────────────┘ │ └──────────┘ └──────────────┘
┌─────────────┐1 │ 1┌───────────┐1 *┌───────────────┐ │ 1┌───────────┐1 *┌───────────────┐
│ FTermBuffer ├----------------------├────┤ FListView ├------┤ FListViewItem │ ├────┤ FListView ├------┤ FListViewItem │
└─────────────┘ │ └───────────┘ └───────────────┘ │ └───────────┘ └───────────────┘
│ ┌─────────────┐ │ ┌─────────────┐
├────┤ FScrollView │ ├────┤ FScrollView │
│ └─────────────┘ │ └─────────────┘

View File

@ -1,5 +1,5 @@
First steps with the Final Cut widget toolkit First steps with the FINAL CUT widget toolkit
============================================= =============================================
Table of Contents Table of Contents

View File

@ -33,7 +33,7 @@ using finalcut::FSize;
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// class TextWindow // class SegmentView
//---------------------------------------------------------------------- //----------------------------------------------------------------------
class SegmentView : public finalcut::FDialog class SegmentView : public finalcut::FDialog

View File

@ -25,6 +25,7 @@ noinst_PROGRAMS = \
calculator \ calculator \
watch \ watch \
term-attributes \ term-attributes \
background-color \
transparent \ transparent \
keyboard \ keyboard \
mouse \ mouse \
@ -50,6 +51,7 @@ mandelbrot_SOURCES = mandelbrot.cpp
calculator_SOURCES = calculator.cpp calculator_SOURCES = calculator.cpp
watch_SOURCES = watch.cpp watch_SOURCES = watch.cpp
term_attributes_SOURCES = term-attributes.cpp term_attributes_SOURCES = term-attributes.cpp
background_color_SOURCES = background-color.cpp
termcap_SOURCES = termcap.cpp termcap_SOURCES = termcap.cpp
transparent_SOURCES = transparent.cpp transparent_SOURCES = transparent.cpp
keyboard_SOURCES = keyboard.cpp keyboard_SOURCES = keyboard.cpp

View File

@ -0,0 +1,140 @@
/***********************************************************************
* background-color.cpp - Sets the background color palette *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
* as published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* The Final Cut is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this program. If not, see *
* <http://www.gnu.org/licenses/>. *
***********************************************************************/
#include <map>
#include <vector>
#include <final/final.h>
using finalcut::FPoint;
using finalcut::FSize;
//----------------------------------------------------------------------
// class Background
//----------------------------------------------------------------------
class Background : public finalcut::FDialog
{
public:
explicit Background (finalcut::FWidget* = nullptr);
private:
// Callback method
void cb_changed (finalcut::FWidget*, FDataPtr);
// Data members
finalcut::FSpinBox red{this};
finalcut::FSpinBox green{this};
finalcut::FSpinBox blue{this};
finalcut::FButton quit{"&Quit", this};
};
//----------------------------------------------------------------------
Background::Background (finalcut::FWidget* parent)
: FDialog(parent)
{
// Dialog settings
setText ("Background color palette");
setGeometry (FPoint(25, 5), FSize(32, 9));
// Spin boxes
red.setGeometry (FPoint(2, 2), FSize(7, 1));
red.setLabelOrientation (finalcut::FLineEdit::label_above);
red.setLabelText ("Red");
red.setRange (0, 255);
red.setValue (0x80);
green.setGeometry (FPoint(12, 2), FSize(7, 1));
green.setLabelOrientation (finalcut::FLineEdit::label_above);
green.setLabelText ("Green");
green.setRange (0, 255);
green.setValue (0xa4);
blue.setGeometry (FPoint(22, 2), FSize(7, 1));
blue.setLabelOrientation (finalcut::FLineEdit::label_above);
blue.setLabelText ("Blue");
blue.setRange (0, 255);
blue.setValue (0xec);
// Set the initial palette values
const auto& wc = getFWidgetColors();
finalcut::FTerm::setPalette ( wc.term_bg
, red.getValue()
, green.getValue()
, blue.getValue() );
// Quit button
quit.setGeometry(FPoint(19, 5), FSize(10, 1));
// Add some function callbacks
quit.addCallback
(
"clicked",
F_METHOD_CALLBACK (this, &finalcut::FApplication::cb_exitApp)
);
red.addCallback
(
"changed",
F_METHOD_CALLBACK (this, &Background::cb_changed)
);
green.addCallback
(
"changed",
F_METHOD_CALLBACK (this, &Background::cb_changed)
);
blue.addCallback
(
"changed",
F_METHOD_CALLBACK (this, &Background::cb_changed)
);
}
//----------------------------------------------------------------------
void Background::cb_changed (finalcut::FWidget*, FDataPtr)
{
const auto& wc = getFWidgetColors();
finalcut::FTerm::setPalette ( wc.term_bg
, red.getValue()
, green.getValue()
, blue.getValue() );
redraw();
updateTerminal();
}
//----------------------------------------------------------------------
// main part
//----------------------------------------------------------------------
int main (int argc, char* argv[])
{
finalcut::FApplication app(argc, argv);
Background dialog(&app);
app.setMainWidget(&dialog);
dialog.show();
return app.exec();
}

View File

@ -253,7 +253,7 @@ void AttribDemo::printColorLine()
{ {
auto parent = static_cast<AttribDlg*>(getParent()); auto parent = static_cast<AttribDlg*>(getParent());
for (FColor color{0}; color < colors; color++) for (FColor color{0}; color < uInt(colors); color++)
{ {
print() << FColorPair(color, parent->bgcolor) << " # "; print() << FColorPair(color, parent->bgcolor) << " # ";
} }

View File

@ -353,7 +353,7 @@ Treeview::Treeview (finalcut::FWidget* parent)
Quit.setGeometry(FPoint(24, 16), FSize(10, 1)); Quit.setGeometry(FPoint(24, 16), FSize(10, 1));
Quit.setText (L"&Quit"); Quit.setText (L"&Quit");
// Add some function callbacks // Callback function
Quit.addCallback Quit.addCallback
( (
"clicked", "clicked",

View File

@ -44,7 +44,7 @@ libfinal_la_SOURCES = \
ffiledialog.cpp \ ffiledialog.cpp \
fkey_map.cpp \ fkey_map.cpp \
fcharmap.cpp \ fcharmap.cpp \
ftextview.cpp \ fspinbox.cpp \
fstartoptions.cpp \ fstartoptions.cpp \
fstatusbar.cpp \ fstatusbar.cpp \
ftermcap.cpp \ ftermcap.cpp \
@ -58,6 +58,7 @@ libfinal_la_SOURCES = \
ftermios.cpp \ ftermios.cpp \
fterm.cpp \ fterm.cpp \
fterm_functions.cpp \ fterm_functions.cpp \
ftextview.cpp \
fvterm.cpp \ fvterm.cpp \
fevent.cpp \ fevent.cpp \
foptiattr.cpp \ foptiattr.cpp \
@ -117,6 +118,7 @@ finalcutinclude_HEADERS = \
include/final/frect.h \ include/final/frect.h \
include/final/fscrollbar.h \ include/final/fscrollbar.h \
include/final/fscrollview.h \ include/final/fscrollview.h \
include/final/fspinbox.h \
include/final/fstartoptions.h \ include/final/fstartoptions.h \
include/final/fstatusbar.h \ include/final/fstatusbar.h \
include/final/fstring.h \ include/final/fstring.h \
@ -133,8 +135,8 @@ finalcutinclude_HEADERS = \
include/final/ftermios.h \ include/final/ftermios.h \
include/final/fterm.h \ include/final/fterm.h \
include/final/ftermdata.h \ include/final/ftermdata.h \
include/final/fvterm.h \
include/final/ftextview.h \ include/final/ftextview.h \
include/final/fvterm.h \
include/final/ftogglebutton.h \ include/final/ftogglebutton.h \
include/final/fcolorpalette.h \ include/final/fcolorpalette.h \
include/final/fwidgetcolors.h \ include/final/fwidgetcolors.h \

View File

@ -151,27 +151,6 @@ bool FButton::setEnable (bool enable)
bool FButton::setFocus (bool enable) bool FButton::setFocus (bool enable)
{ {
FWidget::setFocus(enable); FWidget::setFocus(enable);
if ( enable )
{
if ( isEnabled() )
{
if ( getStatusBar() )
{
const auto& msg = getStatusbarMessage();
const auto& curMsg = getStatusBar()->getMessage();
if ( curMsg != msg )
getStatusBar()->setMessage(msg);
}
}
}
else
{
if ( isEnabled() && getStatusBar() )
getStatusBar()->clearMessage();
}
updateButtonColor(); updateButtonColor();
return enable; return enable;
} }

View File

@ -40,7 +40,7 @@ namespace finalcut
// constructor and destructor // constructor and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FLineEdit::FLineEdit(FWidget* parent) FLineEdit::FLineEdit (FWidget* parent)
: FWidget(parent) : FWidget(parent)
, label{new FLabel("", parent)} , label{new FLabel("", parent)}
{ {
@ -196,35 +196,21 @@ bool FLineEdit::setEnable (bool enable)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FLineEdit::setFocus (bool enable) bool FLineEdit::setFocus (bool enable)
{ {
const auto& wc = getFWidgetColors();
FWidget::setFocus(enable); FWidget::setFocus(enable);
if ( enable ) if ( isEnabled() )
{ {
if ( isEnabled() ) const auto& wc = getFWidgetColors();
if ( enable )
{ {
setForegroundColor (wc.inputfield_active_focus_fg); setForegroundColor (wc.inputfield_active_focus_fg);
setBackgroundColor (wc.inputfield_active_focus_bg); setBackgroundColor (wc.inputfield_active_focus_bg);
if ( getStatusBar() )
{
const auto& msg = getStatusbarMessage();
const auto& curMsg = getStatusBar()->getMessage();
if ( curMsg != msg )
getStatusBar()->setMessage(msg);
}
} }
} else
else
{
if ( isEnabled() )
{ {
setForegroundColor (wc.inputfield_active_fg); setForegroundColor (wc.inputfield_active_fg);
setBackgroundColor (wc.inputfield_active_bg); setBackgroundColor (wc.inputfield_active_bg);
if ( getStatusBar() )
getStatusBar()->clearMessage();
} }
} }
@ -534,6 +520,19 @@ void FLineEdit::onMouseMove (FMouseEvent* ev)
} }
} }
//----------------------------------------------------------------------
void FLineEdit::onWheel (FWheelEvent* ev)
{
// Sends the wheel event to the parent widget
auto widget = getParentWidget();
if ( widget )
{
FApplication::sendEvent(widget, ev);
}
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FLineEdit::onTimer (FTimerEvent*) void FLineEdit::onTimer (FTimerEvent*)
{ {
@ -652,6 +651,10 @@ void FLineEdit::onFocusOut (FFocusEvent*)
void FLineEdit::adjustLabel() void FLineEdit::adjustLabel()
{ {
auto label_width = getColumnWidth(label_text); auto label_width = getColumnWidth(label_text);
auto w = label_associated_widget;
if ( ! w )
return;
if ( hasHotkey() ) if ( hasHotkey() )
label_width--; label_width--;
@ -662,12 +665,12 @@ void FLineEdit::adjustLabel()
switch ( label_orientation ) switch ( label_orientation )
{ {
case label_above: case label_above:
label->setGeometry ( FPoint(getX(), getY() - 1) label->setGeometry ( FPoint(w->getX(), w->getY() - 1)
, FSize(label_width, 1) ); , FSize(label_width, 1) );
break; break;
case label_left: case label_left:
label->setGeometry ( FPoint(getX() - int(label_width) - 1, getY()) label->setGeometry ( FPoint(w->getX() - int(label_width) - 1, w->getY())
, FSize(label_width, 1) ); , FSize(label_width, 1) );
break; break;
} }

View File

@ -180,31 +180,6 @@ void FListBox::setGeometry ( const FPoint& pos, const FSize& size
} }
} }
//----------------------------------------------------------------------
bool FListBox::setFocus (bool enable)
{
FWidget::setFocus(enable);
if ( enable )
{
if ( getStatusBar() )
{
const auto& msg = getStatusbarMessage();
const auto& curMsg = getStatusBar()->getMessage();
if ( curMsg != msg )
getStatusBar()->setMessage(msg);
}
}
else
{
if ( getStatusBar() )
getStatusBar()->clearMessage();
}
return enable;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListBox::setText (const FString& txt) void FListBox::setText (const FString& txt)
{ {

View File

@ -112,56 +112,36 @@ bool FMenuItem::setFocus (bool enable)
{ {
FWidget::setFocus(enable); FWidget::setFocus(enable);
if ( enable ) if ( ! enable || ! isEnabled() || selected )
return enable;
auto menu_list = getFMenuList(*getSuperMenu());
setSelected();
if ( menu_list )
{ {
if ( isEnabled() ) menu_list->unselectItem();
{ menu_list->setSelectedItem(this);
if ( ! selected )
{
auto menu_list = getFMenuList(*getSuperMenu());
setSelected();
if ( menu_list )
{
menu_list->unselectItem();
menu_list->setSelectedItem(this);
}
if ( getStatusBar() )
getStatusBar()->drawMessage();
auto parent = getSuperMenu();
if ( isMenuBar(parent) )
{
auto menubar_ptr = static_cast<FMenuBar*>(parent);
if ( menubar_ptr )
menubar_ptr->redraw();
}
else if ( isMenu(parent) )
{
auto menu_ptr = static_cast<FMenu*>(parent);
if ( menu_ptr )
menu_ptr->redraw();
}
}
if ( getStatusBar() )
{
const auto& msg = getStatusbarMessage();
const auto& curMsg = getStatusBar()->getMessage();
if ( curMsg != msg )
getStatusBar()->setMessage(msg);
}
}
} }
else
if ( getStatusBar() )
getStatusBar()->drawMessage();
auto parent = getSuperMenu();
if ( isMenuBar(parent) )
{ {
if ( isEnabled() && getStatusBar() ) auto menubar_ptr = static_cast<FMenuBar*>(parent);
getStatusBar()->clearMessage();
if ( menubar_ptr )
menubar_ptr->redraw();
}
else if ( isMenu(parent) )
{
auto menu_ptr = static_cast<FMenu*>(parent);
if ( menu_ptr )
menu_ptr->redraw();
} }
return enable; return enable;

View File

@ -174,6 +174,21 @@ void FObject::delChild (FObject* obj)
} }
} }
//----------------------------------------------------------------------
void FObject::setParent (FObject* parent)
{
// Sets a new parent object
if ( ! parent )
return;
removeParent();
parent_obj = parent;
has_parent = true;
parent->children_list.push_back(this);
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FObject::event (FEvent* ev) bool FObject::event (FEvent* ev)
{ {

View File

@ -273,7 +273,7 @@ void FScrollbar::onMouseDown (FMouseEvent* ev)
return; return;
} }
// Process left button // Process left mouse button
scroll_type = getClickedScrollType(mouse_x, mouse_y); scroll_type = getClickedScrollType(mouse_x, mouse_y);
if ( scroll_type == FScrollbar::noScroll ) if ( scroll_type == FScrollbar::noScroll )
@ -341,7 +341,7 @@ void FScrollbar::onMouseMove (FMouseEvent* ev)
return; return;
} }
// Process left button // Process left mouse button
int new_scroll_type = getClickedScrollType(mouse_x, mouse_y); int new_scroll_type = getClickedScrollType(mouse_x, mouse_y);
if ( scroll_type == FScrollbar::scrollJump ) if ( scroll_type == FScrollbar::scrollJump )

View File

@ -21,6 +21,8 @@
***********************************************************************/ ***********************************************************************/
#include <limits> #include <limits>
#include "final/fpoint.h"
#include "final/fsize.h" #include "final/fsize.h"
namespace finalcut namespace finalcut
@ -100,6 +102,26 @@ bool FSize::isEmpty() const
return width == 0 && height == 0; return width == 0 && height == 0;
} }
//----------------------------------------------------------------------
void FSize::scaleBy (int dx, int dy)
{
if ( dx < 0 )
width -= std::size_t(-dx);
else
width += std::size_t(dx);
if ( dx < 0 )
height -= std::size_t(-dy);
else
height += std::size_t(dy);
}
//----------------------------------------------------------------------
void FSize::scaleBy (const FPoint& d)
{
scaleBy (d.getX(), d.getY());
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
std::ostream& operator << (std::ostream& outstr, const FSize& s) std::ostream& operator << (std::ostream& outstr, const FSize& s)
{ {

428
src/fspinbox.cpp Normal file
View File

@ -0,0 +1,428 @@
/***********************************************************************
* fspinbox.cpp - Widget FSpinBox *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
* as published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* The Final Cut is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this program. If not, see *
* <http://www.gnu.org/licenses/>. *
***********************************************************************/
#include <regex>
#include "final/fcolorpair.h"
#include "final/fevent.h"
#include "final/flabel.h"
#include "final/flineedit.h"
#include "final/fpoint.h"
#include "final/fsize.h"
#include "final/fspinbox.h"
#include "final/fstatusbar.h"
#include "final/fwidgetcolors.h"
namespace finalcut
{
//----------------------------------------------------------------------
// class FSpinBox
//----------------------------------------------------------------------
// constructors and destructor
//----------------------------------------------------------------------
FSpinBox::FSpinBox (FWidget* parent)
: FWidget(parent)
{
init();
}
//----------------------------------------------------------------------
FSpinBox::~FSpinBox() // destructor
{ }
// public methods of FSpinBox
//----------------------------------------------------------------------
void FSpinBox::setGeometry ( const FPoint& pos, const FSize& size
, bool adjust )
{
FWidget::setGeometry (pos, size, adjust);
FSize input_field_size(size);
input_field_size.scaleBy(-2, 0);
input_field.setGeometry (FPoint(1, 1), input_field_size, adjust);
}
//----------------------------------------------------------------------
bool FSpinBox::setEnable (bool enable)
{
FWidget::setEnable(enable);
input_field.setEnable(enable);
return enable;
}
//----------------------------------------------------------------------
bool FSpinBox::setFocus (bool enable)
{
FWidget::setFocus(enable);
input_field.setFocus(enable);
return enable;
}
//----------------------------------------------------------------------
bool FSpinBox::setShadow (bool enable)
{
if ( enable
&& getEncoding() != fc::VT100
&& getEncoding() != fc::ASCII )
{
setFlags().shadow = true;
setShadowSize(FSize(1, 1));
}
else
{
setFlags().shadow = false;
setShadowSize(FSize(0, 0));
}
return getFlags().shadow;
}
//----------------------------------------------------------------------
void FSpinBox::setValue (sInt64 n)
{
if ( n > max )
value = max;
else if ( n < min )
value = min;
else
value = n;
updateInputField();
}
//----------------------------------------------------------------------
void FSpinBox::setMinValue (sInt64 n)
{
if ( n <= max )
value = min = n;
}
//----------------------------------------------------------------------
void FSpinBox::setMaxValue (sInt64 n)
{
if ( n >= min )
max = n;
}
//----------------------------------------------------------------------
void FSpinBox::setRange (sInt64 m, sInt64 n)
{
if ( m <= n )
{
value = min = m;
max = n;
}
}
//----------------------------------------------------------------------
void FSpinBox::setPrefix (const FString& text)
{
pfix = text;
updateInputField();
}
//----------------------------------------------------------------------
void FSpinBox::setSuffix (const FString& text)
{
sfix = text;
updateInputField();
}
//----------------------------------------------------------------------
void FSpinBox::draw()
{
const auto& wc = getFWidgetColors();
FColorPair inc_button_color = [&] () -> FColorPair
{
if ( value == max )
return FColorPair ( wc.scrollbar_button_inactive_fg
, wc.scrollbar_button_inactive_bg );
else
return FColorPair ( wc.scrollbar_button_fg
, wc.scrollbar_button_bg );
}();
FColorPair dec_button_color = [&] () -> FColorPair
{
if ( value == min )
return FColorPair ( wc.scrollbar_button_inactive_fg
, wc.scrollbar_button_inactive_bg );
else
return FColorPair ( wc.scrollbar_button_fg
, wc.scrollbar_button_bg );
}();
print() << FPoint(getWidth() - 1, 1)
<< dec_button_color
<< fc::BlackDownPointingTriangle // ▼
<< inc_button_color
<< fc::BlackUpPointingTriangle; // ▲
if ( getFlags().shadow )
drawShadow(this);
}
//----------------------------------------------------------------------
void FSpinBox::onKeyPress (FKeyEvent* ev)
{
if ( ! isEnabled() )
return;
FKey key = ev->key();
switch ( key )
{
case fc::Fkey_tab:
focusNextChild();
break;
case fc::Fkey_btab:
focusPrevChild();
break;
case fc::Fkey_up:
increaseValue();
ev->accept();
break;
case fc::Fkey_down:
decreaseValue();
ev->accept();
break;
default:
break;
}
if ( ev->isAccepted() )
updateInputField();
}
//----------------------------------------------------------------------
void FSpinBox::onMouseDown (FMouseEvent* ev)
{
if ( ev->getButton() != fc::LeftButton
&& ev->getButton() != fc::MiddleButton )
return;
forceFocus();
if ( min == max )
return;
int mouse_x = ev->getX();
int mouse_y = ev->getY();
if ( mouse_x == int(getWidth()) - 1 && mouse_y == 1 )
{
spining_state = FSpinBox::spinDown;
decreaseValue();
updateInputField();
threshold_reached = false;
addTimer(threshold_time);
}
else if ( mouse_x == int(getWidth()) && mouse_y == 1 )
{
spining_state = FSpinBox::spinUp;
increaseValue();
updateInputField();
threshold_reached = false;
addTimer(threshold_time);
}
else
delOwnTimer();
}
//----------------------------------------------------------------------
void FSpinBox::onMouseUp (FMouseEvent*)
{
delOwnTimer();
spining_state = FSpinBox::noSpin;
}
//----------------------------------------------------------------------
void FSpinBox::onWheel (FWheelEvent* ev)
{
int wheel = ev->getWheel();
delOwnTimer();
forceFocus();
spining_state = FSpinBox::noSpin;
switch ( wheel )
{
case fc::WheelUp:
increaseValue();
updateInputField();
break;
case fc::WheelDown:
decreaseValue();
updateInputField();
break;
default:
break;
}
}
//----------------------------------------------------------------------
void FSpinBox::onTimer (FTimerEvent*)
{
if ( ! threshold_reached )
{
threshold_reached = true;
delOwnTimer();
addTimer(repeat_time);
}
switch ( spining_state )
{
case FSpinBox::spinUp:
increaseValue();
updateInputField();
break;
case FSpinBox::spinDown:
decreaseValue();
updateInputField();
break;
default:
break;
}
}
// private methods of FSpinBox
//----------------------------------------------------------------------
void FSpinBox::init()
{
setShadow();
auto parent_widget = getParentWidget();
FLabel* label = input_field.getLabelObject();
label->setParent(getParent());
label->setForegroundColor (parent_widget->getForegroundColor());
label->setBackgroundColor (parent_widget->getBackgroundColor());
input_field.setLabelAssociatedWidget(this);
input_field.setInputFilter("[-[:digit:]]"); // Only numbers
input_field.unsetShadow();
input_field << value;
input_field.addCallback
(
"changed",
F_METHOD_CALLBACK (this, &FSpinBox::cb_inputFieldChange)
);
}
//----------------------------------------------------------------------
inline void FSpinBox::updateInputField()
{
input_field.clear();
input_field << pfix << value << sfix;
input_field.redraw();
redraw();
updateTerminal();
}
//----------------------------------------------------------------------
inline void FSpinBox::increaseValue()
{
if ( value < max )
{
value++;
processChanged();
}
else
delOwnTimer();
}
//----------------------------------------------------------------------
inline void FSpinBox::decreaseValue()
{
if ( value > min )
{
value--;
processChanged();
}
else
delOwnTimer();
}
//----------------------------------------------------------------------
void FSpinBox::processChanged()
{
emitCallback("changed");
}
//----------------------------------------------------------------------
void FSpinBox::forceFocus()
{
if ( hasFocus() )
return;
auto focused_widget = getFocusWidget();
setFocus();
if ( focused_widget )
focused_widget->redraw();
redraw();
if ( getStatusBar() )
getStatusBar()->drawMessage();
}
//----------------------------------------------------------------------
void FSpinBox::cb_inputFieldChange (finalcut::FWidget* w, FDataPtr)
{
auto lineedit = static_cast<FLineEdit*>(w);
if ( lineedit->getText().isEmpty() )
value = 0;
else
{
std::wregex regex(L"[-]?[[:xdigit:]]+");
std::wsmatch match;
std::wstring text = lineedit->getText().wc_str();
if ( std::regex_search(text, match, regex) )
{
FString tmp(match[0]);
value = tmp.toLong();
}
else
value = 0;
}
if ( value > max )
value = max;
else if ( value < min )
value = min;
updateInputField();
processChanged();
}
} // namespace finalcut

View File

@ -150,6 +150,30 @@ const wchar_t ambiguous_width_list[] =
#endif #endif
}; };
const wchar_t reverse_newfont_list[] =
{
fc::NF_rev_left_arrow2,
fc::NF_rev_right_arrow2,
fc::NF_rev_border_corner_upper_right,
fc::NF_rev_border_line_right,
fc::NF_rev_border_line_vertical_left,
fc::NF_rev_border_corner_lower_right,
fc::NF_rev_up_arrow2,
fc::NF_rev_down_arrow2,
fc::NF_rev_up_arrow1,
fc::NF_rev_down_arrow1,
fc::NF_rev_left_arrow1,
fc::NF_rev_right_arrow1,
fc::NF_rev_menu_button1,
fc::NF_rev_menu_button2,
fc::NF_rev_up_pointing_triangle1,
fc::NF_rev_down_pointing_triangle1,
fc::NF_rev_up_pointing_triangle2,
fc::NF_rev_down_pointing_triangle2,
fc::NF_rev_menu_button3,
fc::NF_rev_border_line_right_and_left
};
// FTerm non-member functions // FTerm non-member functions
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -182,6 +206,18 @@ inline bool hasAmbiguousWidth (wchar_t wchar)
return false; return false;
} }
//----------------------------------------------------------------------
bool isReverseNewFontchar (wchar_t wchar)
{
const auto& begin = std::begin(reverse_newfont_list);
const auto& end = std::end(reverse_newfont_list);
if ( std::find(begin, end, wchar) != end ) // found
return true;
return false;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
wchar_t cp437_to_unicode (uChar c) wchar_t cp437_to_unicode (uChar c)
{ {

View File

@ -143,37 +143,23 @@ bool FToggleButton::setEnable (bool enable)
bool FToggleButton::setFocus (bool enable) bool FToggleButton::setFocus (bool enable)
{ {
FWidget::setFocus(enable); FWidget::setFocus(enable);
const auto& wc = getFWidgetColors();
if ( enable ) if ( isEnabled() )
{ {
if ( isEnabled() ) const auto& wc = getFWidgetColors();
if ( enable )
{ {
if ( isRadioButton() ) if ( isRadioButton() )
focus_inside_group = false; focus_inside_group = false;
setForegroundColor (wc.toggle_button_active_focus_fg); setForegroundColor (wc.toggle_button_active_focus_fg);
setBackgroundColor (wc.toggle_button_active_focus_bg); setBackgroundColor (wc.toggle_button_active_focus_bg);
if ( getStatusBar() )
{
const auto& msg = getStatusbarMessage();
const auto& curMsg = getStatusBar()->getMessage();
if ( curMsg != msg )
getStatusBar()->setMessage(msg);
}
} }
} else
else
{
if ( isEnabled() )
{ {
setForegroundColor (wc.toggle_button_active_fg); setForegroundColor (wc.toggle_button_active_fg);
setBackgroundColor (wc.toggle_button_active_bg); setBackgroundColor (wc.toggle_button_active_bg);
if ( getStatusBar() )
getStatusBar()->clearMessage();
} }
} }

View File

@ -2864,41 +2864,16 @@ inline void FVTerm::markAsPrinted (uInt from, uInt to, uInt line)
inline void FVTerm::newFontChanges (FChar*& next_char) inline void FVTerm::newFontChanges (FChar*& next_char)
{ {
// NewFont special cases // NewFont special cases
if ( isNewFont() ) if ( ! isNewFont() )
{ return;
switch ( next_char->ch )
{
case fc::LowerHalfBlock:
next_char->ch = fc::UpperHalfBlock;
// fall through
case fc::NF_rev_left_arrow2:
case fc::NF_rev_right_arrow2:
case fc::NF_rev_border_corner_upper_right:
case fc::NF_rev_border_line_right:
case fc::NF_rev_border_line_vertical_left:
case fc::NF_rev_border_corner_lower_right:
case fc::NF_rev_up_arrow2:
case fc::NF_rev_down_arrow2:
case fc::NF_rev_up_arrow1:
case fc::NF_rev_down_arrow1:
case fc::NF_rev_left_arrow1:
case fc::NF_rev_right_arrow1:
case fc::NF_rev_menu_button1:
case fc::NF_rev_menu_button2:
case fc::NF_rev_up_pointing_triangle1:
case fc::NF_rev_down_pointing_triangle1:
case fc::NF_rev_up_pointing_triangle2:
case fc::NF_rev_down_pointing_triangle2:
case fc::NF_rev_menu_button3:
case fc::NF_rev_border_line_right_and_left:
// Show in reverse video
next_char->attr.bit.reverse = true;
break;
default: if ( next_char->ch == fc::LowerHalfBlock )
break; {
} next_char->ch = fc::UpperHalfBlock;
next_char->attr.bit.reverse = true;
} }
else if ( isReverseNewFontchar(next_char->ch) )
next_char->attr.bit.reverse = true; // Show in reverse video
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -284,23 +284,11 @@ bool FWidget::setFocus (bool enable)
FWidget::setFocusWidget(this); FWidget::setFocusWidget(this);
} }
auto window = FWindow::getWindowWidget(this); // Activates the window with the focused widget
setWindowFocus (enable);
// set window focus
if ( enable && window )
{
if ( ! window->isWindowActive() )
{
bool has_raised = window->raiseWindow();
FWindow::setActiveWindow(window);
if ( has_raised && window->isVisible() && window->isShown() )
window->redraw();
}
window->setWindowFocusWidget(this);
}
// Set status bar text for widget focus
setStatusbarText (enable);
return (flags.focus = enable); return (flags.focus = enable);
} }
@ -1794,17 +1782,7 @@ inline void FWidget::insufficientSpaceAdjust()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FWidget::KeyPressEvent (FKeyEvent* kev) void FWidget::KeyPressEvent (FKeyEvent* kev)
{ {
bool accpt_focus{false}; FWidget* widget(this);
if ( kev->key() == fc::Fkey_tab )
accpt_focus = focusNextChild();
else if ( kev->key() == fc::Fkey_btab )
accpt_focus = focusPrevChild();
if ( accpt_focus )
return;
FWidget* widget(this);
while ( widget ) while ( widget )
{ {
@ -1812,15 +1790,20 @@ void FWidget::KeyPressEvent (FKeyEvent* kev)
if ( ! kev->isAccepted() ) if ( ! kev->isAccepted() )
{ {
if ( kev->key() == fc::Fkey_right FKey key = kev->key();
|| kev->key() == fc::Fkey_down )
accpt_focus = focusNextChild();
else if ( kev->key() == fc::Fkey_left
|| kev->key() == fc::Fkey_up )
accpt_focus = focusPrevChild();
if ( accpt_focus ) if ( [&] () -> bool
{
if ( isFocusNextKey(key) )
return focusNextChild();
else if ( isFocusPrevKey(key) )
return focusPrevChild();
return false;
}() )
{
return; return;
}
} }
if ( kev->isAccepted() || widget->isRootWidget() ) if ( kev->isAccepted() || widget->isRootWidget() )
@ -1846,6 +1829,31 @@ void FWidget::KeyDownEvent (FKeyEvent* kev)
} }
} }
//----------------------------------------------------------------------
void FWidget::setWindowFocus (bool enable)
{
// set the window focus
if ( ! enable )
return;
auto window = FWindow::getWindowWidget(this);
if ( ! window )
return;
if ( ! window->isWindowActive() )
{
bool has_raised = window->raiseWindow();
FWindow::setActiveWindow(window);
if ( has_raised && window->isVisible() && window->isShown() )
window->redraw();
}
window->setWindowFocusWidget(this);
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FWidget::FCallbackPtr FWidget::getCallbackPtr (FCallback cb_function) FWidget::FCallbackPtr FWidget::getCallbackPtr (FCallback cb_function)
{ {
@ -1954,6 +1962,26 @@ void FWidget::setColorTheme()
wcolors.set16ColorTheme(); wcolors.set16ColorTheme();
} }
//----------------------------------------------------------------------
void FWidget::setStatusbarText (bool enable)
{
if ( ! isEnabled() || ! getStatusBar() )
return;
if ( enable )
{
const auto& msg = getStatusbarMessage();
const auto& curMsg = getStatusBar()->getMessage();
if ( curMsg != msg )
getStatusBar()->setMessage(msg);
}
else
{
getStatusBar()->clearMessage();
}
}
// non-member functions // non-member functions
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -27,6 +27,28 @@ namespace finalcut
{ {
// FWidget non-member functions // FWidget non-member functions
//----------------------------------------------------------------------
bool isFocusNextKey (FKey key)
{
if ( key == fc::Fkey_tab
|| key == fc::Fkey_right
|| key == fc::Fkey_down )
return true;
return false;
}
//----------------------------------------------------------------------
bool isFocusPrevKey (FKey key)
{
if ( key == fc::Fkey_btab
|| key == fc::Fkey_left
|| key == fc::Fkey_up )
return true;
return false;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FKey getHotkey (const FString& text) FKey getHotkey (const FString& text)
{ {

View File

@ -117,6 +117,8 @@ void FWidgetColors::set8ColorTheme()
scrollbar_bg = fc::LightGray; scrollbar_bg = fc::LightGray;
scrollbar_button_fg = fc::Black; scrollbar_button_fg = fc::Black;
scrollbar_button_bg = fc::LightGray; scrollbar_button_bg = fc::LightGray;
scrollbar_button_inactive_fg = fc::Cyan;
scrollbar_button_inactive_bg = fc::LightGray;
progressbar_fg = fc::Blue; progressbar_fg = fc::Blue;
progressbar_bg = fc::LightGray; progressbar_bg = fc::LightGray;
} }
@ -206,6 +208,8 @@ void FWidgetColors::set16ColorTheme()
scrollbar_bg = fc::LightBlue; scrollbar_bg = fc::LightBlue;
scrollbar_button_fg = fc::Black; scrollbar_button_fg = fc::Black;
scrollbar_button_bg = fc::LightGray; scrollbar_button_bg = fc::LightGray;
scrollbar_button_inactive_fg = fc::DarkGray;
scrollbar_button_inactive_bg = fc::LightGray;
progressbar_fg = fc::DarkGray; progressbar_fg = fc::DarkGray;
progressbar_bg = fc::LightBlue; progressbar_bg = fc::LightBlue;

View File

@ -72,7 +72,7 @@ class FToolTip;
class FDialog : public FWindow class FDialog : public FWindow
{ {
public: public:
// Using-declaration // Using-declaration
using FWindow::setResizeable; using FWindow::setResizeable;
// Enumeration // Enumeration

View File

@ -62,6 +62,7 @@
#include <final/fscrollbar.h> #include <final/fscrollbar.h>
#include <final/fscrollview.h> #include <final/fscrollview.h>
#include <final/fsize.h> #include <final/fsize.h>
#include <final/fspinbox.h>
#include <final/fstartoptions.h> #include <final/fstartoptions.h>
#include <final/fstatusbar.h> #include <final/fstatusbar.h>
#include <final/fstring.h> #include <final/fstring.h>

View File

@ -70,6 +70,9 @@ class FLabel;
class FLineEdit : public FWidget class FLineEdit : public FWidget
{ {
public: public:
// Using-declaration
using FWidget::setGeometry;
// Enumerations // Enumerations
enum label_o enum label_o
{ {
@ -83,9 +86,6 @@ class FLineEdit : public FWidget
password = 1 password = 1
}; };
// Using-declaration
using FWidget::setGeometry;
// Constructor // Constructor
explicit FLineEdit (FWidget* = nullptr); explicit FLineEdit (FWidget* = nullptr);
explicit FLineEdit (const FString&, FWidget* = nullptr); explicit FLineEdit (const FString&, FWidget* = nullptr);
@ -118,7 +118,8 @@ class FLineEdit : public FWidget
FString getText() const; FString getText() const;
std::size_t getMaxLength() const; std::size_t getMaxLength() const;
std::size_t getCursorPosition() const; std::size_t getCursorPosition() const;
int getLabelOrientation(); FLabel* getLabelObject() const;
label_o getLabelOrientation();
// Mutators // Mutators
void setText (const FString&); void setText (const FString&);
@ -129,6 +130,7 @@ class FLineEdit : public FWidget
void setLabelText (const FString&); void setLabelText (const FString&);
void setInputType (const inputType); void setInputType (const inputType);
void setLabelOrientation (const label_o); void setLabelOrientation (const label_o);
void setLabelAssociatedWidget (FWidget*);
void setGeometry ( const FPoint&, const FSize& void setGeometry ( const FPoint&, const FSize&
, bool = true ) override; , bool = true ) override;
bool setEnable(bool) override; bool setEnable(bool) override;
@ -154,6 +156,7 @@ class FLineEdit : public FWidget
void onMouseDown (FMouseEvent*) override; void onMouseDown (FMouseEvent*) override;
void onMouseUp (FMouseEvent*) override; void onMouseUp (FMouseEvent*) override;
void onMouseMove (FMouseEvent*) override; void onMouseMove (FMouseEvent*) override;
void onWheel (FWheelEvent*) override;
void onTimer (FTimerEvent*) override; void onTimer (FTimerEvent*) override;
void onAccel (FAccelEvent*) override; void onAccel (FAccelEvent*) override;
void onHide (FHideEvent*) override; void onHide (FHideEvent*) override;
@ -206,22 +209,26 @@ class FLineEdit : public FWidget
void processChanged(); void processChanged();
// Data members // Data members
FString text{""}; FString text{""};
FString print_text{""}; FString print_text{""};
FString label_text{""}; FString label_text{""};
FLabel* label{}; FLabel* label{};
std::wstring input_filter{}; FWidget* label_associated_widget{this};
dragScroll drag_scroll{FLineEdit::noScroll}; std::wstring input_filter{};
label_o label_orientation{FLineEdit::label_left}; dragScroll drag_scroll{FLineEdit::noScroll};
inputType input_type{FLineEdit::textfield}; label_o label_orientation{FLineEdit::label_left};
int scroll_repeat{100}; inputType input_type{FLineEdit::textfield};
bool scroll_timer{false}; int scroll_repeat{100};
bool insert_mode{true}; bool scroll_timer{false};
std::size_t cursor_pos{NOT_SET}; bool insert_mode{true};
std::size_t text_offset{0}; std::size_t cursor_pos{NOT_SET};
std::size_t char_width_offset{0}; std::size_t text_offset{0};
std::size_t x_pos{0}; std::size_t char_width_offset{0};
std::size_t max_length{std::numeric_limits<std::size_t>::max()}; std::size_t x_pos{0};
std::size_t max_length{std::numeric_limits<std::size_t>::max()};
// Friend class
friend class FSpinBox;
}; };
@ -243,8 +250,12 @@ inline std::size_t FLineEdit::getCursorPosition() const
{ return cursor_pos; } { return cursor_pos; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline int FLineEdit::getLabelOrientation() inline FLabel* FLineEdit::getLabelObject() const
{ return int(label_orientation); } { return label; }
//----------------------------------------------------------------------
inline FLineEdit::label_o FLineEdit::getLabelOrientation()
{ return label_orientation; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FLineEdit::setInputFilter (const FString& regex_string) inline void FLineEdit::setInputFilter (const FString& regex_string)
@ -258,6 +269,10 @@ inline void FLineEdit::clearInputFilter()
inline void FLineEdit::setInputType (const inputType type) inline void FLineEdit::setInputType (const inputType type)
{ input_type = type; } { input_type = type; }
//----------------------------------------------------------------------
inline void FLineEdit::setLabelAssociatedWidget (FWidget* w)
{ label_associated_widget = w; }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FLineEdit::setEnable() inline bool FLineEdit::setEnable()
{ return setEnable(true); } { return setEnable(true); }

View File

@ -142,12 +142,12 @@ inline void FListBoxItem::clear()
class FListBox : public FWidget class FListBox : public FWidget
{ {
public: public:
// Typedef
typedef std::vector<FListBoxItem> listBoxItems;
// Using-declaration // Using-declaration
using FWidget::setGeometry; using FWidget::setGeometry;
// Typedef
typedef std::vector<FListBoxItem> listBoxItems;
// Constructor // Constructor
explicit FListBox (FWidget* = nullptr); explicit FListBox (FWidget* = nullptr);
template <typename Iterator, typename InsertConverter> template <typename Iterator, typename InsertConverter>
@ -188,9 +188,6 @@ class FListBox : public FWidget
void setMultiSelection (); void setMultiSelection ();
void unsetMultiSelection (); void unsetMultiSelection ();
bool setDisable() override; bool setDisable() override;
bool setFocus (bool) override;
bool setFocus() override;
bool unsetFocus() override;
void setText (const FString&); void setText (const FString&);
// Inquiries // Inquiries
@ -442,14 +439,6 @@ inline void FListBox::unsetMultiSelection()
inline bool FListBox::setDisable() inline bool FListBox::setDisable()
{ return setEnable(false); } { return setEnable(false); }
//----------------------------------------------------------------------
inline bool FListBox::setFocus()
{ return setFocus(true); }
//----------------------------------------------------------------------
inline bool FListBox::unsetFocus()
{ return setFocus(false); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FListBox::isSelected (std::size_t index) inline bool FListBox::isSelected (std::size_t index)
{ return index2iterator(index - 1)->selected; } { return index2iterator(index - 1)->selected; }

View File

@ -113,6 +113,7 @@ class FObject
void removeParent(); void removeParent();
void addChild (FObject*); void addChild (FObject*);
void delChild (FObject*); void delChild (FObject*);
void setParent (FObject*);
// Event handler // Event handler
virtual bool event (FEvent*); virtual bool event (FEvent*);

View File

@ -44,6 +44,9 @@
namespace finalcut namespace finalcut
{ {
// class forward declaration
class FPoint;
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// class FSize // class FSize
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -95,6 +98,10 @@ class FSize
std::size_t& width_ref(); std::size_t& width_ref();
std::size_t& height_ref(); std::size_t& height_ref();
// Methods
void scaleBy (int, int);
void scaleBy (const FPoint&);
private: private:
// Data members // Data members
std::size_t width{0}; std::size_t width{0};

View File

@ -0,0 +1,219 @@
/***********************************************************************
* fspinbox.h - Widget FSpinBox *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2019 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
* as published by the Free Software Foundation; either version 3 of *
* the License, or (at your option) any later version. *
* *
* The Final Cut is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this program. If not, see *
* <http://www.gnu.org/licenses/>. *
***********************************************************************/
/* Inheritance diagram
*
*
*
* FTerm
*
*
*
*
* FVTerm FObject
*
*
*
*
*
*
* FWidget
*
*
*
*
* FSpinBox
*
*/
#ifndef FSPINBOX_H
#define FSPINBOX_H
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
#error "Only <final/final.h> can be included directly."
#endif
#include "final/fwidget.h"
namespace finalcut
{
// class forward declaration
class FLineEdit;
//----------------------------------------------------------------------
// class FSpinBox
//----------------------------------------------------------------------
class FSpinBox : public FWidget
{
public:
// Using-declaration
using FWidget::setGeometry;
// Constructors
explicit FSpinBox (FWidget* = nullptr);
// Disable copy constructor
FSpinBox (const FSpinBox&) = delete;
// Destructor
~FSpinBox();
// Disable assignment operator (=)
FSpinBox& operator = (const FSpinBox&) = delete;
// Accessors
sInt64 getValue();
FString getPrefix() const;
FString getSuffix() const;
FLineEdit::label_o getLabelOrientation();
// Mutators
void setGeometry ( const FPoint&, const FSize&
, bool = true ) override;
bool setEnable (bool) override;
bool setEnable() override;
bool unsetEnable() override;
bool setDisable() override;
bool setFocus (bool) override;
bool setFocus() override;
bool unsetFocus() override;
bool setShadow (bool);
bool setShadow();
bool unsetShadow();
void setValue (sInt64);
void setMinValue (sInt64);
void setMaxValue (sInt64);
void setRange (sInt64, sInt64);
void setPrefix (const FString&);
void setSuffix (const FString&);
void setLabelText (const FString&);
void setLabelOrientation (const FLineEdit::label_o);
// Inquiries
bool hasShadow();
// Methods
void draw() override;
// Event handlers
void onKeyPress (FKeyEvent*) override;
void onMouseDown (FMouseEvent*) override;
void onMouseUp (FMouseEvent*) override;
void onWheel (FWheelEvent*) override;
void onTimer (FTimerEvent*) override;
private:
// Enumeration
enum spiningState
{
noSpin = 0,
spinUp = 1,
spinDown = 2
};
// Methods
void init();
void updateInputField();
void increaseValue();
void decreaseValue();
void processChanged();
void forceFocus();
// Callback methods
void cb_inputFieldChange (finalcut::FWidget*, FDataPtr);
// Data members
FLineEdit input_field{this};
sInt64 value{0};
sInt64 min{std::numeric_limits<sInt64>::min()};
sInt64 max{std::numeric_limits<sInt64>::max()};
FString pfix{};
FString sfix{};
spiningState spining_state{FSpinBox::noSpin};
bool threshold_reached{false};
int threshold_time{500};
int repeat_time{10};
};
// FSpinBox inline functions
//----------------------------------------------------------------------
inline sInt64 FSpinBox::getValue()
{ return value; }
//----------------------------------------------------------------------
FString FSpinBox::getPrefix() const
{ return pfix; }
//----------------------------------------------------------------------
FString FSpinBox::getSuffix() const
{ return sfix; }
//----------------------------------------------------------------------
inline FLineEdit::label_o FSpinBox::getLabelOrientation()
{ return input_field.getLabelOrientation(); }
//----------------------------------------------------------------------
inline bool FSpinBox::setEnable()
{ return setEnable(true); }
//----------------------------------------------------------------------
inline bool FSpinBox::unsetEnable()
{ return setEnable(false); }
//----------------------------------------------------------------------
inline bool FSpinBox::setDisable()
{ return setEnable(false); }
//----------------------------------------------------------------------
inline bool FSpinBox::setFocus()
{ return setFocus(true); }
//----------------------------------------------------------------------
inline bool FSpinBox::unsetFocus()
{ return setFocus(false); }
//----------------------------------------------------------------------
inline bool FSpinBox::setShadow()
{ return setShadow(true); }
//----------------------------------------------------------------------
inline bool FSpinBox::unsetShadow()
{ return setShadow(false); }
//----------------------------------------------------------------------
inline bool FSpinBox::hasShadow()
{ return getFlags().shadow; }
//----------------------------------------------------------------------
inline void FSpinBox::setLabelText (const FString& s)
{ input_field.setLabelText(s); }
//----------------------------------------------------------------------
inline void FSpinBox::setLabelOrientation (const FLineEdit::label_o o)
{ input_field.setLabelOrientation(o); }
} // namespace finalcut
#endif // FSPINBOX_H

View File

@ -388,6 +388,7 @@ class FTerm final
// implemented in fterm_functions.cpp // implemented in fterm_functions.cpp
//---------------------------------------------------------------------- //----------------------------------------------------------------------
uInt env2uint (const char*); uInt env2uint (const char*);
bool isReverseNewFontchar (wchar_t);
wchar_t cp437_to_unicode (uChar); wchar_t cp437_to_unicode (uChar);
uChar unicode_to_cp437 (wchar_t); uChar unicode_to_cp437 (wchar_t);
FString getFullWidth (const FString&); FString getFullWidth (const FString&);

View File

@ -410,6 +410,7 @@ class FWidget : public FVTerm, public FObject
void insufficientSpaceAdjust(); void insufficientSpaceAdjust();
void KeyPressEvent (FKeyEvent*); void KeyPressEvent (FKeyEvent*);
void KeyDownEvent (FKeyEvent*); void KeyDownEvent (FKeyEvent*);
void setWindowFocus (bool);
FCallbackPtr getCallbackPtr (FCallback); FCallbackPtr getCallbackPtr (FCallback);
bool changeFocus (FWidget*, FWidget*, fc::FocusTypes); bool changeFocus (FWidget*, FWidget*, fc::FocusTypes);
void processDestroy(); void processDestroy();
@ -417,6 +418,7 @@ class FWidget : public FVTerm, public FObject
void drawWindows(); void drawWindows();
void drawChildren(); void drawChildren();
static void setColorTheme(); static void setColorTheme();
void setStatusbarText (bool);
// Data members // Data members
FPoint widget_cursor_position{-1, -1}; FPoint widget_cursor_position{-1, -1};
@ -527,6 +529,8 @@ class FWidget : public FVTerm, public FObject
// implemented in fwidget_functions.cpp // implemented in fwidget_functions.cpp
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void detectTermSize(); void detectTermSize();
bool isFocusNextKey (FKey);
bool isFocusPrevKey (FKey);
FKey getHotkey (const FString&); FKey getHotkey (const FString&);
std::size_t getHotkeyPos (const FString& src, FString& dest); std::size_t getHotkeyPos (const FString& src, FString& dest);
void setHotkeyViaString (FWidget*, const FString&); void setHotkeyViaString (FWidget*, const FString&);

View File

@ -134,6 +134,8 @@ class FWidgetColors final
FColor scrollbar_bg{fc::Default}; FColor scrollbar_bg{fc::Default};
FColor scrollbar_button_fg{fc::Default}; FColor scrollbar_button_fg{fc::Default};
FColor scrollbar_button_bg{fc::Default}; FColor scrollbar_button_bg{fc::Default};
FColor scrollbar_button_inactive_fg{fc::Default};
FColor scrollbar_button_inactive_bg{fc::Default};
FColor progressbar_fg{fc::Default}; FColor progressbar_fg{fc::Default};
FColor progressbar_bg{fc::Default}; FColor progressbar_bg{fc::Default};
}; };

View File

@ -59,6 +59,7 @@ class FSizeTest : public CPPUNIT_NS::TestFixture
void subtractionTest(); void subtractionTest();
void areaTest(); void areaTest();
void referenceTest(); void referenceTest();
void scaleTest();
void streamInsertionTest(); void streamInsertionTest();
void streamExtractionTest(); void streamExtractionTest();
@ -82,6 +83,7 @@ class FSizeTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST (subtractionTest); CPPUNIT_TEST (subtractionTest);
CPPUNIT_TEST (areaTest); CPPUNIT_TEST (areaTest);
CPPUNIT_TEST (referenceTest); CPPUNIT_TEST (referenceTest);
CPPUNIT_TEST (scaleTest);
CPPUNIT_TEST (streamInsertionTest); CPPUNIT_TEST (streamInsertionTest);
CPPUNIT_TEST (streamExtractionTest); CPPUNIT_TEST (streamExtractionTest);
@ -369,6 +371,37 @@ void FSizeTest::referenceTest()
CPPUNIT_ASSERT ( s1.getHeight() == 4 ); CPPUNIT_ASSERT ( s1.getHeight() == 4 );
} }
//----------------------------------------------------------------------
void FSizeTest::scaleTest()
{
finalcut::FSize s1 (15, 15);
CPPUNIT_ASSERT ( s1.getWidth() == 15 );
CPPUNIT_ASSERT ( s1.getHeight() == 15 );
CPPUNIT_ASSERT ( s1 == finalcut::FSize(15, 15) );
const finalcut::FPoint p1 (-2, -3);
s1.scaleBy(p1);
CPPUNIT_ASSERT ( s1.getWidth() == 13 );
CPPUNIT_ASSERT ( s1.getHeight() == 12 );
CPPUNIT_ASSERT ( s1 == finalcut::FSize(13, 12) );
const finalcut::FPoint p2 (3, 2);
s1.scaleBy(p2);
CPPUNIT_ASSERT ( s1.getWidth() == 16 );
CPPUNIT_ASSERT ( s1.getHeight() == 14 );
CPPUNIT_ASSERT ( s1 == finalcut::FSize(16, 14) );
s1.scaleBy(1, -1);
CPPUNIT_ASSERT ( s1.getWidth() == 17 );
CPPUNIT_ASSERT ( s1.getHeight() == 13 );
CPPUNIT_ASSERT ( s1 == finalcut::FSize(17, 13) );
s1.scaleBy(-2, 2);
CPPUNIT_ASSERT ( s1.getWidth() == 15 );
CPPUNIT_ASSERT ( s1.getHeight() == 15 );
CPPUNIT_ASSERT ( s1 == finalcut::FSize(15, 15) );
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FSizeTest::streamInsertionTest() void FSizeTest::streamInsertionTest()
{ {