2008-04-24 14:49:12 +02:00
|
|
|
/***************************************************************************
|
|
|
|
|
|
|
|
CColor.cpp
|
|
|
|
|
2009-08-17 12:41:51 +02:00
|
|
|
(c) 2000-2009 Benoît Minisini <gambas@users.sourceforge.net>
|
2008-04-24 14:49:12 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2009-08-17 12:41:51 +02:00
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
2008-04-24 14:49:12 +02:00
|
|
|
any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#define __CCOLOR_CPP
|
|
|
|
|
|
|
|
#include <qapplication.h>
|
|
|
|
#include <qcolor.h>
|
|
|
|
#include <qpalette.h>
|
|
|
|
|
|
|
|
#include "gambas.h"
|
|
|
|
|
|
|
|
#include "CWidget.h"
|
|
|
|
#include "CColor.h"
|
|
|
|
|
|
|
|
static int _h = 0;
|
|
|
|
static int _s = 0;
|
|
|
|
static int _v = 0;
|
|
|
|
|
2009-08-09 00:34:19 +02:00
|
|
|
QColor CCOLOR_merge(const QColor &colorA, const QColor &colorB, int factor)
|
|
|
|
{
|
|
|
|
const int maxFactor = 100;
|
|
|
|
QColor tmp = colorA;
|
|
|
|
tmp.setRed((tmp.red() * factor) / maxFactor + (colorB.red() * (maxFactor - factor)) / maxFactor);
|
|
|
|
tmp.setGreen((tmp.green() * factor) / maxFactor + (colorB.green() * (maxFactor - factor)) / maxFactor);
|
|
|
|
tmp.setBlue((tmp.blue() * factor) / maxFactor + (colorB.blue() * (maxFactor - factor)) / maxFactor);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2008-04-24 14:49:12 +02:00
|
|
|
static void get_hsv(int col)
|
|
|
|
{
|
|
|
|
static int last = 0;
|
|
|
|
|
|
|
|
if (last == col)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QColor c(col);
|
|
|
|
c.getHsv(&_h, &_s, &_v);
|
|
|
|
if (_h < 0)
|
|
|
|
_h = 0;
|
|
|
|
last = col;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-29 15:40:55 +02:00
|
|
|
static void return_color(QPalette::ColorRole role)
|
2008-04-24 14:49:12 +02:00
|
|
|
{
|
2008-04-29 15:40:55 +02:00
|
|
|
GB.ReturnInteger(QApplication::palette().color(role).rgb() & 0xFFFFFF);
|
2008-04-24 14:49:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CCOLOR_background)
|
|
|
|
|
2008-04-29 15:40:55 +02:00
|
|
|
return_color(QPalette::Window);
|
2008-04-24 14:49:12 +02:00
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CCOLOR_foreground)
|
|
|
|
|
2008-04-29 15:40:55 +02:00
|
|
|
return_color(QPalette::WindowText);
|
2008-04-24 14:49:12 +02:00
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CCOLOR_text_background)
|
|
|
|
|
2008-04-29 15:40:55 +02:00
|
|
|
return_color(QPalette::Base);
|
2008-04-24 14:49:12 +02:00
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CCOLOR_text_foreground)
|
|
|
|
|
2008-04-29 15:40:55 +02:00
|
|
|
return_color(QPalette::Text);
|
2008-04-24 14:49:12 +02:00
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CCOLOR_selected_background)
|
|
|
|
|
2008-04-29 15:40:55 +02:00
|
|
|
return_color(QPalette::Highlight);
|
2008-04-24 14:49:12 +02:00
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CCOLOR_light_background)
|
|
|
|
|
|
|
|
QColor col;
|
|
|
|
int h, s, v;
|
|
|
|
|
2008-04-29 15:40:55 +02:00
|
|
|
get_hsv(QApplication::palette().color(QPalette::Highlight).rgb() & 0xFFFFFF);
|
2008-04-24 14:49:12 +02:00
|
|
|
h = _h; s = _s; v = _v;
|
|
|
|
|
2008-04-29 15:40:55 +02:00
|
|
|
get_hsv(QApplication::palette().color(QPalette::Base).rgb() & 0xFFFFFF);
|
2008-04-24 14:49:12 +02:00
|
|
|
|
2008-04-29 15:40:55 +02:00
|
|
|
col = QColor::fromHsv(h, (_s * 3 + s) / 4, (_v * 3 + v) / 4);
|
2008-04-24 14:49:12 +02:00
|
|
|
|
|
|
|
GB.ReturnInteger((uint)col.rgb() & 0xFFFFFF);
|
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CCOLOR_selected_foreground)
|
|
|
|
|
2008-04-29 15:40:55 +02:00
|
|
|
return_color(QPalette::HighlightedText);
|
2008-04-24 14:49:12 +02:00
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CCOLOR_button_background)
|
|
|
|
|
2008-04-29 15:40:55 +02:00
|
|
|
return_color(QPalette::Button);
|
2008-04-24 14:49:12 +02:00
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
BEGIN_PROPERTY(CCOLOR_button_foreground)
|
|
|
|
|
2008-04-29 15:40:55 +02:00
|
|
|
return_color(QPalette::ButtonText);
|
2008-04-24 14:49:12 +02:00
|
|
|
|
|
|
|
END_PROPERTY
|
|
|
|
|
|
|
|
GB_DESC CColorDesc[] =
|
|
|
|
{
|
|
|
|
GB_DECLARE("Color", 0), GB_VIRTUAL_CLASS(),
|
|
|
|
|
|
|
|
GB_STATIC_PROPERTY("Background", "i", CCOLOR_background),
|
|
|
|
GB_STATIC_PROPERTY("SelectedBackground", "i", CCOLOR_selected_background),
|
|
|
|
GB_STATIC_PROPERTY("LightBackground", "i", CCOLOR_light_background),
|
|
|
|
GB_STATIC_PROPERTY("TextBackground", "i", CCOLOR_text_background),
|
|
|
|
GB_STATIC_PROPERTY("ButtonBackground", "i", CCOLOR_button_background),
|
|
|
|
|
|
|
|
GB_STATIC_PROPERTY("Foreground", "i", CCOLOR_foreground),
|
|
|
|
GB_STATIC_PROPERTY("SelectedForeground", "i", CCOLOR_selected_foreground),
|
|
|
|
GB_STATIC_PROPERTY("TextForeground", "i", CCOLOR_text_foreground),
|
|
|
|
GB_STATIC_PROPERTY("ButtonForeground", "i", CCOLOR_button_foreground),
|
|
|
|
|
|
|
|
GB_END_DECLARE
|
|
|
|
};
|
|
|
|
|
|
|
|
|