unit-menu.cpp revision 495c5569abb738d417db95c79ce623fd9f60769f
/**
* \brief Unit Menu Widget - A drop down menu for choosing unit types.
*
* Author:
* Bryce Harrington <bryce@bryceharrington.org>
*
* Copyright (C) 2004 Bryce Harrington
*
* Released under GNU GPL. Read the file 'COPYING' for more information.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <cmath>
#include "unit-menu.h"
namespace Inkscape {
namespace UI {
namespace Widget {
/**
* Construct a UnitMenu
*
*/
{
set_active(0);
}
}
/** Adds the unit type to the widget. This extracts the corresponding
units from the unit map matching the given type, and appends them
to the dropdown widget. It causes the primary unit for the given
unit_type to be selected. */
bool
{
/* Expand the unit widget with unit entries from the unit table */
++iter;
}
return true;
}
/** Removes all unit entries, then adds the unit type to the widget.
This extracts the corresponding
units from the unit map matching the given type, and appends them
to the dropdown widget. It causes the primary unit for the given
unit_type to be selected. */
bool
{
clear_text();
return setUnitType(unit_type);
}
/** Adds a unit, possibly user-defined, to the menu. */
void
{
_unit_table.addUnit(u, false);
append_text(u.abbr);
}
/** Returns the Unit object corresponding to the current selection
in the dropdown widget */
if (get_active_text() == "") {
}
}
/** Sets the dropdown widget to the given unit abbreviation.
Returns true if the unit was selectable, false if not
(i.e., if the unit was not present in the widget) */
bool
// TODO: Determine if 'unit' is available in the dropdown.
// If not, return false
return true;
}
/** Returns the abbreviated unit name of the selected unit */
UnitMenu::getUnitAbbr() const {
if (get_active_text() == "") {
return "";
}
}
/** Returns the UnitType of the selected unit */
UnitMenu::getUnitType() const {
}
/** Returns the unit factor for the selected unit */
double
UnitMenu::getUnitFactor() const
{
}
/** Returns the recommended number of digits for displaying
* numbers of this unit type.
*/
int
UnitMenu::getDefaultDigits() const
{
return getUnit().defaultDigits();
}
/** Returns the recommended step size in spin buttons
* displaying units of this type
*/
double
UnitMenu::getDefaultStep() const
{
}
* in spin buttons displaying units of this type
*/
double
UnitMenu::getDefaultPage() const
{
return 10 * getDefaultStep();
}
/**
* Returns the conversion factor required to convert values
* of the currently selected unit into units of type
* new_unit_abbr.
*/
double
UnitMenu::getConversion(Glib::ustring const &new_unit_abbr, Glib::ustring const &old_unit_abbr) const
{
if (old_unit_abbr != "no_unit")
// Catch the case of zero or negative unit factors (error!)
if (old_factor < 0.0000001 ||
// TODO: Should we assert here?
return 0.00;
}
}
/** Returns true if the selected unit is not dimensionless
* (false for %, true for px, pt, cm, etc)
*/
bool
UnitMenu::isAbsolute() const {
return getUnitType() != UNIT_TYPE_DIMENSIONLESS;
}
/** Returns true if the selected unit is radial (deg or rad)
*/
bool
return getUnitType() == UNIT_TYPE_RADIAL;
}
} // namespace Widget
} // namespace UI
} // namespace Inkscape
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :