Use view/data separation for GuiCharacter colors, which makes it possible to sort the colors

This commit is contained in:
Juergen Spitzmueller 2015-05-17 17:15:01 +02:00
parent 8fc637103f
commit b7c53b6017
2 changed files with 36 additions and 35 deletions

View File

@ -28,6 +28,8 @@
#include "Language.h" #include "Language.h"
#include "Paragraph.h" #include "Paragraph.h"
#include "support/gettext.h"
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <QComboBox> #include <QComboBox>
#include <QModelIndex> #include <QModelIndex>
@ -88,31 +90,28 @@ static QList<BarPair> barData()
} }
static QList<ColorPair> colorData() static QList<ColorCode> colorData()
{ {
QList<ColorPair> colors; QList<ColorCode> colors;
colors << ColorPair(qt_("No change"), Color_ignore); colors << Color_black;
colors << ColorPair(qt_("No color"), Color_none); colors << Color_blue;
colors << ColorPair(qt_("Black"), Color_black); colors << Color_brown;
colors << ColorPair(qt_("Blue"), Color_blue); colors << Color_cyan;
colors << ColorPair(qt_("Brown"), Color_brown); colors << Color_darkgray;
colors << ColorPair(qt_("Cyan"), Color_cyan); colors << Color_gray;
colors << ColorPair(qt_("Darkgray"), Color_darkgray); colors << Color_green;
colors << ColorPair(qt_("Gray"), Color_gray); colors << Color_lightgray;
colors << ColorPair(qt_("Green"), Color_green); colors << Color_lime;
colors << ColorPair(qt_("Lightgray"), Color_lightgray); colors << Color_magenta;
colors << ColorPair(qt_("Lime"), Color_lime); colors << Color_olive;
colors << ColorPair(qt_("Magenta"), Color_magenta); colors << Color_orange;
colors << ColorPair(qt_("Olive"), Color_olive); colors << Color_pink;
colors << ColorPair(qt_("Orange"), Color_orange); colors << Color_purple;
colors << ColorPair(qt_("Pink"), Color_pink); colors << Color_red;
colors << ColorPair(qt_("Purple"), Color_purple); colors << Color_teal;
colors << ColorPair(qt_("Red"), Color_red); colors << Color_violet;
colors << ColorPair(qt_("Teal"), Color_teal); colors << Color_white;
colors << ColorPair(qt_("Violet"), Color_violet); colors << Color_yellow;
colors << ColorPair(qt_("White"), Color_white);
colors << ColorPair(qt_("Yellow"), Color_yellow);
colors << ColorPair(qt_("Reset"), Color_inherit);
return colors; return colors;
} }
@ -174,19 +173,21 @@ template<typename T>
void fillComboColor(QComboBox * combo, QList<T> const & list) void fillComboColor(QComboBox * combo, QList<T> const & list)
{ {
// at first add the 2 colors "No change" and "No color" // at first add the 2 colors "No change" and "No color"
combo->addItem(list.begin()->first); combo->addItem(qt_("No change"), "ignore");
combo->addItem((list.begin() + 1)->first); combo->addItem(qt_("No color"), "none");
// now add the real colors // now add the real colors
QPixmap coloritem(32, 32); QPixmap coloritem(32, 32);
QColor color; QColor color;
typename QList<T>::const_iterator cit = list.begin() + 2; QList<ColorCode>::const_iterator cit = list.begin();
for (; cit != list.end() - 1; ++cit) { for (; cit != list.end(); ++cit) {
color = QColor(guiApp->colorCache().get(cit->second, false)); QString const lyxname = toqstr(lcolor.getLyXName(*cit));
QString const guiname = toqstr(translateIfPossible(lcolor.getGUIName(*cit)));
color = QColor(guiApp->colorCache().get(*cit, false));
coloritem.fill(color); coloritem.fill(color);
combo->addItem(QIcon(coloritem), cit->first); combo->addItem(QIcon(coloritem), guiname, lyxname);
} }
//the last color is "Reset" //the last color is "Reset"
combo->addItem((list.end() - 1)->first); combo->addItem(qt_("Reset"), "inherit");
} }
} }
@ -218,6 +219,7 @@ GuiCharacter::GuiCharacter(GuiView & lv)
size = sizeData(); size = sizeData();
bar = barData(); bar = barData();
color = colorData(); color = colorData();
sort(color.begin(), color.end(), ColorSorter());
language = languageData(); language = languageData();
language.prepend(LanguagePair(qt_("Reset"), "reset")); language.prepend(LanguagePair(qt_("Reset"), "reset"));
@ -395,7 +397,7 @@ void GuiCharacter::paramsToDialog(Font const & font)
shapeCO->setCurrentIndex(findPos2nd(shape, fi.shape())); shapeCO->setCurrentIndex(findPos2nd(shape, fi.shape()));
sizeCO->setCurrentIndex(findPos2nd(size, fi.size())); sizeCO->setCurrentIndex(findPos2nd(size, fi.size()));
miscCO->setCurrentIndex(findPos2nd(bar, getBar(fi))); miscCO->setCurrentIndex(findPos2nd(bar, getBar(fi)));
colorCO->setCurrentIndex(findPos2nd(color, fi.color())); colorCO->setCurrentIndex(colorCO->findData(toqstr(lcolor.getLyXName(fi.color()))));
// reset_language is a null pointer. // reset_language is a null pointer.
QString const lang = (font.language() == reset_language) QString const lang = (font.language() == reset_language)
@ -414,7 +416,7 @@ void GuiCharacter::applyView()
fi.setShape(shape[shapeCO->currentIndex()].second); fi.setShape(shape[shapeCO->currentIndex()].second);
fi.setSize(size[sizeCO->currentIndex()].second); fi.setSize(size[sizeCO->currentIndex()].second);
setBar(fi, bar[miscCO->currentIndex()].second); setBar(fi, bar[miscCO->currentIndex()].second);
fi.setColor(color[colorCO->currentIndex()].second); fi.setColor(lcolor.getFromLyXName(fromqstr(colorCO->itemData(colorCO->currentIndex()).toString())));
font_.setLanguage(languages.getLanguage( font_.setLanguage(languages.getLanguage(
fromqstr(language[langCO->currentIndex()].second))); fromqstr(language[langCO->currentIndex()].second)));

View File

@ -52,7 +52,6 @@ typedef std::pair<QString, FontSeries> SeriesPair;
typedef std::pair<QString, FontShape> ShapePair; typedef std::pair<QString, FontShape> ShapePair;
typedef std::pair<QString, FontSize> SizePair; typedef std::pair<QString, FontSize> SizePair;
typedef std::pair<QString, FontState> BarPair; typedef std::pair<QString, FontState> BarPair;
typedef std::pair<QString, ColorCode> ColorPair;
typedef std::pair<QString, QString> LanguagePair; typedef std::pair<QString, QString> LanguagePair;
class GuiCharacter : public GuiDialog, public Ui::CharacterUi class GuiCharacter : public GuiDialog, public Ui::CharacterUi
@ -87,7 +86,7 @@ private:
QList<ShapePair> shape; QList<ShapePair> shape;
QList<SizePair> size; QList<SizePair> size;
QList<BarPair> bar; QList<BarPair> bar;
QList<ColorPair> color; QList<ColorCode> color;
QList<LanguagePair> language; QList<LanguagePair> language;
/// ///