1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-29 09:30:39 +02:00

Added MenuSettingStringBase, an abstract base class for MenuSettingString, MenuSettingFile and MenuSettingDir.

This removes a lot of duplicate source code and also decreases the binary size slightly.
This commit is contained in:
Maarten ter Huurne 2010-07-28 01:46:32 +02:00
parent 9d05af2881
commit d1d55a7666
11 changed files with 168 additions and 183 deletions

View File

@ -6,6 +6,7 @@ gmenu2x_SOURCES = asfont.cpp button.cpp cpu.cpp dirdialog.cpp filedialog.cpp \
menu.cpp menusettingbool.cpp menusetting.cpp menusettingdir.cpp \
menusettingfile.cpp menusettingimage.cpp menusettingint.cpp \
menusettingmultistring.cpp menusettingrgba.cpp menusettingstring.cpp \
menusettingstringbase.cpp \
messagebox.cpp selector.cpp \
settingsdialog.cpp sfontplus.cpp surfacecollection.cpp surface.cpp \
textdialog.cpp textmanualdialog.cpp touchscreen.cpp translator.cpp \
@ -18,6 +19,7 @@ noinst_HEADERS = asfont.h button.h cpu.h dirdialog.h FastDelegate.h \
menu.h menusettingbool.h menusettingdir.h \
menusettingfile.h menusetting.h menusettingimage.h menusettingint.h \
menusettingmultistring.h menusettingrgba.h menusettingstring.h \
menusettingstringbase.h \
messagebox.h selector.h settingsdialog.h \
sfontplus.h surfacecollection.h surface.h textdialog.h textmanualdialog.h \
touchscreen.h translator.h utilities.h wallpaperdialog.h \

View File

@ -19,62 +19,28 @@
***************************************************************************/
#include "menusettingdir.h"
#include "dirdialog.h"
#include "utilities.h"
using namespace std;
using namespace fastdelegate;
MenuSettingDir::MenuSettingDir(GMenu2X *gmenu2x, const string &name, const string &description, string *value)
: MenuSetting(gmenu2x,name,description) {
MenuSettingDir::MenuSettingDir(
GMenu2X *gmenu2x, const string &name,
const string &description, string *value)
: MenuSettingStringBase(gmenu2x, name, description, value)
{
IconButton *btn;
_value = value;
originalValue = *value;
btn = new IconButton(gmenu2x, "skin:imgs/buttons/x.png", gmenu2x->tr["Clear"]);
btn->setAction(MakeDelegate(this, &MenuSettingDir::clear));
buttonBox.add(btn);
btn = new IconButton(gmenu2x, "skin:imgs/buttons/b.png", gmenu2x->tr["Select a directory"]);
btn->setAction(MakeDelegate(this, &MenuSettingDir::select));
btn->setAction(MakeDelegate(this, &MenuSettingDir::edit));
buttonBox.add(btn);
}
void MenuSettingDir::draw(int y)
{
MenuSetting::draw(y);
gmenu2x->s->write( gmenu2x->font, value(), 155, y+gmenu2x->font->getHalfHeight(), SFontHAlignLeft, SFontVAlignMiddle );
}
void MenuSettingDir::manageInput()
{
if (gmenu2x->input[ACTION_X]) setValue("");
if (gmenu2x->input[ACTION_B]) select();
}
void MenuSettingDir::clear()
{
setValue("");
}
void MenuSettingDir::select()
void MenuSettingDir::edit()
{
DirDialog dd(gmenu2x, description, value());
if (dd.exec()) setValue( dd.getPath() );
}
void MenuSettingDir::setValue(const string &value)
{
*_value = value;
}
const string &MenuSettingDir::value()
{
return *_value;
}
void MenuSettingDir::adjustInput() {}
bool MenuSettingDir::edited() {
return originalValue != value();
}

View File

@ -20,29 +20,19 @@
#ifndef MENUSETTINGDIR_H
#define MENUSETTINGDIR_H
#include "gmenu2x.h"
#include "menusetting.h"
#include "menusettingstringbase.h"
using std::string;
class MenuSettingDir : public MenuSetting {
private:
string originalValue;
string *_value;
class MenuSettingDir : public MenuSettingStringBase {
protected:
virtual void edit();
void select();
void clear();
public:
MenuSettingDir(GMenu2X *gmenu2x, const string &name, const string &description, string *value);
virtual ~MenuSettingDir() {};
virtual void draw(int y);
virtual void manageInput();
virtual void adjustInput();
virtual bool edited();
void setValue(const string &value);
const string &value();
MenuSettingDir(
GMenu2X *gmenu2x, const string &name,
const string &description, string *value);
virtual ~MenuSettingDir() {}
};
#endif

View File

@ -19,15 +19,14 @@
***************************************************************************/
#include "menusettingfile.h"
#include "filedialog.h"
#include "utilities.h"
using namespace std;
using namespace fastdelegate;
MenuSettingFile::MenuSettingFile(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const string &filter_)
: MenuSetting(gmenu2x, name, description)
, originalValue(*value)
, _value(value)
MenuSettingFile::MenuSettingFile(
GMenu2X *gmenu2x, const string &name,
const string &description, string *value, const string &filter_)
: MenuSettingStringBase(gmenu2x, name, description, value)
, filter(filter_)
{
IconButton *btn;
@ -37,47 +36,14 @@ MenuSettingFile::MenuSettingFile(GMenu2X *gmenu2x, const string &name, const str
buttonBox.add(btn);
btn = new IconButton(gmenu2x, "skin:imgs/buttons/b.png", gmenu2x->tr["Select a file"]);
btn->setAction(MakeDelegate(this, &MenuSettingFile::select));
btn->setAction(MakeDelegate(this, &MenuSettingFile::edit));
buttonBox.add(btn);
}
void MenuSettingFile::draw(int y)
{
MenuSetting::draw(y);
gmenu2x->s->write( gmenu2x->font, value(), 155, y+gmenu2x->font->getHalfHeight(), SFontHAlignLeft, SFontVAlignMiddle );
}
void MenuSettingFile::manageInput()
{
if (gmenu2x->input[ACTION_X]) clear();
if (gmenu2x->input[ACTION_B]) select();
}
void MenuSettingFile::clear()
{
setValue("");
}
void MenuSettingFile::select()
void MenuSettingFile::edit()
{
FileDialog fd(gmenu2x, description, filter, value());
if (fd.exec()) {
setValue(fd.getPath() + "/" + fd.getFile());
}
}
void MenuSettingFile::setValue(const string &value)
{
*_value = value;
}
const string &MenuSettingFile::value()
{
return *_value;
}
void MenuSettingFile::adjustInput() {}
bool MenuSettingFile::edited() {
return originalValue != value();
}

View File

@ -20,33 +20,22 @@
#ifndef MENUSETTINGFILE_H
#define MENUSETTINGFILE_H
#include "gmenu2x.h"
#include "menusetting.h"
#include "menusettingstringbase.h"
using std::string;
class MenuSettingFile : public MenuSetting {
class MenuSettingFile : public MenuSettingStringBase {
protected:
string originalValue;
string *_value;
virtual void edit();
string filter;
virtual void select();
void clear();
public:
MenuSettingFile(GMenu2X *gmenu2x, const string &name,
const string &description, string *value,
const string &filter = "");
MenuSettingFile(
GMenu2X *gmenu2x, const string &name,
const string &description, string *value,
const string &filter = "");
virtual ~MenuSettingFile() {}
virtual void draw(int y);
virtual void manageInput();
virtual void adjustInput();
virtual bool edited();
virtual void setValue(const string &value);
const string &value();
};
#endif

View File

@ -28,7 +28,7 @@ MenuSettingImage::MenuSettingImage(GMenu2X *gmenu2x, const string &name, const s
{
}
void MenuSettingImage::select() {
void MenuSettingImage::edit() {
ImageDialog id(gmenu2x, description, filter, value());
if (id.exec()) setValue(id.getPath() + "/" + id.getFile());
}

View File

@ -26,7 +26,7 @@ using std::string;
class MenuSettingImage : public MenuSettingFile {
protected:
virtual void select();
virtual void edit();
public:
MenuSettingImage(GMenu2X *gmenu2x, const string &name,

View File

@ -19,21 +19,20 @@
***************************************************************************/
#include "menusettingstring.h"
#include "inputdialog.h"
#include "utilities.h"
using namespace std;
using namespace fastdelegate;
MenuSettingString::MenuSettingString(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const string &diagTitle, const string &diagIcon)
: MenuSetting(gmenu2x, name, description)
MenuSettingString::MenuSettingString(
GMenu2X *gmenu2x, const string &name,
const string &description, string *value,
const string &diagTitle_, const string &diagIcon_)
: MenuSettingStringBase(gmenu2x, name, description, value)
, diagTitle(diagTitle_)
, diagIcon(diagIcon_)
{
IconButton *btn;
_value = value;
originalValue = *value;
this->diagTitle = diagTitle;
this->diagIcon = diagIcon;
btn = new IconButton(gmenu2x, "skin:imgs/buttons/x.png", gmenu2x->tr["Clear"]);
btn->setAction(MakeDelegate(this, &MenuSettingString::clear));
buttonBox.add(btn);
@ -43,44 +42,10 @@ MenuSettingString::MenuSettingString(GMenu2X *gmenu2x, const string &name, const
buttonBox.add(btn);
}
void MenuSettingString::draw(int y)
{
MenuSetting::draw(y);
gmenu2x->s->write(gmenu2x->font, value(), 155, y+gmenu2x->font->getHalfHeight(), SFontHAlignLeft, SFontVAlignMiddle);
}
void MenuSettingString::manageInput()
{
if (gmenu2x->input[ACTION_X])
clear();
if (gmenu2x->input[ACTION_B])
edit();
}
void MenuSettingString::setValue(const string &value)
{
*_value = value;
}
const string &MenuSettingString::value()
{
return *_value;
}
void MenuSettingString::adjustInput() {}
void MenuSettingString::clear()
{
setValue("");
}
void MenuSettingString::edit()
{
InputDialog id(gmenu2x, gmenu2x->input, gmenu2x->ts,
description, value(), diagTitle, diagIcon);
InputDialog id(
gmenu2x, gmenu2x->input, gmenu2x->ts,
description, value(), diagTitle, diagIcon);
if (id.exec()) setValue(id.getInput());
}
bool MenuSettingString::edited() {
return originalValue != value();
}

View File

@ -20,30 +20,22 @@
#ifndef MENUSETTINGSTRING_H
#define MENUSETTINGSTRING_H
#include "gmenu2x.h"
#include "menusetting.h"
#include "menusettingstringbase.h"
using std::string;
class MenuSettingString : public MenuSetting {
private:
string originalValue, diagTitle, diagIcon;
string *_value;
class MenuSettingString : public MenuSettingStringBase {
protected:
virtual void edit();
void edit();
void clear();
string diagTitle, diagIcon;
public:
MenuSettingString(GMenu2X *gmenu2x, const string &name, const string &description, string *value, const string &diagTitle="", const string &diagIcon="");
virtual ~MenuSettingString() {};
virtual void draw(int y);
virtual void manageInput();
virtual void adjustInput();
virtual bool edited();
void setValue(const string &value);
const string &value();
MenuSettingString(GMenu2X *gmenu2x, const string &name,
const string &description, string *value,
const string &diagTitle = "",
const string &diagIcon = "");
virtual ~MenuSettingString() {}
};
#endif

View File

@ -0,0 +1,65 @@
/***************************************************************************
* Copyright (C) 2006 by Massimiliano Torromeo *
* massimiliano.torromeo@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "menusettingstringbase.h"
using namespace std;
using namespace fastdelegate;
MenuSettingStringBase::MenuSettingStringBase(
GMenu2X *gmenu2x, const string &name,
const string &description, string *value)
: MenuSetting(gmenu2x, name, description)
, originalValue(*value)
, _value(value)
{
}
MenuSettingStringBase::~MenuSettingStringBase()
{
}
void MenuSettingStringBase::draw(int y)
{
MenuSetting::draw(y);
gmenu2x->s->write(
gmenu2x->font, value(),
155, y + gmenu2x->font->getHalfHeight(),
SFontHAlignLeft, SFontVAlignMiddle);
}
void MenuSettingStringBase::manageInput()
{
if (gmenu2x->input[ACTION_X]) clear();
if (gmenu2x->input[ACTION_B]) edit();
}
void MenuSettingStringBase::adjustInput()
{
}
void MenuSettingStringBase::clear()
{
setValue("");
}
bool MenuSettingStringBase::edited()
{
return originalValue != value();
}

View File

@ -0,0 +1,50 @@
/***************************************************************************
* Copyright (C) 2006 by Massimiliano Torromeo *
* massimiliano.torromeo@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef MENUSETTINGSTRINGBASE_H
#define MENUSETTINGSTRINGBASE_H
#include "menusetting.h"
using std::string;
class MenuSettingStringBase : public MenuSetting {
protected:
string originalValue;
string *_value;
virtual void edit() = 0;
void clear();
public:
MenuSettingStringBase(
GMenu2X *gmenu2x, const string &name,
const string &description, string *value);
virtual ~MenuSettingStringBase();
virtual void draw(int y);
virtual void manageInput();
virtual void adjustInput();
virtual bool edited();
void setValue(const string &value) { *_value = value; }
const string &value() { return *_value; }
};
#endif