Add new class FSwitch

This commit is contained in:
Markus Gans 2015-07-04 22:51:47 +02:00
parent f282e3de3a
commit e9548d068e
12 changed files with 189 additions and 8 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 361 B

View File

@ -20,6 +20,7 @@ libfinal_la_SOURCES = \
ftogglebutton.cpp \
fradiobutton.cpp \
fcheckbox.cpp \
fswitch.cpp \
flabel.cpp \
flistbox.cpp \
fdialog.cpp \
@ -45,6 +46,7 @@ finalcutinclude_HEADERS = \
fbuttongroup.h \
fcharmap.h \
fcheckbox.h \
fswitch.h \
fdialog.h \
fenum.h \
fevent.h \

View File

@ -129,8 +129,8 @@ LTLIBRARIES = $(lib_LTLIBRARIES)
libfinal_la_LIBADD =
am_libfinal_la_OBJECTS = fstring.lo fpoint.lo frect.lo fscrollbar.lo \
fprogressbar.lo flineedit.lo fbutton.lo fbuttongroup.lo \
ftogglebutton.lo fradiobutton.lo fcheckbox.lo flabel.lo \
flistbox.lo fdialog.lo fwindow.lo fmessagebox.lo \
ftogglebutton.lo fradiobutton.lo fcheckbox.lo fswitch.lo \
flabel.lo flistbox.lo fdialog.lo fwindow.lo fmessagebox.lo \
ffiledialog.lo ftextview.lo fstatusbar.lo fterm.lo fevent.lo \
foptimove.lo fapp.lo fwidget.lo fobject.lo
libfinal_la_OBJECTS = $(am_libfinal_la_OBJECTS)
@ -381,6 +381,7 @@ libfinal_la_SOURCES = \
ftogglebutton.cpp \
fradiobutton.cpp \
fcheckbox.cpp \
fswitch.cpp \
flabel.cpp \
flistbox.cpp \
fdialog.cpp \
@ -404,6 +405,7 @@ finalcutinclude_HEADERS = \
fbuttongroup.h \
fcharmap.h \
fcheckbox.h \
fswitch.h \
fdialog.h \
fenum.h \
fevent.h \
@ -529,6 +531,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fscrollbar.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fstatusbar.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fstring.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fswitch.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fterm.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ftextview.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ftogglebutton.Plo@am__quote@

View File

@ -12,12 +12,14 @@
//----------------------------------------------------------------------
FCheckBox::FCheckBox(FWidget* parent) : FToggleButton(parent)
{
init();
}
//----------------------------------------------------------------------
FCheckBox::FCheckBox ( const FString& txt,
FWidget* parent ) : FToggleButton(txt, parent)
{
init();
}
//----------------------------------------------------------------------
@ -27,6 +29,13 @@ FCheckBox::~FCheckBox() // destructor
// private methods of FCheckBox
//----------------------------------------------------------------------
void FCheckBox::init()
{
label_offset_pos = 4;
button_width = 4;
}
//----------------------------------------------------------------------
void FCheckBox::draw()
{

View File

@ -19,6 +19,7 @@ class FCheckBox : public FToggleButton
private:
FCheckBox (const FCheckBox&);
FCheckBox& operator = (const FCheckBox&);
void init();
void draw();
void drawCheckButton();

View File

@ -14,6 +14,7 @@
#include "fbutton.h"
#include "fradiobutton.h"
#include "fcheckbox.h"
#include "fswitch.h"
#include "fbuttongroup.h"
#include "flistbox.h"
#include "ftextview.h"

View File

@ -13,12 +13,14 @@
//----------------------------------------------------------------------
FRadioButton::FRadioButton(FWidget* parent) : FToggleButton(parent)
{
init();
}
//----------------------------------------------------------------------
FRadioButton::FRadioButton ( const FString& txt,
FWidget* parent ) : FToggleButton(txt, parent)
{
init();
}
//----------------------------------------------------------------------
@ -28,6 +30,13 @@ FRadioButton::~FRadioButton() // destructor
// private methods of FRadioButton
//----------------------------------------------------------------------
void FRadioButton::init()
{
label_offset_pos = 4;
button_width = 4;
}
//----------------------------------------------------------------------
void FRadioButton::draw()
{

View File

@ -18,6 +18,7 @@ class FRadioButton : public FToggleButton
private:
FRadioButton (const FRadioButton&);
FRadioButton& operator = (const FRadioButton&);
void init();
void draw();
void drawRadioButton();

107
src/fswitch.cpp Normal file
View File

@ -0,0 +1,107 @@
// fswitch.cpp
// class FSwitch
#include "fswitch.h"
//----------------------------------------------------------------------
// class FSwitch
//----------------------------------------------------------------------
// constructor and destructor
//----------------------------------------------------------------------
FSwitch::FSwitch(FWidget* parent) : FToggleButton(parent)
{
button_width = 11;
}
//----------------------------------------------------------------------
FSwitch::FSwitch ( const FString& txt,
FWidget* parent ) : FToggleButton(txt, parent)
{
switch_offset_pos = int(txt.getLength()) + 1;
button_width = 11;
}
//----------------------------------------------------------------------
FSwitch::~FSwitch() // destructor
{
}
// private methods of FSwitch
//----------------------------------------------------------------------
void FSwitch::draw()
{
setUpdateVTerm(false);
drawCheckButton();
drawLabel();
setUpdateVTerm(true);
FToggleButton::draw();
}
//----------------------------------------------------------------------
void FSwitch::drawCheckButton()
{
if ( ! isVisible() )
return;
gotoxy (xpos+xmin-1+switch_offset_pos, ypos+ymin-1);
if ( checked )
{
if ( hasFocus() )
setColor (wc.button_hotkey_fg, wc.button_active_focus_bg);
else
setColor (wc.button_hotkey_fg, wc.button_active_bg);
print (" On ");
setColor (wc.button_inactive_fg, wc.button_inactive_bg);
print (" Off ");
}
else
{
setColor (wc.button_inactive_fg, wc.button_inactive_bg);
print (" On ");
if ( hasFocus() )
setColor (wc.button_hotkey_fg, wc.button_active_focus_bg);
else
setColor (wc.button_hotkey_fg, wc.button_active_bg);
print (" Off ");
}
}
// public methods of FSwitch
//----------------------------------------------------------------------
void FSwitch::setText (FString txt)
{
FToggleButton::setText(txt);
switch_offset_pos = int(txt.getLength()) + 1;
}
//----------------------------------------------------------------------
void FSwitch::onKeyPress (FKeyEvent* event)
{
switch ( event->key() )
{
case fc::Fkey_home:
case fc::Fkey_left:
setChecked();
event->accept();
break;
case fc::Fkey_end:
case fc::Fkey_right:
unsetChecked();
event->accept();
break;
}
if ( event->isAccepted() )
{
draw();
updateTerminal();
}
else
FToggleButton::onKeyPress(event);
}

44
src/fswitch.h Normal file
View File

@ -0,0 +1,44 @@
// fswitch.h
// class FSwitch
#ifndef _FSWITCH_H
#define _FSWITCH_H
#include "ftogglebutton.h"
//----------------------------------------------------------------------
// class FSwitch
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class FSwitch : public FToggleButton
{
private:
int switch_offset_pos;
private:
FSwitch (const FSwitch&);
FSwitch& operator = (const FSwitch&);
void draw();
void drawCheckButton();
public:
explicit FSwitch (FWidget* parent=0); // constructor
FSwitch (const FString&, FWidget* parent=0); // constructor
virtual ~FSwitch(); // destructor
const char* getClassName() const;
void onKeyPress (FKeyEvent*);
void setText (FString);
};
#pragma pack(pop)
// FSwitch inline functions
//----------------------------------------------------------------------
inline const char* FSwitch::getClassName() const
{ return "FSwitch"; }
#endif // _FSWITCH_H

View File

@ -55,13 +55,15 @@ FToggleButton::~FToggleButton() // destructor
//----------------------------------------------------------------------
void FToggleButton::init()
{
setGeometry (1, 1, 4, 1, false); // initialize geometry values
flags = 0;
checked = false;
focus_inside_group = true;
label_offset_pos = 0;
button_group = 0;
button_width = 0;
this->text = "";
setGeometry (1, 1, 4, 1, false); // initialize geometry values
setVisibleCursor();
if ( hasFocus() )
@ -202,7 +204,7 @@ void FToggleButton::drawLabel()
if ( hotkeypos != -1 )
length--;
gotoxy (xpos+xmin+3, ypos+ymin-1);
gotoxy (xpos+xmin-1+label_offset_pos, ypos+ymin-1);
if ( isEnabled() )
setColor(wc.label_fg, wc.label_bg);
@ -332,7 +334,7 @@ void FToggleButton::hide()
//----------------------------------------------------------------------
void FToggleButton::setGeometry (int x, int y, int w, int h, bool adjust)
{
int min_width = 4 + int(text.getLength());
int min_width = button_width + int(text.getLength());
if ( w < min_width )
w = min_width;
FWidget::setGeometry(x, y, w, h, adjust);
@ -586,7 +588,7 @@ bool FToggleButton::setChecked(bool on)
void FToggleButton::setText (FString txt)
{
this->text = txt;
setWidth(4+int(text.getLength()));
setWidth(button_width + int(text.getLength()));
if ( isEnabled() )
{
delAccelerator (this);

View File

@ -19,11 +19,13 @@ class FButtonGroup;
class FToggleButton : public FWidget
{
private:
bool focus_inside_group;
bool focus_inside_group;
protected:
FString text;
bool checked;
int label_offset_pos;
int button_width; // plus margin spaces
FButtonGroup* button_group;
private:
@ -76,7 +78,7 @@ class FToggleButton : public FWidget
bool unsetChecked();
bool isChecked();
void setText (const FString);
virtual void setText (const FString);
FString& getText();
};
#pragma pack(pop)