scalar-unit.cpp revision 136163cf52e17c002bdf20591c539a858ef911ed
/**
* \brief Scalar Unit Widget - A labelled text box, with spin buttons and
* optional icon or suffix, for entering the values of various unit
* types.
*
* A ScalarUnit is a control for entering, viewing, or manipulating
* numbers with units. This differs from ordinary numbers like 2 or
* 3.14 because the number portion of a scalar *only* has meaning
* when considered with its unit type. For instance, 12 m and 12 in
* have very different actual values, but 1 m and 100 cm have the same
* value. The ScalarUnit allows us to abstract the presentation of
* the scalar to the user from the internal representations used by
* the program.
*
* Authors:
* Bryce Harrington <bryce@bryceharrington.org>
* Derek P. Moore <derekm@hackunix.org>
* buliabyak@gmail.com
*
* Copyright (C) 2004-2005 Authors
*
* Released under GNU GPL. Read the file 'COPYING' for more information.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "scalar-unit.h"
#include "spinbutton.h"
namespace Inkscape {
namespace UI {
namespace Widget {
/**
* Construct a ScalarUnit
*
* \param label Label.
* \param unit_type Unit type (defaults to UNIT_TYPE_LINEAR).
* \param suffix Suffix, placed after the widget (defaults to "").
* \param icon Icon filename, placed before the label (defaults to "").
* \param unit_menu UnitMenu drop down; if not specified, one will be created
* and displayed after the widget (defaults to NULL).
* \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label
* indicates the next character should be used for the
* mnemonic accelerator key (defaults to true).
*/
bool mnemonic)
_hundred_percent(0),
_absolute_is_increment(false),
_percentage_is_increment(false)
{
if (_unit_menu == NULL) {
_unit_menu = new UnitMenu();
}
}
/**
* Initializes the scalar based on the settings in _unit_menu.
* Requires that _unit_menu has already been initialized.
*/
void
{
_unit_menu->getDefaultPage());
}
/** Sets the unit for the ScalarUnit widget */
bool
// First set the unit
return false;
}
return true;
}
/** Gets the object for the currently selected unit */
ScalarUnit::getUnit() const {
return _unit_menu->getUnit();
}
/** Gets the UnitType ID for the unit */
ScalarUnit::getUnitType() const {
return _unit_menu->getUnitType();
}
/** Sets the number and unit system */
void
}
/** Convert and sets the number only and keeps the current unit. */
void
if (units == "") {
// set the value in the default units
} else {
}
}
/** Sets the number only */
void
}
/** Returns the value in the given unit system */
double
if (unit_name == "") {
// Return the value in the default units
} else {
}
}
/** Grab focus, and select the text that is in the entry field.
*/
void
_widget->grab_focus();
}
void
{
}
void
{
}
void
{
}
/** Convert value from % to absolute, using _hundred_percent and *_is_increment flags */
double
{
// convert from percent to absolute
double convertedVal = 0;
double hundred_converted = _hundred_percent / _unit_menu->getConversion("px"); // _hundred_percent is in px
value += 100;
return convertedVal;
}
/** Convert value from absolute to %, using _hundred_percent and *_is_increment flags */
double
{
double convertedVal = 0;
// convert from absolute to percent
if (_hundred_percent == 0) {
convertedVal = 0;
else
convertedVal = 100;
} else {
double hundred_converted = _hundred_percent / _unit_menu->getConversion("px", lastUnits); // _hundred_percent is in px
convertedVal -= 100;
}
return convertedVal;
}
/** Assuming the current unit is absolute, get the corresponding % value */
double
{
return convertedVal;
}
/** Assuming the current unit is absolute, set the value corresponding to a given % */
void
{
}
/** Signal handler for updating the value and suffix label when unit is changed */
void
{
double convertedVal = 0;
} else {
}
}
} // namespace Widget
} // namespace UI
} // namespace Inkscape
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :