1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
/*
* Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
*
* 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; version 2 of the
* License.
*
* 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., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#include "wb_editor_image.h"
#include "base/string_utilities.h"
using namespace bec;
ImageEditorBE::ImageEditorBE(bec::GRTManager *grtm, const workbench_model_ImageFigureRef &image)
: bec::BaseEditor(grtm, image), _image(image)
{
}
bool ImageEditorBE::should_close_on_delete_of(const std::string &oid)
{
if (_image.id() == oid || _image->owner().id() == oid)
return true;
return false;
}
void ImageEditorBE::set_filename(const std::string &text)
{
if (text != *_image->filename())
{
AutoUndoEdit undo(this);
_image->setImageFile(text);
undo.end(_("Change Image"));
}
}
void ImageEditorBE::get_size(int &w, int &h)
{
w= (int) _image->width();
h= (int) _image->height();
}
void ImageEditorBE::set_size(int w, int h)
{
if (w > 0 && h > 0 && (w != *_image->width() || h != *_image->height()))
{
AutoUndoEdit undo(this);
_image->width(w);
_image->height(h);
undo.end(_("Resize Image"));
}
}
void ImageEditorBE::set_width(int w)
{
AutoUndoEdit undo(this);
if (*_image->keepAspectRatio() && _image->width() > 0)
{
double aspect_ratio= _image->height() / _image->width();
if (_image->height() != aspect_ratio * w)
_image->height(aspect_ratio * w);
}
if (*_image->width() != w)
_image->width(w);
undo.end(_("Set Image Size"));
}
void ImageEditorBE::set_height(int h)
{
AutoUndoEdit undo(this);
if (*_image->keepAspectRatio() && _image->height() > 0)
{
double aspect_ratio= _image->width() / _image->height();
if (_image->width() != aspect_ratio * h)
_image->width(aspect_ratio * h);
}
if (*_image->height() != h)
_image->height(h);
undo.end(_("Set Image Size"));
}
bool ImageEditorBE::get_keep_aspect_ratio()
{
return _image->keepAspectRatio() == 1;
}
void ImageEditorBE::set_keep_aspect_ratio(bool flag)
{
AutoUndoEdit undo(this);
_image->keepAspectRatio(flag);
undo.end(_("Toggle Image Aspect Ratio"));
}
std::string ImageEditorBE::get_filename() const
{
return _image->filename();
}
std::string ImageEditorBE::get_attached_image_path()
{
grt::Module *module= get_grt()->get_module("Workbench");
if (!module)
throw std::runtime_error("Workbench module not found");
grt::BaseListRef args(get_grt());
args.ginsert(_image->filename());
std::string value = grt::StringRef::cast_from(module->call_function("getAttachedFileTmpPath", args));
return value;
}
std::string ImageEditorBE::get_title()
{
return base::strfmt("Image");
}
|