* improve graphics group UI.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_6_X@28199 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2009-01-17 08:06:04 +00:00
parent 9158749b08
commit ca9723c2da
5 changed files with 404 additions and 214 deletions

View File

@ -15,6 +15,7 @@
#include <config.h>
#include "GuiGraphics.h"
#include "frontends/alert.h"
#include "qt_helpers.h"
#include "Validator.h"
@ -163,9 +164,9 @@ GuiGraphics::GuiGraphics(GuiView & lv)
//graphics pane
connect(filename, SIGNAL(textChanged(const QString &)),
this, SLOT(change_adaptor()));
connect(WidthCB, SIGNAL( clicked()),
connect(WidthCB, SIGNAL(clicked()),
this, SLOT(change_adaptor()));
connect(HeightCB, SIGNAL( clicked()),
connect(HeightCB, SIGNAL(clicked()),
this, SLOT(change_adaptor()));
connect(Width, SIGNAL(textChanged(const QString &)),
this, SLOT(change_adaptor()));
@ -243,8 +244,9 @@ GuiGraphics::GuiGraphics(GuiView & lv)
connect(displayGB, SIGNAL(toggled(bool)), this, SLOT(change_adaptor()));
connect(displayscale, SIGNAL(textChanged(const QString&)),
this, SLOT(change_adaptor()));
connect(groupId, SIGNAL(textChanged(const QString&)),
this, SLOT(change_adaptor()));
connect(groupCO, SIGNAL(currentIndexChanged(int)),
this, SLOT(change_group(int)));
displayscale->setValidator(new QIntValidator(displayscale));
bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
@ -289,6 +291,96 @@ void GuiGraphics::change_adaptor()
}
void GuiGraphics::change_group(int index)
{
QString const new_group = groupCO->itemData(
groupCO->currentIndex()).toString();
// check if the old group consisted only of this member
if (current_group_ != fromqstr(new_group)
&& graphics::countGroupMembers(buffer(), current_group_) == 1) {
if (!new_group.isEmpty()) {
if (Alert::prompt(_("Dissolve previous group?"),
bformat(_("If you assign this graphic to group '%2$s',\n"
"the previously assigned group '%1$s' will be dissolved,\n"
"because this graphic was its only member.\n"
"How do you want to proceed?"),
from_utf8(current_group_), qstring_to_ucs4(new_group)),
0, 0,
bformat(_("Stick with group '%1$s'"),
from_utf8(current_group_)),
bformat(_("Assign to group '%1$s' anyway"),
qstring_to_ucs4(new_group))) == 0) {
groupCO->setCurrentIndex(
groupCO->findData(toqstr(current_group_), Qt::MatchExactly));
return;
}
} else {
if (Alert::prompt(_("Dissolve previous group?"),
bformat(_("If you sign off this graphic from group '%1$s',\n"
"the group will be dissolved,\n"
"because this graphic was its only member.\n"
"How do you want to proceed?"),
from_utf8(current_group_)),
0, 0,
bformat(_("Stick with group '%1$s'"),
from_utf8(current_group_)),
bformat(_("Sign off from group '%1$s'"),
from_utf8(current_group_))) == 0) {
groupCO->setCurrentIndex(
groupCO->findData(toqstr(current_group_), Qt::MatchExactly));
return;
}
}
}
if (new_group.isEmpty()) {
changed();
return;
}
string grp = graphics::getGroupParams(buffer(), fromqstr(new_group));
if (grp.empty()) {
// group does not exist yet
changed();
return;
}
// filename might have been changed
QString current_filename = filename->text();
// group exists: load params into the dialog
groupCO->blockSignals(true);
InsetGraphics::string2params(grp, buffer(), params_);
paramsToDialog(params_);
groupCO->blockSignals(false);
// reset filename
filename->setText(current_filename);
changed();
}
void GuiGraphics::on_newGroupPB_clicked()
{
docstring newgroup;
if (!Alert::askForText(newgroup, _("Enter unique group name:")))
return;
if (newgroup.empty())
return;
if (groupCO->findData(toqstr(newgroup), Qt::MatchExactly) != -1) {
Alert::warning(_("Group already defined!"),
bformat(_("A graphics group with the name '%1$s' already exists."),
newgroup));
return;
}
groupCO->addItem(toqstr(newgroup), toqstr(newgroup));
groupCO->setCurrentIndex(
groupCO->findData(toqstr(newgroup), Qt::MatchExactly));
}
void GuiGraphics::change_bb()
{
bbChanged = true;
@ -530,7 +622,21 @@ void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
Scale->setEnabled(scaleChecked);
displayGB->setEnabled(lyxrc.display_graphics);
groupId->setText(toqstr(igp.groupId));
set<string> grp;
graphics::getGraphicsGroups(buffer(), grp);
set<string>::const_iterator it = grp.begin();
set<string>::const_iterator end = grp.end();
groupCO->blockSignals(true);
groupCO->clear();
for (; it != end; it++)
groupCO->addItem(toqstr(*it), toqstr(*it));
groupCO->insertItem(0, qt_("None"), QString());
if (igp.groupId.empty())
groupCO->setCurrentIndex(0);
else
groupCO->setCurrentIndex(
groupCO->findData(toqstr(igp.groupId), Qt::MatchExactly));
groupCO->blockSignals(false);
lengthAutoToWidgets(Width, widthUnit, igp.width,
unitDefault);
@ -666,7 +772,9 @@ void GuiGraphics::applyView()
// more latex options
igp.special = fromqstr(latexoptions->text());
igp.groupId = fromqstr(groupId->text());
igp.groupId = fromqstr(groupCO->itemData(
groupCO->currentIndex()).toString());
current_group_ = igp.groupId;
}
@ -702,6 +810,7 @@ bool GuiGraphics::initialiseParams(string const & data)
{
InsetGraphics::string2params(data, buffer(), params_);
paramsToDialog(params_);
current_group_ = params_.groupId;
return true;
}

View File

@ -40,7 +40,9 @@ public:
private Q_SLOTS:
void change_adaptor();
void change_group(int);
void change_bb();
void on_newGroupPB_clicked();
void on_browsePB_clicked();
void on_getPB_clicked();
void on_scaleCB_toggled(bool);
@ -79,6 +81,8 @@ private:
std::vector<std::string> origin_ltx;
///
InsetGraphicsParams params_;
/// the current graphics group
std::string current_group_;
};
} // namespace frontend

View File

@ -5,12 +5,14 @@
<rect>
<x>0</x>
<y>0</y>
<width>480</width>
<height>348</height>
<width>482</width>
<height>383</height>
</rect>
</property>
<property name="sizePolicy" >
<sizepolicy vsizetype="Minimum" hsizetype="Minimum" >
<sizepolicy>
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -28,93 +30,6 @@
<property name="spacing" >
<number>6</number>
</property>
<item row="1" column="0" >
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>6</number>
</property>
<property name="margin" >
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="restorePB" >
<property name="text" >
<string>&amp;Restore</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
<property name="default" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="okPB" >
<property name="text" >
<string>&amp;OK</string>
</property>
<property name="autoDefault" >
<bool>true</bool>
</property>
<property name="default" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="applyPB" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Minimum" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text" >
<string>&amp;Apply</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
<property name="default" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closePB" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Minimum" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text" >
<string>Close</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0" >
<widget class="QTabWidget" name="tabWidget" >
<property name="toolTip" >
@ -124,14 +39,6 @@
<number>0</number>
</property>
<widget class="QWidget" name="Graphics" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>458</width>
<height>272</height>
</rect>
</property>
<attribute name="title" >
<string>&amp;Graphics</string>
</attribute>
@ -179,7 +86,9 @@
<bool>true</bool>
</property>
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Minimum" >
<sizepolicy>
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -194,7 +103,7 @@
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<property name="sizeHint" >
<size>
<width>61</width>
<height>20</height>
@ -211,7 +120,9 @@
<bool>true</bool>
</property>
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Minimum" >
<sizepolicy>
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -318,7 +229,9 @@
<item row="0" column="1" >
<widget class="QLineEdit" name="angle" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="MinimumExpanding" >
<sizepolicy>
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -367,14 +280,6 @@
</layout>
</widget>
<widget class="QWidget" name="Clipping" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>458</width>
<height>272</height>
</rect>
</property>
<attribute name="title" >
<string>&amp;Clipping</string>
</attribute>
@ -390,7 +295,7 @@
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0" >
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
@ -414,7 +319,9 @@
<bool>true</bool>
</property>
<property name="sizePolicy" >
<sizepolicy vsizetype="Minimum" hsizetype="Preferred" >
<sizepolicy>
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -516,7 +423,7 @@
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<property name="sizeHint" >
<size>
<width>181</width>
<height>20</height>
@ -537,18 +444,54 @@
</layout>
</widget>
<widget class="QWidget" name="ExtraOptions" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>458</width>
<height>272</height>
</rect>
</property>
<attribute name="title" >
<string>LaTe&amp;X and LyX options</string>
</attribute>
<layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="2" column="0" colspan="3" >
<widget class="QCheckBox" name="unzipCB" >
<property name="toolTip" >
<string>Don't uncompress image before exporting to LaTeX</string>
</property>
<property name="text" >
<string>Don't un&amp;zip on export</string>
</property>
</widget>
</item>
<item row="0" column="2" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>161</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1" >
<widget class="QLineEdit" name="latexoptions" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<string>Additional LaTeX options</string>
</property>
</widget>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="latexoptionsLA" >
<property name="toolTip" >
@ -562,40 +505,20 @@
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QLineEdit" name="latexoptions" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="MinimumExpanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<item row="5" column="0" colspan="3" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="toolTip" >
<string>Additional LaTeX options</string>
<property name="sizeHint" >
<size>
<width>354</width>
<height>81</height>
</size>
</property>
</widget>
</spacer>
</item>
<item row="1" column="0" colspan="2" >
<widget class="QCheckBox" name="draftCB" >
<property name="toolTip" >
<string>Draft mode</string>
</property>
<property name="text" >
<string>&amp;Draft mode</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2" >
<widget class="QCheckBox" name="unzipCB" >
<property name="toolTip" >
<string>Don't uncompress image before exporting to LaTeX</string>
</property>
<property name="text" >
<string>Don't un&amp;zip on export</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2" >
<item row="3" column="0" colspan="3" >
<widget class="QGroupBox" name="displayGB" >
<property name="focusPolicy" >
<enum>Qt::StrongFocus</enum>
@ -619,58 +542,15 @@
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="4" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="label" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<string>Graphics having the same group name will share the same parameters</string>
</property>
<property name="text" >
<string>Grou&amp;p Name:</string>
</property>
<property name="buddy" >
<cstring>groupId</cstring>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QLineEdit" name="groupId" >
<property name="minimumSize" >
<size>
<width>87</width>
<height>0</height>
</size>
</property>
<property name="toolTip" >
<string>Group Name to be set up from the current parameters. Use context menu to assign the existing one.</string>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QLineEdit" name="displayscale" >
<property name="enabled" >
<bool>true</bool>
</property>
<property name="sizePolicy" >
<sizepolicy vsizetype="Fixed" hsizetype="Minimum" >
<sizepolicy>
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -693,26 +573,202 @@
</property>
</widget>
</item>
<item row="0" column="2" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="4" column="1" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
<item row="4" column="0" colspan="3" >
<widget class="QGroupBox" name="graphicsGroupGB" >
<property name="toolTip" >
<string>Assign the graphic to a group of graphics that share the same settings</string>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>354</width>
<height>81</height>
</size>
<property name="title" >
<string>Graphics Group</string>
</property>
</spacer>
<property name="flat" >
<bool>true</bool>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item rowspan="2" row="0" column="2" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>121</width>
<height>51</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="label" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<string/>
</property>
<property name="text" >
<string>A&amp;ssigned to group:</string>
</property>
<property name="buddy" >
<cstring>groupCO</cstring>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QPushButton" name="newGroupPB" >
<property name="toolTip" >
<string>Click to define a new graphics group.</string>
</property>
<property name="text" >
<string>O&amp;pen new group...</string>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QComboBox" name="groupCO" >
<property name="toolTip" >
<string>Select an existing group for the current graphics.</string>
</property>
<property name="editable" >
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0" colspan="3" >
<widget class="QCheckBox" name="draftCB" >
<property name="toolTip" >
<string>Draft mode</string>
</property>
<property name="text" >
<string>&amp;Draft mode</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item row="1" column="0" >
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QPushButton" name="restorePB" >
<property name="text" >
<string>&amp;Restore</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
<property name="default" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="okPB" >
<property name="text" >
<string>&amp;OK</string>
</property>
<property name="autoDefault" >
<bool>true</bool>
</property>
<property name="default" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="applyPB" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text" >
<string>&amp;Apply</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
<property name="default" >
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closePB" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text" >
<string>Close</string>
</property>
<property name="autoDefault" >
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>

View File

@ -972,6 +972,24 @@ void getGraphicsGroups(Buffer const & b, set<string> & ids)
}
int countGroupMembers(Buffer const & b, string const & groupId)
{
int n = 0;
if (groupId.empty())
return n;
Inset & inset = b.inset();
InsetIterator it = inset_iterator_begin(inset);
InsetIterator const end = inset_iterator_end(inset);
for (; it != end; ++it)
if (it->lyxCode() == GRAPHICS_CODE) {
InsetGraphics & ins = static_cast<InsetGraphics &>(*it);
if (ins.getParams().groupId == groupId)
++n;
}
return n;
}
string getGroupParams(Buffer const & b, string const & groupId)
{
if (groupId.empty())

View File

@ -124,6 +124,9 @@ namespace graphics {
/// Saves the list of currently used groups in the document.
void getGraphicsGroups(Buffer const &, std::set<std::string> &);
/// how many members has the current group?
int countGroupMembers(Buffer const &, std::string const &);
/// Returns parameters of a given graphics group (except filename).
std::string getGroupParams(Buffer const &, std::string const &);