+2002-11-17 John Levon <levon@movementarian.org>
+
+ * Makefile.am:
+ * qcoloritem.h:
+ * qcoloritem.C:
+ * ui/QPrefColorsModule.ui:
+ * QPrefs.C:
+ * QPrefsDialog.h:
+ * QPrefsDialog.C: implement colors. We're done !
+
2002-11-17 John Levon <levon@movementarian.org>
* FileDialog.C: split into open/save so open
lengthcombo.C \
lengthcombo.h \
lyx_gui.C \
+ qcoloritem.h \
+ qcoloritem.C \
qfont_loader.h \
qfont_loader.C \
qfont_metrics.C \
#endif
#include "support/lstrings.h"
+#include "Lsstream.h"
+#include <iomanip>
#include "ControlPrefs.h"
#include "QPrefsDialog.h"
#include "lyxrc.h"
#include "frnt_lang.h"
#include "helper_funcs.h"
+#include "debug.h"
#include <qpushbutton.h>
#include <qcheckbox.h>
#include <qspinbox.h>
#include <qcombobox.h>
#include <qlistbox.h>
+#include "qcoloritem.h"
using std::vector;
+using std::ostringstream;
+using std::setfill;
+using std::setw;
+using std::endl;
typedef Qt2CB<ControlPrefs, Qt2DB<QPrefsDialog> > base_class;
controller().setConverters(converters_);
controller().setFormats(formats_);
- // FIXME: controller().setColor(lc, hexname)
+ QPrefColorsModule * colmod(dialog_->colorsModule);
+
+ unsigned int i;
+
+ for (i = 0; i < colmod->lyxObjectsLB->count(); ++i) {
+ QListBoxItem * ib(colmod->lyxObjectsLB->item(i));
+ QColorItem * ci(static_cast<QColorItem*>(ib));
+
+ ostringstream ostr;
+
+ ostr << "#" << std::setbase(16) << setfill('0')
+ << setw(2) << ci->color().red()
+ << setw(2) << ci->color().green()
+ << setw(2) << ci->color().blue();
+
+ string newhex(STRCONV(ostr.str()));
+
+ LColor::color col(dialog_->colors_[i]);
+
+ // FIXME: dubious, but it's what xforms does
+ if (lcolor.getX11Name(col) != newhex) {
+ controller().setColor(col, newhex);
+ }
+ }
}
converters_ = converters;
dialog_->updateConverters();
-
-
- // FIXME: populate colors
}
#include <qlineedit.h>
#include <qcheckbox.h>
#include <qcombobox.h>
+#include <qcolordialog.h>
+#include <qcolor.h>
+#include "qcoloritem.h"
using std::map;
using std::endl;
// Qt sucks
resize(minimumSize());
+ // FIXME: put in controller
+ for (int i = 0; i < LColor::ignore; ++i) {
+ LColor::color lc = static_cast<LColor::color>(i);
+ if (lc == LColor::none
+ || lc == LColor::black
+ || lc == LColor::white
+ || lc == LColor::red
+ || lc == LColor::green
+ || lc == LColor::blue
+ || lc == LColor::cyan
+ || lc == LColor::magenta
+ || lc == LColor::yellow
+ || lc == LColor::inherit
+ || lc == LColor::ignore) continue;
+
+ colors_.push_back(lc);
+ string const x11name(lcolor.getX11Name(lc));
+ string const guiname(lcolor.getGUIName(lc));
+ QColorItem * ci(new QColorItem(QColor(x11name.c_str()), guiname.c_str()));
+ colorsModule->lyxObjectsLB->insertItem(ci);
+ }
+
+ connect(colorsModule->colorChangePB, SIGNAL(clicked()), this, SLOT(change_color()));
+ connect(colorsModule->lyxObjectsLB, SIGNAL(selected(int)), this, SLOT(change_color()));
+
connect(fileformatsModule->formatNewPB, SIGNAL(clicked()), this, SLOT(new_format()));
connect(fileformatsModule->formatRemovePB, SIGNAL(clicked()), this, SLOT(remove_format()));
connect(fileformatsModule->formatModifyPB, SIGNAL(clicked()), this, SLOT(modify_format()));
// Qt really sucks. This is as ugly as it looks, but the alternative
// means having to derive every module == bloat
- // FIXME: connect colors objs
-
connect(convertersModule->converterNewPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
connect(convertersModule->converterRemovePB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
connect(convertersModule->converterModifyPB, SIGNAL(clicked()), this, SLOT(change_adaptor()));
updateFormats();
updateConverters();
}
+
+
+void QPrefsDialog::change_color()
+{
+ QListBox * lb(colorsModule->lyxObjectsLB);
+ if (lb->currentItem() < 0)
+ return;
+ QListBoxItem * ib(lb->item(lb->currentItem()));
+ QColorItem * ci(static_cast<QColorItem*>(ib));
+ QColor c(QColorDialog::getColor(ci->color()));
+ if (c.isValid()) {
+ ci->color(c);
+ lb->update();
+ change_adaptor();
+ }
+}
#pragma interface
#endif
+#include "LColor.h"
+
#include "ui/QPrefsDialogBase.h"
#include <map>
+#include <vector>
class QPrefs;
class QListViewItem;
void modify_converter();
void remove_converter();
+ void change_color();
+
protected:
void closeEvent(QCloseEvent * e);
PaneMap pane_map_;
+ std::vector<LColor::color> colors_;
+
QPrefAsciiModule * asciiModule;
QPrefDateModule * dateModule;
QPrefKeyboardModule * keyboardModule;
QPrefUIModule * uiModule;
QPrefs * form_;
-
};
#endif // PREFSDIALOG_H
--- /dev/null
+/**
+ * \file qcoloritem.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#include "qcoloritem.h"
+
+#include <qfont.h>
+#include <qfontmetrics.h>
+
+QColorItem::QColorItem(QColor c, QString const & t)
+ : color_(c), text_(t)
+{
+ QFont font;
+ QFontMetrics metrics(font);
+
+ ascent_ = metrics.ascent();
+ width_ = 40 + metrics.width(t) + 5;
+ height_ = metrics.ascent() + metrics.descent() + 6;
+}
+
+
+void QColorItem::paint(QPainter * p)
+{
+ p->fillRect(2, 2, 35, height_, color_);
+ p->drawText(40, 3 + ascent_, text_);
+}
--- /dev/null
+/**
+ * \file qcoloritem.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
+ */
+
+#include <qlistbox.h>
+#include <qcolor.h>
+
+class QColorItem : public QListBoxItem {
+
+public:
+ QColorItem(QColor c, QString const & text);
+
+ QColor color() {
+ return color_;
+ }
+
+ void color(QColor c) {
+ color_ = c;
+ }
+
+ virtual int height(const QListBox *) const {
+ return height_;
+ }
+
+ virtual int width(const QListBox *) const {
+ return width_;
+ }
+
+protected:
+ virtual void paint(QPainter * p);
+
+private:
+ int ascent_;
+
+ int height_;
+
+ int width_;
+
+ QColor color_;
+
+ QString text_;
+};
<rect>
<x>0</x>
<y>0</y>
- <width>301</width>
+ <width>297</width>
<height>259</height>
</rect>
</property>
</widget>
<widget>
<class>QListBox</class>
- <item>
- <property>
- <name>text</name>
- <string>New Item</string>
- </property>
- </item>
<property stdset="1">
<name>name</name>
<cstring>lyxObjectsLB</cstring>