CQPaletteChooser::
CQPaletteChooser(QWidget *parent) :
 QWidget(parent)
{
  QHBoxLayout *layout = new QHBoxLayout(this);
  layout->setMargin(2); layout->setSpacing(2);

  edit_   = new QLineEdit  (this);
  button_ = new QPushButton(this);

  button_->setIcon(CQPixmapCacheInst->getIcon("PALETTE_DIALOG"));

  //button_->setFixedSize(QSize(24,24));

  layout->addWidget(edit_  );
  layout->addWidget(button_);

  edit_  ->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
  button_->setSizePolicy(QSizePolicy::Fixed    , QSizePolicy::Fixed);

  connect(edit_  , SIGNAL(editingFinished()), this, SLOT(editPalette()));
  connect(button_, SIGNAL(clicked        ()), this, SLOT(choosePalette()));
}
Example #2
0
bool loadPalette(Pentagram::Palette * pal, const ConvertShapeFormat * format)
{
	GimpRGB color;
	guchar palHack[2];
	palHack[1] = 255;
	bool newPal;
	const gchar * palName;

	for (int i = 0; i < 256; ++i)
	{
		palHack[0] = i;
		pal->native[i] = *((uint16 * ) palHack);
	}

	if (format == &PentagramShapeFormat)
	{
		palName = "Pentagram";
	}
	else if (format == &U8SKFShapeFormat)
	{
		palName = "U8SKF";
	}
	else if (format == &U8ShapeFormat)
	{
		palName = "Ultima8";
	}
	else if (format == &U82DShapeFormat)
	{
		palName = "Ultima8";
	}
	else if (format == &CrusaderShapeFormat)
	{
		palName = "Crusader";
	}
	else if (format == &Crusader2DShapeFormat)
	{
		palName = "Crusader";
	}
	else
	{
		return false;
	}

	newPal = ! gimp_context_set_palette(palName);
	if (newPal)
	{
		gint colors = 0;
		if (gimp_palette_get_info(palName, &colors))
		{
			newPal = false;
			if (colors != 256)
			{
				newPal = true;
				if (!gimp_palette_delete(palName))
					return false;
			}
		}
	}

	if (newPal)
	{
		if (g_ascii_strcasecmp(palName, gimp_palette_new(palName)))
			return false;
		if (!gimp_context_set_palette(palName))
			return false;

		IDataSource * ds = choosePalette();
		if (ds)
		{
			gint j = 0;
			ds->seek(4);
			pal->load(*ds);
			delete ds;
			for (gint i = 0; i < 256; ++i)
			{
				gimp_rgb_set_uchar(&color,
							pal->palette[i * 3],
							pal->palette[i * 3 + 1],
							pal->palette[i * 3 + 2]);
				gimp_palette_add_entry(palName, "Untitled", &color, &j);
				assert (j == i);
			}
		}
		else
		{
			return false;
		}
	}
	else
	{
		for (gint i = 0; i < 256; ++i)
		{
			gimp_palette_entry_get_color(palName, i, &color);
			gimp_rgb_get_uchar(&color,
						&(pal->palette[i * 3]),
						&(pal->palette[i * 3 + 1]),
						&(pal->palette[i * 3 + 2]));
		}
	}

	return true;
}