mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
Fix up GuiBox (use proper data/view separation and clean up)
This commit is contained in:
parent
1e4700b277
commit
bec3f7bc8c
@ -77,60 +77,33 @@ static QStringList boxGuiSpecialLengthNames()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static QList<ColorPair> colorData()
|
static QList<ColorCode> colors()
|
||||||
{
|
{
|
||||||
QList<ColorPair> colors;
|
QList<ColorCode> colors;
|
||||||
colors << ColorPair(qt_("none"), Color_none);
|
colors << Color_none;
|
||||||
colors << ColorPair(qt_("black"), Color_black);
|
colors << Color_black;
|
||||||
colors << ColorPair(qt_("white"), Color_white);
|
colors << Color_white;
|
||||||
colors << ColorPair(qt_("blue"), Color_blue);
|
colors << Color_blue;
|
||||||
colors << ColorPair(qt_("brown"), Color_brown);
|
colors << Color_brown;
|
||||||
colors << ColorPair(qt_("cyan"), Color_cyan);
|
colors << Color_cyan;
|
||||||
colors << ColorPair(qt_("darkgray"), Color_darkgray);
|
colors << Color_darkgray;
|
||||||
colors << ColorPair(qt_("gray"), Color_gray);
|
colors << Color_gray;
|
||||||
colors << ColorPair(qt_("green"), Color_green);
|
colors << Color_green;
|
||||||
colors << ColorPair(qt_("lightgray"), Color_lightgray);
|
colors << Color_lightgray;
|
||||||
colors << ColorPair(qt_("lime"), Color_lime);
|
colors << Color_lime;
|
||||||
colors << ColorPair(qt_("magenta"), Color_magenta);
|
colors << Color_magenta;
|
||||||
colors << ColorPair(qt_("olive"), Color_olive);
|
colors << Color_olive;
|
||||||
colors << ColorPair(qt_("orange"), Color_orange);
|
colors << Color_orange;
|
||||||
colors << ColorPair(qt_("pink"), Color_pink);
|
colors << Color_pink;
|
||||||
colors << ColorPair(qt_("purple"), Color_purple);
|
colors << Color_purple;
|
||||||
colors << ColorPair(qt_("red"), Color_red);
|
colors << Color_red;
|
||||||
colors << ColorPair(qt_("teal"), Color_teal);
|
colors << Color_teal;
|
||||||
colors << ColorPair(qt_("violet"), Color_violet);
|
colors << Color_violet;
|
||||||
colors << ColorPair(qt_("yellow"), Color_yellow);
|
colors << Color_yellow;
|
||||||
return colors;
|
return colors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
void fillComboColor(QComboBox * combo, QList<T> const & list, bool const is_none)
|
|
||||||
{
|
|
||||||
QPixmap coloritem(32, 32);
|
|
||||||
QColor color;
|
|
||||||
// frameColorCO cannot be uncolored
|
|
||||||
if (is_none)
|
|
||||||
combo->addItem(qt_("none"));
|
|
||||||
typename QList<T>::const_iterator cit = list.begin() + 1;
|
|
||||||
for (; cit != list.end(); ++cit) {
|
|
||||||
color = QColor(guiApp->colorCache().get(cit->second, false));
|
|
||||||
coloritem.fill(color);
|
|
||||||
combo->addItem(QIcon(coloritem), cit->first);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
template<class P>
|
|
||||||
static int findPos2nd(QList<P> const & vec, QString val)
|
|
||||||
{
|
|
||||||
for (int i = 0; i != vec.size(); ++i)
|
|
||||||
if (vec[i].first == val)
|
|
||||||
return i;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
GuiBox::GuiBox(QWidget * parent) : InsetParamsWidget(parent)
|
GuiBox::GuiBox(QWidget * parent) : InsetParamsWidget(parent)
|
||||||
{
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
@ -182,16 +155,34 @@ GuiBox::GuiBox(QWidget * parent) : InsetParamsWidget(parent)
|
|||||||
addCheckedWidget(separationED, separationLA);
|
addCheckedWidget(separationED, separationLA);
|
||||||
addCheckedWidget(shadowsizeED, shadowsizeLA);
|
addCheckedWidget(shadowsizeED, shadowsizeLA);
|
||||||
|
|
||||||
// initialize colors
|
|
||||||
color = colorData();
|
|
||||||
// the background can be uncolored while the frame cannot
|
// the background can be uncolored while the frame cannot
|
||||||
fillComboColor(frameColorCO, color, false);
|
color_codes_ = colors();
|
||||||
fillComboColor(backgroundColorCO, color, true);
|
fillComboColor(frameColorCO, false);
|
||||||
|
fillComboColor(backgroundColorCO, true);
|
||||||
|
|
||||||
initDialog();
|
initDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GuiBox::fillComboColor(QComboBox * combo, bool const is_none)
|
||||||
|
{
|
||||||
|
QPixmap coloritem(32, 32);
|
||||||
|
QColor color;
|
||||||
|
// frameColorCO cannot be uncolored
|
||||||
|
if (is_none)
|
||||||
|
combo->addItem(toqstr(translateIfPossible(lcolor.getGUIName(Color_none))),
|
||||||
|
toqstr(lcolor.getLaTeXName(Color_none)));
|
||||||
|
typename QList<ColorCode>::const_iterator cit = color_codes_.begin() + 1;
|
||||||
|
for (; cit != color_codes_.end(); ++cit) {
|
||||||
|
QString const latexname = toqstr(lcolor.getLaTeXName(*cit));
|
||||||
|
QString const guiname = toqstr(translateIfPossible(lcolor.getGUIName(*cit)));
|
||||||
|
color = QColor(guiApp->colorCache().get(*cit, false));
|
||||||
|
coloritem.fill(color);
|
||||||
|
combo->addItem(QIcon(coloritem), guiname, latexname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void GuiBox::on_innerBoxCO_activated(int /* index */)
|
void GuiBox::on_innerBoxCO_activated(int /* index */)
|
||||||
{
|
{
|
||||||
QString itype =
|
QString itype =
|
||||||
@ -231,25 +222,29 @@ void GuiBox::on_typeCO_activated(int index)
|
|||||||
}
|
}
|
||||||
// assure that the frame color is black for frameless boxes to
|
// assure that the frame color is black for frameless boxes to
|
||||||
// provide the color "none"
|
// provide the color "none"
|
||||||
if (frameless && frameColorCO->currentIndex() != 0)
|
int const b = frameColorCO->findData("black");
|
||||||
frameColorCO->setCurrentIndex(0);
|
if (frameless && frameColorCO->currentIndex() != b)
|
||||||
|
frameColorCO->setCurrentIndex(b);
|
||||||
changed();
|
changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GuiBox::on_frameColorCO_currentIndexChanged(int /* index */)
|
void GuiBox::on_frameColorCO_currentIndexChanged(int index)
|
||||||
{
|
{
|
||||||
// if there is a non-black frame color the background canot be uncolored
|
// if there is a non-black frame color the background cannot be uncolored
|
||||||
// therefore remove the entry "none" in this case
|
// therefore remove the entry "none" in this case
|
||||||
if (frameColorCO->currentIndex() != 0) {
|
if (index != frameColorCO->findData("black")) {
|
||||||
if (backgroundColorCO->count() == color.count()) {
|
int const n = backgroundColorCO->findData("none");
|
||||||
if (backgroundColorCO->currentIndex() == 0)
|
if (n != -1) {
|
||||||
backgroundColorCO->setCurrentIndex(findPos2nd(color, qt_("white")));
|
if (backgroundColorCO->currentIndex() == n)
|
||||||
backgroundColorCO->removeItem(0);
|
backgroundColorCO->setCurrentIndex(
|
||||||
|
backgroundColorCO->findData("white"));
|
||||||
|
backgroundColorCO->removeItem(n);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (backgroundColorCO->count() == color.count() - 1)
|
if (backgroundColorCO->findData("none") == -1)
|
||||||
backgroundColorCO->insertItem(0, qt_("none"));
|
backgroundColorCO->insertItem(0, toqstr(translateIfPossible((lcolor.getGUIName(Color_none)))),
|
||||||
|
toqstr(lcolor.getLaTeXName(Color_none)));
|
||||||
}
|
}
|
||||||
changed();
|
changed();
|
||||||
}
|
}
|
||||||
@ -407,12 +402,9 @@ void GuiBox::paramsToDialog(Inset const * inset)
|
|||||||
lengthToWidgets(shadowsizeED, shadowsizeUnitsLC,
|
lengthToWidgets(shadowsizeED, shadowsizeUnitsLC,
|
||||||
(params.shadowsize).asString(), default_unit);
|
(params.shadowsize).asString(), default_unit);
|
||||||
// set color
|
// set color
|
||||||
frameColorCO->setCurrentIndex(findPos2nd(color, qt_(params.framecolor)) - 1);
|
// FIXME: Why use LaTeXName here, not LyXName? (spitz)
|
||||||
// only if the framecolor is black the backgroundcolor has the entry "none"
|
frameColorCO->setCurrentIndex(frameColorCO->findData(toqstr(params.framecolor)));
|
||||||
if (frameColorCO->currentIndex() != 0)
|
backgroundColorCO->setCurrentIndex(backgroundColorCO->findData(toqstr(params.backgroundcolor)));
|
||||||
backgroundColorCO->setCurrentIndex(findPos2nd(color, qt_(params.backgroundcolor)) - 1);
|
|
||||||
else
|
|
||||||
backgroundColorCO->setCurrentIndex(findPos2nd(color, qt_(params.backgroundcolor)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -494,17 +486,16 @@ docstring GuiBox::dialogToParams() const
|
|||||||
params.shadowsize = Length(widgetsToLength(shadowsizeED, shadowsizeUnitsLC));
|
params.shadowsize = Length(widgetsToLength(shadowsizeED, shadowsizeUnitsLC));
|
||||||
else
|
else
|
||||||
params.shadowsize = Length("4pt");
|
params.shadowsize = Length("4pt");
|
||||||
|
// FIXME: Why use LaTeXName here, not LyXName? (spitz)
|
||||||
if (frameColorCO->isEnabled())
|
if (frameColorCO->isEnabled())
|
||||||
params.framecolor = lcolor.getLaTeXName(color[frameColorCO->currentIndex() + 1].second);
|
params.framecolor =
|
||||||
|
fromqstr(frameColorCO->itemData(frameColorCO->currentIndex()).toString());
|
||||||
else
|
else
|
||||||
params.framecolor = "black";
|
params.framecolor = "black";
|
||||||
if (backgroundColorCO->isEnabled()) {
|
if (backgroundColorCO->isEnabled())
|
||||||
// only if the framecolor is black the backgroundcolor has the entry "none"
|
params.backgroundcolor =
|
||||||
if (frameColorCO->currentIndex() != 0)
|
fromqstr(backgroundColorCO->itemData(backgroundColorCO->currentIndex()).toString());
|
||||||
params.backgroundcolor = lcolor.getLaTeXName(color[backgroundColorCO->currentIndex() + 1].second);
|
else
|
||||||
else
|
|
||||||
params.backgroundcolor = lcolor.getLaTeXName(color[backgroundColorCO->currentIndex()].second);
|
|
||||||
} else
|
|
||||||
params.backgroundcolor = "none";
|
params.backgroundcolor = "none";
|
||||||
|
|
||||||
return from_ascii(InsetBox::params2string(params));
|
return from_ascii(InsetBox::params2string(params));
|
||||||
|
@ -20,8 +20,6 @@
|
|||||||
namespace lyx {
|
namespace lyx {
|
||||||
namespace frontend {
|
namespace frontend {
|
||||||
|
|
||||||
typedef std::pair<QString, ColorCode> ColorPair;
|
|
||||||
|
|
||||||
class GuiBox : public InsetParamsWidget, public Ui::BoxUi
|
class GuiBox : public InsetParamsWidget, public Ui::BoxUi
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -48,6 +46,8 @@ private:
|
|||||||
bool checkWidgets(bool readonly) const;
|
bool checkWidgets(bool readonly) const;
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
|
/// Fill the color combos
|
||||||
|
void fillComboColor(QComboBox * combo, bool const is_none);
|
||||||
/// add and remove special lengths
|
/// add and remove special lengths
|
||||||
void setSpecial(bool ibox);
|
void setSpecial(bool ibox);
|
||||||
/// only show valid inner box items
|
/// only show valid inner box items
|
||||||
@ -61,7 +61,7 @@ private:
|
|||||||
///
|
///
|
||||||
QStringList gui_names_spec_;
|
QStringList gui_names_spec_;
|
||||||
///
|
///
|
||||||
QList<ColorPair> color;
|
QList<ColorCode> color_codes_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace frontend
|
} // namespace frontend
|
||||||
|
Loading…
Reference in New Issue
Block a user