mplement colors. And we're done ...

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5655 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Levon 2002-11-17 09:42:25 +00:00
parent 9833278ed8
commit d7118a8fd7
8 changed files with 176 additions and 14 deletions

View File

@ -1,3 +1,13 @@
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

View File

@ -71,6 +71,8 @@ libqt2_la_SOURCES = \
lengthcombo.C \
lengthcombo.h \
lyx_gui.C \
qcoloritem.h \
qcoloritem.C \
qfont_loader.h \
qfont_loader.C \
qfont_metrics.C \

View File

@ -15,6 +15,8 @@
#endif
#include "support/lstrings.h"
#include "Lsstream.h"
#include <iomanip>
#include "ControlPrefs.h"
#include "QPrefsDialog.h"
@ -37,6 +39,7 @@
#include "lyxrc.h"
#include "frnt_lang.h"
#include "helper_funcs.h"
#include "debug.h"
#include <qpushbutton.h>
#include <qcheckbox.h>
@ -44,8 +47,13 @@
#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;
@ -249,7 +257,30 @@ void QPrefs::apply()
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);
}
}
}
@ -420,7 +451,4 @@ void QPrefs::update_contents()
converters_ = converters;
dialog_->updateConverters();
// FIXME: populate colors
}

View File

@ -47,6 +47,9 @@
#include <qlineedit.h>
#include <qcheckbox.h>
#include <qcombobox.h>
#include <qcolordialog.h>
#include <qcolor.h>
#include "qcoloritem.h"
using std::map;
using std::endl;
@ -153,6 +156,31 @@ QPrefsDialog::QPrefsDialog(QPrefs * form)
// 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()));
@ -166,8 +194,6 @@ QPrefsDialog::QPrefsDialog(QPrefs * form)
// 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()));
@ -425,3 +451,19 @@ void QPrefsDialog::remove_format()
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();
}
}

View File

@ -16,9 +16,12 @@
#pragma interface
#endif
#include "LColor.h"
#include "ui/QPrefsDialogBase.h"
#include <map>
#include <vector>
class QPrefs;
class QListViewItem;
@ -65,6 +68,8 @@ public slots:
void modify_converter();
void remove_converter();
void change_color();
protected:
void closeEvent(QCloseEvent * e);
@ -73,6 +78,8 @@ private:
PaneMap pane_map_;
std::vector<LColor::color> colors_;
QPrefAsciiModule * asciiModule;
QPrefDateModule * dateModule;
QPrefKeyboardModule * keyboardModule;
@ -89,7 +96,6 @@ private:
QPrefUIModule * uiModule;
QPrefs * form_;
};
#endif // PREFSDIALOG_H

View File

@ -0,0 +1,32 @@
/**
* \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_);
}

View File

@ -0,0 +1,48 @@
/**
* \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_;
};

View File

@ -13,7 +13,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>301</width>
<width>297</width>
<height>259</height>
</rect>
</property>
@ -62,12 +62,6 @@
</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>