- string const filename(fromqstr(dialog_->filename->text()));
- if (!filename.empty()) {
- string const bb(controller().readBB(filename));
- if (!bb.empty()) {
- dialog_->lbX->setText(toqstr(token(bb, ' ', 0)));
- dialog_->lbY->setText(toqstr(token(bb, ' ', 1)));
- dialog_->rtX->setText(toqstr(token(bb, ' ', 2)));
- dialog_->rtY->setText(toqstr(token(bb, ' ', 3)));
- // the default units for the bb values when reading
- // it from the file
- dialog_->lbXunit->setCurrentIndex(0);
- dialog_->lbYunit->setCurrentIndex(0);
- dialog_->rtXunit->setCurrentIndex(0);
- dialog_->rtYunit->setCurrentIndex(0);
+ string const fn = fromqstr(filename->text());
+ if (fn.empty())
+ return;
+ string const bb = readBoundingBox(fn);
+ bbChanged = false;
+ if (bb.empty())
+ return;
+ doubleToWidget(lbX, token(bb, ' ', 0));
+ doubleToWidget(lbY, token(bb, ' ', 1));
+ doubleToWidget(rtX, token(bb, ' ', 2));
+ doubleToWidget(rtY, token(bb, ' ', 3));
+ // the default units for the bb values when reading
+ // it from the file
+ lbXunit->setCurrentIndex(0);
+ lbYunit->setCurrentIndex(0);
+ rtXunit->setCurrentIndex(0);
+ rtYunit->setCurrentIndex(0);
+}
+
+
+bool GuiGraphics::isValid()
+{
+ return !filename->text().isEmpty();
+}
+
+
+bool GuiGraphics::initialiseParams(string const & data)
+{
+ InsetGraphics::string2params(data, buffer(), params_);
+ paramsToDialog(params_);
+ current_group_ = params_.groupId;
+ return true;
+}
+
+
+void GuiGraphics::clearParams()
+{
+ params_ = InsetGraphicsParams();
+}
+
+
+void GuiGraphics::dispatchParams()
+{
+ InsetGraphicsParams tmp_params(params_);
+ string const lfun = InsetGraphics::params2string(tmp_params, buffer());
+ dispatch(FuncRequest(getLfun(), lfun));
+}
+
+
+QString GuiGraphics::browse(QString const & in_name) const
+{
+ QString const title = qt_("Select graphics file");
+
+ // Does user clipart directory exist?
+ string clipdir = addName(package().user_support().absFilename(), "clipart");
+ FileName clip(clipdir);
+
+ // bail out to system clipart directory
+ if (!clip.isDirectory())
+ clipdir = addName(package().system_support().absFilename(), "clipart");
+
+ return browseRelFile(in_name, bufferFilepath(),
+ title, fileFilters(QString()), false,
+ qt_("Clipart|#C#c"), toqstr(clipdir),
+ qt_("Documents|#o#O"), toqstr(lyxrc.document_path));
+}
+
+
+string GuiGraphics::readBoundingBox(string const & file)
+{
+ FileName const abs_file = support::makeAbsPath(file, fromqstr(bufferFilepath()));
+
+ // try to get it from the file, if possible. Zipped files are
+ // unzipped in the readBB_from_PSFile-Function
+ string const bb = readBB_from_PSFile(abs_file);
+ if (!bb.empty())
+ return bb;
+
+ // we don't, so ask the Graphics Cache if it has loaded the file
+ int width = 0;
+ int height = 0;
+
+ graphics::Cache & gc = graphics::Cache::get();
+ if (gc.inCache(abs_file)) {
+ graphics::Image const * image = gc.item(abs_file)->image();
+
+ if (image) {
+ width = image->width();
+ height = image->height();